@swapkit/toolboxes 1.0.0-beta.0 → 1.0.0-beta.2
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/chunk-0f0249b1.js +3 -0
- package/dist/chunk-0f0249b1.js.map +10 -0
- package/dist/chunk-0h4xdrwz.js +4 -0
- package/dist/chunk-0h4xdrwz.js.map +10 -0
- package/dist/chunk-4yap1fvd.js +3 -0
- package/dist/chunk-4yap1fvd.js.map +10 -0
- package/dist/chunk-fjfxga2v.js +3 -0
- package/dist/chunk-fjfxga2v.js.map +10 -0
- package/dist/{chunk-tvrdndbw.js → chunk-p1kdg37m.js} +2 -2
- package/dist/{chunk-tvrdndbw.js.map → chunk-p1kdg37m.js.map} +1 -1
- package/dist/cosmos/index.cjs +2 -2
- package/dist/cosmos/index.cjs.map +10 -13
- package/dist/cosmos/index.js +2 -2
- package/dist/cosmos/index.js.map +10 -13
- package/dist/evm/index.cjs +2 -2
- package/dist/evm/index.cjs.map +10 -16
- package/dist/evm/index.js +2 -2
- package/dist/evm/index.js.map +10 -16
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +4 -3
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -3
- package/dist/radix/index.cjs +2 -2
- package/dist/radix/index.cjs.map +3 -3
- package/dist/radix/index.js +2 -2
- package/dist/radix/index.js.map +3 -3
- package/dist/ripple/index.cjs +3 -0
- package/dist/ripple/index.cjs.map +10 -0
- package/dist/ripple/index.js +3 -0
- package/dist/ripple/index.js.map +10 -0
- package/dist/solana/index.cjs +2 -2
- package/dist/solana/index.cjs.map +3 -3
- package/dist/solana/index.js +2 -2
- package/dist/solana/index.js.map +3 -3
- package/dist/substrate/index.cjs +2 -2
- package/dist/substrate/index.cjs.map +5 -6
- package/dist/substrate/index.js +2 -2
- package/dist/substrate/index.js.map +5 -6
- package/dist/utxo/index.cjs +2 -2
- package/dist/utxo/index.cjs.map +9 -11
- package/dist/utxo/index.js +2 -2
- package/dist/utxo/index.js.map +9 -11
- package/package.json +30 -24
- package/src/cosmos/index.ts +2 -9
- package/src/cosmos/thorchainUtils/addressFormat.ts +1 -2
- package/src/cosmos/thorchainUtils/index.ts +1 -1
- package/src/cosmos/thorchainUtils/messages.ts +74 -56
- package/src/cosmos/thorchainUtils/registry.ts +16 -23
- package/src/cosmos/thorchainUtils/types/{proto/MsgCompiled.ts → MsgCompiled.ts} +1 -3
- package/src/cosmos/thorchainUtils/types/client-types.ts +16 -23
- package/src/cosmos/toolbox/cosmos.ts +334 -0
- package/src/cosmos/toolbox/index.ts +33 -0
- package/src/cosmos/toolbox/thorchain.ts +118 -131
- package/src/cosmos/types.ts +37 -18
- package/src/cosmos/util.ts +21 -71
- package/src/evm/__tests__/ethereum.test.ts +110 -116
- package/src/evm/api.ts +11 -147
- package/src/evm/helpers.ts +111 -83
- package/src/evm/index.ts +1 -17
- package/src/evm/toolbox/baseEVMToolbox.ts +742 -0
- package/src/evm/toolbox/evm.ts +69 -0
- package/src/evm/toolbox/index.ts +36 -0
- package/src/evm/toolbox/op.ts +97 -143
- package/src/evm/types.ts +50 -28
- package/src/index.ts +235 -0
- package/src/radix/index.ts +18 -19
- package/src/ripple/index.ts +203 -0
- package/src/solana/index.ts +11 -5
- package/src/solana/toolbox.ts +223 -133
- package/src/substrate/index.ts +2 -3
- package/src/substrate/{toolbox/baseSubstrateToolbox.ts → substrate.ts} +104 -72
- package/src/substrate/types.ts +120 -0
- package/src/utils.ts +27 -0
- package/src/utxo/helpers/api.ts +27 -23
- package/src/utxo/helpers/bchaddrjs.ts +21 -21
- package/src/utxo/helpers/index.ts +0 -1
- package/src/utxo/helpers/txSize.ts +3 -4
- package/src/utxo/index.ts +3 -7
- package/src/utxo/toolbox/bitcoinCash.ts +164 -154
- package/src/utxo/toolbox/index.ts +63 -24
- package/src/utxo/toolbox/utxo.ts +376 -229
- package/src/utxo/types.ts +24 -39
- package/src/cosmos/thorchainUtils/types/proto/MsgCompiled.js +0 -2806
- package/src/cosmos/thorchainUtils/util.ts +0 -46
- package/src/cosmos/toolbox/BaseCosmosToolbox.ts +0 -254
- package/src/cosmos/toolbox/gaia.ts +0 -39
- package/src/cosmos/toolbox/getToolboxByChain.ts +0 -29
- package/src/cosmos/toolbox/kujira.ts +0 -61
- package/src/evm/provider.ts +0 -6
- package/src/evm/toolbox/EVMToolbox.ts +0 -662
- package/src/evm/toolbox/arb.ts +0 -61
- package/src/evm/toolbox/avax.ts +0 -36
- package/src/evm/toolbox/base.ts +0 -42
- package/src/evm/toolbox/bsc.ts +0 -34
- package/src/evm/toolbox/eth.ts +0 -44
- package/src/evm/toolbox/getToolboxByChain.ts +0 -42
- package/src/evm/toolbox/matic.ts +0 -42
- package/src/radix/toolbox.ts +0 -693
- package/src/substrate/toolbox/index.ts +0 -40
- package/src/substrate/types/index.ts +0 -2
- package/src/substrate/types/network.ts +0 -42
- package/src/substrate/types/wallet.ts +0 -78
- package/src/utxo/helpers/utils.ts +0 -45
|
@@ -0,0 +1,69 @@
|
|
|
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 {
|
|
7
|
+
getEstimateTransactionFee,
|
|
8
|
+
getIsEIP1559Compatible,
|
|
9
|
+
getNetworkParams,
|
|
10
|
+
getProvider,
|
|
11
|
+
} from "../helpers";
|
|
12
|
+
import type { EVMToolboxParams } from "../types";
|
|
13
|
+
import { BaseEVMToolbox } from "./baseEVMToolbox";
|
|
14
|
+
|
|
15
|
+
export async function ETHToolbox({ provider, ...signer }: EVMToolboxParams) {
|
|
16
|
+
const evmToolbox = await createEvmToolbox(Chain.Ethereum)({
|
|
17
|
+
provider,
|
|
18
|
+
...signer,
|
|
19
|
+
});
|
|
20
|
+
async function multicall(
|
|
21
|
+
callTuples: { address: string; data: string }[],
|
|
22
|
+
multicallAddress = "0x5ba1e12693dc8f9c48aad8770482f4739beed696",
|
|
23
|
+
funcName = "aggregate",
|
|
24
|
+
feeOptionKey: FeeOption = FeeOption.Fast,
|
|
25
|
+
) {
|
|
26
|
+
const txObject = await evmToolbox.createContractTxObject({
|
|
27
|
+
contractAddress: multicallAddress,
|
|
28
|
+
abi: multicallAbi,
|
|
29
|
+
funcName,
|
|
30
|
+
funcParams: [callTuples],
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return evmToolbox.sendTransaction({ ...txObject, feeOptionKey });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return { ...evmToolbox, multicall };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const ARBToolbox = createEvmToolbox(Chain.Arbitrum);
|
|
40
|
+
export const AVAXToolbox = createEvmToolbox(Chain.Avalanche);
|
|
41
|
+
export const BASEToolbox = createEvmToolbox(Chain.Base);
|
|
42
|
+
export const BSCToolbox = createEvmToolbox(Chain.BinanceSmartChain);
|
|
43
|
+
export const MATICToolbox = createEvmToolbox(Chain.Polygon);
|
|
44
|
+
|
|
45
|
+
function createEvmToolbox<C extends EVMChain>(chain: C) {
|
|
46
|
+
return async function createEvmToolbox({
|
|
47
|
+
provider: providerParam,
|
|
48
|
+
...toolboxSignerParams
|
|
49
|
+
}: EVMToolboxParams) {
|
|
50
|
+
const rpcUrl = SKConfig.get("rpcUrls")[chain];
|
|
51
|
+
|
|
52
|
+
const provider = providerParam || (await getProvider(chain, rpcUrl));
|
|
53
|
+
|
|
54
|
+
const isEIP1559Compatible = getIsEIP1559Compatible(chain);
|
|
55
|
+
const signer = match(toolboxSignerParams)
|
|
56
|
+
.with({ phrase: P.string }, ({ phrase }) => HDNodeWallet.fromPhrase(phrase).connect(provider))
|
|
57
|
+
.with({ signer: P.any }, ({ signer }) => signer)
|
|
58
|
+
.otherwise(() => undefined);
|
|
59
|
+
|
|
60
|
+
const evmToolbox = BaseEVMToolbox({ provider, signer, isEIP1559Compatible, chain });
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
...evmToolbox,
|
|
64
|
+
estimateTransactionFee: getEstimateTransactionFee({ provider, isEIP1559Compatible, chain }),
|
|
65
|
+
getNetworkParams: getNetworkParams(chain),
|
|
66
|
+
getBalance: getEvmApi(chain).getBalance,
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Chain, type EVMChain } from "@swapkit/helpers";
|
|
2
|
+
|
|
3
|
+
import { getProvider } from "../helpers";
|
|
4
|
+
import type { EVMToolboxParams } from "../types";
|
|
5
|
+
import { ARBToolbox, AVAXToolbox, BASEToolbox, BSCToolbox, ETHToolbox, MATICToolbox } from "./evm";
|
|
6
|
+
import { OPToolbox } from "./op";
|
|
7
|
+
|
|
8
|
+
export async function getEvmToolbox<T extends EVMChain>(chain: T, params?: EVMToolboxParams) {
|
|
9
|
+
const toolboxParams = {
|
|
10
|
+
...params,
|
|
11
|
+
provider: params?.provider || (await getProvider(chain)),
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
switch (chain) {
|
|
15
|
+
case Chain.Avalanche:
|
|
16
|
+
return AVAXToolbox(toolboxParams);
|
|
17
|
+
case Chain.Arbitrum:
|
|
18
|
+
return ARBToolbox(toolboxParams);
|
|
19
|
+
case Chain.Base:
|
|
20
|
+
return BASEToolbox(toolboxParams);
|
|
21
|
+
case Chain.Optimism:
|
|
22
|
+
return OPToolbox(toolboxParams);
|
|
23
|
+
case Chain.Polygon:
|
|
24
|
+
return MATICToolbox(toolboxParams);
|
|
25
|
+
case Chain.BinanceSmartChain:
|
|
26
|
+
return BSCToolbox(toolboxParams);
|
|
27
|
+
case Chain.Ethereum:
|
|
28
|
+
return ETHToolbox(toolboxParams);
|
|
29
|
+
default:
|
|
30
|
+
throw new Error(`Chain ${chain} is not supported`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export * from "./baseEVMToolbox";
|
|
35
|
+
export * from "./evm";
|
|
36
|
+
export * from "./op";
|
package/src/evm/toolbox/op.ts
CHANGED
|
@@ -1,92 +1,85 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
ChainId,
|
|
5
|
-
ChainToExplorerUrl,
|
|
6
|
-
FeeOption,
|
|
7
|
-
SKConfig,
|
|
8
|
-
} from "@swapkit/helpers";
|
|
9
|
-
import type { BrowserProvider, JsonRpcProvider, Signer, TransactionRequest } from "ethers";
|
|
10
|
-
import { Contract, Transaction } from "ethers";
|
|
1
|
+
import { BaseDecimal, Chain, ChainId, ChainToExplorerUrl, SKConfig } from "@swapkit/helpers";
|
|
2
|
+
import type { BrowserProvider, JsonRpcProvider, Provider, TransactionRequest } from "ethers";
|
|
3
|
+
import { Contract, HDNodeWallet } from "ethers";
|
|
11
4
|
|
|
5
|
+
import { P } from "ts-pattern";
|
|
6
|
+
import { match } from "ts-pattern";
|
|
7
|
+
import { getEvmApi } from "../api";
|
|
12
8
|
import { gasOracleAbi } from "../contracts/op/gasOracle";
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
import {
|
|
9
|
+
import { getProvider } from "../helpers";
|
|
10
|
+
import type { EVMToolboxParams } from "../types";
|
|
11
|
+
import { BaseEVMToolbox } from "./baseEVMToolbox";
|
|
16
12
|
|
|
17
13
|
const GAS_PRICE_ORACLE_ADDRESS = "0x420000000000000000000000000000000000000f";
|
|
18
14
|
|
|
19
|
-
|
|
15
|
+
function connectGasPriceOracle<P extends Provider>(provider: P) {
|
|
20
16
|
return new Contract(GAS_PRICE_ORACLE_ADDRESS, gasOracleAbi, provider);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
tx: TransactionRequest
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return gasPriceOracle.getL1GasUsed(serializedTx);
|
|
88
|
-
}
|
|
89
|
-
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getL1GasPriceFetcher<P extends Provider>(provider: P) {
|
|
20
|
+
return function getL1GasPrice() {
|
|
21
|
+
const gasPriceOracle = connectGasPriceOracle(provider);
|
|
22
|
+
|
|
23
|
+
if (gasPriceOracle && "l1BaseFee" in gasPriceOracle) {
|
|
24
|
+
return gasPriceOracle?.l1BaseFee() as unknown as bigint;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return undefined;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function serializeTx<P extends JsonRpcProvider | BrowserProvider>(provider: P) {
|
|
32
|
+
return async function serializeTx({ from, to, nonce, ...tx }: TransactionRequest) {
|
|
33
|
+
const { Transaction } = await import("ethers");
|
|
34
|
+
|
|
35
|
+
if (!to) throw new Error("Missing to address");
|
|
36
|
+
const txParams = {
|
|
37
|
+
...tx,
|
|
38
|
+
to: to as string,
|
|
39
|
+
nonce: nonce ? nonce : from ? await provider.getTransactionCount(from) : 0,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return Transaction.from(txParams).serialized;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function estimateL1GasCost<P extends JsonRpcProvider | BrowserProvider>(provider: P) {
|
|
47
|
+
return async function estimateL1GasCost(tx: TransactionRequest) {
|
|
48
|
+
const gasPriceOracle = connectGasPriceOracle(provider);
|
|
49
|
+
const serializedTx = await serializeTx(provider)(tx);
|
|
50
|
+
|
|
51
|
+
if (gasPriceOracle && "getL1Fee" in gasPriceOracle) {
|
|
52
|
+
return gasPriceOracle.getL1Fee(serializedTx);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function estimateL2GasCost<P extends JsonRpcProvider | BrowserProvider>(provider: P) {
|
|
58
|
+
return async function estimateL2GasCost(tx: TransactionRequest) {
|
|
59
|
+
const l2GasPrice = await provider.send("eth_gasPrice", []);
|
|
60
|
+
const l2GasCost = await provider.estimateGas(tx);
|
|
61
|
+
return l2GasPrice.mul(l2GasCost);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function estimateTotalGasCost<P extends JsonRpcProvider | BrowserProvider>(provider: P) {
|
|
66
|
+
return async function estimateTotalGasCost(tx: TransactionRequest) {
|
|
67
|
+
const l1GasCost = await estimateL1GasCost(provider)(tx);
|
|
68
|
+
const l2GasCost = await estimateL2GasCost(provider)(tx);
|
|
69
|
+
return l1GasCost.add(l2GasCost);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function estimateL1Gas<P extends JsonRpcProvider | BrowserProvider>(provider: P) {
|
|
74
|
+
return async function estimateL1Gas(tx: TransactionRequest) {
|
|
75
|
+
const gasPriceOracle = connectGasPriceOracle(provider);
|
|
76
|
+
const serializedTx = await serializeTx(provider)(tx);
|
|
77
|
+
|
|
78
|
+
if (gasPriceOracle && "getL1GasUsed" in gasPriceOracle) {
|
|
79
|
+
return gasPriceOracle.getL1GasUsed(serializedTx);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
90
83
|
|
|
91
84
|
const getNetworkParams = () => ({
|
|
92
85
|
chainId: ChainId.OptimismHex,
|
|
@@ -96,68 +89,29 @@ const getNetworkParams = () => ({
|
|
|
96
89
|
blockExplorerUrls: [ChainToExplorerUrl[Chain.Optimism]],
|
|
97
90
|
});
|
|
98
91
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
maxFeePerGas,
|
|
114
|
-
maxPriorityFeePerGas,
|
|
115
|
-
},
|
|
116
|
-
[FeeOption.Fast]: {
|
|
117
|
-
l1GasPrice: ((l1GasPrice || 0n) * 15n) / 10n,
|
|
118
|
-
gasPrice: (price * 15n) / 10n,
|
|
119
|
-
maxFeePerGas,
|
|
120
|
-
maxPriorityFeePerGas: (maxPriorityFeePerGas * 15n) / 10n,
|
|
121
|
-
},
|
|
122
|
-
[FeeOption.Fastest]: {
|
|
123
|
-
l1GasPrice: (l1GasPrice || 0n) * 2n,
|
|
124
|
-
gasPrice: price * 2n,
|
|
125
|
-
maxFeePerGas,
|
|
126
|
-
maxPriorityFeePerGas: maxPriorityFeePerGas * 2n,
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
} catch (error) {
|
|
130
|
-
throw new Error(
|
|
131
|
-
`Failed to estimate gas price: ${(error as any).msg ?? (error as any).toString()}`,
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
export const OPToolbox = ({
|
|
137
|
-
provider,
|
|
138
|
-
signer,
|
|
139
|
-
}: { signer?: Signer; provider: JsonRpcProvider | BrowserProvider }) => {
|
|
140
|
-
const evmToolbox = EVMToolbox({ provider, signer });
|
|
92
|
+
export async function OPToolbox({
|
|
93
|
+
provider: providerParam,
|
|
94
|
+
...toolboxSignerParams
|
|
95
|
+
}: EVMToolboxParams) {
|
|
96
|
+
const chain = Chain.Optimism;
|
|
97
|
+
const rpcUrl = SKConfig.get("rpcUrls")[chain];
|
|
98
|
+
const provider = providerParam || (await getProvider(chain, rpcUrl));
|
|
99
|
+
const signer = match(toolboxSignerParams)
|
|
100
|
+
.with({ phrase: P.string }, ({ phrase }) => HDNodeWallet.fromPhrase(phrase).connect(provider))
|
|
101
|
+
.with({ signer: P.any }, ({ signer }) => signer)
|
|
102
|
+
.otherwise(() => undefined);
|
|
103
|
+
|
|
104
|
+
const evmToolbox = BaseEVMToolbox({ provider, signer });
|
|
105
|
+
const getL1GasPrice = getL1GasPriceFetcher(provider);
|
|
141
106
|
|
|
142
107
|
return {
|
|
143
108
|
...evmToolbox,
|
|
144
|
-
|
|
145
|
-
estimateL1GasCost:
|
|
146
|
-
estimateL2GasCost:
|
|
147
|
-
|
|
148
|
-
|
|
109
|
+
estimateL1Gas: estimateL1Gas(provider),
|
|
110
|
+
estimateL1GasCost: estimateL1GasCost(provider),
|
|
111
|
+
estimateL2GasCost: estimateL2GasCost(provider),
|
|
112
|
+
estimateTotalGasCost: estimateTotalGasCost(provider),
|
|
113
|
+
getBalance: getEvmApi(Chain.Optimism).getBalance,
|
|
114
|
+
getL1GasPrice,
|
|
149
115
|
getNetworkParams,
|
|
150
|
-
estimateGasPrices: () => estimateGasPrices(provider),
|
|
151
|
-
getBalance: (
|
|
152
|
-
address: string,
|
|
153
|
-
potentialScamFilter = true,
|
|
154
|
-
overwriteProvider?: JsonRpcProvider | BrowserProvider,
|
|
155
|
-
) =>
|
|
156
|
-
getBalance({
|
|
157
|
-
provider: overwriteProvider || provider,
|
|
158
|
-
address,
|
|
159
|
-
chain: Chain.Optimism,
|
|
160
|
-
potentialScamFilter,
|
|
161
|
-
}),
|
|
162
116
|
};
|
|
163
|
-
}
|
|
117
|
+
}
|
package/src/evm/types.ts
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
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";
|
|
4
19
|
import type {
|
|
5
20
|
ARBToolbox,
|
|
6
21
|
AVAXToolbox,
|
|
@@ -9,8 +24,9 @@ import type {
|
|
|
9
24
|
ETHToolbox,
|
|
10
25
|
MATICToolbox,
|
|
11
26
|
OPToolbox,
|
|
12
|
-
} from "./
|
|
13
|
-
|
|
27
|
+
} from "./toolbox";
|
|
28
|
+
|
|
29
|
+
import type { getProvider } from "./index";
|
|
14
30
|
|
|
15
31
|
export enum EthNetwork {
|
|
16
32
|
Test = "goerli",
|
|
@@ -22,7 +38,7 @@ export type ApproveParams = {
|
|
|
22
38
|
spenderAddress: string;
|
|
23
39
|
feeOptionKey?: FeeOption;
|
|
24
40
|
amount?: BigNumberish;
|
|
25
|
-
from
|
|
41
|
+
from?: string;
|
|
26
42
|
// Optional fallback in case estimation for gas limit fails
|
|
27
43
|
gasLimitFallback?: BigNumberish;
|
|
28
44
|
nonce?: number;
|
|
@@ -39,7 +55,7 @@ export type IsApprovedParams = ApprovedParams & {
|
|
|
39
55
|
};
|
|
40
56
|
|
|
41
57
|
export type CallParams = {
|
|
42
|
-
callProvider?: ReturnType<typeof getProvider
|
|
58
|
+
callProvider?: Awaited<ReturnType<typeof getProvider>>;
|
|
43
59
|
contractAddress: string;
|
|
44
60
|
abi: readonly JsonFragment[];
|
|
45
61
|
funcName: string;
|
|
@@ -53,30 +69,21 @@ export type EstimateCallParams = Pick<
|
|
|
53
69
|
"contractAddress" | "abi" | "funcName" | "funcParams" | "txOverrides"
|
|
54
70
|
>;
|
|
55
71
|
|
|
56
|
-
export type
|
|
72
|
+
export type EVMTransferParams = GenericTransferParams & {
|
|
73
|
+
sender?: string;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export type EVMCreateTransactionParams = Omit<GenericCreateTransactionParams, "feeRate"> & {
|
|
57
77
|
gasLimit?: bigint;
|
|
58
78
|
gasPrice?: bigint;
|
|
59
79
|
maxFeePerGas?: bigint;
|
|
60
80
|
maxPriorityFeePerGas?: bigint;
|
|
61
81
|
data?: string;
|
|
62
|
-
from: string;
|
|
63
82
|
nonce?: number;
|
|
64
|
-
assetValue: AssetValue;
|
|
65
83
|
};
|
|
66
84
|
|
|
67
|
-
export type EVMToolboxType = ReturnType<
|
|
68
|
-
| typeof ARBToolbox
|
|
69
|
-
| typeof AVAXToolbox
|
|
70
|
-
| typeof BASEToolbox
|
|
71
|
-
| typeof BSCToolbox
|
|
72
|
-
| typeof ETHToolbox
|
|
73
|
-
| typeof MATICToolbox
|
|
74
|
-
| typeof OPToolbox
|
|
75
|
-
>;
|
|
76
|
-
|
|
77
85
|
export type EVMMaxSendableAmountsParams = {
|
|
78
86
|
from: string;
|
|
79
|
-
toolbox: EVMToolboxType;
|
|
80
87
|
assetValue: AssetValue;
|
|
81
88
|
feeOptionKey?: FeeOption;
|
|
82
89
|
memo?: string;
|
|
@@ -109,10 +116,25 @@ export type LegacyEVMTxParams<T = bigint> = EVMTxBaseParams<T> & {
|
|
|
109
116
|
|
|
110
117
|
export type EVMTxParams = EIP1559TxParams | LegacyEVMTxParams;
|
|
111
118
|
|
|
112
|
-
export type
|
|
113
|
-
|
|
|
114
|
-
|
|
115
|
-
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
|
119
|
+
export type EVMToolboxParams = {
|
|
120
|
+
provider?: BrowserProvider | JsonRpcProvider;
|
|
121
|
+
} & (
|
|
122
|
+
| {
|
|
123
|
+
signer?: (ChainSigner<EVMTransferParams, string> & Signer) | JsonRpcSigner;
|
|
124
|
+
}
|
|
125
|
+
| {
|
|
126
|
+
phrase?: string;
|
|
127
|
+
derivationPath?: DerivationPathArray;
|
|
128
|
+
index?: number;
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
export type EVMToolboxes = {
|
|
133
|
+
[Chain.Arbitrum]: Awaited<ReturnType<typeof ARBToolbox>>;
|
|
134
|
+
[Chain.Avalanche]: Awaited<ReturnType<typeof AVAXToolbox>>;
|
|
135
|
+
[Chain.Base]: Awaited<ReturnType<typeof BASEToolbox>>;
|
|
136
|
+
[Chain.BinanceSmartChain]: Awaited<ReturnType<typeof BSCToolbox>>;
|
|
137
|
+
[Chain.Ethereum]: Awaited<ReturnType<typeof ETHToolbox>>;
|
|
138
|
+
[Chain.Optimism]: Awaited<ReturnType<typeof OPToolbox>>;
|
|
139
|
+
[Chain.Polygon]: Awaited<ReturnType<typeof MATICToolbox>>;
|
|
140
|
+
};
|