four-flap-meme-sdk 2.2.1 → 2.2.2
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 +85 -20
- package/dist/index.js +215 -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 +252 -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 +3 -2
- 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 +3 -3
- package/dist/shared/flap/index.js +3 -3
- 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 +172 -92
- package/dist/shared/flap/portal-bundle-merkle/create-to-dex.d.ts +1 -2
- package/dist/shared/flap/portal-bundle-merkle/create-to-dex.js +99 -106
- 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 +7 -73
- 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 -1
- package/dist/shared/flap/portal.js +25 -32
- package/dist/shared/flap/vanity.d.ts +5 -1
- package/dist/shared/flap/vanity.js +17 -6
- package/dist/shared/flap/vault.d.ts +124 -17
- package/dist/shared/flap/vault.js +148 -67
- 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 -260
- 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/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,4 +1,768 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Four.meme
|
|
2
|
+
* Four.meme 内盘捆绑换手(Merkle Bundle)
|
|
3
|
+
*
|
|
4
|
+
* 功能:钱包A卖出代币 → 钱包B买入相同数量 → 原子执行
|
|
3
5
|
*/
|
|
4
|
-
|
|
6
|
+
import { ethers, Contract, Wallet } from 'ethers';
|
|
7
|
+
import { calculateSellAmount } from '../../../utils/swap-helpers.js';
|
|
8
|
+
import { NonceManager, getOptimizedGasPrice, getGasLimit, getGasPriceConfig, getTxType, buildProfitHopTransactions, PROFIT_HOP_COUNT } from '../../../utils/bundle-helpers.js';
|
|
9
|
+
import { ADDRESSES, PROFIT_CONFIG, BLOCKRAZOR_BUILDER_EOA } from '../../../utils/constants.js';
|
|
10
|
+
import { GAS_LIMITS } from '../../../shared/constants/index.js';
|
|
11
|
+
/**
|
|
12
|
+
* 根据 userType 计算利润率
|
|
13
|
+
*/
|
|
14
|
+
function getProfitRateBps(userType) {
|
|
15
|
+
if (userType === 'v0') {
|
|
16
|
+
return PROFIT_CONFIG.RATE_BPS_V0; // 0.06%
|
|
17
|
+
}
|
|
18
|
+
else if (userType === 'v1') {
|
|
19
|
+
return PROFIT_CONFIG.RATE_BPS_V1; // 0.05%
|
|
20
|
+
}
|
|
21
|
+
return PROFIT_CONFIG.RATE_BPS_V0; // 默认 0.06%
|
|
22
|
+
}
|
|
23
|
+
import { TM_ABI, HELPER3_ABI, TM_ADDRESS } from './swap-internal.js';
|
|
24
|
+
import { getBribeAmount, getProfitRecipient } from './config.js';
|
|
25
|
+
import { generateWallets } from '../../../utils/wallet.js';
|
|
26
|
+
// ==================== 多跳转账常量(使用统一常量) ====================
|
|
27
|
+
const NATIVE_TRANSFER_GAS_LIMIT = GAS_LIMITS.NATIVE_TRANSFER;
|
|
28
|
+
const BRIBE_GAS_LIMIT = GAS_LIMITS.BRIBE;
|
|
29
|
+
/**
|
|
30
|
+
* 生成分发多跳路径
|
|
31
|
+
*/
|
|
32
|
+
function generateDisperseHopPaths(targetAddresses, hopCount, provider) {
|
|
33
|
+
if (hopCount <= 0) {
|
|
34
|
+
return targetAddresses.map(addr => ({
|
|
35
|
+
targetAddress: addr,
|
|
36
|
+
hopWallets: [],
|
|
37
|
+
hopWalletsInfo: []
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
return targetAddresses.map(targetAddress => {
|
|
41
|
+
const hopWalletsInfo = generateWallets(hopCount);
|
|
42
|
+
const hopWallets = hopWalletsInfo.map(w => new Wallet(w.privateKey, provider));
|
|
43
|
+
return { targetAddress, hopWallets, hopWalletsInfo };
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 构建原生代币多跳转账链
|
|
48
|
+
*/
|
|
49
|
+
async function buildNativeHopChain(payer, path, finalAmount, gasPrice, chainId, txType, payerNonce) {
|
|
50
|
+
const signedTxs = [];
|
|
51
|
+
const hopCount = path.hopWallets.length;
|
|
52
|
+
if (hopCount === 0) {
|
|
53
|
+
const tx = {
|
|
54
|
+
to: path.targetAddress,
|
|
55
|
+
value: finalAmount,
|
|
56
|
+
nonce: payerNonce,
|
|
57
|
+
gasLimit: NATIVE_TRANSFER_GAS_LIMIT,
|
|
58
|
+
gasPrice,
|
|
59
|
+
chainId,
|
|
60
|
+
type: txType
|
|
61
|
+
};
|
|
62
|
+
signedTxs.push(await payer.signTransaction(tx));
|
|
63
|
+
return signedTxs;
|
|
64
|
+
}
|
|
65
|
+
const hopGasCost = NATIVE_TRANSFER_GAS_LIMIT * gasPrice;
|
|
66
|
+
// 计算每跳需要的金额
|
|
67
|
+
const amountsPerHop = [];
|
|
68
|
+
for (let i = 0; i < hopCount; i++) {
|
|
69
|
+
const remainingHops = hopCount - i;
|
|
70
|
+
amountsPerHop.push(finalAmount + hopGasCost * BigInt(remainingHops));
|
|
71
|
+
}
|
|
72
|
+
// payer → hop1
|
|
73
|
+
signedTxs.push(await payer.signTransaction({
|
|
74
|
+
to: path.hopWallets[0].address,
|
|
75
|
+
value: amountsPerHop[0],
|
|
76
|
+
nonce: payerNonce,
|
|
77
|
+
gasLimit: NATIVE_TRANSFER_GAS_LIMIT,
|
|
78
|
+
gasPrice,
|
|
79
|
+
chainId,
|
|
80
|
+
type: txType
|
|
81
|
+
}));
|
|
82
|
+
// hop1 → hop2 → ... → target
|
|
83
|
+
for (let i = 0; i < hopCount; i++) {
|
|
84
|
+
const fromWallet = path.hopWallets[i];
|
|
85
|
+
const toAddress = i === hopCount - 1 ? path.targetAddress : path.hopWallets[i + 1].address;
|
|
86
|
+
const amount = i === hopCount - 1 ? finalAmount : amountsPerHop[i + 1];
|
|
87
|
+
signedTxs.push(await fromWallet.signTransaction({
|
|
88
|
+
to: toAddress,
|
|
89
|
+
value: amount,
|
|
90
|
+
nonce: 0,
|
|
91
|
+
gasLimit: NATIVE_TRANSFER_GAS_LIMIT,
|
|
92
|
+
gasPrice,
|
|
93
|
+
chainId,
|
|
94
|
+
type: txType
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
return signedTxs;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Four内盘捆绑换手
|
|
101
|
+
*/
|
|
102
|
+
export async function fourBundleSwapMerkle(params) {
|
|
103
|
+
const { sellerPrivateKey, sellAmount, sellPercentage, buyerPrivateKey, tokenAddress, config, startNonces // ✅ 可选:前端预获取的 nonces
|
|
104
|
+
} = params;
|
|
105
|
+
const chainIdNum = config.chainId ?? 56;
|
|
106
|
+
const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
|
|
107
|
+
chainId: chainIdNum,
|
|
108
|
+
name: 'BSC'
|
|
109
|
+
});
|
|
110
|
+
const seller = new Wallet(sellerPrivateKey, provider);
|
|
111
|
+
const buyer = new Wallet(buyerPrivateKey, provider);
|
|
112
|
+
const nonceManager = new NonceManager(provider);
|
|
113
|
+
// ✅ 创建适配的配置对象
|
|
114
|
+
const bundleConfig = {
|
|
115
|
+
minGasPriceGwei: config.minGasPriceGwei,
|
|
116
|
+
maxGasPriceGwei: config.maxGasPriceGwei,
|
|
117
|
+
gasLimit: typeof config.gasLimit === 'bigint' ? Number(config.gasLimit) : config.gasLimit,
|
|
118
|
+
gasLimitMultiplier: config.gasLimitMultiplier,
|
|
119
|
+
txType: config.txType,
|
|
120
|
+
chainId: config.chainId
|
|
121
|
+
};
|
|
122
|
+
const finalGasLimit = getGasLimit(bundleConfig);
|
|
123
|
+
const txType = getTxType(bundleConfig);
|
|
124
|
+
// ✅ 优化:第一批并行 - calculateSellAmount、gasPrice
|
|
125
|
+
const [sellAmountResult, gasPrice] = await Promise.all([
|
|
126
|
+
calculateSellAmount(provider, tokenAddress, seller.address, sellAmount, sellPercentage),
|
|
127
|
+
getOptimizedGasPrice(provider, getGasPriceConfig(bundleConfig))
|
|
128
|
+
]);
|
|
129
|
+
const { amount: sellAmountWei, decimals } = sellAmountResult;
|
|
130
|
+
// ✅ 优化:第二批并行 - sellQuote、allowance、buyerBalance
|
|
131
|
+
const helper3 = new Contract(ADDRESSES.BSC.TokenManagerHelper3, HELPER3_ABI, provider);
|
|
132
|
+
const erc20Contract = new Contract(tokenAddress, ['function allowance(address,address) view returns (uint256)'], provider);
|
|
133
|
+
const [sellQuote, currentAllowance, buyerBalance] = await Promise.all([
|
|
134
|
+
helper3.trySell(tokenAddress, sellAmountWei),
|
|
135
|
+
erc20Contract.allowance(seller.address, TM_ADDRESS),
|
|
136
|
+
provider.getBalance(buyer.address)
|
|
137
|
+
]);
|
|
138
|
+
const sellerWillGetBNB = sellQuote.funds;
|
|
139
|
+
const buyerFunds = sellerWillGetBNB;
|
|
140
|
+
// 验证买方余额
|
|
141
|
+
const reserveGas = ethers.parseEther((config.reserveGasBNB || 0.0005).toString());
|
|
142
|
+
const requiredBalance = buyerFunds + reserveGas;
|
|
143
|
+
if (buyerBalance < requiredBalance) {
|
|
144
|
+
throw new Error(`买方余额不足:\n` +
|
|
145
|
+
` - 需要: ${ethers.formatEther(requiredBalance)} BNB\n` +
|
|
146
|
+
` - 实际: ${ethers.formatEther(buyerBalance)} BNB`);
|
|
147
|
+
}
|
|
148
|
+
// 检查是否需要授权
|
|
149
|
+
const APPROVAL_THRESHOLD = ethers.parseUnits('1000000000', decimals);
|
|
150
|
+
const needApproval = currentAllowance < APPROVAL_THRESHOLD;
|
|
151
|
+
// 利润配置
|
|
152
|
+
const extractProfit = true;
|
|
153
|
+
const profitRateBps = getProfitRateBps(config.userType);
|
|
154
|
+
const profitAmount = extractProfit && sellerWillGetBNB > 0n
|
|
155
|
+
? (sellerWillGetBNB * BigInt(profitRateBps)) / 10000n
|
|
156
|
+
: 0n;
|
|
157
|
+
// ✅ 获取贿赂金额
|
|
158
|
+
const bribeAmount = getBribeAmount(config);
|
|
159
|
+
const needBribeTx = bribeAmount > 0n;
|
|
160
|
+
// ✅ 优化:第三批并行 - 构建交易、获取 nonces
|
|
161
|
+
const tmSeller = new Contract(TM_ADDRESS, TM_ABI, seller);
|
|
162
|
+
const tmBuyer = new Contract(TM_ADDRESS, TM_ABI, buyer);
|
|
163
|
+
// 计算需要的 nonce 数量
|
|
164
|
+
let sellerNonceCount = 1; // 卖出交易
|
|
165
|
+
if (needBribeTx)
|
|
166
|
+
sellerNonceCount++; // 贿赂交易
|
|
167
|
+
if (needApproval)
|
|
168
|
+
sellerNonceCount++; // 授权交易
|
|
169
|
+
if (extractProfit)
|
|
170
|
+
sellerNonceCount++; // 利润交易
|
|
171
|
+
// ✅ 优化:使用批量 nonce 获取(JSON-RPC 批量请求)
|
|
172
|
+
// 如果前端传入了 startNonces,直接使用;否则从链上获取
|
|
173
|
+
const [sellUnsigned, buyUnsigned, noncesResult] = await Promise.all([
|
|
174
|
+
tmSeller.sellToken.populateTransaction(0n, tokenAddress, sellAmountWei, 0n),
|
|
175
|
+
tmBuyer.buyTokenAMAP.populateTransaction(0n, tokenAddress, buyer.address, buyerFunds, 0n, { value: buyerFunds }),
|
|
176
|
+
(async () => {
|
|
177
|
+
// ✅ 如果前端传入了 startNonces,直接使用(性能优化)
|
|
178
|
+
if (startNonces && startNonces.length >= 2) {
|
|
179
|
+
const sellerNonces = Array.from({ length: sellerNonceCount }, (_, i) => startNonces[0] + i);
|
|
180
|
+
const buyerNonce = startNonces[1];
|
|
181
|
+
return { sellerNonces, buyerNonce };
|
|
182
|
+
}
|
|
183
|
+
// 否则从链上获取
|
|
184
|
+
const initialNonces = await nonceManager.getNextNoncesForWallets([seller, buyer]);
|
|
185
|
+
const sellerNonces = Array.from({ length: sellerNonceCount }, (_, i) => initialNonces[0] + i);
|
|
186
|
+
const buyerNonce = initialNonces[1];
|
|
187
|
+
return { sellerNonces, buyerNonce };
|
|
188
|
+
})()
|
|
189
|
+
]);
|
|
190
|
+
const { sellerNonces, buyerNonce } = noncesResult;
|
|
191
|
+
// 分配 nonces
|
|
192
|
+
let idx = 0;
|
|
193
|
+
let bribeNonce;
|
|
194
|
+
let approvalNonce;
|
|
195
|
+
if (needBribeTx)
|
|
196
|
+
bribeNonce = sellerNonces[idx++];
|
|
197
|
+
if (needApproval)
|
|
198
|
+
approvalNonce = sellerNonces[idx++];
|
|
199
|
+
const sellerNonce = sellerNonces[idx++];
|
|
200
|
+
const profitNonce = extractProfit ? sellerNonces[idx] : undefined;
|
|
201
|
+
// ✅ 并行签名所有交易
|
|
202
|
+
const signPromises = [];
|
|
203
|
+
// ✅ 贿赂交易放在首位
|
|
204
|
+
if (needBribeTx && bribeNonce !== undefined) {
|
|
205
|
+
signPromises.push(seller.signTransaction({
|
|
206
|
+
to: BLOCKRAZOR_BUILDER_EOA,
|
|
207
|
+
value: bribeAmount,
|
|
208
|
+
nonce: bribeNonce,
|
|
209
|
+
gasPrice,
|
|
210
|
+
gasLimit: BRIBE_GAS_LIMIT,
|
|
211
|
+
chainId: chainIdNum,
|
|
212
|
+
type: txType
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
// 授权交易
|
|
216
|
+
if (needApproval && approvalNonce !== undefined) {
|
|
217
|
+
const approveInterface = new ethers.Interface(['function approve(address,uint256) returns (bool)']);
|
|
218
|
+
const approveData = approveInterface.encodeFunctionData('approve', [TM_ADDRESS, ethers.MaxUint256]);
|
|
219
|
+
signPromises.push(seller.signTransaction({
|
|
220
|
+
to: tokenAddress,
|
|
221
|
+
data: approveData,
|
|
222
|
+
value: 0n,
|
|
223
|
+
nonce: approvalNonce,
|
|
224
|
+
gasLimit: 80000n,
|
|
225
|
+
gasPrice,
|
|
226
|
+
chainId: chainIdNum,
|
|
227
|
+
type: txType
|
|
228
|
+
}));
|
|
229
|
+
}
|
|
230
|
+
// 卖出和买入交易
|
|
231
|
+
signPromises.push(seller.signTransaction({
|
|
232
|
+
...sellUnsigned,
|
|
233
|
+
from: seller.address,
|
|
234
|
+
nonce: sellerNonce,
|
|
235
|
+
gasLimit: finalGasLimit,
|
|
236
|
+
gasPrice,
|
|
237
|
+
chainId: chainIdNum,
|
|
238
|
+
type: txType
|
|
239
|
+
}), buyer.signTransaction({
|
|
240
|
+
...buyUnsigned,
|
|
241
|
+
from: buyer.address,
|
|
242
|
+
nonce: buyerNonce,
|
|
243
|
+
gasLimit: finalGasLimit,
|
|
244
|
+
gasPrice,
|
|
245
|
+
chainId: chainIdNum,
|
|
246
|
+
type: txType,
|
|
247
|
+
value: buyerFunds
|
|
248
|
+
}));
|
|
249
|
+
const signedTxs = await Promise.all(signPromises);
|
|
250
|
+
// 解析签名结果
|
|
251
|
+
let signIdx = 0;
|
|
252
|
+
let bribeTx = null;
|
|
253
|
+
let approvalTx = null;
|
|
254
|
+
if (needBribeTx)
|
|
255
|
+
bribeTx = signedTxs[signIdx++];
|
|
256
|
+
if (needApproval)
|
|
257
|
+
approvalTx = signedTxs[signIdx++];
|
|
258
|
+
const signedSell = signedTxs[signIdx++];
|
|
259
|
+
const signedBuy = signedTxs[signIdx++];
|
|
260
|
+
nonceManager.clearTemp();
|
|
261
|
+
// ✅ 组装交易列表:贿赂 → 授权 → 卖出 → 买入
|
|
262
|
+
const allTransactions = [];
|
|
263
|
+
if (bribeTx)
|
|
264
|
+
allTransactions.push(bribeTx);
|
|
265
|
+
if (approvalTx)
|
|
266
|
+
allTransactions.push(approvalTx);
|
|
267
|
+
allTransactions.push(signedSell, signedBuy);
|
|
268
|
+
// ✅ 利润多跳转账(强制 2 跳中转)
|
|
269
|
+
let profitHopWallets;
|
|
270
|
+
if (extractProfit && profitAmount > 0n && profitNonce !== undefined) {
|
|
271
|
+
const profitHopResult = await buildProfitHopTransactions({
|
|
272
|
+
provider,
|
|
273
|
+
payerWallet: seller,
|
|
274
|
+
profitAmount: profitAmount,
|
|
275
|
+
profitRecipient: getProfitRecipient(),
|
|
276
|
+
hopCount: PROFIT_HOP_COUNT,
|
|
277
|
+
gasPrice,
|
|
278
|
+
chainId: chainIdNum,
|
|
279
|
+
txType,
|
|
280
|
+
startNonce: profitNonce
|
|
281
|
+
});
|
|
282
|
+
allTransactions.push(...profitHopResult.signedTransactions);
|
|
283
|
+
profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
signedTransactions: allTransactions,
|
|
287
|
+
profitHopWallets, // ✅ 导出利润多跳钱包
|
|
288
|
+
metadata: {
|
|
289
|
+
sellerAddress: seller.address,
|
|
290
|
+
buyerAddress: buyer.address,
|
|
291
|
+
sellAmount: ethers.formatUnits(sellAmountWei, decimals),
|
|
292
|
+
buyAmount: ethers.formatEther(buyerFunds),
|
|
293
|
+
hasApproval: !!approvalTx,
|
|
294
|
+
profitAmount: extractProfit ? ethers.formatEther(profitAmount) : undefined
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Four 内盘批量换手(一卖多买)
|
|
300
|
+
*
|
|
301
|
+
* 功能:主钱包一次卖出 → 多个子钱包同时买入 → 在同一个区块中完成
|
|
302
|
+
* 限制:最多 24 个买方(服务器限制 25 笔交易,包含 1 笔利润交易)
|
|
303
|
+
*/
|
|
304
|
+
export async function fourBatchSwapMerkle(params) {
|
|
305
|
+
const { sellerPrivateKey, sellAmount, sellPercentage, buyerPrivateKeys, tokenAddress, config, startNonces // ✅ 可选:前端预获取的 nonces
|
|
306
|
+
} = params;
|
|
307
|
+
// ✅ 校验买方数量(最多 24 个)
|
|
308
|
+
const MAX_BUYERS = 24;
|
|
309
|
+
if (buyerPrivateKeys.length === 0) {
|
|
310
|
+
throw new Error('至少需要一个买方钱包');
|
|
311
|
+
}
|
|
312
|
+
if (buyerPrivateKeys.length > MAX_BUYERS) {
|
|
313
|
+
throw new Error(`买方钱包数量超过限制: ${buyerPrivateKeys.length} > ${MAX_BUYERS}`);
|
|
314
|
+
}
|
|
315
|
+
const chainIdNum = config.chainId ?? 56;
|
|
316
|
+
const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
|
|
317
|
+
chainId: chainIdNum,
|
|
318
|
+
name: 'BSC'
|
|
319
|
+
});
|
|
320
|
+
const seller = new Wallet(sellerPrivateKey, provider);
|
|
321
|
+
const buyers = buyerPrivateKeys.map(pk => new Wallet(pk, provider));
|
|
322
|
+
const nonceManager = new NonceManager(provider);
|
|
323
|
+
// 创建适配的配置对象
|
|
324
|
+
const bundleConfig = {
|
|
325
|
+
minGasPriceGwei: config.minGasPriceGwei,
|
|
326
|
+
maxGasPriceGwei: config.maxGasPriceGwei,
|
|
327
|
+
gasLimit: typeof config.gasLimit === 'bigint' ? Number(config.gasLimit) : config.gasLimit,
|
|
328
|
+
gasLimitMultiplier: config.gasLimitMultiplier,
|
|
329
|
+
txType: config.txType,
|
|
330
|
+
chainId: config.chainId
|
|
331
|
+
};
|
|
332
|
+
const finalGasLimit = getGasLimit(bundleConfig);
|
|
333
|
+
const txType = getTxType(bundleConfig);
|
|
334
|
+
// ✅ 并行获取:卖出数量、gasPrice
|
|
335
|
+
const [sellAmountResult, gasPrice] = await Promise.all([
|
|
336
|
+
calculateSellAmount(provider, tokenAddress, seller.address, sellAmount, sellPercentage),
|
|
337
|
+
getOptimizedGasPrice(provider, getGasPriceConfig(bundleConfig))
|
|
338
|
+
]);
|
|
339
|
+
const { amount: sellAmountWei, decimals } = sellAmountResult;
|
|
340
|
+
// ✅ 并行获取:sellQuote、allowance、所有买方余额
|
|
341
|
+
const helper3 = new Contract(ADDRESSES.BSC.TokenManagerHelper3, HELPER3_ABI, provider);
|
|
342
|
+
const erc20Contract = new Contract(tokenAddress, ['function allowance(address,address) view returns (uint256)'], provider);
|
|
343
|
+
const [sellQuote, currentAllowance, ...buyerBalances] = await Promise.all([
|
|
344
|
+
helper3.trySell(tokenAddress, sellAmountWei),
|
|
345
|
+
erc20Contract.allowance(seller.address, TM_ADDRESS),
|
|
346
|
+
...buyers.map(buyer => provider.getBalance(buyer.address))
|
|
347
|
+
]);
|
|
348
|
+
const totalBuyerFunds = sellQuote.funds;
|
|
349
|
+
// ✅ 计算每个买方的买入金额(按比例分配)
|
|
350
|
+
let buyAmountsWei;
|
|
351
|
+
if (params.buyerRatios && params.buyerRatios.length === buyers.length) {
|
|
352
|
+
// 按比例分配
|
|
353
|
+
buyAmountsWei = params.buyerRatios.map((ratio, index) => {
|
|
354
|
+
const amount = (totalBuyerFunds * BigInt(Math.round(ratio * 10000))) / 10000n;
|
|
355
|
+
return amount;
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
// 平均分配
|
|
360
|
+
const amountPerBuyer = totalBuyerFunds / BigInt(buyers.length);
|
|
361
|
+
buyAmountsWei = buyers.map(() => amountPerBuyer);
|
|
362
|
+
}
|
|
363
|
+
// ✅ 验证所有买方余额
|
|
364
|
+
const reserveGas = ethers.parseEther((config.reserveGasBNB || 0.0005).toString());
|
|
365
|
+
buyers.forEach((buyer, i) => {
|
|
366
|
+
const required = buyAmountsWei[i] + reserveGas;
|
|
367
|
+
if (buyerBalances[i] < required) {
|
|
368
|
+
throw new Error(`买方 ${i + 1} 余额不足: 需要 ${ethers.formatEther(required)} BNB, 实际 ${ethers.formatEther(buyerBalances[i])} BNB`);
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
// 检查是否需要授权
|
|
372
|
+
const APPROVAL_THRESHOLD = ethers.parseUnits('1000000000', decimals);
|
|
373
|
+
const needApproval = currentAllowance < APPROVAL_THRESHOLD;
|
|
374
|
+
// 利润配置
|
|
375
|
+
const profitRateBps = getProfitRateBps(config.userType);
|
|
376
|
+
const profitAmount = totalBuyerFunds > 0n
|
|
377
|
+
? (totalBuyerFunds * BigInt(profitRateBps)) / 10000n
|
|
378
|
+
: 0n;
|
|
379
|
+
// ✅ 获取贿赂金额
|
|
380
|
+
const bribeAmount = getBribeAmount(config);
|
|
381
|
+
const needBribeTx = bribeAmount > 0n;
|
|
382
|
+
// ✅ 并行构建所有交易
|
|
383
|
+
const tmSeller = new Contract(TM_ADDRESS, TM_ABI, seller);
|
|
384
|
+
const [sellUnsigned, ...buyUnsignedList] = await Promise.all([
|
|
385
|
+
// 卖出交易
|
|
386
|
+
tmSeller.sellToken.populateTransaction(0n, tokenAddress, sellAmountWei, 0n),
|
|
387
|
+
// 所有买入交易
|
|
388
|
+
...buyers.map((buyer, i) => {
|
|
389
|
+
const tmBuyer = new Contract(TM_ADDRESS, TM_ABI, buyer);
|
|
390
|
+
const buyAmount = buyAmountsWei[i];
|
|
391
|
+
return tmBuyer.buyTokenAMAP.populateTransaction(0n, tokenAddress, buyer.address, buyAmount, 0n, { value: buyAmount });
|
|
392
|
+
})
|
|
393
|
+
]);
|
|
394
|
+
// ✅ 计算 nonce
|
|
395
|
+
// seller 需要的 nonce 数量
|
|
396
|
+
let sellerNonceCount = 1; // 卖出交易
|
|
397
|
+
if (needBribeTx)
|
|
398
|
+
sellerNonceCount++; // 贿赂交易
|
|
399
|
+
if (needApproval)
|
|
400
|
+
sellerNonceCount++; // 授权交易
|
|
401
|
+
sellerNonceCount++; // 利润交易
|
|
402
|
+
// ✅ 如果前端传入了 startNonces,直接使用(性能优化)
|
|
403
|
+
// 否则从链上获取
|
|
404
|
+
const allWallets = [seller, ...buyers];
|
|
405
|
+
const initialNonces = startNonces && startNonces.length >= allWallets.length
|
|
406
|
+
? startNonces
|
|
407
|
+
: await nonceManager.getNextNoncesForWallets(allWallets);
|
|
408
|
+
// 分配 seller nonces
|
|
409
|
+
const sellerNonces = Array.from({ length: sellerNonceCount }, (_, i) => initialNonces[0] + i);
|
|
410
|
+
let idx = 0;
|
|
411
|
+
let bribeNonce;
|
|
412
|
+
let approvalNonce;
|
|
413
|
+
if (needBribeTx)
|
|
414
|
+
bribeNonce = sellerNonces[idx++];
|
|
415
|
+
if (needApproval)
|
|
416
|
+
approvalNonce = sellerNonces[idx++];
|
|
417
|
+
const sellerNonce = sellerNonces[idx++];
|
|
418
|
+
const profitNonce = sellerNonces[idx];
|
|
419
|
+
// buyer nonces
|
|
420
|
+
const buyerNonces = initialNonces.slice(1);
|
|
421
|
+
// ✅ 并行签名所有交易
|
|
422
|
+
const signPromises = [];
|
|
423
|
+
// ✅ 贿赂交易放在首位
|
|
424
|
+
if (needBribeTx && bribeNonce !== undefined) {
|
|
425
|
+
signPromises.push(seller.signTransaction({
|
|
426
|
+
to: BLOCKRAZOR_BUILDER_EOA,
|
|
427
|
+
value: bribeAmount,
|
|
428
|
+
nonce: bribeNonce,
|
|
429
|
+
gasPrice,
|
|
430
|
+
gasLimit: BRIBE_GAS_LIMIT,
|
|
431
|
+
chainId: chainIdNum,
|
|
432
|
+
type: txType
|
|
433
|
+
}));
|
|
434
|
+
}
|
|
435
|
+
// 授权交易
|
|
436
|
+
if (needApproval && approvalNonce !== undefined) {
|
|
437
|
+
const approveInterface = new ethers.Interface(['function approve(address,uint256) returns (bool)']);
|
|
438
|
+
const approveData = approveInterface.encodeFunctionData('approve', [TM_ADDRESS, ethers.MaxUint256]);
|
|
439
|
+
signPromises.push(seller.signTransaction({
|
|
440
|
+
to: tokenAddress,
|
|
441
|
+
data: approveData,
|
|
442
|
+
value: 0n,
|
|
443
|
+
nonce: approvalNonce,
|
|
444
|
+
gasLimit: 80000n,
|
|
445
|
+
gasPrice,
|
|
446
|
+
chainId: chainIdNum,
|
|
447
|
+
type: txType
|
|
448
|
+
}));
|
|
449
|
+
}
|
|
450
|
+
// 卖出交易
|
|
451
|
+
signPromises.push(seller.signTransaction({
|
|
452
|
+
...sellUnsigned,
|
|
453
|
+
from: seller.address,
|
|
454
|
+
nonce: sellerNonce,
|
|
455
|
+
gasLimit: finalGasLimit,
|
|
456
|
+
gasPrice,
|
|
457
|
+
chainId: chainIdNum,
|
|
458
|
+
type: txType
|
|
459
|
+
}));
|
|
460
|
+
// 所有买入交易
|
|
461
|
+
buyers.forEach((buyer, i) => {
|
|
462
|
+
signPromises.push(buyer.signTransaction({
|
|
463
|
+
...buyUnsignedList[i],
|
|
464
|
+
from: buyer.address,
|
|
465
|
+
nonce: buyerNonces[i],
|
|
466
|
+
gasLimit: finalGasLimit,
|
|
467
|
+
gasPrice,
|
|
468
|
+
chainId: chainIdNum,
|
|
469
|
+
type: txType,
|
|
470
|
+
value: buyAmountsWei[i]
|
|
471
|
+
}));
|
|
472
|
+
});
|
|
473
|
+
const signedTxs = await Promise.all(signPromises);
|
|
474
|
+
// 解析签名结果
|
|
475
|
+
let signIdx = 0;
|
|
476
|
+
let bribeTx = null;
|
|
477
|
+
let approvalTx = null;
|
|
478
|
+
if (needBribeTx)
|
|
479
|
+
bribeTx = signedTxs[signIdx++];
|
|
480
|
+
if (needApproval)
|
|
481
|
+
approvalTx = signedTxs[signIdx++];
|
|
482
|
+
const signedSell = signedTxs[signIdx++];
|
|
483
|
+
const signedBuys = signedTxs.slice(signIdx, signIdx + buyers.length);
|
|
484
|
+
nonceManager.clearTemp();
|
|
485
|
+
// ✅ 按顺序组装交易数组:贿赂 → 授权 → 卖出 → 买入
|
|
486
|
+
const signedTransactions = [];
|
|
487
|
+
if (bribeTx)
|
|
488
|
+
signedTransactions.push(bribeTx);
|
|
489
|
+
if (approvalTx)
|
|
490
|
+
signedTransactions.push(approvalTx);
|
|
491
|
+
signedTransactions.push(signedSell);
|
|
492
|
+
signedTransactions.push(...signedBuys);
|
|
493
|
+
// ✅ 利润多跳转账(强制 2 跳中转)
|
|
494
|
+
let profitHopWallets;
|
|
495
|
+
if (profitAmount > 0n) {
|
|
496
|
+
const profitHopResult = await buildProfitHopTransactions({
|
|
497
|
+
provider,
|
|
498
|
+
payerWallet: seller,
|
|
499
|
+
profitAmount: profitAmount,
|
|
500
|
+
profitRecipient: getProfitRecipient(),
|
|
501
|
+
hopCount: PROFIT_HOP_COUNT,
|
|
502
|
+
gasPrice,
|
|
503
|
+
chainId: chainIdNum,
|
|
504
|
+
txType,
|
|
505
|
+
startNonce: profitNonce
|
|
506
|
+
});
|
|
507
|
+
signedTransactions.push(...profitHopResult.signedTransactions);
|
|
508
|
+
profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
|
|
509
|
+
}
|
|
510
|
+
return {
|
|
511
|
+
signedTransactions,
|
|
512
|
+
profitHopWallets, // ✅ 导出利润多跳钱包
|
|
513
|
+
metadata: {
|
|
514
|
+
sellerAddress: seller.address,
|
|
515
|
+
buyerAddresses: buyers.map(b => b.address),
|
|
516
|
+
sellAmount: ethers.formatUnits(sellAmountWei, decimals),
|
|
517
|
+
buyAmounts: buyAmountsWei.map(amt => ethers.formatEther(amt)),
|
|
518
|
+
hasApproval: !!approvalTx,
|
|
519
|
+
profitAmount: ethers.formatEther(profitAmount)
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Four 内盘快捷批量换手(资金利用率模式)
|
|
525
|
+
*
|
|
526
|
+
* 流程:[贿赂] → [卖出] → [转账多跳...] → [买入1, 买入2, ...] → [利润]
|
|
527
|
+
*
|
|
528
|
+
* 特点:
|
|
529
|
+
* - 子钱包不需要预先有 BNB
|
|
530
|
+
* - 资金来自主钱包卖出代币所得
|
|
531
|
+
* - 提升资金利用率
|
|
532
|
+
* - ✅ 支持转账多跳,隐藏资金流向
|
|
533
|
+
*
|
|
534
|
+
* 限制:根据多跳数动态计算最大买方数量
|
|
535
|
+
*/
|
|
536
|
+
export async function fourQuickBatchSwapMerkle(params) {
|
|
537
|
+
const { sellerPrivateKey, sellAmount, sellPercentage, buyerPrivateKeys, buyerRatios, buyerAmounts, tokenAddress, config, disperseHopCount = 0, // ✅ 转账多跳数(默认0=直接转账)
|
|
538
|
+
startNonces // ✅ 可选:前端预获取的 nonces
|
|
539
|
+
} = params;
|
|
540
|
+
// ✅ 动态计算最大买方数量(根据多跳数)
|
|
541
|
+
// 固定开销: 贿赂(1) + 卖出(1) + 利润多跳(PROFIT_HOP_COUNT + 1)
|
|
542
|
+
// 转账(N*(H+1)) + 买入(N) = N*(H+2)
|
|
543
|
+
const fixedOverhead = 1 + 1 + PROFIT_HOP_COUNT + 1;
|
|
544
|
+
const maxTxs = 50 - fixedOverhead;
|
|
545
|
+
let MAX_BUYERS = Math.floor(maxTxs / (disperseHopCount + 2));
|
|
546
|
+
MAX_BUYERS = Math.max(1, MAX_BUYERS);
|
|
547
|
+
console.log(`[fourQuickBatchSwapMerkle] 多跳数: ${disperseHopCount}, 最大买方数: ${MAX_BUYERS}`);
|
|
548
|
+
if (buyerPrivateKeys.length === 0) {
|
|
549
|
+
throw new Error('至少需要一个买方钱包');
|
|
550
|
+
}
|
|
551
|
+
if (buyerPrivateKeys.length > MAX_BUYERS) {
|
|
552
|
+
throw new Error(`资金利用率模式(${disperseHopCount}跳)买方钱包数量超过限制: ${buyerPrivateKeys.length} > ${MAX_BUYERS}`);
|
|
553
|
+
}
|
|
554
|
+
// ✅ 校验分配模式
|
|
555
|
+
if (!buyerRatios && !buyerAmounts) {
|
|
556
|
+
throw new Error('必须提供 buyerRatios 或 buyerAmounts');
|
|
557
|
+
}
|
|
558
|
+
if (buyerRatios && buyerRatios.length !== buyerPrivateKeys.length) {
|
|
559
|
+
throw new Error(`buyerRatios 长度 (${buyerRatios.length}) 与 buyerPrivateKeys 长度 (${buyerPrivateKeys.length}) 不匹配`);
|
|
560
|
+
}
|
|
561
|
+
if (buyerAmounts && buyerAmounts.length !== buyerPrivateKeys.length) {
|
|
562
|
+
throw new Error(`buyerAmounts 长度 (${buyerAmounts.length}) 与 buyerPrivateKeys 长度 (${buyerPrivateKeys.length}) 不匹配`);
|
|
563
|
+
}
|
|
564
|
+
const chainIdNum = config.chainId ?? 56;
|
|
565
|
+
const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
|
|
566
|
+
chainId: chainIdNum,
|
|
567
|
+
name: 'BSC'
|
|
568
|
+
});
|
|
569
|
+
const seller = new Wallet(sellerPrivateKey, provider);
|
|
570
|
+
const buyers = buyerPrivateKeys.map(pk => new Wallet(pk, provider));
|
|
571
|
+
const nonceManager = new NonceManager(provider);
|
|
572
|
+
// 创建适配的配置对象
|
|
573
|
+
const bundleConfig = {
|
|
574
|
+
minGasPriceGwei: config.minGasPriceGwei,
|
|
575
|
+
maxGasPriceGwei: config.maxGasPriceGwei,
|
|
576
|
+
gasLimit: typeof config.gasLimit === 'bigint' ? Number(config.gasLimit) : config.gasLimit,
|
|
577
|
+
gasLimitMultiplier: config.gasLimitMultiplier,
|
|
578
|
+
txType: config.txType,
|
|
579
|
+
chainId: config.chainId
|
|
580
|
+
};
|
|
581
|
+
const finalGasLimit = getGasLimit(bundleConfig);
|
|
582
|
+
const txType = getTxType(bundleConfig);
|
|
583
|
+
// ✅ 并行获取:卖出数量、gasPrice
|
|
584
|
+
const [sellAmountResult, gasPrice] = await Promise.all([
|
|
585
|
+
calculateSellAmount(provider, tokenAddress, seller.address, sellAmount, sellPercentage),
|
|
586
|
+
getOptimizedGasPrice(provider, getGasPriceConfig(bundleConfig))
|
|
587
|
+
]);
|
|
588
|
+
const { amount: sellAmountWei, decimals } = sellAmountResult;
|
|
589
|
+
// ✅ 获取卖出报价
|
|
590
|
+
const helper3 = new Contract(ADDRESSES.BSC.TokenManagerHelper3, HELPER3_ABI, provider);
|
|
591
|
+
const sellQuote = await helper3.trySell(tokenAddress, sellAmountWei);
|
|
592
|
+
const estimatedBNBOut = sellQuote.funds;
|
|
593
|
+
console.log(`[fourQuickBatchSwapMerkle] 卖出数量: ${ethers.formatUnits(sellAmountWei, decimals)}`);
|
|
594
|
+
console.log(`[fourQuickBatchSwapMerkle] 预估卖出所得: ${ethers.formatEther(estimatedBNBOut)} BNB`);
|
|
595
|
+
// ✅ 计算利润(根据 userType 动态调整)
|
|
596
|
+
const profitRateBps = getProfitRateBps(config.userType);
|
|
597
|
+
const profitAmount = estimatedBNBOut > 0n
|
|
598
|
+
? (estimatedBNBOut * BigInt(profitRateBps)) / 10000n
|
|
599
|
+
: 0n;
|
|
600
|
+
const distributableAmount = estimatedBNBOut - profitAmount;
|
|
601
|
+
// ✅ 计算每个买方分到的金额
|
|
602
|
+
let transferAmountsWei;
|
|
603
|
+
if (buyerAmounts && buyerAmounts.length === buyers.length) {
|
|
604
|
+
// 数量模式
|
|
605
|
+
transferAmountsWei = buyerAmounts.map(amt => ethers.parseEther(amt));
|
|
606
|
+
const totalTransfer = transferAmountsWei.reduce((a, b) => a + b, 0n);
|
|
607
|
+
if (totalTransfer > distributableAmount) {
|
|
608
|
+
throw new Error(`指定的买入总金额超过可分配金额 (${ethers.formatEther(distributableAmount)} BNB)`);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
else if (buyerRatios && buyerRatios.length === buyers.length) {
|
|
612
|
+
// 比例模式
|
|
613
|
+
transferAmountsWei = buyerRatios.map(ratio => {
|
|
614
|
+
return (distributableAmount * BigInt(Math.round(ratio * 10000))) / 10000n;
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
else {
|
|
618
|
+
throw new Error('必须提供 buyerRatios 或 buyerAmounts');
|
|
619
|
+
}
|
|
620
|
+
// ✅ 获取贿赂金额
|
|
621
|
+
const bribeAmount = getBribeAmount(config);
|
|
622
|
+
// ✅ 验证主钱包余额
|
|
623
|
+
const sellerBalance = await seller.provider.getBalance(seller.address);
|
|
624
|
+
// 主钱包只需要支付:贿赂 + Gas(卖出后有 BNB 可用于转账和利润)
|
|
625
|
+
const sellerGasCost = gasPrice * (GAS_LIMITS.BRIBE + finalGasLimit + GAS_LIMITS.BRIBE * BigInt(buyers.length) + GAS_LIMITS.BRIBE);
|
|
626
|
+
const sellerRequired = bribeAmount + sellerGasCost;
|
|
627
|
+
if (sellerBalance < sellerRequired) {
|
|
628
|
+
throw new Error(`主钱包 BNB 余额不足: 需要约 ${ethers.formatEther(sellerRequired)} BNB (贿赂: ${ethers.formatEther(bribeAmount)}, Gas: ${ethers.formatEther(sellerGasCost)}), 实际 ${ethers.formatEther(sellerBalance)} BNB`);
|
|
629
|
+
}
|
|
630
|
+
// ==================== 规划 Nonce ====================
|
|
631
|
+
// ✅ 如果前端传入了 startNonces,直接使用(性能优化)
|
|
632
|
+
let sellerNonce = startNonces && startNonces.length > 0
|
|
633
|
+
? startNonces[0]
|
|
634
|
+
: await nonceManager.getNextNonce(seller);
|
|
635
|
+
// ==================== 1. 贿赂交易 ====================
|
|
636
|
+
let bribeTx = null;
|
|
637
|
+
if (bribeAmount > 0n) {
|
|
638
|
+
bribeTx = await seller.signTransaction({
|
|
639
|
+
to: BLOCKRAZOR_BUILDER_EOA,
|
|
640
|
+
value: bribeAmount,
|
|
641
|
+
nonce: sellerNonce++,
|
|
642
|
+
gasPrice,
|
|
643
|
+
gasLimit: BRIBE_GAS_LIMIT,
|
|
644
|
+
chainId: chainIdNum,
|
|
645
|
+
type: txType
|
|
646
|
+
});
|
|
647
|
+
console.log(`[fourQuickBatchSwapMerkle] 贿赂交易已签名`);
|
|
648
|
+
}
|
|
649
|
+
// ==================== 2. 卖出交易 ====================
|
|
650
|
+
const tmSeller = new Contract(TM_ADDRESS, TM_ABI, seller);
|
|
651
|
+
const sellUnsigned = await tmSeller.sellToken.populateTransaction(0n, tokenAddress, sellAmountWei, 0n);
|
|
652
|
+
const signedSell = await seller.signTransaction({
|
|
653
|
+
...sellUnsigned,
|
|
654
|
+
from: seller.address,
|
|
655
|
+
nonce: sellerNonce++,
|
|
656
|
+
gasLimit: finalGasLimit,
|
|
657
|
+
gasPrice,
|
|
658
|
+
chainId: chainIdNum,
|
|
659
|
+
type: txType
|
|
660
|
+
});
|
|
661
|
+
console.log(`[fourQuickBatchSwapMerkle] 卖出交易已签名`);
|
|
662
|
+
// ==================== 3. 转账交易(支持多跳)====================
|
|
663
|
+
const reserveGas = ethers.parseEther((config.reserveGasBNB || 0.0005).toString());
|
|
664
|
+
const buyerGasCost = gasPrice * finalGasLimit;
|
|
665
|
+
// ✅ 生成多跳路径
|
|
666
|
+
const hopPaths = generateDisperseHopPaths(buyers.map(b => b.address), disperseHopCount, provider);
|
|
667
|
+
// 收集所有中间钱包信息
|
|
668
|
+
const allHopWallets = [];
|
|
669
|
+
hopPaths.forEach(path => {
|
|
670
|
+
allHopWallets.push(...path.hopWalletsInfo);
|
|
671
|
+
});
|
|
672
|
+
let transferTxs = [];
|
|
673
|
+
if (disperseHopCount === 0) {
|
|
674
|
+
// ✅ 无多跳:直接转账
|
|
675
|
+
const transferNonces = buyers.map((_, i) => sellerNonce + i);
|
|
676
|
+
sellerNonce += buyers.length;
|
|
677
|
+
transferTxs = await Promise.all(buyers.map((buyer, i) => {
|
|
678
|
+
const transferValue = transferAmountsWei[i] + reserveGas + buyerGasCost;
|
|
679
|
+
return seller.signTransaction({
|
|
680
|
+
to: buyer.address,
|
|
681
|
+
value: transferValue,
|
|
682
|
+
nonce: transferNonces[i],
|
|
683
|
+
gasPrice,
|
|
684
|
+
gasLimit: NATIVE_TRANSFER_GAS_LIMIT,
|
|
685
|
+
chainId: chainIdNum,
|
|
686
|
+
type: txType
|
|
687
|
+
});
|
|
688
|
+
}));
|
|
689
|
+
}
|
|
690
|
+
else {
|
|
691
|
+
// ✅ 有多跳:构建多跳转账链
|
|
692
|
+
// ✅ 修复:payer 每次只发送 1 笔交易(到第一个hop钱包),hop钱包用自己的nonce=0
|
|
693
|
+
const hopChains = await Promise.all(hopPaths.map((path, i) => {
|
|
694
|
+
const finalAmount = transferAmountsWei[i] + reserveGas + buyerGasCost;
|
|
695
|
+
const payerNonce = sellerNonce + i; // ✅ payer 每个 buyer 只用 1 个 nonce
|
|
696
|
+
return buildNativeHopChain(seller, path, finalAmount, gasPrice, chainIdNum, txType, payerNonce);
|
|
697
|
+
}));
|
|
698
|
+
transferTxs = hopChains.flat();
|
|
699
|
+
sellerNonce += buyers.length; // ✅ payer 只增加 buyers.length 个 nonce
|
|
700
|
+
}
|
|
701
|
+
console.log(`[fourQuickBatchSwapMerkle] ${transferTxs.length} 笔转账交易已签名 (多跳数=${disperseHopCount})`);
|
|
702
|
+
// ==================== 4. 买入交易 ====================
|
|
703
|
+
// ✅ 如果前端传入了 startNonces,使用 buyer 部分(从索引 1 开始)
|
|
704
|
+
const buyerNonces = startNonces && startNonces.length > 1
|
|
705
|
+
? startNonces.slice(1)
|
|
706
|
+
: await Promise.all(buyers.map(buyer => nonceManager.getNextNonce(buyer)));
|
|
707
|
+
const signedBuys = await Promise.all(buyers.map(async (buyer, i) => {
|
|
708
|
+
const buyAmount = transferAmountsWei[i];
|
|
709
|
+
const tmBuyer = new Contract(TM_ADDRESS, TM_ABI, buyer);
|
|
710
|
+
const buyUnsigned = await tmBuyer.buyTokenAMAP.populateTransaction(0n, tokenAddress, buyer.address, buyAmount, 0n, { value: buyAmount });
|
|
711
|
+
return buyer.signTransaction({
|
|
712
|
+
...buyUnsigned,
|
|
713
|
+
from: buyer.address,
|
|
714
|
+
nonce: buyerNonces[i],
|
|
715
|
+
gasLimit: finalGasLimit,
|
|
716
|
+
gasPrice,
|
|
717
|
+
chainId: chainIdNum,
|
|
718
|
+
type: txType,
|
|
719
|
+
value: buyAmount
|
|
720
|
+
});
|
|
721
|
+
}));
|
|
722
|
+
console.log(`[fourQuickBatchSwapMerkle] ${signedBuys.length} 笔买入交易已签名`);
|
|
723
|
+
nonceManager.clearTemp();
|
|
724
|
+
// ==================== 组装交易数组 ====================
|
|
725
|
+
const signedTransactions = [];
|
|
726
|
+
if (bribeTx)
|
|
727
|
+
signedTransactions.push(bribeTx);
|
|
728
|
+
signedTransactions.push(signedSell);
|
|
729
|
+
signedTransactions.push(...transferTxs);
|
|
730
|
+
signedTransactions.push(...signedBuys);
|
|
731
|
+
// ==================== 5. 利润多跳转账(强制 2 跳中转)====================
|
|
732
|
+
let profitHopWallets;
|
|
733
|
+
if (profitAmount > 0n) {
|
|
734
|
+
const profitHopResult = await buildProfitHopTransactions({
|
|
735
|
+
provider,
|
|
736
|
+
payerWallet: seller,
|
|
737
|
+
profitAmount: profitAmount,
|
|
738
|
+
profitRecipient: getProfitRecipient(),
|
|
739
|
+
hopCount: PROFIT_HOP_COUNT,
|
|
740
|
+
gasPrice,
|
|
741
|
+
chainId: chainIdNum,
|
|
742
|
+
txType,
|
|
743
|
+
startNonce: sellerNonce++
|
|
744
|
+
});
|
|
745
|
+
signedTransactions.push(...profitHopResult.signedTransactions);
|
|
746
|
+
profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
|
|
747
|
+
// 多跳交易已签名
|
|
748
|
+
}
|
|
749
|
+
console.log(`[fourQuickBatchSwapMerkle] 交易组装完成: ${signedTransactions.length} 笔`);
|
|
750
|
+
console.log(` - 贿赂: ${bribeTx ? 1 : 0}`);
|
|
751
|
+
console.log(` - 卖出: 1`);
|
|
752
|
+
console.log(` - 转账: ${transferTxs.length}`);
|
|
753
|
+
console.log(` - 买入: ${signedBuys.length}`);
|
|
754
|
+
return {
|
|
755
|
+
signedTransactions,
|
|
756
|
+
disperseHopWallets: allHopWallets.length > 0 ? allHopWallets : undefined, // ✅ 返回转账多跳钱包
|
|
757
|
+
profitHopWallets, // ✅ 返回利润多跳钱包
|
|
758
|
+
metadata: {
|
|
759
|
+
sellerAddress: seller.address,
|
|
760
|
+
buyerAddresses: buyers.map(b => b.address),
|
|
761
|
+
sellAmount: ethers.formatUnits(sellAmountWei, decimals),
|
|
762
|
+
estimatedBNBOut: ethers.formatEther(estimatedBNBOut),
|
|
763
|
+
transferAmounts: transferAmountsWei.map(amt => ethers.formatEther(amt)),
|
|
764
|
+
profitAmount: profitAmount > 0n ? ethers.formatEther(profitAmount) : undefined,
|
|
765
|
+
disperseHopCount: disperseHopCount > 0 ? disperseHopCount : undefined // ✅ 返回多跳数
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
}
|