@kaspacom/swap-sdk 1.1.7 → 1.1.9
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/index.cjs +28 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.global.js +28 -17
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +28 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1278,23 +1278,33 @@ var SwapService = class {
|
|
|
1278
1278
|
this.loadAllPairs();
|
|
1279
1279
|
this.loadPartnerFee();
|
|
1280
1280
|
}
|
|
1281
|
+
get routerContractFunctionNames() {
|
|
1282
|
+
return {
|
|
1283
|
+
swapExactTokensForTokens: "swapExactTokensForTokens",
|
|
1284
|
+
swapTokensForExactTokens: "swapTokensForExactTokens",
|
|
1285
|
+
swapExactETHForTokens: "swapExactETHForTokens",
|
|
1286
|
+
swapETHForExactTokens: "swapETHForExactTokens",
|
|
1287
|
+
swapExactTokensForETH: "swapExactTokensForETH",
|
|
1288
|
+
swapTokensForExactETH: "swapTokensForExactETH"
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1281
1291
|
get routerAbi() {
|
|
1282
1292
|
return [
|
|
1283
1293
|
// Swaps (ERC20 <-> ERC20)
|
|
1284
|
-
|
|
1285
|
-
|
|
1294
|
+
`function ${this.routerContractFunctionNames.swapExactTokensForTokens}(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)`,
|
|
1295
|
+
`function ${this.routerContractFunctionNames.swapTokensForExactTokens}(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)`,
|
|
1286
1296
|
// Swaps (ETH <-> ERC20)
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1297
|
+
`function ${this.routerContractFunctionNames.swapExactETHForTokens}(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)`,
|
|
1298
|
+
`function ${this.routerContractFunctionNames.swapETHForExactTokens}(uint amountOut, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)`,
|
|
1299
|
+
`function ${this.routerContractFunctionNames.swapExactTokensForETH}(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)`,
|
|
1300
|
+
`function ${this.routerContractFunctionNames.swapTokensForExactETH}(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)`,
|
|
1291
1301
|
// Get Amounts
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1302
|
+
`function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts)`,
|
|
1303
|
+
`function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut)`,
|
|
1304
|
+
`function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn)`,
|
|
1305
|
+
`function getAmountsIn(uint amountOut, address[] memory path) internal view returns (uint[] memory amounts)`,
|
|
1296
1306
|
// Get WETH
|
|
1297
|
-
|
|
1307
|
+
`function WETH() external pure returns (address)`
|
|
1298
1308
|
];
|
|
1299
1309
|
}
|
|
1300
1310
|
get factoryAbi() {
|
|
@@ -1655,6 +1665,7 @@ var SwapService = class {
|
|
|
1655
1665
|
if (!this.signer) {
|
|
1656
1666
|
throw new Error("Please connect wallet first");
|
|
1657
1667
|
}
|
|
1668
|
+
console.log("from the insiddeee", this.routerContractFunctionNames);
|
|
1658
1669
|
try {
|
|
1659
1670
|
const deadlineTimestamp = Math.floor(Date.now() / 1e3) + deadline * 60;
|
|
1660
1671
|
let tx;
|
|
@@ -1664,14 +1675,14 @@ var SwapService = class {
|
|
|
1664
1675
|
const to = this.config.proxyAddress ? this.config.proxyAddress : signerAddress;
|
|
1665
1676
|
if (isOutputAmount) {
|
|
1666
1677
|
if (fromToken.address === import_ethers2.ethers.ZeroAddress) {
|
|
1667
|
-
swapData = iface.encodeFunctionData(
|
|
1678
|
+
swapData = iface.encodeFunctionData(this.routerContractFunctionNames.swapETHForExactTokens, [
|
|
1668
1679
|
amountOutWei,
|
|
1669
1680
|
path,
|
|
1670
1681
|
to,
|
|
1671
1682
|
deadlineTimestamp
|
|
1672
1683
|
]);
|
|
1673
1684
|
} else if (toToken.address === import_ethers2.ethers.ZeroAddress) {
|
|
1674
|
-
swapData = iface.encodeFunctionData(
|
|
1685
|
+
swapData = iface.encodeFunctionData(this.routerContractFunctionNames.swapTokensForExactETH, [
|
|
1675
1686
|
amountOutWei,
|
|
1676
1687
|
amountInWei,
|
|
1677
1688
|
path,
|
|
@@ -1679,7 +1690,7 @@ var SwapService = class {
|
|
|
1679
1690
|
deadlineTimestamp
|
|
1680
1691
|
]);
|
|
1681
1692
|
} else {
|
|
1682
|
-
swapData = iface.encodeFunctionData(
|
|
1693
|
+
swapData = iface.encodeFunctionData(this.routerContractFunctionNames.swapTokensForExactTokens, [
|
|
1683
1694
|
amountOutWei,
|
|
1684
1695
|
amountInWei,
|
|
1685
1696
|
path,
|
|
@@ -1689,14 +1700,14 @@ var SwapService = class {
|
|
|
1689
1700
|
}
|
|
1690
1701
|
} else {
|
|
1691
1702
|
if (fromToken.address === import_ethers2.ethers.ZeroAddress) {
|
|
1692
|
-
swapData = iface.encodeFunctionData(
|
|
1703
|
+
swapData = iface.encodeFunctionData(this.routerContractFunctionNames.swapExactETHForTokens, [
|
|
1693
1704
|
amountOutWei,
|
|
1694
1705
|
path,
|
|
1695
1706
|
to,
|
|
1696
1707
|
deadlineTimestamp
|
|
1697
1708
|
]);
|
|
1698
1709
|
} else if (toToken.address === import_ethers2.ethers.ZeroAddress) {
|
|
1699
|
-
swapData = iface.encodeFunctionData(
|
|
1710
|
+
swapData = iface.encodeFunctionData(this.routerContractFunctionNames.swapExactTokensForETH, [
|
|
1700
1711
|
amountInWei,
|
|
1701
1712
|
amountOutWei,
|
|
1702
1713
|
path,
|
|
@@ -1704,7 +1715,7 @@ var SwapService = class {
|
|
|
1704
1715
|
deadlineTimestamp
|
|
1705
1716
|
]);
|
|
1706
1717
|
} else {
|
|
1707
|
-
swapData = iface.encodeFunctionData(
|
|
1718
|
+
swapData = iface.encodeFunctionData(this.routerContractFunctionNames.swapExactTokensForTokens, [
|
|
1708
1719
|
amountInWei,
|
|
1709
1720
|
amountOutWei,
|
|
1710
1721
|
path,
|