forked from Sakeswap/sakeswap-protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: therealsakeswap <[email protected]>
- Loading branch information
1 parent
213f032
commit 98f8955
Showing
2 changed files
with
62 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
pragma solidity 0.6.12; | ||
|
||
import "@openzeppelin/contracts/math/SafeMath.sol"; | ||
import "./SakeToken.sol"; | ||
|
||
contract DevFunds { | ||
using SafeMath for uint; | ||
|
||
// the sake token | ||
SakeToken public sake; | ||
// dev address to receive sake | ||
address public devaddr; | ||
// last withdraw block | ||
uint public lastWithdrawBlock; | ||
// withdraw interval about 1 month | ||
uint public constant WITHDRAW_INTERVAL = 194800; | ||
// max amount of sake per withdraw | ||
uint public constant WITHDRAW_MAX = 68*10**22; | ||
|
||
constructor(SakeToken _sake, address _devaddr) public { | ||
require(address(_sake) != address(0) && _devaddr != address(0), "invalid address"); | ||
sake = _sake; | ||
devaddr = _devaddr; | ||
lastWithdrawBlock = block.number; | ||
} | ||
|
||
function withdraw() public { | ||
uint unlockBlock = lastWithdrawBlock.add(WITHDRAW_INTERVAL); | ||
require(block.number >= unlockBlock, "sake locked"); | ||
uint _amount = sake.balanceOf(address(this)); | ||
uint amountReal = _amount > WITHDRAW_MAX ? WITHDRAW_MAX : _amount; | ||
require(amountReal > 0, "zero sake amount"); | ||
lastWithdrawBlock = block.number; | ||
sake.transfer(devaddr, amountReal); | ||
} | ||
} |
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,26 @@ | ||
const { expectRevert, time } = require('@openzeppelin/test-helpers'); | ||
const SakeToken = artifacts.require('SakeToken'); | ||
const DevFunds = artifacts.require('DevFunds'); | ||
|
||
contract('DevFunds', ([alice, bob, carol]) => { | ||
beforeEach(async () => { | ||
this.sake = await SakeToken.new({ from: alice }); | ||
this.devFunds = await DevFunds.new(this.sake.address, bob, { from: alice }); | ||
this.withdrawInternal = await this.devFunds.WITHDRAW_INTERVAL(); | ||
this.maxWithdraw = await this.devFunds.WITHDRAW_MAX(); | ||
}); | ||
|
||
it('should revert before lockTime', async () => { | ||
await expectRevert(this.devFunds.withdraw({ from: alice }), 'sake locked'); | ||
const currentBlock = await time.latestBlock(); | ||
const unlockBlock = parseInt(currentBlock) + parseInt(this.withdrawInternal); | ||
await time.advanceBlockTo(unlockBlock); | ||
await expectRevert(this.devFunds.withdraw({ from: alice }), 'zero sake amount'); | ||
await this.sake.mint(this.devFunds.address, '1000000000000000000000000'); | ||
await this.devFunds.withdraw({ from: alice }); | ||
const bal = await this.sake.balanceOf(bob); | ||
assert.equal(bal.valueOf(), parseInt(this.maxWithdraw)); | ||
const lastWithdrawBlock = await this.devFunds.lastWithdrawBlock(); | ||
assert.equal(lastWithdrawBlock.valueOf(), unlockBlock + 3); | ||
}); | ||
}) |