four-flap-meme-sdk 1.9.49 → 2.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/README.en.md +41 -6
- package/README.md +31 -0
- package/README.zh-CN.md +41 -6
- package/dist/abis/common.js +74 -68
- package/dist/abis/flap/vault.js +9 -7
- package/dist/abis/index.d.ts +3 -4
- package/dist/abis/index.js +3 -4
- package/dist/bundle-core/__tests__/config-helpers.test.js +28 -0
- package/dist/bundle-core/__tests__/facade-parity.test.js +33 -0
- package/dist/bundle-core/__tests__/sign-context-helpers.test.d.ts +1 -0
- package/dist/bundle-core/__tests__/sign-context-helpers.test.js +60 -0
- package/dist/bundle-core/__tests__/sign-fixture.test.d.ts +1 -0
- package/dist/bundle-core/__tests__/sign-fixture.test.js +220 -0
- package/dist/bundle-core/__tests__/sign-fixtures.d.ts +10 -0
- package/dist/bundle-core/__tests__/sign-fixtures.js +16 -0
- package/dist/bundle-core/config-helpers.d.ts +36 -0
- package/dist/bundle-core/config-helpers.js +57 -0
- package/dist/bundle-core/errors.d.ts +50 -0
- package/dist/bundle-core/errors.js +34 -0
- package/dist/bundle-core/four-meme/approve-tokenmanager.d.ts +7 -0
- package/dist/bundle-core/four-meme/approve-tokenmanager.js +99 -0
- package/dist/bundle-core/four-meme/core-helpers.d.ts +8 -0
- package/dist/bundle-core/four-meme/core-helpers.js +40 -0
- package/dist/bundle-core/four-meme/core.d.ts +4 -0
- package/dist/bundle-core/four-meme/core.js +515 -0
- package/dist/bundle-core/four-meme/pancake-proxy.d.ts +28 -0
- package/dist/bundle-core/four-meme/pancake-proxy.js +679 -0
- package/dist/bundle-core/four-meme/private.d.ts +27 -0
- package/dist/bundle-core/four-meme/private.js +465 -0
- package/dist/bundle-core/four-meme/sign-context-helpers.d.ts +2 -0
- package/dist/bundle-core/four-meme/sign-context-helpers.js +2 -0
- package/dist/bundle-core/four-meme/swap-buy-first.d.ts +8 -0
- package/dist/bundle-core/four-meme/swap-buy-first.js +493 -0
- package/dist/bundle-core/four-meme/swap-hop-helpers.d.ts +6 -0
- package/dist/bundle-core/four-meme/swap-hop-helpers.js +63 -0
- package/dist/bundle-core/four-meme/swap-internal.d.ts +3 -0
- package/dist/bundle-core/four-meme/swap-internal.js +18 -0
- package/dist/bundle-core/four-meme/swap-sign-helpers.d.ts +27 -0
- package/dist/bundle-core/four-meme/swap-sign-helpers.js +105 -0
- package/dist/bundle-core/four-meme/swap.d.ts +17 -0
- package/dist/bundle-core/four-meme/swap.js +505 -0
- package/dist/bundle-core/four-meme/types/buy-first.d.ts +50 -0
- package/dist/bundle-core/four-meme/types/buy-first.js +1 -0
- package/dist/bundle-core/four-meme/types/core-flow.d.ts +63 -0
- package/dist/bundle-core/four-meme/types/core-flow.js +1 -0
- package/dist/bundle-core/four-meme/types/index.d.ts +600 -0
- package/dist/bundle-core/four-meme/types/index.js +1 -0
- package/dist/bundle-core/four-meme/types/swap-internal.d.ts +19 -0
- package/dist/bundle-core/four-meme/types/swap-internal.js +1 -0
- package/dist/bundle-core/four-meme/types.d.ts +1 -0
- package/dist/bundle-core/four-meme/types.js +1 -0
- package/dist/bundle-core/four-meme/utils-disperse.d.ts +7 -0
- package/dist/bundle-core/four-meme/utils-disperse.js +396 -0
- package/dist/bundle-core/four-meme/utils-pairwise.d.ts +8 -0
- package/dist/bundle-core/four-meme/utils-pairwise.js +328 -0
- package/dist/bundle-core/four-meme/utils-sweep.d.ts +8 -0
- package/dist/bundle-core/four-meme/utils-sweep.js +744 -0
- package/dist/bundle-core/index.d.ts +8 -0
- package/dist/bundle-core/index.js +8 -0
- package/dist/bundle-core/internal.d.ts +21 -0
- package/dist/bundle-core/internal.js +182 -0
- package/dist/bundle-core/sign-context-helpers.d.ts +25 -0
- package/dist/bundle-core/sign-context-helpers.js +67 -0
- package/dist/bundle-core/submit.d.ts +293 -0
- package/dist/bundle-core/submit.js +727 -0
- package/dist/bundle-core/types/index.d.ts +8 -0
- package/dist/bundle-core/types/index.js +1 -0
- package/dist/bundle-core/types.d.ts +1 -0
- package/dist/bundle-core/types.js +1 -0
- package/dist/chains/bsc/four/approve-tokenmanager.d.ts +1 -26
- package/dist/chains/bsc/four/approve-tokenmanager.js +1 -116
- package/dist/chains/bsc/four/config.d.ts +5 -70
- package/dist/chains/bsc/four/config.js +2 -115
- package/dist/chains/bsc/four/core.d.ts +1 -4
- package/dist/chains/bsc/four/core.js +1 -589
- package/dist/chains/bsc/four/disperse.d.ts +12 -0
- package/dist/chains/bsc/four/disperse.js +470 -0
- package/dist/chains/bsc/four/index.d.ts +6 -6
- package/dist/chains/bsc/four/index.js +6 -6
- package/dist/chains/bsc/four/internal.d.ts +2 -50
- package/dist/chains/bsc/four/internal.js +2 -237
- package/dist/chains/bsc/four/pairwise.d.ts +7 -0
- package/dist/chains/bsc/four/pairwise.js +308 -0
- package/dist/chains/bsc/four/pancake-proxy.d.ts +1 -28
- package/dist/chains/bsc/four/pancake-proxy.js +1 -688
- package/dist/chains/bsc/four/private.d.ts +1 -27
- package/dist/chains/bsc/four/private.js +1 -477
- package/dist/chains/bsc/four/submit.d.ts +2 -315
- package/dist/chains/bsc/four/submit.js +2 -746
- package/dist/chains/bsc/four/swap-buy-first.d.ts +2 -55
- package/dist/chains/bsc/four/swap-buy-first.js +2 -506
- package/dist/chains/bsc/four/swap-internal.d.ts +1 -3
- package/dist/chains/bsc/four/swap-internal.js +1 -18
- package/dist/chains/bsc/four/swap.d.ts +2 -144
- package/dist/chains/bsc/four/swap.js +2 -760
- package/dist/chains/bsc/four/sweep.d.ts +13 -0
- package/dist/chains/bsc/four/sweep.js +788 -0
- package/dist/chains/bsc/four/types.d.ts +1 -476
- package/dist/chains/bsc/four/utils-disperse.d.ts +1 -0
- package/dist/chains/bsc/four/utils-disperse.js +1 -0
- package/dist/chains/bsc/four/utils-pairwise.d.ts +1 -0
- package/dist/chains/bsc/four/utils-pairwise.js +1 -0
- package/dist/chains/bsc/four/utils-sweep.d.ts +1 -0
- package/dist/chains/bsc/four/utils-sweep.js +1 -0
- package/dist/chains/bsc/four/utils.d.ts +5 -18
- package/dist/chains/bsc/four/utils.js +5 -1534
- package/dist/chains/bsc/pancake/bundle-buy-first-helpers.d.ts +159 -0
- package/dist/chains/bsc/pancake/bundle-buy-first-helpers.js +117 -0
- package/dist/chains/bsc/pancake/bundle-buy-first.d.ts +1 -91
- package/dist/chains/bsc/pancake/bundle-buy-first.js +97 -207
- package/dist/chains/bsc/pancake/bundle-swap-helpers.d.ts +241 -0
- package/dist/chains/bsc/pancake/bundle-swap-helpers.js +565 -0
- package/dist/chains/bsc/pancake/bundle-swap.d.ts +1 -79
- package/dist/chains/bsc/pancake/bundle-swap.js +111 -686
- package/dist/chains/bsc/pancake/index.d.ts +4 -2
- package/dist/chains/bsc/pancake/index.js +1 -3
- package/dist/chains/bsc/platforms/iro/factory.js +3 -1
- package/dist/chains/bsc/platforms/iro/index.d.ts +5 -5
- package/dist/chains/bsc/platforms/iro/index.js +3 -3
- package/dist/chains/bsc/platforms/iro/pool.js +31 -10
- package/dist/chains/bsc/platforms/iro/token.js +4 -1
- package/dist/chains/eni/batch-router/bundle-approve.js +4 -3
- package/dist/chains/eni/batch-router/transfer.js +54 -23
- package/dist/chains/eni/batch-router/utils.js +32 -6
- package/dist/chains/eni/bundler/sign.js +4 -4
- package/dist/chains/eni/bundler/submit.js +1 -4
- package/dist/chains/eni/constants.js +1 -1
- package/dist/chains/eni/index.d.ts +1 -1
- package/dist/chains/eni/platforms/daoaas/create.js +2 -2
- package/dist/chains/eni/platforms/daoaas/index.d.ts +3 -3
- package/dist/chains/eni/platforms/daoaas/index.js +3 -3
- package/dist/chains/eni/platforms/daoaas/meta.js +8 -4
- package/dist/chains/eni/platforms/daoaas/portal-direct.js +28 -43
- package/dist/chains/eni/platforms/daoaas/portal.js +10 -6
- package/dist/chains/eni/platforms/dswap/liquidity.js +58 -26
- package/dist/chains/eni/platforms/fair-launch/index.d.ts +2 -2
- package/dist/chains/eni/platforms/fair-launch/index.js +1 -1
- package/dist/chains/eni/platforms/fair-launch/launcher.js +87 -47
- package/dist/chains/eni/platforms/fair-launch/pool.js +4 -1
- package/dist/chains/eni/platforms/fair-launch/presets.js +2 -2
- package/dist/chains/eni/platforms/iro/factory.js +3 -1
- package/dist/chains/eni/platforms/iro/index.d.ts +6 -6
- package/dist/chains/eni/platforms/iro/index.js +4 -4
- package/dist/chains/eni/platforms/iro/pool.js +90 -26
- package/dist/chains/eni/platforms/iro/token.js +107 -31
- package/dist/chains/eni/platforms/iro/whitelist.js +6 -18
- package/dist/chains/eni/submit.js +5 -13
- package/dist/chains/xlayer/eip7702/bundle-approve.d.ts +2 -26
- package/dist/chains/xlayer/eip7702/bundle-approve.js +11 -20
- package/dist/chains/xlayer/eip7702/bundle-buy.d.ts +2 -6
- package/dist/chains/xlayer/eip7702/bundle-buy.js +13 -51
- package/dist/chains/xlayer/eip7702/bundle-create.js +93 -56
- package/dist/chains/xlayer/eip7702/bundle-sell.d.ts +2 -6
- package/dist/chains/xlayer/eip7702/bundle-sell.js +26 -74
- package/dist/chains/xlayer/eip7702/bundle-swap.d.ts +3 -65
- package/dist/chains/xlayer/eip7702/bundle-swap.js +51 -68
- package/dist/chains/xlayer/eip7702/constants.d.ts +1 -16
- package/dist/chains/xlayer/eip7702/constants.js +3 -21
- package/dist/chains/xlayer/eip7702/index.d.ts +27 -46
- package/dist/chains/xlayer/eip7702/index.js +27 -81
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-helpers.d.ts +79 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer-helpers.js +1 -0
- package/dist/chains/xlayer/eip7702/multi-hop-transfer.d.ts +2 -203
- package/dist/chains/xlayer/eip7702/multi-hop-transfer.js +58 -291
- package/dist/chains/xlayer/eip7702/transfer-context-helpers.d.ts +26 -0
- package/dist/chains/xlayer/eip7702/transfer-context-helpers.js +57 -0
- package/dist/chains/xlayer/eip7702/types.d.ts +88 -0
- package/dist/chains/xlayer/eip7702/utils.d.ts +0 -3
- package/dist/chains/xlayer/eip7702/utils.js +23 -28
- package/dist/chains/xlayer/eip7702/volume-helpers.d.ts +148 -0
- package/dist/chains/xlayer/eip7702/volume-helpers.js +48 -0
- package/dist/chains/xlayer/eip7702/volume.d.ts +6 -184
- package/dist/chains/xlayer/eip7702/volume.js +83 -158
- package/dist/chains/xlayer/eoa/constants.js +1 -1
- package/dist/chains/xlayer/eoa/dex-helpers.js +5 -5
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.d.ts +126 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.js +228 -0
- package/dist/chains/xlayer/eoa/eoa-bundle-swap.d.ts +1 -95
- package/dist/chains/xlayer/eoa/eoa-bundle-swap.js +64 -276
- package/dist/chains/xlayer/eoa/eoa-wash-volume.d.ts +1 -1
- package/dist/chains/xlayer/eoa/eoa-wash-volume.js +14 -14
- package/dist/chains/xlayer/eoa/index.d.ts +10 -6
- package/dist/chains/xlayer/eoa/index.js +8 -23
- package/dist/chains/xlayer/eoa/portal-ops.js +7 -2
- package/dist/chains/xlayer/eoa/router-manager.js +3 -3
- package/dist/chains/xlayer/eoa/types-core.d.ts +363 -0
- package/dist/chains/xlayer/eoa/types-core.js +53 -0
- package/dist/chains/xlayer/eoa/types-create.d.ts +413 -0
- package/dist/chains/xlayer/eoa/types-create.js +9 -0
- package/dist/chains/xlayer/eoa/types-volume.d.ts +209 -0
- package/dist/chains/xlayer/eoa/types-volume.js +13 -0
- package/dist/chains/xlayer/eoa/types.d.ts +2 -2
- package/dist/chains/xlayer/eoa/types.js +1 -3
- package/dist/contracts/helper3.d.ts +20 -17
- package/dist/contracts/helper3.js +56 -20
- package/dist/contracts/tm-bundle-helpers.d.ts +88 -0
- package/dist/contracts/tm-bundle-helpers.js +72 -0
- package/dist/contracts/tm-bundle-merkle/approve-tokenmanager.d.ts +1 -26
- package/dist/contracts/tm-bundle-merkle/approve-tokenmanager.js +1 -117
- package/dist/contracts/tm-bundle-merkle/config.d.ts +5 -70
- package/dist/contracts/tm-bundle-merkle/config.js +2 -115
- package/dist/contracts/tm-bundle-merkle/core.d.ts +1 -4
- package/dist/contracts/tm-bundle-merkle/core.js +1 -588
- package/dist/contracts/tm-bundle-merkle/index.d.ts +5 -5
- package/dist/contracts/tm-bundle-merkle/index.js +5 -5
- package/dist/contracts/tm-bundle-merkle/internal.d.ts +2 -50
- package/dist/contracts/tm-bundle-merkle/internal.js +2 -236
- package/dist/contracts/tm-bundle-merkle/pancake-proxy.d.ts +1 -28
- package/dist/contracts/tm-bundle-merkle/pancake-proxy.js +1 -687
- package/dist/contracts/tm-bundle-merkle/private.d.ts +1 -27
- package/dist/contracts/tm-bundle-merkle/private.js +1 -476
- package/dist/contracts/tm-bundle-merkle/submit.d.ts +3 -314
- package/dist/contracts/tm-bundle-merkle/submit.js +3 -919
- package/dist/contracts/tm-bundle-merkle/swap-buy-first.d.ts +2 -55
- package/dist/contracts/tm-bundle-merkle/swap-buy-first.js +2 -505
- package/dist/contracts/tm-bundle-merkle/swap-internal.d.ts +1 -3
- package/dist/contracts/tm-bundle-merkle/swap-internal.js +1 -18
- package/dist/contracts/tm-bundle-merkle/swap.d.ts +2 -144
- package/dist/contracts/tm-bundle-merkle/swap.js +2 -757
- package/dist/contracts/tm-bundle-merkle/types.d.ts +1 -476
- package/dist/contracts/tm-bundle-merkle/utils-disperse.d.ts +1 -0
- package/dist/contracts/tm-bundle-merkle/utils-disperse.js +1 -0
- package/dist/contracts/tm-bundle-merkle/utils-pairwise.d.ts +1 -0
- package/dist/contracts/tm-bundle-merkle/utils-pairwise.js +1 -0
- package/dist/contracts/tm-bundle-merkle/utils-sweep.d.ts +1 -0
- package/dist/contracts/tm-bundle-merkle/utils-sweep.js +1 -0
- package/dist/contracts/tm-bundle-merkle/utils.d.ts +5 -6
- package/dist/contracts/tm-bundle-merkle/utils.js +5 -6
- package/dist/contracts/tm-bundle.d.ts +3 -51
- package/dist/contracts/tm-bundle.js +102 -142
- package/dist/contracts/tm.d.ts +3 -2
- package/dist/contracts/tm.js +36 -32
- package/dist/contracts/tm1.js +9 -4
- package/dist/contracts/tm2.js +9 -4
- package/dist/dex/direct-router-helpers.d.ts +264 -0
- package/dist/dex/direct-router-helpers.js +539 -0
- package/dist/dex/direct-router.d.ts +3 -125
- package/dist/dex/direct-router.js +237 -652
- package/dist/dex/types.d.ts +81 -0
- package/dist/dex/types.js +1 -0
- package/dist/exports/root-bundle-and-tooling.d.ts +27 -0
- package/dist/exports/root-bundle-and-tooling.js +30 -0
- package/dist/exports/root-eni-and-bsc-iro.d.ts +26 -0
- package/dist/exports/root-eni-and-bsc-iro.js +66 -0
- package/dist/exports/root-foundations.d.ts +35 -0
- package/dist/exports/root-foundations.js +70 -0
- package/dist/exports/root-swap-dex-and-xlayer.d.ts +30 -0
- package/dist/exports/root-swap-dex-and-xlayer.js +78 -0
- package/dist/flows/create.d.ts +2 -2
- package/dist/flows/create.js +6 -6
- package/dist/flows/index.d.ts +1 -0
- package/dist/flows/index.js +1 -0
- package/dist/index.d.ts +20 -91
- package/dist/index.js +20 -215
- package/dist/shared/abis/common.d.ts +2 -83
- package/dist/shared/abis/common.js +2 -252
- package/dist/shared/abis/index.d.ts +5 -6
- package/dist/shared/abis/index.js +5 -7
- package/dist/shared/clients/blockrazor.js +41 -24
- package/dist/shared/clients/club48.js +30 -26
- package/dist/shared/clients/emitservice.js +2 -0
- package/dist/shared/clients/four.js +23 -18
- package/dist/shared/clients/index.d.ts +8 -0
- package/dist/shared/clients/index.js +8 -0
- package/dist/shared/clients/merkle.js +26 -30
- package/dist/shared/constants/addresses.d.ts +1 -1
- package/dist/shared/constants/addresses.js +11 -2
- package/dist/shared/constants/chains.d.ts +1 -1
- package/dist/shared/constants/chains.js +1 -1
- package/dist/shared/constants/gas.d.ts +1 -1
- package/dist/shared/constants/gas.js +2 -6
- package/dist/shared/constants/index.d.ts +1 -0
- package/dist/shared/constants/index.js +1 -0
- package/dist/shared/constants/quote.d.ts +30 -0
- package/dist/shared/constants/quote.js +37 -0
- package/dist/shared/flap/__tests__/curve.test.js +3 -3
- package/dist/shared/flap/abi.js +1 -1
- package/dist/shared/flap/constants.d.ts +1 -1
- package/dist/shared/flap/constants.js +2 -2
- package/dist/shared/flap/curve.js +3 -0
- package/dist/shared/flap/errors.d.ts +1 -4
- package/dist/shared/flap/errors.js +21 -3
- package/dist/shared/flap/index.d.ts +2 -2
- package/dist/shared/flap/index.js +2 -2
- package/dist/shared/flap/meta.d.ts +16 -18
- package/dist/shared/flap/meta.js +14 -26
- package/dist/shared/flap/permit.js +6 -5
- package/dist/shared/flap/pinata.d.ts +9 -2
- package/dist/shared/flap/pinata.js +20 -18
- package/dist/shared/flap/portal-bundle-merkle/config.d.ts +3 -72
- package/dist/shared/flap/portal-bundle-merkle/config.js +4 -124
- package/dist/shared/flap/portal-bundle-merkle/core-helpers.d.ts +32 -0
- package/dist/shared/flap/portal-bundle-merkle/core-helpers.js +83 -0
- package/dist/shared/flap/portal-bundle-merkle/core.d.ts +0 -4
- package/dist/shared/flap/portal-bundle-merkle/core.js +66 -156
- package/dist/shared/flap/portal-bundle-merkle/create-to-dex.js +81 -86
- package/dist/shared/flap/portal-bundle-merkle/curve-to-dex.js +100 -92
- package/dist/shared/flap/portal-bundle-merkle/index.d.ts +11 -7
- package/dist/shared/flap/portal-bundle-merkle/index.js +4 -7
- package/dist/shared/flap/portal-bundle-merkle/pancake-proxy.js +71 -68
- package/dist/shared/flap/portal-bundle-merkle/private.js +61 -114
- package/dist/shared/flap/portal-bundle-merkle/swap-buy-first-helpers.d.ts +125 -0
- package/dist/shared/flap/portal-bundle-merkle/swap-buy-first-helpers.js +113 -0
- package/dist/shared/flap/portal-bundle-merkle/swap-buy-first.d.ts +1 -64
- package/dist/shared/flap/portal-bundle-merkle/swap-buy-first.js +66 -247
- package/dist/shared/flap/portal-bundle-merkle/swap-helpers.d.ts +149 -0
- package/dist/shared/flap/portal-bundle-merkle/swap-helpers.js +259 -0
- package/dist/shared/flap/portal-bundle-merkle/swap.d.ts +2 -71
- package/dist/shared/flap/portal-bundle-merkle/swap.js +103 -410
- package/dist/shared/flap/portal-bundle-merkle/types.d.ts +73 -3
- package/dist/shared/flap/portal-bundle-merkle/utils-helpers.d.ts +100 -0
- package/dist/shared/flap/portal-bundle-merkle/utils-helpers.js +133 -0
- package/dist/shared/flap/portal-bundle-merkle/utils.d.ts +1 -80
- package/dist/shared/flap/portal-bundle-merkle/utils.js +145 -265
- package/dist/shared/flap/portal-bundle.js +54 -42
- package/dist/shared/flap/portal.js +32 -10
- package/dist/shared/flap/vanity.js +4 -7
- package/dist/shared/flap/vault.d.ts +1 -1
- package/dist/shared/flap/vault.js +54 -48
- package/dist/shared/flap 2/__tests__/curve.test.d.ts +1 -0
- package/dist/shared/flap 2/portal-bundle-merkle/types.js +1 -0
- package/dist/shared/foundation/dex/v3-path.d.ts +6 -0
- package/dist/shared/foundation/dex/v3-path.js +35 -0
- package/dist/shared/foundation/gas/bundle-gas.d.ts +39 -0
- package/dist/shared/foundation/gas/bundle-gas.js +93 -0
- package/dist/shared/foundation/gas/profit-hop.d.ts +20 -0
- package/dist/shared/foundation/gas/profit-hop.js +72 -0
- package/dist/shared/foundation/index.d.ts +13 -0
- package/dist/shared/foundation/index.js +12 -0
- package/dist/shared/foundation/nonce/nonce-manager.d.ts +17 -0
- package/dist/shared/foundation/nonce/nonce-manager.js +180 -0
- package/dist/shared/foundation/normalize-unknown.d.ts +9 -0
- package/dist/shared/foundation/normalize-unknown.js +29 -0
- package/dist/shared/foundation/sdk-logger.d.ts +13 -0
- package/dist/shared/foundation/sdk-logger.js +12 -0
- package/dist/shared/foundation/tx/build-request.d.ts +17 -0
- package/dist/shared/foundation/tx/build-request.js +25 -0
- package/dist/shared/foundation/tx/sign-batch.d.ts +5 -0
- package/dist/shared/foundation/tx/sign-batch.js +26 -0
- package/dist/shared/foundation/tx/wallet-sign-patch.d.ts +1 -0
- package/dist/shared/foundation/tx/wallet-sign-patch.js +18 -0
- package/dist/shared/foundation/types/airdrop-sweep.d.ts +79 -0
- package/dist/shared/foundation/types/airdrop-sweep.js +1 -0
- package/dist/shared/foundation/types/erc20.d.ts +65 -0
- package/dist/shared/foundation/types/erc20.js +1 -0
- package/dist/shared/foundation/types/holders-maker.d.ts +64 -0
- package/dist/shared/foundation/types/holders-maker.js +1 -0
- package/dist/shared/foundation/types/index.d.ts +7 -0
- package/dist/shared/foundation/types/index.js +1 -0
- package/dist/shared/foundation/types/lp-inspect.d.ts +102 -0
- package/dist/shared/foundation/types/lp-inspect.js +1 -0
- package/dist/shared/foundation/types/multicall.d.ts +5 -0
- package/dist/shared/foundation/types/multicall.js +1 -0
- package/dist/shared/foundation/types/private-sale.d.ts +35 -0
- package/dist/shared/foundation/types/private-sale.js +1 -0
- package/dist/shared/foundation/types/quote-helpers.d.ts +17 -0
- package/dist/shared/foundation/types/quote-helpers.js +1 -0
- package/dist/shared/four/tax-token.d.ts +1 -1
- package/dist/shared/four/tax-token.js +27 -7
- package/dist/shared/index.d.ts +4 -0
- package/dist/shared/index.js +4 -0
- package/dist/types/distribute.d.ts +72 -0
- package/dist/types/distribute.js +1 -0
- package/dist/types 2/errors.d.ts +27 -0
- package/dist/types 2/errors.js +34 -0
- package/dist/utils/airdrop-sweep-types.d.ts +1 -0
- package/dist/utils/airdrop-sweep-types.js +1 -0
- package/dist/utils/airdrop-sweep.d.ts +4 -76
- package/dist/utils/airdrop-sweep.js +38 -52
- package/dist/utils/bundle-helpers.d.ts +9 -243
- package/dist/utils/bundle-helpers.js +10 -584
- package/dist/utils/constants.d.ts +5 -61
- package/dist/utils/constants.js +5 -80
- package/dist/utils/contract-factory.d.ts +2 -4
- package/dist/utils/contract-factory.js +25 -18
- package/dist/utils/erc20-types.d.ts +1 -0
- package/dist/utils/erc20-types.js +1 -0
- package/dist/utils/erc20.d.ts +8 -90
- package/dist/utils/erc20.js +94 -153
- package/dist/utils/errors.d.ts +10 -22
- package/dist/utils/errors.js +61 -79
- package/dist/utils/holders-maker/addresses.d.ts +12 -0
- package/dist/utils/holders-maker/addresses.js +15 -0
- package/dist/utils/holders-maker/buy-tx.d.ts +44 -0
- package/dist/utils/holders-maker/buy-tx.js +278 -0
- package/dist/utils/holders-maker/constants.d.ts +6 -0
- package/dist/utils/holders-maker/constants.js +7 -0
- package/dist/utils/holders-maker/disperse.d.ts +18 -0
- package/dist/utils/holders-maker/disperse.js +90 -0
- package/dist/utils/holders-maker/routing.d.ts +4 -0
- package/dist/utils/holders-maker/routing.js +45 -0
- package/dist/utils/holders-maker/transfer-tx.d.ts +4 -0
- package/dist/utils/holders-maker/transfer-tx.js +67 -0
- package/dist/utils/holders-maker-helpers.d.ts +9 -0
- package/dist/utils/holders-maker-helpers.js +9 -0
- package/dist/utils/holders-maker-types.d.ts +1 -0
- package/dist/utils/holders-maker-types.js +1 -0
- package/dist/utils/holders-maker.d.ts +2 -138
- package/dist/utils/holders-maker.js +23 -651
- package/dist/utils/hop-chains.d.ts +35 -0
- package/dist/utils/hop-chains.js +215 -0
- package/dist/utils/lp-inspect-helpers.d.ts +9 -0
- package/dist/utils/lp-inspect-helpers.js +109 -0
- package/dist/utils/lp-inspect-types.d.ts +1 -0
- package/dist/utils/lp-inspect-types.js +1 -0
- package/dist/utils/lp-inspect.d.ts +2 -112
- package/dist/utils/lp-inspect.js +63 -195
- package/dist/utils/mpcExclusive.d.ts +2 -5
- package/dist/utils/mpcExclusive.js +4 -3
- package/dist/utils/private-sale-types.d.ts +1 -0
- package/dist/utils/private-sale-types.js +1 -0
- package/dist/utils/private-sale.d.ts +2 -58
- package/dist/utils/private-sale.js +2 -7
- package/dist/utils/provider-factory.d.ts +4 -0
- package/dist/utils/provider-factory.js +10 -0
- package/dist/utils/quote-helpers-types.d.ts +1 -0
- package/dist/utils/quote-helpers-types.js +1 -0
- package/dist/utils/quote-helpers.d.ts +4 -45
- package/dist/utils/quote-helpers.js +15 -65
- package/dist/utils/stealth-transfer.d.ts +2 -28
- package/dist/utils/stealth-transfer.js +30 -14
- package/dist/utils/swap-helpers.d.ts +0 -3
- package/dist/utils/swap-helpers.js +6 -9
- package/dist/utils/types/airdrop-sweep.d.ts +1 -0
- package/dist/utils/types/airdrop-sweep.js +1 -0
- package/dist/utils/types/contract-factory.d.ts +1 -0
- package/dist/utils/types/contract-factory.js +1 -0
- package/dist/utils/types/erc20.d.ts +1 -0
- package/dist/utils/types/erc20.js +1 -0
- package/dist/utils/types/errors.d.ts +1 -0
- package/dist/utils/types/errors.js +1 -0
- package/dist/utils/types/holders-maker.d.ts +1 -0
- package/dist/utils/types/holders-maker.js +1 -0
- package/dist/utils/types/hop-chains.d.ts +8 -0
- package/dist/utils/types/hop-chains.js +1 -0
- package/dist/utils/types/index.d.ts +13 -0
- package/dist/utils/types/index.js +1 -0
- package/dist/utils/types/lp-inspect.d.ts +1 -0
- package/dist/utils/types/lp-inspect.js +1 -0
- package/dist/utils/types/mpc-exclusive.d.ts +5 -0
- package/dist/utils/types/mpc-exclusive.js +1 -0
- package/dist/utils/types/private-sale.d.ts +1 -0
- package/dist/utils/types/private-sale.js +1 -0
- package/dist/utils/types/quote-helpers.d.ts +1 -0
- package/dist/utils/types/quote-helpers.js +1 -0
- package/dist/utils/types/stealth-transfer.d.ts +44 -0
- package/dist/utils/types/stealth-transfer.js +1 -0
- package/dist/utils/types/wallet.d.ts +25 -0
- package/dist/utils/types/wallet.js +1 -0
- package/dist/utils/wallet.d.ts +2 -25
- package/dist/utils/wallet.js +9 -10
- package/package.json +55 -2
- package/src/abis/contracts/TaxToken.json +969 -0
- package/src/abis/contracts/TokenManager.json +836 -0
- package/src/abis/contracts/TokenManager2.json +136 -0
- package/src/abis/contracts/TokenManagerHelper3.json +993 -0
- /package/dist/{shared 2/flap/__tests__/curve.test.d.ts → bundle-core/__tests__/config-helpers.test.d.ts} +0 -0
- /package/dist/{shared 2/flap/portal-bundle-merkle/types.js → bundle-core/__tests__/facade-parity.test.d.ts} +0 -0
- /package/dist/{shared 2/abis → shared/abis 2}/TaxToken.json +0 -0
- /package/dist/{shared 2/abis → shared/abis 2}/TokenManager.json +0 -0
- /package/dist/{shared 2/abis → shared/abis 2}/TokenManager2.json +0 -0
- /package/dist/{shared 2/abis → shared/abis 2}/TokenManagerHelper3.json +0 -0
- /package/dist/{shared 2/abis → shared/abis 2}/common.d.ts +0 -0
- /package/dist/{shared 2/abis → shared/abis 2}/common.js +0 -0
- /package/dist/{shared 2/abis → shared/abis 2}/index.d.ts +0 -0
- /package/dist/{shared 2/abis → shared/abis 2}/index.js +0 -0
- /package/dist/{shared 2/clients → shared/clients 2}/blockrazor.d.ts +0 -0
- /package/dist/{shared 2/clients → shared/clients 2}/blockrazor.js +0 -0
- /package/dist/{shared 2/clients → shared/clients 2}/club48.d.ts +0 -0
- /package/dist/{shared 2/clients → shared/clients 2}/club48.js +0 -0
- /package/dist/{shared 2/clients → shared/clients 2}/emitservice.d.ts +0 -0
- /package/dist/{shared 2/clients → shared/clients 2}/emitservice.js +0 -0
- /package/dist/{shared 2/clients → shared/clients 2}/four.d.ts +0 -0
- /package/dist/{shared 2/clients → shared/clients 2}/four.js +0 -0
- /package/dist/{shared 2/clients → shared/clients 2}/merkle.d.ts +0 -0
- /package/dist/{shared 2/clients → shared/clients 2}/merkle.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/__tests__/curve.test.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/abi.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/abi.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/constants.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/constants.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/curve.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/curve.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/errors.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/errors.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/index.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/index.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/ipfs.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/ipfs.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/meta.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/meta.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/permit.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/permit.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/pinata.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/pinata.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal-bundle-merkle/config.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal-bundle-merkle/config.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal-bundle-merkle/core.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal-bundle-merkle/core.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal-bundle-merkle/create-to-dex.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal-bundle-merkle/create-to-dex.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal-bundle-merkle/curve-to-dex.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal-bundle-merkle/curve-to-dex.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal-bundle-merkle/index.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal-bundle-merkle/index.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal-bundle-merkle/pancake-proxy.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal-bundle-merkle/pancake-proxy.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal-bundle-merkle/private.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal-bundle-merkle/private.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal-bundle-merkle/swap-buy-first.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal-bundle-merkle/swap-buy-first.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal-bundle-merkle/swap.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal-bundle-merkle/swap.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal-bundle-merkle/types.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal-bundle-merkle/utils.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal-bundle-merkle/utils.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal-bundle.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal-bundle.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/portal.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/vanity.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/vanity.js +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/vault.d.ts +0 -0
- /package/dist/{shared 2/flap → shared/flap 2}/vault.js +0 -0
- /package/dist/{shared 2/four → shared/four 2}/index.d.ts +0 -0
- /package/dist/{shared 2/four → shared/four 2}/index.js +0 -0
- /package/dist/{shared 2/four → shared/four 2}/tax-token.d.ts +0 -0
- /package/dist/{shared 2/four → shared/four 2}/tax-token.js +0 -0
- /package/dist/{shared 2/index.d.ts → shared/index 2.js} +0 -0
- /package/dist/{shared 2/index.js → shared/index.d 2.ts} +0 -0
|
@@ -1,919 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* 用于服务器端接收前端构建的签名交易后,提交到Merkle或BlockRazor
|
|
5
|
-
* 以及 Monad 等不支持 Bundle 的链的逐笔广播
|
|
6
|
-
*/
|
|
7
|
-
import { MerkleClient } from '../../shared/clients/merkle.js';
|
|
8
|
-
import { BlockRazorClient } from '../../shared/clients/blockrazor.js';
|
|
9
|
-
import { ethers } from 'ethers';
|
|
10
|
-
// ✅ MerkleClient 缓存(复用连接,减少初始化开销)
|
|
11
|
-
const merkleClientCache = new Map();
|
|
12
|
-
const CLIENT_CACHE_TTL_MS = 60 * 1000; // 60秒缓存
|
|
13
|
-
/**
|
|
14
|
-
* 获取或创建 MerkleClient(带缓存)
|
|
15
|
-
*/
|
|
16
|
-
function getMerkleClient(config) {
|
|
17
|
-
const cacheKey = `${config.apiKey}-${config.chainId ?? 56}-${config.customRpcUrl || ''}`;
|
|
18
|
-
const now = Date.now();
|
|
19
|
-
const cached = merkleClientCache.get(cacheKey);
|
|
20
|
-
if (cached && cached.expireAt > now) {
|
|
21
|
-
return cached.client;
|
|
22
|
-
}
|
|
23
|
-
// 创建新客户端并缓存
|
|
24
|
-
const client = new MerkleClient({
|
|
25
|
-
apiKey: config.apiKey,
|
|
26
|
-
chainId: config.chainId ?? 56,
|
|
27
|
-
customRpcUrl: config.customRpcUrl
|
|
28
|
-
});
|
|
29
|
-
merkleClientCache.set(cacheKey, { client, expireAt: now + CLIENT_CACHE_TTL_MS });
|
|
30
|
-
return client;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* 提交已签名的交易到Merkle(服务器端使用)
|
|
34
|
-
*
|
|
35
|
-
* 这个方法接收前端构建和签名好的交易,直接提交到Merkle服务
|
|
36
|
-
*
|
|
37
|
-
* @param signedTransactions 签名后的交易数组
|
|
38
|
-
* @param config Merkle提交配置(精简版,只需要提交相关参数)
|
|
39
|
-
* @returns Bundle提交结果
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```typescript
|
|
43
|
-
* // 服务器端代码
|
|
44
|
-
* import { submitBundleToMerkle } from 'four-flap-meme-sdk';
|
|
45
|
-
*
|
|
46
|
-
* const result = await submitBundleToMerkle(signedTransactions, {
|
|
47
|
-
* apiKey: process.env.MERKLE_API_KEY,
|
|
48
|
-
* customRpcUrl: process.env.MERKLE_RPC_URL,
|
|
49
|
-
* bundleBlockOffset: 5
|
|
50
|
-
* });
|
|
51
|
-
*
|
|
52
|
-
* if (result.code) {
|
|
53
|
-
* } else {
|
|
54
|
-
* console.error('❌ Bundle提交失败:', result.error);
|
|
55
|
-
* }
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
export async function submitBundleToMerkle(signedTransactions, config) {
|
|
59
|
-
try {
|
|
60
|
-
const totalTransactions = signedTransactions?.length ?? 0;
|
|
61
|
-
// 验证输入
|
|
62
|
-
if (!signedTransactions || signedTransactions.length === 0) {
|
|
63
|
-
return {
|
|
64
|
-
code: false,
|
|
65
|
-
totalTransactions,
|
|
66
|
-
error: 'signedTransactions cannot be empty'
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
if (!config.apiKey) {
|
|
70
|
-
return {
|
|
71
|
-
code: false,
|
|
72
|
-
totalTransactions,
|
|
73
|
-
error: 'apiKey is required in config'
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
// ✅ 使用缓存的 MerkleClient(复用连接 + 区块号缓存)
|
|
77
|
-
const merkle = getMerkleClient(config);
|
|
78
|
-
// 提交Bundle
|
|
79
|
-
const bundleResult = await merkle.sendBundle({
|
|
80
|
-
transactions: signedTransactions,
|
|
81
|
-
blockOffset: config.bundleBlockOffset ?? 3,
|
|
82
|
-
minBlockOffset: config.minBlockOffset ?? 3,
|
|
83
|
-
autoRetry: config.autoRetryBundle ?? false,
|
|
84
|
-
maxRetries: config.maxBundleRetries ?? 2
|
|
85
|
-
});
|
|
86
|
-
// ✅ 提交成功
|
|
87
|
-
return {
|
|
88
|
-
code: true,
|
|
89
|
-
totalTransactions,
|
|
90
|
-
bundleHash: bundleResult.bundleHash,
|
|
91
|
-
txHashes: bundleResult.txHashes,
|
|
92
|
-
targetBlock: bundleResult.targetBlock,
|
|
93
|
-
txCount: bundleResult.txCount
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
// ❌ 提交失败
|
|
98
|
-
return {
|
|
99
|
-
code: false,
|
|
100
|
-
totalTransactions: signedTransactions?.length ?? 0,
|
|
101
|
-
error: error instanceof Error ? error.message : String(error)
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* 批量提交多个Bundle到Merkle(顺序执行)
|
|
107
|
-
*
|
|
108
|
-
* @param bundles 多个Bundle的签名交易数组
|
|
109
|
-
* @param config Merkle提交配置
|
|
110
|
-
* @returns Bundle提交结果数组
|
|
111
|
-
*/
|
|
112
|
-
export async function submitMultipleBundles(bundles, config) {
|
|
113
|
-
const results = [];
|
|
114
|
-
for (const signedTransactions of bundles) {
|
|
115
|
-
const result = await submitBundleToMerkle(signedTransactions, config);
|
|
116
|
-
results.push(result);
|
|
117
|
-
}
|
|
118
|
-
return results;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* 并行提交多个Bundle到Merkle(适用于独立的Bundle)
|
|
122
|
-
*
|
|
123
|
-
* @param bundles 多个Bundle的签名交易数组
|
|
124
|
-
* @param config Merkle提交配置
|
|
125
|
-
* @returns Bundle提交结果数组
|
|
126
|
-
*/
|
|
127
|
-
export async function submitMultipleBundlesParallel(bundles, config) {
|
|
128
|
-
const promises = bundles.map(signedTransactions => submitBundleToMerkle(signedTransactions, config));
|
|
129
|
-
return await Promise.all(promises);
|
|
130
|
-
}
|
|
131
|
-
// ==================== BlockRazor Bundle 提交方法 ====================
|
|
132
|
-
// ✅ BlockRazorClient 缓存(复用连接,减少初始化开销)
|
|
133
|
-
const blockRazorClientCache = new Map();
|
|
134
|
-
/**
|
|
135
|
-
* 获取或创建 BlockRazorClient(带缓存)
|
|
136
|
-
*/
|
|
137
|
-
function getBlockRazorClient(config) {
|
|
138
|
-
const cacheKey = `${config.apiKey || 'default'}-${config.customRpcUrl || ''}-${config.builderRpcUrl || ''}`;
|
|
139
|
-
const now = Date.now();
|
|
140
|
-
const cached = blockRazorClientCache.get(cacheKey);
|
|
141
|
-
if (cached && cached.expireAt > now) {
|
|
142
|
-
return cached.client;
|
|
143
|
-
}
|
|
144
|
-
// 创建新客户端并缓存
|
|
145
|
-
const client = new BlockRazorClient({
|
|
146
|
-
apiKey: config.apiKey,
|
|
147
|
-
chainId: 56, // BlockRazor 目前只支持 BSC
|
|
148
|
-
customRpcUrl: config.customRpcUrl,
|
|
149
|
-
builderRpcUrl: config.builderRpcUrl
|
|
150
|
-
});
|
|
151
|
-
blockRazorClientCache.set(cacheKey, { client, expireAt: now + CLIENT_CACHE_TTL_MS });
|
|
152
|
-
return client;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* 提交已签名的交易到 BlockRazor(服务器端使用)
|
|
156
|
-
*
|
|
157
|
-
* BlockRazor 是 BSC 链的 Block Builder 服务,支持 Bundle 提交
|
|
158
|
-
*
|
|
159
|
-
* 特点:
|
|
160
|
-
* - 向 Builder EOA 转账 BNB 可提高优先级
|
|
161
|
-
* - 支持 Bundle 合并提高打包率
|
|
162
|
-
* - 最低 Gas Price 要求: 0.05 Gwei
|
|
163
|
-
*
|
|
164
|
-
* @param signedTransactions 签名后的交易数组
|
|
165
|
-
* @param config BlockRazor 提交配置
|
|
166
|
-
* @returns Bundle 提交结果
|
|
167
|
-
*
|
|
168
|
-
* @example
|
|
169
|
-
* ```typescript
|
|
170
|
-
* // 服务器端代码
|
|
171
|
-
* import { submitBundleToBlockRazor } from 'four-flap-meme-sdk';
|
|
172
|
-
*
|
|
173
|
-
* const result = await submitBundleToBlockRazor(signedTransactions, {
|
|
174
|
-
* blockOffset: 10,
|
|
175
|
-
* noMerge: false, // 允许合并
|
|
176
|
-
* autoRetry: true
|
|
177
|
-
* });
|
|
178
|
-
*
|
|
179
|
-
* if (result.code) {
|
|
180
|
-
* } else {
|
|
181
|
-
* console.error('❌ Bundle 提交失败:', result.error);
|
|
182
|
-
* }
|
|
183
|
-
* ```
|
|
184
|
-
*/
|
|
185
|
-
export async function submitBundleToBlockRazor(signedTransactions, config) {
|
|
186
|
-
try {
|
|
187
|
-
const totalTransactions = signedTransactions?.length ?? 0;
|
|
188
|
-
// 验证输入
|
|
189
|
-
if (!signedTransactions || signedTransactions.length === 0) {
|
|
190
|
-
return {
|
|
191
|
-
code: false,
|
|
192
|
-
totalTransactions,
|
|
193
|
-
error: 'signedTransactions cannot be empty'
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
// ✅ 使用缓存的 BlockRazorClient
|
|
197
|
-
const client = getBlockRazorClient(config);
|
|
198
|
-
// 提交 Bundle
|
|
199
|
-
const bundleResult = await client.sendBundle({
|
|
200
|
-
transactions: signedTransactions,
|
|
201
|
-
blockOffset: config.blockOffset ?? 100,
|
|
202
|
-
maxBlockOffset: config.maxBlockOffset ?? 100,
|
|
203
|
-
noMerge: config.noMerge ?? false,
|
|
204
|
-
revertingTxHashes: config.revertingTxHashes,
|
|
205
|
-
autoRetry: config.autoRetry ?? false,
|
|
206
|
-
maxRetries: config.maxRetries ?? 3
|
|
207
|
-
});
|
|
208
|
-
// ✅ 提交成功
|
|
209
|
-
return {
|
|
210
|
-
code: true,
|
|
211
|
-
totalTransactions,
|
|
212
|
-
bundleHash: bundleResult.bundleHash,
|
|
213
|
-
txHashes: bundleResult.txHashes,
|
|
214
|
-
maxBlockNumber: bundleResult.maxBlockNumber,
|
|
215
|
-
txCount: bundleResult.txCount
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
catch (error) {
|
|
219
|
-
// ❌ 提交失败
|
|
220
|
-
return {
|
|
221
|
-
code: false,
|
|
222
|
-
totalTransactions: signedTransactions?.length ?? 0,
|
|
223
|
-
error: error instanceof Error ? error.message : String(error)
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* 批量提交多个 Bundle 到 BlockRazor(顺序执行)
|
|
229
|
-
*
|
|
230
|
-
* @param bundles 多个 Bundle 的签名交易数组
|
|
231
|
-
* @param config BlockRazor 提交配置
|
|
232
|
-
* @returns Bundle 提交结果数组
|
|
233
|
-
*/
|
|
234
|
-
export async function submitMultipleBundlesToBlockRazor(bundles, config) {
|
|
235
|
-
const results = [];
|
|
236
|
-
for (const signedTransactions of bundles) {
|
|
237
|
-
const result = await submitBundleToBlockRazor(signedTransactions, config);
|
|
238
|
-
results.push(result);
|
|
239
|
-
}
|
|
240
|
-
return results;
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* 并行提交多个 Bundle 到 BlockRazor(适用于独立的 Bundle)
|
|
244
|
-
*
|
|
245
|
-
* @param bundles 多个 Bundle 的签名交易数组
|
|
246
|
-
* @param config BlockRazor 提交配置
|
|
247
|
-
* @returns Bundle 提交结果数组
|
|
248
|
-
*/
|
|
249
|
-
export async function submitMultipleBundlesToBlockRazorParallel(bundles, config) {
|
|
250
|
-
const promises = bundles.map(signedTransactions => submitBundleToBlockRazor(signedTransactions, config));
|
|
251
|
-
return await Promise.all(promises);
|
|
252
|
-
}
|
|
253
|
-
function shouldTreatBroadcastErrorAsMaybeSent(msg) {
|
|
254
|
-
const m = String(msg || '').toLowerCase();
|
|
255
|
-
return (m.includes('already known') ||
|
|
256
|
-
m.includes('known transaction') ||
|
|
257
|
-
m.includes('already exists') ||
|
|
258
|
-
m.includes('nonce too low') ||
|
|
259
|
-
m.includes('nonce has already been used') ||
|
|
260
|
-
m.includes('nonce expired') ||
|
|
261
|
-
m.includes('replacement transaction underpriced'));
|
|
262
|
-
}
|
|
263
|
-
async function recoverTxHashIfAlreadySeen(provider, signedTx, errorMessage) {
|
|
264
|
-
if (!shouldTreatBroadcastErrorAsMaybeSent(errorMessage))
|
|
265
|
-
return undefined;
|
|
266
|
-
try {
|
|
267
|
-
const hash = ethers.keccak256(signedTx);
|
|
268
|
-
if (!hash)
|
|
269
|
-
return undefined;
|
|
270
|
-
const tx = await provider.getTransaction(hash);
|
|
271
|
-
return tx ? hash : undefined;
|
|
272
|
-
}
|
|
273
|
-
catch {
|
|
274
|
-
return undefined;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* 并行广播到 RPC(用于不支持 Bundle 的链,如 Monad)
|
|
279
|
-
*
|
|
280
|
-
* ✅ 优化:默认使用并行广播,速度更快
|
|
281
|
-
*
|
|
282
|
-
* @param signedTransactions 签名后的交易数组
|
|
283
|
-
* @param config 直接广播配置
|
|
284
|
-
* @returns 广播结果
|
|
285
|
-
*
|
|
286
|
-
* @example
|
|
287
|
-
* ```typescript
|
|
288
|
-
* // 服务器端代码(Monad 链)
|
|
289
|
-
* import { submitDirectToRpc } from 'four-flap-meme-sdk';
|
|
290
|
-
*
|
|
291
|
-
* const result = await submitDirectToRpc(signedTransactions, {
|
|
292
|
-
* rpcUrl: 'https://rpc-mainnet.monadinfra.com',
|
|
293
|
-
* chainId: 143,
|
|
294
|
-
* chainName: 'MONAD'
|
|
295
|
-
* });
|
|
296
|
-
*
|
|
297
|
-
* if (result.code) {
|
|
298
|
-
* } else {
|
|
299
|
-
* console.error('❌ 全部广播失败:', result.errorSummary);
|
|
300
|
-
* }
|
|
301
|
-
* ```
|
|
302
|
-
*/
|
|
303
|
-
export async function submitDirectToRpc(signedTransactions, config) {
|
|
304
|
-
const totalTransactions = signedTransactions?.length ?? 0;
|
|
305
|
-
// 验证输入
|
|
306
|
-
if (!signedTransactions || signedTransactions.length === 0) {
|
|
307
|
-
return {
|
|
308
|
-
code: false,
|
|
309
|
-
totalTransactions: 0,
|
|
310
|
-
successCount: 0,
|
|
311
|
-
failedCount: 0,
|
|
312
|
-
txHashes: [],
|
|
313
|
-
results: [],
|
|
314
|
-
errorSummary: 'signedTransactions cannot be empty'
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
if (!config.rpcUrl) {
|
|
318
|
-
return {
|
|
319
|
-
code: false,
|
|
320
|
-
totalTransactions,
|
|
321
|
-
successCount: 0,
|
|
322
|
-
failedCount: totalTransactions,
|
|
323
|
-
txHashes: [],
|
|
324
|
-
results: [],
|
|
325
|
-
errorSummary: 'rpcUrl is required in config'
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
const chainId = config.chainId ?? 143;
|
|
329
|
-
const chainName = config.chainName ?? 'MONAD';
|
|
330
|
-
// 创建 Provider
|
|
331
|
-
const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
|
|
332
|
-
chainId,
|
|
333
|
-
name: chainName
|
|
334
|
-
});
|
|
335
|
-
// ✅ 并行广播所有交易
|
|
336
|
-
const broadcastPromises = signedTransactions.map(async (signedTx, i) => {
|
|
337
|
-
try {
|
|
338
|
-
const txResponse = await provider.broadcastTransaction(signedTx);
|
|
339
|
-
// 如果需要等待确认
|
|
340
|
-
if (config.waitForConfirmation) {
|
|
341
|
-
try {
|
|
342
|
-
const receipt = await provider.waitForTransaction(txResponse.hash, 1, config.confirmationTimeout ?? 30000);
|
|
343
|
-
if (receipt && receipt.status === 0) {
|
|
344
|
-
console.warn(`⚠️ [${chainName}] 交易 ${txResponse.hash} 执行失败(已上链但状态为0)`);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
catch {
|
|
348
|
-
console.warn(`⚠️ [${chainName}] 等待交易确认超时: ${txResponse.hash}`);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
return {
|
|
352
|
-
index: i,
|
|
353
|
-
success: true,
|
|
354
|
-
txHash: txResponse.hash
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
catch (error) {
|
|
358
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
359
|
-
console.error(`❌ [${chainName}] 交易 ${i + 1}/${totalTransactions} 广播失败:`, errorMessage);
|
|
360
|
-
// ✅ 兼容:nonce too low / already known 等情况下,交易可能已经被接收
|
|
361
|
-
const recovered = await recoverTxHashIfAlreadySeen(provider, signedTx, errorMessage);
|
|
362
|
-
if (recovered) {
|
|
363
|
-
if (config.waitForConfirmation) {
|
|
364
|
-
try {
|
|
365
|
-
await provider.waitForTransaction(recovered, 1, config.confirmationTimeout ?? 30000);
|
|
366
|
-
}
|
|
367
|
-
catch {
|
|
368
|
-
void 0;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
return { index: i, success: true, txHash: recovered, error: errorMessage };
|
|
372
|
-
}
|
|
373
|
-
return {
|
|
374
|
-
index: i,
|
|
375
|
-
success: false,
|
|
376
|
-
error: errorMessage
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
});
|
|
380
|
-
const results = await Promise.all(broadcastPromises);
|
|
381
|
-
// 按索引排序结果
|
|
382
|
-
results.sort((a, b) => a.index - b.index);
|
|
383
|
-
const txHashes = results.filter(r => r.success && r.txHash).map(r => r.txHash);
|
|
384
|
-
const errors = results.filter(r => !r.success).map(r => `交易 ${r.index + 1}: ${r.error}`);
|
|
385
|
-
const successCount = txHashes.length;
|
|
386
|
-
const failedCount = totalTransactions - successCount;
|
|
387
|
-
return {
|
|
388
|
-
code: successCount > 0,
|
|
389
|
-
totalTransactions,
|
|
390
|
-
successCount,
|
|
391
|
-
failedCount,
|
|
392
|
-
txHashes,
|
|
393
|
-
results,
|
|
394
|
-
errorSummary: errors.length > 0 ? errors.join('; ') : undefined
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
/**
|
|
398
|
-
* ✅ 顺序广播并等待确认(用于多跳交易等需要顺序执行的场景)
|
|
399
|
-
*
|
|
400
|
-
* 每笔交易广播后会等待上链确认,确保后续交易能正确执行
|
|
401
|
-
*
|
|
402
|
-
* ⚠️ 多跳场景:如果某笔交易失败,会立即停止(因为后续交易肯定也会失败)
|
|
403
|
-
*
|
|
404
|
-
* @param signedTransactions 签名后的交易数组
|
|
405
|
-
* @param config 直接广播配置
|
|
406
|
-
* @returns 广播结果
|
|
407
|
-
*/
|
|
408
|
-
export async function submitDirectToRpcSequential(signedTransactions, config) {
|
|
409
|
-
const totalTransactions = signedTransactions?.length ?? 0;
|
|
410
|
-
if (!signedTransactions || signedTransactions.length === 0) {
|
|
411
|
-
return {
|
|
412
|
-
code: false,
|
|
413
|
-
totalTransactions: 0,
|
|
414
|
-
successCount: 0,
|
|
415
|
-
failedCount: 0,
|
|
416
|
-
txHashes: [],
|
|
417
|
-
results: [],
|
|
418
|
-
errorSummary: 'signedTransactions cannot be empty'
|
|
419
|
-
};
|
|
420
|
-
}
|
|
421
|
-
if (!config.rpcUrl) {
|
|
422
|
-
return {
|
|
423
|
-
code: false,
|
|
424
|
-
totalTransactions,
|
|
425
|
-
successCount: 0,
|
|
426
|
-
failedCount: totalTransactions,
|
|
427
|
-
txHashes: [],
|
|
428
|
-
results: [],
|
|
429
|
-
errorSummary: 'rpcUrl is required in config'
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
const chainId = config.chainId ?? 143;
|
|
433
|
-
const chainName = config.chainName ?? 'MONAD';
|
|
434
|
-
// ✅ XLayer 链默认 120 秒超时(网络可能较慢)
|
|
435
|
-
const confirmationTimeout = config.confirmationTimeout ?? (chainId === 196 ? 120000 : 60000);
|
|
436
|
-
const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
|
|
437
|
-
chainId,
|
|
438
|
-
name: chainName
|
|
439
|
-
});
|
|
440
|
-
const results = [];
|
|
441
|
-
const txHashes = [];
|
|
442
|
-
const errors = [];
|
|
443
|
-
// 顺序广播并等待确认
|
|
444
|
-
for (let i = 0; i < signedTransactions.length; i++) {
|
|
445
|
-
const signedTx = signedTransactions[i];
|
|
446
|
-
try {
|
|
447
|
-
// 广播交易
|
|
448
|
-
const txResponse = await provider.broadcastTransaction(signedTx);
|
|
449
|
-
// ✅ 等待交易确认
|
|
450
|
-
const receipt = await provider.waitForTransaction(txResponse.hash, 1, // 等待1个确认
|
|
451
|
-
confirmationTimeout);
|
|
452
|
-
if (receipt && receipt.status === 1) {
|
|
453
|
-
results.push({
|
|
454
|
-
index: i,
|
|
455
|
-
success: true,
|
|
456
|
-
txHash: txResponse.hash
|
|
457
|
-
});
|
|
458
|
-
txHashes.push(txResponse.hash);
|
|
459
|
-
}
|
|
460
|
-
else {
|
|
461
|
-
const errorMsg = `交易执行失败(status=${receipt?.status})`;
|
|
462
|
-
console.error(`❌ [${chainName}] 交易 ${i + 1}/${totalTransactions} 上链失败: ${errorMsg}`);
|
|
463
|
-
results.push({
|
|
464
|
-
index: i,
|
|
465
|
-
success: false,
|
|
466
|
-
txHash: txResponse.hash,
|
|
467
|
-
error: errorMsg
|
|
468
|
-
});
|
|
469
|
-
errors.push(`交易 ${i + 1}: ${errorMsg}`);
|
|
470
|
-
// ✅ 多跳场景:如果某笔失败,后续交易肯定也会失败,立即停止
|
|
471
|
-
console.warn(`⚠️ [${chainName}] 多跳模式检测到失败,停止后续 ${totalTransactions - i - 1} 笔交易`);
|
|
472
|
-
break;
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
catch (error) {
|
|
476
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
477
|
-
console.error(`❌ [${chainName}] 交易 ${i + 1}/${totalTransactions} 广播/确认失败:`, errorMessage);
|
|
478
|
-
// ✅ 兼容:nonce too low / already known 等情况下,交易可能已经被接收
|
|
479
|
-
const recovered = await recoverTxHashIfAlreadySeen(provider, signedTx, errorMessage);
|
|
480
|
-
if (recovered) {
|
|
481
|
-
// 顺序模式依赖确认:尽量等待一下
|
|
482
|
-
try {
|
|
483
|
-
const receipt = await provider.waitForTransaction(recovered, 1, confirmationTimeout);
|
|
484
|
-
if (receipt && receipt.status === 1) {
|
|
485
|
-
results.push({ index: i, success: true, txHash: recovered, error: errorMessage });
|
|
486
|
-
txHashes.push(recovered);
|
|
487
|
-
continue;
|
|
488
|
-
}
|
|
489
|
-
const errorMsg = `交易执行失败(status=${receipt?.status})`;
|
|
490
|
-
console.error(`❌ [${chainName}] 交易 ${i + 1} 恢复失败: ${errorMsg}`);
|
|
491
|
-
results.push({ index: i, success: false, txHash: recovered, error: `${errorMessage} | ${errorMsg}` });
|
|
492
|
-
errors.push(`交易 ${i + 1}: ${errorMessage} | ${errorMsg}`);
|
|
493
|
-
// ✅ 多跳场景:失败则停止
|
|
494
|
-
console.warn(`⚠️ [${chainName}] 多跳模式检测到失败,停止后续 ${totalTransactions - i - 1} 笔交易`);
|
|
495
|
-
break;
|
|
496
|
-
}
|
|
497
|
-
catch (waitError) {
|
|
498
|
-
// 等待超时:对于多跳场景,不能假设成功,需要停止
|
|
499
|
-
const waitErrorMsg = waitError instanceof Error ? waitError.message : String(waitError);
|
|
500
|
-
console.error(`⏱️ [${chainName}] 交易 ${i + 1} 等待确认超时: ${waitErrorMsg}`);
|
|
501
|
-
results.push({ index: i, success: false, txHash: recovered, error: `${errorMessage} | 等待确认超时: ${waitErrorMsg}` });
|
|
502
|
-
errors.push(`交易 ${i + 1}: ${errorMessage} | 等待确认超时`);
|
|
503
|
-
// ✅ 多跳场景:超时也停止
|
|
504
|
-
console.warn(`⚠️ [${chainName}] 多跳模式检测到超时,停止后续 ${totalTransactions - i - 1} 笔交易`);
|
|
505
|
-
break;
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
results.push({
|
|
509
|
-
index: i,
|
|
510
|
-
success: false,
|
|
511
|
-
error: errorMessage
|
|
512
|
-
});
|
|
513
|
-
errors.push(`交易 ${i + 1}: ${errorMessage}`);
|
|
514
|
-
// ✅ 多跳场景:如果某笔失败,后续交易肯定也会失败,立即停止
|
|
515
|
-
console.warn(`⚠️ [${chainName}] 多跳模式检测到失败,停止后续 ${totalTransactions - i - 1} 笔交易`);
|
|
516
|
-
break;
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
const successCount = txHashes.length;
|
|
520
|
-
const failedCount = totalTransactions - successCount;
|
|
521
|
-
return {
|
|
522
|
-
code: successCount > 0,
|
|
523
|
-
totalTransactions,
|
|
524
|
-
successCount,
|
|
525
|
-
failedCount,
|
|
526
|
-
txHashes,
|
|
527
|
-
results,
|
|
528
|
-
errorSummary: errors.length > 0 ? errors.join('; ') : undefined
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
/**
|
|
532
|
-
* ✅ 顺序广播但不等待确认(用于 AA handleOps + tail 等 nonce 连续的场景)
|
|
533
|
-
*
|
|
534
|
-
* 按顺序逐笔发送交易,每笔只等待广播成功(RPC 返回 txHash),不等待链上确认。
|
|
535
|
-
* 这样可以保证交易按顺序进入 mempool,同时避免等待确认超时。
|
|
536
|
-
*
|
|
537
|
-
* @param signedTransactions 签名后的交易数组
|
|
538
|
-
* @param config 直接广播配置
|
|
539
|
-
* @returns 广播结果
|
|
540
|
-
*/
|
|
541
|
-
export async function submitDirectToRpcSequentialNoWait(signedTransactions, config) {
|
|
542
|
-
const totalTransactions = signedTransactions?.length ?? 0;
|
|
543
|
-
if (!signedTransactions || signedTransactions.length === 0) {
|
|
544
|
-
return {
|
|
545
|
-
code: false,
|
|
546
|
-
totalTransactions: 0,
|
|
547
|
-
successCount: 0,
|
|
548
|
-
failedCount: 0,
|
|
549
|
-
txHashes: [],
|
|
550
|
-
results: [],
|
|
551
|
-
errorSummary: 'signedTransactions cannot be empty'
|
|
552
|
-
};
|
|
553
|
-
}
|
|
554
|
-
if (!config.rpcUrl) {
|
|
555
|
-
return {
|
|
556
|
-
code: false,
|
|
557
|
-
totalTransactions,
|
|
558
|
-
successCount: 0,
|
|
559
|
-
failedCount: totalTransactions,
|
|
560
|
-
txHashes: [],
|
|
561
|
-
results: [],
|
|
562
|
-
errorSummary: 'rpcUrl is required in config'
|
|
563
|
-
};
|
|
564
|
-
}
|
|
565
|
-
const chainId = config.chainId ?? 143;
|
|
566
|
-
const chainName = config.chainName ?? 'MONAD';
|
|
567
|
-
const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
|
|
568
|
-
chainId,
|
|
569
|
-
name: chainName
|
|
570
|
-
});
|
|
571
|
-
const results = [];
|
|
572
|
-
const txHashes = [];
|
|
573
|
-
const errors = [];
|
|
574
|
-
// ✅ 顺序广播,每笔只等待广播成功(不等待链上确认)
|
|
575
|
-
for (let i = 0; i < signedTransactions.length; i++) {
|
|
576
|
-
const signedTx = signedTransactions[i];
|
|
577
|
-
try {
|
|
578
|
-
// 广播交易,等待 RPC 返回 txHash
|
|
579
|
-
const txResponse = await provider.broadcastTransaction(signedTx);
|
|
580
|
-
results.push({
|
|
581
|
-
index: i,
|
|
582
|
-
success: true,
|
|
583
|
-
txHash: txResponse.hash
|
|
584
|
-
});
|
|
585
|
-
txHashes.push(txResponse.hash);
|
|
586
|
-
}
|
|
587
|
-
catch (error) {
|
|
588
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
589
|
-
console.error(`❌ [${chainName}] 交易 ${i + 1}/${totalTransactions} 广播失败:`, errorMessage);
|
|
590
|
-
// ✅ 兼容:nonce too low / already known 等情况下,交易可能已经被接收
|
|
591
|
-
const recovered = await recoverTxHashIfAlreadySeen(provider, signedTx, errorMessage);
|
|
592
|
-
if (recovered) {
|
|
593
|
-
results.push({ index: i, success: true, txHash: recovered, error: errorMessage });
|
|
594
|
-
txHashes.push(recovered);
|
|
595
|
-
continue;
|
|
596
|
-
}
|
|
597
|
-
results.push({
|
|
598
|
-
index: i,
|
|
599
|
-
success: false,
|
|
600
|
-
error: errorMessage
|
|
601
|
-
});
|
|
602
|
-
errors.push(`交易 ${i + 1}: ${errorMessage}`);
|
|
603
|
-
// ✅ 如果某笔失败,继续尝试后续交易(可能是 nonce 问题可以自动恢复)
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
const successCount = txHashes.length;
|
|
607
|
-
const failedCount = totalTransactions - successCount;
|
|
608
|
-
return {
|
|
609
|
-
code: successCount > 0,
|
|
610
|
-
totalTransactions,
|
|
611
|
-
successCount,
|
|
612
|
-
failedCount,
|
|
613
|
-
txHashes,
|
|
614
|
-
results,
|
|
615
|
-
errorSummary: errors.length > 0 ? errors.join('; ') : undefined
|
|
616
|
-
};
|
|
617
|
-
}
|
|
618
|
-
/**
|
|
619
|
-
* 并行逐笔广播到 RPC(速度更快,但可能有 nonce 冲突)
|
|
620
|
-
*
|
|
621
|
-
* ⚠️ 注意:仅适用于不同钱包的交易,同一钱包的多笔交易应使用顺序广播
|
|
622
|
-
*
|
|
623
|
-
* @param signedTransactions 签名后的交易数组
|
|
624
|
-
* @param config 直接广播配置
|
|
625
|
-
* @returns 广播结果
|
|
626
|
-
*/
|
|
627
|
-
export async function submitDirectToRpcParallel(signedTransactions, config) {
|
|
628
|
-
const totalTransactions = signedTransactions?.length ?? 0;
|
|
629
|
-
if (!signedTransactions || signedTransactions.length === 0) {
|
|
630
|
-
return {
|
|
631
|
-
code: false,
|
|
632
|
-
totalTransactions: 0,
|
|
633
|
-
successCount: 0,
|
|
634
|
-
failedCount: 0,
|
|
635
|
-
txHashes: [],
|
|
636
|
-
results: [],
|
|
637
|
-
errorSummary: 'signedTransactions cannot be empty'
|
|
638
|
-
};
|
|
639
|
-
}
|
|
640
|
-
if (!config.rpcUrl) {
|
|
641
|
-
return {
|
|
642
|
-
code: false,
|
|
643
|
-
totalTransactions,
|
|
644
|
-
successCount: 0,
|
|
645
|
-
failedCount: totalTransactions,
|
|
646
|
-
txHashes: [],
|
|
647
|
-
results: [],
|
|
648
|
-
errorSummary: 'rpcUrl is required in config'
|
|
649
|
-
};
|
|
650
|
-
}
|
|
651
|
-
const chainId = config.chainId ?? 143;
|
|
652
|
-
const chainName = config.chainName ?? 'MONAD';
|
|
653
|
-
const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
|
|
654
|
-
chainId,
|
|
655
|
-
name: chainName
|
|
656
|
-
});
|
|
657
|
-
// 并行广播
|
|
658
|
-
const broadcastPromises = signedTransactions.map(async (signedTx, i) => {
|
|
659
|
-
try {
|
|
660
|
-
const txResponse = await provider.broadcastTransaction(signedTx);
|
|
661
|
-
return {
|
|
662
|
-
index: i,
|
|
663
|
-
success: true,
|
|
664
|
-
txHash: txResponse.hash
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
catch (error) {
|
|
668
|
-
return {
|
|
669
|
-
index: i,
|
|
670
|
-
success: false,
|
|
671
|
-
error: error instanceof Error ? error.message : String(error)
|
|
672
|
-
};
|
|
673
|
-
}
|
|
674
|
-
});
|
|
675
|
-
const results = await Promise.all(broadcastPromises);
|
|
676
|
-
const txHashes = results.filter(r => r.success && r.txHash).map(r => r.txHash);
|
|
677
|
-
const errors = results.filter(r => !r.success).map(r => `交易 ${r.index + 1}: ${r.error}`);
|
|
678
|
-
const successCount = txHashes.length;
|
|
679
|
-
const failedCount = totalTransactions - successCount;
|
|
680
|
-
return {
|
|
681
|
-
code: successCount > 0,
|
|
682
|
-
totalTransactions,
|
|
683
|
-
successCount,
|
|
684
|
-
failedCount,
|
|
685
|
-
txHashes,
|
|
686
|
-
results,
|
|
687
|
-
errorSummary: errors.length > 0 ? errors.join('; ') : undefined
|
|
688
|
-
};
|
|
689
|
-
}
|
|
690
|
-
/**
|
|
691
|
-
* ENI 快速并行广播:业务交易并行 + 利润交易顺序跟随
|
|
692
|
-
*
|
|
693
|
-
* 流程:
|
|
694
|
-
* 1. 解码所有签名交易,识别哪些 from 地址有多笔交易(即含利润尾随交易的 payer)
|
|
695
|
-
* 2. 把交易分为 "独立交易" 和 "依赖交易"(同 from 的第 2 笔及之后的交易)
|
|
696
|
-
* 3. 并行广播所有独立交易(业务交易)
|
|
697
|
-
* 4. 等待 payer 的业务交易上链后,再提交其利润交易(顺序跟随)
|
|
698
|
-
* 5. 返回合并结果
|
|
699
|
-
*/
|
|
700
|
-
export async function submitEniParallelThenProfit(signedTransactions, config) {
|
|
701
|
-
const totalTransactions = signedTransactions?.length ?? 0;
|
|
702
|
-
const emptyFail = (msg) => ({
|
|
703
|
-
code: false, totalTransactions, successCount: 0, failedCount: totalTransactions,
|
|
704
|
-
txHashes: [], results: [], errorSummary: msg,
|
|
705
|
-
});
|
|
706
|
-
if (!signedTransactions || signedTransactions.length === 0)
|
|
707
|
-
return emptyFail('signedTransactions cannot be empty');
|
|
708
|
-
if (!config.rpcUrl)
|
|
709
|
-
return emptyFail('rpcUrl is required');
|
|
710
|
-
const chainId = config.chainId ?? 173;
|
|
711
|
-
const chainName = config.chainName ?? 'ENI';
|
|
712
|
-
const provider = new ethers.JsonRpcProvider(config.rpcUrl, { chainId, name: chainName });
|
|
713
|
-
// Step 1: 按 from 地址分组,识别独立交易和依赖交易
|
|
714
|
-
const fromCounts = new Map();
|
|
715
|
-
const txMeta = [];
|
|
716
|
-
for (let i = 0; i < signedTransactions.length; i++) {
|
|
717
|
-
try {
|
|
718
|
-
const tx = ethers.Transaction.from(signedTransactions[i]);
|
|
719
|
-
const from = (tx.from || '').toLowerCase();
|
|
720
|
-
const seq = fromCounts.get(from) || 0;
|
|
721
|
-
txMeta.push({ from, index: i, seqInFrom: seq });
|
|
722
|
-
fromCounts.set(from, seq + 1);
|
|
723
|
-
}
|
|
724
|
-
catch {
|
|
725
|
-
txMeta.push({ from: '', index: i, seqInFrom: 0 });
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
// 独立交易:每个 from 的第一笔(seqInFrom === 0)
|
|
729
|
-
// 依赖交易:每个 from 的第 2 笔及之后(seqInFrom > 0,通常是利润交易)
|
|
730
|
-
const independentIndices = txMeta.filter(m => m.seqInFrom === 0).map(m => m.index);
|
|
731
|
-
const dependentGroups = new Map();
|
|
732
|
-
for (const m of txMeta) {
|
|
733
|
-
if (m.seqInFrom > 0) {
|
|
734
|
-
if (!dependentGroups.has(m.from))
|
|
735
|
-
dependentGroups.set(m.from, []);
|
|
736
|
-
dependentGroups.get(m.from).push(m.index);
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
// Step 2: 并行广播所有独立交易
|
|
740
|
-
const allResults = new Array(totalTransactions);
|
|
741
|
-
const independentPromises = independentIndices.map(async (idx) => {
|
|
742
|
-
try {
|
|
743
|
-
const resp = await provider.broadcastTransaction(signedTransactions[idx]);
|
|
744
|
-
allResults[idx] = { index: idx, success: true, txHash: resp.hash };
|
|
745
|
-
}
|
|
746
|
-
catch (error) {
|
|
747
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
748
|
-
const recovered = await recoverTxHashIfAlreadySeen(provider, signedTransactions[idx], errorMessage);
|
|
749
|
-
if (recovered) {
|
|
750
|
-
allResults[idx] = { index: idx, success: true, txHash: recovered, error: errorMessage };
|
|
751
|
-
}
|
|
752
|
-
else {
|
|
753
|
-
allResults[idx] = { index: idx, success: false, error: errorMessage };
|
|
754
|
-
console.error(`❌ [${chainName}] 业务交易 ${idx + 1} 广播失败: ${errorMessage.slice(0, 120)}`);
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
});
|
|
758
|
-
await Promise.all(independentPromises);
|
|
759
|
-
// Step 3: 顺序提交依赖交易(利润交易)
|
|
760
|
-
// 需要等待同 from 的业务交易先上链(nonce 依赖)
|
|
761
|
-
for (const [from, indices] of dependentGroups) {
|
|
762
|
-
// 找到该 from 的业务交易(seqInFrom===0)
|
|
763
|
-
const parentMeta = txMeta.find(m => m.from === from && m.seqInFrom === 0);
|
|
764
|
-
if (parentMeta) {
|
|
765
|
-
const parentResult = allResults[parentMeta.index];
|
|
766
|
-
if (parentResult?.success && parentResult.txHash) {
|
|
767
|
-
// 等待业务交易上链确认
|
|
768
|
-
try {
|
|
769
|
-
await Promise.race([
|
|
770
|
-
provider.waitForTransaction(parentResult.txHash, 1, 10000),
|
|
771
|
-
new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), 10000)),
|
|
772
|
-
]);
|
|
773
|
-
}
|
|
774
|
-
catch {
|
|
775
|
-
console.warn(`⚠️ [${chainName}] 等待 ${from.slice(0, 10)}... 业务交易确认超时,仍尝试发送利润交易`);
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
// 按顺序提交该 from 的依赖交易
|
|
780
|
-
for (const idx of indices) {
|
|
781
|
-
try {
|
|
782
|
-
const resp = await provider.broadcastTransaction(signedTransactions[idx]);
|
|
783
|
-
allResults[idx] = { index: idx, success: true, txHash: resp.hash };
|
|
784
|
-
}
|
|
785
|
-
catch (error) {
|
|
786
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
787
|
-
const recovered = await recoverTxHashIfAlreadySeen(provider, signedTransactions[idx], errorMessage);
|
|
788
|
-
if (recovered) {
|
|
789
|
-
allResults[idx] = { index: idx, success: true, txHash: recovered, error: errorMessage };
|
|
790
|
-
}
|
|
791
|
-
else {
|
|
792
|
-
allResults[idx] = { index: idx, success: false, error: errorMessage };
|
|
793
|
-
console.error(`❌ [${chainName}] 利润交易 ${idx + 1} 广播失败: ${errorMessage.slice(0, 120)}`);
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
// Step 4: 汇总结果
|
|
799
|
-
const txHashes = allResults.filter(r => r?.success && r.txHash).map(r => r.txHash);
|
|
800
|
-
const errors = allResults.filter(r => r && !r.success).map(r => `交易 ${r.index + 1}: ${r.error}`);
|
|
801
|
-
return {
|
|
802
|
-
code: txHashes.length > 0,
|
|
803
|
-
totalTransactions,
|
|
804
|
-
successCount: txHashes.length,
|
|
805
|
-
failedCount: totalTransactions - txHashes.length,
|
|
806
|
-
txHashes,
|
|
807
|
-
results: allResults.filter(Boolean),
|
|
808
|
-
errorSummary: errors.length > 0 ? errors.join('; ') : undefined,
|
|
809
|
-
};
|
|
810
|
-
}
|
|
811
|
-
/**
|
|
812
|
-
* ENI Bundle 提交:模拟验证 → 快速顺序广播 → 同块确认
|
|
813
|
-
*
|
|
814
|
-
* 复用同一 Provider 快速顺序广播,最小化延迟、最大化同块概率。
|
|
815
|
-
* ENI 出块 ~1.08s,连续 nonce 快速提交同块率极高。
|
|
816
|
-
*/
|
|
817
|
-
export async function submitBundleToEni(signedTransactions, config) {
|
|
818
|
-
const totalTransactions = signedTransactions?.length ?? 0;
|
|
819
|
-
const emptyFail = (msg) => ({
|
|
820
|
-
code: false, totalTransactions, successCount: 0, failedCount: totalTransactions,
|
|
821
|
-
txHashes: [], results: [], sameBlock: false, errorSummary: msg,
|
|
822
|
-
});
|
|
823
|
-
if (!signedTransactions || signedTransactions.length === 0)
|
|
824
|
-
return emptyFail('signedTransactions cannot be empty');
|
|
825
|
-
if (!config.rpcUrl)
|
|
826
|
-
return emptyFail('rpcUrl is required');
|
|
827
|
-
const chainId = config.chainId ?? 173;
|
|
828
|
-
const chainName = config.chainName ?? 'ENI';
|
|
829
|
-
const simulationTimeout = config.simulationTimeout ?? 10000;
|
|
830
|
-
const blockConfirmTimeout = config.blockConfirmTimeout ?? 15000;
|
|
831
|
-
const provider = new ethers.JsonRpcProvider(config.rpcUrl, { chainId, name: chainName });
|
|
832
|
-
// Phase 1: 模拟验证
|
|
833
|
-
const simStart = Date.now();
|
|
834
|
-
const simErrors = [];
|
|
835
|
-
for (let i = 0; i < signedTransactions.length; i++) {
|
|
836
|
-
try {
|
|
837
|
-
const tx = ethers.Transaction.from(signedTransactions[i]);
|
|
838
|
-
await Promise.race([
|
|
839
|
-
provider.call({ to: tx.to, data: tx.data, value: tx.value, from: tx.from }),
|
|
840
|
-
new Promise((_, reject) => setTimeout(() => reject(new Error('simulation timeout')), simulationTimeout)),
|
|
841
|
-
]);
|
|
842
|
-
}
|
|
843
|
-
catch (e) {
|
|
844
|
-
const msg = e instanceof Error ? e.message : String(e);
|
|
845
|
-
if (msg.includes('simulation timeout')) {
|
|
846
|
-
console.warn(`⚠️ [${chainName}] 交易 ${i + 1} 模拟超时,跳过验证`);
|
|
847
|
-
}
|
|
848
|
-
else if (msg.includes('execution reverted') || msg.includes('CALL_EXCEPTION')) {
|
|
849
|
-
simErrors.push(`交易 ${i + 1} 模拟失败: ${msg.slice(0, 200)}`);
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
const simulationDurationMs = Date.now() - simStart;
|
|
854
|
-
if (simErrors.length > 0) {
|
|
855
|
-
return { ...emptyFail(simErrors.join('; ')), simulationDurationMs };
|
|
856
|
-
}
|
|
857
|
-
// Phase 2: 快速顺序广播(复用同一 provider 减少连接开销)
|
|
858
|
-
const broadStart = Date.now();
|
|
859
|
-
const results = [];
|
|
860
|
-
const txHashes = [];
|
|
861
|
-
for (let i = 0; i < signedTransactions.length; i++) {
|
|
862
|
-
try {
|
|
863
|
-
const txResponse = await provider.broadcastTransaction(signedTransactions[i]);
|
|
864
|
-
results.push({ index: i, success: true, txHash: txResponse.hash });
|
|
865
|
-
txHashes.push(txResponse.hash);
|
|
866
|
-
}
|
|
867
|
-
catch (error) {
|
|
868
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
869
|
-
const recovered = await recoverTxHashIfAlreadySeen(provider, signedTransactions[i], errorMessage);
|
|
870
|
-
if (recovered) {
|
|
871
|
-
results.push({ index: i, success: true, txHash: recovered, error: errorMessage });
|
|
872
|
-
txHashes.push(recovered);
|
|
873
|
-
}
|
|
874
|
-
else {
|
|
875
|
-
results.push({ index: i, success: false, error: errorMessage });
|
|
876
|
-
console.error(`❌ [${chainName}] Bundle tx ${i + 1}/${totalTransactions} 失败: ${errorMessage}`);
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
const broadcastDurationMs = Date.now() - broadStart;
|
|
881
|
-
const successCount = txHashes.length;
|
|
882
|
-
const failedCount = totalTransactions - successCount;
|
|
883
|
-
if (successCount === 0) {
|
|
884
|
-
return {
|
|
885
|
-
code: false, totalTransactions, successCount, failedCount, txHashes, results,
|
|
886
|
-
sameBlock: false, simulationDurationMs, broadcastDurationMs,
|
|
887
|
-
errorSummary: results.filter(r => !r.success).map(r => r.error).join('; '),
|
|
888
|
-
};
|
|
889
|
-
}
|
|
890
|
-
// Phase 3: 同块确认
|
|
891
|
-
let sameBlock = false;
|
|
892
|
-
let blockNumber;
|
|
893
|
-
const blockNumbers = [];
|
|
894
|
-
try {
|
|
895
|
-
const receipts = await Promise.all(txHashes.map(hash => Promise.race([
|
|
896
|
-
provider.waitForTransaction(hash, 1, blockConfirmTimeout),
|
|
897
|
-
new Promise((resolve) => setTimeout(() => resolve(null), blockConfirmTimeout)),
|
|
898
|
-
])));
|
|
899
|
-
for (const receipt of receipts) {
|
|
900
|
-
if (receipt && receipt.blockNumber) {
|
|
901
|
-
blockNumbers.push(receipt.blockNumber);
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
if (blockNumbers.length === txHashes.length && blockNumbers.length > 0) {
|
|
905
|
-
const uniqueBlocks = new Set(blockNumbers);
|
|
906
|
-
sameBlock = uniqueBlocks.size === 1;
|
|
907
|
-
blockNumber = sameBlock ? blockNumbers[0] : undefined;
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
catch (e) {
|
|
911
|
-
console.warn(`⚠️ [${chainName}] Bundle 区块确认超时`, e instanceof Error ? e.message : String(e));
|
|
912
|
-
}
|
|
913
|
-
return {
|
|
914
|
-
code: true, totalTransactions, successCount, failedCount, txHashes, results,
|
|
915
|
-
sameBlock, blockNumber,
|
|
916
|
-
blockNumbers: blockNumbers.length > 0 ? blockNumbers : undefined,
|
|
917
|
-
simulationDurationMs, broadcastDurationMs,
|
|
918
|
-
};
|
|
919
|
-
}
|
|
1
|
+
/** Bundle 提交 — 实现见 bundle-core/submit;ENI 见 chains/eni/submit */
|
|
2
|
+
export { submitBundleToMerkle, submitMultipleBundles, submitMultipleBundlesParallel, submitBundleToBlockRazor, submitMultipleBundlesToBlockRazor, submitMultipleBundlesToBlockRazorParallel, submitDirectToRpc, submitDirectToRpcSequential, submitDirectToRpcSequentialNoWait, submitDirectToRpcParallel, submitDirectToRpcSmart, } from '../../bundle-core/submit.js';
|
|
3
|
+
export { submitBundleToEni, submitEniParallelThenProfit, } from '../../chains/eni/submit.js';
|