mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
feat: add claim() for Pod TokenDrop
This commit is contained in:
parent
2705ab4ad9
commit
e28def660c
|
@ -7,6 +7,7 @@ contract Events {
|
||||||
event LogWithdrawInstantlyFrom(address prizePool, address from, uint256 amount, address controlledToken, uint256 maximumExitFee, uint256 exitFee, uint256 getId, uint256 setId);
|
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 LogClaim(address tokenFaucet, address user, uint256 claimed, uint256 setId);
|
||||||
event LogClaimAll(address tokenFaucetProxyFactory, address user, TokenFaucetInterface[] tokenFaucets);
|
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 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);
|
event LogWithdrawFromPod(address pod, uint256 shareAmount, uint256 tokenAmount, uint256 maxFee, uint256 getId, uint256 setId);
|
||||||
}
|
}
|
|
@ -6,6 +6,10 @@ interface PrizePoolInterface {
|
||||||
function withdrawInstantlyFrom( address from, uint256 amount, address controlledToken, uint256 maximumExitFee) external returns (uint256);
|
function withdrawInstantlyFrom( address from, uint256 amount, address controlledToken, uint256 maximumExitFee) external returns (uint256);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface PodTokenDropInterface {
|
||||||
|
function claim(address user) external returns (uint256);
|
||||||
|
}
|
||||||
|
|
||||||
interface TokenFaucetInterface {
|
interface TokenFaucetInterface {
|
||||||
function claim( address user) external returns (uint256);
|
function claim( address user) external returns (uint256);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ pragma solidity ^0.7.0;
|
||||||
|
|
||||||
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
||||||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||||
import { PrizePoolInterface, TokenFaucetInterface, TokenFaucetProxyFactoryInterface, PodInterface } from "./interface.sol";
|
import { PrizePoolInterface, TokenFaucetInterface, TokenFaucetProxyFactoryInterface, PodInterface, PodTokenDropInterface } from "./interface.sol";
|
||||||
|
|
||||||
import { TokenInterface } from "../../common/interfaces.sol";
|
import { TokenInterface } from "../../common/interfaces.sol";
|
||||||
import { Stores } from "../../common/stores.sol";
|
import { Stores } from "../../common/stores.sol";
|
||||||
|
@ -139,6 +139,26 @@ abstract contract PoolTogetherResolver is Events, DSMath, Basic {
|
||||||
_eventParam = abi.encode(address(tokenFaucetProxyFactory), address(this), tokenFaucets);
|
_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
|
* @dev Deposit into Pod
|
||||||
* @notice Deposit assets into the Pod in exchange for share tokens
|
* @notice Deposit assets into the Pod in exchange for share tokens
|
||||||
|
|
|
@ -33,6 +33,7 @@ const PT_UNISWAP_POOLETHLP_TICKET_ADDR = "0xeb8928ee92efb06c44d072a24c2bcb993b61
|
||||||
const POOL_PRIZE_POOL_ADDR = "0x396b4489da692788e327e2e4b2b0459a5ef26791" // POOL Prize Pool
|
const POOL_PRIZE_POOL_ADDR = "0x396b4489da692788e327e2e4b2b0459a5ef26791" // POOL Prize Pool
|
||||||
const PT_POOL_TICKET_ADDR = "0x27d22a7648e955e510a40bdb058333e9190d12d4" // Pool Together POOL Ticket
|
const PT_POOL_TICKET_ADDR = "0x27d22a7648e955e510a40bdb058333e9190d12d4" // Pool Together POOL Ticket
|
||||||
const WETH_ADDR = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" // WETH
|
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
|
// 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)
|
const WETH_PRIZE_POOL_ADDR = "0xa88ca010b32a54d446fc38091ddbca55750cbfc3" // Community WETH Prize Pool (Rari)
|
||||||
|
@ -44,7 +45,9 @@ const prizePoolABI = [
|
||||||
|
|
||||||
const podABI = [
|
const podABI = [
|
||||||
"function getEarlyExitFee(uint256 amount) external returns (uint256)",
|
"function getEarlyExitFee(uint256 amount) external returns (uint256)",
|
||||||
"function balanceOfUnderlying(address user) external view returns (uint256 amount)"
|
"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 POD_FACTORY_ADDRESS = "0x4e3a9f9fbafb2ec49727cffa2a411f7a0c1c4ce1"
|
||||||
|
@ -52,6 +55,10 @@ const podFactoryABI = [
|
||||||
"function create( address _prizePool, address _ticket, address _faucet, address _manager, uint8 _decimals) external returns (address pod)"
|
"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 () {
|
describe("PoolTogether", function () {
|
||||||
const connectorName = "COMPOUND-TEST-A"
|
const connectorName = "COMPOUND-TEST-A"
|
||||||
const uniswapConnectorName = "UNISWAP-TEST-A"
|
const uniswapConnectorName = "UNISWAP-TEST-A"
|
||||||
|
@ -386,13 +393,50 @@ describe("PoolTogether", function () {
|
||||||
expect(podBalanceAfter, `Pod DAI token greater than 0`).to.be.eq(ethers.utils.parseEther("99"));
|
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 () {
|
it("Should wait 11 days, withdraw all podTokens, get back 99 DAI", async function () {
|
||||||
const amount = ethers.utils.parseEther("99") // 99 DAI
|
const amount = ethers.utils.parseEther("99") // 99 DAI
|
||||||
|
|
||||||
const podContract = new ethers.Contract(DAI_POD_ADDR, podABI, ethers.provider);
|
const podContract = new ethers.Contract(DAI_POD_ADDR, podABI, ethers.provider);
|
||||||
let maxFee = await podContract.callStatic["getEarlyExitFee"](amount);
|
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
|
// 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 = [
|
const spells = [
|
||||||
{
|
{
|
||||||
|
@ -417,6 +461,7 @@ describe("PoolTogether", function () {
|
||||||
|
|
||||||
// Increase time by 11 days so we get back all DAI without early withdrawal fee
|
// 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_increaseTime", [11*24*60*60]);
|
||||||
|
await ethers.provider.send("evm_mine");
|
||||||
|
|
||||||
// Run spell transaction
|
// Run spell transaction
|
||||||
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
|
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
|
||||||
|
@ -435,6 +480,9 @@ describe("PoolTogether", function () {
|
||||||
expect(podBalanceAfter, `Pod DAI Token equals 0`).to.be.eq(0);
|
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() {
|
it("Should deposit and withdraw from pod, get back same amount of 99 DAI", async function() {
|
||||||
const amount = ethers.utils.parseEther("99")
|
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 maxFee = 0; // maxFee 0 since it doesn't give chance for Pod to actually deposit into PrizePool
|
||||||
|
|
Loading…
Reference in New Issue
Block a user