redact vesting expiry to auction configuration
This commit is contained in:
parent
228831255e
commit
2969ace51b
@ -1,4 +1,4 @@
|
||||
pragma solidity 0.8.0;
|
||||
pragma solidity 0.8.13;
|
||||
|
||||
import "@openzeppelin/token/ERC20/IERC20.sol";
|
||||
import "@interfaces/IStaking.sol";
|
||||
@ -11,6 +11,7 @@ contract DelegatedInstance {
|
||||
uint256 public _balance;
|
||||
|
||||
address public _governanceAddress;
|
||||
address public _stakingAddress;
|
||||
address public _tokenAddress;
|
||||
|
||||
constructor(
|
||||
@ -54,8 +55,8 @@ contract DelegatedInstance {
|
||||
function unlockAndRedeem() public {
|
||||
require(msg.sender == _sender, "INVALID SENDER");
|
||||
|
||||
uint256 reward = IStaking(_stakingAddress).checkReward();
|
||||
uint256 stake = _balance;
|
||||
uint256 reward = IStaking(_stakingAddress).checkReward(address(this));
|
||||
|
||||
delete _balance;
|
||||
|
||||
@ -68,20 +69,17 @@ contract DelegatedInstance {
|
||||
|
||||
contract DelegatedVesting {
|
||||
|
||||
uint256 public _period;
|
||||
address public _governanceAddress;
|
||||
address public _tokenAddress;
|
||||
address public _governanceAddress;
|
||||
|
||||
mapping(address => uint256) _balances;
|
||||
mapping(address => address) _instances;
|
||||
mapping(address => uint256) _commitments;
|
||||
|
||||
constructor(
|
||||
uint256 vestingDuration,
|
||||
address governanceAddress,
|
||||
address tokenAddress
|
||||
) {
|
||||
_period = vestingDuration;
|
||||
_tokenAddress = tokenAddress;
|
||||
_governanceAddress = governanceAddress;
|
||||
}
|
||||
@ -98,10 +96,13 @@ contract DelegatedVesting {
|
||||
return _balances[stakeholder] > 0 && _commitments[stakeholder] < block.timestamp;
|
||||
}
|
||||
|
||||
function makeCommitment(address stakeholder, uint256 amount) public {
|
||||
require(IERC20(_tokenAddress).transferFrom(msg.sender, address(this), amount));
|
||||
function makeCommitment(address stakeholder, uint256 amount, uint256 expiry) public {
|
||||
require(block.timestamp < expiry, "INVALID EXPIRY TIMESTAMP");
|
||||
require(_commitments[stakeholder] == 0, "ACTIVE VESTING");
|
||||
|
||||
_commitments[stakeholder] = block.timestmap + _period;
|
||||
IERC20(_tokenAddress).transferFrom(msg.sender, address(this), amount);
|
||||
|
||||
_commitments[stakeholder] = expiry;
|
||||
_balances[stakeholder] += amount;
|
||||
}
|
||||
|
||||
@ -115,15 +116,13 @@ contract DelegatedVesting {
|
||||
require(isActiveCommitment(msg.sender), "INVALID COMMITMENT");
|
||||
|
||||
if(isDelegatedCommitment(msg.sender)) {
|
||||
DelegatedInstance(_instance[msg.sender]).delegate(delegateAddress);
|
||||
DelegatedInstance(_instances[msg.sender]).delegate(delegateAddress);
|
||||
} else {
|
||||
DelegatedInstance e = new DelegatedInstance(
|
||||
msg.sender,
|
||||
_governanceAddress,
|
||||
_tokenAddress,
|
||||
_balances[msg.sender],
|
||||
deadline,
|
||||
v, r, s
|
||||
_balances[msg.sender]
|
||||
);
|
||||
|
||||
_instances[msg.sender] = address(e);
|
||||
@ -139,6 +138,7 @@ contract DelegatedVesting {
|
||||
uint256 stake = _balances[msg.sender];
|
||||
address delegated = _instances[msg.sender];
|
||||
|
||||
delete _commitments[msg.sender];
|
||||
delete _balances[msg.sender];
|
||||
delete _instances[msg.sender];
|
||||
|
||||
|
@ -1,25 +1,28 @@
|
||||
pragma solidity 0.8.0;
|
||||
pragma solidity 0.8.13;
|
||||
|
||||
import "@openzeppelin/token/ERC20/IERC20.sol";
|
||||
import "@interfaces/IRDA.sol";
|
||||
import "@root/DelegatedVesting.sol";
|
||||
import "@root/RDA.sol";
|
||||
|
||||
contract Proposal {
|
||||
|
||||
function executeProposal() external {
|
||||
address tokenAddress = 0x77777FeDdddFfC19Ff86DB637967013e6C6A116C;
|
||||
address wethAddress = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
|
||||
address governanceAddress = 0x77777FeDdddFfC19Ff86DB637967013e6C6A116C;
|
||||
|
||||
address vestingAddress = address(new DelegatedVesting(tokenAddress, governanceAddress));
|
||||
address auctionAddress = address(new RDA());
|
||||
|
||||
uint256 VESTING_PERIOD = 10 weeks;
|
||||
uint256 AUCTION_START_TS = block.timestamp;
|
||||
uint256 AUCTION_END_TS = AUCTION_START_TS + 1 week;
|
||||
uint256 AUCTION_END_TS = AUCTION_START_TS + 1 weeks;
|
||||
uint256 AUCTION_ORIGIN_PRICE = 4172000 gwei;
|
||||
uint256 AUCTION_RESERVE_AMOUNT = 100000 ether;
|
||||
uint256 AUCTION_MINIMUM_AMOUNT = 1 ether;
|
||||
uint256 AUCTION_WINDOW_LENGTH = 8 hours;
|
||||
|
||||
address wethAddress;
|
||||
address tokenAddress;
|
||||
address governanceAddress;
|
||||
address auctionAddress;
|
||||
address vestingAddress;
|
||||
|
||||
IRDA(auctionAddress).createAuction(
|
||||
function executeProposal() external {
|
||||
RDA(auctionAddress).createAuction(
|
||||
vestingAddress,
|
||||
governanceAddress,
|
||||
tokenAddress,
|
||||
@ -29,7 +32,8 @@ contract Proposal {
|
||||
AUCTION_ORIGIN_PRICE,
|
||||
AUCTION_START_TS,
|
||||
AUCTION_END_TS,
|
||||
AUCTION_WINDOW_LENGTH
|
||||
AUCTION_WINDOW_LENGTH,
|
||||
VESTING_PERIOD
|
||||
);
|
||||
}
|
||||
|
||||
|
25
src/RDA.sol
25
src/RDA.sol
@ -3,8 +3,8 @@ pragma solidity 0.8.13;
|
||||
import { UD60x18 } from "@prb/math/UD60x18.sol";
|
||||
|
||||
import { IRDA } from "@interfaces/IRDA.sol";
|
||||
import { IVesting } from "@interfaces/IVesting.sol";
|
||||
import { IERC20 } from "@openzeppelin/token/ERC20/IERC20.sol";
|
||||
import { IDelegatedVesting } from "@interfaces/IDelegatedVesting.sol";
|
||||
|
||||
import { add, sub, mul, wrap, unwrap, gt, mod, div } from "@prb/math/UD60x18.sol";
|
||||
|
||||
@ -28,6 +28,8 @@ contract RDA is IRDA {
|
||||
/* @dev Auction mapping for the window index */
|
||||
mapping(bytes => uint256) public _windows;
|
||||
|
||||
mapping(bytes => Vesting) public _vesting;
|
||||
|
||||
struct Auction {
|
||||
uint256 windowDuration; /* @dev Unix time window duration */
|
||||
uint256 windowTimestamp; /* @dev Unix timestamp for window start */
|
||||
@ -47,6 +49,11 @@ contract RDA is IRDA {
|
||||
bool processed; /* @dev Window fuflfillment state */
|
||||
}
|
||||
|
||||
struct Vesting {
|
||||
address instance;
|
||||
uint256 period;
|
||||
}
|
||||
|
||||
/*
|
||||
* @dev Conditioner to ensure an auction is active
|
||||
* @param a͟u͟c͟t͟i͟o͟n͟I͟d͟ Encoded auction parameter identifier
|
||||
@ -126,7 +133,8 @@ contract RDA is IRDA {
|
||||
uint256 startingOriginPrice,
|
||||
uint256 startTimestamp,
|
||||
uint256 endTimestamp,
|
||||
uint256 windowDuration
|
||||
uint256 windowDuration,
|
||||
uint256 vestingDuration
|
||||
) external returns (bytes memory) {
|
||||
bytes memory auctionId = abi.encode(
|
||||
operatorAddress,
|
||||
@ -142,6 +150,9 @@ contract RDA is IRDA {
|
||||
revert AuctionExists();
|
||||
}
|
||||
|
||||
_vesting[auctionId].instance = vestingAddress;
|
||||
_vesting[auctionId].period = vestingDuration;
|
||||
|
||||
IERC20(reserveToken).transferFrom(msg.sender, address(this), reserveAmount);
|
||||
|
||||
state.duration = endTimestamp - startTimestamp;
|
||||
@ -151,7 +162,6 @@ contract RDA is IRDA {
|
||||
state.endTimestamp = endTimestamp;
|
||||
state.reserves = reserveAmount;
|
||||
state.price = startingOriginPrice;
|
||||
state.vesting = vestingAddress;
|
||||
|
||||
emit NewAuction(auctionId, reserveToken, reserveAmount, startingOriginPrice, endTimestamp);
|
||||
|
||||
@ -392,17 +402,20 @@ contract RDA is IRDA {
|
||||
inactiveAuction(auctionId)
|
||||
external {
|
||||
bytes memory claimHash = _claims[bidder][auctionId];
|
||||
address vestingAddress = _auctions[auctionId].vesting;
|
||||
|
||||
delete _claims[bidder][auctionId];
|
||||
|
||||
(uint256 refund, uint256 claim) = balancesOf(claimHash);
|
||||
|
||||
delete _claims[bidder][auctionId];
|
||||
uint256 vestingTimestamp = block.timestamp + _vesting[auctionId].period;
|
||||
address vestingAddress = _vesting[auctionId].instance;
|
||||
|
||||
if (refund > 0) {
|
||||
IERC20(purchaseToken(auctionId)).transfer(bidder, refund);
|
||||
}
|
||||
if (claim > 0) {
|
||||
IVesting(vestingAddress).makeCommitment(bidder, claim);
|
||||
IERC20(reserveToken(auctionId)).approve(vestingAddress, claim);
|
||||
IDelegatedVesting(vestingAddress).makeCommitment(bidder, claim, vestingTimestamp);
|
||||
}
|
||||
|
||||
emit Claim(auctionId, claimHash);
|
||||
|
7
src/interfaces/IDelegatedVesting.sol
Normal file
7
src/interfaces/IDelegatedVesting.sol
Normal file
@ -0,0 +1,7 @@
|
||||
pragma solidity 0.8.13;
|
||||
|
||||
interface IDelegatedVesting {
|
||||
|
||||
function makeCommitment(address stakeholder, uint256 amount, uint256 expiry) external;
|
||||
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
pragma solidity 0.8.0;
|
||||
|
||||
interface IERC20 {
|
||||
|
||||
function transferFrom(address from, address to, uint256 amount) external returns (bool);
|
||||
|
||||
function transfer(address to, uint256 amount) external returns (bool);
|
||||
|
||||
function balanceOf(address owner) external view returns (uint256);
|
||||
|
||||
function approve(address spender, uint256 amount) external;
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
pragma solidity 0.8.0;
|
||||
pragma solidity 0.8.13;
|
||||
|
||||
interface IGovernance {
|
||||
|
||||
|
@ -19,6 +19,7 @@ interface IRDA {
|
||||
error AuctionExists();
|
||||
|
||||
function createAuction(
|
||||
address vestingAddress,
|
||||
address operatorAddress,
|
||||
address reserveToken,
|
||||
address purchaseToken,
|
||||
@ -27,6 +28,7 @@ interface IRDA {
|
||||
uint256 startingOriginPrice,
|
||||
uint256 startTimestamp,
|
||||
uint256 endTimestamp,
|
||||
uint256 vestingTimestamp,
|
||||
uint256 windowDuration
|
||||
) external returns (bytes memory);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
pragma solidity 0.8.0;
|
||||
pragma solidity 0.8.13;
|
||||
|
||||
interface IStaking {
|
||||
|
||||
|
@ -1,7 +0,0 @@
|
||||
pragma solidity 0.8.0;
|
||||
|
||||
interface IVesting {
|
||||
|
||||
function makeCommitment(address stakeholder, uint256 amount) external;
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user