four-flap-meme-sdk 3.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle/four-meme/approve-tokenmanager.d.ts +2 -2
- package/dist/bundle/four-meme/approve-tokenmanager.js +3 -3
- package/dist/bundle/four-meme/core/buy-flow.d.ts +5 -0
- package/dist/bundle/four-meme/core/buy-flow.js +147 -0
- package/dist/bundle/four-meme/core/constants.d.ts +6 -0
- package/dist/bundle/four-meme/core/constants.js +15 -0
- package/dist/bundle/four-meme/core/create-token.d.ts +5 -0
- package/dist/bundle/four-meme/core/create-token.js +137 -0
- package/dist/bundle/four-meme/core/index.d.ts +14 -0
- package/dist/bundle/four-meme/core/index.js +14 -0
- package/dist/bundle/four-meme/core/sell-flow.d.ts +5 -0
- package/dist/bundle/four-meme/core/sell-flow.js +240 -0
- package/dist/bundle/four-meme/core-helpers.js +1 -1
- package/dist/bundle/four-meme/core.d.ts +7 -4
- package/dist/bundle/four-meme/core.js +5 -513
- package/dist/bundle/four-meme/pancake-proxy/approve.d.ts +15 -0
- package/dist/bundle/four-meme/pancake-proxy/approve.js +113 -0
- package/dist/bundle/four-meme/pancake-proxy/buy.d.ts +8 -0
- package/dist/bundle/four-meme/pancake-proxy/buy.js +143 -0
- package/dist/bundle/four-meme/pancake-proxy/constants.d.ts +25 -0
- package/dist/bundle/four-meme/pancake-proxy/constants.js +14 -0
- package/dist/bundle/four-meme/pancake-proxy/helpers.d.ts +45 -0
- package/dist/bundle/four-meme/pancake-proxy/helpers.js +232 -0
- package/dist/bundle/four-meme/pancake-proxy/index.d.ts +15 -0
- package/dist/bundle/four-meme/pancake-proxy/index.js +15 -0
- package/dist/bundle/four-meme/pancake-proxy/sell.d.ts +8 -0
- package/dist/bundle/four-meme/pancake-proxy/sell.js +194 -0
- package/dist/bundle/four-meme/pancake-proxy.d.ts +4 -20
- package/dist/bundle/four-meme/pancake-proxy.js +3 -670
- package/dist/bundle/four-meme/private/buy.d.ts +16 -0
- package/dist/bundle/four-meme/private/buy.js +225 -0
- package/dist/bundle/four-meme/private/index.d.ts +11 -0
- package/dist/bundle/four-meme/private/index.js +11 -0
- package/dist/bundle/four-meme/private/sell.d.ts +18 -0
- package/dist/bundle/four-meme/private/sell.js +245 -0
- package/dist/bundle/four-meme/private.d.ts +5 -25
- package/dist/bundle/four-meme/private.js +5 -463
- package/dist/bundle/four-meme/swap/batch.d.ts +8 -0
- package/dist/bundle/four-meme/swap/batch.js +170 -0
- package/dist/bundle/four-meme/swap/bundle.d.ts +8 -0
- package/dist/bundle/four-meme/swap/bundle.js +147 -0
- package/dist/bundle/four-meme/swap/index.d.ts +14 -0
- package/dist/bundle/four-meme/swap/index.js +13 -0
- package/dist/bundle/four-meme/swap/quick-batch.d.ts +8 -0
- package/dist/bundle/four-meme/swap/quick-batch.js +206 -0
- package/dist/bundle/four-meme/swap-buy-first/helpers.d.ts +20 -0
- package/dist/bundle/four-meme/swap-buy-first/helpers.js +39 -0
- package/dist/bundle/four-meme/swap-buy-first/index.d.ts +12 -0
- package/dist/bundle/four-meme/swap-buy-first/index.js +11 -0
- package/dist/bundle/four-meme/swap-buy-first/multi-wallet.d.ts +20 -0
- package/dist/bundle/four-meme/swap-buy-first/multi-wallet.js +198 -0
- package/dist/bundle/four-meme/swap-buy-first/single.d.ts +7 -0
- package/dist/bundle/four-meme/swap-buy-first/single.js +232 -0
- package/dist/bundle/four-meme/swap-buy-first.d.ts +4 -3
- package/dist/bundle/four-meme/swap-buy-first.js +4 -451
- package/dist/bundle/four-meme/swap-hop-helpers.d.ts +2 -2
- package/dist/bundle/four-meme/swap-sign-helpers.d.ts +2 -2
- package/dist/bundle/four-meme/swap-sign-helpers.js +1 -1
- package/dist/bundle/four-meme/swap.d.ts +4 -14
- package/dist/bundle/four-meme/swap.js +4 -502
- package/dist/bundle/four-meme/types/index.d.ts +1 -1
- package/dist/bundle/four-meme/utils-disperse.d.ts +1 -1
- package/dist/bundle/four-meme/utils-disperse.js +1 -1
- package/dist/bundle/four-meme/utils-pairwise.d.ts +1 -1
- package/dist/bundle/four-meme/utils-pairwise.js +1 -1
- package/dist/bundle/four-meme/utils-sweep/context.d.ts +39 -0
- package/dist/bundle/four-meme/utils-sweep/context.js +7 -0
- package/dist/bundle/four-meme/utils-sweep/erc20-no-hop.d.ts +5 -0
- package/dist/bundle/four-meme/utils-sweep/erc20-no-hop.js +162 -0
- package/dist/bundle/four-meme/utils-sweep/index.d.ts +13 -0
- package/dist/bundle/four-meme/utils-sweep/index.js +13 -0
- package/dist/bundle/four-meme/utils-sweep/main.d.ts +8 -0
- package/dist/bundle/four-meme/utils-sweep/main.js +114 -0
- package/dist/bundle/four-meme/utils-sweep/native-no-hop.d.ts +5 -0
- package/dist/bundle/four-meme/utils-sweep/native-no-hop.js +156 -0
- package/dist/bundle/four-meme/utils-sweep/with-hops.d.ts +6 -0
- package/dist/bundle/four-meme/utils-sweep/with-hops.js +382 -0
- package/dist/bundle/four-meme/utils-sweep.d.ts +3 -4
- package/dist/bundle/four-meme/utils-sweep.js +3 -740
- package/dist/bundle/internal.d.ts +2 -2
- package/dist/bundle/sign-context-helpers.d.ts +1 -26
- package/dist/bundle/sign-context-helpers.js +1 -63
- package/dist/bundle/submit/blockrazor.d.ts +94 -0
- package/dist/bundle/submit/blockrazor.js +122 -0
- package/dist/bundle/submit/direct.d.ts +118 -0
- package/dist/bundle/submit/direct.js +484 -0
- package/dist/bundle/submit/helpers.d.ts +7 -0
- package/dist/bundle/submit/helpers.js +15 -0
- package/dist/bundle/submit/index.d.ts +14 -0
- package/dist/bundle/submit/index.js +14 -0
- package/dist/bundle/submit/merkle.d.ts +84 -0
- package/dist/bundle/submit/merkle.js +121 -0
- package/dist/bundle/submit.d.ts +3 -286
- package/dist/bundle/submit.js +3 -724
- package/dist/chains/bsc/four/types.d.ts +1 -1
- package/dist/chains/bsc/index.d.ts +1 -1
- package/dist/chains/bsc/index.js +2 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-build.d.ts +25 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-build.js +177 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-constants.d.ts +30 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-constants.js +24 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-helpers.d.ts +11 -149
- package/dist/chains/bsc/pancake/bundle-buy-first-helpers.js +12 -74
- package/dist/chains/bsc/pancake/bundle-buy-first-multi-wallet.d.ts +9 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-multi-wallet.js +225 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-plan.d.ts +14 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-plan.js +64 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-profit.d.ts +12 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-profit.js +22 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-quote.d.ts +15 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-quote.js +122 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-types.d.ts +179 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-types.js +1 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-validate.d.ts +2 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-validate.js +41 -0
- package/dist/chains/bsc/pancake/bundle-buy-first.d.ts +1 -1
- package/dist/chains/bsc/pancake/bundle-buy-first.js +8 -578
- package/dist/chains/bsc/pancake/bundle-swap-helpers.d.ts +11 -239
- package/dist/chains/bsc/pancake/bundle-swap-helpers.js +12 -564
- package/dist/chains/bsc/pancake/bundle-swap-types.d.ts +183 -0
- package/dist/chains/bsc/pancake/bundle-swap-types.js +17 -0
- package/dist/chains/bsc/pancake/bundle-swap.d.ts +10 -132
- package/dist/chains/bsc/pancake/bundle-swap.js +12 -1003
- package/dist/chains/bsc/pancake/hop-chain.d.ts +18 -0
- package/dist/chains/bsc/pancake/hop-chain.js +227 -0
- package/dist/chains/bsc/pancake/quote.d.ts +14 -0
- package/dist/chains/bsc/pancake/quote.js +84 -0
- package/dist/chains/bsc/pancake/swap-batch.d.ts +42 -0
- package/dist/chains/bsc/pancake/swap-batch.js +283 -0
- package/dist/chains/bsc/pancake/swap-build.d.ts +19 -0
- package/dist/chains/bsc/pancake/swap-build.js +226 -0
- package/dist/chains/bsc/pancake/swap-cross.d.ts +42 -0
- package/dist/chains/bsc/pancake/swap-cross.js +140 -0
- package/dist/chains/bsc/pancake/swap-quick.d.ts +54 -0
- package/dist/chains/bsc/pancake/swap-quick.js +424 -0
- package/dist/chains/bsc/pancake/swap-single.d.ts +2 -0
- package/dist/chains/bsc/pancake/swap-single.js +182 -0
- package/dist/chains/bsc/platforms/four/index.d.ts +21 -3
- package/dist/chains/bsc/platforms/four/index.js +28 -3
- package/dist/chains/eni/batch-router/transfer-disperse.d.ts +37 -0
- package/dist/chains/eni/batch-router/transfer-disperse.js +302 -0
- package/dist/chains/eni/batch-router/transfer-shared.d.ts +9 -0
- package/dist/chains/eni/batch-router/transfer-shared.js +10 -0
- package/dist/chains/eni/batch-router/transfer-sweep.d.ts +51 -0
- package/dist/chains/eni/batch-router/transfer-sweep.js +364 -0
- package/dist/chains/eni/batch-router/transfer.d.ts +4 -74
- package/dist/chains/eni/batch-router/transfer.js +2 -647
- package/dist/chains/eni/index.d.ts +2 -0
- package/dist/chains/eni/index.js +4 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct-profit.d.ts +17 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct-profit.js +30 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct-submit.d.ts +12 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct-submit.js +396 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct-tx.d.ts +20 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct-tx.js +165 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct.d.ts +3 -32
- package/dist/chains/eni/platforms/daoaas/portal-direct.js +3 -571
- package/dist/chains/eni/submit.js +1 -1
- package/dist/chains/xlayer/constants.d.ts +0 -2
- package/dist/chains/xlayer/constants.js +0 -2
- package/dist/chains/xlayer/eip7702/auth.d.ts +16 -0
- package/dist/chains/xlayer/eip7702/auth.js +81 -0
- package/dist/chains/xlayer/eip7702/bundle-create-buy.d.ts +22 -0
- package/dist/chains/xlayer/eip7702/bundle-create-buy.js +201 -0
- package/dist/chains/xlayer/eip7702/bundle-create-helpers.d.ts +114 -0
- package/dist/chains/xlayer/eip7702/bundle-create-helpers.js +139 -0
- package/dist/chains/xlayer/eip7702/bundle-create-to-dex.d.ts +24 -0
- package/dist/chains/xlayer/eip7702/bundle-create-to-dex.js +233 -0
- package/dist/chains/xlayer/eip7702/bundle-create.d.ts +3 -35
- package/dist/chains/xlayer/eip7702/bundle-create.js +3 -746
- package/dist/chains/xlayer/eip7702/bundle-graduate-buy.d.ts +22 -0
- package/dist/chains/xlayer/eip7702/bundle-graduate-buy.js +214 -0
- package/dist/chains/xlayer/eip7702/bundle-sell.js +1 -1
- package/dist/chains/xlayer/eip7702/bundle-swap-batch.d.ts +31 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-batch.js +216 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-helpers.d.ts +21 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-helpers.js +206 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-multi.d.ts +33 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-multi.js +146 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-single.d.ts +31 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-single.js +177 -0
- package/dist/chains/xlayer/eip7702/bundle-swap.d.ts +6 -61
- package/dist/chains/xlayer/eip7702/bundle-swap.js +3 -712
- package/dist/chains/xlayer/eip7702/bytes.d.ts +4 -0
- package/dist/chains/xlayer/eip7702/bytes.js +31 -0
- package/dist/chains/xlayer/eip7702/gas.d.ts +19 -0
- package/dist/chains/xlayer/eip7702/gas.js +152 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-disperse.d.ts +5 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-disperse.js +196 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-pairwise.d.ts +5 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-pairwise.js +188 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-sweep.d.ts +5 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-sweep.js +220 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer.d.ts +8 -4
- package/dist/chains/xlayer/eip7702/multi-hop-transfer.js +5 -591
- package/dist/chains/xlayer/eip7702/profit.d.ts +32 -0
- package/dist/chains/xlayer/eip7702/profit.js +59 -0
- package/dist/chains/xlayer/eip7702/provider.d.ts +3 -0
- package/dist/chains/xlayer/eip7702/provider.js +17 -0
- package/dist/chains/xlayer/eip7702/time.d.ts +2 -0
- package/dist/chains/xlayer/eip7702/time.js +10 -0
- package/dist/chains/xlayer/eip7702/tx-build.d.ts +10 -0
- package/dist/chains/xlayer/eip7702/tx-build.js +128 -0
- package/dist/chains/xlayer/eip7702/utils.d.ts +19 -85
- package/dist/chains/xlayer/eip7702/utils.js +19 -484
- package/dist/chains/xlayer/eip7702/volume-bundle.d.ts +13 -0
- package/dist/chains/xlayer/eip7702/volume-bundle.js +250 -0
- package/dist/chains/xlayer/eip7702/volume-internal.d.ts +13 -0
- package/dist/chains/xlayer/eip7702/volume-internal.js +169 -0
- package/dist/chains/xlayer/eip7702/volume-make.d.ts +8 -0
- package/dist/chains/xlayer/eip7702/volume-make.js +38 -0
- package/dist/chains/xlayer/eip7702/volume-single-round.d.ts +17 -0
- package/dist/chains/xlayer/eip7702/volume-single-round.js +44 -0
- package/dist/chains/xlayer/eip7702/volume-swap.d.ts +18 -0
- package/dist/chains/xlayer/eip7702/volume-swap.js +30 -0
- package/dist/chains/xlayer/eip7702/volume-wash.d.ts +8 -0
- package/dist/chains/xlayer/eip7702/volume-wash.js +191 -0
- package/dist/chains/xlayer/eip7702/volume.d.ts +7 -35
- package/dist/chains/xlayer/eip7702/volume.js +5 -697
- package/dist/chains/xlayer/eip7702/wallet.d.ts +6 -0
- package/dist/chains/xlayer/eip7702/wallet.js +17 -0
- package/dist/chains/xlayer/eoa/aa-types.d.ts +176 -0
- package/dist/chains/xlayer/eoa/aa-types.js +6 -0
- package/dist/chains/xlayer/eoa/constants.d.ts +0 -2
- package/dist/chains/xlayer/eoa/constants.js +0 -2
- package/dist/chains/xlayer/eoa/context.d.ts +8 -0
- package/dist/chains/xlayer/eoa/context.js +23 -0
- package/dist/chains/xlayer/eoa/encoders.d.ts +147 -0
- package/dist/chains/xlayer/eoa/encoders.js +147 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-cross.d.ts +5 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-cross.js +113 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.d.ts +10 -123
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.js +10 -225
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-pure.d.ts +50 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-pure.js +170 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-quick.d.ts +5 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-quick.js +257 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-types.d.ts +99 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-types.js +11 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap.d.ts +5 -47
- package/dist/chains/xlayer/eoa/eoa-bundle-swap.js +3 -522
- package/dist/chains/xlayer/eoa/eoa-types.d.ts +776 -0
- package/dist/chains/xlayer/eoa/eoa-types.js +6 -0
- package/dist/chains/xlayer/eoa/eoa-wash-volume.d.ts +8 -0
- package/dist/chains/xlayer/eoa/eoa-wash-volume.js +8 -0
- package/dist/chains/xlayer/eoa/format.d.ts +34 -0
- package/dist/chains/xlayer/eoa/format.js +56 -0
- package/dist/chains/xlayer/eoa/hop-chain.d.ts +4 -0
- package/dist/chains/xlayer/eoa/hop-chain.js +87 -0
- package/dist/chains/xlayer/eoa/nonce-map.d.ts +20 -0
- package/dist/chains/xlayer/eoa/nonce-map.js +51 -0
- package/dist/chains/xlayer/eoa/portal-ops.d.ts +9 -292
- package/dist/chains/xlayer/eoa/portal-ops.js +9 -486
- package/dist/chains/xlayer/eoa/query.d.ts +117 -0
- package/dist/chains/xlayer/eoa/query.js +285 -0
- package/dist/chains/xlayer/eoa/quote.d.ts +6 -0
- package/dist/chains/xlayer/eoa/quote.js +90 -0
- package/dist/chains/xlayer/eoa/types.d.ts +9 -959
- package/dist/chains/xlayer/eoa/types.js +9 -49
- package/dist/core/clients/blockrazor.js +1 -1
- package/dist/core/clients/merkle.js +1 -1
- package/dist/core/erc20/allowances.d.ts +104 -0
- package/dist/core/erc20/allowances.js +205 -0
- package/dist/core/erc20/approve.d.ts +141 -0
- package/dist/core/erc20/approve.js +325 -0
- package/dist/core/erc20/helpers.d.ts +20 -0
- package/dist/core/erc20/helpers.js +109 -0
- package/dist/core/erc20/index.d.ts +13 -0
- package/dist/core/erc20/index.js +12 -0
- package/dist/core/gas/bundle-gas.d.ts +6 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/quote/index.d.ts +1 -0
- package/dist/core/quote/index.js +1 -0
- package/dist/core/quote/quote-helpers.d.ts +78 -0
- package/dist/core/quote/quote-helpers.js +289 -0
- package/dist/core/quote/types.d.ts +1 -0
- package/dist/core/quote/types.js +1 -0
- package/dist/core/sign-context-helpers.d.ts +29 -0
- package/dist/core/sign-context-helpers.js +63 -0
- package/dist/domains/dex/direct-router-helpers.d.ts +16 -268
- package/dist/domains/dex/direct-router-helpers.js +16 -535
- package/dist/domains/dex/direct-router-types.d.ts +104 -0
- package/dist/domains/dex/direct-router-types.js +81 -0
- package/dist/domains/dex/direct-router-v2-buy.d.ts +2 -0
- package/dist/domains/dex/direct-router-v2-buy.js +249 -0
- package/dist/domains/dex/direct-router-v2-sell.d.ts +5 -0
- package/dist/domains/dex/direct-router-v2-sell.js +270 -0
- package/dist/domains/dex/direct-router-v2.d.ts +9 -0
- package/dist/domains/dex/direct-router-v2.js +9 -0
- package/dist/domains/dex/direct-router-v3.d.ts +17 -0
- package/dist/domains/dex/direct-router-v3.js +432 -0
- package/dist/domains/dex/direct-router.d.ts +11 -26
- package/dist/domains/dex/direct-router.js +10 -977
- package/dist/domains/dex/dyo-encode.d.ts +62 -0
- package/dist/domains/dex/dyo-encode.js +124 -0
- package/dist/domains/dex/profit.d.ts +24 -0
- package/dist/domains/dex/profit.js +86 -0
- package/dist/domains/dex/provider.d.ts +10 -0
- package/dist/domains/dex/provider.js +27 -0
- package/dist/domains/dex/quote.d.ts +7 -0
- package/dist/domains/dex/quote.js +52 -0
- package/dist/domains/dex/router.d.ts +56 -0
- package/dist/domains/dex/router.js +193 -0
- package/dist/domains/flap/portal-bundle/batch.d.ts +9 -0
- package/dist/domains/flap/portal-bundle/batch.js +193 -0
- package/dist/domains/flap/portal-bundle/create.d.ts +5 -0
- package/dist/domains/flap/portal-bundle/create.js +153 -0
- package/dist/domains/flap/portal-bundle/helpers.d.ts +32 -0
- package/dist/domains/flap/portal-bundle/helpers.js +50 -0
- package/dist/domains/flap/portal-bundle/index.d.ts +16 -0
- package/dist/domains/flap/portal-bundle/index.js +15 -0
- package/dist/domains/flap/portal-bundle/private.d.ts +5 -0
- package/dist/domains/flap/portal-bundle/private.js +198 -0
- package/dist/domains/flap/portal-bundle/types.d.ts +102 -0
- package/dist/domains/flap/portal-bundle/types.js +1 -0
- package/dist/domains/flap/portal-bundle-merkle/core-batch.d.ts +13 -0
- package/dist/domains/flap/portal-bundle-merkle/core-batch.js +376 -0
- package/dist/domains/flap/portal-bundle-merkle/core-helpers.d.ts +75 -7
- package/dist/domains/flap/portal-bundle-merkle/core-helpers.js +259 -20
- package/dist/domains/flap/portal-bundle-merkle/core.d.ts +2 -13
- package/dist/domains/flap/portal-bundle-merkle/core.js +12 -629
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/constants.d.ts +70 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/constants.js +90 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/index.d.ts +12 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/index.js +11 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/main.d.ts +15 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/main.js +432 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/types.d.ts +113 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/types.js +4 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex.d.ts +4 -127
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex.js +4 -527
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/constants.d.ts +42 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/constants.js +81 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/index.d.ts +12 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/index.js +11 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/main.d.ts +15 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/main.js +339 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/types.d.ts +72 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/types.js +4 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex.d.ts +4 -85
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex.js +4 -425
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/approve.d.ts +12 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/approve.js +102 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/buy.d.ts +5 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/buy.js +135 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/helpers.d.ts +52 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/helpers.js +267 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/index.d.ts +14 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/index.js +14 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/sell.d.ts +5 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/sell.js +195 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy.d.ts +3 -24
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy.js +3 -700
- package/dist/domains/flap/portal-bundle-merkle/private/buy.d.ts +9 -0
- package/dist/domains/flap/portal-bundle-merkle/private/buy.js +188 -0
- package/dist/domains/flap/portal-bundle-merkle/private/helpers.d.ts +36 -0
- package/dist/domains/flap/portal-bundle-merkle/private/helpers.js +127 -0
- package/dist/domains/flap/portal-bundle-merkle/private/index.d.ts +12 -0
- package/dist/domains/flap/portal-bundle-merkle/private/index.js +12 -0
- package/dist/domains/flap/portal-bundle-merkle/private/sell.d.ts +9 -0
- package/dist/domains/flap/portal-bundle-merkle/private/sell.js +191 -0
- package/dist/domains/flap/portal-bundle-merkle/private.d.ts +5 -15
- package/dist/domains/flap/portal-bundle-merkle/private.js +5 -494
- package/dist/domains/flap/portal-bundle-merkle/swap-batch.js +3 -2
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-chain.d.ts +4 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-chain.js +43 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-constants.d.ts +13 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-constants.js +21 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-helpers.d.ts +11 -121
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-helpers.js +11 -109
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-multi-wallet.d.ts +20 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-multi-wallet.js +223 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-plan.d.ts +32 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-plan.js +66 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-profit.d.ts +22 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-profit.js +22 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-quote.d.ts +51 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-quote.js +149 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-types.d.ts +87 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-types.js +1 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first.js +5 -404
- package/dist/domains/flap/portal-bundle-merkle/swap-helpers.d.ts +0 -1
- package/dist/domains/flap/portal-bundle-merkle/swap-helpers.js +0 -7
- package/dist/domains/flap/portal-bundle-merkle/swap-planning.js +1 -1
- package/dist/domains/flap/portal-bundle-merkle/swap-quick-batch.js +3 -2
- package/dist/domains/flap/portal-bundle-merkle/swap-single.js +3 -2
- package/dist/domains/flap/portal-bundle-merkle/utils/disperse.d.ts +2 -0
- package/dist/domains/flap/portal-bundle-merkle/utils/disperse.js +275 -0
- package/dist/domains/flap/portal-bundle-merkle/utils/index.d.ts +11 -0
- package/dist/domains/flap/portal-bundle-merkle/utils/index.js +11 -0
- package/dist/domains/flap/portal-bundle-merkle/utils/sweep.d.ts +9 -0
- package/dist/domains/flap/portal-bundle-merkle/utils/sweep.js +570 -0
- package/dist/domains/flap/portal-bundle-merkle/utils.d.ts +5 -8
- package/dist/domains/flap/portal-bundle-merkle/utils.js +5 -841
- package/dist/domains/flap/portal-bundle.d.ts +5 -117
- package/dist/domains/flap/portal-bundle.js +5 -587
- package/dist/domains/flap/portal.d.ts +13 -404
- package/dist/domains/flap/portal.js +12 -619
- package/dist/domains/flap/reader.d.ts +51 -0
- package/dist/domains/flap/reader.js +275 -0
- package/dist/domains/flap/types.d.ts +246 -0
- package/dist/domains/flap/types.js +104 -0
- package/dist/domains/flap/vault/constants.d.ts +220 -0
- package/dist/domains/flap/vault/constants.js +173 -0
- package/dist/domains/flap/vault/encode.d.ts +39 -0
- package/dist/domains/flap/vault/encode.js +135 -0
- package/dist/domains/flap/vault/index.d.ts +15 -0
- package/dist/domains/flap/vault/index.js +14 -0
- package/dist/domains/flap/vault/query.d.ts +40 -0
- package/dist/domains/flap/vault/query.js +104 -0
- package/dist/domains/flap/vault/types.d.ts +147 -0
- package/dist/domains/flap/vault/types.js +29 -0
- package/dist/domains/flap/vault.d.ts +3 -413
- package/dist/domains/flap/vault.js +3 -467
- package/dist/domains/flap/writer.d.ts +124 -0
- package/dist/domains/flap/writer.js +255 -0
- package/dist/domains/four/contracts/tm-bundle-batch.d.ts +35 -0
- package/dist/domains/four/contracts/tm-bundle-batch.js +286 -0
- package/dist/domains/four/contracts/tm-bundle-create.d.ts +2 -0
- package/dist/domains/four/contracts/tm-bundle-create.js +304 -0
- package/dist/domains/four/contracts/tm-bundle-helpers.d.ts +2 -1
- package/dist/domains/four/contracts/tm-bundle-helpers.js +3 -0
- package/dist/domains/four/contracts/tm-bundle-private.d.ts +36 -0
- package/dist/domains/four/contracts/tm-bundle-private.js +164 -0
- package/dist/domains/four/contracts/tm-bundle.d.ts +10 -71
- package/dist/domains/four/contracts/tm-bundle.js +9 -738
- package/dist/domains/lp-inspect/inspect-helpers.d.ts +25 -0
- package/dist/domains/lp-inspect/inspect-helpers.js +343 -0
- package/dist/domains/lp-inspect/inspect.d.ts +8 -0
- package/dist/domains/lp-inspect/inspect.js +332 -0
- package/dist/domains/lp-inspect/lp-inspect.d.ts +9 -37
- package/dist/domains/lp-inspect/lp-inspect.js +9 -775
- package/dist/domains/lp-inspect/registry.d.ts +43 -0
- package/dist/domains/lp-inspect/registry.js +127 -0
- package/dist/domains/merkle/index.d.ts +1 -1
- package/dist/exports/root-bundle-and-tooling.d.ts +9 -1
- package/dist/exports/root-bundle-and-tooling.js +8 -1
- package/dist/exports/root-foundations.d.ts +1 -1
- package/dist/exports/root-foundations.js +1 -1
- package/dist/exports/root-swap-dex-and-xlayer.d.ts +4 -4
- package/dist/exports/root-swap-dex-and-xlayer.js +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/utils/swap-helpers.js +1 -1
- package/package.json +1 -81
|
@@ -0,0 +1,570 @@
|
|
|
1
|
+
import { ethers, Wallet } from 'ethers';
|
|
2
|
+
import { getOptimizedGasPrice, NonceManager, buildProfitHopTransactions, PROFIT_HOP_COUNT, } from '../../../../utils/bundle-helpers.js';
|
|
3
|
+
import { GAS_LIMITS, calculateTransferFee } from '../../../../core/constants/index.js';
|
|
4
|
+
import { CHAIN_ID_MAP, getTxType, getGasPriceConfig, shouldExtractProfit, getProfitRecipient } from '../config.js';
|
|
5
|
+
import { batchGetBalances, calculateGasLimit, generateHopWallets, getErc20Decimals, isNativeTokenAddress, } from '../../../../bundle/internal.js';
|
|
6
|
+
import { createSignProvider, resolveHopCountInput, resolveProvidedHops, } from '../../../../bundle/sign-context-helpers.js';
|
|
7
|
+
/**
|
|
8
|
+
* Flap Protocol: 归集(仅签名版本)
|
|
9
|
+
* ✅ 支持利润提取(按地址数量收取固定费用)
|
|
10
|
+
* ✅ 查询余额最大的钱包支付利润
|
|
11
|
+
* ✅ 支持多跳
|
|
12
|
+
* ✅ 支持 Multicall3 批量获取余额
|
|
13
|
+
*/
|
|
14
|
+
export async function flapSweepWithBundleMerkle(params) {
|
|
15
|
+
const { chain, sourcePrivateKeys, target, ratioPct, ratios, amount, amounts, tokenAddress, tokenDecimals, skipIfInsufficient = true, hopCount = 0, hopPrivateKeys, sources, config, } = params;
|
|
16
|
+
if (!sourcePrivateKeys || sourcePrivateKeys.length === 0) {
|
|
17
|
+
return { signedTransactions: [], hopWallets: undefined };
|
|
18
|
+
}
|
|
19
|
+
const chainIdNum = CHAIN_ID_MAP[chain] ?? 56;
|
|
20
|
+
const provider = createSignProvider(config.rpcUrl, chainIdNum, chain);
|
|
21
|
+
const isNative = isNativeTokenAddress(tokenAddress);
|
|
22
|
+
const txType = getTxType(config);
|
|
23
|
+
const clamp = (n) => typeof n === 'number' && Number.isFinite(n) ? Math.max(0, Math.min(100, Math.floor(n))) : undefined;
|
|
24
|
+
const ratio = clamp(ratioPct);
|
|
25
|
+
const actualKeys = (() => {
|
|
26
|
+
if (sources && sources.length > 0)
|
|
27
|
+
return sources.map((s) => s.privateKey);
|
|
28
|
+
return sourcePrivateKeys;
|
|
29
|
+
})();
|
|
30
|
+
const providedHops = resolveProvidedHops(actualKeys.length, hopPrivateKeys, sources);
|
|
31
|
+
const hopCountInput = resolveHopCountInput(actualKeys.length, hopCount, sources);
|
|
32
|
+
const preparedHops = providedHops ?? generateHopWallets(actualKeys.length, hopCountInput);
|
|
33
|
+
const hasHops = preparedHops !== null;
|
|
34
|
+
const maxHopCount = preparedHops ? Math.max(...preparedHops.map((h) => h.length)) : 0;
|
|
35
|
+
const finalGasLimit = calculateGasLimit(config, isNative, hasHops, maxHopCount);
|
|
36
|
+
const nativeGasLimit = GAS_LIMITS.BRIBE;
|
|
37
|
+
const signedTxs = [];
|
|
38
|
+
const extractProfit = shouldExtractProfit();
|
|
39
|
+
const profitAddr = getProfitRecipient();
|
|
40
|
+
let totalProfit = 0n;
|
|
41
|
+
let totalAmountBeforeProfit = 0n;
|
|
42
|
+
let profitHopWallets; // ✅ 收集利润多跳钱包
|
|
43
|
+
if (!preparedHops) {
|
|
44
|
+
// ========== 无多跳:直接批量归集 ==========
|
|
45
|
+
const wallets = actualKeys.map((pk) => new Wallet(pk, provider));
|
|
46
|
+
const addresses = wallets.map((w) => w.address);
|
|
47
|
+
const nonceManager = new NonceManager(provider);
|
|
48
|
+
// ✅ 按地址数量收取固定费用(原生代币)
|
|
49
|
+
if (extractProfit) {
|
|
50
|
+
totalProfit = calculateTransferFee(chainIdNum, wallets.length);
|
|
51
|
+
}
|
|
52
|
+
if (isNative) {
|
|
53
|
+
const [gasPrice, balances] = await Promise.all([
|
|
54
|
+
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
55
|
+
batchGetBalances(provider, addresses),
|
|
56
|
+
]);
|
|
57
|
+
const gasCostBase = nativeGasLimit * gasPrice;
|
|
58
|
+
const profitTxGas = GAS_LIMITS.NATIVE_TRANSFER * gasPrice * BigInt(PROFIT_HOP_COUNT + 1);
|
|
59
|
+
// 第一步:计算所有钱包的归集金额,找出余额最大的钱包
|
|
60
|
+
const sweepAmounts = [];
|
|
61
|
+
let maxSweepIndex = -1;
|
|
62
|
+
let maxSweepAmount = 0n;
|
|
63
|
+
for (let i = 0; i < wallets.length; i++) {
|
|
64
|
+
const bal = balances[i];
|
|
65
|
+
let toSend = 0n;
|
|
66
|
+
const ratioForI = (() => {
|
|
67
|
+
if (sources && sources[i] && sources[i].ratioPct !== undefined)
|
|
68
|
+
return clamp(sources[i].ratioPct);
|
|
69
|
+
if (ratios && ratios[i] !== undefined)
|
|
70
|
+
return clamp(ratios[i]);
|
|
71
|
+
return ratio;
|
|
72
|
+
})();
|
|
73
|
+
const amountStrForI = (() => {
|
|
74
|
+
if (sources && sources[i] && sources[i].amount !== undefined)
|
|
75
|
+
return String(sources[i].amount);
|
|
76
|
+
if (amounts && amounts[i] !== undefined)
|
|
77
|
+
return String(amounts[i]);
|
|
78
|
+
return amount !== undefined ? String(amount) : undefined;
|
|
79
|
+
})();
|
|
80
|
+
const gasCost = gasCostBase;
|
|
81
|
+
if (ratioForI !== undefined) {
|
|
82
|
+
const want = (bal * BigInt(ratioForI)) / 100n;
|
|
83
|
+
const maxSendable = bal > gasCost ? bal - gasCost : 0n;
|
|
84
|
+
toSend = want > maxSendable ? maxSendable : want;
|
|
85
|
+
}
|
|
86
|
+
else if (amountStrForI && amountStrForI.trim().length > 0) {
|
|
87
|
+
const amt = ethers.parseEther(amountStrForI);
|
|
88
|
+
const need = amt + gasCost;
|
|
89
|
+
if (!skipIfInsufficient || bal >= need)
|
|
90
|
+
toSend = amt;
|
|
91
|
+
}
|
|
92
|
+
sweepAmounts.push(toSend);
|
|
93
|
+
totalAmountBeforeProfit += toSend;
|
|
94
|
+
// ✅ 找出余额最大的钱包作为利润支付者
|
|
95
|
+
if (toSend > maxSweepAmount) {
|
|
96
|
+
maxSweepAmount = toSend;
|
|
97
|
+
maxSweepIndex = i;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// 检查支付者余额是否足够支付利润
|
|
101
|
+
if (extractProfit && totalProfit > 0n && maxSweepIndex >= 0) {
|
|
102
|
+
const payerBalance = balances[maxSweepIndex];
|
|
103
|
+
const payerSweepAmount = sweepAmounts[maxSweepIndex];
|
|
104
|
+
const payerNeedGas = gasCostBase + profitTxGas;
|
|
105
|
+
if (payerBalance < payerSweepAmount + payerNeedGas + totalProfit) {
|
|
106
|
+
// 余额不足支付利润,减少归集金额
|
|
107
|
+
const maxPayerSweep = payerBalance > payerNeedGas + totalProfit ? payerBalance - payerNeedGas - totalProfit : 0n;
|
|
108
|
+
sweepAmounts[maxSweepIndex] = maxPayerSweep;
|
|
109
|
+
totalAmountBeforeProfit = sweepAmounts.reduce((sum, amt) => sum + amt, 0n);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// 第二步:生成归集交易
|
|
113
|
+
let payerProfitNonce;
|
|
114
|
+
if (extractProfit && totalProfit > 0n && maxSweepIndex >= 0) {
|
|
115
|
+
const payerWallet = wallets[maxSweepIndex];
|
|
116
|
+
const nonces = await nonceManager.getNextNonceBatch(payerWallet, 2);
|
|
117
|
+
payerProfitNonce = nonces[1];
|
|
118
|
+
}
|
|
119
|
+
const walletsToSweep = wallets.filter((_, i) => sweepAmounts[i] > 0n && i !== maxSweepIndex);
|
|
120
|
+
const nonces = walletsToSweep.length > 0 ? await nonceManager.getNextNoncesForWallets(walletsToSweep) : [];
|
|
121
|
+
let nonceIdx = 0;
|
|
122
|
+
const txPromises = wallets.map(async (w, i) => {
|
|
123
|
+
const toSend = sweepAmounts[i];
|
|
124
|
+
if (toSend <= 0n)
|
|
125
|
+
return null;
|
|
126
|
+
// ✅ 全额归集,不从转账金额中扣除利润
|
|
127
|
+
let nonce;
|
|
128
|
+
if (i === maxSweepIndex && payerProfitNonce !== undefined) {
|
|
129
|
+
nonce = payerProfitNonce - 1;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
nonce = nonces[nonceIdx++];
|
|
133
|
+
}
|
|
134
|
+
const mainTx = await w.signTransaction({
|
|
135
|
+
to: target,
|
|
136
|
+
value: toSend,
|
|
137
|
+
nonce,
|
|
138
|
+
gasPrice,
|
|
139
|
+
gasLimit: nativeGasLimit,
|
|
140
|
+
chainId: chainIdNum,
|
|
141
|
+
type: txType,
|
|
142
|
+
});
|
|
143
|
+
return mainTx;
|
|
144
|
+
});
|
|
145
|
+
const allTxs = (await Promise.all(txPromises)).filter((tx) => tx !== null);
|
|
146
|
+
signedTxs.push(...allTxs);
|
|
147
|
+
// ✅ 利润多跳转账(固定费用,原生代币)
|
|
148
|
+
if (extractProfit && totalProfit > 0n && maxSweepIndex >= 0 && payerProfitNonce !== undefined) {
|
|
149
|
+
const payerWallet = wallets[maxSweepIndex];
|
|
150
|
+
const profitHopResult = await buildProfitHopTransactions({
|
|
151
|
+
provider,
|
|
152
|
+
payerWallet,
|
|
153
|
+
profitAmount: totalProfit,
|
|
154
|
+
profitRecipient: profitAddr,
|
|
155
|
+
hopCount: PROFIT_HOP_COUNT,
|
|
156
|
+
gasPrice,
|
|
157
|
+
chainId: chainIdNum,
|
|
158
|
+
txType,
|
|
159
|
+
startNonce: payerProfitNonce,
|
|
160
|
+
});
|
|
161
|
+
signedTxs.push(...profitHopResult.signedTransactions);
|
|
162
|
+
profitHopWallets = profitHopResult.hopWallets;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
// ERC20 归集
|
|
167
|
+
const [gasPrice, decimals, balances, nativeBalances] = await Promise.all([
|
|
168
|
+
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
169
|
+
Promise.resolve(tokenDecimals ?? (await getErc20Decimals(provider, tokenAddress))),
|
|
170
|
+
batchGetBalances(provider, addresses, tokenAddress),
|
|
171
|
+
batchGetBalances(provider, addresses),
|
|
172
|
+
]);
|
|
173
|
+
const iface = new ethers.Interface(['function transfer(address,uint256) returns (bool)']);
|
|
174
|
+
const profitTxGas = GAS_LIMITS.NATIVE_TRANSFER * gasPrice * BigInt(PROFIT_HOP_COUNT + 1);
|
|
175
|
+
const sweepAmounts = [];
|
|
176
|
+
let maxSweepIndex = -1;
|
|
177
|
+
let maxSweepAmount = 0n;
|
|
178
|
+
for (let i = 0; i < wallets.length; i++) {
|
|
179
|
+
const bal = balances[i];
|
|
180
|
+
let toSend = 0n;
|
|
181
|
+
const ratioForI = (() => {
|
|
182
|
+
if (sources && sources[i] && sources[i].ratioPct !== undefined)
|
|
183
|
+
return clamp(sources[i].ratioPct);
|
|
184
|
+
if (ratios && ratios[i] !== undefined)
|
|
185
|
+
return clamp(ratios[i]);
|
|
186
|
+
return ratio;
|
|
187
|
+
})();
|
|
188
|
+
const amountStrForI = (() => {
|
|
189
|
+
if (sources && sources[i] && sources[i].amount !== undefined)
|
|
190
|
+
return String(sources[i].amount);
|
|
191
|
+
if (amounts && amounts[i] !== undefined)
|
|
192
|
+
return String(amounts[i]);
|
|
193
|
+
return amount !== undefined ? String(amount) : undefined;
|
|
194
|
+
})();
|
|
195
|
+
if (ratioForI !== undefined) {
|
|
196
|
+
toSend = (bal * BigInt(ratioForI)) / 100n;
|
|
197
|
+
}
|
|
198
|
+
else if (amountStrForI && amountStrForI.trim().length > 0) {
|
|
199
|
+
toSend = ethers.parseUnits(amountStrForI, decimals);
|
|
200
|
+
}
|
|
201
|
+
if (toSend <= 0n || (skipIfInsufficient && bal < toSend)) {
|
|
202
|
+
sweepAmounts.push(0n);
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
const totalGasNeeded = finalGasLimit * gasPrice;
|
|
206
|
+
const nativeBal = nativeBalances[i] ?? 0n;
|
|
207
|
+
if (skipIfInsufficient && nativeBal < totalGasNeeded) {
|
|
208
|
+
sweepAmounts.push(0n);
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
sweepAmounts.push(toSend);
|
|
212
|
+
totalAmountBeforeProfit += toSend;
|
|
213
|
+
// ✅ 找出原生代币余额最大的钱包作为利润支付者
|
|
214
|
+
if (nativeBal > maxSweepAmount) {
|
|
215
|
+
maxSweepAmount = nativeBal;
|
|
216
|
+
maxSweepIndex = i;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
// 检查支付者原生代币余额是否足够支付固定费用
|
|
220
|
+
if (extractProfit && totalProfit > 0n && maxSweepIndex >= 0) {
|
|
221
|
+
const payerNativeBalance = nativeBalances[maxSweepIndex] ?? 0n;
|
|
222
|
+
const payerNeedGas = finalGasLimit * gasPrice + profitTxGas + totalProfit;
|
|
223
|
+
if (payerNativeBalance < payerNeedGas) {
|
|
224
|
+
// 余额不足,跳过利润收取
|
|
225
|
+
totalProfit = 0n;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
let payerProfitNonce;
|
|
229
|
+
if (extractProfit && totalProfit > 0n && maxSweepIndex >= 0) {
|
|
230
|
+
const payerWallet = wallets[maxSweepIndex];
|
|
231
|
+
const nonces = await nonceManager.getNextNonceBatch(payerWallet, 2);
|
|
232
|
+
payerProfitNonce = nonces[1];
|
|
233
|
+
}
|
|
234
|
+
const walletsToSweepErc20 = wallets.filter((_, i) => sweepAmounts[i] > 0n && i !== maxSweepIndex);
|
|
235
|
+
const noncesErc20 = walletsToSweepErc20.length > 0 ? await nonceManager.getNextNoncesForWallets(walletsToSweepErc20) : [];
|
|
236
|
+
let nonceIdxErc20 = 0;
|
|
237
|
+
const txPromises = wallets.map(async (w, i) => {
|
|
238
|
+
const toSend = sweepAmounts[i];
|
|
239
|
+
if (toSend <= 0n)
|
|
240
|
+
return null;
|
|
241
|
+
let nonce;
|
|
242
|
+
if (i === maxSweepIndex && payerProfitNonce !== undefined) {
|
|
243
|
+
nonce = payerProfitNonce - 1;
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
nonce = noncesErc20[nonceIdxErc20++];
|
|
247
|
+
}
|
|
248
|
+
// ✅ 全额归集 ERC20,不从转账金额中扣除利润
|
|
249
|
+
const data = iface.encodeFunctionData('transfer', [target, toSend]);
|
|
250
|
+
const mainTx = await w.signTransaction({
|
|
251
|
+
to: tokenAddress,
|
|
252
|
+
data,
|
|
253
|
+
value: 0n,
|
|
254
|
+
nonce,
|
|
255
|
+
gasPrice,
|
|
256
|
+
gasLimit: finalGasLimit,
|
|
257
|
+
chainId: chainIdNum,
|
|
258
|
+
type: txType,
|
|
259
|
+
});
|
|
260
|
+
return mainTx;
|
|
261
|
+
});
|
|
262
|
+
const allTxs = (await Promise.all(txPromises)).filter((tx) => tx !== null);
|
|
263
|
+
signedTxs.push(...allTxs);
|
|
264
|
+
// ✅ 利润多跳转账(固定费用,原生代币)
|
|
265
|
+
if (extractProfit && totalProfit > 0n && maxSweepIndex >= 0 && payerProfitNonce !== undefined) {
|
|
266
|
+
const payerWallet = wallets[maxSweepIndex];
|
|
267
|
+
const profitHopResult = await buildProfitHopTransactions({
|
|
268
|
+
provider,
|
|
269
|
+
payerWallet,
|
|
270
|
+
profitAmount: totalProfit,
|
|
271
|
+
profitRecipient: profitAddr,
|
|
272
|
+
hopCount: PROFIT_HOP_COUNT,
|
|
273
|
+
gasPrice,
|
|
274
|
+
chainId: chainIdNum,
|
|
275
|
+
txType,
|
|
276
|
+
startNonce: payerProfitNonce,
|
|
277
|
+
});
|
|
278
|
+
signedTxs.push(...profitHopResult.signedTransactions);
|
|
279
|
+
profitHopWallets = profitHopResult.hopWallets;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
// ========== 有多跳:构建跳转链归集 ==========
|
|
285
|
+
const sourceWallets = actualKeys.map((pk) => new Wallet(pk, provider));
|
|
286
|
+
// ✅ 按地址数量收取固定费用(原生代币)
|
|
287
|
+
if (extractProfit) {
|
|
288
|
+
totalProfit = calculateTransferFee(chainIdNum, sourceWallets.length);
|
|
289
|
+
}
|
|
290
|
+
const withHopIndexes = [];
|
|
291
|
+
const withoutHopIndexes = [];
|
|
292
|
+
for (let i = 0; i < preparedHops.length; i++) {
|
|
293
|
+
if (preparedHops[i].length > 0) {
|
|
294
|
+
withHopIndexes.push(i);
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
withoutHopIndexes.push(i);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
const sourceAddresses = sourceWallets.map((w) => w.address);
|
|
301
|
+
const [gasPrice, decimals, balances, nativeBalances] = await Promise.all([
|
|
302
|
+
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
303
|
+
isNative
|
|
304
|
+
? Promise.resolve(18)
|
|
305
|
+
: Promise.resolve(tokenDecimals ?? (await getErc20Decimals(provider, tokenAddress))),
|
|
306
|
+
batchGetBalances(provider, sourceAddresses, tokenAddress),
|
|
307
|
+
isNative ? Promise.resolve([]) : batchGetBalances(provider, sourceAddresses),
|
|
308
|
+
]);
|
|
309
|
+
const iface = isNative ? null : new ethers.Interface(['function transfer(address,uint256) returns (bool)']);
|
|
310
|
+
const gasFeePerHop = finalGasLimit * gasPrice;
|
|
311
|
+
const nonceManager = new NonceManager(provider);
|
|
312
|
+
const sweepAmounts = new Array(sourceWallets.length).fill(0n);
|
|
313
|
+
// 处理无跳转的地址
|
|
314
|
+
for (const i of withoutHopIndexes) {
|
|
315
|
+
const sourceWallet = sourceWallets[i];
|
|
316
|
+
const bal = balances[i];
|
|
317
|
+
let toSend = 0n;
|
|
318
|
+
if (isNative) {
|
|
319
|
+
const gasCost = nativeGasLimit * gasPrice;
|
|
320
|
+
const ratioForI = (() => {
|
|
321
|
+
if (sources && sources[i] && sources[i].ratioPct !== undefined)
|
|
322
|
+
return clamp(sources[i].ratioPct);
|
|
323
|
+
if (ratios && ratios[i] !== undefined)
|
|
324
|
+
return clamp(ratios[i]);
|
|
325
|
+
return ratio;
|
|
326
|
+
})();
|
|
327
|
+
const amountStrForI = (() => {
|
|
328
|
+
if (sources && sources[i] && sources[i].amount !== undefined)
|
|
329
|
+
return String(sources[i].amount);
|
|
330
|
+
if (amounts && amounts[i] !== undefined)
|
|
331
|
+
return String(amounts[i]);
|
|
332
|
+
return amount !== undefined ? String(amount) : undefined;
|
|
333
|
+
})();
|
|
334
|
+
if (ratioForI !== undefined) {
|
|
335
|
+
const want = (bal * BigInt(ratioForI)) / 100n;
|
|
336
|
+
const maxSendable = bal > gasCost ? bal - gasCost : 0n;
|
|
337
|
+
toSend = want > maxSendable ? maxSendable : want;
|
|
338
|
+
}
|
|
339
|
+
else if (amountStrForI && amountStrForI.trim().length > 0) {
|
|
340
|
+
const amt = ethers.parseEther(amountStrForI);
|
|
341
|
+
const need = amt + gasCost;
|
|
342
|
+
if (!skipIfInsufficient || bal >= need)
|
|
343
|
+
toSend = amt;
|
|
344
|
+
}
|
|
345
|
+
if (toSend > 0n) {
|
|
346
|
+
sweepAmounts[i] = toSend;
|
|
347
|
+
totalAmountBeforeProfit += toSend;
|
|
348
|
+
const nonce = await nonceManager.getNextNonce(sourceWallet);
|
|
349
|
+
const tx = await sourceWallet.signTransaction({
|
|
350
|
+
to: target,
|
|
351
|
+
value: toSend,
|
|
352
|
+
nonce,
|
|
353
|
+
gasPrice,
|
|
354
|
+
gasLimit: nativeGasLimit,
|
|
355
|
+
chainId: chainIdNum,
|
|
356
|
+
type: txType,
|
|
357
|
+
});
|
|
358
|
+
signedTxs.push(tx);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
const ratioForI = (() => {
|
|
363
|
+
if (sources && sources[i] && sources[i].ratioPct !== undefined)
|
|
364
|
+
return clamp(sources[i].ratioPct);
|
|
365
|
+
if (ratios && ratios[i] !== undefined)
|
|
366
|
+
return clamp(ratios[i]);
|
|
367
|
+
return ratio;
|
|
368
|
+
})();
|
|
369
|
+
const amountStrForI = (() => {
|
|
370
|
+
if (sources && sources[i] && sources[i].amount !== undefined)
|
|
371
|
+
return String(sources[i].amount);
|
|
372
|
+
if (amounts && amounts[i] !== undefined)
|
|
373
|
+
return String(amounts[i]);
|
|
374
|
+
return amount !== undefined ? String(amount) : undefined;
|
|
375
|
+
})();
|
|
376
|
+
if (ratioForI !== undefined) {
|
|
377
|
+
toSend = (bal * BigInt(ratioForI)) / 100n;
|
|
378
|
+
}
|
|
379
|
+
else if (amountStrForI && amountStrForI.trim().length > 0) {
|
|
380
|
+
toSend = ethers.parseUnits(amountStrForI, decimals);
|
|
381
|
+
}
|
|
382
|
+
if (toSend > 0n && (!skipIfInsufficient || bal >= toSend)) {
|
|
383
|
+
sweepAmounts[i] = toSend;
|
|
384
|
+
totalAmountBeforeProfit += toSend;
|
|
385
|
+
const nonce = await nonceManager.getNextNonce(sourceWallet);
|
|
386
|
+
const data = iface.encodeFunctionData('transfer', [target, toSend]);
|
|
387
|
+
const tx = await sourceWallet.signTransaction({
|
|
388
|
+
to: tokenAddress,
|
|
389
|
+
data,
|
|
390
|
+
value: 0n,
|
|
391
|
+
nonce,
|
|
392
|
+
gasPrice,
|
|
393
|
+
gasLimit: finalGasLimit,
|
|
394
|
+
chainId: chainIdNum,
|
|
395
|
+
type: txType,
|
|
396
|
+
});
|
|
397
|
+
signedTxs.push(tx);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
// 处理有跳转的地址
|
|
402
|
+
for (const i of withHopIndexes) {
|
|
403
|
+
const sourceWallet = sourceWallets[i];
|
|
404
|
+
const hopChain = preparedHops[i];
|
|
405
|
+
let toSend = 0n;
|
|
406
|
+
const bal = balances[i];
|
|
407
|
+
if (isNative) {
|
|
408
|
+
const totalGasCost = finalGasLimit * gasPrice * BigInt(hopChain.length + 1);
|
|
409
|
+
const ratioForI = (() => {
|
|
410
|
+
if (sources && sources[i] && sources[i].ratioPct !== undefined)
|
|
411
|
+
return clamp(sources[i].ratioPct);
|
|
412
|
+
if (ratios && ratios[i] !== undefined)
|
|
413
|
+
return clamp(ratios[i]);
|
|
414
|
+
return ratio;
|
|
415
|
+
})();
|
|
416
|
+
const amountStrForI = (() => {
|
|
417
|
+
if (sources && sources[i] && sources[i].amount !== undefined)
|
|
418
|
+
return String(sources[i].amount);
|
|
419
|
+
if (amounts && amounts[i] !== undefined)
|
|
420
|
+
return String(amounts[i]);
|
|
421
|
+
return amount !== undefined ? String(amount) : undefined;
|
|
422
|
+
})();
|
|
423
|
+
if (ratioForI !== undefined) {
|
|
424
|
+
const want = (bal * BigInt(ratioForI)) / 100n;
|
|
425
|
+
const maxSendable = bal > totalGasCost ? bal - totalGasCost : 0n;
|
|
426
|
+
toSend = want > maxSendable ? maxSendable : want;
|
|
427
|
+
}
|
|
428
|
+
else if (amountStrForI && amountStrForI.trim().length > 0) {
|
|
429
|
+
const amt = ethers.parseEther(amountStrForI);
|
|
430
|
+
const need = amt + totalGasCost;
|
|
431
|
+
if (!skipIfInsufficient || bal >= need)
|
|
432
|
+
toSend = amt;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
const nativeBal = nativeBalances[i];
|
|
437
|
+
const nativeNeeded = gasFeePerHop * BigInt(hopChain.length) + finalGasLimit * gasPrice;
|
|
438
|
+
if (nativeBal < nativeNeeded && skipIfInsufficient)
|
|
439
|
+
continue;
|
|
440
|
+
const ratioForI = (() => {
|
|
441
|
+
if (sources && sources[i] && sources[i].ratioPct !== undefined)
|
|
442
|
+
return clamp(sources[i].ratioPct);
|
|
443
|
+
if (ratios && ratios[i] !== undefined)
|
|
444
|
+
return clamp(ratios[i]);
|
|
445
|
+
return ratio;
|
|
446
|
+
})();
|
|
447
|
+
const amountStrForI = (() => {
|
|
448
|
+
if (sources && sources[i] && sources[i].amount !== undefined)
|
|
449
|
+
return String(sources[i].amount);
|
|
450
|
+
if (amounts && amounts[i] !== undefined)
|
|
451
|
+
return String(amounts[i]);
|
|
452
|
+
return amount !== undefined ? String(amount) : undefined;
|
|
453
|
+
})();
|
|
454
|
+
if (ratioForI !== undefined) {
|
|
455
|
+
toSend = (bal * BigInt(ratioForI)) / 100n;
|
|
456
|
+
}
|
|
457
|
+
else if (amountStrForI && amountStrForI.trim().length > 0) {
|
|
458
|
+
toSend = ethers.parseUnits(amountStrForI, decimals);
|
|
459
|
+
}
|
|
460
|
+
if (skipIfInsufficient && bal < toSend)
|
|
461
|
+
toSend = 0n;
|
|
462
|
+
}
|
|
463
|
+
if (toSend <= 0n)
|
|
464
|
+
continue;
|
|
465
|
+
sweepAmounts[i] = toSend;
|
|
466
|
+
totalAmountBeforeProfit += toSend;
|
|
467
|
+
// ✅ 支持 string 和 GeneratedWallet 两种类型
|
|
468
|
+
const fullChain = [
|
|
469
|
+
sourceWallet,
|
|
470
|
+
...hopChain.map((w) => new Wallet(typeof w === 'string' ? w : w.privateKey, provider)),
|
|
471
|
+
];
|
|
472
|
+
const addresses = [...fullChain.map((w) => w.address), target];
|
|
473
|
+
if (!isNative) {
|
|
474
|
+
const gasNonces = await nonceManager.getNextNonceBatch(sourceWallet, hopChain.length);
|
|
475
|
+
for (let j = 0; j < hopChain.length; j++) {
|
|
476
|
+
const tx = await sourceWallet.signTransaction({
|
|
477
|
+
to: fullChain[j + 1].address,
|
|
478
|
+
value: gasFeePerHop,
|
|
479
|
+
nonce: gasNonces[j],
|
|
480
|
+
gasPrice,
|
|
481
|
+
gasLimit: nativeGasLimit,
|
|
482
|
+
chainId: chainIdNum,
|
|
483
|
+
type: txType,
|
|
484
|
+
});
|
|
485
|
+
signedTxs.push(tx);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
for (let j = 0; j < addresses.length - 1; j++) {
|
|
489
|
+
const fromWallet = fullChain[j];
|
|
490
|
+
const toAddress = addresses[j + 1];
|
|
491
|
+
const nonce = j === 0 ? await nonceManager.getNextNonce(sourceWallet) : 0;
|
|
492
|
+
if (isNative) {
|
|
493
|
+
const remainingHops = addresses.length - 2 - j;
|
|
494
|
+
const additionalGas = gasFeePerHop * BigInt(remainingHops);
|
|
495
|
+
const valueToTransfer = toSend + additionalGas;
|
|
496
|
+
const tx = await fromWallet.signTransaction({
|
|
497
|
+
to: toAddress,
|
|
498
|
+
value: valueToTransfer,
|
|
499
|
+
nonce,
|
|
500
|
+
gasPrice,
|
|
501
|
+
gasLimit: finalGasLimit,
|
|
502
|
+
chainId: chainIdNum,
|
|
503
|
+
type: txType,
|
|
504
|
+
});
|
|
505
|
+
signedTxs.push(tx);
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
const data = iface.encodeFunctionData('transfer', [toAddress, toSend]);
|
|
509
|
+
const tx = await fromWallet.signTransaction({
|
|
510
|
+
to: tokenAddress,
|
|
511
|
+
data,
|
|
512
|
+
value: 0n,
|
|
513
|
+
nonce,
|
|
514
|
+
gasPrice,
|
|
515
|
+
gasLimit: finalGasLimit,
|
|
516
|
+
chainId: chainIdNum,
|
|
517
|
+
type: txType,
|
|
518
|
+
});
|
|
519
|
+
signedTxs.push(tx);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
// ✅ 利润多跳转账(固定费用,原生代币)- totalProfit 已在函数开头计算
|
|
524
|
+
if (extractProfit && totalProfit > 0n && totalAmountBeforeProfit > 0n) {
|
|
525
|
+
// 找出余额最大的钱包作为利润支付者
|
|
526
|
+
let maxSweepIndex = -1;
|
|
527
|
+
let maxSweepAmount = 0n;
|
|
528
|
+
for (let i = 0; i < sweepAmounts.length; i++) {
|
|
529
|
+
if (sweepAmounts[i] > maxSweepAmount) {
|
|
530
|
+
maxSweepAmount = sweepAmounts[i];
|
|
531
|
+
maxSweepIndex = i;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
if (maxSweepIndex >= 0) {
|
|
535
|
+
const payerWallet = sourceWallets[maxSweepIndex];
|
|
536
|
+
const profitNonce = await nonceManager.getNextNonce(payerWallet);
|
|
537
|
+
const profitHopResult = await buildProfitHopTransactions({
|
|
538
|
+
provider,
|
|
539
|
+
payerWallet,
|
|
540
|
+
profitAmount: totalProfit,
|
|
541
|
+
profitRecipient: profitAddr,
|
|
542
|
+
hopCount: PROFIT_HOP_COUNT,
|
|
543
|
+
gasPrice,
|
|
544
|
+
chainId: chainIdNum,
|
|
545
|
+
txType,
|
|
546
|
+
startNonce: profitNonce,
|
|
547
|
+
});
|
|
548
|
+
signedTxs.push(...profitHopResult.signedTransactions);
|
|
549
|
+
profitHopWallets = profitHopResult.hopWallets;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
return {
|
|
554
|
+
signedTransactions: signedTxs,
|
|
555
|
+
hopWallets: preparedHops || undefined,
|
|
556
|
+
profitHopWallets, // ✅ 返回利润多跳钱包
|
|
557
|
+
metadata: extractProfit
|
|
558
|
+
? {
|
|
559
|
+
totalAmount: isNative
|
|
560
|
+
? ethers.formatEther(totalAmountBeforeProfit)
|
|
561
|
+
: ethers.formatUnits(totalAmountBeforeProfit, tokenDecimals ?? 18),
|
|
562
|
+
profitAmount: ethers.formatEther(totalProfit),
|
|
563
|
+
profitRecipient: profitAddr,
|
|
564
|
+
sourceCount: actualKeys.length,
|
|
565
|
+
isNative,
|
|
566
|
+
tokenAddress: isNative ? undefined : tokenAddress,
|
|
567
|
+
}
|
|
568
|
+
: undefined,
|
|
569
|
+
};
|
|
570
|
+
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import type { FlapDisperseMerkleResult, FlapDisperseSignParams, FlapSweepMerkleResult, FlapSweepSignParams } from './types.js';
|
|
2
|
-
export declare function flapDisperseWithBundleMerkle(params: FlapDisperseSignParams): Promise<FlapDisperseMerkleResult>;
|
|
3
1
|
/**
|
|
4
|
-
* Flap Protocol
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* ✅ 支持 Multicall3 批量获取余额
|
|
2
|
+
* Flap Protocol 分散 / 归集(Merkle Bundle)
|
|
3
|
+
*
|
|
4
|
+
* 原超长文件按职责拆分为 utils/ 目录下的多个子文件,
|
|
5
|
+
* 对外 export 符号与路径保持不变(见 utils/index.ts)。
|
|
9
6
|
*/
|
|
10
|
-
export
|
|
7
|
+
export * from './utils/index.js';
|