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
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { GAS_CONFIG } from '../../constants/gas.js';
|
|
2
|
+
export function getDeadline(minutes = GAS_CONFIG.DEFAULT_DEADLINE_MINUTES) {
|
|
3
|
+
return Math.floor(Date.now() / 1000) + 60 * minutes;
|
|
4
|
+
}
|
|
5
|
+
export function encodeV3Path(tokens, fees) {
|
|
6
|
+
if (tokens.length < 2) {
|
|
7
|
+
throw new Error('V3 path 需要至少 2 个代币');
|
|
8
|
+
}
|
|
9
|
+
if (fees.length !== tokens.length - 1) {
|
|
10
|
+
throw new Error(`费率数量 (${fees.length}) 必须等于代币数量 - 1 (${tokens.length - 1})`);
|
|
11
|
+
}
|
|
12
|
+
let path = '0x';
|
|
13
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
14
|
+
path += tokens[i].slice(2).toLowerCase().padStart(40, '0');
|
|
15
|
+
if (i < fees.length) {
|
|
16
|
+
path += fees[i].toString(16).padStart(6, '0');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return path;
|
|
20
|
+
}
|
|
21
|
+
export function decodeV3Path(path) {
|
|
22
|
+
const cleanPath = path.startsWith('0x') ? path.slice(2) : path;
|
|
23
|
+
const tokens = [];
|
|
24
|
+
const fees = [];
|
|
25
|
+
let offset = 0;
|
|
26
|
+
while (offset < cleanPath.length) {
|
|
27
|
+
tokens.push('0x' + cleanPath.slice(offset, offset + 40));
|
|
28
|
+
offset += 40;
|
|
29
|
+
if (offset < cleanPath.length) {
|
|
30
|
+
fees.push(parseInt(cleanPath.slice(offset, offset + 6), 16));
|
|
31
|
+
offset += 6;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return { tokens, fees };
|
|
35
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { JsonRpcProvider, type TransactionRequest } from 'ethers';
|
|
2
|
+
export interface GasPriceConfig {
|
|
3
|
+
baseGasPrice?: bigint;
|
|
4
|
+
multiplierPercent?: number;
|
|
5
|
+
minGasPrice?: bigint;
|
|
6
|
+
maxGasPrice?: bigint;
|
|
7
|
+
}
|
|
8
|
+
export declare function getOptimizedGasPrice(provider: JsonRpcProvider, config?: GasPriceConfig): Promise<bigint>;
|
|
9
|
+
export interface GasEstimateConfig {
|
|
10
|
+
multiplier?: number;
|
|
11
|
+
fallbackGasLimit?: bigint;
|
|
12
|
+
allowFailure?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function estimateGasWithSafety(provider: JsonRpcProvider, txRequest: TransactionRequest, config?: GasEstimateConfig): Promise<bigint>;
|
|
15
|
+
export declare function estimateGasBatch(provider: JsonRpcProvider, txRequests: TransactionRequest[], config?: GasEstimateConfig): Promise<bigint[]>;
|
|
16
|
+
export interface BuildTransactionOptions {
|
|
17
|
+
from: string;
|
|
18
|
+
to?: string;
|
|
19
|
+
data?: string;
|
|
20
|
+
value?: bigint;
|
|
21
|
+
nonce: number;
|
|
22
|
+
gasPrice: bigint;
|
|
23
|
+
gasLimit: bigint;
|
|
24
|
+
chainId: number;
|
|
25
|
+
type?: 0 | 2;
|
|
26
|
+
}
|
|
27
|
+
export declare function buildTransaction(options: BuildTransactionOptions): TransactionRequest;
|
|
28
|
+
export interface CommonBundleConfig {
|
|
29
|
+
gasLimit?: number;
|
|
30
|
+
gasLimitMultiplier?: number;
|
|
31
|
+
minGasPriceGwei?: number;
|
|
32
|
+
maxGasPriceGwei?: number;
|
|
33
|
+
txType?: 0 | 2;
|
|
34
|
+
chainId?: number;
|
|
35
|
+
}
|
|
36
|
+
export declare function getGasLimit(config: CommonBundleConfig, defaultGas?: number): bigint;
|
|
37
|
+
export declare function getGasPriceConfig(config: CommonBundleConfig): GasPriceConfig;
|
|
38
|
+
export declare function getTxType(config: CommonBundleConfig): 0 | 2;
|
|
39
|
+
export declare function buildGasFields(txType: number, gasPrice: bigint): Record<string, unknown>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
export async function getOptimizedGasPrice(provider, config) {
|
|
3
|
+
const feeData = await provider.getFeeData();
|
|
4
|
+
const chainGasPrice = feeData.gasPrice || ethers.parseUnits('3', 'gwei');
|
|
5
|
+
let gasPrice;
|
|
6
|
+
if (config?.baseGasPrice) {
|
|
7
|
+
gasPrice = config.baseGasPrice;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
gasPrice = chainGasPrice;
|
|
11
|
+
}
|
|
12
|
+
const multiplier = config?.multiplierPercent ?? 50;
|
|
13
|
+
gasPrice = (gasPrice * BigInt(100 + multiplier)) / 100n;
|
|
14
|
+
if (gasPrice < chainGasPrice) {
|
|
15
|
+
gasPrice = chainGasPrice;
|
|
16
|
+
}
|
|
17
|
+
if (config?.minGasPrice && gasPrice < config.minGasPrice) {
|
|
18
|
+
gasPrice = config.minGasPrice;
|
|
19
|
+
}
|
|
20
|
+
if (config?.maxGasPrice && gasPrice > config.maxGasPrice) {
|
|
21
|
+
gasPrice = config.maxGasPrice;
|
|
22
|
+
}
|
|
23
|
+
return gasPrice;
|
|
24
|
+
}
|
|
25
|
+
export async function estimateGasWithSafety(provider, txRequest, config) {
|
|
26
|
+
const multiplier = config?.multiplier ?? 1.2;
|
|
27
|
+
const fallback = config?.fallbackGasLimit ?? 600000n;
|
|
28
|
+
const allowFailure = config?.allowFailure ?? true;
|
|
29
|
+
try {
|
|
30
|
+
const estimated = await provider.estimateGas(txRequest);
|
|
31
|
+
return BigInt(Math.ceil(Number(estimated) * multiplier));
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (!allowFailure) {
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
return fallback;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export async function estimateGasBatch(provider, txRequests, config) {
|
|
41
|
+
return Promise.all(txRequests.map((req) => estimateGasWithSafety(provider, req, config)));
|
|
42
|
+
}
|
|
43
|
+
export function buildTransaction(options) {
|
|
44
|
+
const tx = {
|
|
45
|
+
from: options.from,
|
|
46
|
+
nonce: options.nonce,
|
|
47
|
+
gasLimit: options.gasLimit,
|
|
48
|
+
chainId: options.chainId,
|
|
49
|
+
};
|
|
50
|
+
if (options.to)
|
|
51
|
+
tx.to = options.to;
|
|
52
|
+
if (options.data)
|
|
53
|
+
tx.data = options.data;
|
|
54
|
+
if (options.value)
|
|
55
|
+
tx.value = options.value;
|
|
56
|
+
if (options.type === 2) {
|
|
57
|
+
tx.type = 2;
|
|
58
|
+
tx.maxFeePerGas = options.gasPrice;
|
|
59
|
+
tx.maxPriorityFeePerGas = options.gasPrice / 10n;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
tx.type = 0;
|
|
63
|
+
tx.gasPrice = options.gasPrice;
|
|
64
|
+
}
|
|
65
|
+
return tx;
|
|
66
|
+
}
|
|
67
|
+
export function getGasLimit(config, defaultGas = 500000) {
|
|
68
|
+
if (config.gasLimit !== undefined) {
|
|
69
|
+
return typeof config.gasLimit === 'bigint' ? config.gasLimit : BigInt(config.gasLimit);
|
|
70
|
+
}
|
|
71
|
+
const multiplier = config.gasLimitMultiplier ?? 1.0;
|
|
72
|
+
return BigInt(Math.ceil(defaultGas * multiplier));
|
|
73
|
+
}
|
|
74
|
+
export function getGasPriceConfig(config) {
|
|
75
|
+
const gasPriceConfig = {};
|
|
76
|
+
if (config.minGasPriceGwei !== undefined) {
|
|
77
|
+
gasPriceConfig.baseGasPrice = ethers.parseUnits(String(config.minGasPriceGwei), 'gwei');
|
|
78
|
+
gasPriceConfig.multiplierPercent = 0;
|
|
79
|
+
}
|
|
80
|
+
if (config.maxGasPriceGwei !== undefined) {
|
|
81
|
+
gasPriceConfig.maxGasPrice = ethers.parseUnits(String(config.maxGasPriceGwei), 'gwei');
|
|
82
|
+
}
|
|
83
|
+
return gasPriceConfig;
|
|
84
|
+
}
|
|
85
|
+
export function getTxType(config) {
|
|
86
|
+
return config.txType ?? 0;
|
|
87
|
+
}
|
|
88
|
+
export function buildGasFields(txType, gasPrice) {
|
|
89
|
+
if (txType === 2) {
|
|
90
|
+
return { type: 2, maxFeePerGas: gasPrice, maxPriorityFeePerGas: gasPrice / 10n || 1n };
|
|
91
|
+
}
|
|
92
|
+
return { type: 0, gasPrice };
|
|
93
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { JsonRpcProvider, Wallet } from 'ethers';
|
|
2
|
+
import { type GeneratedWallet } from '../../../utils/wallet.js';
|
|
3
|
+
export interface ProfitHopConfig {
|
|
4
|
+
provider: JsonRpcProvider;
|
|
5
|
+
payerWallet: Wallet;
|
|
6
|
+
profitAmount: bigint;
|
|
7
|
+
profitRecipient: string;
|
|
8
|
+
hopCount?: number;
|
|
9
|
+
gasPrice: bigint;
|
|
10
|
+
chainId: number;
|
|
11
|
+
txType: number;
|
|
12
|
+
startNonce?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface ProfitHopResult {
|
|
15
|
+
signedTransactions: string[];
|
|
16
|
+
hopWallets: GeneratedWallet[];
|
|
17
|
+
totalNonceUsed: number;
|
|
18
|
+
}
|
|
19
|
+
export declare const PROFIT_HOP_COUNT = 2;
|
|
20
|
+
export declare function buildProfitHopTransactions(config: ProfitHopConfig): Promise<ProfitHopResult>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Wallet } from 'ethers';
|
|
2
|
+
import { generateWallets } from '../../../utils/wallet.js';
|
|
3
|
+
import { GAS_LIMITS, CHAINS } from '../../constants/index.js';
|
|
4
|
+
import { NonceManager } from '../nonce/nonce-manager.js';
|
|
5
|
+
import { buildGasFields } from './bundle-gas.js';
|
|
6
|
+
export const PROFIT_HOP_COUNT = 2;
|
|
7
|
+
const CHAINS_REQUIRE_HOP = [CHAINS.BSC.chainId];
|
|
8
|
+
export async function buildProfitHopTransactions(config) {
|
|
9
|
+
const { provider, payerWallet, profitAmount, profitRecipient, hopCount = PROFIT_HOP_COUNT, gasPrice, chainId, txType, startNonce, } = config;
|
|
10
|
+
if (profitAmount <= 0n) {
|
|
11
|
+
return { signedTransactions: [], hopWallets: [], totalNonceUsed: 0 };
|
|
12
|
+
}
|
|
13
|
+
const nativeTransferGasLimit = GAS_LIMITS.NATIVE_TRANSFER;
|
|
14
|
+
const signedTxs = [];
|
|
15
|
+
const nonceManager = new NonceManager(provider);
|
|
16
|
+
const payerNonce = startNonce ?? (await nonceManager.getNextNonce(payerWallet));
|
|
17
|
+
const needHop = CHAINS_REQUIRE_HOP.includes(chainId);
|
|
18
|
+
const gasFields = buildGasFields(txType, gasPrice);
|
|
19
|
+
if (!needHop) {
|
|
20
|
+
const directTx = await payerWallet.signTransaction({
|
|
21
|
+
to: profitRecipient,
|
|
22
|
+
value: profitAmount,
|
|
23
|
+
nonce: payerNonce,
|
|
24
|
+
gasLimit: nativeTransferGasLimit,
|
|
25
|
+
chainId,
|
|
26
|
+
...gasFields,
|
|
27
|
+
});
|
|
28
|
+
signedTxs.push(directTx);
|
|
29
|
+
return { signedTransactions: signedTxs, hopWallets: [], totalNonceUsed: 1 };
|
|
30
|
+
}
|
|
31
|
+
const gasFeePerHop = nativeTransferGasLimit * gasPrice;
|
|
32
|
+
const hopWalletsInfo = generateWallets(hopCount);
|
|
33
|
+
const hopWallets = hopWalletsInfo.map((w) => new Wallet(w.privateKey, provider));
|
|
34
|
+
const hopAmounts = [];
|
|
35
|
+
for (let i = hopCount - 1; i >= 0; i--) {
|
|
36
|
+
if (i === hopCount - 1) {
|
|
37
|
+
hopAmounts.unshift(profitAmount + gasFeePerHop);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
hopAmounts.unshift(hopAmounts[0] + gasFeePerHop);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const payerTx = await payerWallet.signTransaction({
|
|
44
|
+
to: hopWallets[0].address,
|
|
45
|
+
value: hopAmounts[0],
|
|
46
|
+
nonce: payerNonce,
|
|
47
|
+
gasLimit: nativeTransferGasLimit,
|
|
48
|
+
chainId,
|
|
49
|
+
...gasFields,
|
|
50
|
+
});
|
|
51
|
+
signedTxs.push(payerTx);
|
|
52
|
+
for (let i = 0; i < hopCount; i++) {
|
|
53
|
+
const fromWallet = hopWallets[i];
|
|
54
|
+
const isLastHop = i === hopCount - 1;
|
|
55
|
+
const toAddress = isLastHop ? profitRecipient : hopWallets[i + 1].address;
|
|
56
|
+
const value = isLastHop ? profitAmount : hopAmounts[i + 1];
|
|
57
|
+
const hopTx = await fromWallet.signTransaction({
|
|
58
|
+
to: toAddress,
|
|
59
|
+
value,
|
|
60
|
+
nonce: 0,
|
|
61
|
+
gasLimit: nativeTransferGasLimit,
|
|
62
|
+
chainId,
|
|
63
|
+
...gasFields,
|
|
64
|
+
});
|
|
65
|
+
signedTxs.push(hopTx);
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
signedTransactions: signedTxs,
|
|
69
|
+
hopWallets: hopWalletsInfo,
|
|
70
|
+
totalNonceUsed: 1,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK 横向基础(错误规范化、可选日志、共享类型与 Tx 构建)。
|
|
3
|
+
* 新代码优先从这里收口 unknown / Logger / 复用类型;存量代码可渐进迁移。
|
|
4
|
+
*/
|
|
5
|
+
export { getErrorMessageFromUnknown, normalizeUnknownError, type NormalizedErrorShape } from './normalize-unknown.js';
|
|
6
|
+
export { noopSdkLogger, consoleSdkLogger, type SdkLogger } from './sdk-logger.js';
|
|
7
|
+
export type { Aggregate3CallResult, EnsureAllowanceResult, EnsureAllowanceBatchItemResult, ApproveTokenBatchParams, ApproveTokenBatchRawParams, ApproveTokenBatchResult, ApproveTokenBatchSignResult, HoldersMakerChain, HoldersMakerTradeType, BaseTokenType, HoldersMakerConfig, HoldersMakerParams, TransactionLayer, BatchResult, HoldersMakerResult, DexConfig, ChainDexConfig, PoolPairInfo, V3PoolInfo, DexPoolInfo, BestPoolInfo, LPPlatform, LPInfo, InspectOptions, BundleSubmitResult, SignedTransactionsResult, AirdropDisperseParams, AirdropDisperseSignParams, AirdropSweepParams, AirdropSweepSignParams, DisperseParams, DisperseSignParams, SweepParams, SweepSignParams, PrivateSaleSignConfig, PrivateSaleTransferParams, BatchPrivateSaleParams, PrivateSaleResult, SupportedChain, QuoteParams, QuoteResult, } from './types/index.js';
|
|
8
|
+
export { buildTransactionRequest, type BuildTxRequestParams } from './tx/build-request.js';
|
|
9
|
+
export { NonceManager } from './nonce/nonce-manager.js';
|
|
10
|
+
export { type GasPriceConfig, type GasEstimateConfig, type BuildTransactionOptions, type CommonBundleConfig, getOptimizedGasPrice, estimateGasWithSafety, estimateGasBatch, buildTransaction, getGasLimit, getGasPriceConfig, getTxType, buildGasFields, } from './gas/bundle-gas.js';
|
|
11
|
+
export { type ProfitHopConfig, type ProfitHopResult, PROFIT_HOP_COUNT, buildProfitHopTransactions, } from './gas/profit-hop.js';
|
|
12
|
+
export { getChainId, signTransactionsBatch, signTransactionsBatchMultiWallet, validateSignedTransactions, } from './tx/sign-batch.js';
|
|
13
|
+
export { getDeadline, encodeV3Path, decodeV3Path } from './dex/v3-path.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK 横向基础(错误规范化、可选日志、共享类型与 Tx 构建)。
|
|
3
|
+
* 新代码优先从这里收口 unknown / Logger / 复用类型;存量代码可渐进迁移。
|
|
4
|
+
*/
|
|
5
|
+
export { getErrorMessageFromUnknown, normalizeUnknownError } from './normalize-unknown.js';
|
|
6
|
+
export { noopSdkLogger, consoleSdkLogger } from './sdk-logger.js';
|
|
7
|
+
export { buildTransactionRequest } from './tx/build-request.js';
|
|
8
|
+
export { NonceManager } from './nonce/nonce-manager.js';
|
|
9
|
+
export { getOptimizedGasPrice, estimateGasWithSafety, estimateGasBatch, buildTransaction, getGasLimit, getGasPriceConfig, getTxType, buildGasFields, } from './gas/bundle-gas.js';
|
|
10
|
+
export { PROFIT_HOP_COUNT, buildProfitHopTransactions, } from './gas/profit-hop.js';
|
|
11
|
+
export { getChainId, signTransactionsBatch, signTransactionsBatchMultiWallet, validateSignedTransactions, } from './tx/sign-batch.js';
|
|
12
|
+
export { getDeadline, encodeV3Path, decodeV3Path } from './dex/v3-path.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import '../tx/wallet-sign-patch.js';
|
|
2
|
+
import { JsonRpcProvider, Wallet } from 'ethers';
|
|
3
|
+
/**
|
|
4
|
+
* Nonce 管理器 — bundle 交易中管理多钱包 nonce
|
|
5
|
+
*/
|
|
6
|
+
export declare class NonceManager {
|
|
7
|
+
private provider;
|
|
8
|
+
private tempNonceCache;
|
|
9
|
+
private chainIdPromise?;
|
|
10
|
+
constructor(provider: JsonRpcProvider);
|
|
11
|
+
private getChainId;
|
|
12
|
+
getNextNonce(wallet: Wallet | string): Promise<number>;
|
|
13
|
+
getNextNonceBatch(wallet: Wallet | string, count: number): Promise<number[]>;
|
|
14
|
+
clearTemp(): void;
|
|
15
|
+
getTempCachedNonce(address: string): number | undefined;
|
|
16
|
+
getNextNoncesForWallets(wallets: (Wallet | string)[]): Promise<number[]>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import '../tx/wallet-sign-patch.js';
|
|
2
|
+
import { CHAINS } from '../../constants/index.js';
|
|
3
|
+
const GLOBAL_NONCE_TTL_MS = 60 * 1000;
|
|
4
|
+
const globalNonceCursorByChain = new Map();
|
|
5
|
+
function isFlakyNonceChain(chainId) {
|
|
6
|
+
return Number(chainId) === CHAINS.XLAYER.chainId;
|
|
7
|
+
}
|
|
8
|
+
function getCursorMap(chainId) {
|
|
9
|
+
let m = globalNonceCursorByChain.get(chainId);
|
|
10
|
+
if (!m) {
|
|
11
|
+
m = new Map();
|
|
12
|
+
globalNonceCursorByChain.set(chainId, m);
|
|
13
|
+
}
|
|
14
|
+
return m;
|
|
15
|
+
}
|
|
16
|
+
function getGlobalNextNonce(chainId, addrLower) {
|
|
17
|
+
const m = globalNonceCursorByChain.get(chainId);
|
|
18
|
+
if (!m)
|
|
19
|
+
return undefined;
|
|
20
|
+
const e = m.get(addrLower);
|
|
21
|
+
if (!e)
|
|
22
|
+
return undefined;
|
|
23
|
+
if (Date.now() - e.updatedAt > GLOBAL_NONCE_TTL_MS) {
|
|
24
|
+
m.delete(addrLower);
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
return e.nextNonce;
|
|
28
|
+
}
|
|
29
|
+
function setGlobalNextNonce(chainId, addrLower, nextNonce) {
|
|
30
|
+
const m = getCursorMap(chainId);
|
|
31
|
+
const cur = m.get(addrLower);
|
|
32
|
+
const next = Number(nextNonce);
|
|
33
|
+
if (!Number.isFinite(next) || next < 0)
|
|
34
|
+
return;
|
|
35
|
+
if (!cur || next > cur.nextNonce || Date.now() - cur.updatedAt > GLOBAL_NONCE_TTL_MS) {
|
|
36
|
+
m.set(addrLower, { nextNonce: next, updatedAt: Date.now() });
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
cur.updatedAt = Date.now();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Nonce 管理器 — bundle 交易中管理多钱包 nonce
|
|
44
|
+
*/
|
|
45
|
+
export class NonceManager {
|
|
46
|
+
provider;
|
|
47
|
+
tempNonceCache = new Map();
|
|
48
|
+
chainIdPromise;
|
|
49
|
+
constructor(provider) {
|
|
50
|
+
this.provider = provider;
|
|
51
|
+
}
|
|
52
|
+
async getChainId() {
|
|
53
|
+
if (!this.chainIdPromise) {
|
|
54
|
+
this.chainIdPromise = this.provider
|
|
55
|
+
.getNetwork()
|
|
56
|
+
.then((n) => Number(n.chainId))
|
|
57
|
+
.catch(() => 0);
|
|
58
|
+
}
|
|
59
|
+
return this.chainIdPromise;
|
|
60
|
+
}
|
|
61
|
+
async getNextNonce(wallet) {
|
|
62
|
+
const address = typeof wallet === 'string' ? wallet : wallet.address;
|
|
63
|
+
const key = address.toLowerCase();
|
|
64
|
+
const chainId = await this.getChainId();
|
|
65
|
+
const flaky = isFlakyNonceChain(chainId);
|
|
66
|
+
if (this.tempNonceCache.has(key)) {
|
|
67
|
+
const cachedNonce = this.tempNonceCache.get(key);
|
|
68
|
+
this.tempNonceCache.set(key, cachedNonce + 1);
|
|
69
|
+
if (flaky)
|
|
70
|
+
setGlobalNextNonce(chainId, key, cachedNonce + 1);
|
|
71
|
+
return cachedNonce;
|
|
72
|
+
}
|
|
73
|
+
const onchainNonce = await this.provider.getTransactionCount(address, 'pending');
|
|
74
|
+
let effectiveNonce = onchainNonce;
|
|
75
|
+
if (flaky) {
|
|
76
|
+
const globalNext = getGlobalNextNonce(chainId, key);
|
|
77
|
+
if (globalNext !== undefined) {
|
|
78
|
+
const delta = globalNext - onchainNonce;
|
|
79
|
+
if (delta > 0 && delta <= 10) {
|
|
80
|
+
effectiveNonce = globalNext;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
setGlobalNextNonce(chainId, key, effectiveNonce + 1);
|
|
84
|
+
}
|
|
85
|
+
this.tempNonceCache.set(key, effectiveNonce + 1);
|
|
86
|
+
return effectiveNonce;
|
|
87
|
+
}
|
|
88
|
+
async getNextNonceBatch(wallet, count) {
|
|
89
|
+
const address = typeof wallet === 'string' ? wallet : wallet.address;
|
|
90
|
+
const key = address.toLowerCase();
|
|
91
|
+
const chainId = await this.getChainId();
|
|
92
|
+
const flaky = isFlakyNonceChain(chainId);
|
|
93
|
+
let startNonce;
|
|
94
|
+
if (this.tempNonceCache.has(key)) {
|
|
95
|
+
startNonce = this.tempNonceCache.get(key);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
startNonce = await this.provider.getTransactionCount(address, 'pending');
|
|
99
|
+
}
|
|
100
|
+
if (flaky) {
|
|
101
|
+
const globalNext = getGlobalNextNonce(chainId, key);
|
|
102
|
+
if (globalNext !== undefined) {
|
|
103
|
+
const delta = globalNext - startNonce;
|
|
104
|
+
if (delta > 0 && delta <= 10)
|
|
105
|
+
startNonce = globalNext;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
this.tempNonceCache.set(key, startNonce + count);
|
|
109
|
+
if (flaky)
|
|
110
|
+
setGlobalNextNonce(chainId, key, startNonce + count);
|
|
111
|
+
return Array.from({ length: count }, (_, i) => startNonce + i);
|
|
112
|
+
}
|
|
113
|
+
clearTemp() {
|
|
114
|
+
this.tempNonceCache.clear();
|
|
115
|
+
}
|
|
116
|
+
getTempCachedNonce(address) {
|
|
117
|
+
return this.tempNonceCache.get(address.toLowerCase());
|
|
118
|
+
}
|
|
119
|
+
async getNextNoncesForWallets(wallets) {
|
|
120
|
+
const addresses = wallets.map((w) => (typeof w === 'string' ? w : w.address));
|
|
121
|
+
const keys = addresses.map((a) => a.toLowerCase());
|
|
122
|
+
const chainId = await this.getChainId();
|
|
123
|
+
const flaky = isFlakyNonceChain(chainId);
|
|
124
|
+
const needQuery = [];
|
|
125
|
+
const results = new Array(wallets.length);
|
|
126
|
+
for (let i = 0; i < keys.length; i++) {
|
|
127
|
+
const key = keys[i];
|
|
128
|
+
if (this.tempNonceCache.has(key)) {
|
|
129
|
+
const cachedNonce = this.tempNonceCache.get(key);
|
|
130
|
+
results[i] = cachedNonce;
|
|
131
|
+
this.tempNonceCache.set(key, cachedNonce + 1);
|
|
132
|
+
if (flaky)
|
|
133
|
+
setGlobalNextNonce(chainId, key, cachedNonce + 1);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
needQuery.push({ index: i, address: addresses[i] });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (needQuery.length > 0) {
|
|
140
|
+
let queryResults;
|
|
141
|
+
try {
|
|
142
|
+
const batchRequests = needQuery.map(({ address }, idx) => ({
|
|
143
|
+
method: 'eth_getTransactionCount',
|
|
144
|
+
params: [address, 'pending'],
|
|
145
|
+
id: idx + 1,
|
|
146
|
+
jsonrpc: '2.0',
|
|
147
|
+
}));
|
|
148
|
+
const rawResults = await this.provider._send(batchRequests);
|
|
149
|
+
queryResults = rawResults.map((r) => {
|
|
150
|
+
if (r.result) {
|
|
151
|
+
return parseInt(r.result, 16);
|
|
152
|
+
}
|
|
153
|
+
return 0;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
const queryPromises = needQuery.map(({ address }) => this.provider.getTransactionCount(address, 'pending'));
|
|
158
|
+
queryResults = await Promise.all(queryPromises);
|
|
159
|
+
}
|
|
160
|
+
for (let i = 0; i < needQuery.length; i++) {
|
|
161
|
+
const { index, address } = needQuery[i];
|
|
162
|
+
const key = address.toLowerCase();
|
|
163
|
+
const onchainNonce = queryResults[i];
|
|
164
|
+
let effectiveNonce = onchainNonce;
|
|
165
|
+
if (flaky) {
|
|
166
|
+
const globalNext = getGlobalNextNonce(chainId, key);
|
|
167
|
+
if (globalNext !== undefined) {
|
|
168
|
+
const delta = globalNext - onchainNonce;
|
|
169
|
+
if (delta > 0 && delta <= 10)
|
|
170
|
+
effectiveNonce = globalNext;
|
|
171
|
+
}
|
|
172
|
+
setGlobalNextNonce(chainId, key, effectiveNonce + 1);
|
|
173
|
+
}
|
|
174
|
+
results[index] = effectiveNonce;
|
|
175
|
+
this.tempNonceCache.set(key, effectiveNonce + 1);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return results;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK 统一的 unknown / Error 收口(审计:catch 宜用 unknown + normalize)
|
|
3
|
+
*/
|
|
4
|
+
export interface NormalizedErrorShape {
|
|
5
|
+
message: string;
|
|
6
|
+
cause?: unknown;
|
|
7
|
+
}
|
|
8
|
+
export declare function getErrorMessageFromUnknown(error: unknown): string;
|
|
9
|
+
export declare function normalizeUnknownError(error: unknown): NormalizedErrorShape;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK 统一的 unknown / Error 收口(审计:catch 宜用 unknown + normalize)
|
|
3
|
+
*/
|
|
4
|
+
export function getErrorMessageFromUnknown(error) {
|
|
5
|
+
if (error instanceof Error)
|
|
6
|
+
return error.message;
|
|
7
|
+
if (typeof error === 'string')
|
|
8
|
+
return error;
|
|
9
|
+
if (error !== null && typeof error === 'object') {
|
|
10
|
+
const o = error;
|
|
11
|
+
const m = o.message;
|
|
12
|
+
if (typeof m === 'string')
|
|
13
|
+
return m;
|
|
14
|
+
const reason = o.reason;
|
|
15
|
+
if (typeof reason === 'string')
|
|
16
|
+
return reason;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
return String(error);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return 'Unknown error';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export function normalizeUnknownError(error) {
|
|
26
|
+
const message = getErrorMessageFromUnknown(error);
|
|
27
|
+
const cause = error instanceof Error && error.cause !== undefined ? error.cause : error instanceof Error ? undefined : error;
|
|
28
|
+
return { message, ...(cause !== undefined ? { cause } : {}) };
|
|
29
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK 可选日志门面(默认静默);业务侧可传入以替代 console.*
|
|
3
|
+
*/
|
|
4
|
+
export interface SdkLogger {
|
|
5
|
+
debug?: (msg: string, ...args: unknown[]) => void;
|
|
6
|
+
info?: (msg: string, ...args: unknown[]) => void;
|
|
7
|
+
warn?: (msg: string, ...args: unknown[]) => void;
|
|
8
|
+
error?: (msg: string, ...args: unknown[]) => void;
|
|
9
|
+
}
|
|
10
|
+
/** 不输出日志(库的推荐默认)。 */
|
|
11
|
+
export declare const noopSdkLogger: SdkLogger;
|
|
12
|
+
/** 直接使用 console(仅调试/过渡期)。 */
|
|
13
|
+
export declare const consoleSdkLogger: SdkLogger;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK 可选日志门面(默认静默);业务侧可传入以替代 console.*
|
|
3
|
+
*/
|
|
4
|
+
/** 不输出日志(库的推荐默认)。 */
|
|
5
|
+
export const noopSdkLogger = {};
|
|
6
|
+
/** 直接使用 console(仅调试/过渡期)。 */
|
|
7
|
+
export const consoleSdkLogger = {
|
|
8
|
+
debug: (msg, ...args) => console.debug(msg, ...args),
|
|
9
|
+
info: (msg, ...args) => console.info(msg, ...args),
|
|
10
|
+
warn: (msg, ...args) => console.warn(msg, ...args),
|
|
11
|
+
error: (msg, ...args) => console.error(msg, ...args),
|
|
12
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TransactionLike, TransactionRequest } from 'ethers';
|
|
2
|
+
/** 构建签名用 TransactionRequest 的公共参数 */
|
|
3
|
+
export type BuildTxRequestParams = {
|
|
4
|
+
from: string;
|
|
5
|
+
nonce: number;
|
|
6
|
+
gasLimit: bigint;
|
|
7
|
+
gasPrice: bigint;
|
|
8
|
+
priorityFee: bigint;
|
|
9
|
+
chainId: number;
|
|
10
|
+
txType: number;
|
|
11
|
+
value?: bigint;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* 将 populateTransaction 结果与 gas/nonce 字段合并为可签名交易。
|
|
15
|
+
* type 0 (Legacy) 使用 gasPrice;type 2 (EIP-1559) 使用 maxFeePerGas + maxPriorityFeePerGas。
|
|
16
|
+
*/
|
|
17
|
+
export declare function buildTransactionRequest(unsigned: TransactionLike, { from, nonce, gasLimit, gasPrice, priorityFee, chainId, txType, value }: BuildTxRequestParams): TransactionRequest;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 将 populateTransaction 结果与 gas/nonce 字段合并为可签名交易。
|
|
3
|
+
* type 0 (Legacy) 使用 gasPrice;type 2 (EIP-1559) 使用 maxFeePerGas + maxPriorityFeePerGas。
|
|
4
|
+
*/
|
|
5
|
+
export function buildTransactionRequest(unsigned, { from, nonce, gasLimit, gasPrice, priorityFee, chainId, txType, value }) {
|
|
6
|
+
const tx = {
|
|
7
|
+
...unsigned,
|
|
8
|
+
from,
|
|
9
|
+
nonce,
|
|
10
|
+
gasLimit,
|
|
11
|
+
chainId,
|
|
12
|
+
type: txType,
|
|
13
|
+
};
|
|
14
|
+
if (value !== undefined) {
|
|
15
|
+
tx.value = value;
|
|
16
|
+
}
|
|
17
|
+
if (txType === 2) {
|
|
18
|
+
tx.maxFeePerGas = gasPrice;
|
|
19
|
+
tx.maxPriorityFeePerGas = priorityFee;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
tx.gasPrice = gasPrice;
|
|
23
|
+
}
|
|
24
|
+
return tx;
|
|
25
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { JsonRpcProvider, Wallet, type TransactionRequest } from 'ethers';
|
|
2
|
+
export declare function getChainId(provider: JsonRpcProvider, configChainId?: number): Promise<number>;
|
|
3
|
+
export declare function signTransactionsBatch(wallet: Wallet, transactions: TransactionRequest[]): Promise<string[]>;
|
|
4
|
+
export declare function signTransactionsBatchMultiWallet(wallets: Wallet[], transactions: TransactionRequest[]): Promise<string[]>;
|
|
5
|
+
export declare function validateSignedTransactions(signedTxs: string[]): boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export async function getChainId(provider, configChainId) {
|
|
2
|
+
if (configChainId !== undefined)
|
|
3
|
+
return configChainId;
|
|
4
|
+
const network = await provider.getNetwork();
|
|
5
|
+
return Number(network.chainId);
|
|
6
|
+
}
|
|
7
|
+
export async function signTransactionsBatch(wallet, transactions) {
|
|
8
|
+
return Promise.all(transactions.map((tx) => wallet.signTransaction(tx)));
|
|
9
|
+
}
|
|
10
|
+
export async function signTransactionsBatchMultiWallet(wallets, transactions) {
|
|
11
|
+
if (wallets.length !== transactions.length) {
|
|
12
|
+
throw new Error(`Wallet count (${wallets.length}) must match transaction count (${transactions.length})`);
|
|
13
|
+
}
|
|
14
|
+
return Promise.all(transactions.map((tx, i) => wallets[i].signTransaction(tx)));
|
|
15
|
+
}
|
|
16
|
+
export function validateSignedTransactions(signedTxs) {
|
|
17
|
+
if (!signedTxs || signedTxs.length === 0) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
for (const tx of signedTxs) {
|
|
21
|
+
if (typeof tx !== 'string' || !tx.startsWith('0x')) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EIP-1559 兼容:当 txType=2 但传了 gasPrice 时,自动转换为 maxFeePerGas
|
|
3
|
+
* 模块加载时 patch Wallet.prototype.signTransaction(全局一次)
|
|
4
|
+
*/
|
|
5
|
+
import { Wallet } from 'ethers';
|
|
6
|
+
const _origWalletSign = Wallet.prototype.signTransaction;
|
|
7
|
+
Wallet.prototype.signTransaction = async function (tx) {
|
|
8
|
+
const signable = tx;
|
|
9
|
+
if (signable.type === 2 && signable.gasPrice != null && signable.maxFeePerGas == null) {
|
|
10
|
+
const { gasPrice: gp, ...rest } = signable;
|
|
11
|
+
return _origWalletSign.call(this, {
|
|
12
|
+
...rest,
|
|
13
|
+
maxFeePerGas: gp,
|
|
14
|
+
maxPriorityFeePerGas: rest.maxPriorityFeePerGas ?? 0n,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return _origWalletSign.call(this, tx);
|
|
18
|
+
};
|