@swapkit/toolboxes 4.0.0-beta.50 → 4.0.0-beta.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/cosmos/index.cjs +2 -2
- package/dist/src/cosmos/index.cjs.map +10 -6
- package/dist/src/cosmos/index.js +2 -2
- package/dist/src/cosmos/index.js.map +10 -6
- package/dist/src/evm/index.cjs +2 -2
- package/dist/src/evm/index.cjs.map +10 -8
- package/dist/src/evm/index.js +2 -2
- package/dist/src/evm/index.js.map +10 -8
- package/dist/src/index.cjs +4 -2
- package/dist/src/index.cjs.map +54 -4
- package/dist/src/index.js +4 -2
- package/dist/src/index.js.map +54 -4
- package/dist/src/near/index.cjs +2 -2
- package/dist/src/near/index.cjs.map +7 -5
- package/dist/src/near/index.js +2 -2
- package/dist/src/near/index.js.map +7 -5
- package/dist/src/radix/index.cjs +2 -2
- package/dist/src/radix/index.cjs.map +2 -2
- package/dist/src/radix/index.js +2 -2
- package/dist/src/radix/index.js.map +2 -2
- package/dist/src/ripple/index.cjs +2 -2
- package/dist/src/ripple/index.cjs.map +2 -2
- package/dist/src/ripple/index.js +2 -2
- package/dist/src/ripple/index.js.map +2 -2
- package/dist/src/solana/index.cjs +2 -2
- package/dist/src/solana/index.cjs.map +5 -4
- package/dist/src/solana/index.js +2 -2
- package/dist/src/solana/index.js.map +5 -4
- package/dist/src/substrate/index.cjs +2 -2
- package/dist/src/substrate/index.cjs.map +6 -5
- package/dist/src/substrate/index.js +2 -2
- package/dist/src/substrate/index.js.map +6 -5
- package/dist/src/tron/index.cjs +2 -2
- package/dist/src/tron/index.cjs.map +6 -5
- package/dist/src/tron/index.js +2 -2
- package/dist/src/tron/index.js.map +6 -5
- package/dist/src/utxo/index.cjs +4 -4
- package/dist/src/utxo/index.cjs.map +10 -7
- package/dist/src/utxo/index.js +4 -4
- package/dist/src/utxo/index.js.map +10 -7
- package/{src/cosmos/index.ts → dist/types/cosmos/index.d.ts} +1 -0
- package/dist/types/cosmos/index.d.ts.map +1 -0
- package/dist/types/cosmos/thorchainUtils/addressFormat.d.ts +5 -0
- package/dist/types/cosmos/thorchainUtils/addressFormat.d.ts.map +1 -0
- package/{src/cosmos/thorchainUtils/index.ts → dist/types/cosmos/thorchainUtils/index.d.ts} +1 -0
- package/dist/types/cosmos/thorchainUtils/index.d.ts.map +1 -0
- package/dist/types/cosmos/thorchainUtils/messages.d.ts +208 -0
- package/dist/types/cosmos/thorchainUtils/messages.d.ts.map +1 -0
- package/dist/types/cosmos/thorchainUtils/registry.d.ts +4 -0
- package/dist/types/cosmos/thorchainUtils/registry.d.ts.map +1 -0
- package/dist/types/cosmos/thorchainUtils/types/MsgCompiled.d.ts +2 -0
- package/dist/types/cosmos/thorchainUtils/types/MsgCompiled.d.ts.map +1 -0
- package/dist/types/cosmos/thorchainUtils/types/client-types.d.ts +66 -0
- package/dist/types/cosmos/thorchainUtils/types/client-types.d.ts.map +1 -0
- package/dist/types/cosmos/thorchainUtils/types/index.d.ts +2 -0
- package/dist/types/cosmos/thorchainUtils/types/index.d.ts.map +1 -0
- package/dist/types/cosmos/toolbox/cosmos.d.ts +93 -0
- package/dist/types/cosmos/toolbox/cosmos.d.ts.map +1 -0
- package/dist/types/cosmos/toolbox/index.d.ts +14 -0
- package/dist/types/cosmos/toolbox/index.d.ts.map +1 -0
- package/dist/types/cosmos/toolbox/thorchain.d.ts +158 -0
- package/dist/types/cosmos/toolbox/thorchain.d.ts.map +1 -0
- package/{src/cosmos/types.ts → dist/types/cosmos/types.d.ts} +24 -29
- package/dist/types/cosmos/types.d.ts.map +1 -0
- package/dist/types/cosmos/util.d.ts +68 -0
- package/dist/types/cosmos/util.d.ts.map +1 -0
- package/dist/types/evm/api.d.ts +8 -0
- package/dist/types/evm/api.d.ts.map +1 -0
- package/dist/types/evm/contracts/eth/multicall.d.ts +36 -0
- package/dist/types/evm/contracts/eth/multicall.d.ts.map +1 -0
- package/dist/types/evm/contracts/op/gasOracle.d.ts +40 -0
- package/dist/types/evm/contracts/op/gasOracle.d.ts.map +1 -0
- package/dist/types/evm/helpers.d.ts +20 -0
- package/dist/types/evm/helpers.d.ts.map +1 -0
- package/{src/evm/index.ts → dist/types/evm/index.d.ts} +1 -0
- package/dist/types/evm/index.d.ts.map +1 -0
- package/dist/types/evm/toolbox/baseEVMToolbox.d.ts +82 -0
- package/dist/types/evm/toolbox/baseEVMToolbox.d.ts.map +1 -0
- package/dist/types/evm/toolbox/evm.d.ts +367 -0
- package/dist/types/evm/toolbox/evm.d.ts.map +1 -0
- package/dist/types/evm/toolbox/index.d.ts +89 -0
- package/dist/types/evm/toolbox/index.d.ts.map +1 -0
- package/dist/types/evm/toolbox/op.d.ts +62 -0
- package/dist/types/evm/toolbox/op.d.ts.map +1 -0
- package/dist/types/evm/types.d.ts +98 -0
- package/dist/types/evm/types.d.ts.map +1 -0
- package/dist/types/index.d.ts +63 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/near/helpers/core.d.ts +15 -0
- package/dist/types/near/helpers/core.d.ts.map +1 -0
- package/dist/types/near/helpers/gasEstimation.d.ts +41 -0
- package/dist/types/near/helpers/gasEstimation.d.ts.map +1 -0
- package/dist/types/near/helpers/nep141.d.ts +72 -0
- package/dist/types/near/helpers/nep141.d.ts.map +1 -0
- package/dist/types/near/index.d.ts +10 -0
- package/dist/types/near/index.d.ts.map +1 -0
- package/dist/types/near/toolbox.d.ts +4 -0
- package/dist/types/near/toolbox.d.ts.map +1 -0
- package/dist/types/near/types/contract.d.ts +38 -0
- package/dist/types/near/types/contract.d.ts.map +1 -0
- package/dist/types/near/types/nep141.d.ts +56 -0
- package/dist/types/near/types/nep141.d.ts.map +1 -0
- package/dist/types/near/types/toolbox.d.ts +57 -0
- package/dist/types/near/types/toolbox.d.ts.map +1 -0
- package/dist/types/near/types.d.ts +44 -0
- package/dist/types/near/types.d.ts.map +1 -0
- package/dist/types/radix/index.d.ts +14 -0
- package/dist/types/radix/index.d.ts.map +1 -0
- package/dist/types/ripple/index.d.ts +43 -0
- package/dist/types/ripple/index.d.ts.map +1 -0
- package/dist/types/solana/index.d.ts +37 -0
- package/dist/types/solana/index.d.ts.map +1 -0
- package/dist/types/solana/toolbox.d.ts +41 -0
- package/dist/types/solana/toolbox.d.ts.map +1 -0
- package/dist/types/substrate/balance.d.ts +17 -0
- package/dist/types/substrate/balance.d.ts.map +1 -0
- package/{src/substrate/index.ts → dist/types/substrate/index.d.ts} +1 -0
- package/dist/types/substrate/index.d.ts.map +1 -0
- package/dist/types/substrate/substrate.d.ts +148 -0
- package/dist/types/substrate/substrate.d.ts.map +1 -0
- package/dist/types/substrate/types.d.ts +100 -0
- package/dist/types/substrate/types.d.ts.map +1 -0
- package/dist/types/tron/helpers/trc20.abi.d.ts +156 -0
- package/dist/types/tron/helpers/trc20.abi.d.ts.map +1 -0
- package/dist/types/tron/helpers/trongrid.d.ts +8 -0
- package/dist/types/tron/helpers/trongrid.d.ts.map +1 -0
- package/dist/types/tron/index.d.ts +6 -0
- package/dist/types/tron/index.d.ts.map +1 -0
- package/dist/types/tron/toolbox.d.ts +26 -0
- package/dist/types/tron/toolbox.d.ts.map +1 -0
- package/dist/types/tron/types.d.ts +101 -0
- package/dist/types/tron/types.d.ts.map +1 -0
- package/dist/types/types.d.ts +18 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils.d.ts +4 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/types/utxo/helpers/api.d.ts +133 -0
- package/dist/types/utxo/helpers/api.d.ts.map +1 -0
- package/dist/types/utxo/helpers/bchaddrjs.d.ts +10 -0
- package/dist/types/utxo/helpers/bchaddrjs.d.ts.map +1 -0
- package/dist/types/utxo/helpers/coinselect.d.ts +16 -0
- package/dist/types/utxo/helpers/coinselect.d.ts.map +1 -0
- package/{src/utxo/helpers/index.ts → dist/types/utxo/helpers/index.d.ts} +1 -0
- package/dist/types/utxo/helpers/index.d.ts.map +1 -0
- package/dist/types/utxo/helpers/txSize.d.ts +21 -0
- package/dist/types/utxo/helpers/txSize.d.ts.map +1 -0
- package/{src/utxo/index.ts → dist/types/utxo/index.d.ts} +1 -0
- package/dist/types/utxo/index.d.ts.map +1 -0
- package/dist/types/utxo/toolbox/bitcoinCash.d.ts +104 -0
- package/dist/types/utxo/toolbox/bitcoinCash.d.ts.map +1 -0
- package/dist/types/utxo/toolbox/index.d.ts +50 -0
- package/dist/types/utxo/toolbox/index.d.ts.map +1 -0
- package/dist/types/utxo/toolbox/utxo.d.ts +102 -0
- package/dist/types/utxo/toolbox/utxo.d.ts.map +1 -0
- package/dist/types/utxo/toolbox/zcash.d.ts +83 -0
- package/dist/types/utxo/toolbox/zcash.d.ts.map +1 -0
- package/dist/types/utxo/types.d.ts +46 -0
- package/dist/types/utxo/types.d.ts.map +1 -0
- package/package.json +15 -18
- package/dist/chunk-0h4xdrwz.js +0 -5
- package/dist/chunk-0h4xdrwz.js.map +0 -10
- package/dist/chunk-4yap1fvd.js +0 -4
- package/dist/chunk-4yap1fvd.js.map +0 -10
- package/dist/chunk-9bqegm61.js +0 -4
- package/dist/chunk-9bqegm61.js.map +0 -10
- package/dist/chunk-fazw0jvt.js +0 -4
- package/dist/chunk-fazw0jvt.js.map +0 -9
- package/dist/chunk-fjfxga2v.js +0 -4
- package/dist/chunk-fjfxga2v.js.map +0 -10
- package/dist/chunk-s47y8512.js +0 -5
- package/dist/chunk-s47y8512.js.map +0 -9
- package/dist/chunk-vtd17cje.js +0 -4
- package/dist/chunk-vtd17cje.js.map +0 -10
- package/dist/chunk-zcdeg6h9.js +0 -5
- package/dist/chunk-zcdeg6h9.js.map +0 -10
- package/src/cosmos/thorchainUtils/addressFormat.ts +0 -26
- package/src/cosmos/thorchainUtils/messages.ts +0 -262
- package/src/cosmos/thorchainUtils/registry.ts +0 -44
- package/src/cosmos/thorchainUtils/types/MsgCompiled.ts +0 -2800
- package/src/cosmos/thorchainUtils/types/client-types.ts +0 -73
- package/src/cosmos/thorchainUtils/types/index.ts +0 -1
- package/src/cosmos/toolbox/cosmos.ts +0 -375
- package/src/cosmos/toolbox/index.ts +0 -33
- package/src/cosmos/toolbox/thorchain.ts +0 -313
- package/src/cosmos/util.ts +0 -266
- package/src/evm/__tests__/address-validation.test.ts +0 -86
- package/src/evm/__tests__/ethereum.test.ts +0 -141
- package/src/evm/api.ts +0 -21
- package/src/evm/contracts/eth/multicall.ts +0 -165
- package/src/evm/contracts/op/gasOracle.ts +0 -151
- package/src/evm/helpers.ts +0 -194
- package/src/evm/toolbox/baseEVMToolbox.ts +0 -762
- package/src/evm/toolbox/evm.ts +0 -66
- package/src/evm/toolbox/index.ts +0 -52
- package/src/evm/toolbox/op.ts +0 -131
- package/src/evm/types.ts +0 -146
- package/src/index.ts +0 -263
- package/src/near/__tests__/core.test.ts +0 -80
- package/src/near/helpers/contractFactory.ts +0 -22
- package/src/near/helpers/core.ts +0 -91
- package/src/near/helpers/gasEstimation.ts +0 -110
- package/src/near/helpers/index.ts +0 -5
- package/src/near/helpers/nep141.ts +0 -110
- package/src/near/index.ts +0 -24
- package/src/near/toolbox.ts +0 -509
- package/src/near/types/contract.ts +0 -48
- package/src/near/types/nep141.ts +0 -66
- package/src/near/types.ts +0 -57
- package/src/radix/index.ts +0 -156
- package/src/ripple/index.ts +0 -192
- package/src/solana/index.ts +0 -55
- package/src/solana/toolbox.ts +0 -433
- package/src/substrate/balance.ts +0 -92
- package/src/substrate/substrate.ts +0 -320
- package/src/substrate/types.ts +0 -120
- package/src/tron/__tests__/toolbox.test.ts +0 -147
- package/src/tron/helpers/trc20.abi.ts +0 -107
- package/src/tron/helpers/trongrid.ts +0 -54
- package/src/tron/index.ts +0 -17
- package/src/tron/toolbox.ts +0 -650
- package/src/tron/types.ts +0 -120
- package/src/utils.ts +0 -27
- package/src/utxo/__tests__/zcash-integration.test.ts +0 -114
- package/src/utxo/helpers/api.ts +0 -560
- package/src/utxo/helpers/bchaddrjs.ts +0 -183
- package/src/utxo/helpers/coinselect.ts +0 -98
- package/src/utxo/helpers/txSize.ts +0 -104
- package/src/utxo/toolbox/bitcoinCash.ts +0 -320
- package/src/utxo/toolbox/index.ts +0 -90
- package/src/utxo/toolbox/utxo.ts +0 -525
- package/src/utxo/toolbox/zcash.ts +0 -208
- package/src/utxo/types.ts +0 -57
package/src/evm/toolbox/evm.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { Chain, type EVMChain, FeeOption, SKConfig } from "@swapkit/helpers";
|
|
2
|
-
import { HDNodeWallet } from "ethers";
|
|
3
|
-
import { P, match } from "ts-pattern";
|
|
4
|
-
import { getEvmApi } from "../api";
|
|
5
|
-
import { multicallAbi } from "../contracts/eth/multicall";
|
|
6
|
-
import { getIsEIP1559Compatible, getNetworkParams, getProvider } from "../helpers";
|
|
7
|
-
import type { EVMToolboxParams } from "../types";
|
|
8
|
-
import { BaseEVMToolbox } from "./baseEVMToolbox";
|
|
9
|
-
|
|
10
|
-
export async function ETHToolbox({ provider, ...signer }: EVMToolboxParams) {
|
|
11
|
-
const evmToolbox = await createEvmToolbox(Chain.Ethereum)({
|
|
12
|
-
provider,
|
|
13
|
-
...signer,
|
|
14
|
-
});
|
|
15
|
-
async function multicall(
|
|
16
|
-
callTuples: { address: string; data: string }[],
|
|
17
|
-
multicallAddress = "0x5ba1e12693dc8f9c48aad8770482f4739beed696",
|
|
18
|
-
funcName = "aggregate",
|
|
19
|
-
feeOptionKey: FeeOption = FeeOption.Fast,
|
|
20
|
-
) {
|
|
21
|
-
const txObject = await evmToolbox.createContractTxObject({
|
|
22
|
-
contractAddress: multicallAddress,
|
|
23
|
-
abi: multicallAbi,
|
|
24
|
-
funcName,
|
|
25
|
-
funcParams: [callTuples],
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
return evmToolbox.sendTransaction({ ...txObject, feeOptionKey });
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return { ...evmToolbox, multicall };
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const ARBToolbox = createEvmToolbox(Chain.Arbitrum);
|
|
35
|
-
export const AURORAToolbox = createEvmToolbox(Chain.Aurora);
|
|
36
|
-
export const AVAXToolbox = createEvmToolbox(Chain.Avalanche);
|
|
37
|
-
export const BASEToolbox = createEvmToolbox(Chain.Base);
|
|
38
|
-
export const BERAToolbox = createEvmToolbox(Chain.Berachain);
|
|
39
|
-
export const BSCToolbox = createEvmToolbox(Chain.BinanceSmartChain);
|
|
40
|
-
export const GNOToolbox = createEvmToolbox(Chain.Gnosis);
|
|
41
|
-
export const MATICToolbox = createEvmToolbox(Chain.Polygon);
|
|
42
|
-
|
|
43
|
-
function createEvmToolbox<C extends EVMChain>(chain: C) {
|
|
44
|
-
return async function createEvmToolbox({
|
|
45
|
-
provider: providerParam,
|
|
46
|
-
...toolboxSignerParams
|
|
47
|
-
}: EVMToolboxParams) {
|
|
48
|
-
const rpcUrl = SKConfig.get("rpcUrls")[chain];
|
|
49
|
-
|
|
50
|
-
const provider = providerParam || (await getProvider(chain, rpcUrl));
|
|
51
|
-
|
|
52
|
-
const isEIP1559Compatible = getIsEIP1559Compatible(chain);
|
|
53
|
-
const signer = match(toolboxSignerParams)
|
|
54
|
-
.with({ phrase: P.string }, ({ phrase }) => HDNodeWallet.fromPhrase(phrase).connect(provider))
|
|
55
|
-
.with({ signer: P.any }, ({ signer }) => signer)
|
|
56
|
-
.otherwise(() => undefined);
|
|
57
|
-
|
|
58
|
-
const evmToolbox = BaseEVMToolbox({ provider, signer, isEIP1559Compatible, chain });
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
...evmToolbox,
|
|
62
|
-
getNetworkParams: getNetworkParams(chain),
|
|
63
|
-
getBalance: getEvmApi(chain).getBalance,
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
}
|
package/src/evm/toolbox/index.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { Chain, type EVMChain, SwapKitError } from "@swapkit/helpers";
|
|
2
|
-
|
|
3
|
-
import { getProvider } from "../helpers";
|
|
4
|
-
import type { EVMToolboxParams } from "../types";
|
|
5
|
-
import {
|
|
6
|
-
ARBToolbox,
|
|
7
|
-
AURORAToolbox,
|
|
8
|
-
AVAXToolbox,
|
|
9
|
-
BASEToolbox,
|
|
10
|
-
BERAToolbox,
|
|
11
|
-
BSCToolbox,
|
|
12
|
-
ETHToolbox,
|
|
13
|
-
GNOToolbox,
|
|
14
|
-
MATICToolbox,
|
|
15
|
-
} from "./evm";
|
|
16
|
-
import { OPToolbox } from "./op";
|
|
17
|
-
|
|
18
|
-
export async function getEvmToolbox<T extends EVMChain>(chain: T, params?: EVMToolboxParams) {
|
|
19
|
-
const toolboxParams = {
|
|
20
|
-
...params,
|
|
21
|
-
provider: params?.provider || (await getProvider(chain)),
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
switch (chain) {
|
|
25
|
-
case Chain.Arbitrum:
|
|
26
|
-
return ARBToolbox(toolboxParams);
|
|
27
|
-
case Chain.Aurora:
|
|
28
|
-
return AURORAToolbox(toolboxParams);
|
|
29
|
-
case Chain.Avalanche:
|
|
30
|
-
return AVAXToolbox(toolboxParams);
|
|
31
|
-
case Chain.Base:
|
|
32
|
-
return BASEToolbox(toolboxParams);
|
|
33
|
-
case Chain.Berachain:
|
|
34
|
-
return BERAToolbox(toolboxParams);
|
|
35
|
-
case Chain.BinanceSmartChain:
|
|
36
|
-
return BSCToolbox(toolboxParams);
|
|
37
|
-
case Chain.Gnosis:
|
|
38
|
-
return GNOToolbox(toolboxParams);
|
|
39
|
-
case Chain.Optimism:
|
|
40
|
-
return OPToolbox(toolboxParams);
|
|
41
|
-
case Chain.Polygon:
|
|
42
|
-
return MATICToolbox(toolboxParams);
|
|
43
|
-
case Chain.Ethereum:
|
|
44
|
-
return ETHToolbox(toolboxParams);
|
|
45
|
-
default:
|
|
46
|
-
throw new SwapKitError("toolbox_evm_not_supported", { chain });
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export * from "./baseEVMToolbox";
|
|
51
|
-
export * from "./evm";
|
|
52
|
-
export * from "./op";
|
package/src/evm/toolbox/op.ts
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BaseDecimal,
|
|
3
|
-
Chain,
|
|
4
|
-
ChainId,
|
|
5
|
-
ChainToExplorerUrl,
|
|
6
|
-
SKConfig,
|
|
7
|
-
SwapKitError,
|
|
8
|
-
} from "@swapkit/helpers";
|
|
9
|
-
import type {
|
|
10
|
-
Authorization,
|
|
11
|
-
BrowserProvider,
|
|
12
|
-
JsonRpcProvider,
|
|
13
|
-
Provider,
|
|
14
|
-
TransactionRequest,
|
|
15
|
-
} from "ethers";
|
|
16
|
-
import { Contract, HDNodeWallet } from "ethers";
|
|
17
|
-
|
|
18
|
-
import { P } from "ts-pattern";
|
|
19
|
-
import { match } from "ts-pattern";
|
|
20
|
-
import { getEvmApi } from "../api";
|
|
21
|
-
import { gasOracleAbi } from "../contracts/op/gasOracle";
|
|
22
|
-
import { getProvider } from "../helpers";
|
|
23
|
-
import type { EVMToolboxParams } from "../types";
|
|
24
|
-
import { BaseEVMToolbox } from "./baseEVMToolbox";
|
|
25
|
-
|
|
26
|
-
const GAS_PRICE_ORACLE_ADDRESS = "0x420000000000000000000000000000000000000f";
|
|
27
|
-
|
|
28
|
-
function connectGasPriceOracle<P extends Provider>(provider: P) {
|
|
29
|
-
return new Contract(GAS_PRICE_ORACLE_ADDRESS, gasOracleAbi, provider);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function getL1GasPriceFetcher<P extends Provider>(provider: P) {
|
|
33
|
-
return function getL1GasPrice() {
|
|
34
|
-
const gasPriceOracle = connectGasPriceOracle(provider);
|
|
35
|
-
|
|
36
|
-
if (gasPriceOracle && "l1BaseFee" in gasPriceOracle) {
|
|
37
|
-
return gasPriceOracle?.l1BaseFee() as unknown as bigint;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return undefined;
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function serializeTx<P extends JsonRpcProvider | BrowserProvider>(provider: P) {
|
|
45
|
-
return async function serializeTx({ from, to, nonce, ...tx }: TransactionRequest) {
|
|
46
|
-
const { Transaction } = await import("ethers");
|
|
47
|
-
|
|
48
|
-
if (!to)
|
|
49
|
-
throw new SwapKitError("toolbox_evm_invalid_transaction", { error: "Missing to address" });
|
|
50
|
-
|
|
51
|
-
return Transaction.from({
|
|
52
|
-
...tx,
|
|
53
|
-
authorizationList: tx.authorizationList as Authorization[],
|
|
54
|
-
to: to as string,
|
|
55
|
-
nonce: nonce ? nonce : from ? await provider.getTransactionCount(from) : 0,
|
|
56
|
-
}).serialized;
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function estimateL1GasCost<P extends JsonRpcProvider | BrowserProvider>(provider: P) {
|
|
61
|
-
return async function estimateL1GasCost(tx: TransactionRequest) {
|
|
62
|
-
const gasPriceOracle = connectGasPriceOracle(provider);
|
|
63
|
-
const serializedTx = await serializeTx(provider)(tx);
|
|
64
|
-
|
|
65
|
-
if (gasPriceOracle && "getL1Fee" in gasPriceOracle) {
|
|
66
|
-
return gasPriceOracle.getL1Fee(serializedTx);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function estimateL2GasCost<P extends JsonRpcProvider | BrowserProvider>(provider: P) {
|
|
72
|
-
return async function estimateL2GasCost(tx: TransactionRequest) {
|
|
73
|
-
const l2GasPrice = await provider.send("eth_gasPrice", []);
|
|
74
|
-
const l2GasCost = await provider.estimateGas(tx);
|
|
75
|
-
return l2GasPrice.mul(l2GasCost);
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function estimateTotalGasCost<P extends JsonRpcProvider | BrowserProvider>(provider: P) {
|
|
80
|
-
return async function estimateTotalGasCost(tx: TransactionRequest) {
|
|
81
|
-
const l1GasCost = await estimateL1GasCost(provider)(tx);
|
|
82
|
-
const l2GasCost = await estimateL2GasCost(provider)(tx);
|
|
83
|
-
return l1GasCost.add(l2GasCost);
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function estimateL1Gas<P extends JsonRpcProvider | BrowserProvider>(provider: P) {
|
|
88
|
-
return async function estimateL1Gas(tx: TransactionRequest) {
|
|
89
|
-
const gasPriceOracle = connectGasPriceOracle(provider);
|
|
90
|
-
const serializedTx = await serializeTx(provider)(tx);
|
|
91
|
-
|
|
92
|
-
if (gasPriceOracle && "getL1GasUsed" in gasPriceOracle) {
|
|
93
|
-
return gasPriceOracle.getL1GasUsed(serializedTx);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const getNetworkParams = () => ({
|
|
99
|
-
chainId: ChainId.OptimismHex,
|
|
100
|
-
chainName: "Optimism",
|
|
101
|
-
nativeCurrency: { name: "Ethereum", symbol: Chain.Ethereum, decimals: BaseDecimal.ETH },
|
|
102
|
-
rpcUrls: [SKConfig.get("rpcUrls")[Chain.Optimism]],
|
|
103
|
-
blockExplorerUrls: [ChainToExplorerUrl[Chain.Optimism]],
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
export async function OPToolbox({
|
|
107
|
-
provider: providerParam,
|
|
108
|
-
...toolboxSignerParams
|
|
109
|
-
}: EVMToolboxParams) {
|
|
110
|
-
const chain = Chain.Optimism;
|
|
111
|
-
const rpcUrl = SKConfig.get("rpcUrls")[chain];
|
|
112
|
-
const provider = providerParam || (await getProvider(chain, rpcUrl));
|
|
113
|
-
const signer = match(toolboxSignerParams)
|
|
114
|
-
.with({ phrase: P.string }, ({ phrase }) => HDNodeWallet.fromPhrase(phrase).connect(provider))
|
|
115
|
-
.with({ signer: P.any }, ({ signer }) => signer)
|
|
116
|
-
.otherwise(() => undefined);
|
|
117
|
-
|
|
118
|
-
const evmToolbox = BaseEVMToolbox({ provider, signer });
|
|
119
|
-
const getL1GasPrice = getL1GasPriceFetcher(provider);
|
|
120
|
-
|
|
121
|
-
return {
|
|
122
|
-
...evmToolbox,
|
|
123
|
-
estimateL1Gas: estimateL1Gas(provider),
|
|
124
|
-
estimateL1GasCost: estimateL1GasCost(provider),
|
|
125
|
-
estimateL2GasCost: estimateL2GasCost(provider),
|
|
126
|
-
estimateTotalGasCost: estimateTotalGasCost(provider),
|
|
127
|
-
getBalance: getEvmApi(Chain.Optimism).getBalance,
|
|
128
|
-
getL1GasPrice,
|
|
129
|
-
getNetworkParams,
|
|
130
|
-
};
|
|
131
|
-
}
|
package/src/evm/types.ts
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AssetValue,
|
|
3
|
-
ChainSigner,
|
|
4
|
-
DerivationPathArray,
|
|
5
|
-
FeeOption,
|
|
6
|
-
GenericCreateTransactionParams,
|
|
7
|
-
GenericTransferParams,
|
|
8
|
-
} from "@swapkit/helpers";
|
|
9
|
-
import { Chain } from "@swapkit/helpers";
|
|
10
|
-
import type {
|
|
11
|
-
BigNumberish,
|
|
12
|
-
BrowserProvider,
|
|
13
|
-
JsonFragment,
|
|
14
|
-
JsonRpcProvider,
|
|
15
|
-
JsonRpcSigner,
|
|
16
|
-
Signer,
|
|
17
|
-
Transaction,
|
|
18
|
-
} from "ethers";
|
|
19
|
-
import type {
|
|
20
|
-
ARBToolbox,
|
|
21
|
-
AURORAToolbox,
|
|
22
|
-
AVAXToolbox,
|
|
23
|
-
BASEToolbox,
|
|
24
|
-
BERAToolbox,
|
|
25
|
-
BSCToolbox,
|
|
26
|
-
ETHToolbox,
|
|
27
|
-
GNOToolbox,
|
|
28
|
-
MATICToolbox,
|
|
29
|
-
OPToolbox,
|
|
30
|
-
} from "./toolbox";
|
|
31
|
-
|
|
32
|
-
import type { getProvider } from "./index";
|
|
33
|
-
|
|
34
|
-
export enum EthNetwork {
|
|
35
|
-
Test = "goerli",
|
|
36
|
-
Main = "homestead",
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export type ApproveParams = {
|
|
40
|
-
assetAddress: string;
|
|
41
|
-
spenderAddress: string;
|
|
42
|
-
feeOptionKey?: FeeOption;
|
|
43
|
-
amount?: BigNumberish;
|
|
44
|
-
from?: string;
|
|
45
|
-
// Optional fallback in case estimation for gas limit fails
|
|
46
|
-
gasLimitFallback?: BigNumberish;
|
|
47
|
-
nonce?: number;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export type ApprovedParams = {
|
|
51
|
-
assetAddress: string;
|
|
52
|
-
spenderAddress: string;
|
|
53
|
-
from: string;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export type IsApprovedParams = ApprovedParams & {
|
|
57
|
-
amount?: BigNumberish;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export type CallParams = {
|
|
61
|
-
callProvider?: Awaited<ReturnType<typeof getProvider>>;
|
|
62
|
-
contractAddress: string;
|
|
63
|
-
abi: readonly JsonFragment[];
|
|
64
|
-
funcName: string;
|
|
65
|
-
funcParams?: unknown[];
|
|
66
|
-
txOverrides?: Partial<Transaction>;
|
|
67
|
-
feeOption?: FeeOption;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export type EstimateCallParams = Pick<
|
|
71
|
-
CallParams,
|
|
72
|
-
"contractAddress" | "abi" | "funcName" | "funcParams" | "txOverrides"
|
|
73
|
-
>;
|
|
74
|
-
|
|
75
|
-
export type EVMTransferParams = GenericTransferParams & {
|
|
76
|
-
sender?: string;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export type EVMCreateTransactionParams = Omit<GenericCreateTransactionParams, "feeRate"> & {
|
|
80
|
-
gasLimit?: bigint;
|
|
81
|
-
gasPrice?: bigint;
|
|
82
|
-
maxFeePerGas?: bigint;
|
|
83
|
-
maxPriorityFeePerGas?: bigint;
|
|
84
|
-
data?: string;
|
|
85
|
-
nonce?: number;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
export type EVMMaxSendableAmountsParams = {
|
|
89
|
-
from: string;
|
|
90
|
-
assetValue: AssetValue;
|
|
91
|
-
feeOptionKey?: FeeOption;
|
|
92
|
-
memo?: string;
|
|
93
|
-
abi?: readonly JsonFragment[];
|
|
94
|
-
funcName?: string;
|
|
95
|
-
contractAddress?: string;
|
|
96
|
-
funcParams?: unknown[];
|
|
97
|
-
txOverrides?: Partial<Transaction>;
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
export type EVMTxBaseParams<T = bigint> = {
|
|
101
|
-
to?: string;
|
|
102
|
-
from?: string;
|
|
103
|
-
nonce?: number;
|
|
104
|
-
gasLimit?: T;
|
|
105
|
-
data?: string;
|
|
106
|
-
value?: T;
|
|
107
|
-
chainId?: T;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
export type EIP1559TxParams<T = bigint> = EVMTxBaseParams<T> & {
|
|
111
|
-
type?: number;
|
|
112
|
-
maxFeePerGas?: T;
|
|
113
|
-
maxPriorityFeePerGas?: T;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
export type LegacyEVMTxParams<T = bigint> = EVMTxBaseParams<T> & {
|
|
117
|
-
gasPrice?: T;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
export type EVMTxParams = EIP1559TxParams | LegacyEVMTxParams;
|
|
121
|
-
|
|
122
|
-
export type EVMToolboxParams = {
|
|
123
|
-
provider?: BrowserProvider | JsonRpcProvider;
|
|
124
|
-
} & (
|
|
125
|
-
| {
|
|
126
|
-
signer?: (ChainSigner<EVMTransferParams, string> & Signer) | JsonRpcSigner;
|
|
127
|
-
}
|
|
128
|
-
| {
|
|
129
|
-
phrase?: string;
|
|
130
|
-
derivationPath?: DerivationPathArray;
|
|
131
|
-
index?: number;
|
|
132
|
-
}
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
export type EVMToolboxes = {
|
|
136
|
-
[Chain.Arbitrum]: Awaited<ReturnType<typeof ARBToolbox>>;
|
|
137
|
-
[Chain.Aurora]: Awaited<ReturnType<typeof AURORAToolbox>>;
|
|
138
|
-
[Chain.Avalanche]: Awaited<ReturnType<typeof AVAXToolbox>>;
|
|
139
|
-
[Chain.Base]: Awaited<ReturnType<typeof BASEToolbox>>;
|
|
140
|
-
[Chain.Berachain]: Awaited<ReturnType<typeof BERAToolbox>>;
|
|
141
|
-
[Chain.BinanceSmartChain]: Awaited<ReturnType<typeof BSCToolbox>>;
|
|
142
|
-
[Chain.Ethereum]: Awaited<ReturnType<typeof ETHToolbox>>;
|
|
143
|
-
[Chain.Gnosis]: Awaited<ReturnType<typeof GNOToolbox>>;
|
|
144
|
-
[Chain.Optimism]: Awaited<ReturnType<typeof OPToolbox>>;
|
|
145
|
-
[Chain.Polygon]: Awaited<ReturnType<typeof MATICToolbox>>;
|
|
146
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AssetValue,
|
|
3
|
-
Chain,
|
|
4
|
-
type CosmosChain,
|
|
5
|
-
type EVMChain,
|
|
6
|
-
FeeOption,
|
|
7
|
-
type GenericCreateTransactionParams,
|
|
8
|
-
type SubstrateChain,
|
|
9
|
-
SwapKitError,
|
|
10
|
-
type UTXOChain,
|
|
11
|
-
} from "@swapkit/helpers";
|
|
12
|
-
import type { getCosmosToolbox } from "@swapkit/toolboxes/cosmos";
|
|
13
|
-
|
|
14
|
-
import type { ETHToolbox, EVMCreateTransactionParams, getEvmToolbox } from "@swapkit/toolboxes/evm";
|
|
15
|
-
import type { getNearToolbox } from "@swapkit/toolboxes/near";
|
|
16
|
-
import type { RadixToolbox } from "@swapkit/toolboxes/radix";
|
|
17
|
-
import type { getRippleToolbox } from "@swapkit/toolboxes/ripple";
|
|
18
|
-
import type { SolanaCreateTransactionParams, getSolanaToolbox } from "@swapkit/toolboxes/solana";
|
|
19
|
-
import type { getSubstrateToolbox } from "@swapkit/toolboxes/substrate";
|
|
20
|
-
import type { createTronToolbox } from "@swapkit/toolboxes/tron";
|
|
21
|
-
import type { getUtxoToolbox } from "@swapkit/toolboxes/utxo";
|
|
22
|
-
|
|
23
|
-
export async function getAddressValidator() {
|
|
24
|
-
const { match } = await import("ts-pattern");
|
|
25
|
-
const { cosmosValidateAddress } = await import("@swapkit/toolboxes/cosmos");
|
|
26
|
-
const { evmValidateAddress } = await import("@swapkit/toolboxes/evm");
|
|
27
|
-
const { substrateValidateAddress } = await import("@swapkit/toolboxes/substrate");
|
|
28
|
-
const { getUTXOAddressValidator } = await import("@swapkit/toolboxes/utxo");
|
|
29
|
-
const { getSolanaAddressValidator } = await import("@swapkit/toolboxes/solana");
|
|
30
|
-
const { getValidateNearAddress } = await import("@swapkit/toolboxes/near");
|
|
31
|
-
const { rippleValidateAddress } = await import("@swapkit/toolboxes/ripple");
|
|
32
|
-
const { radixValidateAddress } = await import("@swapkit/toolboxes/radix");
|
|
33
|
-
const { getTronAddressValidator } = await import("@swapkit/toolboxes/tron");
|
|
34
|
-
|
|
35
|
-
const solanaValidateAddress = await getSolanaAddressValidator();
|
|
36
|
-
const utxoValidateAddress = await getUTXOAddressValidator();
|
|
37
|
-
const tronValidateAddress = await getTronAddressValidator();
|
|
38
|
-
const nearValidateAddress = await getValidateNearAddress();
|
|
39
|
-
|
|
40
|
-
return function validateAddress({ address, chain }: { address: string; chain: Chain }) {
|
|
41
|
-
const isValid = match(chain)
|
|
42
|
-
.with(
|
|
43
|
-
Chain.Arbitrum,
|
|
44
|
-
Chain.Aurora,
|
|
45
|
-
Chain.Avalanche,
|
|
46
|
-
Chain.Base,
|
|
47
|
-
Chain.Berachain,
|
|
48
|
-
Chain.BinanceSmartChain,
|
|
49
|
-
Chain.Ethereum,
|
|
50
|
-
Chain.Gnosis,
|
|
51
|
-
Chain.Optimism,
|
|
52
|
-
Chain.Polygon,
|
|
53
|
-
() => evmValidateAddress({ address }),
|
|
54
|
-
)
|
|
55
|
-
.with(Chain.Litecoin, Chain.Dash, Chain.Dogecoin, Chain.BitcoinCash, Chain.Bitcoin, () =>
|
|
56
|
-
utxoValidateAddress({ address, chain: chain as UTXOChain }),
|
|
57
|
-
)
|
|
58
|
-
.with(Chain.Cosmos, Chain.Kujira, Chain.Maya, Chain.THORChain, () =>
|
|
59
|
-
cosmosValidateAddress({ address, chain: chain as CosmosChain }),
|
|
60
|
-
)
|
|
61
|
-
.with(Chain.Chainflip, Chain.Polkadot, () =>
|
|
62
|
-
substrateValidateAddress({ address, chain: chain as SubstrateChain }),
|
|
63
|
-
)
|
|
64
|
-
.with(Chain.Radix, () => radixValidateAddress(address))
|
|
65
|
-
.with(Chain.Near, () => nearValidateAddress(address))
|
|
66
|
-
.with(Chain.Ripple, () => rippleValidateAddress(address))
|
|
67
|
-
.with(Chain.Solana, () => solanaValidateAddress(address))
|
|
68
|
-
.with(Chain.Tron, () => tronValidateAddress(address))
|
|
69
|
-
.otherwise(() => false);
|
|
70
|
-
|
|
71
|
-
return isValid;
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function getFeeEstimator<T extends keyof CreateTransactionParams>(chain: T) {
|
|
76
|
-
return async function estimateFee(params: CreateTransactionParams[T]) {
|
|
77
|
-
const { match } = await import("ts-pattern");
|
|
78
|
-
|
|
79
|
-
return match(chain as Chain)
|
|
80
|
-
.returnType<Promise<AssetValue>>()
|
|
81
|
-
.with(
|
|
82
|
-
Chain.Arbitrum,
|
|
83
|
-
Chain.Aurora,
|
|
84
|
-
Chain.Avalanche,
|
|
85
|
-
Chain.Base,
|
|
86
|
-
Chain.Berachain,
|
|
87
|
-
Chain.BinanceSmartChain,
|
|
88
|
-
Chain.Ethereum,
|
|
89
|
-
Chain.Gnosis,
|
|
90
|
-
Chain.Optimism,
|
|
91
|
-
Chain.Polygon,
|
|
92
|
-
async (chain) => {
|
|
93
|
-
const toolbox = await getToolbox(chain);
|
|
94
|
-
const txObject = await toolbox.createTransaction(params);
|
|
95
|
-
|
|
96
|
-
return (toolbox as Awaited<ReturnType<typeof ETHToolbox>>).estimateTransactionFee({
|
|
97
|
-
...txObject,
|
|
98
|
-
feeOption: params.feeOptionKey || FeeOption.Fast,
|
|
99
|
-
chain,
|
|
100
|
-
});
|
|
101
|
-
},
|
|
102
|
-
)
|
|
103
|
-
.with(
|
|
104
|
-
Chain.Bitcoin,
|
|
105
|
-
Chain.BitcoinCash,
|
|
106
|
-
Chain.Dogecoin,
|
|
107
|
-
Chain.Dash,
|
|
108
|
-
Chain.Litecoin,
|
|
109
|
-
Chain.Polkadot,
|
|
110
|
-
Chain.Solana,
|
|
111
|
-
Chain.Ripple,
|
|
112
|
-
Chain.Tron,
|
|
113
|
-
Chain.Near,
|
|
114
|
-
async (chain) => {
|
|
115
|
-
const toolbox = await getToolbox(chain);
|
|
116
|
-
return toolbox.estimateTransactionFee(params) as Promise<AssetValue>;
|
|
117
|
-
},
|
|
118
|
-
)
|
|
119
|
-
.with(Chain.THORChain, Chain.Maya, Chain.Kujira, Chain.Cosmos, async () => {
|
|
120
|
-
const { estimateTransactionFee } = await import("@swapkit/toolboxes/cosmos");
|
|
121
|
-
return estimateTransactionFee(params);
|
|
122
|
-
})
|
|
123
|
-
.otherwise(async () => AssetValue.from({ chain }));
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
type Toolboxes = {
|
|
128
|
-
[key in EVMChain]: Awaited<ReturnType<typeof getEvmToolbox>>;
|
|
129
|
-
} & {
|
|
130
|
-
[key in UTXOChain]: Awaited<ReturnType<typeof getUtxoToolbox>>;
|
|
131
|
-
} & {
|
|
132
|
-
[key in CosmosChain]: Awaited<ReturnType<typeof getCosmosToolbox>>;
|
|
133
|
-
} & {
|
|
134
|
-
[key in SubstrateChain]: Awaited<ReturnType<typeof getSubstrateToolbox>>;
|
|
135
|
-
} & {
|
|
136
|
-
[Chain.Radix]: Awaited<ReturnType<typeof RadixToolbox>>;
|
|
137
|
-
[Chain.Near]: Awaited<ReturnType<typeof getNearToolbox>>;
|
|
138
|
-
[Chain.Ripple]: Awaited<ReturnType<typeof getRippleToolbox>>;
|
|
139
|
-
[Chain.Solana]: Awaited<ReturnType<typeof getSolanaToolbox>>;
|
|
140
|
-
[Chain.Tron]: Awaited<ReturnType<typeof createTronToolbox>>;
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
type ToolboxParams = { [key in EVMChain]: Parameters<typeof getEvmToolbox>[1] } & {
|
|
144
|
-
[key in UTXOChain]: undefined;
|
|
145
|
-
} & {
|
|
146
|
-
[key in CosmosChain]: Parameters<typeof getCosmosToolbox>[1];
|
|
147
|
-
} & {
|
|
148
|
-
[key in SubstrateChain]: Parameters<typeof getSubstrateToolbox>[1];
|
|
149
|
-
} & {
|
|
150
|
-
[Chain.Radix]: Parameters<typeof RadixToolbox>[0];
|
|
151
|
-
[Chain.Near]: Parameters<typeof getNearToolbox>[0];
|
|
152
|
-
[Chain.Ripple]: Parameters<typeof getRippleToolbox>[0];
|
|
153
|
-
[Chain.Solana]: Parameters<typeof getSolanaToolbox>[0];
|
|
154
|
-
[Chain.Tron]: Parameters<typeof createTronToolbox>[0];
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
type CreateTransactionParams = { [key in EVMChain]: EVMCreateTransactionParams } & {
|
|
158
|
-
[key in UTXOChain]: GenericCreateTransactionParams;
|
|
159
|
-
} & {
|
|
160
|
-
[key in CosmosChain]: GenericCreateTransactionParams;
|
|
161
|
-
} & {
|
|
162
|
-
[key in SubstrateChain]: GenericCreateTransactionParams;
|
|
163
|
-
} & {
|
|
164
|
-
[Chain.Radix]: GenericCreateTransactionParams;
|
|
165
|
-
[Chain.Ripple]: GenericCreateTransactionParams;
|
|
166
|
-
[Chain.Near]: GenericCreateTransactionParams;
|
|
167
|
-
[Chain.Solana]: SolanaCreateTransactionParams;
|
|
168
|
-
[Chain.Tron]: GenericCreateTransactionParams;
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
export async function getToolbox<T extends keyof Toolboxes>(
|
|
172
|
-
chain: T,
|
|
173
|
-
params?: ToolboxParams[T],
|
|
174
|
-
): Promise<Toolboxes[T]> {
|
|
175
|
-
const { match } = await import("ts-pattern");
|
|
176
|
-
|
|
177
|
-
return match(chain as Chain)
|
|
178
|
-
.returnType<Promise<Toolboxes[T]>>()
|
|
179
|
-
.with(
|
|
180
|
-
Chain.Arbitrum,
|
|
181
|
-
Chain.Aurora,
|
|
182
|
-
Chain.Avalanche,
|
|
183
|
-
Chain.Base,
|
|
184
|
-
Chain.Berachain,
|
|
185
|
-
Chain.BinanceSmartChain,
|
|
186
|
-
Chain.Ethereum,
|
|
187
|
-
Chain.Gnosis,
|
|
188
|
-
Chain.Optimism,
|
|
189
|
-
Chain.Polygon,
|
|
190
|
-
async () => {
|
|
191
|
-
const { getEvmToolbox } = await import("@swapkit/toolboxes/evm");
|
|
192
|
-
const evmToolbox = await getEvmToolbox(
|
|
193
|
-
chain as EVMChain,
|
|
194
|
-
params as Parameters<typeof getEvmToolbox>[1],
|
|
195
|
-
);
|
|
196
|
-
return evmToolbox as Toolboxes[T];
|
|
197
|
-
},
|
|
198
|
-
)
|
|
199
|
-
.with(
|
|
200
|
-
Chain.Litecoin,
|
|
201
|
-
Chain.Dash,
|
|
202
|
-
Chain.Dogecoin,
|
|
203
|
-
Chain.BitcoinCash,
|
|
204
|
-
Chain.Bitcoin,
|
|
205
|
-
Chain.Zcash,
|
|
206
|
-
async () => {
|
|
207
|
-
const { getUtxoToolbox } = await import("@swapkit/toolboxes/utxo");
|
|
208
|
-
const utxoToolbox = await getUtxoToolbox(
|
|
209
|
-
chain as UTXOChain,
|
|
210
|
-
params as Parameters<typeof getUtxoToolbox>[1],
|
|
211
|
-
);
|
|
212
|
-
return utxoToolbox as Toolboxes[T];
|
|
213
|
-
},
|
|
214
|
-
)
|
|
215
|
-
.with(Chain.Cosmos, Chain.Kujira, Chain.Maya, Chain.THORChain, async () => {
|
|
216
|
-
const { getCosmosToolbox } = await import("@swapkit/toolboxes/cosmos");
|
|
217
|
-
const cosmosToolbox = await getCosmosToolbox(
|
|
218
|
-
chain as CosmosChain,
|
|
219
|
-
params as Parameters<typeof getCosmosToolbox>[1],
|
|
220
|
-
);
|
|
221
|
-
return cosmosToolbox as Toolboxes[T];
|
|
222
|
-
})
|
|
223
|
-
.with(Chain.Chainflip, Chain.Polkadot, async () => {
|
|
224
|
-
const { getSubstrateToolbox } = await import("@swapkit/toolboxes/substrate");
|
|
225
|
-
const substrateToolbox = await getSubstrateToolbox(
|
|
226
|
-
chain as SubstrateChain,
|
|
227
|
-
params as Parameters<typeof getSubstrateToolbox>[1],
|
|
228
|
-
);
|
|
229
|
-
return substrateToolbox as Toolboxes[T];
|
|
230
|
-
})
|
|
231
|
-
.with(Chain.Radix, async () => {
|
|
232
|
-
const { RadixToolbox } = await import("@swapkit/toolboxes/radix");
|
|
233
|
-
const radixToolbox = await RadixToolbox(params as Parameters<typeof RadixToolbox>[0]);
|
|
234
|
-
return radixToolbox as Toolboxes[T];
|
|
235
|
-
})
|
|
236
|
-
.with(Chain.Ripple, async () => {
|
|
237
|
-
const { getRippleToolbox } = await import("@swapkit/toolboxes/ripple");
|
|
238
|
-
const rippleToolbox = await getRippleToolbox(
|
|
239
|
-
params as Parameters<typeof getRippleToolbox>[0],
|
|
240
|
-
);
|
|
241
|
-
return rippleToolbox as Toolboxes[T];
|
|
242
|
-
})
|
|
243
|
-
.with(Chain.Solana, async () => {
|
|
244
|
-
const { getSolanaToolbox } = await import("@swapkit/toolboxes/solana");
|
|
245
|
-
const solanaToolbox = await getSolanaToolbox(
|
|
246
|
-
params as Parameters<typeof getSolanaToolbox>[0],
|
|
247
|
-
);
|
|
248
|
-
return solanaToolbox as Toolboxes[T];
|
|
249
|
-
})
|
|
250
|
-
.with(Chain.Tron, async () => {
|
|
251
|
-
const { createTronToolbox } = await import("@swapkit/toolboxes/tron");
|
|
252
|
-
const tronToolbox = await createTronToolbox(params);
|
|
253
|
-
return tronToolbox as Toolboxes[T];
|
|
254
|
-
})
|
|
255
|
-
.with(Chain.Near, async () => {
|
|
256
|
-
const { getNearToolbox } = await import("@swapkit/toolboxes/near");
|
|
257
|
-
const nearToolbox = await getNearToolbox(params as Parameters<typeof getNearToolbox>[0]);
|
|
258
|
-
return nearToolbox as Toolboxes[T];
|
|
259
|
-
})
|
|
260
|
-
.otherwise(() => {
|
|
261
|
-
throw new SwapKitError("toolbox_not_supported", { chain });
|
|
262
|
-
});
|
|
263
|
-
}
|