@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.js
CHANGED
|
@@ -1246,23 +1246,33 @@ var SwapService = class {
|
|
|
1246
1246
|
this.loadAllPairs();
|
|
1247
1247
|
this.loadPartnerFee();
|
|
1248
1248
|
}
|
|
1249
|
+
get routerContractFunctionNames() {
|
|
1250
|
+
return {
|
|
1251
|
+
swapExactTokensForTokens: "swapExactTokensForTokens",
|
|
1252
|
+
swapTokensForExactTokens: "swapTokensForExactTokens",
|
|
1253
|
+
swapExactETHForTokens: "swapExactETHForTokens",
|
|
1254
|
+
swapETHForExactTokens: "swapETHForExactTokens",
|
|
1255
|
+
swapExactTokensForETH: "swapExactTokensForETH",
|
|
1256
|
+
swapTokensForExactETH: "swapTokensForExactETH"
|
|
1257
|
+
};
|
|
1258
|
+
}
|
|
1249
1259
|
get routerAbi() {
|
|
1250
1260
|
return [
|
|
1251
1261
|
// Swaps (ERC20 <-> ERC20)
|
|
1252
|
-
|
|
1253
|
-
|
|
1262
|
+
`function ${this.routerContractFunctionNames.swapExactTokensForTokens}(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)`,
|
|
1263
|
+
`function ${this.routerContractFunctionNames.swapTokensForExactTokens}(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)`,
|
|
1254
1264
|
// Swaps (ETH <-> ERC20)
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1265
|
+
`function ${this.routerContractFunctionNames.swapExactETHForTokens}(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)`,
|
|
1266
|
+
`function ${this.routerContractFunctionNames.swapETHForExactTokens}(uint amountOut, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)`,
|
|
1267
|
+
`function ${this.routerContractFunctionNames.swapExactTokensForETH}(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)`,
|
|
1268
|
+
`function ${this.routerContractFunctionNames.swapTokensForExactETH}(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)`,
|
|
1259
1269
|
// Get Amounts
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1270
|
+
`function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts)`,
|
|
1271
|
+
`function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut)`,
|
|
1272
|
+
`function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn)`,
|
|
1273
|
+
`function getAmountsIn(uint amountOut, address[] memory path) internal view returns (uint[] memory amounts)`,
|
|
1264
1274
|
// Get WETH
|
|
1265
|
-
|
|
1275
|
+
`function WETH() external pure returns (address)`
|
|
1266
1276
|
];
|
|
1267
1277
|
}
|
|
1268
1278
|
get factoryAbi() {
|
|
@@ -1623,6 +1633,7 @@ var SwapService = class {
|
|
|
1623
1633
|
if (!this.signer) {
|
|
1624
1634
|
throw new Error("Please connect wallet first");
|
|
1625
1635
|
}
|
|
1636
|
+
console.log("from the insiddeee", this.routerContractFunctionNames);
|
|
1626
1637
|
try {
|
|
1627
1638
|
const deadlineTimestamp = Math.floor(Date.now() / 1e3) + deadline * 60;
|
|
1628
1639
|
let tx;
|
|
@@ -1632,14 +1643,14 @@ var SwapService = class {
|
|
|
1632
1643
|
const to = this.config.proxyAddress ? this.config.proxyAddress : signerAddress;
|
|
1633
1644
|
if (isOutputAmount) {
|
|
1634
1645
|
if (fromToken.address === ethers.ZeroAddress) {
|
|
1635
|
-
swapData = iface.encodeFunctionData(
|
|
1646
|
+
swapData = iface.encodeFunctionData(this.routerContractFunctionNames.swapETHForExactTokens, [
|
|
1636
1647
|
amountOutWei,
|
|
1637
1648
|
path,
|
|
1638
1649
|
to,
|
|
1639
1650
|
deadlineTimestamp
|
|
1640
1651
|
]);
|
|
1641
1652
|
} else if (toToken.address === ethers.ZeroAddress) {
|
|
1642
|
-
swapData = iface.encodeFunctionData(
|
|
1653
|
+
swapData = iface.encodeFunctionData(this.routerContractFunctionNames.swapTokensForExactETH, [
|
|
1643
1654
|
amountOutWei,
|
|
1644
1655
|
amountInWei,
|
|
1645
1656
|
path,
|
|
@@ -1647,7 +1658,7 @@ var SwapService = class {
|
|
|
1647
1658
|
deadlineTimestamp
|
|
1648
1659
|
]);
|
|
1649
1660
|
} else {
|
|
1650
|
-
swapData = iface.encodeFunctionData(
|
|
1661
|
+
swapData = iface.encodeFunctionData(this.routerContractFunctionNames.swapTokensForExactTokens, [
|
|
1651
1662
|
amountOutWei,
|
|
1652
1663
|
amountInWei,
|
|
1653
1664
|
path,
|
|
@@ -1657,14 +1668,14 @@ var SwapService = class {
|
|
|
1657
1668
|
}
|
|
1658
1669
|
} else {
|
|
1659
1670
|
if (fromToken.address === ethers.ZeroAddress) {
|
|
1660
|
-
swapData = iface.encodeFunctionData(
|
|
1671
|
+
swapData = iface.encodeFunctionData(this.routerContractFunctionNames.swapExactETHForTokens, [
|
|
1661
1672
|
amountOutWei,
|
|
1662
1673
|
path,
|
|
1663
1674
|
to,
|
|
1664
1675
|
deadlineTimestamp
|
|
1665
1676
|
]);
|
|
1666
1677
|
} else if (toToken.address === ethers.ZeroAddress) {
|
|
1667
|
-
swapData = iface.encodeFunctionData(
|
|
1678
|
+
swapData = iface.encodeFunctionData(this.routerContractFunctionNames.swapExactTokensForETH, [
|
|
1668
1679
|
amountInWei,
|
|
1669
1680
|
amountOutWei,
|
|
1670
1681
|
path,
|
|
@@ -1672,7 +1683,7 @@ var SwapService = class {
|
|
|
1672
1683
|
deadlineTimestamp
|
|
1673
1684
|
]);
|
|
1674
1685
|
} else {
|
|
1675
|
-
swapData = iface.encodeFunctionData(
|
|
1686
|
+
swapData = iface.encodeFunctionData(this.routerContractFunctionNames.swapExactTokensForTokens, [
|
|
1676
1687
|
amountInWei,
|
|
1677
1688
|
amountOutWei,
|
|
1678
1689
|
path,
|