From 1252c0f4279601459e4878faf27bc55856de1d96 Mon Sep 17 00:00:00 2001 From: cryptoDev222 Date: Thu, 2 Sep 2021 03:09:09 -0500 Subject: [PATCH] refactor: minor fixes and implement ETH-INST pool test --- .../connectors/uniswapStaker/events.sol | 2 +- .../mainnet/connectors/uniswapStaker/main.sol | 16 ++-- scripts/addLiquidity.js | 9 ++ test/uniswapStake/uniswapStake.test.js | 94 +++++++++++++++++-- 4 files changed, 104 insertions(+), 17 deletions(-) diff --git a/contracts/mainnet/connectors/uniswapStaker/events.sol b/contracts/mainnet/connectors/uniswapStaker/events.sol index b5b2e8b0..0406b33c 100644 --- a/contracts/mainnet/connectors/uniswapStaker/events.sol +++ b/contracts/mainnet/connectors/uniswapStaker/events.sol @@ -18,7 +18,7 @@ contract Events { ); event LogIncentiveCreated( - uint256 tokenId, + address poolAddr, uint256 startTime, uint256 endTime, uint256 reward diff --git a/contracts/mainnet/connectors/uniswapStaker/main.sol b/contracts/mainnet/connectors/uniswapStaker/main.sol index 18ca0916..e65f44d9 100644 --- a/contracts/mainnet/connectors/uniswapStaker/main.sol +++ b/contracts/mainnet/connectors/uniswapStaker/main.sol @@ -177,24 +177,21 @@ abstract contract UniswapResolver is Helpers, Events { * @param _rewardToken _rewardToken address * @param _length incentive length * @param _refundee refundee address - * @param _tokenId NFT LP token id + * @param _poolAddr Uniswap V3 Pool address * @param _reward reward amount */ function createIncentive( address _rewardToken, uint256 _length, address _refundee, - uint256 _tokenId, + address _poolAddr, uint256 _reward ) external payable returns (string memory _eventName, bytes memory _eventParam) { - if (_tokenId == 0) _tokenId = _getLastNftId(address(this)); - address poolAddr = getPoolAddress(_tokenId); - - IUniswapV3Pool pool = IUniswapV3Pool(poolAddr); + IUniswapV3Pool pool = IUniswapV3Pool(_poolAddr); uint256 _startTime = block.timestamp; uint256 _endTime = _startTime + _length; IUniswapV3Staker.IncentiveKey memory _key = IUniswapV3Staker @@ -205,10 +202,13 @@ abstract contract UniswapResolver is Helpers, Events { _endTime, _refundee ); + if (_rewardToken != ethAddr) { + IERC20Minimal(_rewardToken).approve(address(staker), _reward); + } staker.createIncentive(_key, _reward); - _eventName = "LogIncentiveCreated(uint256,uint256,uint256,uint256)"; - _eventParam = abi.encode(_tokenId, _startTime, _endTime, _reward); + _eventName = "LogIncentiveCreated(address,uint256,uint256,uint256)"; + _eventParam = abi.encode(_poolAddr, _startTime, _endTime, _reward); } } diff --git a/scripts/addLiquidity.js b/scripts/addLiquidity.js index 0fb51156..c461a775 100644 --- a/scripts/addLiquidity.js +++ b/scripts/addLiquidity.js @@ -50,6 +50,15 @@ const tokenMapping = { await mineTx(contract.mint(address, amt)); }, }, + inst: { + impersonateSigner: "0x75e89d5979E4f6Fba9F97c104c2F0AFB3F1dcB88", + address: "0x6f40d4a6237c257fff2db00fa0510deeecd303eb", + abi: ["function transfer(address to, uint value)"], + process: async function(owner, address, amt) { + const contract = new ethers.Contract(this.address, this.abi, owner); + await mineTx(contract.transfer(address, amt)); + }, + } }; module.exports = async (tokenName, address, amt) => { diff --git a/test/uniswapStake/uniswapStake.test.js b/test/uniswapStake/uniswapStake.test.js index be684b6a..67b523a0 100644 --- a/test/uniswapStake/uniswapStake.test.js +++ b/test/uniswapStake/uniswapStake.test.js @@ -30,6 +30,7 @@ const TICK_SPACINGS = { const DAI_ADDR = "0x6b175474e89094c44da98b954eedeac495271d0f" const ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" +const INST_ADDR = "0x6f40d4a6237c257fff2db00fa0510deeecd303eb" let tokenIds = [] const abiCoder = ethers.utils.defaultAbiCoder @@ -88,7 +89,7 @@ describe("UniswapV3", function () { await addLiquidity("dai", dsaWallet0.address, ethers.utils.parseEther("100000")); }); - it("Deposit ETH & USDT into DSA wallet", async function () { + it("Deposit ETH & USDT & INST into DSA wallet", async function () { await wallet0.sendTransaction({ to: dsaWallet0.address, value: ethers.utils.parseEther("10") @@ -97,12 +98,14 @@ describe("UniswapV3", function () { await addLiquidity("dai", dsaWallet0.address, ethers.utils.parseEther("100000")); await addLiquidity("usdt", dsaWallet0.address, ethers.utils.parseEther("100000")); + await addLiquidity("inst", dsaWallet0.address, ethers.utils.parseEther("10000")); }); }); describe("Main", function () { const ethAmount = ethers.utils.parseEther("0.1") // 1 ETH const daiAmount = ethers.utils.parseEther("400") // 1 ETH + const instAmount = ethers.utils.parseEther("50") it("Should mint successfully", async function () { const getIds = ["0", "0"] @@ -124,6 +127,22 @@ describe("UniswapV3", function () { getIds, setId ], + }, + { + connector: connectorUniswap, + method: "mint", + args: [ + INST_ADDR, + ethAddress, + FeeAmount.MEDIUM, + getMinTick(TICK_SPACINGS[FeeAmount.MEDIUM]), + getMaxTick(TICK_SPACINGS[FeeAmount.MEDIUM]), + instAmount, + ethAmount, + "500000000000000000", + getIds, + setId + ], } ] @@ -133,7 +152,9 @@ describe("UniswapV3", function () { let castEvent = new Promise((resolve, reject) => { dsaWallet0.on('LogCast', (origin, sender, value, targetNames, targets, eventNames, eventParams, event) => { const params = abiCoder.decode(["uint256", "uint256", "uint256", "uint256", "int24", "int24"], eventParams[0]); + const params1 = abiCoder.decode(["uint256", "uint256", "uint256", "uint256", "int24", "int24"], eventParams[1]); tokenIds.push(params[0]); + tokenIds.push(params1[0]); event.removeListener(); resolve({ @@ -153,6 +174,7 @@ describe("UniswapV3", function () { }); it("Should create incentive successfully", async function () { + console.log("TokenIds", tokenIds[1]); const spells = [ { connector: connectorStaker, @@ -161,20 +183,32 @@ describe("UniswapV3", function () { ethAddress, "1000", dsaWallet0.address, - tokenIds[0], + "0xc2e9f25be6257c210d7adf0d4cd6e3e881ba25f8", + ethers.utils.parseEther("0.01") + ], + }, + { + connector: connectorStaker, + method: "createIncentive", + args: [ + INST_ADDR, + "50", + dsaWallet0.address, + "0xcba27c8e7115b4eb50aa14999bc0866674a96ecb", ethers.utils.parseEther("0.01") ], }] - const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) + const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address) let receipt = await tx.wait() let castEvent = new Promise((resolve, reject) => { dsaWallet0.on('LogCast', (origin, sender, value, targetNames, targets, eventNames, eventParams, event) => { const params = abiCoder.decode(["uint256", "uint256", "uint256", "uint256"], eventParams[0]); + const params1 = abiCoder.decode(["uint256", "uint256", "uint256", "uint256"], eventParams[1]); event.removeListener(); - resolve({ start: params[1], end: params[2] }); + resolve({ start: [params[1], params1[1]], end: [params[2], params1[2]] }); }); setTimeout(() => { @@ -201,11 +235,29 @@ describe("UniswapV3", function () { method: "stake", args: [ ethAddress, - startTime, - endTime, + startTime[0], + endTime[0], dsaWallet0.address, tokenIds[0] ], + }, + { + connector: connectorStaker, + method: "deposit", + args: [ + tokenIds[1] + ], + }, + { + connector: connectorStaker, + method: "stake", + args: [ + INST_ADDR, + startTime[1], + endTime[1], + dsaWallet0.address, + tokenIds[1] + ], } ] @@ -222,7 +274,14 @@ describe("UniswapV3", function () { connector: connectorStaker, method: "claimRewards", args: [ - ethAddress, + DAI_ADDR, + dsaWallet0.address, + "1000", + ], + connector: connectorStaker, + method: "claimRewards", + args: [ + INST_ADDR, dsaWallet0.address, "1000", ], @@ -239,7 +298,7 @@ describe("UniswapV3", function () { connector: connectorStaker, method: "unstake", args: [ - ethAddress, + DAI_ADDR, startTime, endTime, dsaWallet0.address, @@ -253,6 +312,25 @@ describe("UniswapV3", function () { tokenIds[0], dsaWallet0.address, ], + }, + { + connector: connectorStaker, + method: "unstake", + args: [ + INST_ADDR, + startTime, + endTime, + dsaWallet0.address, + tokenIds[1] + ], + }, + { + connector: connectorStaker, + method: "withdraw", + args: [ + tokenIds[1], + dsaWallet0.address, + ], } ]