-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into jade/de-prize-join
- Loading branch information
Showing
87 changed files
with
3,806 additions
and
835 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"MOONEYToken": "0x3B3024e49261866a420F2444Fa1f248902C8D143", | ||
"vMOONEYToken": "0xa83aceC4e6784a0c9C4Ba6fa414665Ba15F6F3b6" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"MOONEYToken": "0x6585a54A98fADA893904EB8A9E9CDFb927bddf39", | ||
"vMOONEYToken": "0x7f8f1B45c3FD6Be4F467520Fc1Cf030d5CaBAcF5" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
[default] | ||
[profile.default] | ||
src = "src" | ||
out = "out" | ||
libs = ["lib"] | ||
evm_version = "berlin" | ||
|
||
#[profile.default.compiler] | ||
#version = "0.8.10" | ||
|
||
# Vyper compiler settings | ||
[profile.default.vyper] | ||
vyper_version = "0.3.1" |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
//import "@openzeppelin/contracts-4.2.0/access/Ownable.sol"; | ||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
||
contract SmartWalletChecker is Ownable { | ||
bool public isWhitelistEnabled; | ||
mapping(address => bool) public wallets; | ||
address public checker; | ||
address public future_checker; | ||
|
||
event ApproveWallet(address); | ||
event RevokeWallet(address); | ||
event WhitelistEnabled(bool); | ||
|
||
constructor(bool _isWhitelistEnabled) public Ownable() { | ||
// Set state variables | ||
setIsWhitelistEnabled(_isWhitelistEnabled); | ||
} | ||
|
||
function commitSetChecker(address _checker) external onlyOwner { | ||
future_checker = _checker; | ||
} | ||
|
||
function applySetChecker() external onlyOwner { | ||
checker = future_checker; | ||
} | ||
|
||
function approveWallet(address _wallet) external onlyOwner { | ||
wallets[_wallet] = true; | ||
|
||
emit ApproveWallet(_wallet); | ||
} | ||
|
||
function revokeWallet(address _wallet) external onlyOwner { | ||
wallets[_wallet] = false; | ||
|
||
emit RevokeWallet(_wallet); | ||
} | ||
|
||
function setIsWhitelistEnabled(bool _isWhitelistEnabled) public onlyOwner { | ||
isWhitelistEnabled = _isWhitelistEnabled; | ||
|
||
emit WhitelistEnabled(_isWhitelistEnabled); | ||
} | ||
|
||
function check(address _wallet) external view returns (bool) { | ||
if (!isWhitelistEnabled) { | ||
return true; | ||
} | ||
|
||
bool _check = wallets[_wallet]; | ||
if (_check) { | ||
return _check; | ||
} else { | ||
if (checker != address(0)) { | ||
return SmartWalletChecker(checker).check(_wallet); | ||
} | ||
} | ||
return false; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
||
interface IERC20Interface { | ||
function transfer(address recipient, uint256 amount) external returns (bool); | ||
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); | ||
function balanceOf(address account) external view returns (uint256); | ||
} | ||
|
||
interface IVotingEscrowInterface { | ||
function deposit_for(address _addr, uint256 _value) external; | ||
} | ||
|
||
contract VotingEscrowDepositor is Ownable{ | ||
IERC20Interface public token; | ||
IVotingEscrowInterface public escrowToken; | ||
// map from address to amount availabe to withdraw | ||
mapping(address => uint256) public availableToWithdraw; | ||
address[] public withdrawAddresses; | ||
|
||
constructor(address _tokenAddress, address _escrowTokenAddress){ | ||
token = IERC20Interface(_tokenAddress); | ||
escrowToken = IVotingEscrowInterface(_escrowTokenAddress); | ||
} | ||
|
||
function increaseWithdrawAmounts(address[] memory addresses, uint256[] memory amounts) external onlyOwner{ | ||
require(addresses.length == amounts.length, "Arrays must be of equal length"); | ||
uint256 totalAmount = 0; | ||
for (uint256 i = 0; i < addresses.length; i++) { | ||
if (availableToWithdraw[addresses[i]] == 0) { | ||
withdrawAddresses.push(addresses[i]); | ||
} | ||
availableToWithdraw[addresses[i]] += amounts[i]; | ||
totalAmount += amounts[i]; | ||
} | ||
require(token.transferFrom(msg.sender, address(this), totalAmount), "Token transfer failed"); | ||
} | ||
|
||
function clearWithdrawAmounts() external onlyOwner { | ||
for (uint256 i = 0; i < withdrawAddresses.length; i++) { | ||
availableToWithdraw[withdrawAddresses[i]] = 0; | ||
} | ||
delete withdrawAddresses; | ||
} | ||
|
||
function withdraw() external { | ||
uint256 amount = availableToWithdraw[msg.sender]; | ||
require(amount > 0, "No amount available to withdraw"); | ||
availableToWithdraw[msg.sender] = 0; | ||
require(token.transfer(msg.sender, amount), "Token transfer failed"); | ||
escrowToken.deposit_for(msg.sender, amount); | ||
} | ||
|
||
function returnTokens() external onlyOwner { | ||
uint256 balance = token.balanceOf(address(this)); | ||
require(token.transfer(msg.sender, balance), "Token transfer failed"); | ||
} | ||
|
||
function sendVotingEscrowTokens(address _addr, uint256 _value) external onlyOwner { | ||
require(token.transfer(_addr, _value), "Token transfer failed"); | ||
escrowToken.deposit_for(_addr, _value); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "forge-std/Test.sol"; | ||
import "../governance/VotingEscrowDepositor.sol"; | ||
import "../governance/SmartWalletChecker.sol"; | ||
import "../governance/IVotingEscrow.sol"; | ||
import "../tokens/MyToken.sol"; | ||
|
||
contract VotingEscrowDepositorTest is Test { | ||
VotingEscrowDepositor public depositor; | ||
MyToken public token; | ||
IVotingEscrow public escrowToken; | ||
SmartWalletChecker public checker; | ||
|
||
address public user = address(0x123); | ||
uint256 public initialBalance = 126144000 * 2; | ||
uint256 depositAmount = 126144000; | ||
|
||
address public MOONEY = 0x5FbDB2315678afecb367f032d93F642f64180aa3; | ||
|
||
address public vMOONEY = 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512; | ||
|
||
|
||
function setUp() public { | ||
token = MyToken(MOONEY); | ||
|
||
escrowToken = IVotingEscrow(vMOONEY); | ||
vm.prank(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266); | ||
depositor = new VotingEscrowDepositor(address(MOONEY), address(vMOONEY)); | ||
checker = new SmartWalletChecker(true); | ||
checker.approveWallet(address(depositor)); | ||
// we don't seem to need this in prod, but required for tests | ||
checker.approveWallet(address(user)); | ||
vm.prank(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266); | ||
escrowToken.commit_smart_wallet_checker(address(checker)); | ||
vm.prank(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266); | ||
escrowToken.apply_smart_wallet_checker(); | ||
//token.transfer(address(depositor), initialBalance); | ||
address[] memory addresses = new address[](1); | ||
addresses[0] = address(user); | ||
uint256[] memory amounts = new uint256[](1); | ||
amounts[0] = depositAmount; | ||
vm.prank(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266); | ||
token.approve(address(depositor), depositAmount); | ||
vm.prank(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266); | ||
depositor.increaseWithdrawAmounts(addresses, amounts); | ||
vm.prank(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266); | ||
token.transfer(address(user), initialBalance); | ||
vm.prank(user); | ||
token.approve(address(escrowToken), initialBalance); | ||
vm.prank(user); | ||
escrowToken.create_lock(initialBalance, block.timestamp + 4*60 * 60 * 24 * 365); | ||
vm.prank(user); | ||
token.approve(address(escrowToken), depositAmount); | ||
vm.prank(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266); | ||
depositor.sendVotingEscrowTokens(address(user), depositAmount); | ||
} | ||
|
||
function testTransferAndDepositFor() public { | ||
vm.prank(user); | ||
depositor.withdraw(); | ||
assertEq(escrowToken.balanceOf(user), depositAmount + initialBalance); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
NEXT_PUBLIC_CHAIN=mumbai | ||
NEXT_PUBLIC_VMOONEY_REQUIRED_STAKE=1 | ||
NEXT_PUBLIC_SNAPSHOT_API_KEY=placeholder | ||
COORDINAPE_API_KEY=placeholder |
Oops, something went wrong.