Skip to content

Commit 262630c

Browse files
committed
feat: add support for Monad
1 parent 07b51a1 commit 262630c

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

cypress/support/chain-fixtures.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export const TEST_ADDRESSES: Record<SupportedChainId, string> = {
6565
[ChainId.Mantle]: '0xEF12EAA20882A33487Ab069C2E27855aF49D9B16',
6666
[ChainId.MetisAndromedaMainnet]: '0x50E92fd1f4A456b6669637635333C6275ada797d',
6767
[ChainId.MintMainnet]: '0x0cf19FEAB99a1cdA5e101c1a6689490496aD630A',
68+
[ChainId.MonadMainnet]: '0x6cCEF041d4Be3Db50Cc093cff835D8E793FcbfAF',
6869
[ChainId.Mode]: '0x0A30C1F21E0268A58327665aA5106a8444c5C21c',
6970
[ChainId.Moonbeam]: '0x8107b00171a02f83D7a17f62941841C29c3ae60F',
7071
[ChainId.Moonriver]: '0x8107b00171a02f83D7a17f62941841C29c3ae60F',

lib/api/logs/CovalentEventGetter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class CovalentEventGetter implements EventGetter {
2222

2323
// Covalent removed their "latest block" API, so now we have to get status for *ALL* chains instead
2424

25-
const apiUrl = `https://api.covalenthq.com/v1/chains/status`;
25+
const apiUrl = `https://api.covalenthq.com/v1/chains/status/`;
2626
const headers = this.getHeaders();
2727
const result = await this.queue.add(() => ky.get(apiUrl, { headers, retry: 3, timeout: false }).json<any>());
2828

@@ -55,7 +55,7 @@ export class CovalentEventGetter implements EventGetter {
5555
topics: Array<string | null>,
5656
): Promise<Log[]> {
5757
const [mainTopic, ...secondaryTopics] = topics.filter((topic) => !isNullish(topic));
58-
const apiUrl = `https://api.covalenthq.com/v1/${chainId}/events/topics/${mainTopic}`;
58+
const apiUrl = `https://api.covalenthq.com/v1/${chainId}/events/topics/${mainTopic}/`;
5959

6060
const searchParams = {
6161
'starting-block': fromBlock === 0 ? 'earliest' : fromBlock,
@@ -83,7 +83,7 @@ export class CovalentEventGetter implements EventGetter {
8383

8484
private getHeaders(): Record<string, string> {
8585
return {
86-
Authorization: `Basic ${Buffer.from(`${this.apiKey}:`).toString('base64')}`,
86+
Authorization: `Bearer ${this.apiKey}`,
8787
};
8888
}
8989
}

lib/utils/chains.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export const CHAIN_SELECT_MAINNETS = [
3737
ChainId.Mantle,
3838
ChainId.Mode,
3939
ChainId.Gnosis,
40+
ChainId.MonadMainnet,
4041
ChainId.Blast,
4142
ChainId.ZkSyncMainnet,
4243
ChainId.Swellchain,
@@ -1445,6 +1446,9 @@ export const CHAINS = {
14451446
name: 'MegaETH Testnet',
14461447
logoUrl: '/assets/images/vendor/chains/megaeth.svg',
14471448
explorerUrl: 'https://web3.okx.com/explorer/megaeth-testnet',
1449+
rpc: {
1450+
main: `https://megaeth-testnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}`,
1451+
},
14481452
deployedContracts: { ...MULTICALL },
14491453
isTestnet: true,
14501454
correspondingMainnetChainId: 12345678903,
@@ -1502,10 +1506,17 @@ export const CHAINS = {
15021506
priceStrategy: undefined, // TODO
15031507
}),
15041508
[ChainId.MonadMainnet]: new Chain({
1505-
type: SupportType.UNSUPPORTED,
1509+
type: SupportType.ETHERSCAN_COMPATIBLE,
15061510
chainId: ChainId.MonadMainnet,
15071511
name: 'Monad',
1512+
nativeTokenCoingeckoId: 'monad',
15081513
logoUrl: '/assets/images/vendor/chains/monad.svg',
1514+
explorerUrl: 'https://monadscan.com',
1515+
rpc: {
1516+
main: `https://monad-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}`,
1517+
free: 'https://rpc.monad.xyz',
1518+
},
1519+
deployedContracts: { ...MULTICALL },
15091520
}),
15101521
[ChainId.MonadTestnet]: new Chain({
15111522
type: SupportType.ETHERSCAN_COMPATIBLE,

scripts/get-chain-order.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ const hasDeployedMulticall = async (chainId: number, multicallData: readonly any
8282
const registeredMulticall = multicallData.find((data) => data.chainId === chainId);
8383
if (registeredMulticall) return true;
8484

85-
const publicClient = createViemPublicClientForChain(chainId);
86-
const unregisteredMulticall = await publicClient.getCode({ address: MULTICALL_ADDRESS });
85+
try {
86+
const publicClient = createViemPublicClientForChain(chainId);
87+
const unregisteredMulticall = await publicClient.getCode({ address: MULTICALL_ADDRESS });
8788

88-
if (unregisteredMulticall && unregisteredMulticall !== '0x') return true;
89+
if (unregisteredMulticall && unregisteredMulticall !== '0x') return true;
90+
} catch {}
8991

9092
return false;
9193
};

test/chains.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { expect } from 'chai';
33
import { TEST_ADDRESSES } from 'cypress/support/chain-fixtures';
44
import { SupportType } from 'lib/chains/Chain';
55
import { ALCHEMY_API_KEY, DRPC_API_KEY, INFURA_API_KEY } from 'lib/constants';
6+
import { getScriptLogsProvider } from 'lib/ScriptLogsProvider';
67
import {
78
createViemPublicClientForChain,
89
getChainApiUrl,
@@ -104,6 +105,12 @@ describe('Chain Support', () => {
104105
ALCHEMY_API_KEY && expect(getChainFreeRpcUrl(chainId)).to.not.include(ALCHEMY_API_KEY);
105106
DRPC_API_KEY && expect(getChainFreeRpcUrl(chainId)).to.not.include(DRPC_API_KEY);
106107
});
108+
109+
it('can retrieve latest block number', async () => {
110+
const logsProvider = getScriptLogsProvider(chainId);
111+
const blockHeight = await logsProvider.getLatestBlock();
112+
expect(blockHeight).to.exist;
113+
});
107114
});
108115
});
109116
});

0 commit comments

Comments
 (0)