From 475612f506dc341d0ca2a342cfd66b6fc48e26d7 Mon Sep 17 00:00:00 2001 From: eccheung4 Date: Fri, 2 Jul 2021 19:49:43 -0700 Subject: [PATCH] WIP --- .../connectors/pooltogether/events.sol | 4 +- .../connectors/pooltogether/interface.sol | 6 +++ .../mainnet/connectors/pooltogether/main.sol | 40 ++++++++++++++----- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/contracts/mainnet/connectors/pooltogether/events.sol b/contracts/mainnet/connectors/pooltogether/events.sol index 6009945f..4bb8184e 100644 --- a/contracts/mainnet/connectors/pooltogether/events.sol +++ b/contracts/mainnet/connectors/pooltogether/events.sol @@ -1,6 +1,6 @@ pragma solidity ^0.7.0; contract Events { - event LogDepositTo(address to, uint256 amount, address controlledToken, address referrer); - event LogWithdrawInstantlyFrom(address from, uint256 amount, address controlledToken, uint256 maximumExitFee); + 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); } \ No newline at end of file diff --git a/contracts/mainnet/connectors/pooltogether/interface.sol b/contracts/mainnet/connectors/pooltogether/interface.sol index e69de29b..1ff58783 100644 --- a/contracts/mainnet/connectors/pooltogether/interface.sol +++ b/contracts/mainnet/connectors/pooltogether/interface.sol @@ -0,0 +1,6 @@ +pragma solidity ^0.7.0; + +interface PrizePoolInterface { + function depositTo( address to, uint256 amount, address controlledToken, address referrer) external; + function withdrawInstantlyFrom( address from, uint256 amount, address controlledToken, uint256 maximumExitFee) external returns (uint256); +} \ No newline at end of file diff --git a/contracts/mainnet/connectors/pooltogether/main.sol b/contracts/mainnet/connectors/pooltogether/main.sol index 6dbe7b55..03a8ccc9 100644 --- a/contracts/mainnet/connectors/pooltogether/main.sol +++ b/contracts/mainnet/connectors/pooltogether/main.sol @@ -7,52 +7,74 @@ 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 } from "./interface.sol"; import { TokenInterface } from "../../common/interfaces.sol"; import ( Events ) from "./events.sol"; import { DSMath } from "../../common/math.sol"; +import { Basic } from "../../common/basic.sol"; -abstract contract PoolTogetherResolver is Events, DSMath { +abstract contract PoolTogetherResolver is Events, DSMath, Basic { using SafeERC20 for IERC20; /** * @dev Deposit into Prize Pool + * @notice Deposit a token into a prize pool + * @param prizePool PrizePool address to deposit to * @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. * @param referrer The address that should receive referral awards, if any. + * @param getId Get token amount at this ID from `InstaMemory` Contract. + * @param setId Set token amount at this ID in `InstaMemory` Contract. */ function depositTo( + address prizePool, address: to, uint256 amount, address controlledToken, - address referrer - ) external payable returns ( string memory _eventName, bytes memory _eventParam) { + address referrer, + uint256 getId, + uint256 setId + ) external returns ( string memory _eventName, bytes memory _eventParam) { + uint _amount = getUint(getId, amount); + PrizePoolInterface prizePoolContract = PrizePoolInterface(prizePool); - _eventName = "LogDepositTo(address, uint256, address, address)"; - _eventParam = abi.encode(address(to), amount, address(controlledToken), address(referrer)); + // Approve prizePool + + 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); } /** - * #dev Withdraw from Prize Pool + * @dev Withdraw from Prize Pool + * @notice Withdraw a token from a prize pool * @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. * @param maximumExitFee The maximum early exit fee the caller is willing to pay. This prevents the Prize Strategy from changing the fee on the fly. + * @param getId Get token amount at this ID from `InstaMemory` Contract. + * @param setId Set token amount at this ID in `InstaMemory` Contract. */ function withdrawInstantlyFrom ( address from, uint256 amount, address controlledToken, - uint256 maximumExitFee + uint256 maximumExitFee, + uint256 getId, + uint256 setId ) external returns (string memory _eventName, bytes memory _eventParam) { - _eventName = "LogWithdrawInstantlyFrom(address, uint256, address, uint256)"; - _eventParams = abi.encode(address(from), amount, address(controlledToken), maximumExitFee); + _eventName = "LogWithdrawInstantlyFrom(address,uint256,address,uint256,uint256,uint256)"; + _eventParams = abi.encode(address(from), amount, address(controlledToken), maximumExitFee, getId, setId); }