@swapkit/helpers 3.0.0-beta.2 → 3.0.0-beta.21
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 +6 -6
- package/dist/api/index.js +2 -2
- package/dist/api/index.js.map +6 -6
- 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 +18 -18
- package/dist/index.js +3 -3
- package/dist/index.js.map +18 -18
- package/dist/tokens/index.js +2 -2
- package/dist/tokens/index.js.map +2 -2
- package/package.json +6 -5
- 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 +16 -10
- package/src/api/swapkitApi/types.ts +1 -1
- package/src/api/thornode/endpoints.ts +22 -4
- package/src/api/thornode/types.ts +3 -2
- package/src/index.ts +1 -0
- package/src/modules/__tests__/assetValue.test.ts +66 -23
- package/src/modules/__tests__/swapKitNumber.test.ts +4 -5
- package/src/modules/assetValue.ts +84 -33
- package/src/modules/bigIntArithmetics.ts +12 -1
- package/src/modules/feeMultiplier.ts +87 -0
- package/src/modules/requestClient.ts +34 -23
- package/src/modules/swapKitConfig.ts +9 -1
- package/src/modules/swapKitError.ts +325 -105
- package/src/types/chains.ts +98 -44
- package/src/types/derivationPath.ts +2 -0
- package/src/types/quotes.ts +1 -2
- package/src/types/sdk.ts +0 -2
- package/src/types/wallet.ts +5 -0
- package/src/utils/__tests__/memo.test.ts +0 -20
- package/src/utils/asset.ts +18 -27
- package/src/utils/derivationPath.ts +6 -0
- package/src/utils/memo.ts +5 -42
- package/src/utils/others.ts +1 -2
- package/src/utils/wallets.ts +6 -3
package/dist/tokens/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{e as w}from"../chunk-dzypg9sp.js";import{f as C}from"../chunk-vgg88vt8.js";import{g as p}from"../chunk-wssz50sc.js";import{h as m}from"../chunk-vadspc46.js";import{i as x}from"../chunk-jhmhh7ax.js";import{j as f}from"../chunk-tn4e7zrk.js";import{k as l}from"../chunk-ghdhtvtt.js";import{l as L}from"../chunk-rarep8vg.js";import{m as e}from"../chunk-bf0ph1bk.js";import{n as V}from"../chunk-nm1av1e6.js";import{o as t}from"../chunk-bh986mnf.js";import{p as a}from"../chunk-b8hashv0.js";import{q as i}from"../chunk-rr043vwc.js";import{r as o}from"../chunk-7shcm26h.js";import{t as T}from"../chunk-s82pm7xc.js";var s={};T(s,{UniswapV3List:()=>C,UniswapV2List:()=>w,TraderjoeV2List:()=>V,ThorchainList:()=>e,SushiswapList:()=>L,PangolinList:()=>l,PancakeswapList:()=>f,OpenOceanV2List:()=>x,OneInchList:()=>m,MayaList:()=>p,JupiterList:()=>o,ChainflipList:()=>i,CaviarV1List:()=>a,CamelotV3List:()=>t});function B(O){for(let c of Object.values(s)){let r=c.tokens.find((P)=>P.identifier===O);if(r?.logoURI)return r.logoURI}return}export{s as tokenLists,B as getTokenIcon};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=3A5B936F2C5A6EC964756E2164756E21
|
package/dist/tokens/index.js.map
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import * as tokenLists from \"./lists\";\n\nexport function getTokenIcon(identifier: string): string | undefined {\n // Search through all lists for a matching token\n for (const list of Object.values(tokenLists)) {\n const token = list.tokens.find((token) => token.identifier === identifier);\n if (token?.logoURI) {\n return token.logoURI;\n }\n }\n\n return undefined;\n}\n\nexport { tokenLists };\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": "g9BAEO,IAAS,JAAY,JAAC,HAAwC,JAEnE,GAAW,AAAQ,EAAO,EAAO,JAAU,HAAG,JAC5C,DAAM,HAAQ,EAAK,OAAO,KAAK,CAAC,IAAU,EAAM,aAAe,CAAU,EACzE,GAAI,GAAO,QACT,OAAO,EAAM,QAIjB",
|
|
8
|
+
"debugId": "3A5B936F2C5A6EC964756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "swapkit-oss",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
4
|
+
"ethers": "6.14.3",
|
|
5
|
+
"ts-pattern": "5.7.1",
|
|
6
|
+
"zod": "3.25.57",
|
|
7
|
+
"zustand": "5.0.5"
|
|
7
8
|
},
|
|
8
9
|
"description": "SwapKit - Helpers",
|
|
9
10
|
"devDependencies": {
|
|
10
|
-
"@swapkit/toolboxes": "1.0.0-beta.
|
|
11
|
+
"@swapkit/toolboxes": "1.0.0-beta.31"
|
|
11
12
|
},
|
|
12
13
|
"exports": {
|
|
13
14
|
".": {
|
|
@@ -54,5 +55,5 @@
|
|
|
54
55
|
"type-check:go": "tsgo"
|
|
55
56
|
},
|
|
56
57
|
"type": "module",
|
|
57
|
-
"version": "3.0.0-beta.
|
|
58
|
+
"version": "3.0.0-beta.21"
|
|
58
59
|
}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { AssetValue, BaseDecimal, Chain, RequestClient, SwapKitNumber } from "@swapkit/helpers";
|
|
2
|
-
import type {
|
|
3
|
-
BorrowerDetails,
|
|
4
|
-
MemberDetailsMayachain,
|
|
5
|
-
MemberDetailsThorchain,
|
|
6
|
-
SaverDetails,
|
|
7
|
-
THORNameDetails,
|
|
8
|
-
} from "./types";
|
|
2
|
+
import type { MemberDetailsMayachain, MemberDetailsThorchain, THORNameDetails } from "./types";
|
|
9
3
|
|
|
10
4
|
function getMidgardBaseUrl(isThorchain = true) {
|
|
11
5
|
return isThorchain ? "https://midgard.ninerealms.com" : "https://midgard.mayachain.info";
|
|
@@ -16,18 +10,6 @@ function getNameServiceBaseUrl(isThorchain = true) {
|
|
|
16
10
|
return isThorchain ? `${baseUrl}/v2/thorname` : `${baseUrl}/v2/mayaname`;
|
|
17
11
|
}
|
|
18
12
|
|
|
19
|
-
function getBorrowerDetailRaw(baseUrl: string) {
|
|
20
|
-
return function getBorrowerDetail(address: string) {
|
|
21
|
-
return RequestClient.get<BorrowerDetails>(`${baseUrl}/v2/borrower/${address}`);
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function getSaverDetailRaw(baseUrl: string) {
|
|
26
|
-
return function getSaverDetail(address: string) {
|
|
27
|
-
return RequestClient.get<SaverDetails>(`${baseUrl}/v2/saver/${address}`);
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
13
|
function getLiquidityPositionRaw<Chain extends Chain.THORChain | Chain.Maya>(baseUrl: string) {
|
|
32
14
|
return function getLiquidityPosition(
|
|
33
15
|
address: string,
|
|
@@ -56,50 +38,10 @@ function getNamesByOwner(baseUrl: string) {
|
|
|
56
38
|
};
|
|
57
39
|
}
|
|
58
40
|
|
|
59
|
-
function getBorrowerDetail(borrowerDetailGetter: ReturnType<typeof getBorrowerDetailRaw>) {
|
|
60
|
-
return async function getBorrowerDetail(address: string) {
|
|
61
|
-
const rawBorrowerDetail = await borrowerDetailGetter(address);
|
|
62
|
-
|
|
63
|
-
return rawBorrowerDetail.pools.map((p) => ({
|
|
64
|
-
collateral_deposited: AssetValue.from({
|
|
65
|
-
asset: p.collateral_asset,
|
|
66
|
-
value: p.collateral_deposited,
|
|
67
|
-
fromBaseDecimal: BaseDecimal.THOR,
|
|
68
|
-
}),
|
|
69
|
-
collateral_withdrawn: AssetValue.from({
|
|
70
|
-
asset: p.collateral_asset,
|
|
71
|
-
value: p.collateral_withdrawn,
|
|
72
|
-
fromBaseDecimal: BaseDecimal.THOR,
|
|
73
|
-
}),
|
|
74
|
-
debt_issued_tor: SwapKitNumber.fromBigInt(BigInt(p.debt_issued_tor), BaseDecimal.THOR),
|
|
75
|
-
debt_repaid_tor: SwapKitNumber.fromBigInt(BigInt(p.debt_repaid_tor), BaseDecimal.THOR),
|
|
76
|
-
last_open_loan_timestamp: p.last_open_loan_timestamp,
|
|
77
|
-
last_repay_loan_timestamp: p.last_repay_loan_timestamp,
|
|
78
|
-
target_assets: p.target_assets.map((asset) => AssetValue.from({ asset })),
|
|
79
|
-
}));
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
41
|
function getPoolAsset({ asset, value }: { asset: string; value: string }) {
|
|
84
42
|
return AssetValue.from({ asset, value, fromBaseDecimal: BaseDecimal.THOR });
|
|
85
43
|
}
|
|
86
44
|
|
|
87
|
-
function getSaverDetail(saverDetailGetter: ReturnType<typeof getSaverDetailRaw>) {
|
|
88
|
-
return async function getSaverDetail(address: string) {
|
|
89
|
-
const rawSaverPositions = await saverDetailGetter(address);
|
|
90
|
-
|
|
91
|
-
return rawSaverPositions.pools.map((p) => ({
|
|
92
|
-
assetAdded: getPoolAsset({ asset: p.pool, value: p.assetAdded }),
|
|
93
|
-
assetDeposit: getPoolAsset({ asset: p.pool, value: p.assetDeposit }),
|
|
94
|
-
assetRedeem: getPoolAsset({ asset: p.pool, value: p.assetRedeem }),
|
|
95
|
-
assetWithdrawn: getPoolAsset({ asset: p.pool, value: p.assetWithdrawn }),
|
|
96
|
-
assetRegisteredAddress: p.assetAddress,
|
|
97
|
-
dateFirstAdded: p.dateFirstAdded,
|
|
98
|
-
dateLastAdded: p.dateLastAdded,
|
|
99
|
-
}));
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
45
|
function getLiquidityPosition<IsThorchain extends boolean = true>({
|
|
104
46
|
liquidityPositionGetter,
|
|
105
47
|
isThorchain,
|
|
@@ -134,15 +76,9 @@ function getMidgardMethodsForProtocol<T extends Chain.THORChain | Chain.Maya>(ch
|
|
|
134
76
|
const midgardBaseUrl = getMidgardBaseUrl(isThorchain);
|
|
135
77
|
const nameServiceBaseUrl = getNameServiceBaseUrl(isThorchain);
|
|
136
78
|
const liquidityPositionGetter = getLiquidityPositionRaw<T>(midgardBaseUrl);
|
|
137
|
-
const borrowerDetailGetter = getBorrowerDetailRaw(midgardBaseUrl);
|
|
138
|
-
const saverDetailGetter = getSaverDetailRaw(midgardBaseUrl);
|
|
139
79
|
|
|
140
80
|
return {
|
|
141
81
|
getLiquidityPositionRaw: liquidityPositionGetter,
|
|
142
|
-
getBorrowerDetailRaw: borrowerDetailGetter,
|
|
143
|
-
getSaverDetailRaw: saverDetailGetter,
|
|
144
|
-
getBorrowerDetail: getBorrowerDetail(borrowerDetailGetter),
|
|
145
|
-
getSaversDetail: getSaverDetail(saverDetailGetter),
|
|
146
82
|
getNameDetails: getNameDetails(nameServiceBaseUrl),
|
|
147
83
|
getNamesByAddress: getNamesByAddress(nameServiceBaseUrl),
|
|
148
84
|
getNamesByOwner: getNamesByOwner(nameServiceBaseUrl),
|
package/src/api/midgard/types.ts
CHANGED
|
@@ -1,52 +1,3 @@
|
|
|
1
|
-
export type BorrowerDetails = {
|
|
2
|
-
/** @description List details of all the loans identified with the given address */
|
|
3
|
-
pools: BorrowerPool[];
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
export type BorrowerPool = {
|
|
7
|
-
/** @description The asset that the borrower used as collateral */
|
|
8
|
-
collateral_asset: string;
|
|
9
|
-
/** @description Int64(e8), The total amount of collateral that user deposited */
|
|
10
|
-
collateral_deposited: string;
|
|
11
|
-
/** @description Int64(e8), The total amount of collateral the system paid back to the user */
|
|
12
|
-
collateral_withdrawn: string;
|
|
13
|
-
/** @description Int64(e8), The total amount of debt issued as debt for user. denominated in TOR. */
|
|
14
|
-
debt_issued_tor: string;
|
|
15
|
-
/** @description Int64(e8), The total amount of debt that the user paid back. denominated in TOR. */
|
|
16
|
-
debt_repaid_tor: string;
|
|
17
|
-
/** @description Int64, Unix timestamp for the last time borrower opened a loan */
|
|
18
|
-
last_open_loan_timestamp: string;
|
|
19
|
-
/** @description Int64, Unix timestamp for the last time borrower repayment occurred */
|
|
20
|
-
last_repay_loan_timestamp: string;
|
|
21
|
-
target_assets: string[];
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export type SaverDetails = {
|
|
25
|
-
/** @description List details of all the savers identified with the given address */
|
|
26
|
-
pools: SaverPool[];
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export type SaverPool = {
|
|
30
|
-
/** @description Int64(e8), total asset added in the saver pool by member */
|
|
31
|
-
assetAdded: string;
|
|
32
|
-
/** @description saver address used by the member */
|
|
33
|
-
assetAddress: string;
|
|
34
|
-
/** @description Int64(e8), total asset that is currently deposited by the member */
|
|
35
|
-
assetDeposit: string;
|
|
36
|
-
/** @description Int64(e8), total asset can be redeemed from the saver pool by member */
|
|
37
|
-
assetRedeem: string;
|
|
38
|
-
/** @description Int64(e8), total asset withdrawn from the saver pool by member */
|
|
39
|
-
assetWithdrawn: string;
|
|
40
|
-
/** @description Int64, Unix timestamp for the first time member deposited into the saver pool */
|
|
41
|
-
dateFirstAdded: string;
|
|
42
|
-
/** @description Int64, Unix timestamp for the last time member deposited into the saver pool */
|
|
43
|
-
dateLastAdded: string;
|
|
44
|
-
/** @description The Pool rest of the data are refering to (only those pools can show up which have a corresponding saver pool) */
|
|
45
|
-
pool: string;
|
|
46
|
-
/** @description Int64, saver liquidity units that belong the the member */
|
|
47
|
-
saverUnits: string;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
1
|
export type MemberDetailsMayachain = {
|
|
51
2
|
/** @MemberPool List details of all the liquidity providers identified with the given address */
|
|
52
3
|
pools: MemberPoolMayachain[];
|
|
@@ -28,12 +28,19 @@ import {
|
|
|
28
28
|
type TrackerResponse,
|
|
29
29
|
} from "./types";
|
|
30
30
|
|
|
31
|
+
const SKRequestClient = RequestClient.extend({
|
|
32
|
+
getDynamicHeader: () => {
|
|
33
|
+
const { swapKit } = SKConfig.get("apiKeys");
|
|
34
|
+
return swapKit ? { "x-api-key": swapKit } : {};
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
31
38
|
export function getTrackerDetails(json: TrackerParams) {
|
|
32
|
-
return
|
|
39
|
+
return SKRequestClient.post<TrackerResponse>(getApiUrl("/track"), { json });
|
|
33
40
|
}
|
|
34
41
|
|
|
35
42
|
export async function getSwapQuote(json: QuoteRequest) {
|
|
36
|
-
const response = await
|
|
43
|
+
const response = await SKRequestClient.post<QuoteResponse>(getApiUrl("/quote"), { json });
|
|
37
44
|
|
|
38
45
|
if (response.error) {
|
|
39
46
|
throw new SwapKitError("api_v2_server_error", { message: response.error });
|
|
@@ -47,9 +54,8 @@ export async function getSwapQuote(json: QuoteRequest) {
|
|
|
47
54
|
}
|
|
48
55
|
|
|
49
56
|
return parsedResponse.data;
|
|
50
|
-
} catch (
|
|
57
|
+
} catch (_error) {
|
|
51
58
|
// throw new SwapKitError("api_v2_invalid_response", error);
|
|
52
|
-
console.warn(error);
|
|
53
59
|
return response;
|
|
54
60
|
}
|
|
55
61
|
}
|
|
@@ -60,7 +66,7 @@ export async function getChainBalance<T extends Chain>({
|
|
|
60
66
|
scamFilter = true,
|
|
61
67
|
}: { chain: T; address: string; scamFilter?: boolean }) {
|
|
62
68
|
const url = getApiUrl(`/balance?chain=${chain}&address=${address}`);
|
|
63
|
-
const balanceResponse = await
|
|
69
|
+
const balanceResponse = await SKRequestClient.get<BalanceResponse>(url);
|
|
64
70
|
const balances = Array.isArray(balanceResponse) ? balanceResponse : [];
|
|
65
71
|
|
|
66
72
|
return scamFilter ? filterAssets(balances) : balances;
|
|
@@ -68,17 +74,17 @@ export async function getChainBalance<T extends Chain>({
|
|
|
68
74
|
|
|
69
75
|
export function getTokenListProviders() {
|
|
70
76
|
const url = getApiUrl("/providers");
|
|
71
|
-
return
|
|
77
|
+
return SKRequestClient.get<TokenListProvidersResponse>(url);
|
|
72
78
|
}
|
|
73
79
|
|
|
74
80
|
export function getTokenList(provider: ProviderName) {
|
|
75
81
|
const url = getApiUrl(`/tokens?provider=${provider}`);
|
|
76
|
-
return
|
|
82
|
+
return SKRequestClient.get<TokensResponseV2>(url);
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
export async function getPrice(body: PriceRequest) {
|
|
80
86
|
const url = getApiUrl("/price");
|
|
81
|
-
const response = await
|
|
87
|
+
const response = await SKRequestClient.post<PriceResponse>(url, {
|
|
82
88
|
json: body,
|
|
83
89
|
});
|
|
84
90
|
|
|
@@ -97,7 +103,7 @@ export async function getPrice(body: PriceRequest) {
|
|
|
97
103
|
|
|
98
104
|
export async function getGasRate() {
|
|
99
105
|
const url = getApiUrl("/gas");
|
|
100
|
-
const response = await
|
|
106
|
+
const response = await SKRequestClient.get<GasResponse>(url);
|
|
101
107
|
|
|
102
108
|
try {
|
|
103
109
|
const parsedResponse = GasResponseSchema.safeParse(response);
|
|
@@ -120,7 +126,7 @@ export async function getChainflipDepositChannel(body: BrokerDepositChannelParam
|
|
|
120
126
|
}
|
|
121
127
|
const url = SKConfig.get("integrations").chainflip?.brokerUrl || getApiUrl("/channel");
|
|
122
128
|
|
|
123
|
-
const response = await
|
|
129
|
+
const response = await SKRequestClient.post<DepositChannelResponse>(url, { json: body });
|
|
124
130
|
|
|
125
131
|
try {
|
|
126
132
|
const parsedResponse = DepositChannelResponseSchema.safeParse(response);
|
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
type AssetValue,
|
|
3
3
|
Chain,
|
|
4
4
|
ChainId,
|
|
5
|
-
ErrorCode,
|
|
6
5
|
FeeTypeEnum,
|
|
7
6
|
ProviderName,
|
|
8
7
|
WarningCodeEnum,
|
|
@@ -20,6 +19,7 @@ import {
|
|
|
20
19
|
unknown,
|
|
21
20
|
type z,
|
|
22
21
|
} from "zod";
|
|
22
|
+
import { ErrorCode } from "../../types/quotes";
|
|
23
23
|
|
|
24
24
|
export enum PriorityLabel {
|
|
25
25
|
CHEAPEST = "CHEAPEST",
|
|
@@ -34,8 +34,8 @@ function getNameServiceBaseUrl(type?: THORNodeType) {
|
|
|
34
34
|
return `${baseUrl(type)}/${nsType}`;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export function getLastBlock(type
|
|
38
|
-
return RequestClient.get<LastBlockItem[]>(`${baseUrl(type)}/lastblock`);
|
|
37
|
+
export function getLastBlock<T extends THORNodeType = "thorchain">(type: T = "thorchain" as T) {
|
|
38
|
+
return RequestClient.get<LastBlockItem<T>[]>(`${baseUrl(type)}/lastblock`);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
export function getThorchainQueue(type?: THORNodeType) {
|
|
@@ -54,8 +54,26 @@ export function getInboundAddresses(type?: THORNodeType) {
|
|
|
54
54
|
return RequestClient.get<InboundAddressesItem[]>(`${baseUrl(type)}/inbound_addresses`);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
export function getTHORNodeTNSDetails({
|
|
58
|
-
|
|
57
|
+
export async function getTHORNodeTNSDetails({
|
|
58
|
+
type,
|
|
59
|
+
name,
|
|
60
|
+
}: { type?: THORNodeType; name: string }): Promise<THORNodeTNSDetails> {
|
|
61
|
+
try {
|
|
62
|
+
const result = await RequestClient.get<THORNodeTNSDetails>(
|
|
63
|
+
`${getNameServiceBaseUrl(type)}/${name}`,
|
|
64
|
+
);
|
|
65
|
+
return result;
|
|
66
|
+
} catch (_error) {
|
|
67
|
+
// If we get an error, the name doesn't exist and is available for registration
|
|
68
|
+
return {
|
|
69
|
+
name,
|
|
70
|
+
expire_block_height: 0,
|
|
71
|
+
owner: "",
|
|
72
|
+
preferred_asset: "",
|
|
73
|
+
affiliate_collector_rune: "",
|
|
74
|
+
aliases: [],
|
|
75
|
+
};
|
|
76
|
+
}
|
|
59
77
|
}
|
|
60
78
|
|
|
61
79
|
export async function getTNSPreferredAsset({ type, tns }: { type?: THORNodeType; tns: string }) {
|
|
@@ -21,11 +21,12 @@ export type InboundAddressesItem = {
|
|
|
21
21
|
router?: string;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
export type LastBlockItem = {
|
|
24
|
+
export type LastBlockItem<T extends THORNodeType = "thorchain"> = {
|
|
25
25
|
chain: string;
|
|
26
26
|
last_observed_in: number;
|
|
27
27
|
last_signed_out: number;
|
|
28
|
-
|
|
28
|
+
} & {
|
|
29
|
+
[K in T]: number;
|
|
29
30
|
};
|
|
30
31
|
|
|
31
32
|
export type NodeItem = {
|
package/src/index.ts
CHANGED
|
@@ -13,7 +13,7 @@ describe("AssetValue", () => {
|
|
|
13
13
|
symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
14
14
|
});
|
|
15
15
|
expect(fakeAvaxUSDCAsset.toString()).toBe(
|
|
16
|
-
"AVAX.USDC-
|
|
16
|
+
"AVAX.USDC-0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
|
|
17
17
|
);
|
|
18
18
|
|
|
19
19
|
const ethSynth = new AssetValue({
|
|
@@ -115,20 +115,20 @@ describe("AssetValue", () => {
|
|
|
115
115
|
const arbWeth = AssetValue.from({
|
|
116
116
|
asset: "ARB.WETH-0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
117
117
|
});
|
|
118
|
-
expect(arbWeth.toString()).toBe("ARB.WETH-
|
|
118
|
+
expect(arbWeth.toString()).toBe("ARB.WETH-0x82aF49447D8a07e3bd95BD0d56f35241523fBab1");
|
|
119
119
|
|
|
120
120
|
const baseAssetFromString = AssetValue.from({
|
|
121
121
|
asset: "BASE.USDC-0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
|
|
122
122
|
});
|
|
123
123
|
expect(baseAssetFromString.toString()).toBe(
|
|
124
|
-
"BASE.USDC-
|
|
124
|
+
"BASE.USDC-0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
125
125
|
);
|
|
126
126
|
|
|
127
127
|
const avaxSolanaAsset = AssetValue.from({
|
|
128
128
|
asset: "AVAX.SOL-0XFE6B19286885A4F7F55ADAD09C3CD1F906D2478F",
|
|
129
129
|
});
|
|
130
130
|
expect(avaxSolanaAsset.toString()).toBe(
|
|
131
|
-
"AVAX.SOL-
|
|
131
|
+
"AVAX.SOL-0xFE6B19286885a4F7F55AdAD09C3Cd1f906D2478F",
|
|
132
132
|
);
|
|
133
133
|
});
|
|
134
134
|
});
|
|
@@ -190,11 +190,11 @@ describe("AssetValue", () => {
|
|
|
190
190
|
symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
191
191
|
});
|
|
192
192
|
expect(fakeAvaxUSDCAsset.toUrl()).toBe(
|
|
193
|
-
"AVAX.USDC-
|
|
193
|
+
"AVAX.USDC-0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
|
|
194
194
|
);
|
|
195
195
|
|
|
196
196
|
const thor = AssetValue.from({ asset: "ETH.THOR" });
|
|
197
|
-
expect(thor.toUrl()).toBe("ETH.THOR-
|
|
197
|
+
expect(thor.toUrl()).toBe("ETH.THOR-0xa5f2211B9b8170F694421f2046281775E8468044");
|
|
198
198
|
|
|
199
199
|
const ethSynth = new AssetValue({
|
|
200
200
|
chain: Chain.THORChain,
|
|
@@ -299,10 +299,10 @@ describe("AssetValue", () => {
|
|
|
299
299
|
chain: Chain.Avalanche,
|
|
300
300
|
symbol: "USDC-0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
|
|
301
301
|
});
|
|
302
|
-
expect(avaxUSDCAsset.toString()).toBe("AVAX.USDC-
|
|
302
|
+
expect(avaxUSDCAsset.toString()).toBe("AVAX.USDC-0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E");
|
|
303
303
|
|
|
304
304
|
const thor = AssetValue.from({ asset: "ETH.THOR" });
|
|
305
|
-
expect(thor.toString()).toBe("ETH.THOR-
|
|
305
|
+
expect(thor.toString()).toBe("ETH.THOR-0xa5f2211B9b8170F694421f2046281775E8468044");
|
|
306
306
|
|
|
307
307
|
const ethSynth = await AssetValue.from({
|
|
308
308
|
asset: "ETH/ETH",
|
|
@@ -331,12 +331,12 @@ describe("AssetValue", () => {
|
|
|
331
331
|
|
|
332
332
|
expect(avaxUSDCAsset).toEqual(
|
|
333
333
|
expect.objectContaining({
|
|
334
|
-
address: "
|
|
334
|
+
address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
|
|
335
335
|
chain: Chain.Avalanche,
|
|
336
336
|
decimal: 6,
|
|
337
337
|
isGasAsset: false,
|
|
338
338
|
isSynthetic: false,
|
|
339
|
-
symbol: "USDC-
|
|
339
|
+
symbol: "USDC-0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
|
|
340
340
|
ticker: "USDC",
|
|
341
341
|
}),
|
|
342
342
|
);
|
|
@@ -465,7 +465,7 @@ describe("AssetValue", () => {
|
|
|
465
465
|
|
|
466
466
|
expect(synthETH.toString()).toBe("ETH/ETH");
|
|
467
467
|
expect(eth.toString()).toBe("ETH.ETH");
|
|
468
|
-
expect(thor.toString()).toBe("ETH.THOR-
|
|
468
|
+
expect(thor.toString()).toBe("ETH.THOR-0xa5f2211B9b8170F694421f2046281775E8468044");
|
|
469
469
|
expect(synthThor.toString()).toBe("ETH/THOR-0xa5f2211b9b8170f694421f2046281775e8468044");
|
|
470
470
|
expect(synthDashes.toString()).toBe("ETH/PENDLE-LPT-0x1234");
|
|
471
471
|
});
|
|
@@ -481,12 +481,12 @@ describe("AssetValue", () => {
|
|
|
481
481
|
expect(thor).toBeDefined();
|
|
482
482
|
expect(thor).toEqual(
|
|
483
483
|
expect.objectContaining({
|
|
484
|
-
address: "
|
|
484
|
+
address: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
|
|
485
485
|
chain: Chain.Arbitrum,
|
|
486
486
|
decimal: 6,
|
|
487
487
|
isGasAsset: false,
|
|
488
488
|
isSynthetic: false,
|
|
489
|
-
symbol: "USDT-
|
|
489
|
+
symbol: "USDT-0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
|
|
490
490
|
ticker: "USDT",
|
|
491
491
|
}),
|
|
492
492
|
);
|
|
@@ -503,12 +503,12 @@ describe("AssetValue", () => {
|
|
|
503
503
|
expect(thor).toBeDefined();
|
|
504
504
|
expect(thor).toEqual(
|
|
505
505
|
expect.objectContaining({
|
|
506
|
-
address: "
|
|
506
|
+
address: "0xa5f2211B9b8170F694421f2046281775E8468044",
|
|
507
507
|
chain: Chain.Ethereum,
|
|
508
508
|
decimal: 18,
|
|
509
509
|
isGasAsset: false,
|
|
510
510
|
isSynthetic: false,
|
|
511
|
-
symbol: "THOR-
|
|
511
|
+
symbol: "THOR-0xa5f2211B9b8170F694421f2046281775E8468044",
|
|
512
512
|
ticker: "THOR",
|
|
513
513
|
}),
|
|
514
514
|
);
|
|
@@ -519,12 +519,12 @@ describe("AssetValue", () => {
|
|
|
519
519
|
expect(usdc).toBeDefined();
|
|
520
520
|
expect(usdc).toEqual(
|
|
521
521
|
expect.objectContaining({
|
|
522
|
-
address: "
|
|
522
|
+
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
523
523
|
chain: Chain.Ethereum,
|
|
524
524
|
decimal: 6,
|
|
525
525
|
isGasAsset: false,
|
|
526
526
|
isSynthetic: false,
|
|
527
|
-
symbol: "USDC-
|
|
527
|
+
symbol: "USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
528
528
|
ticker: "USDC",
|
|
529
529
|
}),
|
|
530
530
|
);
|
|
@@ -580,12 +580,12 @@ describe("AssetValue", () => {
|
|
|
580
580
|
expect(AvaxBTCb).toBeDefined();
|
|
581
581
|
expect(AvaxBTCb).toEqual(
|
|
582
582
|
expect.objectContaining({
|
|
583
|
-
address: "
|
|
583
|
+
address: "0x152b9d0FdC40C096757F570A51E494bd4b943E50",
|
|
584
584
|
chain: Chain.Avalanche,
|
|
585
585
|
decimal: 8,
|
|
586
586
|
isGasAsset: false,
|
|
587
587
|
isSynthetic: false,
|
|
588
|
-
symbol: "BTC.B-
|
|
588
|
+
symbol: "BTC.B-0x152b9d0FdC40C096757F570A51E494bd4b943E50",
|
|
589
589
|
ticker: "BTC.B",
|
|
590
590
|
}),
|
|
591
591
|
);
|
|
@@ -655,12 +655,12 @@ describe("AssetValue", () => {
|
|
|
655
655
|
expect(AvaxUSDC).toBeDefined();
|
|
656
656
|
expect(AvaxUSDC).toEqual(
|
|
657
657
|
expect.objectContaining({
|
|
658
|
-
address: "
|
|
658
|
+
address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
|
|
659
659
|
chain: Chain.Avalanche,
|
|
660
660
|
decimal: 6,
|
|
661
661
|
isGasAsset: false,
|
|
662
662
|
isSynthetic: false,
|
|
663
|
-
symbol: "USDC-
|
|
663
|
+
symbol: "USDC-0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
|
|
664
664
|
ticker: "USDC",
|
|
665
665
|
}),
|
|
666
666
|
);
|
|
@@ -731,12 +731,12 @@ describe("AssetValue", () => {
|
|
|
731
731
|
const thor = AssetValue.from({ asset: "ETH.THOR" });
|
|
732
732
|
expect(thor).toEqual(
|
|
733
733
|
expect.objectContaining({
|
|
734
|
-
address: "
|
|
734
|
+
address: "0xa5f2211B9b8170F694421f2046281775E8468044",
|
|
735
735
|
chain: Chain.Ethereum,
|
|
736
736
|
decimal: 18,
|
|
737
737
|
isGasAsset: false,
|
|
738
738
|
isSynthetic: false,
|
|
739
|
-
symbol: "THOR-
|
|
739
|
+
symbol: "THOR-0xa5f2211B9b8170F694421f2046281775E8468044",
|
|
740
740
|
ticker: "THOR",
|
|
741
741
|
}),
|
|
742
742
|
);
|
|
@@ -794,6 +794,32 @@ describe("AssetValue", () => {
|
|
|
794
794
|
type: "Native",
|
|
795
795
|
}),
|
|
796
796
|
);
|
|
797
|
+
|
|
798
|
+
const trxAsset = AssetValue.from({ chain: Chain.Tron });
|
|
799
|
+
expect(trxAsset).toEqual(
|
|
800
|
+
expect.objectContaining({
|
|
801
|
+
chain: Chain.Tron,
|
|
802
|
+
decimal: BaseDecimal.TRX,
|
|
803
|
+
isGasAsset: true,
|
|
804
|
+
isSynthetic: false,
|
|
805
|
+
symbol: "TRX",
|
|
806
|
+
ticker: "TRX",
|
|
807
|
+
type: "Native",
|
|
808
|
+
}),
|
|
809
|
+
);
|
|
810
|
+
|
|
811
|
+
const trxAssetFromString = AssetValue.from({ asset: "TRX.TRX" });
|
|
812
|
+
expect(trxAssetFromString).toEqual(
|
|
813
|
+
expect.objectContaining({
|
|
814
|
+
chain: Chain.Tron,
|
|
815
|
+
decimal: BaseDecimal.TRX,
|
|
816
|
+
isGasAsset: true,
|
|
817
|
+
isSynthetic: false,
|
|
818
|
+
symbol: "TRX",
|
|
819
|
+
ticker: "TRX",
|
|
820
|
+
type: "Native",
|
|
821
|
+
}),
|
|
822
|
+
);
|
|
797
823
|
});
|
|
798
824
|
|
|
799
825
|
test("keep SOL address casing", () => {
|
|
@@ -811,6 +837,23 @@ describe("AssetValue", () => {
|
|
|
811
837
|
}),
|
|
812
838
|
);
|
|
813
839
|
});
|
|
840
|
+
|
|
841
|
+
test("TRC20 tokens are not marked as gas assets", () => {
|
|
842
|
+
const tronUsdt = AssetValue.from({
|
|
843
|
+
asset: "TRX.USDT-TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
|
|
844
|
+
});
|
|
845
|
+
|
|
846
|
+
expect(tronUsdt).toEqual(
|
|
847
|
+
expect.objectContaining({
|
|
848
|
+
address: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
|
|
849
|
+
chain: Chain.Tron,
|
|
850
|
+
isGasAsset: false,
|
|
851
|
+
isSynthetic: false,
|
|
852
|
+
symbol: "USDT-TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
|
|
853
|
+
ticker: "USDT",
|
|
854
|
+
}),
|
|
855
|
+
);
|
|
856
|
+
});
|
|
814
857
|
});
|
|
815
858
|
});
|
|
816
859
|
|
|
@@ -27,11 +27,11 @@ describe("SwapKitNumber", () => {
|
|
|
27
27
|
|
|
28
28
|
const skNumber5 = new SwapKitNumber({ value: 0.1005, decimal: 3 });
|
|
29
29
|
expect(skNumber5.getValue("string")).toBe("0.101");
|
|
30
|
-
expect(skNumber5.getBaseValue("bigint")).toBe(
|
|
30
|
+
expect(skNumber5.getBaseValue("bigint")).toBe(101n);
|
|
31
31
|
|
|
32
32
|
const skNumber6 = new SwapKitNumber({ value: -0.1005, decimal: 3 });
|
|
33
33
|
expect(skNumber6.getValue("string")).toBe("-0.101");
|
|
34
|
-
expect(skNumber6.getBaseValue("bigint")).toBe(-
|
|
34
|
+
expect(skNumber6.getBaseValue("bigint")).toBe(-101n);
|
|
35
35
|
expect(skNumber6.decimal).toBe(3);
|
|
36
36
|
expect(skNumber6.getValue("number")).toBe(-0.101);
|
|
37
37
|
expect(skNumber6.decimalMultiplier).toBe(100000000n);
|
|
@@ -355,9 +355,8 @@ describe("SwapKitNumber", () => {
|
|
|
355
355
|
|
|
356
356
|
const result = skNumber1.mul(skNumber2);
|
|
357
357
|
|
|
358
|
-
// The exact result of 1.23 * 4.56 is 5.6088
|
|
359
358
|
expect(result.getValue("string")).toBe("5.609");
|
|
360
|
-
expect(result.getBaseValue("bigint")).toBe(
|
|
359
|
+
expect(result.getBaseValue("bigint")).toBe(5609n);
|
|
361
360
|
|
|
362
361
|
const skNumber3 = new SwapKitNumber({ decimal: 2, value: 1.23 });
|
|
363
362
|
const skNumber4 = new SwapKitNumber(-1.234567891);
|
|
@@ -367,7 +366,7 @@ describe("SwapKitNumber", () => {
|
|
|
367
366
|
// The exact result of 1.23 * -1.234567891 is -1,518518505
|
|
368
367
|
// If we round it to 2 decimal places, we should get 5.61
|
|
369
368
|
expect(result2.getValue("string")).toBe("-1.52");
|
|
370
|
-
expect(result2.getBaseValue("bigint")).toBe(-
|
|
369
|
+
expect(result2.getBaseValue("bigint")).toBe(-152n);
|
|
371
370
|
});
|
|
372
371
|
});
|
|
373
372
|
|