Skip to content

Commit

Permalink
Replace OpenZeppelin Ownable due to out of gas errors on initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
apbendi committed Apr 25, 2020
1 parent 246baac commit 6c85a2f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 9 additions & 3 deletions contracts/GuildBank.sol
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
pragma solidity ^0.5.0;

import "@openzeppelin/contracts-ethereum-package/contracts/ownership/Ownable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";

interface ISablier {
function createStream(address recipient, uint256 deposit, address tokenAddress, uint256 startTime, uint256 stopTime) external returns (uint256);
}

contract GuildBank is Ownable {
contract GuildBank {
using SafeMath for uint256;

address public owner;
IERC20 public approvedToken; // approved token contract reference
ISablier public sablier;

event Withdrawal(address indexed receiver, uint256 amount);

constructor(address approvedTokenAddress) public {
owner = msg.sender;
approvedToken = IERC20(approvedTokenAddress);
sablier = ISablier(0xA4fc358455Febe425536fd1878bE67FfDBDEC59a);
approvedToken.approve(address(sablier), uint256(-1));
Expand All @@ -28,7 +29,12 @@ contract GuildBank is Ownable {
return approvedToken.transfer(receiver, amount);
}

function initiateStream(address grantee, uint256 amount, uint256 duration) public {
function initiateStream(address grantee, uint256 amount, uint256 duration) public onlyOwner {
sablier.createStream(grantee, amount, address(approvedToken), block.timestamp, block.timestamp + duration);
}

modifier onlyOwner() {
require(msg.sender == owner, "Endaoment::GuildBank - Not Owner");
_;
}
}
4 changes: 4 additions & 0 deletions test/endaoment-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { accounts, contract, web3 } = require('@openzeppelin/test-environment');
const { time, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const Moloch = contract.fromArtifact('Moloch');
const GuildBank = contract.fromArtifact('GuildBank');
const { toWeiDai, stealDai, approveDai } = require('./helpers');

const PERIOD_DURATION = 17280;
Expand Down Expand Up @@ -31,6 +32,9 @@ describe('Moloch', () => {
{from: summoner}
);

const guildBankAddr = await this.instance.guildBank();
this.guildBank = await GuildBank.at(guildBankAddr);

await stealDai(1000, summoner);
await stealDai(20000, member1);
await stealDai(20000, member2);
Expand Down

0 comments on commit 6c85a2f

Please sign in to comment.