four-flap-meme-sdk 3.0.0 → 4.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/bundle/four-meme/approve-tokenmanager.d.ts +2 -2
- package/dist/bundle/four-meme/approve-tokenmanager.js +3 -3
- package/dist/bundle/four-meme/core/buy-flow.d.ts +5 -0
- package/dist/bundle/four-meme/core/buy-flow.js +147 -0
- package/dist/bundle/four-meme/core/constants.d.ts +6 -0
- package/dist/bundle/four-meme/core/constants.js +15 -0
- package/dist/bundle/four-meme/core/create-token.d.ts +5 -0
- package/dist/bundle/four-meme/core/create-token.js +137 -0
- package/dist/bundle/four-meme/core/index.d.ts +14 -0
- package/dist/bundle/four-meme/core/index.js +14 -0
- package/dist/bundle/four-meme/core/sell-flow.d.ts +5 -0
- package/dist/bundle/four-meme/core/sell-flow.js +240 -0
- package/dist/bundle/four-meme/core-helpers.js +1 -1
- package/dist/bundle/four-meme/core.d.ts +7 -4
- package/dist/bundle/four-meme/core.js +5 -513
- package/dist/bundle/four-meme/pancake-proxy/approve.d.ts +15 -0
- package/dist/bundle/four-meme/pancake-proxy/approve.js +113 -0
- package/dist/bundle/four-meme/pancake-proxy/buy.d.ts +8 -0
- package/dist/bundle/four-meme/pancake-proxy/buy.js +143 -0
- package/dist/bundle/four-meme/pancake-proxy/constants.d.ts +25 -0
- package/dist/bundle/four-meme/pancake-proxy/constants.js +14 -0
- package/dist/bundle/four-meme/pancake-proxy/helpers.d.ts +45 -0
- package/dist/bundle/four-meme/pancake-proxy/helpers.js +232 -0
- package/dist/bundle/four-meme/pancake-proxy/index.d.ts +15 -0
- package/dist/bundle/four-meme/pancake-proxy/index.js +15 -0
- package/dist/bundle/four-meme/pancake-proxy/sell.d.ts +8 -0
- package/dist/bundle/four-meme/pancake-proxy/sell.js +194 -0
- package/dist/bundle/four-meme/pancake-proxy.d.ts +4 -20
- package/dist/bundle/four-meme/pancake-proxy.js +3 -670
- package/dist/bundle/four-meme/private/buy.d.ts +16 -0
- package/dist/bundle/four-meme/private/buy.js +225 -0
- package/dist/bundle/four-meme/private/index.d.ts +11 -0
- package/dist/bundle/four-meme/private/index.js +11 -0
- package/dist/bundle/four-meme/private/sell.d.ts +18 -0
- package/dist/bundle/four-meme/private/sell.js +245 -0
- package/dist/bundle/four-meme/private.d.ts +5 -25
- package/dist/bundle/four-meme/private.js +5 -463
- package/dist/bundle/four-meme/swap/batch.d.ts +8 -0
- package/dist/bundle/four-meme/swap/batch.js +170 -0
- package/dist/bundle/four-meme/swap/bundle.d.ts +8 -0
- package/dist/bundle/four-meme/swap/bundle.js +147 -0
- package/dist/bundle/four-meme/swap/index.d.ts +14 -0
- package/dist/bundle/four-meme/swap/index.js +13 -0
- package/dist/bundle/four-meme/swap/quick-batch.d.ts +8 -0
- package/dist/bundle/four-meme/swap/quick-batch.js +206 -0
- package/dist/bundle/four-meme/swap-buy-first/helpers.d.ts +20 -0
- package/dist/bundle/four-meme/swap-buy-first/helpers.js +39 -0
- package/dist/bundle/four-meme/swap-buy-first/index.d.ts +12 -0
- package/dist/bundle/four-meme/swap-buy-first/index.js +11 -0
- package/dist/bundle/four-meme/swap-buy-first/multi-wallet.d.ts +20 -0
- package/dist/bundle/four-meme/swap-buy-first/multi-wallet.js +198 -0
- package/dist/bundle/four-meme/swap-buy-first/single.d.ts +7 -0
- package/dist/bundle/four-meme/swap-buy-first/single.js +232 -0
- package/dist/bundle/four-meme/swap-buy-first.d.ts +4 -3
- package/dist/bundle/four-meme/swap-buy-first.js +4 -451
- package/dist/bundle/four-meme/swap-hop-helpers.d.ts +2 -2
- package/dist/bundle/four-meme/swap-sign-helpers.d.ts +2 -2
- package/dist/bundle/four-meme/swap-sign-helpers.js +1 -1
- package/dist/bundle/four-meme/swap.d.ts +4 -14
- package/dist/bundle/four-meme/swap.js +4 -502
- package/dist/bundle/four-meme/types/index.d.ts +1 -1
- package/dist/bundle/four-meme/utils-disperse.d.ts +1 -1
- package/dist/bundle/four-meme/utils-disperse.js +1 -1
- package/dist/bundle/four-meme/utils-pairwise.d.ts +1 -1
- package/dist/bundle/four-meme/utils-pairwise.js +1 -1
- package/dist/bundle/four-meme/utils-sweep/context.d.ts +39 -0
- package/dist/bundle/four-meme/utils-sweep/context.js +7 -0
- package/dist/bundle/four-meme/utils-sweep/erc20-no-hop.d.ts +5 -0
- package/dist/bundle/four-meme/utils-sweep/erc20-no-hop.js +162 -0
- package/dist/bundle/four-meme/utils-sweep/index.d.ts +13 -0
- package/dist/bundle/four-meme/utils-sweep/index.js +13 -0
- package/dist/bundle/four-meme/utils-sweep/main.d.ts +8 -0
- package/dist/bundle/four-meme/utils-sweep/main.js +114 -0
- package/dist/bundle/four-meme/utils-sweep/native-no-hop.d.ts +5 -0
- package/dist/bundle/four-meme/utils-sweep/native-no-hop.js +156 -0
- package/dist/bundle/four-meme/utils-sweep/with-hops.d.ts +6 -0
- package/dist/bundle/four-meme/utils-sweep/with-hops.js +382 -0
- package/dist/bundle/four-meme/utils-sweep.d.ts +3 -4
- package/dist/bundle/four-meme/utils-sweep.js +3 -740
- package/dist/bundle/internal.d.ts +2 -2
- package/dist/bundle/sign-context-helpers.d.ts +1 -26
- package/dist/bundle/sign-context-helpers.js +1 -63
- package/dist/bundle/submit/blockrazor.d.ts +94 -0
- package/dist/bundle/submit/blockrazor.js +122 -0
- package/dist/bundle/submit/direct.d.ts +118 -0
- package/dist/bundle/submit/direct.js +484 -0
- package/dist/bundle/submit/helpers.d.ts +7 -0
- package/dist/bundle/submit/helpers.js +15 -0
- package/dist/bundle/submit/index.d.ts +14 -0
- package/dist/bundle/submit/index.js +14 -0
- package/dist/bundle/submit/merkle.d.ts +84 -0
- package/dist/bundle/submit/merkle.js +121 -0
- package/dist/bundle/submit.d.ts +3 -286
- package/dist/bundle/submit.js +3 -724
- package/dist/chains/bsc/four/types.d.ts +1 -1
- package/dist/chains/bsc/index.d.ts +1 -1
- package/dist/chains/bsc/index.js +2 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-build.d.ts +25 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-build.js +177 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-constants.d.ts +30 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-constants.js +24 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-helpers.d.ts +11 -149
- package/dist/chains/bsc/pancake/bundle-buy-first-helpers.js +12 -74
- package/dist/chains/bsc/pancake/bundle-buy-first-multi-wallet.d.ts +9 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-multi-wallet.js +225 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-plan.d.ts +14 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-plan.js +64 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-profit.d.ts +12 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-profit.js +22 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-quote.d.ts +15 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-quote.js +122 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-types.d.ts +179 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-types.js +1 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-validate.d.ts +2 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-validate.js +41 -0
- package/dist/chains/bsc/pancake/bundle-buy-first.d.ts +1 -1
- package/dist/chains/bsc/pancake/bundle-buy-first.js +8 -578
- package/dist/chains/bsc/pancake/bundle-swap-helpers.d.ts +11 -239
- package/dist/chains/bsc/pancake/bundle-swap-helpers.js +12 -564
- package/dist/chains/bsc/pancake/bundle-swap-types.d.ts +183 -0
- package/dist/chains/bsc/pancake/bundle-swap-types.js +17 -0
- package/dist/chains/bsc/pancake/bundle-swap.d.ts +10 -132
- package/dist/chains/bsc/pancake/bundle-swap.js +12 -1003
- package/dist/chains/bsc/pancake/hop-chain.d.ts +18 -0
- package/dist/chains/bsc/pancake/hop-chain.js +227 -0
- package/dist/chains/bsc/pancake/quote.d.ts +14 -0
- package/dist/chains/bsc/pancake/quote.js +84 -0
- package/dist/chains/bsc/pancake/swap-batch.d.ts +42 -0
- package/dist/chains/bsc/pancake/swap-batch.js +283 -0
- package/dist/chains/bsc/pancake/swap-build.d.ts +19 -0
- package/dist/chains/bsc/pancake/swap-build.js +226 -0
- package/dist/chains/bsc/pancake/swap-cross.d.ts +42 -0
- package/dist/chains/bsc/pancake/swap-cross.js +140 -0
- package/dist/chains/bsc/pancake/swap-quick.d.ts +54 -0
- package/dist/chains/bsc/pancake/swap-quick.js +424 -0
- package/dist/chains/bsc/pancake/swap-single.d.ts +2 -0
- package/dist/chains/bsc/pancake/swap-single.js +182 -0
- package/dist/chains/bsc/platforms/four/index.d.ts +21 -3
- package/dist/chains/bsc/platforms/four/index.js +28 -3
- package/dist/chains/eni/batch-router/transfer-disperse.d.ts +37 -0
- package/dist/chains/eni/batch-router/transfer-disperse.js +302 -0
- package/dist/chains/eni/batch-router/transfer-shared.d.ts +9 -0
- package/dist/chains/eni/batch-router/transfer-shared.js +10 -0
- package/dist/chains/eni/batch-router/transfer-sweep.d.ts +51 -0
- package/dist/chains/eni/batch-router/transfer-sweep.js +364 -0
- package/dist/chains/eni/batch-router/transfer.d.ts +4 -74
- package/dist/chains/eni/batch-router/transfer.js +2 -647
- package/dist/chains/eni/index.d.ts +2 -0
- package/dist/chains/eni/index.js +4 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct-profit.d.ts +17 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct-profit.js +30 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct-submit.d.ts +12 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct-submit.js +396 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct-tx.d.ts +20 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct-tx.js +165 -0
- package/dist/chains/eni/platforms/daoaas/portal-direct.d.ts +3 -32
- package/dist/chains/eni/platforms/daoaas/portal-direct.js +3 -571
- package/dist/chains/eni/submit.js +1 -1
- package/dist/chains/xlayer/constants.d.ts +0 -2
- package/dist/chains/xlayer/constants.js +0 -2
- package/dist/chains/xlayer/eip7702/auth.d.ts +16 -0
- package/dist/chains/xlayer/eip7702/auth.js +81 -0
- package/dist/chains/xlayer/eip7702/bundle-create-buy.d.ts +22 -0
- package/dist/chains/xlayer/eip7702/bundle-create-buy.js +201 -0
- package/dist/chains/xlayer/eip7702/bundle-create-helpers.d.ts +114 -0
- package/dist/chains/xlayer/eip7702/bundle-create-helpers.js +139 -0
- package/dist/chains/xlayer/eip7702/bundle-create-to-dex.d.ts +24 -0
- package/dist/chains/xlayer/eip7702/bundle-create-to-dex.js +233 -0
- package/dist/chains/xlayer/eip7702/bundle-create.d.ts +3 -35
- package/dist/chains/xlayer/eip7702/bundle-create.js +3 -746
- package/dist/chains/xlayer/eip7702/bundle-graduate-buy.d.ts +22 -0
- package/dist/chains/xlayer/eip7702/bundle-graduate-buy.js +214 -0
- package/dist/chains/xlayer/eip7702/bundle-sell.js +1 -1
- package/dist/chains/xlayer/eip7702/bundle-swap-batch.d.ts +31 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-batch.js +216 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-helpers.d.ts +21 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-helpers.js +206 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-multi.d.ts +33 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-multi.js +146 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-single.d.ts +31 -0
- package/dist/chains/xlayer/eip7702/bundle-swap-single.js +177 -0
- package/dist/chains/xlayer/eip7702/bundle-swap.d.ts +6 -61
- package/dist/chains/xlayer/eip7702/bundle-swap.js +3 -712
- package/dist/chains/xlayer/eip7702/bytes.d.ts +4 -0
- package/dist/chains/xlayer/eip7702/bytes.js +31 -0
- package/dist/chains/xlayer/eip7702/gas.d.ts +19 -0
- package/dist/chains/xlayer/eip7702/gas.js +152 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-disperse.d.ts +5 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-disperse.js +196 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-pairwise.d.ts +5 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-pairwise.js +188 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-sweep.d.ts +5 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-sweep.js +220 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer.d.ts +8 -4
- package/dist/chains/xlayer/eip7702/multi-hop-transfer.js +5 -591
- package/dist/chains/xlayer/eip7702/profit.d.ts +32 -0
- package/dist/chains/xlayer/eip7702/profit.js +59 -0
- package/dist/chains/xlayer/eip7702/provider.d.ts +3 -0
- package/dist/chains/xlayer/eip7702/provider.js +17 -0
- package/dist/chains/xlayer/eip7702/time.d.ts +2 -0
- package/dist/chains/xlayer/eip7702/time.js +10 -0
- package/dist/chains/xlayer/eip7702/tx-build.d.ts +10 -0
- package/dist/chains/xlayer/eip7702/tx-build.js +128 -0
- package/dist/chains/xlayer/eip7702/utils.d.ts +19 -85
- package/dist/chains/xlayer/eip7702/utils.js +19 -484
- package/dist/chains/xlayer/eip7702/volume-bundle.d.ts +13 -0
- package/dist/chains/xlayer/eip7702/volume-bundle.js +250 -0
- package/dist/chains/xlayer/eip7702/volume-internal.d.ts +13 -0
- package/dist/chains/xlayer/eip7702/volume-internal.js +169 -0
- package/dist/chains/xlayer/eip7702/volume-make.d.ts +8 -0
- package/dist/chains/xlayer/eip7702/volume-make.js +38 -0
- package/dist/chains/xlayer/eip7702/volume-single-round.d.ts +17 -0
- package/dist/chains/xlayer/eip7702/volume-single-round.js +44 -0
- package/dist/chains/xlayer/eip7702/volume-swap.d.ts +18 -0
- package/dist/chains/xlayer/eip7702/volume-swap.js +30 -0
- package/dist/chains/xlayer/eip7702/volume-wash.d.ts +8 -0
- package/dist/chains/xlayer/eip7702/volume-wash.js +191 -0
- package/dist/chains/xlayer/eip7702/volume.d.ts +7 -35
- package/dist/chains/xlayer/eip7702/volume.js +5 -697
- package/dist/chains/xlayer/eip7702/wallet.d.ts +6 -0
- package/dist/chains/xlayer/eip7702/wallet.js +17 -0
- package/dist/chains/xlayer/eoa/aa-types.d.ts +176 -0
- package/dist/chains/xlayer/eoa/aa-types.js +6 -0
- package/dist/chains/xlayer/eoa/constants.d.ts +0 -2
- package/dist/chains/xlayer/eoa/constants.js +0 -2
- package/dist/chains/xlayer/eoa/context.d.ts +8 -0
- package/dist/chains/xlayer/eoa/context.js +23 -0
- package/dist/chains/xlayer/eoa/encoders.d.ts +147 -0
- package/dist/chains/xlayer/eoa/encoders.js +147 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-cross.d.ts +5 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-cross.js +113 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.d.ts +10 -123
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.js +10 -225
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-pure.d.ts +50 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-pure.js +170 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-quick.d.ts +5 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-quick.js +257 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-types.d.ts +99 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-types.js +11 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap.d.ts +5 -47
- package/dist/chains/xlayer/eoa/eoa-bundle-swap.js +3 -522
- package/dist/chains/xlayer/eoa/eoa-types.d.ts +776 -0
- package/dist/chains/xlayer/eoa/eoa-types.js +6 -0
- package/dist/chains/xlayer/eoa/eoa-wash-volume.d.ts +8 -0
- package/dist/chains/xlayer/eoa/eoa-wash-volume.js +8 -0
- package/dist/chains/xlayer/eoa/format.d.ts +34 -0
- package/dist/chains/xlayer/eoa/format.js +56 -0
- package/dist/chains/xlayer/eoa/hop-chain.d.ts +4 -0
- package/dist/chains/xlayer/eoa/hop-chain.js +87 -0
- package/dist/chains/xlayer/eoa/nonce-map.d.ts +20 -0
- package/dist/chains/xlayer/eoa/nonce-map.js +51 -0
- package/dist/chains/xlayer/eoa/portal-ops.d.ts +9 -292
- package/dist/chains/xlayer/eoa/portal-ops.js +9 -486
- package/dist/chains/xlayer/eoa/query.d.ts +117 -0
- package/dist/chains/xlayer/eoa/query.js +285 -0
- package/dist/chains/xlayer/eoa/quote.d.ts +6 -0
- package/dist/chains/xlayer/eoa/quote.js +90 -0
- package/dist/chains/xlayer/eoa/types.d.ts +9 -959
- package/dist/chains/xlayer/eoa/types.js +9 -49
- package/dist/core/clients/blockrazor.js +1 -1
- package/dist/core/clients/merkle.js +1 -1
- package/dist/core/erc20/allowances.d.ts +104 -0
- package/dist/core/erc20/allowances.js +205 -0
- package/dist/core/erc20/approve.d.ts +141 -0
- package/dist/core/erc20/approve.js +325 -0
- package/dist/core/erc20/helpers.d.ts +20 -0
- package/dist/core/erc20/helpers.js +109 -0
- package/dist/core/erc20/index.d.ts +13 -0
- package/dist/core/erc20/index.js +12 -0
- package/dist/core/gas/bundle-gas.d.ts +6 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/quote/index.d.ts +1 -0
- package/dist/core/quote/index.js +1 -0
- package/dist/core/quote/quote-helpers.d.ts +78 -0
- package/dist/core/quote/quote-helpers.js +289 -0
- package/dist/core/quote/types.d.ts +1 -0
- package/dist/core/quote/types.js +1 -0
- package/dist/core/sign-context-helpers.d.ts +29 -0
- package/dist/core/sign-context-helpers.js +63 -0
- package/dist/domains/dex/direct-router-helpers.d.ts +16 -268
- package/dist/domains/dex/direct-router-helpers.js +16 -535
- package/dist/domains/dex/direct-router-types.d.ts +104 -0
- package/dist/domains/dex/direct-router-types.js +81 -0
- package/dist/domains/dex/direct-router-v2-buy.d.ts +2 -0
- package/dist/domains/dex/direct-router-v2-buy.js +249 -0
- package/dist/domains/dex/direct-router-v2-sell.d.ts +5 -0
- package/dist/domains/dex/direct-router-v2-sell.js +270 -0
- package/dist/domains/dex/direct-router-v2.d.ts +9 -0
- package/dist/domains/dex/direct-router-v2.js +9 -0
- package/dist/domains/dex/direct-router-v3.d.ts +17 -0
- package/dist/domains/dex/direct-router-v3.js +432 -0
- package/dist/domains/dex/direct-router.d.ts +11 -26
- package/dist/domains/dex/direct-router.js +10 -977
- package/dist/domains/dex/dyo-encode.d.ts +62 -0
- package/dist/domains/dex/dyo-encode.js +124 -0
- package/dist/domains/dex/profit.d.ts +24 -0
- package/dist/domains/dex/profit.js +86 -0
- package/dist/domains/dex/provider.d.ts +10 -0
- package/dist/domains/dex/provider.js +27 -0
- package/dist/domains/dex/quote.d.ts +7 -0
- package/dist/domains/dex/quote.js +52 -0
- package/dist/domains/dex/router.d.ts +56 -0
- package/dist/domains/dex/router.js +193 -0
- package/dist/domains/flap/portal-bundle/batch.d.ts +9 -0
- package/dist/domains/flap/portal-bundle/batch.js +193 -0
- package/dist/domains/flap/portal-bundle/create.d.ts +5 -0
- package/dist/domains/flap/portal-bundle/create.js +153 -0
- package/dist/domains/flap/portal-bundle/helpers.d.ts +32 -0
- package/dist/domains/flap/portal-bundle/helpers.js +50 -0
- package/dist/domains/flap/portal-bundle/index.d.ts +16 -0
- package/dist/domains/flap/portal-bundle/index.js +15 -0
- package/dist/domains/flap/portal-bundle/private.d.ts +5 -0
- package/dist/domains/flap/portal-bundle/private.js +198 -0
- package/dist/domains/flap/portal-bundle/types.d.ts +102 -0
- package/dist/domains/flap/portal-bundle/types.js +1 -0
- package/dist/domains/flap/portal-bundle-merkle/core-batch.d.ts +13 -0
- package/dist/domains/flap/portal-bundle-merkle/core-batch.js +376 -0
- package/dist/domains/flap/portal-bundle-merkle/core-helpers.d.ts +75 -7
- package/dist/domains/flap/portal-bundle-merkle/core-helpers.js +259 -20
- package/dist/domains/flap/portal-bundle-merkle/core.d.ts +2 -13
- package/dist/domains/flap/portal-bundle-merkle/core.js +12 -629
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/constants.d.ts +70 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/constants.js +90 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/index.d.ts +12 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/index.js +11 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/main.d.ts +15 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/main.js +432 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/types.d.ts +113 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex/types.js +4 -0
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex.d.ts +4 -127
- package/dist/domains/flap/portal-bundle-merkle/create-to-dex.js +4 -527
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/constants.d.ts +42 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/constants.js +81 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/index.d.ts +12 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/index.js +11 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/main.d.ts +15 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/main.js +339 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/types.d.ts +72 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/types.js +4 -0
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex.d.ts +4 -85
- package/dist/domains/flap/portal-bundle-merkle/curve-to-dex.js +4 -425
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/approve.d.ts +12 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/approve.js +102 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/buy.d.ts +5 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/buy.js +135 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/helpers.d.ts +52 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/helpers.js +267 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/index.d.ts +14 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/index.js +14 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/sell.d.ts +5 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/sell.js +195 -0
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy.d.ts +3 -24
- package/dist/domains/flap/portal-bundle-merkle/pancake-proxy.js +3 -700
- package/dist/domains/flap/portal-bundle-merkle/private/buy.d.ts +9 -0
- package/dist/domains/flap/portal-bundle-merkle/private/buy.js +188 -0
- package/dist/domains/flap/portal-bundle-merkle/private/helpers.d.ts +36 -0
- package/dist/domains/flap/portal-bundle-merkle/private/helpers.js +127 -0
- package/dist/domains/flap/portal-bundle-merkle/private/index.d.ts +12 -0
- package/dist/domains/flap/portal-bundle-merkle/private/index.js +12 -0
- package/dist/domains/flap/portal-bundle-merkle/private/sell.d.ts +9 -0
- package/dist/domains/flap/portal-bundle-merkle/private/sell.js +191 -0
- package/dist/domains/flap/portal-bundle-merkle/private.d.ts +5 -15
- package/dist/domains/flap/portal-bundle-merkle/private.js +5 -494
- package/dist/domains/flap/portal-bundle-merkle/swap-batch.js +3 -2
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-chain.d.ts +4 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-chain.js +43 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-constants.d.ts +13 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-constants.js +21 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-helpers.d.ts +11 -121
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-helpers.js +11 -109
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-multi-wallet.d.ts +20 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-multi-wallet.js +223 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-plan.d.ts +32 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-plan.js +66 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-profit.d.ts +22 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-profit.js +22 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-quote.d.ts +51 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-quote.js +149 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-types.d.ts +87 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-types.js +1 -0
- package/dist/domains/flap/portal-bundle-merkle/swap-buy-first.js +5 -404
- package/dist/domains/flap/portal-bundle-merkle/swap-helpers.d.ts +0 -1
- package/dist/domains/flap/portal-bundle-merkle/swap-helpers.js +0 -7
- package/dist/domains/flap/portal-bundle-merkle/swap-planning.js +1 -1
- package/dist/domains/flap/portal-bundle-merkle/swap-quick-batch.js +3 -2
- package/dist/domains/flap/portal-bundle-merkle/swap-single.js +3 -2
- package/dist/domains/flap/portal-bundle-merkle/utils/disperse.d.ts +2 -0
- package/dist/domains/flap/portal-bundle-merkle/utils/disperse.js +275 -0
- package/dist/domains/flap/portal-bundle-merkle/utils/index.d.ts +11 -0
- package/dist/domains/flap/portal-bundle-merkle/utils/index.js +11 -0
- package/dist/domains/flap/portal-bundle-merkle/utils/sweep.d.ts +9 -0
- package/dist/domains/flap/portal-bundle-merkle/utils/sweep.js +570 -0
- package/dist/domains/flap/portal-bundle-merkle/utils.d.ts +5 -8
- package/dist/domains/flap/portal-bundle-merkle/utils.js +5 -841
- package/dist/domains/flap/portal-bundle.d.ts +5 -117
- package/dist/domains/flap/portal-bundle.js +5 -587
- package/dist/domains/flap/portal.d.ts +13 -404
- package/dist/domains/flap/portal.js +12 -619
- package/dist/domains/flap/reader.d.ts +51 -0
- package/dist/domains/flap/reader.js +275 -0
- package/dist/domains/flap/types.d.ts +246 -0
- package/dist/domains/flap/types.js +104 -0
- package/dist/domains/flap/vault/constants.d.ts +220 -0
- package/dist/domains/flap/vault/constants.js +173 -0
- package/dist/domains/flap/vault/encode.d.ts +39 -0
- package/dist/domains/flap/vault/encode.js +135 -0
- package/dist/domains/flap/vault/index.d.ts +15 -0
- package/dist/domains/flap/vault/index.js +14 -0
- package/dist/domains/flap/vault/query.d.ts +40 -0
- package/dist/domains/flap/vault/query.js +104 -0
- package/dist/domains/flap/vault/types.d.ts +147 -0
- package/dist/domains/flap/vault/types.js +29 -0
- package/dist/domains/flap/vault.d.ts +3 -413
- package/dist/domains/flap/vault.js +3 -467
- package/dist/domains/flap/writer.d.ts +124 -0
- package/dist/domains/flap/writer.js +255 -0
- package/dist/domains/four/contracts/tm-bundle-batch.d.ts +35 -0
- package/dist/domains/four/contracts/tm-bundle-batch.js +286 -0
- package/dist/domains/four/contracts/tm-bundle-create.d.ts +2 -0
- package/dist/domains/four/contracts/tm-bundle-create.js +304 -0
- package/dist/domains/four/contracts/tm-bundle-helpers.d.ts +2 -1
- package/dist/domains/four/contracts/tm-bundle-helpers.js +3 -0
- package/dist/domains/four/contracts/tm-bundle-private.d.ts +36 -0
- package/dist/domains/four/contracts/tm-bundle-private.js +164 -0
- package/dist/domains/four/contracts/tm-bundle.d.ts +10 -71
- package/dist/domains/four/contracts/tm-bundle.js +9 -738
- package/dist/domains/lp-inspect/inspect-helpers.d.ts +25 -0
- package/dist/domains/lp-inspect/inspect-helpers.js +343 -0
- package/dist/domains/lp-inspect/inspect.d.ts +8 -0
- package/dist/domains/lp-inspect/inspect.js +332 -0
- package/dist/domains/lp-inspect/lp-inspect.d.ts +9 -37
- package/dist/domains/lp-inspect/lp-inspect.js +9 -775
- package/dist/domains/lp-inspect/registry.d.ts +43 -0
- package/dist/domains/lp-inspect/registry.js +127 -0
- package/dist/domains/merkle/index.d.ts +1 -1
- package/dist/exports/root-bundle-and-tooling.d.ts +9 -1
- package/dist/exports/root-bundle-and-tooling.js +8 -1
- package/dist/exports/root-foundations.d.ts +1 -1
- package/dist/exports/root-foundations.js +1 -1
- package/dist/exports/root-swap-dex-and-xlayer.d.ts +4 -4
- package/dist/exports/root-swap-dex-and-xlayer.js +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/utils/swap-helpers.js +1 -1
- package/package.json +1 -81
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* swap-quick - 快捷批量换手(资金自动流转)
|
|
3
|
+
*/
|
|
4
|
+
import { GAS_LIMITS, CHAINS, getProfitRecipient, ADDRESSES, BLOCKRAZOR_BUILDER_EOA } from '../../../core/constants/index.js';
|
|
5
|
+
import { getGasLimit } from '../../../core/gas/bundle-gas.js';
|
|
6
|
+
import { ethers, Contract, Wallet } from 'ethers';
|
|
7
|
+
import { calculateSellAmount } from '../../../utils/swap-helpers.js';
|
|
8
|
+
import { NonceManager, buildProfitHopTransactions, PROFIT_HOP_COUNT, } from '../../../utils/bundle-helpers.js';
|
|
9
|
+
import { ERC20_ABI } from '../../../abis/common.js';
|
|
10
|
+
import { BRIBE_GAS_LIMIT, FLAT_FEE, NATIVE_TRANSFER_GAS_LIMIT, PANCAKE_V2_ROUTER_ABI, PANCAKE_V2_ROUTER_ADDRESS, PANCAKE_V3_ROUTER_ABI, PANCAKE_V3_ROUTER_ADDRESS, ZERO_ADDRESS, buildBNBHopChainForERC20, buildERC20HopChain, buildNativeHopChain, calculateProfitAmount, createPancakeContext, generateDisperseHopPaths, getERC20ToNativeQuote, getGasPrice, quoteSellOutput, } from './bundle-swap-helpers.js';
|
|
11
|
+
/**
|
|
12
|
+
* PancakeSwap 快捷批量换手(资金自动流转)
|
|
13
|
+
*
|
|
14
|
+
* 流程:[贿赂] → [卖出] → [转账多跳...] → [买入1, 买入2, ...] → [利润]
|
|
15
|
+
*
|
|
16
|
+
* 特点:
|
|
17
|
+
* - 子钱包不需要预先有余额
|
|
18
|
+
* - 资金来自主钱包卖出代币所得
|
|
19
|
+
* - 提升资金利用率
|
|
20
|
+
* - 支持 BNB 和 ERC20(如 USDT)两种模式
|
|
21
|
+
* - ✅ 支持转账多跳,隐藏资金流向
|
|
22
|
+
*
|
|
23
|
+
* 限制:根据多跳数动态计算最大买方数量
|
|
24
|
+
*/
|
|
25
|
+
export async function pancakeQuickBatchSwapMerkle(params) {
|
|
26
|
+
const { sellerPrivateKey, sellAmount, sellPercentage, buyerPrivateKeys, buyerRatios, buyerAmounts, tokenAddress, routeParams, config, quoteToken, quoteTokenDecimals = 18, disperseHopCount = 0, // ✅ 转账多跳数(默认0=直接转账)
|
|
27
|
+
startNonces, // ✅ 可选:前端预获取的 nonces
|
|
28
|
+
} = params;
|
|
29
|
+
// ✅ 判断是否使用原生代币
|
|
30
|
+
const useNativeToken = !quoteToken || quoteToken === ZERO_ADDRESS;
|
|
31
|
+
// ✅ 根据 chainId 获取正确的 Wrapped Native Token 地址
|
|
32
|
+
const chainId = config.chainId ?? CHAINS.BSC.chainId;
|
|
33
|
+
const WRAPPED_NATIVE = chainId === CHAINS.XLAYER.chainId
|
|
34
|
+
? ADDRESSES.XLAYER.WOKB.toLowerCase() // XLayer: WOKB
|
|
35
|
+
: ADDRESSES.BSC.WBNB.toLowerCase(); // BSC: WBNB
|
|
36
|
+
// ✅ 动态计算最大买方数量(根据多跳数)
|
|
37
|
+
// 固定开销: 贿赂(1) + 卖出(1) + 利润多跳(PROFIT_HOP_COUNT + 1)
|
|
38
|
+
// BNB 模式(无多跳): 转账(N) + 买入(N) = 2N
|
|
39
|
+
// BNB 模式(有多跳H): 转账(N*(H+1)) + 买入(N) = N*(H+2)
|
|
40
|
+
// ERC20 模式(无多跳): 转账(N) + 买入(N) = 2N
|
|
41
|
+
// ERC20 模式(有多跳H): BNB转账(N*(H+1)) + ERC20转账(N*(H+1)) + 买入(N) = N*(2H+3)
|
|
42
|
+
const fixedOverhead = 1 + 1 + PROFIT_HOP_COUNT + 1; // 贿赂 + 卖出 + 利润多跳
|
|
43
|
+
const maxTxs = 50 - fixedOverhead;
|
|
44
|
+
let MAX_BUYERS;
|
|
45
|
+
if (useNativeToken) {
|
|
46
|
+
// BNB 模式: N*(H+2) <= maxTxs => N <= maxTxs / (H+2)
|
|
47
|
+
MAX_BUYERS = Math.floor(maxTxs / (disperseHopCount + 2));
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
// ERC20 模式: N*(2H+3) <= maxTxs => N <= maxTxs / (2H+3)
|
|
51
|
+
MAX_BUYERS = Math.floor(maxTxs / (2 * disperseHopCount + 3));
|
|
52
|
+
}
|
|
53
|
+
MAX_BUYERS = Math.max(1, MAX_BUYERS); // 至少1个
|
|
54
|
+
if (buyerPrivateKeys.length === 0) {
|
|
55
|
+
throw new Error('至少需要一个买方钱包');
|
|
56
|
+
}
|
|
57
|
+
if (buyerPrivateKeys.length > MAX_BUYERS) {
|
|
58
|
+
const mode = useNativeToken ? 'BNB' : 'ERC20';
|
|
59
|
+
throw new Error(`资金利用率模式(${mode}, ${disperseHopCount}跳)买方钱包数量超过限制: ${buyerPrivateKeys.length} > ${MAX_BUYERS}`);
|
|
60
|
+
}
|
|
61
|
+
// ✅ 校验分配模式
|
|
62
|
+
if (!buyerRatios && !buyerAmounts) {
|
|
63
|
+
throw new Error('必须提供 buyerRatios 或 buyerAmounts');
|
|
64
|
+
}
|
|
65
|
+
if (buyerRatios && buyerRatios.length !== buyerPrivateKeys.length) {
|
|
66
|
+
throw new Error(`buyerRatios 长度 (${buyerRatios.length}) 与 buyerPrivateKeys 长度 (${buyerPrivateKeys.length}) 不匹配`);
|
|
67
|
+
}
|
|
68
|
+
if (buyerAmounts && buyerAmounts.length !== buyerPrivateKeys.length) {
|
|
69
|
+
throw new Error(`buyerAmounts 长度 (${buyerAmounts.length}) 与 buyerPrivateKeys 长度 (${buyerPrivateKeys.length}) 不匹配`);
|
|
70
|
+
}
|
|
71
|
+
const context = createPancakeContext(config);
|
|
72
|
+
const seller = new Wallet(sellerPrivateKey, context.provider);
|
|
73
|
+
const buyers = buyerPrivateKeys.map((pk) => new Wallet(pk, context.provider));
|
|
74
|
+
// ✅ 校验卖出路径输出代币是否匹配
|
|
75
|
+
let sellOutputToken;
|
|
76
|
+
if (routeParams.routeType === 'v2') {
|
|
77
|
+
const { v2Path } = routeParams;
|
|
78
|
+
sellOutputToken = v2Path[v2Path.length - 1];
|
|
79
|
+
}
|
|
80
|
+
else if (routeParams.routeType === 'v3-single') {
|
|
81
|
+
const { v3TokenOut } = routeParams;
|
|
82
|
+
sellOutputToken = v3TokenOut;
|
|
83
|
+
}
|
|
84
|
+
else if (routeParams.routeType === 'v3-multi') {
|
|
85
|
+
const { v2Path } = routeParams;
|
|
86
|
+
if (v2Path && v2Path.length > 0) {
|
|
87
|
+
sellOutputToken = v2Path[v2Path.length - 1];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// 校验输出代币
|
|
91
|
+
const wrappedNativeName = chainId === CHAINS.XLAYER.chainId ? 'WOKB' : 'WBNB';
|
|
92
|
+
if (useNativeToken) {
|
|
93
|
+
// 原生代币模式:输出必须是 Wrapped Native Token(BSC: WBNB, XLayer: WOKB)
|
|
94
|
+
if (!sellOutputToken || sellOutputToken.toLowerCase() !== WRAPPED_NATIVE) {
|
|
95
|
+
throw new Error(`原生代币模式要求卖出路径以 ${wrappedNativeName} 结尾(当前输出: ${sellOutputToken || '未知'})。` +
|
|
96
|
+
`请切换交易对或使用 ERC20 模式。`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// ERC20 模式:输出必须是指定的 quoteToken
|
|
101
|
+
if (!sellOutputToken || sellOutputToken.toLowerCase() !== quoteToken.toLowerCase()) {
|
|
102
|
+
throw new Error(`ERC20 模式要求卖出路径以 ${quoteToken} 结尾(当前输出: ${sellOutputToken || '未知'})。`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// ✅ 创建共享资源
|
|
106
|
+
const nonceManager = new NonceManager(context.provider);
|
|
107
|
+
const finalGasLimit = getGasLimit(config, 800000);
|
|
108
|
+
const txType = config.txType ?? 0;
|
|
109
|
+
const ERC20_TRANSFER_GAS = GAS_LIMITS.ERC20_TRANSFER; // ERC20 transfer 的 gas 限制
|
|
110
|
+
// ✅ 并行获取 gasPrice 和卖出数量
|
|
111
|
+
const [gasPrice, sellAmountResult] = await Promise.all([
|
|
112
|
+
getGasPrice(context.provider, config),
|
|
113
|
+
calculateSellAmount(context.provider, tokenAddress, seller.address, sellAmount, sellPercentage),
|
|
114
|
+
]);
|
|
115
|
+
const { amount: sellAmountWei, decimals } = sellAmountResult;
|
|
116
|
+
const quoteResult = await quoteSellOutput({
|
|
117
|
+
routeParams,
|
|
118
|
+
sellAmountWei,
|
|
119
|
+
provider: context.provider,
|
|
120
|
+
v2RouterAddress: config.v2RouterAddress,
|
|
121
|
+
});
|
|
122
|
+
const estimatedOutput = quoteResult.estimatedBNBOut;
|
|
123
|
+
// ✅ 计算利润(万分之六)
|
|
124
|
+
let profitAmount;
|
|
125
|
+
if (useNativeToken) {
|
|
126
|
+
profitAmount = calculateProfitAmount(estimatedOutput, config.userType);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
// ERC20 模式:需要将 ERC20 价值转换为 BNB
|
|
130
|
+
const version = routeParams.routeType === 'v2' ? 'v2' : 'v3';
|
|
131
|
+
const fee = routeParams.routeType === 'v3-single' ? routeParams.v3Fee : undefined;
|
|
132
|
+
const estimatedBNBValue = await getERC20ToNativeQuote(context.provider, quoteToken, estimatedOutput, version, fee);
|
|
133
|
+
profitAmount = calculateProfitAmount(estimatedBNBValue, config.userType);
|
|
134
|
+
}
|
|
135
|
+
const distributableAmount = estimatedOutput - (useNativeToken ? profitAmount : 0n);
|
|
136
|
+
// ✅ 计算每个买方分到的金额
|
|
137
|
+
let transferAmountsWei;
|
|
138
|
+
if (buyerAmounts && buyerAmounts.length === buyers.length) {
|
|
139
|
+
// 数量模式
|
|
140
|
+
transferAmountsWei = buyerAmounts.map((amt) => useNativeToken ? ethers.parseEther(amt) : ethers.parseUnits(amt, quoteTokenDecimals));
|
|
141
|
+
const totalTransfer = transferAmountsWei.reduce((a, b) => a + b, 0n);
|
|
142
|
+
if (totalTransfer > distributableAmount) {
|
|
143
|
+
const formatted = useNativeToken
|
|
144
|
+
? ethers.formatEther(distributableAmount)
|
|
145
|
+
: ethers.formatUnits(distributableAmount, quoteTokenDecimals);
|
|
146
|
+
throw new Error(`指定的买入总金额超过可分配金额 (${formatted})`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else if (buyerRatios && buyerRatios.length === buyers.length) {
|
|
150
|
+
// 比例模式
|
|
151
|
+
transferAmountsWei = buyerRatios.map((ratio) => {
|
|
152
|
+
return (distributableAmount * BigInt(Math.round(ratio * 10000))) / 10000n;
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
throw new Error('必须提供 buyerRatios 或 buyerAmounts');
|
|
157
|
+
}
|
|
158
|
+
// ✅ 获取贿赂金额
|
|
159
|
+
const bribeAmount = config.bribeAmount && config.bribeAmount > 0 ? ethers.parseEther(String(config.bribeAmount)) : 0n;
|
|
160
|
+
// ✅ 验证主钱包余额
|
|
161
|
+
const sellerBalance = await seller.provider.getBalance(seller.address);
|
|
162
|
+
let sellerGasCost;
|
|
163
|
+
let sellerRequired;
|
|
164
|
+
if (useNativeToken) {
|
|
165
|
+
// BNB 模式:贿赂(BRIBE) + 卖出(gasLimit) + N个原生转账(BRIBE each) + 利润(BRIBE)
|
|
166
|
+
sellerGasCost =
|
|
167
|
+
gasPrice * (BRIBE_GAS_LIMIT + finalGasLimit + BRIBE_GAS_LIMIT * BigInt(buyers.length) + BRIBE_GAS_LIMIT);
|
|
168
|
+
sellerRequired = bribeAmount + sellerGasCost;
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
// ERC20 模式:子钱包已预留 BNB,不需要主钱包转 Gas
|
|
172
|
+
// 卖方 Gas: 贿赂(BRIBE) + 卖出(gasLimit) + N个ERC20转账(65000 each) + 利润(BRIBE)
|
|
173
|
+
sellerGasCost =
|
|
174
|
+
gasPrice * (BRIBE_GAS_LIMIT + finalGasLimit + ERC20_TRANSFER_GAS * BigInt(buyers.length) + BRIBE_GAS_LIMIT);
|
|
175
|
+
sellerRequired = bribeAmount + sellerGasCost;
|
|
176
|
+
}
|
|
177
|
+
if (sellerBalance < sellerRequired) {
|
|
178
|
+
throw new Error(`主钱包 BNB 余额不足: 需要约 ${ethers.formatEther(sellerRequired)} BNB (贿赂: ${ethers.formatEther(bribeAmount)}, Gas: ${ethers.formatEther(sellerGasCost)}), 实际 ${ethers.formatEther(sellerBalance)} BNB`);
|
|
179
|
+
}
|
|
180
|
+
// ==================== 规划 Nonce ====================
|
|
181
|
+
// ✅ 如果前端传入了 startNonces,直接使用(性能优化)
|
|
182
|
+
let sellerNonce = startNonces && startNonces.length > 0 ? startNonces[0] : await nonceManager.getNextNonce(seller);
|
|
183
|
+
const deadline = Math.floor(Date.now() / 1000) + 600;
|
|
184
|
+
// ==================== 1. 贿赂交易 ====================
|
|
185
|
+
let bribeTx = null;
|
|
186
|
+
if (bribeAmount > 0n) {
|
|
187
|
+
bribeTx = await seller.signTransaction({
|
|
188
|
+
to: BLOCKRAZOR_BUILDER_EOA,
|
|
189
|
+
value: bribeAmount,
|
|
190
|
+
nonce: sellerNonce++,
|
|
191
|
+
gasPrice,
|
|
192
|
+
gasLimit: BRIBE_GAS_LIMIT,
|
|
193
|
+
chainId: context.chainId,
|
|
194
|
+
type: txType,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
// ==================== 2. 卖出交易 ====================
|
|
198
|
+
const v3RouterIface2 = new ethers.Interface(PANCAKE_V3_ROUTER_ABI);
|
|
199
|
+
const quickV2Addr = config.v2RouterAddress || PANCAKE_V2_ROUTER_ADDRESS;
|
|
200
|
+
let sellUnsigned;
|
|
201
|
+
if (routeParams.routeType === 'v2') {
|
|
202
|
+
const { v2Path } = routeParams;
|
|
203
|
+
const v2RouterSeller = new Contract(quickV2Addr, PANCAKE_V2_ROUTER_ABI, seller);
|
|
204
|
+
if (useNativeToken) {
|
|
205
|
+
// ✅ 原生代币模式(BNB):Token → WBNB → BNB
|
|
206
|
+
sellUnsigned = await v2RouterSeller.swapExactTokensForETHSupportingFeeOnTransferTokens.populateTransaction(sellAmountWei, 0n, v2Path, seller.address, deadline);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
// ✅ ERC20 模式(USDT):Token → USDT
|
|
210
|
+
sellUnsigned = await v2RouterSeller.swapExactTokensForTokensSupportingFeeOnTransferTokens.populateTransaction(sellAmountWei, 0n, v2Path, seller.address, deadline);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
else if (routeParams.routeType === 'v3-single') {
|
|
214
|
+
const { v3TokenIn, v3TokenOut, v3Fee } = routeParams;
|
|
215
|
+
const v3RouterSeller = new Contract(PANCAKE_V3_ROUTER_ADDRESS, PANCAKE_V3_ROUTER_ABI, seller);
|
|
216
|
+
const sellSwapData = v3RouterIface2.encodeFunctionData('exactInputSingle', [
|
|
217
|
+
{
|
|
218
|
+
tokenIn: v3TokenIn,
|
|
219
|
+
tokenOut: v3TokenOut,
|
|
220
|
+
fee: v3Fee,
|
|
221
|
+
recipient: useNativeToken ? PANCAKE_V3_ROUTER_ADDRESS : seller.address,
|
|
222
|
+
amountIn: sellAmountWei,
|
|
223
|
+
amountOutMinimum: 0n,
|
|
224
|
+
sqrtPriceLimitX96: 0n,
|
|
225
|
+
},
|
|
226
|
+
]);
|
|
227
|
+
if (useNativeToken) {
|
|
228
|
+
// 原生代币:需要 unwrap WBNB
|
|
229
|
+
const sellUnwrapData = v3RouterIface2.encodeFunctionData('unwrapWETH9', [0n, seller.address]);
|
|
230
|
+
sellUnsigned = await v3RouterSeller.multicall.populateTransaction(deadline, [sellSwapData, sellUnwrapData]);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
// ERC20:直接接收代币
|
|
234
|
+
sellUnsigned = await v3RouterSeller.multicall.populateTransaction(deadline, [sellSwapData]);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
throw new Error('V3 多跳路由暂不支持官方合约,请使用 V2 路由或 V3 单跳');
|
|
239
|
+
}
|
|
240
|
+
const signedSell = await seller.signTransaction({
|
|
241
|
+
...sellUnsigned,
|
|
242
|
+
from: seller.address,
|
|
243
|
+
nonce: sellerNonce++,
|
|
244
|
+
gasLimit: finalGasLimit,
|
|
245
|
+
gasPrice,
|
|
246
|
+
chainId: context.chainId,
|
|
247
|
+
type: txType,
|
|
248
|
+
});
|
|
249
|
+
// ==================== 3. 转账交易(支持多跳)====================
|
|
250
|
+
const buyerGasCost = gasPrice * finalGasLimit;
|
|
251
|
+
// ✅ 生成多跳路径
|
|
252
|
+
const hopPaths = generateDisperseHopPaths(buyers.map((b) => b.address), disperseHopCount, context.provider);
|
|
253
|
+
// 收集所有中间钱包信息
|
|
254
|
+
const allHopWallets = [];
|
|
255
|
+
hopPaths.forEach((path) => {
|
|
256
|
+
allHopWallets.push(...path.hopWalletsInfo);
|
|
257
|
+
});
|
|
258
|
+
let transferTxs;
|
|
259
|
+
if (disperseHopCount === 0) {
|
|
260
|
+
// ✅ 无多跳:直接转账
|
|
261
|
+
const transferNonces = buyers.map((_, i) => sellerNonce + i);
|
|
262
|
+
sellerNonce += buyers.length;
|
|
263
|
+
if (useNativeToken) {
|
|
264
|
+
transferTxs = await Promise.all(buyers.map((buyer, i) => {
|
|
265
|
+
const transferValue = transferAmountsWei[i] + FLAT_FEE + buyerGasCost;
|
|
266
|
+
return seller.signTransaction({
|
|
267
|
+
to: buyer.address,
|
|
268
|
+
value: transferValue,
|
|
269
|
+
nonce: transferNonces[i],
|
|
270
|
+
gasPrice,
|
|
271
|
+
gasLimit: NATIVE_TRANSFER_GAS_LIMIT,
|
|
272
|
+
chainId: context.chainId,
|
|
273
|
+
type: txType,
|
|
274
|
+
});
|
|
275
|
+
}));
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
const erc20Interface = new ethers.Interface(ERC20_ABI);
|
|
279
|
+
transferTxs = await Promise.all(buyers.map((buyer, i) => {
|
|
280
|
+
const transferData = erc20Interface.encodeFunctionData('transfer', [buyer.address, transferAmountsWei[i]]);
|
|
281
|
+
return seller.signTransaction({
|
|
282
|
+
to: quoteToken,
|
|
283
|
+
data: transferData,
|
|
284
|
+
value: 0n,
|
|
285
|
+
nonce: transferNonces[i],
|
|
286
|
+
gasPrice,
|
|
287
|
+
gasLimit: ERC20_TRANSFER_GAS,
|
|
288
|
+
chainId: context.chainId,
|
|
289
|
+
type: txType,
|
|
290
|
+
});
|
|
291
|
+
}));
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
// ✅ 有多跳:构建多跳转账链
|
|
296
|
+
if (useNativeToken) {
|
|
297
|
+
// BNB 多跳转账
|
|
298
|
+
// ✅ 修复:payer 每次只发送 1 笔交易(到第一个hop钱包),hop钱包用自己的nonce=0
|
|
299
|
+
const hopChains = await Promise.all(hopPaths.map((path, i) => {
|
|
300
|
+
const finalAmount = transferAmountsWei[i] + FLAT_FEE + buyerGasCost;
|
|
301
|
+
const payerNonce = sellerNonce + i; // ✅ payer 每个 buyer 只用 1 个 nonce
|
|
302
|
+
return buildNativeHopChain(seller, path, finalAmount, gasPrice, context.chainId, txType, payerNonce);
|
|
303
|
+
}));
|
|
304
|
+
transferTxs = hopChains.flat();
|
|
305
|
+
sellerNonce += buyers.length; // ✅ payer 只增加 buyers.length 个 nonce
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
// ERC20 多跳转账:先转 BNB(给中间钱包 gas),再转 ERC20
|
|
309
|
+
// ✅ 修复:payer 每次只发送 1 笔交易(到第一个hop钱包),hop钱包用自己的nonce=0/1
|
|
310
|
+
// 1. 构建 BNB 多跳链(为中间钱包和最终钱包预留 gas)
|
|
311
|
+
const bnbHopChains = await Promise.all(hopPaths.map((path, i) => {
|
|
312
|
+
// 最终钱包需要的 gas(用于买入交易)
|
|
313
|
+
const finalGasAmount = buyerGasCost;
|
|
314
|
+
const payerNonce = sellerNonce + i; // ✅ payer 每个 buyer 只用 1 个 nonce
|
|
315
|
+
return buildBNBHopChainForERC20(seller, path, finalGasAmount, gasPrice, context.chainId, txType, payerNonce);
|
|
316
|
+
}));
|
|
317
|
+
const bnbTxs = bnbHopChains.flat();
|
|
318
|
+
sellerNonce += buyers.length; // ✅ payer 只增加 buyers.length 个 nonce
|
|
319
|
+
// 2. 构建 ERC20 多跳链
|
|
320
|
+
const erc20HopChains = await Promise.all(hopPaths.map((path, i) => {
|
|
321
|
+
const payerNonce = sellerNonce + i; // ✅ payer 每个 buyer 只用 1 个 nonce
|
|
322
|
+
return buildERC20HopChain(seller, path, quoteToken, transferAmountsWei[i], gasPrice, context.chainId, txType, payerNonce);
|
|
323
|
+
}));
|
|
324
|
+
const erc20Txs = erc20HopChains.flat();
|
|
325
|
+
sellerNonce += buyers.length; // ✅ payer 只增加 buyers.length 个 nonce
|
|
326
|
+
transferTxs = [...bnbTxs, ...erc20Txs];
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
// ==================== 4. 买入交易 ====================
|
|
330
|
+
// ✅ 如果前端传入了 startNonces,使用 buyer 部分(从索引 1 开始)
|
|
331
|
+
const buyerNonces = startNonces && startNonces.length > 1
|
|
332
|
+
? startNonces.slice(1)
|
|
333
|
+
: await Promise.all(buyers.map((buyer) => nonceManager.getNextNonce(buyer)));
|
|
334
|
+
const signedBuys = await Promise.all(buyers.map(async (buyer, i) => {
|
|
335
|
+
const buyAmount = transferAmountsWei[i];
|
|
336
|
+
// ✅ ERC20 模式:value = 0(通过代币授权支付)
|
|
337
|
+
const buyValue = useNativeToken ? buyAmount + FLAT_FEE : 0n;
|
|
338
|
+
let buyUnsigned;
|
|
339
|
+
if (routeParams.routeType === 'v2') {
|
|
340
|
+
const { v2Path } = routeParams;
|
|
341
|
+
const reversePath = [...v2Path].reverse();
|
|
342
|
+
const v2RouterBuyer = new Contract(quickV2Addr, PANCAKE_V2_ROUTER_ABI, buyer);
|
|
343
|
+
if (useNativeToken) {
|
|
344
|
+
buyUnsigned = await v2RouterBuyer.swapExactETHForTokensSupportingFeeOnTransferTokens.populateTransaction(0n, reversePath, buyer.address, deadline, { value: buyValue });
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
buyUnsigned = await v2RouterBuyer.swapExactTokensForTokensSupportingFeeOnTransferTokens.populateTransaction(buyAmount, 0n, reversePath, buyer.address, deadline);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
else if (routeParams.routeType === 'v3-single') {
|
|
351
|
+
const { v3TokenIn, v3TokenOut, v3Fee } = routeParams;
|
|
352
|
+
const v3RouterBuyer = new Contract(PANCAKE_V3_ROUTER_ADDRESS, PANCAKE_V3_ROUTER_ABI, buyer);
|
|
353
|
+
const buySwapData = v3RouterIface2.encodeFunctionData('exactInputSingle', [
|
|
354
|
+
{
|
|
355
|
+
tokenIn: v3TokenOut,
|
|
356
|
+
tokenOut: v3TokenIn,
|
|
357
|
+
fee: v3Fee,
|
|
358
|
+
recipient: buyer.address,
|
|
359
|
+
amountIn: buyAmount,
|
|
360
|
+
amountOutMinimum: 0n,
|
|
361
|
+
sqrtPriceLimitX96: 0n,
|
|
362
|
+
},
|
|
363
|
+
]);
|
|
364
|
+
buyUnsigned = await v3RouterBuyer.multicall.populateTransaction(deadline, [buySwapData], { value: buyValue });
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
throw new Error('V3 多跳路由暂不支持官方合约,请使用 V2 路由或 V3 单跳');
|
|
368
|
+
}
|
|
369
|
+
return buyer.signTransaction({
|
|
370
|
+
...buyUnsigned,
|
|
371
|
+
from: buyer.address,
|
|
372
|
+
nonce: buyerNonces[i],
|
|
373
|
+
gasLimit: finalGasLimit,
|
|
374
|
+
gasPrice,
|
|
375
|
+
chainId: context.chainId,
|
|
376
|
+
type: txType,
|
|
377
|
+
});
|
|
378
|
+
}));
|
|
379
|
+
nonceManager.clearTemp();
|
|
380
|
+
// ==================== 组装交易数组 ====================
|
|
381
|
+
// BNB 模式:贿赂 → 卖出 → 转账 → 买入 → 利润多跳
|
|
382
|
+
// ERC20 模式:贿赂 → 卖出 → ERC20转账 → BNB Gas转账 → 买入 → 利润多跳
|
|
383
|
+
const signedTransactions = [];
|
|
384
|
+
if (bribeTx)
|
|
385
|
+
signedTransactions.push(bribeTx);
|
|
386
|
+
signedTransactions.push(signedSell);
|
|
387
|
+
signedTransactions.push(...transferTxs);
|
|
388
|
+
signedTransactions.push(...signedBuys);
|
|
389
|
+
// ==================== 5. 利润多跳转账(强制 2 跳中转)====================
|
|
390
|
+
let profitHopWallets;
|
|
391
|
+
if (profitAmount > 0n) {
|
|
392
|
+
const profitHopResult = await buildProfitHopTransactions({
|
|
393
|
+
provider: context.provider,
|
|
394
|
+
payerWallet: seller,
|
|
395
|
+
profitAmount,
|
|
396
|
+
profitRecipient: getProfitRecipient(),
|
|
397
|
+
hopCount: PROFIT_HOP_COUNT,
|
|
398
|
+
gasPrice,
|
|
399
|
+
chainId: context.chainId,
|
|
400
|
+
txType,
|
|
401
|
+
startNonce: sellerNonce++,
|
|
402
|
+
});
|
|
403
|
+
signedTransactions.push(...profitHopResult.signedTransactions);
|
|
404
|
+
profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
|
|
405
|
+
// 多跳交易已签名
|
|
406
|
+
}
|
|
407
|
+
return {
|
|
408
|
+
signedTransactions,
|
|
409
|
+
disperseHopWallets: allHopWallets.length > 0 ? allHopWallets : undefined, // ✅ 返回转账多跳钱包
|
|
410
|
+
profitHopWallets, // ✅ 返回利润多跳钱包
|
|
411
|
+
metadata: {
|
|
412
|
+
sellerAddress: seller.address,
|
|
413
|
+
buyerAddresses: buyers.map((b) => b.address),
|
|
414
|
+
sellAmount: ethers.formatUnits(sellAmountWei, decimals),
|
|
415
|
+
estimatedOutput: useNativeToken
|
|
416
|
+
? ethers.formatEther(estimatedOutput)
|
|
417
|
+
: ethers.formatUnits(estimatedOutput, quoteTokenDecimals),
|
|
418
|
+
transferAmounts: transferAmountsWei.map((amt) => useNativeToken ? ethers.formatEther(amt) : ethers.formatUnits(amt, quoteTokenDecimals)),
|
|
419
|
+
profitAmount: profitAmount > 0n ? ethers.formatEther(profitAmount) : undefined,
|
|
420
|
+
useNativeToken,
|
|
421
|
+
disperseHopCount: disperseHopCount > 0 ? disperseHopCount : undefined, // ✅ 返回多跳数
|
|
422
|
+
},
|
|
423
|
+
};
|
|
424
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* swap-single - 单笔换手(一卖一买)
|
|
3
|
+
*/
|
|
4
|
+
import { getProfitRecipient, BLOCKRAZOR_BUILDER_EOA } from '../../../core/constants/index.js';
|
|
5
|
+
import { getGasLimit } from '../../../core/gas/bundle-gas.js';
|
|
6
|
+
import { ethers, Wallet } from 'ethers';
|
|
7
|
+
import { calculateSellAmount } from '../../../utils/swap-helpers.js';
|
|
8
|
+
import { NonceManager, buildProfitHopTransactions, PROFIT_HOP_COUNT, } from '../../../utils/bundle-helpers.js';
|
|
9
|
+
import { BRIBE_GAS_LIMIT, ZERO_ADDRESS, buildNoncePlanFromNonces, buildSwapTransactions, calculateBuyerBudget, calculateProfitAmount, createPancakeContext, getERC20ToNativeQuote, getGasPrice, planNonces, quoteSellOutput, validateFinalBalances, } from './bundle-swap-helpers.js';
|
|
10
|
+
export async function pancakeBundleSwapMerkle(params) {
|
|
11
|
+
const { sellerPrivateKey, sellAmount, sellPercentage, buyerPrivateKey, tokenAddress, routeParams, config, quoteToken, quoteTokenDecimals = 18, startNonces, // ✅ 可选:前端预获取的 nonces
|
|
12
|
+
} = params;
|
|
13
|
+
// ✅ 判断是否使用原生代币(BNB)或 ERC20 代币(如 USDT)
|
|
14
|
+
const useNativeToken = !quoteToken || quoteToken === ZERO_ADDRESS;
|
|
15
|
+
const context = createPancakeContext(config);
|
|
16
|
+
const seller = new Wallet(sellerPrivateKey, context.provider);
|
|
17
|
+
const buyer = new Wallet(buyerPrivateKey, context.provider);
|
|
18
|
+
const sameAddress = seller.address.toLowerCase() === buyer.address.toLowerCase();
|
|
19
|
+
// ✅ 提前创建 NonceManager,供所有交易共享
|
|
20
|
+
const nonceManager = new NonceManager(context.provider);
|
|
21
|
+
const finalGasLimit = getGasLimit(config, 800000);
|
|
22
|
+
const txType = config.txType ?? 0;
|
|
23
|
+
// ✅ 并行获取 gasPrice 和卖出数量
|
|
24
|
+
const [gasPrice, sellAmountResult] = await Promise.all([
|
|
25
|
+
getGasPrice(context.provider, config),
|
|
26
|
+
calculateSellAmount(context.provider, tokenAddress, seller.address, sellAmount, sellPercentage),
|
|
27
|
+
]);
|
|
28
|
+
const { amount: sellAmountWei, decimals } = sellAmountResult;
|
|
29
|
+
const quoteResult = await quoteSellOutput({
|
|
30
|
+
routeParams,
|
|
31
|
+
sellAmountWei,
|
|
32
|
+
provider: context.provider,
|
|
33
|
+
v2RouterAddress: config.v2RouterAddress,
|
|
34
|
+
});
|
|
35
|
+
const buyerBudget = await calculateBuyerBudget({
|
|
36
|
+
buyer,
|
|
37
|
+
quotedBNBOut: quoteResult.estimatedBNBOut,
|
|
38
|
+
reserveGasBNB: config.reserveGasBNB,
|
|
39
|
+
useNativeToken,
|
|
40
|
+
quoteToken,
|
|
41
|
+
quoteTokenDecimals,
|
|
42
|
+
provider: context.provider,
|
|
43
|
+
});
|
|
44
|
+
const swapUnsigned = await buildSwapTransactions({
|
|
45
|
+
routeParams,
|
|
46
|
+
sellAmountWei,
|
|
47
|
+
buyAmountBNB: buyerBudget.buyAmountBNB,
|
|
48
|
+
buyer,
|
|
49
|
+
seller,
|
|
50
|
+
tokenAddress,
|
|
51
|
+
useNativeToken,
|
|
52
|
+
v2RouterAddress: config.v2RouterAddress,
|
|
53
|
+
});
|
|
54
|
+
// ✅ 修复:利润计算应基于 BNB 数量,不是 ERC20 数量
|
|
55
|
+
// 如果输出是原生代币(BNB),直接使用报价结果
|
|
56
|
+
// 如果输出是 ERC20(如 USDT),需要先转换为 BNB 等值
|
|
57
|
+
let profitAmount;
|
|
58
|
+
if (useNativeToken) {
|
|
59
|
+
// 输出是 BNB,直接计算利润(根据 userType 动态调整)
|
|
60
|
+
profitAmount = calculateProfitAmount(quoteResult.estimatedBNBOut, config.userType);
|
|
61
|
+
// 利润计算完成
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// 输出是 ERC20,需要先获取 ERC20 → BNB 的报价
|
|
65
|
+
const version = routeParams.routeType === 'v2' ? 'v2' : 'v3';
|
|
66
|
+
const fee = routeParams.routeType === 'v3-single' ? routeParams.v3Fee : undefined;
|
|
67
|
+
const estimatedBNBValue = await getERC20ToNativeQuote(context.provider, quoteToken, quoteResult.estimatedBNBOut, // 这实际上是 ERC20 数量
|
|
68
|
+
version, fee);
|
|
69
|
+
profitAmount = calculateProfitAmount(estimatedBNBValue, config.userType);
|
|
70
|
+
// ERC20→BNB 报价完成
|
|
71
|
+
}
|
|
72
|
+
// ✅ 获取贿赂金额
|
|
73
|
+
const bribeAmount = config.bribeAmount && config.bribeAmount > 0 ? ethers.parseEther(String(config.bribeAmount)) : 0n;
|
|
74
|
+
const needBribeTx = bribeAmount > 0n;
|
|
75
|
+
// ✅ 使用共享的 NonceManager 规划 nonce
|
|
76
|
+
// 如果前端传入了 startNonces,直接使用(性能优化)
|
|
77
|
+
const noncePlan = startNonces && startNonces.length >= (sameAddress ? 1 : 2)
|
|
78
|
+
? buildNoncePlanFromNonces(startNonces, sameAddress, false, profitAmount > 0n, needBribeTx)
|
|
79
|
+
: await planNonces({
|
|
80
|
+
seller,
|
|
81
|
+
buyer,
|
|
82
|
+
sameAddress,
|
|
83
|
+
approvalExists: false, // ✅ 已移除授权
|
|
84
|
+
profitNeeded: profitAmount > 0n,
|
|
85
|
+
needBribeTx,
|
|
86
|
+
nonceManager,
|
|
87
|
+
});
|
|
88
|
+
// ✅ 并行签名所有交易
|
|
89
|
+
const signPromises = [];
|
|
90
|
+
// 贿赂交易
|
|
91
|
+
if (needBribeTx && noncePlan.bribeNonce !== undefined) {
|
|
92
|
+
signPromises.push(seller
|
|
93
|
+
.signTransaction({
|
|
94
|
+
to: BLOCKRAZOR_BUILDER_EOA,
|
|
95
|
+
value: bribeAmount,
|
|
96
|
+
nonce: noncePlan.bribeNonce,
|
|
97
|
+
gasPrice,
|
|
98
|
+
gasLimit: BRIBE_GAS_LIMIT,
|
|
99
|
+
chainId: context.chainId,
|
|
100
|
+
type: txType,
|
|
101
|
+
})
|
|
102
|
+
.then((tx) => ({ type: 'bribe', tx })));
|
|
103
|
+
}
|
|
104
|
+
// 卖出交易
|
|
105
|
+
signPromises.push(seller
|
|
106
|
+
.signTransaction({
|
|
107
|
+
...swapUnsigned.sellUnsigned,
|
|
108
|
+
from: seller.address,
|
|
109
|
+
nonce: noncePlan.sellerNonce,
|
|
110
|
+
gasLimit: finalGasLimit,
|
|
111
|
+
gasPrice,
|
|
112
|
+
chainId: context.chainId,
|
|
113
|
+
type: txType,
|
|
114
|
+
})
|
|
115
|
+
.then((tx) => ({ type: 'sell', tx })));
|
|
116
|
+
// 买入交易
|
|
117
|
+
signPromises.push(buyer
|
|
118
|
+
.signTransaction({
|
|
119
|
+
...swapUnsigned.buyUnsigned,
|
|
120
|
+
from: buyer.address,
|
|
121
|
+
nonce: noncePlan.buyerNonce,
|
|
122
|
+
gasLimit: finalGasLimit,
|
|
123
|
+
gasPrice,
|
|
124
|
+
chainId: context.chainId,
|
|
125
|
+
type: txType,
|
|
126
|
+
})
|
|
127
|
+
.then((tx) => ({ type: 'buy', tx })));
|
|
128
|
+
// ✅ 并行执行所有签名
|
|
129
|
+
const signedResults = await Promise.all(signPromises);
|
|
130
|
+
// 按类型提取结果
|
|
131
|
+
const bribeTx = signedResults.find((r) => r.type === 'bribe')?.tx || null;
|
|
132
|
+
const signedSell = signedResults.find((r) => r.type === 'sell').tx;
|
|
133
|
+
const signedBuy = signedResults.find((r) => r.type === 'buy').tx;
|
|
134
|
+
nonceManager.clearTemp();
|
|
135
|
+
validateFinalBalances({
|
|
136
|
+
sameAddress,
|
|
137
|
+
buyerBalance: buyerBudget.buyerBalance,
|
|
138
|
+
buyAmountBNB: buyerBudget.buyAmountBNB,
|
|
139
|
+
reserveGas: buyerBudget.reserveGas,
|
|
140
|
+
gasLimit: finalGasLimit,
|
|
141
|
+
gasPrice,
|
|
142
|
+
useNativeToken,
|
|
143
|
+
quoteTokenDecimals,
|
|
144
|
+
provider: context.provider,
|
|
145
|
+
buyerAddress: buyer.address,
|
|
146
|
+
});
|
|
147
|
+
// ✅ 组装顺序:贿赂 → 卖出 → 买入
|
|
148
|
+
const signedTransactions = [];
|
|
149
|
+
if (bribeTx)
|
|
150
|
+
signedTransactions.push(bribeTx);
|
|
151
|
+
signedTransactions.push(signedSell, signedBuy);
|
|
152
|
+
// ✅ 利润多跳转账(强制 2 跳中转)
|
|
153
|
+
let profitHopWallets;
|
|
154
|
+
if (profitAmount > 0n && noncePlan.profitNonce !== undefined) {
|
|
155
|
+
const profitHopResult = await buildProfitHopTransactions({
|
|
156
|
+
provider: context.provider,
|
|
157
|
+
payerWallet: seller,
|
|
158
|
+
profitAmount,
|
|
159
|
+
profitRecipient: getProfitRecipient(),
|
|
160
|
+
hopCount: PROFIT_HOP_COUNT,
|
|
161
|
+
gasPrice,
|
|
162
|
+
chainId: context.chainId,
|
|
163
|
+
txType,
|
|
164
|
+
startNonce: noncePlan.profitNonce,
|
|
165
|
+
});
|
|
166
|
+
signedTransactions.push(...profitHopResult.signedTransactions);
|
|
167
|
+
profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
signedTransactions,
|
|
171
|
+
profitHopWallets, // ✅ 导出利润多跳钱包
|
|
172
|
+
metadata: {
|
|
173
|
+
sellerAddress: seller.address,
|
|
174
|
+
buyerAddress: buyer.address,
|
|
175
|
+
sellAmount: ethers.formatUnits(sellAmountWei, decimals),
|
|
176
|
+
buyAmount: useNativeToken
|
|
177
|
+
? ethers.formatEther(buyerBudget.buyAmountBNB)
|
|
178
|
+
: ethers.formatUnits(buyerBudget.buyAmountBNB, quoteTokenDecimals),
|
|
179
|
+
profitAmount: profitAmount > 0n ? ethers.formatEther(profitAmount) : undefined,
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* BSC - Four.meme
|
|
2
|
+
* BSC - Four.meme 平台模块(有意 facade)
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* 这是 chains/bsc 层的 Four.meme 快捷入口 facade,被 chains/bsc/index.ts 引用,
|
|
5
|
+
* 用于把 bundle 层的 Four.meme 实现以快捷别名暴露到 chains/bsc 命名空间下。
|
|
6
|
+
*
|
|
7
|
+
* 依赖说明:本文件仅从 `bundle/` 层重新导出(types / errors / config-helpers /
|
|
8
|
+
* four-meme 各子模块 / submit),不引入除 bundle 之外的其它反向依赖(如 domains/、
|
|
9
|
+
* chains/ 其它平台),故作为 facade 有意保留,不修改任何导出与逻辑。
|
|
5
10
|
*/
|
|
6
|
-
export * from '
|
|
11
|
+
export type * from '../../../../bundle/four-meme/types/index.js';
|
|
12
|
+
export type { FourAnyConfig } from '../../../../bundle/four-meme/types/core-flow.js';
|
|
13
|
+
export { BUNDLE_ERRORS as ERRORS, getBundleErrorMessage as getErrorMessage, } from '../../../../bundle/errors.js';
|
|
14
|
+
export { getTxType, getGasPriceMultiplier, getBundleOptions, getGasPriceConfig, shouldExtractProfit, getProfitRateBps, getProfitRecipient, calculateProfit, calculateBatchProfit, getBribeAmount, } from '../../../../bundle/config-helpers.js';
|
|
15
|
+
export { createTokenWithBundleBuyMerkle, batchBuyWithBundleMerkle, batchSellWithBundleMerkle, } from '../../../../bundle/four-meme/core.js';
|
|
16
|
+
export { fourPrivateBuyMerkle, fourPrivateSellMerkle, fourBatchPrivateBuyMerkle, fourBatchPrivateSellMerkle, } from '../../../../bundle/four-meme/private.js';
|
|
17
|
+
export { disperseWithBundleMerkle } from '../../../../bundle/four-meme/utils-disperse.js';
|
|
18
|
+
export { sweepWithBundleMerkle } from '../../../../bundle/four-meme/utils-sweep.js';
|
|
19
|
+
export { pairwiseTransferWithBundleMerkle } from '../../../../bundle/four-meme/utils-pairwise.js';
|
|
20
|
+
export { fourPancakeProxyBatchBuyMerkle, fourPancakeProxyBatchSellMerkle, approveFourPancakeProxy, approveFourPancakeProxyBatch, } from '../../../../bundle/four-meme/pancake-proxy.js';
|
|
21
|
+
export { approveFourTokenManagerBatch } from '../../../../bundle/four-meme/approve-tokenmanager.js';
|
|
22
|
+
export { submitBundleToMerkle, submitMultipleBundles, submitMultipleBundlesParallel, submitBundleToBlockRazor, submitMultipleBundlesToBlockRazor, submitMultipleBundlesToBlockRazorParallel, submitDirectToRpc, submitDirectToRpcSequential, submitDirectToRpcSequentialNoWait, submitDirectToRpcParallel, submitDirectToRpcSmart, type MerkleSubmitConfig, type SubmitBundleResult, type BlockRazorSubmitConfig, type BlockRazorSubmitResult, type DirectSubmitConfig, type DirectSubmitResult, type DirectTxResult, } from '../../../../bundle/submit.js';
|
|
23
|
+
export { fourBundleBuyFirstMerkle } from '../../../../bundle/four-meme/swap-buy-first.js';
|
|
24
|
+
export { fourBundleSwapMerkle, fourBatchSwapMerkle, fourQuickBatchSwapMerkle, } from '../../../../bundle/four-meme/swap.js';
|