init vault app
This commit is contained in:
		
							parent
							
								
									22021f2d46
								
							
						
					
					
						commit
						0320fa59f6
					
				@ -1,31 +1 @@
 | 
			
		||||
# Aragon Bare Boilerplate
 | 
			
		||||
 | 
			
		||||
> 🕵️ [Find more boilerplates using GitHub](https://github.com/search?q=topic:aragon-boilerplate) | 
 | 
			
		||||
> ✨ [Official boilerplates](https://github.com/search?q=topic:aragon-boilerplate+org:aragon)
 | 
			
		||||
 | 
			
		||||
Bare boilerplate for Aragon applications.
 | 
			
		||||
 | 
			
		||||
This boilerplate *only* includes the contract interfaces and `@aragon/client`, along with the two required application manifests: `manifest.json` and `arapp.json`.
 | 
			
		||||
 | 
			
		||||
This boilerplate is ideal for building applications that do not use React
 | 
			
		||||
 | 
			
		||||
## Usage
 | 
			
		||||
 | 
			
		||||
```sh
 | 
			
		||||
aragon init foo.aragonpm.test bare
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## What's in the box?
 | 
			
		||||
 | 
			
		||||
### npm Scripts
 | 
			
		||||
 | 
			
		||||
- **test**: Runs your Truffle tests
 | 
			
		||||
- **build**: Compiles your contracts
 | 
			
		||||
- **start**: Runs your app locally
 | 
			
		||||
- **deploy**: Deploys your app smart contract to a local chain
 | 
			
		||||
- **publish**: Publishes a new version of your app
 | 
			
		||||
 | 
			
		||||
### Libraries
 | 
			
		||||
 | 
			
		||||
- [**@aragon/os**](https://github.com/aragon/aragonOS): Aragon interfaces
 | 
			
		||||
- [**@aragon/client**](https://github.com/aragon/aragon.js/tree/master/packages/aragon-client): Wrapper for Aragon application RPC
 | 
			
		||||
# Kredits Vault
 | 
			
		||||
 | 
			
		||||
@ -1,26 +0,0 @@
 | 
			
		||||
pragma solidity ^0.4.24;
 | 
			
		||||
 | 
			
		||||
import "@aragon/os/contracts/apps/AragonApp.sol";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
contract App is AragonApp {
 | 
			
		||||
    ////
 | 
			
		||||
    ////               ....
 | 
			
		||||
    ////           .,,,,..,,,,.
 | 
			
		||||
    ////       ..,,.. ..     .,,,..
 | 
			
		||||
    ////     .,,.  ..,:....,,..  .,,.
 | 
			
		||||
    ////    ,:   ...,.    .,,..,.   :,
 | 
			
		||||
    ////    .:. ,. ,           ,.. .:.
 | 
			
		||||
    ////     ,:,.  ..        .,,., :,
 | 
			
		||||
    ////      ,;.   ........,..,..:,
 | 
			
		||||
    ////       ,:.       .. .....:,
 | 
			
		||||
    ////        .:,           .::.
 | 
			
		||||
    ////          .,,.      .,,.
 | 
			
		||||
    ////            .,,,..,,,.
 | 
			
		||||
    ////               ....
 | 
			
		||||
    ////
 | 
			
		||||
    ////  Build something beautiful.
 | 
			
		||||
    function initialize() public onlyInit {
 | 
			
		||||
        initialized();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										74
									
								
								apps/vault/contracts/Vault.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								apps/vault/contracts/Vault.sol
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,74 @@
 | 
			
		||||
pragma solidity ^0.4.24;
 | 
			
		||||
 | 
			
		||||
import "@aragon/os/contracts/apps/AragonApp.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";
 | 
			
		||||
 | 
			
		||||
contract Vault is EtherTokenConstant, AragonApp, DepositableStorage {
 | 
			
		||||
    using SafeERC20 for ERC20;
 | 
			
		||||
 | 
			
		||||
    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";
 | 
			
		||||
 | 
			
		||||
    event VaultDeposit(address indexed token, address indexed sender, 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() external onlyInit {
 | 
			
		||||
        initialized();
 | 
			
		||||
        setDepositable(true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
    * @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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										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
											
										
									
								
							@ -11,13 +11,16 @@
 | 
			
		||||
    "parcel-bundler": "^1.11.0"
 | 
			
		||||
  },
 | 
			
		||||
  "scripts": {
 | 
			
		||||
    "start": "aragon run",
 | 
			
		||||
    "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",
 | 
			
		||||
    "deploy": "aragon deploy",
 | 
			
		||||
    "build:app": "parcel build app/index.html -d dist/ --public-url \".\" --no-cache",
 | 
			
		||||
    "build:script": "parcel build app/script.js -d dist/ --no-cache",
 | 
			
		||||
    "build": "npm run build:app && npm run build:script",
 | 
			
		||||
    "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",
 | 
			
		||||
 | 
			
		||||
@ -1,63 +1 @@
 | 
			
		||||
/**
 | 
			
		||||
 * https://github.com/aragon/aragonOS/blob/v4.0.0/truffle-config.js
 | 
			
		||||
 */
 | 
			
		||||
const homedir = require('homedir')
 | 
			
		||||
const path = require('path')
 | 
			
		||||
 | 
			
		||||
const HDWalletProvider = require('truffle-hdwallet-provider')
 | 
			
		||||
const HDWalletProviderPrivkey = require('truffle-hdwallet-provider-privkey')
 | 
			
		||||
 | 
			
		||||
const DEFAULT_MNEMONIC = 'explain tackle mirror kit van hammer degree position ginger unfair soup bonus'
 | 
			
		||||
 | 
			
		||||
const defaultRPC = (network) =>
 | 
			
		||||
  `https://${network}.infura.io`
 | 
			
		||||
 | 
			
		||||
const configFilePath = (filename) =>
 | 
			
		||||
  path.join(homedir(), `.aragon/${filename}`)
 | 
			
		||||
 | 
			
		||||
const mnemonic = () => {
 | 
			
		||||
  try {
 | 
			
		||||
    return require(configFilePath('mnemonic.json')).mnemonic
 | 
			
		||||
  } catch (e) {
 | 
			
		||||
    return DEFAULT_MNEMONIC
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const settingsForNetwork = (network) => {
 | 
			
		||||
  try {
 | 
			
		||||
    return require(configFilePath(`${network}_key.json`))
 | 
			
		||||
  } catch (e) {
 | 
			
		||||
    return { }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Lazily loaded provider
 | 
			
		||||
const providerForNetwork = (network) => (
 | 
			
		||||
  () => {
 | 
			
		||||
    let { rpc, keys } = settingsForNetwork(network)
 | 
			
		||||
    rpc = rpc || defaultRPC(network)
 | 
			
		||||
 | 
			
		||||
    if (!keys || keys.length == 0) {
 | 
			
		||||
      return new HDWalletProvider(mnemonic(), rpc)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return new HDWalletProviderPrivkey(keys, rpc)
 | 
			
		||||
  }
 | 
			
		||||
)
 | 
			
		||||
module.exports = {
 | 
			
		||||
  networks: {
 | 
			
		||||
    development: {
 | 
			
		||||
      host: 'localhost',
 | 
			
		||||
      port: 8545,
 | 
			
		||||
      network_id: '*'
 | 
			
		||||
    },
 | 
			
		||||
    mainnet: {
 | 
			
		||||
      network_id: 1,
 | 
			
		||||
      provider: providerForNetwork('mainnet')
 | 
			
		||||
    },
 | 
			
		||||
    rinkeby: {
 | 
			
		||||
      network_id: 4,
 | 
			
		||||
      provider: providerForNetwork('rinkeby')
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
module.exports = require("../../truffle.js");
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user