four-flap-meme-sdk 2.2.7 → 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 -1
- package/dist/shared/flap/constants.js +4 -3
- 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 -164
- 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 -107
- 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 -4
- package/dist/shared/flap/vanity.js +20 -13
- 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 -79
- package/dist/shared/flap/portal-create-token.js +0 -261
- 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,32 +1,180 @@
|
|
|
1
|
+
import { ethers, Wallet } from 'ethers';
|
|
2
|
+
import { getOptimizedGasPrice, NonceManager, buildProfitHopTransactions, PROFIT_HOP_COUNT } from '../../../utils/bundle-helpers.js';
|
|
3
|
+
import { ADDRESSES } from '../../../utils/constants.js';
|
|
4
|
+
import { GAS_LIMITS, PROFIT_CONFIG, calculateTransferFee } from '../../constants/index.js';
|
|
5
|
+
import { MULTICALL3_ABI, ERC20_BALANCE_ABI } from '../../abis/common.js';
|
|
6
|
+
import { getTxType, getGasPriceConfig, shouldExtractProfit, getProfitRecipient } from './config.js';
|
|
7
|
+
// ==================== 链配置 ====================
|
|
8
|
+
const CHAIN_ID_MAP = {
|
|
9
|
+
'BSC': 56,
|
|
10
|
+
'MONAD': 143,
|
|
11
|
+
'XLAYER': 196
|
|
12
|
+
};
|
|
13
|
+
// ==================== 链常量 ====================
|
|
14
|
+
// ✅ 使用公共模块
|
|
15
|
+
const MULTICALL3_ADDRESS = ADDRESSES.BSC.Multicall3;
|
|
16
|
+
// ==================== 内部辅助函数 ====================
|
|
17
|
+
const decimalsCache = new Map();
|
|
18
|
+
async function getErc20Decimals(provider, token) {
|
|
19
|
+
const network = await provider.getNetwork();
|
|
20
|
+
const key = `${network.chainId}_${token.toLowerCase()}`;
|
|
21
|
+
if (decimalsCache.has(key))
|
|
22
|
+
return decimalsCache.get(key);
|
|
23
|
+
try {
|
|
24
|
+
const erc20 = new ethers.Contract(token, ['function decimals() view returns (uint8)'], provider);
|
|
25
|
+
const d = await erc20.decimals();
|
|
26
|
+
if (!Number.isFinite(d) || d < 0 || d > 36)
|
|
27
|
+
return 18;
|
|
28
|
+
decimalsCache.set(key, d);
|
|
29
|
+
return d;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return 18;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
1
35
|
/**
|
|
2
|
-
*
|
|
36
|
+
* ✅ 生成多跳中间钱包(返回完整钱包信息:地址 + 私钥)
|
|
37
|
+
*/
|
|
38
|
+
function generateHopWallets(recipientCount, hopCount) {
|
|
39
|
+
const hopCounts = Array.isArray(hopCount) ? hopCount : new Array(recipientCount).fill(hopCount);
|
|
40
|
+
if (hopCounts.every(h => h <= 0))
|
|
41
|
+
return null;
|
|
42
|
+
const result = [];
|
|
43
|
+
for (let i = 0; i < recipientCount; i++) {
|
|
44
|
+
const chain = [];
|
|
45
|
+
for (let j = 0; j < hopCounts[i]; j++) {
|
|
46
|
+
const wallet = Wallet.createRandom();
|
|
47
|
+
chain.push({
|
|
48
|
+
address: wallet.address,
|
|
49
|
+
privateKey: wallet.privateKey
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
result.push(chain);
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
function normalizeAmounts(recipients, amount, amounts) {
|
|
57
|
+
if (amounts && amounts.length > 0) {
|
|
58
|
+
if (amounts.length !== recipients.length) {
|
|
59
|
+
throw new Error(`amounts length (${amounts.length}) must match recipients length (${recipients.length})`);
|
|
60
|
+
}
|
|
61
|
+
return amounts;
|
|
62
|
+
}
|
|
63
|
+
if (amount !== undefined && amount.trim().length > 0) {
|
|
64
|
+
return new Array(recipients.length).fill(amount);
|
|
65
|
+
}
|
|
66
|
+
throw new Error('Either amount or amounts must be provided');
|
|
67
|
+
}
|
|
68
|
+
async function batchGetBalances(provider, addresses, tokenAddress) {
|
|
69
|
+
if (addresses.length === 0)
|
|
70
|
+
return [];
|
|
71
|
+
if (!tokenAddress) {
|
|
72
|
+
return Promise.all(addresses.map(addr => provider.getBalance(addr).catch(() => 0n)));
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
// ✅ 使用公共模块
|
|
76
|
+
const multicall = new ethers.Contract(MULTICALL3_ADDRESS, MULTICALL3_ABI, provider);
|
|
77
|
+
const iface = new ethers.Interface(ERC20_BALANCE_ABI);
|
|
78
|
+
const calls = addresses.map(addr => ({
|
|
79
|
+
target: tokenAddress,
|
|
80
|
+
allowFailure: true,
|
|
81
|
+
callData: iface.encodeFunctionData('balanceOf', [addr])
|
|
82
|
+
}));
|
|
83
|
+
try {
|
|
84
|
+
const results = await multicall.aggregate3(calls);
|
|
85
|
+
return results.map((result) => {
|
|
86
|
+
if (result.success) {
|
|
87
|
+
return iface.decodeFunctionResult('balanceOf', result.returnData)[0];
|
|
88
|
+
}
|
|
89
|
+
return 0n;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
const fallbackCalls = addresses.map(addr => provider
|
|
94
|
+
.call({ to: tokenAddress, data: iface.encodeFunctionData('balanceOf', [addr]) })
|
|
95
|
+
.then(raw => iface.decodeFunctionResult('balanceOf', raw)[0])
|
|
96
|
+
.catch(() => 0n));
|
|
97
|
+
return Promise.all(fallbackCalls);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* 计算 Gas Limit
|
|
103
|
+
* - 原生代币转账:21000 gas(固定)
|
|
104
|
+
* - ERC20 标准 transfer:约 45000-55000 gas,使用 55000 作为安全值
|
|
105
|
+
*
|
|
106
|
+
* ✅ 优化:降低 ERC20 gas limit,减少中转钱包 BNB 残留
|
|
107
|
+
*/
|
|
108
|
+
function calculateGasLimit(config, isNative, hasHops, _hopCount = 0) {
|
|
109
|
+
if (config.gasLimit !== undefined) {
|
|
110
|
+
return BigInt(config.gasLimit);
|
|
111
|
+
}
|
|
112
|
+
// ✅ 原生代币: 21000, ERC20 标准 transfer: 48000(USDT 最低约 46815)
|
|
113
|
+
const baseGas = isNative ? 21000 : 48000;
|
|
114
|
+
// ✅ 多跳时每个中转钱包只执行一笔 transfer,使用较小的安全系数
|
|
115
|
+
const multiplier = config.gasLimitMultiplier ?? 1.1;
|
|
116
|
+
return BigInt(Math.ceil(baseGas * multiplier));
|
|
117
|
+
}
|
|
118
|
+
function isNativeTokenAddress(tokenAddress) {
|
|
119
|
+
if (!tokenAddress)
|
|
120
|
+
return true;
|
|
121
|
+
const v = tokenAddress.trim().toLowerCase();
|
|
122
|
+
if (!v)
|
|
123
|
+
return true;
|
|
124
|
+
if (v === 'native')
|
|
125
|
+
return true;
|
|
126
|
+
if (v === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee')
|
|
127
|
+
return true;
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
// ==================== 分散函数 ====================
|
|
131
|
+
/**
|
|
132
|
+
* Flap Protocol: 分散(仅签名版本)
|
|
133
|
+
* ✅ 支持利润提取(按地址数量收取固定费用)
|
|
134
|
+
* ✅ 支持多跳
|
|
135
|
+
* ✅ 支持 Multicall3 批量获取余额
|
|
3
136
|
*/
|
|
4
|
-
import { ethers, Wallet } from 'ethers';
|
|
5
|
-
import { getOptimizedGasPrice, NonceManager, buildProfitHopTransactions, PROFIT_HOP_COUNT, } from '../../../utils/bundle-helpers.js';
|
|
6
|
-
import { GAS_LIMITS, calculateTransferFee } from '../../constants/index.js';
|
|
7
|
-
import { CHAIN_ID_MAP, getTxType, getGasPriceConfig, shouldExtractProfit, getProfitRecipient } from './config.js';
|
|
8
|
-
import { batchGetBalances, calculateGasLimit, generateHopWallets, getErc20Decimals, isNativeTokenAddress, normalizeAmounts, } from '../../../bundle-core/internal.js';
|
|
9
|
-
import { createSignProvider, createSignWallet, normalizeItemsOrRecipientsAmounts, resolveHopCountInput, resolveProvidedHops, } from '../../../bundle-core/sign-context-helpers.js';
|
|
10
137
|
export async function flapDisperseWithBundleMerkle(params) {
|
|
11
|
-
const { chain, fromPrivateKey, recipients, amount, amounts, tokenAddress, tokenDecimals, hopCount = 0, hopPrivateKeys, items, config, startNonce
|
|
138
|
+
const { chain, fromPrivateKey, recipients, amount, amounts, tokenAddress, tokenDecimals, hopCount = 0, hopPrivateKeys, items, config, startNonce } = params;
|
|
12
139
|
if (!recipients || recipients.length === 0) {
|
|
13
140
|
return { signedTransactions: [], hopWallets: undefined };
|
|
14
141
|
}
|
|
15
142
|
const chainIdNum = CHAIN_ID_MAP[chain] ?? 56;
|
|
16
|
-
const provider =
|
|
17
|
-
const mainWallet =
|
|
143
|
+
const provider = new ethers.JsonRpcProvider(config.rpcUrl, { chainId: chainIdNum, name: chain });
|
|
144
|
+
const mainWallet = new Wallet(fromPrivateKey, provider);
|
|
18
145
|
const isNative = isNativeTokenAddress(tokenAddress);
|
|
19
146
|
const txType = getTxType(config);
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
147
|
+
// 预处理数据
|
|
148
|
+
const normalizedAmounts = items && items.length > 0
|
|
149
|
+
? items.map(it => (typeof it.amount === 'bigint' ? it.amount.toString() : String(it.amount)))
|
|
150
|
+
: normalizeAmounts(recipients, amount, amounts);
|
|
151
|
+
const providedHops = (() => {
|
|
152
|
+
if (hopPrivateKeys && hopPrivateKeys.length > 0) {
|
|
153
|
+
if (hopPrivateKeys.length !== recipients.length) {
|
|
154
|
+
throw new Error(`hopPrivateKeys length (${hopPrivateKeys.length}) must match recipients length (${recipients.length})`);
|
|
155
|
+
}
|
|
156
|
+
return hopPrivateKeys.every(h => h.length === 0) ? null : hopPrivateKeys;
|
|
157
|
+
}
|
|
158
|
+
if (items && items.length > 0) {
|
|
159
|
+
const hops = items.map(it => it.hopPrivateKeys ?? []);
|
|
160
|
+
return hops.every(h => h.length === 0) ? null : hops;
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
})();
|
|
164
|
+
const hopCountInput = (() => {
|
|
165
|
+
if (items && items.length > 0) {
|
|
166
|
+
const baseArray = Array.isArray(hopCount) ? hopCount : new Array(recipients.length).fill(hopCount);
|
|
167
|
+
return items.map((it, i) => (typeof it.hopCount === 'number' ? it.hopCount : (baseArray[i] ?? 0)));
|
|
168
|
+
}
|
|
169
|
+
return hopCount;
|
|
170
|
+
})();
|
|
23
171
|
const preparedHops = providedHops ?? generateHopWallets(recipients.length, hopCountInput);
|
|
24
172
|
const hasHops = preparedHops !== null;
|
|
25
|
-
const maxHopCount = hasHops ? Math.max(...preparedHops.map(
|
|
173
|
+
const maxHopCount = hasHops ? Math.max(...preparedHops.map(h => h.length)) : 0;
|
|
26
174
|
const finalGasLimit = calculateGasLimit(config, isNative, hasHops, maxHopCount);
|
|
27
175
|
const nativeGasLimit = GAS_LIMITS.BRIBE;
|
|
28
176
|
const signedTxs = [];
|
|
29
|
-
const extractProfit = shouldExtractProfit();
|
|
177
|
+
const extractProfit = shouldExtractProfit(config);
|
|
30
178
|
const profitAddr = getProfitRecipient();
|
|
31
179
|
let totalProfit = 0n;
|
|
32
180
|
let totalAmountBeforeProfit = 0n;
|
|
@@ -40,11 +188,12 @@ export async function flapDisperseWithBundleMerkle(params) {
|
|
|
40
188
|
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
41
189
|
startNonce !== undefined
|
|
42
190
|
? Promise.resolve(Array.from({ length: totalTxCount }, (_, i) => startNonce + i))
|
|
43
|
-
: nonceManager.getNextNonceBatch(mainWallet, totalTxCount)
|
|
191
|
+
: nonceManager.getNextNonceBatch(mainWallet, totalTxCount)
|
|
44
192
|
]);
|
|
45
193
|
// ✅ 按地址数量收取固定费用(原生代币)
|
|
46
194
|
if (extractProfit) {
|
|
47
195
|
totalProfit = calculateTransferFee(chainIdNum, recipients.length);
|
|
196
|
+
console.log(`[flap disperse] 利润按地址数量收取: ${ethers.formatEther(totalProfit)} 原生币 (${recipients.length} 地址)`);
|
|
48
197
|
}
|
|
49
198
|
if (isNative) {
|
|
50
199
|
const txDataList = recipients.map((to, i) => {
|
|
@@ -60,7 +209,7 @@ export async function flapDisperseWithBundleMerkle(params) {
|
|
|
60
209
|
gasPrice,
|
|
61
210
|
gasLimit: nativeGasLimit,
|
|
62
211
|
chainId: chainIdNum,
|
|
63
|
-
type: txType
|
|
212
|
+
type: txType
|
|
64
213
|
}));
|
|
65
214
|
signedTxs.push(...(await Promise.all(txPromises)));
|
|
66
215
|
}
|
|
@@ -82,7 +231,7 @@ export async function flapDisperseWithBundleMerkle(params) {
|
|
|
82
231
|
gasPrice,
|
|
83
232
|
gasLimit: finalGasLimit,
|
|
84
233
|
chainId: chainIdNum,
|
|
85
|
-
type: txType
|
|
234
|
+
type: txType
|
|
86
235
|
}));
|
|
87
236
|
signedTxs.push(...(await Promise.all(txPromises)));
|
|
88
237
|
}
|
|
@@ -97,7 +246,7 @@ export async function flapDisperseWithBundleMerkle(params) {
|
|
|
97
246
|
gasPrice,
|
|
98
247
|
chainId: chainIdNum,
|
|
99
248
|
txType,
|
|
100
|
-
startNonce: nonces[recipients.length]
|
|
249
|
+
startNonce: nonces[recipients.length]
|
|
101
250
|
});
|
|
102
251
|
signedTxs.push(...profitHopResult.signedTransactions);
|
|
103
252
|
profitHopWallets = profitHopResult.hopWallets;
|
|
@@ -107,9 +256,7 @@ export async function flapDisperseWithBundleMerkle(params) {
|
|
|
107
256
|
// ========== 有多跳:构建跳转链 ==========
|
|
108
257
|
const [gasPrice, decimals] = await Promise.all([
|
|
109
258
|
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
110
|
-
isNative
|
|
111
|
-
? Promise.resolve(18)
|
|
112
|
-
: Promise.resolve(tokenDecimals ?? (await getErc20Decimals(provider, tokenAddress))),
|
|
259
|
+
isNative ? Promise.resolve(18) : Promise.resolve(tokenDecimals ?? await getErc20Decimals(provider, tokenAddress))
|
|
113
260
|
]);
|
|
114
261
|
const iface = isNative ? null : new ethers.Interface(['function transfer(address,uint256) returns (bool)']);
|
|
115
262
|
const gasFeePerHop = finalGasLimit * gasPrice;
|
|
@@ -120,7 +267,7 @@ export async function flapDisperseWithBundleMerkle(params) {
|
|
|
120
267
|
mainWalletNonceCount += 1;
|
|
121
268
|
}
|
|
122
269
|
else {
|
|
123
|
-
const nonceNeed = isNative ? 1 : hopChain.length + 1;
|
|
270
|
+
const nonceNeed = isNative ? 1 : (hopChain.length + 1);
|
|
124
271
|
mainWalletNonceCount += nonceNeed;
|
|
125
272
|
}
|
|
126
273
|
}
|
|
@@ -134,6 +281,7 @@ export async function flapDisperseWithBundleMerkle(params) {
|
|
|
134
281
|
// ✅ 按地址数量收取固定费用(原生代币)
|
|
135
282
|
if (extractProfit) {
|
|
136
283
|
totalProfit = calculateTransferFee(chainIdNum, recipients.length);
|
|
284
|
+
console.log(`[flap disperse hops] 利润按地址数量收取: ${ethers.formatEther(totalProfit)} 原生币 (${recipients.length} 地址)`);
|
|
137
285
|
}
|
|
138
286
|
for (let i = 0; i < recipients.length; i++) {
|
|
139
287
|
const finalRecipient = recipients[i];
|
|
@@ -149,55 +297,27 @@ export async function flapDisperseWithBundleMerkle(params) {
|
|
|
149
297
|
if (isNative) {
|
|
150
298
|
txsToSign.push({
|
|
151
299
|
wallet: mainWallet,
|
|
152
|
-
tx: {
|
|
153
|
-
to: finalRecipient,
|
|
154
|
-
value: amountWei,
|
|
155
|
-
nonce,
|
|
156
|
-
gasPrice,
|
|
157
|
-
gasLimit: nativeGasLimit,
|
|
158
|
-
chainId: chainIdNum,
|
|
159
|
-
type: txType,
|
|
160
|
-
},
|
|
300
|
+
tx: { to: finalRecipient, value: amountWei, nonce, gasPrice, gasLimit: nativeGasLimit, chainId: chainIdNum, type: txType }
|
|
161
301
|
});
|
|
162
302
|
}
|
|
163
303
|
else {
|
|
164
304
|
const data = iface.encodeFunctionData('transfer', [finalRecipient, amountWei]);
|
|
165
305
|
txsToSign.push({
|
|
166
306
|
wallet: mainWallet,
|
|
167
|
-
tx: {
|
|
168
|
-
to: tokenAddress,
|
|
169
|
-
data,
|
|
170
|
-
value: 0n,
|
|
171
|
-
nonce,
|
|
172
|
-
gasPrice,
|
|
173
|
-
gasLimit: finalGasLimit,
|
|
174
|
-
chainId: chainIdNum,
|
|
175
|
-
type: txType,
|
|
176
|
-
},
|
|
307
|
+
tx: { to: tokenAddress, data, value: 0n, nonce, gasPrice, gasLimit: finalGasLimit, chainId: chainIdNum, type: txType }
|
|
177
308
|
});
|
|
178
309
|
}
|
|
179
310
|
continue;
|
|
180
311
|
}
|
|
181
312
|
// ✅ 支持 string 和 GeneratedWallet 两种类型
|
|
182
|
-
const fullChain = [
|
|
183
|
-
|
|
184
|
-
...hopChain.map((w) => new Wallet(typeof w === 'string' ? w : w.privateKey, provider)),
|
|
185
|
-
];
|
|
186
|
-
const addresses = [...fullChain.map((w) => w.address), finalRecipient];
|
|
313
|
+
const fullChain = [mainWallet, ...hopChain.map(w => new Wallet(typeof w === 'string' ? w : w.privateKey, provider))];
|
|
314
|
+
const addresses = [...fullChain.map(w => w.address), finalRecipient];
|
|
187
315
|
if (!isNative) {
|
|
188
316
|
for (let j = 0; j < hopChain.length; j++) {
|
|
189
317
|
const nonce = allMainNonces[mainNonceIdx++];
|
|
190
318
|
txsToSign.push({
|
|
191
319
|
wallet: mainWallet,
|
|
192
|
-
tx: {
|
|
193
|
-
to: fullChain[j + 1].address,
|
|
194
|
-
value: gasFeePerHop,
|
|
195
|
-
nonce,
|
|
196
|
-
gasPrice,
|
|
197
|
-
gasLimit: nativeGasLimit,
|
|
198
|
-
chainId: chainIdNum,
|
|
199
|
-
type: txType,
|
|
200
|
-
},
|
|
320
|
+
tx: { to: fullChain[j + 1].address, value: gasFeePerHop, nonce, gasPrice, gasLimit: nativeGasLimit, chainId: chainIdNum, type: txType }
|
|
201
321
|
});
|
|
202
322
|
}
|
|
203
323
|
}
|
|
@@ -211,31 +331,14 @@ export async function flapDisperseWithBundleMerkle(params) {
|
|
|
211
331
|
const transferValue = amountWei + additionalGas;
|
|
212
332
|
txsToSign.push({
|
|
213
333
|
wallet: fromWallet,
|
|
214
|
-
tx: {
|
|
215
|
-
to: toAddress,
|
|
216
|
-
value: transferValue,
|
|
217
|
-
nonce,
|
|
218
|
-
gasPrice,
|
|
219
|
-
gasLimit: finalGasLimit,
|
|
220
|
-
chainId: chainIdNum,
|
|
221
|
-
type: txType,
|
|
222
|
-
},
|
|
334
|
+
tx: { to: toAddress, value: transferValue, nonce, gasPrice, gasLimit: finalGasLimit, chainId: chainIdNum, type: txType }
|
|
223
335
|
});
|
|
224
336
|
}
|
|
225
337
|
else {
|
|
226
338
|
const data = iface.encodeFunctionData('transfer', [toAddress, amountWei]);
|
|
227
339
|
txsToSign.push({
|
|
228
340
|
wallet: fromWallet,
|
|
229
|
-
tx: {
|
|
230
|
-
to: tokenAddress,
|
|
231
|
-
data,
|
|
232
|
-
value: 0n,
|
|
233
|
-
nonce,
|
|
234
|
-
gasPrice,
|
|
235
|
-
gasLimit: finalGasLimit,
|
|
236
|
-
chainId: chainIdNum,
|
|
237
|
-
type: txType,
|
|
238
|
-
},
|
|
341
|
+
tx: { to: tokenAddress, data, value: 0n, nonce, gasPrice, gasLimit: finalGasLimit, chainId: chainIdNum, type: txType }
|
|
239
342
|
});
|
|
240
343
|
}
|
|
241
344
|
}
|
|
@@ -244,7 +347,7 @@ export async function flapDisperseWithBundleMerkle(params) {
|
|
|
244
347
|
signedTxs.push(...signedTxsResult);
|
|
245
348
|
// ✅ 利润多跳转账(固定费用,原生代币)
|
|
246
349
|
if (extractProfit && totalProfit > 0n) {
|
|
247
|
-
const profitNonce = allMainNonces[mainNonceIdx];
|
|
350
|
+
const profitNonce = allMainNonces[mainNonceIdx++];
|
|
248
351
|
const profitHopResult = await buildProfitHopTransactions({
|
|
249
352
|
provider,
|
|
250
353
|
payerWallet: mainWallet,
|
|
@@ -254,7 +357,7 @@ export async function flapDisperseWithBundleMerkle(params) {
|
|
|
254
357
|
gasPrice,
|
|
255
358
|
chainId: chainIdNum,
|
|
256
359
|
txType,
|
|
257
|
-
startNonce: profitNonce
|
|
360
|
+
startNonce: profitNonce
|
|
258
361
|
});
|
|
259
362
|
signedTxs.push(...profitHopResult.signedTransactions);
|
|
260
363
|
profitHopWallets = profitHopResult.hopWallets;
|
|
@@ -264,16 +367,14 @@ export async function flapDisperseWithBundleMerkle(params) {
|
|
|
264
367
|
signedTransactions: signedTxs,
|
|
265
368
|
hopWallets: preparedHops || undefined,
|
|
266
369
|
profitHopWallets, // ✅ 返回利润多跳钱包
|
|
267
|
-
metadata: extractProfit
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
: undefined,
|
|
370
|
+
metadata: extractProfit ? {
|
|
371
|
+
totalAmount: ethers.formatEther(totalAmountBeforeProfit),
|
|
372
|
+
profitAmount: ethers.formatEther(totalProfit),
|
|
373
|
+
profitRecipient: profitAddr,
|
|
374
|
+
recipientCount: recipients.length,
|
|
375
|
+
isNative,
|
|
376
|
+
tokenAddress: isNative ? undefined : tokenAddress
|
|
377
|
+
} : undefined
|
|
277
378
|
};
|
|
278
379
|
}
|
|
279
380
|
// ==================== 归集函数 ====================
|
|
@@ -285,50 +386,71 @@ export async function flapDisperseWithBundleMerkle(params) {
|
|
|
285
386
|
* ✅ 支持 Multicall3 批量获取余额
|
|
286
387
|
*/
|
|
287
388
|
export async function flapSweepWithBundleMerkle(params) {
|
|
288
|
-
const { chain, sourcePrivateKeys, target, ratioPct, ratios, amount, amounts, tokenAddress, tokenDecimals, skipIfInsufficient = true, hopCount = 0, hopPrivateKeys, sources, config
|
|
389
|
+
const { chain, sourcePrivateKeys, target, ratioPct, ratios, amount, amounts, tokenAddress, tokenDecimals, skipIfInsufficient = true, hopCount = 0, hopPrivateKeys, sources, config } = params;
|
|
289
390
|
if (!sourcePrivateKeys || sourcePrivateKeys.length === 0) {
|
|
290
391
|
return { signedTransactions: [], hopWallets: undefined };
|
|
291
392
|
}
|
|
292
393
|
const chainIdNum = CHAIN_ID_MAP[chain] ?? 56;
|
|
293
|
-
const provider =
|
|
394
|
+
const provider = new ethers.JsonRpcProvider(config.rpcUrl, { chainId: chainIdNum, name: chain });
|
|
294
395
|
const isNative = isNativeTokenAddress(tokenAddress);
|
|
295
396
|
const txType = getTxType(config);
|
|
296
|
-
const clamp = (n) => typeof n === 'number' && Number.isFinite(n)
|
|
397
|
+
const clamp = (n) => (typeof n === 'number' && Number.isFinite(n)
|
|
398
|
+
? Math.max(0, Math.min(100, Math.floor(n)))
|
|
399
|
+
: undefined);
|
|
297
400
|
const ratio = clamp(ratioPct);
|
|
298
401
|
const actualKeys = (() => {
|
|
299
402
|
if (sources && sources.length > 0)
|
|
300
|
-
return sources.map(
|
|
403
|
+
return sources.map(s => s.privateKey);
|
|
301
404
|
return sourcePrivateKeys;
|
|
302
405
|
})();
|
|
303
|
-
const providedHops =
|
|
304
|
-
|
|
406
|
+
const providedHops = (() => {
|
|
407
|
+
if (hopPrivateKeys && hopPrivateKeys.length > 0) {
|
|
408
|
+
if (hopPrivateKeys.length !== actualKeys.length) {
|
|
409
|
+
throw new Error(`hopPrivateKeys length (${hopPrivateKeys.length}) must match sourcePrivateKeys length (${actualKeys.length})`);
|
|
410
|
+
}
|
|
411
|
+
return hopPrivateKeys.every(h => h.length === 0) ? null : hopPrivateKeys;
|
|
412
|
+
}
|
|
413
|
+
if (sources && sources.length > 0) {
|
|
414
|
+
const hops = sources.map(s => s.hopPrivateKeys ?? []);
|
|
415
|
+
return hops.every(h => h.length === 0) ? null : hops;
|
|
416
|
+
}
|
|
417
|
+
return null;
|
|
418
|
+
})();
|
|
419
|
+
const hopCountInput = (() => {
|
|
420
|
+
if (sources && sources.length > 0) {
|
|
421
|
+
const baseArray = Array.isArray(hopCount) ? hopCount : new Array(actualKeys.length).fill(hopCount);
|
|
422
|
+
return sources.map((s, i) => (typeof s.hopCount === 'number' ? s.hopCount : (baseArray[i] ?? 0)));
|
|
423
|
+
}
|
|
424
|
+
return hopCount;
|
|
425
|
+
})();
|
|
305
426
|
const preparedHops = providedHops ?? generateHopWallets(actualKeys.length, hopCountInput);
|
|
306
427
|
const hasHops = preparedHops !== null;
|
|
307
|
-
const maxHopCount = hasHops ? Math.max(...preparedHops.map(
|
|
428
|
+
const maxHopCount = hasHops ? Math.max(...preparedHops.map(h => h.length)) : 0;
|
|
308
429
|
const finalGasLimit = calculateGasLimit(config, isNative, hasHops, maxHopCount);
|
|
309
430
|
const nativeGasLimit = GAS_LIMITS.BRIBE;
|
|
310
431
|
const signedTxs = [];
|
|
311
|
-
const extractProfit = shouldExtractProfit();
|
|
432
|
+
const extractProfit = shouldExtractProfit(config);
|
|
312
433
|
const profitAddr = getProfitRecipient();
|
|
313
434
|
let totalProfit = 0n;
|
|
314
435
|
let totalAmountBeforeProfit = 0n;
|
|
315
436
|
let profitHopWallets; // ✅ 收集利润多跳钱包
|
|
316
437
|
if (!preparedHops) {
|
|
317
438
|
// ========== 无多跳:直接批量归集 ==========
|
|
318
|
-
const wallets = actualKeys.map(
|
|
319
|
-
const addresses = wallets.map(
|
|
439
|
+
const wallets = actualKeys.map(pk => new Wallet(pk, provider));
|
|
440
|
+
const addresses = wallets.map(w => w.address);
|
|
320
441
|
const nonceManager = new NonceManager(provider);
|
|
321
442
|
// ✅ 按地址数量收取固定费用(原生代币)
|
|
322
443
|
if (extractProfit) {
|
|
323
444
|
totalProfit = calculateTransferFee(chainIdNum, wallets.length);
|
|
445
|
+
console.log(`[flap sweep] 利润按地址数量收取: ${ethers.formatEther(totalProfit)} 原生币 (${wallets.length} 地址)`);
|
|
324
446
|
}
|
|
325
447
|
if (isNative) {
|
|
326
448
|
const [gasPrice, balances] = await Promise.all([
|
|
327
449
|
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
328
|
-
batchGetBalances(provider, addresses)
|
|
450
|
+
batchGetBalances(provider, addresses)
|
|
329
451
|
]);
|
|
330
452
|
const gasCostBase = nativeGasLimit * gasPrice;
|
|
331
|
-
const profitTxGas =
|
|
453
|
+
const profitTxGas = PROFIT_CONFIG.HOP.GAS_LIMIT * gasPrice * BigInt(PROFIT_HOP_COUNT + 1);
|
|
332
454
|
// 第一步:计算所有钱包的归集金额,找出余额最大的钱包
|
|
333
455
|
const sweepAmounts = [];
|
|
334
456
|
let maxSweepIndex = -1;
|
|
@@ -353,7 +475,7 @@ export async function flapSweepWithBundleMerkle(params) {
|
|
|
353
475
|
const gasCost = gasCostBase;
|
|
354
476
|
if (ratioForI !== undefined) {
|
|
355
477
|
const want = (bal * BigInt(ratioForI)) / 100n;
|
|
356
|
-
const maxSendable = bal > gasCost ? bal - gasCost : 0n;
|
|
478
|
+
const maxSendable = bal > gasCost ? (bal - gasCost) : 0n;
|
|
357
479
|
toSend = want > maxSendable ? maxSendable : want;
|
|
358
480
|
}
|
|
359
481
|
else if (amountStrForI && amountStrForI.trim().length > 0) {
|
|
@@ -377,7 +499,7 @@ export async function flapSweepWithBundleMerkle(params) {
|
|
|
377
499
|
const payerNeedGas = gasCostBase + profitTxGas;
|
|
378
500
|
if (payerBalance < payerSweepAmount + payerNeedGas + totalProfit) {
|
|
379
501
|
// 余额不足支付利润,减少归集金额
|
|
380
|
-
const maxPayerSweep = payerBalance > payerNeedGas + totalProfit ? payerBalance - payerNeedGas - totalProfit : 0n;
|
|
502
|
+
const maxPayerSweep = payerBalance > (payerNeedGas + totalProfit) ? payerBalance - payerNeedGas - totalProfit : 0n;
|
|
381
503
|
sweepAmounts[maxSweepIndex] = maxPayerSweep;
|
|
382
504
|
totalAmountBeforeProfit = sweepAmounts.reduce((sum, amt) => sum + amt, 0n);
|
|
383
505
|
}
|
|
@@ -390,7 +512,9 @@ export async function flapSweepWithBundleMerkle(params) {
|
|
|
390
512
|
payerProfitNonce = nonces[1];
|
|
391
513
|
}
|
|
392
514
|
const walletsToSweep = wallets.filter((_, i) => sweepAmounts[i] > 0n && i !== maxSweepIndex);
|
|
393
|
-
const nonces = walletsToSweep.length > 0
|
|
515
|
+
const nonces = walletsToSweep.length > 0
|
|
516
|
+
? await nonceManager.getNextNoncesForWallets(walletsToSweep)
|
|
517
|
+
: [];
|
|
394
518
|
let nonceIdx = 0;
|
|
395
519
|
const txPromises = wallets.map(async (w, i) => {
|
|
396
520
|
const toSend = sweepAmounts[i];
|
|
@@ -411,11 +535,11 @@ export async function flapSweepWithBundleMerkle(params) {
|
|
|
411
535
|
gasPrice,
|
|
412
536
|
gasLimit: nativeGasLimit,
|
|
413
537
|
chainId: chainIdNum,
|
|
414
|
-
type: txType
|
|
538
|
+
type: txType
|
|
415
539
|
});
|
|
416
540
|
return mainTx;
|
|
417
541
|
});
|
|
418
|
-
const allTxs = (await Promise.all(txPromises)).filter(
|
|
542
|
+
const allTxs = (await Promise.all(txPromises)).filter(tx => tx !== null);
|
|
419
543
|
signedTxs.push(...allTxs);
|
|
420
544
|
// ✅ 利润多跳转账(固定费用,原生代币)
|
|
421
545
|
if (extractProfit && totalProfit > 0n && maxSweepIndex >= 0 && payerProfitNonce !== undefined) {
|
|
@@ -429,7 +553,7 @@ export async function flapSweepWithBundleMerkle(params) {
|
|
|
429
553
|
gasPrice,
|
|
430
554
|
chainId: chainIdNum,
|
|
431
555
|
txType,
|
|
432
|
-
startNonce: payerProfitNonce
|
|
556
|
+
startNonce: payerProfitNonce
|
|
433
557
|
});
|
|
434
558
|
signedTxs.push(...profitHopResult.signedTransactions);
|
|
435
559
|
profitHopWallets = profitHopResult.hopWallets;
|
|
@@ -439,12 +563,12 @@ export async function flapSweepWithBundleMerkle(params) {
|
|
|
439
563
|
// ERC20 归集
|
|
440
564
|
const [gasPrice, decimals, balances, nativeBalances] = await Promise.all([
|
|
441
565
|
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
442
|
-
Promise.resolve(tokenDecimals ??
|
|
566
|
+
Promise.resolve(tokenDecimals ?? await getErc20Decimals(provider, tokenAddress)),
|
|
443
567
|
batchGetBalances(provider, addresses, tokenAddress),
|
|
444
|
-
batchGetBalances(provider, addresses)
|
|
568
|
+
batchGetBalances(provider, addresses)
|
|
445
569
|
]);
|
|
446
570
|
const iface = new ethers.Interface(['function transfer(address,uint256) returns (bool)']);
|
|
447
|
-
const profitTxGas =
|
|
571
|
+
const profitTxGas = PROFIT_CONFIG.HOP.GAS_LIMIT * gasPrice * BigInt(PROFIT_HOP_COUNT + 1);
|
|
448
572
|
const sweepAmounts = [];
|
|
449
573
|
let maxSweepIndex = -1;
|
|
450
574
|
let maxSweepAmount = 0n;
|
|
@@ -505,7 +629,9 @@ export async function flapSweepWithBundleMerkle(params) {
|
|
|
505
629
|
payerProfitNonce = nonces[1];
|
|
506
630
|
}
|
|
507
631
|
const walletsToSweepErc20 = wallets.filter((_, i) => sweepAmounts[i] > 0n && i !== maxSweepIndex);
|
|
508
|
-
const noncesErc20 = walletsToSweepErc20.length > 0
|
|
632
|
+
const noncesErc20 = walletsToSweepErc20.length > 0
|
|
633
|
+
? await nonceManager.getNextNoncesForWallets(walletsToSweepErc20)
|
|
634
|
+
: [];
|
|
509
635
|
let nonceIdxErc20 = 0;
|
|
510
636
|
const txPromises = wallets.map(async (w, i) => {
|
|
511
637
|
const toSend = sweepAmounts[i];
|
|
@@ -528,11 +654,11 @@ export async function flapSweepWithBundleMerkle(params) {
|
|
|
528
654
|
gasPrice,
|
|
529
655
|
gasLimit: finalGasLimit,
|
|
530
656
|
chainId: chainIdNum,
|
|
531
|
-
type: txType
|
|
657
|
+
type: txType
|
|
532
658
|
});
|
|
533
659
|
return mainTx;
|
|
534
660
|
});
|
|
535
|
-
const allTxs = (await Promise.all(txPromises)).filter(
|
|
661
|
+
const allTxs = (await Promise.all(txPromises)).filter(tx => tx !== null);
|
|
536
662
|
signedTxs.push(...allTxs);
|
|
537
663
|
// ✅ 利润多跳转账(固定费用,原生代币)
|
|
538
664
|
if (extractProfit && totalProfit > 0n && maxSweepIndex >= 0 && payerProfitNonce !== undefined) {
|
|
@@ -546,7 +672,7 @@ export async function flapSweepWithBundleMerkle(params) {
|
|
|
546
672
|
gasPrice,
|
|
547
673
|
chainId: chainIdNum,
|
|
548
674
|
txType,
|
|
549
|
-
startNonce: payerProfitNonce
|
|
675
|
+
startNonce: payerProfitNonce
|
|
550
676
|
});
|
|
551
677
|
signedTxs.push(...profitHopResult.signedTransactions);
|
|
552
678
|
profitHopWallets = profitHopResult.hopWallets;
|
|
@@ -555,10 +681,11 @@ export async function flapSweepWithBundleMerkle(params) {
|
|
|
555
681
|
}
|
|
556
682
|
else {
|
|
557
683
|
// ========== 有多跳:构建跳转链归集 ==========
|
|
558
|
-
const sourceWallets = actualKeys.map(
|
|
684
|
+
const sourceWallets = actualKeys.map(pk => new Wallet(pk, provider));
|
|
559
685
|
// ✅ 按地址数量收取固定费用(原生代币)
|
|
560
686
|
if (extractProfit) {
|
|
561
687
|
totalProfit = calculateTransferFee(chainIdNum, sourceWallets.length);
|
|
688
|
+
console.log(`[flap sweep hops] 利润按地址数量收取: ${ethers.formatEther(totalProfit)} 原生币 (${sourceWallets.length} 地址)`);
|
|
562
689
|
}
|
|
563
690
|
const withHopIndexes = [];
|
|
564
691
|
const withoutHopIndexes = [];
|
|
@@ -570,14 +697,12 @@ export async function flapSweepWithBundleMerkle(params) {
|
|
|
570
697
|
withoutHopIndexes.push(i);
|
|
571
698
|
}
|
|
572
699
|
}
|
|
573
|
-
const sourceAddresses = sourceWallets.map(
|
|
700
|
+
const sourceAddresses = sourceWallets.map(w => w.address);
|
|
574
701
|
const [gasPrice, decimals, balances, nativeBalances] = await Promise.all([
|
|
575
702
|
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
576
|
-
isNative
|
|
577
|
-
? Promise.resolve(18)
|
|
578
|
-
: Promise.resolve(tokenDecimals ?? (await getErc20Decimals(provider, tokenAddress))),
|
|
703
|
+
isNative ? Promise.resolve(18) : Promise.resolve(tokenDecimals ?? await getErc20Decimals(provider, tokenAddress)),
|
|
579
704
|
batchGetBalances(provider, sourceAddresses, tokenAddress),
|
|
580
|
-
isNative ? Promise.resolve([]) : batchGetBalances(provider, sourceAddresses)
|
|
705
|
+
isNative ? Promise.resolve([]) : batchGetBalances(provider, sourceAddresses)
|
|
581
706
|
]);
|
|
582
707
|
const iface = isNative ? null : new ethers.Interface(['function transfer(address,uint256) returns (bool)']);
|
|
583
708
|
const gasFeePerHop = finalGasLimit * gasPrice;
|
|
@@ -606,7 +731,7 @@ export async function flapSweepWithBundleMerkle(params) {
|
|
|
606
731
|
})();
|
|
607
732
|
if (ratioForI !== undefined) {
|
|
608
733
|
const want = (bal * BigInt(ratioForI)) / 100n;
|
|
609
|
-
const maxSendable = bal > gasCost ? bal - gasCost : 0n;
|
|
734
|
+
const maxSendable = bal > gasCost ? (bal - gasCost) : 0n;
|
|
610
735
|
toSend = want > maxSendable ? maxSendable : want;
|
|
611
736
|
}
|
|
612
737
|
else if (amountStrForI && amountStrForI.trim().length > 0) {
|
|
@@ -626,7 +751,7 @@ export async function flapSweepWithBundleMerkle(params) {
|
|
|
626
751
|
gasPrice,
|
|
627
752
|
gasLimit: nativeGasLimit,
|
|
628
753
|
chainId: chainIdNum,
|
|
629
|
-
type: txType
|
|
754
|
+
type: txType
|
|
630
755
|
});
|
|
631
756
|
signedTxs.push(tx);
|
|
632
757
|
}
|
|
@@ -665,7 +790,7 @@ export async function flapSweepWithBundleMerkle(params) {
|
|
|
665
790
|
gasPrice,
|
|
666
791
|
gasLimit: finalGasLimit,
|
|
667
792
|
chainId: chainIdNum,
|
|
668
|
-
type: txType
|
|
793
|
+
type: txType
|
|
669
794
|
});
|
|
670
795
|
signedTxs.push(tx);
|
|
671
796
|
}
|
|
@@ -695,7 +820,7 @@ export async function flapSweepWithBundleMerkle(params) {
|
|
|
695
820
|
})();
|
|
696
821
|
if (ratioForI !== undefined) {
|
|
697
822
|
const want = (bal * BigInt(ratioForI)) / 100n;
|
|
698
|
-
const maxSendable = bal > totalGasCost ? bal - totalGasCost : 0n;
|
|
823
|
+
const maxSendable = bal > totalGasCost ? (bal - totalGasCost) : 0n;
|
|
699
824
|
toSend = want > maxSendable ? maxSendable : want;
|
|
700
825
|
}
|
|
701
826
|
else if (amountStrForI && amountStrForI.trim().length > 0) {
|
|
@@ -707,7 +832,7 @@ export async function flapSweepWithBundleMerkle(params) {
|
|
|
707
832
|
}
|
|
708
833
|
else {
|
|
709
834
|
const nativeBal = nativeBalances[i];
|
|
710
|
-
const nativeNeeded = gasFeePerHop * BigInt(hopChain.length) + finalGasLimit * gasPrice;
|
|
835
|
+
const nativeNeeded = (gasFeePerHop * BigInt(hopChain.length)) + (finalGasLimit * gasPrice);
|
|
711
836
|
if (nativeBal < nativeNeeded && skipIfInsufficient)
|
|
712
837
|
continue;
|
|
713
838
|
const ratioForI = (() => {
|
|
@@ -738,11 +863,8 @@ export async function flapSweepWithBundleMerkle(params) {
|
|
|
738
863
|
sweepAmounts[i] = toSend;
|
|
739
864
|
totalAmountBeforeProfit += toSend;
|
|
740
865
|
// ✅ 支持 string 和 GeneratedWallet 两种类型
|
|
741
|
-
const fullChain = [
|
|
742
|
-
|
|
743
|
-
...hopChain.map((w) => new Wallet(typeof w === 'string' ? w : w.privateKey, provider)),
|
|
744
|
-
];
|
|
745
|
-
const addresses = [...fullChain.map((w) => w.address), target];
|
|
866
|
+
const fullChain = [sourceWallet, ...hopChain.map(w => new Wallet(typeof w === 'string' ? w : w.privateKey, provider))];
|
|
867
|
+
const addresses = [...fullChain.map(w => w.address), target];
|
|
746
868
|
if (!isNative) {
|
|
747
869
|
const gasNonces = await nonceManager.getNextNonceBatch(sourceWallet, hopChain.length);
|
|
748
870
|
for (let j = 0; j < hopChain.length; j++) {
|
|
@@ -753,7 +875,7 @@ export async function flapSweepWithBundleMerkle(params) {
|
|
|
753
875
|
gasPrice,
|
|
754
876
|
gasLimit: nativeGasLimit,
|
|
755
877
|
chainId: chainIdNum,
|
|
756
|
-
type: txType
|
|
878
|
+
type: txType
|
|
757
879
|
});
|
|
758
880
|
signedTxs.push(tx);
|
|
759
881
|
}
|
|
@@ -761,7 +883,9 @@ export async function flapSweepWithBundleMerkle(params) {
|
|
|
761
883
|
for (let j = 0; j < addresses.length - 1; j++) {
|
|
762
884
|
const fromWallet = fullChain[j];
|
|
763
885
|
const toAddress = addresses[j + 1];
|
|
764
|
-
const nonce = j === 0
|
|
886
|
+
const nonce = j === 0
|
|
887
|
+
? await nonceManager.getNextNonce(sourceWallet)
|
|
888
|
+
: 0;
|
|
765
889
|
if (isNative) {
|
|
766
890
|
const remainingHops = addresses.length - 2 - j;
|
|
767
891
|
const additionalGas = gasFeePerHop * BigInt(remainingHops);
|
|
@@ -773,7 +897,7 @@ export async function flapSweepWithBundleMerkle(params) {
|
|
|
773
897
|
gasPrice,
|
|
774
898
|
gasLimit: finalGasLimit,
|
|
775
899
|
chainId: chainIdNum,
|
|
776
|
-
type: txType
|
|
900
|
+
type: txType
|
|
777
901
|
});
|
|
778
902
|
signedTxs.push(tx);
|
|
779
903
|
}
|
|
@@ -787,7 +911,7 @@ export async function flapSweepWithBundleMerkle(params) {
|
|
|
787
911
|
gasPrice,
|
|
788
912
|
gasLimit: finalGasLimit,
|
|
789
913
|
chainId: chainIdNum,
|
|
790
|
-
type: txType
|
|
914
|
+
type: txType
|
|
791
915
|
});
|
|
792
916
|
signedTxs.push(tx);
|
|
793
917
|
}
|
|
@@ -816,7 +940,7 @@ export async function flapSweepWithBundleMerkle(params) {
|
|
|
816
940
|
gasPrice,
|
|
817
941
|
chainId: chainIdNum,
|
|
818
942
|
txType,
|
|
819
|
-
startNonce: profitNonce
|
|
943
|
+
startNonce: profitNonce
|
|
820
944
|
});
|
|
821
945
|
signedTxs.push(...profitHopResult.signedTransactions);
|
|
822
946
|
profitHopWallets = profitHopResult.hopWallets;
|
|
@@ -827,17 +951,13 @@ export async function flapSweepWithBundleMerkle(params) {
|
|
|
827
951
|
signedTransactions: signedTxs,
|
|
828
952
|
hopWallets: preparedHops || undefined,
|
|
829
953
|
profitHopWallets, // ✅ 返回利润多跳钱包
|
|
830
|
-
metadata: extractProfit
|
|
831
|
-
?
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
isNative,
|
|
839
|
-
tokenAddress: isNative ? undefined : tokenAddress,
|
|
840
|
-
}
|
|
841
|
-
: undefined,
|
|
954
|
+
metadata: extractProfit ? {
|
|
955
|
+
totalAmount: isNative ? ethers.formatEther(totalAmountBeforeProfit) : ethers.formatUnits(totalAmountBeforeProfit, tokenDecimals ?? 18),
|
|
956
|
+
profitAmount: ethers.formatEther(totalProfit),
|
|
957
|
+
profitRecipient: profitAddr,
|
|
958
|
+
sourceCount: actualKeys.length,
|
|
959
|
+
isNative,
|
|
960
|
+
tokenAddress: isNative ? undefined : tokenAddress
|
|
961
|
+
} : undefined
|
|
842
962
|
};
|
|
843
963
|
}
|