Skip to content

Commit

Permalink
add devFunds contract
Browse files Browse the repository at this point in the history
Signed-off-by: therealsakeswap <[email protected]>
  • Loading branch information
therealsakeswap committed Sep 11, 2020
1 parent 213f032 commit 98f8955
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
36 changes: 36 additions & 0 deletions contracts/DevFunds.sol
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);
}
}
26 changes: 26 additions & 0 deletions test/DevFunds.test.js
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);
});
})

0 comments on commit 98f8955

Please sign in to comment.