four-flap-meme-sdk 2.2.2 → 2.2.3
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 +41 -6
- package/README.md +31 -0
- package/README.zh-CN.md +41 -6
- package/dist/__tests__/subpath-exports.test.d.ts +1 -0
- package/dist/__tests__/subpath-exports.test.js +64 -0
- package/dist/abis/common.d.ts +85 -0
- package/dist/abis/common.js +264 -0
- package/dist/abis/contracts/TaxToken.json +969 -0
- package/dist/abis/contracts/TokenManager2.json +136 -0
- package/dist/abis/contracts/index.d.ts +5 -0
- package/dist/abis/contracts/index.js +5 -0
- package/dist/abis/flap/index.d.ts +3 -0
- package/dist/abis/flap/index.js +3 -0
- package/dist/abis/flap/portal-events.d.ts +6 -0
- package/dist/abis/flap/portal-events.js +17 -0
- package/dist/abis/flap/portal.d.ts +6 -0
- package/dist/abis/flap/portal.js +37 -0
- package/dist/abis/flap/vault.d.ts +171 -0
- package/dist/abis/flap/vault.js +91 -0
- package/dist/abis/index.d.ts +8 -0
- package/dist/abis/index.js +11 -0
- package/dist/bundle-core/__tests__/config-helpers.test.d.ts +1 -0
- package/dist/bundle-core/__tests__/config-helpers.test.js +28 -0
- package/dist/bundle-core/__tests__/facade-parity.test.d.ts +1 -0
- package/dist/bundle-core/__tests__/facade-parity.test.js +33 -0
- package/dist/bundle-core/__tests__/sign-context-helpers.test.d.ts +1 -0
- package/dist/bundle-core/__tests__/sign-context-helpers.test.js +60 -0
- package/dist/bundle-core/__tests__/sign-fixture.test.d.ts +1 -0
- package/dist/bundle-core/__tests__/sign-fixture.test.js +220 -0
- package/dist/bundle-core/__tests__/sign-fixtures.d.ts +10 -0
- package/dist/bundle-core/__tests__/sign-fixtures.js +16 -0
- package/dist/bundle-core/config-helpers.d.ts +36 -0
- package/dist/bundle-core/config-helpers.js +57 -0
- package/dist/bundle-core/errors.d.ts +50 -0
- package/dist/bundle-core/errors.js +35 -0
- package/dist/bundle-core/four-meme/approve-tokenmanager.d.ts +7 -0
- package/dist/bundle-core/four-meme/approve-tokenmanager.js +99 -0
- package/dist/bundle-core/four-meme/core-helpers.d.ts +8 -0
- package/dist/bundle-core/four-meme/core-helpers.js +40 -0
- package/dist/bundle-core/four-meme/core.d.ts +4 -0
- package/dist/bundle-core/four-meme/core.js +515 -0
- package/dist/bundle-core/four-meme/pancake-proxy.d.ts +28 -0
- package/dist/bundle-core/four-meme/pancake-proxy.js +679 -0
- package/dist/bundle-core/four-meme/private.d.ts +27 -0
- package/dist/bundle-core/four-meme/private.js +465 -0
- package/dist/bundle-core/four-meme/sign-context-helpers.d.ts +2 -0
- package/dist/bundle-core/four-meme/sign-context-helpers.js +2 -0
- package/dist/bundle-core/four-meme/swap-buy-first.d.ts +8 -0
- package/dist/bundle-core/four-meme/swap-buy-first.js +493 -0
- package/dist/bundle-core/four-meme/swap-hop-helpers.d.ts +6 -0
- package/dist/bundle-core/four-meme/swap-hop-helpers.js +63 -0
- package/dist/bundle-core/four-meme/swap-internal.d.ts +3 -0
- package/dist/bundle-core/four-meme/swap-internal.js +18 -0
- package/dist/bundle-core/four-meme/swap-sign-helpers.d.ts +27 -0
- package/dist/bundle-core/four-meme/swap-sign-helpers.js +105 -0
- package/dist/bundle-core/four-meme/swap.d.ts +17 -0
- package/dist/bundle-core/four-meme/swap.js +505 -0
- package/dist/bundle-core/four-meme/types/buy-first.d.ts +50 -0
- package/dist/bundle-core/four-meme/types/buy-first.js +1 -0
- package/dist/bundle-core/four-meme/types/core-flow.d.ts +63 -0
- package/dist/bundle-core/four-meme/types/core-flow.js +1 -0
- package/dist/bundle-core/four-meme/types/index.d.ts +600 -0
- package/dist/bundle-core/four-meme/types/index.js +1 -0
- package/dist/bundle-core/four-meme/types/swap-internal.d.ts +19 -0
- package/dist/bundle-core/four-meme/types/swap-internal.js +1 -0
- package/dist/bundle-core/four-meme/types.d.ts +1 -0
- package/dist/bundle-core/four-meme/types.js +1 -0
- package/dist/bundle-core/four-meme/utils-disperse.d.ts +7 -0
- package/dist/bundle-core/four-meme/utils-disperse.js +396 -0
- package/dist/bundle-core/four-meme/utils-pairwise.d.ts +8 -0
- package/dist/bundle-core/four-meme/utils-pairwise.js +328 -0
- package/dist/bundle-core/four-meme/utils-sweep.d.ts +8 -0
- package/dist/bundle-core/four-meme/utils-sweep.js +744 -0
- package/dist/bundle-core/index.d.ts +8 -0
- package/dist/bundle-core/index.js +8 -0
- package/dist/bundle-core/internal.d.ts +21 -0
- package/dist/bundle-core/internal.js +182 -0
- package/dist/bundle-core/sign-context-helpers.d.ts +25 -0
- package/dist/bundle-core/sign-context-helpers.js +67 -0
- package/dist/bundle-core/submit.d.ts +293 -0
- package/dist/bundle-core/submit.js +727 -0
- package/dist/bundle-core/types/index.d.ts +8 -0
- package/dist/bundle-core/types/index.js +1 -0
- package/dist/bundle-core/types.d.ts +1 -0
- package/dist/bundle-core/types.js +1 -0
- package/dist/chains/bsc/four/approve-tokenmanager.d.ts +1 -26
- package/dist/chains/bsc/four/approve-tokenmanager.js +1 -113
- package/dist/chains/bsc/four/config.d.ts +5 -67
- package/dist/chains/bsc/four/config.js +2 -114
- package/dist/chains/bsc/four/core.d.ts +1 -4
- package/dist/chains/bsc/four/core.js +1 -592
- 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 +2 -46
- package/dist/chains/bsc/four/internal.js +2 -239
- package/dist/chains/bsc/four/pancake-proxy.d.ts +1 -28
- package/dist/chains/bsc/four/pancake-proxy.js +1 -687
- package/dist/chains/bsc/four/private.d.ts +1 -27
- package/dist/chains/bsc/four/private.js +1 -477
- package/dist/chains/bsc/four/submit.d.ts +2 -315
- package/dist/chains/bsc/four/submit.js +2 -752
- package/dist/chains/bsc/four/swap-buy-first.d.ts +2 -55
- package/dist/chains/bsc/four/swap-buy-first.js +2 -507
- package/dist/chains/bsc/four/swap-internal.d.ts +1 -3
- package/dist/chains/bsc/four/swap-internal.js +1 -18
- package/dist/chains/bsc/four/swap.d.ts +2 -144
- package/dist/chains/bsc/four/swap.js +2 -766
- package/dist/chains/bsc/four/types.d.ts +1 -476
- package/dist/chains/bsc/four/utils-disperse.d.ts +1 -0
- package/dist/chains/bsc/four/utils-disperse.js +1 -0
- package/dist/chains/bsc/four/utils-pairwise.d.ts +1 -0
- package/dist/chains/bsc/four/utils-pairwise.js +1 -0
- package/dist/chains/bsc/four/utils-sweep.d.ts +1 -0
- package/dist/chains/bsc/four/utils-sweep.js +1 -0
- package/dist/chains/bsc/four/utils.d.ts +5 -18
- package/dist/chains/bsc/four/utils.js +5 -1552
- package/dist/chains/bsc/iro.d.ts +5 -0
- package/dist/chains/bsc/iro.js +4 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-helpers.d.ts +159 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-helpers.js +117 -0
- package/dist/chains/bsc/pancake/bundle-buy-first.d.ts +1 -91
- package/dist/chains/bsc/pancake/bundle-buy-first.js +97 -212
- package/dist/chains/bsc/pancake/bundle-swap-helpers.d.ts +241 -0
- package/dist/chains/bsc/pancake/bundle-swap-helpers.js +565 -0
- package/dist/chains/bsc/pancake/bundle-swap.d.ts +1 -79
- package/dist/chains/bsc/pancake/bundle-swap.js +114 -726
- package/dist/chains/bsc/pancake/index.d.ts +4 -2
- package/dist/chains/bsc/pancake/index.js +1 -3
- package/dist/chains/bsc/platforms/iro/factory.d.ts +2 -2
- package/dist/chains/bsc/platforms/iro/factory.js +3 -1
- 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 +31 -10
- package/dist/chains/bsc/platforms/iro/token.js +4 -1
- package/dist/chains/eni/batch-router/bundle-approve.js +4 -3
- package/dist/chains/eni/batch-router/transfer.js +55 -25
- package/dist/chains/eni/batch-router/utils.js +32 -6
- package/dist/chains/eni/bundler/sign.js +5 -6
- package/dist/chains/eni/bundler/submit.js +1 -4
- package/dist/chains/eni/constants.js +1 -1
- package/dist/chains/eni/flat-aliases.d.ts +10 -0
- package/dist/chains/eni/flat-aliases.js +8 -0
- package/dist/chains/eni/index.d.ts +2 -1
- package/dist/chains/eni/index.js +1 -0
- 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 +9 -6
- package/dist/chains/eni/platforms/daoaas/portal-direct.js +28 -44
- package/dist/chains/eni/platforms/daoaas/portal.js +10 -6
- package/dist/chains/eni/platforms/dswap/liquidity.js +58 -26
- 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 +87 -46
- package/dist/chains/eni/platforms/fair-launch/pool.js +4 -1
- 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 +3 -1
- 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 +90 -26
- package/dist/chains/eni/platforms/iro/token.js +107 -31
- package/dist/chains/eni/platforms/iro/whitelist.js +6 -18
- package/dist/chains/eni/submit.d.ts +43 -0
- package/dist/chains/eni/submit.js +286 -0
- package/dist/chains/index.d.ts +13 -0
- package/dist/chains/index.js +13 -0
- package/dist/chains/xlayer/eip7702/bundle-approve.d.ts +2 -26
- package/dist/chains/xlayer/eip7702/bundle-approve.js +11 -21
- package/dist/chains/xlayer/eip7702/bundle-buy.d.ts +2 -6
- package/dist/chains/xlayer/eip7702/bundle-buy.js +13 -51
- package/dist/chains/xlayer/eip7702/bundle-create.js +93 -59
- package/dist/chains/xlayer/eip7702/bundle-sell.d.ts +2 -6
- package/dist/chains/xlayer/eip7702/bundle-sell.js +29 -111
- package/dist/chains/xlayer/eip7702/bundle-swap.d.ts +3 -65
- package/dist/chains/xlayer/eip7702/bundle-swap.js +51 -245
- package/dist/chains/xlayer/eip7702/constants.d.ts +1 -16
- package/dist/chains/xlayer/eip7702/constants.js +3 -21
- package/dist/chains/xlayer/eip7702/flat-aliases.d.ts +13 -0
- package/dist/chains/xlayer/eip7702/flat-aliases.js +10 -0
- package/dist/chains/xlayer/eip7702/index.d.ts +28 -46
- package/dist/chains/xlayer/eip7702/index.js +28 -81
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-helpers.d.ts +79 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-helpers.js +1 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer.d.ts +2 -203
- package/dist/chains/xlayer/eip7702/multi-hop-transfer.js +63 -307
- package/dist/chains/xlayer/eip7702/transfer-context-helpers.d.ts +26 -0
- package/dist/chains/xlayer/eip7702/transfer-context-helpers.js +57 -0
- package/dist/chains/xlayer/eip7702/types.d.ts +88 -0
- package/dist/chains/xlayer/eip7702/utils.d.ts +0 -3
- package/dist/chains/xlayer/eip7702/utils.js +23 -28
- package/dist/chains/xlayer/eip7702/volume-helpers.d.ts +148 -0
- package/dist/chains/xlayer/eip7702/volume-helpers.js +48 -0
- package/dist/chains/xlayer/eip7702/volume.d.ts +6 -184
- package/dist/chains/xlayer/eip7702/volume.js +89 -164
- 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-helpers.d.ts +126 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.js +228 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap.d.ts +1 -95
- package/dist/chains/xlayer/eoa/eoa-bundle-swap.js +66 -299
- package/dist/chains/xlayer/eoa/eoa-wash-volume.d.ts +1 -1
- package/dist/chains/xlayer/eoa/eoa-wash-volume.js +18 -23
- package/dist/chains/xlayer/eoa/index.d.ts +10 -6
- package/dist/chains/xlayer/eoa/index.js +8 -23
- package/dist/chains/xlayer/eoa/portal-ops.js +7 -2
- 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 +1 -3
- package/dist/chains/xlayer/index.d.ts +3 -2
- package/dist/chains/xlayer/index.js +4 -7
- package/dist/contracts/helper3.d.ts +20 -5
- package/dist/contracts/helper3.js +56 -20
- package/dist/contracts/tm-bundle-helpers.d.ts +88 -0
- package/dist/contracts/tm-bundle-helpers.js +72 -0
- package/dist/contracts/tm-bundle-merkle/approve-tokenmanager.d.ts +1 -26
- package/dist/contracts/tm-bundle-merkle/approve-tokenmanager.js +1 -113
- package/dist/contracts/tm-bundle-merkle/config.d.ts +5 -67
- package/dist/contracts/tm-bundle-merkle/config.js +2 -114
- package/dist/contracts/tm-bundle-merkle/core.d.ts +1 -4
- package/dist/contracts/tm-bundle-merkle/core.js +1 -591
- 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 +2 -46
- package/dist/contracts/tm-bundle-merkle/internal.js +2 -238
- package/dist/contracts/tm-bundle-merkle/pancake-proxy.d.ts +1 -28
- package/dist/contracts/tm-bundle-merkle/pancake-proxy.js +1 -686
- package/dist/contracts/tm-bundle-merkle/private.d.ts +1 -27
- package/dist/contracts/tm-bundle-merkle/private.js +1 -476
- package/dist/contracts/tm-bundle-merkle/submit.d.ts +3 -314
- package/dist/contracts/tm-bundle-merkle/submit.js +3 -928
- package/dist/contracts/tm-bundle-merkle/swap-buy-first.d.ts +2 -55
- package/dist/contracts/tm-bundle-merkle/swap-buy-first.js +2 -506
- package/dist/contracts/tm-bundle-merkle/swap-internal.d.ts +1 -3
- package/dist/contracts/tm-bundle-merkle/swap-internal.js +1 -18
- package/dist/contracts/tm-bundle-merkle/swap.d.ts +2 -144
- package/dist/contracts/tm-bundle-merkle/swap.js +2 -764
- package/dist/contracts/tm-bundle-merkle/types.d.ts +1 -476
- package/dist/contracts/tm-bundle-merkle/utils-disperse.d.ts +1 -0
- package/dist/contracts/tm-bundle-merkle/utils-disperse.js +1 -0
- package/dist/contracts/tm-bundle-merkle/utils-pairwise.d.ts +1 -0
- package/dist/contracts/tm-bundle-merkle/utils-pairwise.js +1 -0
- package/dist/contracts/tm-bundle-merkle/utils-sweep.d.ts +1 -0
- package/dist/contracts/tm-bundle-merkle/utils-sweep.js +1 -0
- package/dist/contracts/tm-bundle-merkle/utils.d.ts +6 -18
- package/dist/contracts/tm-bundle-merkle/utils.js +6 -1501
- package/dist/contracts/tm-bundle.d.ts +3 -51
- package/dist/contracts/tm-bundle.js +108 -177
- package/dist/contracts/tm.d.ts +3 -2
- package/dist/contracts/tm.js +37 -32
- package/dist/contracts/tm1.js +9 -4
- package/dist/contracts/tm2.js +9 -4
- package/dist/dex/direct-router-helpers.d.ts +264 -0
- package/dist/dex/direct-router-helpers.js +539 -0
- package/dist/dex/direct-router.d.ts +3 -125
- package/dist/dex/direct-router.js +237 -666
- package/dist/dex/types.d.ts +81 -0
- package/dist/dex/types.js +1 -0
- package/dist/exports/root-bundle-and-tooling.d.ts +27 -0
- package/dist/exports/root-bundle-and-tooling.js +30 -0
- package/dist/exports/root-eni-and-bsc-iro.d.ts +26 -0
- package/dist/exports/root-eni-and-bsc-iro.js +66 -0
- package/dist/exports/root-foundations.d.ts +35 -0
- package/dist/exports/root-foundations.js +70 -0
- package/dist/exports/root-swap-dex-and-xlayer.d.ts +30 -0
- package/dist/exports/root-swap-dex-and-xlayer.js +78 -0
- package/dist/flap/index.d.ts +10 -0
- package/dist/flap/index.js +8 -0
- package/dist/flows/create.d.ts +2 -1
- package/dist/flows/create.js +6 -6
- package/dist/flows/index.d.ts +1 -0
- package/dist/flows/index.js +1 -0
- package/dist/index.d.ts +20 -85
- package/dist/index.js +20 -215
- package/dist/merkle/index.d.ts +12 -0
- package/dist/merkle/index.js +11 -0
- package/dist/shared/abis/common.d.ts +2 -83
- package/dist/shared/abis/common.js +2 -252
- package/dist/shared/abis/index.d.ts +5 -6
- package/dist/shared/abis/index.js +5 -7
- package/dist/shared/clients/blockrazor.js +39 -25
- package/dist/shared/clients/club48.d.ts +2 -2
- package/dist/shared/clients/club48.js +34 -29
- package/dist/shared/clients/emitservice.js +2 -0
- package/dist/shared/clients/four.d.ts +21 -6
- package/dist/shared/clients/four.js +29 -24
- package/dist/shared/clients/index.d.ts +8 -0
- package/dist/shared/clients/index.js +8 -0
- package/dist/shared/clients/merkle.js +27 -34
- package/dist/shared/constants/addresses.d.ts +1 -1
- package/dist/shared/constants/addresses.js +11 -2
- 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 +2 -6
- package/dist/shared/constants/index.d.ts +3 -0
- package/dist/shared/constants/index.js +1 -0
- package/dist/shared/constants/quote.d.ts +30 -0
- package/dist/shared/constants/quote.js +37 -0
- package/dist/shared/flap/abi.js +1 -1
- package/dist/shared/flap/constants.d.ts +1 -2
- package/dist/shared/flap/constants.js +2 -3
- package/dist/shared/flap/curve.js +3 -0
- package/dist/shared/flap/errors.d.ts +1 -4
- package/dist/shared/flap/errors.js +20 -1
- package/dist/shared/flap/index.d.ts +5 -4
- package/dist/shared/flap/index.js +5 -4
- package/dist/shared/flap/meta.d.ts +22 -18
- package/dist/shared/flap/meta.js +12 -17
- package/dist/shared/flap/permit.js +5 -2
- package/dist/shared/flap/pinata.d.ts +22 -6
- package/dist/shared/flap/pinata.js +21 -26
- package/dist/shared/flap/portal-bundle-merkle/config.d.ts +3 -72
- package/dist/shared/flap/portal-bundle-merkle/config.js +4 -124
- package/dist/shared/flap/portal-bundle-merkle/core-helpers.d.ts +32 -0
- package/dist/shared/flap/portal-bundle-merkle/core-helpers.js +83 -0
- package/dist/shared/flap/portal-bundle-merkle/core.d.ts +0 -4
- package/dist/shared/flap/portal-bundle-merkle/core.js +86 -278
- package/dist/shared/flap/portal-bundle-merkle/create-to-dex.d.ts +7 -2
- package/dist/shared/flap/portal-bundle-merkle/create-to-dex.js +101 -206
- package/dist/shared/flap/portal-bundle-merkle/curve-to-dex.js +100 -92
- package/dist/shared/flap/portal-bundle-merkle/index.d.ts +11 -7
- package/dist/shared/flap/portal-bundle-merkle/index.js +4 -7
- package/dist/shared/flap/portal-bundle-merkle/pancake-proxy.js +71 -68
- package/dist/shared/flap/portal-bundle-merkle/private.js +61 -114
- package/dist/shared/flap/portal-bundle-merkle/swap-buy-first-helpers.d.ts +125 -0
- package/dist/shared/flap/portal-bundle-merkle/swap-buy-first-helpers.js +113 -0
- package/dist/shared/flap/portal-bundle-merkle/swap-buy-first.d.ts +1 -64
- package/dist/shared/flap/portal-bundle-merkle/swap-buy-first.js +66 -247
- package/dist/shared/flap/portal-bundle-merkle/swap-helpers.d.ts +149 -0
- package/dist/shared/flap/portal-bundle-merkle/swap-helpers.js +259 -0
- package/dist/shared/flap/portal-bundle-merkle/swap.d.ts +2 -71
- package/dist/shared/flap/portal-bundle-merkle/swap.js +103 -410
- package/dist/shared/flap/portal-bundle-merkle/types.d.ts +83 -9
- package/dist/shared/flap/portal-bundle-merkle/utils.d.ts +1 -80
- package/dist/shared/flap/portal-bundle-merkle/utils.js +145 -265
- package/dist/shared/flap/portal-bundle.js +55 -56
- package/dist/shared/flap/portal-create-token.d.ts +77 -0
- package/dist/shared/flap/portal-create-token.js +214 -0
- package/dist/shared/flap/portal.d.ts +14 -3
- package/dist/shared/flap/portal.js +50 -25
- package/dist/shared/flap/vanity.d.ts +1 -5
- package/dist/shared/flap/vanity.js +6 -17
- package/dist/shared/flap/vault.d.ts +17 -124
- package/dist/shared/flap/vault.js +67 -148
- package/dist/shared/foundation/dex/v3-path.d.ts +6 -0
- package/dist/shared/foundation/dex/v3-path.js +35 -0
- package/dist/shared/foundation/gas/bundle-gas.d.ts +49 -0
- package/dist/shared/foundation/gas/bundle-gas.js +93 -0
- package/dist/shared/foundation/gas/profit-hop.d.ts +20 -0
- package/dist/shared/foundation/gas/profit-hop.js +72 -0
- package/dist/shared/foundation/index.d.ts +13 -0
- package/dist/shared/foundation/index.js +12 -0
- package/dist/shared/foundation/nonce/nonce-manager.d.ts +17 -0
- package/dist/shared/foundation/nonce/nonce-manager.js +183 -0
- package/dist/shared/foundation/normalize-unknown.d.ts +9 -0
- package/dist/shared/foundation/normalize-unknown.js +29 -0
- package/dist/shared/foundation/sdk-logger.d.ts +13 -0
- package/dist/shared/foundation/sdk-logger.js +12 -0
- package/dist/shared/foundation/tx/build-request.d.ts +17 -0
- package/dist/shared/foundation/tx/build-request.js +25 -0
- package/dist/shared/foundation/tx/sign-batch.d.ts +5 -0
- package/dist/shared/foundation/tx/sign-batch.js +26 -0
- package/dist/shared/foundation/tx/wallet-sign-patch.d.ts +1 -0
- package/dist/shared/foundation/tx/wallet-sign-patch.js +18 -0
- package/dist/shared/foundation/types/airdrop-sweep.d.ts +79 -0
- package/dist/shared/foundation/types/airdrop-sweep.js +1 -0
- package/dist/shared/foundation/types/erc20.d.ts +65 -0
- package/dist/shared/foundation/types/erc20.js +1 -0
- package/dist/shared/foundation/types/holders-maker.d.ts +64 -0
- package/dist/shared/foundation/types/holders-maker.js +1 -0
- package/dist/shared/foundation/types/index.d.ts +7 -0
- package/dist/shared/foundation/types/index.js +1 -0
- package/dist/shared/foundation/types/lp-inspect.d.ts +102 -0
- package/dist/shared/foundation/types/lp-inspect.js +1 -0
- package/dist/shared/foundation/types/multicall.d.ts +5 -0
- package/dist/shared/foundation/types/multicall.js +1 -0
- package/dist/shared/foundation/types/private-sale.d.ts +35 -0
- package/dist/shared/foundation/types/private-sale.js +1 -0
- package/dist/shared/foundation/types/quote-helpers.d.ts +17 -0
- package/dist/shared/foundation/types/quote-helpers.js +1 -0
- package/dist/shared/four/tax-token.d.ts +1 -1
- package/dist/shared/four/tax-token.js +27 -7
- package/dist/shared/index.d.ts +6 -0
- package/dist/shared/index.js +4 -0
- package/dist/types/errors.d.ts +27 -0
- package/dist/types/errors.js +34 -0
- package/dist/utils/airdrop-sweep.d.ts +4 -76
- package/dist/utils/airdrop-sweep.js +42 -55
- package/dist/utils/bundle-helpers.d.ts +9 -243
- package/dist/utils/bundle-helpers.js +10 -584
- package/dist/utils/constants.d.ts +5 -61
- package/dist/utils/constants.js +5 -80
- package/dist/utils/contract-factory.d.ts +2 -4
- package/dist/utils/contract-factory.js +25 -18
- package/dist/utils/erc20.d.ts +7 -89
- package/dist/utils/erc20.js +94 -125
- package/dist/utils/errors.d.ts +12 -1
- package/dist/utils/errors.js +60 -1
- package/dist/utils/holders-maker/addresses.d.ts +12 -0
- package/dist/utils/holders-maker/addresses.js +15 -0
- package/dist/utils/holders-maker/buy-tx.d.ts +44 -0
- package/dist/utils/holders-maker/buy-tx.js +278 -0
- package/dist/utils/holders-maker/constants.d.ts +6 -0
- package/dist/utils/holders-maker/constants.js +7 -0
- package/dist/utils/holders-maker/disperse.d.ts +18 -0
- package/dist/utils/holders-maker/disperse.js +90 -0
- package/dist/utils/holders-maker/routing.d.ts +4 -0
- package/dist/utils/holders-maker/routing.js +45 -0
- package/dist/utils/holders-maker/transfer-tx.d.ts +4 -0
- package/dist/utils/holders-maker/transfer-tx.js +67 -0
- package/dist/utils/holders-maker-helpers.d.ts +9 -0
- package/dist/utils/holders-maker-helpers.js +9 -0
- package/dist/utils/holders-maker.d.ts +2 -138
- package/dist/utils/holders-maker.js +26 -661
- package/dist/utils/hop-chains.d.ts +35 -0
- package/dist/utils/hop-chains.js +215 -0
- package/dist/utils/lp-inspect-helpers.d.ts +9 -0
- package/dist/utils/lp-inspect-helpers.js +109 -0
- package/dist/utils/lp-inspect.d.ts +2 -112
- package/dist/utils/lp-inspect.js +73 -223
- package/dist/utils/mpcExclusive.d.ts +2 -5
- package/dist/utils/mpcExclusive.js +4 -3
- package/dist/utils/private-sale.d.ts +2 -58
- package/dist/utils/private-sale.js +4 -15
- package/dist/utils/provider-factory.d.ts +4 -0
- package/dist/utils/provider-factory.js +10 -0
- package/dist/utils/quote-helpers.d.ts +4 -45
- package/dist/utils/quote-helpers.js +17 -74
- package/dist/utils/stealth-transfer.d.ts +2 -28
- package/dist/utils/stealth-transfer.js +31 -15
- package/dist/utils/swap-helpers.d.ts +2 -15
- package/dist/utils/swap-helpers.js +6 -11
- package/dist/utils/types/airdrop-sweep.d.ts +1 -0
- package/dist/utils/types/airdrop-sweep.js +1 -0
- package/dist/utils/types/contract-factory.d.ts +1 -0
- package/dist/utils/types/contract-factory.js +1 -0
- package/dist/utils/types/erc20.d.ts +1 -0
- package/dist/utils/types/erc20.js +1 -0
- package/dist/utils/types/errors.d.ts +1 -0
- package/dist/utils/types/errors.js +1 -0
- package/dist/utils/types/holders-maker.d.ts +1 -0
- package/dist/utils/types/holders-maker.js +1 -0
- package/dist/utils/types/hop-chains.d.ts +8 -0
- package/dist/utils/types/hop-chains.js +1 -0
- package/dist/utils/types/index.d.ts +13 -0
- package/dist/utils/types/index.js +1 -0
- package/dist/utils/types/lp-inspect.d.ts +1 -0
- package/dist/utils/types/lp-inspect.js +1 -0
- package/dist/utils/types/mpc-exclusive.d.ts +5 -0
- package/dist/utils/types/mpc-exclusive.js +1 -0
- package/dist/utils/types/private-sale.d.ts +1 -0
- package/dist/utils/types/private-sale.js +1 -0
- package/dist/utils/types/quote-helpers.d.ts +1 -0
- package/dist/utils/types/quote-helpers.js +1 -0
- package/dist/utils/types/stealth-transfer.d.ts +44 -0
- package/dist/utils/types/stealth-transfer.js +1 -0
- package/dist/utils/types/wallet.d.ts +25 -0
- package/dist/utils/types/wallet.js +1 -0
- package/dist/utils/wallet.d.ts +2 -25
- package/dist/utils/wallet.js +13 -10
- package/dist/vanity/index.d.ts +5 -0
- package/dist/vanity/index.js +5 -0
- package/package.json +160 -4
- package/src/abis/contracts/TaxToken.json +969 -0
- package/src/abis/contracts/TokenManager.json +836 -0
- package/src/abis/contracts/TokenManager2.json +136 -0
- package/src/abis/contracts/TokenManagerHelper3.json +993 -0
- package/dist/shared/abis/TaxToken.json +0 -105
- package/dist/shared/abis/TokenManager2.json +0 -60
- /package/dist/{shared/abis → abis/contracts}/TokenManager.json +0 -0
- /package/dist/{shared/abis → abis/contracts}/TokenManagerHelper3.json +0 -0
|
@@ -1,768 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Four.meme
|
|
3
|
-
*
|
|
4
|
-
* 功能:钱包A卖出代币 → 钱包B买入相同数量 → 原子执行
|
|
2
|
+
* Four.meme 内盘捆绑换手 — 实现见 bundle-core/four-meme/
|
|
5
3
|
*/
|
|
6
|
-
|
|
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
|
-
}
|
|
4
|
+
export { fourBundleSwapMerkle, fourBatchSwapMerkle, fourQuickBatchSwapMerkle, } from '../../../bundle-core/four-meme/swap.js';
|