four-flap-meme-sdk 3.0.1 → 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/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/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 -85
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EIP-7702 买到毕业 (Graduate Buy)
|
|
3
|
+
*
|
|
4
|
+
* 自动计算剩余毕业容量,将钱包分为内盘和外盘组:
|
|
5
|
+
* 1. 内盘买入(直到毕业)
|
|
6
|
+
* 2. 外盘买入(毕业后)
|
|
7
|
+
* 3. 利润提取
|
|
8
|
+
*
|
|
9
|
+
* 只生成签名,由调用方决定如何提交
|
|
10
|
+
*/
|
|
11
|
+
import type { BundleGraduateBuyParams, BundleGraduateBuyResult } from './types.js';
|
|
12
|
+
/**
|
|
13
|
+
* 买到毕业(EIP-7702 版本)
|
|
14
|
+
*
|
|
15
|
+
* 自动计算剩余毕业容量,将钱包分为内盘和外盘组:
|
|
16
|
+
* 1. 内盘买入(直到毕业)
|
|
17
|
+
* 2. 外盘买入(毕业后)
|
|
18
|
+
* 3. 利润提取
|
|
19
|
+
*
|
|
20
|
+
* @returns 只返回签名后的交易,不发送
|
|
21
|
+
*/
|
|
22
|
+
export declare function bundleGraduateBuy(params: BundleGraduateBuyParams): Promise<BundleGraduateBuyResult>;
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EIP-7702 买到毕业 (Graduate Buy)
|
|
3
|
+
*
|
|
4
|
+
* 自动计算剩余毕业容量,将钱包分为内盘和外盘组:
|
|
5
|
+
* 1. 内盘买入(直到毕业)
|
|
6
|
+
* 2. 外盘买入(毕业后)
|
|
7
|
+
* 3. 利润提取
|
|
8
|
+
*
|
|
9
|
+
* 只生成签名,由调用方决定如何提交
|
|
10
|
+
*/
|
|
11
|
+
import { ethers, Interface, Contract } from 'ethers';
|
|
12
|
+
import { FLAP_PORTAL_ADDRESS, UNIFIED_DELEGATE_ADDRESS, UNIFIED_DELEGATE_ABI, FLAP_PORTAL_ABI, POTATOSWAP_V2_ROUTER, POTATOSWAP_V3_ROUTER, GAS_ESTIMATE, } from './constants.js';
|
|
13
|
+
import { getCachedProvider, createWallet, signAuthorizationsWithNonces, batchGetNonces, buildEIP7702TransactionSync, calculateProfitAmountByUserType, getProfitRecipient, } from './utils.js';
|
|
14
|
+
import { lpFeeProfileToV3Fee, buildProfitCall, encodeFlapBuyCall, encodeV3BuyCall, encodeV2BuyCall, } from './bundle-create-helpers.js';
|
|
15
|
+
/**
|
|
16
|
+
* 买到毕业(EIP-7702 版本)
|
|
17
|
+
*
|
|
18
|
+
* 自动计算剩余毕业容量,将钱包分为内盘和外盘组:
|
|
19
|
+
* 1. 内盘买入(直到毕业)
|
|
20
|
+
* 2. 外盘买入(毕业后)
|
|
21
|
+
* 3. 利润提取
|
|
22
|
+
*
|
|
23
|
+
* @returns 只返回签名后的交易,不发送
|
|
24
|
+
*/
|
|
25
|
+
export async function bundleGraduateBuy(params) {
|
|
26
|
+
const { tokenAddress, privateKeys, payerPrivateKey, amountMode, totalBuyAmount, minAmount, maxAmount, walletAmounts, enableDexBuy = false, extensionData = '0x', curveAddresses, dexAddresses, graduationAmount, userType = 'v0', // ✅ 用户类型(影响利润率)
|
|
27
|
+
config, } = params;
|
|
28
|
+
const provider = getCachedProvider(config?.rpcUrl);
|
|
29
|
+
const delegateAddress = (config?.delegateAddress && config.delegateAddress.trim()) || UNIFIED_DELEGATE_ADDRESS;
|
|
30
|
+
const delegateInterface = new Interface(UNIFIED_DELEGATE_ABI);
|
|
31
|
+
// 创建钱包
|
|
32
|
+
const payerWallet = createWallet(payerPrivateKey, provider);
|
|
33
|
+
const wallets = privateKeys.map((pk) => createWallet(pk, provider));
|
|
34
|
+
// 获取代币状态
|
|
35
|
+
const portalContract = new Contract(FLAP_PORTAL_ADDRESS, FLAP_PORTAL_ABI, provider);
|
|
36
|
+
const tokenState = await portalContract.getTokenV7(tokenAddress);
|
|
37
|
+
const reserve = tokenState[1];
|
|
38
|
+
const h = tokenState[5];
|
|
39
|
+
const k = tokenState[6];
|
|
40
|
+
const lpFeeProfile = Number(tokenState[15]);
|
|
41
|
+
// 计算毕业容量
|
|
42
|
+
const graduationReserveWei = (h * k) / 10n ** 18n;
|
|
43
|
+
const poolReserveOkb = Number(ethers.formatEther(reserve));
|
|
44
|
+
const graduateCapacity = graduationAmount ?? Number(ethers.formatEther(graduationReserveWei));
|
|
45
|
+
const remainingToGraduate = Math.max(0, graduateCapacity - poolReserveOkb);
|
|
46
|
+
const remainingToGraduateWei = ethers.parseEther(remainingToGraduate.toFixed(18));
|
|
47
|
+
// 计算每个钱包的金额
|
|
48
|
+
const normalizedWalletAmounts = {};
|
|
49
|
+
if (walletAmounts) {
|
|
50
|
+
for (const [key, value] of Object.entries(walletAmounts)) {
|
|
51
|
+
normalizedWalletAmounts[key.toLowerCase()] = value;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
let finalAmounts = [];
|
|
55
|
+
if (amountMode === 'average') {
|
|
56
|
+
const avg = (totalBuyAmount || 0) / wallets.length;
|
|
57
|
+
finalAmounts = wallets.map(() => avg);
|
|
58
|
+
}
|
|
59
|
+
else if (amountMode === 'random') {
|
|
60
|
+
finalAmounts = wallets.map(() => {
|
|
61
|
+
return (minAmount || 0) + Math.random() * ((maxAmount || 0) - (minAmount || 0));
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
else if (amountMode === 'custom') {
|
|
65
|
+
finalAmounts = wallets.map((w) => {
|
|
66
|
+
return normalizedWalletAmounts[w.address.toLowerCase()] ?? 0;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
// 钱包分组
|
|
70
|
+
const curveBuyers = [];
|
|
71
|
+
const dexBuyers = [];
|
|
72
|
+
const hasFrontendGrouping = curveAddresses && curveAddresses.length > 0;
|
|
73
|
+
if (hasFrontendGrouping) {
|
|
74
|
+
const curveSet = new Set(curveAddresses.map((a) => a.toLowerCase()));
|
|
75
|
+
const dexSet = dexAddresses ? new Set(dexAddresses.map((a) => a.toLowerCase())) : new Set();
|
|
76
|
+
for (let i = 0; i < wallets.length; i++) {
|
|
77
|
+
const wallet = wallets[i];
|
|
78
|
+
const ownerAddr = wallet.address.toLowerCase();
|
|
79
|
+
const amountNum = normalizedWalletAmounts[ownerAddr] ?? finalAmounts[i] ?? 0;
|
|
80
|
+
const amountWei = ethers.parseEther(amountNum.toFixed(18));
|
|
81
|
+
if (curveSet.has(ownerAddr)) {
|
|
82
|
+
curveBuyers.push({ wallet, amount: amountWei });
|
|
83
|
+
}
|
|
84
|
+
else if (dexSet.has(ownerAddr) && enableDexBuy) {
|
|
85
|
+
dexBuyers.push({ wallet, amount: amountWei });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
let currentCurveTotal = 0n;
|
|
91
|
+
for (let i = 0; i < wallets.length; i++) {
|
|
92
|
+
const wallet = wallets[i];
|
|
93
|
+
const amountWei = ethers.parseEther(finalAmounts[i].toFixed(18));
|
|
94
|
+
if (currentCurveTotal < remainingToGraduateWei) {
|
|
95
|
+
const needed = remainingToGraduateWei - currentCurveTotal;
|
|
96
|
+
if (amountWei <= needed) {
|
|
97
|
+
curveBuyers.push({ wallet, amount: amountWei });
|
|
98
|
+
currentCurveTotal += amountWei;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
curveBuyers.push({ wallet, amount: needed });
|
|
102
|
+
currentCurveTotal = remainingToGraduateWei;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else if (enableDexBuy) {
|
|
106
|
+
dexBuyers.push({ wallet, amount: amountWei });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// 合并所有参与的钱包
|
|
111
|
+
const allWalletsMap = new Map();
|
|
112
|
+
allWalletsMap.set(payerWallet.address.toLowerCase(), payerWallet);
|
|
113
|
+
curveBuyers.forEach((b) => allWalletsMap.set(b.wallet.address.toLowerCase(), b.wallet));
|
|
114
|
+
dexBuyers.forEach((b) => allWalletsMap.set(b.wallet.address.toLowerCase(), b.wallet));
|
|
115
|
+
const allWallets = Array.from(allWalletsMap.values());
|
|
116
|
+
const mainWallet = payerWallet;
|
|
117
|
+
const mainWalletIndex = allWallets.findIndex((w) => w.address.toLowerCase() === mainWallet.address.toLowerCase());
|
|
118
|
+
// 计算金额和利润(单边模式:只有买入)
|
|
119
|
+
const curveTotalWei = curveBuyers.reduce((sum, b) => sum + b.amount, 0n);
|
|
120
|
+
const dexTotalWei = dexBuyers.reduce((sum, b) => sum + b.amount, 0n);
|
|
121
|
+
const totalAmount = curveTotalWei + dexTotalWei;
|
|
122
|
+
const profitAmount = calculateProfitAmountByUserType(totalAmount, userType, false); // ✅ 支持 userType
|
|
123
|
+
const profitRecipient = getProfitRecipient(config);
|
|
124
|
+
// 并行获取 nonce 和 fee data
|
|
125
|
+
const [nonces, feeData] = await Promise.all([
|
|
126
|
+
batchGetNonces(allWallets.map((w) => w.address), provider),
|
|
127
|
+
provider.getFeeData(),
|
|
128
|
+
]);
|
|
129
|
+
// 签名授权
|
|
130
|
+
const authorizations = signAuthorizationsWithNonces(allWallets, nonces, delegateAddress, mainWalletIndex);
|
|
131
|
+
// 构建调用
|
|
132
|
+
const calls = [];
|
|
133
|
+
const deadline = Math.floor(Date.now() / 1000) + 1200; // 20 min
|
|
134
|
+
// 1. 利润转账
|
|
135
|
+
if (profitAmount > 0n) {
|
|
136
|
+
calls.push(buildProfitCall(payerWallet.address, profitAmount, profitRecipient, delegateInterface));
|
|
137
|
+
}
|
|
138
|
+
// 2. 内盘买入
|
|
139
|
+
// lpFeeProfile >= 0 表示 V3 池子,需要使用 swapExactInputV3
|
|
140
|
+
const useV3OrV4 = lpFeeProfile !== undefined && lpFeeProfile >= 0;
|
|
141
|
+
for (let i = 0; i < curveBuyers.length; i++) {
|
|
142
|
+
const { wallet, amount } = curveBuyers[i];
|
|
143
|
+
const buyData = encodeFlapBuyCall(tokenAddress, amount, useV3OrV4, extensionData);
|
|
144
|
+
const buyBatchCall = delegateInterface.encodeFunctionData('executeBatch', [
|
|
145
|
+
[
|
|
146
|
+
{
|
|
147
|
+
target: FLAP_PORTAL_ADDRESS,
|
|
148
|
+
value: amount,
|
|
149
|
+
data: buyData,
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
]);
|
|
153
|
+
// ✅ 修复:value 设为 0n,让钱包使用自己余额买入
|
|
154
|
+
calls.push({
|
|
155
|
+
target: wallet.address,
|
|
156
|
+
allowFailure: false,
|
|
157
|
+
value: 0n,
|
|
158
|
+
callData: buyBatchCall,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
// 3. 外盘买入
|
|
162
|
+
if (enableDexBuy && dexBuyers.length > 0) {
|
|
163
|
+
const dexType = lpFeeProfile >= 0 ? 'V3' : 'V2';
|
|
164
|
+
const v3Fee = lpFeeProfileToV3Fee(lpFeeProfile);
|
|
165
|
+
for (let i = 0; i < dexBuyers.length; i++) {
|
|
166
|
+
const { wallet, amount } = dexBuyers[i];
|
|
167
|
+
let swapData;
|
|
168
|
+
let routerAddress;
|
|
169
|
+
if (dexType === 'V3') {
|
|
170
|
+
routerAddress = POTATOSWAP_V3_ROUTER;
|
|
171
|
+
swapData = encodeV3BuyCall(tokenAddress, v3Fee, wallet.address, deadline, amount);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
routerAddress = POTATOSWAP_V2_ROUTER;
|
|
175
|
+
swapData = encodeV2BuyCall(tokenAddress, wallet.address, deadline);
|
|
176
|
+
}
|
|
177
|
+
const dexBatchCall = delegateInterface.encodeFunctionData('executeBatch', [
|
|
178
|
+
[
|
|
179
|
+
{
|
|
180
|
+
target: routerAddress,
|
|
181
|
+
value: amount,
|
|
182
|
+
data: swapData,
|
|
183
|
+
},
|
|
184
|
+
],
|
|
185
|
+
]);
|
|
186
|
+
// ✅ 修复:value 设为 0n,让钱包使用自己余额买入
|
|
187
|
+
calls.push({
|
|
188
|
+
target: wallet.address,
|
|
189
|
+
allowFailure: false,
|
|
190
|
+
value: 0n,
|
|
191
|
+
callData: dexBatchCall,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
// ✅ 利润从 Payer 钱包余额转出,主交易不需要支付额外费用
|
|
196
|
+
const totalValue = 0n;
|
|
197
|
+
// 构建签名交易(毕业操作强制使用高 gas limit)
|
|
198
|
+
const graduateConfig = {
|
|
199
|
+
...config,
|
|
200
|
+
gasLimit: GAS_ESTIMATE.GRADUATE, // ✅ 毕业操作需要约 800 万 gas
|
|
201
|
+
};
|
|
202
|
+
const signedTransaction = buildEIP7702TransactionSync(mainWallet, authorizations, calls, totalValue, nonces[mainWalletIndex], feeData, graduateConfig);
|
|
203
|
+
return {
|
|
204
|
+
signedTransaction,
|
|
205
|
+
metadata: {
|
|
206
|
+
tokenAddress,
|
|
207
|
+
curveCount: curveBuyers.length,
|
|
208
|
+
dexCount: dexBuyers.length,
|
|
209
|
+
curveTotalAmount: ethers.formatEther(curveTotalWei),
|
|
210
|
+
dexTotalAmount: ethers.formatEther(dexTotalWei),
|
|
211
|
+
profitAmount: ethers.formatEther(profitAmount),
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { ethers, Contract } from 'ethers';
|
|
10
10
|
import { getCachedProvider, createWallet, signAuthorizationsWithNonces, batchGetNonces, buildEIP7702TransactionSync, calculateProfitAmountByUserType, getProfitRecipient, } from './utils.js';
|
|
11
11
|
import { UNIFIED_DELEGATE_ADDRESS, POTATOSWAP_V2_ROUTER, POTATOSWAP_V3_ROUTER, FLAP_PORTAL_ADDRESS, WOKB_ADDRESS, V3_FEE_TIERS, UNIFIED_DELEGATE_ABI, FLAP_PORTAL_ABI, ERC20_ABI, XLAYER_RPC_URL, } from './constants.js';
|
|
12
|
-
import { quoteV2, quoteV3 } from '../../../
|
|
12
|
+
import { quoteV2, quoteV3 } from '../../../core/quote/quote-helpers.js';
|
|
13
13
|
// ========================================
|
|
14
14
|
// 路由地址获取
|
|
15
15
|
// ========================================
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EIP-7702 批量换手(一卖多买)
|
|
3
|
+
*
|
|
4
|
+
* 在一笔交易中完成:
|
|
5
|
+
* 1. 主钱包卖币 → 获得 OKB
|
|
6
|
+
* 2. OKB 多跳转账 → 中间钱包1 → 中间钱包2 → 分发者
|
|
7
|
+
* 3. 分发者按比例转账给多个买家
|
|
8
|
+
* 4. 各买家买币
|
|
9
|
+
*
|
|
10
|
+
* 支持 FLAP 内盘、V2 和 V3 三种交易类型
|
|
11
|
+
* 只生成签名,由调用方决定如何提交
|
|
12
|
+
*/
|
|
13
|
+
import type { BundleBatchSwapParams, BundleSwapResult } from './types.js';
|
|
14
|
+
/**
|
|
15
|
+
* 批量换手(一卖多买)- 生成签名后的交易
|
|
16
|
+
*
|
|
17
|
+
* @param params 批量换手参数
|
|
18
|
+
* @returns 签名后的交易和元数据
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // FLAP 内盘一对多换手
|
|
22
|
+
* const result = await bundleBatchSwap({
|
|
23
|
+
* sellerPrivateKey: '0x...',
|
|
24
|
+
* buyerPrivateKeys: ['0x...', '0x...'],
|
|
25
|
+
* tokenAddress: '0x...',
|
|
26
|
+
* sellAmount: '100',
|
|
27
|
+
* tradeType: 'FLAP',
|
|
28
|
+
* });
|
|
29
|
+
*/
|
|
30
|
+
export type { BundleBatchSwapParams } from './types.js';
|
|
31
|
+
export declare function bundleBatchSwap(params: BundleBatchSwapParams): Promise<BundleSwapResult>;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EIP-7702 批量换手(一卖多买)
|
|
3
|
+
*
|
|
4
|
+
* 在一笔交易中完成:
|
|
5
|
+
* 1. 主钱包卖币 → 获得 OKB
|
|
6
|
+
* 2. OKB 多跳转账 → 中间钱包1 → 中间钱包2 → 分发者
|
|
7
|
+
* 3. 分发者按比例转账给多个买家
|
|
8
|
+
* 4. 各买家买币
|
|
9
|
+
*
|
|
10
|
+
* 支持 FLAP 内盘、V2 和 V3 三种交易类型
|
|
11
|
+
* 只生成签名,由调用方决定如何提交
|
|
12
|
+
*/
|
|
13
|
+
import { ethers } from 'ethers';
|
|
14
|
+
import { getCachedProvider, createWallet, signAuthorization, batchGetNonces, buildEIP7702TransactionSync, calculateProfitAmountByUserType, getProfitRecipient, generateRandomWallets, } from './utils.js';
|
|
15
|
+
import { UNIFIED_DELEGATE_ADDRESS, UNIFIED_DELEGATE_ABI, FLAP_PORTAL_ABI, V3_FEE_TIERS, } from './constants.js';
|
|
16
|
+
import { getDefaultRouter, truncateDecimals, quoteSellOutput, buildBuyCallInternal, buildSellCallWithAmountInternal, } from './bundle-swap-helpers.js';
|
|
17
|
+
export async function bundleBatchSwap(params) {
|
|
18
|
+
const { sellerPrivateKey, buyerPrivateKeys, buyerRatios, tokenAddress, tokenDecimals = 18, sellAmount, hopCount = 0, tradeType = 'V3', routerAddress, fee = V3_FEE_TIERS.MEDIUM, userType = 'v0', useFundUtilization = false, // ✅ 默认普通模式
|
|
19
|
+
config, } = params;
|
|
20
|
+
const provider = getCachedProvider(config?.rpcUrl);
|
|
21
|
+
const delegateAddress = (config?.delegateAddress && config.delegateAddress.trim()) || UNIFIED_DELEGATE_ADDRESS;
|
|
22
|
+
const actualRouter = routerAddress ?? getDefaultRouter(tradeType);
|
|
23
|
+
const delegateInterface = new ethers.Interface(UNIFIED_DELEGATE_ABI);
|
|
24
|
+
const portalInterface = new ethers.Interface(FLAP_PORTAL_ABI);
|
|
25
|
+
// ========================================
|
|
26
|
+
// 创建钱包
|
|
27
|
+
// ========================================
|
|
28
|
+
const sellerWallet = createWallet(sellerPrivateKey, provider);
|
|
29
|
+
const buyerWallets = buyerPrivateKeys.map((pk) => createWallet(pk, provider));
|
|
30
|
+
// 资金利用率模式才需要中间钱包
|
|
31
|
+
const actualHopCount = useFundUtilization ? hopCount : 0;
|
|
32
|
+
const hopWalletInfos = actualHopCount > 0 ? generateRandomWallets(actualHopCount) : [];
|
|
33
|
+
const hopWallets = hopWalletInfos.map((info) => createWallet(info.privateKey, provider));
|
|
34
|
+
const sellAmountWei = ethers.parseUnits(truncateDecimals(sellAmount, tokenDecimals), tokenDecimals);
|
|
35
|
+
// 获取卖出报价
|
|
36
|
+
const estimatedOkbOut = await quoteSellOutput(sellAmountWei, tokenAddress, tradeType, fee, config?.rpcUrl);
|
|
37
|
+
// 计算利润和买入金额
|
|
38
|
+
const profitAmount = estimatedOkbOut > 0n ? calculateProfitAmountByUserType(estimatedOkbOut, userType, true) : 0n;
|
|
39
|
+
const profitRecipient = getProfitRecipient(config);
|
|
40
|
+
const totalBuyAmountAfterProfit = estimatedOkbOut > profitAmount ? estimatedOkbOut - profitAmount : 0n;
|
|
41
|
+
// 验证报价
|
|
42
|
+
if (tradeType === 'FLAP' && totalBuyAmountAfterProfit <= 0n) {
|
|
43
|
+
throw new Error('FLAP 内盘模式需要有效的报价,请检查代币地址或稍后重试');
|
|
44
|
+
}
|
|
45
|
+
// ========================================
|
|
46
|
+
// 并行获取数据
|
|
47
|
+
// ========================================
|
|
48
|
+
const addressesToQuery = [sellerWallet.address, ...buyerWallets.map((w) => w.address)];
|
|
49
|
+
const [nonces, feeData, ...buyerBalances] = await Promise.all([
|
|
50
|
+
batchGetNonces(addressesToQuery, provider),
|
|
51
|
+
provider.getFeeData(),
|
|
52
|
+
...buyerWallets.map((w) => provider.getBalance(w.address)),
|
|
53
|
+
]);
|
|
54
|
+
const sellerNonce = nonces[0];
|
|
55
|
+
const buyerNonces = nonces.slice(1);
|
|
56
|
+
// 普通模式验证:买家需要预存足够的 OKB
|
|
57
|
+
if (!useFundUtilization && tradeType === 'FLAP') {
|
|
58
|
+
const totalBuyerBalance = buyerBalances.reduce((sum, b) => sum + BigInt(b.toString()), 0n);
|
|
59
|
+
if (totalBuyerBalance < totalBuyAmountAfterProfit) {
|
|
60
|
+
throw new Error(`普通模式需要买家钱包总余额足够,需要 ${ethers.formatEther(totalBuyAmountAfterProfit)},当前总计 ${ethers.formatEther(totalBuyerBalance)}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// ========================================
|
|
64
|
+
// 签署授权
|
|
65
|
+
// ========================================
|
|
66
|
+
const authPromises = [];
|
|
67
|
+
authPromises.push(signAuthorization(sellerWallet, delegateAddress, BigInt(sellerNonce + 1)));
|
|
68
|
+
for (let i = 0; i < buyerWallets.length; i++) {
|
|
69
|
+
authPromises.push(signAuthorization(buyerWallets[i], delegateAddress, BigInt(buyerNonces[i])));
|
|
70
|
+
}
|
|
71
|
+
// 中间钱包授权(资金利用率模式)
|
|
72
|
+
for (const hopWallet of hopWallets) {
|
|
73
|
+
authPromises.push(signAuthorization(hopWallet, delegateAddress, 0n));
|
|
74
|
+
}
|
|
75
|
+
const authorizations = await Promise.all(authPromises);
|
|
76
|
+
// ========================================
|
|
77
|
+
// 构建调用
|
|
78
|
+
// ========================================
|
|
79
|
+
const calls = [];
|
|
80
|
+
// ✅ 计算每个买家的买入金额
|
|
81
|
+
// 所有模式都按比例分配卖家卖出所得,避免买卖资金不匹配
|
|
82
|
+
let buyAmountsPerBuyer;
|
|
83
|
+
if (buyerWallets.length === 1) {
|
|
84
|
+
// 单买家:使用全部卖出所得
|
|
85
|
+
buyAmountsPerBuyer = [totalBuyAmountAfterProfit];
|
|
86
|
+
}
|
|
87
|
+
else if (buyerRatios && buyerRatios.length === buyerWallets.length) {
|
|
88
|
+
// 多买家 + 有比例:按前端传入的比例分配
|
|
89
|
+
let allocated = 0n;
|
|
90
|
+
buyAmountsPerBuyer = buyerRatios.map((ratio, i) => {
|
|
91
|
+
const amount = (totalBuyAmountAfterProfit * BigInt(Math.round(ratio * 10000))) / 10000n;
|
|
92
|
+
if (i === buyerRatios.length - 1) {
|
|
93
|
+
return totalBuyAmountAfterProfit - allocated;
|
|
94
|
+
}
|
|
95
|
+
allocated += amount;
|
|
96
|
+
return amount;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// 多买家无比例:均分
|
|
101
|
+
const avgAmount = totalBuyAmountAfterProfit / BigInt(buyerWallets.length);
|
|
102
|
+
const remainder = totalBuyAmountAfterProfit % BigInt(buyerWallets.length);
|
|
103
|
+
buyAmountsPerBuyer = buyerWallets.map((_, i) => i === buyerWallets.length - 1 ? avgAmount + remainder : avgAmount);
|
|
104
|
+
}
|
|
105
|
+
if (useFundUtilization) {
|
|
106
|
+
// ========================================
|
|
107
|
+
// ✅ 资金利用率模式(一卖多买)
|
|
108
|
+
// 1. 卖家卖出代币 → 获得 OKB
|
|
109
|
+
// 2. 利润从卖家 OKB 中扣除
|
|
110
|
+
// 3. 卖家(或最后一个 hop)按比例转账给各买家
|
|
111
|
+
// 4. 各买家用收到的 OKB 买入
|
|
112
|
+
// ========================================
|
|
113
|
+
// 1. 卖家卖出
|
|
114
|
+
const sellCall = buildSellCallWithAmountInternal(sellerWallet, sellAmountWei, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
|
|
115
|
+
calls.push(sellCall);
|
|
116
|
+
// 2. 利润刮取(从卖家余额扣除)
|
|
117
|
+
if (profitAmount > 0n) {
|
|
118
|
+
calls.push({
|
|
119
|
+
target: sellerWallet.address,
|
|
120
|
+
allowFailure: false,
|
|
121
|
+
value: 0n,
|
|
122
|
+
callData: delegateInterface.encodeFunctionData('transferAmount', [profitRecipient, profitAmount]),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
// 3. OKB 转账逻辑
|
|
126
|
+
// 确定分发者:如果有多跳,最后一个 hop 是分发者;否则卖家是分发者
|
|
127
|
+
const distributor = hopWallets.length > 0 ? hopWallets[hopWallets.length - 1] : sellerWallet;
|
|
128
|
+
if (hopWallets.length > 0) {
|
|
129
|
+
// ✅ 修复:卖家只转移"卖出所得 - 利润",不是全部余额
|
|
130
|
+
// 避免把卖家原有的 OKB 也转走
|
|
131
|
+
calls.push({
|
|
132
|
+
target: sellerWallet.address,
|
|
133
|
+
allowFailure: false,
|
|
134
|
+
value: 0n,
|
|
135
|
+
callData: delegateInterface.encodeFunctionData('transferAmount', [
|
|
136
|
+
hopWallets[0].address,
|
|
137
|
+
totalBuyAmountAfterProfit,
|
|
138
|
+
]),
|
|
139
|
+
});
|
|
140
|
+
// 中间钱包之间转账(到最后一个 hop):使用 transferTo(全部余额)
|
|
141
|
+
for (let i = 0; i < hopWallets.length - 1; i++) {
|
|
142
|
+
calls.push({
|
|
143
|
+
target: hopWallets[i].address,
|
|
144
|
+
allowFailure: false,
|
|
145
|
+
value: 0n,
|
|
146
|
+
callData: delegateInterface.encodeFunctionData('transferTo', [hopWallets[i + 1].address]),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// 分发者按比例转给各买家
|
|
151
|
+
for (let i = 0; i < buyerWallets.length; i++) {
|
|
152
|
+
const amountToTransfer = buyAmountsPerBuyer[i];
|
|
153
|
+
if (amountToTransfer <= 0n)
|
|
154
|
+
continue;
|
|
155
|
+
// ✅ 最后一个买家使用 transferTo(全部余额),确保资金不滞留
|
|
156
|
+
const isLastBuyer = i === buyerWallets.length - 1;
|
|
157
|
+
calls.push({
|
|
158
|
+
target: distributor.address,
|
|
159
|
+
allowFailure: false,
|
|
160
|
+
value: 0n,
|
|
161
|
+
callData: isLastBuyer
|
|
162
|
+
? delegateInterface.encodeFunctionData('transferTo', [buyerWallets[i].address])
|
|
163
|
+
: delegateInterface.encodeFunctionData('transferAmount', [buyerWallets[i].address, amountToTransfer]),
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
// 4. 所有买家买入
|
|
167
|
+
for (let i = 0; i < buyerWallets.length; i++) {
|
|
168
|
+
const buyCall = buildBuyCallInternal(buyerWallets[i], buyAmountsPerBuyer[i], tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
|
|
169
|
+
calls.push(buyCall);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
// ========================================
|
|
174
|
+
// ✅ 普通模式(一卖多买)
|
|
175
|
+
// 1. 卖家卖出代币 → OKB 留在卖家账户
|
|
176
|
+
// 2. 利润从第一个买家 OKB 中扣除
|
|
177
|
+
// 3. 各买家用自己预存的 OKB 买入
|
|
178
|
+
// ========================================
|
|
179
|
+
// 1. 卖家卖出(OKB 留在卖家账户)
|
|
180
|
+
const sellCall = buildSellCallWithAmountInternal(sellerWallet, sellAmountWei, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
|
|
181
|
+
calls.push(sellCall);
|
|
182
|
+
// 2. 利润刮取(从第一个买家余额扣除)
|
|
183
|
+
if (profitAmount > 0n) {
|
|
184
|
+
calls.push({
|
|
185
|
+
target: buyerWallets[0].address,
|
|
186
|
+
allowFailure: false,
|
|
187
|
+
value: 0n,
|
|
188
|
+
callData: delegateInterface.encodeFunctionData('transferAmount', [profitRecipient, profitAmount]),
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
// 3. 所有买家买入(使用自己预存的 OKB)
|
|
192
|
+
for (let i = 0; i < buyerWallets.length; i++) {
|
|
193
|
+
const buyCall = buildBuyCallInternal(buyerWallets[i], buyAmountsPerBuyer[i], tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
|
|
194
|
+
calls.push(buyCall);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// ========================================
|
|
198
|
+
// 构建交易
|
|
199
|
+
// ========================================
|
|
200
|
+
const signedTransaction = buildEIP7702TransactionSync(sellerWallet, authorizations, calls, 0n, sellerNonce, feeData, config);
|
|
201
|
+
return {
|
|
202
|
+
signedTransaction,
|
|
203
|
+
hopWallets: hopWalletInfos,
|
|
204
|
+
metadata: {
|
|
205
|
+
sellerAddress: sellerWallet.address,
|
|
206
|
+
buyerAddresses: buyerWallets.map((w) => w.address),
|
|
207
|
+
sellAmount: ethers.formatUnits(sellAmountWei, tokenDecimals),
|
|
208
|
+
estimatedOkbOut: ethers.formatEther(estimatedOkbOut),
|
|
209
|
+
estimatedBuyAmount: ethers.formatEther(totalBuyAmountAfterProfit),
|
|
210
|
+
profitAmount: ethers.formatEther(profitAmount),
|
|
211
|
+
profitRecipient,
|
|
212
|
+
userType,
|
|
213
|
+
useFundUtilization,
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bundle-swap 内部工具函数
|
|
3
|
+
*
|
|
4
|
+
* 供 bundle-swap-single / bundle-swap-batch / bundle-swap-multi 共享使用,
|
|
5
|
+
* 不作为公共 API 导出。
|
|
6
|
+
*/
|
|
7
|
+
import { ethers, Wallet } from 'ethers';
|
|
8
|
+
import type { Call3Value, TradeType } from './types.js';
|
|
9
|
+
export declare function getDefaultRouter(tradeType: TradeType): string;
|
|
10
|
+
/**
|
|
11
|
+
* 截断小数位数,避免 parseEther/parseUnits 报错
|
|
12
|
+
* @param value 数值字符串
|
|
13
|
+
* @param decimals 保留的小数位数(默认 18)
|
|
14
|
+
*/
|
|
15
|
+
export declare function truncateDecimals(value: string, decimals?: number): string;
|
|
16
|
+
/**
|
|
17
|
+
* 获取卖出报价:预估卖出代币能得到多少 OKB
|
|
18
|
+
*/
|
|
19
|
+
export declare function quoteSellOutput(sellAmount: bigint, tokenAddress: string, tradeType: TradeType, fee: number, rpcUrl?: string): Promise<bigint>;
|
|
20
|
+
export declare function buildBuyCallInternal(wallet: Wallet, amount: bigint, tokenAddress: string, tradeType: TradeType, routerAddress: string, fee: number, delegateInterface: ethers.Interface, portalInterface: ethers.Interface): Call3Value;
|
|
21
|
+
export declare function buildSellCallWithAmountInternal(wallet: Wallet, amount: bigint, tokenAddress: string, tradeType: TradeType, routerAddress: string, fee: number, delegateInterface: ethers.Interface, portalInterface: ethers.Interface): Call3Value;
|