-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dxdaoTimeLock #754
base: arc-factory
Are you sure you want to change the base?
dxdaoTimeLock #754
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
pragma solidity ^0.5.17; | ||
|
||
|
||
contract DxDAOTimeLock { | ||
|
||
address public owner; | ||
uint256 public releaseTime; | ||
|
||
constructor(address _owner, uint256 _releaseTime) public { | ||
owner = _owner; | ||
releaseTime = _releaseTime; | ||
} | ||
|
||
function () external payable { | ||
} | ||
|
||
function withdraw() external { | ||
require(msg.sender == owner, "only owner can withdraw"); | ||
// solhint-disable-next-line not-rely-on-time | ||
require(releaseTime < now, "cannot withdraw before releaseTime"); | ||
// solhint-disable-next-line avoid-call-value | ||
(bool success, ) = owner.call.value(address(this).balance)(""); | ||
require(success, "sendEther failed."); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,12 @@ contract Wallet is Ownable { | |
emit Pay(_beneficiary, amount); | ||
} | ||
|
||
function genericCall(address _contract, bytes memory _encodedABI) | ||
public | ||
returns(bool success, bytes memory returnValue) { | ||
// solhint-disable-next-line avoid-low-level-calls | ||
(success, returnValue) = _contract.call(_encodedABI); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why instead of sending the _encodeABI we execute the withdraw function with the signature that we already know it will have?
Doing this we make sure that the ONLY function that can be executed is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a public generic function which can call any contract specific Abis. |
||
require(success, "call fail"); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const helpers = require('./helpers'); | ||
|
||
const Wallet = artifacts.require("./Wallet.sol"); | ||
const DxDAOTimeLock = artifacts.require("./DxDAOTimeLock.sol"); | ||
contract('DxDAOTimeLock', accounts => { | ||
|
||
it("sendEther", async () => { | ||
var wallet = await Wallet.new(); | ||
await wallet.initialize(accounts[0]); | ||
var owner = wallet.address; | ||
var block = await web3.eth.getBlock("latest"); | ||
var releaseTime = block.timestamp + (30*60*60*24); | ||
var dxDAOTimeLock = await DxDAOTimeLock.new(owner,releaseTime); | ||
assert.equal(await dxDAOTimeLock.owner(), owner); | ||
assert.equal(await dxDAOTimeLock.releaseTime(), releaseTime); | ||
|
||
//send funds to wallet | ||
await web3.eth.sendTransaction({from:accounts[0],to:owner, value: web3.utils.toWei('10', "ether")}); | ||
assert.equal(await web3.eth.getBalance(owner), web3.utils.toWei('10', "ether")); | ||
await wallet.pay(dxDAOTimeLock.address); | ||
await wallet.pay(dxDAOTimeLock.address); | ||
assert.equal(await web3.eth.getBalance(dxDAOTimeLock.address), web3.utils.toWei('10', "ether")); | ||
|
||
var encodedABI = await new web3.eth.Contract(dxDAOTimeLock.abi) | ||
.methods | ||
.withdraw() | ||
.encodeABI(); | ||
|
||
try { | ||
await wallet.genericCall(dxDAOTimeLock.address, encodedABI); | ||
throw 'cannot withdraw before time'; | ||
} catch (error) { | ||
helpers.assertVMException(error); | ||
} | ||
await helpers.increaseTime((30*60*60*24)+1); | ||
try { | ||
await dxDAOTimeLock.withdraw(); | ||
throw 'only Owner can withdraw'; | ||
} catch (error) { | ||
helpers.assertVMException(error); | ||
} | ||
await wallet.genericCall(dxDAOTimeLock.address, encodedABI); | ||
assert.equal(await web3.eth.getBalance(owner), web3.utils.toWei('10', "ether")); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not
msg.sender.transfer(address(this).balance)
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because transfer is limited in gas. it might work for dxdao avatar though no promise for other contracts which consume gas on the fallback function.
https://diligence.consensys.net/blog/2019/09/stop-using-soliditys-transfer-now/