@swapkit/helpers 1.0.0-rc.112 → 1.0.0-rc.114
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 +2 -2897
- package/dist/index.js.map +11 -11
- package/package.json +6 -15
- package/src/helpers/__tests__/memo.test.ts +54 -73
- package/src/helpers/memo.ts +152 -45
- package/src/helpers/web3wallets.ts +1 -0
- package/src/modules/assetValue.ts +1 -0
- package/src/modules/bigIntArithmetics.ts +2 -6
- package/src/modules/swapKitError.ts +11 -13
- package/src/types/chains.ts +5 -1
- package/src/types/derivationPath.ts +3 -1
- package/src/types/network.ts +3 -1
- package/src/types/wallet.ts +16 -16
package/package.json
CHANGED
|
@@ -2,17 +2,8 @@
|
|
|
2
2
|
"author": "swapkit-oss",
|
|
3
3
|
"description": "SwapKit - Helpers",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
},
|
|
8
|
-
"devDependencies": {
|
|
9
|
-
"@swapkit/tokens": "1.0.0-rc.54",
|
|
10
|
-
"bun-types": "1.1.8",
|
|
11
|
-
"ethers": "6.11.1"
|
|
12
|
-
},
|
|
13
|
-
"peerDependencies": {
|
|
14
|
-
"@swapkit/tokens": "1.0.0-rc.54",
|
|
15
|
-
"ky": "1.2.3",
|
|
5
|
+
"@swapkit/tokens": "1.0.0-rc.56",
|
|
6
|
+
"ky": "1.3.0",
|
|
16
7
|
"zod": "3.23.8"
|
|
17
8
|
},
|
|
18
9
|
"files": [
|
|
@@ -30,13 +21,13 @@
|
|
|
30
21
|
},
|
|
31
22
|
"scripts": {
|
|
32
23
|
"build": "bun run ./build.ts",
|
|
33
|
-
"clean": "rm -rf
|
|
34
|
-
"lint": "biome check --
|
|
24
|
+
"clean": "rm -rf dist node_modules *.tsbuildinfo",
|
|
25
|
+
"lint": "biome check --write ./src",
|
|
35
26
|
"test": "bun test",
|
|
36
|
-
"test:coverage": "
|
|
27
|
+
"test:coverage": "bun test --coverage",
|
|
37
28
|
"type-check": "tsc --noEmit"
|
|
38
29
|
},
|
|
39
30
|
"type": "module",
|
|
40
31
|
"types": "./src/index.ts",
|
|
41
|
-
"version": "1.0.0-rc.
|
|
32
|
+
"version": "1.0.0-rc.114"
|
|
42
33
|
}
|
|
@@ -1,91 +1,72 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
import { Chain, MemoType } from "../../types";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
getMemoForDeposit,
|
|
6
|
+
getMemoForLeaveAndBond,
|
|
7
|
+
getMemoForNameRegister,
|
|
8
|
+
getMemoForSaverDeposit,
|
|
9
|
+
getMemoForSaverWithdraw,
|
|
10
|
+
getMemoForWithdraw,
|
|
11
|
+
} from "../memo.ts";
|
|
5
12
|
|
|
6
|
-
describe("
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
[MemoType.BOND, "BOND:ABC123"],
|
|
11
|
-
];
|
|
12
|
-
|
|
13
|
-
for (const [memoType, expected = ""] of nodeMemos) {
|
|
14
|
-
test(`returns correct memo for ${memoType}`, () => {
|
|
15
|
-
const result = getMemoFor(memoType as MemoType, { address: "ABC123" });
|
|
16
|
-
expect(result).toBe(expected);
|
|
17
|
-
});
|
|
18
|
-
}
|
|
13
|
+
describe("getMemoForSaverDeposit", () => {
|
|
14
|
+
test("returns correct memo for single side", () => {
|
|
15
|
+
const result = getMemoForSaverDeposit({ chain: Chain.Ethereum, symbol: "ETH" });
|
|
16
|
+
expect(result).toBe("+:ETH/ETH");
|
|
19
17
|
});
|
|
18
|
+
});
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
test("returns correct memo for Thorname Register", () => {
|
|
28
|
-
const result = getMemoFor(MemoType.NAME_REGISTER, {
|
|
29
|
-
name: "thorname",
|
|
30
|
-
chain: "BNB",
|
|
31
|
-
address: "0xABC123",
|
|
32
|
-
owner: "0xDEF456",
|
|
33
|
-
});
|
|
34
|
-
expect(result).toBe("~:thorname:BNB:0xABC123:0xDEF456");
|
|
20
|
+
describe("getMemoForSaverWithdraw", () => {
|
|
21
|
+
test("returns correct memo for single side", () => {
|
|
22
|
+
const result = getMemoForSaverWithdraw({
|
|
23
|
+
basisPoints: 5000,
|
|
24
|
+
chain: Chain.Ethereum,
|
|
25
|
+
symbol: "ETH",
|
|
35
26
|
});
|
|
27
|
+
expect(result).toBe("-:ETH/ETH:5000");
|
|
28
|
+
});
|
|
29
|
+
});
|
|
36
30
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
address: "0xABC123",
|
|
42
|
-
owner: "0xDEF456",
|
|
43
|
-
});
|
|
44
|
-
expect(result).toBe("~:mayaname:BNB:0xABC123:0xDEF456");
|
|
45
|
-
});
|
|
31
|
+
describe("getMemoForLeaveAndBond", () => {
|
|
32
|
+
test("returns correct memo for Leave", () => {
|
|
33
|
+
const result = getMemoForLeaveAndBond({ address: "ABC123", type: MemoType.LEAVE });
|
|
34
|
+
expect(result).toBe("LEAVE:ABC123");
|
|
46
35
|
});
|
|
47
36
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
singleSide: true,
|
|
54
|
-
});
|
|
55
|
-
expect(result).toBe("+:ETH/ETH");
|
|
56
|
-
});
|
|
37
|
+
test("returns correct memo for Bond", () => {
|
|
38
|
+
const result = getMemoForLeaveAndBond({ address: "ABC123", type: MemoType.BOND });
|
|
39
|
+
expect(result).toBe("BOND:ABC123");
|
|
40
|
+
});
|
|
41
|
+
});
|
|
57
42
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
43
|
+
describe("getMemoForNameRegister", () => {
|
|
44
|
+
test("returns correct memo for single side", () => {
|
|
45
|
+
const result = getMemoForNameRegister({
|
|
46
|
+
name: "asdfg",
|
|
47
|
+
chain: Chain.Ethereum,
|
|
48
|
+
owner: "thor1234",
|
|
49
|
+
address: "0xaasd123",
|
|
65
50
|
});
|
|
51
|
+
expect(result).toBe("~:asdfg:ETH:0xaasd123:thor1234");
|
|
66
52
|
});
|
|
53
|
+
});
|
|
67
54
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
basisPoints: 10000,
|
|
75
|
-
singleSide: true,
|
|
76
|
-
});
|
|
77
|
-
expect(result).toBe("-:BTC/BTC:10000");
|
|
78
|
-
});
|
|
55
|
+
describe("getMemoForDeposit", () => {
|
|
56
|
+
test("returns correct memo for single side", () => {
|
|
57
|
+
const result = getMemoForDeposit({ chain: Chain.Ethereum, symbol: "ETH" });
|
|
58
|
+
expect(result).toBe("+:ETH.ETH");
|
|
59
|
+
});
|
|
60
|
+
});
|
|
79
61
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
});
|
|
88
|
-
expect(result).toBe("-:ETH.ETH:100:ETH.ETH");
|
|
62
|
+
describe("getMemoForWithdraw", () => {
|
|
63
|
+
test("returns correct memo for single side", () => {
|
|
64
|
+
const result = getMemoForWithdraw({
|
|
65
|
+
chain: Chain.Ethereum,
|
|
66
|
+
symbol: "ETH",
|
|
67
|
+
ticker: "ETH",
|
|
68
|
+
basisPoints: 100,
|
|
89
69
|
});
|
|
70
|
+
expect(result).toBe("-:ETH.ETH:100");
|
|
90
71
|
});
|
|
91
72
|
});
|
package/src/helpers/memo.ts
CHANGED
|
@@ -1,17 +1,130 @@
|
|
|
1
1
|
import { Chain } from "../types/chains";
|
|
2
2
|
import { MemoType } from "../types/sdk";
|
|
3
3
|
|
|
4
|
-
export type NameRegisterParam = {
|
|
5
|
-
name: string;
|
|
6
|
-
chain: string;
|
|
7
|
-
address: string;
|
|
8
|
-
owner?: string;
|
|
9
|
-
preferredAsset?: string;
|
|
10
|
-
expiryBlock?: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
4
|
type WithChain<T extends {}> = T & { chain: Chain };
|
|
14
5
|
|
|
6
|
+
type WithAffiliate<T extends {}> = T & { affiliateAddress?: string; affiliateBasisPoints?: number };
|
|
7
|
+
|
|
8
|
+
function addAffiliate(memo: string, { affiliateAddress, affiliateBasisPoints }: WithAffiliate<{}>) {
|
|
9
|
+
const affiliatePart = affiliateAddress ? `:${affiliateAddress}:${affiliateBasisPoints || 0}` : "";
|
|
10
|
+
|
|
11
|
+
return `${memo}${affiliatePart}`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getPoolIdentifier({ chain, symbol }: { chain: Chain; symbol: string }) {
|
|
15
|
+
switch (chain) {
|
|
16
|
+
case Chain.Bitcoin:
|
|
17
|
+
case Chain.Dogecoin:
|
|
18
|
+
case Chain.Litecoin:
|
|
19
|
+
return chain.slice(0, 1).toLowerCase();
|
|
20
|
+
case Chain.BitcoinCash:
|
|
21
|
+
return "c";
|
|
22
|
+
|
|
23
|
+
default:
|
|
24
|
+
return `${chain}.${symbol}`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function getMemoForLeaveAndBond({
|
|
29
|
+
type,
|
|
30
|
+
address,
|
|
31
|
+
}: { type: MemoType.BOND | MemoType.LEAVE; address: string }) {
|
|
32
|
+
return `${type}:${address}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function getMemoForUnbond({
|
|
36
|
+
address,
|
|
37
|
+
unbondAmount,
|
|
38
|
+
}: { address: string; unbondAmount: number }) {
|
|
39
|
+
return `${MemoType.UNBOND}:${address}:${unbondAmount}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function getMemoForNameRegister({
|
|
43
|
+
name,
|
|
44
|
+
chain,
|
|
45
|
+
address,
|
|
46
|
+
owner,
|
|
47
|
+
}: { name: string; chain: string; address: string; owner?: string }) {
|
|
48
|
+
const baseMemo = `${MemoType.NAME_REGISTER}:${name}:${chain}:${address}`;
|
|
49
|
+
const ownerAssignmentOrChangePart = owner ? `:${owner}` : "";
|
|
50
|
+
|
|
51
|
+
return `${baseMemo}${ownerAssignmentOrChangePart}`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function getMemoForLoan(
|
|
55
|
+
memoType: MemoType.OPEN_LOAN | MemoType.CLOSE_LOAN,
|
|
56
|
+
{
|
|
57
|
+
asset,
|
|
58
|
+
address,
|
|
59
|
+
minAmount,
|
|
60
|
+
...affiliate
|
|
61
|
+
}: WithAffiliate<{
|
|
62
|
+
address: string;
|
|
63
|
+
asset: string;
|
|
64
|
+
minAmount?: string;
|
|
65
|
+
}>,
|
|
66
|
+
) {
|
|
67
|
+
const baseMemo = `${memoType}:${asset}:${address}`;
|
|
68
|
+
const minAmountPart = minAmount ? `:${minAmount}` : "";
|
|
69
|
+
|
|
70
|
+
return addAffiliate(`${baseMemo}${minAmountPart}`, affiliate);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function getMemoForSaverDeposit({
|
|
74
|
+
chain,
|
|
75
|
+
symbol,
|
|
76
|
+
...affiliate
|
|
77
|
+
}: WithAffiliate<{ chain: Chain; symbol: string }>) {
|
|
78
|
+
return addAffiliate(`${MemoType.DEPOSIT}:${chain}/${symbol}`, affiliate);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function getMemoForDeposit({
|
|
82
|
+
chain,
|
|
83
|
+
symbol,
|
|
84
|
+
address,
|
|
85
|
+
}: { chain: Chain; symbol: string; address?: string }) {
|
|
86
|
+
const poolIdentifier = getPoolIdentifier({ chain, symbol });
|
|
87
|
+
const addressPart = address ? `:${address}` : "";
|
|
88
|
+
|
|
89
|
+
return `${MemoType.DEPOSIT}:${poolIdentifier}${addressPart}`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function getMemoForSaverWithdraw({
|
|
93
|
+
chain,
|
|
94
|
+
symbol,
|
|
95
|
+
basisPoints,
|
|
96
|
+
...affiliate
|
|
97
|
+
}: WithAffiliate<{ chain: Chain; symbol: string; basisPoints: number }>) {
|
|
98
|
+
return addAffiliate(`${MemoType.WITHDRAW}:${chain}/${symbol}:${basisPoints}`, affiliate);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function getMemoForWithdraw({
|
|
102
|
+
chain,
|
|
103
|
+
symbol,
|
|
104
|
+
ticker,
|
|
105
|
+
basisPoints,
|
|
106
|
+
targetAsset,
|
|
107
|
+
...affiliate
|
|
108
|
+
}: WithAffiliate<{
|
|
109
|
+
chain: Chain;
|
|
110
|
+
symbol: string;
|
|
111
|
+
ticker: string;
|
|
112
|
+
basisPoints: number;
|
|
113
|
+
targetAsset?: string;
|
|
114
|
+
}>) {
|
|
115
|
+
const shortenedSymbol =
|
|
116
|
+
chain === "ETH" && ticker !== "ETH" ? `${ticker}-${symbol.slice(-3)}` : symbol;
|
|
117
|
+
const targetPart = targetAsset ? `:${targetAsset}` : "";
|
|
118
|
+
|
|
119
|
+
return addAffiliate(
|
|
120
|
+
`${MemoType.WITHDRAW}:${chain}.${shortenedSymbol}:${basisPoints}${targetPart}`,
|
|
121
|
+
affiliate,
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @deprecated - Use separate functions per each memo type like getMemoForDeposit, getMemoForWithdraw, etc.
|
|
127
|
+
*/
|
|
15
128
|
export type MemoOptions<T extends MemoType> = {
|
|
16
129
|
[MemoType.BOND]: { address: string };
|
|
17
130
|
[MemoType.LEAVE]: { address: string };
|
|
@@ -26,68 +139,62 @@ export type MemoOptions<T extends MemoType> = {
|
|
|
26
139
|
targetAssetString?: string;
|
|
27
140
|
singleSide?: boolean;
|
|
28
141
|
}>;
|
|
29
|
-
[MemoType.NAME_REGISTER]:
|
|
142
|
+
[MemoType.NAME_REGISTER]: { name: string; chain: string; address: string };
|
|
30
143
|
}[T];
|
|
31
144
|
|
|
145
|
+
/**
|
|
146
|
+
* @deprecated - Use separate functions per each memo type like getMemoForDeposit, getMemoForWithdraw, etc.
|
|
147
|
+
*/
|
|
32
148
|
export const getMemoFor = <T extends MemoType>(memoType: T, options: MemoOptions<T>) => {
|
|
33
149
|
switch (memoType) {
|
|
34
150
|
case MemoType.LEAVE:
|
|
35
151
|
case MemoType.BOND: {
|
|
36
152
|
const { address } = options as MemoOptions<MemoType.BOND>;
|
|
37
|
-
return
|
|
153
|
+
return getMemoForLeaveAndBond({ type: memoType, address });
|
|
38
154
|
}
|
|
39
155
|
|
|
40
156
|
case MemoType.UNBOND: {
|
|
41
157
|
const { address, unbondAmount } = options as MemoOptions<MemoType.UNBOND>;
|
|
42
|
-
return
|
|
158
|
+
return getMemoForUnbond({ address, unbondAmount });
|
|
43
159
|
}
|
|
44
160
|
|
|
45
161
|
case MemoType.NAME_REGISTER: {
|
|
46
|
-
|
|
47
|
-
|
|
162
|
+
return getMemoForNameRegister(options as MemoOptions<MemoType.NAME_REGISTER>);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
case MemoType.OPEN_LOAN:
|
|
166
|
+
case MemoType.CLOSE_LOAN: {
|
|
167
|
+
return getMemoForLoan(memoType, options as MemoOptions<MemoType.OPEN_LOAN>);
|
|
48
168
|
}
|
|
49
169
|
|
|
50
170
|
case MemoType.DEPOSIT: {
|
|
51
171
|
const { chain, symbol, address, singleSide } = options as MemoOptions<MemoType.DEPOSIT>;
|
|
52
172
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return "d";
|
|
59
|
-
case Chain.BitcoinCash:
|
|
60
|
-
return "c";
|
|
61
|
-
default:
|
|
62
|
-
return `${chain}.${symbol}`;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
return singleSide
|
|
67
|
-
? `${memoType}:${chain}/${symbol}`
|
|
68
|
-
: `${memoType}:${getPoolIdentifier(chain, symbol)}:${address || ""}`;
|
|
173
|
+
if (singleSide) {
|
|
174
|
+
return getMemoForSaverDeposit({ chain, symbol });
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return getMemoForDeposit({ chain, symbol, address });
|
|
69
178
|
}
|
|
70
179
|
|
|
71
180
|
case MemoType.WITHDRAW: {
|
|
72
|
-
const {
|
|
73
|
-
|
|
181
|
+
const {
|
|
182
|
+
chain,
|
|
183
|
+
ticker,
|
|
184
|
+
symbol,
|
|
185
|
+
basisPoints,
|
|
186
|
+
targetAssetString: targetAsset,
|
|
187
|
+
singleSide,
|
|
188
|
+
} = options as MemoOptions<MemoType.WITHDRAW>;
|
|
74
189
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const assetDivider = singleSide ? "/" : ".";
|
|
79
|
-
|
|
80
|
-
return `${memoType}:${chain}${assetDivider}${shortenedSymbol}:${basisPoints}${target}`;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
case MemoType.OPEN_LOAN:
|
|
84
|
-
case MemoType.CLOSE_LOAN: {
|
|
85
|
-
const { asset, address } = options as MemoOptions<MemoType.OPEN_LOAN>;
|
|
190
|
+
if (singleSide) {
|
|
191
|
+
return getMemoForSaverWithdraw({ chain, symbol, basisPoints });
|
|
192
|
+
}
|
|
86
193
|
|
|
87
|
-
return
|
|
194
|
+
return getMemoForWithdraw({ chain, ticker, symbol, basisPoints, targetAsset });
|
|
88
195
|
}
|
|
89
196
|
|
|
90
197
|
default:
|
|
91
|
-
|
|
198
|
+
throw new Error(`Unsupported memo type: ${memoType}`);
|
|
92
199
|
}
|
|
93
200
|
};
|
|
@@ -13,6 +13,7 @@ export type EthereumWindowProvider = BrowserProvider & {
|
|
|
13
13
|
isMetaMask?: boolean;
|
|
14
14
|
isOkxWallet?: boolean;
|
|
15
15
|
isTrust?: boolean;
|
|
16
|
+
isTalisman?: boolean;
|
|
16
17
|
on: (event: string, callback?: () => void) => void;
|
|
17
18
|
overrideIsMetaMask?: boolean;
|
|
18
19
|
request: <T = unknown>(args: { method: string; params?: unknown[] }) => Promise<T>;
|
|
@@ -177,6 +177,7 @@ export class AssetValue extends BigIntArithmetics {
|
|
|
177
177
|
|
|
178
178
|
static fromChainOrSignature(assetString: CommonAssetString, value: NumberPrimitives = 0) {
|
|
179
179
|
const { decimal, identifier } = getCommonAssetInfo(assetString);
|
|
180
|
+
|
|
180
181
|
return new AssetValue({ value: safeValue(value, decimal), decimal, identifier });
|
|
181
182
|
}
|
|
182
183
|
|
|
@@ -42,9 +42,7 @@ export function formatBigIntToSafeValue({
|
|
|
42
42
|
// Check if we need to round up
|
|
43
43
|
if (Number.parseInt(decimalString[bigIntDecimal] || "0") >= 5) {
|
|
44
44
|
// Increment the last decimal place and slice off the rest
|
|
45
|
-
decimalString = `${decimalString.substring(0, bigIntDecimal - 1)}${(
|
|
46
|
-
Number.parseInt(decimalString[bigIntDecimal - 1] || "0") + 1
|
|
47
|
-
).toString()}`;
|
|
45
|
+
decimalString = `${decimalString.substring(0, bigIntDecimal - 1)}${(Number.parseInt(decimalString[bigIntDecimal - 1] || "0") + 1).toString()}`;
|
|
48
46
|
} else {
|
|
49
47
|
// Just slice off the extra digits
|
|
50
48
|
decimalString = decimalString.substring(0, bigIntDecimal);
|
|
@@ -277,9 +275,7 @@ export class BigIntArithmetics {
|
|
|
277
275
|
// Check if we need to round up
|
|
278
276
|
if (Number.parseInt(decimalString[bigIntDecimal] || "0") >= 5) {
|
|
279
277
|
// Increment the last decimal place and slice off the rest
|
|
280
|
-
decimalString = `${decimalString.substring(0, bigIntDecimal - 1)}${(
|
|
281
|
-
Number.parseInt(decimalString[bigIntDecimal - 1] || "0") + 1
|
|
282
|
-
).toString()}`;
|
|
278
|
+
decimalString = `${decimalString.substring(0, bigIntDecimal - 1)}${(Number.parseInt(decimalString[bigIntDecimal - 1] || "0") + 1).toString()}`;
|
|
283
279
|
} else {
|
|
284
280
|
// Just slice off the extra digits
|
|
285
281
|
decimalString = decimalString.substring(0, bigIntDecimal);
|
|
@@ -11,7 +11,6 @@ const errorMessages = {
|
|
|
11
11
|
core_plugin_swap_not_found: 10007,
|
|
12
12
|
core_approve_asset_target_invalid: 10008,
|
|
13
13
|
core_chain_halted: 10099,
|
|
14
|
-
|
|
15
14
|
/**
|
|
16
15
|
* Core - Wallet Connection
|
|
17
16
|
*/
|
|
@@ -39,12 +38,12 @@ const errorMessages = {
|
|
|
39
38
|
* Core - Transaction
|
|
40
39
|
*/
|
|
41
40
|
core_transaction_deposit_error: 10301,
|
|
42
|
-
|
|
41
|
+
core_transaction_create_liquidity_base_error: 10302,
|
|
43
42
|
core_transaction_create_liquidity_asset_error: 10303,
|
|
44
43
|
core_transaction_create_liquidity_invalid_params: 10304,
|
|
45
44
|
core_transaction_add_liquidity_invalid_params: 10305,
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
core_transaction_add_liquidity_base_address: 10306,
|
|
46
|
+
core_transaction_add_liquidity_base_error: 10307,
|
|
48
47
|
core_transaction_add_liquidity_asset_error: 10308,
|
|
49
48
|
core_transaction_withdraw_error: 10309,
|
|
50
49
|
core_transaction_deposit_to_pool_error: 10310,
|
|
@@ -53,38 +52,37 @@ const errorMessages = {
|
|
|
53
52
|
core_transaction_invalid_sender_address: 10313,
|
|
54
53
|
core_transaction_deposit_server_error: 10314,
|
|
55
54
|
core_transaction_user_rejected: 10315,
|
|
56
|
-
core_transaction_create_liquidity_cacao_error: 10316,
|
|
57
|
-
core_transaction_add_liquidity_no_cacao_address: 10306,
|
|
58
|
-
core_transaction_add_liquidity_cacao_error: 10307,
|
|
59
|
-
|
|
60
55
|
/**
|
|
61
56
|
* Wallets
|
|
62
57
|
*/
|
|
58
|
+
wallet_connection_rejected_by_user: 20000,
|
|
63
59
|
wallet_ledger_connection_error: 20001,
|
|
64
60
|
wallet_ledger_connection_claimed: 20002,
|
|
65
61
|
wallet_ledger_get_address_error: 20003,
|
|
66
62
|
wallet_ledger_device_not_found: 20004,
|
|
67
63
|
wallet_ledger_device_locked: 20005,
|
|
68
|
-
|
|
64
|
+
wallet_phantom_not_found: 20101,
|
|
65
|
+
wallet_xdefi_not_found: 20201,
|
|
66
|
+
wallet_xdefi_failed_to_add_or_switch_network: 20202,
|
|
69
67
|
/**
|
|
70
68
|
* Chainflip
|
|
71
69
|
*/
|
|
72
70
|
chainflip_channel_error: 30001,
|
|
73
71
|
chainflip_broker_recipient_error: 30002,
|
|
74
|
-
|
|
75
72
|
/**
|
|
76
73
|
* THORChain
|
|
77
74
|
*/
|
|
78
|
-
|
|
75
|
+
thorchain_chain_halted: 40001,
|
|
76
|
+
thorchain_trading_halted: 40002,
|
|
79
77
|
/**
|
|
80
78
|
* SwapKit API
|
|
81
79
|
*/
|
|
82
|
-
api_v2_invalid_response:
|
|
80
|
+
api_v2_invalid_response: 50001,
|
|
83
81
|
|
|
84
82
|
/**
|
|
85
83
|
* Helpers
|
|
86
84
|
*/
|
|
87
|
-
helpers_number_different_decimals:
|
|
85
|
+
helpers_number_different_decimals: 99001,
|
|
88
86
|
} as const;
|
|
89
87
|
|
|
90
88
|
export type ErrorKeys = keyof typeof errorMessages;
|
package/src/types/chains.ts
CHANGED
|
@@ -20,6 +20,7 @@ export enum Chain {
|
|
|
20
20
|
Polygon = "MATIC",
|
|
21
21
|
Radix = "XRD",
|
|
22
22
|
THORChain = "THOR",
|
|
23
|
+
Solana = "SOL",
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export type WalletChain = Exclude<Chain, Chain.Chainflip | Chain.Radix>;
|
|
@@ -52,6 +53,7 @@ export enum ChainId {
|
|
|
52
53
|
Radix = "radix-mainnet",
|
|
53
54
|
THORChain = "thorchain-mainnet-v1",
|
|
54
55
|
THORChainStagenet = "thorchain-stagenet-v2",
|
|
56
|
+
Solana = "solana",
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
export const ChainIdToChain: Record<ChainId, Chain> = {
|
|
@@ -82,6 +84,7 @@ export const ChainIdToChain: Record<ChainId, Chain> = {
|
|
|
82
84
|
[ChainId.Radix]: Chain.Radix,
|
|
83
85
|
[ChainId.THORChainStagenet]: Chain.THORChain,
|
|
84
86
|
[ChainId.THORChain]: Chain.THORChain,
|
|
87
|
+
[ChainId.Solana]: Chain.Solana,
|
|
85
88
|
};
|
|
86
89
|
|
|
87
90
|
type ChainNameType = keyof typeof Chain;
|
|
@@ -106,9 +109,10 @@ export enum BaseDecimal {
|
|
|
106
109
|
MATIC = 18,
|
|
107
110
|
MAYA = 10,
|
|
108
111
|
OP = 18,
|
|
112
|
+
SOL = 9,
|
|
109
113
|
THOR = 8,
|
|
110
|
-
ZEC = 8,
|
|
111
114
|
XRD = 18,
|
|
115
|
+
ZEC = 8,
|
|
112
116
|
}
|
|
113
117
|
|
|
114
118
|
export type SubstrateChain = Chain.Polkadot | Chain.Chainflip;
|
|
@@ -27,8 +27,9 @@ export enum DerivationPath {
|
|
|
27
27
|
MATIC = "m/44'/60'/0'/0",
|
|
28
28
|
MAYA = "m/44'/931'/0'/0",
|
|
29
29
|
OP = "m/44'/60'/0'/0",
|
|
30
|
-
|
|
30
|
+
SOL = "m/44'/501'/0'/0",
|
|
31
31
|
THOR = "m/44'/931'/0'/0",
|
|
32
|
+
XRD = "////",
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
export type DerivationPathArray = [number, number, number, number, number?];
|
|
@@ -49,6 +50,7 @@ export const NetworkDerivationPath: Record<Chain, DerivationPathArray> = {
|
|
|
49
50
|
MATIC: [44, 60, 0, 0, 0],
|
|
50
51
|
MAYA: [44, 931, 0, 0, 0],
|
|
51
52
|
OP: [44, 60, 0, 0, 0],
|
|
53
|
+
SOL: [44, 501, 0, 0, 0],
|
|
52
54
|
THOR: [44, 931, 0, 0, 0],
|
|
53
55
|
|
|
54
56
|
// Polkadot and related network derivation path is not number based
|
package/src/types/network.ts
CHANGED
|
@@ -20,6 +20,7 @@ export enum RPCUrl {
|
|
|
20
20
|
Radix = "https://radix-mainnet.rpc.grove.city/v1/326002fc/core",
|
|
21
21
|
THORChain = "https://rpc.thorswap.net",
|
|
22
22
|
THORChainStagenet = "https://stagenet-rpc.ninerealms.com",
|
|
23
|
+
Solana = "https://mainnet.helius-rpc.com/?api-key=2cbe3ae6-cfc5-4141-a093-0055d0fa3d80",
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export enum ExplorerUrl {
|
|
@@ -38,8 +39,9 @@ export enum ExplorerUrl {
|
|
|
38
39
|
Litecoin = "https://blockchair.com/litecoin",
|
|
39
40
|
Maya = "https://www.mayascan.org",
|
|
40
41
|
Optimism = "https://optimistic.etherscan.io",
|
|
41
|
-
Polkadot = "https://polkadot.subscan.io
|
|
42
|
+
Polkadot = "https://polkadot.subscan.io",
|
|
42
43
|
Polygon = "https://polygonscan.com",
|
|
43
44
|
Radix = "https://dashboard.radixdlt.com",
|
|
44
45
|
THORChain = "https://runescan.io",
|
|
46
|
+
Solana = "https://solscan.io",
|
|
45
47
|
}
|
package/src/types/wallet.ts
CHANGED
|
@@ -9,23 +9,25 @@ declare global {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export enum WalletOption {
|
|
12
|
-
|
|
13
|
-
KEEPKEY = "KEEPKEY",
|
|
14
|
-
XDEFI = "XDEFI",
|
|
15
|
-
METAMASK = "METAMASK",
|
|
16
|
-
COINBASE_WEB = "COINBASE_WEB",
|
|
12
|
+
BRAVE = "BRAVE",
|
|
17
13
|
COINBASE_MOBILE = "COINBASE_MOBILE",
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
COINBASE_WEB = "COINBASE_WEB",
|
|
15
|
+
EIP6963 = "EIP6963",
|
|
16
|
+
EXODUS = "EXODUS",
|
|
17
|
+
KEEPKEY = "KEEPKEY",
|
|
21
18
|
KEPLR = "KEPLR",
|
|
19
|
+
KEYSTORE = "KEYSTORE",
|
|
20
|
+
LEDGER = "LEDGER",
|
|
21
|
+
METAMASK = "METAMASK",
|
|
22
22
|
OKX = "OKX",
|
|
23
23
|
OKX_MOBILE = "OKX_MOBILE",
|
|
24
|
-
|
|
25
|
-
WALLETCONNECT = "WALLETCONNECT",
|
|
26
|
-
EIP6963 = "EIP6963",
|
|
27
|
-
EXODUS = "EXODUS",
|
|
24
|
+
PHANTOM = "PHANTOM",
|
|
28
25
|
RADIX_WALLET = "RADIX_WALLET",
|
|
26
|
+
TREZOR = "TREZOR",
|
|
27
|
+
TALISMAN = "TALISMAN",
|
|
28
|
+
TRUSTWALLET_WEB = "TRUSTWALLET_WEB",
|
|
29
|
+
WALLETCONNECT = "WALLETCONNECT",
|
|
30
|
+
XDEFI = "XDEFI",
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
export enum LedgerErrorCode {
|
|
@@ -43,10 +45,8 @@ export type ChainWallet = {
|
|
|
43
45
|
};
|
|
44
46
|
|
|
45
47
|
export type EmptyWallet = { [key in Chain]?: unknown };
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// @ts-expect-error
|
|
49
|
-
[key in Chain]: ChainWallet & T[key];
|
|
48
|
+
export type BaseWallet<T extends EmptyWallet | Record<string, unknown>> = {
|
|
49
|
+
[key in Chain]: ChainWallet & (T extends EmptyWallet ? T[key] : unknown);
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
export type EIP6963ProviderInfo = {
|