four-flap-meme-sdk 2.2.8 → 2.2.10
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/README.en.md +6 -41
- package/README.md +0 -31
- package/README.zh-CN.md +6 -41
- package/dist/chains/bsc/four/approve-tokenmanager.d.ts +26 -1
- package/dist/chains/bsc/four/approve-tokenmanager.js +113 -1
- package/dist/chains/bsc/four/config.d.ts +67 -5
- package/dist/chains/bsc/four/config.js +114 -2
- package/dist/chains/bsc/four/core.d.ts +4 -1
- package/dist/chains/bsc/four/core.js +592 -1
- package/dist/chains/bsc/four/index.d.ts +6 -6
- package/dist/chains/bsc/four/index.js +6 -6
- package/dist/chains/bsc/four/internal.d.ts +46 -2
- package/dist/chains/bsc/four/internal.js +239 -2
- package/dist/chains/bsc/four/pancake-proxy.d.ts +28 -1
- package/dist/chains/bsc/four/pancake-proxy.js +687 -1
- package/dist/chains/bsc/four/private.d.ts +27 -1
- package/dist/chains/bsc/four/private.js +477 -1
- package/dist/chains/bsc/four/submit.d.ts +315 -2
- package/dist/chains/bsc/four/submit.js +752 -2
- package/dist/chains/bsc/four/swap-buy-first.d.ts +55 -2
- package/dist/chains/bsc/four/swap-buy-first.js +507 -2
- package/dist/chains/bsc/four/swap-internal.d.ts +3 -1
- package/dist/chains/bsc/four/swap-internal.js +18 -1
- package/dist/chains/bsc/four/swap.d.ts +144 -2
- package/dist/chains/bsc/four/swap.js +766 -2
- package/dist/chains/bsc/four/types.d.ts +476 -1
- package/dist/chains/bsc/four/utils.d.ts +18 -5
- package/dist/chains/bsc/four/utils.js +1552 -5
- package/dist/chains/bsc/pancake/bundle-buy-first.d.ts +91 -1
- package/dist/chains/bsc/pancake/bundle-buy-first.js +212 -97
- package/dist/chains/bsc/pancake/bundle-swap.d.ts +79 -1
- package/dist/chains/bsc/pancake/bundle-swap.js +726 -114
- package/dist/chains/bsc/pancake/index.d.ts +2 -4
- package/dist/chains/bsc/pancake/index.js +3 -1
- package/dist/chains/bsc/platforms/iro/factory.d.ts +2 -2
- package/dist/chains/bsc/platforms/iro/factory.js +1 -3
- package/dist/chains/bsc/platforms/iro/index.d.ts +5 -5
- package/dist/chains/bsc/platforms/iro/index.js +3 -3
- package/dist/chains/bsc/platforms/iro/pool.js +10 -31
- package/dist/chains/bsc/platforms/iro/token.js +1 -4
- package/dist/chains/eni/batch-router/bundle-approve.js +3 -4
- package/dist/chains/eni/batch-router/transfer.js +25 -55
- package/dist/chains/eni/batch-router/utils.js +6 -32
- package/dist/chains/eni/bundler/sign.js +6 -5
- package/dist/chains/eni/bundler/submit.js +4 -1
- package/dist/chains/eni/constants.js +1 -1
- package/dist/chains/eni/index.d.ts +1 -2
- package/dist/chains/eni/index.js +0 -1
- package/dist/chains/eni/platforms/daoaas/create.js +2 -2
- package/dist/chains/eni/platforms/daoaas/index.d.ts +3 -3
- package/dist/chains/eni/platforms/daoaas/index.js +3 -3
- package/dist/chains/eni/platforms/daoaas/meta.js +6 -9
- package/dist/chains/eni/platforms/daoaas/portal-direct.js +44 -28
- package/dist/chains/eni/platforms/daoaas/portal.js +6 -10
- package/dist/chains/eni/platforms/dswap/liquidity.js +26 -58
- package/dist/chains/eni/platforms/fair-launch/index.d.ts +2 -2
- package/dist/chains/eni/platforms/fair-launch/index.js +1 -1
- package/dist/chains/eni/platforms/fair-launch/launcher.js +46 -87
- package/dist/chains/eni/platforms/fair-launch/pool.js +1 -4
- package/dist/chains/eni/platforms/fair-launch/presets.js +2 -2
- package/dist/chains/eni/platforms/iro/factory.d.ts +2 -2
- package/dist/chains/eni/platforms/iro/factory.js +1 -3
- package/dist/chains/eni/platforms/iro/index.d.ts +6 -6
- package/dist/chains/eni/platforms/iro/index.js +4 -4
- package/dist/chains/eni/platforms/iro/pool.js +26 -90
- package/dist/chains/eni/platforms/iro/token.js +31 -107
- package/dist/chains/eni/platforms/iro/whitelist.js +18 -6
- package/dist/chains/index.d.ts +0 -13
- package/dist/chains/index.js +0 -13
- package/dist/chains/xlayer/eip7702/bundle-approve.d.ts +26 -2
- package/dist/chains/xlayer/eip7702/bundle-approve.js +21 -11
- package/dist/chains/xlayer/eip7702/bundle-buy.d.ts +6 -2
- package/dist/chains/xlayer/eip7702/bundle-buy.js +51 -13
- package/dist/chains/xlayer/eip7702/bundle-create.js +59 -93
- package/dist/chains/xlayer/eip7702/bundle-sell.d.ts +6 -2
- package/dist/chains/xlayer/eip7702/bundle-sell.js +111 -29
- package/dist/chains/xlayer/eip7702/bundle-swap.d.ts +65 -3
- package/dist/chains/xlayer/eip7702/bundle-swap.js +245 -51
- package/dist/chains/xlayer/eip7702/constants.d.ts +16 -1
- package/dist/chains/xlayer/eip7702/constants.js +21 -3
- package/dist/chains/xlayer/eip7702/index.d.ts +46 -28
- package/dist/chains/xlayer/eip7702/index.js +81 -28
- package/dist/chains/xlayer/eip7702/multi-hop-transfer.d.ts +203 -2
- package/dist/chains/xlayer/eip7702/multi-hop-transfer.js +307 -63
- package/dist/chains/xlayer/eip7702/types.d.ts +0 -88
- package/dist/chains/xlayer/eip7702/utils.d.ts +3 -0
- package/dist/chains/xlayer/eip7702/utils.js +28 -23
- package/dist/chains/xlayer/eip7702/volume.d.ts +184 -6
- package/dist/chains/xlayer/eip7702/volume.js +164 -89
- package/dist/chains/xlayer/eoa/constants.js +1 -1
- package/dist/chains/xlayer/eoa/dex-helpers.js +5 -5
- package/dist/chains/xlayer/eoa/eoa-bundle-swap.d.ts +95 -1
- package/dist/chains/xlayer/eoa/eoa-bundle-swap.js +299 -66
- package/dist/chains/xlayer/eoa/eoa-wash-volume.d.ts +1 -1
- package/dist/chains/xlayer/eoa/eoa-wash-volume.js +23 -18
- package/dist/chains/xlayer/eoa/index.d.ts +6 -10
- package/dist/chains/xlayer/eoa/index.js +23 -8
- package/dist/chains/xlayer/eoa/portal-ops.js +2 -7
- package/dist/chains/xlayer/eoa/router-manager.js +3 -3
- package/dist/chains/xlayer/eoa/types.d.ts +2 -2
- package/dist/chains/xlayer/eoa/types.js +3 -1
- package/dist/chains/xlayer/index.d.ts +2 -3
- package/dist/chains/xlayer/index.js +7 -4
- package/dist/contracts/helper3.d.ts +5 -20
- package/dist/contracts/helper3.js +20 -56
- package/dist/contracts/tm-bundle-merkle/approve-tokenmanager.d.ts +26 -1
- package/dist/contracts/tm-bundle-merkle/approve-tokenmanager.js +113 -1
- package/dist/contracts/tm-bundle-merkle/config.d.ts +67 -5
- package/dist/contracts/tm-bundle-merkle/config.js +114 -2
- package/dist/contracts/tm-bundle-merkle/core.d.ts +4 -1
- package/dist/contracts/tm-bundle-merkle/core.js +591 -1
- package/dist/contracts/tm-bundle-merkle/index.d.ts +5 -5
- package/dist/contracts/tm-bundle-merkle/index.js +5 -5
- package/dist/contracts/tm-bundle-merkle/internal.d.ts +46 -2
- package/dist/contracts/tm-bundle-merkle/internal.js +238 -2
- package/dist/contracts/tm-bundle-merkle/pancake-proxy.d.ts +28 -1
- package/dist/contracts/tm-bundle-merkle/pancake-proxy.js +686 -1
- package/dist/contracts/tm-bundle-merkle/private.d.ts +27 -1
- package/dist/contracts/tm-bundle-merkle/private.js +476 -1
- package/dist/contracts/tm-bundle-merkle/submit.d.ts +314 -3
- package/dist/contracts/tm-bundle-merkle/submit.js +928 -3
- package/dist/contracts/tm-bundle-merkle/swap-buy-first.d.ts +55 -2
- package/dist/contracts/tm-bundle-merkle/swap-buy-first.js +506 -2
- package/dist/contracts/tm-bundle-merkle/swap-internal.d.ts +3 -1
- package/dist/contracts/tm-bundle-merkle/swap-internal.js +18 -1
- package/dist/contracts/tm-bundle-merkle/swap.d.ts +144 -2
- package/dist/contracts/tm-bundle-merkle/swap.js +764 -2
- package/dist/contracts/tm-bundle-merkle/types.d.ts +476 -1
- package/dist/contracts/tm-bundle-merkle/utils.d.ts +18 -6
- package/dist/contracts/tm-bundle-merkle/utils.js +1501 -6
- package/dist/contracts/tm-bundle.d.ts +51 -3
- package/dist/contracts/tm-bundle.js +177 -108
- package/dist/contracts/tm.d.ts +2 -3
- package/dist/contracts/tm.js +32 -37
- package/dist/contracts/tm1.js +4 -9
- package/dist/contracts/tm2.js +4 -9
- package/dist/dex/direct-router.d.ts +125 -3
- package/dist/dex/direct-router.js +666 -237
- package/dist/flows/create.d.ts +1 -2
- package/dist/flows/create.js +6 -6
- package/dist/index.d.ts +86 -20
- package/dist/index.js +216 -20
- package/dist/shared/abis/TaxToken.json +105 -0
- package/dist/shared/abis/TokenManager2.json +60 -0
- package/dist/shared/abis/common.d.ts +83 -2
- package/dist/shared/abis/common.js +253 -2
- package/dist/shared/abis/index.d.ts +6 -5
- package/dist/shared/abis/index.js +7 -5
- package/dist/shared/clients/blockrazor.js +25 -39
- package/dist/shared/clients/club48.d.ts +2 -2
- package/dist/shared/clients/club48.js +29 -34
- package/dist/shared/clients/emitservice.js +0 -2
- package/dist/shared/clients/four.d.ts +6 -21
- package/dist/shared/clients/four.js +24 -29
- package/dist/shared/clients/merkle.js +34 -27
- package/dist/shared/constants/addresses.d.ts +1 -1
- package/dist/shared/constants/addresses.js +2 -11
- package/dist/shared/constants/chains.d.ts +1 -1
- package/dist/shared/constants/chains.js +1 -1
- package/dist/shared/constants/gas.d.ts +1 -1
- package/dist/shared/constants/gas.js +6 -2
- package/dist/shared/constants/index.d.ts +0 -3
- package/dist/shared/constants/index.js +0 -1
- package/dist/shared/flap/abi.js +1 -1
- package/dist/shared/flap/constants.d.ts +2 -3
- package/dist/shared/flap/constants.js +4 -5
- package/dist/shared/flap/curve.js +0 -3
- package/dist/shared/flap/errors.d.ts +4 -1
- package/dist/shared/flap/errors.js +1 -20
- package/dist/shared/flap/index.d.ts +5 -5
- package/dist/shared/flap/index.js +5 -5
- package/dist/shared/flap/launch-v6.d.ts +117 -0
- package/dist/shared/flap/launch-v6.js +111 -0
- package/dist/shared/flap/meta.d.ts +18 -22
- package/dist/shared/flap/meta.js +17 -12
- package/dist/shared/flap/permit.js +2 -5
- package/dist/shared/flap/pinata.d.ts +6 -22
- package/dist/shared/flap/pinata.js +26 -21
- package/dist/shared/flap/portal-bundle-merkle/config.d.ts +72 -3
- package/dist/shared/flap/portal-bundle-merkle/config.js +124 -4
- package/dist/shared/flap/portal-bundle-merkle/core.d.ts +4 -0
- package/dist/shared/flap/portal-bundle-merkle/core.js +267 -161
- package/dist/shared/flap/portal-bundle-merkle/create-to-dex.d.ts +4 -17
- package/dist/shared/flap/portal-bundle-merkle/create-to-dex.js +195 -104
- package/dist/shared/flap/portal-bundle-merkle/curve-to-dex.js +92 -100
- package/dist/shared/flap/portal-bundle-merkle/index.d.ts +7 -11
- package/dist/shared/flap/portal-bundle-merkle/index.js +7 -4
- package/dist/shared/flap/portal-bundle-merkle/pancake-proxy.js +68 -71
- package/dist/shared/flap/portal-bundle-merkle/private.js +114 -61
- package/dist/shared/flap/portal-bundle-merkle/swap-buy-first.d.ts +64 -1
- package/dist/shared/flap/portal-bundle-merkle/swap-buy-first.js +247 -66
- package/dist/shared/flap/portal-bundle-merkle/swap.d.ts +71 -2
- package/dist/shared/flap/portal-bundle-merkle/swap.js +410 -103
- package/dist/shared/flap/portal-bundle-merkle/types.d.ts +12 -88
- package/dist/shared/flap/portal-bundle-merkle/utils.d.ts +80 -1
- package/dist/shared/flap/portal-bundle-merkle/utils.js +265 -145
- package/dist/shared/flap/portal-bundle.js +56 -55
- package/dist/shared/flap/portal.d.ts +3 -14
- package/dist/shared/flap/portal.js +26 -49
- package/dist/shared/flap/vanity.d.ts +5 -8
- package/dist/shared/flap/vanity.js +20 -21
- package/dist/shared/flap/vault.d.ts +93 -25
- package/dist/shared/flap/vault.js +126 -75
- package/dist/shared/four/tax-token.d.ts +1 -1
- package/dist/shared/four/tax-token.js +7 -27
- package/dist/shared/index.d.ts +0 -6
- package/dist/shared/index.js +0 -4
- package/dist/utils/airdrop-sweep.d.ts +76 -4
- package/dist/utils/airdrop-sweep.js +55 -42
- package/dist/utils/bundle-helpers.d.ts +243 -9
- package/dist/utils/bundle-helpers.js +584 -10
- package/dist/utils/constants.d.ts +61 -5
- package/dist/utils/constants.js +80 -5
- package/dist/utils/contract-factory.d.ts +4 -2
- package/dist/utils/contract-factory.js +18 -25
- package/dist/utils/erc20.d.ts +89 -7
- package/dist/utils/erc20.js +125 -94
- package/dist/utils/errors.d.ts +1 -12
- package/dist/utils/errors.js +1 -60
- package/dist/utils/holders-maker.d.ts +138 -2
- package/dist/utils/holders-maker.js +661 -26
- package/dist/utils/lp-inspect.d.ts +112 -2
- package/dist/utils/lp-inspect.js +223 -73
- package/dist/utils/mpcExclusive.d.ts +5 -2
- package/dist/utils/mpcExclusive.js +3 -4
- package/dist/utils/private-sale.d.ts +58 -2
- package/dist/utils/private-sale.js +15 -4
- package/dist/utils/provider-factory.d.ts +0 -4
- package/dist/utils/provider-factory.js +0 -10
- package/dist/utils/quote-helpers.d.ts +45 -4
- package/dist/utils/quote-helpers.js +74 -17
- package/dist/utils/stealth-transfer.d.ts +28 -2
- package/dist/utils/stealth-transfer.js +15 -31
- package/dist/utils/swap-helpers.d.ts +15 -2
- package/dist/utils/swap-helpers.js +11 -6
- package/dist/utils/wallet.d.ts +25 -2
- package/dist/utils/wallet.js +10 -13
- package/package.json +4 -160
- package/dist/__tests__/subpath-exports.test.d.ts +0 -1
- package/dist/__tests__/subpath-exports.test.js +0 -64
- package/dist/abis/common.d.ts +0 -85
- package/dist/abis/common.js +0 -264
- package/dist/abis/contracts/TaxToken.json +0 -969
- package/dist/abis/contracts/TokenManager2.json +0 -136
- package/dist/abis/contracts/index.d.ts +0 -5
- package/dist/abis/contracts/index.js +0 -5
- package/dist/abis/flap/index.d.ts +0 -3
- package/dist/abis/flap/index.js +0 -3
- package/dist/abis/flap/portal-events.d.ts +0 -6
- package/dist/abis/flap/portal-events.js +0 -17
- package/dist/abis/flap/portal.d.ts +0 -6
- package/dist/abis/flap/portal.js +0 -37
- package/dist/abis/flap/vault.d.ts +0 -171
- package/dist/abis/flap/vault.js +0 -91
- package/dist/abis/index.d.ts +0 -8
- package/dist/abis/index.js +0 -11
- package/dist/bundle-core/__tests__/config-helpers.test.d.ts +0 -1
- package/dist/bundle-core/__tests__/config-helpers.test.js +0 -28
- package/dist/bundle-core/__tests__/facade-parity.test.d.ts +0 -1
- package/dist/bundle-core/__tests__/facade-parity.test.js +0 -33
- package/dist/bundle-core/__tests__/sign-context-helpers.test.d.ts +0 -1
- package/dist/bundle-core/__tests__/sign-context-helpers.test.js +0 -60
- package/dist/bundle-core/__tests__/sign-fixture.test.d.ts +0 -1
- package/dist/bundle-core/__tests__/sign-fixture.test.js +0 -220
- package/dist/bundle-core/__tests__/sign-fixtures.d.ts +0 -10
- package/dist/bundle-core/__tests__/sign-fixtures.js +0 -16
- package/dist/bundle-core/config-helpers.d.ts +0 -36
- package/dist/bundle-core/config-helpers.js +0 -57
- package/dist/bundle-core/errors.d.ts +0 -50
- package/dist/bundle-core/errors.js +0 -35
- package/dist/bundle-core/four-meme/approve-tokenmanager.d.ts +0 -7
- package/dist/bundle-core/four-meme/approve-tokenmanager.js +0 -99
- package/dist/bundle-core/four-meme/core-helpers.d.ts +0 -8
- package/dist/bundle-core/four-meme/core-helpers.js +0 -40
- package/dist/bundle-core/four-meme/core.d.ts +0 -4
- package/dist/bundle-core/four-meme/core.js +0 -515
- package/dist/bundle-core/four-meme/pancake-proxy.d.ts +0 -28
- package/dist/bundle-core/four-meme/pancake-proxy.js +0 -679
- package/dist/bundle-core/four-meme/private.d.ts +0 -27
- package/dist/bundle-core/four-meme/private.js +0 -465
- package/dist/bundle-core/four-meme/sign-context-helpers.d.ts +0 -2
- package/dist/bundle-core/four-meme/sign-context-helpers.js +0 -2
- package/dist/bundle-core/four-meme/swap-buy-first.d.ts +0 -8
- package/dist/bundle-core/four-meme/swap-buy-first.js +0 -493
- package/dist/bundle-core/four-meme/swap-hop-helpers.d.ts +0 -6
- package/dist/bundle-core/four-meme/swap-hop-helpers.js +0 -63
- package/dist/bundle-core/four-meme/swap-internal.d.ts +0 -3
- package/dist/bundle-core/four-meme/swap-internal.js +0 -18
- package/dist/bundle-core/four-meme/swap-sign-helpers.d.ts +0 -27
- package/dist/bundle-core/four-meme/swap-sign-helpers.js +0 -105
- package/dist/bundle-core/four-meme/swap.d.ts +0 -17
- package/dist/bundle-core/four-meme/swap.js +0 -505
- package/dist/bundle-core/four-meme/types/buy-first.d.ts +0 -50
- package/dist/bundle-core/four-meme/types/buy-first.js +0 -1
- package/dist/bundle-core/four-meme/types/core-flow.d.ts +0 -63
- package/dist/bundle-core/four-meme/types/core-flow.js +0 -1
- package/dist/bundle-core/four-meme/types/index.d.ts +0 -600
- package/dist/bundle-core/four-meme/types/index.js +0 -1
- package/dist/bundle-core/four-meme/types/swap-internal.d.ts +0 -19
- package/dist/bundle-core/four-meme/types/swap-internal.js +0 -1
- package/dist/bundle-core/four-meme/types.d.ts +0 -1
- package/dist/bundle-core/four-meme/types.js +0 -1
- package/dist/bundle-core/four-meme/utils-disperse.d.ts +0 -7
- package/dist/bundle-core/four-meme/utils-disperse.js +0 -396
- package/dist/bundle-core/four-meme/utils-pairwise.d.ts +0 -8
- package/dist/bundle-core/four-meme/utils-pairwise.js +0 -328
- package/dist/bundle-core/four-meme/utils-sweep.d.ts +0 -8
- package/dist/bundle-core/four-meme/utils-sweep.js +0 -744
- package/dist/bundle-core/index.d.ts +0 -8
- package/dist/bundle-core/index.js +0 -8
- package/dist/bundle-core/internal.d.ts +0 -21
- package/dist/bundle-core/internal.js +0 -182
- package/dist/bundle-core/sign-context-helpers.d.ts +0 -25
- package/dist/bundle-core/sign-context-helpers.js +0 -67
- package/dist/bundle-core/submit.d.ts +0 -293
- package/dist/bundle-core/submit.js +0 -727
- package/dist/bundle-core/types/index.d.ts +0 -8
- package/dist/bundle-core/types/index.js +0 -1
- package/dist/bundle-core/types.d.ts +0 -1
- package/dist/bundle-core/types.js +0 -1
- package/dist/chains/bsc/four/utils-disperse.d.ts +0 -1
- package/dist/chains/bsc/four/utils-disperse.js +0 -1
- package/dist/chains/bsc/four/utils-pairwise.d.ts +0 -1
- package/dist/chains/bsc/four/utils-pairwise.js +0 -1
- package/dist/chains/bsc/four/utils-sweep.d.ts +0 -1
- package/dist/chains/bsc/four/utils-sweep.js +0 -1
- package/dist/chains/bsc/iro.d.ts +0 -5
- package/dist/chains/bsc/iro.js +0 -4
- package/dist/chains/bsc/pancake/bundle-buy-first-helpers.d.ts +0 -159
- package/dist/chains/bsc/pancake/bundle-buy-first-helpers.js +0 -117
- package/dist/chains/bsc/pancake/bundle-swap-helpers.d.ts +0 -241
- package/dist/chains/bsc/pancake/bundle-swap-helpers.js +0 -565
- package/dist/chains/eni/flat-aliases.d.ts +0 -10
- package/dist/chains/eni/flat-aliases.js +0 -8
- package/dist/chains/eni/submit.d.ts +0 -43
- package/dist/chains/eni/submit.js +0 -286
- package/dist/chains/xlayer/eip7702/flat-aliases.d.ts +0 -13
- package/dist/chains/xlayer/eip7702/flat-aliases.js +0 -10
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-helpers.d.ts +0 -79
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-helpers.js +0 -1
- package/dist/chains/xlayer/eip7702/transfer-context-helpers.d.ts +0 -26
- package/dist/chains/xlayer/eip7702/transfer-context-helpers.js +0 -57
- package/dist/chains/xlayer/eip7702/volume-helpers.d.ts +0 -148
- package/dist/chains/xlayer/eip7702/volume-helpers.js +0 -48
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.d.ts +0 -126
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.js +0 -228
- package/dist/contracts/tm-bundle-helpers.d.ts +0 -88
- package/dist/contracts/tm-bundle-helpers.js +0 -72
- package/dist/contracts/tm-bundle-merkle/utils-disperse.d.ts +0 -1
- package/dist/contracts/tm-bundle-merkle/utils-disperse.js +0 -1
- package/dist/contracts/tm-bundle-merkle/utils-pairwise.d.ts +0 -1
- package/dist/contracts/tm-bundle-merkle/utils-pairwise.js +0 -1
- package/dist/contracts/tm-bundle-merkle/utils-sweep.d.ts +0 -1
- package/dist/contracts/tm-bundle-merkle/utils-sweep.js +0 -1
- package/dist/dex/direct-router-helpers.d.ts +0 -264
- package/dist/dex/direct-router-helpers.js +0 -539
- package/dist/dex/types.d.ts +0 -81
- package/dist/dex/types.js +0 -1
- package/dist/exports/root-bundle-and-tooling.d.ts +0 -27
- package/dist/exports/root-bundle-and-tooling.js +0 -30
- package/dist/exports/root-eni-and-bsc-iro.d.ts +0 -26
- package/dist/exports/root-eni-and-bsc-iro.js +0 -66
- package/dist/exports/root-foundations.d.ts +0 -35
- package/dist/exports/root-foundations.js +0 -70
- package/dist/exports/root-swap-dex-and-xlayer.d.ts +0 -30
- package/dist/exports/root-swap-dex-and-xlayer.js +0 -78
- package/dist/flap/index.d.ts +0 -10
- package/dist/flap/index.js +0 -8
- package/dist/flows/index.d.ts +0 -1
- package/dist/flows/index.js +0 -1
- package/dist/merkle/index.d.ts +0 -12
- package/dist/merkle/index.js +0 -11
- package/dist/shared/clients/index.d.ts +0 -8
- package/dist/shared/clients/index.js +0 -8
- package/dist/shared/constants/quote.d.ts +0 -30
- package/dist/shared/constants/quote.js +0 -37
- package/dist/shared/flap/portal-bundle-merkle/core-helpers.d.ts +0 -32
- package/dist/shared/flap/portal-bundle-merkle/core-helpers.js +0 -83
- package/dist/shared/flap/portal-bundle-merkle/swap-buy-first-helpers.d.ts +0 -125
- package/dist/shared/flap/portal-bundle-merkle/swap-buy-first-helpers.js +0 -113
- package/dist/shared/flap/portal-bundle-merkle/swap-helpers.d.ts +0 -149
- package/dist/shared/flap/portal-bundle-merkle/swap-helpers.js +0 -259
- package/dist/shared/flap/portal-create-token.d.ts +0 -81
- package/dist/shared/flap/portal-create-token.js +0 -255
- package/dist/shared/foundation/dex/v3-path.d.ts +0 -6
- package/dist/shared/foundation/dex/v3-path.js +0 -35
- package/dist/shared/foundation/gas/bundle-gas.d.ts +0 -49
- package/dist/shared/foundation/gas/bundle-gas.js +0 -93
- package/dist/shared/foundation/gas/profit-hop.d.ts +0 -20
- package/dist/shared/foundation/gas/profit-hop.js +0 -72
- package/dist/shared/foundation/index.d.ts +0 -13
- package/dist/shared/foundation/index.js +0 -12
- package/dist/shared/foundation/nonce/nonce-manager.d.ts +0 -17
- package/dist/shared/foundation/nonce/nonce-manager.js +0 -183
- package/dist/shared/foundation/normalize-unknown.d.ts +0 -9
- package/dist/shared/foundation/normalize-unknown.js +0 -29
- package/dist/shared/foundation/sdk-logger.d.ts +0 -13
- package/dist/shared/foundation/sdk-logger.js +0 -12
- package/dist/shared/foundation/tx/build-request.d.ts +0 -17
- package/dist/shared/foundation/tx/build-request.js +0 -25
- package/dist/shared/foundation/tx/sign-batch.d.ts +0 -5
- package/dist/shared/foundation/tx/sign-batch.js +0 -26
- package/dist/shared/foundation/tx/wallet-sign-patch.d.ts +0 -1
- package/dist/shared/foundation/tx/wallet-sign-patch.js +0 -18
- package/dist/shared/foundation/types/airdrop-sweep.d.ts +0 -79
- package/dist/shared/foundation/types/airdrop-sweep.js +0 -1
- package/dist/shared/foundation/types/erc20.d.ts +0 -65
- package/dist/shared/foundation/types/erc20.js +0 -1
- package/dist/shared/foundation/types/holders-maker.d.ts +0 -64
- package/dist/shared/foundation/types/holders-maker.js +0 -1
- package/dist/shared/foundation/types/index.d.ts +0 -7
- package/dist/shared/foundation/types/index.js +0 -1
- package/dist/shared/foundation/types/lp-inspect.d.ts +0 -102
- package/dist/shared/foundation/types/lp-inspect.js +0 -1
- package/dist/shared/foundation/types/multicall.d.ts +0 -5
- package/dist/shared/foundation/types/multicall.js +0 -1
- package/dist/shared/foundation/types/private-sale.d.ts +0 -35
- package/dist/shared/foundation/types/private-sale.js +0 -1
- package/dist/shared/foundation/types/quote-helpers.d.ts +0 -17
- package/dist/shared/foundation/types/quote-helpers.js +0 -1
- package/dist/types/errors.d.ts +0 -27
- package/dist/types/errors.js +0 -34
- package/dist/utils/holders-maker/addresses.d.ts +0 -12
- package/dist/utils/holders-maker/addresses.js +0 -15
- package/dist/utils/holders-maker/buy-tx.d.ts +0 -44
- package/dist/utils/holders-maker/buy-tx.js +0 -278
- package/dist/utils/holders-maker/constants.d.ts +0 -6
- package/dist/utils/holders-maker/constants.js +0 -7
- package/dist/utils/holders-maker/disperse.d.ts +0 -18
- package/dist/utils/holders-maker/disperse.js +0 -90
- package/dist/utils/holders-maker/routing.d.ts +0 -4
- package/dist/utils/holders-maker/routing.js +0 -45
- package/dist/utils/holders-maker/transfer-tx.d.ts +0 -4
- package/dist/utils/holders-maker/transfer-tx.js +0 -67
- package/dist/utils/holders-maker-helpers.d.ts +0 -9
- package/dist/utils/holders-maker-helpers.js +0 -9
- package/dist/utils/hop-chains.d.ts +0 -35
- package/dist/utils/hop-chains.js +0 -215
- package/dist/utils/lp-inspect-helpers.d.ts +0 -9
- package/dist/utils/lp-inspect-helpers.js +0 -109
- package/dist/utils/types/airdrop-sweep.d.ts +0 -1
- package/dist/utils/types/airdrop-sweep.js +0 -1
- package/dist/utils/types/contract-factory.d.ts +0 -1
- package/dist/utils/types/contract-factory.js +0 -1
- package/dist/utils/types/erc20.d.ts +0 -1
- package/dist/utils/types/erc20.js +0 -1
- package/dist/utils/types/errors.d.ts +0 -1
- package/dist/utils/types/errors.js +0 -1
- package/dist/utils/types/holders-maker.d.ts +0 -1
- package/dist/utils/types/holders-maker.js +0 -1
- package/dist/utils/types/hop-chains.d.ts +0 -8
- package/dist/utils/types/hop-chains.js +0 -1
- package/dist/utils/types/index.d.ts +0 -13
- package/dist/utils/types/index.js +0 -1
- package/dist/utils/types/lp-inspect.d.ts +0 -1
- package/dist/utils/types/lp-inspect.js +0 -1
- package/dist/utils/types/mpc-exclusive.d.ts +0 -5
- package/dist/utils/types/mpc-exclusive.js +0 -1
- package/dist/utils/types/private-sale.d.ts +0 -1
- package/dist/utils/types/private-sale.js +0 -1
- package/dist/utils/types/quote-helpers.d.ts +0 -1
- package/dist/utils/types/quote-helpers.js +0 -1
- package/dist/utils/types/stealth-transfer.d.ts +0 -44
- package/dist/utils/types/stealth-transfer.js +0 -1
- package/dist/utils/types/wallet.d.ts +0 -25
- package/dist/utils/types/wallet.js +0 -1
- package/dist/vanity/index.d.ts +0 -5
- package/dist/vanity/index.js +0 -5
- package/src/abis/contracts/TaxToken.json +0 -969
- package/src/abis/contracts/TokenManager.json +0 -836
- package/src/abis/contracts/TokenManager2.json +0 -136
- package/src/abis/contracts/TokenManagerHelper3.json +0 -993
- /package/dist/{abis/contracts → shared/abis}/TokenManager.json +0 -0
- /package/dist/{abis/contracts → shared/abis}/TokenManagerHelper3.json +0 -0
|
@@ -1,744 +0,0 @@
|
|
|
1
|
-
import { ethers, Wallet } from 'ethers';
|
|
2
|
-
import { getOptimizedGasPrice, NonceManager, buildProfitHopTransactions, PROFIT_HOP_COUNT, } from '../../utils/bundle-helpers.js';
|
|
3
|
-
import { calculateTransferFee } from '../../shared/constants/index.js';
|
|
4
|
-
import { getTxType, getGasPriceConfig, shouldExtractProfit, getProfitRecipient, getBribeAmount, } from '../config-helpers.js';
|
|
5
|
-
import { getErc20Decimals as _getErc20Decimals, generateHopWallets as _generateHopWallets, batchGetBalances as _batchGetBalances, calculateGasLimit as _calculateGasLimit, isNativeTokenAddress as _isNativeTokenAddress, } from '../internal.js';
|
|
6
|
-
import { createSignProvider, resolveHopCountInput, resolveProvidedHops, signBribeTransaction, } from '../sign-context-helpers.js';
|
|
7
|
-
/**
|
|
8
|
-
* 归集(仅签名版本 - 不依赖 Merkle)
|
|
9
|
-
* ✅ 精简版:只负责签名交易,不提交到 Merkle
|
|
10
|
-
*
|
|
11
|
-
* ⚠️ `SweepSignParams.startNonce` 当前未接入;nonce 由 NonceManager / `getTransactionCount` 分配。
|
|
12
|
-
*/
|
|
13
|
-
export async function sweepWithBundleMerkle(params) {
|
|
14
|
-
const { sourcePrivateKeys, target, targetPrivateKey, ratioPct, ratios, amount, amounts, tokenAddress, tokenDecimals, skipIfInsufficient = true, hopCount = 0, hopPrivateKeys, sources, config, } = params;
|
|
15
|
-
// 快速返回空结果
|
|
16
|
-
if (!sourcePrivateKeys || sourcePrivateKeys.length === 0) {
|
|
17
|
-
return {
|
|
18
|
-
signedTransactions: [],
|
|
19
|
-
hopWallets: undefined,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
// 初始化
|
|
23
|
-
const chainIdNum = config.chainId ?? 56;
|
|
24
|
-
const provider = createSignProvider(config.rpcUrl, chainIdNum);
|
|
25
|
-
const isNative = _isNativeTokenAddress(tokenAddress);
|
|
26
|
-
const txType = getTxType(config);
|
|
27
|
-
// ✅ 如果提供了 targetPrivateKey,创建 targetWallet 用于支付利润
|
|
28
|
-
const targetWallet = targetPrivateKey ? new Wallet(targetPrivateKey, provider) : null;
|
|
29
|
-
// 归集比例处理
|
|
30
|
-
const clamp = (n) => typeof n === 'number' && Number.isFinite(n) ? Math.max(0, Math.min(100, Math.floor(n))) : undefined;
|
|
31
|
-
const ratio = clamp(ratioPct);
|
|
32
|
-
// 生成跳转钱包
|
|
33
|
-
// 统一 sources 输入
|
|
34
|
-
const actualKeys = (() => {
|
|
35
|
-
if (sources && sources.length > 0)
|
|
36
|
-
return sources.map((s) => s.privateKey);
|
|
37
|
-
return sourcePrivateKeys;
|
|
38
|
-
})();
|
|
39
|
-
// hop 私钥链优先使用传入
|
|
40
|
-
const providedHops = resolveProvidedHops(actualKeys.length, hopPrivateKeys, sources);
|
|
41
|
-
const hopCountInput = resolveHopCountInput(actualKeys.length, hopCount, sources);
|
|
42
|
-
const preparedHops = providedHops ?? _generateHopWallets(actualKeys.length, hopCountInput);
|
|
43
|
-
const hasHops = preparedHops !== null;
|
|
44
|
-
const maxHopCount = hasHops ? Math.max(...preparedHops.map((h) => h.length)) : 0;
|
|
45
|
-
// 智能计算 Gas Limit
|
|
46
|
-
const finalGasLimit = _calculateGasLimit(config, isNative, hasHops, maxHopCount);
|
|
47
|
-
const nativeGasLimit = (config.prefer21000ForNative ?? false) ? 21000n : finalGasLimit;
|
|
48
|
-
const signedTxs = [];
|
|
49
|
-
// ✅ 利润提取配置
|
|
50
|
-
const extractProfit = shouldExtractProfit();
|
|
51
|
-
const profitAddr = getProfitRecipient();
|
|
52
|
-
let totalProfit = 0n;
|
|
53
|
-
let totalAmountBeforeProfit = 0n;
|
|
54
|
-
let profitHopWallets; // ✅ 收集利润多跳钱包
|
|
55
|
-
// ✅ BSC 链贿赂支持(由 targetWallet 支付,如果提供了 targetPrivateKey)
|
|
56
|
-
const bribeAmount = chainIdNum === 56 ? getBribeAmount(config) : 0n;
|
|
57
|
-
const needBribeTx = bribeAmount > 0n && targetWallet !== null;
|
|
58
|
-
const bribeSignedTx = [];
|
|
59
|
-
// ✅ 贿赂交易放在最前面(由 targetWallet 签名)
|
|
60
|
-
if (needBribeTx && targetWallet) {
|
|
61
|
-
const [bribeGasPrice, bribeNonce] = await Promise.all([
|
|
62
|
-
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
63
|
-
provider.getTransactionCount(targetWallet.address),
|
|
64
|
-
]);
|
|
65
|
-
bribeSignedTx.push(await signBribeTransaction(targetWallet, bribeAmount, bribeNonce, bribeGasPrice, chainIdNum, txType));
|
|
66
|
-
}
|
|
67
|
-
if (!preparedHops) {
|
|
68
|
-
// ========== 无多跳:直接批量归集 ==========
|
|
69
|
-
const wallets = actualKeys.map((pk) => new Wallet(pk, provider));
|
|
70
|
-
const addresses = wallets.map((w) => w.address);
|
|
71
|
-
const nonceManager = new NonceManager(provider);
|
|
72
|
-
// ✅ 优化:并行获取 gasPrice 和余额
|
|
73
|
-
if (isNative) {
|
|
74
|
-
// ✅ 原生币:并行获取 gasPrice 和余额
|
|
75
|
-
const [gasPrice, balances] = await Promise.all([
|
|
76
|
-
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
77
|
-
_batchGetBalances(provider, addresses),
|
|
78
|
-
]);
|
|
79
|
-
const gasCostBase = nativeGasLimit * gasPrice;
|
|
80
|
-
// ✅ 修复:利润多跳需要 PROFIT_HOP_COUNT + 1 笔交易的 gas(payer → hop1 → hop2 → 利润地址)
|
|
81
|
-
// ✅ 统一使用 21055n 作为利润多跳的 gas limit
|
|
82
|
-
const PROFIT_HOP_GAS_LIMIT = 21055n;
|
|
83
|
-
const profitTxGas = PROFIT_HOP_GAS_LIMIT * gasPrice * BigInt(PROFIT_HOP_COUNT + 1);
|
|
84
|
-
// ✅ 第一步:计算所有钱包的归集金额和利润,找出归集金额最大的钱包
|
|
85
|
-
const sweepAmounts = [];
|
|
86
|
-
let maxSweepIndex = -1;
|
|
87
|
-
let maxSweepAmount = 0n;
|
|
88
|
-
for (let i = 0; i < wallets.length; i++) {
|
|
89
|
-
const bal = balances[i];
|
|
90
|
-
let toSend = 0n;
|
|
91
|
-
const ratioForI = (() => {
|
|
92
|
-
if (sources && sources[i] && sources[i].ratioPct !== undefined)
|
|
93
|
-
return clamp(sources[i].ratioPct);
|
|
94
|
-
if (ratios && ratios[i] !== undefined)
|
|
95
|
-
return clamp(ratios[i]);
|
|
96
|
-
return ratio;
|
|
97
|
-
})();
|
|
98
|
-
const amountStrForI = (() => {
|
|
99
|
-
if (sources && sources[i] && sources[i].amount !== undefined)
|
|
100
|
-
return String(sources[i].amount);
|
|
101
|
-
if (amounts && amounts[i] !== undefined)
|
|
102
|
-
return String(amounts[i]);
|
|
103
|
-
return amount !== undefined ? String(amount) : undefined;
|
|
104
|
-
})();
|
|
105
|
-
// ✅ 只有支付者需要 2 笔交易的 gas,其他钱包只需要 1 笔
|
|
106
|
-
const gasCost = gasCostBase; // 所有钱包都只计算主转账的 gas
|
|
107
|
-
if (ratioForI !== undefined) {
|
|
108
|
-
const want = (bal * BigInt(ratioForI)) / 100n;
|
|
109
|
-
const maxSendable = bal > gasCost ? bal - gasCost : 0n;
|
|
110
|
-
toSend = want > maxSendable ? maxSendable : want;
|
|
111
|
-
}
|
|
112
|
-
else if (amountStrForI && amountStrForI.trim().length > 0) {
|
|
113
|
-
const amt = ethers.parseEther(amountStrForI);
|
|
114
|
-
const need = amt + gasCost;
|
|
115
|
-
if (!skipIfInsufficient || bal >= need)
|
|
116
|
-
toSend = amt;
|
|
117
|
-
}
|
|
118
|
-
sweepAmounts.push(toSend);
|
|
119
|
-
totalAmountBeforeProfit += toSend;
|
|
120
|
-
// 找出归集金额最大的钱包
|
|
121
|
-
if (toSend > maxSweepAmount) {
|
|
122
|
-
maxSweepAmount = toSend;
|
|
123
|
-
maxSweepIndex = i;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
// ✅ 按地址数量收取固定费用(不受转账金额和中转次数影响)
|
|
127
|
-
const activeAddressCount = sweepAmounts.filter((a) => a > 0n).length;
|
|
128
|
-
if (extractProfit && activeAddressCount > 0) {
|
|
129
|
-
totalProfit = calculateTransferFee(chainIdNum, activeAddressCount);
|
|
130
|
-
}
|
|
131
|
-
// ✅ 如果需要提取费用,检查支付者是否有足够余额支付费用转账的额外 gas
|
|
132
|
-
if (extractProfit && totalProfit > 0n && maxSweepIndex >= 0) {
|
|
133
|
-
const payerBalance = balances[maxSweepIndex];
|
|
134
|
-
const payerSweepAmount = sweepAmounts[maxSweepIndex];
|
|
135
|
-
const payerNeedGas = gasCostBase + profitTxGas; // 支付者需要 2 笔交易的 gas
|
|
136
|
-
// 如果支付者余额不足以支付 2 笔交易的 gas + 费用,减少其归集金额
|
|
137
|
-
if (payerBalance < payerSweepAmount + payerNeedGas + totalProfit) {
|
|
138
|
-
const maxPayerSweep = payerBalance > payerNeedGas + totalProfit ? payerBalance - payerNeedGas - totalProfit : 0n;
|
|
139
|
-
sweepAmounts[maxSweepIndex] = maxPayerSweep;
|
|
140
|
-
totalAmountBeforeProfit = sweepAmounts.reduce((sum, amt) => sum + amt, 0n);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
// ✅ 第二步:生成归集交易
|
|
144
|
-
// ✅ 确定利润支付者:优先使用 targetWallet,否则使用归集金额最大的源钱包
|
|
145
|
-
const useTargetAsPayer = targetWallet !== null;
|
|
146
|
-
const profitPayerWallet = useTargetAsPayer ? targetWallet : maxSweepIndex >= 0 ? wallets[maxSweepIndex] : null;
|
|
147
|
-
// ✅ 先为支付者预留 nonce,确保 nonce 连续
|
|
148
|
-
let payerProfitNonce;
|
|
149
|
-
if (extractProfit && totalProfit > 0n && profitPayerWallet) {
|
|
150
|
-
const nonces = await nonceManager.getNextNonceBatch(profitPayerWallet, useTargetAsPayer ? 1 : 2);
|
|
151
|
-
payerProfitNonce = useTargetAsPayer ? nonces[0] : nonces[1]; // targetWallet 只需要 1 个 nonce
|
|
152
|
-
}
|
|
153
|
-
// ✅ 优化:批量获取所有钱包的 nonce(JSON-RPC 批量请求)
|
|
154
|
-
// 过滤出需要归集的钱包(如果用 targetWallet 支付利润,则不排除 maxSweepIndex)
|
|
155
|
-
const walletsToSweep = wallets.filter((_, i) => sweepAmounts[i] > 0n && (useTargetAsPayer || i !== maxSweepIndex));
|
|
156
|
-
const nonces = walletsToSweep.length > 0 ? await nonceManager.getNextNoncesForWallets(walletsToSweep) : [];
|
|
157
|
-
let nonceIdx = 0;
|
|
158
|
-
const txPromises = wallets.map(async (w, i) => {
|
|
159
|
-
const toSend = sweepAmounts[i];
|
|
160
|
-
if (toSend <= 0n)
|
|
161
|
-
return null;
|
|
162
|
-
let actualToSend = toSend;
|
|
163
|
-
if (extractProfit && !useTargetAsPayer) {
|
|
164
|
-
// ✅ 如果由源钱包支付利润,支付者扣除所有利润总和;其他钱包不扣利润,归集干净
|
|
165
|
-
if (i === maxSweepIndex && totalProfit > 0n) {
|
|
166
|
-
actualToSend = toSend - totalProfit; // 支付者扣除所有利润总和
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
actualToSend = toSend; // 其他钱包不扣利润,归集全部
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
// ✅ 如果由 targetWallet 支付利润,所有源钱包都归集全部金额
|
|
173
|
-
// ✅ 支付者使用预留的第一个 nonce,其他钱包使用批量获取的 nonce
|
|
174
|
-
let nonce;
|
|
175
|
-
if (!useTargetAsPayer && i === maxSweepIndex && payerProfitNonce !== undefined) {
|
|
176
|
-
nonce = payerProfitNonce - 1; // 使用预留的第一个 nonce
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
nonce = nonces[nonceIdx++];
|
|
180
|
-
}
|
|
181
|
-
const mainTx = await w.signTransaction({
|
|
182
|
-
to: target,
|
|
183
|
-
value: actualToSend,
|
|
184
|
-
nonce,
|
|
185
|
-
gasPrice,
|
|
186
|
-
gasLimit: nativeGasLimit,
|
|
187
|
-
chainId: BigInt(chainIdNum),
|
|
188
|
-
type: txType,
|
|
189
|
-
});
|
|
190
|
-
return mainTx;
|
|
191
|
-
});
|
|
192
|
-
const allTxs = (await Promise.all(txPromises)).filter((tx) => tx !== null);
|
|
193
|
-
signedTxs.push(...allTxs);
|
|
194
|
-
// ✅ 第三步:利润多跳转账(强制 2 跳中转)
|
|
195
|
-
if (extractProfit && totalProfit > 0n && profitPayerWallet && payerProfitNonce !== undefined) {
|
|
196
|
-
const profitHopResult = await buildProfitHopTransactions({
|
|
197
|
-
provider,
|
|
198
|
-
payerWallet: profitPayerWallet,
|
|
199
|
-
profitAmount: totalProfit,
|
|
200
|
-
profitRecipient: profitAddr,
|
|
201
|
-
hopCount: PROFIT_HOP_COUNT,
|
|
202
|
-
gasPrice,
|
|
203
|
-
chainId: chainIdNum,
|
|
204
|
-
txType,
|
|
205
|
-
startNonce: payerProfitNonce,
|
|
206
|
-
});
|
|
207
|
-
signedTxs.push(...profitHopResult.signedTransactions);
|
|
208
|
-
profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
// ✅ ERC20:并行获取 gasPrice、decimals、余额(传入 chainIdNum 避免 NETWORK_ERROR)
|
|
213
|
-
const [gasPrice, decimals, balances, bnbBalances] = await Promise.all([
|
|
214
|
-
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
215
|
-
Promise.resolve(tokenDecimals ?? (await _getErc20Decimals(provider, tokenAddress, chainIdNum))),
|
|
216
|
-
_batchGetBalances(provider, addresses, tokenAddress),
|
|
217
|
-
config.checkBnbForErc20NoHop ? _batchGetBalances(provider, addresses) : Promise.resolve([]),
|
|
218
|
-
]);
|
|
219
|
-
const iface = new ethers.Interface(['function transfer(address,uint256) returns (bool)']);
|
|
220
|
-
// ✅ 修复:利润多跳需要 PROFIT_HOP_COUNT + 1 笔交易的 gas
|
|
221
|
-
// ✅ 统一使用 21055n 作为利润多跳的 gas limit
|
|
222
|
-
const PROFIT_HOP_GAS_LIMIT_ERC20 = 21055n;
|
|
223
|
-
const profitTxGas = PROFIT_HOP_GAS_LIMIT_ERC20 * gasPrice * BigInt(PROFIT_HOP_COUNT + 1);
|
|
224
|
-
// ✅ 第一步:计算所有钱包的归集金额和利润,找出归集金额最大的钱包
|
|
225
|
-
const sweepAmounts = [];
|
|
226
|
-
let maxSweepIndex = -1;
|
|
227
|
-
let maxSweepAmount = 0n;
|
|
228
|
-
for (let i = 0; i < wallets.length; i++) {
|
|
229
|
-
const bal = balances[i];
|
|
230
|
-
let toSend = 0n;
|
|
231
|
-
const ratioForI = (() => {
|
|
232
|
-
if (sources && sources[i] && sources[i].ratioPct !== undefined)
|
|
233
|
-
return clamp(sources[i].ratioPct);
|
|
234
|
-
if (ratios && ratios[i] !== undefined)
|
|
235
|
-
return clamp(ratios[i]);
|
|
236
|
-
return ratio;
|
|
237
|
-
})();
|
|
238
|
-
const amountStrForI = (() => {
|
|
239
|
-
if (sources && sources[i] && sources[i].amount !== undefined)
|
|
240
|
-
return String(sources[i].amount);
|
|
241
|
-
if (amounts && amounts[i] !== undefined)
|
|
242
|
-
return String(amounts[i]);
|
|
243
|
-
return amount !== undefined ? String(amount) : undefined;
|
|
244
|
-
})();
|
|
245
|
-
if (ratioForI !== undefined) {
|
|
246
|
-
toSend = (bal * BigInt(ratioForI)) / 100n;
|
|
247
|
-
}
|
|
248
|
-
else if (amountStrForI && amountStrForI.trim().length > 0) {
|
|
249
|
-
toSend = ethers.parseUnits(amountStrForI, decimals);
|
|
250
|
-
}
|
|
251
|
-
if (toSend <= 0n || (skipIfInsufficient && bal < toSend)) {
|
|
252
|
-
sweepAmounts.push(0n);
|
|
253
|
-
continue;
|
|
254
|
-
}
|
|
255
|
-
// ✅ 检查 BNB 余额(只需主转账的 gas,支付者后面单独检查)
|
|
256
|
-
const totalGasNeeded = finalGasLimit * gasPrice;
|
|
257
|
-
if (config.checkBnbForErc20NoHop) {
|
|
258
|
-
const bnb = bnbBalances[i] ?? 0n;
|
|
259
|
-
if (skipIfInsufficient && bnb < totalGasNeeded) {
|
|
260
|
-
sweepAmounts.push(0n);
|
|
261
|
-
continue;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
sweepAmounts.push(toSend);
|
|
265
|
-
totalAmountBeforeProfit += toSend;
|
|
266
|
-
// 找出归集金额最大的钱包
|
|
267
|
-
if (toSend > maxSweepAmount) {
|
|
268
|
-
maxSweepAmount = toSend;
|
|
269
|
-
maxSweepIndex = i;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
// ✅ 按地址数量收取固定费用(原生代币支付,不受转账金额影响)
|
|
273
|
-
const activeAddressCountErc20 = sweepAmounts.filter((a) => a > 0n).length;
|
|
274
|
-
let nativeProfitAmount = 0n;
|
|
275
|
-
if (extractProfit && activeAddressCountErc20 > 0) {
|
|
276
|
-
nativeProfitAmount = calculateTransferFee(chainIdNum, activeAddressCountErc20);
|
|
277
|
-
totalProfit = nativeProfitAmount;
|
|
278
|
-
}
|
|
279
|
-
// ✅ 确定费用支付者:优先使用 targetWallet,否则使用归集金额最大的源钱包
|
|
280
|
-
const useTargetAsPayerErc20 = targetWallet !== null;
|
|
281
|
-
const profitPayerWalletErc20 = useTargetAsPayerErc20
|
|
282
|
-
? targetWallet
|
|
283
|
-
: maxSweepIndex >= 0
|
|
284
|
-
? wallets[maxSweepIndex]
|
|
285
|
-
: null;
|
|
286
|
-
// ✅ 如果需要提取费用,检查支付者是否有足够原生代币支付
|
|
287
|
-
if (extractProfit && nativeProfitAmount > 0n && profitPayerWalletErc20 && config.checkBnbForErc20NoHop) {
|
|
288
|
-
const payerBnbBalance = useTargetAsPayerErc20
|
|
289
|
-
? await provider.getBalance(target)
|
|
290
|
-
: (bnbBalances[maxSweepIndex] ?? 0n);
|
|
291
|
-
const payerNeedGas = (useTargetAsPayerErc20 ? 0n : finalGasLimit * gasPrice) + profitTxGas + nativeProfitAmount;
|
|
292
|
-
// 如果支付者原生代币余额不足,跳过费用提取
|
|
293
|
-
if (payerBnbBalance < payerNeedGas) {
|
|
294
|
-
nativeProfitAmount = 0n;
|
|
295
|
-
totalProfit = 0n;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
// ✅ 第二步:生成归集交易(ERC20 全额归集,费用以原生币单独支付)
|
|
299
|
-
let payerProfitNonce;
|
|
300
|
-
if (extractProfit && nativeProfitAmount > 0n && profitPayerWalletErc20) {
|
|
301
|
-
const nonces = await nonceManager.getNextNonceBatch(profitPayerWalletErc20, useTargetAsPayerErc20 ? 1 : 2);
|
|
302
|
-
payerProfitNonce = useTargetAsPayerErc20 ? nonces[0] : nonces[1];
|
|
303
|
-
}
|
|
304
|
-
// ✅ 优化:批量获取所有钱包的 nonce(JSON-RPC 批量请求)
|
|
305
|
-
// 过滤出需要归集的钱包(如果用 targetWallet 支付利润,则不排除 maxSweepIndex)
|
|
306
|
-
const walletsToSweepErc20 = wallets.filter((_, i) => sweepAmounts[i] > 0n && (useTargetAsPayerErc20 || i !== maxSweepIndex));
|
|
307
|
-
const noncesErc20 = walletsToSweepErc20.length > 0 ? await nonceManager.getNextNoncesForWallets(walletsToSweepErc20) : [];
|
|
308
|
-
let nonceIdxErc20 = 0;
|
|
309
|
-
const txPromises = wallets.map(async (w, i) => {
|
|
310
|
-
const toSend = sweepAmounts[i];
|
|
311
|
-
if (toSend <= 0n)
|
|
312
|
-
return null;
|
|
313
|
-
// ✅ ERC20 归集:全部归集,不扣除代币(利润从 BNB 支付)
|
|
314
|
-
const actualToSend = toSend;
|
|
315
|
-
// ✅ 支付者使用预留的第一个 nonce,其他钱包使用批量获取的 nonce
|
|
316
|
-
let nonce;
|
|
317
|
-
if (!useTargetAsPayerErc20 && i === maxSweepIndex && payerProfitNonce !== undefined) {
|
|
318
|
-
nonce = payerProfitNonce - 1; // 使用预留的第一个 nonce
|
|
319
|
-
}
|
|
320
|
-
else {
|
|
321
|
-
nonce = noncesErc20[nonceIdxErc20++];
|
|
322
|
-
}
|
|
323
|
-
const data = iface.encodeFunctionData('transfer', [target, actualToSend]);
|
|
324
|
-
const mainTx = await w.signTransaction({
|
|
325
|
-
to: tokenAddress,
|
|
326
|
-
data,
|
|
327
|
-
value: 0n,
|
|
328
|
-
nonce,
|
|
329
|
-
gasPrice,
|
|
330
|
-
gasLimit: finalGasLimit,
|
|
331
|
-
chainId: BigInt(chainIdNum),
|
|
332
|
-
type: txType,
|
|
333
|
-
});
|
|
334
|
-
return mainTx;
|
|
335
|
-
});
|
|
336
|
-
const allTxs = (await Promise.all(txPromises)).filter((tx) => tx !== null);
|
|
337
|
-
signedTxs.push(...allTxs);
|
|
338
|
-
// ✅ 第三步:费用多跳转账(强制 2 跳中转)
|
|
339
|
-
if (extractProfit && nativeProfitAmount > 0n && profitPayerWalletErc20 && payerProfitNonce !== undefined) {
|
|
340
|
-
const profitHopResult = await buildProfitHopTransactions({
|
|
341
|
-
provider,
|
|
342
|
-
payerWallet: profitPayerWalletErc20,
|
|
343
|
-
profitAmount: nativeProfitAmount,
|
|
344
|
-
profitRecipient: profitAddr,
|
|
345
|
-
hopCount: PROFIT_HOP_COUNT,
|
|
346
|
-
gasPrice,
|
|
347
|
-
chainId: chainIdNum,
|
|
348
|
-
txType,
|
|
349
|
-
startNonce: payerProfitNonce,
|
|
350
|
-
});
|
|
351
|
-
signedTxs.push(...profitHopResult.signedTransactions);
|
|
352
|
-
profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
else {
|
|
357
|
-
// ========== 有多跳:构建跳转链归集 ==========
|
|
358
|
-
// ✅ 优化版:批量计算 + 批量获取 nonce + 并行签名
|
|
359
|
-
const sourceWallets = actualKeys.map((pk) => new Wallet(pk, provider));
|
|
360
|
-
const withHopIndexes = [];
|
|
361
|
-
const withoutHopIndexes = [];
|
|
362
|
-
for (let i = 0; i < preparedHops.length; i++) {
|
|
363
|
-
if (preparedHops[i].length > 0) {
|
|
364
|
-
withHopIndexes.push(i);
|
|
365
|
-
}
|
|
366
|
-
else {
|
|
367
|
-
withoutHopIndexes.push(i);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
const sourceAddresses = sourceWallets.map((w) => w.address);
|
|
371
|
-
// ✅ 优化:并行获取 gasPrice、decimals、余额
|
|
372
|
-
const [gasPrice, decimals, balances, bnbBalances] = await Promise.all([
|
|
373
|
-
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
374
|
-
isNative
|
|
375
|
-
? Promise.resolve(18)
|
|
376
|
-
: Promise.resolve(tokenDecimals ?? (await _getErc20Decimals(provider, tokenAddress, chainIdNum))),
|
|
377
|
-
_batchGetBalances(provider, sourceAddresses, tokenAddress),
|
|
378
|
-
isNative ? Promise.resolve([]) : _batchGetBalances(provider, sourceAddresses),
|
|
379
|
-
]);
|
|
380
|
-
const iface = isNative ? null : new ethers.Interface(['function transfer(address,uint256) returns (bool)']);
|
|
381
|
-
// ✅ Gas limit 设置(与分散函数保持一致)
|
|
382
|
-
// - 原生代币转账:21000(固定)
|
|
383
|
-
// - ERC20 转账:65000(固定,因为 gas 波动较大,不再使用模拟预估)
|
|
384
|
-
const nativeTransferGasLimit = 21000n;
|
|
385
|
-
const erc20TransferGasLimit = 65000n;
|
|
386
|
-
// ✅ 原生代币多跳的 gas 费(每跳只需要 21000)
|
|
387
|
-
const nativeHopGasFee = nativeTransferGasLimit * gasPrice;
|
|
388
|
-
// ✅ ERC20 多跳时,中转钱包需要执行 2 笔交易(转 gas + 转 ERC20)
|
|
389
|
-
const erc20HopGasFee = erc20TransferGasLimit * gasPrice;
|
|
390
|
-
const nativeHopGasFeeForErc20 = nativeTransferGasLimit * gasPrice;
|
|
391
|
-
const nonceManager = new NonceManager(provider);
|
|
392
|
-
// ✅ 用于记录每个钱包的归集金额
|
|
393
|
-
const sweepAmounts = new Array(sourceWallets.length).fill(0n);
|
|
394
|
-
// ✅ 辅助函数:获取比例和金额
|
|
395
|
-
const getRatioForI = (i) => {
|
|
396
|
-
if (sources && sources[i] && sources[i].ratioPct !== undefined)
|
|
397
|
-
return clamp(sources[i].ratioPct);
|
|
398
|
-
if (ratios && ratios[i] !== undefined)
|
|
399
|
-
return clamp(ratios[i]);
|
|
400
|
-
return ratio;
|
|
401
|
-
};
|
|
402
|
-
const getAmountStrForI = (i) => {
|
|
403
|
-
if (sources && sources[i] && sources[i].amount !== undefined)
|
|
404
|
-
return String(sources[i].amount);
|
|
405
|
-
if (amounts && amounts[i] !== undefined)
|
|
406
|
-
return String(amounts[i]);
|
|
407
|
-
return amount !== undefined ? String(amount) : undefined;
|
|
408
|
-
};
|
|
409
|
-
const noHopTxDataList = [];
|
|
410
|
-
for (const i of withoutHopIndexes) {
|
|
411
|
-
const bal = balances[i];
|
|
412
|
-
let toSend = 0n;
|
|
413
|
-
const ratioForI = getRatioForI(i);
|
|
414
|
-
const amountStrForI = getAmountStrForI(i);
|
|
415
|
-
if (isNative) {
|
|
416
|
-
const gasCost = nativeGasLimit * gasPrice;
|
|
417
|
-
if (ratioForI !== undefined) {
|
|
418
|
-
const want = (bal * BigInt(ratioForI)) / 100n;
|
|
419
|
-
const maxSendable = bal > gasCost ? bal - gasCost : 0n;
|
|
420
|
-
toSend = want > maxSendable ? maxSendable : want;
|
|
421
|
-
}
|
|
422
|
-
else if (amountStrForI && amountStrForI.trim().length > 0) {
|
|
423
|
-
const amt = ethers.parseEther(amountStrForI);
|
|
424
|
-
const need = amt + gasCost;
|
|
425
|
-
if (!skipIfInsufficient || bal >= need)
|
|
426
|
-
toSend = amt;
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
else {
|
|
430
|
-
if (ratioForI !== undefined) {
|
|
431
|
-
toSend = (bal * BigInt(ratioForI)) / 100n;
|
|
432
|
-
}
|
|
433
|
-
else if (amountStrForI && amountStrForI.trim().length > 0) {
|
|
434
|
-
toSend = ethers.parseUnits(amountStrForI, decimals);
|
|
435
|
-
}
|
|
436
|
-
if (skipIfInsufficient && bal < toSend)
|
|
437
|
-
toSend = 0n;
|
|
438
|
-
}
|
|
439
|
-
if (toSend > 0n) {
|
|
440
|
-
sweepAmounts[i] = toSend;
|
|
441
|
-
totalAmountBeforeProfit += toSend;
|
|
442
|
-
noHopTxDataList.push({ index: i, wallet: sourceWallets[i], toSend });
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
// ========== 第2步:批量获取无跳转钱包的 nonces ==========
|
|
446
|
-
const noHopWallets = noHopTxDataList.map((d) => d.wallet);
|
|
447
|
-
const noHopNonces = noHopWallets.length > 0 ? await nonceManager.getNextNoncesForWallets(noHopWallets) : [];
|
|
448
|
-
// ========== 第3步:并行签名无跳转交易 ==========
|
|
449
|
-
const noHopTxPromises = noHopTxDataList.map((data, idx) => {
|
|
450
|
-
const { wallet, toSend } = data;
|
|
451
|
-
const nonce = noHopNonces[idx];
|
|
452
|
-
if (isNative) {
|
|
453
|
-
return wallet.signTransaction({
|
|
454
|
-
to: target,
|
|
455
|
-
value: toSend,
|
|
456
|
-
nonce,
|
|
457
|
-
gasPrice,
|
|
458
|
-
gasLimit: nativeGasLimit,
|
|
459
|
-
chainId: BigInt(chainIdNum),
|
|
460
|
-
type: txType,
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
|
-
else {
|
|
464
|
-
const txData = iface.encodeFunctionData('transfer', [target, toSend]);
|
|
465
|
-
return wallet.signTransaction({
|
|
466
|
-
to: tokenAddress,
|
|
467
|
-
data: txData,
|
|
468
|
-
value: 0n,
|
|
469
|
-
nonce,
|
|
470
|
-
gasPrice,
|
|
471
|
-
gasLimit: finalGasLimit,
|
|
472
|
-
chainId: BigInt(chainIdNum),
|
|
473
|
-
type: txType,
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
});
|
|
477
|
-
if (noHopTxPromises.length > 0) {
|
|
478
|
-
const noHopSignedTxs = await Promise.all(noHopTxPromises);
|
|
479
|
-
signedTxs.push(...noHopSignedTxs);
|
|
480
|
-
}
|
|
481
|
-
const hopTxDataList = [];
|
|
482
|
-
for (const i of withHopIndexes) {
|
|
483
|
-
const sourceWallet = sourceWallets[i];
|
|
484
|
-
const hopChain = preparedHops[i];
|
|
485
|
-
const bal = balances[i];
|
|
486
|
-
let toSend = 0n;
|
|
487
|
-
const ratioForI = getRatioForI(i);
|
|
488
|
-
const amountStrForI = getAmountStrForI(i);
|
|
489
|
-
if (isNative) {
|
|
490
|
-
// 原生代币多跳每跳只需要 21000 gas
|
|
491
|
-
const totalGasCost = nativeTransferGasLimit * gasPrice * BigInt(hopChain.length + 1);
|
|
492
|
-
if (ratioForI !== undefined) {
|
|
493
|
-
const want = (bal * BigInt(ratioForI)) / 100n;
|
|
494
|
-
const maxSendable = bal > totalGasCost ? bal - totalGasCost : 0n;
|
|
495
|
-
toSend = want > maxSendable ? maxSendable : want;
|
|
496
|
-
}
|
|
497
|
-
else if (amountStrForI && amountStrForI.trim().length > 0) {
|
|
498
|
-
const amt = ethers.parseEther(amountStrForI);
|
|
499
|
-
const need = amt + totalGasCost;
|
|
500
|
-
if (!skipIfInsufficient || bal >= need)
|
|
501
|
-
toSend = amt;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
else {
|
|
505
|
-
const bnbBal = bnbBalances[i];
|
|
506
|
-
// 计算 ERC20 多跳所需的 BNB(逐层传递模式):
|
|
507
|
-
// - 源钱包执行 2 笔交易的 gas(转 gas 21000 + 转 ERC20)
|
|
508
|
-
// - 源钱包转给第一个中转钱包的 gas(包含后续所有)
|
|
509
|
-
// 简化计算:每个中转钱包 ≈ (21000 + erc20GasLimit) * gasPrice
|
|
510
|
-
const sourceGas = (nativeTransferGasLimit + erc20TransferGasLimit) * gasPrice;
|
|
511
|
-
const hopGas = (nativeHopGasFeeForErc20 + erc20HopGasFee) * BigInt(hopChain.length);
|
|
512
|
-
const bnbNeeded = sourceGas + hopGas;
|
|
513
|
-
if (bnbBal < bnbNeeded && skipIfInsufficient)
|
|
514
|
-
continue;
|
|
515
|
-
if (ratioForI !== undefined) {
|
|
516
|
-
toSend = (bal * BigInt(ratioForI)) / 100n;
|
|
517
|
-
}
|
|
518
|
-
else if (amountStrForI && amountStrForI.trim().length > 0) {
|
|
519
|
-
toSend = ethers.parseUnits(amountStrForI, decimals);
|
|
520
|
-
}
|
|
521
|
-
if (skipIfInsufficient && bal < toSend)
|
|
522
|
-
toSend = 0n;
|
|
523
|
-
}
|
|
524
|
-
if (toSend <= 0n)
|
|
525
|
-
continue;
|
|
526
|
-
sweepAmounts[i] = toSend;
|
|
527
|
-
totalAmountBeforeProfit += toSend;
|
|
528
|
-
// ✅ 支持 string 和 GeneratedWallet 两种类型
|
|
529
|
-
const fullChain = [
|
|
530
|
-
sourceWallet,
|
|
531
|
-
...hopChain.map((w) => new Wallet(typeof w === 'string' ? w : w.privateKey, provider)),
|
|
532
|
-
];
|
|
533
|
-
const addresses = [...fullChain.map((w) => w.address), target];
|
|
534
|
-
hopTxDataList.push({ index: i, sourceWallet, toSend, hopChain, fullChain, addresses });
|
|
535
|
-
}
|
|
536
|
-
// ========== 第5步:计算每个有跳转钱包需要的 nonce 数量并批量获取 ==========
|
|
537
|
-
// 每个源钱包需要的 nonce 数量:
|
|
538
|
-
// - Native: 1(一笔转账包含后续所有 gas)
|
|
539
|
-
// - ERC20: 2(转 gas + 转 ERC20)
|
|
540
|
-
const hopNonceNeeds = hopTxDataList.map(() => (isNative ? 1 : 2));
|
|
541
|
-
const hopSourceWallets = hopTxDataList.map((d) => d.sourceWallet);
|
|
542
|
-
// ✅ 批量获取所有有跳转钱包的 nonces
|
|
543
|
-
const hopNoncesFlat = [];
|
|
544
|
-
if (hopSourceWallets.length > 0) {
|
|
545
|
-
const batchNoncePromises = hopSourceWallets.map((w, idx) => nonceManager.getNextNonceBatch(w, hopNonceNeeds[idx]));
|
|
546
|
-
const batchNonces = await Promise.all(batchNoncePromises);
|
|
547
|
-
batchNonces.forEach((nonces) => hopNoncesFlat.push(...nonces));
|
|
548
|
-
}
|
|
549
|
-
const hopTxsToSign = [];
|
|
550
|
-
let nonceOffset = 0;
|
|
551
|
-
for (let dataIdx = 0; dataIdx < hopTxDataList.length; dataIdx++) {
|
|
552
|
-
const { sourceWallet, toSend, hopChain, fullChain, addresses } = hopTxDataList[dataIdx];
|
|
553
|
-
const nonceCount = hopNonceNeeds[dataIdx];
|
|
554
|
-
const nonces = hopNoncesFlat.slice(nonceOffset, nonceOffset + nonceCount);
|
|
555
|
-
nonceOffset += nonceCount;
|
|
556
|
-
if (isNative) {
|
|
557
|
-
// ========== 原生代币多跳:gas 包含在转账金额中逐层传递 ==========
|
|
558
|
-
for (let j = 0; j < addresses.length - 1; j++) {
|
|
559
|
-
const fromWallet = fullChain[j];
|
|
560
|
-
const toAddress = addresses[j + 1];
|
|
561
|
-
const nonce = j === 0 ? nonces[0] : 0;
|
|
562
|
-
const remainingHops = addresses.length - 2 - j;
|
|
563
|
-
const additionalGas = nativeHopGasFee * BigInt(remainingHops);
|
|
564
|
-
const valueToTransfer = toSend + additionalGas;
|
|
565
|
-
hopTxsToSign.push({
|
|
566
|
-
wallet: fromWallet,
|
|
567
|
-
tx: {
|
|
568
|
-
to: toAddress,
|
|
569
|
-
value: valueToTransfer,
|
|
570
|
-
nonce,
|
|
571
|
-
gasPrice,
|
|
572
|
-
gasLimit: nativeTransferGasLimit,
|
|
573
|
-
chainId: BigInt(chainIdNum),
|
|
574
|
-
type: txType,
|
|
575
|
-
},
|
|
576
|
-
});
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
else {
|
|
580
|
-
// ========== ERC20 多跳:gas 也逐层传递(保护隐私)==========
|
|
581
|
-
// 计算每个中转钱包需要的 gas(从后往前)
|
|
582
|
-
const hopGasNeeds = [];
|
|
583
|
-
for (let j = hopChain.length - 1; j >= 0; j--) {
|
|
584
|
-
if (j === hopChain.length - 1) {
|
|
585
|
-
// 最后一个中转钱包:只需要 ERC20 转账的 gas
|
|
586
|
-
hopGasNeeds.unshift(erc20HopGasFee);
|
|
587
|
-
}
|
|
588
|
-
else {
|
|
589
|
-
// 其他中转钱包:转 gas(21000) + 转 ERC20 + 后续的 gas
|
|
590
|
-
const nextHopGas = hopGasNeeds[0];
|
|
591
|
-
hopGasNeeds.unshift(nativeHopGasFeeForErc20 + erc20HopGasFee + nextHopGas);
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
// 第一步:源钱包给第一个中转钱包转 gas(包含所有后续的 gas)
|
|
595
|
-
const totalGasForFirstHop = hopGasNeeds[0];
|
|
596
|
-
hopTxsToSign.push({
|
|
597
|
-
wallet: sourceWallet,
|
|
598
|
-
tx: {
|
|
599
|
-
to: fullChain[1].address,
|
|
600
|
-
value: totalGasForFirstHop,
|
|
601
|
-
nonce: nonces[0],
|
|
602
|
-
gasPrice,
|
|
603
|
-
gasLimit: nativeTransferGasLimit,
|
|
604
|
-
chainId: BigInt(chainIdNum),
|
|
605
|
-
type: txType,
|
|
606
|
-
},
|
|
607
|
-
});
|
|
608
|
-
// 第二步:源钱包给第一个中转钱包转 ERC20
|
|
609
|
-
const sourceToFirstHopData = iface.encodeFunctionData('transfer', [fullChain[1].address, toSend]);
|
|
610
|
-
hopTxsToSign.push({
|
|
611
|
-
wallet: sourceWallet,
|
|
612
|
-
tx: {
|
|
613
|
-
to: tokenAddress,
|
|
614
|
-
data: sourceToFirstHopData,
|
|
615
|
-
value: 0n,
|
|
616
|
-
nonce: nonces[1],
|
|
617
|
-
gasPrice,
|
|
618
|
-
gasLimit: erc20TransferGasLimit,
|
|
619
|
-
chainId: BigInt(chainIdNum),
|
|
620
|
-
type: txType,
|
|
621
|
-
},
|
|
622
|
-
});
|
|
623
|
-
// 第三步:中转钱包逐层传递(gas 和 ERC20)
|
|
624
|
-
for (let j = 1; j < fullChain.length; j++) {
|
|
625
|
-
const fromWallet = fullChain[j];
|
|
626
|
-
const toAddress = addresses[j + 1]; // 下一个地址(可能是中转钱包或最终目标)
|
|
627
|
-
const isLastHop = j === fullChain.length - 1;
|
|
628
|
-
if (!isLastHop) {
|
|
629
|
-
// 非最后一个中转钱包:先转 gas 给下一个中转钱包
|
|
630
|
-
const gasToTransfer = hopGasNeeds[j]; // 下一个中转钱包需要的 gas
|
|
631
|
-
hopTxsToSign.push({
|
|
632
|
-
wallet: fromWallet,
|
|
633
|
-
tx: {
|
|
634
|
-
to: toAddress,
|
|
635
|
-
value: gasToTransfer,
|
|
636
|
-
nonce: 0, // 中转钱包的第一笔交易
|
|
637
|
-
gasPrice,
|
|
638
|
-
gasLimit: nativeTransferGasLimit,
|
|
639
|
-
chainId: BigInt(chainIdNum),
|
|
640
|
-
type: txType,
|
|
641
|
-
},
|
|
642
|
-
});
|
|
643
|
-
// 再转 ERC20
|
|
644
|
-
const erc20Data = iface.encodeFunctionData('transfer', [toAddress, toSend]);
|
|
645
|
-
hopTxsToSign.push({
|
|
646
|
-
wallet: fromWallet,
|
|
647
|
-
tx: {
|
|
648
|
-
to: tokenAddress,
|
|
649
|
-
data: erc20Data,
|
|
650
|
-
value: 0n,
|
|
651
|
-
nonce: 1, // 中转钱包的第二笔交易
|
|
652
|
-
gasPrice,
|
|
653
|
-
gasLimit: erc20TransferGasLimit,
|
|
654
|
-
chainId: BigInt(chainIdNum),
|
|
655
|
-
type: txType,
|
|
656
|
-
},
|
|
657
|
-
});
|
|
658
|
-
}
|
|
659
|
-
else {
|
|
660
|
-
// 最后一个中转钱包:只转 ERC20 给最终目标
|
|
661
|
-
const erc20Data = iface.encodeFunctionData('transfer', [toAddress, toSend]);
|
|
662
|
-
hopTxsToSign.push({
|
|
663
|
-
wallet: fromWallet,
|
|
664
|
-
tx: {
|
|
665
|
-
to: tokenAddress,
|
|
666
|
-
data: erc20Data,
|
|
667
|
-
value: 0n,
|
|
668
|
-
nonce: 0, // 最后一个中转钱包只有一笔交易
|
|
669
|
-
gasPrice,
|
|
670
|
-
gasLimit: erc20TransferGasLimit,
|
|
671
|
-
chainId: BigInt(chainIdNum),
|
|
672
|
-
type: txType,
|
|
673
|
-
},
|
|
674
|
-
});
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
// ✅ 并行签名所有有跳转的交易
|
|
680
|
-
if (hopTxsToSign.length > 0) {
|
|
681
|
-
const hopSignedTxs = await Promise.all(hopTxsToSign.map(({ wallet, tx }) => wallet.signTransaction(tx)));
|
|
682
|
-
signedTxs.push(...hopSignedTxs);
|
|
683
|
-
}
|
|
684
|
-
// ========== 第7步:按地址数量收取固定费用(原生代币) ==========
|
|
685
|
-
const activeHopAddressCount = sweepAmounts.filter((a) => a > 0n).length;
|
|
686
|
-
if (extractProfit && activeHopAddressCount > 0) {
|
|
687
|
-
// ✅ 确定费用支付者:优先使用 targetWallet,否则使用归集金额最大的源钱包
|
|
688
|
-
let maxSweepIndex = -1;
|
|
689
|
-
let maxSweepAmount = 0n;
|
|
690
|
-
for (let i = 0; i < sweepAmounts.length; i++) {
|
|
691
|
-
if (sweepAmounts[i] > maxSweepAmount) {
|
|
692
|
-
maxSweepAmount = sweepAmounts[i];
|
|
693
|
-
maxSweepIndex = i;
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
const useTargetAsPayerHop = targetWallet !== null;
|
|
697
|
-
const profitPayerWalletHop = useTargetAsPayerHop
|
|
698
|
-
? targetWallet
|
|
699
|
-
: maxSweepIndex >= 0
|
|
700
|
-
? sourceWallets[maxSweepIndex]
|
|
701
|
-
: null;
|
|
702
|
-
// ✅ 按地址数量收取固定费用
|
|
703
|
-
const nativeProfitAmount = calculateTransferFee(chainIdNum, activeHopAddressCount);
|
|
704
|
-
totalProfit = nativeProfitAmount;
|
|
705
|
-
// ✅ 费用多跳转账(强制 2 跳中转)
|
|
706
|
-
if (nativeProfitAmount > 0n && profitPayerWalletHop) {
|
|
707
|
-
const profitNonce = await nonceManager.getNextNonce(profitPayerWalletHop);
|
|
708
|
-
const profitHopResult = await buildProfitHopTransactions({
|
|
709
|
-
provider,
|
|
710
|
-
payerWallet: profitPayerWalletHop,
|
|
711
|
-
profitAmount: nativeProfitAmount,
|
|
712
|
-
profitRecipient: profitAddr,
|
|
713
|
-
hopCount: PROFIT_HOP_COUNT,
|
|
714
|
-
gasPrice,
|
|
715
|
-
chainId: chainIdNum,
|
|
716
|
-
txType,
|
|
717
|
-
startNonce: profitNonce,
|
|
718
|
-
});
|
|
719
|
-
signedTxs.push(...profitHopResult.signedTransactions);
|
|
720
|
-
profitHopWallets = profitHopResult.hopWallets; // ✅ 收集费用多跳钱包
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
// ✅ 简化返回:贿赂交易放在最前面,然后是签名交易、多跳钱包和元数据
|
|
725
|
-
return {
|
|
726
|
-
signedTransactions: [...bribeSignedTx, ...signedTxs],
|
|
727
|
-
hopWallets: preparedHops || undefined,
|
|
728
|
-
profitHopWallets, // ✅ 返回利润多跳钱包
|
|
729
|
-
metadata: extractProfit
|
|
730
|
-
? {
|
|
731
|
-
totalAmount: isNative
|
|
732
|
-
? ethers.formatEther(totalAmountBeforeProfit)
|
|
733
|
-
: ethers.formatUnits(totalAmountBeforeProfit, tokenDecimals ?? 18),
|
|
734
|
-
profitAmount: ethers.formatEther(totalProfit), // ✅ 利润统一用原生代币(BNB/ETH)显示
|
|
735
|
-
profitRecipient: profitAddr,
|
|
736
|
-
sourceCount: actualKeys.length,
|
|
737
|
-
isNative,
|
|
738
|
-
tokenAddress: isNative ? undefined : tokenAddress,
|
|
739
|
-
hasBribeTx: bribeSignedTx.length > 0, // ✅ 标记是否有贿赂交易
|
|
740
|
-
bribeAmount: bribeSignedTx.length > 0 ? ethers.formatEther(bribeAmount) : undefined,
|
|
741
|
-
}
|
|
742
|
-
: undefined,
|
|
743
|
-
};
|
|
744
|
-
}
|