@swapkit/helpers 1.0.4 → 1.1.1
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/index.js +5 -2
- package/dist/index.js.map +13 -13
- package/package.json +11 -2
- package/src/helpers/__tests__/asset.test.ts +2 -2
- package/src/helpers/__tests__/derivationPath.ts +16 -0
- package/src/helpers/__tests__/memo.test.ts +16 -0
- package/src/helpers/__tests__/others.test.ts +2 -14
- package/src/helpers/asset.ts +4 -0
- package/src/helpers/derivationPath.ts +24 -14
- package/src/helpers/memo.ts +18 -0
- package/src/helpers/others.ts +15 -11
- package/src/helpers/web3wallets.ts +0 -9
- package/src/modules/__tests__/assetValue.test.ts +12 -11
- package/src/modules/assetValue.ts +16 -6
- package/src/modules/swapKitError.ts +23 -2
- package/src/types/commonTypes.ts +3 -12
- package/src/types/sdk.ts +18 -1
- package/src/types/wallet.ts +33 -3
package/package.json
CHANGED
|
@@ -2,10 +2,19 @@
|
|
|
2
2
|
"author": "swapkit-oss",
|
|
3
3
|
"description": "SwapKit - Helpers",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@swapkit/tokens": "1.0.
|
|
5
|
+
"@swapkit/tokens": "1.0.2",
|
|
6
6
|
"ky": "1.4.0",
|
|
7
|
+
"picocolors": "1.0.1",
|
|
7
8
|
"zod": "3.23.8"
|
|
8
9
|
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@swapkit/toolbox-cosmos": "1.0.6",
|
|
12
|
+
"@swapkit/toolbox-evm": "1.1.1",
|
|
13
|
+
"@swapkit/toolbox-solana": "1.0.6",
|
|
14
|
+
"@swapkit/toolbox-radix": "1.0.6",
|
|
15
|
+
"@swapkit/toolbox-substrate": "1.1.1",
|
|
16
|
+
"@swapkit/toolbox-utxo": "1.0.6"
|
|
17
|
+
},
|
|
9
18
|
"files": [
|
|
10
19
|
"src/",
|
|
11
20
|
"dist/"
|
|
@@ -29,5 +38,5 @@
|
|
|
29
38
|
},
|
|
30
39
|
"type": "module",
|
|
31
40
|
"types": "./src/index.ts",
|
|
32
|
-
"version": "1.
|
|
41
|
+
"version": "1.1.1"
|
|
33
42
|
}
|
|
@@ -174,7 +174,7 @@ describe("getDecimal", () => {
|
|
|
174
174
|
});
|
|
175
175
|
|
|
176
176
|
describe("Radix", () => {
|
|
177
|
-
test(
|
|
177
|
+
test.todo(
|
|
178
178
|
"returns proper decimal for radix and it's assets",
|
|
179
179
|
async () => {
|
|
180
180
|
const radixDecimal = await getDecimal({ chain: Chain.Radix, symbol: "XRD" });
|
|
@@ -218,7 +218,7 @@ describe("assetFromString", () => {
|
|
|
218
218
|
});
|
|
219
219
|
});
|
|
220
220
|
|
|
221
|
-
test("should return the correct object for Radix resource", () => {
|
|
221
|
+
test.todo("should return the correct object for Radix resource", () => {
|
|
222
222
|
const assetString =
|
|
223
223
|
"XRD.xwBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75";
|
|
224
224
|
const result = assetFromString(assetString);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import type { DerivationPathArray } from "../../types";
|
|
4
|
+
import { derivationPathToString } from "../derivationPath";
|
|
5
|
+
|
|
6
|
+
describe("derivationPathToString", () => {
|
|
7
|
+
test("should return the correct string for a full path", () => {
|
|
8
|
+
const path = [1, 2, 3, 4, 5] as DerivationPathArray;
|
|
9
|
+
expect(derivationPathToString(path)).toEqual("m/1'/2'/3'/4/5");
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test("should return the correct string for a short path", () => {
|
|
13
|
+
const path = [1, 2, 3, 4] as DerivationPathArray;
|
|
14
|
+
expect(derivationPathToString(path)).toEqual("m/1'/2'/3'/4");
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -4,6 +4,7 @@ import { Chain, MemoType } from "../../types";
|
|
|
4
4
|
import {
|
|
5
5
|
getMemoForDeposit,
|
|
6
6
|
getMemoForLeaveAndBond,
|
|
7
|
+
getMemoForNamePreferredAssetRegister,
|
|
7
8
|
getMemoForNameRegister,
|
|
8
9
|
getMemoForSaverDeposit,
|
|
9
10
|
getMemoForSaverWithdraw,
|
|
@@ -52,6 +53,21 @@ describe("getMemoForNameRegister", () => {
|
|
|
52
53
|
});
|
|
53
54
|
});
|
|
54
55
|
|
|
56
|
+
describe("getMemoForNamePreferredAssetRegister", () => {
|
|
57
|
+
test("returns correct memo for single side", () => {
|
|
58
|
+
const result = getMemoForNamePreferredAssetRegister({
|
|
59
|
+
name: "asdfg",
|
|
60
|
+
chain: Chain.Ethereum,
|
|
61
|
+
owner: "thor1234",
|
|
62
|
+
asset: "ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48",
|
|
63
|
+
payout: "0x6621d872f17109d6601c49edba526ebcfd332d5d",
|
|
64
|
+
});
|
|
65
|
+
expect(result).toBe(
|
|
66
|
+
"~:asdfg:ETH:0x6621d872f17109d6601c49edba526ebcfd332d5d:thor1234:ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48",
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
55
71
|
describe("getMemoForDeposit", () => {
|
|
56
72
|
test("returns correct memo for single side", () => {
|
|
57
73
|
const result = getMemoForDeposit({ chain: Chain.Ethereum, symbol: "ETH" });
|
|
@@ -1,20 +1,8 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import { Chain
|
|
2
|
+
import { Chain } from "../../types";
|
|
3
3
|
|
|
4
4
|
import { findAssetBy } from "../asset.ts";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
describe("derivationPathToString", () => {
|
|
8
|
-
test("should return the correct string for a full path", () => {
|
|
9
|
-
const path = [1, 2, 3, 4, 5] as DerivationPathArray;
|
|
10
|
-
expect(derivationPathToString(path)).toEqual("m/1'/2'/3'/4/5");
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
test("should return the correct string for a short path", () => {
|
|
14
|
-
const path = [1, 2, 3, 4] as DerivationPathArray;
|
|
15
|
-
expect(derivationPathToString(path)).toEqual("m/1'/2'/3'/4");
|
|
16
|
-
});
|
|
17
|
-
});
|
|
5
|
+
import { getTHORNameCost } from "../others.ts";
|
|
18
6
|
|
|
19
7
|
describe("getTHORNameCost", () => {
|
|
20
8
|
describe("for correct values", () => {
|
package/src/helpers/asset.ts
CHANGED
|
@@ -8,6 +8,10 @@ const getDecimalMethodHex = "0x313ce567";
|
|
|
8
8
|
|
|
9
9
|
export type CommonAssetString = (typeof CommonAssetStrings)[number] | Chain;
|
|
10
10
|
|
|
11
|
+
export type ConditionalAssetValueReturn<T extends boolean> = T extends true
|
|
12
|
+
? Promise<AssetValue[]>
|
|
13
|
+
: AssetValue[];
|
|
14
|
+
|
|
11
15
|
export const CommonAssetStrings = [
|
|
12
16
|
`${Chain.Maya}.MAYA`,
|
|
13
17
|
`${Chain.Ethereum}.THOR`,
|
|
@@ -13,28 +13,38 @@ type Params = {
|
|
|
13
13
|
type?: "legacy" | "ledgerLive" | "nativeSegwitMiddleAccount" | "segwit";
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
const updatedLastIndex = (path: DerivationPathArray, index: number) =>
|
|
17
|
-
...path.slice(0, path.length - 1),
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const updatedLastIndex = (path: DerivationPathArray, index: number) => {
|
|
17
|
+
const newPath = [...path.slice(0, path.length - 1), index];
|
|
18
|
+
return newPath as DerivationPathArray;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export function derivationPathToString([network, chainId, account, change, index]:
|
|
22
|
+
| [number, number, number, number, number | undefined]
|
|
23
|
+
| DerivationPathArray) {
|
|
24
|
+
const shortPath = typeof index !== "number";
|
|
25
|
+
|
|
26
|
+
return `m/${network}'/${chainId}'/${account}'/${change}${shortPath ? "" : `/${index}`}`;
|
|
27
|
+
}
|
|
20
28
|
|
|
21
29
|
export function getDerivationPathFor({ chain, index, addressIndex = 0, type }: Params) {
|
|
22
30
|
if (EVMChains.includes(chain as EVMChain)) {
|
|
23
|
-
if (type === "legacy") return [44, 60, 0, index];
|
|
24
|
-
if (type === "ledgerLive") return [44, 60, index, 0, addressIndex];
|
|
31
|
+
if (type === "legacy") return [44, 60, 0, index] as DerivationPathArray;
|
|
32
|
+
if (type === "ledgerLive") return [44, 60, index, 0, addressIndex] as DerivationPathArray;
|
|
25
33
|
return updatedLastIndex(NetworkDerivationPath[chain], index);
|
|
26
34
|
}
|
|
27
35
|
|
|
28
|
-
|
|
29
|
-
const chainId = chain === Chain.Bitcoin ? 0 : 2;
|
|
36
|
+
const chainId = chain === Chain.Litecoin ? 2 : 0;
|
|
30
37
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
switch (type) {
|
|
39
|
+
case "nativeSegwitMiddleAccount":
|
|
40
|
+
return [84, chainId, index, 0, addressIndex] as DerivationPathArray;
|
|
41
|
+
case "segwit":
|
|
42
|
+
return [49, chainId, 0, 0, index] as DerivationPathArray;
|
|
43
|
+
case "legacy":
|
|
44
|
+
return [44, chainId, 0, 0, index] as DerivationPathArray;
|
|
45
|
+
default:
|
|
46
|
+
return updatedLastIndex(NetworkDerivationPath[chain], index);
|
|
35
47
|
}
|
|
36
|
-
|
|
37
|
-
return updatedLastIndex(NetworkDerivationPath[chain], index);
|
|
38
48
|
}
|
|
39
49
|
|
|
40
50
|
export function getWalletFormatFor(path: string) {
|
package/src/helpers/memo.ts
CHANGED
|
@@ -72,6 +72,24 @@ export function getMemoForNameRegister({
|
|
|
72
72
|
return `${baseMemo}${ownerAssignmentOrChangePart}`;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
export function getMemoForNamePreferredAssetRegister({
|
|
76
|
+
name,
|
|
77
|
+
chain,
|
|
78
|
+
asset,
|
|
79
|
+
payout,
|
|
80
|
+
owner,
|
|
81
|
+
}: {
|
|
82
|
+
name: string;
|
|
83
|
+
chain: Chain;
|
|
84
|
+
asset: string;
|
|
85
|
+
payout: string;
|
|
86
|
+
owner: string;
|
|
87
|
+
}) {
|
|
88
|
+
const memo = [name, chain, payout, owner, asset].join(":");
|
|
89
|
+
|
|
90
|
+
return `${MemoType.NAME_REGISTER}:${memo}`;
|
|
91
|
+
}
|
|
92
|
+
|
|
75
93
|
export function getMemoForLoan(
|
|
76
94
|
memoType: MemoType.OPEN_LOAN | MemoType.CLOSE_LOAN,
|
|
77
95
|
{
|
package/src/helpers/others.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type ErrorKeys, SwapKitError } from "../modules/swapKitError";
|
|
2
2
|
import { Chain } from "../types";
|
|
3
|
-
import type { DerivationPathArray } from "../types/derivationPath";
|
|
4
3
|
|
|
5
4
|
// 10 rune for register, 1 rune per year
|
|
6
5
|
// MINIMUM_REGISTRATION_FEE = 11
|
|
@@ -25,14 +24,6 @@ export function getMAYANameCost(numberOfYears: number) {
|
|
|
25
24
|
return Math.round((10 + numberOfYears * 1.0512) * 1e10) / 1e10;
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
export function derivationPathToString([network, chainId, account, change, index]:
|
|
29
|
-
| [number, number, number, number, number | undefined]
|
|
30
|
-
| DerivationPathArray) {
|
|
31
|
-
const shortPath = typeof index !== "number";
|
|
32
|
-
|
|
33
|
-
return `m/${network}'/${chainId}'/${account}'/${change}${shortPath ? "" : `/${index}`}`;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
27
|
export function wrapWithThrow<T>(fn: () => T, errorKey?: ErrorKeys) {
|
|
37
28
|
try {
|
|
38
29
|
return fn();
|
|
@@ -45,7 +36,7 @@ export function wrapWithThrow<T>(fn: () => T, errorKey?: ErrorKeys) {
|
|
|
45
36
|
}
|
|
46
37
|
}
|
|
47
38
|
|
|
48
|
-
export
|
|
39
|
+
export function getChainIdentifier<T extends Chain>(chain: T) {
|
|
49
40
|
switch (chain) {
|
|
50
41
|
case Chain.THORChain:
|
|
51
42
|
return `${chain}.RUNE`;
|
|
@@ -59,4 +50,17 @@ export const getChainIdentifier = (chain: Chain) => {
|
|
|
59
50
|
default:
|
|
60
51
|
return `${chain}.${chain}`;
|
|
61
52
|
}
|
|
62
|
-
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const skipWarnings = ["production", "test"].includes(process.env.NODE_ENV || "");
|
|
56
|
+
const warnings = new Set();
|
|
57
|
+
export function warnOnce(condition: boolean, warning: string) {
|
|
58
|
+
if (!skipWarnings && condition) {
|
|
59
|
+
if (warnings.has(warning)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
warnings.add(warning);
|
|
64
|
+
console.warn(warning);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -28,15 +28,6 @@ declare const window: {
|
|
|
28
28
|
braveSolana: Todo;
|
|
29
29
|
} & Window;
|
|
30
30
|
|
|
31
|
-
// declare global {
|
|
32
|
-
// interface Window {
|
|
33
|
-
// ethereum: EthereumWindowProvider;
|
|
34
|
-
// trustwallet: EthereumWindowProvider;
|
|
35
|
-
// coinbaseWalletExtension: EthereumWindowProvider;
|
|
36
|
-
// braveSolana: Todo;
|
|
37
|
-
// }
|
|
38
|
-
// }
|
|
39
|
-
|
|
40
31
|
type NetworkParams = {
|
|
41
32
|
chainId: ChainId;
|
|
42
33
|
chainName: string;
|
|
@@ -42,16 +42,17 @@ describe("AssetValue", () => {
|
|
|
42
42
|
|
|
43
43
|
expect(atomDerived.toString()).toBe("THOR.ATOM");
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
45
|
+
// TODO:
|
|
46
|
+
// const radixXWBTC = new AssetValue({
|
|
47
|
+
// identifier:
|
|
48
|
+
// "RADIX.XWBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75",
|
|
49
|
+
// decimal: 8,
|
|
50
|
+
// value: 11112222,
|
|
51
|
+
// });
|
|
52
|
+
|
|
53
|
+
// expect(radixXWBTC.toString()).toBe(
|
|
54
|
+
// "RADIX.XWBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75",
|
|
55
|
+
// )
|
|
55
56
|
});
|
|
56
57
|
});
|
|
57
58
|
|
|
@@ -254,7 +255,7 @@ describe("AssetValue", () => {
|
|
|
254
255
|
);
|
|
255
256
|
});
|
|
256
257
|
|
|
257
|
-
test("creates AssetValue with _ symbol", async () => {
|
|
258
|
+
test.todo("creates AssetValue with _ symbol", async () => {
|
|
258
259
|
const radixXWBTC = await AssetValue.from({
|
|
259
260
|
asset: "XRD.XWBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75",
|
|
260
261
|
asyncTokenLookup: true,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { red, yellow } from "picocolors";
|
|
1
2
|
import {
|
|
2
3
|
type CommonAssetString,
|
|
3
4
|
CommonAssetStrings,
|
|
@@ -6,6 +7,7 @@ import {
|
|
|
6
7
|
getDecimal,
|
|
7
8
|
isGasAsset,
|
|
8
9
|
} from "../helpers/asset.ts";
|
|
10
|
+
import { warnOnce } from "../helpers/others.ts";
|
|
9
11
|
import { validateIdentifier } from "../helpers/validators.ts";
|
|
10
12
|
import { BaseDecimal, Chain, type ChainId, ChainToChainId } from "../types/chains.ts";
|
|
11
13
|
import type { TokenNames, TokenTax } from "../types/tokens.ts";
|
|
@@ -112,9 +114,7 @@ export class AssetValue extends BigIntArithmetics {
|
|
|
112
114
|
...fromAssetOrChain
|
|
113
115
|
}: T & AssetValueFromParams): ConditionalAssetValueReturn<T> {
|
|
114
116
|
const parsedValue = value instanceof BigIntArithmetics ? value.getValue("string") : value;
|
|
115
|
-
|
|
116
117
|
const isFromChain = "chain" in fromAssetOrChain;
|
|
117
|
-
|
|
118
118
|
const assetOrChain = isFromChain ? fromAssetOrChain.chain : fromAssetOrChain.asset;
|
|
119
119
|
|
|
120
120
|
const isFromCommonAssetOrChain =
|
|
@@ -126,11 +126,21 @@ export class AssetValue extends BigIntArithmetics {
|
|
|
126
126
|
: { identifier: assetOrChain, decimal: undefined };
|
|
127
127
|
|
|
128
128
|
const { chain, isSynthetic } = getAssetInfo(unsafeIdentifier);
|
|
129
|
+
const token = staticTokensMap.get(unsafeIdentifier.toUpperCase() as TokenNames);
|
|
130
|
+
const tokenDecimal = token?.decimal || commonAssetDecimal;
|
|
131
|
+
|
|
132
|
+
warnOnce(
|
|
133
|
+
!(asyncTokenLookup || tokenDecimal),
|
|
134
|
+
yellow(
|
|
135
|
+
`Couldn't find static decimal for ${red(unsafeIdentifier)} (Using default ${red(BaseDecimal[chain])} decimal as fallback).
|
|
136
|
+
This can result in incorrect calculations and mess with amount sent on transactions.
|
|
137
|
+
You can load static assets by installing @swapkit/tokens package and calling AssetValue.loadStaticAssets()
|
|
138
|
+
or by passing asyncTokenLookup: true to the from() function, which will make it async and return a promise.`,
|
|
139
|
+
),
|
|
140
|
+
);
|
|
129
141
|
|
|
130
|
-
const {
|
|
131
|
-
|
|
132
|
-
) || {
|
|
133
|
-
decimal: commonAssetDecimal || BaseDecimal[chain],
|
|
142
|
+
const { decimal, identifier, tax } = token || {
|
|
143
|
+
decimal: tokenDecimal || BaseDecimal[chain],
|
|
134
144
|
identifier: unsafeIdentifier,
|
|
135
145
|
};
|
|
136
146
|
|
|
@@ -10,8 +10,11 @@ const errorCodes = {
|
|
|
10
10
|
core_plugin_swap_not_found: 10007,
|
|
11
11
|
core_approve_asset_target_invalid: 10008,
|
|
12
12
|
core_explorer_unsupported_chain: 10009,
|
|
13
|
+
core_verify_message_not_supported: 10010,
|
|
13
14
|
core_chain_halted: 10099,
|
|
14
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Core - Wallet
|
|
17
|
+
*/
|
|
15
18
|
core_wallet_connection_not_found: 10100,
|
|
16
19
|
core_wallet_xdefi_not_installed: 10101,
|
|
17
20
|
core_wallet_evmwallet_not_installed: 10102,
|
|
@@ -24,6 +27,7 @@ const errorCodes = {
|
|
|
24
27
|
core_wallet_keepkey_not_installed: 10109,
|
|
25
28
|
core_wallet_talisman_not_installed: 10110,
|
|
26
29
|
core_wallet_not_keypair_wallet: 10111,
|
|
30
|
+
core_wallet_sign_message_not_supported: 10110,
|
|
27
31
|
/**
|
|
28
32
|
* Core - Swap
|
|
29
33
|
*/
|
|
@@ -80,6 +84,7 @@ const errorCodes = {
|
|
|
80
84
|
wallet_trezor_failed_to_get_address: 20503,
|
|
81
85
|
wallet_talisman_not_enabled: 20601,
|
|
82
86
|
wallet_talisman_not_found: 20602,
|
|
87
|
+
wallet_polkadot_not_found: 20701,
|
|
83
88
|
/**
|
|
84
89
|
* Chainflip
|
|
85
90
|
*/
|
|
@@ -105,12 +110,24 @@ const errorCodes = {
|
|
|
105
110
|
* SwapKit API
|
|
106
111
|
*/
|
|
107
112
|
api_v2_invalid_response: 50001,
|
|
108
|
-
|
|
109
113
|
/**
|
|
110
114
|
* Toolboxes
|
|
111
115
|
*/
|
|
112
116
|
toolbox_cosmos_signer_not_defined: 90101,
|
|
113
117
|
toolbox_cosmos_no_accounts_found: 90102,
|
|
118
|
+
toolbox_cosmos_verify_signature_no_pubkey: 90103,
|
|
119
|
+
toolbox_evm_no_abi_fragment: 90201,
|
|
120
|
+
toolbox_evm_no_signer: 90202,
|
|
121
|
+
toolbox_evm_no_signer_address: 90203,
|
|
122
|
+
toolbox_evm_no_from_address: 90204,
|
|
123
|
+
toolbox_evm_no_contract_address: 90205,
|
|
124
|
+
toolbox_evm_no_fee_data: 90206,
|
|
125
|
+
toolbox_evm_no_gas_price: 90207,
|
|
126
|
+
toolbox_evm_no_to_address: 90208,
|
|
127
|
+
toolbox_evm_invalid_gas_asset_address: 90209,
|
|
128
|
+
toolbox_evm_provider_not_eip1193_compatible: 90210,
|
|
129
|
+
toolbox_evm_error_estimating_gas_limit: 90211,
|
|
130
|
+
toolbox_evm_error_sending_transaction: 90212,
|
|
114
131
|
/**
|
|
115
132
|
* Helpers
|
|
116
133
|
*/
|
|
@@ -122,6 +139,10 @@ const errorCodes = {
|
|
|
122
139
|
helpers_invalid_memo_type: 99005,
|
|
123
140
|
helpers_failed_to_switch_network: 99103,
|
|
124
141
|
helpers_not_found_provider: 99200,
|
|
142
|
+
/**
|
|
143
|
+
* Anything else
|
|
144
|
+
*/
|
|
145
|
+
not_implemented: 99999,
|
|
125
146
|
} as const;
|
|
126
147
|
|
|
127
148
|
export type ErrorKeys = keyof typeof errorCodes;
|
package/src/types/commonTypes.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { AssetValue } from "../modules/assetValue.ts";
|
|
2
1
|
import type { Chain, CosmosChain, EVMChain, UTXOChain } from "./chains.ts";
|
|
3
|
-
import type {
|
|
2
|
+
import type { ChainWallet } from "./wallet.ts";
|
|
4
3
|
|
|
5
4
|
export type ConnectConfig = {
|
|
6
5
|
stagenet?: boolean;
|
|
@@ -49,22 +48,14 @@ export type ConnectConfig = {
|
|
|
49
48
|
chainflipBrokerUrl?: string;
|
|
50
49
|
};
|
|
51
50
|
|
|
52
|
-
export type AddChainWalletParams<T extends Chain> = {
|
|
53
|
-
address: string;
|
|
54
|
-
balance: AssetValue[];
|
|
55
|
-
walletType: WalletOption;
|
|
56
|
-
chain: T;
|
|
57
|
-
[key: string]: Todo;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
51
|
type ApisType = { [key in UTXOChain]?: string | Todo } & {
|
|
61
52
|
[key in EVMChain]?: string | Todo;
|
|
62
53
|
} & {
|
|
63
54
|
[key in CosmosChain]?: string;
|
|
64
55
|
};
|
|
65
56
|
|
|
66
|
-
export type ConnectWalletParams = {
|
|
67
|
-
addChain: <T extends Chain>(params:
|
|
57
|
+
export type ConnectWalletParams<M = { [key in string]: NotWorth }> = {
|
|
58
|
+
addChain: <T extends Chain>(params: ChainWallet<T> & M) => void;
|
|
68
59
|
apis: ApisType;
|
|
69
60
|
config: ConnectConfig;
|
|
70
61
|
rpcUrls: { [chain in Chain]?: string };
|
package/src/types/sdk.ts
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
|
+
import type { CovalentApiType, EthplorerApiType } from "@swapkit/toolbox-evm";
|
|
2
|
+
import type { BlockchairApiType } from "@swapkit/toolbox-utxo";
|
|
1
3
|
import { z } from "zod";
|
|
4
|
+
|
|
2
5
|
import type { AssetValue } from "../modules/assetValue";
|
|
6
|
+
import type { Chain, CosmosChain, UTXOChain } from "./chains";
|
|
3
7
|
import type { QuoteResponseRoute } from "./quotes";
|
|
4
8
|
|
|
9
|
+
type CovalentChains =
|
|
10
|
+
| Chain.BinanceSmartChain
|
|
11
|
+
| Chain.Polygon
|
|
12
|
+
| Chain.Avalanche
|
|
13
|
+
| Chain.Arbitrum
|
|
14
|
+
| Chain.Optimism;
|
|
15
|
+
|
|
16
|
+
export type ChainApis = { [key in CovalentChains]?: CovalentApiType } & {
|
|
17
|
+
[key in Chain.Ethereum]?: EthplorerApiType;
|
|
18
|
+
} & { [key in CosmosChain]?: Todo } & {
|
|
19
|
+
[key in UTXOChain]?: BlockchairApiType;
|
|
20
|
+
};
|
|
21
|
+
|
|
5
22
|
export type GenericSwapParams = {
|
|
6
23
|
buyAsset?: AssetValue;
|
|
7
24
|
sellAsset?: AssetValue;
|
|
@@ -37,10 +54,10 @@ export type WalletTxParams = {
|
|
|
37
54
|
};
|
|
38
55
|
|
|
39
56
|
export enum MemoType {
|
|
57
|
+
NAME_REGISTER = "~",
|
|
40
58
|
BOND = "BOND",
|
|
41
59
|
DEPOSIT = "+",
|
|
42
60
|
LEAVE = "LEAVE",
|
|
43
|
-
NAME_REGISTER = "~",
|
|
44
61
|
UNBOND = "UNBOND",
|
|
45
62
|
WITHDRAW = "-",
|
|
46
63
|
OPEN_LOAN = "$+",
|
package/src/types/wallet.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
import type { CosmosWallets, ThorchainWallets } from "@swapkit/toolbox-cosmos";
|
|
2
|
+
import type { EVMWallets } from "@swapkit/toolbox-evm";
|
|
3
|
+
import type { SolanaWallet } from "@swapkit/toolbox-solana";
|
|
4
|
+
import type { SubstrateWallets } from "@swapkit/toolbox-substrate";
|
|
5
|
+
import type { UTXOWallets } from "@swapkit/toolbox-utxo";
|
|
1
6
|
import type { Eip1193Provider } from "ethers";
|
|
7
|
+
|
|
2
8
|
import type { AssetValue } from "../modules/assetValue";
|
|
3
9
|
import type { Chain } from "./chains";
|
|
10
|
+
import type { ConnectWalletParams } from "./commonTypes";
|
|
4
11
|
|
|
5
12
|
declare global {
|
|
6
13
|
interface WindowEventMap {
|
|
@@ -8,6 +15,8 @@ declare global {
|
|
|
8
15
|
}
|
|
9
16
|
}
|
|
10
17
|
|
|
18
|
+
export type { CosmosWallets, ThorchainWallets, EVMWallets, SubstrateWallets, UTXOWallets };
|
|
19
|
+
|
|
11
20
|
export enum WalletOption {
|
|
12
21
|
BRAVE = "BRAVE",
|
|
13
22
|
COINBASE_MOBILE = "COINBASE_MOBILE",
|
|
@@ -22,6 +31,7 @@ export enum WalletOption {
|
|
|
22
31
|
OKX = "OKX",
|
|
23
32
|
OKX_MOBILE = "OKX_MOBILE",
|
|
24
33
|
PHANTOM = "PHANTOM",
|
|
34
|
+
POLKADOT_JS = "POLKADOT_JS",
|
|
25
35
|
RADIX_WALLET = "RADIX_WALLET",
|
|
26
36
|
TREZOR = "TREZOR",
|
|
27
37
|
TALISMAN = "TALISMAN",
|
|
@@ -36,17 +46,37 @@ export enum LedgerErrorCode {
|
|
|
36
46
|
TC_NotFound = 65535,
|
|
37
47
|
}
|
|
38
48
|
|
|
39
|
-
export type ChainWallet = {
|
|
40
|
-
chain:
|
|
49
|
+
export type ChainWallet<T extends Chain> = {
|
|
50
|
+
chain: T;
|
|
41
51
|
address: string;
|
|
42
52
|
balance: AssetValue[];
|
|
43
53
|
walletType: WalletOption;
|
|
44
54
|
disconnect?: () => void;
|
|
55
|
+
signMessage?: (message: string) => Promise<string>;
|
|
45
56
|
};
|
|
46
57
|
|
|
47
58
|
export type EmptyWallet = { [key in Chain]?: unknown };
|
|
48
59
|
export type BaseWallet<T extends EmptyWallet | Record<string, unknown>> = {
|
|
49
|
-
[key in Chain]: ChainWallet & (T extends EmptyWallet ? T[key] :
|
|
60
|
+
[key in Chain]: ChainWallet<key> & (T extends EmptyWallet ? T[key] : never);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type FullWallet = BaseWallet<
|
|
64
|
+
EVMWallets & UTXOWallets & CosmosWallets & ThorchainWallets & SubstrateWallets & SolanaWallet
|
|
65
|
+
>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @deprecated use FullWallet instead
|
|
69
|
+
*/
|
|
70
|
+
export type Wallet = FullWallet;
|
|
71
|
+
|
|
72
|
+
export type SwapKitWallet<ConnectParams extends Todo[]> = (
|
|
73
|
+
params: ConnectWalletParams,
|
|
74
|
+
) => (...connectParams: ConnectParams) => boolean | Promise<boolean>;
|
|
75
|
+
|
|
76
|
+
export type SwapKitPluginParams<Config = {}> = {
|
|
77
|
+
getWallet: <T extends Chain>(chain: T) => FullWallet[T];
|
|
78
|
+
stagenet?: boolean;
|
|
79
|
+
config: Config;
|
|
50
80
|
};
|
|
51
81
|
|
|
52
82
|
export type EIP6963ProviderInfo = {
|