mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Add claimAll function
This commit is contained in:
parent
8d9600b3b2
commit
bf80497bb2
|
@ -1,7 +1,10 @@
|
||||||
pragma solidity ^0.7.0;
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
|
import { TokenFaucetInterface } from "./interface.sol";
|
||||||
|
|
||||||
contract Events {
|
contract Events {
|
||||||
event LogDepositTo(address prizePool, address to, uint256 amount, address controlledToken, address referrer, uint256 getId, uint256 setId);
|
event LogDepositTo(address prizePool, address to, uint256 amount, address controlledToken, address referrer, uint256 getId, uint256 setId);
|
||||||
event LogWithdrawInstantlyFrom(address prizePool, address from, uint256 amount, address controlledToken, uint256 maximumExitFee, uint256 getId, uint256 setId);
|
event LogWithdrawInstantlyFrom(address prizePool, address from, uint256 amount, address controlledToken, uint256 maximumExitFee, uint256 getId, uint256 setId);
|
||||||
event LogClaim(address tokenFaucet, address user);
|
event LogClaim(address tokenFaucet, address user);
|
||||||
|
event LogClaimAll(address tokenFaucetProxyFactory, address user, TokenFaucetInterface[] tokenFaucets);
|
||||||
}
|
}
|
|
@ -9,3 +9,7 @@ interface PrizePoolInterface {
|
||||||
interface TokenFaucetInterface {
|
interface TokenFaucetInterface {
|
||||||
function claim( address user) external returns (uint256);
|
function claim( address user) external returns (uint256);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface TokenFaucetProxyFactoryInterface {
|
||||||
|
function claimAll(address user, TokenFaucetInterface[] calldata tokenFaucets) external;
|
||||||
|
}
|
|
@ -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} from "./interface.sol";
|
import { PrizePoolInterface, TokenFaucetInterface, TokenFaucetProxyFactoryInterface } from "./interface.sol";
|
||||||
|
|
||||||
import { TokenInterface } from "../../common/interfaces.sol";
|
import { TokenInterface } from "../../common/interfaces.sol";
|
||||||
import { Events } from "./events.sol";
|
import { Events } from "./events.sol";
|
||||||
|
@ -106,6 +106,25 @@ abstract contract PoolTogetherResolver is Events, DSMath, Basic {
|
||||||
_eventParam = abi.encode(address(tokenFaucet), address(user));
|
_eventParam = abi.encode(address(tokenFaucet), address(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Runs claim on all passed comptrollers for a user.
|
||||||
|
* @notice Runs claim on all passed comptrollers for a user.
|
||||||
|
* @param tokenFaucetProxyFactory The TokenFaucetProxyFactory address
|
||||||
|
* @param user The user to claim tokens for
|
||||||
|
* @param tokenFaucets The tokenFaucets to call claim on.
|
||||||
|
*/
|
||||||
|
function claimAll (
|
||||||
|
address tokenFaucetProxyFactory,
|
||||||
|
address user,
|
||||||
|
TokenFaucetInterface[] calldata tokenFaucets
|
||||||
|
) external returns (string memory _eventName, bytes memory _eventParam) {
|
||||||
|
TokenFaucetProxyFactoryInterface tokenFaucetProxyFactoryContract = TokenFaucetProxyFactoryInterface(tokenFaucetProxyFactory);
|
||||||
|
|
||||||
|
tokenFaucetProxyFactoryContract.claimAll(user, tokenFaucets);
|
||||||
|
|
||||||
|
_eventName = "LogClaimAll(address,address,TokenFaucetInterface[])";
|
||||||
|
_eventParam = abi.encode(address(tokenFaucetProxyFactory), address(user), tokenFaucets);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contract ConnectV2PoolTogether is PoolTogetherResolver {
|
contract ConnectV2PoolTogether is PoolTogetherResolver {
|
||||||
|
|
|
@ -142,13 +142,18 @@ describe("PoolTogether", function () {
|
||||||
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("9"));
|
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("9"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should withdraw all PrizePool and get back 100 DAI", async function () {
|
it("Should wait 11 days, withdraw all PrizePool, get back 100 DAI, and claim POOL", async function () {
|
||||||
const amount = ethers.utils.parseEther("100") // 100 DAI
|
const amount = ethers.utils.parseEther("100") // 100 DAI
|
||||||
const spells = [
|
const spells = [
|
||||||
{
|
{
|
||||||
connector: ptConnectorName,
|
connector: ptConnectorName,
|
||||||
method: "withdrawInstantlyFrom",
|
method: "withdrawInstantlyFrom",
|
||||||
args: [prizePool, dsaWallet0.address, amount, controlledToken, amount, 0, 0]
|
args: [prizePool, dsaWallet0.address, amount, controlledToken, amount, 0, 0]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
connector: ptConnectorName,
|
||||||
|
method: "claim",
|
||||||
|
args: [daiPoolFaucet, dsaWallet0.address]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -165,6 +170,12 @@ describe("PoolTogether", function () {
|
||||||
const tokenName = await cToken.name()
|
const tokenName = await cToken.name()
|
||||||
console.log("\tBalance before: ", balance.toString(), tokenName)
|
console.log("\tBalance before: ", balance.toString(), tokenName)
|
||||||
|
|
||||||
|
// PoolToken is 0
|
||||||
|
let poolToken = await ethers.getContractAt(abis.basic.erc20, poolTokenAddress)
|
||||||
|
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
|
||||||
|
const poolTokenName = await poolToken.name()
|
||||||
|
console.log("\tBalance before: ", poolBalance.toString(), poolTokenName)
|
||||||
|
|
||||||
// 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]);
|
||||||
|
|
||||||
|
@ -183,9 +194,14 @@ describe("PoolTogether", function () {
|
||||||
const balanceAfter = await cToken.balanceOf(dsaWallet0.address)
|
const balanceAfter = await cToken.balanceOf(dsaWallet0.address)
|
||||||
console.log("\tBalance after: ", balanceAfter.toString(), tokenName)
|
console.log("\tBalance after: ", balanceAfter.toString(), tokenName)
|
||||||
expect(balanceAfter.toNumber()).to.be.eq(0);
|
expect(balanceAfter.toNumber()).to.be.eq(0);
|
||||||
|
|
||||||
|
// Expect Pool Token Balance to be greater than 0
|
||||||
|
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
|
||||||
|
console.log("\tBalance after: ", poolBalanceAfter.toString(), poolTokenName)
|
||||||
|
expect(poolBalanceAfter).to.be.gt(ethers.utils.parseEther("0"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should deposit and withdraw all PrizePool, get back less than 100 DAI, and claim POOL", async function() {
|
it("Should deposit and withdraw all PrizePool, get back less than 100 DAI", async function() {
|
||||||
const amount = ethers.utils.parseEther("100") // 100 DAI
|
const amount = ethers.utils.parseEther("100") // 100 DAI
|
||||||
const spells = [
|
const spells = [
|
||||||
{
|
{
|
||||||
|
@ -197,11 +213,6 @@ describe("PoolTogether", function () {
|
||||||
connector: ptConnectorName,
|
connector: ptConnectorName,
|
||||||
method: "withdrawInstantlyFrom",
|
method: "withdrawInstantlyFrom",
|
||||||
args: [prizePool, dsaWallet0.address, amount, controlledToken, amount, 0, 0]
|
args: [prizePool, dsaWallet0.address, amount, controlledToken, amount, 0, 0]
|
||||||
},
|
|
||||||
{
|
|
||||||
connector: ptConnectorName,
|
|
||||||
method: "claim",
|
|
||||||
args: [daiPoolFaucet, dsaWallet0.address]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -240,7 +251,79 @@ describe("PoolTogether", function () {
|
||||||
console.log("\tBalance after: ", balanceAfter.toString(), tokenName)
|
console.log("\tBalance after: ", balanceAfter.toString(), tokenName)
|
||||||
expect(balanceAfter.toNumber()).to.be.eq(0);
|
expect(balanceAfter.toNumber()).to.be.eq(0);
|
||||||
|
|
||||||
// Expect Pool Token Balance to be greate than 0
|
// Expect Pool Token Balance to greater than 0
|
||||||
|
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
|
||||||
|
console.log("\tBalance after: ", poolBalanceAfter.toString(), poolTokenName)
|
||||||
|
expect(poolBalanceAfter).to.be.gt(ethers.utils.parseEther("0"));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should deposit, wait 11 days, and withdraw all PrizePool, get 99 DAI, and claim all POOL using claimAll", async function() {
|
||||||
|
const amount = ethers.utils.parseEther("99") // 99 DAI
|
||||||
|
const depositSpells = [
|
||||||
|
{
|
||||||
|
connector: ptConnectorName,
|
||||||
|
method: "depositTo",
|
||||||
|
args: [prizePool, dsaWallet0.address, amount, controlledToken, constants.address_zero, 0, 0]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
const withdrawSpells = [
|
||||||
|
{
|
||||||
|
connector: ptConnectorName,
|
||||||
|
method: "withdrawInstantlyFrom",
|
||||||
|
args: [prizePool, dsaWallet0.address, amount, controlledToken, amount, 0, 0]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
connector: ptConnectorName,
|
||||||
|
method: "claimAll",
|
||||||
|
args: [tokenFaucetProxyFactory, dsaWallet0.address, [daiPoolFaucet]]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
// Before spell
|
||||||
|
// DAI balance is 0
|
||||||
|
let daiToken = await ethers.getContractAt(abis.basic.erc20, token)
|
||||||
|
let daiBalance = await daiToken.balanceOf(dsaWallet0.address);
|
||||||
|
console.log("Before Spell:")
|
||||||
|
console.log("\tBalance before: ", daiBalance.toString(), tokens.dai.symbol);
|
||||||
|
|
||||||
|
// PT Dai Ticket is 0
|
||||||
|
let cToken = await ethers.getContractAt(abis.basic.erc20, controlledToken)
|
||||||
|
const balance = await cToken.balanceOf(dsaWallet0.address)
|
||||||
|
const tokenName = await cToken.name()
|
||||||
|
console.log("\tBalance before: ", balance.toString(), tokenName)
|
||||||
|
|
||||||
|
// PoolToken is 0
|
||||||
|
let poolToken = await ethers.getContractAt(abis.basic.erc20, poolTokenAddress)
|
||||||
|
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
|
||||||
|
const poolTokenName = await poolToken.name()
|
||||||
|
console.log("\tBalance before: ", poolBalance.toString(), poolTokenName)
|
||||||
|
|
||||||
|
// Run spell transaction
|
||||||
|
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(depositSpells), wallet1.address)
|
||||||
|
const receipt = await tx.wait()
|
||||||
|
|
||||||
|
// 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]);
|
||||||
|
|
||||||
|
// Run spell transaction
|
||||||
|
const tx2 = await dsaWallet0.connect(wallet0).cast(...encodeSpells(withdrawSpells), wallet1.address)
|
||||||
|
const receipt2 = await tx2.wait()
|
||||||
|
|
||||||
|
// After spell
|
||||||
|
// Expect DAI balance to be 99
|
||||||
|
daiBalance = await daiToken.balanceOf(dsaWallet0.address);
|
||||||
|
console.log("After spell: ");
|
||||||
|
console.log("\tBalance after: ", daiBalance.toString(), tokens.dai.symbol);
|
||||||
|
expect(daiBalance).to.be.eq(ethers.utils.parseEther("99"));
|
||||||
|
|
||||||
|
// Expect PT Dai Ticket to equal 0
|
||||||
|
const balanceAfter = await cToken.balanceOf(dsaWallet0.address)
|
||||||
|
console.log("\tBalance after: ", balanceAfter.toString(), tokenName)
|
||||||
|
expect(balanceAfter.toNumber()).to.be.eq(0);
|
||||||
|
|
||||||
|
// Expect Pool Token Balance to be greateir than 0
|
||||||
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
|
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
|
||||||
console.log("\tBalance after: ", poolBalanceAfter.toString(), poolTokenName)
|
console.log("\tBalance after: ", poolBalanceAfter.toString(), poolTokenName)
|
||||||
expect(poolBalanceAfter).to.be.gt(ethers.utils.parseEther("0"));
|
expect(poolBalanceAfter).to.be.gt(ethers.utils.parseEther("0"));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user