Skip to content

Commit

Permalink
Implement withdraw function.
Browse files Browse the repository at this point in the history
  • Loading branch information
lacasian committed Sep 7, 2020
1 parent 5c15683 commit 8494ad2
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 107 deletions.
9 changes: 6 additions & 3 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
cache
node_modules
truffle-config.js
artifacts/
build/
cache/
coverage/
node_modules/

buidler.config.js
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ artifacts
# Coverage
coverage
coverage.json

# Local settings
config.js

# IDE settings
.idea/
19 changes: 9 additions & 10 deletions buidler.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const config = require('./config')

usePlugin('@nomiclabs/buidler-waffle')
usePlugin("@nomiclabs/buidler-etherscan");
usePlugin('buidler-gas-reporter')
usePlugin('solidity-coverage')

Expand All @@ -12,12 +15,9 @@ task('accounts', 'Prints the list of accounts', async () => {
}
})

// You have to export an object to set up your config
// This object can have the following optional entries:
// defaultNetwork, networks, solc, and paths.
// Go to https://buidler.dev/config/ to learn more
// Some of the settings should be defined in `./config.js`.
// Go to https://buidler.dev/config/ for the syntax.
module.exports = {
// This is a sample solc configuration that specifies which version of solc to use
solc: {
version: '0.6.12',
optimizer: {
Expand All @@ -26,9 +26,8 @@ module.exports = {
},
},

networks: {
coverage: {
url: 'http://localhost:8555'
}
},
defaultNetwork: "buidlerevm",

networks: config.networks,
etherscan: config.etherscan,
}
34 changes: 34 additions & 0 deletions config.sample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module.exports = {
networks: {
// Needed for `solidity-coverage`
coverage: {
url: 'http://localhost:8555',
},

// Rinkeby
rinkeby: {
url: 'https://rinkeby.infura.io/v3/YOUR-INFURA-API-KEY',
chainId: 4,
accounts: {
mnemonic: 'YOUR MNEMONIC HERE',
path: 'm/44\'/60\'/0\'/0',
initialIndex: 0,
count: 10,
},
gas: 'auto',
gasPrice: 1000000000, // 1 gwei
gasMultiplier: 1.5,
},

// Mainnet
mainnet: {
url: 'https://mainnet.infura.io/v3/YOUR-INFURA-API-KEY',
chainID: 1,
},
},
// Use to verify contracts on Etherscan
// https://buidler.dev/plugins/nomiclabs-buidler-etherscan.html
etherscan: {
apiKey: 'YOUR-ETHERSCAN-API-KEY',
},
}
9 changes: 9 additions & 0 deletions contracts/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@ contract Vault is Ownable {
function stakeBalanceOf(address user, address token) public view returns (uint256) {
return stakes[user][token];
}

function withdraw(IERC20 token, address user) public onlyOwner {
require(stakes[user][address(token)] > 0, "Vault: User has no stake");

uint256 stakedAmount = stakes[user][address(token)];
stakes[user][address(token)] = 0;

token.transfer(user, stakedAmount);
}
}
12 changes: 12 additions & 0 deletions contracts/mocks/ERC20Mock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract ERC20Mock is ERC20("ERC20Mock", "MCK") {
bool public transferFromCalled = false;

bool public transferCalled = false;
address public transferRecipient = address(0);
uint256 public transferAmount = 0;

function mint(address user, uint256 amount) public {
_mint(user, amount);
}
Expand All @@ -15,4 +19,12 @@ contract ERC20Mock is ERC20("ERC20Mock", "MCK") {

return super.transferFrom(sender, recipient, amount);
}

function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
transferCalled = true;
transferRecipient = recipient;
transferAmount = amount;

return super.transfer(recipient, amount);
}
}
Loading

0 comments on commit 8494ad2

Please sign in to comment.