@swapkit/helpers 2.6.0 → 3.0.0-beta.1
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 +3 -0
- package/dist/api/index.cjs.map +16 -0
- package/dist/api/index.js +3 -0
- package/dist/api/index.js.map +16 -0
- package/dist/chunk-1gwdyyeh.js +4 -0
- package/dist/chunk-1gwdyyeh.js.map +10 -0
- package/dist/chunk-2bhvezjh.js +4 -0
- package/dist/chunk-2bhvezjh.js.map +10 -0
- package/dist/chunk-3ptwhtpd.js +3 -0
- package/dist/chunk-3ptwhtpd.js.map +10 -0
- package/dist/chunk-3wnfcm30.js +4 -0
- package/dist/chunk-3wnfcm30.js.map +9 -0
- package/dist/chunk-40epvqbm.js +3 -0
- package/dist/chunk-40epvqbm.js.map +10 -0
- package/dist/chunk-49nsjaay.js +3 -0
- package/dist/chunk-49nsjaay.js.map +10 -0
- package/dist/chunk-4b66tryh.js +4 -0
- package/dist/chunk-4b66tryh.js.map +10 -0
- package/dist/chunk-4kzjrrjv.js +3 -0
- package/dist/chunk-4kzjrrjv.js.map +10 -0
- package/dist/chunk-5m49s8z8.js +4 -0
- package/dist/chunk-5m49s8z8.js.map +10 -0
- package/dist/chunk-9b6y7r75.js +4 -0
- package/dist/chunk-9b6y7r75.js.map +10 -0
- package/dist/chunk-9zcbvqq2.js +3 -0
- package/dist/chunk-9zcbvqq2.js.map +10 -0
- package/dist/chunk-a0bpx1q3.js +4 -0
- package/dist/chunk-a0bpx1q3.js.map +10 -0
- package/dist/chunk-a0fxkkfh.js +4 -0
- package/dist/chunk-a0fxkkfh.js.map +10 -0
- package/dist/chunk-a6bjd9ar.js +3 -0
- package/dist/chunk-a6bjd9ar.js.map +10 -0
- package/dist/chunk-bg6pz5qh.js +3 -0
- package/dist/chunk-bg6pz5qh.js.map +10 -0
- package/dist/chunk-cpdcnp2x.js +4 -0
- package/dist/chunk-cpdcnp2x.js.map +10 -0
- package/dist/chunk-fazw0jvt.js +3 -0
- package/dist/chunk-fazw0jvt.js.map +9 -0
- package/dist/chunk-fr86y3rx.js +4 -0
- package/dist/chunk-fr86y3rx.js.map +10 -0
- package/dist/chunk-ftdtdkhk.js +3 -0
- package/dist/chunk-ftdtdkhk.js.map +10 -0
- package/dist/chunk-gjeaw024.js +4 -0
- package/dist/chunk-gjeaw024.js.map +10 -0
- package/dist/chunk-hdcdd2cf.js +4 -0
- package/dist/chunk-hdcdd2cf.js.map +10 -0
- package/dist/chunk-q2pb6ggs.js +3 -0
- package/dist/chunk-q2pb6ggs.js.map +10 -0
- package/dist/chunk-t9s9811k.js +3 -0
- package/dist/chunk-t9s9811k.js.map +10 -0
- package/dist/chunk-v4dvhh90.js +4 -0
- package/dist/chunk-v4dvhh90.js.map +10 -0
- package/dist/chunk-vzptz52h.js +4 -0
- package/dist/chunk-vzptz52h.js.map +10 -0
- package/dist/chunk-wyr5d8ad.js +3 -0
- package/dist/chunk-wyr5d8ad.js.map +10 -0
- package/dist/chunk-x0jsq6ag.js +3 -0
- package/dist/chunk-x0jsq6ag.js.map +10 -0
- package/dist/chunk-x2fe9scs.js +3 -0
- package/dist/chunk-x2fe9scs.js.map +10 -0
- package/dist/chunk-xm5jkehh.js +4 -0
- package/dist/chunk-xm5jkehh.js.map +10 -0
- package/dist/chunk-xzb1nshn.js +3 -0
- package/dist/chunk-xzb1nshn.js.map +10 -0
- package/dist/contracts/index.cjs +3 -0
- package/dist/contracts/index.cjs.map +38 -0
- package/dist/contracts/index.js +3 -0
- package/dist/contracts/index.js.map +38 -0
- package/dist/index.cjs +6 -0
- package/dist/index.cjs.map +30 -0
- package/dist/index.js +3 -3
- package/dist/index.js.map +23 -23
- package/dist/tokens/index.cjs +3 -0
- package/dist/tokens/index.cjs.map +10 -0
- package/dist/tokens/index.js +3 -0
- package/dist/tokens/index.js.map +10 -0
- package/package.json +35 -16
- package/src/api/index.ts +19 -0
- package/src/api/microgard/endpoints.ts +83 -0
- package/src/api/microgard/types.ts +60 -0
- package/src/api/midgard/endpoints.ts +154 -0
- package/src/api/midgard/types.ts +155 -0
- package/src/api/swapkitApi/endpoints.ts +161 -0
- package/src/api/swapkitApi/types.ts +576 -0
- package/src/api/thornode/endpoints.ts +78 -0
- package/src/api/thornode/types.ts +241 -0
- package/src/api/thorswapStatic/endpoints.ts +46 -0
- package/src/api/thorswapStatic/types.ts +18 -0
- package/src/contracts/abis/avaxGeneric.ts +92 -0
- package/src/contracts/abis/avaxWoofi.ts +145 -0
- package/src/contracts/abis/bscGeneric.ts +106 -0
- package/src/contracts/abis/chainflipGateway.ts +330 -0
- package/src/contracts/abis/erc20.ts +99 -0
- package/src/contracts/abis/ethGeneric.ts +92 -0
- package/src/contracts/abis/mayaEvmVaults.ts +331 -0
- package/src/contracts/abis/pancakeV2.ts +145 -0
- package/src/contracts/abis/pangolin.ts +120 -0
- package/src/contracts/abis/sushiswap.ts +120 -0
- package/src/contracts/abis/tcEthVault.ts +650 -0
- package/src/contracts/abis/traderJoe.ts +120 -0
- package/src/contracts/abis/uniswapV2.ts +120 -0
- package/src/contracts/abis/uniswapV2Leg.ts +128 -0
- package/src/contracts/abis/uniswapV3_100.ts +128 -0
- package/src/contracts/abis/uniswapV3_10000.ts +128 -0
- package/src/contracts/abis/uniswapV3_3000.ts +128 -0
- package/src/contracts/abis/uniswapV3_500.ts +128 -0
- package/src/contracts/index.ts +95 -0
- package/src/contracts/routers/index.ts +58 -0
- package/src/contracts/routers/kyber.ts +402 -0
- package/src/contracts/routers/oneinch.ts +2188 -0
- package/src/contracts/routers/pancakeswap.ts +340 -0
- package/src/contracts/routers/pangolin.ts +340 -0
- package/src/contracts/routers/sushiswap.ts +340 -0
- package/src/contracts/routers/traderJoe.ts +340 -0
- package/src/contracts/routers/uniswapv2.ts +340 -0
- package/src/contracts/routers/uniswapv3.ts +254 -0
- package/src/contracts/routers/woofi.ts +171 -0
- package/src/index.ts +19 -15
- package/src/modules/__tests__/assetValue.test.ts +50 -24
- package/src/modules/__tests__/swapKitConfig.test.ts +37 -0
- package/src/modules/assetValue.ts +82 -141
- package/src/modules/bigIntArithmetics.ts +6 -2
- package/src/modules/requestClient.ts +53 -65
- package/src/modules/swapKitConfig.ts +134 -0
- package/src/modules/swapKitError.ts +19 -14
- package/src/tokens/index.ts +15 -0
- package/src/tokens/lists/camelot_v3.ts +15920 -0
- package/src/tokens/lists/caviar_v1.ts +1694 -0
- package/src/tokens/lists/chainflip.ts +104 -0
- package/src/tokens/lists/index.ts +14 -0
- package/src/tokens/lists/jupiter.ts +29606 -0
- package/src/tokens/lists/mayachain.ts +513 -0
- package/src/tokens/lists/oneinch.ts +14238 -0
- package/src/tokens/lists/openocean_v2.ts +11514 -0
- package/src/tokens/lists/pancakeswap.ts +4296 -0
- package/src/tokens/lists/pangolin_v1.ts +175 -0
- package/src/tokens/lists/sushiswap_v2.ts +965 -0
- package/src/tokens/lists/thorchain.ts +669 -0
- package/src/tokens/lists/traderjoe_v2.ts +1384 -0
- package/src/tokens/lists/uniswap_v2.ts +5596 -0
- package/src/tokens/lists/uniswap_v3.ts +5946 -0
- package/src/types/chains.ts +48 -51
- package/src/types/commonTypes.ts +3 -90
- package/src/types/derivationPath.ts +11 -24
- package/src/types/index.ts +3 -4
- package/src/types/quotes.ts +0 -1
- package/src/types/radix.ts +2 -2
- package/src/types/sdk.ts +0 -40
- package/src/types/tokens.ts +14 -17
- package/src/types/wallet.ts +70 -33
- package/src/{helpers → utils}/__tests__/asset.test.ts +0 -27
- package/src/utils/asset.ts +235 -0
- package/src/{helpers → utils}/derivationPath.ts +31 -9
- package/src/{helpers → utils}/memo.ts +0 -82
- package/src/{helpers → utils}/others.ts +12 -5
- package/src/utils/plugin.ts +13 -0
- package/src/utils/tokens.ts +73 -0
- package/src/{helpers → utils}/validators.ts +7 -5
- package/src/{helpers/web3wallets.ts → utils/wallets.ts} +189 -145
- package/src/helpers/asset.ts +0 -324
- package/src/modules/walletUtils.ts +0 -30
- package/src/types/network.ts +0 -49
- /package/src/{helpers/__tests__/derivationPath.ts → utils/__tests__/derivationPath.test.ts} +0 -0
- /package/src/{helpers → utils}/__tests__/memo.test.ts +0 -0
- /package/src/{helpers → utils}/__tests__/others.test.ts +0 -0
- /package/src/{helpers → utils}/__tests__/validators.test.ts +0 -0
- /package/src/{helpers → utils}/liquidity.ts +0 -0
|
@@ -0,0 +1,161 @@
|
|
|
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 PriceRequest,
|
|
20
|
+
type PriceResponse,
|
|
21
|
+
PriceResponseSchema,
|
|
22
|
+
type QuoteRequest,
|
|
23
|
+
type QuoteResponse,
|
|
24
|
+
QuoteResponseSchema,
|
|
25
|
+
type TokenListProvidersResponse,
|
|
26
|
+
type TokensResponseV2,
|
|
27
|
+
type TrackerParams,
|
|
28
|
+
type TrackerResponse,
|
|
29
|
+
} from "./types";
|
|
30
|
+
|
|
31
|
+
export function getTrackerDetails(json: TrackerParams) {
|
|
32
|
+
return RequestClient.post<TrackerResponse>(getApiUrl("/track"), { json });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function getSwapQuote(json: QuoteRequest) {
|
|
36
|
+
const response = await RequestClient.post<QuoteResponse>(getApiUrl("/quote"), { json });
|
|
37
|
+
|
|
38
|
+
if (response.error) {
|
|
39
|
+
throw new SwapKitError("api_v2_server_error", { message: response.error });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
const parsedResponse = QuoteResponseSchema.safeParse(response);
|
|
44
|
+
|
|
45
|
+
if (!parsedResponse.success) {
|
|
46
|
+
throw new SwapKitError("api_v2_invalid_response", parsedResponse.error);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return parsedResponse.data;
|
|
50
|
+
} catch (error) {
|
|
51
|
+
// throw new SwapKitError("api_v2_invalid_response", error);
|
|
52
|
+
console.warn(error);
|
|
53
|
+
return response;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function getChainBalance<T extends Chain>({
|
|
58
|
+
chain,
|
|
59
|
+
address,
|
|
60
|
+
scamFilter = true,
|
|
61
|
+
}: { chain: T; address: string; scamFilter?: boolean }) {
|
|
62
|
+
const url = getApiUrl(`/balance?chain=${chain}&address=${address}`);
|
|
63
|
+
const balanceResponse = await RequestClient.get<BalanceResponse>(url);
|
|
64
|
+
const balances = Array.isArray(balanceResponse) ? balanceResponse : [];
|
|
65
|
+
|
|
66
|
+
return scamFilter ? filterAssets(balances) : balances;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function getTokenListProviders() {
|
|
70
|
+
const url = getApiUrl("/providers");
|
|
71
|
+
return RequestClient.get<TokenListProvidersResponse>(url);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function getTokenList(provider: ProviderName) {
|
|
75
|
+
const url = getApiUrl(`/tokens?provider=${provider}`);
|
|
76
|
+
return RequestClient.get<TokensResponseV2>(url);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export async function getPrice(body: PriceRequest) {
|
|
80
|
+
const url = getApiUrl("/price");
|
|
81
|
+
const response = await RequestClient.post<PriceResponse>(url, {
|
|
82
|
+
json: body,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
const parsedResponse = PriceResponseSchema.safeParse(response);
|
|
87
|
+
|
|
88
|
+
if (!parsedResponse.success) {
|
|
89
|
+
throw new SwapKitError("api_v2_invalid_response", parsedResponse.error);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return parsedResponse.data;
|
|
93
|
+
} catch (error) {
|
|
94
|
+
throw new SwapKitError("api_v2_invalid_response", error);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function getGasRate() {
|
|
99
|
+
const url = getApiUrl("/gas");
|
|
100
|
+
const response = await RequestClient.get<GasResponse>(url);
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
const parsedResponse = GasResponseSchema.safeParse(response);
|
|
104
|
+
|
|
105
|
+
if (!parsedResponse.success) {
|
|
106
|
+
throw new SwapKitError("api_v2_invalid_response", parsedResponse.error);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return parsedResponse.data;
|
|
110
|
+
} catch (error) {
|
|
111
|
+
throw new SwapKitError("api_v2_invalid_response", error);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export async function getChainflipDepositChannel(body: BrokerDepositChannelParams) {
|
|
116
|
+
const { destinationAddress } = body;
|
|
117
|
+
|
|
118
|
+
if (!destinationAddress) {
|
|
119
|
+
throw new SwapKitError("chainflip_broker_invalid_params");
|
|
120
|
+
}
|
|
121
|
+
const url = SKConfig.get("integrations").chainflip?.brokerUrl || getApiUrl("/channel");
|
|
122
|
+
|
|
123
|
+
const response = await RequestClient.post<DepositChannelResponse>(url, { json: body });
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
const parsedResponse = DepositChannelResponseSchema.safeParse(response);
|
|
127
|
+
|
|
128
|
+
if (!parsedResponse.success) {
|
|
129
|
+
throw new SwapKitError("api_v2_invalid_response", parsedResponse.error);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return parsedResponse.data;
|
|
133
|
+
} catch (error) {
|
|
134
|
+
throw new SwapKitError("api_v2_invalid_response", error);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function getApiUrl(path?: `/${string}`) {
|
|
139
|
+
const { isDev, apiUrl, devApiUrl } = SKConfig.get("envs");
|
|
140
|
+
|
|
141
|
+
return `${isDev ? devApiUrl : apiUrl}${path}`;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function evmAssetHasAddress(assetString: string) {
|
|
145
|
+
const [chain, symbol] = assetString.split(".") as [EVMChain, string];
|
|
146
|
+
if (!EVMChains.includes(chain as EVMChain)) return true;
|
|
147
|
+
const splitSymbol = symbol.split("-");
|
|
148
|
+
const address = splitSymbol.length === 1 ? undefined : splitSymbol[splitSymbol.length - 1];
|
|
149
|
+
|
|
150
|
+
return isGasAsset({ chain: chain as Chain, symbol }) || !!address;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const potentialScamRegex = new RegExp(
|
|
154
|
+
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
|
|
155
|
+
"gmi",
|
|
156
|
+
);
|
|
157
|
+
function filterAssets(tokens: BalanceResponse) {
|
|
158
|
+
return tokens.filter((token) => {
|
|
159
|
+
return !potentialScamRegex.test(token.identifier) && evmAssetHasAddress(token.identifier);
|
|
160
|
+
});
|
|
161
|
+
}
|