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