@kaspacom/swap-sdk 1.1.18 → 1.1.20
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/README.md +1 -1
- package/dist/index.cjs +61 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -17
- package/dist/index.d.ts +23 -17
- package/dist/index.global.js +61 -57
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +61 -57
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -101,7 +101,7 @@ console.log(tokens);
|
|
|
101
101
|
### createKaspaComSwapController(options)
|
|
102
102
|
Creates and returns a `SwapSdkController` instance. Accepts either a preset string for `networkConfig` or a full `SwapSdkNetworkConfig` object.
|
|
103
103
|
|
|
104
|
-
- **options.networkConfig**: `'kasplex-testnet'`, `'kasplex'` or `SwapSdkNetworkConfig`
|
|
104
|
+
- **options.networkConfig**: `'kasplex-testnet'`, `'igra-testnet'`, `'kasplex'` or `SwapSdkNetworkConfig`
|
|
105
105
|
- **options.walletProvider**: EIP-1193 provider (e.g., `window.ethereum`)
|
|
106
106
|
- **options.partnerKey?**: Optional partner key string
|
|
107
107
|
- **options.onChange?**: `(state, patch) => Promise<void>` callback invoked on any state change
|
package/dist/index.cjs
CHANGED
|
@@ -1255,6 +1255,7 @@ var SwapService = class {
|
|
|
1255
1255
|
this.swapOptions = swapOptions;
|
|
1256
1256
|
this.signer = null;
|
|
1257
1257
|
this.pairs = [];
|
|
1258
|
+
this.tokensByAddress = {};
|
|
1258
1259
|
this.resolvePairsLoaded = null;
|
|
1259
1260
|
this.rejectPairsLoaded = null;
|
|
1260
1261
|
this.resolvePartnerFeeLoaded = null;
|
|
@@ -1364,28 +1365,17 @@ var SwapService = class {
|
|
|
1364
1365
|
}
|
|
1365
1366
|
return num.toFixed(decimals);
|
|
1366
1367
|
}
|
|
1367
|
-
async
|
|
1368
|
-
const
|
|
1369
|
-
|
|
1370
|
-
id
|
|
1371
|
-
reserve0
|
|
1372
|
-
reserve1
|
|
1373
|
-
token0 { id symbol name decimals }
|
|
1374
|
-
token1 { id symbol name decimals }
|
|
1375
|
-
}
|
|
1376
|
-
}`;
|
|
1377
|
-
const response = await fetch(this.config.graphEndpoint, {
|
|
1378
|
-
method: "POST",
|
|
1379
|
-
headers: { "Content-Type": "application/json" },
|
|
1380
|
-
body: JSON.stringify({ query })
|
|
1368
|
+
async refreshPairsFromBackend() {
|
|
1369
|
+
const response = await fetch(`${this.config.badckendApiUrl}/dex/graph-pairs`, {
|
|
1370
|
+
method: "GET"
|
|
1381
1371
|
});
|
|
1382
1372
|
if (!response.ok) throw new Error(`Network error: ${response.status}`);
|
|
1383
|
-
const
|
|
1384
|
-
if (!data
|
|
1385
|
-
return data
|
|
1373
|
+
const data = await response.json();
|
|
1374
|
+
if (!data) throw new Error(`No pairs found: ${data}`);
|
|
1375
|
+
return data;
|
|
1386
1376
|
}
|
|
1387
1377
|
async refreshPairs() {
|
|
1388
|
-
const pairsResult = this.swapOptions.getPairsData ? await this.swapOptions.getPairsData() : await this.
|
|
1378
|
+
const pairsResult = this.swapOptions.getPairsData ? await this.swapOptions.getPairsData() : await this.refreshPairsFromBackend();
|
|
1389
1379
|
const pairs = [];
|
|
1390
1380
|
for (const pair of pairsResult) {
|
|
1391
1381
|
pairs.push(
|
|
@@ -1393,6 +1383,11 @@ var SwapService = class {
|
|
|
1393
1383
|
);
|
|
1394
1384
|
}
|
|
1395
1385
|
this.pairs = pairs;
|
|
1386
|
+
this.tokensByAddress = pairsResult.reduce((acc, pair) => {
|
|
1387
|
+
acc[pair.token0.id.toLowerCase()] = pair.token0;
|
|
1388
|
+
acc[pair.token1.id.toLowerCase()] = pair.token1;
|
|
1389
|
+
return acc;
|
|
1390
|
+
}, {});
|
|
1396
1391
|
}
|
|
1397
1392
|
/**
|
|
1398
1393
|
* Loads all pairs from The Graph and caches them as Uniswap SDK Pair instances.
|
|
@@ -1801,40 +1796,23 @@ var SwapService = class {
|
|
|
1801
1796
|
* @param graphEndpoint The GraphQL endpoint URL
|
|
1802
1797
|
* @param search Optional search string for symbol or name
|
|
1803
1798
|
*/
|
|
1804
|
-
async getTokensFromGraph(limit
|
|
1805
|
-
|
|
1806
|
-
const
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
method: "POST",
|
|
1822
|
-
headers: { "Content-Type": "application/json" },
|
|
1823
|
-
body: JSON.stringify({ query })
|
|
1824
|
-
});
|
|
1825
|
-
if (!response.ok) throw new Error(`Network error: ${response.status}`);
|
|
1826
|
-
const { data } = await response.json();
|
|
1827
|
-
if (!data || !data.tokens) return [];
|
|
1828
|
-
return data.tokens.map((token) => ({
|
|
1829
|
-
address: token.id,
|
|
1830
|
-
symbol: token.symbol,
|
|
1831
|
-
name: token.name,
|
|
1832
|
-
decimals: Number(token.decimals)
|
|
1833
|
-
}));
|
|
1834
|
-
} catch (error) {
|
|
1835
|
-
console.error("Error fetching tokens from graph:", error);
|
|
1836
|
-
return [];
|
|
1837
|
-
}
|
|
1799
|
+
async getTokensFromGraph(limit, search) {
|
|
1800
|
+
await this.waitForPairsLoaded();
|
|
1801
|
+
const allTokens = Object.values(this.tokensByAddress);
|
|
1802
|
+
let result = allTokens;
|
|
1803
|
+
if (search) {
|
|
1804
|
+
const searchLowerCase = search.toLowerCase();
|
|
1805
|
+
result = result.filter((token) => token.symbol.toLowerCase().includes(searchLowerCase) || token.name.toLowerCase().includes(searchLowerCase));
|
|
1806
|
+
}
|
|
1807
|
+
if (limit) {
|
|
1808
|
+
result = result.slice(0, limit);
|
|
1809
|
+
}
|
|
1810
|
+
return result.map((token) => ({
|
|
1811
|
+
address: token.id,
|
|
1812
|
+
name: token.name,
|
|
1813
|
+
symbol: token.symbol,
|
|
1814
|
+
decimals: Number.parseInt(token.decimals, 10)
|
|
1815
|
+
}));
|
|
1838
1816
|
}
|
|
1839
1817
|
/**
|
|
1840
1818
|
* Concatenates bytes: selector, array of bytes (each element is Uint8Array), array length (uint8, 1 byte), marker (bytes16(keccak256(markerString)))
|
|
@@ -2052,7 +2030,7 @@ var SwapSdkController = class {
|
|
|
2052
2030
|
async getPartnerFee() {
|
|
2053
2031
|
return Number(await this.swapService.loadPartnerFee()) / 100;
|
|
2054
2032
|
}
|
|
2055
|
-
async getTokensFromGraph(limit
|
|
2033
|
+
async getTokensFromGraph(limit, search) {
|
|
2056
2034
|
if (!this.swapService) {
|
|
2057
2035
|
throw new Error("Swap Service not exists");
|
|
2058
2036
|
}
|
|
@@ -2071,7 +2049,7 @@ var SwapSdkController = class {
|
|
|
2071
2049
|
}
|
|
2072
2050
|
}
|
|
2073
2051
|
async refreshTokensAndUpdateQuote(forceQuoteUpdate = false) {
|
|
2074
|
-
await this.swapService?.
|
|
2052
|
+
await this.swapService?.refreshPairsFromBackend();
|
|
2075
2053
|
if ((this.options.updateQuoteAfterRefreshPairs || forceQuoteUpdate) && !this.state.loader) {
|
|
2076
2054
|
await this.calculateQuoteIfNeeded();
|
|
2077
2055
|
}
|
|
@@ -2092,11 +2070,11 @@ var NETWORKS = {
|
|
|
2092
2070
|
"kasplex-testnet": {
|
|
2093
2071
|
name: "Kasplex Test",
|
|
2094
2072
|
chainId: 167012,
|
|
2095
|
-
rpcUrl: "https://rpc.
|
|
2073
|
+
rpcUrl: "https://rpc.kasplextest.xyz",
|
|
2096
2074
|
routerAddress: "0x81Cc4e7DbC652ec9168Bc2F4435C02d7F315148e",
|
|
2097
2075
|
factoryAddress: "0x89d5842017ceA7dd18D10EE6c679cE199d2aD99E",
|
|
2098
2076
|
proxyAddress: "0x5B7e7830851816f8ad968B0e0c336bd50b4860Ad",
|
|
2099
|
-
|
|
2077
|
+
badckendApiUrl: "https://dev-api-defi.kaspa.com",
|
|
2100
2078
|
blockExplorerUrl: "https://explorer.testnet.kasplextest.xyz",
|
|
2101
2079
|
additionalJsonRpcApiProviderOptionsOptions: {
|
|
2102
2080
|
batchMaxCount: 1,
|
|
@@ -2117,6 +2095,32 @@ var NETWORKS = {
|
|
|
2117
2095
|
},
|
|
2118
2096
|
isTestnet: true
|
|
2119
2097
|
},
|
|
2098
|
+
"igra-testnet": {
|
|
2099
|
+
name: "Igra Caravel",
|
|
2100
|
+
chainId: 19416,
|
|
2101
|
+
rpcUrl: "https://caravel.igralabs.com:8545",
|
|
2102
|
+
routerAddress: "0x9a5514828a3c2b36920b7c4fe0d6bd7fe8e8924f",
|
|
2103
|
+
factoryAddress: "0x1a8136A6da6CA7fe8960c4d098d90Ba2BA712B9F",
|
|
2104
|
+
proxyAddress: "0x47f80b6d7071b7738d6dd9d973d7515ce753e9d9",
|
|
2105
|
+
badckendApiUrl: "https://dev-api-defi.kaspa.com",
|
|
2106
|
+
blockExplorerUrl: "https://explorer.caravel.igralabs.com",
|
|
2107
|
+
additionalJsonRpcApiProviderOptionsOptions: {
|
|
2108
|
+
batchMaxSize: 0
|
|
2109
|
+
},
|
|
2110
|
+
wrappedToken: {
|
|
2111
|
+
address: "0x65C280485cA2Ea32aB6A684E2e0646ff1F842A80",
|
|
2112
|
+
decimals: 18,
|
|
2113
|
+
name: "Igra Wrapped Kaspa",
|
|
2114
|
+
symbol: "IWKAS"
|
|
2115
|
+
},
|
|
2116
|
+
nativeToken: {
|
|
2117
|
+
address: import_ethers3.ethers.ZeroAddress,
|
|
2118
|
+
decimals: 18,
|
|
2119
|
+
name: "Igra Kaspa",
|
|
2120
|
+
symbol: "IKAS"
|
|
2121
|
+
},
|
|
2122
|
+
isTestnet: true
|
|
2123
|
+
},
|
|
2120
2124
|
"kasplex": {
|
|
2121
2125
|
name: "Kasplex",
|
|
2122
2126
|
chainId: 202555,
|
|
@@ -2124,7 +2128,7 @@ var NETWORKS = {
|
|
|
2124
2128
|
routerAddress: "0x3a1f0bD164fe9D8fa18Da5abAB352dC634CA5F10",
|
|
2125
2129
|
factoryAddress: "0xa9CBa43A407c9Eb30933EA21f7b9D74A128D613c",
|
|
2126
2130
|
proxyAddress: "0x4c5BEaAE83577E3a117ce2F477fC42a1EA39A8a3",
|
|
2127
|
-
|
|
2131
|
+
badckendApiUrl: "https://api-defi.kaspa.com",
|
|
2128
2132
|
blockExplorerUrl: "https://explorer.kasplex.org",
|
|
2129
2133
|
additionalJsonRpcApiProviderOptionsOptions: {
|
|
2130
2134
|
batchMaxCount: 1,
|