four-flap-meme-sdk 3.0.1 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle/four-meme/approve-tokenmanager.d.ts +2 -2
- package/dist/bundle/four-meme/approve-tokenmanager.js +3 -3
- package/dist/bundle/four-meme/core/buy-flow.d.ts +5 -0
- package/dist/bundle/four-meme/core/buy-flow.js +147 -0
- package/dist/bundle/four-meme/core/constants.d.ts +6 -0
- package/dist/bundle/four-meme/core/constants.js +15 -0
- package/dist/bundle/four-meme/core/create-token.d.ts +5 -0
- package/dist/bundle/four-meme/core/create-token.js +137 -0
- package/dist/bundle/four-meme/core/index.d.ts +14 -0
- package/dist/bundle/four-meme/core/index.js +14 -0
- package/dist/bundle/four-meme/core/sell-flow.d.ts +5 -0
- package/dist/bundle/four-meme/core/sell-flow.js +240 -0
- package/dist/bundle/four-meme/core-helpers.js +1 -1
- package/dist/bundle/four-meme/core.d.ts +7 -4
- package/dist/bundle/four-meme/core.js +5 -513
- package/dist/bundle/four-meme/pancake-proxy/approve.d.ts +15 -0
- package/dist/bundle/four-meme/pancake-proxy/approve.js +113 -0
- package/dist/bundle/four-meme/pancake-proxy/buy.d.ts +8 -0
- package/dist/bundle/four-meme/pancake-proxy/buy.js +143 -0
- package/dist/bundle/four-meme/pancake-proxy/constants.d.ts +25 -0
- package/dist/bundle/four-meme/pancake-proxy/constants.js +14 -0
- package/dist/bundle/four-meme/pancake-proxy/helpers.d.ts +45 -0
- package/dist/bundle/four-meme/pancake-proxy/helpers.js +232 -0
- package/dist/bundle/four-meme/pancake-proxy/index.d.ts +15 -0
- package/dist/bundle/four-meme/pancake-proxy/index.js +15 -0
- package/dist/bundle/four-meme/pancake-proxy/sell.d.ts +8 -0
- package/dist/bundle/four-meme/pancake-proxy/sell.js +194 -0
- package/dist/bundle/four-meme/pancake-proxy.d.ts +4 -20
- package/dist/bundle/four-meme/pancake-proxy.js +3 -670
- package/dist/bundle/four-meme/private/buy.d.ts +16 -0
- package/dist/bundle/four-meme/private/buy.js +225 -0
- package/dist/bundle/four-meme/private/index.d.ts +11 -0
- package/dist/bundle/four-meme/private/index.js +11 -0
- package/dist/bundle/four-meme/private/sell.d.ts +18 -0
- package/dist/bundle/four-meme/private/sell.js +245 -0
- package/dist/bundle/four-meme/private.d.ts +5 -25
- package/dist/bundle/four-meme/private.js +5 -463
- package/dist/bundle/four-meme/swap/batch.d.ts +8 -0
- package/dist/bundle/four-meme/swap/batch.js +170 -0
- package/dist/bundle/four-meme/swap/bundle.d.ts +8 -0
- package/dist/bundle/four-meme/swap/bundle.js +147 -0
- package/dist/bundle/four-meme/swap/index.d.ts +14 -0
- package/dist/bundle/four-meme/swap/index.js +13 -0
- package/dist/bundle/four-meme/swap/quick-batch.d.ts +8 -0
- package/dist/bundle/four-meme/swap/quick-batch.js +206 -0
- package/dist/bundle/four-meme/swap-buy-first/helpers.d.ts +20 -0
- package/dist/bundle/four-meme/swap-buy-first/helpers.js +39 -0
- package/dist/bundle/four-meme/swap-buy-first/index.d.ts +12 -0
- package/dist/bundle/four-meme/swap-buy-first/index.js +11 -0
- package/dist/bundle/four-meme/swap-buy-first/multi-wallet.d.ts +20 -0
- package/dist/bundle/four-meme/swap-buy-first/multi-wallet.js +198 -0
- package/dist/bundle/four-meme/swap-buy-first/single.d.ts +7 -0
- package/dist/bundle/four-meme/swap-buy-first/single.js +232 -0
- package/dist/bundle/four-meme/swap-buy-first.d.ts +4 -3
- package/dist/bundle/four-meme/swap-buy-first.js +4 -451
- package/dist/bundle/four-meme/swap-hop-helpers.d.ts +2 -2
- package/dist/bundle/four-meme/swap-sign-helpers.d.ts +2 -2
- package/dist/bundle/four-meme/swap-sign-helpers.js +1 -1
- package/dist/bundle/four-meme/swap.d.ts +4 -14
- package/dist/bundle/four-meme/swap.js +4 -502
- package/dist/bundle/four-meme/types/index.d.ts +1 -1
- package/dist/bundle/four-meme/utils-disperse.d.ts +1 -1
- package/dist/bundle/four-meme/utils-disperse.js +1 -1
- package/dist/bundle/four-meme/utils-pairwise.d.ts +1 -1
- package/dist/bundle/four-meme/utils-pairwise.js +1 -1
- package/dist/bundle/four-meme/utils-sweep/context.d.ts +39 -0
- package/dist/bundle/four-meme/utils-sweep/context.js +7 -0
- package/dist/bundle/four-meme/utils-sweep/erc20-no-hop.d.ts +5 -0
- package/dist/bundle/four-meme/utils-sweep/erc20-no-hop.js +162 -0
- package/dist/bundle/four-meme/utils-sweep/index.d.ts +13 -0
- package/dist/bundle/four-meme/utils-sweep/index.js +13 -0
- package/dist/bundle/four-meme/utils-sweep/main.d.ts +8 -0
- package/dist/bundle/four-meme/utils-sweep/main.js +114 -0
- package/dist/bundle/four-meme/utils-sweep/native-no-hop.d.ts +5 -0
- package/dist/bundle/four-meme/utils-sweep/native-no-hop.js +156 -0
- package/dist/bundle/four-meme/utils-sweep/with-hops.d.ts +6 -0
- package/dist/bundle/four-meme/utils-sweep/with-hops.js +382 -0
- package/dist/bundle/four-meme/utils-sweep.d.ts +3 -4
- package/dist/bundle/four-meme/utils-sweep.js +3 -740
- package/dist/bundle/internal.d.ts +2 -2
- package/dist/bundle/sign-context-helpers.d.ts +1 -26
- package/dist/bundle/sign-context-helpers.js +1 -63
- package/dist/bundle/submit/blockrazor.d.ts +94 -0
- package/dist/bundle/submit/blockrazor.js +122 -0
- package/dist/bundle/submit/direct.d.ts +118 -0
- package/dist/bundle/submit/direct.js +484 -0
- package/dist/bundle/submit/helpers.d.ts +7 -0
- package/dist/bundle/submit/helpers.js +15 -0
- package/dist/bundle/submit/index.d.ts +14 -0
- package/dist/bundle/submit/index.js +14 -0
- package/dist/bundle/submit/merkle.d.ts +84 -0
- package/dist/bundle/submit/merkle.js +121 -0
- package/dist/bundle/submit.d.ts +3 -286
- package/dist/bundle/submit.js +3 -724
- package/dist/chains/bsc/four/types.d.ts +1 -1
- package/dist/chains/bsc/pancake/bundle-buy-first-build.d.ts +25 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-build.js +177 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-constants.d.ts +30 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-constants.js +24 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-helpers.d.ts +11 -149
- package/dist/chains/bsc/pancake/bundle-buy-first-helpers.js +12 -74
- package/dist/chains/bsc/pancake/bundle-buy-first-multi-wallet.d.ts +9 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-multi-wallet.js +225 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-plan.d.ts +14 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-plan.js +64 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-profit.d.ts +12 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-profit.js +22 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-quote.d.ts +15 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-quote.js +122 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-types.d.ts +179 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-types.js +1 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-validate.d.ts +2 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-validate.js +41 -0
- package/dist/chains/bsc/pancake/bundle-buy-first.d.ts +1 -1
- package/dist/chains/bsc/pancake/bundle-buy-first.js +8 -578
- package/dist/chains/bsc/pancake/bundle-swap-helpers.d.ts +11 -239
- package/dist/chains/bsc/pancake/bundle-swap-helpers.js +12 -564
- package/dist/chains/bsc/pancake/bundle-swap-types.d.ts +183 -0
- package/dist/chains/bsc/pancake/bundle-swap-types.js +17 -0
- package/dist/chains/bsc/pancake/bundle-swap.d.ts +10 -132
- package/dist/chains/bsc/pancake/bundle-swap.js +12 -1003
- package/dist/chains/bsc/pancake/hop-chain.d.ts +18 -0
- package/dist/chains/bsc/pancake/hop-chain.js +227 -0
- package/dist/chains/bsc/pancake/quote.d.ts +14 -0
- package/dist/chains/bsc/pancake/quote.js +84 -0
- package/dist/chains/bsc/pancake/swap-batch.d.ts +42 -0
- package/dist/chains/bsc/pancake/swap-batch.js +283 -0
- package/dist/chains/bsc/pancake/swap-build.d.ts +19 -0
- package/dist/chains/bsc/pancake/swap-build.js +226 -0
- package/dist/chains/bsc/pancake/swap-cross.d.ts +42 -0
- package/dist/chains/bsc/pancake/swap-cross.js +140 -0
- package/dist/chains/bsc/pancake/swap-quick.d.ts +54 -0
- package/dist/chains/bsc/pancake/swap-quick.js +424 -0
- package/dist/chains/bsc/pancake/swap-single.d.ts +2 -0
- package/dist/chains/bsc/pancake/swap-single.js +182 -0
- package/dist/chains/bsc/platforms/four/index.d.ts +21 -3
- package/dist/chains/bsc/platforms/four/index.js +28 -3
- package/dist/chains/eni/batch-router/transfer-disperse.d.ts +37 -0
- package/dist/chains/eni/batch-router/transfer-disperse.js +302 -0
- package/dist/chains/eni/batch-router/transfer-shared.d.ts +9 -0
- package/dist/chains/eni/batch-router/transfer-shared.js +10 -0
- package/dist/chains/eni/batch-router/transfer-sweep.d.ts +51 -0
- package/dist/chains/eni/batch-router/transfer-sweep.js +364 -0
- package/dist/chains/eni/batch-router/transfer.d.ts +4 -74
- package/dist/chains/eni/batch-router/transfer.js +2 -647
- package/dist/chains/eni/platforms/daoaas/portal-direct-profit.d.ts +17 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct-profit.js +30 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct-submit.d.ts +12 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct-submit.js +396 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct-tx.d.ts +20 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct-tx.js +165 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct.d.ts +3 -32
- package/dist/chains/eni/platforms/daoaas/portal-direct.js +3 -571
- package/dist/chains/eni/submit.js +1 -1
- package/dist/chains/xlayer/constants.d.ts +0 -2
- package/dist/chains/xlayer/constants.js +0 -2
- package/dist/chains/xlayer/eip7702/auth.d.ts +16 -0
- package/dist/chains/xlayer/eip7702/auth.js +81 -0
- package/dist/chains/xlayer/eip7702/bundle-create-buy.d.ts +22 -0
- package/dist/chains/xlayer/eip7702/bundle-create-buy.js +201 -0
- package/dist/chains/xlayer/eip7702/bundle-create-helpers.d.ts +114 -0
- package/dist/chains/xlayer/eip7702/bundle-create-helpers.js +139 -0
- package/dist/chains/xlayer/eip7702/bundle-create-to-dex.d.ts +24 -0
- package/dist/chains/xlayer/eip7702/bundle-create-to-dex.js +233 -0
- package/dist/chains/xlayer/eip7702/bundle-create.d.ts +3 -35
- package/dist/chains/xlayer/eip7702/bundle-create.js +3 -746
- package/dist/chains/xlayer/eip7702/bundle-graduate-buy.d.ts +22 -0
- package/dist/chains/xlayer/eip7702/bundle-graduate-buy.js +214 -0
- package/dist/chains/xlayer/eip7702/bundle-sell.js +1 -1
- package/dist/chains/xlayer/eip7702/bundle-swap-batch.d.ts +31 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-batch.js +216 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-helpers.d.ts +21 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-helpers.js +206 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-multi.d.ts +33 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-multi.js +146 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-single.d.ts +31 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-single.js +177 -0
- package/dist/chains/xlayer/eip7702/bundle-swap.d.ts +6 -61
- package/dist/chains/xlayer/eip7702/bundle-swap.js +3 -712
- package/dist/chains/xlayer/eip7702/bytes.d.ts +4 -0
- package/dist/chains/xlayer/eip7702/bytes.js +31 -0
- package/dist/chains/xlayer/eip7702/gas.d.ts +19 -0
- package/dist/chains/xlayer/eip7702/gas.js +152 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-disperse.d.ts +5 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-disperse.js +196 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-pairwise.d.ts +5 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-pairwise.js +188 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-sweep.d.ts +5 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-sweep.js +220 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer.d.ts +8 -4
- package/dist/chains/xlayer/eip7702/multi-hop-transfer.js +5 -591
- package/dist/chains/xlayer/eip7702/profit.d.ts +32 -0
- package/dist/chains/xlayer/eip7702/profit.js +59 -0
- package/dist/chains/xlayer/eip7702/provider.d.ts +3 -0
- package/dist/chains/xlayer/eip7702/provider.js +17 -0
- package/dist/chains/xlayer/eip7702/time.d.ts +2 -0
- package/dist/chains/xlayer/eip7702/time.js +10 -0
- package/dist/chains/xlayer/eip7702/tx-build.d.ts +10 -0
- package/dist/chains/xlayer/eip7702/tx-build.js +128 -0
- package/dist/chains/xlayer/eip7702/utils.d.ts +19 -85
- package/dist/chains/xlayer/eip7702/utils.js +19 -484
- package/dist/chains/xlayer/eip7702/volume-bundle.d.ts +13 -0
- package/dist/chains/xlayer/eip7702/volume-bundle.js +250 -0
- package/dist/chains/xlayer/eip7702/volume-internal.d.ts +13 -0
- package/dist/chains/xlayer/eip7702/volume-internal.js +169 -0
- package/dist/chains/xlayer/eip7702/volume-make.d.ts +8 -0
- package/dist/chains/xlayer/eip7702/volume-make.js +38 -0
- package/dist/chains/xlayer/eip7702/volume-single-round.d.ts +17 -0
- package/dist/chains/xlayer/eip7702/volume-single-round.js +44 -0
- package/dist/chains/xlayer/eip7702/volume-swap.d.ts +18 -0
- package/dist/chains/xlayer/eip7702/volume-swap.js +30 -0
- package/dist/chains/xlayer/eip7702/volume-wash.d.ts +8 -0
- package/dist/chains/xlayer/eip7702/volume-wash.js +191 -0
- package/dist/chains/xlayer/eip7702/volume.d.ts +7 -35
- package/dist/chains/xlayer/eip7702/volume.js +5 -697
- package/dist/chains/xlayer/eip7702/wallet.d.ts +6 -0
- package/dist/chains/xlayer/eip7702/wallet.js +17 -0
- package/dist/chains/xlayer/eoa/aa-types.d.ts +176 -0
- package/dist/chains/xlayer/eoa/aa-types.js +6 -0
- package/dist/chains/xlayer/eoa/constants.d.ts +0 -2
- package/dist/chains/xlayer/eoa/constants.js +0 -2
- package/dist/chains/xlayer/eoa/context.d.ts +8 -0
- package/dist/chains/xlayer/eoa/context.js +23 -0
- package/dist/chains/xlayer/eoa/encoders.d.ts +147 -0
- package/dist/chains/xlayer/eoa/encoders.js +147 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-cross.d.ts +5 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-cross.js +113 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.d.ts +10 -123
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.js +10 -225
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-pure.d.ts +50 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-pure.js +170 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-quick.d.ts +5 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-quick.js +257 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-types.d.ts +99 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-types.js +11 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap.d.ts +5 -47
- package/dist/chains/xlayer/eoa/eoa-bundle-swap.js +3 -522
- package/dist/chains/xlayer/eoa/eoa-types.d.ts +776 -0
- package/dist/chains/xlayer/eoa/eoa-types.js +6 -0
- package/dist/chains/xlayer/eoa/eoa-wash-volume.d.ts +8 -0
- package/dist/chains/xlayer/eoa/eoa-wash-volume.js +8 -0
- package/dist/chains/xlayer/eoa/format.d.ts +34 -0
- package/dist/chains/xlayer/eoa/format.js +56 -0
- package/dist/chains/xlayer/eoa/hop-chain.d.ts +4 -0
- package/dist/chains/xlayer/eoa/hop-chain.js +87 -0
- package/dist/chains/xlayer/eoa/nonce-map.d.ts +20 -0
- package/dist/chains/xlayer/eoa/nonce-map.js +51 -0
- package/dist/chains/xlayer/eoa/portal-ops.d.ts +9 -292
- package/dist/chains/xlayer/eoa/portal-ops.js +9 -486
- package/dist/chains/xlayer/eoa/query.d.ts +117 -0
- package/dist/chains/xlayer/eoa/query.js +285 -0
- package/dist/chains/xlayer/eoa/quote.d.ts +6 -0
- package/dist/chains/xlayer/eoa/quote.js +90 -0
- package/dist/chains/xlayer/eoa/types.d.ts +9 -959
- package/dist/chains/xlayer/eoa/types.js +9 -49
- package/dist/core/clients/blockrazor.js +1 -1
- package/dist/core/clients/merkle.js +1 -1
- package/dist/core/erc20/allowances.d.ts +104 -0
- package/dist/core/erc20/allowances.js +205 -0
- package/dist/core/erc20/approve.d.ts +141 -0
- package/dist/core/erc20/approve.js +325 -0
- package/dist/core/erc20/helpers.d.ts +20 -0
- package/dist/core/erc20/helpers.js +109 -0
- package/dist/core/erc20/index.d.ts +13 -0
- package/dist/core/erc20/index.js +12 -0
- package/dist/core/gas/bundle-gas.d.ts +6 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/quote/index.d.ts +1 -0
- package/dist/core/quote/index.js +1 -0
- package/dist/core/quote/quote-helpers.d.ts +78 -0
- package/dist/core/quote/quote-helpers.js +289 -0
- package/dist/core/quote/types.d.ts +1 -0
- package/dist/core/quote/types.js +1 -0
- package/dist/core/sign-context-helpers.d.ts +29 -0
- package/dist/core/sign-context-helpers.js +63 -0
- package/dist/domains/dex/direct-router-helpers.d.ts +16 -268
- package/dist/domains/dex/direct-router-helpers.js +16 -535
- package/dist/domains/dex/direct-router-types.d.ts +104 -0
- package/dist/domains/dex/direct-router-types.js +81 -0
- package/dist/domains/dex/direct-router-v2-buy.d.ts +2 -0
- package/dist/domains/dex/direct-router-v2-buy.js +249 -0
- package/dist/domains/dex/direct-router-v2-sell.d.ts +5 -0
- package/dist/domains/dex/direct-router-v2-sell.js +270 -0
- package/dist/domains/dex/direct-router-v2.d.ts +9 -0
- package/dist/domains/dex/direct-router-v2.js +9 -0
- package/dist/domains/dex/direct-router-v3.d.ts +17 -0
- package/dist/domains/dex/direct-router-v3.js +432 -0
- package/dist/domains/dex/direct-router.d.ts +11 -26
- package/dist/domains/dex/direct-router.js +10 -977
- package/dist/domains/dex/dyo-encode.d.ts +62 -0
- package/dist/domains/dex/dyo-encode.js +124 -0
- package/dist/domains/dex/profit.d.ts +24 -0
- package/dist/domains/dex/profit.js +86 -0
- package/dist/domains/dex/provider.d.ts +10 -0
- package/dist/domains/dex/provider.js +27 -0
- package/dist/domains/dex/quote.d.ts +7 -0
- package/dist/domains/dex/quote.js +52 -0
- package/dist/domains/dex/router.d.ts +56 -0
- package/dist/domains/dex/router.js +193 -0
- package/dist/domains/flap/portal-bundle/batch.d.ts +9 -0
- package/dist/domains/flap/portal-bundle/batch.js +193 -0
- package/dist/domains/flap/portal-bundle/create.d.ts +5 -0
- package/dist/domains/flap/portal-bundle/create.js +153 -0
- package/dist/domains/flap/portal-bundle/helpers.d.ts +32 -0
- package/dist/domains/flap/portal-bundle/helpers.js +50 -0
- package/dist/domains/flap/portal-bundle/index.d.ts +16 -0
- package/dist/domains/flap/portal-bundle/index.js +15 -0
- package/dist/domains/flap/portal-bundle/private.d.ts +5 -0
- package/dist/domains/flap/portal-bundle/private.js +198 -0
- package/dist/domains/flap/portal-bundle/types.d.ts +102 -0
- package/dist/domains/flap/portal-bundle/types.js +1 -0
- package/dist/domains/flap/portal-bundle-merkle/core-batch.d.ts +13 -0
- package/dist/domains/flap/portal-bundle-merkle/core-batch.js +376 -0
- package/dist/domains/flap/portal-bundle-merkle/core-helpers.d.ts +75 -7
- package/dist/domains/flap/portal-bundle-merkle/core-helpers.js +259 -20
- package/dist/domains/flap/portal-bundle-merkle/core.d.ts +2 -13
- package/dist/domains/flap/portal-bundle-merkle/core.js +12 -629
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/constants.d.ts +70 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/constants.js +90 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/index.d.ts +12 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/index.js +11 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/main.d.ts +15 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/main.js +432 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/types.d.ts +113 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/types.js +4 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex.d.ts +4 -127
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex.js +4 -527
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/constants.d.ts +42 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/constants.js +81 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/index.d.ts +12 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/index.js +11 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/main.d.ts +15 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/main.js +339 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/types.d.ts +72 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/types.js +4 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex.d.ts +4 -85
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex.js +4 -425
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/approve.d.ts +12 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/approve.js +102 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/buy.d.ts +5 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/buy.js +135 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/helpers.d.ts +52 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/helpers.js +267 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/index.d.ts +14 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/index.js +14 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/sell.d.ts +5 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/sell.js +195 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy.d.ts +3 -24
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy.js +3 -700
- package/dist/domains/flap/portal-bundle-merkle/private/buy.d.ts +9 -0
- package/dist/domains/flap/portal-bundle-merkle/private/buy.js +188 -0
- package/dist/domains/flap/portal-bundle-merkle/private/helpers.d.ts +36 -0
- package/dist/domains/flap/portal-bundle-merkle/private/helpers.js +127 -0
- package/dist/domains/flap/portal-bundle-merkle/private/index.d.ts +12 -0
- package/dist/domains/flap/portal-bundle-merkle/private/index.js +12 -0
- package/dist/domains/flap/portal-bundle-merkle/private/sell.d.ts +9 -0
- package/dist/domains/flap/portal-bundle-merkle/private/sell.js +191 -0
- package/dist/domains/flap/portal-bundle-merkle/private.d.ts +5 -15
- package/dist/domains/flap/portal-bundle-merkle/private.js +5 -494
- package/dist/domains/flap/portal-bundle-merkle/swap-batch.js +3 -2
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-chain.d.ts +4 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-chain.js +43 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-constants.d.ts +13 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-constants.js +21 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-helpers.d.ts +11 -121
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-helpers.js +11 -109
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-multi-wallet.d.ts +20 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-multi-wallet.js +223 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-plan.d.ts +32 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-plan.js +66 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-profit.d.ts +22 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-profit.js +22 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-quote.d.ts +51 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-quote.js +149 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-types.d.ts +87 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-types.js +1 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first.js +5 -404
- package/dist/domains/flap/portal-bundle-merkle/swap-helpers.d.ts +0 -1
- package/dist/domains/flap/portal-bundle-merkle/swap-helpers.js +0 -7
- package/dist/domains/flap/portal-bundle-merkle/swap-planning.js +1 -1
- package/dist/domains/flap/portal-bundle-merkle/swap-quick-batch.js +3 -2
- package/dist/domains/flap/portal-bundle-merkle/swap-single.js +3 -2
- package/dist/domains/flap/portal-bundle-merkle/utils/disperse.d.ts +2 -0
- package/dist/domains/flap/portal-bundle-merkle/utils/disperse.js +275 -0
- package/dist/domains/flap/portal-bundle-merkle/utils/index.d.ts +11 -0
- package/dist/domains/flap/portal-bundle-merkle/utils/index.js +11 -0
- package/dist/domains/flap/portal-bundle-merkle/utils/sweep.d.ts +9 -0
- package/dist/domains/flap/portal-bundle-merkle/utils/sweep.js +570 -0
- package/dist/domains/flap/portal-bundle-merkle/utils.d.ts +5 -8
- package/dist/domains/flap/portal-bundle-merkle/utils.js +5 -841
- package/dist/domains/flap/portal-bundle.d.ts +5 -117
- package/dist/domains/flap/portal-bundle.js +5 -587
- package/dist/domains/flap/portal.d.ts +13 -404
- package/dist/domains/flap/portal.js +12 -619
- package/dist/domains/flap/reader.d.ts +51 -0
- package/dist/domains/flap/reader.js +275 -0
- package/dist/domains/flap/types.d.ts +246 -0
- package/dist/domains/flap/types.js +104 -0
- package/dist/domains/flap/vault/constants.d.ts +220 -0
- package/dist/domains/flap/vault/constants.js +173 -0
- package/dist/domains/flap/vault/encode.d.ts +39 -0
- package/dist/domains/flap/vault/encode.js +135 -0
- package/dist/domains/flap/vault/index.d.ts +15 -0
- package/dist/domains/flap/vault/index.js +14 -0
- package/dist/domains/flap/vault/query.d.ts +40 -0
- package/dist/domains/flap/vault/query.js +104 -0
- package/dist/domains/flap/vault/types.d.ts +147 -0
- package/dist/domains/flap/vault/types.js +29 -0
- package/dist/domains/flap/vault.d.ts +3 -413
- package/dist/domains/flap/vault.js +3 -467
- package/dist/domains/flap/writer.d.ts +124 -0
- package/dist/domains/flap/writer.js +255 -0
- package/dist/domains/four/contracts/tm-bundle-batch.d.ts +35 -0
- package/dist/domains/four/contracts/tm-bundle-batch.js +286 -0
- package/dist/domains/four/contracts/tm-bundle-create.d.ts +2 -0
- package/dist/domains/four/contracts/tm-bundle-create.js +304 -0
- package/dist/domains/four/contracts/tm-bundle-helpers.d.ts +2 -1
- package/dist/domains/four/contracts/tm-bundle-helpers.js +3 -0
- package/dist/domains/four/contracts/tm-bundle-private.d.ts +36 -0
- package/dist/domains/four/contracts/tm-bundle-private.js +164 -0
- package/dist/domains/four/contracts/tm-bundle.d.ts +10 -71
- package/dist/domains/four/contracts/tm-bundle.js +9 -738
- package/dist/domains/lp-inspect/inspect-helpers.d.ts +25 -0
- package/dist/domains/lp-inspect/inspect-helpers.js +343 -0
- package/dist/domains/lp-inspect/inspect.d.ts +8 -0
- package/dist/domains/lp-inspect/inspect.js +332 -0
- package/dist/domains/lp-inspect/lp-inspect.d.ts +9 -37
- package/dist/domains/lp-inspect/lp-inspect.js +9 -775
- package/dist/domains/lp-inspect/registry.d.ts +43 -0
- package/dist/domains/lp-inspect/registry.js +127 -0
- package/dist/domains/merkle/index.d.ts +1 -1
- package/dist/exports/root-bundle-and-tooling.d.ts +9 -1
- package/dist/exports/root-bundle-and-tooling.js +8 -1
- package/dist/exports/root-foundations.d.ts +1 -1
- package/dist/exports/root-foundations.js +1 -1
- package/dist/exports/root-swap-dex-and-xlayer.d.ts +4 -4
- package/dist/exports/root-swap-dex-and-xlayer.js +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/utils/swap-helpers.js +1 -1
- package/package.json +1 -85
|
@@ -1,777 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* lp-inspect
|
|
2
|
+
* lp-inspect barrel
|
|
3
|
+
*
|
|
4
|
+
* 原超长文件按职责拆分为:
|
|
5
|
+
* - registry.ts:DEX/稳定币注册表、链配置、报价代币列表
|
|
6
|
+
* - inspect.ts:inspectTokenLP 主查询流程 + V2/V3 批量查询
|
|
7
|
+
*
|
|
8
|
+
* 对外 export 符号与路径保持不变。
|
|
3
9
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { ADDRESSES, ZERO_ADDRESS } from '../../core/constants/index.js';
|
|
7
|
-
import { getErrorMessageFromUnknown } from '../../core/index.js';
|
|
8
|
-
import { MULTICALL3_ABI, V2_FACTORY_ABI, V2_PAIR_ABI, V3_FACTORY_ABI, ERC20_ABI } from '../../abis/common.js';
|
|
9
|
-
import { Helper3 } from '../four/contracts/helper3.js';
|
|
10
|
-
import { FlapPortal } from '../flap/portal.js';
|
|
11
|
-
import { CHAIN_DEX_CONFIGS, DEFAULT_V3_FEE_TIERS, runtimeConfigs } from './lp-inspect-helpers.js';
|
|
12
|
-
export async function getFactoryFromRouter(routerAddress, rpcUrl, routerType = 'v2') {
|
|
13
|
-
const provider = createProvider(rpcUrl);
|
|
14
|
-
const result = {};
|
|
15
|
-
// V2 Router ABI: factory()
|
|
16
|
-
const V2_ROUTER_ABI = ['function factory() view returns (address)'];
|
|
17
|
-
// V3 SwapRouter02 ABI: factory() 和 factoryV2()
|
|
18
|
-
const V3_ROUTER_ABI = ['function factory() view returns (address)', 'function factoryV2() view returns (address)'];
|
|
19
|
-
try {
|
|
20
|
-
if (routerType === 'v2') {
|
|
21
|
-
const router = new Contract(routerAddress, V2_ROUTER_ABI, provider);
|
|
22
|
-
result.v2Factory = await router.factory();
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
// V3 SwapRouter02 可能同时有 V2 和 V3 Factory
|
|
26
|
-
const router = new Contract(routerAddress, V3_ROUTER_ABI, provider);
|
|
27
|
-
// ✅ 并行获取 V3 和 V2 Factory
|
|
28
|
-
const [v3Factory, v2Factory] = await Promise.all([
|
|
29
|
-
router.factory().catch(() => undefined),
|
|
30
|
-
router.factoryV2().catch(() => undefined),
|
|
31
|
-
]);
|
|
32
|
-
if (v3Factory)
|
|
33
|
-
result.v3Factory = v3Factory;
|
|
34
|
-
if (v2Factory)
|
|
35
|
-
result.v2Factory = v2Factory;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
console.error(`❌ 获取 Factory 地址失败:`, getErrorMessageFromUnknown(error));
|
|
40
|
-
}
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* 动态注册 DYORSwap(从 Router 获取 Factory)
|
|
45
|
-
*/
|
|
46
|
-
export async function registerDYORSwap(rpcUrl) {
|
|
47
|
-
const DYORSWAP_ROUTER = ADDRESSES.XLAYER.DyorSwapRouter;
|
|
48
|
-
try {
|
|
49
|
-
// 从 Router 获取 Factory 地址
|
|
50
|
-
const factories = await getFactoryFromRouter(DYORSWAP_ROUTER, rpcUrl, 'v3');
|
|
51
|
-
if (factories.v2Factory || factories.v3Factory) {
|
|
52
|
-
const chainConfig = getChainConfig('XLAYER');
|
|
53
|
-
if (chainConfig && chainConfig.dexes.DYORSWAP) {
|
|
54
|
-
if (factories.v2Factory) {
|
|
55
|
-
chainConfig.dexes.DYORSWAP.v2Factory = factories.v2Factory;
|
|
56
|
-
}
|
|
57
|
-
if (factories.v3Factory) {
|
|
58
|
-
chainConfig.dexes.DYORSWAP.v3Factory = factories.v3Factory;
|
|
59
|
-
}
|
|
60
|
-
chainConfig.dexes.DYORSWAP.enabled = true;
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
console.error('❌ 注册 DYORSwap 失败:', getErrorMessageFromUnknown(error));
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/** 注册新的 DEX */
|
|
72
|
-
export function registerDex(chain, dexKey, config) {
|
|
73
|
-
const chainConfig = getChainConfig(chain);
|
|
74
|
-
if (chainConfig) {
|
|
75
|
-
chainConfig.dexes[dexKey] = config;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
/** 注册新的稳定币 */
|
|
79
|
-
export function registerStableCoin(chain, coin) {
|
|
80
|
-
const chainConfig = getChainConfig(chain);
|
|
81
|
-
if (chainConfig) {
|
|
82
|
-
// 检查是否已存在
|
|
83
|
-
const exists = chainConfig.stableCoins.some((c) => c.address.toLowerCase() === coin.address.toLowerCase());
|
|
84
|
-
if (!exists) {
|
|
85
|
-
chainConfig.stableCoins.push(coin);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
/** 获取链配置(优先运行时配置) */
|
|
90
|
-
export function getChainConfig(chain) {
|
|
91
|
-
if (runtimeConfigs[chain]) {
|
|
92
|
-
return runtimeConfigs[chain];
|
|
93
|
-
}
|
|
94
|
-
if (CHAIN_DEX_CONFIGS[chain]) {
|
|
95
|
-
// 深拷贝到运行时配置
|
|
96
|
-
runtimeConfigs[chain] = JSON.parse(JSON.stringify(CHAIN_DEX_CONFIGS[chain]));
|
|
97
|
-
return runtimeConfigs[chain];
|
|
98
|
-
}
|
|
99
|
-
return undefined;
|
|
100
|
-
}
|
|
101
|
-
/** 获取支持的 DEX 列表 */
|
|
102
|
-
export function getSupportedDexes(chain) {
|
|
103
|
-
const config = getChainConfig(chain);
|
|
104
|
-
if (!config)
|
|
105
|
-
return [];
|
|
106
|
-
return Object.entries(config.dexes).map(([key, dex]) => ({
|
|
107
|
-
key,
|
|
108
|
-
name: dex.name,
|
|
109
|
-
enabled: dex.enabled,
|
|
110
|
-
}));
|
|
111
|
-
}
|
|
112
|
-
/** 获取支持的稳定币列表 */
|
|
113
|
-
export function getSupportedStableCoins(chain) {
|
|
114
|
-
const config = getChainConfig(chain);
|
|
115
|
-
if (!config)
|
|
116
|
-
return [];
|
|
117
|
-
return config.stableCoins;
|
|
118
|
-
}
|
|
119
|
-
/** 获取所有报价代币(包装原生 + 稳定币) */
|
|
120
|
-
export function getQuoteTokens(chain) {
|
|
121
|
-
const config = getChainConfig(chain);
|
|
122
|
-
if (!config)
|
|
123
|
-
return [];
|
|
124
|
-
return [
|
|
125
|
-
{ address: config.wrappedNative, symbol: config.wrappedNativeSymbol, decimals: 18, isNative: true },
|
|
126
|
-
...config.stableCoins.map((c) => ({ ...c, isNative: false })),
|
|
127
|
-
];
|
|
128
|
-
}
|
|
129
|
-
// ============================================================================
|
|
130
|
-
// ABI 别名(从公共模块导入)
|
|
131
|
-
// ============================================================================
|
|
132
|
-
const I_UNIV2_FACTORY_ABI = V2_FACTORY_ABI;
|
|
133
|
-
const I_UNIV2_PAIR_ABI = V2_PAIR_ABI;
|
|
134
|
-
const I_ERC20_ABI = ERC20_ABI;
|
|
135
|
-
const I_UNIV3_FACTORY_ABI = V3_FACTORY_ABI;
|
|
136
|
-
// ============================================================================
|
|
137
|
-
// 常量(从公共模块导入)
|
|
138
|
-
// ============================================================================
|
|
139
|
-
const MULTICALL3_ADDRESS = ADDRESSES.BSC.Multicall3;
|
|
140
|
-
/** Provider 缓存 */
|
|
141
|
-
const providerCache = new Map();
|
|
142
|
-
function getProvider(rpcUrl) {
|
|
143
|
-
if (!providerCache.has(rpcUrl)) {
|
|
144
|
-
providerCache.set(rpcUrl, createProvider(rpcUrl));
|
|
145
|
-
}
|
|
146
|
-
return providerCache.get(rpcUrl);
|
|
147
|
-
}
|
|
148
|
-
/** 精度缓存 */
|
|
149
|
-
const decimalsCache = new Map();
|
|
150
|
-
async function getTokenDecimals(tokenAddress, provider) {
|
|
151
|
-
const key = tokenAddress.toLowerCase();
|
|
152
|
-
if (decimalsCache.has(key)) {
|
|
153
|
-
return decimalsCache.get(key);
|
|
154
|
-
}
|
|
155
|
-
try {
|
|
156
|
-
const contract = new Contract(tokenAddress, I_ERC20_ABI, provider);
|
|
157
|
-
const decimals = await contract.decimals();
|
|
158
|
-
const result = Number(decimals);
|
|
159
|
-
decimalsCache.set(key, result);
|
|
160
|
-
return result;
|
|
161
|
-
}
|
|
162
|
-
catch {
|
|
163
|
-
return 18;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
/** 格式化余额 */
|
|
167
|
-
function formatBalance(balance, format, decimals = 18) {
|
|
168
|
-
return format ? formatUnits(balance, decimals) : balance.toString();
|
|
169
|
-
}
|
|
170
|
-
/** 标准化流动性值(转换为统一精度用于比较) */
|
|
171
|
-
function normalizeLiquidity(amount, decimals) {
|
|
172
|
-
// 将所有值标准化到 18 位精度进行比较
|
|
173
|
-
if (decimals < 18) {
|
|
174
|
-
return amount * BigInt(10 ** (18 - decimals));
|
|
175
|
-
}
|
|
176
|
-
else if (decimals > 18) {
|
|
177
|
-
return amount / BigInt(10 ** (decimals - 18));
|
|
178
|
-
}
|
|
179
|
-
return amount;
|
|
180
|
-
}
|
|
181
|
-
// ============================================================================
|
|
182
|
-
// 主查询函数
|
|
183
|
-
// ============================================================================
|
|
184
|
-
export async function inspectTokenLP(token, opts) {
|
|
185
|
-
const provider = getProvider(opts.rpcUrl);
|
|
186
|
-
const shouldFormat = opts.formatBalances !== false;
|
|
187
|
-
const multicall3 = opts.multicall3 || MULTICALL3_ADDRESS;
|
|
188
|
-
const v3FeeTiers = opts.v3FeeTiers || DEFAULT_V3_FEE_TIERS;
|
|
189
|
-
// 初始化返回结构
|
|
190
|
-
const result = {
|
|
191
|
-
platform: 'UNKNOWN',
|
|
192
|
-
allPools: [],
|
|
193
|
-
bestPools: [],
|
|
194
|
-
};
|
|
195
|
-
// 获取链配置
|
|
196
|
-
let chainConfig = getChainConfig(opts.chain);
|
|
197
|
-
if (!chainConfig) {
|
|
198
|
-
return result;
|
|
199
|
-
}
|
|
200
|
-
// 应用自定义配置
|
|
201
|
-
if (opts.customDexConfig) {
|
|
202
|
-
chainConfig = { ...chainConfig, ...opts.customDexConfig };
|
|
203
|
-
}
|
|
204
|
-
// 查询代币精度和总供应量
|
|
205
|
-
let tokenDecimals;
|
|
206
|
-
let totalSupplyRaw;
|
|
207
|
-
try {
|
|
208
|
-
const tokenContract = new Contract(token, ['function decimals() view returns (uint8)', 'function totalSupply() view returns (uint256)'], provider);
|
|
209
|
-
const [decimals, supply] = await Promise.all([
|
|
210
|
-
tokenContract.decimals().catch(() => 18),
|
|
211
|
-
tokenContract.totalSupply().catch(() => undefined),
|
|
212
|
-
]);
|
|
213
|
-
tokenDecimals = Number(decimals);
|
|
214
|
-
totalSupplyRaw = supply ? BigInt(supply) : undefined;
|
|
215
|
-
result.decimals = tokenDecimals;
|
|
216
|
-
if (totalSupplyRaw !== undefined) {
|
|
217
|
-
result.totalSupplyRaw = totalSupplyRaw;
|
|
218
|
-
result.totalSupply = formatBalance(totalSupplyRaw, shouldFormat, tokenDecimals);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
catch {
|
|
222
|
-
tokenDecimals = 18;
|
|
223
|
-
}
|
|
224
|
-
// ========================================
|
|
225
|
-
// 1. 内盘检测:Flap
|
|
226
|
-
// ========================================
|
|
227
|
-
if (opts.flapChain) {
|
|
228
|
-
try {
|
|
229
|
-
const flap = new FlapPortal({ chain: opts.flapChain, rpcUrl: opts.rpcUrl });
|
|
230
|
-
// ✅ 优先尝试 getTokenV7(包含 taxRate),失败则 fallback 到 getTokenV5
|
|
231
|
-
let st = null;
|
|
232
|
-
let taxRate;
|
|
233
|
-
try {
|
|
234
|
-
const stV7 = await flap.getTokenV7(token);
|
|
235
|
-
st = stV7;
|
|
236
|
-
taxRate = Number(stV7.taxRate ?? 0n);
|
|
237
|
-
}
|
|
238
|
-
catch {
|
|
239
|
-
st = await flap.getTokenV5(token);
|
|
240
|
-
}
|
|
241
|
-
if (st && st.status !== undefined && Number(st.status) !== 4) {
|
|
242
|
-
result.platform = 'FLAP';
|
|
243
|
-
let quoteDecimals = 18;
|
|
244
|
-
let quoteSymbol = chainConfig.wrappedNativeSymbol;
|
|
245
|
-
const quoteTokenAddress = st.quoteTokenAddress;
|
|
246
|
-
if (quoteTokenAddress && quoteTokenAddress.toLowerCase() !== ZERO_ADDRESS) {
|
|
247
|
-
quoteDecimals = await getTokenDecimals(quoteTokenAddress, provider);
|
|
248
|
-
const stableCoin = chainConfig.stableCoins.find((c) => c.address.toLowerCase() === quoteTokenAddress.toLowerCase());
|
|
249
|
-
quoteSymbol = stableCoin?.symbol || 'TOKEN';
|
|
250
|
-
}
|
|
251
|
-
result.flap = {
|
|
252
|
-
quoteToken: quoteTokenAddress,
|
|
253
|
-
quoteSymbol,
|
|
254
|
-
quoteDecimals,
|
|
255
|
-
reserveNative: formatBalance(st.reserve, shouldFormat, quoteDecimals),
|
|
256
|
-
circulatingSupply: formatBalance(st.circulatingSupply, shouldFormat, tokenDecimals ?? 18),
|
|
257
|
-
price: formatBalance(st.price, shouldFormat),
|
|
258
|
-
taxRate, // ✅ 包含税率
|
|
259
|
-
};
|
|
260
|
-
// ✅ 同时设置顶层税率,方便统一读取
|
|
261
|
-
if (taxRate && taxRate > 0) {
|
|
262
|
-
result.taxRate = taxRate;
|
|
263
|
-
}
|
|
264
|
-
return result;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
catch {
|
|
268
|
-
// Flap 检测失败,继续其他平台检测
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
// ========================================
|
|
272
|
-
// 1b. 内盘检测:DAOaaS Portal(ENI 链)
|
|
273
|
-
// ========================================
|
|
274
|
-
if (opts.chain === 'ENI') {
|
|
275
|
-
try {
|
|
276
|
-
const portalAddress = ADDRESSES.ENI.DaoaasPortal;
|
|
277
|
-
const portalAbi = [
|
|
278
|
-
'function getTokenState(address token) view returns (uint256)',
|
|
279
|
-
'function getPrice(address token) view returns (uint256)',
|
|
280
|
-
'function getOKAmountBySale(address token, uint256 tokenAmount) view returns (uint256)',
|
|
281
|
-
];
|
|
282
|
-
const portal = new Contract(portalAddress, portalAbi, provider);
|
|
283
|
-
const status = Number(await portal.getTokenState(token));
|
|
284
|
-
// status: 0=不存在, 1=交易中(内盘), 2=已毕业(外盘)
|
|
285
|
-
if (status === 1) {
|
|
286
|
-
result.platform = 'DAOAAS';
|
|
287
|
-
const price = (await portal.getPrice(token));
|
|
288
|
-
const tokenContract = new Contract(token, ['function totalSupply() view returns (uint256)', 'function balanceOf(address) view returns (uint256)'], provider);
|
|
289
|
-
const [totalSupply, portalTokenBalance] = await Promise.all([
|
|
290
|
-
tokenContract.totalSupply(),
|
|
291
|
-
tokenContract.balanceOf(portalAddress),
|
|
292
|
-
]);
|
|
293
|
-
const circulatingSupply = totalSupply - portalTokenBalance;
|
|
294
|
-
let reserveNative = '0';
|
|
295
|
-
try {
|
|
296
|
-
if (circulatingSupply > 0n) {
|
|
297
|
-
const saleValue = (await portal.getOKAmountBySale(token, circulatingSupply));
|
|
298
|
-
reserveNative = formatBalance(saleValue, shouldFormat, 18);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
catch {
|
|
302
|
-
try {
|
|
303
|
-
const egasBalance = await provider.getBalance(portalAddress);
|
|
304
|
-
reserveNative = formatBalance(egasBalance, shouldFormat, 18);
|
|
305
|
-
}
|
|
306
|
-
catch {
|
|
307
|
-
/* ignore */
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
result.daoaas = {
|
|
311
|
-
quoteToken: ZERO_ADDRESS,
|
|
312
|
-
quoteSymbol: 'EGAS',
|
|
313
|
-
quoteDecimals: 18,
|
|
314
|
-
reserveNative,
|
|
315
|
-
circulatingSupply: formatBalance(circulatingSupply, shouldFormat, tokenDecimals ?? 18),
|
|
316
|
-
price: formatEther(price),
|
|
317
|
-
status,
|
|
318
|
-
};
|
|
319
|
-
return result;
|
|
320
|
-
}
|
|
321
|
-
// status === 2 (Graduated): 已毕业到 DSWAP V2,继续走外盘检测
|
|
322
|
-
}
|
|
323
|
-
catch {
|
|
324
|
-
// DAOaaS Portal 检测失败,继续其他平台检测
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
// ========================================
|
|
328
|
-
// 2. 内盘检测:Four.meme(仅 BSC)
|
|
329
|
-
// ========================================
|
|
330
|
-
if (opts.chain === 'BSC') {
|
|
331
|
-
try {
|
|
332
|
-
const helper = Helper3.connectByChain('BSC', opts.rpcUrl);
|
|
333
|
-
const info = await helper.getTokenInfo(token);
|
|
334
|
-
const tokenManager = info.tokenManager;
|
|
335
|
-
const versionNum = Number(info.version);
|
|
336
|
-
const liquidityAdded = info.liquidityAdded;
|
|
337
|
-
const isValid = tokenManager && tokenManager !== ZERO_ADDRESS && (versionNum === 1 || versionNum === 2);
|
|
338
|
-
if (isValid && !liquidityAdded) {
|
|
339
|
-
result.platform = 'FOUR';
|
|
340
|
-
const reserveNative = formatBalance(info.funds, shouldFormat);
|
|
341
|
-
const offerTokens = formatBalance(info.offers, shouldFormat);
|
|
342
|
-
const lastPrice = formatBalance(info.lastPrice, shouldFormat);
|
|
343
|
-
result.four = { helper: ADDRESSES.BSC.TokenManagerHelper3, reserveNative, offerTokens, lastPrice };
|
|
344
|
-
return result;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
catch {
|
|
348
|
-
// Four.meme 检测失败,继续外盘检测
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
// ========================================
|
|
352
|
-
// 3. 外盘检测:多 DEX 批量查询
|
|
353
|
-
// ========================================
|
|
354
|
-
const enabledDexes = Object.entries(chainConfig.dexes).filter(([_, dex]) => dex.enabled);
|
|
355
|
-
// 构建报价代币列表
|
|
356
|
-
const quoteTokens = [
|
|
357
|
-
{ address: chainConfig.wrappedNative, symbol: chainConfig.wrappedNativeSymbol, decimals: 18 },
|
|
358
|
-
...chainConfig.stableCoins,
|
|
359
|
-
];
|
|
360
|
-
// 所有最佳池子候选
|
|
361
|
-
const allBestPoolCandidates = [];
|
|
362
|
-
// 并行查询所有 DEX
|
|
363
|
-
const dexPromises = enabledDexes.map(async ([dexKey, dexConfig]) => {
|
|
364
|
-
const dexPoolInfo = {
|
|
365
|
-
dexName: dexConfig.name,
|
|
366
|
-
dexKey,
|
|
367
|
-
v2Pairs: [],
|
|
368
|
-
v3Pools: [],
|
|
369
|
-
};
|
|
370
|
-
// V2 查询
|
|
371
|
-
if (dexConfig.v2Factory) {
|
|
372
|
-
try {
|
|
373
|
-
const v2Pairs = await queryV2Pairs(token, dexConfig.v2Factory, quoteTokens, provider, multicall3, tokenDecimals ?? 18, shouldFormat);
|
|
374
|
-
dexPoolInfo.v2Pairs = v2Pairs;
|
|
375
|
-
// 添加到最佳池子候选
|
|
376
|
-
for (const pair of v2Pairs) {
|
|
377
|
-
if (pair.reserveQuoteRaw && pair.reserveQuoteRaw > 0n) {
|
|
378
|
-
allBestPoolCandidates.push({
|
|
379
|
-
dex: dexConfig.name,
|
|
380
|
-
dexKey,
|
|
381
|
-
version: 'v2',
|
|
382
|
-
quoteToken: pair.quoteToken,
|
|
383
|
-
quoteSymbol: pair.quoteSymbol,
|
|
384
|
-
quoteDecimals: pair.quoteDecimals,
|
|
385
|
-
pairAddress: pair.pairAddress,
|
|
386
|
-
liquidity: pair.reserveQuote,
|
|
387
|
-
liquidityRaw: normalizeLiquidity(pair.reserveQuoteRaw, pair.quoteDecimals),
|
|
388
|
-
reserveToken: pair.reserveToken, // ✅ 新增
|
|
389
|
-
reserveTokenRaw: pair.reserveTokenRaw, // ✅ 新增
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
catch {
|
|
395
|
-
// 单个 DEX V2 查询失败,继续其他 DEX
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
// V3 查询
|
|
399
|
-
if (dexConfig.v3Factory) {
|
|
400
|
-
try {
|
|
401
|
-
const v3Pools = await queryV3Pools(token, dexConfig.v3Factory, quoteTokens, v3FeeTiers, provider, multicall3, tokenDecimals ?? 18, shouldFormat);
|
|
402
|
-
dexPoolInfo.v3Pools = v3Pools;
|
|
403
|
-
// 添加到最佳池子候选
|
|
404
|
-
for (const pool of v3Pools) {
|
|
405
|
-
if (pool.reserveQuoteRaw && pool.reserveQuoteRaw > 0n) {
|
|
406
|
-
allBestPoolCandidates.push({
|
|
407
|
-
dex: dexConfig.name,
|
|
408
|
-
dexKey,
|
|
409
|
-
version: 'v3',
|
|
410
|
-
fee: pool.fee,
|
|
411
|
-
quoteToken: pool.quoteToken,
|
|
412
|
-
quoteSymbol: pool.quoteSymbol,
|
|
413
|
-
quoteDecimals: pool.quoteDecimals,
|
|
414
|
-
pairAddress: pool.pairAddress,
|
|
415
|
-
liquidity: pool.reserveQuote,
|
|
416
|
-
liquidityRaw: normalizeLiquidity(pool.reserveQuoteRaw, pool.quoteDecimals),
|
|
417
|
-
reserveToken: pool.reserveToken, // ✅ 新增
|
|
418
|
-
reserveTokenRaw: pool.reserveTokenRaw, // ✅ 新增
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
catch {
|
|
424
|
-
// 单个 DEX V3 查询失败,继续其他 DEX
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
return dexPoolInfo;
|
|
428
|
-
});
|
|
429
|
-
// 等待所有 DEX 查询完成
|
|
430
|
-
const dexResults = await Promise.all(dexPromises);
|
|
431
|
-
// 过滤出有流动性的 DEX
|
|
432
|
-
result.allPools = dexResults.filter((dex) => dex.v2Pairs.length > 0 || dex.v3Pools.length > 0);
|
|
433
|
-
// 按流动性排序最佳池子,并计算 poolRatio
|
|
434
|
-
result.bestPools = allBestPoolCandidates
|
|
435
|
-
.sort((a, b) => {
|
|
436
|
-
// 降序排列
|
|
437
|
-
if (b.liquidityRaw > a.liquidityRaw)
|
|
438
|
-
return 1;
|
|
439
|
-
if (b.liquidityRaw < a.liquidityRaw)
|
|
440
|
-
return -1;
|
|
441
|
-
return 0;
|
|
442
|
-
})
|
|
443
|
-
.slice(0, 10) // 最多返回 10 个
|
|
444
|
-
.map((pool) => {
|
|
445
|
-
// ✅ 计算池子代币占比
|
|
446
|
-
if (pool.reserveTokenRaw && totalSupplyRaw && totalSupplyRaw > 0n) {
|
|
447
|
-
// 计算百分比:(reserveTokenRaw / totalSupplyRaw) * 100
|
|
448
|
-
// 为了保持精度,先乘以 10000,再除以 totalSupply,得到万分比
|
|
449
|
-
const ratioBps = (pool.reserveTokenRaw * 10000n) / totalSupplyRaw;
|
|
450
|
-
const ratioPercent = Number(ratioBps) / 100; // 转为百分比
|
|
451
|
-
pool.poolRatio = `${ratioPercent.toFixed(2)}%`;
|
|
452
|
-
}
|
|
453
|
-
return pool;
|
|
454
|
-
});
|
|
455
|
-
// ✅ 同时为 allPools 中的每个池子计算 poolRatio
|
|
456
|
-
if (totalSupplyRaw && totalSupplyRaw > 0n) {
|
|
457
|
-
for (const dexPool of result.allPools) {
|
|
458
|
-
for (const pair of dexPool.v2Pairs) {
|
|
459
|
-
if (pair.reserveTokenRaw) {
|
|
460
|
-
const ratioBps = (pair.reserveTokenRaw * 10000n) / totalSupplyRaw;
|
|
461
|
-
const ratioPercent = Number(ratioBps) / 100;
|
|
462
|
-
pair.poolRatio = `${ratioPercent.toFixed(2)}%`;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
for (const pool of dexPool.v3Pools) {
|
|
466
|
-
if (pool.reserveTokenRaw) {
|
|
467
|
-
const ratioBps = (pool.reserveTokenRaw * 10000n) / totalSupplyRaw;
|
|
468
|
-
const ratioPercent = Number(ratioBps) / 100;
|
|
469
|
-
pool.poolRatio = `${ratioPercent.toFixed(2)}%`;
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
// 确定平台类型
|
|
475
|
-
result.platform = determinePlatform(result.allPools);
|
|
476
|
-
// ========================================
|
|
477
|
-
// 4. 外盘税率查询(仅 Flap 链)
|
|
478
|
-
// ========================================
|
|
479
|
-
// 对于已毕业到外盘的代币,尝试从 Flap Portal 获取税率
|
|
480
|
-
if (opts.flapChain && !result.flap && result.platform !== 'UNKNOWN') {
|
|
481
|
-
try {
|
|
482
|
-
const flap = new FlapPortal({ chain: opts.flapChain, rpcUrl: opts.rpcUrl });
|
|
483
|
-
const stV7 = await flap.getTokenV7(token);
|
|
484
|
-
// taxRate 是 bigint,需要转换为 number
|
|
485
|
-
const taxRate = Number(stV7.taxRate ?? 0n);
|
|
486
|
-
if (taxRate > 0) {
|
|
487
|
-
result.taxRate = taxRate;
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
catch {
|
|
491
|
-
// V7 不支持或代币不是 Flap 创建的,忽略
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
return result;
|
|
495
|
-
}
|
|
496
|
-
// ============================================================================
|
|
497
|
-
// V2 批量查询
|
|
498
|
-
// ============================================================================
|
|
499
|
-
async function queryV2Pairs(token, factoryAddress, quoteTokens, provider, multicall3, tokenDecimals, shouldFormat) {
|
|
500
|
-
const results = [];
|
|
501
|
-
const factoryIface = new Interface(I_UNIV2_FACTORY_ABI);
|
|
502
|
-
const pairIface = new Interface(I_UNIV2_PAIR_ABI);
|
|
503
|
-
const mcIface = new Interface(MULTICALL3_ABI);
|
|
504
|
-
// 第一步:批量查询所有 getPair
|
|
505
|
-
const pairCalls = quoteTokens.map((qt) => ({
|
|
506
|
-
target: factoryAddress,
|
|
507
|
-
callData: factoryIface.encodeFunctionData('getPair', [token, qt.address]),
|
|
508
|
-
quoteToken: qt,
|
|
509
|
-
}));
|
|
510
|
-
try {
|
|
511
|
-
const aggData = mcIface.encodeFunctionData('aggregate', [
|
|
512
|
-
pairCalls.map((c) => ({ target: c.target, callData: c.callData })),
|
|
513
|
-
]);
|
|
514
|
-
const res = await provider.call({ to: multicall3, data: aggData });
|
|
515
|
-
const [, returnData] = mcIface.decodeFunctionResult('aggregate', res);
|
|
516
|
-
// 解析 pair 地址
|
|
517
|
-
const validPairs = [];
|
|
518
|
-
for (let i = 0; i < pairCalls.length; i++) {
|
|
519
|
-
try {
|
|
520
|
-
const decoded = factoryIface.decodeFunctionResult('getPair', returnData[i]);
|
|
521
|
-
const pairAddress = decoded[0];
|
|
522
|
-
if (pairAddress && pairAddress.toLowerCase() !== ZERO_ADDRESS) {
|
|
523
|
-
validPairs.push({ pairAddress, quoteToken: pairCalls[i].quoteToken });
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
catch {
|
|
527
|
-
// 解码失败,跳过
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
if (validPairs.length === 0)
|
|
531
|
-
return results;
|
|
532
|
-
// 第二步:批量查询 getReserves
|
|
533
|
-
const reserveCalls = validPairs.flatMap((p) => [
|
|
534
|
-
{ target: p.pairAddress, callData: pairIface.encodeFunctionData('token0', []) },
|
|
535
|
-
{ target: p.pairAddress, callData: pairIface.encodeFunctionData('token1', []) },
|
|
536
|
-
{ target: p.pairAddress, callData: pairIface.encodeFunctionData('getReserves', []) },
|
|
537
|
-
]);
|
|
538
|
-
const aggData2 = mcIface.encodeFunctionData('aggregate', [reserveCalls]);
|
|
539
|
-
const res2 = await provider.call({ to: multicall3, data: aggData2 });
|
|
540
|
-
const [, returnData2] = mcIface.decodeFunctionResult('aggregate', res2);
|
|
541
|
-
// 解析储备量
|
|
542
|
-
for (let i = 0; i < validPairs.length; i++) {
|
|
543
|
-
try {
|
|
544
|
-
const idx = i * 3;
|
|
545
|
-
const token0 = pairIface.decodeFunctionResult('token0', returnData2[idx])[0];
|
|
546
|
-
pairIface.decodeFunctionResult('token1', returnData2[idx + 1]);
|
|
547
|
-
const [r0, r1] = pairIface.decodeFunctionResult('getReserves', returnData2[idx + 2]);
|
|
548
|
-
const p = validPairs[i];
|
|
549
|
-
const isToken0 = token0.toLowerCase() === token.toLowerCase();
|
|
550
|
-
const reserveToken = isToken0 ? r0 : r1;
|
|
551
|
-
const reserveQuote = isToken0 ? r1 : r0;
|
|
552
|
-
results.push({
|
|
553
|
-
quoteToken: p.quoteToken.address,
|
|
554
|
-
quoteSymbol: p.quoteToken.symbol,
|
|
555
|
-
quoteDecimals: p.quoteToken.decimals,
|
|
556
|
-
pairAddress: p.pairAddress,
|
|
557
|
-
reserveToken: formatBalance(reserveToken, shouldFormat, tokenDecimals),
|
|
558
|
-
reserveQuote: formatBalance(reserveQuote, shouldFormat, p.quoteToken.decimals),
|
|
559
|
-
reserveQuoteRaw: reserveQuote,
|
|
560
|
-
reserveTokenRaw: reserveToken, // ✅ 新增
|
|
561
|
-
});
|
|
562
|
-
}
|
|
563
|
-
catch {
|
|
564
|
-
// 单条 reserve 解码失败,跳过
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
catch {
|
|
569
|
-
// Fallback: 逐个查询
|
|
570
|
-
return queryV2PairsFallback(token, factoryAddress, quoteTokens, provider, tokenDecimals, shouldFormat);
|
|
571
|
-
}
|
|
572
|
-
return results;
|
|
573
|
-
}
|
|
574
|
-
async function queryV2PairsFallback(token, factoryAddress, quoteTokens, provider, tokenDecimals, shouldFormat) {
|
|
575
|
-
const factory = new Contract(factoryAddress, I_UNIV2_FACTORY_ABI, provider);
|
|
576
|
-
// ✅ 并行查询所有 quoteToken 的交易对
|
|
577
|
-
const pairResults = await Promise.all(quoteTokens.map(async (qt) => {
|
|
578
|
-
try {
|
|
579
|
-
const pairAddress = await factory.getPair(token, qt.address);
|
|
580
|
-
if (!pairAddress || pairAddress.toLowerCase() === ZERO_ADDRESS) {
|
|
581
|
-
return null;
|
|
582
|
-
}
|
|
583
|
-
const pair = new Contract(pairAddress, I_UNIV2_PAIR_ABI, provider);
|
|
584
|
-
const [token0, , reserves] = await Promise.all([pair.token0(), pair.token1(), pair.getReserves()]);
|
|
585
|
-
const [r0, r1] = reserves;
|
|
586
|
-
const isToken0 = token0.toLowerCase() === token.toLowerCase();
|
|
587
|
-
const reserveToken = isToken0 ? r0 : r1;
|
|
588
|
-
const reserveQuote = isToken0 ? r1 : r0;
|
|
589
|
-
return {
|
|
590
|
-
quoteToken: qt.address,
|
|
591
|
-
quoteSymbol: qt.symbol,
|
|
592
|
-
quoteDecimals: qt.decimals,
|
|
593
|
-
pairAddress,
|
|
594
|
-
reserveToken: formatBalance(reserveToken, shouldFormat, tokenDecimals),
|
|
595
|
-
reserveQuote: formatBalance(reserveQuote, shouldFormat, qt.decimals),
|
|
596
|
-
reserveQuoteRaw: reserveQuote,
|
|
597
|
-
reserveTokenRaw: reserveToken,
|
|
598
|
-
};
|
|
599
|
-
}
|
|
600
|
-
catch {
|
|
601
|
-
return null;
|
|
602
|
-
}
|
|
603
|
-
}));
|
|
604
|
-
// 过滤掉 null 结果
|
|
605
|
-
return pairResults.filter((r) => r !== null);
|
|
606
|
-
}
|
|
607
|
-
// ============================================================================
|
|
608
|
-
// V3 批量查询
|
|
609
|
-
// ============================================================================
|
|
610
|
-
async function queryV3Pools(token, factoryAddress, quoteTokens, feeTiers, provider, multicall3, tokenDecimals, shouldFormat) {
|
|
611
|
-
const results = [];
|
|
612
|
-
const factoryIface = new Interface(I_UNIV3_FACTORY_ABI);
|
|
613
|
-
const erc20Iface = new Interface(I_ERC20_ABI);
|
|
614
|
-
const mcIface = new Interface(MULTICALL3_ABI);
|
|
615
|
-
// 构建所有查询组合
|
|
616
|
-
const poolCalls = [];
|
|
617
|
-
for (const qt of quoteTokens) {
|
|
618
|
-
for (const fee of feeTiers) {
|
|
619
|
-
// V3 要求 token0 < token1
|
|
620
|
-
const tokenLower = token.toLowerCase();
|
|
621
|
-
const quoteLower = qt.address.toLowerCase();
|
|
622
|
-
const [token0, token1] = tokenLower < quoteLower ? [tokenLower, quoteLower] : [quoteLower, tokenLower];
|
|
623
|
-
poolCalls.push({
|
|
624
|
-
target: factoryAddress,
|
|
625
|
-
callData: factoryIface.encodeFunctionData('getPool', [token0, token1, fee]),
|
|
626
|
-
quoteToken: qt,
|
|
627
|
-
fee,
|
|
628
|
-
});
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
try {
|
|
632
|
-
// 第一步:批量查询所有 getPool
|
|
633
|
-
const aggData = mcIface.encodeFunctionData('aggregate', [
|
|
634
|
-
poolCalls.map((c) => ({ target: c.target, callData: c.callData })),
|
|
635
|
-
]);
|
|
636
|
-
const res = await provider.call({ to: multicall3, data: aggData });
|
|
637
|
-
const [, returnData] = mcIface.decodeFunctionResult('aggregate', res);
|
|
638
|
-
// 解析有效的池子
|
|
639
|
-
const validPools = [];
|
|
640
|
-
for (let i = 0; i < poolCalls.length; i++) {
|
|
641
|
-
try {
|
|
642
|
-
const decoded = factoryIface.decodeFunctionResult('getPool', returnData[i]);
|
|
643
|
-
const poolAddress = decoded[0];
|
|
644
|
-
if (poolAddress && poolAddress.toLowerCase() !== ZERO_ADDRESS) {
|
|
645
|
-
validPools.push({
|
|
646
|
-
poolAddress,
|
|
647
|
-
quoteToken: poolCalls[i].quoteToken,
|
|
648
|
-
fee: poolCalls[i].fee,
|
|
649
|
-
});
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
catch {
|
|
653
|
-
// 解码失败,跳过
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
if (validPools.length === 0)
|
|
657
|
-
return results;
|
|
658
|
-
// 第二步:批量查询余额
|
|
659
|
-
const balanceCalls = validPools.flatMap((p) => [
|
|
660
|
-
{ target: token, callData: erc20Iface.encodeFunctionData('balanceOf', [p.poolAddress]) },
|
|
661
|
-
{ target: p.quoteToken.address, callData: erc20Iface.encodeFunctionData('balanceOf', [p.poolAddress]) },
|
|
662
|
-
]);
|
|
663
|
-
const aggData2 = mcIface.encodeFunctionData('aggregate', [balanceCalls]);
|
|
664
|
-
const res2 = await provider.call({ to: multicall3, data: aggData2 });
|
|
665
|
-
const [, returnData2] = mcIface.decodeFunctionResult('aggregate', res2);
|
|
666
|
-
// 解析余额
|
|
667
|
-
for (let i = 0; i < validPools.length; i++) {
|
|
668
|
-
try {
|
|
669
|
-
const idx = i * 2;
|
|
670
|
-
const tokenBalance = erc20Iface.decodeFunctionResult('balanceOf', returnData2[idx])[0];
|
|
671
|
-
const quoteBalance = erc20Iface.decodeFunctionResult('balanceOf', returnData2[idx + 1])[0];
|
|
672
|
-
const p = validPools[i];
|
|
673
|
-
results.push({
|
|
674
|
-
quoteToken: p.quoteToken.address,
|
|
675
|
-
quoteSymbol: p.quoteToken.symbol,
|
|
676
|
-
quoteDecimals: p.quoteToken.decimals,
|
|
677
|
-
pairAddress: p.poolAddress,
|
|
678
|
-
reserveToken: formatBalance(tokenBalance, shouldFormat, tokenDecimals),
|
|
679
|
-
reserveQuote: formatBalance(quoteBalance, shouldFormat, p.quoteToken.decimals),
|
|
680
|
-
reserveQuoteRaw: quoteBalance,
|
|
681
|
-
reserveTokenRaw: tokenBalance, // ✅ 新增
|
|
682
|
-
fee: p.fee,
|
|
683
|
-
});
|
|
684
|
-
}
|
|
685
|
-
catch {
|
|
686
|
-
// 单条 balance 解码失败,跳过
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
catch {
|
|
691
|
-
// Fallback: 逐个查询
|
|
692
|
-
return queryV3PoolsFallback(token, factoryAddress, quoteTokens, feeTiers, provider, tokenDecimals, shouldFormat);
|
|
693
|
-
}
|
|
694
|
-
return results;
|
|
695
|
-
}
|
|
696
|
-
async function queryV3PoolsFallback(token, factoryAddress, quoteTokens, feeTiers, provider, tokenDecimals, shouldFormat) {
|
|
697
|
-
const factory = new Contract(factoryAddress, I_UNIV3_FACTORY_ABI, provider);
|
|
698
|
-
const tokenContract = new Contract(token, I_ERC20_ABI, provider);
|
|
699
|
-
// ✅ 构建所有查询组合
|
|
700
|
-
const queries = [];
|
|
701
|
-
for (const qt of quoteTokens) {
|
|
702
|
-
const tokenLower = token.toLowerCase();
|
|
703
|
-
const quoteLower = qt.address.toLowerCase();
|
|
704
|
-
const [token0, token1] = tokenLower < quoteLower ? [tokenLower, quoteLower] : [quoteLower, tokenLower];
|
|
705
|
-
for (const fee of feeTiers) {
|
|
706
|
-
queries.push({ qt, fee, token0, token1 });
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
// ✅ 并行查询所有池子
|
|
710
|
-
const poolResults = await Promise.all(queries.map(async ({ qt, fee, token0, token1 }) => {
|
|
711
|
-
try {
|
|
712
|
-
const poolAddress = await factory.getPool(token0, token1, fee);
|
|
713
|
-
if (!poolAddress || poolAddress.toLowerCase() === ZERO_ADDRESS) {
|
|
714
|
-
return null;
|
|
715
|
-
}
|
|
716
|
-
const quoteContract = new Contract(qt.address, I_ERC20_ABI, provider);
|
|
717
|
-
// ✅ 并行获取余额
|
|
718
|
-
const [tokenBalance, quoteBalance] = await Promise.all([
|
|
719
|
-
tokenContract.balanceOf(poolAddress),
|
|
720
|
-
quoteContract.balanceOf(poolAddress),
|
|
721
|
-
]);
|
|
722
|
-
return {
|
|
723
|
-
quoteToken: qt.address,
|
|
724
|
-
quoteSymbol: qt.symbol,
|
|
725
|
-
quoteDecimals: qt.decimals,
|
|
726
|
-
pairAddress: poolAddress,
|
|
727
|
-
reserveToken: formatBalance(tokenBalance, shouldFormat, tokenDecimals),
|
|
728
|
-
reserveQuote: formatBalance(quoteBalance, shouldFormat, qt.decimals),
|
|
729
|
-
reserveQuoteRaw: quoteBalance,
|
|
730
|
-
reserveTokenRaw: tokenBalance,
|
|
731
|
-
fee,
|
|
732
|
-
};
|
|
733
|
-
}
|
|
734
|
-
catch {
|
|
735
|
-
return null;
|
|
736
|
-
}
|
|
737
|
-
}));
|
|
738
|
-
// 过滤掉 null 结果
|
|
739
|
-
return poolResults.filter((r) => r !== null);
|
|
740
|
-
}
|
|
741
|
-
// ============================================================================
|
|
742
|
-
// 平台类型判断
|
|
743
|
-
// ============================================================================
|
|
744
|
-
function determinePlatform(allPools) {
|
|
745
|
-
if (allPools.length === 0)
|
|
746
|
-
return 'UNKNOWN';
|
|
747
|
-
// 统计有流动性的 DEX
|
|
748
|
-
const dexesWithLiquidity = allPools.filter((dex) => dex.v2Pairs.length > 0 || dex.v3Pools.length > 0);
|
|
749
|
-
if (dexesWithLiquidity.length > 1) {
|
|
750
|
-
return 'MULTI_DEX';
|
|
751
|
-
}
|
|
752
|
-
if (dexesWithLiquidity.length === 1) {
|
|
753
|
-
const dex = dexesWithLiquidity[0];
|
|
754
|
-
const hasV2 = dex.v2Pairs.length > 0;
|
|
755
|
-
const hasV3 = dex.v3Pools.length > 0;
|
|
756
|
-
if (dex.dexKey === 'PANCAKESWAP') {
|
|
757
|
-
if (hasV2 && hasV3)
|
|
758
|
-
return 'MULTI_DEX';
|
|
759
|
-
if (hasV3)
|
|
760
|
-
return 'PANCAKESWAP_V3';
|
|
761
|
-
return 'PANCAKESWAP_V2';
|
|
762
|
-
}
|
|
763
|
-
if (dex.dexKey === 'UNISWAP') {
|
|
764
|
-
if (hasV2 && hasV3)
|
|
765
|
-
return 'MULTI_DEX';
|
|
766
|
-
if (hasV3)
|
|
767
|
-
return 'UNISWAP_V3';
|
|
768
|
-
return 'UNISWAP_V2';
|
|
769
|
-
}
|
|
770
|
-
if (dex.dexKey === 'IROSWAP') {
|
|
771
|
-
return 'IROSWAP_V2';
|
|
772
|
-
}
|
|
773
|
-
// 其他 DEX
|
|
774
|
-
return 'MULTI_DEX';
|
|
775
|
-
}
|
|
776
|
-
return 'UNKNOWN';
|
|
777
|
-
}
|
|
10
|
+
export * from './registry.js';
|
|
11
|
+
export * from './inspect.js';
|