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,128 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* 功能:钱包B先买入代币 → 钱包A卖出相同数量 → 原子执行
|
|
2
|
+
* bundle-buy-first - 主函数
|
|
5
3
|
*/
|
|
6
4
|
import { ethers, Contract, Wallet } from 'ethers';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
5
|
+
import { createSignProvider } from '../../../bundle-core/sign-context-helpers.js';
|
|
6
|
+
import { NonceManager, getDeadline, buildProfitHopTransactions, PROFIT_HOP_COUNT, } from '../../../utils/bundle-helpers.js';
|
|
7
|
+
import { BLOCKRAZOR_BUILDER_EOA, ZERO_ADDRESS } from '../../../shared/constants/index.js';
|
|
8
|
+
import { GAS_LIMITS, getProfitRecipient } from '../../../shared/constants/index.js';
|
|
10
9
|
import { quoteV2, quoteV3, getTokenToNativeQuote } from '../../../utils/quote-helpers.js';
|
|
11
|
-
import {
|
|
12
|
-
/**
|
|
13
|
-
* 获取 Gas Limit
|
|
14
|
-
*/
|
|
15
|
-
function getGasLimit(config, defaultGas = 800000) {
|
|
16
|
-
if (config.gasLimit !== undefined) {
|
|
17
|
-
return typeof config.gasLimit === 'bigint' ? config.gasLimit : BigInt(config.gasLimit);
|
|
18
|
-
}
|
|
19
|
-
const multiplier = config.gasLimitMultiplier ?? 1.0;
|
|
20
|
-
const calculatedGas = Math.ceil(defaultGas * multiplier);
|
|
21
|
-
return BigInt(calculatedGas);
|
|
22
|
-
}
|
|
23
|
-
async function getGasPrice(provider, config) {
|
|
24
|
-
const feeData = await provider.getFeeData();
|
|
25
|
-
let gasPrice = feeData.gasPrice || ethers.parseUnits('3', 'gwei');
|
|
26
|
-
if (config.minGasPriceGwei) {
|
|
27
|
-
const minGas = ethers.parseUnits(config.minGasPriceGwei.toString(), 'gwei');
|
|
28
|
-
if (gasPrice < minGas)
|
|
29
|
-
gasPrice = minGas;
|
|
30
|
-
}
|
|
31
|
-
if (config.maxGasPriceGwei) {
|
|
32
|
-
const maxGas = ethers.parseUnits(config.maxGasPriceGwei.toString(), 'gwei');
|
|
33
|
-
if (gasPrice > maxGas)
|
|
34
|
-
gasPrice = maxGas;
|
|
35
|
-
}
|
|
36
|
-
return gasPrice;
|
|
37
|
-
}
|
|
38
|
-
// ✅ ABI 别名(从公共模块导入)
|
|
39
|
-
const PANCAKE_V2_ROUTER_ABI = V2_ROUTER_ABI;
|
|
40
|
-
const PANCAKE_V3_ROUTER_ABI = V3_ROUTER02_ABI;
|
|
41
|
-
const ERC20_BALANCE_OF_ABI = ERC20_BALANCE_ABI;
|
|
42
|
-
// ✅ 使用官方 PancakeSwap Router 地址
|
|
43
|
-
const PANCAKE_V2_ROUTER_ADDRESS = ADDRESSES.BSC.PancakeV2Router;
|
|
44
|
-
const PANCAKE_V3_ROUTER_ADDRESS = ADDRESSES.BSC.PancakeV3Router;
|
|
45
|
-
// 常量
|
|
46
|
-
const FLAT_FEE = 0n;
|
|
47
|
-
// ==================== 多笔买卖常量 ====================
|
|
48
|
-
/** 最大 Bundle 签名数 */
|
|
49
|
-
const MAX_BUNDLE_SIGNATURES = 50;
|
|
50
|
-
/** 贿赂交易数 */
|
|
51
|
-
const BRIBE_TX_COUNT = 1;
|
|
52
|
-
/** 利润中转交易数(支付者 1 笔 + 中转钱包 PROFIT_HOP_COUNT 笔 + 最终接收 1 笔) */
|
|
53
|
-
const PROFIT_TX_COUNT = PROFIT_HOP_COUNT + 2; // 2 + 2 = 4
|
|
54
|
-
/** 最大买卖交易数 */
|
|
55
|
-
const MAX_SWAP_TX_COUNT = MAX_BUNDLE_SIGNATURES - BRIBE_TX_COUNT - PROFIT_TX_COUNT; // 50 - 1 - 4 = 45
|
|
56
|
-
/**
|
|
57
|
-
* 根据 userType 获取每笔交易的利润率
|
|
58
|
-
*/
|
|
59
|
-
function getProfitRatePerTxBps(userType) {
|
|
60
|
-
if (userType === 'v1') {
|
|
61
|
-
return PROFIT_CONFIG.RATE_BPS_V1_DOUBLE;
|
|
62
|
-
}
|
|
63
|
-
return PROFIT_CONFIG.RATE_BPS_V0_DOUBLE; // v0 或默认
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* 验证买卖笔数
|
|
67
|
-
*/
|
|
68
|
-
function validateSwapCounts(buyCount, sellCount) {
|
|
69
|
-
if (buyCount < 1) {
|
|
70
|
-
throw new Error(`买入笔数必须至少为 1,当前为 ${buyCount}`);
|
|
71
|
-
}
|
|
72
|
-
if (sellCount < 1) {
|
|
73
|
-
throw new Error(`卖出笔数必须至少为 1,当前为 ${sellCount}`);
|
|
74
|
-
}
|
|
75
|
-
const totalSwaps = buyCount + sellCount;
|
|
76
|
-
if (totalSwaps > MAX_SWAP_TX_COUNT) {
|
|
77
|
-
throw new Error(`买卖笔数总和 (${totalSwaps}) 超出限制 (${MAX_SWAP_TX_COUNT}),` +
|
|
78
|
-
`最大签名数为 ${MAX_BUNDLE_SIGNATURES}(${BRIBE_TX_COUNT} 贿赂 + ${PROFIT_TX_COUNT} 利润 + ${MAX_SWAP_TX_COUNT} 买卖)`);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* ✅ 将金额随机拆分成多份(更自然,不像机器人)
|
|
83
|
-
* 每份金额在平均值的 50%-150% 之间随机浮动
|
|
84
|
-
*/
|
|
85
|
-
function splitAmount(totalAmount, count) {
|
|
86
|
-
if (count <= 0) {
|
|
87
|
-
throw new Error('拆分份数必须大于 0');
|
|
88
|
-
}
|
|
89
|
-
if (count === 1) {
|
|
90
|
-
return [totalAmount];
|
|
91
|
-
}
|
|
92
|
-
// 生成随机权重(0.5 - 1.5 之间)
|
|
93
|
-
const weights = [];
|
|
94
|
-
for (let i = 0; i < count; i++) {
|
|
95
|
-
// 随机值在 0.5 - 1.5 之间,使每份金额有 ±50% 的浮动
|
|
96
|
-
weights.push(0.5 + Math.random());
|
|
97
|
-
}
|
|
98
|
-
// 计算权重总和
|
|
99
|
-
const totalWeight = weights.reduce((a, b) => a + b, 0);
|
|
100
|
-
// 根据权重分配金额
|
|
101
|
-
const amounts = [];
|
|
102
|
-
let allocated = 0n;
|
|
103
|
-
for (let i = 0; i < count - 1; i++) {
|
|
104
|
-
// 按权重比例分配
|
|
105
|
-
const ratio = weights[i] / totalWeight;
|
|
106
|
-
const amount = BigInt(Math.floor(Number(totalAmount) * ratio));
|
|
107
|
-
amounts.push(amount);
|
|
108
|
-
allocated += amount;
|
|
109
|
-
}
|
|
110
|
-
// 最后一份分配剩余的全部(确保总和精确)
|
|
111
|
-
amounts.push(totalAmount - allocated);
|
|
112
|
-
// 随机打乱顺序(让大小金额交错出现)
|
|
113
|
-
for (let i = amounts.length - 1; i > 0; i--) {
|
|
114
|
-
const j = Math.floor(Math.random() * (i + 1));
|
|
115
|
-
[amounts[i], amounts[j]] = [amounts[j], amounts[i]];
|
|
116
|
-
}
|
|
117
|
-
return amounts;
|
|
118
|
-
}
|
|
10
|
+
import { ERC20_BALANCE_OF_ABI, FLAT_FEE, PANCAKE_V2_ROUTER_ABI, PANCAKE_V2_ROUTER_ADDRESS, PANCAKE_V3_ROUTER_ABI, PANCAKE_V3_ROUTER_ADDRESS, getGasLimit, getGasPrice, getProfitRatePerTxBps, splitAmount, validateSwapCounts, } from './bundle-buy-first-helpers.js';
|
|
119
11
|
export async function pancakeBundleBuyFirstMerkle(params) {
|
|
120
|
-
const { buyerPrivateKey, buyerPrivateKeys, sellerPrivateKey, sellerPrivateKeys,
|
|
121
|
-
buyCount: _buyCount, sellCount: _sellCount, taxRateBps = 0 // ✅ 税率(基点),用于计算实际可卖出代币数量
|
|
12
|
+
const { buyerPrivateKey, buyerPrivateKeys, sellerPrivateKey, sellerPrivateKeys, routeParams, buyerFunds, buyerFundsPercentage, config, quoteToken, quoteTokenDecimals = 18, buyCount: _buyCount, sellCount: _sellCount, taxRateBps = 0, // ✅ 税率(基点),用于计算实际可卖出代币数量
|
|
122
13
|
} = params;
|
|
123
14
|
// ✅ 判断是否为多钱包模式
|
|
124
|
-
const isMultiWalletMode = !!(buyerPrivateKeys && buyerPrivateKeys.length > 0) ||
|
|
125
|
-
!!(sellerPrivateKeys && sellerPrivateKeys.length > 0);
|
|
15
|
+
const isMultiWalletMode = !!(buyerPrivateKeys && buyerPrivateKeys.length > 0) || !!(sellerPrivateKeys && sellerPrivateKeys.length > 0);
|
|
126
16
|
// ✅ 多钱包模式:buyCount/sellCount 代表钱包数量
|
|
127
17
|
// 单钱包模式(向后兼容):buyCount/sellCount 代表同一钱包执行的交易笔数
|
|
128
18
|
const buyCount = _buyCount ?? 1;
|
|
@@ -132,13 +22,12 @@ export async function pancakeBundleBuyFirstMerkle(params) {
|
|
|
132
22
|
return await pancakeBundleBuyFirstMultiWallet({
|
|
133
23
|
buyerPrivateKeys: buyerPrivateKeys || (buyerPrivateKey ? [buyerPrivateKey] : []),
|
|
134
24
|
sellerPrivateKeys: sellerPrivateKeys || (sellerPrivateKey ? [sellerPrivateKey] : []),
|
|
135
|
-
tokenAddress,
|
|
136
25
|
routeParams,
|
|
137
26
|
buyerFunds,
|
|
138
27
|
config,
|
|
139
28
|
quoteToken,
|
|
140
29
|
quoteTokenDecimals,
|
|
141
|
-
taxRateBps // ✅ 传递税率
|
|
30
|
+
taxRateBps, // ✅ 传递税率
|
|
142
31
|
});
|
|
143
32
|
}
|
|
144
33
|
// ✅ 单钱包模式(向后兼容):验证买卖笔数
|
|
@@ -163,13 +52,13 @@ export async function pancakeBundleBuyFirstMerkle(params) {
|
|
|
163
52
|
useNativeToken,
|
|
164
53
|
quoteToken,
|
|
165
54
|
quoteTokenDecimals,
|
|
166
|
-
provider: context.provider
|
|
55
|
+
provider: context.provider,
|
|
167
56
|
});
|
|
168
57
|
const quoteResult = await quoteTokenOutput({
|
|
169
58
|
routeParams,
|
|
170
59
|
buyerFundsWei: buyerFundsInfo.buyerFundsWei,
|
|
171
60
|
provider: context.provider,
|
|
172
|
-
v2RouterOverride: config.v2RouterAddress
|
|
61
|
+
v2RouterOverride: config.v2RouterAddress,
|
|
173
62
|
});
|
|
174
63
|
// ✅ 拆分买入和卖出金额
|
|
175
64
|
const buyAmountsWei = splitAmount(buyerFundsInfo.buyerFundsWei, buyCount);
|
|
@@ -179,7 +68,6 @@ export async function pancakeBundleBuyFirstMerkle(params) {
|
|
|
179
68
|
if (taxRateBps > 0) {
|
|
180
69
|
// 税率基点转换:500 bps = 5% = 0.05,实际获得 = 报价 * (10000 - 税率) / 10000
|
|
181
70
|
actualTokenOut = (quoteResult.quotedTokenOut * BigInt(10000 - taxRateBps)) / 10000n;
|
|
182
|
-
console.log(`[pancakeBundleBuyFirst] 税币模式: 税率=${taxRateBps}bps, 报价=${quoteResult.quotedTokenOut}, 实际可卖=${actualTokenOut}`);
|
|
183
71
|
}
|
|
184
72
|
const sellAmountsWei = splitAmount(actualTokenOut, sellCount);
|
|
185
73
|
// ✅ 构建多笔买入和卖出交易
|
|
@@ -189,9 +77,8 @@ export async function pancakeBundleBuyFirstMerkle(params) {
|
|
|
189
77
|
sellAmountsWei,
|
|
190
78
|
buyer,
|
|
191
79
|
seller,
|
|
192
|
-
tokenAddress,
|
|
193
80
|
useNativeToken,
|
|
194
|
-
v2RouterAddress: config.v2RouterAddress
|
|
81
|
+
v2RouterAddress: config.v2RouterAddress,
|
|
195
82
|
});
|
|
196
83
|
const finalGasLimit = getGasLimit(config);
|
|
197
84
|
const gasPrice = await getGasPrice(context.provider, config);
|
|
@@ -210,9 +97,7 @@ export async function pancakeBundleBuyFirstMerkle(params) {
|
|
|
210
97
|
// ERC20→BNB 转换完成
|
|
211
98
|
}
|
|
212
99
|
// ✅ 获取贿赂金额
|
|
213
|
-
const bribeAmount = config.bribeAmount && config.bribeAmount > 0
|
|
214
|
-
? ethers.parseEther(String(config.bribeAmount))
|
|
215
|
-
: 0n;
|
|
100
|
+
const bribeAmount = config.bribeAmount && config.bribeAmount > 0 ? ethers.parseEther(String(config.bribeAmount)) : 0n;
|
|
216
101
|
const needBribeTx = bribeAmount > 0n;
|
|
217
102
|
// ✅ 规划多笔交易 nonce(忽略 startNonces,使用新的多笔规划)
|
|
218
103
|
const multiNoncePlan = await planMultiNonces({
|
|
@@ -223,7 +108,7 @@ export async function pancakeBundleBuyFirstMerkle(params) {
|
|
|
223
108
|
sameAddress,
|
|
224
109
|
extractProfit: profitAmount > 0n,
|
|
225
110
|
needBribeTx,
|
|
226
|
-
nonceManager
|
|
111
|
+
nonceManager,
|
|
227
112
|
});
|
|
228
113
|
// ✅ 贿赂交易放在首位(由卖方发送,与利润交易同一钱包)
|
|
229
114
|
let bribeTx = null;
|
|
@@ -235,7 +120,7 @@ export async function pancakeBundleBuyFirstMerkle(params) {
|
|
|
235
120
|
gasPrice,
|
|
236
121
|
gasLimit: GAS_LIMITS.BRIBE,
|
|
237
122
|
chainId: context.chainId,
|
|
238
|
-
type: txType
|
|
123
|
+
type: txType,
|
|
239
124
|
});
|
|
240
125
|
}
|
|
241
126
|
// ✅ 并行签名所有买入交易
|
|
@@ -246,7 +131,7 @@ export async function pancakeBundleBuyFirstMerkle(params) {
|
|
|
246
131
|
gasLimit: finalGasLimit,
|
|
247
132
|
gasPrice,
|
|
248
133
|
chainId: context.chainId,
|
|
249
|
-
type: txType
|
|
134
|
+
type: txType,
|
|
250
135
|
})));
|
|
251
136
|
// ✅ 并行签名所有卖出交易
|
|
252
137
|
const signedSells = await Promise.all(swapUnsignedArray.sellUnsignedArray.map((unsigned, i) => seller.signTransaction({
|
|
@@ -256,7 +141,7 @@ export async function pancakeBundleBuyFirstMerkle(params) {
|
|
|
256
141
|
gasLimit: finalGasLimit,
|
|
257
142
|
gasPrice,
|
|
258
143
|
chainId: context.chainId,
|
|
259
|
-
type: txType
|
|
144
|
+
type: txType,
|
|
260
145
|
})));
|
|
261
146
|
nonceManager.clearTemp();
|
|
262
147
|
validateFinalBalances({
|
|
@@ -269,7 +154,7 @@ export async function pancakeBundleBuyFirstMerkle(params) {
|
|
|
269
154
|
useNativeToken,
|
|
270
155
|
quoteTokenDecimals,
|
|
271
156
|
provider: context.provider,
|
|
272
|
-
buyerAddress: buyer.address
|
|
157
|
+
buyerAddress: buyer.address,
|
|
273
158
|
});
|
|
274
159
|
// ✅ 组装顺序:贿赂 → 买入(多笔) → 卖出(多笔)(与 Flap 一致)
|
|
275
160
|
const allTransactions = [];
|
|
@@ -284,7 +169,7 @@ export async function pancakeBundleBuyFirstMerkle(params) {
|
|
|
284
169
|
profitNonce: multiNoncePlan.profitNonce,
|
|
285
170
|
gasPrice,
|
|
286
171
|
chainId: context.chainId,
|
|
287
|
-
txType
|
|
172
|
+
txType,
|
|
288
173
|
});
|
|
289
174
|
let profitHopWallets;
|
|
290
175
|
if (profitResult) {
|
|
@@ -306,22 +191,17 @@ export async function pancakeBundleBuyFirstMerkle(params) {
|
|
|
306
191
|
buyCount,
|
|
307
192
|
sellCount,
|
|
308
193
|
// ✅ 返回每笔交易的具体金额(随机分配后的数组)
|
|
309
|
-
buyAmounts: buyAmountsWei.map(amt => useNativeToken
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
sellAmounts: sellAmountsWei.map(amt => amt.toString())
|
|
313
|
-
}
|
|
194
|
+
buyAmounts: buyAmountsWei.map((amt) => useNativeToken ? ethers.formatEther(amt) : ethers.formatUnits(amt, quoteTokenDecimals)),
|
|
195
|
+
sellAmounts: sellAmountsWei.map((amt) => amt.toString()),
|
|
196
|
+
},
|
|
314
197
|
};
|
|
315
198
|
}
|
|
316
199
|
function createPancakeContext(config) {
|
|
317
200
|
const chainId = config.chainId ?? 56;
|
|
318
|
-
const provider =
|
|
319
|
-
chainId,
|
|
320
|
-
name: 'BSC'
|
|
321
|
-
});
|
|
201
|
+
const provider = createSignProvider(config.rpcUrl, chainId, 'BSC');
|
|
322
202
|
return { chainId, provider };
|
|
323
203
|
}
|
|
324
|
-
async function calculateBuyerFunds({ buyer, buyerFunds, buyerFundsPercentage, reserveGas, useNativeToken = true, quoteToken, quoteTokenDecimals = 18, provider }) {
|
|
204
|
+
async function calculateBuyerFunds({ buyer, buyerFunds, buyerFundsPercentage, reserveGas, useNativeToken = true, quoteToken, quoteTokenDecimals = 18, provider, }) {
|
|
325
205
|
const reserveGasWei = ethers.parseEther((reserveGas ?? 0.0005).toString());
|
|
326
206
|
// ✅ 根据是否使用原生代币获取不同的余额
|
|
327
207
|
let buyerBalance;
|
|
@@ -344,7 +224,9 @@ async function calculateBuyerFunds({ buyer, buyerFunds, buyerFundsPercentage, re
|
|
|
344
224
|
const pct = Math.max(0, Math.min(100, buyerFundsPercentage));
|
|
345
225
|
// ✅ 原生代币需要预留 Gas,ERC20 不需要
|
|
346
226
|
const spendable = useNativeToken
|
|
347
|
-
?
|
|
227
|
+
? buyerBalance > reserveGasWei
|
|
228
|
+
? buyerBalance - reserveGasWei
|
|
229
|
+
: 0n
|
|
348
230
|
: buyerBalance;
|
|
349
231
|
buyerFundsWei = (spendable * BigInt(Math.floor(pct * 100))) / 10000n;
|
|
350
232
|
}
|
|
@@ -376,7 +258,7 @@ async function calculateBuyerFunds({ buyer, buyerFunds, buyerFundsPercentage, re
|
|
|
376
258
|
/**
|
|
377
259
|
* ✅ 使用 quote-helpers 统一报价
|
|
378
260
|
*/
|
|
379
|
-
async function quoteTokenOutput({ routeParams, buyerFundsWei, provider, v2RouterOverride }) {
|
|
261
|
+
async function quoteTokenOutput({ routeParams, buyerFundsWei, provider, v2RouterOverride, }) {
|
|
380
262
|
// V2 路由
|
|
381
263
|
if (routeParams.routeType === 'v2') {
|
|
382
264
|
const { v2Path } = routeParams;
|
|
@@ -413,7 +295,7 @@ async function quoteTokenOutput({ routeParams, buyerFundsWei, provider, v2Router
|
|
|
413
295
|
/**
|
|
414
296
|
* ✅ 构建多笔买入和卖出交易
|
|
415
297
|
*/
|
|
416
|
-
async function buildMultiRouteTransactions({ routeParams, buyAmountsWei, sellAmountsWei, buyer, seller,
|
|
298
|
+
async function buildMultiRouteTransactions({ routeParams, buyAmountsWei, sellAmountsWei, buyer, seller, useNativeToken = true, v2RouterAddress, }) {
|
|
417
299
|
const deadline = getDeadline();
|
|
418
300
|
if (routeParams.routeType === 'v2') {
|
|
419
301
|
const { v2Path } = routeParams;
|
|
@@ -424,17 +306,17 @@ async function buildMultiRouteTransactions({ routeParams, buyAmountsWei, sellAmo
|
|
|
424
306
|
// ✅ 根据是否使用原生代币选择不同的函数
|
|
425
307
|
if (useNativeToken) {
|
|
426
308
|
// BNB 池子:使用 swapExactETHForTokens / swapExactTokensForETH
|
|
427
|
-
const buyUnsignedArray = await Promise.all(buyAmountsWei.map(amount => {
|
|
309
|
+
const buyUnsignedArray = await Promise.all(buyAmountsWei.map((amount) => {
|
|
428
310
|
const buyValue = amount + FLAT_FEE;
|
|
429
311
|
return v2RouterBuyer.swapExactETHForTokensSupportingFeeOnTransferTokens.populateTransaction(0n, v2Path, buyer.address, deadline, { value: buyValue });
|
|
430
312
|
}));
|
|
431
|
-
const sellUnsignedArray = await Promise.all(sellAmountsWei.map(amount => v2RouterSeller.swapExactTokensForETHSupportingFeeOnTransferTokens.populateTransaction(amount, 0n, reversePath, seller.address, deadline)));
|
|
313
|
+
const sellUnsignedArray = await Promise.all(sellAmountsWei.map((amount) => v2RouterSeller.swapExactTokensForETHSupportingFeeOnTransferTokens.populateTransaction(amount, 0n, reversePath, seller.address, deadline)));
|
|
432
314
|
return { buyUnsignedArray, sellUnsignedArray };
|
|
433
315
|
}
|
|
434
316
|
else {
|
|
435
317
|
// ✅ ERC20 池子(如 USDT):使用 swapExactTokensForTokens
|
|
436
|
-
const buyUnsignedArray = await Promise.all(buyAmountsWei.map(amount => v2RouterBuyer.swapExactTokensForTokensSupportingFeeOnTransferTokens.populateTransaction(amount, 0n, v2Path, buyer.address, deadline)));
|
|
437
|
-
const sellUnsignedArray = await Promise.all(sellAmountsWei.map(amount => v2RouterSeller.swapExactTokensForTokensSupportingFeeOnTransferTokens.populateTransaction(amount, 0n, reversePath, seller.address, deadline)));
|
|
318
|
+
const buyUnsignedArray = await Promise.all(buyAmountsWei.map((amount) => v2RouterBuyer.swapExactTokensForTokensSupportingFeeOnTransferTokens.populateTransaction(amount, 0n, v2Path, buyer.address, deadline)));
|
|
319
|
+
const sellUnsignedArray = await Promise.all(sellAmountsWei.map((amount) => v2RouterSeller.swapExactTokensForTokensSupportingFeeOnTransferTokens.populateTransaction(amount, 0n, reversePath, seller.address, deadline)));
|
|
438
320
|
return { buyUnsignedArray, sellUnsignedArray };
|
|
439
321
|
}
|
|
440
322
|
}
|
|
@@ -444,32 +326,36 @@ async function buildMultiRouteTransactions({ routeParams, buyAmountsWei, sellAmo
|
|
|
444
326
|
const v3RouterBuyer = new Contract(PANCAKE_V3_ROUTER_ADDRESS, PANCAKE_V3_ROUTER_ABI, buyer);
|
|
445
327
|
const v3RouterSeller = new Contract(PANCAKE_V3_ROUTER_ADDRESS, PANCAKE_V3_ROUTER_ABI, seller);
|
|
446
328
|
// 构建多笔买入交易(ERC20 模式 value = 0,因为通过代币授权支付)
|
|
447
|
-
const buyUnsignedArray = await Promise.all(buyAmountsWei.map(amount => {
|
|
329
|
+
const buyUnsignedArray = await Promise.all(buyAmountsWei.map((amount) => {
|
|
448
330
|
const buyValue = useNativeToken ? amount + FLAT_FEE : 0n;
|
|
449
|
-
const buySwapData = v3RouterIface.encodeFunctionData('exactInputSingle', [
|
|
331
|
+
const buySwapData = v3RouterIface.encodeFunctionData('exactInputSingle', [
|
|
332
|
+
{
|
|
450
333
|
tokenIn: v3TokenIn,
|
|
451
334
|
tokenOut: v3TokenOut,
|
|
452
335
|
fee: v3Fee,
|
|
453
336
|
recipient: buyer.address,
|
|
454
337
|
amountIn: amount,
|
|
455
338
|
amountOutMinimum: 0n,
|
|
456
|
-
sqrtPriceLimitX96: 0n
|
|
457
|
-
}
|
|
339
|
+
sqrtPriceLimitX96: 0n,
|
|
340
|
+
},
|
|
341
|
+
]);
|
|
458
342
|
return v3RouterBuyer.multicall.populateTransaction(deadline, [buySwapData], { value: buyValue });
|
|
459
343
|
}));
|
|
460
344
|
// ✅ 根据是否使用原生代币构建不同的卖出交易
|
|
461
345
|
if (useNativeToken) {
|
|
462
346
|
// BNB 池子:卖出后 unwrap WBNB 为 BNB
|
|
463
|
-
const sellUnsignedArray = await Promise.all(sellAmountsWei.map(amount => {
|
|
464
|
-
const sellSwapData = v3RouterIface.encodeFunctionData('exactInputSingle', [
|
|
347
|
+
const sellUnsignedArray = await Promise.all(sellAmountsWei.map((amount) => {
|
|
348
|
+
const sellSwapData = v3RouterIface.encodeFunctionData('exactInputSingle', [
|
|
349
|
+
{
|
|
465
350
|
tokenIn: v3TokenOut,
|
|
466
351
|
tokenOut: v3TokenIn,
|
|
467
352
|
fee: v3Fee,
|
|
468
353
|
recipient: PANCAKE_V3_ROUTER_ADDRESS,
|
|
469
354
|
amountIn: amount,
|
|
470
355
|
amountOutMinimum: 0n,
|
|
471
|
-
sqrtPriceLimitX96: 0n
|
|
472
|
-
}
|
|
356
|
+
sqrtPriceLimitX96: 0n,
|
|
357
|
+
},
|
|
358
|
+
]);
|
|
473
359
|
const sellUnwrapData = v3RouterIface.encodeFunctionData('unwrapWETH9', [0n, seller.address]);
|
|
474
360
|
return v3RouterSeller.multicall.populateTransaction(deadline, [sellSwapData, sellUnwrapData]);
|
|
475
361
|
}));
|
|
@@ -477,16 +363,18 @@ async function buildMultiRouteTransactions({ routeParams, buyAmountsWei, sellAmo
|
|
|
477
363
|
}
|
|
478
364
|
else {
|
|
479
365
|
// ✅ ERC20 池子:卖出后直接获得 ERC20
|
|
480
|
-
const sellUnsignedArray = await Promise.all(sellAmountsWei.map(amount => {
|
|
481
|
-
const sellSwapData = v3RouterIface.encodeFunctionData('exactInputSingle', [
|
|
366
|
+
const sellUnsignedArray = await Promise.all(sellAmountsWei.map((amount) => {
|
|
367
|
+
const sellSwapData = v3RouterIface.encodeFunctionData('exactInputSingle', [
|
|
368
|
+
{
|
|
482
369
|
tokenIn: v3TokenOut,
|
|
483
370
|
tokenOut: v3TokenIn,
|
|
484
371
|
fee: v3Fee,
|
|
485
372
|
recipient: seller.address, // 直接发送到卖方地址
|
|
486
373
|
amountIn: amount,
|
|
487
374
|
amountOutMinimum: 0n,
|
|
488
|
-
sqrtPriceLimitX96: 0n
|
|
489
|
-
}
|
|
375
|
+
sqrtPriceLimitX96: 0n,
|
|
376
|
+
},
|
|
377
|
+
]);
|
|
490
378
|
return v3RouterSeller.multicall.populateTransaction(deadline, [sellSwapData]);
|
|
491
379
|
}));
|
|
492
380
|
return { buyUnsignedArray, sellUnsignedArray };
|
|
@@ -498,7 +386,7 @@ async function buildMultiRouteTransactions({ routeParams, buyAmountsWei, sellAmo
|
|
|
498
386
|
* ✅ 规划多笔交易 nonce(与 Flap 一致)
|
|
499
387
|
* 交易顺序:贿赂 → 买入(多笔) → 卖出(多笔) → 利润
|
|
500
388
|
*/
|
|
501
|
-
async function planMultiNonces({ buyer, seller, buyCount, sellCount, sameAddress, extractProfit, needBribeTx, nonceManager }) {
|
|
389
|
+
async function planMultiNonces({ buyer, seller, buyCount, sellCount, sameAddress, extractProfit, needBribeTx, nonceManager, }) {
|
|
502
390
|
const profitNonceCount = extractProfit ? 1 : 0;
|
|
503
391
|
if (sameAddress) {
|
|
504
392
|
// 同一地址:贿赂(可选) + 买入(多笔) + 卖出(多笔) + 利润(可选)
|
|
@@ -510,8 +398,7 @@ async function planMultiNonces({ buyer, seller, buyCount, sellCount, sameAddress
|
|
|
510
398
|
const buyerNonces = nonces.slice(idx, idx + buyCount);
|
|
511
399
|
idx += buyCount;
|
|
512
400
|
const sellerNonces = nonces.slice(idx, idx + sellCount);
|
|
513
|
-
idx
|
|
514
|
-
const profitNonce = extractProfit ? nonces[idx] : undefined;
|
|
401
|
+
const profitNonce = extractProfit ? nonces[idx + sellCount] : undefined;
|
|
515
402
|
return { buyerNonces, sellerNonces, bribeNonce, profitNonce };
|
|
516
403
|
}
|
|
517
404
|
// 不同地址
|
|
@@ -521,19 +408,18 @@ async function planMultiNonces({ buyer, seller, buyCount, sellCount, sameAddress
|
|
|
521
408
|
const sellerTxCount = bribeTxCount + sellCount + profitNonceCount;
|
|
522
409
|
const [buyerNonces, sellerNoncesAll] = await Promise.all([
|
|
523
410
|
nonceManager.getNextNonceBatch(buyer, buyCount),
|
|
524
|
-
nonceManager.getNextNonceBatch(seller, sellerTxCount)
|
|
411
|
+
nonceManager.getNextNonceBatch(seller, sellerTxCount),
|
|
525
412
|
]);
|
|
526
413
|
let idx = 0;
|
|
527
414
|
const bribeNonce = needBribeTx ? sellerNoncesAll[idx++] : undefined;
|
|
528
415
|
const sellerNonces = sellerNoncesAll.slice(idx, idx + sellCount);
|
|
529
|
-
idx
|
|
530
|
-
const profitNonce = extractProfit ? sellerNoncesAll[idx] : undefined;
|
|
416
|
+
const profitNonce = extractProfit ? sellerNoncesAll[idx + sellCount] : undefined;
|
|
531
417
|
return { buyerNonces, sellerNonces, bribeNonce, profitNonce };
|
|
532
418
|
}
|
|
533
419
|
/**
|
|
534
420
|
* 构建利润多跳转账交易(强制 2 跳中转)
|
|
535
421
|
*/
|
|
536
|
-
async function buildProfitTransaction({ provider, seller, profitAmount, profitNonce, gasPrice, chainId, txType }) {
|
|
422
|
+
async function buildProfitTransaction({ provider, seller, profitAmount, profitNonce, gasPrice, chainId, txType, }) {
|
|
537
423
|
if (profitNonce === undefined || profitAmount === 0n) {
|
|
538
424
|
return null;
|
|
539
425
|
}
|
|
@@ -541,16 +427,16 @@ async function buildProfitTransaction({ provider, seller, profitAmount, profitNo
|
|
|
541
427
|
provider,
|
|
542
428
|
payerWallet: seller,
|
|
543
429
|
profitAmount,
|
|
544
|
-
profitRecipient:
|
|
430
|
+
profitRecipient: getProfitRecipient(),
|
|
545
431
|
hopCount: PROFIT_HOP_COUNT,
|
|
546
432
|
gasPrice,
|
|
547
433
|
chainId,
|
|
548
434
|
txType,
|
|
549
|
-
startNonce: profitNonce
|
|
435
|
+
startNonce: profitNonce,
|
|
550
436
|
});
|
|
551
437
|
return { signedTransactions: profitHopResult.signedTransactions, hopWallets: profitHopResult.hopWallets };
|
|
552
438
|
}
|
|
553
|
-
async function validateFinalBalances({ sameAddress, buyerFundsWei, buyerBalance, reserveGas, gasLimit, gasPrice, useNativeToken = true, quoteTokenDecimals = 18, provider, buyerAddress }) {
|
|
439
|
+
async function validateFinalBalances({ sameAddress, buyerFundsWei, buyerBalance, reserveGas, gasLimit, gasPrice, useNativeToken = true, quoteTokenDecimals = 18, provider, buyerAddress, }) {
|
|
554
440
|
const gasCost = gasLimit * gasPrice;
|
|
555
441
|
if (sameAddress) {
|
|
556
442
|
// 同一地址:需要足够的余额支付两笔交易
|
|
@@ -594,7 +480,7 @@ async function validateFinalBalances({ sameAddress, buyerFundsWei, buyerBalance,
|
|
|
594
480
|
* - ✅ 优化:最大化并行操作
|
|
595
481
|
*/
|
|
596
482
|
async function pancakeBundleBuyFirstMultiWallet(params) {
|
|
597
|
-
const { buyerPrivateKeys, sellerPrivateKeys,
|
|
483
|
+
const { buyerPrivateKeys, sellerPrivateKeys, routeParams, buyerFunds, config, quoteToken, quoteTokenDecimals = 18, taxRateBps = 0, // ✅ 税率(基点)
|
|
598
484
|
} = params;
|
|
599
485
|
const buyCount = buyerPrivateKeys.length;
|
|
600
486
|
const sellCount = sellerPrivateKeys.length;
|
|
@@ -612,8 +498,8 @@ async function pancakeBundleBuyFirstMultiWallet(params) {
|
|
|
612
498
|
const context = createPancakeContext(config);
|
|
613
499
|
const nonceManager = new NonceManager(context.provider);
|
|
614
500
|
// 创建所有钱包实例
|
|
615
|
-
const buyers = buyerPrivateKeys.map(pk => new Wallet(pk, context.provider));
|
|
616
|
-
const sellers = sellerPrivateKeys.map(pk => new Wallet(pk, context.provider));
|
|
501
|
+
const buyers = buyerPrivateKeys.map((pk) => new Wallet(pk, context.provider));
|
|
502
|
+
const sellers = sellerPrivateKeys.map((pk) => new Wallet(pk, context.provider));
|
|
617
503
|
// 使用第一个卖方作为主卖方(支付贿赂和利润)
|
|
618
504
|
const mainSeller = sellers[0];
|
|
619
505
|
// ✅ 计算总交易金额
|
|
@@ -632,16 +518,14 @@ async function pancakeBundleBuyFirstMultiWallet(params) {
|
|
|
632
518
|
const finalGasLimit = getGasLimit(config);
|
|
633
519
|
const txType = config.txType ?? 0;
|
|
634
520
|
const deadline = BigInt(getDeadline());
|
|
635
|
-
const bribeAmount = config.bribeAmount && config.bribeAmount > 0
|
|
636
|
-
? ethers.parseEther(String(config.bribeAmount))
|
|
637
|
-
: 0n;
|
|
521
|
+
const bribeAmount = config.bribeAmount && config.bribeAmount > 0 ? ethers.parseEther(String(config.bribeAmount)) : 0n;
|
|
638
522
|
const needBribeTx = bribeAmount > 0n;
|
|
639
523
|
// ✅ 第一批并行:报价 + Gas价格 + 所有钱包 nonces
|
|
640
524
|
// 预先计算所有唯一钱包地址(去重)
|
|
641
525
|
const allWallets = [...sellers, ...buyers];
|
|
642
526
|
const uniqueWallets = allWallets.filter((w, i) => {
|
|
643
527
|
const addr = w.address.toLowerCase();
|
|
644
|
-
const firstIdx = allWallets.findIndex(x => x.address.toLowerCase() === addr);
|
|
528
|
+
const firstIdx = allWallets.findIndex((x) => x.address.toLowerCase() === addr);
|
|
645
529
|
return firstIdx === i;
|
|
646
530
|
});
|
|
647
531
|
const [quoteResult, gasPrice, noncesArray] = await Promise.all([
|
|
@@ -649,10 +533,10 @@ async function pancakeBundleBuyFirstMultiWallet(params) {
|
|
|
649
533
|
routeParams,
|
|
650
534
|
buyerFundsWei: totalFundsWei,
|
|
651
535
|
provider: context.provider,
|
|
652
|
-
v2RouterOverride: config.v2RouterAddress
|
|
536
|
+
v2RouterOverride: config.v2RouterAddress,
|
|
653
537
|
}),
|
|
654
538
|
getGasPrice(context.provider, config),
|
|
655
|
-
nonceManager.getNextNoncesForWallets(uniqueWallets)
|
|
539
|
+
nonceManager.getNextNoncesForWallets(uniqueWallets),
|
|
656
540
|
]);
|
|
657
541
|
// 构建 nonces Map
|
|
658
542
|
const noncesMap = new Map();
|
|
@@ -665,7 +549,6 @@ async function pancakeBundleBuyFirstMultiWallet(params) {
|
|
|
665
549
|
let actualTokenOut = quoteResult.quotedTokenOut;
|
|
666
550
|
if (taxRateBps > 0) {
|
|
667
551
|
actualTokenOut = (quoteResult.quotedTokenOut * BigInt(10000 - taxRateBps)) / 10000n;
|
|
668
|
-
console.log(`[pancakeBundleBuyFirstMultiWallet] 税币模式: 税率=${taxRateBps}bps, 报价=${quoteResult.quotedTokenOut}, 实际可卖=${actualTokenOut}`);
|
|
669
552
|
}
|
|
670
553
|
// ✅ 将代币平均分配给卖方
|
|
671
554
|
const sellAmountsWei = splitAmount(actualTokenOut, sellCount);
|
|
@@ -695,19 +578,19 @@ async function pancakeBundleBuyFirstMultiWallet(params) {
|
|
|
695
578
|
gasPrice,
|
|
696
579
|
gasLimit: GAS_LIMITS.BRIBE,
|
|
697
580
|
chainId: context.chainId,
|
|
698
|
-
type: txType
|
|
581
|
+
type: txType,
|
|
699
582
|
});
|
|
700
583
|
}
|
|
701
584
|
// 2. 预分配所有 nonces(同步操作,避免竞态)
|
|
702
585
|
const buyerNonces = [];
|
|
703
586
|
const sellerNonces = [];
|
|
704
|
-
buyers.forEach(buyer => {
|
|
587
|
+
buyers.forEach((buyer) => {
|
|
705
588
|
const addr = buyer.address.toLowerCase();
|
|
706
589
|
const nonce = noncesMap.get(addr);
|
|
707
590
|
buyerNonces.push(nonce);
|
|
708
591
|
noncesMap.set(addr, nonce + 1);
|
|
709
592
|
});
|
|
710
|
-
sellers.forEach(seller => {
|
|
593
|
+
sellers.forEach((seller) => {
|
|
711
594
|
const addr = seller.address.toLowerCase();
|
|
712
595
|
const nonce = noncesMap.get(addr);
|
|
713
596
|
sellerNonces.push(nonce);
|
|
@@ -719,10 +602,9 @@ async function pancakeBundleBuyFirstMultiWallet(params) {
|
|
|
719
602
|
routeParams,
|
|
720
603
|
buyAmount: buyAmountsWei[i],
|
|
721
604
|
buyer,
|
|
722
|
-
tokenAddress,
|
|
723
605
|
useNativeToken,
|
|
724
606
|
deadline,
|
|
725
|
-
v2RouterAddress: config.v2RouterAddress
|
|
607
|
+
v2RouterAddress: config.v2RouterAddress,
|
|
726
608
|
});
|
|
727
609
|
return buyer.signTransaction({
|
|
728
610
|
...unsigned,
|
|
@@ -731,7 +613,7 @@ async function pancakeBundleBuyFirstMultiWallet(params) {
|
|
|
731
613
|
gasLimit: finalGasLimit,
|
|
732
614
|
gasPrice,
|
|
733
615
|
chainId: context.chainId,
|
|
734
|
-
type: txType
|
|
616
|
+
type: txType,
|
|
735
617
|
});
|
|
736
618
|
});
|
|
737
619
|
// 4. 并行构建所有卖出交易
|
|
@@ -740,10 +622,9 @@ async function pancakeBundleBuyFirstMultiWallet(params) {
|
|
|
740
622
|
routeParams,
|
|
741
623
|
sellAmount: sellAmountsWei[i],
|
|
742
624
|
seller,
|
|
743
|
-
tokenAddress,
|
|
744
625
|
useNativeToken,
|
|
745
626
|
deadline,
|
|
746
|
-
v2RouterAddress: config.v2RouterAddress
|
|
627
|
+
v2RouterAddress: config.v2RouterAddress,
|
|
747
628
|
});
|
|
748
629
|
return seller.signTransaction({
|
|
749
630
|
...unsigned,
|
|
@@ -752,14 +633,14 @@ async function pancakeBundleBuyFirstMultiWallet(params) {
|
|
|
752
633
|
gasLimit: finalGasLimit,
|
|
753
634
|
gasPrice,
|
|
754
635
|
chainId: context.chainId,
|
|
755
|
-
type: txType
|
|
636
|
+
type: txType,
|
|
756
637
|
});
|
|
757
638
|
});
|
|
758
639
|
// ✅ 并行签名所有交易(贿赂 + 买入 + 卖出)
|
|
759
640
|
const [bribeTx, signedBuys, signedSells] = await Promise.all([
|
|
760
641
|
bribeTxPromise,
|
|
761
642
|
Promise.all(buyTxPromises),
|
|
762
|
-
Promise.all(sellTxPromises)
|
|
643
|
+
Promise.all(sellTxPromises),
|
|
763
644
|
]);
|
|
764
645
|
// 组装交易顺序:贿赂 → 买入 → 卖出
|
|
765
646
|
if (bribeTx)
|
|
@@ -777,7 +658,7 @@ async function pancakeBundleBuyFirstMultiWallet(params) {
|
|
|
777
658
|
profitNonce,
|
|
778
659
|
gasPrice,
|
|
779
660
|
chainId: context.chainId,
|
|
780
|
-
txType
|
|
661
|
+
txType,
|
|
781
662
|
});
|
|
782
663
|
if (profitResult) {
|
|
783
664
|
allTransactions.push(...profitResult.signedTransactions);
|
|
@@ -789,8 +670,8 @@ async function pancakeBundleBuyFirstMultiWallet(params) {
|
|
|
789
670
|
signedTransactions: allTransactions,
|
|
790
671
|
profitHopWallets,
|
|
791
672
|
metadata: {
|
|
792
|
-
buyerAddress: buyers.map(b => b.address).join(','),
|
|
793
|
-
sellerAddress: sellers.map(s => s.address).join(','),
|
|
673
|
+
buyerAddress: buyers.map((b) => b.address).join(','),
|
|
674
|
+
sellerAddress: sellers.map((s) => s.address).join(','),
|
|
794
675
|
buyAmount: useNativeToken
|
|
795
676
|
? ethers.formatEther(totalFundsWei)
|
|
796
677
|
: ethers.formatUnits(totalFundsWei, quoteTokenDecimals),
|
|
@@ -798,15 +679,13 @@ async function pancakeBundleBuyFirstMultiWallet(params) {
|
|
|
798
679
|
profitAmount: profitAmount > 0n ? ethers.formatEther(profitAmount) : undefined,
|
|
799
680
|
buyCount,
|
|
800
681
|
sellCount,
|
|
801
|
-
buyAmounts: buyAmountsWei.map(amt => useNativeToken
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
sellAmounts: sellAmountsWei.map(amt => amt.toString())
|
|
805
|
-
}
|
|
682
|
+
buyAmounts: buyAmountsWei.map((amt) => useNativeToken ? ethers.formatEther(amt) : ethers.formatUnits(amt, quoteTokenDecimals)),
|
|
683
|
+
sellAmounts: sellAmountsWei.map((amt) => amt.toString()),
|
|
684
|
+
},
|
|
806
685
|
};
|
|
807
686
|
}
|
|
808
687
|
// ✅ 构建单笔买入交易
|
|
809
|
-
async function buildSingleBuyTx({ routeParams, buyAmount, buyer,
|
|
688
|
+
async function buildSingleBuyTx({ routeParams, buyAmount, buyer, useNativeToken, deadline, v2RouterAddress, }) {
|
|
810
689
|
if (routeParams.routeType === 'v2') {
|
|
811
690
|
const { v2Path } = routeParams;
|
|
812
691
|
const v2Router = new Contract(v2RouterAddress || PANCAKE_V2_ROUTER_ADDRESS, PANCAKE_V2_ROUTER_ABI, buyer);
|
|
@@ -822,21 +701,23 @@ async function buildSingleBuyTx({ routeParams, buyAmount, buyer, tokenAddress, u
|
|
|
822
701
|
const v3RouterIface = new ethers.Interface(PANCAKE_V3_ROUTER_ABI);
|
|
823
702
|
const v3Router = new Contract(PANCAKE_V3_ROUTER_ADDRESS, PANCAKE_V3_ROUTER_ABI, buyer);
|
|
824
703
|
const buyValue = useNativeToken ? buyAmount : 0n;
|
|
825
|
-
const buySwapData = v3RouterIface.encodeFunctionData('exactInputSingle', [
|
|
704
|
+
const buySwapData = v3RouterIface.encodeFunctionData('exactInputSingle', [
|
|
705
|
+
{
|
|
826
706
|
tokenIn: v3TokenIn,
|
|
827
707
|
tokenOut: v3TokenOut,
|
|
828
708
|
fee: v3Fee,
|
|
829
709
|
recipient: buyer.address,
|
|
830
710
|
amountIn: buyAmount,
|
|
831
711
|
amountOutMinimum: 0n,
|
|
832
|
-
sqrtPriceLimitX96: 0n
|
|
833
|
-
}
|
|
712
|
+
sqrtPriceLimitX96: 0n,
|
|
713
|
+
},
|
|
714
|
+
]);
|
|
834
715
|
return await v3Router.multicall.populateTransaction(deadline, [buySwapData], { value: buyValue });
|
|
835
716
|
}
|
|
836
717
|
throw new Error('V3 多跳路由暂不支持');
|
|
837
718
|
}
|
|
838
719
|
// ✅ 构建单笔卖出交易
|
|
839
|
-
async function buildSingleSellTx({ routeParams, sellAmount, seller,
|
|
720
|
+
async function buildSingleSellTx({ routeParams, sellAmount, seller, useNativeToken, deadline, v2RouterAddress, }) {
|
|
840
721
|
if (routeParams.routeType === 'v2') {
|
|
841
722
|
const { v2Path } = routeParams;
|
|
842
723
|
const reversePath = [...v2Path].reverse();
|
|
@@ -853,28 +734,32 @@ async function buildSingleSellTx({ routeParams, sellAmount, seller, tokenAddress
|
|
|
853
734
|
const v3RouterIface = new ethers.Interface(PANCAKE_V3_ROUTER_ABI);
|
|
854
735
|
const v3Router = new Contract(PANCAKE_V3_ROUTER_ADDRESS, PANCAKE_V3_ROUTER_ABI, seller);
|
|
855
736
|
if (useNativeToken) {
|
|
856
|
-
const sellSwapData = v3RouterIface.encodeFunctionData('exactInputSingle', [
|
|
737
|
+
const sellSwapData = v3RouterIface.encodeFunctionData('exactInputSingle', [
|
|
738
|
+
{
|
|
857
739
|
tokenIn: v3TokenOut,
|
|
858
740
|
tokenOut: v3TokenIn,
|
|
859
741
|
fee: v3Fee,
|
|
860
742
|
recipient: PANCAKE_V3_ROUTER_ADDRESS,
|
|
861
743
|
amountIn: sellAmount,
|
|
862
744
|
amountOutMinimum: 0n,
|
|
863
|
-
sqrtPriceLimitX96: 0n
|
|
864
|
-
}
|
|
745
|
+
sqrtPriceLimitX96: 0n,
|
|
746
|
+
},
|
|
747
|
+
]);
|
|
865
748
|
const sellUnwrapData = v3RouterIface.encodeFunctionData('unwrapWETH9', [0n, seller.address]);
|
|
866
749
|
return await v3Router.multicall.populateTransaction(deadline, [sellSwapData, sellUnwrapData]);
|
|
867
750
|
}
|
|
868
751
|
else {
|
|
869
|
-
const sellSwapData = v3RouterIface.encodeFunctionData('exactInputSingle', [
|
|
752
|
+
const sellSwapData = v3RouterIface.encodeFunctionData('exactInputSingle', [
|
|
753
|
+
{
|
|
870
754
|
tokenIn: v3TokenOut,
|
|
871
755
|
tokenOut: v3TokenIn,
|
|
872
756
|
fee: v3Fee,
|
|
873
757
|
recipient: seller.address,
|
|
874
758
|
amountIn: sellAmount,
|
|
875
759
|
amountOutMinimum: 0n,
|
|
876
|
-
sqrtPriceLimitX96: 0n
|
|
877
|
-
}
|
|
760
|
+
sqrtPriceLimitX96: 0n,
|
|
761
|
+
},
|
|
762
|
+
]);
|
|
878
763
|
return await v3Router.multicall.populateTransaction(deadline, [sellSwapData]);
|
|
879
764
|
}
|
|
880
765
|
}
|