-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
1,466 additions
and
2,358 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ build | |
node_modules | ||
coverage | ||
coverage.json | ||
artifacts |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
* | ||
* This code has not been reviewed. | ||
* Do not use or deploy this code before reviewing it personally first. | ||
*/ | ||
pragma solidity 0.5.3; | ||
|
||
import { ERC1820Client } from "erc1820/contracts/ERC1820Client.sol"; | ||
import { ERC777TokensSender } from "../ERC777TokensSender.sol"; | ||
import { ERC777TokensRecipient } from "../ERC777TokensRecipient.sol"; | ||
import { ERC777Token } from "../ERC777Token.sol"; | ||
|
||
|
||
contract ContractAccount is ERC1820Client, ERC777TokensSender, ERC777TokensRecipient { | ||
bool private allowTokensToSend; | ||
bool private allowTokensReceived; | ||
|
||
event NotifiedTokensToSend( | ||
address token, | ||
address operator, | ||
address from, | ||
address to, | ||
uint256 amount, | ||
uint256 balanceFrom, | ||
uint256 balanceTo, | ||
bytes data, | ||
bytes operatorData | ||
); | ||
|
||
event NotifiedTokensReceived( | ||
address token, | ||
address operator, | ||
address from, | ||
address to, | ||
uint256 amount, | ||
uint256 balanceFrom, | ||
uint256 balanceTo, | ||
bytes data, | ||
bytes operatorData | ||
); | ||
|
||
constructor(bool _allowTokensToSend, bool _allowTokensReceived) public { | ||
setInterfaceImplementation("ERC777TokensSender", address(this)); | ||
setInterfaceImplementation("ERC777TokensRecipient", address(this)); | ||
allowTokensToSend = _allowTokensToSend; | ||
allowTokensReceived = _allowTokensReceived; | ||
} | ||
|
||
function tokensToSend( | ||
address _operator, | ||
address _from, | ||
address _to, | ||
uint256 _amount, | ||
bytes calldata _data, | ||
bytes calldata _operatorData | ||
) | ||
external | ||
{ | ||
require(allowTokensToSend, "Send not allowed"); | ||
emit NotifiedTokensToSend( | ||
msg.sender, | ||
_operator, | ||
_from, | ||
_to, | ||
_amount, | ||
ERC777Token(msg.sender).balanceOf(_from), | ||
ERC777Token(msg.sender).balanceOf(_to), | ||
_data, | ||
_operatorData | ||
); | ||
} | ||
|
||
function tokensReceived( | ||
address _operator, | ||
address _from, | ||
address _to, | ||
uint256 _amount, | ||
bytes calldata _data, | ||
bytes calldata _operatorData | ||
) | ||
external | ||
{ | ||
require(allowTokensReceived, "Send not allowed"); | ||
emit NotifiedTokensReceived( | ||
msg.sender, | ||
_operator, | ||
_from, | ||
_to, | ||
_amount, | ||
ERC777Token(msg.sender).balanceOf(_from), | ||
ERC777Token(msg.sender).balanceOf(_to), | ||
_data, | ||
_operatorData | ||
); | ||
} | ||
|
||
function send(address token, address to, uint256 amount, bytes calldata data) external { | ||
ERC777Token(token).send(to, amount, data); | ||
} | ||
|
||
function burn(address token, uint256 amount, bytes calldata data) external { | ||
ERC777Token(token).operatorBurn(address(this), amount, data, ""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const path = require('path'); | ||
const DEFAULT_ARTIFACTS_PATH = path.resolve(__dirname, '../artifacts/combined.json'); | ||
|
||
module.exports = function loadArtifacts(jsonPath = DEFAULT_ARTIFACTS_PATH) { | ||
const solcJson = require(jsonPath); | ||
const artifacts = Object.assign({}, solcJson, {contracts: {}}); | ||
|
||
Object.keys(solcJson.contracts).forEach(contractPath => { | ||
let path = (contractPath.startsWith('./') ? contractPath.slice(2) : contractPath) | ||
.replace('.sol:', '.').replace(/\//g, '.').split('.'); | ||
let contractName = path.pop(); | ||
|
||
let last = path.reduce((obj, key) => obj[key] = obj[key] || {}, artifacts); | ||
last[contractName] = Object.assign({}, solcJson.contracts[contractPath]); | ||
last[contractName].abi = JSON.parse(last[contractName].abi); | ||
|
||
last[contractName].deploy = async (web3, options = {}) => { | ||
if (!last[contractName].bin || last[contractName].bin === '0x') { | ||
throw new Error(`Missing bytecode for ${contractPath}`); | ||
} | ||
if (!last[contractName].abi) { | ||
throw new Error(`Missing abi for ${contractPath}`); | ||
} | ||
if (!options.from) { | ||
options.from = (await web3.eth.getAccounts())[0]; | ||
} | ||
|
||
let contract = new web3.eth.Contract(last[contractName].abi, null, { from: options.from }); | ||
const gas = await contract.deploy({ data: last[contractName].bin, arguments: options.arguments }) | ||
.estimateGas({ from: options.from }); | ||
if (!options.gas) { | ||
options.gas = gas; | ||
} else if (options.gas < gas) { | ||
console.warn(`Specified gas amount ${options.gas} is lower than the estimated ${gas}.`); | ||
} | ||
return await contract.deploy({ arguments: options.arguments, data: last[contractName].bin }) | ||
.send({ from: options.from, gas: options.gas, gasLimit: options.gasLimit }); | ||
}; | ||
|
||
last[contractName] | ||
.instance = (web3, address, options = {}) => new web3.eth.Contract(last[contractName].abi, address, options); | ||
}); | ||
|
||
return artifacts | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.