@swapkit/helpers 4.0.0-beta.33 → 4.0.0-beta.34
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.js +2 -2
- package/dist/api/index.js.map +1 -1
- package/dist/{chunk-ganzk321.js → chunk-hm14bfyg.js} +3 -3
- package/dist/{chunk-fazw0jvt.js.map → chunk-hm14bfyg.js.map} +1 -1
- package/dist/chunk-vb4wtm2w.js +4 -0
- package/dist/{chunk-ganzk321.js.map → chunk-vb4wtm2w.js.map} +1 -1
- package/dist/contracts.cjs +4 -0
- package/dist/contracts.cjs.map +10 -0
- package/dist/contracts.js +4 -0
- package/dist/contracts.js.map +10 -0
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +9 -9
- package/dist/index.js +3 -3
- package/dist/index.js.map +9 -9
- package/dist/tokens.cjs +4 -0
- package/dist/tokens.cjs.map +10 -0
- package/dist/tokens.js +4 -0
- package/dist/tokens.js.map +10 -0
- package/dist/types/api/index.d.ts +238 -0
- package/dist/types/api/index.d.ts.map +1 -0
- package/dist/types/api/microgard/endpoints.d.ts +25 -0
- package/dist/types/api/microgard/endpoints.d.ts.map +1 -0
- package/dist/types/api/microgard/types.d.ts +56 -0
- package/dist/types/api/microgard/types.d.ts.map +1 -0
- package/dist/types/api/midgard/endpoints.d.ts +35 -0
- package/dist/types/api/midgard/endpoints.d.ts.map +1 -0
- package/dist/types/api/midgard/types.d.ts +102 -0
- package/dist/types/api/midgard/types.d.ts.map +1 -0
- package/dist/types/api/swapkitApi/endpoints.d.ts +194 -0
- package/dist/types/api/swapkitApi/endpoints.d.ts.map +1 -0
- package/dist/types/api/swapkitApi/types.d.ts +7238 -0
- package/dist/types/api/swapkitApi/types.d.ts.map +1 -0
- package/dist/types/api/thornode/endpoints.d.ts +31 -0
- package/dist/types/api/thornode/endpoints.d.ts.map +1 -0
- package/dist/types/api/thornode/types.d.ts +264 -0
- package/dist/types/api/thornode/types.d.ts.map +1 -0
- package/dist/types/api/thorswapStatic/endpoints.d.ts +7 -0
- package/dist/types/api/thorswapStatic/endpoints.d.ts.map +1 -0
- package/dist/types/api/thorswapStatic/types.d.ts +22 -0
- package/dist/types/api/thorswapStatic/types.d.ts.map +1 -0
- package/dist/types/contracts.d.ts +2 -0
- package/dist/types/contracts.d.ts.map +1 -0
- package/{src/index.ts → dist/types/index.d.ts} +3 -4
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/modules/assetValue.d.ts +71 -0
- package/dist/types/modules/assetValue.d.ts.map +1 -0
- package/dist/types/modules/bigIntArithmetics.d.ts +56 -0
- package/dist/types/modules/bigIntArithmetics.d.ts.map +1 -0
- package/dist/types/modules/feeMultiplier.d.ts +45 -0
- package/dist/types/modules/feeMultiplier.d.ts.map +1 -0
- package/dist/types/modules/requestClient.d.ts +22 -0
- package/dist/types/modules/requestClient.d.ts.map +1 -0
- package/dist/types/modules/swapKitConfig.d.ts +98 -0
- package/dist/types/modules/swapKitConfig.d.ts.map +1 -0
- package/dist/types/modules/swapKitError.d.ts +829 -0
- package/dist/types/modules/swapKitError.d.ts.map +1 -0
- package/dist/types/modules/swapKitNumber.d.ts +7 -0
- package/dist/types/modules/swapKitNumber.d.ts.map +1 -0
- package/dist/types/tokens.d.ts +2 -0
- package/dist/types/tokens.d.ts.map +1 -0
- package/dist/types/types/chains.d.ts +187 -0
- package/dist/types/types/chains.d.ts.map +1 -0
- package/dist/types/types/commonTypes.d.ts +37 -0
- package/dist/types/types/commonTypes.d.ts.map +1 -0
- package/dist/types/types/derivationPath.d.ts +17 -0
- package/dist/types/types/derivationPath.d.ts.map +1 -0
- package/dist/types/types/errors/apiV1.d.ts +2 -0
- package/dist/types/types/errors/apiV1.d.ts.map +1 -0
- package/{src/types/index.ts → dist/types/types/index.d.ts} +1 -1
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/types/quotes.d.ts +170 -0
- package/dist/types/types/quotes.d.ts.map +1 -0
- package/dist/types/types/radix.d.ts +15 -0
- package/dist/types/types/radix.d.ts.map +1 -0
- package/dist/types/types/sdk.d.ts +35 -0
- package/dist/types/types/sdk.d.ts.map +1 -0
- package/dist/types/types/wallet.d.ts +121 -0
- package/dist/types/types/wallet.d.ts.map +1 -0
- package/dist/types/utils/asset.d.ts +40 -0
- package/dist/types/utils/asset.d.ts.map +1 -0
- package/dist/types/utils/derivationPath.d.ts +19 -0
- package/dist/types/utils/derivationPath.d.ts.map +1 -0
- package/dist/types/utils/explorerUrls.d.ts +10 -0
- package/dist/types/utils/explorerUrls.d.ts.map +1 -0
- package/dist/types/utils/liquidity.d.ts +59 -0
- package/dist/types/utils/liquidity.d.ts.map +1 -0
- package/dist/types/utils/memo.d.ts +65 -0
- package/dist/types/utils/memo.d.ts.map +1 -0
- package/dist/types/utils/others.d.ts +9 -0
- package/dist/types/utils/others.d.ts.map +1 -0
- package/dist/types/utils/validators.d.ts +3 -0
- package/dist/types/utils/validators.d.ts.map +1 -0
- package/dist/types/utils/wallets.d.ts +32 -0
- package/dist/types/utils/wallets.d.ts.map +1 -0
- package/package.json +14 -15
- package/dist/chunk-06q78xy3.js +0 -4
- package/dist/chunk-06q78xy3.js.map +0 -10
- package/dist/chunk-0q5vvg5c.js +0 -5
- package/dist/chunk-0q5vvg5c.js.map +0 -10
- package/dist/chunk-18bxh1n7.js +0 -5
- package/dist/chunk-18bxh1n7.js.map +0 -10
- package/dist/chunk-3qya5ng9.js +0 -4
- package/dist/chunk-3qya5ng9.js.map +0 -10
- package/dist/chunk-4yqymkbp.js +0 -5
- package/dist/chunk-4yqymkbp.js.map +0 -10
- package/dist/chunk-50gpwcq9.js +0 -4
- package/dist/chunk-50gpwcq9.js.map +0 -10
- package/dist/chunk-6atq9cs7.js +0 -4
- package/dist/chunk-6atq9cs7.js.map +0 -10
- package/dist/chunk-6m0d5pv4.js +0 -5
- package/dist/chunk-6m0d5pv4.js.map +0 -10
- package/dist/chunk-8x46g3wq.js +0 -5
- package/dist/chunk-8x46g3wq.js.map +0 -10
- package/dist/chunk-92sk0g47.js +0 -5
- package/dist/chunk-92sk0g47.js.map +0 -10
- package/dist/chunk-9f2b3enk.js +0 -5
- package/dist/chunk-9f2b3enk.js.map +0 -10
- package/dist/chunk-adrafsdk.js +0 -5
- package/dist/chunk-adrafsdk.js.map +0 -10
- package/dist/chunk-b1hang9z.js +0 -5
- package/dist/chunk-b1hang9z.js.map +0 -10
- package/dist/chunk-becdmywt.js +0 -4
- package/dist/chunk-becdmywt.js.map +0 -10
- package/dist/chunk-ehz0t9d1.js +0 -4
- package/dist/chunk-ehz0t9d1.js.map +0 -10
- package/dist/chunk-fazw0jvt.js +0 -4
- package/dist/chunk-fm9ycn0h.js +0 -5
- package/dist/chunk-fm9ycn0h.js.map +0 -10
- package/dist/chunk-g67e2r57.js +0 -4
- package/dist/chunk-g67e2r57.js.map +0 -10
- package/dist/chunk-he3vy8gt.js +0 -4
- package/dist/chunk-he3vy8gt.js.map +0 -10
- package/dist/chunk-jjayk2y5.js +0 -4
- package/dist/chunk-jjayk2y5.js.map +0 -10
- package/dist/chunk-mmyv2vsv.js +0 -5
- package/dist/chunk-mmyv2vsv.js.map +0 -10
- package/dist/chunk-phev7aw7.js +0 -4
- package/dist/chunk-phev7aw7.js.map +0 -10
- package/dist/chunk-rhqk87p2.js +0 -5
- package/dist/chunk-rhqk87p2.js.map +0 -10
- package/dist/chunk-rnv7fdjk.js +0 -4
- package/dist/chunk-rnv7fdjk.js.map +0 -10
- package/dist/chunk-rwh98p1c.js +0 -4
- package/dist/chunk-rwh98p1c.js.map +0 -10
- package/dist/chunk-v9zj2gsj.js +0 -5
- package/dist/chunk-v9zj2gsj.js.map +0 -10
- package/dist/chunk-vv5bgsn8.js +0 -4
- package/dist/chunk-vv5bgsn8.js.map +0 -10
- package/dist/chunk-vwh9jfxn.js +0 -5
- package/dist/chunk-vwh9jfxn.js.map +0 -10
- package/dist/chunk-x0rqy75t.js +0 -4
- package/dist/chunk-x0rqy75t.js.map +0 -10
- package/dist/contracts/index.cjs +0 -4
- package/dist/contracts/index.cjs.map +0 -38
- package/dist/contracts/index.js +0 -4
- package/dist/contracts/index.js.map +0 -38
- package/dist/tokens/index.cjs +0 -4
- package/dist/tokens/index.cjs.map +0 -10
- package/dist/tokens/index.js +0 -4
- package/dist/tokens/index.js.map +0 -10
- package/src/api/index.ts +0 -19
- package/src/api/microgard/endpoints.ts +0 -83
- package/src/api/microgard/types.ts +0 -57
- package/src/api/midgard/endpoints.ts +0 -90
- package/src/api/midgard/types.ts +0 -106
- package/src/api/swapkitApi/endpoints.ts +0 -193
- package/src/api/swapkitApi/types.ts +0 -635
- package/src/api/thornode/endpoints.ts +0 -116
- package/src/api/thornode/types.ts +0 -276
- package/src/api/thorswapStatic/endpoints.ts +0 -46
- package/src/api/thorswapStatic/types.ts +0 -18
- package/src/contracts/abis/avaxGeneric.ts +0 -92
- package/src/contracts/abis/avaxWoofi.ts +0 -145
- package/src/contracts/abis/bscGeneric.ts +0 -106
- package/src/contracts/abis/chainflipGateway.ts +0 -330
- package/src/contracts/abis/erc20.ts +0 -99
- package/src/contracts/abis/ethGeneric.ts +0 -92
- package/src/contracts/abis/mayaEvmVaults.ts +0 -331
- package/src/contracts/abis/pancakeV2.ts +0 -145
- package/src/contracts/abis/pangolin.ts +0 -120
- package/src/contracts/abis/sushiswap.ts +0 -120
- package/src/contracts/abis/tcEthVault.ts +0 -650
- package/src/contracts/abis/traderJoe.ts +0 -120
- package/src/contracts/abis/uniswapV2.ts +0 -120
- package/src/contracts/abis/uniswapV2Leg.ts +0 -128
- package/src/contracts/abis/uniswapV3_100.ts +0 -128
- package/src/contracts/abis/uniswapV3_10000.ts +0 -128
- package/src/contracts/abis/uniswapV3_3000.ts +0 -128
- package/src/contracts/abis/uniswapV3_500.ts +0 -128
- package/src/contracts/index.ts +0 -95
- package/src/contracts/routers/index.ts +0 -58
- package/src/contracts/routers/kyber.ts +0 -402
- package/src/contracts/routers/oneinch.ts +0 -2188
- package/src/contracts/routers/pancakeswap.ts +0 -340
- package/src/contracts/routers/pangolin.ts +0 -340
- package/src/contracts/routers/sushiswap.ts +0 -340
- package/src/contracts/routers/traderJoe.ts +0 -340
- package/src/contracts/routers/uniswapv2.ts +0 -340
- package/src/contracts/routers/uniswapv3.ts +0 -254
- package/src/contracts/routers/woofi.ts +0 -171
- package/src/modules/__tests__/assetValue.test.ts +0 -877
- package/src/modules/__tests__/bigIntArithmetics.test.ts +0 -30
- package/src/modules/__tests__/swapKitConfig.test.ts +0 -37
- package/src/modules/__tests__/swapKitNumber.test.ts +0 -560
- package/src/modules/assetValue.ts +0 -387
- package/src/modules/bigIntArithmetics.ts +0 -436
- package/src/modules/feeMultiplier.ts +0 -87
- package/src/modules/requestClient.ts +0 -83
- package/src/modules/swapKitConfig.ts +0 -143
- package/src/modules/swapKitError.ts +0 -442
- package/src/modules/swapKitNumber.ts +0 -16
- package/src/tokens/index.ts +0 -15
- package/src/tokens/lists/camelot_v3.ts +0 -16060
- package/src/tokens/lists/caviar_v1.ts +0 -1704
- package/src/tokens/lists/chainflip.ts +0 -104
- package/src/tokens/lists/index.ts +0 -14
- package/src/tokens/lists/jupiter.ts +0 -33563
- package/src/tokens/lists/mayachain.ts +0 -509
- package/src/tokens/lists/near.ts +0 -458
- package/src/tokens/lists/oneinch.ts +0 -15006
- package/src/tokens/lists/openocean_v2.ts +0 -12434
- package/src/tokens/lists/pancakeswap.ts +0 -6136
- package/src/tokens/lists/pangolin_v1.ts +0 -75
- package/src/tokens/lists/sushiswap_v2.ts +0 -595
- package/src/tokens/lists/thorchain.ts +0 -748
- package/src/tokens/lists/traderjoe_v2.ts +0 -594
- package/src/tokens/lists/uniswap_v2.ts +0 -11484
- package/src/tokens/lists/uniswap_v3.ts +0 -19424
- package/src/types/chains.ts +0 -555
- package/src/types/commonTypes.ts +0 -58
- package/src/types/derivationPath.ts +0 -58
- package/src/types/errors/apiV1.ts +0 -0
- package/src/types/quotes.ts +0 -172
- package/src/types/radix.ts +0 -14
- package/src/types/sdk.ts +0 -42
- package/src/types/tokens.ts +0 -17
- package/src/types/wallet.ts +0 -166
- package/src/utils/__tests__/asset.test.ts +0 -193
- package/src/utils/__tests__/derivationPath.test.ts +0 -16
- package/src/utils/__tests__/memo.test.ts +0 -103
- package/src/utils/__tests__/others.test.ts +0 -88
- package/src/utils/__tests__/validators.test.ts +0 -24
- package/src/utils/asset.ts +0 -231
- package/src/utils/derivationPath.ts +0 -98
- package/src/utils/liquidity.ts +0 -179
- package/src/utils/memo.ts +0 -143
- package/src/utils/others.ts +0 -86
- package/src/utils/plugin.ts +0 -13
- package/src/utils/tokens.ts +0 -73
- package/src/utils/validators.ts +0 -32
- package/src/utils/wallets.ts +0 -276
package/dist/tokens/index.cjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
var j={};t(j,{tokenLists:()=>s,getTokenIcon:()=>h});module.exports=U(j);var s={};t(s,{UniswapV3List:()=>O,UniswapV2List:()=>C,TraderjoeV2List:()=>w,ThorchainList:()=>V,SushiswapList:()=>e,PangolinList:()=>L,PancakeswapList:()=>l,OpenOceanV2List:()=>f,OneInchList:()=>x,MayaList:()=>m,JupiterList:()=>p,ChainflipList:()=>o,CaviarV1List:()=>i,CamelotV3List:()=>a});function h(c){for(let P of Object.values(s)){let r=P.tokens.find((T)=>T.identifier===c);if(r?.logoURI)return r.logoURI}return}
|
|
2
|
-
|
|
3
|
-
//# debugId=0E83121C7CFC524864756E2164756E21
|
|
4
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/tokens/index.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
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
|
-
],
|
|
7
|
-
"mappings": "2WAEO,SAAS,CAAY,CAAC,EAAwC,CAEnE,QAAW,KAAQ,OAAO,OAAO,CAAU,EAAG,CAC5C,IAAM,EAAQ,EAAK,OAAO,KAAK,CAAC,IAAU,EAAM,aAAe,CAAU,EACzE,GAAI,GAAO,QACT,OAAO,EAAM,QAIjB",
|
|
8
|
-
"debugId": "0E83121C7CFC524864756E2164756E21",
|
|
9
|
-
"names": []
|
|
10
|
-
}
|
package/dist/tokens/index.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{a as w}from"../chunk-vwh9jfxn.js";import{b as C}from"../chunk-mmyv2vsv.js";import{c as p}from"../chunk-b1hang9z.js";import{d as m}from"../chunk-4yqymkbp.js";import{e as x}from"../chunk-rhqk87p2.js";import{f}from"../chunk-v9zj2gsj.js";import{g as l}from"../chunk-6m0d5pv4.js";import{h as L}from"../chunk-18bxh1n7.js";import{i as e}from"../chunk-92sk0g47.js";import{j as V}from"../chunk-8x46g3wq.js";import{k as t}from"../chunk-9f2b3enk.js";import{l as a}from"../chunk-0q5vvg5c.js";import{m as i}from"../chunk-adrafsdk.js";import{n as o}from"../chunk-fm9ycn0h.js";import{p as T}from"../chunk-ganzk321.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
|
-
|
|
3
|
-
//# debugId=4914D9B24FD3F03364756E2164756E21
|
|
4
|
-
//# sourceMappingURL=index.js.map
|
package/dist/tokens/index.js.map
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/tokens/index.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
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
|
-
],
|
|
7
|
-
"mappings": "28BAEO,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": "4914D9B24FD3F03364756E2164756E21",
|
|
9
|
-
"names": []
|
|
10
|
-
}
|
package/src/api/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import * as microgard from "./microgard/endpoints";
|
|
2
|
-
import { mayachainMidgard, thorchainMidgard } from "./midgard/endpoints";
|
|
3
|
-
import * as swapkit from "./swapkitApi/endpoints";
|
|
4
|
-
import * as thornode from "./thornode/endpoints";
|
|
5
|
-
import * as tsStatic from "./thorswapStatic/endpoints";
|
|
6
|
-
|
|
7
|
-
export * from "./microgard/types";
|
|
8
|
-
export * from "./thorswapStatic/types";
|
|
9
|
-
export * from "./thornode/types";
|
|
10
|
-
export * from "./swapkitApi/types";
|
|
11
|
-
|
|
12
|
-
export const SwapKitApi = {
|
|
13
|
-
...swapkit,
|
|
14
|
-
...tsStatic,
|
|
15
|
-
mayachainMidgard,
|
|
16
|
-
microgard,
|
|
17
|
-
thorchainMidgard,
|
|
18
|
-
thornode,
|
|
19
|
-
};
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AssetValue,
|
|
3
|
-
BaseDecimal,
|
|
4
|
-
type Chain,
|
|
5
|
-
RequestClient,
|
|
6
|
-
SwapKitNumber,
|
|
7
|
-
} from "@swapkit/helpers";
|
|
8
|
-
import type { LiquidityPositionRaw, PoolDetail, PoolPeriod, THORNameDetails } from "./types";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* TODO: Move to SKConfig under midgardUrls.microgard
|
|
12
|
-
*/
|
|
13
|
-
const baseUrl = "https://mu.thorswap.net";
|
|
14
|
-
|
|
15
|
-
export function getTHORNameDetails(thorname: string) {
|
|
16
|
-
return RequestClient.get<THORNameDetails>(`${baseUrl}/thorname/lookup/${thorname}`);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function getTHORNamesByOwner(owner: string) {
|
|
20
|
-
return RequestClient.get<string[]>(`${baseUrl}/thorname/owner/${owner}`);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function getTHORNamesByAddress(address: string) {
|
|
24
|
-
return RequestClient.get<string[]>(`${baseUrl}/thorname/address/${address}`);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function getTHORChainPools(period: PoolPeriod) {
|
|
28
|
-
return RequestClient.get<PoolDetail[]>(`${baseUrl}/pools`, { searchParams: { period } });
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function getLiquidityPositionsRaw(addresses: string[]) {
|
|
32
|
-
return RequestClient.get<LiquidityPositionRaw[]>(
|
|
33
|
-
`${baseUrl}/fullmember?address=${addresses.join(",")}`,
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export async function getTNSChainAddress({ chain, tns }: { chain: Chain; tns: string }) {
|
|
38
|
-
const tnsDetails = await getTHORNameDetails(tns);
|
|
39
|
-
|
|
40
|
-
return tnsDetails?.entries?.find((e) => e.chain.toLowerCase() === chain.toLowerCase())?.address;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export async function getLiquidityPositions(addresses: string[]) {
|
|
44
|
-
const rawLiquidityPositions = await getLiquidityPositionsRaw(addresses);
|
|
45
|
-
|
|
46
|
-
return rawLiquidityPositions.map((p) => ({
|
|
47
|
-
assetRegisteredAddress: p.assetAddress,
|
|
48
|
-
asset: AssetValue.from({
|
|
49
|
-
asset: p.pool,
|
|
50
|
-
value: p.assetAdded,
|
|
51
|
-
fromBaseDecimal: BaseDecimal.THOR,
|
|
52
|
-
}),
|
|
53
|
-
assetPending: AssetValue.from({
|
|
54
|
-
asset: p.pool,
|
|
55
|
-
value: p.assetPending,
|
|
56
|
-
fromBaseDecimal: BaseDecimal.THOR,
|
|
57
|
-
}),
|
|
58
|
-
assetWithdrawn: AssetValue.from({
|
|
59
|
-
asset: p.pool,
|
|
60
|
-
value: p.assetWithdrawn,
|
|
61
|
-
fromBaseDecimal: BaseDecimal.THOR,
|
|
62
|
-
}),
|
|
63
|
-
runeRegisteredAddress: p.runeAddress,
|
|
64
|
-
rune: AssetValue.from({
|
|
65
|
-
asset: "THOR.RUNE",
|
|
66
|
-
value: p.runeAdded,
|
|
67
|
-
fromBaseDecimal: BaseDecimal.THOR,
|
|
68
|
-
}),
|
|
69
|
-
runePending: AssetValue.from({
|
|
70
|
-
asset: "THOR.RUNE",
|
|
71
|
-
value: p.runePending,
|
|
72
|
-
fromBaseDecimal: BaseDecimal.THOR,
|
|
73
|
-
}),
|
|
74
|
-
runeWithdrawn: AssetValue.from({
|
|
75
|
-
asset: "THOR.RUNE",
|
|
76
|
-
value: p.runeWithdrawn,
|
|
77
|
-
fromBaseDecimal: BaseDecimal.THOR,
|
|
78
|
-
}),
|
|
79
|
-
poolShare: new SwapKitNumber(p.sharedUnits).div(p.poolUnits),
|
|
80
|
-
dateLastAdded: p.dateLastAdded,
|
|
81
|
-
dateFirstAdded: p.dateFirstAdded,
|
|
82
|
-
}));
|
|
83
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { AssetValue, SwapKitNumber } from "@swapkit/helpers";
|
|
2
|
-
|
|
3
|
-
export type THORNameDetails = {
|
|
4
|
-
entries: Array<{ address: string; chain: string }>;
|
|
5
|
-
owner: string;
|
|
6
|
-
expire: string;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export type PoolPeriod = "1h" | "24h" | "7d" | "30d" | "90d" | "100d" | "180d" | "365d";
|
|
10
|
-
|
|
11
|
-
export type PoolDetail = {
|
|
12
|
-
annualPercentageRate: string;
|
|
13
|
-
asset: string;
|
|
14
|
-
assetDepth: string;
|
|
15
|
-
assetPrice: string;
|
|
16
|
-
assetPriceUSD: string;
|
|
17
|
-
liquidityUnits: string;
|
|
18
|
-
poolAPY: string;
|
|
19
|
-
runeDepth: string;
|
|
20
|
-
status: string;
|
|
21
|
-
synthSupply: string;
|
|
22
|
-
synthUnits: string;
|
|
23
|
-
units: string;
|
|
24
|
-
volume24h: string;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export type LiquidityPositionRaw = {
|
|
28
|
-
assetAdded: string;
|
|
29
|
-
assetAddress: string;
|
|
30
|
-
assetPending: string;
|
|
31
|
-
assetWithdrawn: string;
|
|
32
|
-
dateFirstAdded: string;
|
|
33
|
-
dateLastAdded: string;
|
|
34
|
-
pool: string;
|
|
35
|
-
poolAssetDepth: string;
|
|
36
|
-
poolRuneDepth: string;
|
|
37
|
-
poolUnits: string;
|
|
38
|
-
runeAdded: string;
|
|
39
|
-
runeAddress: string;
|
|
40
|
-
runePending: string;
|
|
41
|
-
runeWithdrawn: string;
|
|
42
|
-
sharedUnits: string;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export type LiquidityPosition = {
|
|
46
|
-
asset: AssetValue;
|
|
47
|
-
assetPending: AssetValue;
|
|
48
|
-
assetWithdrawn: AssetValue;
|
|
49
|
-
assetAddress: string;
|
|
50
|
-
native: AssetValue;
|
|
51
|
-
nativeAddress: string;
|
|
52
|
-
nativePending: AssetValue;
|
|
53
|
-
nativeWithdrawn: AssetValue;
|
|
54
|
-
dateFirstAdded: string;
|
|
55
|
-
dateLastAdded: string;
|
|
56
|
-
poolShare: SwapKitNumber;
|
|
57
|
-
};
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { AssetValue, BaseDecimal, Chain, RequestClient, SwapKitNumber } from "@swapkit/helpers";
|
|
2
|
-
import type { MemberDetailsMayachain, MemberDetailsThorchain, THORNameDetails } from "./types";
|
|
3
|
-
|
|
4
|
-
function getMidgardBaseUrl(isThorchain = true) {
|
|
5
|
-
return isThorchain ? "https://midgard.ninerealms.com" : "https://midgard.mayachain.info";
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function getNameServiceBaseUrl(isThorchain = true) {
|
|
9
|
-
const baseUrl = getMidgardBaseUrl(isThorchain);
|
|
10
|
-
return isThorchain ? `${baseUrl}/v2/thorname` : `${baseUrl}/v2/mayaname`;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function getLiquidityPositionRaw<Chain extends Chain.THORChain | Chain.Maya>(baseUrl: string) {
|
|
14
|
-
return function getLiquidityPosition(
|
|
15
|
-
address: string,
|
|
16
|
-
): Promise<Chain extends Chain.THORChain ? MemberDetailsThorchain : MemberDetailsMayachain> {
|
|
17
|
-
return RequestClient.get<
|
|
18
|
-
Chain extends Chain.THORChain ? MemberDetailsThorchain : MemberDetailsMayachain
|
|
19
|
-
>(`${baseUrl}/v2/member/${address}`);
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function getNameDetails(baseUrl: string) {
|
|
24
|
-
return function getNameDetails(name: string) {
|
|
25
|
-
return RequestClient.get<THORNameDetails>(`${baseUrl}/lookup/${name}`);
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function getNamesByAddress(baseUrl: string) {
|
|
30
|
-
return function getNamesByAddress(address: string) {
|
|
31
|
-
return RequestClient.get<string[]>(`${baseUrl}/rlookup/${address}`);
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function getNamesByOwner(baseUrl: string) {
|
|
36
|
-
return function getNamesByOwner(address: string) {
|
|
37
|
-
return RequestClient.get<string[]>(`${baseUrl}/owner/${address}`);
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function getPoolAsset({ asset, value }: { asset: string; value: string }) {
|
|
42
|
-
return AssetValue.from({ asset, value, fromBaseDecimal: BaseDecimal.THOR });
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function getLiquidityPosition<IsThorchain extends boolean = true>({
|
|
46
|
-
liquidityPositionGetter,
|
|
47
|
-
isThorchain,
|
|
48
|
-
}: {
|
|
49
|
-
liquidityPositionGetter: ReturnType<
|
|
50
|
-
typeof getLiquidityPositionRaw<IsThorchain extends true ? Chain.THORChain : Chain.Maya>
|
|
51
|
-
>;
|
|
52
|
-
isThorchain: IsThorchain;
|
|
53
|
-
}) {
|
|
54
|
-
return async function getLiquidityPosition(address: string) {
|
|
55
|
-
const rawLiquidityPositions = await liquidityPositionGetter(address);
|
|
56
|
-
const fieldPrefix = isThorchain ? "rune" : "cacao";
|
|
57
|
-
|
|
58
|
-
return rawLiquidityPositions.pools.map((p) => ({
|
|
59
|
-
[`${fieldPrefix}Pending`]: getPoolAsset({ asset: "THOR.RUNE", value: p.runePending }),
|
|
60
|
-
[`${fieldPrefix}RegisteredAddress`]: p.runeAddress,
|
|
61
|
-
[`${fieldPrefix}Withdrawn`]: getPoolAsset({ asset: "THOR.RUNE", value: p.runeWithdrawn }),
|
|
62
|
-
[fieldPrefix]: getPoolAsset({ asset: "THOR.RUNE", value: p.runeAdded }),
|
|
63
|
-
asset: getPoolAsset({ asset: p.pool, value: p.assetAdded }),
|
|
64
|
-
assetPending: getPoolAsset({ asset: p.pool, value: p.assetPending }),
|
|
65
|
-
assetRegisteredAddress: p.assetAddress,
|
|
66
|
-
assetWithdrawn: getPoolAsset({ asset: p.pool, value: p.assetWithdrawn }),
|
|
67
|
-
dateFirstAdded: p.dateFirstAdded,
|
|
68
|
-
dateLastAdded: p.dateLastAdded,
|
|
69
|
-
poolShare: new SwapKitNumber(p.liquidityUnits).div(p.pool),
|
|
70
|
-
}));
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function getMidgardMethodsForProtocol<T extends Chain.THORChain | Chain.Maya>(chain: T) {
|
|
75
|
-
const isThorchain = chain === Chain.THORChain;
|
|
76
|
-
const midgardBaseUrl = getMidgardBaseUrl(isThorchain);
|
|
77
|
-
const nameServiceBaseUrl = getNameServiceBaseUrl(isThorchain);
|
|
78
|
-
const liquidityPositionGetter = getLiquidityPositionRaw<T>(midgardBaseUrl);
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
getLiquidityPositionRaw: liquidityPositionGetter,
|
|
82
|
-
getNameDetails: getNameDetails(nameServiceBaseUrl),
|
|
83
|
-
getNamesByAddress: getNamesByAddress(nameServiceBaseUrl),
|
|
84
|
-
getNamesByOwner: getNamesByOwner(nameServiceBaseUrl),
|
|
85
|
-
getLiquidityPosition: getLiquidityPosition({ liquidityPositionGetter, isThorchain }),
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export const thorchainMidgard = getMidgardMethodsForProtocol(Chain.THORChain);
|
|
90
|
-
export const mayachainMidgard = getMidgardMethodsForProtocol(Chain.Maya);
|
package/src/api/midgard/types.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
export type MemberDetailsMayachain = {
|
|
2
|
-
/** @MemberPool List details of all the liquidity providers identified with the given address */
|
|
3
|
-
pools: MemberPoolMayachain[];
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
export type MemberPoolMayachain = {
|
|
7
|
-
/** @description Int64(e8), total asset added to the pool by member */
|
|
8
|
-
assetAdded: string;
|
|
9
|
-
/** @description asset address used by the member */
|
|
10
|
-
assetAddress: string;
|
|
11
|
-
/** @description Int64(e8), total asset that is currently deposited to the pool by member.
|
|
12
|
-
* This field is same as the `asset_deposit_value` field in thornode. Mainly can be used
|
|
13
|
-
* for tracking, mainly Growth Percentage
|
|
14
|
-
* */
|
|
15
|
-
assetDeposit: string;
|
|
16
|
-
/** @description Int64(e8), asset sent but not added yet, it will be added when the rune pair arrives
|
|
17
|
-
* */
|
|
18
|
-
assetPending: string;
|
|
19
|
-
/** @description Int64(e8), total asset withdrawn from the pool by member */
|
|
20
|
-
assetWithdrawn: string;
|
|
21
|
-
/** @description Int64(e8), total Cacao that is currently deposited to the pool by member.
|
|
22
|
-
* This field is same as the `rune_deposit_value` field in thornode. Mainly can be used
|
|
23
|
-
* for tracking, mainly Growth Percentage
|
|
24
|
-
* */
|
|
25
|
-
cacaoDeposit: string;
|
|
26
|
-
/** @description Int64, Unix timestamp for the first time member deposited into the pool */
|
|
27
|
-
dateFirstAdded: string;
|
|
28
|
-
/** @description Int64, Unix timestamp for the last time member deposited into the pool */
|
|
29
|
-
dateLastAdded: string;
|
|
30
|
-
/** @description Int64, pool liquidity units that belong the the member */
|
|
31
|
-
liquidityUnits: string;
|
|
32
|
-
/** @description Pool rest of the data refers to */
|
|
33
|
-
pool: string;
|
|
34
|
-
/** @description Int64(e8), total Rune added to the pool by member */
|
|
35
|
-
runeAdded: string;
|
|
36
|
-
/** @description Rune address used by the member */
|
|
37
|
-
runeAddress: string;
|
|
38
|
-
/** @description Int64(e8), Rune sent but not added yet, it will be added when the asset pair arrives
|
|
39
|
-
* */
|
|
40
|
-
runePending: string;
|
|
41
|
-
/** @description Int64(e8), total Rune withdrawn from the pool by member */
|
|
42
|
-
runeWithdrawn: string;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export type MemberDetailsThorchain = {
|
|
46
|
-
/** @MemberPool List details of all the liquidity providers identified with the given address */
|
|
47
|
-
pools: MemberPoolThorchain[];
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export type MemberPoolThorchain = {
|
|
51
|
-
/** @description Int64(e8), total asset added to the pool by member */
|
|
52
|
-
assetAdded: string;
|
|
53
|
-
/** @description asset address used by the member */
|
|
54
|
-
assetAddress: string;
|
|
55
|
-
/** @description Int64(e8), total asset that is currently deposited to the pool by member.
|
|
56
|
-
* This field is same as the `asset_deposit_value` field in thornode. Mainly can be used
|
|
57
|
-
* for tracking, mainly Growth Percentage
|
|
58
|
-
* */
|
|
59
|
-
assetDeposit: string;
|
|
60
|
-
/** @description Int64(e8), asset sent but not added yet, it will be added when the rune pair arrives
|
|
61
|
-
* */
|
|
62
|
-
assetPending: string;
|
|
63
|
-
/** @description Int64(e8), total asset withdrawn from the pool by member */
|
|
64
|
-
assetWithdrawn: string;
|
|
65
|
-
/** @description Int64(e8), total Rune that is currently deposited to the pool by member.
|
|
66
|
-
* This field is same as the `rune_deposit_value` field in thornode. Mainly can be used
|
|
67
|
-
* for tracking, mainly Growth Percentage
|
|
68
|
-
* */
|
|
69
|
-
runeDeposit: string;
|
|
70
|
-
/** @description Int64, Unix timestamp for the first time member deposited into the pool */
|
|
71
|
-
dateFirstAdded: string;
|
|
72
|
-
/** @description Int64, Unix timestamp for the last time member deposited into the pool */
|
|
73
|
-
dateLastAdded: string;
|
|
74
|
-
/** @description Int64, pool liquidity units that belong the the member */
|
|
75
|
-
liquidityUnits: string;
|
|
76
|
-
/** @description Pool rest of the data refers to */
|
|
77
|
-
pool: string;
|
|
78
|
-
/** @description Int64(e8), total Rune added to the pool by member */
|
|
79
|
-
runeAdded: string;
|
|
80
|
-
/** @description Rune address used by the member */
|
|
81
|
-
runeAddress: string;
|
|
82
|
-
/** @description Int64(e8), Rune sent but not added yet, it will be added when the asset pair arrives
|
|
83
|
-
* */
|
|
84
|
-
runePending: string;
|
|
85
|
-
/** @description Int64(e8), total Rune withdrawn from the pool by member */
|
|
86
|
-
runeWithdrawn: string;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
export type THORNameDetails = {
|
|
90
|
-
/** @description List details of all chains and their addresses for a given THORName */
|
|
91
|
-
entries: THORNameEntry[];
|
|
92
|
-
/** @description Int64, THORChain block height in which THORName expires */
|
|
93
|
-
expire: string;
|
|
94
|
-
/**
|
|
95
|
-
* @description owner's THOR address
|
|
96
|
-
* @example thor102y0m3uptg0vvudeyh00r2fnz70wq7d8y7mu2g
|
|
97
|
-
*/
|
|
98
|
-
owner: string;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
export type THORNameEntry = {
|
|
102
|
-
/** @description address on blockchain */
|
|
103
|
-
address: string;
|
|
104
|
-
/** @description blockchain */
|
|
105
|
-
chain: string;
|
|
106
|
-
};
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type Chain,
|
|
3
|
-
type EVMChain,
|
|
4
|
-
EVMChains,
|
|
5
|
-
type ProviderName,
|
|
6
|
-
RequestClient,
|
|
7
|
-
SKConfig,
|
|
8
|
-
SwapKitError,
|
|
9
|
-
isGasAsset,
|
|
10
|
-
} from "@swapkit/helpers";
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
type BalanceResponse,
|
|
14
|
-
type BrokerDepositChannelParams,
|
|
15
|
-
type DepositChannelResponse,
|
|
16
|
-
DepositChannelResponseSchema,
|
|
17
|
-
type GasResponse,
|
|
18
|
-
GasResponseSchema,
|
|
19
|
-
type NearDepositChannelParams,
|
|
20
|
-
type NearSwapResponse,
|
|
21
|
-
NearSwapResponseSchema,
|
|
22
|
-
type PriceRequest,
|
|
23
|
-
type PriceResponse,
|
|
24
|
-
PriceResponseSchema,
|
|
25
|
-
type QuoteRequest,
|
|
26
|
-
type QuoteResponse,
|
|
27
|
-
QuoteResponseSchema,
|
|
28
|
-
type TokenListProvidersResponse,
|
|
29
|
-
type TokensResponseV2,
|
|
30
|
-
type TrackerParams,
|
|
31
|
-
type TrackerResponse,
|
|
32
|
-
} from "./types";
|
|
33
|
-
|
|
34
|
-
const SKRequestClient = RequestClient.extend({
|
|
35
|
-
dynamicHeader: () => {
|
|
36
|
-
const { swapKit } = SKConfig.get("apiKeys");
|
|
37
|
-
return swapKit ? { "x-api-key": swapKit } : {};
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
export function getTrackerDetails(json: TrackerParams) {
|
|
42
|
-
return SKRequestClient.post<TrackerResponse>(getApiUrl("/track"), { json });
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export async function getSwapQuote(json: QuoteRequest) {
|
|
46
|
-
const response = await SKRequestClient.post<QuoteResponse>(getApiUrl("/quote"), { json });
|
|
47
|
-
|
|
48
|
-
if (response.error) {
|
|
49
|
-
throw new SwapKitError("api_v2_server_error", { message: response.error });
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
const parsedResponse = QuoteResponseSchema.safeParse(response);
|
|
54
|
-
|
|
55
|
-
if (!parsedResponse.success) {
|
|
56
|
-
throw new SwapKitError("api_v2_invalid_response", parsedResponse.error);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return parsedResponse.data;
|
|
60
|
-
} catch (_error) {
|
|
61
|
-
// throw new SwapKitError("api_v2_invalid_response", error);
|
|
62
|
-
return response;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export async function getChainBalance<T extends Chain>({
|
|
67
|
-
chain,
|
|
68
|
-
address,
|
|
69
|
-
scamFilter = true,
|
|
70
|
-
}: { chain: T; address: string; scamFilter?: boolean }) {
|
|
71
|
-
const url = getApiUrl(`/balance?chain=${chain}&address=${address}`);
|
|
72
|
-
const balanceResponse = await SKRequestClient.get<BalanceResponse>(url);
|
|
73
|
-
const balances = Array.isArray(balanceResponse) ? balanceResponse : [];
|
|
74
|
-
|
|
75
|
-
return scamFilter ? filterAssets(balances) : balances;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function getTokenListProviders() {
|
|
79
|
-
const url = getApiUrl("/providers");
|
|
80
|
-
return SKRequestClient.get<TokenListProvidersResponse>(url);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function getTokenList(provider: ProviderName) {
|
|
84
|
-
const url = getApiUrl(`/tokens?provider=${provider}`);
|
|
85
|
-
return SKRequestClient.get<TokensResponseV2>(url);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export async function getPrice(body: PriceRequest) {
|
|
89
|
-
const url = getApiUrl("/price");
|
|
90
|
-
const response = await SKRequestClient.post<PriceResponse>(url, {
|
|
91
|
-
json: body,
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
const parsedResponse = PriceResponseSchema.safeParse(response);
|
|
96
|
-
|
|
97
|
-
if (!parsedResponse.success) {
|
|
98
|
-
throw new SwapKitError("api_v2_invalid_response", parsedResponse.error);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return parsedResponse.data;
|
|
102
|
-
} catch (error) {
|
|
103
|
-
throw new SwapKitError("api_v2_invalid_response", error);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export async function getGasRate() {
|
|
108
|
-
const url = getApiUrl("/gas");
|
|
109
|
-
const response = await SKRequestClient.get<GasResponse>(url);
|
|
110
|
-
|
|
111
|
-
try {
|
|
112
|
-
const parsedResponse = GasResponseSchema.safeParse(response);
|
|
113
|
-
|
|
114
|
-
if (!parsedResponse.success) {
|
|
115
|
-
throw new SwapKitError("api_v2_invalid_response", parsedResponse.error);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return parsedResponse.data;
|
|
119
|
-
} catch (error) {
|
|
120
|
-
throw new SwapKitError("api_v2_invalid_response", error);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export async function getChainflipDepositChannel(body: BrokerDepositChannelParams) {
|
|
125
|
-
const { destinationAddress } = body;
|
|
126
|
-
|
|
127
|
-
if (!destinationAddress) {
|
|
128
|
-
throw new SwapKitError("chainflip_broker_invalid_params");
|
|
129
|
-
}
|
|
130
|
-
const url = SKConfig.get("integrations").chainflip?.brokerUrl || getApiUrl("/channel");
|
|
131
|
-
|
|
132
|
-
const response = await SKRequestClient.post<DepositChannelResponse>(url, { json: body });
|
|
133
|
-
|
|
134
|
-
try {
|
|
135
|
-
const parsedResponse = DepositChannelResponseSchema.safeParse(response);
|
|
136
|
-
|
|
137
|
-
if (!parsedResponse.success) {
|
|
138
|
-
throw new SwapKitError("api_v2_invalid_response", parsedResponse.error);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return parsedResponse.data;
|
|
142
|
-
} catch (error) {
|
|
143
|
-
throw new SwapKitError("api_v2_invalid_response", error);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export async function getNearDepositChannel(body: NearDepositChannelParams) {
|
|
148
|
-
const { destinationAddress } = body;
|
|
149
|
-
|
|
150
|
-
if (!destinationAddress) {
|
|
151
|
-
throw new SwapKitError("chainflip_broker_invalid_params");
|
|
152
|
-
}
|
|
153
|
-
const url = getApiUrl("/near/channel");
|
|
154
|
-
|
|
155
|
-
const response = await SKRequestClient.post<NearSwapResponse>(url, { json: body });
|
|
156
|
-
|
|
157
|
-
try {
|
|
158
|
-
const parsedResponse = NearSwapResponseSchema.safeParse(response);
|
|
159
|
-
|
|
160
|
-
if (!parsedResponse.success) {
|
|
161
|
-
throw new SwapKitError("api_v2_invalid_response", parsedResponse.error);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return parsedResponse.data;
|
|
165
|
-
} catch (error) {
|
|
166
|
-
throw new SwapKitError("api_v2_invalid_response", error);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function getApiUrl(path?: `/${string}`) {
|
|
171
|
-
const { isDev, apiUrl, devApiUrl } = SKConfig.get("envs");
|
|
172
|
-
|
|
173
|
-
return `${isDev ? devApiUrl : apiUrl}${path}`;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function evmAssetHasAddress(assetString: string) {
|
|
177
|
-
const [chain, symbol] = assetString.split(".") as [EVMChain, string];
|
|
178
|
-
if (!EVMChains.includes(chain as EVMChain)) return true;
|
|
179
|
-
const splitSymbol = symbol.split("-");
|
|
180
|
-
const address = splitSymbol.length === 1 ? undefined : splitSymbol[splitSymbol.length - 1];
|
|
181
|
-
|
|
182
|
-
return isGasAsset({ chain: chain as Chain, symbol }) || !!address;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const potentialScamRegex = new RegExp(
|
|
186
|
-
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
|
|
187
|
-
"gmi",
|
|
188
|
-
);
|
|
189
|
-
function filterAssets(tokens: BalanceResponse) {
|
|
190
|
-
return tokens.filter((token) => {
|
|
191
|
-
return !potentialScamRegex.test(token.identifier) && evmAssetHasAddress(token.identifier);
|
|
192
|
-
});
|
|
193
|
-
}
|