four-flap-meme-sdk 3.0.1 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle/four-meme/approve-tokenmanager.d.ts +2 -2
- package/dist/bundle/four-meme/approve-tokenmanager.js +3 -3
- package/dist/bundle/four-meme/core/buy-flow.d.ts +5 -0
- package/dist/bundle/four-meme/core/buy-flow.js +147 -0
- package/dist/bundle/four-meme/core/constants.d.ts +6 -0
- package/dist/bundle/four-meme/core/constants.js +15 -0
- package/dist/bundle/four-meme/core/create-token.d.ts +5 -0
- package/dist/bundle/four-meme/core/create-token.js +137 -0
- package/dist/bundle/four-meme/core/index.d.ts +14 -0
- package/dist/bundle/four-meme/core/index.js +14 -0
- package/dist/bundle/four-meme/core/sell-flow.d.ts +5 -0
- package/dist/bundle/four-meme/core/sell-flow.js +240 -0
- package/dist/bundle/four-meme/core-helpers.js +1 -1
- package/dist/bundle/four-meme/core.d.ts +7 -4
- package/dist/bundle/four-meme/core.js +5 -513
- package/dist/bundle/four-meme/pancake-proxy/approve.d.ts +15 -0
- package/dist/bundle/four-meme/pancake-proxy/approve.js +113 -0
- package/dist/bundle/four-meme/pancake-proxy/buy.d.ts +8 -0
- package/dist/bundle/four-meme/pancake-proxy/buy.js +143 -0
- package/dist/bundle/four-meme/pancake-proxy/constants.d.ts +25 -0
- package/dist/bundle/four-meme/pancake-proxy/constants.js +14 -0
- package/dist/bundle/four-meme/pancake-proxy/helpers.d.ts +45 -0
- package/dist/bundle/four-meme/pancake-proxy/helpers.js +232 -0
- package/dist/bundle/four-meme/pancake-proxy/index.d.ts +15 -0
- package/dist/bundle/four-meme/pancake-proxy/index.js +15 -0
- package/dist/bundle/four-meme/pancake-proxy/sell.d.ts +8 -0
- package/dist/bundle/four-meme/pancake-proxy/sell.js +194 -0
- package/dist/bundle/four-meme/pancake-proxy.d.ts +4 -20
- package/dist/bundle/four-meme/pancake-proxy.js +3 -670
- package/dist/bundle/four-meme/private/buy.d.ts +16 -0
- package/dist/bundle/four-meme/private/buy.js +225 -0
- package/dist/bundle/four-meme/private/index.d.ts +11 -0
- package/dist/bundle/four-meme/private/index.js +11 -0
- package/dist/bundle/four-meme/private/sell.d.ts +18 -0
- package/dist/bundle/four-meme/private/sell.js +245 -0
- package/dist/bundle/four-meme/private.d.ts +5 -25
- package/dist/bundle/four-meme/private.js +5 -463
- package/dist/bundle/four-meme/swap/batch.d.ts +8 -0
- package/dist/bundle/four-meme/swap/batch.js +170 -0
- package/dist/bundle/four-meme/swap/bundle.d.ts +8 -0
- package/dist/bundle/four-meme/swap/bundle.js +147 -0
- package/dist/bundle/four-meme/swap/index.d.ts +14 -0
- package/dist/bundle/four-meme/swap/index.js +13 -0
- package/dist/bundle/four-meme/swap/quick-batch.d.ts +8 -0
- package/dist/bundle/four-meme/swap/quick-batch.js +206 -0
- package/dist/bundle/four-meme/swap-buy-first/helpers.d.ts +20 -0
- package/dist/bundle/four-meme/swap-buy-first/helpers.js +39 -0
- package/dist/bundle/four-meme/swap-buy-first/index.d.ts +12 -0
- package/dist/bundle/four-meme/swap-buy-first/index.js +11 -0
- package/dist/bundle/four-meme/swap-buy-first/multi-wallet.d.ts +20 -0
- package/dist/bundle/four-meme/swap-buy-first/multi-wallet.js +198 -0
- package/dist/bundle/four-meme/swap-buy-first/single.d.ts +7 -0
- package/dist/bundle/four-meme/swap-buy-first/single.js +232 -0
- package/dist/bundle/four-meme/swap-buy-first.d.ts +4 -3
- package/dist/bundle/four-meme/swap-buy-first.js +4 -451
- package/dist/bundle/four-meme/swap-hop-helpers.d.ts +2 -2
- package/dist/bundle/four-meme/swap-sign-helpers.d.ts +2 -2
- package/dist/bundle/four-meme/swap-sign-helpers.js +1 -1
- package/dist/bundle/four-meme/swap.d.ts +4 -14
- package/dist/bundle/four-meme/swap.js +4 -502
- package/dist/bundle/four-meme/types/index.d.ts +1 -1
- package/dist/bundle/four-meme/utils-disperse.d.ts +1 -1
- package/dist/bundle/four-meme/utils-disperse.js +1 -1
- package/dist/bundle/four-meme/utils-pairwise.d.ts +1 -1
- package/dist/bundle/four-meme/utils-pairwise.js +1 -1
- package/dist/bundle/four-meme/utils-sweep/context.d.ts +39 -0
- package/dist/bundle/four-meme/utils-sweep/context.js +7 -0
- package/dist/bundle/four-meme/utils-sweep/erc20-no-hop.d.ts +5 -0
- package/dist/bundle/four-meme/utils-sweep/erc20-no-hop.js +162 -0
- package/dist/bundle/four-meme/utils-sweep/index.d.ts +13 -0
- package/dist/bundle/four-meme/utils-sweep/index.js +13 -0
- package/dist/bundle/four-meme/utils-sweep/main.d.ts +8 -0
- package/dist/bundle/four-meme/utils-sweep/main.js +114 -0
- package/dist/bundle/four-meme/utils-sweep/native-no-hop.d.ts +5 -0
- package/dist/bundle/four-meme/utils-sweep/native-no-hop.js +156 -0
- package/dist/bundle/four-meme/utils-sweep/with-hops.d.ts +6 -0
- package/dist/bundle/four-meme/utils-sweep/with-hops.js +382 -0
- package/dist/bundle/four-meme/utils-sweep.d.ts +3 -4
- package/dist/bundle/four-meme/utils-sweep.js +3 -740
- package/dist/bundle/internal.d.ts +2 -2
- package/dist/bundle/sign-context-helpers.d.ts +1 -26
- package/dist/bundle/sign-context-helpers.js +1 -63
- package/dist/bundle/submit/blockrazor.d.ts +94 -0
- package/dist/bundle/submit/blockrazor.js +122 -0
- package/dist/bundle/submit/direct.d.ts +118 -0
- package/dist/bundle/submit/direct.js +484 -0
- package/dist/bundle/submit/helpers.d.ts +7 -0
- package/dist/bundle/submit/helpers.js +15 -0
- package/dist/bundle/submit/index.d.ts +14 -0
- package/dist/bundle/submit/index.js +14 -0
- package/dist/bundle/submit/merkle.d.ts +84 -0
- package/dist/bundle/submit/merkle.js +121 -0
- package/dist/bundle/submit.d.ts +3 -286
- package/dist/bundle/submit.js +3 -724
- package/dist/chains/bsc/four/types.d.ts +1 -1
- package/dist/chains/bsc/pancake/bundle-buy-first-build.d.ts +25 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-build.js +177 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-constants.d.ts +30 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-constants.js +24 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-helpers.d.ts +11 -149
- package/dist/chains/bsc/pancake/bundle-buy-first-helpers.js +12 -74
- package/dist/chains/bsc/pancake/bundle-buy-first-multi-wallet.d.ts +9 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-multi-wallet.js +225 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-plan.d.ts +14 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-plan.js +64 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-profit.d.ts +12 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-profit.js +22 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-quote.d.ts +15 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-quote.js +122 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-types.d.ts +179 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-types.js +1 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-validate.d.ts +2 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-validate.js +41 -0
- package/dist/chains/bsc/pancake/bundle-buy-first.d.ts +1 -1
- package/dist/chains/bsc/pancake/bundle-buy-first.js +8 -578
- package/dist/chains/bsc/pancake/bundle-swap-helpers.d.ts +11 -239
- package/dist/chains/bsc/pancake/bundle-swap-helpers.js +12 -564
- package/dist/chains/bsc/pancake/bundle-swap-types.d.ts +183 -0
- package/dist/chains/bsc/pancake/bundle-swap-types.js +17 -0
- package/dist/chains/bsc/pancake/bundle-swap.d.ts +10 -132
- package/dist/chains/bsc/pancake/bundle-swap.js +12 -1003
- package/dist/chains/bsc/pancake/hop-chain.d.ts +18 -0
- package/dist/chains/bsc/pancake/hop-chain.js +227 -0
- package/dist/chains/bsc/pancake/quote.d.ts +14 -0
- package/dist/chains/bsc/pancake/quote.js +84 -0
- package/dist/chains/bsc/pancake/swap-batch.d.ts +42 -0
- package/dist/chains/bsc/pancake/swap-batch.js +283 -0
- package/dist/chains/bsc/pancake/swap-build.d.ts +19 -0
- package/dist/chains/bsc/pancake/swap-build.js +226 -0
- package/dist/chains/bsc/pancake/swap-cross.d.ts +42 -0
- package/dist/chains/bsc/pancake/swap-cross.js +140 -0
- package/dist/chains/bsc/pancake/swap-quick.d.ts +54 -0
- package/dist/chains/bsc/pancake/swap-quick.js +424 -0
- package/dist/chains/bsc/pancake/swap-single.d.ts +2 -0
- package/dist/chains/bsc/pancake/swap-single.js +182 -0
- package/dist/chains/bsc/platforms/four/index.d.ts +21 -3
- package/dist/chains/bsc/platforms/four/index.js +28 -3
- package/dist/chains/eni/batch-router/transfer-disperse.d.ts +37 -0
- package/dist/chains/eni/batch-router/transfer-disperse.js +302 -0
- package/dist/chains/eni/batch-router/transfer-shared.d.ts +9 -0
- package/dist/chains/eni/batch-router/transfer-shared.js +10 -0
- package/dist/chains/eni/batch-router/transfer-sweep.d.ts +51 -0
- package/dist/chains/eni/batch-router/transfer-sweep.js +364 -0
- package/dist/chains/eni/batch-router/transfer.d.ts +4 -74
- package/dist/chains/eni/batch-router/transfer.js +2 -647
- package/dist/chains/eni/platforms/daoaas/portal-direct-profit.d.ts +17 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct-profit.js +30 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct-submit.d.ts +12 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct-submit.js +396 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct-tx.d.ts +20 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct-tx.js +165 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct.d.ts +3 -32
- package/dist/chains/eni/platforms/daoaas/portal-direct.js +3 -571
- package/dist/chains/eni/submit.js +1 -1
- package/dist/chains/xlayer/constants.d.ts +0 -2
- package/dist/chains/xlayer/constants.js +0 -2
- package/dist/chains/xlayer/eip7702/auth.d.ts +16 -0
- package/dist/chains/xlayer/eip7702/auth.js +81 -0
- package/dist/chains/xlayer/eip7702/bundle-create-buy.d.ts +22 -0
- package/dist/chains/xlayer/eip7702/bundle-create-buy.js +201 -0
- package/dist/chains/xlayer/eip7702/bundle-create-helpers.d.ts +114 -0
- package/dist/chains/xlayer/eip7702/bundle-create-helpers.js +139 -0
- package/dist/chains/xlayer/eip7702/bundle-create-to-dex.d.ts +24 -0
- package/dist/chains/xlayer/eip7702/bundle-create-to-dex.js +233 -0
- package/dist/chains/xlayer/eip7702/bundle-create.d.ts +3 -35
- package/dist/chains/xlayer/eip7702/bundle-create.js +3 -746
- package/dist/chains/xlayer/eip7702/bundle-graduate-buy.d.ts +22 -0
- package/dist/chains/xlayer/eip7702/bundle-graduate-buy.js +214 -0
- package/dist/chains/xlayer/eip7702/bundle-sell.js +1 -1
- package/dist/chains/xlayer/eip7702/bundle-swap-batch.d.ts +31 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-batch.js +216 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-helpers.d.ts +21 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-helpers.js +206 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-multi.d.ts +33 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-multi.js +146 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-single.d.ts +31 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-single.js +177 -0
- package/dist/chains/xlayer/eip7702/bundle-swap.d.ts +6 -61
- package/dist/chains/xlayer/eip7702/bundle-swap.js +3 -712
- package/dist/chains/xlayer/eip7702/bytes.d.ts +4 -0
- package/dist/chains/xlayer/eip7702/bytes.js +31 -0
- package/dist/chains/xlayer/eip7702/gas.d.ts +19 -0
- package/dist/chains/xlayer/eip7702/gas.js +152 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-disperse.d.ts +5 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-disperse.js +196 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-pairwise.d.ts +5 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-pairwise.js +188 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-sweep.d.ts +5 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-sweep.js +220 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer.d.ts +8 -4
- package/dist/chains/xlayer/eip7702/multi-hop-transfer.js +5 -591
- package/dist/chains/xlayer/eip7702/profit.d.ts +32 -0
- package/dist/chains/xlayer/eip7702/profit.js +59 -0
- package/dist/chains/xlayer/eip7702/provider.d.ts +3 -0
- package/dist/chains/xlayer/eip7702/provider.js +17 -0
- package/dist/chains/xlayer/eip7702/time.d.ts +2 -0
- package/dist/chains/xlayer/eip7702/time.js +10 -0
- package/dist/chains/xlayer/eip7702/tx-build.d.ts +10 -0
- package/dist/chains/xlayer/eip7702/tx-build.js +128 -0
- package/dist/chains/xlayer/eip7702/utils.d.ts +19 -85
- package/dist/chains/xlayer/eip7702/utils.js +19 -484
- package/dist/chains/xlayer/eip7702/volume-bundle.d.ts +13 -0
- package/dist/chains/xlayer/eip7702/volume-bundle.js +250 -0
- package/dist/chains/xlayer/eip7702/volume-internal.d.ts +13 -0
- package/dist/chains/xlayer/eip7702/volume-internal.js +169 -0
- package/dist/chains/xlayer/eip7702/volume-make.d.ts +8 -0
- package/dist/chains/xlayer/eip7702/volume-make.js +38 -0
- package/dist/chains/xlayer/eip7702/volume-single-round.d.ts +17 -0
- package/dist/chains/xlayer/eip7702/volume-single-round.js +44 -0
- package/dist/chains/xlayer/eip7702/volume-swap.d.ts +18 -0
- package/dist/chains/xlayer/eip7702/volume-swap.js +30 -0
- package/dist/chains/xlayer/eip7702/volume-wash.d.ts +8 -0
- package/dist/chains/xlayer/eip7702/volume-wash.js +191 -0
- package/dist/chains/xlayer/eip7702/volume.d.ts +7 -35
- package/dist/chains/xlayer/eip7702/volume.js +5 -697
- package/dist/chains/xlayer/eip7702/wallet.d.ts +6 -0
- package/dist/chains/xlayer/eip7702/wallet.js +17 -0
- package/dist/chains/xlayer/eoa/aa-types.d.ts +176 -0
- package/dist/chains/xlayer/eoa/aa-types.js +6 -0
- package/dist/chains/xlayer/eoa/constants.d.ts +0 -2
- package/dist/chains/xlayer/eoa/constants.js +0 -2
- package/dist/chains/xlayer/eoa/context.d.ts +8 -0
- package/dist/chains/xlayer/eoa/context.js +23 -0
- package/dist/chains/xlayer/eoa/encoders.d.ts +147 -0
- package/dist/chains/xlayer/eoa/encoders.js +147 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-cross.d.ts +5 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-cross.js +113 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.d.ts +10 -123
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.js +10 -225
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-pure.d.ts +50 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-pure.js +170 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-quick.d.ts +5 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-quick.js +257 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-types.d.ts +99 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-types.js +11 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap.d.ts +5 -47
- package/dist/chains/xlayer/eoa/eoa-bundle-swap.js +3 -522
- package/dist/chains/xlayer/eoa/eoa-types.d.ts +776 -0
- package/dist/chains/xlayer/eoa/eoa-types.js +6 -0
- package/dist/chains/xlayer/eoa/eoa-wash-volume.d.ts +8 -0
- package/dist/chains/xlayer/eoa/eoa-wash-volume.js +8 -0
- package/dist/chains/xlayer/eoa/format.d.ts +34 -0
- package/dist/chains/xlayer/eoa/format.js +56 -0
- package/dist/chains/xlayer/eoa/hop-chain.d.ts +4 -0
- package/dist/chains/xlayer/eoa/hop-chain.js +87 -0
- package/dist/chains/xlayer/eoa/nonce-map.d.ts +20 -0
- package/dist/chains/xlayer/eoa/nonce-map.js +51 -0
- package/dist/chains/xlayer/eoa/portal-ops.d.ts +9 -292
- package/dist/chains/xlayer/eoa/portal-ops.js +9 -486
- package/dist/chains/xlayer/eoa/query.d.ts +117 -0
- package/dist/chains/xlayer/eoa/query.js +285 -0
- package/dist/chains/xlayer/eoa/quote.d.ts +6 -0
- package/dist/chains/xlayer/eoa/quote.js +90 -0
- package/dist/chains/xlayer/eoa/types.d.ts +9 -959
- package/dist/chains/xlayer/eoa/types.js +9 -49
- package/dist/core/clients/blockrazor.js +1 -1
- package/dist/core/clients/merkle.js +1 -1
- package/dist/core/erc20/allowances.d.ts +104 -0
- package/dist/core/erc20/allowances.js +205 -0
- package/dist/core/erc20/approve.d.ts +141 -0
- package/dist/core/erc20/approve.js +325 -0
- package/dist/core/erc20/helpers.d.ts +20 -0
- package/dist/core/erc20/helpers.js +109 -0
- package/dist/core/erc20/index.d.ts +13 -0
- package/dist/core/erc20/index.js +12 -0
- package/dist/core/gas/bundle-gas.d.ts +6 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/quote/index.d.ts +1 -0
- package/dist/core/quote/index.js +1 -0
- package/dist/core/quote/quote-helpers.d.ts +78 -0
- package/dist/core/quote/quote-helpers.js +289 -0
- package/dist/core/quote/types.d.ts +1 -0
- package/dist/core/quote/types.js +1 -0
- package/dist/core/sign-context-helpers.d.ts +29 -0
- package/dist/core/sign-context-helpers.js +63 -0
- package/dist/domains/dex/direct-router-helpers.d.ts +16 -268
- package/dist/domains/dex/direct-router-helpers.js +16 -535
- package/dist/domains/dex/direct-router-types.d.ts +104 -0
- package/dist/domains/dex/direct-router-types.js +81 -0
- package/dist/domains/dex/direct-router-v2-buy.d.ts +2 -0
- package/dist/domains/dex/direct-router-v2-buy.js +249 -0
- package/dist/domains/dex/direct-router-v2-sell.d.ts +5 -0
- package/dist/domains/dex/direct-router-v2-sell.js +270 -0
- package/dist/domains/dex/direct-router-v2.d.ts +9 -0
- package/dist/domains/dex/direct-router-v2.js +9 -0
- package/dist/domains/dex/direct-router-v3.d.ts +17 -0
- package/dist/domains/dex/direct-router-v3.js +432 -0
- package/dist/domains/dex/direct-router.d.ts +11 -26
- package/dist/domains/dex/direct-router.js +10 -977
- package/dist/domains/dex/dyo-encode.d.ts +62 -0
- package/dist/domains/dex/dyo-encode.js +124 -0
- package/dist/domains/dex/profit.d.ts +24 -0
- package/dist/domains/dex/profit.js +86 -0
- package/dist/domains/dex/provider.d.ts +10 -0
- package/dist/domains/dex/provider.js +27 -0
- package/dist/domains/dex/quote.d.ts +7 -0
- package/dist/domains/dex/quote.js +52 -0
- package/dist/domains/dex/router.d.ts +56 -0
- package/dist/domains/dex/router.js +193 -0
- package/dist/domains/flap/portal-bundle/batch.d.ts +9 -0
- package/dist/domains/flap/portal-bundle/batch.js +193 -0
- package/dist/domains/flap/portal-bundle/create.d.ts +5 -0
- package/dist/domains/flap/portal-bundle/create.js +153 -0
- package/dist/domains/flap/portal-bundle/helpers.d.ts +32 -0
- package/dist/domains/flap/portal-bundle/helpers.js +50 -0
- package/dist/domains/flap/portal-bundle/index.d.ts +16 -0
- package/dist/domains/flap/portal-bundle/index.js +15 -0
- package/dist/domains/flap/portal-bundle/private.d.ts +5 -0
- package/dist/domains/flap/portal-bundle/private.js +198 -0
- package/dist/domains/flap/portal-bundle/types.d.ts +102 -0
- package/dist/domains/flap/portal-bundle/types.js +1 -0
- package/dist/domains/flap/portal-bundle-merkle/core-batch.d.ts +13 -0
- package/dist/domains/flap/portal-bundle-merkle/core-batch.js +376 -0
- package/dist/domains/flap/portal-bundle-merkle/core-helpers.d.ts +75 -7
- package/dist/domains/flap/portal-bundle-merkle/core-helpers.js +259 -20
- package/dist/domains/flap/portal-bundle-merkle/core.d.ts +2 -13
- package/dist/domains/flap/portal-bundle-merkle/core.js +12 -629
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/constants.d.ts +70 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/constants.js +90 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/index.d.ts +12 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/index.js +11 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/main.d.ts +15 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/main.js +432 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/types.d.ts +113 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/types.js +4 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex.d.ts +4 -127
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex.js +4 -527
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/constants.d.ts +42 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/constants.js +81 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/index.d.ts +12 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/index.js +11 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/main.d.ts +15 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/main.js +339 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/types.d.ts +72 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/types.js +4 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex.d.ts +4 -85
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex.js +4 -425
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/approve.d.ts +12 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/approve.js +102 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/buy.d.ts +5 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/buy.js +135 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/helpers.d.ts +52 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/helpers.js +267 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/index.d.ts +14 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/index.js +14 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/sell.d.ts +5 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/sell.js +195 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy.d.ts +3 -24
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy.js +3 -700
- package/dist/domains/flap/portal-bundle-merkle/private/buy.d.ts +9 -0
- package/dist/domains/flap/portal-bundle-merkle/private/buy.js +188 -0
- package/dist/domains/flap/portal-bundle-merkle/private/helpers.d.ts +36 -0
- package/dist/domains/flap/portal-bundle-merkle/private/helpers.js +127 -0
- package/dist/domains/flap/portal-bundle-merkle/private/index.d.ts +12 -0
- package/dist/domains/flap/portal-bundle-merkle/private/index.js +12 -0
- package/dist/domains/flap/portal-bundle-merkle/private/sell.d.ts +9 -0
- package/dist/domains/flap/portal-bundle-merkle/private/sell.js +191 -0
- package/dist/domains/flap/portal-bundle-merkle/private.d.ts +5 -15
- package/dist/domains/flap/portal-bundle-merkle/private.js +5 -494
- package/dist/domains/flap/portal-bundle-merkle/swap-batch.js +3 -2
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-chain.d.ts +4 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-chain.js +43 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-constants.d.ts +13 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-constants.js +21 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-helpers.d.ts +11 -121
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-helpers.js +11 -109
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-multi-wallet.d.ts +20 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-multi-wallet.js +223 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-plan.d.ts +32 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-plan.js +66 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-profit.d.ts +22 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-profit.js +22 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-quote.d.ts +51 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-quote.js +149 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-types.d.ts +87 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-types.js +1 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first.js +5 -404
- package/dist/domains/flap/portal-bundle-merkle/swap-helpers.d.ts +0 -1
- package/dist/domains/flap/portal-bundle-merkle/swap-helpers.js +0 -7
- package/dist/domains/flap/portal-bundle-merkle/swap-planning.js +1 -1
- package/dist/domains/flap/portal-bundle-merkle/swap-quick-batch.js +3 -2
- package/dist/domains/flap/portal-bundle-merkle/swap-single.js +3 -2
- package/dist/domains/flap/portal-bundle-merkle/utils/disperse.d.ts +2 -0
- package/dist/domains/flap/portal-bundle-merkle/utils/disperse.js +275 -0
- package/dist/domains/flap/portal-bundle-merkle/utils/index.d.ts +11 -0
- package/dist/domains/flap/portal-bundle-merkle/utils/index.js +11 -0
- package/dist/domains/flap/portal-bundle-merkle/utils/sweep.d.ts +9 -0
- package/dist/domains/flap/portal-bundle-merkle/utils/sweep.js +570 -0
- package/dist/domains/flap/portal-bundle-merkle/utils.d.ts +5 -8
- package/dist/domains/flap/portal-bundle-merkle/utils.js +5 -841
- package/dist/domains/flap/portal-bundle.d.ts +5 -117
- package/dist/domains/flap/portal-bundle.js +5 -587
- package/dist/domains/flap/portal.d.ts +13 -404
- package/dist/domains/flap/portal.js +12 -619
- package/dist/domains/flap/reader.d.ts +51 -0
- package/dist/domains/flap/reader.js +275 -0
- package/dist/domains/flap/types.d.ts +246 -0
- package/dist/domains/flap/types.js +104 -0
- package/dist/domains/flap/vault/constants.d.ts +220 -0
- package/dist/domains/flap/vault/constants.js +173 -0
- package/dist/domains/flap/vault/encode.d.ts +39 -0
- package/dist/domains/flap/vault/encode.js +135 -0
- package/dist/domains/flap/vault/index.d.ts +15 -0
- package/dist/domains/flap/vault/index.js +14 -0
- package/dist/domains/flap/vault/query.d.ts +40 -0
- package/dist/domains/flap/vault/query.js +104 -0
- package/dist/domains/flap/vault/types.d.ts +147 -0
- package/dist/domains/flap/vault/types.js +29 -0
- package/dist/domains/flap/vault.d.ts +3 -413
- package/dist/domains/flap/vault.js +3 -467
- package/dist/domains/flap/writer.d.ts +124 -0
- package/dist/domains/flap/writer.js +255 -0
- package/dist/domains/four/contracts/tm-bundle-batch.d.ts +35 -0
- package/dist/domains/four/contracts/tm-bundle-batch.js +286 -0
- package/dist/domains/four/contracts/tm-bundle-create.d.ts +2 -0
- package/dist/domains/four/contracts/tm-bundle-create.js +304 -0
- package/dist/domains/four/contracts/tm-bundle-helpers.d.ts +2 -1
- package/dist/domains/four/contracts/tm-bundle-helpers.js +3 -0
- package/dist/domains/four/contracts/tm-bundle-private.d.ts +36 -0
- package/dist/domains/four/contracts/tm-bundle-private.js +164 -0
- package/dist/domains/four/contracts/tm-bundle.d.ts +10 -71
- package/dist/domains/four/contracts/tm-bundle.js +9 -738
- package/dist/domains/lp-inspect/inspect-helpers.d.ts +25 -0
- package/dist/domains/lp-inspect/inspect-helpers.js +343 -0
- package/dist/domains/lp-inspect/inspect.d.ts +8 -0
- package/dist/domains/lp-inspect/inspect.js +332 -0
- package/dist/domains/lp-inspect/lp-inspect.d.ts +9 -37
- package/dist/domains/lp-inspect/lp-inspect.js +9 -775
- package/dist/domains/lp-inspect/registry.d.ts +43 -0
- package/dist/domains/lp-inspect/registry.js +127 -0
- package/dist/domains/merkle/index.d.ts +1 -1
- package/dist/exports/root-bundle-and-tooling.d.ts +9 -1
- package/dist/exports/root-bundle-and-tooling.js +8 -1
- package/dist/exports/root-foundations.d.ts +1 -1
- package/dist/exports/root-foundations.js +1 -1
- package/dist/exports/root-swap-dex-and-xlayer.d.ts +4 -4
- package/dist/exports/root-swap-dex-and-xlayer.js +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/utils/swap-helpers.js +1 -1
- package/package.json +1 -85
|
@@ -1,52 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* core -
|
|
2
|
+
* core - 主函数(发币 + 捆绑买入)
|
|
3
|
+
*
|
|
4
|
+
* 拆分说明:batchBuyWithBundleMerkle / batchSellWithBundleMerkle 已抽取到
|
|
5
|
+
* core-batch.ts,本文件通过 re-export 保持对外符号/路径/签名不变。
|
|
3
6
|
*/
|
|
4
|
-
import { ethers, Wallet
|
|
5
|
-
import {
|
|
7
|
+
import { ethers, Wallet } from 'ethers';
|
|
8
|
+
import { getGasLimit } from '../../../core/gas/bundle-gas.js';
|
|
9
|
+
import { NonceManager, buildProfitHopTransactions, PROFIT_HOP_COUNT, } from '../../../utils/bundle-helpers.js';
|
|
6
10
|
import { ZERO_ADDRESS } from '../../../core/constants/index.js';
|
|
7
11
|
import { GAS_LIMITS } from '../../../core/constants/index.js';
|
|
8
|
-
import { MULTICALL3_ABI } from '../../../core/shared-abis/common.js';
|
|
9
12
|
import { FLAP_PORTAL_ADDRESSES, FLAP_ORIGINAL_PORTAL_ADDRESSES } from '../constants.js';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
import { SdkError } from '../../../utils/errors.js';
|
|
15
|
-
import { SdkErrorCode } from '../../../core/legacy-types/errors.js';
|
|
16
|
-
function validateQuoteTokenDecimals(decimals, source) {
|
|
17
|
-
if (decimals === undefined)
|
|
18
|
-
return undefined;
|
|
19
|
-
if (!Number.isInteger(decimals) || decimals < 0 || decimals > 18) {
|
|
20
|
-
throw new SdkError(SdkErrorCode.INVALID_AMOUNT, `${source}: quoteTokenDecimals 必须是 0-18 的整数,收到 ${String(decimals)}`);
|
|
21
|
-
}
|
|
22
|
-
return decimals;
|
|
23
|
-
}
|
|
24
|
-
function resolveCreateTokenLaunchFlags(params) {
|
|
25
|
-
const normalizedTax = normalizeTaxLaunchConfig(params.taxV2Config, params.taxRate);
|
|
26
|
-
const isTaxLaunch = !!normalizedTax || (params.taxRate ?? 0) > 0;
|
|
27
|
-
const hasVault = !!normalizedTax?.vaultConfig && normalizedTax.vaultConfig.vaultType !== 'none';
|
|
28
|
-
const useV7Portal = !isTaxLaunch &&
|
|
29
|
-
!hasVault &&
|
|
30
|
-
(params.lpFeeProfile !== undefined ||
|
|
31
|
-
params.dexId !== undefined ||
|
|
32
|
-
params.migratorType === MigratorType.PCS_INFINITY_CL_MIGRATOR);
|
|
33
|
-
return { normalizedTax, isTaxLaunch, hasVault, useV7Portal };
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* 无捆绑钱包、仅 Dev 自跟买、原生报价 → Flap 文档方式 A(create 内 quoteAmt + msg.value)
|
|
37
|
-
*/
|
|
38
|
-
function canUseLaunchMethodA(privateKeys, buyAmounts, devAddress, useNativeToken) {
|
|
39
|
-
if (!useNativeToken || buyAmounts.length !== 1 || privateKeys.length !== 2) {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
try {
|
|
43
|
-
const buyerAddr = new Wallet(privateKeys[1]).address;
|
|
44
|
-
return buyerAddr.toLowerCase() === devAddress.toLowerCase();
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
13
|
+
import { populateCreateTokenTransaction, } from '../portal-create-token.js';
|
|
14
|
+
import { PORTAL_ABI, getErrorMessage, getTxType, shouldExtractProfit, getProfitRecipient, getBribeAmount, BLOCKRAZOR_BUILDER_EOA, } from './config.js';
|
|
15
|
+
import { getTokenToNativeQuote, validateQuoteTokenDecimals, resolveCreateTokenLaunchFlags, canUseLaunchMethodA, createChainContext, resolveGasPrice, createWallets, analyzeBuyFunds, findMaxIndex, buildGasLimitList, populateBuyTransactionsWithQuote, allocateBuyerNonces, signBuyTransactions, buildProfitMetadata, } from './core-helpers.js';
|
|
16
|
+
export { batchBuyWithBundleMerkle, batchSellWithBundleMerkle } from './core-batch.js';
|
|
50
17
|
export async function createTokenWithBundleBuyMerkle(params) {
|
|
51
18
|
const { chain, privateKeys, buyAmounts, tokenInfo, tokenAddress, config } = params;
|
|
52
19
|
if (privateKeys.length === 0) {
|
|
@@ -101,7 +68,7 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
101
68
|
...createTxUnsigned,
|
|
102
69
|
from: devWallet.address,
|
|
103
70
|
nonce: devNonce,
|
|
104
|
-
gasLimit: getGasLimit(config),
|
|
71
|
+
gasLimit: getGasLimit(config, 800000),
|
|
105
72
|
gasPrice,
|
|
106
73
|
chainId,
|
|
107
74
|
type: getTxType(config),
|
|
@@ -241,587 +208,3 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
241
208
|
},
|
|
242
209
|
};
|
|
243
210
|
}
|
|
244
|
-
/**
|
|
245
|
-
* Flap Protocol: 批量购买(仅签名版本 - 不依赖 Merkle)
|
|
246
|
-
* ✅ 精简版:只负责签名交易,不提交到 Merkle
|
|
247
|
-
* ✅ 支持 quoteToken:传入 USDC 等地址时使用该代币购买,否则使用原生代币
|
|
248
|
-
*/
|
|
249
|
-
export async function batchBuyWithBundleMerkle(params) {
|
|
250
|
-
const { chain, privateKeys, buyAmounts, tokenAddress, quoteToken, quoteTokenDecimals, config } = params;
|
|
251
|
-
if (privateKeys.length === 0 || buyAmounts.length !== privateKeys.length) {
|
|
252
|
-
throw new Error(getErrorMessage('KEY_AMOUNT_MISMATCH'));
|
|
253
|
-
}
|
|
254
|
-
const { provider, chainId } = createChainContext(chain, config.rpcUrl);
|
|
255
|
-
const nonceManager = new NonceManager(provider);
|
|
256
|
-
const buyers = createWallets(privateKeys, provider);
|
|
257
|
-
const extractProfit = shouldExtractProfit();
|
|
258
|
-
const { fundsList, originalAmounts, totalBuyAmount, totalProfit } = analyzeBuyFunds(buyAmounts, config, extractProfit);
|
|
259
|
-
const maxFundsIndex = findMaxIndex(originalAmounts);
|
|
260
|
-
const gasLimits = buildGasLimitList(buyers.length, config);
|
|
261
|
-
// ✅ 确定 inputToken:如果传入了 quoteToken 且非零地址,则使用它;否则使用零地址(原生代币)
|
|
262
|
-
const inputToken = quoteToken && quoteToken !== ZERO_ADDRESS ? quoteToken : ZERO_ADDRESS;
|
|
263
|
-
// ✅ 如果使用非原生代币,则 value 应为 0(不发送原生代币)
|
|
264
|
-
const useNativeToken = inputToken === ZERO_ADDRESS;
|
|
265
|
-
const validatedBatchQuoteDecimals = validateQuoteTokenDecimals(quoteTokenDecimals, 'batchBuyWithBundleMerkle');
|
|
266
|
-
// ✅ 如果使用非原生代币(如 USDC),需要根据精度转换金额
|
|
267
|
-
// buyAmounts 是按 18 位精度传入的,需要转换为目标代币精度
|
|
268
|
-
let adjustedFundsList = fundsList;
|
|
269
|
-
let profitTokenAmount = totalProfit;
|
|
270
|
-
if (!useNativeToken && validatedBatchQuoteDecimals !== undefined && validatedBatchQuoteDecimals !== 18) {
|
|
271
|
-
// 从 18 位精度转换为目标精度
|
|
272
|
-
// 例如:0.1 ETH (18位) = 100000000000000000 wei
|
|
273
|
-
// 转为 USDC (6位) = 100000 (0.1 USDC)
|
|
274
|
-
const decimalsDiff = 18 - validatedBatchQuoteDecimals;
|
|
275
|
-
const divisor = BigInt(10 ** decimalsDiff);
|
|
276
|
-
adjustedFundsList = fundsList.map((amount) => amount / divisor);
|
|
277
|
-
profitTokenAmount = totalProfit / divisor;
|
|
278
|
-
}
|
|
279
|
-
// ✅ ERC20 购买:获取代币利润等值的原生代币(BNB)报价
|
|
280
|
-
let nativeProfitAmount = totalProfit; // 原生代币购买时直接使用
|
|
281
|
-
if (!useNativeToken && extractProfit && totalProfit > 0n) {
|
|
282
|
-
// 将代币利润转换为等值原生代币(BNB/OKB/MON)
|
|
283
|
-
nativeProfitAmount = await getTokenToNativeQuote(provider, inputToken, profitTokenAmount, chainId);
|
|
284
|
-
}
|
|
285
|
-
// ✅ 优化:如果前端传入了 nonces,需要调整以避免利润交易 nonce 冲突
|
|
286
|
-
const presetNonces = config.nonces;
|
|
287
|
-
// ✅ 并行执行需要的 RPC 操作
|
|
288
|
-
const [gasPrice, unsignedBuys, buyerNonces] = await Promise.all([
|
|
289
|
-
resolveGasPrice(provider, config),
|
|
290
|
-
populateBuyTransactionsWithQuote(buyers, FLAP_PORTAL_ADDRESSES[chain], tokenAddress, adjustedFundsList, inputToken, useNativeToken),
|
|
291
|
-
presetNonces && presetNonces.length === buyers.length
|
|
292
|
-
? adjustNoncesForProfit(presetNonces) // ✅ 调整 nonces 避免冲突
|
|
293
|
-
: allocateBuyerNonces(buyers, extractProfit, maxFundsIndex, nativeProfitAmount, nonceManager),
|
|
294
|
-
]);
|
|
295
|
-
// ✅ 贿赂交易放在首位(提高 BlockRazor 打包优先级)
|
|
296
|
-
const bribeAmount = getBribeAmount(config);
|
|
297
|
-
const bribeTxs = [];
|
|
298
|
-
if (bribeAmount > 0n && maxFundsIndex >= 0 && buyers.length > 0) {
|
|
299
|
-
const bribeNonce = buyerNonces[maxFundsIndex];
|
|
300
|
-
const bribeTx = await buyers[maxFundsIndex].signTransaction({
|
|
301
|
-
to: BLOCKRAZOR_BUILDER_EOA,
|
|
302
|
-
value: bribeAmount,
|
|
303
|
-
nonce: bribeNonce,
|
|
304
|
-
gasPrice,
|
|
305
|
-
gasLimit: GAS_LIMITS.BRIBE,
|
|
306
|
-
chainId,
|
|
307
|
-
type: getTxType(config),
|
|
308
|
-
});
|
|
309
|
-
bribeTxs.push(bribeTx);
|
|
310
|
-
// 调整 maxFundsIndex 钱包的 nonce(买入交易 +1)
|
|
311
|
-
buyerNonces[maxFundsIndex] = bribeNonce + 1;
|
|
312
|
-
}
|
|
313
|
-
const signedBuys = await signBuyTransactions({
|
|
314
|
-
unsignedBuys,
|
|
315
|
-
buyers,
|
|
316
|
-
nonces: buyerNonces,
|
|
317
|
-
gasLimits,
|
|
318
|
-
gasPrice,
|
|
319
|
-
chainId,
|
|
320
|
-
config,
|
|
321
|
-
fundsList: adjustedFundsList, // ✅ 使用调整后的金额
|
|
322
|
-
useNativeToken, // ✅ USDT 购买时 value=0,BNB 购买时 value=金额
|
|
323
|
-
});
|
|
324
|
-
// ✅ 利润多跳转账
|
|
325
|
-
const profitTxs = [];
|
|
326
|
-
let profitHopWallets;
|
|
327
|
-
// ✅ 检查是否使用分布式利润模式
|
|
328
|
-
const profitMode = config.profitMode ?? 'single';
|
|
329
|
-
if (extractProfit && nativeProfitAmount > 0n) {
|
|
330
|
-
if (profitMode === 'distributed') {
|
|
331
|
-
// ✅ 分布式模式:每个钱包独立扣除自己的利润,每个都有独立的多跳
|
|
332
|
-
// 最多支持 12 个钱包(12 交易 + 36 多跳 + 1 贿赂 = 49 笔)
|
|
333
|
-
const MAX_DISTRIBUTED_WALLETS = 12;
|
|
334
|
-
if (buyers.length > MAX_DISTRIBUTED_WALLETS) {
|
|
335
|
-
throw new Error(`分布式利润模式最多支持 ${MAX_DISTRIBUTED_WALLETS} 个钱包,当前 ${buyers.length} 个`);
|
|
336
|
-
}
|
|
337
|
-
profitHopWallets = [];
|
|
338
|
-
// 计算每个钱包的利润(按比例分配)
|
|
339
|
-
const perWalletProfits = [];
|
|
340
|
-
for (let i = 0; i < buyers.length; i++) {
|
|
341
|
-
const walletOriginalAmount = originalAmounts[i];
|
|
342
|
-
// 按比例计算该钱包应承担的利润
|
|
343
|
-
const walletProfit = totalBuyAmount > 0n ? (nativeProfitAmount * walletOriginalAmount) / totalBuyAmount : 0n;
|
|
344
|
-
perWalletProfits.push(walletProfit);
|
|
345
|
-
}
|
|
346
|
-
// 为每个钱包生成独立的利润多跳交易
|
|
347
|
-
for (let i = 0; i < buyers.length; i++) {
|
|
348
|
-
const walletProfit = perWalletProfits[i];
|
|
349
|
-
if (walletProfit > 0n) {
|
|
350
|
-
const profitNonce = buyerNonces[i] + 1; // 每个钱包买入后 +1
|
|
351
|
-
const profitHopResult = await buildProfitHopTransactions({
|
|
352
|
-
provider,
|
|
353
|
-
payerWallet: buyers[i],
|
|
354
|
-
profitAmount: walletProfit,
|
|
355
|
-
profitRecipient: getProfitRecipient(),
|
|
356
|
-
hopCount: PROFIT_HOP_COUNT,
|
|
357
|
-
gasPrice,
|
|
358
|
-
chainId,
|
|
359
|
-
txType: getTxType(config),
|
|
360
|
-
startNonce: profitNonce,
|
|
361
|
-
});
|
|
362
|
-
profitTxs.push(...profitHopResult.signedTransactions);
|
|
363
|
-
if (profitHopResult.hopWallets) {
|
|
364
|
-
profitHopWallets.push(...profitHopResult.hopWallets);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
else {
|
|
370
|
-
// ✅ 单一模式(默认):从金额最大的钱包统一扣除所有利润
|
|
371
|
-
if (maxFundsIndex >= 0) {
|
|
372
|
-
const profitNonce = buyerNonces[maxFundsIndex] + 1;
|
|
373
|
-
const profitHopResult = await buildProfitHopTransactions({
|
|
374
|
-
provider,
|
|
375
|
-
payerWallet: buyers[maxFundsIndex],
|
|
376
|
-
profitAmount: nativeProfitAmount,
|
|
377
|
-
profitRecipient: getProfitRecipient(),
|
|
378
|
-
hopCount: PROFIT_HOP_COUNT,
|
|
379
|
-
gasPrice,
|
|
380
|
-
chainId,
|
|
381
|
-
txType: getTxType(config),
|
|
382
|
-
startNonce: profitNonce,
|
|
383
|
-
});
|
|
384
|
-
profitTxs.push(...profitHopResult.signedTransactions);
|
|
385
|
-
profitHopWallets = profitHopResult.hopWallets;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
nonceManager.clearTemp();
|
|
390
|
-
// ✅ 组装顺序:贿赂 → 买入 → 利润多跳
|
|
391
|
-
return {
|
|
392
|
-
signedTransactions: [...bribeTxs, ...signedBuys, ...profitTxs],
|
|
393
|
-
profitHopWallets, // ✅ 返回利润多跳钱包
|
|
394
|
-
metadata: {
|
|
395
|
-
...buildProfitMetadata(extractProfit, totalBuyAmount, nativeProfitAmount, buyers.length),
|
|
396
|
-
profitMode, // ✅ 返回使用的利润模式
|
|
397
|
-
},
|
|
398
|
-
};
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* Flap Protocol: 批量卖出(仅签名版本 - 不依赖 Merkle)
|
|
402
|
-
* ✅ 精简版:只负责签名交易,不提交到 Merkle
|
|
403
|
-
* ✅ 支持 quoteToken:传入 USDC 等地址时卖出为该代币,否则卖出为原生代币
|
|
404
|
-
*/
|
|
405
|
-
export async function batchSellWithBundleMerkle(params) {
|
|
406
|
-
const { chain, privateKeys, sellAmounts, tokenAddress, quoteToken, minOutputAmounts, config } = params;
|
|
407
|
-
if (privateKeys.length === 0 || sellAmounts.length !== privateKeys.length) {
|
|
408
|
-
throw new Error(getErrorMessage('SELL_KEY_AMOUNT_MISMATCH'));
|
|
409
|
-
}
|
|
410
|
-
const { provider, chainId } = createChainContext(chain, config.rpcUrl);
|
|
411
|
-
const nonceManager = new NonceManager(provider);
|
|
412
|
-
const wallets = createWallets(privateKeys, provider);
|
|
413
|
-
const amountsWei = sellAmounts.map((a) => ethers.parseUnits(a, 18));
|
|
414
|
-
const portalAddr = FLAP_PORTAL_ADDRESSES[chain];
|
|
415
|
-
const readOnlyPortal = new ethers.Contract(portalAddr, PORTAL_ABI, provider);
|
|
416
|
-
const gasLimits = buildGasLimitList(wallets.length, config);
|
|
417
|
-
const portals = wallets.map((w) => new ethers.Contract(portalAddr, PORTAL_ABI, w));
|
|
418
|
-
// ✅ 确定 outputToken:如果传入了 quoteToken 且非零地址,则使用它;否则使用零地址(原生代币)
|
|
419
|
-
const outputToken = quoteToken && quoteToken !== ZERO_ADDRESS ? quoteToken : ZERO_ADDRESS;
|
|
420
|
-
const useNativeOutput = outputToken === ZERO_ADDRESS;
|
|
421
|
-
// ✅ 优化:如果前端传入了 nonces,直接使用(跳过 RPC 调用)
|
|
422
|
-
const presetNonces = config.nonces;
|
|
423
|
-
const extractProfit = shouldExtractProfit();
|
|
424
|
-
// ✅ 并行执行 gasPrice 和 quoteSellOutputs(Multicall3)
|
|
425
|
-
const [gasPrice, quotedOutputs] = await Promise.all([
|
|
426
|
-
resolveGasPrice(provider, config),
|
|
427
|
-
quoteSellOutputsWithQuote(readOnlyPortal, tokenAddress, amountsWei, outputToken),
|
|
428
|
-
]);
|
|
429
|
-
// ✅ 计算利润和 maxRevenueIndex(用于 nonce 分配)
|
|
430
|
-
let totalTokenProfit = 0n;
|
|
431
|
-
let maxRevenueIndex = -1;
|
|
432
|
-
let maxRevenue = 0n;
|
|
433
|
-
if (extractProfit && quotedOutputs.length > 0) {
|
|
434
|
-
for (let i = 0; i < wallets.length; i++) {
|
|
435
|
-
const quoted = quotedOutputs[i];
|
|
436
|
-
if (quoted > 0n) {
|
|
437
|
-
const { profit } = calculateProfit(quoted);
|
|
438
|
-
totalTokenProfit += profit;
|
|
439
|
-
if (quoted > maxRevenue) {
|
|
440
|
-
maxRevenue = quoted;
|
|
441
|
-
maxRevenueIndex = i;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
// ✅ 修复:根据是否需要贿赂/利润交易,统一分配 nonces
|
|
447
|
-
const bribeAmount = getBribeAmount(config);
|
|
448
|
-
const needBribeTx = bribeAmount > 0n && maxRevenueIndex >= 0;
|
|
449
|
-
const needProfitTx = extractProfit && totalTokenProfit > 0n && maxRevenueIndex >= 0;
|
|
450
|
-
// 计算 maxRevenueIndex 钱包需要的 nonce 数量:贿赂(可选) + 卖出 + 利润(可选)
|
|
451
|
-
const maxRevenueNonceCount = 1 + (needBribeTx ? 1 : 0) + (needProfitTx ? 1 : 0);
|
|
452
|
-
let nonces;
|
|
453
|
-
let bribeNonce;
|
|
454
|
-
let profitNonce;
|
|
455
|
-
if (presetNonces && presetNonces.length === wallets.length) {
|
|
456
|
-
// ✅ 使用前端传入的 nonces
|
|
457
|
-
nonces = [...presetNonces];
|
|
458
|
-
if (needBribeTx) {
|
|
459
|
-
bribeNonce = nonces[maxRevenueIndex];
|
|
460
|
-
nonces[maxRevenueIndex] = bribeNonce + 1; // 卖出交易 nonce +1
|
|
461
|
-
}
|
|
462
|
-
profitNonce = needProfitTx ? nonces[maxRevenueIndex] + 1 : undefined;
|
|
463
|
-
}
|
|
464
|
-
else if (maxRevenueNonceCount > 1 && maxRevenueIndex >= 0) {
|
|
465
|
-
// maxRevenueIndex 钱包需要多个连续 nonce
|
|
466
|
-
const maxRevenueNonces = await nonceManager.getNextNonceBatch(wallets[maxRevenueIndex], maxRevenueNonceCount);
|
|
467
|
-
// 其他钱包各需要 1 个 nonce
|
|
468
|
-
const otherWallets = wallets.filter((_, i) => i !== maxRevenueIndex);
|
|
469
|
-
const otherNonces = otherWallets.length > 0 ? await nonceManager.getNextNoncesForWallets(otherWallets) : [];
|
|
470
|
-
// 组装最终的 nonces 数组(保持原顺序)
|
|
471
|
-
nonces = [];
|
|
472
|
-
let otherIdx = 0;
|
|
473
|
-
let nonceIdx = 0;
|
|
474
|
-
if (needBribeTx) {
|
|
475
|
-
bribeNonce = maxRevenueNonces[nonceIdx++]; // 贿赂交易用第一个 nonce
|
|
476
|
-
}
|
|
477
|
-
for (let i = 0; i < wallets.length; i++) {
|
|
478
|
-
if (i === maxRevenueIndex) {
|
|
479
|
-
nonces.push(maxRevenueNonces[nonceIdx++]); // 卖出交易
|
|
480
|
-
}
|
|
481
|
-
else {
|
|
482
|
-
nonces.push(otherNonces[otherIdx++]);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
if (needProfitTx) {
|
|
486
|
-
profitNonce = maxRevenueNonces[nonceIdx]; // 利润交易用最后一个 nonce
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
else {
|
|
490
|
-
// 不需要额外交易,所有钱包各 1 个 nonce
|
|
491
|
-
nonces = await nonceManager.getNextNoncesForWallets(wallets);
|
|
492
|
-
}
|
|
493
|
-
const minOuts = resolveMinOutputs(minOutputAmounts, wallets.length, quotedOutputs);
|
|
494
|
-
// ✅ 优化:构建未签名交易(这里是本地操作,但仍然并行执行以提高效率)
|
|
495
|
-
const unsignedList = await Promise.all(portals.map((portal, i) => portal.swapExactInput.populateTransaction({
|
|
496
|
-
inputToken: tokenAddress,
|
|
497
|
-
outputToken, // ✅ 使用动态 outputToken
|
|
498
|
-
inputAmount: amountsWei[i],
|
|
499
|
-
minOutputAmount: minOuts[i],
|
|
500
|
-
permitData: '0x',
|
|
501
|
-
})));
|
|
502
|
-
// ✅ 贿赂交易放在首位
|
|
503
|
-
const bribeTxs = [];
|
|
504
|
-
if (needBribeTx && bribeNonce !== undefined) {
|
|
505
|
-
const bribeTx = await wallets[maxRevenueIndex].signTransaction({
|
|
506
|
-
to: BLOCKRAZOR_BUILDER_EOA,
|
|
507
|
-
value: bribeAmount,
|
|
508
|
-
nonce: bribeNonce,
|
|
509
|
-
gasPrice,
|
|
510
|
-
gasLimit: GAS_LIMITS.BRIBE,
|
|
511
|
-
chainId,
|
|
512
|
-
type: getTxType(config),
|
|
513
|
-
});
|
|
514
|
-
bribeTxs.push(bribeTx);
|
|
515
|
-
}
|
|
516
|
-
// ✅ 签名所有卖出交易(并行)
|
|
517
|
-
// ✅ 卖出交易 value 必须为 0,不能发送原生代币
|
|
518
|
-
const signedList = await Promise.all(unsignedList.map((unsigned, i) => wallets[i].signTransaction({
|
|
519
|
-
...unsigned,
|
|
520
|
-
from: wallets[i].address,
|
|
521
|
-
nonce: nonces[i],
|
|
522
|
-
gasLimit: gasLimits[i],
|
|
523
|
-
gasPrice,
|
|
524
|
-
chainId,
|
|
525
|
-
type: getTxType(config),
|
|
526
|
-
value: 0n, // ✅ 卖出交易不发送原生代币
|
|
527
|
-
})));
|
|
528
|
-
// ✅ 利润多跳转账
|
|
529
|
-
const profitTxs = [];
|
|
530
|
-
let profitHopWallets;
|
|
531
|
-
// ✅ 检查是否使用分布式利润模式
|
|
532
|
-
const profitMode = config.profitMode ?? 'single';
|
|
533
|
-
if (needProfitTx) {
|
|
534
|
-
// ERC20 输出时:获取代币利润等值的原生代币(BNB)报价
|
|
535
|
-
let totalNativeProfitAmount = totalTokenProfit;
|
|
536
|
-
if (!useNativeOutput && outputToken) {
|
|
537
|
-
totalNativeProfitAmount = await getTokenToNativeQuote(provider, outputToken, totalTokenProfit, chainId);
|
|
538
|
-
}
|
|
539
|
-
if (totalNativeProfitAmount > 0n) {
|
|
540
|
-
if (profitMode === 'distributed') {
|
|
541
|
-
// ✅ 分布式模式:每个钱包独立扣除自己的利润,每个都有独立的多跳
|
|
542
|
-
// 最多支持 12 个钱包(12 交易 + 36 多跳 + 1 贿赂 = 49 笔)
|
|
543
|
-
const MAX_DISTRIBUTED_WALLETS = 12;
|
|
544
|
-
if (wallets.length > MAX_DISTRIBUTED_WALLETS) {
|
|
545
|
-
throw new Error(`分布式利润模式最多支持 ${MAX_DISTRIBUTED_WALLETS} 个钱包,当前 ${wallets.length} 个`);
|
|
546
|
-
}
|
|
547
|
-
profitHopWallets = [];
|
|
548
|
-
// 计算每个钱包的利润(按卖出收益比例分配)
|
|
549
|
-
const totalQuoted = quotedOutputs.reduce((sum, q) => sum + q, 0n);
|
|
550
|
-
for (let i = 0; i < wallets.length; i++) {
|
|
551
|
-
const quoted = quotedOutputs[i];
|
|
552
|
-
if (quoted > 0n && totalQuoted > 0n) {
|
|
553
|
-
// 按比例计算该钱包应承担的利润
|
|
554
|
-
const walletProfit = (totalNativeProfitAmount * quoted) / totalQuoted;
|
|
555
|
-
if (walletProfit > 0n) {
|
|
556
|
-
const walletProfitNonce = nonces[i] + 1; // 每个钱包卖出后 +1
|
|
557
|
-
const profitHopResult = await buildProfitHopTransactions({
|
|
558
|
-
provider,
|
|
559
|
-
payerWallet: wallets[i],
|
|
560
|
-
profitAmount: walletProfit,
|
|
561
|
-
profitRecipient: getProfitRecipient(),
|
|
562
|
-
hopCount: PROFIT_HOP_COUNT,
|
|
563
|
-
gasPrice,
|
|
564
|
-
chainId,
|
|
565
|
-
txType: getTxType(config),
|
|
566
|
-
startNonce: walletProfitNonce,
|
|
567
|
-
});
|
|
568
|
-
profitTxs.push(...profitHopResult.signedTransactions);
|
|
569
|
-
if (profitHopResult.hopWallets) {
|
|
570
|
-
profitHopWallets.push(...profitHopResult.hopWallets);
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
else {
|
|
577
|
-
// ✅ 单一模式(默认):从收益最大的钱包统一扣除所有利润
|
|
578
|
-
if (profitNonce !== undefined) {
|
|
579
|
-
const profitHopResult = await buildProfitHopTransactions({
|
|
580
|
-
provider,
|
|
581
|
-
payerWallet: wallets[maxRevenueIndex],
|
|
582
|
-
profitAmount: totalNativeProfitAmount,
|
|
583
|
-
profitRecipient: getProfitRecipient(),
|
|
584
|
-
hopCount: PROFIT_HOP_COUNT,
|
|
585
|
-
gasPrice,
|
|
586
|
-
chainId,
|
|
587
|
-
txType: getTxType(config),
|
|
588
|
-
startNonce: profitNonce,
|
|
589
|
-
});
|
|
590
|
-
profitTxs.push(...profitHopResult.signedTransactions);
|
|
591
|
-
profitHopWallets = profitHopResult.hopWallets;
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
nonceManager.clearTemp();
|
|
597
|
-
// ✅ 组装顺序:贿赂 → 卖出 → 利润多跳
|
|
598
|
-
return {
|
|
599
|
-
signedTransactions: [...bribeTxs, ...signedList, ...profitTxs],
|
|
600
|
-
profitHopWallets, // ✅ 返回利润多跳钱包
|
|
601
|
-
metadata: {
|
|
602
|
-
profitMode, // ✅ 返回使用的利润模式
|
|
603
|
-
totalProfit: totalTokenProfit.toString(),
|
|
604
|
-
},
|
|
605
|
-
};
|
|
606
|
-
}
|
|
607
|
-
// ✅ Provider 缓存(复用连接,减少初始化开销)
|
|
608
|
-
const providerCache = new Map();
|
|
609
|
-
const PROVIDER_CACHE_TTL_MS = 60 * 1000; // 60秒缓存
|
|
610
|
-
function createChainContext(chain, rpcUrl) {
|
|
611
|
-
const chainId = CHAIN_ID_MAP[chain];
|
|
612
|
-
const cacheKey = `${chain}-${rpcUrl}`;
|
|
613
|
-
const now = Date.now();
|
|
614
|
-
// ✅ 检查缓存
|
|
615
|
-
const cached = providerCache.get(cacheKey);
|
|
616
|
-
if (cached && cached.expireAt > now) {
|
|
617
|
-
return { chainId, provider: cached.provider };
|
|
618
|
-
}
|
|
619
|
-
// ✅ 创建新 Provider 并缓存
|
|
620
|
-
const provider = new ethers.JsonRpcProvider(rpcUrl, { chainId, name: chain });
|
|
621
|
-
providerCache.set(cacheKey, { provider, expireAt: now + PROVIDER_CACHE_TTL_MS });
|
|
622
|
-
return { chainId, provider };
|
|
623
|
-
}
|
|
624
|
-
async function resolveGasPrice(provider, config) {
|
|
625
|
-
if ('gasPrice' in config && config.gasPrice !== undefined) {
|
|
626
|
-
return config.gasPrice;
|
|
627
|
-
}
|
|
628
|
-
return await getOptimizedGasPrice(provider, getGasPriceConfig(config));
|
|
629
|
-
}
|
|
630
|
-
function createWallets(privateKeys, provider) {
|
|
631
|
-
return privateKeys.map((key) => new Wallet(key, provider));
|
|
632
|
-
}
|
|
633
|
-
function analyzeBuyFunds(buyAmounts, config, extractProfit) {
|
|
634
|
-
const result = {
|
|
635
|
-
fundsList: [],
|
|
636
|
-
originalAmounts: [],
|
|
637
|
-
totalBuyAmount: 0n,
|
|
638
|
-
totalProfit: 0n,
|
|
639
|
-
};
|
|
640
|
-
buyAmounts.forEach((amount) => {
|
|
641
|
-
const originalAmount = ethers.parseEther(amount);
|
|
642
|
-
result.originalAmounts.push(originalAmount);
|
|
643
|
-
result.totalBuyAmount += originalAmount;
|
|
644
|
-
if (extractProfit) {
|
|
645
|
-
const { remaining, profit } = calculateProfit(originalAmount);
|
|
646
|
-
result.totalProfit += profit;
|
|
647
|
-
result.fundsList.push(remaining);
|
|
648
|
-
}
|
|
649
|
-
else {
|
|
650
|
-
result.fundsList.push(originalAmount);
|
|
651
|
-
}
|
|
652
|
-
});
|
|
653
|
-
return result;
|
|
654
|
-
}
|
|
655
|
-
function findMaxIndex(values) {
|
|
656
|
-
if (values.length === 0) {
|
|
657
|
-
return -1;
|
|
658
|
-
}
|
|
659
|
-
let maxIndex = 0;
|
|
660
|
-
let maxValue = values[0];
|
|
661
|
-
for (let i = 1; i < values.length; i++) {
|
|
662
|
-
if (values[i] > maxValue) {
|
|
663
|
-
maxValue = values[i];
|
|
664
|
-
maxIndex = i;
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
return maxIndex;
|
|
668
|
-
}
|
|
669
|
-
/**
|
|
670
|
-
* ✅ 支持 quoteToken 的买入交易构建
|
|
671
|
-
* 当 inputToken 为非零地址(如 USDC)时,value 为 0
|
|
672
|
-
*/
|
|
673
|
-
async function populateBuyTransactionsWithQuote(buyers, portalAddr, tokenAddress, fundsList, inputToken, useNativeToken) {
|
|
674
|
-
const portals = buyers.map((wallet) => new ethers.Contract(portalAddr, PORTAL_ABI, wallet));
|
|
675
|
-
return await Promise.all(portals.map((portal, i) => portal.swapExactInput.populateTransaction({
|
|
676
|
-
inputToken,
|
|
677
|
-
outputToken: tokenAddress,
|
|
678
|
-
inputAmount: fundsList[i],
|
|
679
|
-
minOutputAmount: 0n,
|
|
680
|
-
permitData: '0x',
|
|
681
|
-
},
|
|
682
|
-
// ✅ 如果使用原生代币,value 为购买金额;否则为 0
|
|
683
|
-
useNativeToken ? { value: fundsList[i] } : {})));
|
|
684
|
-
}
|
|
685
|
-
function buildGasLimitList(length, config) {
|
|
686
|
-
const gasLimit = getGasLimit(config);
|
|
687
|
-
return new Array(length).fill(gasLimit);
|
|
688
|
-
}
|
|
689
|
-
/**
|
|
690
|
-
* ✅ 修复:不再调整其他钱包的 nonce
|
|
691
|
-
*
|
|
692
|
-
* 之前的错误逻辑:如果钱包 B 的 nonce 与利润交易的 nonce 数值相同,就 +1
|
|
693
|
-
* 这是错误的!因为不同钱包的 nonce 是独立的,即使数值相同也不会冲突!
|
|
694
|
-
*
|
|
695
|
-
* 正确逻辑:直接返回原始 nonces,不做任何调整
|
|
696
|
-
* - 每个钱包使用自己的 nonce 发送买入交易
|
|
697
|
-
* - 利润交易使用 maxIndex 钱包的 nonce + 1(在构建利润交易时处理)
|
|
698
|
-
*/
|
|
699
|
-
function adjustNoncesForProfit(presetNonces) {
|
|
700
|
-
// ✅ 直接返回原始 nonces,不做任何调整
|
|
701
|
-
// 不同钱包的 nonce 是独立的,不会冲突
|
|
702
|
-
return presetNonces;
|
|
703
|
-
}
|
|
704
|
-
/**
|
|
705
|
-
* ✅ 修复:明确分配 nonces,避免隐式状态依赖
|
|
706
|
-
*/
|
|
707
|
-
async function allocateBuyerNonces(buyers, extractProfit, maxIndex, totalProfit, nonceManager) {
|
|
708
|
-
const needProfitTx = extractProfit && totalProfit > 0n && maxIndex >= 0 && maxIndex < buyers.length;
|
|
709
|
-
if (!needProfitTx) {
|
|
710
|
-
// 不需要利润交易,所有钱包各 1 个 nonce
|
|
711
|
-
return await nonceManager.getNextNoncesForWallets(buyers);
|
|
712
|
-
}
|
|
713
|
-
// 需要利润交易:maxIndex 钱包需要 2 个连续 nonce(买入 + 利润)
|
|
714
|
-
const maxIndexNonces = await nonceManager.getNextNonceBatch(buyers[maxIndex], 2);
|
|
715
|
-
// 其他钱包各需要 1 个 nonce
|
|
716
|
-
const otherBuyers = buyers.filter((_, i) => i !== maxIndex);
|
|
717
|
-
const otherNonces = otherBuyers.length > 0 ? await nonceManager.getNextNoncesForWallets(otherBuyers) : [];
|
|
718
|
-
// 组装最终的 nonces 数组(保持原顺序)
|
|
719
|
-
const nonces = [];
|
|
720
|
-
let otherIdx = 0;
|
|
721
|
-
for (let i = 0; i < buyers.length; i++) {
|
|
722
|
-
if (i === maxIndex) {
|
|
723
|
-
nonces.push(maxIndexNonces[0]); // 买入交易用第一个 nonce
|
|
724
|
-
}
|
|
725
|
-
else {
|
|
726
|
-
nonces.push(otherNonces[otherIdx++]);
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
return nonces;
|
|
730
|
-
}
|
|
731
|
-
async function signBuyTransactions({ unsignedBuys, buyers, nonces, gasLimits, gasPrice, chainId, config, fundsList, useNativeToken = true, // ✅ 默认使用原生代币
|
|
732
|
-
}) {
|
|
733
|
-
return await Promise.all(unsignedBuys.map((unsigned, i) => buyers[i].signTransaction({
|
|
734
|
-
...unsigned,
|
|
735
|
-
from: buyers[i].address,
|
|
736
|
-
nonce: nonces[i],
|
|
737
|
-
gasLimit: gasLimits[i],
|
|
738
|
-
gasPrice,
|
|
739
|
-
chainId,
|
|
740
|
-
type: getTxType(config),
|
|
741
|
-
value: useNativeToken ? fundsList[i] : 0n, // ✅ 非原生代币时 value 为 0
|
|
742
|
-
})));
|
|
743
|
-
}
|
|
744
|
-
function buildProfitMetadata(extractProfit, totalBuyAmount, totalProfit, buyerCount) {
|
|
745
|
-
if (!extractProfit) {
|
|
746
|
-
return undefined;
|
|
747
|
-
}
|
|
748
|
-
return {
|
|
749
|
-
totalBuyAmount: ethers.formatEther(totalBuyAmount),
|
|
750
|
-
profitAmount: ethers.formatEther(totalProfit),
|
|
751
|
-
profitRecipient: getProfitRecipient(),
|
|
752
|
-
buyerCount,
|
|
753
|
-
};
|
|
754
|
-
}
|
|
755
|
-
/**
|
|
756
|
-
* ✅ 使用 Multicall3 批量获取卖出报价(单次 RPC)
|
|
757
|
-
* 比 Promise.all 更高效,N 个报价只需 1 次网络请求
|
|
758
|
-
*/
|
|
759
|
-
async function quoteSellOutputsWithQuote(portal, tokenAddress, amountsWei, outputToken) {
|
|
760
|
-
if (amountsWei.length === 0)
|
|
761
|
-
return [];
|
|
762
|
-
// 如果只有 1 个,直接调用(避免 multicall 开销)
|
|
763
|
-
if (amountsWei.length === 1) {
|
|
764
|
-
try {
|
|
765
|
-
const result = await portal.quoteExactInput.staticCall({
|
|
766
|
-
inputToken: tokenAddress,
|
|
767
|
-
outputToken,
|
|
768
|
-
inputAmount: amountsWei[0],
|
|
769
|
-
});
|
|
770
|
-
return [result];
|
|
771
|
-
}
|
|
772
|
-
catch {
|
|
773
|
-
return [0n];
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
const provider = portal.runner;
|
|
777
|
-
const portalAddress = await portal.getAddress();
|
|
778
|
-
const portalIface = new Interface(PORTAL_ABI);
|
|
779
|
-
const multicall = new Contract(MULTICALL3_ADDRESS, MULTICALL3_ABI, provider);
|
|
780
|
-
// 构建批量调用
|
|
781
|
-
const calls = amountsWei.map((amount) => ({
|
|
782
|
-
target: portalAddress,
|
|
783
|
-
allowFailure: true, // 允许单个失败
|
|
784
|
-
callData: portalIface.encodeFunctionData('quoteExactInput', [
|
|
785
|
-
{
|
|
786
|
-
inputToken: tokenAddress,
|
|
787
|
-
outputToken,
|
|
788
|
-
inputAmount: amount,
|
|
789
|
-
},
|
|
790
|
-
]),
|
|
791
|
-
}));
|
|
792
|
-
try {
|
|
793
|
-
const results = await multicall.aggregate3.staticCall(calls);
|
|
794
|
-
return results.map((r) => {
|
|
795
|
-
if (r.success && r.returnData && r.returnData !== '0x') {
|
|
796
|
-
try {
|
|
797
|
-
const decoded = portalIface.decodeFunctionResult('quoteExactInput', r.returnData);
|
|
798
|
-
return BigInt(decoded[0]);
|
|
799
|
-
}
|
|
800
|
-
catch {
|
|
801
|
-
return 0n;
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
return 0n;
|
|
805
|
-
});
|
|
806
|
-
}
|
|
807
|
-
catch {
|
|
808
|
-
// Multicall 失败,回退到并行调用
|
|
809
|
-
return await Promise.all(amountsWei.map(async (amount) => {
|
|
810
|
-
try {
|
|
811
|
-
return await portal.quoteExactInput.staticCall({
|
|
812
|
-
inputToken: tokenAddress,
|
|
813
|
-
outputToken,
|
|
814
|
-
inputAmount: amount,
|
|
815
|
-
});
|
|
816
|
-
}
|
|
817
|
-
catch {
|
|
818
|
-
return 0n;
|
|
819
|
-
}
|
|
820
|
-
}));
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
function resolveMinOutputs(_provided, walletCount, _quotedOutputs) {
|
|
824
|
-
// ✅ 已移除滑点保护:minOutput 固定为 0
|
|
825
|
-
return Array(walletCount).fill(0n);
|
|
826
|
-
}
|
|
827
|
-
// ✅ 贿赂交易和利润交易已内联到各函数中,确保正确的顺序:贿赂 → 主交易 → 利润
|