Last active
May 27, 2020 02:31
-
-
Save sunnya97/f3529715452235803e771535aa4704d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >=0.4.22 <0.7.0; | |
import "./IERC20.sol"; | |
contract DumbOpyn { | |
struct Put { | |
uint id; | |
address creator; | |
address executor; | |
uint begin_exercise_period; | |
uint end_exercise_period; | |
IERC20 collateral_token; | |
uint collateral_amount; | |
IERC20 underlying_token; | |
uint underlying_amount; | |
} | |
mapping (uint=>Put) puts; | |
uint next_id; | |
function newPut(address executor, uint begin_exercise_period, uint end_exercise_period, IERC20 collateral_token, uint collateral_amount, address underlying_token, uint underlying_amount) external { | |
address creator = msg.sender; | |
collateral_token.transferFrom(creator, this.address, collateral_amount); | |
puts[next_id] = Put( | |
next_id, | |
creator, | |
executor, | |
begin_exercise_period, | |
end_exercise_period, | |
collateral_token, | |
collateral_amount, | |
underlying_token, | |
underlying_amount | |
); | |
next_id = next_id + 1; | |
} | |
function exercisePut(uint id) external { | |
Put memory put = puts[id]; | |
require (msg.sender == put.executor, "only the executor can exercise this option"); | |
require(block.timestamp > put.begin_exercise_period, "the exercise period has not begun yet"); | |
require(block.timestamp < put.end_exercise_period, "the exercise period is over"); | |
put.underlying_token.transferFrom(put.executor, put.creator, put.underlying_amount); | |
put.collateral_token.trasfer(put.executor, put.collateral_amount); | |
puts[id] = Put(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment