@swapkit/helpers 1.2.3 → 1.3.0
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 +3 -3
- package/dist/index.js.map +8 -10
- package/package.json +9 -9
- package/src/helpers/memo.ts +106 -148
- package/src/index.ts +1 -0
- package/src/modules/requestClient.ts +6 -4
- package/src/types/index.ts +0 -3
- package/src/types/quotes.ts +113 -363
- package/src/types/sdk.ts +3 -83
- package/src/types/abis/erc20.ts +0 -99
- package/src/types/abis/mayaEvmVaults.ts +0 -331
- package/src/types/abis/tcEthVault.ts +0 -496
package/package.json
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
"author": "swapkit-oss",
|
|
3
3
|
"description": "SwapKit - Helpers",
|
|
4
4
|
"dependencies": {
|
|
5
|
+
"@swapkit/contracts": "1.0.4",
|
|
5
6
|
"@swapkit/tokens": "1.0.3",
|
|
6
|
-
"picocolors": "1.0.1"
|
|
7
|
-
"zod": "3.23.8"
|
|
7
|
+
"picocolors": "1.0.1"
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
|
-
"@swapkit/toolbox-cosmos": "1.0.
|
|
11
|
-
"@swapkit/toolbox-evm": "1.1.
|
|
12
|
-
"@swapkit/toolbox-solana": "1.0.
|
|
13
|
-
"@swapkit/toolbox-radix": "1.0.
|
|
14
|
-
"@swapkit/toolbox-substrate": "1.1.
|
|
15
|
-
"@swapkit/toolbox-utxo": "1.0.
|
|
10
|
+
"@swapkit/toolbox-cosmos": "1.0.16",
|
|
11
|
+
"@swapkit/toolbox-evm": "1.1.9",
|
|
12
|
+
"@swapkit/toolbox-solana": "1.0.14",
|
|
13
|
+
"@swapkit/toolbox-radix": "1.0.14",
|
|
14
|
+
"@swapkit/toolbox-substrate": "1.1.9",
|
|
15
|
+
"@swapkit/toolbox-utxo": "1.0.14"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"src/",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
},
|
|
38
38
|
"type": "module",
|
|
39
39
|
"types": "./src/index.ts",
|
|
40
|
-
"version": "1.
|
|
40
|
+
"version": "1.3.0"
|
|
41
41
|
}
|
package/src/helpers/memo.ts
CHANGED
|
@@ -2,111 +2,19 @@ import { SwapKitError } from "../modules/swapKitError";
|
|
|
2
2
|
import { Chain } from "../types/chains";
|
|
3
3
|
import { MemoType } from "../types/sdk";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
type WithAffiliate<T extends {}> = T & {
|
|
8
|
-
affiliateAddress?: string;
|
|
9
|
-
affiliateBasisPoints?: number;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
function addAffiliate(memo: string, { affiliateAddress, affiliateBasisPoints }: WithAffiliate<{}>) {
|
|
13
|
-
const affiliatePart = affiliateAddress ? `:${affiliateAddress}:${affiliateBasisPoints || 0}` : "";
|
|
14
|
-
|
|
15
|
-
return `${memo}${affiliatePart}`;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function getPoolIdentifier({
|
|
19
|
-
chain,
|
|
20
|
-
symbol,
|
|
21
|
-
}: {
|
|
22
|
-
chain: Chain;
|
|
23
|
-
symbol: string;
|
|
24
|
-
}) {
|
|
25
|
-
switch (chain) {
|
|
26
|
-
case Chain.Bitcoin:
|
|
27
|
-
case Chain.Dogecoin:
|
|
28
|
-
case Chain.Litecoin:
|
|
29
|
-
return chain.slice(0, 1).toLowerCase();
|
|
30
|
-
case Chain.BitcoinCash:
|
|
31
|
-
return "c";
|
|
32
|
-
|
|
33
|
-
default:
|
|
34
|
-
return `${chain}.${symbol}`;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function getMemoForLeaveAndBond({
|
|
39
|
-
type,
|
|
40
|
-
address,
|
|
41
|
-
}: {
|
|
42
|
-
type: MemoType.BOND | MemoType.LEAVE;
|
|
43
|
-
address: string;
|
|
44
|
-
}) {
|
|
5
|
+
export function getMemoForLeaveAndBond({ type, address }: BondOrLeaveParams) {
|
|
45
6
|
return `${type}:${address}`;
|
|
46
7
|
}
|
|
47
8
|
|
|
48
|
-
export function getMemoForUnbond({
|
|
49
|
-
address,
|
|
50
|
-
unbondAmount,
|
|
51
|
-
}: {
|
|
52
|
-
address: string;
|
|
53
|
-
unbondAmount: number;
|
|
54
|
-
}) {
|
|
9
|
+
export function getMemoForUnbond({ address, unbondAmount }: UnbondParams) {
|
|
55
10
|
return `${MemoType.UNBOND}:${address}:${unbondAmount}`;
|
|
56
11
|
}
|
|
57
12
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}: {
|
|
64
|
-
name: string;
|
|
65
|
-
chain: string;
|
|
66
|
-
address: string;
|
|
67
|
-
owner?: string;
|
|
68
|
-
}) {
|
|
69
|
-
const baseMemo = `${MemoType.NAME_REGISTER}:${name}:${chain}:${address}`;
|
|
70
|
-
const ownerAssignmentOrChangePart = owner ? `:${owner}` : "";
|
|
71
|
-
|
|
72
|
-
return `${baseMemo}${ownerAssignmentOrChangePart}`;
|
|
73
|
-
}
|
|
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
|
-
|
|
93
|
-
export function getMemoForLoan(
|
|
94
|
-
memoType: MemoType.OPEN_LOAN | MemoType.CLOSE_LOAN,
|
|
95
|
-
{
|
|
96
|
-
asset,
|
|
97
|
-
address,
|
|
98
|
-
minAmount,
|
|
99
|
-
...affiliate
|
|
100
|
-
}: WithAffiliate<{
|
|
101
|
-
address: string;
|
|
102
|
-
asset: string;
|
|
103
|
-
minAmount?: string;
|
|
104
|
-
}>,
|
|
105
|
-
) {
|
|
106
|
-
const baseMemo = `${memoType}:${asset}:${address}`;
|
|
107
|
-
const minAmountPart = minAmount ? `:${minAmount}` : "";
|
|
108
|
-
|
|
109
|
-
return addAffiliate(`${baseMemo}${minAmountPart}`, affiliate);
|
|
13
|
+
/**
|
|
14
|
+
* Deposit
|
|
15
|
+
*/
|
|
16
|
+
export function getMemoForRunePoolDeposit(affiliate?: WithAffiliate<{}>) {
|
|
17
|
+
return addAffiliate(MemoType.RUNEPOOL_DEPOSIT, affiliate);
|
|
110
18
|
}
|
|
111
19
|
|
|
112
20
|
export function getMemoForSaverDeposit({
|
|
@@ -128,12 +36,14 @@ export function getMemoForDeposit({
|
|
|
128
36
|
address?: string;
|
|
129
37
|
}>) {
|
|
130
38
|
const poolIdentifier = getPoolIdentifier({ chain, symbol });
|
|
131
|
-
const
|
|
132
|
-
const addressPart = address ? `:${address}` : hasAffiliateInfo ? ":" : "";
|
|
39
|
+
const addressPart = address ? `:${address}:` : ":";
|
|
133
40
|
|
|
134
41
|
return addAffiliate(`${MemoType.DEPOSIT}:${poolIdentifier}${addressPart}`, affiliate);
|
|
135
42
|
}
|
|
136
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Withdraw
|
|
46
|
+
*/
|
|
137
47
|
export function getMemoForSaverWithdraw({
|
|
138
48
|
chain,
|
|
139
49
|
symbol,
|
|
@@ -148,13 +58,7 @@ export function getMemoForWithdraw({
|
|
|
148
58
|
ticker,
|
|
149
59
|
basisPoints,
|
|
150
60
|
targetAsset,
|
|
151
|
-
}: {
|
|
152
|
-
chain: Chain;
|
|
153
|
-
symbol: string;
|
|
154
|
-
ticker: string;
|
|
155
|
-
basisPoints: number;
|
|
156
|
-
targetAsset?: string;
|
|
157
|
-
}) {
|
|
61
|
+
}: WithdrawParams) {
|
|
158
62
|
const shortenedSymbol =
|
|
159
63
|
chain === "ETH" && ticker !== "ETH" ? `${ticker}-${symbol.slice(-3)}` : symbol;
|
|
160
64
|
const targetPart = targetAsset ? `:${targetAsset}` : "";
|
|
@@ -162,10 +66,6 @@ export function getMemoForWithdraw({
|
|
|
162
66
|
return `${MemoType.WITHDRAW}:${chain}.${shortenedSymbol}:${basisPoints}${targetPart}`;
|
|
163
67
|
}
|
|
164
68
|
|
|
165
|
-
export function getMemoForRunePoolDeposit() {
|
|
166
|
-
return `${MemoType.RUNEPOOL_DEPOSIT}`;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
69
|
export function getMemoForRunePoolWithdraw({
|
|
170
70
|
basisPoints,
|
|
171
71
|
...affiliate
|
|
@@ -174,62 +74,120 @@ export function getMemoForRunePoolWithdraw({
|
|
|
174
74
|
}
|
|
175
75
|
|
|
176
76
|
/**
|
|
177
|
-
*
|
|
77
|
+
* TNS
|
|
78
|
+
*/
|
|
79
|
+
export function getMemoForNameRegister({ name, chain, address, owner }: NameRegisterParams) {
|
|
80
|
+
const baseMemo = `${MemoType.NAME_REGISTER}:${name}:${chain}:${address}`;
|
|
81
|
+
const ownerAssignmentOrChangePart = owner ? `:${owner}` : "";
|
|
82
|
+
|
|
83
|
+
return `${baseMemo}${ownerAssignmentOrChangePart}`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function getMemoForNamePreferredAssetRegister({
|
|
87
|
+
name,
|
|
88
|
+
chain,
|
|
89
|
+
asset,
|
|
90
|
+
payout,
|
|
91
|
+
owner,
|
|
92
|
+
}: PreferredAssetRegisterParams) {
|
|
93
|
+
return `${MemoType.NAME_REGISTER}:${name}:${chain}:${payout}:${owner}:${asset}`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function getMemoForLoan(
|
|
97
|
+
memoType: MemoType.OPEN_LOAN | MemoType.CLOSE_LOAN,
|
|
98
|
+
{
|
|
99
|
+
asset,
|
|
100
|
+
address,
|
|
101
|
+
minAmount,
|
|
102
|
+
...affiliate
|
|
103
|
+
}: WithAffiliate<{ address: string; asset: string; minAmount?: string }>,
|
|
104
|
+
) {
|
|
105
|
+
const baseMemo = `${memoType}:${asset}:${address}`;
|
|
106
|
+
const minAmountPart = minAmount ? `:${minAmount}` : "";
|
|
107
|
+
|
|
108
|
+
return addAffiliate(`${baseMemo}${minAmountPart}`, affiliate);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Internal helpers
|
|
178
113
|
*/
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
114
|
+
function addAffiliate(
|
|
115
|
+
memo: string,
|
|
116
|
+
{ affiliateAddress, affiliateBasisPoints }: WithAffiliate<{}> = {},
|
|
117
|
+
) {
|
|
118
|
+
const affiliatedMemo = `${memo}${affiliateAddress ? `:${affiliateAddress}:${affiliateBasisPoints || 0}` : ""}`;
|
|
119
|
+
|
|
120
|
+
return affiliatedMemo.endsWith(":") ? affiliatedMemo.slice(0, -1) : affiliatedMemo;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function getPoolIdentifier({
|
|
124
|
+
chain,
|
|
125
|
+
symbol,
|
|
126
|
+
}: {
|
|
127
|
+
chain: Chain;
|
|
128
|
+
symbol: string;
|
|
129
|
+
}) {
|
|
130
|
+
switch (chain) {
|
|
131
|
+
case Chain.Bitcoin:
|
|
132
|
+
case Chain.Dogecoin:
|
|
133
|
+
case Chain.Litecoin:
|
|
134
|
+
return chain.slice(0, 1).toLowerCase();
|
|
135
|
+
case Chain.BitcoinCash:
|
|
136
|
+
return "c";
|
|
137
|
+
|
|
138
|
+
default:
|
|
139
|
+
return `${chain}.${symbol}`;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
type WithAffiliate<T extends {}> = T & {
|
|
144
|
+
affiliateAddress?: string;
|
|
145
|
+
affiliateBasisPoints?: number;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
type BondOrLeaveParams = { type: MemoType.BOND | MemoType.LEAVE; address: string };
|
|
149
|
+
type UnbondParams = { address: string; unbondAmount: number };
|
|
150
|
+
type NameRegisterParams = { name: string; chain: string; address: string; owner?: string };
|
|
151
|
+
type PreferredAssetRegisterParams = {
|
|
152
|
+
name: string;
|
|
153
|
+
chain: Chain;
|
|
154
|
+
asset: string;
|
|
155
|
+
payout: string;
|
|
156
|
+
owner: string;
|
|
157
|
+
};
|
|
158
|
+
type WithdrawParams = {
|
|
159
|
+
chain: Chain;
|
|
160
|
+
symbol: string;
|
|
161
|
+
ticker: string;
|
|
162
|
+
basisPoints: number;
|
|
163
|
+
targetAsset?: string;
|
|
164
|
+
};
|
|
205
165
|
|
|
206
166
|
/**
|
|
207
167
|
* @deprecated - Use separate functions per each memo type like getMemoForDeposit, getMemoForWithdraw, etc.
|
|
208
168
|
*/
|
|
209
|
-
export const getMemoFor = <T extends MemoType>(memoType: T, options:
|
|
169
|
+
export const getMemoFor = <T extends MemoType>(memoType: T, options: NotWorth) => {
|
|
210
170
|
switch (memoType) {
|
|
211
171
|
case MemoType.LEAVE:
|
|
212
172
|
case MemoType.BOND: {
|
|
213
|
-
|
|
214
|
-
return getMemoForLeaveAndBond({ type: memoType, address });
|
|
173
|
+
return getMemoForLeaveAndBond({ type: memoType, address: options?.address });
|
|
215
174
|
}
|
|
216
175
|
|
|
217
176
|
case MemoType.UNBOND: {
|
|
218
|
-
|
|
219
|
-
return getMemoForUnbond({ address, unbondAmount });
|
|
177
|
+
return getMemoForUnbond({ address: options?.address, unbondAmount: options?.unbondAmount });
|
|
220
178
|
}
|
|
221
179
|
|
|
222
180
|
case MemoType.NAME_REGISTER: {
|
|
223
|
-
return getMemoForNameRegister(options
|
|
181
|
+
return getMemoForNameRegister(options);
|
|
224
182
|
}
|
|
225
183
|
|
|
226
184
|
case MemoType.OPEN_LOAN:
|
|
227
185
|
case MemoType.CLOSE_LOAN: {
|
|
228
|
-
return getMemoForLoan(memoType, options
|
|
186
|
+
return getMemoForLoan(memoType, options);
|
|
229
187
|
}
|
|
230
188
|
|
|
231
189
|
case MemoType.DEPOSIT: {
|
|
232
|
-
const { chain, symbol, address, singleSide } = options
|
|
190
|
+
const { chain, symbol, address, singleSide } = options;
|
|
233
191
|
|
|
234
192
|
if (singleSide) {
|
|
235
193
|
return getMemoForSaverDeposit({ chain, symbol });
|
|
@@ -246,7 +204,7 @@ export const getMemoFor = <T extends MemoType>(memoType: T, options: MemoOptions
|
|
|
246
204
|
basisPoints,
|
|
247
205
|
targetAssetString: targetAsset,
|
|
248
206
|
singleSide,
|
|
249
|
-
} = options
|
|
207
|
+
} = options;
|
|
250
208
|
|
|
251
209
|
if (singleSide) {
|
|
252
210
|
return getMemoForSaverWithdraw({ chain, symbol, basisPoints });
|
package/src/index.ts
CHANGED
|
@@ -22,10 +22,12 @@ export function setRequestClientConfig({ apiKey, ...config }: Options) {
|
|
|
22
22
|
async function fetchWithConfig(url: string, options: Options) {
|
|
23
23
|
const { apiKey, ...config } = clientConfig;
|
|
24
24
|
const { searchParams, json, body } = options;
|
|
25
|
-
const headers = {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
const headers = {
|
|
26
|
+
...defaultRequestHeaders,
|
|
27
|
+
...config.headers,
|
|
28
|
+
...options.headers,
|
|
29
|
+
...(json ? { "Content-Type": "application/json" } : {}),
|
|
30
|
+
} as Record<string, string>;
|
|
29
31
|
|
|
30
32
|
const bodyToSend = json ? JSON.stringify(json) : body;
|
|
31
33
|
|