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
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* direct-router-v3 - V3 批量买卖(直接调用 Router)
|
|
3
|
+
*/
|
|
4
|
+
import { ethers, Wallet, Contract } from 'ethers';
|
|
5
|
+
import { getGasLimit } from '../../core/gas/bundle-gas.js';
|
|
6
|
+
import { NonceManager, buildProfitHopTransactions, PROFIT_HOP_COUNT, buildGasFields, } from '../../utils/bundle-helpers.js';
|
|
7
|
+
import { getProfitRecipient, CHAINS, GAS_LIMITS } from '../../core/constants/index.js';
|
|
8
|
+
import { getErrorMessageFromUnknown } from '../../core/index.js';
|
|
9
|
+
import { ERC20_ABI } from '../../abis/common.js';
|
|
10
|
+
import { getTokenToNativeQuote } from '../../core/quote/quote-helpers.js';
|
|
11
|
+
import { CHAIN_IDS, V3_ROUTER02_ABI, V3_ROUTER_LEGACY_ABI, buildBribeTransaction, buildProfitTransactionWithHops, calculateProfitAmount, findMaxFlowIndex, getBribeAmount, getCachedProvider, getDeadline, getGasPrice, getWrappedNative, isLegacySwapRouter, isNativeToken, quoteXLayerV3TokenToNativeBySlot0, } from './direct-router-helpers.js';
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// V3 直接交易
|
|
14
|
+
// ============================================================================
|
|
15
|
+
/**
|
|
16
|
+
* V3 批量买入(直接调用 Router)
|
|
17
|
+
*
|
|
18
|
+
* 自动识别 SwapRouter 版本:
|
|
19
|
+
* - SwapRouter02 (PancakeSwap V3): exactInputSingle 不含 deadline,multicall 含 deadline
|
|
20
|
+
* - SwapRouter (旧版 Uniswap V3): exactInputSingle 含 deadline,multicall 不含 deadline
|
|
21
|
+
*/
|
|
22
|
+
export async function directV3BatchBuy(params) {
|
|
23
|
+
const { chain, privateKeys, buyAmounts, tokenAddress, routerAddress, fee, quoteToken, quoteTokenDecimals = 18, startNonces, config, } = params;
|
|
24
|
+
if (privateKeys.length !== buyAmounts.length) {
|
|
25
|
+
throw new Error('privateKeys 和 buyAmounts 长度必须相同');
|
|
26
|
+
}
|
|
27
|
+
const chainId = config.chainId || CHAIN_IDS[chain.toUpperCase()] || CHAINS.BSC.chainId;
|
|
28
|
+
// ✅ 方案 C:使用缓存的 Provider
|
|
29
|
+
const provider = getCachedProvider(config.rpcUrl, chainId, chain);
|
|
30
|
+
const useNative = isNativeToken(quoteToken);
|
|
31
|
+
const wrappedNative = getWrappedNative(chain);
|
|
32
|
+
const useLegacyRouter = isLegacySwapRouter(chain, routerAddress);
|
|
33
|
+
const routerAbi = useLegacyRouter ? V3_ROUTER_LEGACY_ABI : V3_ROUTER02_ABI;
|
|
34
|
+
const wallets = privateKeys.map((pk) => new Wallet(pk, provider));
|
|
35
|
+
// ✅ 预先计算所有金额(同步操作,无 RPC)
|
|
36
|
+
const flowAmounts = buyAmounts.map((amount) => ethers.parseUnits(amount, quoteTokenDecimals));
|
|
37
|
+
const totalFlowWei = flowAmounts.reduce((sum, amt) => sum + amt, 0n);
|
|
38
|
+
const baseProfitWei = calculateProfitAmount(totalFlowWei);
|
|
39
|
+
// ✅ 方案 B:并行获取 nonces、gasPrice 和 ERC20 报价
|
|
40
|
+
const [nonces, gasPrice, nativeProfitWei] = await Promise.all([
|
|
41
|
+
startNonces && startNonces.length === wallets.length
|
|
42
|
+
? Promise.resolve(startNonces)
|
|
43
|
+
: new NonceManager(provider).getNextNoncesForWallets(wallets),
|
|
44
|
+
getGasPrice(provider, config),
|
|
45
|
+
// ERC20 报价(V3 买入用 V3 报价)
|
|
46
|
+
!useNative && baseProfitWei > 0n && quoteToken
|
|
47
|
+
? chain.toUpperCase() === 'XLAYER'
|
|
48
|
+
? quoteXLayerV3TokenToNativeBySlot0({ provider, tokenIn: quoteToken, amountIn: baseProfitWei, fee })
|
|
49
|
+
: getTokenToNativeQuote(provider, quoteToken, baseProfitWei, chain, 'v3', fee)
|
|
50
|
+
: Promise.resolve(baseProfitWei),
|
|
51
|
+
]);
|
|
52
|
+
let profitWei = nativeProfitWei > 0n ? nativeProfitWei : 0n;
|
|
53
|
+
if (profitWei > 0n && chain.toUpperCase() === 'ENI') {
|
|
54
|
+
profitWei += GAS_LIMITS.NATIVE_TRANSFER * gasPrice;
|
|
55
|
+
}
|
|
56
|
+
const gasLimit = getGasLimit(config, 300000);
|
|
57
|
+
const txType = config.txType ?? 0;
|
|
58
|
+
const routerIface = new ethers.Interface(routerAbi);
|
|
59
|
+
const inputToken = useNative ? wrappedNative : quoteToken;
|
|
60
|
+
const deadline = getDeadline();
|
|
61
|
+
// 构建交易数据的辅助函数
|
|
62
|
+
const buildV3BuyTxData = (wallet, amountWei) => {
|
|
63
|
+
if (useLegacyRouter) {
|
|
64
|
+
const swapParams = {
|
|
65
|
+
tokenIn: inputToken,
|
|
66
|
+
tokenOut: tokenAddress,
|
|
67
|
+
fee,
|
|
68
|
+
recipient: wallet.address,
|
|
69
|
+
deadline,
|
|
70
|
+
amountIn: amountWei,
|
|
71
|
+
amountOutMinimum: 0n,
|
|
72
|
+
sqrtPriceLimitX96: 0n,
|
|
73
|
+
};
|
|
74
|
+
if (useNative) {
|
|
75
|
+
const swapData = routerIface.encodeFunctionData('exactInputSingle', [swapParams]);
|
|
76
|
+
const refundData = routerIface.encodeFunctionData('refundETH', []);
|
|
77
|
+
return {
|
|
78
|
+
txData: routerIface.encodeFunctionData('multicall(bytes[])', [[swapData, refundData]]),
|
|
79
|
+
txValue: amountWei,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return { txData: routerIface.encodeFunctionData('exactInputSingle', [swapParams]), txValue: 0n };
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
const swapParams = {
|
|
86
|
+
tokenIn: inputToken,
|
|
87
|
+
tokenOut: tokenAddress,
|
|
88
|
+
fee,
|
|
89
|
+
recipient: wallet.address,
|
|
90
|
+
amountIn: amountWei,
|
|
91
|
+
amountOutMinimum: 0n,
|
|
92
|
+
sqrtPriceLimitX96: 0n,
|
|
93
|
+
};
|
|
94
|
+
if (useNative) {
|
|
95
|
+
const swapData = routerIface.encodeFunctionData('exactInputSingle', [swapParams]);
|
|
96
|
+
const refundData = routerIface.encodeFunctionData('refundETH', []);
|
|
97
|
+
return {
|
|
98
|
+
txData: routerIface.encodeFunctionData('multicall(uint256,bytes[])', [deadline, [swapData, refundData]]),
|
|
99
|
+
txValue: amountWei,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
// ✅ 修复:ERC20 买入也需要使用 multicall 包装以传递 deadline
|
|
103
|
+
// SwapRouter02 的 exactInputSingle 不包含 deadline 参数,必须通过 multicall 传递
|
|
104
|
+
const swapData = routerIface.encodeFunctionData('exactInputSingle', [swapParams]);
|
|
105
|
+
return {
|
|
106
|
+
txData: routerIface.encodeFunctionData('multicall(uint256,bytes[])', [deadline, [swapData]]),
|
|
107
|
+
txValue: 0n,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const maxFlowIndex = findMaxFlowIndex(flowAmounts);
|
|
112
|
+
const bribeWei = getBribeAmount(config, chain);
|
|
113
|
+
const hasBribe = bribeWei > 0n && wallets.length > 0;
|
|
114
|
+
const hasProfit = profitWei > 0n;
|
|
115
|
+
const nonceOffsets = wallets.map((_, i) => (i === maxFlowIndex && hasBribe ? 1 : 0));
|
|
116
|
+
// ✅ 方案 A:并行签名所有交易(贿赂、主交易、利润)
|
|
117
|
+
const signPromises = [];
|
|
118
|
+
if (hasBribe) {
|
|
119
|
+
signPromises.push(buildBribeTransaction(wallets[maxFlowIndex], bribeWei, nonces[maxFlowIndex], gasPrice, chainId, txType).then((tx) => ({ type: 'bribe', index: 0, tx })));
|
|
120
|
+
}
|
|
121
|
+
wallets.forEach((wallet, i) => {
|
|
122
|
+
const { txData, txValue } = buildV3BuyTxData(wallet, flowAmounts[i]);
|
|
123
|
+
signPromises.push(wallet
|
|
124
|
+
.signTransaction({
|
|
125
|
+
to: routerAddress,
|
|
126
|
+
data: txData,
|
|
127
|
+
value: txValue,
|
|
128
|
+
nonce: nonces[i] + nonceOffsets[i],
|
|
129
|
+
gasLimit,
|
|
130
|
+
...buildGasFields(txType, gasPrice),
|
|
131
|
+
chainId,
|
|
132
|
+
})
|
|
133
|
+
.then((tx) => ({ type: 'swap', index: i, tx })));
|
|
134
|
+
});
|
|
135
|
+
const signedResults = await Promise.all(signPromises);
|
|
136
|
+
const bribeTxs = signedResults.filter((r) => r.type === 'bribe').map((r) => r.tx);
|
|
137
|
+
const swapTxs = signedResults
|
|
138
|
+
.filter((r) => r.type === 'swap')
|
|
139
|
+
.sort((a, b) => a.index - b.index)
|
|
140
|
+
.map((r) => r.tx);
|
|
141
|
+
// ✅ 检查是否使用分布式利润模式
|
|
142
|
+
const profitMode = config.profitMode || 'single';
|
|
143
|
+
const skipProfit = config.skipProfit === true;
|
|
144
|
+
const profitAddr = getProfitRecipient();
|
|
145
|
+
// 利润多跳转账
|
|
146
|
+
let profitTxs = [];
|
|
147
|
+
let profitHopWallets;
|
|
148
|
+
if (hasProfit && !skipProfit) {
|
|
149
|
+
if (profitMode === 'distributed') {
|
|
150
|
+
// ✅ 分布式模式:每个钱包独立扣除自己的利润
|
|
151
|
+
const MAX_DISTRIBUTED_WALLETS = 12;
|
|
152
|
+
if (wallets.length > MAX_DISTRIBUTED_WALLETS) {
|
|
153
|
+
throw new Error(`分布式利润模式最多支持 ${MAX_DISTRIBUTED_WALLETS} 个钱包,当前 ${wallets.length} 个`);
|
|
154
|
+
}
|
|
155
|
+
profitHopWallets = [];
|
|
156
|
+
// 计算每个钱包的利润(按比例分配)
|
|
157
|
+
for (let i = 0; i < wallets.length; i++) {
|
|
158
|
+
const walletProfit = totalFlowWei > 0n ? (profitWei * flowAmounts[i]) / totalFlowWei : 0n;
|
|
159
|
+
if (walletProfit > 0n) {
|
|
160
|
+
const walletProfitNonce = nonces[i] + nonceOffsets[i] + 1;
|
|
161
|
+
const profitResult = await buildProfitHopTransactions({
|
|
162
|
+
provider,
|
|
163
|
+
payerWallet: wallets[i],
|
|
164
|
+
profitAmount: walletProfit,
|
|
165
|
+
profitRecipient: profitAddr,
|
|
166
|
+
hopCount: PROFIT_HOP_COUNT,
|
|
167
|
+
gasPrice,
|
|
168
|
+
chainId,
|
|
169
|
+
txType,
|
|
170
|
+
startNonce: walletProfitNonce,
|
|
171
|
+
});
|
|
172
|
+
profitTxs.push(...profitResult.signedTransactions);
|
|
173
|
+
if (profitResult.hopWallets) {
|
|
174
|
+
profitHopWallets.push(...profitResult.hopWallets);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
// ✅ 单一模式(默认):从金额最大的钱包统一扣除
|
|
181
|
+
const profitNonce = nonces[maxFlowIndex] + nonceOffsets[maxFlowIndex] + 1;
|
|
182
|
+
const profitResult = await buildProfitTransactionWithHops(provider, wallets[maxFlowIndex], profitWei, profitNonce, gasPrice, chainId, txType, profitAddr);
|
|
183
|
+
profitTxs = profitResult.signedTransactions;
|
|
184
|
+
profitHopWallets = profitResult.hopWallets;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const signedTxs = [...bribeTxs, ...swapTxs, ...profitTxs];
|
|
188
|
+
return {
|
|
189
|
+
signedTransactions: signedTxs,
|
|
190
|
+
profitHopWallets,
|
|
191
|
+
metadata: {
|
|
192
|
+
profitMode, // ✅ 返回使用的利润模式
|
|
193
|
+
profitAmount: ethers.formatEther(profitWei),
|
|
194
|
+
profitRecipient: profitAddr,
|
|
195
|
+
totalFlow: ethers.formatUnits(totalFlowWei, quoteTokenDecimals),
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* V3 批量卖出(直接调用 Router)
|
|
201
|
+
*
|
|
202
|
+
* 自动识别 SwapRouter 版本:
|
|
203
|
+
* - SwapRouter02 (PancakeSwap V3): exactInputSingle 不含 deadline,multicall 含 deadline
|
|
204
|
+
* - SwapRouter (旧版 Uniswap V3): exactInputSingle 含 deadline,multicall 不含 deadline
|
|
205
|
+
*/
|
|
206
|
+
export async function directV3BatchSell(params) {
|
|
207
|
+
const { chain, privateKeys, sellPercentages, sellAmounts, tokenAddress, tokenDecimals = 18, routerAddress, fee, quoteToken, startNonces, config, } = params;
|
|
208
|
+
const chainId = config.chainId || CHAIN_IDS[chain.toUpperCase()] || CHAINS.BSC.chainId;
|
|
209
|
+
// ✅ 方案 C:使用缓存的 Provider
|
|
210
|
+
const provider = getCachedProvider(config.rpcUrl, chainId, chain);
|
|
211
|
+
const useNativeOutput = isNativeToken(quoteToken);
|
|
212
|
+
const wrappedNative = getWrappedNative(chain);
|
|
213
|
+
const useLegacyRouter = isLegacySwapRouter(chain, routerAddress);
|
|
214
|
+
const routerAbi = useLegacyRouter ? V3_ROUTER_LEGACY_ABI : V3_ROUTER02_ABI;
|
|
215
|
+
const wallets = privateKeys.map((pk) => new Wallet(pk, provider));
|
|
216
|
+
const tokenContract = new Contract(tokenAddress, ERC20_ABI, provider);
|
|
217
|
+
// ✅ 并行获取所有 RPC 数据
|
|
218
|
+
const [balances, nonces, gasPrice] = await Promise.all([
|
|
219
|
+
Promise.all(wallets.map((w) => tokenContract.balanceOf(w.address))),
|
|
220
|
+
startNonces && startNonces.length === wallets.length
|
|
221
|
+
? Promise.resolve(startNonces)
|
|
222
|
+
: new NonceManager(provider).getNextNoncesForWallets(wallets),
|
|
223
|
+
getGasPrice(provider, config),
|
|
224
|
+
]);
|
|
225
|
+
const gasLimit = getGasLimit(config, 350000);
|
|
226
|
+
const txType = config.txType ?? 0;
|
|
227
|
+
// 计算卖出数量(同步操作,无 RPC)
|
|
228
|
+
const sellAmountsWei = [];
|
|
229
|
+
for (let i = 0; i < wallets.length; i++) {
|
|
230
|
+
if (sellAmounts && sellAmounts[i]) {
|
|
231
|
+
sellAmountsWei.push(ethers.parseUnits(sellAmounts[i], tokenDecimals));
|
|
232
|
+
}
|
|
233
|
+
else if (sellPercentages && sellPercentages[i]) {
|
|
234
|
+
const pct = Math.min(100, Math.max(0, sellPercentages[i]));
|
|
235
|
+
sellAmountsWei.push((balances[i] * BigInt(pct)) / 100n);
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
sellAmountsWei.push(balances[i]);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
const totalSellAmount = sellAmountsWei.reduce((sum, o) => sum + o, 0n);
|
|
242
|
+
// ✅ 修复:对于卖出操作,利润应基于【得到的 BNB/原生代币】而不是【卖出的代币数量】
|
|
243
|
+
// 使用 V2 Router 获取卖出报价,然后基于预估得到的原生代币数量计算利润
|
|
244
|
+
const nativeProfitPromise = (async () => {
|
|
245
|
+
try {
|
|
246
|
+
if (useNativeOutput) {
|
|
247
|
+
// 卖出代币 → 得到 BNB:先获取 V3 报价,再计算利润
|
|
248
|
+
const estimatedBNBOut = chain.toUpperCase() === 'XLAYER'
|
|
249
|
+
? await quoteXLayerV3TokenToNativeBySlot0({
|
|
250
|
+
provider,
|
|
251
|
+
tokenIn: tokenAddress,
|
|
252
|
+
amountIn: totalSellAmount,
|
|
253
|
+
fee,
|
|
254
|
+
})
|
|
255
|
+
: await getTokenToNativeQuote(provider, tokenAddress, totalSellAmount, chain, 'v3', fee);
|
|
256
|
+
if (estimatedBNBOut <= 0n)
|
|
257
|
+
return 0n;
|
|
258
|
+
const profit = calculateProfitAmount(estimatedBNBOut);
|
|
259
|
+
return profit;
|
|
260
|
+
}
|
|
261
|
+
else if (quoteToken) {
|
|
262
|
+
// 卖出代币 → 得到 ERC20:先获取 V3 报价,再计算利润
|
|
263
|
+
const estimatedBNBOut = chain.toUpperCase() === 'XLAYER'
|
|
264
|
+
? await quoteXLayerV3TokenToNativeBySlot0({
|
|
265
|
+
provider,
|
|
266
|
+
tokenIn: tokenAddress,
|
|
267
|
+
amountIn: totalSellAmount,
|
|
268
|
+
fee,
|
|
269
|
+
})
|
|
270
|
+
: await getTokenToNativeQuote(provider, tokenAddress, totalSellAmount, chain, 'v3', fee);
|
|
271
|
+
if (estimatedBNBOut <= 0n)
|
|
272
|
+
return 0n;
|
|
273
|
+
const profit = calculateProfitAmount(estimatedBNBOut);
|
|
274
|
+
return profit;
|
|
275
|
+
}
|
|
276
|
+
return 0n;
|
|
277
|
+
}
|
|
278
|
+
catch (error) {
|
|
279
|
+
console.error(`[V3 Sell Profit] Error:`, getErrorMessageFromUnknown(error));
|
|
280
|
+
return 0n;
|
|
281
|
+
}
|
|
282
|
+
})();
|
|
283
|
+
const routerIface = new ethers.Interface(routerAbi);
|
|
284
|
+
const outputToken = useNativeOutput ? wrappedNative : quoteToken;
|
|
285
|
+
const deadline = getDeadline();
|
|
286
|
+
// 构建卖出交易数据的辅助函数
|
|
287
|
+
const buildV3SellTxData = (wallet, sellAmount) => {
|
|
288
|
+
if (useLegacyRouter) {
|
|
289
|
+
const swapParams = {
|
|
290
|
+
tokenIn: tokenAddress,
|
|
291
|
+
tokenOut: outputToken,
|
|
292
|
+
fee,
|
|
293
|
+
recipient: useNativeOutput ? routerAddress : wallet.address,
|
|
294
|
+
deadline,
|
|
295
|
+
amountIn: sellAmount,
|
|
296
|
+
amountOutMinimum: 0n,
|
|
297
|
+
sqrtPriceLimitX96: 0n,
|
|
298
|
+
};
|
|
299
|
+
if (useNativeOutput) {
|
|
300
|
+
return routerIface.encodeFunctionData('multicall(bytes[])', [
|
|
301
|
+
[
|
|
302
|
+
routerIface.encodeFunctionData('exactInputSingle', [swapParams]),
|
|
303
|
+
routerIface.encodeFunctionData('unwrapWETH9', [0n, wallet.address]),
|
|
304
|
+
],
|
|
305
|
+
]);
|
|
306
|
+
}
|
|
307
|
+
// ✅ 修复:ERC20 输出也需要使用 multicall 包装以传递 deadline
|
|
308
|
+
return routerIface.encodeFunctionData('multicall(bytes[])', [
|
|
309
|
+
[routerIface.encodeFunctionData('exactInputSingle', [swapParams])],
|
|
310
|
+
]);
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
const swapParams = {
|
|
314
|
+
tokenIn: tokenAddress,
|
|
315
|
+
tokenOut: outputToken,
|
|
316
|
+
fee,
|
|
317
|
+
recipient: useNativeOutput ? routerAddress : wallet.address,
|
|
318
|
+
amountIn: sellAmount,
|
|
319
|
+
amountOutMinimum: 0n,
|
|
320
|
+
sqrtPriceLimitX96: 0n,
|
|
321
|
+
};
|
|
322
|
+
if (useNativeOutput) {
|
|
323
|
+
return routerIface.encodeFunctionData('multicall(uint256,bytes[])', [
|
|
324
|
+
deadline,
|
|
325
|
+
[
|
|
326
|
+
routerIface.encodeFunctionData('exactInputSingle', [swapParams]),
|
|
327
|
+
routerIface.encodeFunctionData('unwrapWETH9', [0n, wallet.address]),
|
|
328
|
+
],
|
|
329
|
+
]);
|
|
330
|
+
}
|
|
331
|
+
// ✅ 修复:ERC20 输出也需要使用 multicall 包装以传递 deadline
|
|
332
|
+
return routerIface.encodeFunctionData('multicall(uint256,bytes[])', [
|
|
333
|
+
deadline,
|
|
334
|
+
[routerIface.encodeFunctionData('exactInputSingle', [swapParams])],
|
|
335
|
+
]);
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
const maxOutputIndex = findMaxFlowIndex(sellAmountsWei);
|
|
339
|
+
const bribeWei = getBribeAmount(config, chain);
|
|
340
|
+
const hasBribe = bribeWei > 0n && wallets.length > 0;
|
|
341
|
+
const nonceOffsets = wallets.map((_, i) => (i === maxOutputIndex && hasBribe ? 1 : 0));
|
|
342
|
+
// ✅ 方案 A:并行签名所有交易(贿赂、卖出)+ 并行获取 ERC20 报价
|
|
343
|
+
const signPromises = [];
|
|
344
|
+
if (hasBribe) {
|
|
345
|
+
signPromises.push(buildBribeTransaction(wallets[maxOutputIndex], bribeWei, nonces[maxOutputIndex], gasPrice, chainId, txType).then((tx) => ({ type: 'bribe', index: 0, tx })));
|
|
346
|
+
}
|
|
347
|
+
wallets.forEach((wallet, i) => {
|
|
348
|
+
if (sellAmountsWei[i] <= 0n)
|
|
349
|
+
return;
|
|
350
|
+
signPromises.push(wallet
|
|
351
|
+
.signTransaction({
|
|
352
|
+
to: routerAddress,
|
|
353
|
+
data: buildV3SellTxData(wallet, sellAmountsWei[i]),
|
|
354
|
+
value: 0n,
|
|
355
|
+
nonce: nonces[i] + nonceOffsets[i],
|
|
356
|
+
gasLimit,
|
|
357
|
+
...buildGasFields(txType, gasPrice),
|
|
358
|
+
chainId,
|
|
359
|
+
})
|
|
360
|
+
.then((tx) => ({ type: 'swap', index: i, tx })));
|
|
361
|
+
});
|
|
362
|
+
// ✅ 并行执行:签名 + ERC20 报价
|
|
363
|
+
const [signedResults, nativeProfitWei] = await Promise.all([Promise.all(signPromises), nativeProfitPromise]);
|
|
364
|
+
let profitWei = nativeProfitWei > 0n ? nativeProfitWei : 0n;
|
|
365
|
+
if (profitWei > 0n && chain.toUpperCase() === 'ENI') {
|
|
366
|
+
profitWei += GAS_LIMITS.NATIVE_TRANSFER * gasPrice;
|
|
367
|
+
}
|
|
368
|
+
// ✅ 检查是否使用分布式利润模式
|
|
369
|
+
const profitMode = config.profitMode || 'single';
|
|
370
|
+
const skipProfit = config.skipProfit === true;
|
|
371
|
+
const profitAddr = getProfitRecipient();
|
|
372
|
+
// 利润多跳转账
|
|
373
|
+
let profitTxs = [];
|
|
374
|
+
let profitHopWallets;
|
|
375
|
+
if (profitWei > 0n && wallets.length > 0 && !skipProfit) {
|
|
376
|
+
if (profitMode === 'distributed') {
|
|
377
|
+
// ✅ 分布式模式:每个钱包独立扣除自己的利润
|
|
378
|
+
const MAX_DISTRIBUTED_WALLETS = 12;
|
|
379
|
+
if (wallets.length > MAX_DISTRIBUTED_WALLETS) {
|
|
380
|
+
throw new Error(`分布式利润模式最多支持 ${MAX_DISTRIBUTED_WALLETS} 个钱包,当前 ${wallets.length} 个`);
|
|
381
|
+
}
|
|
382
|
+
profitHopWallets = [];
|
|
383
|
+
// 计算每个钱包的利润(按卖出金额比例分配)
|
|
384
|
+
for (let i = 0; i < wallets.length; i++) {
|
|
385
|
+
const walletProfit = totalSellAmount > 0n ? (profitWei * sellAmountsWei[i]) / totalSellAmount : 0n;
|
|
386
|
+
if (walletProfit > 0n) {
|
|
387
|
+
const walletProfitNonce = nonces[i] + nonceOffsets[i] + 1;
|
|
388
|
+
const profitResult = await buildProfitHopTransactions({
|
|
389
|
+
provider,
|
|
390
|
+
payerWallet: wallets[i],
|
|
391
|
+
profitAmount: walletProfit,
|
|
392
|
+
profitRecipient: profitAddr,
|
|
393
|
+
hopCount: PROFIT_HOP_COUNT,
|
|
394
|
+
gasPrice,
|
|
395
|
+
chainId,
|
|
396
|
+
txType,
|
|
397
|
+
startNonce: walletProfitNonce,
|
|
398
|
+
});
|
|
399
|
+
profitTxs.push(...profitResult.signedTransactions);
|
|
400
|
+
if (profitResult.hopWallets) {
|
|
401
|
+
profitHopWallets.push(...profitResult.hopWallets);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
// ✅ 单一模式(默认):从卖出金额最大的钱包统一扣除
|
|
408
|
+
const profitNonce = nonces[maxOutputIndex] + nonceOffsets[maxOutputIndex] + 1;
|
|
409
|
+
const profitResult = await buildProfitTransactionWithHops(provider, wallets[maxOutputIndex], profitWei, profitNonce, gasPrice, chainId, txType, profitAddr);
|
|
410
|
+
profitTxs = profitResult.signedTransactions;
|
|
411
|
+
profitHopWallets = profitResult.hopWallets;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
// 按类型分组并按顺序组装
|
|
415
|
+
const validResults = signedResults.filter((r) => r !== null);
|
|
416
|
+
const bribeTxs = validResults.filter((r) => r.type === 'bribe').map((r) => r.tx);
|
|
417
|
+
const swapTxs = validResults
|
|
418
|
+
.filter((r) => r.type === 'swap')
|
|
419
|
+
.sort((a, b) => a.index - b.index)
|
|
420
|
+
.map((r) => r.tx);
|
|
421
|
+
const signedTxs = [...bribeTxs, ...swapTxs, ...profitTxs];
|
|
422
|
+
return {
|
|
423
|
+
signedTransactions: signedTxs,
|
|
424
|
+
profitHopWallets,
|
|
425
|
+
metadata: {
|
|
426
|
+
profitMode, // ✅ 返回使用的利润模式
|
|
427
|
+
profitAmount: ethers.formatEther(profitWei),
|
|
428
|
+
profitRecipient: profitAddr,
|
|
429
|
+
totalFlow: ethers.formatEther(totalSellAmount),
|
|
430
|
+
},
|
|
431
|
+
};
|
|
432
|
+
}
|
|
@@ -1,28 +1,13 @@
|
|
|
1
|
-
import type { DirectV2BuyParams, DirectV2SellParams, DirectV3BuyParams, DirectV3SellParams, DirectRouterResult, DexKey, RouterVersion } from './types.js';
|
|
2
|
-
export type { DirectV2BuyParams, DirectV2SellParams, DirectV3BuyParams, DirectV3SellParams, DirectRouterResult, DirectRouterSignConfig, DexKey, RouterVersion, } from './types.js';
|
|
3
|
-
export { DIRECT_ROUTERS } from './direct-router-helpers.js';
|
|
4
|
-
export declare function directV2BatchBuy(params: DirectV2BuyParams): Promise<DirectRouterResult>;
|
|
5
|
-
/**
|
|
6
|
-
* V2 批量卖出(直接调用 Router)
|
|
7
|
-
*/
|
|
8
|
-
export declare function directV2BatchSell(params: DirectV2SellParams): Promise<DirectRouterResult>;
|
|
9
|
-
/**
|
|
10
|
-
* V3 批量买入(直接调用 Router)
|
|
11
|
-
*
|
|
12
|
-
* 自动识别 SwapRouter 版本:
|
|
13
|
-
* - SwapRouter02 (PancakeSwap V3): exactInputSingle 不含 deadline,multicall 含 deadline
|
|
14
|
-
* - SwapRouter (旧版 Uniswap V3): exactInputSingle 含 deadline,multicall 不含 deadline
|
|
15
|
-
*/
|
|
16
|
-
export declare function directV3BatchBuy(params: DirectV3BuyParams): Promise<DirectRouterResult>;
|
|
17
1
|
/**
|
|
18
|
-
*
|
|
2
|
+
* direct-router - 主入口(barrel re-export)
|
|
19
3
|
*
|
|
20
|
-
*
|
|
21
|
-
* -
|
|
22
|
-
* -
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*
|
|
27
|
-
|
|
28
|
-
export
|
|
4
|
+
* 实现已按版本拆分到子文件:
|
|
5
|
+
* - direct-router-v2.ts: V2 批量买卖 directV2BatchBuy / directV2BatchSell
|
|
6
|
+
* - direct-router-v3.ts: V3 批量买卖 directV3BatchBuy / directV3BatchSell
|
|
7
|
+
* - router.ts: getRouterAddress 等 Router 地址/识别工具
|
|
8
|
+
*/
|
|
9
|
+
export * from './direct-router-v2.js';
|
|
10
|
+
export * from './direct-router-v3.js';
|
|
11
|
+
export { getRouterAddress } from './router.js';
|
|
12
|
+
export { DIRECT_ROUTERS } from './direct-router-helpers.js';
|
|
13
|
+
export type { DirectV2BuyParams, DirectV2SellParams, DirectV3BuyParams, DirectV3SellParams, DirectRouterResult, DirectRouterSignConfig, DexKey, RouterVersion, } from './types.js';
|