mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
WIP: Withdrawal Working
This commit is contained in:
parent
aa6e61a6d7
commit
8702de7dd1
|
@ -1,6 +1,6 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
event LogDepositTo(address to, uint256 amount, address controlledToken, address referrer, uint256 getId, uint256 setId);
|
||||
event LogWithdrawInstantlyFrom(address from, uint256 amount, address controlledToken, uint256 maximumExitFee, 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);
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
interface PrizePoolInterface {
|
||||
function token() external view returns (address);
|
||||
function depositTo( address to, uint256 amount, address controlledToken, address referrer) external;
|
||||
function withdrawInstantlyFrom( address from, uint256 amount, address controlledToken, uint256 maximumExitFee) external returns (uint256);
|
||||
}
|
|
@ -21,7 +21,6 @@ abstract contract PoolTogetherResolver is Events, DSMath, Basic {
|
|||
* @dev Deposit into Prize Pool
|
||||
* @notice Deposit a token into a prize pool
|
||||
* @param prizePool PrizePool address to deposit to
|
||||
* @param token Token to deposit
|
||||
* @param to Address to whom the controlled tokens should be minted
|
||||
* @param amount The amount of the underlying asset the user wishes to deposit. The Prize Pool contract should have been pre-approved by the caller to transfer the underlying ERC20 tokens.
|
||||
* @param controlledToken The address of the token that they wish to mint. For our default Prize Strategy this will either be the Ticket address or the Sponsorship address. Those addresses can be looked up on the Prize Strategy.
|
||||
|
@ -32,7 +31,6 @@ abstract contract PoolTogetherResolver is Events, DSMath, Basic {
|
|||
|
||||
function depositTo(
|
||||
address prizePool,
|
||||
address token,
|
||||
address to,
|
||||
uint256 amount,
|
||||
address controlledToken,
|
||||
|
@ -43,22 +41,24 @@ abstract contract PoolTogetherResolver is Events, DSMath, Basic {
|
|||
uint _amount = getUint(getId, amount);
|
||||
|
||||
PrizePoolInterface prizePoolContract = PrizePoolInterface(prizePool);
|
||||
address prizePoolToken = prizePoolContract.token();
|
||||
|
||||
// Approve prizePool
|
||||
TokenInterface tokenContract = TokenInterface(token);
|
||||
TokenInterface tokenContract = TokenInterface(prizePoolToken);
|
||||
tokenContract.approve(prizePool, _amount);
|
||||
|
||||
prizePoolContract.depositTo(to, amount, controlledToken, referrer);
|
||||
prizePoolContract.depositTo(to, _amount, controlledToken, referrer);
|
||||
|
||||
setUint(setId, _amount);
|
||||
|
||||
_eventName = "LogDepositTo(address,uint256,address,address,uint256, uint256)";
|
||||
_eventParam = abi.encode(address(to), amount, address(controlledToken), address(referrer), getId, setId);
|
||||
_eventName = "LogDepositTo(address,address,uint256,address,address,uint256, uint256)";
|
||||
_eventParam = abi.encode(address(prizePool), address(to), _amount, address(controlledToken), address(referrer), getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Withdraw from Prize Pool
|
||||
* @notice Withdraw a token from a prize pool
|
||||
* @param prizePool PrizePool address to deposit to
|
||||
* @param from The address to withdraw from. This means you can withdraw on another user's behalf if you have an allowance for the controlled token.
|
||||
* @param amount THe amount to withdraw
|
||||
* @param controlledToken The controlled token to withdraw from.
|
||||
|
@ -68,6 +68,7 @@ abstract contract PoolTogetherResolver is Events, DSMath, Basic {
|
|||
*/
|
||||
|
||||
function withdrawInstantlyFrom (
|
||||
address prizePool,
|
||||
address from,
|
||||
uint256 amount,
|
||||
address controlledToken,
|
||||
|
@ -75,13 +76,17 @@ abstract contract PoolTogetherResolver is Events, DSMath, Basic {
|
|||
uint256 getId,
|
||||
uint256 setId
|
||||
) external returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amount = getUint(getId, amount);
|
||||
|
||||
PrizePoolInterface prizePoolContract = PrizePoolInterface(prizePool);
|
||||
|
||||
_eventName = "LogWithdrawInstantlyFrom(address,uint256,address,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(address(from), amount, address(controlledToken), maximumExitFee, getId, setId);
|
||||
prizePoolContract.withdrawInstantlyFrom(from, _amount, controlledToken, maximumExitFee);
|
||||
|
||||
setUint(setId, _amount);
|
||||
|
||||
_eventName = "LogWithdrawInstantlyFrom(address,address,uint256,address,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(address(prizePool), address(from), _amount, address(controlledToken), maximumExitFee, getId, setId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
contract ConnectV2PoolTogether is PoolTogetherResolver {
|
||||
|
|
|
@ -16,6 +16,10 @@ const tokens = require("../../scripts/constant/tokens");
|
|||
const connectV2CompoundArtifacts = require("../../artifacts/contracts/mainnet/connectors/compound/main.sol/ConnectV2Compound.json")
|
||||
const connectV2PoolTogetherArtifacts = require("../../artifacts/contracts/mainnet/connectors/pooltogether/main.sol/ConnectV2PoolTogether.json")
|
||||
|
||||
const token = tokens.dai.address // DAI Token
|
||||
const prizePool = "0xEBfb47A7ad0FD6e57323C8A42B2E5A6a4F68fc1a" // DAI Prize Pool
|
||||
const controlledToken = "0x334cBb5858417Aee161B53Ee0D5349cCF54514CF" // PT DAI Ticket
|
||||
|
||||
describe("PoolTogether", function () {
|
||||
const connectorName = "COMPOUND-TEST-A"
|
||||
const ptConnectorName = "POOLTOGETHER-TEST-A"
|
||||
|
@ -31,20 +35,20 @@ describe("PoolTogether", function () {
|
|||
before(async () => {
|
||||
masterSigner = await getMasterSigner(wallet3)
|
||||
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
|
||||
|
||||
connector = await deployAndEnableConnector({
|
||||
connectorName,
|
||||
contractArtifact: connectV2CompoundArtifacts,
|
||||
signer: masterSigner,
|
||||
connectors: instaConnectorsV2
|
||||
})
|
||||
console.log("Connector address", connector.address)
|
||||
|
||||
ptConnector = await deployAndEnableConnector({
|
||||
connectorName: ptConnectorName,
|
||||
contractArtifact: connectV2PoolTogetherArtifacts,
|
||||
signer: masterSigner,
|
||||
connectors: instaConnectorsV2
|
||||
})
|
||||
console.log("PTConnector address", ptConnector.address)
|
||||
})
|
||||
|
||||
it("Should have contracts deployed.", async function () {
|
||||
|
@ -87,11 +91,8 @@ describe("PoolTogether", function () {
|
|||
});
|
||||
|
||||
it("Should borrow DAI from Compound and deposit DAI into DAI Prize Pool", async function () {
|
||||
const amount = 100 // 100 DAI
|
||||
const amount = ethers.utils.parseEther("100") // 100 DAI
|
||||
const setId = "83478237"
|
||||
const token = tokens.dai.address // DAI Token
|
||||
const prizePool = "0xEBfb47A7ad0FD6e57323C8A42B2E5A6a4F68fc1a" // DAI Prize Pool
|
||||
const controlledToken = "0x334cBb5858417Aee161B53Ee0D5349cCF54514CF" // PT DAI Ticket
|
||||
const spells = [
|
||||
{
|
||||
connector: connectorName,
|
||||
|
@ -101,50 +102,64 @@ describe("PoolTogether", function () {
|
|||
{
|
||||
connector: ptConnectorName,
|
||||
method: "depositTo",
|
||||
args: [prizePool, token, dsaWallet0.address, amount, controlledToken, constants.address_zero, setId, 0]
|
||||
args: [prizePool, dsaWallet0.address, amount, controlledToken, constants.address_zero, setId, 0]
|
||||
}
|
||||
]
|
||||
let daiToken = await ethers.getContractAt(abis.basic.erc20, token)
|
||||
let daiBalance = await daiToken.balanceOf(dsaWallet0.address);
|
||||
console.log("DAI balance before: ", daiBalance.toString());
|
||||
|
||||
let cToken = await ethers.getContractAt(abis.basic.erc20, controlledToken)
|
||||
const balance = await cToken.balanceOf(dsaWallet0.address)
|
||||
const tokenName = await cToken.name()
|
||||
console.log("Balance: ", balance.toString(), tokenName)
|
||||
console.log("PTDAI balance before: ", balance.toString(), tokenName)
|
||||
|
||||
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
|
||||
const receipt = await tx.wait()
|
||||
|
||||
// Expect DAI balance to equal 0
|
||||
daiBalance = await daiToken.balanceOf(dsaWallet0.address);
|
||||
console.log("DAI balance after: ", daiBalance.toString());
|
||||
expect(daiBalance).to.be.eq(ethers.utils.parseEther("0"));
|
||||
|
||||
// Expect PT DAI Ticket to equal 100
|
||||
const balanceAfter = await cToken.balanceOf(dsaWallet0.address)
|
||||
console.log("Balance: ", balanceAfter.toString(), tokenName)
|
||||
console.log("PTDAI balance after: ", balanceAfter.toString(), tokenName)
|
||||
expect(balanceAfter.toString()).to.be.eq(ethers.utils.parseEther("100"));
|
||||
|
||||
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("9"));
|
||||
// Should have 100 PT DAI Tickets
|
||||
expect(balanceAfter.toNumber()).to.be.eq(100);
|
||||
});
|
||||
|
||||
// it("Should deposit all ETH in Compound", async function () {
|
||||
// const spells = [
|
||||
// {
|
||||
// connector: connectorName,
|
||||
// method: "deposit",
|
||||
// args: ["ETH-A", constants.max_value, 0, 0]
|
||||
// }
|
||||
// ]
|
||||
it("Should withdraw all PrizePool", async function () {
|
||||
const amount = ethers.utils.parseEther("100") // 100 DAI
|
||||
const spells = [
|
||||
{
|
||||
connector: ptConnectorName,
|
||||
method: "withdrawInstantlyFrom",
|
||||
args: [prizePool, dsaWallet0.address, amount, controlledToken, amount, 0, 0]
|
||||
}
|
||||
]
|
||||
let daiToken = await ethers.getContractAt(abis.basic.erc20, token)
|
||||
let daiBalance = await daiToken.balanceOf(dsaWallet0.address);
|
||||
console.log("DAI balance before: ", daiBalance.toString());
|
||||
|
||||
// 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("0"));
|
||||
// });
|
||||
let cToken = await ethers.getContractAt(abis.basic.erc20, controlledToken)
|
||||
const balance = await cToken.balanceOf(dsaWallet0.address)
|
||||
const tokenName = await cToken.name()
|
||||
console.log("PTDAI balance before: ", balance.toString(), tokenName)
|
||||
|
||||
// it("Should withdraw all ETH from Compound", async function () {
|
||||
// const spells = [
|
||||
// {
|
||||
// connector: connectorName,
|
||||
// method: "withdraw",
|
||||
// args: ["ETH-A", constants.max_value, 0, 0]
|
||||
// }
|
||||
// ]
|
||||
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
|
||||
const receipt = await tx.wait()
|
||||
|
||||
// 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.gte(ethers.utils.parseEther("10"));
|
||||
// });
|
||||
// Expect DAI balance to be greater than 90
|
||||
daiBalance = await daiToken.balanceOf(dsaWallet0.address);
|
||||
console.log("DAI balance after: ", daiBalance.toString());
|
||||
expect(daiBalance).to.be.gt(ethers.utils.parseEther("90"));
|
||||
|
||||
// Expect PT Dai Ticket to equal 0
|
||||
const balanceAfter = await cToken.balanceOf(dsaWallet0.address)
|
||||
console.log("PTDAI balance after: ", balanceAfter.toString(), tokenName)
|
||||
expect(balanceAfter.toNumber()).to.be.eq(0);
|
||||
});
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue
Block a user