Vault app #172
7
apps/vault/.gitignore
vendored
Normal file
7
apps/vault/.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
# Dependencies
|
||||
node_modules
|
||||
|
||||
# Build dirs
|
||||
.cache/
|
||||
build/
|
||||
dist/
|
0
apps/vault/.ipfsignore
Normal file
0
apps/vault/.ipfsignore
Normal file
1
apps/vault/README.md
Normal file
1
apps/vault/README.md
Normal file
@ -0,0 +1 @@
|
||||
# Kredits Vault
|
28
apps/vault/arapp.json
Normal file
28
apps/vault/arapp.json
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"roles": [
|
||||
{
|
||||
"name": "Dummy role",
|
||||
"id": "DUMMY_ROLE",
|
||||
"params": []
|
||||
}
|
||||
],
|
||||
"environments": {
|
||||
"default": {
|
||||
"network": "development",
|
||||
"appName": "kredits-vault.open.aragonpm.eth"
|
||||
},
|
||||
"rinkeby": {
|
||||
"registry": "0x98df287b6c145399aaa709692c8d308357bc085d",
|
||||
"appName": "kredits-vault.open.aragonpm.eth",
|
||||
"wsRPC": "wss://rinkeby.eth.aragon.network/ws",
|
||||
"network": "rinkeby"
|
||||
},
|
||||
"mainnet": {
|
||||
"registry": "0x314159265dd8dbb310642f98f50c066173c1259b",
|
||||
"appName": "kredits-vault.open.aragonpm.eth",
|
||||
"wsRPC": "wss://mainnet.eth.aragon.network/ws",
|
||||
"network": "mainnet"
|
||||
}
|
||||
},
|
||||
"path": "contracts/App.sol"
|
||||
}
|
158
apps/vault/contracts/Vault.sol
Normal file
158
apps/vault/contracts/Vault.sol
Normal file
@ -0,0 +1,158 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "@aragon/os/contracts/apps/AragonApp.sol";
|
||||
import "@aragon/os/contracts/kernel/IKernel.sol";
|
||||
import "@aragon/os/contracts/common/DepositableStorage.sol";
|
||||
import "@aragon/os/contracts/common/EtherTokenConstant.sol";
|
||||
import "@aragon/os/contracts/common/SafeERC20.sol";
|
||||
import "@aragon/os/contracts/lib/token/ERC20.sol";
|
||||
|
||||
interface IContributor {
|
||||
function getContributorAddressById(uint32 id) view public returns (address);
|
||||
function contributorsCount() view public returns (uint32);
|
||||
}
|
||||
|
||||
interface IToken {
|
||||
function balanceOf(address owner) public view returns (uint256);
|
||||
function totalSupply() public view returns (uint256);
|
||||
}
|
||||
|
||||
contract Vault is EtherTokenConstant, AragonApp, DepositableStorage {
|
||||
using SafeERC20 for ERC20;
|
||||
|
||||
bytes32 public constant TRANSFER_ROLE = keccak256("TRANSFER_ROLE");
|
||||
|
||||
string private constant ERROR_NOT_DEPOSITABLE = "VAULT_NOT_DEPOSITABLE";
|
||||
string private constant ERROR_DEPOSIT_VALUE_ZERO = "VAULT_DEPOSIT_VALUE_ZERO";
|
||||
string private constant ERROR_VALUE_MISMATCH = "VAULT_VALUE_MISMATCH";
|
||||
string private constant ERROR_TOKEN_TRANSFER_FROM_REVERTED = "VAULT_TOKEN_TRANSFER_FROM_REVERT";
|
||||
string private constant ERROR_TRANSFER_VALUE_ZERO = "VAULT_TRANSFER_VALUE_ZERO";
|
||||
string private constant ERROR_SEND_REVERTED = "VAULT_SEND_REVERTED";
|
||||
string private constant ERROR_TOKEN_TRANSFER_REVERTED = "VAULT_TOKEN_TRANSFER_REVERTED";
|
||||
|
||||
uint256 private _snapshotTotalSupply;
|
||||
|
||||
mapping (address => uint256) private _snapshotBalances;
|
||||
|
||||
// ensure alphabetic order
|
||||
enum Apps { Contribution, Contributor, Proposal, Token }
|
||||
bytes32[4] public appIds;
|
||||
|
||||
event VaultDeposit(address indexed token, address indexed sender, uint256 amount);
|
||||
event VaultTransfer(address indexed token, address indexed to, uint256 amount);
|
||||
|
||||
function () external payable isInitialized {
|
||||
_deposit(ETH, msg.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Initialize Vault app
|
||||
* @dev As an AragonApp it needs to be initialized in order for roles (`auth` and `authP`) to work
|
||||
*/
|
||||
function initialize(bytes32[4] _appIds) external onlyInit {
|
||||
initialized();
|
||||
|
||||
appIds = _appIds;
|
||||
setDepositable(true);
|
||||
}
|
||||
|
||||
function getContract(uint8 appId) public view returns (address) {
|
||||
IKernel k = IKernel(kernel());
|
||||
return k.getApp(KERNEL_APP_ADDR_NAMESPACE, appIds[appId]);
|
||||
}
|
||||
|
||||
function getContributorAddressById(uint32 contributorId) public view returns (address) {
|
||||
address contributor = getContract(uint8(Apps.Contributor));
|
||||
return IContributor(contributor).getContributorAddressById(contributorId);
|
||||
}
|
||||
|
||||
function getContributorsAddresses() internal view returns (address[]) {
|
||||
address contributor = getContract(uint8(Apps.Contributor));
|
||||
uint32 contributorsCount = IContributor(contributor).contributorsCount();
|
||||
|
||||
address[] memory contributorsAddresses = new address[](contributorsCount);
|
||||
|
||||
for(uint32 i = 1; i <= contributorsCount; i++) {
|
||||
address contributorAddress = IContributor(contributor).getContributorAddressById(i);
|
||||
contributorsAddresses[i-1] = contributorAddress;
|
||||
}
|
||||
|
||||
return contributorsAddresses;
|
||||
}
|
||||
|
||||
function balanceOf(address owner) public view returns (uint256) {
|
||||
address token = getContract(uint8(Apps.Token));
|
||||
return IToken(token).balanceOf(owner);
|
||||
}
|
||||
|
||||
function totalSupply() public view returns (uint256) {
|
||||
address token = getContract(uint8(Apps.Token));
|
||||
return IToken(token).totalSupply();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Deposit `_value` `_token` to the vault
|
||||
* @param _token Address of the token being transferred
|
||||
* @param _value Amount of tokens being transferred
|
||||
*/
|
||||
function deposit(address _token, uint256 _value) external payable isInitialized {
|
||||
_deposit(_token, _value);
|
||||
}
|
||||
|
||||
function balance(address _token) public view returns (uint256) {
|
||||
if (_token == ETH) {
|
||||
return address(this).balance;
|
||||
} else {
|
||||
return ERC20(_token).staticBalanceOf(address(this));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Disable recovery escape hatch, as it could be used
|
||||
* maliciously to transfer funds away from the vault
|
||||
*/
|
||||
function allowRecoverability(address) public view returns (bool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function _deposit(address _token, uint256 _value) internal {
|
||||
require(isDepositable(), ERROR_NOT_DEPOSITABLE);
|
||||
require(_value > 0, ERROR_DEPOSIT_VALUE_ZERO);
|
||||
|
||||
if (_token == ETH) {
|
||||
// Deposit is implicit in this case
|
||||
require(msg.value == _value, ERROR_VALUE_MISMATCH);
|
||||
} else {
|
||||
require(
|
||||
ERC20(_token).safeTransferFrom(msg.sender, address(this), _value),
|
||||
ERROR_TOKEN_TRANSFER_FROM_REVERTED
|
||||
);
|
||||
}
|
||||
|
||||
emit VaultDeposit(_token, msg.sender, _value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Transfer `_value` `_token` from the Vault to `_to`
|
||||
* @param _token Address of the token being transferred
|
||||
* @param _to Address of the recipient of tokens
|
||||
* @param _value Amount of tokens being transferred
|
||||
*/
|
||||
/* solium-disable-next-line function-order */
|
||||
function transfer(address _token, address _to, uint256 _value)
|
||||
external
|
||||
authP(TRANSFER_ROLE, arr(_token, _to, _value))
|
||||
{
|
||||
require(_value > 0, ERROR_TRANSFER_VALUE_ZERO);
|
||||
|
||||
if (_token == ETH) {
|
||||
require(_to.send(_value), ERROR_SEND_REVERTED);
|
||||
} else {
|
||||
require(ERC20(_token).safeTransfer(_to, _value), ERROR_TOKEN_TRANSFER_REVERTED);
|
||||
}
|
||||
|
||||
emit VaultTransfer(_token, _to, _value);
|
||||
}
|
||||
|
||||
|
||||
}
|
23
apps/vault/contracts/misc/Migrations.sol
Normal file
23
apps/vault/contracts/misc/Migrations.sol
Normal file
@ -0,0 +1,23 @@
|
||||
pragma solidity ^0.4.4;
|
||||
|
||||
contract Migrations {
|
||||
address public owner;
|
||||
uint public last_completed_migration;
|
||||
|
||||
modifier restricted() {
|
||||
if (msg.sender == owner) _;
|
||||
}
|
||||
|
||||
function Migrations() {
|
||||
owner = msg.sender;
|
||||
}
|
||||
|
||||
function setCompleted(uint completed) restricted {
|
||||
last_completed_migration = completed;
|
||||
}
|
||||
|
||||
function upgrade(address new_address) restricted {
|
||||
Migrations upgraded = Migrations(new_address);
|
||||
upgraded.setCompleted(last_completed_migration);
|
||||
}
|
||||
}
|
10
apps/vault/manifest.json
Normal file
10
apps/vault/manifest.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "Application",
|
||||
"description": "An application for Aragon",
|
||||
"icons": [{
|
||||
"src": "/dist/images/icon.png",
|
||||
"sizes": "192x192"
|
||||
}],
|
||||
"start_url": "/dist/index.html",
|
||||
"script": "/dist/script.js"
|
||||
}
|
5
apps/vault/migrations/1_initial_migration.js
Normal file
5
apps/vault/migrations/1_initial_migration.js
Normal file
@ -0,0 +1,5 @@
|
||||
var Migrations = artifacts.require('./Migrations.sol')
|
||||
|
||||
module.exports = function (deployer) {
|
||||
deployer.deploy(Migrations)
|
||||
}
|
5
apps/vault/migrations/2_deploy_contracts.js
Normal file
5
apps/vault/migrations/2_deploy_contracts.js
Normal file
@ -0,0 +1,5 @@
|
||||
var App = artifacts.require('./App.sol')
|
||||
|
||||
module.exports = function (deployer) {
|
||||
deployer.deploy(App)
|
||||
}
|
9364
apps/vault/package-lock.json
generated
Normal file
9364
apps/vault/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
30
apps/vault/package.json
Normal file
30
apps/vault/package.json
Normal file
@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "kredits-vault",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"dependencies": {
|
||||
"@aragon/client": "^1.1.0",
|
||||
"@aragon/os": "^4.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@aragon/cli": "^5.4.0",
|
||||
"parcel-bundler": "^1.11.0"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "npm run start:aragon:ipfs",
|
||||
"start:aragon:ipfs": "aragon run",
|
||||
"start:aragon:http": "aragon run --http localhost:8001 --http-served-from ./dist",
|
||||
"start:app": "",
|
||||
"test": "aragon contracts test",
|
||||
"compile": "aragon contracts compile",
|
||||
"sync-assets": "",
|
||||
"build:app": "",
|
||||
"build:script": "",
|
||||
"build": "",
|
||||
"publish:patch": "aragon apm publish patch",
|
||||
"publish:minor": "aragon apm publish minor",
|
||||
"publish:major": "aragon apm publish major",
|
||||
"versions": "aragon apm versions"
|
||||
},
|
||||
"keywords": []
|
||||
}
|
1
apps/vault/truffle.js
Normal file
1
apps/vault/truffle.js
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require("../../truffle.js");
|
Loading…
x
Reference in New Issue
Block a user