@pioneer-platform/swapkit-client 0.0.2
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/CHANGELOG.md +10 -0
- package/README.md +159 -0
- package/docs/docs.md +1508 -0
- package/lib/index.d.ts +81 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +271 -0
- package/lib/index.js.map +1 -0
- package/package.json +30 -0
- package/test-arb-amount.js +47 -0
- package/test-various-routes.js +60 -0
- package/tsconfig.json +20 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
declare const TAG = " | swapkit | ";
|
|
2
|
+
declare const log: any;
|
|
3
|
+
declare const axios: any;
|
|
4
|
+
declare let caipToNetworkId: any, getChainEnumValue: any, caipToThorchain: any;
|
|
5
|
+
declare const SWAPKIT_API_URL: string;
|
|
6
|
+
declare const SWAPKIT_API_KEY: string;
|
|
7
|
+
declare let networkSupport: string[];
|
|
8
|
+
declare let assetSupport: string[];
|
|
9
|
+
declare const EXCLUDED_PROVIDERS: string[];
|
|
10
|
+
interface SwapKitQuoteRequest {
|
|
11
|
+
sellAsset: string;
|
|
12
|
+
sellAmount: string;
|
|
13
|
+
buyAsset: string;
|
|
14
|
+
sourceAddress?: string;
|
|
15
|
+
destinationAddress?: string;
|
|
16
|
+
slippage?: number;
|
|
17
|
+
providers?: string[];
|
|
18
|
+
}
|
|
19
|
+
interface SwapKitQuoteResponse {
|
|
20
|
+
routes: Array<{
|
|
21
|
+
routeId: string;
|
|
22
|
+
expectedOutput: string;
|
|
23
|
+
expectedOutputUSD: string;
|
|
24
|
+
path: string;
|
|
25
|
+
provider: string;
|
|
26
|
+
estimatedTime: {
|
|
27
|
+
total: number;
|
|
28
|
+
inbound?: number;
|
|
29
|
+
swap?: number;
|
|
30
|
+
outbound?: number;
|
|
31
|
+
};
|
|
32
|
+
fees: Array<{
|
|
33
|
+
asset: string;
|
|
34
|
+
amount: string;
|
|
35
|
+
type: string;
|
|
36
|
+
}>;
|
|
37
|
+
meta?: {
|
|
38
|
+
buyAsset: {
|
|
39
|
+
chain: string;
|
|
40
|
+
symbol: string;
|
|
41
|
+
ticker: string;
|
|
42
|
+
};
|
|
43
|
+
sellAsset: {
|
|
44
|
+
chain: string;
|
|
45
|
+
symbol: string;
|
|
46
|
+
ticker: string;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
}>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get available providers from SwapKit API
|
|
53
|
+
*/
|
|
54
|
+
declare const getProviders: () => Promise<any>;
|
|
55
|
+
/**
|
|
56
|
+
* Load supported assets from SwapKit API
|
|
57
|
+
* Filters out THORChain and MayaChain assets
|
|
58
|
+
*/
|
|
59
|
+
declare const loadSupportedAssets: () => Promise<string[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Convert CAIP asset identifier to SwapKit asset format
|
|
62
|
+
* SwapKit uses THORChain format: CHAIN.SYMBOL or CHAIN.SYMBOL-ADDRESS
|
|
63
|
+
* Examples:
|
|
64
|
+
* - eip155:1/slip44:60 -> ETH.ETH
|
|
65
|
+
* - eip155:8453/slip44:60 -> BASE.ETH
|
|
66
|
+
* - eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 -> ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48
|
|
67
|
+
*/
|
|
68
|
+
declare const caipToSwapKitAsset: (caip: string, asset: any) => string | null;
|
|
69
|
+
/**
|
|
70
|
+
* Get quote from SwapKit API
|
|
71
|
+
*/
|
|
72
|
+
declare const get_quote: (quote: any) => Promise<any>;
|
|
73
|
+
/**
|
|
74
|
+
* Get route with transaction details
|
|
75
|
+
*/
|
|
76
|
+
declare const get_route_with_tx: (routeId: string, sourceAddress: string, destinationAddress: string) => Promise<any>;
|
|
77
|
+
/**
|
|
78
|
+
* Track transaction status
|
|
79
|
+
*/
|
|
80
|
+
declare const track_transaction: (txId: string, routeId: string)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AM,EAAE,MAAM,CAAA;YACd,IAAI,EAAE,MAAM,CAAA;SACf,CAAC,CAAA;QACF,IAAI,CAAC,EAAE;YACH,QAAQ,EAAE;gBACN,KAAK,EAAE,MAAM,CAAA;gBACb,MAAM,EAAE,MAAM,CAAA;gBACd,MAAM,EAAE,MAAM,CAAA;aACjB,CAAA;YACD,SAAS,EAAE;gBACP,KAAK,EAAE,MAAM,CAAA;gBACb,MAAM,EAAE,MAAM,CAAA;gBACd,MAAM,EAAE,MAAM,CAAA;aACjB,CAAA;SACJ,CAAA;KACJ,CAAC,CAAA;CACL;AAuCD;;GAEG;AACH,QAAA,MAAM,YAAY,oBAiBjB,CAAA;AAED;;;GAGG;AACH,QAAA,MAAM,mBAAmB,QAAqB,OAAO,CAAC,MAAM,EAAE,CAiB7D,CAAA;AAED;;;;;;;GAOG;AACH,QAAA,MAAM,kBAAkB,GAAY,MAAM,MAAM,EAAE,OAAO,GAAG,KAAG,MAAM,GAAG,IAoBvE,CAAA;AAED;;GAEG;AACH,QAAA,MAAM,SAAS,GAAkB,OAAO,GAAG,iBAyG1C,CAAA;AAED;;GAEG;AACH,QAAA,MAAM,iBAAiB,GAAkB,SAAS,MAAM,EAAE,eAAe,MAAM,EAAE,oBAAoB,MAAM,iBA0B1G,CAAA;AAED;;GAEG;AACH,QAAA,MAAM,iBAAiB,GAAkB,MAAM,MAAM,EAAE,SAAS,MAAM,iBA0BrE,CAAA"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/*
|
|
2
|
+
SwapKit Integration
|
|
3
|
+
- API-only integration for cross-chain swaps
|
|
4
|
+
- Excludes THORChain and MayaChain assets (handled by dedicated integrations)
|
|
5
|
+
- Focuses on EVM chains and non-supported assets
|
|
6
|
+
*/
|
|
7
|
+
const TAG = " | swapkit | ";
|
|
8
|
+
const log = require('@pioneer-platform/loggerdog')();
|
|
9
|
+
const axios = require('axios');
|
|
10
|
+
let { caipToNetworkId, getChainEnumValue, caipToThorchain } = require("@pioneer-platform/pioneer-caip");
|
|
11
|
+
// SwapKit API configuration
|
|
12
|
+
const SWAPKIT_API_URL = process.env.SWAPKIT_API_URL || 'https://api.swapkit.dev';
|
|
13
|
+
const SWAPKIT_API_KEY = process.env.SWAPKIT_API_KEY || undefined;
|
|
14
|
+
// Supported networks - Prioritizing EVM chains and non-THORChain/MayaChain assets
|
|
15
|
+
let networkSupport = [
|
|
16
|
+
'eip155:1', // Ethereum
|
|
17
|
+
'eip155:42161', // Arbitrum
|
|
18
|
+
'eip155:8453', // Base
|
|
19
|
+
'eip155:43114', // Avalanche
|
|
20
|
+
'eip155:137', // Polygon
|
|
21
|
+
'eip155:10', // Optimism
|
|
22
|
+
'eip155:56', // BSC
|
|
23
|
+
'eip155:100', // Gnosis
|
|
24
|
+
'eip155:80094', // Berachain
|
|
25
|
+
'eip155:143', // Monad
|
|
26
|
+
'eip155:2868', // Hyperliquid
|
|
27
|
+
'eip155:146', // Sonic
|
|
28
|
+
'eip155:130', // Unichain
|
|
29
|
+
'eip155:1313161554', // Aurora
|
|
30
|
+
];
|
|
31
|
+
// Asset support - All supported assets (will filter out THOR/MAYA at quote time)
|
|
32
|
+
let assetSupport = [];
|
|
33
|
+
// Providers to exclude (THORChain and MayaChain)
|
|
34
|
+
const EXCLUDED_PROVIDERS = ['THORCHAIN', 'MAYACHAIN', 'MAYA'];
|
|
35
|
+
module.exports = {
|
|
36
|
+
init: async function (settings) {
|
|
37
|
+
try {
|
|
38
|
+
log.info(TAG, "Initializing SwapKit integration...");
|
|
39
|
+
// Build asset support list (native assets for each supported network)
|
|
40
|
+
assetSupport = await loadSupportedAssets();
|
|
41
|
+
log.info(TAG, "Loaded", assetSupport.length, "supported assets");
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
log.error(TAG, "Failed to initialize:", e);
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
networkSupport: function () {
|
|
50
|
+
return networkSupport.map(caip => caipToNetworkId(caip));
|
|
51
|
+
},
|
|
52
|
+
assetSupport: function () {
|
|
53
|
+
return assetSupport;
|
|
54
|
+
},
|
|
55
|
+
getQuote: function (quote) {
|
|
56
|
+
return get_quote(quote);
|
|
57
|
+
},
|
|
58
|
+
getRouteWithTx: function (routeId, sourceAddress, destinationAddress) {
|
|
59
|
+
return get_route_with_tx(routeId, sourceAddress, destinationAddress);
|
|
60
|
+
},
|
|
61
|
+
trackTransaction: function (txId, routeId) {
|
|
62
|
+
return track_transaction(txId, routeId);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Get available providers from SwapKit API
|
|
67
|
+
*/
|
|
68
|
+
const getProviders = async function () {
|
|
69
|
+
let tag = TAG + " | getProviders | ";
|
|
70
|
+
try {
|
|
71
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
72
|
+
if (SWAPKIT_API_KEY) {
|
|
73
|
+
headers['x-api-key'] = SWAPKIT_API_KEY;
|
|
74
|
+
}
|
|
75
|
+
const response = await axios.get(`${SWAPKIT_API_URL}/providers`, { headers });
|
|
76
|
+
// Filter out excluded providers
|
|
77
|
+
const providers = response.data.providers || [];
|
|
78
|
+
return providers.filter((p) => !EXCLUDED_PROVIDERS.includes(p.toUpperCase()));
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
log.error(tag, "Error fetching providers:", e);
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Load supported assets from SwapKit API
|
|
87
|
+
* Filters out THORChain and MayaChain assets
|
|
88
|
+
*/
|
|
89
|
+
const loadSupportedAssets = async function () {
|
|
90
|
+
let tag = TAG + " | loadSupportedAssets | ";
|
|
91
|
+
try {
|
|
92
|
+
// For now, return network-level support
|
|
93
|
+
// SwapKit API will handle asset-level validation
|
|
94
|
+
// We'll convert network CAIPs to asset CAIPs for native tokens
|
|
95
|
+
const nativeAssets = networkSupport.map(caip => {
|
|
96
|
+
// Convert network CAIP to native asset CAIP
|
|
97
|
+
// e.g., eip155:1 -> eip155:1/slip44:60 (ETH)
|
|
98
|
+
return caip + '/slip44:60'; // This is a simplified version, real implementation would map properly
|
|
99
|
+
});
|
|
100
|
+
return nativeAssets;
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
log.error(tag, "Error loading supported assets:", e);
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Convert CAIP asset identifier to SwapKit asset format
|
|
109
|
+
* SwapKit uses THORChain format: CHAIN.SYMBOL or CHAIN.SYMBOL-ADDRESS
|
|
110
|
+
* Examples:
|
|
111
|
+
* - eip155:1/slip44:60 -> ETH.ETH
|
|
112
|
+
* - eip155:8453/slip44:60 -> BASE.ETH
|
|
113
|
+
* - eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 -> ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48
|
|
114
|
+
*/
|
|
115
|
+
const caipToSwapKitAsset = function (caip, asset) {
|
|
116
|
+
let tag = TAG + " | caipToSwapKitAsset | ";
|
|
117
|
+
try {
|
|
118
|
+
// Get ticker symbol from the asset object
|
|
119
|
+
let ticker = asset?.symbol || asset?.ticker;
|
|
120
|
+
// Use pioneer-caip's caipToThorchain function - SwapKit uses same format
|
|
121
|
+
const swapkitFormat = caipToThorchain(caip, ticker);
|
|
122
|
+
if (!swapkitFormat) {
|
|
123
|
+
log.error(tag, "Failed to convert CAIP to SwapKit format:", caip, "ticker:", ticker);
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
log.info(tag, "Converted", caip, "->", swapkitFormat);
|
|
127
|
+
return swapkitFormat;
|
|
128
|
+
}
|
|
129
|
+
catch (e) {
|
|
130
|
+
log.error(tag, "Error converting CAIP to SwapKit format:", caip, e);
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Get quote from SwapKit API
|
|
136
|
+
*/
|
|
137
|
+
const get_quote = async function (quote) {
|
|
138
|
+
let tag = TAG + " | get_quote | ";
|
|
139
|
+
try {
|
|
140
|
+
log.info(tag, "Getting quote:", quote);
|
|
141
|
+
// Extract CAIP and asset objects
|
|
142
|
+
const sellAssetCaip = typeof quote.sellAsset === 'string' ? quote.sellAsset : quote.sellAsset.caip;
|
|
143
|
+
const buyAssetCaip = typeof quote.buyAsset === 'string' ? quote.buyAsset : quote.buyAsset.caip;
|
|
144
|
+
const sellAssetObj = typeof quote.sellAsset === 'object' ? quote.sellAsset : null;
|
|
145
|
+
const buyAssetObj = typeof quote.buyAsset === 'object' ? quote.buyAsset : null;
|
|
146
|
+
// Convert CAIP to SwapKit format (needs ticker from asset object)
|
|
147
|
+
const sellAsset = caipToSwapKitAsset(sellAssetCaip, sellAssetObj);
|
|
148
|
+
const buyAsset = caipToSwapKitAsset(buyAssetCaip, buyAssetObj);
|
|
149
|
+
if (!sellAsset || !buyAsset) {
|
|
150
|
+
log.error(tag, "Failed to convert assets to SwapKit format");
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
log.info(tag, "Converted assets - sell:", sellAsset, "buy:", buyAsset);
|
|
154
|
+
// Build request payload
|
|
155
|
+
// Following SwapKit recommended flow: initial quote without addresses (no balance check)
|
|
156
|
+
const payload = {
|
|
157
|
+
sellAsset,
|
|
158
|
+
sellAmount: quote.sellAmount,
|
|
159
|
+
buyAsset,
|
|
160
|
+
// NOTE: sourceAddress/destinationAddress can be omitted for initial quote
|
|
161
|
+
// This avoids balance verification and provides pricing info only
|
|
162
|
+
// For actual tx building, use includeTx: true with addresses
|
|
163
|
+
slippage: quote.slippage || 3,
|
|
164
|
+
providers: [] // Let SwapKit choose, but it will exclude THOR/MAYA
|
|
165
|
+
};
|
|
166
|
+
// Add addresses only if we want transaction data
|
|
167
|
+
// For now, we just want quotes, so we omit them to avoid balance checks
|
|
168
|
+
if (quote.includeTx) {
|
|
169
|
+
payload.sourceAddress = quote.senderAddress;
|
|
170
|
+
payload.destinationAddress = quote.recipientAddress;
|
|
171
|
+
}
|
|
172
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
173
|
+
if (SWAPKIT_API_KEY) {
|
|
174
|
+
headers['x-api-key'] = SWAPKIT_API_KEY;
|
|
175
|
+
}
|
|
176
|
+
log.info(tag, "Requesting quote from SwapKit API:", payload);
|
|
177
|
+
const response = await axios.post(`${SWAPKIT_API_URL}/quote`, payload, { headers });
|
|
178
|
+
log.info(tag, "Raw SwapKit response:", response.data);
|
|
179
|
+
if (!response.data || !response.data.routes || response.data.routes.length === 0) {
|
|
180
|
+
log.warn(tag, "No routes found from SwapKit");
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
// Filter out any THOR/MAYA routes that might have slipped through
|
|
184
|
+
const filteredRoutes = response.data.routes.filter(route => {
|
|
185
|
+
const provider = route.provider.toUpperCase();
|
|
186
|
+
return !EXCLUDED_PROVIDERS.includes(provider);
|
|
187
|
+
});
|
|
188
|
+
if (filteredRoutes.length === 0) {
|
|
189
|
+
log.warn(tag, "All routes were from excluded providers (THOR/MAYA)");
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
// Convert SwapKit response to Pioneer format
|
|
193
|
+
const quotes = filteredRoutes.map(route => {
|
|
194
|
+
return {
|
|
195
|
+
id: route.routeId,
|
|
196
|
+
source: 'swapkit',
|
|
197
|
+
provider: route.provider,
|
|
198
|
+
complete: true,
|
|
199
|
+
sellAsset: sellAssetCaip,
|
|
200
|
+
sellAmount: quote.sellAmount,
|
|
201
|
+
buyAsset: buyAssetCaip,
|
|
202
|
+
amountOut: route.expectedOutput,
|
|
203
|
+
buyAmount: route.expectedOutput,
|
|
204
|
+
meta: {
|
|
205
|
+
quoteMode: "SWAPKIT",
|
|
206
|
+
provider: route.provider,
|
|
207
|
+
route: route
|
|
208
|
+
},
|
|
209
|
+
fees: route.fees,
|
|
210
|
+
estimatedTime: route.estimatedTime.total,
|
|
211
|
+
path: route.path
|
|
212
|
+
};
|
|
213
|
+
});
|
|
214
|
+
log.info(tag, "Returning", quotes.length, "quotes");
|
|
215
|
+
return quotes;
|
|
216
|
+
}
|
|
217
|
+
catch (e) {
|
|
218
|
+
log.error(tag, "Error getting quote:", e.message || e);
|
|
219
|
+
if (e.response) {
|
|
220
|
+
log.error(tag, "API response error:", e.response.data);
|
|
221
|
+
}
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Get route with transaction details
|
|
227
|
+
*/
|
|
228
|
+
const get_route_with_tx = async function (routeId, sourceAddress, destinationAddress) {
|
|
229
|
+
let tag = TAG + " | get_route_with_tx | ";
|
|
230
|
+
try {
|
|
231
|
+
log.info(tag, "Getting route with tx:", { routeId, sourceAddress, destinationAddress });
|
|
232
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
233
|
+
if (SWAPKIT_API_KEY) {
|
|
234
|
+
headers['x-api-key'] = SWAPKIT_API_KEY;
|
|
235
|
+
}
|
|
236
|
+
const response = await axios.post(`${SWAPKIT_API_URL}/swap`, { routeId, sourceAddress, destinationAddress }, { headers });
|
|
237
|
+
log.info(tag, "Route with tx response:", response.data);
|
|
238
|
+
return response.data;
|
|
239
|
+
}
|
|
240
|
+
catch (e) {
|
|
241
|
+
log.error(tag, "Error getting route with tx:", e.message || e);
|
|
242
|
+
if (e.response) {
|
|
243
|
+
log.error(tag, "API response error:", e.response.data);
|
|
244
|
+
}
|
|
245
|
+
throw e;
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Track transaction status
|
|
250
|
+
*/
|
|
251
|
+
const track_transaction = async function (txId, routeId) {
|
|
252
|
+
let tag = TAG + " | track_transaction | ";
|
|
253
|
+
try {
|
|
254
|
+
log.info(tag, "Tracking transaction:", { txId, routeId });
|
|
255
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
256
|
+
if (SWAPKIT_API_KEY) {
|
|
257
|
+
headers['x-api-key'] = SWAPKIT_API_KEY;
|
|
258
|
+
}
|
|
259
|
+
const response = await axios.post(`${SWAPKIT_API_URL}/track`, { txId, routeId }, { headers });
|
|
260
|
+
log.info(tag, "Track response:", response.data);
|
|
261
|
+
return response.data;
|
|
262
|
+
}
|
|
263
|
+
catch (e) {
|
|
264
|
+
log.error(tag, "Error tracking transaction:", e.message || e);
|
|
265
|
+
if (e.response) {
|
|
266
|
+
log.error(tag, "API response error:", e.response.data);
|
|
267
|
+
}
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;EAKE;AAEF,MAAM,GAAG,GAAG,eAAe,CAAA;AAC3B,MAAM,GAAG,GAAG,OAAO,CAAC,6BAA6B,CAAC,EAAE,CAAA;AACpD,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAC9B,IAAI,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,gCAAgC,CAAC,CAAA;AAEvG,4BAA4B;AAC5B,MAAM,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,yBAAyB,CAAA;AAChF,MAAM,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,SAAS,CAAA;AAEhE,kFAAkF;AAClF,IAAI,cAAc,GAAG;IACjB,UAAU,EAAO,WAAW;IAC5B,cAAc,EAAG,WAAW;IAC5B,aAAa,EAAI,OAAO;IACxB,cAAc,EAAG,YAAY;IAC7B,YAAY,EAAK,UAAU;IAC3B,WAAW,EAAM,WAAW;IAC5B,WAAW,EAAM,MAAM;IACvB,YAAY,EAAK,SAAS;IAC1B,cAAc,EA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IAAI,eAAe,EAAE,CAAC;YAClB,OAAO,CAAC,WAAW,CAAC,GAAG,eAAe,CAAA;QAC1C,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAC7B,GAAG,eAAe,QAAQ,EAC1B,EAAE,IAAI,EAAE,OAAO,EAAE,EACjB,EAAE,OAAO,EAAE,CACd,CAAA;QAED,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,iBAAiB,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAA;QAC/C,OAAO,QAAQ,CAAC,IAAI,CAAA;IAExB,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QACd,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,6BAA6B,EAAE,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,CAAA;QAC7D,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;YACb,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,qBAAqB,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QAC1D,CAAC;QACD,OAAO,IAAI,CAAA;IACf,CAAC;AACL,CAAC,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pioneer-platform/swapkit-client",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"main": "./lib/index.js",
|
|
5
|
+
"types": "./lib/index.d.ts",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@pioneer-platform/loggerdog": "^8.11.0",
|
|
8
|
+
"@pioneer-platform/pioneer-caip": "^9.10.9",
|
|
9
|
+
"@pioneer-platform/pioneer-coins": "^9.11.9",
|
|
10
|
+
"axios": "^1.6.0",
|
|
11
|
+
"dotenv": "^17.2.3"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"npm": "pnpm i",
|
|
15
|
+
"test": "pnpm run build && node __tests__/test-module.js",
|
|
16
|
+
"build": "tsc -p .",
|
|
17
|
+
"prepublish": "pnpm run build",
|
|
18
|
+
"refresh": "rm -rf ./node_modules ./package-lock.json && pnpm install"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/jest": "^25.2.3",
|
|
22
|
+
"@types/node": "^18.16.0",
|
|
23
|
+
"@types/source-map-support": "^0.5.3",
|
|
24
|
+
"jest": "^26.4.2",
|
|
25
|
+
"onchange": "^7.0.2",
|
|
26
|
+
"serve": "^11.3.2",
|
|
27
|
+
"ts-jest": "^29.0.5",
|
|
28
|
+
"typescript": "^5.0.4"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require("dotenv").config({path:'../../../.env'})
|
|
2
|
+
const axios = require('axios')
|
|
3
|
+
|
|
4
|
+
async function testRoute(amount, name) {
|
|
5
|
+
const payload = {
|
|
6
|
+
sellAsset: "ETH.ETH",
|
|
7
|
+
buyAsset: "ARB.ETH",
|
|
8
|
+
sellAmount: amount,
|
|
9
|
+
slippage: 3,
|
|
10
|
+
includeTx: false
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const response = await axios.post(
|
|
15
|
+
'https://api.swapkit.dev/quote',
|
|
16
|
+
payload,
|
|
17
|
+
{ headers: {
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
'x-api-key': process.env.SWAPKIT_API_KEY
|
|
20
|
+
}}
|
|
21
|
+
)
|
|
22
|
+
const routes = response.data.routes || []
|
|
23
|
+
console.log('✅ ' + name + ': ' + routes.length + ' routes')
|
|
24
|
+
if (routes.length > 0) {
|
|
25
|
+
console.log(' Providers:', routes.map(r => r.provider || '(unnamed)').join(', '))
|
|
26
|
+
}
|
|
27
|
+
return true
|
|
28
|
+
} catch (e) {
|
|
29
|
+
const data = e.response ? e.response.data : {}
|
|
30
|
+
if (data.providerErrors) {
|
|
31
|
+
const errors = data.providerErrors.map(pe => pe.provider + ':' + pe.errorCode).join(', ')
|
|
32
|
+
console.log('⚠️ ' + name + ': ' + errors)
|
|
33
|
+
} else {
|
|
34
|
+
console.log('❌ ' + name + ': ' + (data.error || 'unknown'))
|
|
35
|
+
}
|
|
36
|
+
return false
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function test() {
|
|
41
|
+
console.log('Testing ETH → ARB with different amounts\n')
|
|
42
|
+
await testRoute("0.001", "0.001 ETH")
|
|
43
|
+
await testRoute("0.01", "0.01 ETH")
|
|
44
|
+
await testRoute("0.1", "0.1 ETH")
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
test()
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require("dotenv").config({path:'../../../.env'})
|
|
2
|
+
const axios = require('axios')
|
|
3
|
+
|
|
4
|
+
async function testRoute(sell, buy, name) {
|
|
5
|
+
const payload = {
|
|
6
|
+
sellAsset: sell,
|
|
7
|
+
buyAsset: buy,
|
|
8
|
+
sellAmount: "0.001",
|
|
9
|
+
slippage: 3,
|
|
10
|
+
includeTx: false
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const response = await axios.post(
|
|
15
|
+
'https://api.swapkit.dev/quote',
|
|
16
|
+
payload,
|
|
17
|
+
{ headers: {
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
'x-api-key': process.env.SWAPKIT_API_KEY
|
|
20
|
+
}}
|
|
21
|
+
)
|
|
22
|
+
const routes = response.data.routes || []
|
|
23
|
+
const providers = routes.map(r => r.provider).filter(Boolean).join(', ') || '(no providers listed)'
|
|
24
|
+
console.log('✅ ' + name + ': ' + routes.length + ' routes - ' + providers)
|
|
25
|
+
return true
|
|
26
|
+
} catch (e) {
|
|
27
|
+
const status = e.response ? e.response.status : 'unknown'
|
|
28
|
+
const data = e.response ? e.response.data : {}
|
|
29
|
+
if (data.providerErrors) {
|
|
30
|
+
console.log('⚠️ ' + name + ': ' + data.providerErrors.map(pe => pe.provider + ':' + pe.errorCode).join(', '))
|
|
31
|
+
} else if (data.error) {
|
|
32
|
+
console.log('❌ ' + name + ': ' + data.error)
|
|
33
|
+
} else {
|
|
34
|
+
console.log('❌ ' + name + ': HTTP ' + status)
|
|
35
|
+
}
|
|
36
|
+
return false
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function test() {
|
|
41
|
+
console.log('Testing SwapKit Routes\n')
|
|
42
|
+
|
|
43
|
+
// THORChain cross-chain (docs say these should work)
|
|
44
|
+
await testRoute("BTC.BTC", "ETH.ETH", "BTC → ETH")
|
|
45
|
+
await testRoute("ETH.ETH", "BTC.BTC", "ETH → BTC")
|
|
46
|
+
|
|
47
|
+
// L2 bridges (what user wants)
|
|
48
|
+
await testRoute("ETH.ETH", "BASE.ETH", "ETH → BASE")
|
|
49
|
+
await testRoute("ETH.ETH", "ARB.ETH", "ETH → ARB")
|
|
50
|
+
await testRoute("ETH.ETH", "OP.ETH", "ETH → OP")
|
|
51
|
+
|
|
52
|
+
// Same-chain DEX (1inch on Ethereum)
|
|
53
|
+
await testRoute("ETH.ETH", "ETH.USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", "ETH → USDC (Ethereum)")
|
|
54
|
+
|
|
55
|
+
// Other cross-chain
|
|
56
|
+
await testRoute("ETH.ETH", "AVAX.AVAX", "ETH → AVAX")
|
|
57
|
+
await testRoute("ETH.ETH", "BSC.BNB", "ETH → BNB")
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
test()
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"lib": ["ES2020"],
|
|
6
|
+
"outDir": "./lib",
|
|
7
|
+
"rootDir": "./src",
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"declarationMap": true,
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"strict": false,
|
|
12
|
+
"esModuleInterop": true,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"resolveJsonModule": true,
|
|
16
|
+
"moduleResolution": "node"
|
|
17
|
+
},
|
|
18
|
+
"include": ["src/**/*"],
|
|
19
|
+
"exclude": ["node_modules", "lib", "__tests__"]
|
|
20
|
+
}
|