From bc3d9bc5ab5f42b33acc0d19de352e54081efdf9 Mon Sep 17 00:00:00 2001 From: bhavik Date: Fri, 3 Dec 2021 17:38:48 +0530 Subject: [PATCH 1/6] added paraswap on mainnet --- .../avalanche/connectors/paraswap/helpers.sol | 45 +++++++----- .../mainnet/connectors/paraswap/events.sol | 11 +++ .../mainnet/connectors/paraswap/helpers.sol | 70 +++++++++++++++++++ .../mainnet/connectors/paraswap/interface.sol | 5 ++ .../mainnet/connectors/paraswap/main.sol | 55 +++++++++++++++ 5 files changed, 170 insertions(+), 16 deletions(-) create mode 100644 contracts/mainnet/connectors/paraswap/events.sol create mode 100644 contracts/mainnet/connectors/paraswap/helpers.sol create mode 100644 contracts/mainnet/connectors/paraswap/interface.sol create mode 100644 contracts/mainnet/connectors/paraswap/main.sol diff --git a/contracts/avalanche/connectors/paraswap/helpers.sol b/contracts/avalanche/connectors/paraswap/helpers.sol index ccee429b..861f3760 100644 --- a/contracts/avalanche/connectors/paraswap/helpers.sol +++ b/contracts/avalanche/connectors/paraswap/helpers.sol @@ -1,12 +1,11 @@ pragma solidity ^0.7.0; -import { DSMath } from "../../common/math.sol"; -import { Basic } from "../../common/basic.sol"; -import { TokenInterface } from "../../common/interfaces.sol"; -import { AugustusSwapperInterface } from "./interface.sol"; +import {DSMath} from "../../common/math.sol"; +import {Basic} from "../../common/basic.sol"; +import {TokenInterface} from "../../common/interfaces.sol"; +import {AugustusSwapperInterface} from "./interface.sol"; abstract contract Helpers is DSMath, Basic { - struct SwapData { TokenInterface sellToken; TokenInterface buyToken; @@ -16,17 +15,27 @@ abstract contract Helpers is DSMath, Basic { bytes callData; } - address internal constant paraswap = 0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57; + address internal constant paraswap = + 0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57; - function _swapHelper(SwapData memory swapData, uint256 wmaticAmt) internal returns (uint256 buyAmt) { + function _swapHelper(SwapData memory swapData, uint256 wavaxAmt) + internal + returns (uint256 buyAmt) + { TokenInterface buyToken = swapData.buyToken; - (uint256 _buyDec, uint256 _sellDec) = getTokensDec(buyToken, swapData.sellToken); + (uint256 _buyDec, uint256 _sellDec) = getTokensDec( + buyToken, + swapData.sellToken + ); uint256 _sellAmt18 = convertTo18(_sellDec, swapData._sellAmt); - uint256 _slippageAmt = convert18ToDec(_buyDec, wmul(swapData.unitAmt, _sellAmt18)); + uint256 _slippageAmt = convert18ToDec( + _buyDec, + wmul(swapData.unitAmt, _sellAmt18) + ); uint256 initalBal = getTokenBal(buyToken); - (bool success, ) = paraswap.call{value: wmaticAmt}(swapData.callData); + (bool success, ) = paraswap.call{value: wavaxAmt}(swapData.callData); if (!success) revert("paraswap-failed"); uint256 finalBal = getTokenBal(buyToken); @@ -36,22 +45,26 @@ abstract contract Helpers is DSMath, Basic { require(_slippageAmt <= buyAmt, "Too much slippage"); } - function _swap(SwapData memory swapData, uint256 setId) internal returns (SwapData memory) { + function _swap(SwapData memory swapData, uint256 setId) + internal + returns (SwapData memory) + { TokenInterface _sellAddr = swapData.sellToken; - uint256 maticAmt; + uint256 avaxAmt; if (address(_sellAddr) == avaxAddr) { - maticAmt = swapData._sellAmt; + avaxAmt = swapData._sellAmt; } else { - address tokenProxy = AugustusSwapperInterface(paraswap).getTokenTransferProxy(); + address tokenProxy = AugustusSwapperInterface(paraswap) + .getTokenTransferProxy(); approve(TokenInterface(_sellAddr), tokenProxy, swapData._sellAmt); } - swapData._buyAmt = _swapHelper(swapData, maticAmt); + swapData._buyAmt = _swapHelper(swapData, avaxAmt); setUint(setId, swapData._buyAmt); return swapData; } -} \ No newline at end of file +} diff --git a/contracts/mainnet/connectors/paraswap/events.sol b/contracts/mainnet/connectors/paraswap/events.sol new file mode 100644 index 00000000..0f9470dc --- /dev/null +++ b/contracts/mainnet/connectors/paraswap/events.sol @@ -0,0 +1,11 @@ +pragma solidity ^0.7.0; + +contract Events { + event LogSwap( + address buyToken, + address sellToken, + uint256 buyAmt, + uint256 sellAmt, + uint256 setId + ); +} \ No newline at end of file diff --git a/contracts/mainnet/connectors/paraswap/helpers.sol b/contracts/mainnet/connectors/paraswap/helpers.sol new file mode 100644 index 00000000..8f8e8d74 --- /dev/null +++ b/contracts/mainnet/connectors/paraswap/helpers.sol @@ -0,0 +1,70 @@ +pragma solidity ^0.7.0; + +import {DSMath} from "../../common/math.sol"; +import {Basic} from "../../common/basic.sol"; +import {TokenInterface} from "../../common/interfaces.sol"; +import {AugustusSwapperInterface} from "./interface.sol"; + +abstract contract Helpers is DSMath, Basic { + struct SwapData { + TokenInterface sellToken; + TokenInterface buyToken; + uint256 _sellAmt; + uint256 _buyAmt; + uint256 unitAmt; + bytes callData; + } + + address internal constant paraswap = + 0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57; + + function _swapHelper(SwapData memory swapData, uint256 wethAmt) + internal + returns (uint256 buyAmt) + { + TokenInterface buyToken = swapData.buyToken; + (uint256 _buyDec, uint256 _sellDec) = getTokensDec( + buyToken, + swapData.sellToken + ); + uint256 _sellAmt18 = convertTo18(_sellDec, swapData._sellAmt); + uint256 _slippageAmt = convert18ToDec( + _buyDec, + wmul(swapData.unitAmt, _sellAmt18) + ); + + uint256 initalBal = getTokenBal(buyToken); + + (bool success, ) = paraswap.call{value: wethAmt}(swapData.callData); + if (!success) revert("paraswap-failed"); + + uint256 finalBal = getTokenBal(buyToken); + + buyAmt = sub(finalBal, initalBal); + + require(_slippageAmt <= buyAmt, "Too much slippage"); + } + + function _swap(SwapData memory swapData, uint256 setId) + internal + returns (SwapData memory) + { + TokenInterface _sellAddr = swapData.sellToken; + + uint256 ethAmt; + + if (address(_sellAddr) == ethAddr) { + ethAmt = swapData._sellAmt; + } else { + address tokenProxy = AugustusSwapperInterface(paraswap) + .getTokenTransferProxy(); + approve(TokenInterface(_sellAddr), tokenProxy, swapData._sellAmt); + } + + swapData._buyAmt = _swapHelper(swapData, ethAmt); + + setUint(setId, swapData._buyAmt); + + return swapData; + } +} diff --git a/contracts/mainnet/connectors/paraswap/interface.sol b/contracts/mainnet/connectors/paraswap/interface.sol new file mode 100644 index 00000000..a63b4c77 --- /dev/null +++ b/contracts/mainnet/connectors/paraswap/interface.sol @@ -0,0 +1,5 @@ +pragma solidity ^0.7.0; + +interface AugustusSwapperInterface { + function getTokenTransferProxy() external view returns (address); +} \ No newline at end of file diff --git a/contracts/mainnet/connectors/paraswap/main.sol b/contracts/mainnet/connectors/paraswap/main.sol new file mode 100644 index 00000000..2041c11c --- /dev/null +++ b/contracts/mainnet/connectors/paraswap/main.sol @@ -0,0 +1,55 @@ +pragma solidity ^0.7.0; + +/** + * @title Paraswap. + * @dev DEX Aggregator. + */ + +import { TokenInterface } from "../../common/interfaces.sol"; +import { Stores } from "../../common/stores.sol"; +import { Helpers } from "./helpers.sol"; + +abstract contract ParaswapResolver is Helpers { + /** + * @dev Sell ETH/ERC20_Token using ParaSwap. + * @notice Swap tokens from exchanges like kyber, 0x etc, with calculation done off-chain. + * @param buyAddr The address of the token to buy.(For MATIC: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param sellAddr The address of the token to sell.(For MATIC: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param sellAmt The amount of the token to sell. + * @param unitAmt The amount of buyAmt/sellAmt with slippage. + * @param callData Data from paraswap API. + * @param setId ID stores the amount of token brought. + */ + function swap( + address buyAddr, + address sellAddr, + uint256 sellAmt, + uint256 unitAmt, + bytes calldata callData, + uint256 setId + ) external payable returns (string memory _eventName, bytes memory _eventParam) { + Helpers.SwapData memory swapData = Helpers.SwapData({ + buyToken: TokenInterface(buyAddr), + sellToken: TokenInterface(sellAddr), + unitAmt: unitAmt, + callData: callData, + _sellAmt: sellAmt, + _buyAmt: 0 + }); + + swapData = _swap(swapData, setId); + + _eventName = "LogSwap(address,address,uint256,uint256,uint256)"; + _eventParam = abi.encode( + address(swapData.buyToken), + address(swapData.sellToken), + swapData._buyAmt, + swapData._sellAmt, + setId + ); + } +} + +contract ConnectV2Paraswap is ParaswapResolver { + string public name = "Paraswap-v1"; +} \ No newline at end of file From dfe3a9e056c31438721642e51808409f13cf8515 Mon Sep 17 00:00:00 2001 From: bhavik Date: Fri, 3 Dec 2021 23:13:41 +0530 Subject: [PATCH 2/6] updated-comments --- .../mainnet/connectors/paraswap/main.sol | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/contracts/mainnet/connectors/paraswap/main.sol b/contracts/mainnet/connectors/paraswap/main.sol index 2041c11c..ad152a66 100644 --- a/contracts/mainnet/connectors/paraswap/main.sol +++ b/contracts/mainnet/connectors/paraswap/main.sol @@ -5,21 +5,21 @@ pragma solidity ^0.7.0; * @dev DEX Aggregator. */ -import { TokenInterface } from "../../common/interfaces.sol"; -import { Stores } from "../../common/stores.sol"; -import { Helpers } from "./helpers.sol"; +import {TokenInterface} from "../../common/interfaces.sol"; +import {Stores} from "../../common/stores.sol"; +import {Helpers} from "./helpers.sol"; abstract contract ParaswapResolver is Helpers { /** * @dev Sell ETH/ERC20_Token using ParaSwap. * @notice Swap tokens from exchanges like kyber, 0x etc, with calculation done off-chain. - * @param buyAddr The address of the token to buy.(For MATIC: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) - * @param sellAddr The address of the token to sell.(For MATIC: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param buyAddr The address of the token to buy.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param sellAddr The address of the token to sell.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param sellAmt The amount of the token to sell. * @param unitAmt The amount of buyAmt/sellAmt with slippage. * @param callData Data from paraswap API. * @param setId ID stores the amount of token brought. - */ + */ function swap( address buyAddr, address sellAddr, @@ -27,7 +27,11 @@ abstract contract ParaswapResolver is Helpers { uint256 unitAmt, bytes calldata callData, uint256 setId - ) external payable returns (string memory _eventName, bytes memory _eventParam) { + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { Helpers.SwapData memory swapData = Helpers.SwapData({ buyToken: TokenInterface(buyAddr), sellToken: TokenInterface(sellAddr), @@ -52,4 +56,4 @@ abstract contract ParaswapResolver is Helpers { contract ConnectV2Paraswap is ParaswapResolver { string public name = "Paraswap-v1"; -} \ No newline at end of file +} From aba4325ebe332308ebeef8a425500e43665f1ae3 Mon Sep 17 00:00:00 2001 From: bhavik Date: Sun, 12 Dec 2021 01:45:55 +0530 Subject: [PATCH 3/6] added-test --- test/mainnet/paraswap/paraswap.test.ts | 182 +++++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 test/mainnet/paraswap/paraswap.test.ts diff --git a/test/mainnet/paraswap/paraswap.test.ts b/test/mainnet/paraswap/paraswap.test.ts new file mode 100644 index 00000000..39f56574 --- /dev/null +++ b/test/mainnet/paraswap/paraswap.test.ts @@ -0,0 +1,182 @@ +import hre from "hardhat"; +import { expect } from "chai"; +import { abis } from "../../../scripts/constant/abis"; +import { addresses } from "../../../scripts/tests/mainnet/addresses"; +import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector"; +import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"; +import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"; +import { + ConnectV2ParaswapMainnet, + ConnectV2ParaswapMainnet__factory, +} from "../../../typechain"; +import { parseEther } from "@ethersproject/units"; +import { encodeSpells } from "../../../scripts/tests/encodeSpells"; +import { tokens } from "../../../scripts/tests/mainnet/tokens"; +import { constants } from "../../../scripts/constant/constant"; +import { addLiquidity } from "../../../scripts/tests/addLiquidity"; +import BigNumber from "bignumber.js"; +import axios from "axios"; +const { web3, deployments, waffle, ethers } = hre; +const { provider, deployContract } = waffle; +describe("Paraswap", function() { + const connectorName = "paraswap-test"; + let dsaWallet0: any; + let masterSigner: any; + let instaConnectorsV2: any; + let connector: any; + const wallets = provider.getWallets(); + const [wallet0, wallet1, wallet2, wallet3] = wallets; + before(async () => { + // await hre.network.provider.request({ + // method: "hardhat_reset", + // params: [ + // { + // forking: { + // jsonRpcUrl: hre.config.networks.hardhat.forking.url, + // blockNumber: 13300000, + // }, + // }, + // ], + // }); + masterSigner = await getMasterSigner(); + const erc20 = abis.basic.erc20; + instaConnectorsV2 = await ethers.getContractAt( + abis.core.connectorsV2, + addresses.core.connectorsV2 + ); + const iusdc = await ethers.getContractAt( + erc20, + "0xc2132D05D31c914a87C6611C10748AEb04B58e8F" + ); + // console.log("instance = ", iusdc); + connector = await deployAndEnableConnector({ + connectorName, + contractArtifact: ConnectV2ParaswapMainnet__factory, + signer: masterSigner, + connectors: instaConnectorsV2, + }); + // console.log("Connector address", connector.address); + }); + it("Should have contracts deployed.", async function() { + expect(!!instaConnectorsV2.address).to.be.true; + expect(!!connector.address).to.be.true; + expect(!!masterSigner.address).to.be.true; + }); + describe("DSA wallet setup", function() { + it("Should build DSA v2", async function() { + dsaWallet0 = await buildDSAv2(wallet0.address); + expect(!!dsaWallet0.address).to.be.true; + }); + it("Deposit ETH into DSA wallet", async function() { + await wallet0.sendTransaction({ + to: dsaWallet0.address, + value: ethers.utils.parseEther("10"), + }); + + expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte( + ethers.utils.parseEther("10") + ); + }); + }); + describe("Main", function() { + it("it should swap tokens", async function() { + async function getArg() { + const slippage = 1; + /* eth -> USDT */ + const sellTokenAddress = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; // eth, decimals 18 + const sellTokenDecimals = 18; + const buyTokenAddress = "0xdac17f958d2ee523a2206206994597c13d831ec7"; // USDT, decimals 6 + const buyTokenDecimals = 6; + const amount = 2; + const srcAmount = new BigNumber(amount) + .times(new BigNumber(10).pow(sellTokenDecimals)) + .toFixed(0); + const fromAddress = dsaWallet0.address; + let url = `https://apiv5.paraswap.io/prices/`; + let params = { + srcToken: sellTokenAddress, + destToken: buyTokenAddress, + srcDecimals: sellTokenDecimals, + destDecimals: buyTokenDecimals, + amount: srcAmount, + side: "SELL", + network: 1, + }; + + const priceRoute = await axios + .get(url, { params: params }) + .then((data) => data.data.priceRoute); + + let buyTokenAmount = priceRoute.destAmount; + let minAmount = new BigNumber(priceRoute.destAmount) + .times(1 - slippage / 100) + .toFixed(0); + + let txConfig = { + priceRoute: priceRoute, + srcToken: sellTokenAddress, + destToken: buyTokenAddress, + srcDecimals: sellTokenDecimals, + destDecimals: buyTokenDecimals, + srcAmount: srcAmount, + destAmount: minAmount, + userAddress: fromAddress, + }; + let url2 = "https://apiv5.paraswap.io/transactions/1?ignoreChecks=true"; + const calldata = await axios + .post(url2, txConfig) + .then((data) => data.data.data); + // console.log(calldata); + + function caculateUnitAmt( + buyAmount: any, + sellAmount: any, + buyDecimal: any, + sellDecimal: any, + maxSlippage: any + ) { + let unitAmt: any; + unitAmt = new BigNumber(buyAmount) + .dividedBy(10 ** buyDecimal) + .dividedBy(new BigNumber(sellAmount).dividedBy(10 ** sellDecimal)); + unitAmt = unitAmt.multipliedBy((100 - maxSlippage) / 100); + unitAmt = unitAmt.multipliedBy(1e18).toFixed(0); + return unitAmt; + } + + let unitAmt = caculateUnitAmt( + buyTokenAmount, + srcAmount, + buyTokenDecimals, + sellTokenDecimals, + 1 + ); + + return [ + buyTokenAddress, + sellTokenAddress, + srcAmount, + unitAmt, + calldata, + 0, + ]; + } + let arg = await getArg(); + const spells = [ + { + connector: connectorName, + method: "swap", + args: arg, + }, + ]; + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.address); + const receipt = await tx.wait(); + + expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( + ethers.utils.parseEther("8") + ); + }); + }); +}); From 0fb4826c5bf38ae919e58d8b64a6d720040e4138 Mon Sep 17 00:00:00 2001 From: bhavik Date: Sun, 12 Dec 2021 01:57:35 +0530 Subject: [PATCH 4/6] changed contract name --- contracts/mainnet/connectors/paraswap/main.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/mainnet/connectors/paraswap/main.sol b/contracts/mainnet/connectors/paraswap/main.sol index ad152a66..91180ad4 100644 --- a/contracts/mainnet/connectors/paraswap/main.sol +++ b/contracts/mainnet/connectors/paraswap/main.sol @@ -54,6 +54,6 @@ abstract contract ParaswapResolver is Helpers { } } -contract ConnectV2Paraswap is ParaswapResolver { +contract ConnectV2ParaswapMainnet is ParaswapResolver { string public name = "Paraswap-v1"; } From 9b6c759ce858104351606a7a93028f14f75e5108 Mon Sep 17 00:00:00 2001 From: bhavik Date: Sun, 12 Dec 2021 01:58:36 +0530 Subject: [PATCH 5/6] updated-test --- test/mainnet/paraswap/paraswap.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mainnet/paraswap/paraswap.test.ts b/test/mainnet/paraswap/paraswap.test.ts index 39f56574..b64656b0 100644 --- a/test/mainnet/paraswap/paraswap.test.ts +++ b/test/mainnet/paraswap/paraswap.test.ts @@ -79,7 +79,7 @@ describe("Paraswap", function() { }); }); describe("Main", function() { - it("it should swap tokens", async function() { + it("should swap successfully", async function() { async function getArg() { const slippage = 1; /* eth -> USDT */ From ac3ef0f0717c2b35c6515f282dd3d0db72fbbfe9 Mon Sep 17 00:00:00 2001 From: bhavik mehta Date: Sat, 1 Jan 2022 17:18:13 +0530 Subject: [PATCH 6/6] changed contract name --- .../mainnet/connectors/paraswap/main.sol | 4 +- test/mainnet/paraswap/paraswap.test.ts | 37 ++++++++----------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/contracts/mainnet/connectors/paraswap/main.sol b/contracts/mainnet/connectors/paraswap/main.sol index 91180ad4..0d32dd04 100644 --- a/contracts/mainnet/connectors/paraswap/main.sol +++ b/contracts/mainnet/connectors/paraswap/main.sol @@ -54,6 +54,6 @@ abstract contract ParaswapResolver is Helpers { } } -contract ConnectV2ParaswapMainnet is ParaswapResolver { - string public name = "Paraswap-v1"; +contract ConnectV2ParaswapV5 is ParaswapResolver { + string public name = "Paraswap-v5"; } diff --git a/test/mainnet/paraswap/paraswap.test.ts b/test/mainnet/paraswap/paraswap.test.ts index b64656b0..d225285c 100644 --- a/test/mainnet/paraswap/paraswap.test.ts +++ b/test/mainnet/paraswap/paraswap.test.ts @@ -6,9 +6,8 @@ import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnable import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"; import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"; import { - ConnectV2ParaswapMainnet, - ConnectV2ParaswapMainnet__factory, -} from "../../../typechain"; + ConnectV2ParaswapV5__factory, +} from "../../../typechain" import { parseEther } from "@ethersproject/units"; import { encodeSpells } from "../../../scripts/tests/encodeSpells"; import { tokens } from "../../../scripts/tests/mainnet/tokens"; @@ -27,31 +26,28 @@ describe("Paraswap", function() { const wallets = provider.getWallets(); const [wallet0, wallet1, wallet2, wallet3] = wallets; before(async () => { - // await hre.network.provider.request({ - // method: "hardhat_reset", - // params: [ - // { - // forking: { - // jsonRpcUrl: hre.config.networks.hardhat.forking.url, - // blockNumber: 13300000, - // }, - // }, - // ], - // }); + await hre.network.provider.request({ + method: "hardhat_reset", + params: [ + { + forking: { + // @ts-ignore + jsonRpcUrl: hre.config.networks.hardhat.forking.url, + // blockNumber: 13300000, + }, + }, + ], + }); masterSigner = await getMasterSigner(); const erc20 = abis.basic.erc20; instaConnectorsV2 = await ethers.getContractAt( abis.core.connectorsV2, addresses.core.connectorsV2 ); - const iusdc = await ethers.getContractAt( - erc20, - "0xc2132D05D31c914a87C6611C10748AEb04B58e8F" - ); - // console.log("instance = ", iusdc); + connector = await deployAndEnableConnector({ connectorName, - contractArtifact: ConnectV2ParaswapMainnet__factory, + contractArtifact: ConnectV2ParaswapV5__factory, signer: masterSigner, connectors: instaConnectorsV2, }); @@ -126,7 +122,6 @@ describe("Paraswap", function() { const calldata = await axios .post(url2, txConfig) .then((data) => data.data.data); - // console.log(calldata); function caculateUnitAmt( buyAmount: any,