From 220e826e018c3d92e0543fb285a19313be311d24 Mon Sep 17 00:00:00 2001 From: eccheung4 Date: Wed, 29 Sep 2021 07:38:03 -0700 Subject: [PATCH] fix: remove code for PODs --- .../connectors/pooltogether/events.sol | 3 - .../connectors/pooltogether/interface.sol | 11 - .../polygon/connectors/pooltogether/main.sol | 95 +------ .../pooltogether-polygon/pooltogether.test.js | 269 ------------------ 4 files changed, 1 insertion(+), 377 deletions(-) diff --git a/contracts/polygon/connectors/pooltogether/events.sol b/contracts/polygon/connectors/pooltogether/events.sol index 564b21bc..02b106c8 100644 --- a/contracts/polygon/connectors/pooltogether/events.sol +++ b/contracts/polygon/connectors/pooltogether/events.sol @@ -7,7 +7,4 @@ contract Events { event LogWithdrawInstantlyFrom(address prizePool, address from, uint256 amount, address controlledToken, uint256 maximumExitFee, uint256 exitFee, uint256 getId, uint256 setId); event LogClaim(address tokenFaucet, address user, uint256 claimed, uint256 setId); event LogClaimAll(address tokenFaucetProxyFactory, address user, TokenFaucetInterface[] tokenFaucets); - event LogClaimPodTokenDrop(address podTokenDrop, address user, uint256 claimed, uint256 setId); - event LogDepositToPod(address prizePoolToken, address pod, address to, uint256 amount, uint256 podShare, uint256 getId, uint256 setId); - event LogWithdrawFromPod(address pod, uint256 shareAmount, uint256 tokenAmount, uint256 maxFee, uint256 getId, uint256 setId); } \ No newline at end of file diff --git a/contracts/polygon/connectors/pooltogether/interface.sol b/contracts/polygon/connectors/pooltogether/interface.sol index 7dd1ae94..c82d1b8b 100644 --- a/contracts/polygon/connectors/pooltogether/interface.sol +++ b/contracts/polygon/connectors/pooltogether/interface.sol @@ -6,21 +6,10 @@ interface PrizePoolInterface { function withdrawInstantlyFrom( address from, uint256 amount, address controlledToken, uint256 maximumExitFee) external returns (uint256); } -interface PodTokenDropInterface { - function claim(address user) external returns (uint256); -} - interface TokenFaucetInterface { function claim( address user) external returns (uint256); } interface TokenFaucetProxyFactoryInterface { function claimAll(address user, TokenFaucetInterface[] calldata tokenFaucets) external; -} - -interface PodInterface { - function token() external view returns (address); - function depositTo(address to, uint256 tokenAmount) external returns (uint256); - function withdraw(uint256 shareAmount, uint256 maxFee) external returns (uint256); - function balanceOf(address account) external view returns (uint256); } \ No newline at end of file diff --git a/contracts/polygon/connectors/pooltogether/main.sol b/contracts/polygon/connectors/pooltogether/main.sol index bb15feac..e763e78e 100644 --- a/contracts/polygon/connectors/pooltogether/main.sol +++ b/contracts/polygon/connectors/pooltogether/main.sol @@ -7,7 +7,7 @@ pragma solidity ^0.7.0; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; - import { PrizePoolInterface, TokenFaucetInterface, TokenFaucetProxyFactoryInterface, PodInterface, PodTokenDropInterface } from "./interface.sol"; + import { PrizePoolInterface, TokenFaucetInterface, TokenFaucetProxyFactoryInterface } from "./interface.sol"; import { TokenInterface } from "../../common/interfaces.sol"; import { Stores } from "../../common/stores.sol"; @@ -138,99 +138,6 @@ abstract contract PoolTogetherResolver is Events, DSMath, Basic { _eventName = "LogClaimAll(address,address,TokenFaucetInterface[])"; _eventParam = abi.encode(address(tokenFaucetProxyFactory), address(this), tokenFaucets); } - - /** - * @dev Claim asset rewards from a Pod TokenDrop - * @notice Claim asset rewards from a TokenDrop - * @param podTokenDrop Pod TokenDrop address - * @param setId Set claimed amount at this ID in `InstaMemory` Contract. - */ - function claimPodTokenDrop ( - address podTokenDrop, - uint256 setId - ) external payable returns (string memory _eventName, bytes memory _eventParam) { - PodTokenDropInterface podTokenDropContract = PodTokenDropInterface(podTokenDrop); - - uint256 claimed = podTokenDropContract.claim(address(this)); - - setUint(setId, claimed); - - _eventName = "LogClaimPodTokenDrop(address,address,uint256,uint256)"; - _eventParam = abi.encode(address(podTokenDrop), address(this), claimed, setId); - } - - /** - * @dev Deposit into Pod - * @notice Deposit assets into the Pod in exchange for share tokens - * @param prizePoolToken Prize Pool Token Address - * @param pod Pod address to deposit to - * @param tokenAmount The amount of tokens to deposit. These are the same tokens used to deposit into the underlying prize pool. - * @param getId Get token amount at this ID from `InstaMemory` Contract. - * @param setId Set token amount at this ID in `InstaMemory` Contract. - */ - function depositToPod( - address prizePoolToken, - address pod, - uint256 tokenAmount, - uint256 getId, - uint256 setId - ) external payable returns ( string memory _eventName, bytes memory _eventParam) { - uint _tokenAmount= getUint(getId, tokenAmount); - - PodInterface podContract = PodInterface(pod); - - bool isEth = prizePoolToken == wethAddr; - - // Approve pod - TokenInterface tokenContract = TokenInterface(prizePoolToken); - if (isEth) { - _tokenAmount = _tokenAmount == uint256(-1) ? address(this).balance : _tokenAmount; - convertEthToWeth(isEth, tokenContract, _tokenAmount); - } else { - _tokenAmount = _tokenAmount == uint256(-1) ? tokenContract.balanceOf(address(this)) : _tokenAmount; - } - approve(tokenContract, pod, _tokenAmount); - - uint256 _podShare = podContract.depositTo(address(this), _tokenAmount); - - setUint(setId, _podShare); - - _eventName = "LogDepositToPod(address,address,address,uint256,uint256,uint256,uint256)"; - _eventParam = abi.encode(address(prizePoolToken), address(pod), address(this), _tokenAmount, _podShare, getId, setId); - } - - /** - * @dev Withdraw from shares from Pod - * @notice Withdraws a users share of the prize pool. - * @dev The function should first withdraw from the 'float'; i.e. the funds that have not yet been deposited. - * @param pod Pod address - * @param shareAmount The number of Pod shares to burn. - * @param maxFee Max fee amount for withdrawl if amount isn't available in float. - * @param getId Get token amount at this ID from `InstaMemory` Contract. - * @param setId Set token amount at this ID in `InstaMemory` Contract. - */ - - function withdrawFromPod ( - address pod, - uint256 shareAmount, - uint256 maxFee, - uint256 getId, - uint256 setId - ) external payable returns (string memory _eventName, bytes memory _eventParam) { - uint _shareAmount = getUint(getId, shareAmount); - - PodInterface podContract = PodInterface(pod); - _shareAmount = _shareAmount == uint256(-1) ? podContract.balanceOf(address(this)) : _shareAmount; - - uint256 _tokenAmount = podContract.withdraw(_shareAmount, maxFee); - - convertWethToEth(address(podContract.token()) == wethAddr, TokenInterface(podContract.token()), _tokenAmount); - - setUint(setId, _tokenAmount); - - _eventName = "LogWithdrawFromPod(address,uint256,uint256,uint256,uint256,uint256)"; - _eventParam = abi.encode(address(pod), _shareAmount, _tokenAmount, maxFee, getId, setId); - } } contract ConnectV2PoolTogether is PoolTogetherResolver { diff --git a/test/pooltogether-polygon/pooltogether.test.js b/test/pooltogether-polygon/pooltogether.test.js index 6dc2697b..4441f1bf 100644 --- a/test/pooltogether-polygon/pooltogether.test.js +++ b/test/pooltogether-polygon/pooltogether.test.js @@ -25,7 +25,6 @@ const PT_DAI_TICKET_ADDR = "0x334cBb5858417Aee161B53Ee0D5349cCF54514CF" // PT DA const DAI_POOL_FAUCET_ADDR = "0xF362ce295F2A4eaE4348fFC8cDBCe8d729ccb8Eb" // DAI POOL Faucet const POOL_TOKEN_ADDRESS = "0x0cEC1A9154Ff802e7934Fc916Ed7Ca50bDE6844e" // POOL Tocken const TOKEN_FAUCET_PROXY_FACTORY_ADDR = "0xE4E9cDB3E139D7E8a41172C20b6Ed17b6750f117" // TokenFaucetProxyFactory for claimAll -const DAI_POD_ADDR = "0x2f994e2E4F3395649eeE8A89092e63Ca526dA829" // DAI Pod const UNISWAP_POOLETHLP_PRIZE_POOL_ADDR = "0x3AF7072D29Adde20FC7e173a7CB9e45307d2FB0A" // Uniswap Pool/ETH LP PrizePool const UNISWAP_POOLETHLP_FAUCET_ADDR = "0x9A29401EF1856b669f55Ae5b24505b3B6fAEb370" // Uniswap Pool/ETH LP Faucet const UNISWAP_POOLETHLP_TOKEN_ADDR = "0x85cb0bab616fe88a89a35080516a8928f38b518b" // Uniswap Pool/ETH Token @@ -33,7 +32,6 @@ const PT_UNISWAP_POOLETHLP_TICKET_ADDR = "0xeb8928ee92efb06c44d072a24c2bcb993b61 const POOL_PRIZE_POOL_ADDR = "0x396b4489da692788e327e2e4b2b0459a5ef26791" // POOL Prize Pool const PT_POOL_TICKET_ADDR = "0x27d22a7648e955e510a40bdb058333e9190d12d4" // Pool Together POOL Ticket const WETH_ADDR = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" // WETH -const DAI_POD_TOKEN_DROP = "0xc5209623E3dFdf9C0cCbe497c8012883C4147731" // Community WETH Prize Pool (Rari): https://reference-app.pooltogether.com/pools/mainnet/0xa88ca010b32a54d446fc38091ddbca55750cbfc3/manage#stats const WETH_PRIZE_POOL_ADDR = "0xa88ca010b32a54d446fc38091ddbca55750cbfc3" // Community WETH Prize Pool (Rari) @@ -43,22 +41,6 @@ const prizePoolABI = [ "function calculateEarlyExitFee( address from, address controlledToken, uint256 amount) external returns ( uint256 exitFee, uint256 burnedCredit)" ] -const podABI = [ - "function getEarlyExitFee(uint256 amount) external returns (uint256)", - "function balanceOfUnderlying(address user) external view returns (uint256 amount)", - "function drop() public returns (uint256)", - "function balanceOf(address account) external view returns (uint256)" -] - -const POD_FACTORY_ADDRESS = "0x4e3a9f9fbafb2ec49727cffa2a411f7a0c1c4ce1" -const podFactoryABI = [ - "function create( address _prizePool, address _ticket, address _faucet, address _manager, uint8 _decimals) external returns (address pod)" -] - -const tokenDropABI = [ - "function claim(address user) external returns (uint256)", -] - describe("PoolTogether", function () { const connectorName = "COMPOUND-TEST-A" const uniswapConnectorName = "UNISWAP-TEST-A" @@ -354,185 +336,6 @@ describe("PoolTogether", function () { }); }) - describe("Main - DAI Pod Test", function() { - it("Should deposit 99 DAI in DAI Pod", async function() { - const amount = ethers.utils.parseEther("99") // 99 DAI - const spells = [ - { - connector: ptConnectorName, - method: "depositToPod", - args: [DAI_TOKEN_ADDR, DAI_POD_ADDR, amount, 0, 0] - } - ] - - // Before spell - let daiToken = await ethers.getContractAt(abis.basic.erc20, DAI_TOKEN_ADDR) - let daiBalance = await daiToken.balanceOf(dsaWallet0.address); - expect(daiBalance, `DAI balance equals 99`).to.be.eq(ethers.utils.parseEther("99")); - - let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS) - const poolBalance = await poolToken.balanceOf(dsaWallet0.address) - expect(poolBalance, `POOL Token greater than 0`).to.be.gt(0); - - let podToken = await ethers.getContractAt(abis.basic.erc20, DAI_POD_ADDR) - const podBalance = await podToken.balanceOf(dsaWallet0.address) - expect(podBalance, `Pod DAI Token equals 0`).to.be.eq(0); - - // Run spell transaction - const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) - const receipt = await tx.wait() - - // After spell - daiBalance = await daiToken.balanceOf(dsaWallet0.address); - expect(daiBalance, `DAI equals 0`).to.be.eq(0); - - const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address) - expect(poolBalanceAfter, `POOL Token greater than 0`).to.be.gt(0); - - const podBalanceAfter = await podToken.balanceOf(dsaWallet0.address) - expect(podBalanceAfter, `Pod DAI token greater than 0`).to.be.eq(ethers.utils.parseEther("99")); - }); - - it("Should claim rewards from pod token drop", async function() { - const spells = [ - { - connector: ptConnectorName, - method: "claimPodTokenDrop", - args: [DAI_POD_TOKEN_DROP, 0] - } - ] - - const tokenDropContract = new ethers.Contract(DAI_POD_TOKEN_DROP, tokenDropABI, ethers.provider); - const podContract = new ethers.Contract(DAI_POD_ADDR, podABI, masterSigner); - - // drop(): Claim TokenDrop asset for PrizePool Pod and transfers token(s) to external Pod TokenDrop - // dropt() also calls batch which, Deposit Pod float into PrizePool. Deposits the current float - // amount into the PrizePool and claims current POOL rewards. - const dropTx = await podContract.drop(); - await dropTx.wait(); - - // POOL Rewards able to claim from Pod Token Drop - let claimAmount = await tokenDropContract.callStatic["claim"](dsaWallet0.address); - - // Before spell - let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS) - const poolBalance = await poolToken.balanceOf(dsaWallet0.address) - expect(poolBalance, `POOL Token greater than 0`).to.be.gt(0); - - // Run spell transaction - const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) - const receipt = await tx.wait() - - // After spell - const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address) - const total = claimAmount.add(poolBalance); - expect(poolBalanceAfter, `POOL Token same as before spell`).to.be.eq(total); - }); - - it("Should wait 11 days, withdraw all podTokens, get back 99 DAI", async function () { - const amount = ethers.utils.parseEther("99") // 99 DAI - - const podContract = new ethers.Contract(DAI_POD_ADDR, podABI, ethers.provider); - let maxFee = await podContract.callStatic["getEarlyExitFee"](amount); - // maxFee depends on if token has been deposited to PrizePool yet - // since we called drop in previous test case, the tokens were deposited to PrizePool - expect(maxFee, "Exit Fee equal to .99 DAI because token still in float").to.be.eq(ethers.utils.parseEther(".99")); - - const spells = [ - { - connector: ptConnectorName, - method: "withdrawFromPod", - args: [DAI_POD_ADDR, amount, maxFee, 0, 0] - } - ] - - // Before spell - let daiToken = await ethers.getContractAt(abis.basic.erc20, DAI_TOKEN_ADDR) - let daiBalance = await daiToken.balanceOf(dsaWallet0.address); - expect(daiBalance, `DAI Balance equals 0`).to.be.eq(0); - - let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS) - const poolBalance = await poolToken.balanceOf(dsaWallet0.address) - expect(poolBalance, `POOL Token balance greater than 0`).to.be.gt(0); - - let podToken = await ethers.getContractAt(abis.basic.erc20, DAI_POD_ADDR) - const podBalance = await podToken.balanceOf(dsaWallet0.address) - expect(podBalance, `Pod DAI Token equals 99`).to.be.eq(ethers.utils.parseEther("99")); - - // Increase time by 11 days so we get back all DAI without early withdrawal fee - await ethers.provider.send("evm_increaseTime", [11*24*60*60]); - await ethers.provider.send("evm_mine"); - - // Run spell transaction - const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) - const receipt = await tx.wait() - - // After spell - daiBalance = await daiToken.balanceOf(dsaWallet0.address); - expect(daiBalance, - `DAI balance equals 99, because of no early withdrawal fee` - ).to.be.eq(ethers.utils.parseEther("99")); - - const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address) - expect(poolBalanceAfter, `POOL Token to be greater than 0`).to.be.gt(0); - - const podBalanceAfter = await podToken.balanceOf(dsaWallet0.address) - expect(podBalanceAfter, `Pod DAI Token equals 0`).to.be.eq(0); - }); - - - - - it("Should deposit and withdraw from pod, get back same amount of 99 DAI", async function() { - const amount = ethers.utils.parseEther("99") - const maxFee = 0; // maxFee 0 since it doesn't give chance for Pod to actually deposit into PrizePool - - const spells = [ - { - connector: ptConnectorName, - method: "depositToPod", - args: [DAI_TOKEN_ADDR, DAI_POD_ADDR, amount, 0, 0] - }, - { - connector: ptConnectorName, - method: "withdrawFromPod", - args: [DAI_POD_ADDR, amount, maxFee, 0, 0] - } - ] - - // Before spell - let daiToken = await ethers.getContractAt(abis.basic.erc20, DAI_TOKEN_ADDR) - let daiBalance = await daiToken.balanceOf(dsaWallet0.address); - expect(daiBalance, `DAI equals 99`).to.be.eq(ethers.utils.parseEther("99")); - - let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS) - const poolBalance = await poolToken.balanceOf(dsaWallet0.address) - expect(poolBalance, `POOL Token greater than 0`).to.be.gt(0); - - // PodToken is 0 - let podToken = await ethers.getContractAt(abis.basic.erc20, DAI_POD_ADDR) - const podBalance = await podToken.balanceOf(dsaWallet0.address) - expect(podBalance, `Pod DAI Token equals 0`).to.be.eq(0); - - // Run spell transaction - const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) - const receipt = await tx.wait() - - // After spell - daiBalance = await daiToken.balanceOf(dsaWallet0.address); - expect(daiBalance, - `DAI balance to be equal to 99, because funds still in 'float` - ).to.be.eq(ethers.utils.parseEther("99")); - - const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address) - expect(poolBalanceAfter, `POOL Token same as before spell`).to.be.eq(poolBalance); - - // Expect Pod Token Balance to equal 0 - const podBalanceAfter = await podToken.balanceOf(dsaWallet0.address) - expect(podBalanceAfter, `Pod DAI Token equals 0`).to.be.eq(ethers.utils.parseEther("0")); - }); - }) - describe("Main - UNISWAP POOL/ETH Prize Pool Test", function () { it("Should use uniswap to swap ETH for POOL, deposit to POOL/ETH LP, deposit POOL/ETH LP to PrizePool", async function () { const amount = ethers.utils.parseEther("100") // 100 POOL @@ -736,76 +539,4 @@ describe("PoolTogether", function () { expect(ethBalanceAfter, `ETH Balance equal to before spell because no early exit fee`).to.be.eq(ethBalanceBefore); }); }); - - describe("Main - WETH Pod Test", function() { - let podAddress - it("Should deposit 1 ETH in WETH Pod and get Pod Ticket", async function() { - const amount = ethers.utils.parseEther("1") - - // Create Pod for WETH Prize Pool (Rari) - const podFactoryContract = new ethers.Contract(POD_FACTORY_ADDRESS, podFactoryABI, masterSigner) - podAddress = await podFactoryContract.callStatic.create(WETH_PRIZE_POOL_ADDR, WETH_POOL_TICKET_ADDR, constants.address_zero, wallet0.address, 18) - await podFactoryContract.create(WETH_PRIZE_POOL_ADDR, WETH_POOL_TICKET_ADDR, constants.address_zero, wallet0.address, 18) - - const spells = [ - { - connector: ptConnectorName, - method: "depositToPod", - args: [WETH_ADDR, podAddress, amount, 0, 0] - } - ] - - // Before Deposit Spell - const podContract = new ethers.Contract(podAddress, podABI, ethers.provider); - let podBalanceBefore = await podContract.balanceOfUnderlying(dsaWallet0.address) - expect(podBalanceBefore, `Pod balance equal to 0`).to.be.eq(0); - - let ethBalanceBefore = await ethers.provider.getBalance(dsaWallet0.address); - - // Run spell transaction - const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) - const receipt = await tx.wait() - - // After Deposit spell - let ethBalanceAfter = await ethers.provider.getBalance(dsaWallet0.address); - expect(ethBalanceAfter, `ETH balance less than before`).to.be.lt(ethBalanceBefore); - - podBalanceAfter = await podContract.balanceOfUnderlying(dsaWallet0.address) - expect(podBalanceAfter, `Pod balance equal to 1`).to.be.eq(ethers.utils.parseEther("1")); - }); - - it("Should withdraw 1 Ticket from WETH Pod and get back ETH", async function() { - const amount = ethers.utils.parseEther("1") - - const podContract = new ethers.Contract(podAddress, podABI, ethers.provider); - let maxFee = await podContract.callStatic["getEarlyExitFee"](amount); - expect(maxFee, "Exit Fee equal to 0 DAI because token still in float").to.be.eq(0); - // maxFee depends on if token has been deposited to PrizePool yet - - const spells = [ - { - connector: ptConnectorName, - method: "withdrawFromPod", - args: [podAddress, amount, maxFee, 0, 0] - } - ] - - // Before Deposit Spell - let podBalanceBefore = await podContract.balanceOfUnderlying(dsaWallet0.address) - expect(podBalanceBefore, `Pod balance equal to 1`).to.be.eq(ethers.utils.parseEther("1")); - - let ethBalanceBefore = await ethers.provider.getBalance(dsaWallet0.address); - - // Run spell transaction - const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) - const receipt = await tx.wait() - - // After Deposit spell - let ethBalanceAfter = await ethers.provider.getBalance(dsaWallet0.address); - expect(ethBalanceAfter, `ETH balance greater than before`).to.be.gt(ethBalanceBefore); - - podBalanceAfter = await podContract.balanceOfUnderlying(dsaWallet0.address) - expect(podBalanceAfter, `Pod balance equal to 0`).to.be.eq(ethers.utils.parseEther("0")); - }); - }); }) \ No newline at end of file