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,843 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Flap Protocol 分散 / 归集(Merkle Bundle)
|
|
3
|
+
*
|
|
4
|
+
* 原超长文件按职责拆分为 utils/ 目录下的多个子文件,
|
|
5
|
+
* 对外 export 符号与路径保持不变(见 utils/index.ts)。
|
|
3
6
|
*/
|
|
4
|
-
|
|
5
|
-
import { getOptimizedGasPrice, NonceManager, buildProfitHopTransactions, PROFIT_HOP_COUNT, } from '../../../utils/bundle-helpers.js';
|
|
6
|
-
import { GAS_LIMITS, calculateTransferFee } from '../../../core/constants/index.js';
|
|
7
|
-
import { CHAIN_ID_MAP, getTxType, getGasPriceConfig, shouldExtractProfit, getProfitRecipient } from './config.js';
|
|
8
|
-
import { batchGetBalances, calculateGasLimit, generateHopWallets, getErc20Decimals, isNativeTokenAddress, normalizeAmounts, } from '../../../bundle/internal.js';
|
|
9
|
-
import { createSignProvider, createSignWallet, normalizeItemsOrRecipientsAmounts, resolveHopCountInput, resolveProvidedHops, } from '../../../bundle/sign-context-helpers.js';
|
|
10
|
-
export async function flapDisperseWithBundleMerkle(params) {
|
|
11
|
-
const { chain, fromPrivateKey, recipients, amount, amounts, tokenAddress, tokenDecimals, hopCount = 0, hopPrivateKeys, items, config, startNonce, } = params;
|
|
12
|
-
if (!recipients || recipients.length === 0) {
|
|
13
|
-
return { signedTransactions: [], hopWallets: undefined };
|
|
14
|
-
}
|
|
15
|
-
const chainIdNum = CHAIN_ID_MAP[chain] ?? 56;
|
|
16
|
-
const provider = createSignProvider(config.rpcUrl, chainIdNum, chain);
|
|
17
|
-
const mainWallet = createSignWallet(fromPrivateKey, provider);
|
|
18
|
-
const isNative = isNativeTokenAddress(tokenAddress);
|
|
19
|
-
const txType = getTxType(config);
|
|
20
|
-
const normalizedAmounts = normalizeItemsOrRecipientsAmounts(recipients, items, amount, amounts, normalizeAmounts);
|
|
21
|
-
const providedHops = resolveProvidedHops(recipients.length, hopPrivateKeys, items);
|
|
22
|
-
const hopCountInput = resolveHopCountInput(recipients.length, hopCount, items);
|
|
23
|
-
const preparedHops = providedHops ?? generateHopWallets(recipients.length, hopCountInput);
|
|
24
|
-
const hasHops = preparedHops !== null;
|
|
25
|
-
const maxHopCount = preparedHops ? Math.max(...preparedHops.map((h) => h.length)) : 0;
|
|
26
|
-
const finalGasLimit = calculateGasLimit(config, isNative, hasHops, maxHopCount);
|
|
27
|
-
const nativeGasLimit = GAS_LIMITS.BRIBE;
|
|
28
|
-
const signedTxs = [];
|
|
29
|
-
const extractProfit = shouldExtractProfit();
|
|
30
|
-
const profitAddr = getProfitRecipient();
|
|
31
|
-
let totalProfit = 0n;
|
|
32
|
-
let totalAmountBeforeProfit = 0n;
|
|
33
|
-
let profitHopWallets; // ✅ 收集利润多跳钱包
|
|
34
|
-
const nonceManager = new NonceManager(provider);
|
|
35
|
-
if (!preparedHops) {
|
|
36
|
-
// ========== 无多跳:直接批量转账 ==========
|
|
37
|
-
const extraTxCount = extractProfit ? 1 : 0;
|
|
38
|
-
const totalTxCount = recipients.length + extraTxCount;
|
|
39
|
-
const [gasPrice, nonces] = await Promise.all([
|
|
40
|
-
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
41
|
-
startNonce !== undefined
|
|
42
|
-
? Promise.resolve(Array.from({ length: totalTxCount }, (_, i) => startNonce + i))
|
|
43
|
-
: nonceManager.getNextNonceBatch(mainWallet, totalTxCount),
|
|
44
|
-
]);
|
|
45
|
-
// ✅ 按地址数量收取固定费用(原生代币)
|
|
46
|
-
if (extractProfit) {
|
|
47
|
-
totalProfit = calculateTransferFee(chainIdNum, recipients.length);
|
|
48
|
-
}
|
|
49
|
-
if (isNative) {
|
|
50
|
-
const txDataList = recipients.map((to, i) => {
|
|
51
|
-
const originalAmount = ethers.parseEther(normalizedAmounts[i]);
|
|
52
|
-
totalAmountBeforeProfit += originalAmount;
|
|
53
|
-
// ✅ 不再从转账金额中扣除利润,全额转账
|
|
54
|
-
return { to, value: originalAmount, nonce: nonces[i] };
|
|
55
|
-
});
|
|
56
|
-
const txPromises = txDataList.map(({ to, value, nonce }) => mainWallet.signTransaction({
|
|
57
|
-
to,
|
|
58
|
-
value,
|
|
59
|
-
nonce,
|
|
60
|
-
gasPrice,
|
|
61
|
-
gasLimit: nativeGasLimit,
|
|
62
|
-
chainId: chainIdNum,
|
|
63
|
-
type: txType,
|
|
64
|
-
}));
|
|
65
|
-
signedTxs.push(...(await Promise.all(txPromises)));
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
const decimals = tokenDecimals ?? (await getErc20Decimals(provider, tokenAddress));
|
|
69
|
-
const iface = new ethers.Interface(['function transfer(address,uint256) returns (bool)']);
|
|
70
|
-
const txDataList = recipients.map((to, i) => {
|
|
71
|
-
const originalAmount = ethers.parseUnits(normalizedAmounts[i], decimals);
|
|
72
|
-
totalAmountBeforeProfit += originalAmount;
|
|
73
|
-
// ✅ 不再从转账金额中扣除利润,全额转账
|
|
74
|
-
const data = iface.encodeFunctionData('transfer', [to, originalAmount]);
|
|
75
|
-
return { data, nonce: nonces[i] };
|
|
76
|
-
});
|
|
77
|
-
const txPromises = txDataList.map(({ data, nonce }) => mainWallet.signTransaction({
|
|
78
|
-
to: tokenAddress,
|
|
79
|
-
data,
|
|
80
|
-
value: 0n,
|
|
81
|
-
nonce,
|
|
82
|
-
gasPrice,
|
|
83
|
-
gasLimit: finalGasLimit,
|
|
84
|
-
chainId: chainIdNum,
|
|
85
|
-
type: txType,
|
|
86
|
-
}));
|
|
87
|
-
signedTxs.push(...(await Promise.all(txPromises)));
|
|
88
|
-
}
|
|
89
|
-
// ✅ 利润多跳转账(固定费用,原生代币)
|
|
90
|
-
if (extractProfit && totalProfit > 0n) {
|
|
91
|
-
const profitHopResult = await buildProfitHopTransactions({
|
|
92
|
-
provider,
|
|
93
|
-
payerWallet: mainWallet,
|
|
94
|
-
profitAmount: totalProfit,
|
|
95
|
-
profitRecipient: profitAddr,
|
|
96
|
-
hopCount: PROFIT_HOP_COUNT,
|
|
97
|
-
gasPrice,
|
|
98
|
-
chainId: chainIdNum,
|
|
99
|
-
txType,
|
|
100
|
-
startNonce: nonces[recipients.length],
|
|
101
|
-
});
|
|
102
|
-
signedTxs.push(...profitHopResult.signedTransactions);
|
|
103
|
-
profitHopWallets = profitHopResult.hopWallets;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
// ========== 有多跳:构建跳转链 ==========
|
|
108
|
-
const [gasPrice, decimals] = await Promise.all([
|
|
109
|
-
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
110
|
-
isNative
|
|
111
|
-
? Promise.resolve(18)
|
|
112
|
-
: Promise.resolve(tokenDecimals ?? (await getErc20Decimals(provider, tokenAddress))),
|
|
113
|
-
]);
|
|
114
|
-
const iface = isNative ? null : new ethers.Interface(['function transfer(address,uint256) returns (bool)']);
|
|
115
|
-
const gasFeePerHop = finalGasLimit * gasPrice;
|
|
116
|
-
let mainWalletNonceCount = 0;
|
|
117
|
-
for (let i = 0; i < recipients.length; i++) {
|
|
118
|
-
const hopChain = preparedHops[i];
|
|
119
|
-
if (hopChain.length === 0) {
|
|
120
|
-
mainWalletNonceCount += 1;
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
const nonceNeed = isNative ? 1 : hopChain.length + 1;
|
|
124
|
-
mainWalletNonceCount += nonceNeed;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (extractProfit)
|
|
128
|
-
mainWalletNonceCount += 1;
|
|
129
|
-
const allMainNonces = startNonce !== undefined
|
|
130
|
-
? Array.from({ length: mainWalletNonceCount }, (_, i) => startNonce + i)
|
|
131
|
-
: await nonceManager.getNextNonceBatch(mainWallet, mainWalletNonceCount);
|
|
132
|
-
let mainNonceIdx = 0;
|
|
133
|
-
const txsToSign = [];
|
|
134
|
-
// ✅ 按地址数量收取固定费用(原生代币)
|
|
135
|
-
if (extractProfit) {
|
|
136
|
-
totalProfit = calculateTransferFee(chainIdNum, recipients.length);
|
|
137
|
-
}
|
|
138
|
-
for (let i = 0; i < recipients.length; i++) {
|
|
139
|
-
const finalRecipient = recipients[i];
|
|
140
|
-
const originalAmountWei = isNative
|
|
141
|
-
? ethers.parseEther(normalizedAmounts[i])
|
|
142
|
-
: ethers.parseUnits(normalizedAmounts[i], decimals);
|
|
143
|
-
totalAmountBeforeProfit += originalAmountWei;
|
|
144
|
-
// ✅ 不再从转账金额中扣除利润,全额转账
|
|
145
|
-
const amountWei = originalAmountWei;
|
|
146
|
-
const hopChain = preparedHops[i];
|
|
147
|
-
if (hopChain.length === 0) {
|
|
148
|
-
const nonce = allMainNonces[mainNonceIdx++];
|
|
149
|
-
if (isNative) {
|
|
150
|
-
txsToSign.push({
|
|
151
|
-
wallet: mainWallet,
|
|
152
|
-
tx: {
|
|
153
|
-
to: finalRecipient,
|
|
154
|
-
value: amountWei,
|
|
155
|
-
nonce,
|
|
156
|
-
gasPrice,
|
|
157
|
-
gasLimit: nativeGasLimit,
|
|
158
|
-
chainId: chainIdNum,
|
|
159
|
-
type: txType,
|
|
160
|
-
},
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
const data = iface.encodeFunctionData('transfer', [finalRecipient, amountWei]);
|
|
165
|
-
txsToSign.push({
|
|
166
|
-
wallet: mainWallet,
|
|
167
|
-
tx: {
|
|
168
|
-
to: tokenAddress,
|
|
169
|
-
data,
|
|
170
|
-
value: 0n,
|
|
171
|
-
nonce,
|
|
172
|
-
gasPrice,
|
|
173
|
-
gasLimit: finalGasLimit,
|
|
174
|
-
chainId: chainIdNum,
|
|
175
|
-
type: txType,
|
|
176
|
-
},
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
// ✅ 支持 string 和 GeneratedWallet 两种类型
|
|
182
|
-
const fullChain = [
|
|
183
|
-
mainWallet,
|
|
184
|
-
...hopChain.map((w) => new Wallet(typeof w === 'string' ? w : w.privateKey, provider)),
|
|
185
|
-
];
|
|
186
|
-
const addresses = [...fullChain.map((w) => w.address), finalRecipient];
|
|
187
|
-
if (!isNative) {
|
|
188
|
-
for (let j = 0; j < hopChain.length; j++) {
|
|
189
|
-
const nonce = allMainNonces[mainNonceIdx++];
|
|
190
|
-
txsToSign.push({
|
|
191
|
-
wallet: mainWallet,
|
|
192
|
-
tx: {
|
|
193
|
-
to: fullChain[j + 1].address,
|
|
194
|
-
value: gasFeePerHop,
|
|
195
|
-
nonce,
|
|
196
|
-
gasPrice,
|
|
197
|
-
gasLimit: nativeGasLimit,
|
|
198
|
-
chainId: chainIdNum,
|
|
199
|
-
type: txType,
|
|
200
|
-
},
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
for (let j = 0; j < addresses.length - 1; j++) {
|
|
205
|
-
const fromWallet = fullChain[j];
|
|
206
|
-
const toAddress = addresses[j + 1];
|
|
207
|
-
const nonce = j === 0 ? allMainNonces[mainNonceIdx++] : 0;
|
|
208
|
-
if (isNative) {
|
|
209
|
-
const remainingHops = addresses.length - 2 - j;
|
|
210
|
-
const additionalGas = gasFeePerHop * BigInt(remainingHops);
|
|
211
|
-
const transferValue = amountWei + additionalGas;
|
|
212
|
-
txsToSign.push({
|
|
213
|
-
wallet: fromWallet,
|
|
214
|
-
tx: {
|
|
215
|
-
to: toAddress,
|
|
216
|
-
value: transferValue,
|
|
217
|
-
nonce,
|
|
218
|
-
gasPrice,
|
|
219
|
-
gasLimit: finalGasLimit,
|
|
220
|
-
chainId: chainIdNum,
|
|
221
|
-
type: txType,
|
|
222
|
-
},
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
const data = iface.encodeFunctionData('transfer', [toAddress, amountWei]);
|
|
227
|
-
txsToSign.push({
|
|
228
|
-
wallet: fromWallet,
|
|
229
|
-
tx: {
|
|
230
|
-
to: tokenAddress,
|
|
231
|
-
data,
|
|
232
|
-
value: 0n,
|
|
233
|
-
nonce,
|
|
234
|
-
gasPrice,
|
|
235
|
-
gasLimit: finalGasLimit,
|
|
236
|
-
chainId: chainIdNum,
|
|
237
|
-
type: txType,
|
|
238
|
-
},
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
const signedTxsResult = await Promise.all(txsToSign.map(({ wallet, tx }) => wallet.signTransaction(tx)));
|
|
244
|
-
signedTxs.push(...signedTxsResult);
|
|
245
|
-
// ✅ 利润多跳转账(固定费用,原生代币)
|
|
246
|
-
if (extractProfit && totalProfit > 0n) {
|
|
247
|
-
const profitNonce = allMainNonces[mainNonceIdx];
|
|
248
|
-
const profitHopResult = await buildProfitHopTransactions({
|
|
249
|
-
provider,
|
|
250
|
-
payerWallet: mainWallet,
|
|
251
|
-
profitAmount: totalProfit,
|
|
252
|
-
profitRecipient: profitAddr,
|
|
253
|
-
hopCount: PROFIT_HOP_COUNT,
|
|
254
|
-
gasPrice,
|
|
255
|
-
chainId: chainIdNum,
|
|
256
|
-
txType,
|
|
257
|
-
startNonce: profitNonce,
|
|
258
|
-
});
|
|
259
|
-
signedTxs.push(...profitHopResult.signedTransactions);
|
|
260
|
-
profitHopWallets = profitHopResult.hopWallets;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
return {
|
|
264
|
-
signedTransactions: signedTxs,
|
|
265
|
-
hopWallets: preparedHops || undefined,
|
|
266
|
-
profitHopWallets, // ✅ 返回利润多跳钱包
|
|
267
|
-
metadata: extractProfit
|
|
268
|
-
? {
|
|
269
|
-
totalAmount: ethers.formatEther(totalAmountBeforeProfit),
|
|
270
|
-
profitAmount: ethers.formatEther(totalProfit),
|
|
271
|
-
profitRecipient: profitAddr,
|
|
272
|
-
recipientCount: recipients.length,
|
|
273
|
-
isNative,
|
|
274
|
-
tokenAddress: isNative ? undefined : tokenAddress,
|
|
275
|
-
}
|
|
276
|
-
: undefined,
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
// ==================== 归集函数 ====================
|
|
280
|
-
/**
|
|
281
|
-
* Flap Protocol: 归集(仅签名版本)
|
|
282
|
-
* ✅ 支持利润提取(按地址数量收取固定费用)
|
|
283
|
-
* ✅ 查询余额最大的钱包支付利润
|
|
284
|
-
* ✅ 支持多跳
|
|
285
|
-
* ✅ 支持 Multicall3 批量获取余额
|
|
286
|
-
*/
|
|
287
|
-
export async function flapSweepWithBundleMerkle(params) {
|
|
288
|
-
const { chain, sourcePrivateKeys, target, ratioPct, ratios, amount, amounts, tokenAddress, tokenDecimals, skipIfInsufficient = true, hopCount = 0, hopPrivateKeys, sources, config, } = params;
|
|
289
|
-
if (!sourcePrivateKeys || sourcePrivateKeys.length === 0) {
|
|
290
|
-
return { signedTransactions: [], hopWallets: undefined };
|
|
291
|
-
}
|
|
292
|
-
const chainIdNum = CHAIN_ID_MAP[chain] ?? 56;
|
|
293
|
-
const provider = createSignProvider(config.rpcUrl, chainIdNum, chain);
|
|
294
|
-
const isNative = isNativeTokenAddress(tokenAddress);
|
|
295
|
-
const txType = getTxType(config);
|
|
296
|
-
const clamp = (n) => typeof n === 'number' && Number.isFinite(n) ? Math.max(0, Math.min(100, Math.floor(n))) : undefined;
|
|
297
|
-
const ratio = clamp(ratioPct);
|
|
298
|
-
const actualKeys = (() => {
|
|
299
|
-
if (sources && sources.length > 0)
|
|
300
|
-
return sources.map((s) => s.privateKey);
|
|
301
|
-
return sourcePrivateKeys;
|
|
302
|
-
})();
|
|
303
|
-
const providedHops = resolveProvidedHops(actualKeys.length, hopPrivateKeys, sources);
|
|
304
|
-
const hopCountInput = resolveHopCountInput(actualKeys.length, hopCount, sources);
|
|
305
|
-
const preparedHops = providedHops ?? generateHopWallets(actualKeys.length, hopCountInput);
|
|
306
|
-
const hasHops = preparedHops !== null;
|
|
307
|
-
const maxHopCount = preparedHops ? Math.max(...preparedHops.map((h) => h.length)) : 0;
|
|
308
|
-
const finalGasLimit = calculateGasLimit(config, isNative, hasHops, maxHopCount);
|
|
309
|
-
const nativeGasLimit = GAS_LIMITS.BRIBE;
|
|
310
|
-
const signedTxs = [];
|
|
311
|
-
const extractProfit = shouldExtractProfit();
|
|
312
|
-
const profitAddr = getProfitRecipient();
|
|
313
|
-
let totalProfit = 0n;
|
|
314
|
-
let totalAmountBeforeProfit = 0n;
|
|
315
|
-
let profitHopWallets; // ✅ 收集利润多跳钱包
|
|
316
|
-
if (!preparedHops) {
|
|
317
|
-
// ========== 无多跳:直接批量归集 ==========
|
|
318
|
-
const wallets = actualKeys.map((pk) => new Wallet(pk, provider));
|
|
319
|
-
const addresses = wallets.map((w) => w.address);
|
|
320
|
-
const nonceManager = new NonceManager(provider);
|
|
321
|
-
// ✅ 按地址数量收取固定费用(原生代币)
|
|
322
|
-
if (extractProfit) {
|
|
323
|
-
totalProfit = calculateTransferFee(chainIdNum, wallets.length);
|
|
324
|
-
}
|
|
325
|
-
if (isNative) {
|
|
326
|
-
const [gasPrice, balances] = await Promise.all([
|
|
327
|
-
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
328
|
-
batchGetBalances(provider, addresses),
|
|
329
|
-
]);
|
|
330
|
-
const gasCostBase = nativeGasLimit * gasPrice;
|
|
331
|
-
const profitTxGas = GAS_LIMITS.NATIVE_TRANSFER * gasPrice * BigInt(PROFIT_HOP_COUNT + 1);
|
|
332
|
-
// 第一步:计算所有钱包的归集金额,找出余额最大的钱包
|
|
333
|
-
const sweepAmounts = [];
|
|
334
|
-
let maxSweepIndex = -1;
|
|
335
|
-
let maxSweepAmount = 0n;
|
|
336
|
-
for (let i = 0; i < wallets.length; i++) {
|
|
337
|
-
const bal = balances[i];
|
|
338
|
-
let toSend = 0n;
|
|
339
|
-
const ratioForI = (() => {
|
|
340
|
-
if (sources && sources[i] && sources[i].ratioPct !== undefined)
|
|
341
|
-
return clamp(sources[i].ratioPct);
|
|
342
|
-
if (ratios && ratios[i] !== undefined)
|
|
343
|
-
return clamp(ratios[i]);
|
|
344
|
-
return ratio;
|
|
345
|
-
})();
|
|
346
|
-
const amountStrForI = (() => {
|
|
347
|
-
if (sources && sources[i] && sources[i].amount !== undefined)
|
|
348
|
-
return String(sources[i].amount);
|
|
349
|
-
if (amounts && amounts[i] !== undefined)
|
|
350
|
-
return String(amounts[i]);
|
|
351
|
-
return amount !== undefined ? String(amount) : undefined;
|
|
352
|
-
})();
|
|
353
|
-
const gasCost = gasCostBase;
|
|
354
|
-
if (ratioForI !== undefined) {
|
|
355
|
-
const want = (bal * BigInt(ratioForI)) / 100n;
|
|
356
|
-
const maxSendable = bal > gasCost ? bal - gasCost : 0n;
|
|
357
|
-
toSend = want > maxSendable ? maxSendable : want;
|
|
358
|
-
}
|
|
359
|
-
else if (amountStrForI && amountStrForI.trim().length > 0) {
|
|
360
|
-
const amt = ethers.parseEther(amountStrForI);
|
|
361
|
-
const need = amt + gasCost;
|
|
362
|
-
if (!skipIfInsufficient || bal >= need)
|
|
363
|
-
toSend = amt;
|
|
364
|
-
}
|
|
365
|
-
sweepAmounts.push(toSend);
|
|
366
|
-
totalAmountBeforeProfit += toSend;
|
|
367
|
-
// ✅ 找出余额最大的钱包作为利润支付者
|
|
368
|
-
if (toSend > maxSweepAmount) {
|
|
369
|
-
maxSweepAmount = toSend;
|
|
370
|
-
maxSweepIndex = i;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
// 检查支付者余额是否足够支付利润
|
|
374
|
-
if (extractProfit && totalProfit > 0n && maxSweepIndex >= 0) {
|
|
375
|
-
const payerBalance = balances[maxSweepIndex];
|
|
376
|
-
const payerSweepAmount = sweepAmounts[maxSweepIndex];
|
|
377
|
-
const payerNeedGas = gasCostBase + profitTxGas;
|
|
378
|
-
if (payerBalance < payerSweepAmount + payerNeedGas + totalProfit) {
|
|
379
|
-
// 余额不足支付利润,减少归集金额
|
|
380
|
-
const maxPayerSweep = payerBalance > payerNeedGas + totalProfit ? payerBalance - payerNeedGas - totalProfit : 0n;
|
|
381
|
-
sweepAmounts[maxSweepIndex] = maxPayerSweep;
|
|
382
|
-
totalAmountBeforeProfit = sweepAmounts.reduce((sum, amt) => sum + amt, 0n);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
// 第二步:生成归集交易
|
|
386
|
-
let payerProfitNonce;
|
|
387
|
-
if (extractProfit && totalProfit > 0n && maxSweepIndex >= 0) {
|
|
388
|
-
const payerWallet = wallets[maxSweepIndex];
|
|
389
|
-
const nonces = await nonceManager.getNextNonceBatch(payerWallet, 2);
|
|
390
|
-
payerProfitNonce = nonces[1];
|
|
391
|
-
}
|
|
392
|
-
const walletsToSweep = wallets.filter((_, i) => sweepAmounts[i] > 0n && i !== maxSweepIndex);
|
|
393
|
-
const nonces = walletsToSweep.length > 0 ? await nonceManager.getNextNoncesForWallets(walletsToSweep) : [];
|
|
394
|
-
let nonceIdx = 0;
|
|
395
|
-
const txPromises = wallets.map(async (w, i) => {
|
|
396
|
-
const toSend = sweepAmounts[i];
|
|
397
|
-
if (toSend <= 0n)
|
|
398
|
-
return null;
|
|
399
|
-
// ✅ 全额归集,不从转账金额中扣除利润
|
|
400
|
-
let nonce;
|
|
401
|
-
if (i === maxSweepIndex && payerProfitNonce !== undefined) {
|
|
402
|
-
nonce = payerProfitNonce - 1;
|
|
403
|
-
}
|
|
404
|
-
else {
|
|
405
|
-
nonce = nonces[nonceIdx++];
|
|
406
|
-
}
|
|
407
|
-
const mainTx = await w.signTransaction({
|
|
408
|
-
to: target,
|
|
409
|
-
value: toSend,
|
|
410
|
-
nonce,
|
|
411
|
-
gasPrice,
|
|
412
|
-
gasLimit: nativeGasLimit,
|
|
413
|
-
chainId: chainIdNum,
|
|
414
|
-
type: txType,
|
|
415
|
-
});
|
|
416
|
-
return mainTx;
|
|
417
|
-
});
|
|
418
|
-
const allTxs = (await Promise.all(txPromises)).filter((tx) => tx !== null);
|
|
419
|
-
signedTxs.push(...allTxs);
|
|
420
|
-
// ✅ 利润多跳转账(固定费用,原生代币)
|
|
421
|
-
if (extractProfit && totalProfit > 0n && maxSweepIndex >= 0 && payerProfitNonce !== undefined) {
|
|
422
|
-
const payerWallet = wallets[maxSweepIndex];
|
|
423
|
-
const profitHopResult = await buildProfitHopTransactions({
|
|
424
|
-
provider,
|
|
425
|
-
payerWallet,
|
|
426
|
-
profitAmount: totalProfit,
|
|
427
|
-
profitRecipient: profitAddr,
|
|
428
|
-
hopCount: PROFIT_HOP_COUNT,
|
|
429
|
-
gasPrice,
|
|
430
|
-
chainId: chainIdNum,
|
|
431
|
-
txType,
|
|
432
|
-
startNonce: payerProfitNonce,
|
|
433
|
-
});
|
|
434
|
-
signedTxs.push(...profitHopResult.signedTransactions);
|
|
435
|
-
profitHopWallets = profitHopResult.hopWallets;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
else {
|
|
439
|
-
// ERC20 归集
|
|
440
|
-
const [gasPrice, decimals, balances, nativeBalances] = await Promise.all([
|
|
441
|
-
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
442
|
-
Promise.resolve(tokenDecimals ?? (await getErc20Decimals(provider, tokenAddress))),
|
|
443
|
-
batchGetBalances(provider, addresses, tokenAddress),
|
|
444
|
-
batchGetBalances(provider, addresses),
|
|
445
|
-
]);
|
|
446
|
-
const iface = new ethers.Interface(['function transfer(address,uint256) returns (bool)']);
|
|
447
|
-
const profitTxGas = GAS_LIMITS.NATIVE_TRANSFER * gasPrice * BigInt(PROFIT_HOP_COUNT + 1);
|
|
448
|
-
const sweepAmounts = [];
|
|
449
|
-
let maxSweepIndex = -1;
|
|
450
|
-
let maxSweepAmount = 0n;
|
|
451
|
-
for (let i = 0; i < wallets.length; i++) {
|
|
452
|
-
const bal = balances[i];
|
|
453
|
-
let toSend = 0n;
|
|
454
|
-
const ratioForI = (() => {
|
|
455
|
-
if (sources && sources[i] && sources[i].ratioPct !== undefined)
|
|
456
|
-
return clamp(sources[i].ratioPct);
|
|
457
|
-
if (ratios && ratios[i] !== undefined)
|
|
458
|
-
return clamp(ratios[i]);
|
|
459
|
-
return ratio;
|
|
460
|
-
})();
|
|
461
|
-
const amountStrForI = (() => {
|
|
462
|
-
if (sources && sources[i] && sources[i].amount !== undefined)
|
|
463
|
-
return String(sources[i].amount);
|
|
464
|
-
if (amounts && amounts[i] !== undefined)
|
|
465
|
-
return String(amounts[i]);
|
|
466
|
-
return amount !== undefined ? String(amount) : undefined;
|
|
467
|
-
})();
|
|
468
|
-
if (ratioForI !== undefined) {
|
|
469
|
-
toSend = (bal * BigInt(ratioForI)) / 100n;
|
|
470
|
-
}
|
|
471
|
-
else if (amountStrForI && amountStrForI.trim().length > 0) {
|
|
472
|
-
toSend = ethers.parseUnits(amountStrForI, decimals);
|
|
473
|
-
}
|
|
474
|
-
if (toSend <= 0n || (skipIfInsufficient && bal < toSend)) {
|
|
475
|
-
sweepAmounts.push(0n);
|
|
476
|
-
continue;
|
|
477
|
-
}
|
|
478
|
-
const totalGasNeeded = finalGasLimit * gasPrice;
|
|
479
|
-
const nativeBal = nativeBalances[i] ?? 0n;
|
|
480
|
-
if (skipIfInsufficient && nativeBal < totalGasNeeded) {
|
|
481
|
-
sweepAmounts.push(0n);
|
|
482
|
-
continue;
|
|
483
|
-
}
|
|
484
|
-
sweepAmounts.push(toSend);
|
|
485
|
-
totalAmountBeforeProfit += toSend;
|
|
486
|
-
// ✅ 找出原生代币余额最大的钱包作为利润支付者
|
|
487
|
-
if (nativeBal > maxSweepAmount) {
|
|
488
|
-
maxSweepAmount = nativeBal;
|
|
489
|
-
maxSweepIndex = i;
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
// 检查支付者原生代币余额是否足够支付固定费用
|
|
493
|
-
if (extractProfit && totalProfit > 0n && maxSweepIndex >= 0) {
|
|
494
|
-
const payerNativeBalance = nativeBalances[maxSweepIndex] ?? 0n;
|
|
495
|
-
const payerNeedGas = finalGasLimit * gasPrice + profitTxGas + totalProfit;
|
|
496
|
-
if (payerNativeBalance < payerNeedGas) {
|
|
497
|
-
// 余额不足,跳过利润收取
|
|
498
|
-
totalProfit = 0n;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
let payerProfitNonce;
|
|
502
|
-
if (extractProfit && totalProfit > 0n && maxSweepIndex >= 0) {
|
|
503
|
-
const payerWallet = wallets[maxSweepIndex];
|
|
504
|
-
const nonces = await nonceManager.getNextNonceBatch(payerWallet, 2);
|
|
505
|
-
payerProfitNonce = nonces[1];
|
|
506
|
-
}
|
|
507
|
-
const walletsToSweepErc20 = wallets.filter((_, i) => sweepAmounts[i] > 0n && i !== maxSweepIndex);
|
|
508
|
-
const noncesErc20 = walletsToSweepErc20.length > 0 ? await nonceManager.getNextNoncesForWallets(walletsToSweepErc20) : [];
|
|
509
|
-
let nonceIdxErc20 = 0;
|
|
510
|
-
const txPromises = wallets.map(async (w, i) => {
|
|
511
|
-
const toSend = sweepAmounts[i];
|
|
512
|
-
if (toSend <= 0n)
|
|
513
|
-
return null;
|
|
514
|
-
let nonce;
|
|
515
|
-
if (i === maxSweepIndex && payerProfitNonce !== undefined) {
|
|
516
|
-
nonce = payerProfitNonce - 1;
|
|
517
|
-
}
|
|
518
|
-
else {
|
|
519
|
-
nonce = noncesErc20[nonceIdxErc20++];
|
|
520
|
-
}
|
|
521
|
-
// ✅ 全额归集 ERC20,不从转账金额中扣除利润
|
|
522
|
-
const data = iface.encodeFunctionData('transfer', [target, toSend]);
|
|
523
|
-
const mainTx = await w.signTransaction({
|
|
524
|
-
to: tokenAddress,
|
|
525
|
-
data,
|
|
526
|
-
value: 0n,
|
|
527
|
-
nonce,
|
|
528
|
-
gasPrice,
|
|
529
|
-
gasLimit: finalGasLimit,
|
|
530
|
-
chainId: chainIdNum,
|
|
531
|
-
type: txType,
|
|
532
|
-
});
|
|
533
|
-
return mainTx;
|
|
534
|
-
});
|
|
535
|
-
const allTxs = (await Promise.all(txPromises)).filter((tx) => tx !== null);
|
|
536
|
-
signedTxs.push(...allTxs);
|
|
537
|
-
// ✅ 利润多跳转账(固定费用,原生代币)
|
|
538
|
-
if (extractProfit && totalProfit > 0n && maxSweepIndex >= 0 && payerProfitNonce !== undefined) {
|
|
539
|
-
const payerWallet = wallets[maxSweepIndex];
|
|
540
|
-
const profitHopResult = await buildProfitHopTransactions({
|
|
541
|
-
provider,
|
|
542
|
-
payerWallet,
|
|
543
|
-
profitAmount: totalProfit,
|
|
544
|
-
profitRecipient: profitAddr,
|
|
545
|
-
hopCount: PROFIT_HOP_COUNT,
|
|
546
|
-
gasPrice,
|
|
547
|
-
chainId: chainIdNum,
|
|
548
|
-
txType,
|
|
549
|
-
startNonce: payerProfitNonce,
|
|
550
|
-
});
|
|
551
|
-
signedTxs.push(...profitHopResult.signedTransactions);
|
|
552
|
-
profitHopWallets = profitHopResult.hopWallets;
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
else {
|
|
557
|
-
// ========== 有多跳:构建跳转链归集 ==========
|
|
558
|
-
const sourceWallets = actualKeys.map((pk) => new Wallet(pk, provider));
|
|
559
|
-
// ✅ 按地址数量收取固定费用(原生代币)
|
|
560
|
-
if (extractProfit) {
|
|
561
|
-
totalProfit = calculateTransferFee(chainIdNum, sourceWallets.length);
|
|
562
|
-
}
|
|
563
|
-
const withHopIndexes = [];
|
|
564
|
-
const withoutHopIndexes = [];
|
|
565
|
-
for (let i = 0; i < preparedHops.length; i++) {
|
|
566
|
-
if (preparedHops[i].length > 0) {
|
|
567
|
-
withHopIndexes.push(i);
|
|
568
|
-
}
|
|
569
|
-
else {
|
|
570
|
-
withoutHopIndexes.push(i);
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
const sourceAddresses = sourceWallets.map((w) => w.address);
|
|
574
|
-
const [gasPrice, decimals, balances, nativeBalances] = await Promise.all([
|
|
575
|
-
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
576
|
-
isNative
|
|
577
|
-
? Promise.resolve(18)
|
|
578
|
-
: Promise.resolve(tokenDecimals ?? (await getErc20Decimals(provider, tokenAddress))),
|
|
579
|
-
batchGetBalances(provider, sourceAddresses, tokenAddress),
|
|
580
|
-
isNative ? Promise.resolve([]) : batchGetBalances(provider, sourceAddresses),
|
|
581
|
-
]);
|
|
582
|
-
const iface = isNative ? null : new ethers.Interface(['function transfer(address,uint256) returns (bool)']);
|
|
583
|
-
const gasFeePerHop = finalGasLimit * gasPrice;
|
|
584
|
-
const nonceManager = new NonceManager(provider);
|
|
585
|
-
const sweepAmounts = new Array(sourceWallets.length).fill(0n);
|
|
586
|
-
// 处理无跳转的地址
|
|
587
|
-
for (const i of withoutHopIndexes) {
|
|
588
|
-
const sourceWallet = sourceWallets[i];
|
|
589
|
-
const bal = balances[i];
|
|
590
|
-
let toSend = 0n;
|
|
591
|
-
if (isNative) {
|
|
592
|
-
const gasCost = nativeGasLimit * gasPrice;
|
|
593
|
-
const ratioForI = (() => {
|
|
594
|
-
if (sources && sources[i] && sources[i].ratioPct !== undefined)
|
|
595
|
-
return clamp(sources[i].ratioPct);
|
|
596
|
-
if (ratios && ratios[i] !== undefined)
|
|
597
|
-
return clamp(ratios[i]);
|
|
598
|
-
return ratio;
|
|
599
|
-
})();
|
|
600
|
-
const amountStrForI = (() => {
|
|
601
|
-
if (sources && sources[i] && sources[i].amount !== undefined)
|
|
602
|
-
return String(sources[i].amount);
|
|
603
|
-
if (amounts && amounts[i] !== undefined)
|
|
604
|
-
return String(amounts[i]);
|
|
605
|
-
return amount !== undefined ? String(amount) : undefined;
|
|
606
|
-
})();
|
|
607
|
-
if (ratioForI !== undefined) {
|
|
608
|
-
const want = (bal * BigInt(ratioForI)) / 100n;
|
|
609
|
-
const maxSendable = bal > gasCost ? bal - gasCost : 0n;
|
|
610
|
-
toSend = want > maxSendable ? maxSendable : want;
|
|
611
|
-
}
|
|
612
|
-
else if (amountStrForI && amountStrForI.trim().length > 0) {
|
|
613
|
-
const amt = ethers.parseEther(amountStrForI);
|
|
614
|
-
const need = amt + gasCost;
|
|
615
|
-
if (!skipIfInsufficient || bal >= need)
|
|
616
|
-
toSend = amt;
|
|
617
|
-
}
|
|
618
|
-
if (toSend > 0n) {
|
|
619
|
-
sweepAmounts[i] = toSend;
|
|
620
|
-
totalAmountBeforeProfit += toSend;
|
|
621
|
-
const nonce = await nonceManager.getNextNonce(sourceWallet);
|
|
622
|
-
const tx = await sourceWallet.signTransaction({
|
|
623
|
-
to: target,
|
|
624
|
-
value: toSend,
|
|
625
|
-
nonce,
|
|
626
|
-
gasPrice,
|
|
627
|
-
gasLimit: nativeGasLimit,
|
|
628
|
-
chainId: chainIdNum,
|
|
629
|
-
type: txType,
|
|
630
|
-
});
|
|
631
|
-
signedTxs.push(tx);
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
else {
|
|
635
|
-
const ratioForI = (() => {
|
|
636
|
-
if (sources && sources[i] && sources[i].ratioPct !== undefined)
|
|
637
|
-
return clamp(sources[i].ratioPct);
|
|
638
|
-
if (ratios && ratios[i] !== undefined)
|
|
639
|
-
return clamp(ratios[i]);
|
|
640
|
-
return ratio;
|
|
641
|
-
})();
|
|
642
|
-
const amountStrForI = (() => {
|
|
643
|
-
if (sources && sources[i] && sources[i].amount !== undefined)
|
|
644
|
-
return String(sources[i].amount);
|
|
645
|
-
if (amounts && amounts[i] !== undefined)
|
|
646
|
-
return String(amounts[i]);
|
|
647
|
-
return amount !== undefined ? String(amount) : undefined;
|
|
648
|
-
})();
|
|
649
|
-
if (ratioForI !== undefined) {
|
|
650
|
-
toSend = (bal * BigInt(ratioForI)) / 100n;
|
|
651
|
-
}
|
|
652
|
-
else if (amountStrForI && amountStrForI.trim().length > 0) {
|
|
653
|
-
toSend = ethers.parseUnits(amountStrForI, decimals);
|
|
654
|
-
}
|
|
655
|
-
if (toSend > 0n && (!skipIfInsufficient || bal >= toSend)) {
|
|
656
|
-
sweepAmounts[i] = toSend;
|
|
657
|
-
totalAmountBeforeProfit += toSend;
|
|
658
|
-
const nonce = await nonceManager.getNextNonce(sourceWallet);
|
|
659
|
-
const data = iface.encodeFunctionData('transfer', [target, toSend]);
|
|
660
|
-
const tx = await sourceWallet.signTransaction({
|
|
661
|
-
to: tokenAddress,
|
|
662
|
-
data,
|
|
663
|
-
value: 0n,
|
|
664
|
-
nonce,
|
|
665
|
-
gasPrice,
|
|
666
|
-
gasLimit: finalGasLimit,
|
|
667
|
-
chainId: chainIdNum,
|
|
668
|
-
type: txType,
|
|
669
|
-
});
|
|
670
|
-
signedTxs.push(tx);
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
// 处理有跳转的地址
|
|
675
|
-
for (const i of withHopIndexes) {
|
|
676
|
-
const sourceWallet = sourceWallets[i];
|
|
677
|
-
const hopChain = preparedHops[i];
|
|
678
|
-
let toSend = 0n;
|
|
679
|
-
const bal = balances[i];
|
|
680
|
-
if (isNative) {
|
|
681
|
-
const totalGasCost = finalGasLimit * gasPrice * BigInt(hopChain.length + 1);
|
|
682
|
-
const ratioForI = (() => {
|
|
683
|
-
if (sources && sources[i] && sources[i].ratioPct !== undefined)
|
|
684
|
-
return clamp(sources[i].ratioPct);
|
|
685
|
-
if (ratios && ratios[i] !== undefined)
|
|
686
|
-
return clamp(ratios[i]);
|
|
687
|
-
return ratio;
|
|
688
|
-
})();
|
|
689
|
-
const amountStrForI = (() => {
|
|
690
|
-
if (sources && sources[i] && sources[i].amount !== undefined)
|
|
691
|
-
return String(sources[i].amount);
|
|
692
|
-
if (amounts && amounts[i] !== undefined)
|
|
693
|
-
return String(amounts[i]);
|
|
694
|
-
return amount !== undefined ? String(amount) : undefined;
|
|
695
|
-
})();
|
|
696
|
-
if (ratioForI !== undefined) {
|
|
697
|
-
const want = (bal * BigInt(ratioForI)) / 100n;
|
|
698
|
-
const maxSendable = bal > totalGasCost ? bal - totalGasCost : 0n;
|
|
699
|
-
toSend = want > maxSendable ? maxSendable : want;
|
|
700
|
-
}
|
|
701
|
-
else if (amountStrForI && amountStrForI.trim().length > 0) {
|
|
702
|
-
const amt = ethers.parseEther(amountStrForI);
|
|
703
|
-
const need = amt + totalGasCost;
|
|
704
|
-
if (!skipIfInsufficient || bal >= need)
|
|
705
|
-
toSend = amt;
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
else {
|
|
709
|
-
const nativeBal = nativeBalances[i];
|
|
710
|
-
const nativeNeeded = gasFeePerHop * BigInt(hopChain.length) + finalGasLimit * gasPrice;
|
|
711
|
-
if (nativeBal < nativeNeeded && skipIfInsufficient)
|
|
712
|
-
continue;
|
|
713
|
-
const ratioForI = (() => {
|
|
714
|
-
if (sources && sources[i] && sources[i].ratioPct !== undefined)
|
|
715
|
-
return clamp(sources[i].ratioPct);
|
|
716
|
-
if (ratios && ratios[i] !== undefined)
|
|
717
|
-
return clamp(ratios[i]);
|
|
718
|
-
return ratio;
|
|
719
|
-
})();
|
|
720
|
-
const amountStrForI = (() => {
|
|
721
|
-
if (sources && sources[i] && sources[i].amount !== undefined)
|
|
722
|
-
return String(sources[i].amount);
|
|
723
|
-
if (amounts && amounts[i] !== undefined)
|
|
724
|
-
return String(amounts[i]);
|
|
725
|
-
return amount !== undefined ? String(amount) : undefined;
|
|
726
|
-
})();
|
|
727
|
-
if (ratioForI !== undefined) {
|
|
728
|
-
toSend = (bal * BigInt(ratioForI)) / 100n;
|
|
729
|
-
}
|
|
730
|
-
else if (amountStrForI && amountStrForI.trim().length > 0) {
|
|
731
|
-
toSend = ethers.parseUnits(amountStrForI, decimals);
|
|
732
|
-
}
|
|
733
|
-
if (skipIfInsufficient && bal < toSend)
|
|
734
|
-
toSend = 0n;
|
|
735
|
-
}
|
|
736
|
-
if (toSend <= 0n)
|
|
737
|
-
continue;
|
|
738
|
-
sweepAmounts[i] = toSend;
|
|
739
|
-
totalAmountBeforeProfit += toSend;
|
|
740
|
-
// ✅ 支持 string 和 GeneratedWallet 两种类型
|
|
741
|
-
const fullChain = [
|
|
742
|
-
sourceWallet,
|
|
743
|
-
...hopChain.map((w) => new Wallet(typeof w === 'string' ? w : w.privateKey, provider)),
|
|
744
|
-
];
|
|
745
|
-
const addresses = [...fullChain.map((w) => w.address), target];
|
|
746
|
-
if (!isNative) {
|
|
747
|
-
const gasNonces = await nonceManager.getNextNonceBatch(sourceWallet, hopChain.length);
|
|
748
|
-
for (let j = 0; j < hopChain.length; j++) {
|
|
749
|
-
const tx = await sourceWallet.signTransaction({
|
|
750
|
-
to: fullChain[j + 1].address,
|
|
751
|
-
value: gasFeePerHop,
|
|
752
|
-
nonce: gasNonces[j],
|
|
753
|
-
gasPrice,
|
|
754
|
-
gasLimit: nativeGasLimit,
|
|
755
|
-
chainId: chainIdNum,
|
|
756
|
-
type: txType,
|
|
757
|
-
});
|
|
758
|
-
signedTxs.push(tx);
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
for (let j = 0; j < addresses.length - 1; j++) {
|
|
762
|
-
const fromWallet = fullChain[j];
|
|
763
|
-
const toAddress = addresses[j + 1];
|
|
764
|
-
const nonce = j === 0 ? await nonceManager.getNextNonce(sourceWallet) : 0;
|
|
765
|
-
if (isNative) {
|
|
766
|
-
const remainingHops = addresses.length - 2 - j;
|
|
767
|
-
const additionalGas = gasFeePerHop * BigInt(remainingHops);
|
|
768
|
-
const valueToTransfer = toSend + additionalGas;
|
|
769
|
-
const tx = await fromWallet.signTransaction({
|
|
770
|
-
to: toAddress,
|
|
771
|
-
value: valueToTransfer,
|
|
772
|
-
nonce,
|
|
773
|
-
gasPrice,
|
|
774
|
-
gasLimit: finalGasLimit,
|
|
775
|
-
chainId: chainIdNum,
|
|
776
|
-
type: txType,
|
|
777
|
-
});
|
|
778
|
-
signedTxs.push(tx);
|
|
779
|
-
}
|
|
780
|
-
else {
|
|
781
|
-
const data = iface.encodeFunctionData('transfer', [toAddress, toSend]);
|
|
782
|
-
const tx = await fromWallet.signTransaction({
|
|
783
|
-
to: tokenAddress,
|
|
784
|
-
data,
|
|
785
|
-
value: 0n,
|
|
786
|
-
nonce,
|
|
787
|
-
gasPrice,
|
|
788
|
-
gasLimit: finalGasLimit,
|
|
789
|
-
chainId: chainIdNum,
|
|
790
|
-
type: txType,
|
|
791
|
-
});
|
|
792
|
-
signedTxs.push(tx);
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
// ✅ 利润多跳转账(固定费用,原生代币)- totalProfit 已在函数开头计算
|
|
797
|
-
if (extractProfit && totalProfit > 0n && totalAmountBeforeProfit > 0n) {
|
|
798
|
-
// 找出余额最大的钱包作为利润支付者
|
|
799
|
-
let maxSweepIndex = -1;
|
|
800
|
-
let maxSweepAmount = 0n;
|
|
801
|
-
for (let i = 0; i < sweepAmounts.length; i++) {
|
|
802
|
-
if (sweepAmounts[i] > maxSweepAmount) {
|
|
803
|
-
maxSweepAmount = sweepAmounts[i];
|
|
804
|
-
maxSweepIndex = i;
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
if (maxSweepIndex >= 0) {
|
|
808
|
-
const payerWallet = sourceWallets[maxSweepIndex];
|
|
809
|
-
const profitNonce = await nonceManager.getNextNonce(payerWallet);
|
|
810
|
-
const profitHopResult = await buildProfitHopTransactions({
|
|
811
|
-
provider,
|
|
812
|
-
payerWallet,
|
|
813
|
-
profitAmount: totalProfit,
|
|
814
|
-
profitRecipient: profitAddr,
|
|
815
|
-
hopCount: PROFIT_HOP_COUNT,
|
|
816
|
-
gasPrice,
|
|
817
|
-
chainId: chainIdNum,
|
|
818
|
-
txType,
|
|
819
|
-
startNonce: profitNonce,
|
|
820
|
-
});
|
|
821
|
-
signedTxs.push(...profitHopResult.signedTransactions);
|
|
822
|
-
profitHopWallets = profitHopResult.hopWallets;
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
return {
|
|
827
|
-
signedTransactions: signedTxs,
|
|
828
|
-
hopWallets: preparedHops || undefined,
|
|
829
|
-
profitHopWallets, // ✅ 返回利润多跳钱包
|
|
830
|
-
metadata: extractProfit
|
|
831
|
-
? {
|
|
832
|
-
totalAmount: isNative
|
|
833
|
-
? ethers.formatEther(totalAmountBeforeProfit)
|
|
834
|
-
: ethers.formatUnits(totalAmountBeforeProfit, tokenDecimals ?? 18),
|
|
835
|
-
profitAmount: ethers.formatEther(totalProfit),
|
|
836
|
-
profitRecipient: profitAddr,
|
|
837
|
-
sourceCount: actualKeys.length,
|
|
838
|
-
isNative,
|
|
839
|
-
tokenAddress: isNative ? undefined : tokenAddress,
|
|
840
|
-
}
|
|
841
|
-
: undefined,
|
|
842
|
-
};
|
|
843
|
-
}
|
|
7
|
+
export * from './utils/index.js';
|