@swapkit/toolboxes 1.0.0-beta.0 → 1.0.0-beta.10
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 +27 -23
- 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 +19 -26
- 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 +125 -137
- package/src/cosmos/types.ts +37 -18
- package/src/cosmos/util.ts +24 -74
- 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 +744 -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 +199 -0
- package/src/solana/index.ts +11 -5
- package/src/solana/toolbox.ts +227 -137
- 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 +165 -155
- package/src/utxo/toolbox/index.ts +63 -24
- package/src/utxo/toolbox/utxo.ts +376 -229
- package/src/utxo/types.ts +26 -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,334 @@
|
|
|
1
|
+
import type { StdFee } from "@cosmjs/amino";
|
|
2
|
+
import type { Account } from "@cosmjs/stargate";
|
|
3
|
+
import { base64, bech32 } from "@scure/base";
|
|
4
|
+
import {
|
|
5
|
+
AssetValue,
|
|
6
|
+
BaseDecimal,
|
|
7
|
+
Chain,
|
|
8
|
+
type ChainId,
|
|
9
|
+
ChainToChainId,
|
|
10
|
+
type CosmosChain,
|
|
11
|
+
CosmosChainPrefixes,
|
|
12
|
+
DerivationPath,
|
|
13
|
+
type DerivationPathArray,
|
|
14
|
+
FeeOption,
|
|
15
|
+
type GenericTransferParams,
|
|
16
|
+
NetworkDerivationPath,
|
|
17
|
+
SKConfig,
|
|
18
|
+
SwapKitError,
|
|
19
|
+
SwapKitNumber,
|
|
20
|
+
derivationPathToString,
|
|
21
|
+
updateDerivationPath,
|
|
22
|
+
} from "@swapkit/helpers";
|
|
23
|
+
import { SwapKitApi } from "@swapkit/helpers/api";
|
|
24
|
+
import { P, match } from "ts-pattern";
|
|
25
|
+
import { getBalance } from "../../utils";
|
|
26
|
+
import type { CosmosToolboxParams } from "../types";
|
|
27
|
+
import {
|
|
28
|
+
cosmosCreateTransaction,
|
|
29
|
+
createSigningStargateClient,
|
|
30
|
+
createStargateClient,
|
|
31
|
+
getDenomWithChain,
|
|
32
|
+
getMsgSendDenom,
|
|
33
|
+
} from "../util";
|
|
34
|
+
|
|
35
|
+
export async function fetchFeeRateFromSwapKit(chainId: ChainId, safeDefault: number) {
|
|
36
|
+
try {
|
|
37
|
+
const response = await SwapKitApi.getGasRate();
|
|
38
|
+
const responseGasRate = response.find((gas) => gas.chainId === chainId)?.value;
|
|
39
|
+
|
|
40
|
+
return responseGasRate ? Number.parseFloat(responseGasRate) : safeDefault;
|
|
41
|
+
} catch (e) {
|
|
42
|
+
console.error(e);
|
|
43
|
+
return safeDefault;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function getSignerFromPhrase({
|
|
48
|
+
phrase,
|
|
49
|
+
prefix,
|
|
50
|
+
...derivationParams
|
|
51
|
+
}: { phrase: string; prefix?: string } & (
|
|
52
|
+
| { chain: Chain; index?: number }
|
|
53
|
+
| { derivationPath: string }
|
|
54
|
+
)) {
|
|
55
|
+
const { DirectSecp256k1HdWallet } = (await import("@cosmjs/proto-signing")).default;
|
|
56
|
+
const { stringToPath } = (await import("@cosmjs/crypto")).default;
|
|
57
|
+
|
|
58
|
+
const derivationPath =
|
|
59
|
+
"derivationPath" in derivationParams
|
|
60
|
+
? derivationParams.derivationPath
|
|
61
|
+
: `${DerivationPath[derivationParams.chain]}/${derivationParams.index}`;
|
|
62
|
+
|
|
63
|
+
return DirectSecp256k1HdWallet.fromMnemonic(phrase, {
|
|
64
|
+
prefix,
|
|
65
|
+
hdPaths: [stringToPath(derivationPath)],
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function getSignerFromPrivateKey({
|
|
70
|
+
privateKey,
|
|
71
|
+
prefix,
|
|
72
|
+
}: {
|
|
73
|
+
privateKey: Uint8Array;
|
|
74
|
+
prefix: string;
|
|
75
|
+
}) {
|
|
76
|
+
const { DirectSecp256k1Wallet } = (await import("@cosmjs/proto-signing")).default;
|
|
77
|
+
|
|
78
|
+
return DirectSecp256k1Wallet.fromKey(privateKey, prefix);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const SafeDefaultFeeValues = {
|
|
82
|
+
[Chain.Cosmos]: 500,
|
|
83
|
+
[Chain.Kujira]: 1000,
|
|
84
|
+
[Chain.THORChain]: 5000000,
|
|
85
|
+
[Chain.Maya]: 5000000,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export function verifySignature(getAccount: (address: string) => Promise<Account | null>) {
|
|
89
|
+
return async function verifySignature({
|
|
90
|
+
signature,
|
|
91
|
+
message,
|
|
92
|
+
address,
|
|
93
|
+
}: {
|
|
94
|
+
signature: string;
|
|
95
|
+
message: string;
|
|
96
|
+
address: string;
|
|
97
|
+
}) {
|
|
98
|
+
const account = await getAccount(address);
|
|
99
|
+
if (!account?.pubkey) throw new SwapKitError("toolbox_cosmos_verify_signature_no_pubkey");
|
|
100
|
+
const { Secp256k1Signature, Secp256k1 } = (await import("@cosmjs/crypto")).default;
|
|
101
|
+
|
|
102
|
+
const secpSignature = Secp256k1Signature.fromFixedLength(base64.decode(signature));
|
|
103
|
+
return Secp256k1.verifySignature(secpSignature, base64.decode(message), account.pubkey.value);
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export async function createCosmosToolbox({ chain, ...toolboxParams }: CosmosToolboxParams) {
|
|
108
|
+
const rpcUrl = SKConfig.get("rpcUrls")[chain];
|
|
109
|
+
const chainPrefix = CosmosChainPrefixes[chain];
|
|
110
|
+
|
|
111
|
+
const index = "index" in toolboxParams ? toolboxParams.index || 0 : 0;
|
|
112
|
+
const derivationPath = derivationPathToString(
|
|
113
|
+
"derivationPath" in toolboxParams && toolboxParams.derivationPath
|
|
114
|
+
? toolboxParams.derivationPath
|
|
115
|
+
: updateDerivationPath(NetworkDerivationPath[chain], { index }),
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const signer = await match(toolboxParams)
|
|
119
|
+
.with({ phrase: P.string }, ({ phrase }) =>
|
|
120
|
+
getSignerFromPhrase({ phrase, prefix: chainPrefix, derivationPath }),
|
|
121
|
+
)
|
|
122
|
+
.with({ signer: P.any }, ({ signer }) => signer)
|
|
123
|
+
.otherwise(() => undefined);
|
|
124
|
+
|
|
125
|
+
async function getAccount(address: string) {
|
|
126
|
+
const client = await createStargateClient(rpcUrl);
|
|
127
|
+
return client.getAccount(address);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function getAddress() {
|
|
131
|
+
const [account] = (await signer?.getAccounts()) || [];
|
|
132
|
+
return account?.address;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function getPubKey() {
|
|
136
|
+
const [account] = (await signer?.getAccounts()) || [];
|
|
137
|
+
if (!account?.pubkey) {
|
|
138
|
+
throw new SwapKitError("toolbox_cosmos_signer_not_defined");
|
|
139
|
+
}
|
|
140
|
+
return base64.encode(account?.pubkey);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function transfer({
|
|
144
|
+
recipient,
|
|
145
|
+
assetValue,
|
|
146
|
+
memo = "",
|
|
147
|
+
feeRate,
|
|
148
|
+
feeOptionKey = FeeOption.Fast,
|
|
149
|
+
}: GenericTransferParams) {
|
|
150
|
+
const from = await getAddress();
|
|
151
|
+
|
|
152
|
+
if (!(signer && from)) {
|
|
153
|
+
throw new SwapKitError("toolbox_cosmos_signer_not_defined");
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const feeAssetValue = AssetValue.from({
|
|
157
|
+
chain,
|
|
158
|
+
});
|
|
159
|
+
const assetDenom = getDenomWithChain(feeAssetValue);
|
|
160
|
+
|
|
161
|
+
const txFee =
|
|
162
|
+
feeRate ||
|
|
163
|
+
feeToStdFee((await getFees(chain, SafeDefaultFeeValues[chain]))[feeOptionKey], assetDenom);
|
|
164
|
+
|
|
165
|
+
const signingClient = await createSigningStargateClient(rpcUrl, signer);
|
|
166
|
+
const message = [
|
|
167
|
+
{
|
|
168
|
+
denom: getMsgSendDenom(`u${assetValue.symbol}`).toLowerCase(),
|
|
169
|
+
amount: assetValue.getBaseValue("string"),
|
|
170
|
+
},
|
|
171
|
+
];
|
|
172
|
+
|
|
173
|
+
const { transactionHash } = await signingClient.sendTokens(
|
|
174
|
+
from,
|
|
175
|
+
recipient,
|
|
176
|
+
message,
|
|
177
|
+
txFee,
|
|
178
|
+
memo,
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
return transactionHash;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
transfer,
|
|
186
|
+
getAddress,
|
|
187
|
+
getAccount,
|
|
188
|
+
getBalance: getBalance(chain),
|
|
189
|
+
getSignerFromPhrase: async ({
|
|
190
|
+
phrase,
|
|
191
|
+
derivationPath,
|
|
192
|
+
}: { phrase: string; derivationPath: DerivationPathArray }) =>
|
|
193
|
+
getSignerFromPhrase({
|
|
194
|
+
phrase,
|
|
195
|
+
prefix: chainPrefix,
|
|
196
|
+
derivationPath: derivationPathToString(derivationPath),
|
|
197
|
+
index,
|
|
198
|
+
}),
|
|
199
|
+
getSignerFromPrivateKey: async (privateKey: Uint8Array) => {
|
|
200
|
+
const { DirectSecp256k1Wallet } = (await import("@cosmjs/proto-signing")).default;
|
|
201
|
+
return DirectSecp256k1Wallet.fromKey(privateKey, chainPrefix);
|
|
202
|
+
},
|
|
203
|
+
createPrivateKeyFromPhrase: createPrivateKeyFromPhrase(derivationPath),
|
|
204
|
+
validateAddress: getCosmosValidateAddress(chainPrefix),
|
|
205
|
+
getPubKey,
|
|
206
|
+
getFees: () => getFees(chain, SafeDefaultFeeValues[chain]),
|
|
207
|
+
fetchFeeRateFromSwapKit,
|
|
208
|
+
getBalanceAsDenoms: cosmosBalanceDenomsGetter(rpcUrl),
|
|
209
|
+
createTransaction: cosmosCreateTransaction,
|
|
210
|
+
verifySignature: verifySignature(getAccount),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export async function getFeeRateFromThorswap(chainId: ChainId, safeDefault: number) {
|
|
215
|
+
try {
|
|
216
|
+
const response = await SwapKitApi.getGasRate();
|
|
217
|
+
const responseGasRate = response.find((gas) => gas.chainId === chainId)?.value;
|
|
218
|
+
|
|
219
|
+
return responseGasRate ? Number.parseFloat(responseGasRate) : safeDefault;
|
|
220
|
+
} catch (e) {
|
|
221
|
+
console.error(e);
|
|
222
|
+
return safeDefault;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function cosmosValidateAddress({
|
|
227
|
+
address,
|
|
228
|
+
chain,
|
|
229
|
+
prefix: chainPrefix,
|
|
230
|
+
}: { address: string } & (
|
|
231
|
+
| { prefix: string; chain?: undefined }
|
|
232
|
+
| { chain: CosmosChain; prefix?: undefined }
|
|
233
|
+
)) {
|
|
234
|
+
const prefix = chainPrefix || getPrefix(chain);
|
|
235
|
+
|
|
236
|
+
if (!(prefix && address)) {
|
|
237
|
+
throw new SwapKitError("toolbox_cosmos_validate_address_prefix_not_found");
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return getCosmosValidateAddress(prefix)(address);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function estimateTransactionFee({
|
|
244
|
+
assetValue: { chain },
|
|
245
|
+
}: {
|
|
246
|
+
assetValue: AssetValue;
|
|
247
|
+
}) {
|
|
248
|
+
return AssetValue.from({ chain, value: getMinTransactionFee(chain) });
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function getPrefix<C extends CosmosChain>(chain?: C) {
|
|
252
|
+
const { isStagenet } = SKConfig.get("envs");
|
|
253
|
+
const useStagenetPrefix = chain
|
|
254
|
+
? [Chain.THORChain, Chain.Maya].includes(chain) && isStagenet
|
|
255
|
+
: false;
|
|
256
|
+
const basePrefix = chain ? CosmosChainPrefixes[chain] : undefined;
|
|
257
|
+
|
|
258
|
+
return useStagenetPrefix ? `s${basePrefix}` : basePrefix;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async function getFees(chain: Chain, safeDefault: number) {
|
|
262
|
+
const baseFee = await fetchFeeRateFromSwapKit(ChainToChainId[chain], safeDefault);
|
|
263
|
+
return {
|
|
264
|
+
average: SwapKitNumber.fromBigInt(BigInt(baseFee), BaseDecimal[chain]),
|
|
265
|
+
fast: SwapKitNumber.fromBigInt(BigInt(Math.floor(baseFee * 1.5)), BaseDecimal[chain]),
|
|
266
|
+
fastest: SwapKitNumber.fromBigInt(BigInt(Math.floor(baseFee * 2)), BaseDecimal[chain]),
|
|
267
|
+
} as { [key in FeeOption]: SwapKitNumber };
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function feeToStdFee(fee: SwapKitNumber, denom: string): StdFee {
|
|
271
|
+
return {
|
|
272
|
+
amount: [{ denom, amount: fee.getBaseValue("string") }],
|
|
273
|
+
gas: "200000",
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function getMinTransactionFee(chain: Chain) {
|
|
278
|
+
return (
|
|
279
|
+
{
|
|
280
|
+
[Chain.Cosmos]: 0.007,
|
|
281
|
+
[Chain.Kujira]: 0.02,
|
|
282
|
+
[Chain.THORChain]: 0.02,
|
|
283
|
+
[Chain.Maya]: 0.02,
|
|
284
|
+
}[chain as CosmosChain] || 0
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function getCosmosValidateAddress(prefix: string) {
|
|
289
|
+
return function validateAddress(address: string) {
|
|
290
|
+
if (!address.startsWith(prefix)) return false;
|
|
291
|
+
|
|
292
|
+
try {
|
|
293
|
+
const { prefix, words } = bech32.decode(address as `${string}1${string}`);
|
|
294
|
+
const normalized = bech32.encode(prefix, words);
|
|
295
|
+
|
|
296
|
+
return normalized === address.toLocaleLowerCase();
|
|
297
|
+
} catch (_error) {
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function cosmosBalanceDenomsGetter(rpcUrl: string) {
|
|
304
|
+
return async function getCosmosBalanceDenoms(address: string) {
|
|
305
|
+
const client = await createStargateClient(rpcUrl);
|
|
306
|
+
const allBalances = await client.getAllBalances(address);
|
|
307
|
+
|
|
308
|
+
const balances = allBalances.map((balance) => ({
|
|
309
|
+
...balance,
|
|
310
|
+
denom: balance.denom.includes("/") ? balance.denom.toUpperCase() : balance.denom,
|
|
311
|
+
}));
|
|
312
|
+
|
|
313
|
+
return balances;
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function createPrivateKeyFromPhrase(derivationPath: string) {
|
|
318
|
+
return async function createPrivateKeyFromPhrase(phrase: string) {
|
|
319
|
+
const { Bip39, EnglishMnemonic, Slip10, Slip10Curve, stringToPath } = await import(
|
|
320
|
+
"@cosmjs/crypto"
|
|
321
|
+
);
|
|
322
|
+
|
|
323
|
+
const mnemonicChecked = new EnglishMnemonic(phrase);
|
|
324
|
+
const seed = await Bip39.mnemonicToSeed(mnemonicChecked);
|
|
325
|
+
|
|
326
|
+
const { privkey } = Slip10.derivePath(
|
|
327
|
+
Slip10Curve.Secp256k1,
|
|
328
|
+
seed,
|
|
329
|
+
stringToPath(derivationPath),
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
return privkey;
|
|
333
|
+
};
|
|
334
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Chain, type CosmosChain } from "@swapkit/helpers";
|
|
2
|
+
|
|
3
|
+
import type { CosmosToolboxParams } from "../types";
|
|
4
|
+
import { createCosmosToolbox } from "./cosmos";
|
|
5
|
+
import { createThorchainToolbox } from "./thorchain";
|
|
6
|
+
|
|
7
|
+
export type CosmosToolboxes = {
|
|
8
|
+
GAIA: ReturnType<typeof createCosmosToolbox>;
|
|
9
|
+
KUJI: ReturnType<typeof createCosmosToolbox>;
|
|
10
|
+
MAYA: ReturnType<typeof createThorchainToolbox>;
|
|
11
|
+
THOR: ReturnType<typeof createThorchainToolbox>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const getCosmosToolbox = <T extends CosmosChain>(
|
|
15
|
+
chain: T,
|
|
16
|
+
params?: Omit<CosmosToolboxParams, "chain">,
|
|
17
|
+
): CosmosToolboxes[T] => {
|
|
18
|
+
switch (chain) {
|
|
19
|
+
case Chain.Cosmos:
|
|
20
|
+
case Chain.Kujira:
|
|
21
|
+
return createCosmosToolbox({ chain, ...params }) as CosmosToolboxes[T];
|
|
22
|
+
|
|
23
|
+
case Chain.Maya:
|
|
24
|
+
case Chain.THORChain:
|
|
25
|
+
return createThorchainToolbox({ chain, ...params }) as CosmosToolboxes[T];
|
|
26
|
+
|
|
27
|
+
default:
|
|
28
|
+
throw new Error(`Chain ${chain} is not supported`);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export * from "./cosmos";
|
|
33
|
+
export * from "./thorchain";
|