@swapkit/helpers 3.0.0-beta.11 → 3.0.0-beta.13
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/api/index.cjs +2 -2
- package/dist/api/index.cjs.map +5 -5
- package/dist/api/index.js +2 -2
- package/dist/api/index.js.map +5 -5
- package/dist/{chunk-6vvdbb6s.js → chunk-7shcm26h.js} +3 -3
- package/dist/{chunk-6vvdbb6s.js.map → chunk-7shcm26h.js.map} +1 -1
- package/dist/chunk-8fdws4se.js +4 -0
- package/dist/chunk-8fdws4se.js.map +10 -0
- package/dist/{chunk-dbsrwnw2.js → chunk-b8hashv0.js} +3 -3
- package/dist/{chunk-dbsrwnw2.js.map → chunk-b8hashv0.js.map} +1 -1
- package/dist/{chunk-kdcsgh3q.js → chunk-bf0ph1bk.js} +3 -3
- package/dist/{chunk-kdcsgh3q.js.map → chunk-bf0ph1bk.js.map} +1 -1
- package/dist/{chunk-mmwvr2y8.js → chunk-bh986mnf.js} +3 -3
- package/dist/{chunk-mmwvr2y8.js.map → chunk-bh986mnf.js.map} +1 -1
- package/dist/{chunk-ahpfxkx0.js → chunk-dzypg9sp.js} +3 -3
- package/dist/{chunk-ahpfxkx0.js.map → chunk-dzypg9sp.js.map} +1 -1
- package/dist/{chunk-wmxwvv8c.js → chunk-ghdhtvtt.js} +3 -3
- package/dist/{chunk-wmxwvv8c.js.map → chunk-ghdhtvtt.js.map} +1 -1
- package/dist/{chunk-fr86y3rx.js → chunk-jhmhh7ax.js} +3 -3
- package/dist/{chunk-fr86y3rx.js.map → chunk-jhmhh7ax.js.map} +1 -1
- package/dist/{chunk-ekd1k975.js → chunk-nm1av1e6.js} +3 -3
- package/dist/{chunk-ekd1k975.js.map → chunk-nm1av1e6.js.map} +1 -1
- package/dist/{chunk-wrjh857m.js → chunk-rarep8vg.js} +3 -3
- package/dist/{chunk-wrjh857m.js.map → chunk-rarep8vg.js.map} +1 -1
- package/dist/{chunk-kr69v1tm.js → chunk-rr043vwc.js} +3 -3
- package/dist/{chunk-kr69v1tm.js.map → chunk-rr043vwc.js.map} +1 -1
- package/dist/{chunk-3wnfcm30.js → chunk-s82pm7xc.js} +2 -2
- package/dist/{chunk-3wnfcm30.js.map → chunk-s82pm7xc.js.map} +1 -1
- package/dist/chunk-sb9hymk1.js +3 -0
- package/dist/chunk-sb9hymk1.js.map +10 -0
- package/dist/{chunk-tq87xn7m.js → chunk-tn4e7zrk.js} +3 -3
- package/dist/{chunk-tq87xn7m.js.map → chunk-tn4e7zrk.js.map} +1 -1
- package/dist/{chunk-z8emzpyc.js → chunk-vadspc46.js} +3 -3
- package/dist/{chunk-z8emzpyc.js.map → chunk-vadspc46.js.map} +1 -1
- package/dist/{chunk-xyczdrny.js → chunk-vgg88vt8.js} +3 -3
- package/dist/{chunk-xyczdrny.js.map → chunk-vgg88vt8.js.map} +1 -1
- package/dist/{chunk-q8xy3739.js → chunk-wssz50sc.js} +3 -3
- package/dist/{chunk-q8xy3739.js.map → chunk-wssz50sc.js.map} +1 -1
- package/dist/contracts/index.js +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +15 -16
- package/dist/index.js +3 -3
- package/dist/index.js.map +15 -16
- package/dist/tokens/index.js +2 -2
- package/dist/tokens/index.js.map +2 -2
- package/package.json +2 -2
- package/src/api/microgard/types.ts +0 -3
- package/src/api/midgard/endpoints.ts +1 -65
- package/src/api/midgard/types.ts +0 -49
- package/src/api/swapkitApi/endpoints.ts +1 -2
- package/src/api/swapkitApi/types.ts +1 -1
- package/src/modules/__tests__/assetValue.test.ts +42 -0
- package/src/modules/__tests__/swapKitNumber.test.ts +4 -5
- package/src/modules/assetValue.ts +12 -28
- package/src/modules/bigIntArithmetics.ts +12 -1
- package/src/modules/requestClient.ts +36 -22
- package/src/modules/swapKitError.ts +294 -105
- package/src/types/chains.ts +45 -37
- package/src/types/derivationPath.ts +1 -0
- package/src/types/quotes.ts +0 -2
- package/src/types/sdk.ts +0 -2
- package/src/types/wallet.ts +2 -0
- package/src/utils/__tests__/memo.test.ts +0 -20
- package/src/utils/asset.ts +3 -2
- package/src/utils/memo.ts +5 -42
- package/src/utils/others.ts +1 -2
- package/src/utils/wallets.ts +4 -1
|
@@ -8,29 +8,9 @@ import {
|
|
|
8
8
|
getMemoForNameRegister,
|
|
9
9
|
getMemoForRunePoolDeposit,
|
|
10
10
|
getMemoForRunePoolWithdraw,
|
|
11
|
-
getMemoForSaverDeposit,
|
|
12
|
-
getMemoForSaverWithdraw,
|
|
13
11
|
getMemoForWithdraw,
|
|
14
12
|
} from "../memo";
|
|
15
13
|
|
|
16
|
-
describe("getMemoForSaverDeposit", () => {
|
|
17
|
-
test("returns correct memo for single side", () => {
|
|
18
|
-
const result = getMemoForSaverDeposit({ chain: Chain.Ethereum, symbol: "ETH" });
|
|
19
|
-
expect(result).toBe("+:ETH/ETH");
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe("getMemoForSaverWithdraw", () => {
|
|
24
|
-
test("returns correct memo for single side", () => {
|
|
25
|
-
const result = getMemoForSaverWithdraw({
|
|
26
|
-
basisPoints: 5000,
|
|
27
|
-
chain: Chain.Ethereum,
|
|
28
|
-
symbol: "ETH",
|
|
29
|
-
});
|
|
30
|
-
expect(result).toBe("-:ETH/ETH:5000");
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
14
|
describe("getMemoForLeaveAndBond", () => {
|
|
35
15
|
test("returns correct memo for Leave", () => {
|
|
36
16
|
const result = getMemoForLeaveAndBond({ address: "ABC123", type: MemoType.LEAVE });
|
package/src/utils/asset.ts
CHANGED
|
@@ -53,7 +53,7 @@ async function getContractDecimals({ chain, to }: { chain: EVMChain; to: string
|
|
|
53
53
|
|
|
54
54
|
return Number.parseInt(BigInt(result || BaseDecimal[chain]).toString());
|
|
55
55
|
} catch (error) {
|
|
56
|
-
console.error(error);
|
|
56
|
+
console.error(`Failed to fetch contract decimals for ${to} on ${chain}:`, error);
|
|
57
57
|
return BaseDecimal[chain];
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -77,7 +77,7 @@ async function getRadixAssetDecimal(symbol: string) {
|
|
|
77
77
|
|
|
78
78
|
return manager.divisibility.value.divisibility;
|
|
79
79
|
} catch (error) {
|
|
80
|
-
console.error(error);
|
|
80
|
+
console.error(`Failed to fetch Radix asset decimal for ${symbol}:`, error);
|
|
81
81
|
return BaseDecimal[Chain.Radix];
|
|
82
82
|
}
|
|
83
83
|
}
|
|
@@ -139,6 +139,7 @@ export const getCommonAssetInfo = (assetString: CommonAssetString) => {
|
|
|
139
139
|
Chain.Kujira,
|
|
140
140
|
Chain.Ripple,
|
|
141
141
|
Chain.Polkadot,
|
|
142
|
+
Chain.Tron,
|
|
142
143
|
(asset) => ({ identifier: `${asset}.${asset}`, decimal }),
|
|
143
144
|
)
|
|
144
145
|
.with(Chain.Radix, "XRD.XRD", () => ({ identifier: "XRD.XRD", decimal }))
|
package/src/utils/memo.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { match } from "ts-pattern";
|
|
1
2
|
import { Chain } from "../types/chains";
|
|
2
3
|
import { MemoType } from "../types/sdk";
|
|
3
4
|
|
|
@@ -16,14 +17,6 @@ export function getMemoForRunePoolDeposit(affiliate?: WithAffiliate<{}>) {
|
|
|
16
17
|
return addAffiliate(MemoType.RUNEPOOL_DEPOSIT, affiliate);
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
export function getMemoForSaverDeposit({
|
|
20
|
-
chain,
|
|
21
|
-
symbol,
|
|
22
|
-
...affiliate
|
|
23
|
-
}: WithAffiliate<{ chain: Chain; symbol: string }>) {
|
|
24
|
-
return addAffiliate(`${MemoType.DEPOSIT}:${chain}/${symbol}`, affiliate);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
20
|
export function getMemoForDeposit({
|
|
28
21
|
chain,
|
|
29
22
|
symbol,
|
|
@@ -43,14 +36,6 @@ export function getMemoForDeposit({
|
|
|
43
36
|
/**
|
|
44
37
|
* Withdraw
|
|
45
38
|
*/
|
|
46
|
-
export function getMemoForSaverWithdraw({
|
|
47
|
-
chain,
|
|
48
|
-
symbol,
|
|
49
|
-
basisPoints,
|
|
50
|
-
}: { chain: Chain; symbol: string; basisPoints: number }) {
|
|
51
|
-
return `${MemoType.WITHDRAW}:${chain}/${symbol}:${basisPoints}`;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
39
|
export function getMemoForWithdraw({
|
|
55
40
|
chain,
|
|
56
41
|
symbol,
|
|
@@ -92,21 +77,6 @@ export function getMemoForNamePreferredAssetRegister({
|
|
|
92
77
|
return `${MemoType.NAME_REGISTER}:${name}:${chain}:${payout}:${owner}:${asset}`;
|
|
93
78
|
}
|
|
94
79
|
|
|
95
|
-
export function getMemoForLoan(
|
|
96
|
-
memoType: MemoType.OPEN_LOAN | MemoType.CLOSE_LOAN,
|
|
97
|
-
{
|
|
98
|
-
asset,
|
|
99
|
-
address,
|
|
100
|
-
minAmount,
|
|
101
|
-
...affiliate
|
|
102
|
-
}: WithAffiliate<{ address: string; asset: string; minAmount?: string }>,
|
|
103
|
-
) {
|
|
104
|
-
const baseMemo = `${memoType}:${asset}:${address}`;
|
|
105
|
-
const minAmountPart = minAmount ? `:${minAmount}` : "";
|
|
106
|
-
|
|
107
|
-
return addAffiliate(`${baseMemo}${minAmountPart}`, affiliate);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
80
|
/**
|
|
111
81
|
* Internal helpers
|
|
112
82
|
*/
|
|
@@ -126,17 +96,10 @@ function getPoolIdentifier({
|
|
|
126
96
|
chain: Chain;
|
|
127
97
|
symbol: string;
|
|
128
98
|
}) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return chain.slice(0, 1).toLowerCase();
|
|
134
|
-
case Chain.BitcoinCash:
|
|
135
|
-
return "c";
|
|
136
|
-
|
|
137
|
-
default:
|
|
138
|
-
return `${chain}.${symbol}`;
|
|
139
|
-
}
|
|
99
|
+
return match(chain)
|
|
100
|
+
.with(Chain.Bitcoin, Chain.Dogecoin, Chain.Litecoin, () => chain.slice(0, 1).toLowerCase())
|
|
101
|
+
.with(Chain.BitcoinCash, () => "c")
|
|
102
|
+
.otherwise(() => `${chain}.${symbol}`);
|
|
140
103
|
}
|
|
141
104
|
|
|
142
105
|
type WithAffiliate<T extends {}> = T & {
|
package/src/utils/others.ts
CHANGED
|
@@ -34,7 +34,7 @@ export function wrapWithThrow<T>(fn: () => T, errorKey?: ErrorKeys) {
|
|
|
34
34
|
throw new SwapKitError(errorKey, error);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
return
|
|
37
|
+
return;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -62,7 +62,6 @@ export function warnOnce(condition: boolean, warning: string) {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
warnings.add(warning);
|
|
65
|
-
console.warn(warning);
|
|
66
65
|
}
|
|
67
66
|
}
|
|
68
67
|
|
package/src/utils/wallets.ts
CHANGED
|
@@ -70,7 +70,10 @@ export async function switchEVMWalletNetwork(
|
|
|
70
70
|
});
|
|
71
71
|
} catch (_error) {
|
|
72
72
|
if (!networkParams) {
|
|
73
|
-
throw new
|
|
73
|
+
throw new SwapKitError("helpers_failed_to_switch_network", {
|
|
74
|
+
error: _error,
|
|
75
|
+
reason: "networkParams not provided",
|
|
76
|
+
});
|
|
74
77
|
}
|
|
75
78
|
await addEVMWalletNetwork(provider, networkParams);
|
|
76
79
|
}
|