four-flap-meme-sdk 3.0.0 → 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/index.d.ts +1 -1
- package/dist/chains/bsc/index.js +2 -0
- 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/index.d.ts +2 -0
- package/dist/chains/eni/index.js +4 -0
- 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 -81
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { V2_ROUTER_ABI as _V2_ROUTER_ABI, V3_ROUTER02_ABI as _V3_ROUTER02_ABI, V3_ROUTER_LEGACY_ABI as _V3_ROUTER_LEGACY_ABI, SWAP_ROUTER02_V2_ABI as _SWAP_ROUTER02_V2_ABI, } from '../../abis/common.js';
|
|
2
|
+
import { ADDRESSES, CHAINS } from '../../core/constants/index.js';
|
|
3
|
+
export const DEFAULT_GAS_LIMIT = 300000;
|
|
4
|
+
export const DEADLINE_MINUTES = 20;
|
|
5
|
+
/** Router 地址配置 - ✅ 使用公共模块中的地址 */
|
|
6
|
+
export const DIRECT_ROUTERS = {
|
|
7
|
+
BSC: {
|
|
8
|
+
PANCAKESWAP_V2: ADDRESSES.BSC.PancakeV2Router,
|
|
9
|
+
PANCAKESWAP_V3: ADDRESSES.BSC.PancakeV3Router,
|
|
10
|
+
IROSWAP_V2: ADDRESSES.BSC.IroSwapV2Router,
|
|
11
|
+
WBNB: ADDRESSES.BSC.WBNB,
|
|
12
|
+
},
|
|
13
|
+
MONAD: {
|
|
14
|
+
PANCAKESWAP_V2: ADDRESSES.MONAD.PancakeV2Router,
|
|
15
|
+
PANCAKESWAP_V3: ADDRESSES.MONAD.PancakeV3Router,
|
|
16
|
+
UNISWAP_V2: ADDRESSES.MONAD.UniswapV2Router,
|
|
17
|
+
UNISWAP_V3: ADDRESSES.MONAD.UniswapV3Router,
|
|
18
|
+
WMON: ADDRESSES.MONAD.WMON,
|
|
19
|
+
},
|
|
20
|
+
// XLayer (PotatoSwap + DYORSwap)
|
|
21
|
+
XLAYER: {
|
|
22
|
+
POTATOSWAP_V2: ADDRESSES.XLAYER.PotatoSwapV2Router,
|
|
23
|
+
POTATOSWAP_V3: ADDRESSES.XLAYER.PotatoSwapSwapRouter02,
|
|
24
|
+
DYORSWAP_ROUTER: ADDRESSES.XLAYER.DyorSwapRouter,
|
|
25
|
+
DYORSWAP_FACTORY: ADDRESSES.XLAYER.DyorSwapV2Factory,
|
|
26
|
+
V3_ROUTER: ADDRESSES.XLAYER.PotatoSwapV3Router,
|
|
27
|
+
V3_FACTORY: ADDRESSES.XLAYER.PotatoSwapV3Factory,
|
|
28
|
+
WOKB: ADDRESSES.XLAYER.WOKB,
|
|
29
|
+
},
|
|
30
|
+
ENI: {
|
|
31
|
+
DSWAP_V2: ADDRESSES.ENI.DswapV2Router,
|
|
32
|
+
DSWAP_V3: ADDRESSES.ENI.DswapV3Router02,
|
|
33
|
+
IROSWAP_V2: ADDRESSES.ENI.IroSwapV2Router,
|
|
34
|
+
WEGAS: ADDRESSES.ENI.WEGAS,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
/** 链 ID 映射 */
|
|
38
|
+
export const CHAIN_IDS = {
|
|
39
|
+
BSC: CHAINS.BSC.chainId,
|
|
40
|
+
MONAD: CHAINS.MONAD.chainId,
|
|
41
|
+
XLAYER: CHAINS.XLAYER.chainId,
|
|
42
|
+
ENI: CHAINS.ENI.chainId,
|
|
43
|
+
};
|
|
44
|
+
/** V2 Router ABI */
|
|
45
|
+
export const V2_ROUTER_ABI = _V2_ROUTER_ABI;
|
|
46
|
+
/** SwapRouter02 的 V2 方法 ABI - ✅ 从公共模块导入 */
|
|
47
|
+
export const SWAP_ROUTER02_V2_ABI = _SWAP_ROUTER02_V2_ABI;
|
|
48
|
+
/**
|
|
49
|
+
* DYORSwap SwapRouter02 的 V2 方法
|
|
50
|
+
*
|
|
51
|
+
* ⚠️ 重要:DYORSwap 使用自定义的函数签名,无法通过标准 ABI 编码
|
|
52
|
+
* 必须手动构造 calldata
|
|
53
|
+
*
|
|
54
|
+
* swapExactTokensForTokens selector: 0x3234fe0d
|
|
55
|
+
* unwrapWETH9 selector: 0x7342292e
|
|
56
|
+
* refundETH selector: 0x6d29fcf4
|
|
57
|
+
*/
|
|
58
|
+
export const DYORSWAP_SELECTORS = {
|
|
59
|
+
swapExactTokensForTokens: '0x3234fe0d',
|
|
60
|
+
unwrapWETH9: '0x7342292e',
|
|
61
|
+
refundETH: '0x6d29fcf4',
|
|
62
|
+
multicall: '0x5ae401dc',
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* DYORSwap 的 ETHBack_Dividend 合约地址
|
|
66
|
+
* 这是 refundETH 中使用的固定地址,不是 LP 池地址
|
|
67
|
+
*/
|
|
68
|
+
export const DYORSWAP_ETHBACK_DIVIDEND = ADDRESSES.XLAYER.DyorSwapEthBackDividend;
|
|
69
|
+
/** V3 SwapRouter02 ABI (PancakeSwap V3, 新版 Uniswap) */
|
|
70
|
+
export const V3_ROUTER02_ABI = _V3_ROUTER02_ABI;
|
|
71
|
+
/** V3 SwapRouter(旧版)ABI (Monad Uniswap V3) */
|
|
72
|
+
export const V3_ROUTER_LEGACY_ABI = _V3_ROUTER_LEGACY_ABI;
|
|
73
|
+
export const XLAYER_V3_FACTORY_ABI = [
|
|
74
|
+
'function getPool(address tokenA, address tokenB, uint24 fee) view returns (address pool)',
|
|
75
|
+
];
|
|
76
|
+
export const XLAYER_V3_POOL_ABI = [
|
|
77
|
+
'function slot0() view returns (uint160 sqrtPriceX96,int24 tick,uint16 observationIndex,uint16 observationCardinality,uint16 observationCardinalityNext,uint8 feeProtocol,bool unlocked)',
|
|
78
|
+
'function token0() view returns (address)',
|
|
79
|
+
'function token1() view returns (address)',
|
|
80
|
+
];
|
|
81
|
+
export const V3_FEE_DENOMINATOR = 1000000n; // UniswapV3 fee: X / 1e6
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* direct-router-v2-buy - V2 批量买入(直接调用 Router)
|
|
3
|
+
* 从 direct-router-v2.ts 抽取,direct-router-v2.ts 通过 re-export 保持对外不变。
|
|
4
|
+
*/
|
|
5
|
+
import { ethers, Wallet, Contract } from 'ethers';
|
|
6
|
+
import { getGasLimit } from '../../core/gas/bundle-gas.js';
|
|
7
|
+
import { NonceManager, buildProfitHopTransactions, PROFIT_HOP_COUNT, buildGasFields, } from '../../utils/bundle-helpers.js';
|
|
8
|
+
import { getProfitRecipient, CHAINS, GAS_LIMITS } from '../../core/constants/index.js';
|
|
9
|
+
import { ERC20_ABI } from '../../abis/common.js';
|
|
10
|
+
import { getTokenToNativeQuote } from '../../core/quote/quote-helpers.js';
|
|
11
|
+
import { CHAIN_IDS, DIRECT_ROUTERS, SWAP_ROUTER02_V2_ABI, V2_ROUTER_ABI, buildBribeTransaction, buildProfitTransactionWithHops, calculateProfitAmount, encodeDYORMulticall, encodeDYORRefundETH, encodeDYORSwapExactTokensForTokens, findMaxFlowIndex, filterEniNativeBuyIndices, getBribeAmount, getCachedProvider, getDeadline, getGasPrice, getWrappedNative, isDYORSwap, isNativeToken, isSwapRouter02, } from './direct-router-helpers.js';
|
|
12
|
+
export async function directV2BatchBuy(params) {
|
|
13
|
+
const { chain, privateKeys, buyAmounts, tokenAddress, routerAddress, quoteToken, quoteTokenDecimals = 18, startNonces, config, } = params;
|
|
14
|
+
if (privateKeys.length !== buyAmounts.length) {
|
|
15
|
+
throw new Error('privateKeys 和 buyAmounts 长度必须相同');
|
|
16
|
+
}
|
|
17
|
+
const chainId = config.chainId || CHAIN_IDS[chain.toUpperCase()] || CHAINS.BSC.chainId;
|
|
18
|
+
// ✅ 方案 C:使用缓存的 Provider
|
|
19
|
+
const provider = getCachedProvider(config.rpcUrl, chainId, chain);
|
|
20
|
+
const useNative = isNativeToken(quoteToken);
|
|
21
|
+
const wrappedNative = getWrappedNative(chain);
|
|
22
|
+
// 创建钱包
|
|
23
|
+
const wallets = privateKeys.map((pk) => new Wallet(pk, provider));
|
|
24
|
+
// ✅ 预先计算所有金额(同步操作,无 RPC)
|
|
25
|
+
const flowAmounts = buyAmounts.map((amount) => ethers.parseUnits(amount, quoteTokenDecimals));
|
|
26
|
+
const totalFlowWei = flowAmounts.reduce((sum, amt) => sum + amt, 0n);
|
|
27
|
+
const baseProfitWei = calculateProfitAmount(totalFlowWei);
|
|
28
|
+
// ✅ 方案 B:并行获取 nonces、gasPrice、ERC20 报价 以及(非原生代币时)授权额度
|
|
29
|
+
const quoteTokenContract = !useNative && quoteToken ? new Contract(quoteToken, ERC20_ABI, provider) : null;
|
|
30
|
+
const [nonces, gasPrice, nativeProfitWei, buyAllowances] = await Promise.all([
|
|
31
|
+
startNonces && startNonces.length === wallets.length
|
|
32
|
+
? Promise.resolve(startNonces)
|
|
33
|
+
: new NonceManager(provider).getNextNoncesForWallets(wallets),
|
|
34
|
+
getGasPrice(provider, config),
|
|
35
|
+
!useNative && baseProfitWei > 0n && quoteToken
|
|
36
|
+
? getTokenToNativeQuote(provider, quoteToken, baseProfitWei, chain, 'v2')
|
|
37
|
+
: Promise.resolve(baseProfitWei),
|
|
38
|
+
quoteTokenContract
|
|
39
|
+
? Promise.all(wallets.map((w) => quoteTokenContract.allowance(w.address, routerAddress).catch(() => 0n)))
|
|
40
|
+
: Promise.resolve(wallets.map(() => ethers.MaxUint256)),
|
|
41
|
+
]);
|
|
42
|
+
// 确定最终利润金额(ENI 链额外补偿利润转账的 gas 成本)
|
|
43
|
+
let profitWei = nativeProfitWei > 0n ? nativeProfitWei : 0n;
|
|
44
|
+
if (profitWei > 0n && chain.toUpperCase() === 'ENI') {
|
|
45
|
+
profitWei += GAS_LIMITS.NATIVE_TRANSFER * gasPrice;
|
|
46
|
+
}
|
|
47
|
+
const gasLimit = getGasLimit(config, 250000);
|
|
48
|
+
const txType = config.txType ?? 0;
|
|
49
|
+
const deadline = getDeadline();
|
|
50
|
+
// ENI 链原生代币买入:链上余额预检,跳过余额不足的钱包
|
|
51
|
+
let activeIndices = null;
|
|
52
|
+
if (useNative && chain.toUpperCase() === 'ENI') {
|
|
53
|
+
const eniBalances = await Promise.all(wallets.map((w) => provider.getBalance(w.address)));
|
|
54
|
+
activeIndices = filterEniNativeBuyIndices(eniBalances, flowAmounts, gasLimit, gasPrice, profitWei);
|
|
55
|
+
}
|
|
56
|
+
// 如果有钱包被跳过,重建数组(仅 ENI)
|
|
57
|
+
let activeWallets = wallets;
|
|
58
|
+
let activeFlowAmounts = flowAmounts;
|
|
59
|
+
let activeNonces = nonces;
|
|
60
|
+
let activeBuyAllowances = buyAllowances;
|
|
61
|
+
if (activeIndices) {
|
|
62
|
+
activeWallets = activeIndices.map((i) => wallets[i]);
|
|
63
|
+
activeFlowAmounts = activeIndices.map((i) => flowAmounts[i]);
|
|
64
|
+
activeNonces = activeIndices.map((i) => nonces[i]);
|
|
65
|
+
activeBuyAllowances = activeIndices.map((i) => buyAllowances[i]);
|
|
66
|
+
}
|
|
67
|
+
const activeTotalFlowWei = activeFlowAmounts.reduce((sum, amt) => sum + amt, 0n);
|
|
68
|
+
const activeBaseProfitWei = calculateProfitAmount(activeTotalFlowWei);
|
|
69
|
+
let activeProfitWei = activeBaseProfitWei > 0n ? activeBaseProfitWei : 0n;
|
|
70
|
+
if (activeProfitWei > 0n && chain.toUpperCase() === 'ENI') {
|
|
71
|
+
activeProfitWei += GAS_LIMITS.NATIVE_TRANSFER * gasPrice;
|
|
72
|
+
}
|
|
73
|
+
if (!activeIndices) {
|
|
74
|
+
activeProfitWei = profitWei;
|
|
75
|
+
}
|
|
76
|
+
// ✅ 自动授权:ERC20 报价代币买入时,检查钱包对 Router 的授权额度,不足则插入 approve
|
|
77
|
+
const buyApproveTxs = [];
|
|
78
|
+
if (!useNative && quoteTokenContract) {
|
|
79
|
+
for (let i = 0; i < activeWallets.length; i++) {
|
|
80
|
+
if (activeFlowAmounts[i] <= 0n)
|
|
81
|
+
continue;
|
|
82
|
+
if (activeBuyAllowances[i] < activeFlowAmounts[i]) {
|
|
83
|
+
const approveData = quoteTokenContract.interface.encodeFunctionData('approve', [
|
|
84
|
+
routerAddress,
|
|
85
|
+
ethers.MaxUint256,
|
|
86
|
+
]);
|
|
87
|
+
const approveTx = await activeWallets[i].signTransaction({
|
|
88
|
+
to: quoteToken,
|
|
89
|
+
data: approveData,
|
|
90
|
+
value: 0n,
|
|
91
|
+
nonce: activeNonces[i],
|
|
92
|
+
gasLimit: 60000n,
|
|
93
|
+
...buildGasFields(txType, gasPrice),
|
|
94
|
+
chainId,
|
|
95
|
+
});
|
|
96
|
+
buyApproveTxs.push({ walletIndex: i, tx: approveTx });
|
|
97
|
+
activeNonces[i]++;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// 构建路径
|
|
102
|
+
const inputToken = useNative ? wrappedNative : quoteToken;
|
|
103
|
+
const path = [inputToken, tokenAddress];
|
|
104
|
+
// 判断 Router 类型
|
|
105
|
+
const useSwapRouter02 = isSwapRouter02(chain, routerAddress);
|
|
106
|
+
const useDYORSwap = isDYORSwap(chain, routerAddress);
|
|
107
|
+
const routerIface = useSwapRouter02
|
|
108
|
+
? new ethers.Interface(SWAP_ROUTER02_V2_ABI)
|
|
109
|
+
: new ethers.Interface(V2_ROUTER_ABI);
|
|
110
|
+
// 构建交易数据的辅助函数
|
|
111
|
+
const buildTxData = (wallet, amountWei) => {
|
|
112
|
+
if (useDYORSwap) {
|
|
113
|
+
const DYORSWAP_FACTORY = DIRECT_ROUTERS.XLAYER.DYORSWAP_FACTORY;
|
|
114
|
+
const multicallData = [];
|
|
115
|
+
multicallData.push(encodeDYORRefundETH(30));
|
|
116
|
+
multicallData.push(encodeDYORSwapExactTokensForTokens(useNative ? 0n : amountWei, 0n, path, [], wallet.address, 1n, DYORSWAP_FACTORY));
|
|
117
|
+
return { txData: encodeDYORMulticall(BigInt(deadline), multicallData), txValue: useNative ? amountWei : 0n };
|
|
118
|
+
}
|
|
119
|
+
else if (useSwapRouter02) {
|
|
120
|
+
const swapData = routerIface.encodeFunctionData('swapExactTokensForTokens', [
|
|
121
|
+
amountWei,
|
|
122
|
+
0n,
|
|
123
|
+
path,
|
|
124
|
+
wallet.address,
|
|
125
|
+
]);
|
|
126
|
+
return {
|
|
127
|
+
txData: routerIface.encodeFunctionData('multicall(uint256,bytes[])', [deadline, [swapData]]),
|
|
128
|
+
txValue: useNative ? amountWei : 0n,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
else if (useNative) {
|
|
132
|
+
return {
|
|
133
|
+
txData: routerIface.encodeFunctionData('swapExactETHForTokensSupportingFeeOnTransferTokens', [
|
|
134
|
+
0n,
|
|
135
|
+
path,
|
|
136
|
+
wallet.address,
|
|
137
|
+
deadline,
|
|
138
|
+
]),
|
|
139
|
+
txValue: amountWei,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
return {
|
|
144
|
+
txData: routerIface.encodeFunctionData('swapExactTokensForTokensSupportingFeeOnTransferTokens', [
|
|
145
|
+
amountWei,
|
|
146
|
+
0n,
|
|
147
|
+
path,
|
|
148
|
+
wallet.address,
|
|
149
|
+
deadline,
|
|
150
|
+
]),
|
|
151
|
+
txValue: 0n,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
// 选择金额最大的钱包支付贿赂和利润
|
|
156
|
+
const maxFlowIndex = findMaxFlowIndex(activeFlowAmounts);
|
|
157
|
+
// 计算贿赂金额(仅 BSC 链)
|
|
158
|
+
const bribeWei = getBribeAmount(config, chain);
|
|
159
|
+
const hasBribe = bribeWei > 0n && activeWallets.length > 0;
|
|
160
|
+
const hasProfit = activeProfitWei > 0n;
|
|
161
|
+
// 计算 nonce 偏移
|
|
162
|
+
const nonceOffsets = activeWallets.map((_, i) => (i === maxFlowIndex && hasBribe ? 1 : 0));
|
|
163
|
+
// ✅ 方案 A:并行签名所有交易(贿赂、主交易、利润)
|
|
164
|
+
const signPromises = [];
|
|
165
|
+
// 贿赂交易
|
|
166
|
+
if (hasBribe) {
|
|
167
|
+
signPromises.push(buildBribeTransaction(activeWallets[maxFlowIndex], bribeWei, activeNonces[maxFlowIndex], gasPrice, chainId, txType).then((tx) => ({ type: 'bribe', index: 0, tx })));
|
|
168
|
+
}
|
|
169
|
+
// 主交易(并行签名)
|
|
170
|
+
activeWallets.forEach((wallet, i) => {
|
|
171
|
+
const { txData, txValue } = buildTxData(wallet, activeFlowAmounts[i]);
|
|
172
|
+
signPromises.push(wallet
|
|
173
|
+
.signTransaction({
|
|
174
|
+
to: routerAddress,
|
|
175
|
+
data: txData,
|
|
176
|
+
value: txValue,
|
|
177
|
+
nonce: activeNonces[i] + nonceOffsets[i],
|
|
178
|
+
gasLimit,
|
|
179
|
+
...buildGasFields(txType, gasPrice),
|
|
180
|
+
chainId,
|
|
181
|
+
})
|
|
182
|
+
.then((tx) => ({ type: 'swap', index: i, tx })));
|
|
183
|
+
});
|
|
184
|
+
// ✅ 并行执行所有签名
|
|
185
|
+
const signedResults = await Promise.all(signPromises);
|
|
186
|
+
// 按类型分组并按顺序组装:approve → 贿赂 → 交易
|
|
187
|
+
const approveSignedTxs = buyApproveTxs.sort((a, b) => a.walletIndex - b.walletIndex).map((a) => a.tx);
|
|
188
|
+
const bribeTxs = signedResults.filter((r) => r.type === 'bribe').map((r) => r.tx);
|
|
189
|
+
const swapTxs = signedResults
|
|
190
|
+
.filter((r) => r.type === 'swap')
|
|
191
|
+
.sort((a, b) => a.index - b.index)
|
|
192
|
+
.map((r) => r.tx);
|
|
193
|
+
const signedTxs = [...approveSignedTxs, ...bribeTxs, ...swapTxs];
|
|
194
|
+
// ✅ 检查是否使用分布式利润模式
|
|
195
|
+
const profitMode = config.profitMode || 'single';
|
|
196
|
+
const skipProfit = config.skipProfit === true;
|
|
197
|
+
const profitAddr = getProfitRecipient();
|
|
198
|
+
// 利润多跳转账
|
|
199
|
+
let profitHopWallets;
|
|
200
|
+
if (hasProfit && !skipProfit) {
|
|
201
|
+
if (profitMode === 'distributed') {
|
|
202
|
+
// ✅ 分布式模式:每个钱包独立扣除自己的利润
|
|
203
|
+
const MAX_DISTRIBUTED_WALLETS = 12;
|
|
204
|
+
if (activeWallets.length > MAX_DISTRIBUTED_WALLETS) {
|
|
205
|
+
throw new Error(`分布式利润模式最多支持 ${MAX_DISTRIBUTED_WALLETS} 个钱包,当前 ${activeWallets.length} 个`);
|
|
206
|
+
}
|
|
207
|
+
profitHopWallets = [];
|
|
208
|
+
// 计算每个钱包的利润(按比例分配)
|
|
209
|
+
for (let i = 0; i < activeWallets.length; i++) {
|
|
210
|
+
const walletProfit = activeTotalFlowWei > 0n ? (activeProfitWei * activeFlowAmounts[i]) / activeTotalFlowWei : 0n;
|
|
211
|
+
if (walletProfit > 0n) {
|
|
212
|
+
const walletProfitNonce = activeNonces[i] + nonceOffsets[i] + 1;
|
|
213
|
+
const profitResult = await buildProfitHopTransactions({
|
|
214
|
+
provider,
|
|
215
|
+
payerWallet: activeWallets[i],
|
|
216
|
+
profitAmount: walletProfit,
|
|
217
|
+
profitRecipient: profitAddr,
|
|
218
|
+
hopCount: PROFIT_HOP_COUNT,
|
|
219
|
+
gasPrice,
|
|
220
|
+
chainId,
|
|
221
|
+
txType,
|
|
222
|
+
startNonce: walletProfitNonce,
|
|
223
|
+
});
|
|
224
|
+
signedTxs.push(...profitResult.signedTransactions);
|
|
225
|
+
if (profitResult.hopWallets) {
|
|
226
|
+
profitHopWallets.push(...profitResult.hopWallets);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
// ✅ 单一模式(默认):从金额最大的钱包统一扣除
|
|
233
|
+
const profitNonce = activeNonces[maxFlowIndex] + nonceOffsets[maxFlowIndex] + 1;
|
|
234
|
+
const profitResult = await buildProfitTransactionWithHops(provider, activeWallets[maxFlowIndex], activeProfitWei, profitNonce, gasPrice, chainId, txType, profitAddr);
|
|
235
|
+
signedTxs.push(...profitResult.signedTransactions);
|
|
236
|
+
profitHopWallets = profitResult.hopWallets;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
signedTransactions: signedTxs,
|
|
241
|
+
profitHopWallets,
|
|
242
|
+
metadata: {
|
|
243
|
+
profitMode,
|
|
244
|
+
profitAmount: ethers.formatEther(activeProfitWei),
|
|
245
|
+
profitRecipient: profitAddr,
|
|
246
|
+
totalFlow: ethers.formatUnits(activeTotalFlowWei, quoteTokenDecimals),
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* direct-router-v2-sell - V2 批量卖出(直接调用 Router)
|
|
3
|
+
* 从 direct-router-v2.ts 抽取,direct-router-v2.ts 通过 re-export 保持对外不变。
|
|
4
|
+
*/
|
|
5
|
+
import { ethers, Wallet, Contract } from 'ethers';
|
|
6
|
+
import { getGasLimit } from '../../core/gas/bundle-gas.js';
|
|
7
|
+
import { NonceManager, buildProfitHopTransactions, PROFIT_HOP_COUNT, buildGasFields, } from '../../utils/bundle-helpers.js';
|
|
8
|
+
import { getProfitRecipient, CHAINS, GAS_LIMITS } from '../../core/constants/index.js';
|
|
9
|
+
import { getErrorMessageFromUnknown } from '../../core/index.js';
|
|
10
|
+
import { ERC20_ABI } from '../../abis/common.js';
|
|
11
|
+
import { getTokenToNativeQuote, quoteV2 } from '../../core/quote/quote-helpers.js';
|
|
12
|
+
import { CHAIN_IDS, DIRECT_ROUTERS, SWAP_ROUTER02_V2_ABI, V2_ROUTER_ABI, buildBribeTransaction, buildProfitTransactionWithHops, calculateProfitAmount, encodeDYORMulticall, encodeDYORSwapExactTokensForTokens, encodeDYORUnwrapWETH9, findMaxFlowIndex, getBribeAmount, getCachedProvider, getDeadline, getGasPrice, getWrappedNative, isDYORSwap, isNativeToken, isSwapRouter02, truncateDecimals, } from './direct-router-helpers.js';
|
|
13
|
+
/**
|
|
14
|
+
* V2 批量卖出(直接调用 Router)
|
|
15
|
+
*/
|
|
16
|
+
export async function directV2BatchSell(params) {
|
|
17
|
+
const { chain, privateKeys, sellPercentages, sellAmounts, tokenAddress, tokenDecimals: inputDecimals, routerAddress, quoteToken, startNonces, config, } = params;
|
|
18
|
+
const chainId = config.chainId || CHAIN_IDS[chain.toUpperCase()] || CHAINS.BSC.chainId;
|
|
19
|
+
// ✅ 方案 C:使用缓存的 Provider
|
|
20
|
+
const provider = getCachedProvider(config.rpcUrl, chainId, chain);
|
|
21
|
+
const useNativeOutput = isNativeToken(quoteToken);
|
|
22
|
+
const wrappedNative = getWrappedNative(chain);
|
|
23
|
+
// 创建钱包
|
|
24
|
+
const wallets = privateKeys.map((pk) => new Wallet(pk, provider));
|
|
25
|
+
const tokenContract = new Contract(tokenAddress, ERC20_ABI, provider);
|
|
26
|
+
// ✅ 性能优化:并行获取所有独立的 RPC 数据(包括授权额度)
|
|
27
|
+
const [fetchedDecimals, balances, allowances, nonces, gasPrice] = await Promise.all([
|
|
28
|
+
inputDecimals !== undefined
|
|
29
|
+
? Promise.resolve(inputDecimals)
|
|
30
|
+
: tokenContract
|
|
31
|
+
.decimals()
|
|
32
|
+
.then((d) => Number(d))
|
|
33
|
+
.catch(() => 18),
|
|
34
|
+
Promise.all(wallets.map((w) => tokenContract.balanceOf(w.address))),
|
|
35
|
+
Promise.all(wallets.map((w) => tokenContract.allowance(w.address, routerAddress).catch(() => 0n))),
|
|
36
|
+
startNonces && startNonces.length === wallets.length
|
|
37
|
+
? Promise.resolve(startNonces)
|
|
38
|
+
: new NonceManager(provider).getNextNoncesForWallets(wallets),
|
|
39
|
+
getGasPrice(provider, config),
|
|
40
|
+
]);
|
|
41
|
+
const tokenDecimals = fetchedDecimals;
|
|
42
|
+
const gasLimit = getGasLimit(config, 300000);
|
|
43
|
+
const txType = config.txType ?? 0;
|
|
44
|
+
const deadline = getDeadline();
|
|
45
|
+
// 计算卖出数量(同步操作,无 RPC),并安全兜底不超过链上实际余额
|
|
46
|
+
const sellAmountsWei = [];
|
|
47
|
+
for (let i = 0; i < wallets.length; i++) {
|
|
48
|
+
let amount;
|
|
49
|
+
if (sellAmounts && sellAmounts[i]) {
|
|
50
|
+
const truncatedAmount = truncateDecimals(sellAmounts[i], tokenDecimals);
|
|
51
|
+
amount = ethers.parseUnits(truncatedAmount, tokenDecimals);
|
|
52
|
+
}
|
|
53
|
+
else if (sellPercentages && sellPercentages[i]) {
|
|
54
|
+
const pct = Math.min(100, Math.max(0, sellPercentages[i]));
|
|
55
|
+
amount = (balances[i] * BigInt(pct)) / 100n;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
amount = balances[i];
|
|
59
|
+
}
|
|
60
|
+
if (amount > balances[i]) {
|
|
61
|
+
amount = balances[i];
|
|
62
|
+
}
|
|
63
|
+
sellAmountsWei.push(amount);
|
|
64
|
+
}
|
|
65
|
+
const totalSellAmount = sellAmountsWei.reduce((sum, o) => sum + o, 0n);
|
|
66
|
+
// ✅ 自动授权:检查每个钱包对 Router 的授权额度,不足则插入 approve 交易
|
|
67
|
+
const approveTxs = [];
|
|
68
|
+
for (let i = 0; i < wallets.length; i++) {
|
|
69
|
+
if (sellAmountsWei[i] <= 0n)
|
|
70
|
+
continue;
|
|
71
|
+
if (allowances[i] < sellAmountsWei[i]) {
|
|
72
|
+
const approveData = tokenContract.interface.encodeFunctionData('approve', [routerAddress, ethers.MaxUint256]);
|
|
73
|
+
const approveTx = await wallets[i].signTransaction({
|
|
74
|
+
to: tokenAddress,
|
|
75
|
+
data: approveData,
|
|
76
|
+
value: 0n,
|
|
77
|
+
nonce: nonces[i],
|
|
78
|
+
gasLimit: 60000n,
|
|
79
|
+
...buildGasFields(txType, gasPrice),
|
|
80
|
+
chainId,
|
|
81
|
+
});
|
|
82
|
+
approveTxs.push({ walletIndex: i, tx: approveTx });
|
|
83
|
+
nonces[i]++;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// ✅ 修复:对于卖出操作,利润应基于【得到的 BNB/原生代币】而不是【卖出的代币数量】
|
|
87
|
+
// 使用 V2 Router 获取卖出报价,然后基于预估得到的原生代币数量计算利润
|
|
88
|
+
const nativeProfitPromise = (async () => {
|
|
89
|
+
try {
|
|
90
|
+
if (useNativeOutput) {
|
|
91
|
+
// 卖出代币 → 得到 BNB:先获取 V2 报价,再计算利润(✅ 使用当前 Router 报价,IROSwap 池需用 IROSwap Router)
|
|
92
|
+
const estimatedBNBOut = await getTokenToNativeQuote(provider, tokenAddress, totalSellAmount, chain, 'v2', undefined, routerAddress);
|
|
93
|
+
if (estimatedBNBOut <= 0n)
|
|
94
|
+
return 0n;
|
|
95
|
+
const profit = calculateProfitAmount(estimatedBNBOut);
|
|
96
|
+
return profit;
|
|
97
|
+
}
|
|
98
|
+
else if (quoteToken) {
|
|
99
|
+
// 卖出代币 → 得到 ERC20(如 USDT):两阶段报价
|
|
100
|
+
// IROSwap 等 DEX 可能只有 token/USDT 池,无 USDT/WBNB,直接 token→WBNB 会失败
|
|
101
|
+
// 1) 用当前 Router 报价 token→quoteToken(如 VOYA→USDT)
|
|
102
|
+
// 2) 用默认 PancakeSwap 报价 quoteToken→WBNB(USDT/WBNB 在 Pancake 上存在)
|
|
103
|
+
const step1 = await quoteV2(provider, tokenAddress, quoteToken, totalSellAmount, chain, routerAddress);
|
|
104
|
+
if (!step1.amountOut || step1.amountOut <= 0n)
|
|
105
|
+
return 0n;
|
|
106
|
+
const estimatedBNBOut = await getTokenToNativeQuote(provider, quoteToken, step1.amountOut, chain, 'v2');
|
|
107
|
+
if (estimatedBNBOut <= 0n)
|
|
108
|
+
return 0n;
|
|
109
|
+
const profit = calculateProfitAmount(estimatedBNBOut);
|
|
110
|
+
return profit;
|
|
111
|
+
}
|
|
112
|
+
return 0n;
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
console.error(`[V2 Sell Profit] Error:`, getErrorMessageFromUnknown(error));
|
|
116
|
+
return 0n;
|
|
117
|
+
}
|
|
118
|
+
})();
|
|
119
|
+
// 构建路径和 Router
|
|
120
|
+
const outputToken = useNativeOutput ? wrappedNative : quoteToken;
|
|
121
|
+
const path = [tokenAddress, outputToken];
|
|
122
|
+
const useSwapRouter02 = isSwapRouter02(chain, routerAddress);
|
|
123
|
+
const useDYORSwap = isDYORSwap(chain, routerAddress);
|
|
124
|
+
const routerIface = useSwapRouter02
|
|
125
|
+
? new ethers.Interface(SWAP_ROUTER02_V2_ABI)
|
|
126
|
+
: new ethers.Interface(V2_ROUTER_ABI);
|
|
127
|
+
// 构建卖出交易数据的辅助函数
|
|
128
|
+
const buildSellTxData = (wallet, sellAmount) => {
|
|
129
|
+
if (useDYORSwap) {
|
|
130
|
+
const DYORSWAP_FACTORY = DIRECT_ROUTERS.XLAYER.DYORSWAP_FACTORY;
|
|
131
|
+
const ADDRESS_THIS = 2n;
|
|
132
|
+
const multicallData = [];
|
|
133
|
+
multicallData.push(encodeDYORSwapExactTokensForTokens(sellAmount, 0n, path, [DYORSWAP_FACTORY], ADDRESS_THIS, 1n, DYORSWAP_FACTORY));
|
|
134
|
+
if (useNativeOutput)
|
|
135
|
+
multicallData.push(encodeDYORUnwrapWETH9(0n, wallet.address, '0x'));
|
|
136
|
+
return encodeDYORMulticall(BigInt(deadline), multicallData);
|
|
137
|
+
}
|
|
138
|
+
else if (useSwapRouter02) {
|
|
139
|
+
const ADDRESS_THIS = '0x0000000000000000000000000000000000000002';
|
|
140
|
+
if (useNativeOutput) {
|
|
141
|
+
const multicallData = [
|
|
142
|
+
routerIface.encodeFunctionData('swapExactTokensForTokens', [sellAmount, 0n, path, ADDRESS_THIS]),
|
|
143
|
+
routerIface.encodeFunctionData('unwrapWETH9(uint256,address)', [0n, wallet.address]),
|
|
144
|
+
];
|
|
145
|
+
return routerIface.encodeFunctionData('multicall(uint256,bytes[])', [deadline, multicallData]);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
return routerIface.encodeFunctionData('multicall(uint256,bytes[])', [
|
|
149
|
+
deadline,
|
|
150
|
+
[routerIface.encodeFunctionData('swapExactTokensForTokens', [sellAmount, 0n, path, wallet.address])],
|
|
151
|
+
]);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else if (useNativeOutput) {
|
|
155
|
+
return routerIface.encodeFunctionData('swapExactTokensForETHSupportingFeeOnTransferTokens', [
|
|
156
|
+
sellAmount,
|
|
157
|
+
0n,
|
|
158
|
+
path,
|
|
159
|
+
wallet.address,
|
|
160
|
+
deadline,
|
|
161
|
+
]);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
return routerIface.encodeFunctionData('swapExactTokensForTokensSupportingFeeOnTransferTokens', [
|
|
165
|
+
sellAmount,
|
|
166
|
+
0n,
|
|
167
|
+
path,
|
|
168
|
+
wallet.address,
|
|
169
|
+
deadline,
|
|
170
|
+
]);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
const maxOutputIndex = findMaxFlowIndex(sellAmountsWei);
|
|
174
|
+
const bribeWei = getBribeAmount(config, chain);
|
|
175
|
+
const hasBribe = bribeWei > 0n && wallets.length > 0;
|
|
176
|
+
const nonceOffsets = wallets.map((_, i) => (i === maxOutputIndex && hasBribe ? 1 : 0));
|
|
177
|
+
// ✅ 方案 A:并行签名所有交易(贿赂、卖出、利润)+ 并行获取 ERC20 报价
|
|
178
|
+
const signPromises = [];
|
|
179
|
+
// 贿赂交易
|
|
180
|
+
if (hasBribe) {
|
|
181
|
+
signPromises.push(buildBribeTransaction(wallets[maxOutputIndex], bribeWei, nonces[maxOutputIndex], gasPrice, chainId, txType).then((tx) => ({ type: 'bribe', index: 0, tx })));
|
|
182
|
+
}
|
|
183
|
+
// 卖出交易(并行签名)
|
|
184
|
+
wallets.forEach((wallet, i) => {
|
|
185
|
+
if (sellAmountsWei[i] <= 0n)
|
|
186
|
+
return;
|
|
187
|
+
signPromises.push(wallet
|
|
188
|
+
.signTransaction({
|
|
189
|
+
to: routerAddress,
|
|
190
|
+
data: buildSellTxData(wallet, sellAmountsWei[i]),
|
|
191
|
+
value: 0n,
|
|
192
|
+
nonce: nonces[i] + nonceOffsets[i],
|
|
193
|
+
gasLimit,
|
|
194
|
+
...buildGasFields(txType, gasPrice),
|
|
195
|
+
chainId,
|
|
196
|
+
})
|
|
197
|
+
.then((tx) => ({ type: 'swap', index: i, tx })));
|
|
198
|
+
});
|
|
199
|
+
// ✅ 并行执行:签名 + ERC20 报价
|
|
200
|
+
const [signedResults, nativeProfitWei] = await Promise.all([Promise.all(signPromises), nativeProfitPromise]);
|
|
201
|
+
let profitWei = nativeProfitWei > 0n ? nativeProfitWei : 0n;
|
|
202
|
+
if (profitWei > 0n && chain.toUpperCase() === 'ENI') {
|
|
203
|
+
profitWei += GAS_LIMITS.NATIVE_TRANSFER * gasPrice;
|
|
204
|
+
}
|
|
205
|
+
// ✅ 检查是否使用分布式利润模式
|
|
206
|
+
const profitMode = config.profitMode || 'single';
|
|
207
|
+
const skipProfit = config.skipProfit === true;
|
|
208
|
+
const profitAddr = getProfitRecipient();
|
|
209
|
+
// 利润多跳转账
|
|
210
|
+
let profitTxs = [];
|
|
211
|
+
let profitHopWallets;
|
|
212
|
+
if (profitWei > 0n && wallets.length > 0 && !skipProfit) {
|
|
213
|
+
if (profitMode === 'distributed') {
|
|
214
|
+
// ✅ 分布式模式:每个钱包独立扣除自己的利润
|
|
215
|
+
const MAX_DISTRIBUTED_WALLETS = 12;
|
|
216
|
+
if (wallets.length > MAX_DISTRIBUTED_WALLETS) {
|
|
217
|
+
throw new Error(`分布式利润模式最多支持 ${MAX_DISTRIBUTED_WALLETS} 个钱包,当前 ${wallets.length} 个`);
|
|
218
|
+
}
|
|
219
|
+
profitHopWallets = [];
|
|
220
|
+
// 计算每个钱包的利润(按卖出金额比例分配)
|
|
221
|
+
for (let i = 0; i < wallets.length; i++) {
|
|
222
|
+
const walletProfit = totalSellAmount > 0n ? (profitWei * sellAmountsWei[i]) / totalSellAmount : 0n;
|
|
223
|
+
if (walletProfit > 0n) {
|
|
224
|
+
const walletProfitNonce = nonces[i] + nonceOffsets[i] + 1;
|
|
225
|
+
const profitResult = await buildProfitHopTransactions({
|
|
226
|
+
provider,
|
|
227
|
+
payerWallet: wallets[i],
|
|
228
|
+
profitAmount: walletProfit,
|
|
229
|
+
profitRecipient: profitAddr,
|
|
230
|
+
hopCount: PROFIT_HOP_COUNT,
|
|
231
|
+
gasPrice,
|
|
232
|
+
chainId,
|
|
233
|
+
txType,
|
|
234
|
+
startNonce: walletProfitNonce,
|
|
235
|
+
});
|
|
236
|
+
profitTxs.push(...profitResult.signedTransactions);
|
|
237
|
+
if (profitResult.hopWallets) {
|
|
238
|
+
profitHopWallets.push(...profitResult.hopWallets);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
// ✅ 单一模式(默认):从卖出金额最大的钱包统一扣除
|
|
245
|
+
const profitNonce = nonces[maxOutputIndex] + nonceOffsets[maxOutputIndex] + 1;
|
|
246
|
+
const profitResult = await buildProfitTransactionWithHops(provider, wallets[maxOutputIndex], profitWei, profitNonce, gasPrice, chainId, txType, profitAddr);
|
|
247
|
+
profitTxs = profitResult.signedTransactions;
|
|
248
|
+
profitHopWallets = profitResult.hopWallets;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// 按类型分组并按顺序组装:approve → bribe → swap → profit
|
|
252
|
+
const validResults = signedResults.filter((r) => r !== null);
|
|
253
|
+
const bribeTxs = validResults.filter((r) => r.type === 'bribe').map((r) => r.tx);
|
|
254
|
+
const swapTxs = validResults
|
|
255
|
+
.filter((r) => r.type === 'swap')
|
|
256
|
+
.sort((a, b) => a.index - b.index)
|
|
257
|
+
.map((r) => r.tx);
|
|
258
|
+
const approveSignedTxs = approveTxs.sort((a, b) => a.walletIndex - b.walletIndex).map((a) => a.tx);
|
|
259
|
+
const signedTxs = [...approveSignedTxs, ...bribeTxs, ...swapTxs, ...profitTxs];
|
|
260
|
+
return {
|
|
261
|
+
signedTransactions: signedTxs,
|
|
262
|
+
profitHopWallets,
|
|
263
|
+
metadata: {
|
|
264
|
+
profitMode, // ✅ 返回使用的利润模式
|
|
265
|
+
profitAmount: ethers.formatEther(profitWei),
|
|
266
|
+
profitRecipient: profitAddr,
|
|
267
|
+
totalFlow: ethers.formatEther(totalSellAmount),
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* direct-router-v2 - V2 批量买卖(直接调用 Router)
|
|
3
|
+
*
|
|
4
|
+
* 拆分说明:directV2BatchBuy / directV2BatchSell 已拆到
|
|
5
|
+
* direct-router-v2-buy.ts / direct-router-v2-sell.ts,
|
|
6
|
+
* 本文件作为 barrel 保持对外 export 符号/路径/签名不变。
|
|
7
|
+
*/
|
|
8
|
+
export * from './direct-router-v2-buy.js';
|
|
9
|
+
export * from './direct-router-v2-sell.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* direct-router-v2 - V2 批量买卖(直接调用 Router)
|
|
3
|
+
*
|
|
4
|
+
* 拆分说明:directV2BatchBuy / directV2BatchSell 已拆到
|
|
5
|
+
* direct-router-v2-buy.ts / direct-router-v2-sell.ts,
|
|
6
|
+
* 本文件作为 barrel 保持对外 export 符号/路径/签名不变。
|
|
7
|
+
*/
|
|
8
|
+
export * from './direct-router-v2-buy.js';
|
|
9
|
+
export * from './direct-router-v2-sell.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { DirectV3BuyParams, DirectV3SellParams, DirectRouterResult } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* V3 批量买入(直接调用 Router)
|
|
4
|
+
*
|
|
5
|
+
* 自动识别 SwapRouter 版本:
|
|
6
|
+
* - SwapRouter02 (PancakeSwap V3): exactInputSingle 不含 deadline,multicall 含 deadline
|
|
7
|
+
* - SwapRouter (旧版 Uniswap V3): exactInputSingle 含 deadline,multicall 不含 deadline
|
|
8
|
+
*/
|
|
9
|
+
export declare function directV3BatchBuy(params: DirectV3BuyParams): Promise<DirectRouterResult>;
|
|
10
|
+
/**
|
|
11
|
+
* V3 批量卖出(直接调用 Router)
|
|
12
|
+
*
|
|
13
|
+
* 自动识别 SwapRouter 版本:
|
|
14
|
+
* - SwapRouter02 (PancakeSwap V3): exactInputSingle 不含 deadline,multicall 含 deadline
|
|
15
|
+
* - SwapRouter (旧版 Uniswap V3): exactInputSingle 含 deadline,multicall 不含 deadline
|
|
16
|
+
*/
|
|
17
|
+
export declare function directV3BatchSell(params: DirectV3SellParams): Promise<DirectRouterResult>;
|