Skip to content

Commit 156d413

Browse files
authored
feat: megaeth swap (#169)
* feat: added megaeth multicall for balance, enabled swap on megaeth * fix: fixed multicall balance string not being in decimal string * fix: removed cfee estimation if amount is 0
1 parent 5bf9bc1 commit 156d413

6 files changed

Lines changed: 226 additions & 42 deletions

File tree

src/commons/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ export type Chain = {
383383
};
384384
};
385385
universe: Universe;
386+
swapSupported: boolean;
386387
};
387388

388389
interface EthereumProvider {

src/commons/types/swap-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ export type AnkrBalance = {
218218
balance: string;
219219
balanceUSD: string;
220220
chainID: number;
221+
error?: boolean;
221222
tokenAddress: `0x${string}`;
222223
tokenData: {
223224
decimals: number;

src/sdk/ca-base/chains.ts

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ const TESTNET_CHAINS: Chain[] = [
192192
// universe: Universe.TRON,
193193
// },
194194
{
195+
swapSupported: false,
195196
blockExplorers: {
196197
default: {
197198
name: 'Citrea Testnet explorer',
@@ -228,6 +229,7 @@ const TESTNET_CHAINS: Chain[] = [
228229
universe: Universe.ETHEREUM,
229230
},
230231
{
232+
swapSupported: false,
231233
blockExplorers: {
232234
default: {
233235
name: 'Arbitrum Sepolia Explorer',
@@ -274,6 +276,7 @@ const TESTNET_CHAINS: Chain[] = [
274276
universe: Universe.ETHEREUM,
275277
},
276278
{
279+
swapSupported: false,
277280
blockExplorers: {
278281
default: {
279282
name: 'OP Sepolia Explorer',
@@ -320,6 +323,7 @@ const TESTNET_CHAINS: Chain[] = [
320323
universe: Universe.ETHEREUM,
321324
},
322325
{
326+
swapSupported: false,
323327
blockExplorers: {
324328
default: {
325329
name: 'Amoy Polygon Explorer',
@@ -359,6 +363,7 @@ const TESTNET_CHAINS: Chain[] = [
359363
universe: Universe.ETHEREUM,
360364
},
361365
{
366+
swapSupported: false,
362367
blockExplorers: {
363368
default: {
364369
name: 'Base Sepolia Scan',
@@ -398,6 +403,7 @@ const TESTNET_CHAINS: Chain[] = [
398403
universe: Universe.ETHEREUM,
399404
},
400405
{
406+
swapSupported: false,
401407
blockExplorers: {
402408
default: {
403409
name: 'Monad Testnet Explorer',
@@ -441,6 +447,7 @@ const TESTNET_CHAINS: Chain[] = [
441447
universe: Universe.ETHEREUM,
442448
},
443449
{
450+
swapSupported: false,
444451
blockExplorers: {
445452
default: {
446453
name: 'Etherscan Sepolia',
@@ -479,46 +486,11 @@ const TESTNET_CHAINS: Chain[] = [
479486
},
480487
universe: Universe.ETHEREUM,
481488
},
482-
// {
483-
// blockExplorers: {
484-
// default: {
485-
// name: 'Validium Testnet Explorer',
486-
// url: 'https://testnet.explorer.validium.network',
487-
// },
488-
// },
489-
// custom: {
490-
// icon: 'https://assets.coingecko.com/asset_platforms/images/279/large/ethereum.png',
491-
// knownTokens: [
492-
// {
493-
// contractAddress: TOKEN_CONTRACT_ADDRESSES['USDC'][SUPPORTED_CHAINS.VALIDIUM_TESTNET],
494-
// decimals: 6,
495-
// logo: getLogoFromSymbol('USDC'),
496-
// name: 'USD Coin',
497-
// symbol: 'USDC',
498-
// },
499-
// ],
500-
// },
501-
// id: SUPPORTED_CHAINS.VALIDIUM_TESTNET,
502-
// name: 'Validium Testnet',
503-
// ankrName: '',
504-
// nativeCurrency: {
505-
// decimals: 18,
506-
// name: 'VLDM',
507-
// symbol: 'VLDM',
508-
// },
509-
// rpcUrls: {
510-
// default: {
511-
// http: ['https://testnet.l2.rpc.validium.network'],
512-
// publicHttp: ['https://testnet.l2.rpc.validium.network'],
513-
// webSocket: ['wss://testnet.l2.rpc.validium.network/ws'],
514-
// },
515-
// },
516-
// universe: Universe.ETHEREUM,
517-
// },
518489
];
519490

520491
const MAINNET_CHAINS: Chain[] = [
521492
{
493+
swapSupported: false,
522494
blockExplorers: {
523495
default: {
524496
name: 'Citrea Explorer',
@@ -562,6 +534,7 @@ const MAINNET_CHAINS: Chain[] = [
562534
universe: Universe.ETHEREUM,
563535
},
564536
{
537+
swapSupported: false,
565538
blockExplorers: {
566539
default: {
567540
name: 'KaiaScan',
@@ -598,6 +571,7 @@ const MAINNET_CHAINS: Chain[] = [
598571
universe: Universe.ETHEREUM,
599572
},
600573
{
574+
swapSupported: false,
601575
blockExplorers: {
602576
default: {
603577
name: 'Etherscan',
@@ -641,6 +615,7 @@ const MAINNET_CHAINS: Chain[] = [
641615
universe: Universe.ETHEREUM,
642616
},
643617
{
618+
swapSupported: false,
644619
blockExplorers: {
645620
default: {
646621
name: 'Monad Vision',
@@ -677,6 +652,7 @@ const MAINNET_CHAINS: Chain[] = [
677652
universe: Universe.ETHEREUM,
678653
},
679654
{
655+
swapSupported: true,
680656
blockExplorers: {
681657
default: {
682658
name: 'Optimism Etherscan',
@@ -720,6 +696,7 @@ const MAINNET_CHAINS: Chain[] = [
720696
universe: Universe.ETHEREUM,
721697
},
722698
{
699+
swapSupported: true,
723700
blockExplorers: {
724701
default: {
725702
name: 'MegaETH Blockscout',
@@ -757,6 +734,7 @@ const MAINNET_CHAINS: Chain[] = [
757734
universe: Universe.ETHEREUM,
758735
},
759736
{
737+
swapSupported: true,
760738
blockExplorers: {
761739
default: {
762740
name: 'Polygonscan',
@@ -800,6 +778,7 @@ const MAINNET_CHAINS: Chain[] = [
800778
universe: Universe.ETHEREUM,
801779
},
802780
{
781+
swapSupported: true,
803782
blockExplorers: {
804783
default: {
805784
name: 'Basescan',
@@ -836,6 +815,7 @@ const MAINNET_CHAINS: Chain[] = [
836815
universe: Universe.ETHEREUM,
837816
},
838817
{
818+
swapSupported: true,
839819
blockExplorers: {
840820
default: {
841821
name: 'Arbiscan',
@@ -879,6 +859,7 @@ const MAINNET_CHAINS: Chain[] = [
879859
universe: Universe.ETHEREUM,
880860
},
881861
{
862+
swapSupported: true,
882863
blockExplorers: {
883864
default: {
884865
name: 'Scrollscan',
@@ -922,6 +903,7 @@ const MAINNET_CHAINS: Chain[] = [
922903
universe: Universe.ETHEREUM,
923904
},
924905
{
906+
swapSupported: true,
925907
blockExplorers: {
926908
default: {
927909
name: 'Snowscan',
@@ -965,6 +947,7 @@ const MAINNET_CHAINS: Chain[] = [
965947
universe: Universe.ETHEREUM,
966948
},
967949
{
950+
swapSupported: true,
968951
blockExplorers: {
969952
default: {
970953
name: 'BscScan',
@@ -1015,6 +998,7 @@ const MAINNET_CHAINS: Chain[] = [
1015998
universe: Universe.ETHEREUM,
1016999
},
10171000
{
1001+
swapSupported: false,
10181002
blockExplorers: {
10191003
default: {
10201004
name: 'Hyperscan',

src/sdk/ca-base/swap/route.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,10 @@ const _exactOutRoute = async (
282282

283283
// Collection Fee needs to be calculated on cot
284284
const estimatedCollectionFee = estimateCollectionFee(
285-
uniqBy(balances, (b) => b.chainID).map((b) => {
285+
uniqBy(
286+
balances.filter((b) => new Decimal(b.amount).gt(0)),
287+
(b) => b.chainID
288+
).map((b) => {
286289
const cdm = ChaindataMap.get(new OmniversalChainID(Universe.ETHEREUM, b.chainID));
287290
if (!cdm) {
288291
throw Errors.internal(`chain data not found for chain ${input.toChainId}`);

src/sdk/ca-base/swap/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,7 @@ export const performDestinationSwap = async ({
16531653

16541654
export const getSwapSupportedChains = (chainList: ChainListType) => {
16551655
return chainList.chains
1656-
.filter((chain) => chain.ankrName !== '')
1656+
.filter((chain) => chain.swapSupported)
16571657
.map((chain) => ({
16581658
id: chain.id,
16591659
name: chain.name,

0 commit comments

Comments
 (0)