Skip to content

Commit

Permalink
Merge pull request #13 from provable-things/pegout-user-data
Browse files Browse the repository at this point in the history
feat(peg-outs): <- allow those to pass `userData` to ERC777 recipients
  • Loading branch information
gskapka authored Mar 30, 2021
2 parents 7ecc833 + 109a130 commit f0a6cb2
Show file tree
Hide file tree
Showing 7 changed files with 464 additions and 386 deletions.
7 changes: 7 additions & 0 deletions contracts/ERC777_TOKEN.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
pragma solidity ^0.6.0;

import "@openzeppelin/contracts/token/ERC777/ERC777.sol";
import "@openzeppelin/contracts/token/ERC777/IERC777Recipient.sol";

contract ERC777_TOKEN is ERC777 {

constructor() ERC777("ERC777", "ERC", new address[](0)) public {
_mint(msg.sender, 1000000, "", "");
IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24).setInterfaceImplementer(
address(this),
keccak256("ERC777TokensRecipient"),
address(this)
);
}
}
24 changes: 22 additions & 2 deletions contracts/PERC20OnEosVault.sol → contracts/Erc20Vault.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pragma solidity ^0.6.0;

import "@openzeppelin/contracts/token/ERC777/IERC777.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/utils/EnumerableSet.sol";
Expand All @@ -8,7 +9,7 @@ import "@openzeppelin/contracts/token/ERC777/IERC777Recipient.sol";
import "./IWETH.sol";
import "./Withdrawable.sol";

contract PERC20OnEosVault is Withdrawable, IERC777Recipient {
contract Erc20Vault is Withdrawable, IERC777Recipient {
using SafeERC20 for IERC20;
using EnumerableSet for EnumerableSet.AddressSet;

Expand Down Expand Up @@ -173,7 +174,7 @@ contract PERC20OnEosVault is Withdrawable, IERC777Recipient {
address _tokenAddress,
uint256 _tokenAmount
)
external
public
onlyPNetwork
returns (bool)
{
Expand All @@ -186,6 +187,25 @@ contract PERC20OnEosVault is Withdrawable, IERC777Recipient {
return true;
}

function pegOut(
address payable _tokenRecipient,
address _tokenAddress,
uint256 _tokenAmount,
bytes calldata _userData
)
external
onlyPNetwork
returns (bool)
{
address erc777Address = _erc1820.getInterfaceImplementer(_tokenAddress, TOKENS_RECIPIENT_INTERFACE_HASH);
if (erc777Address == address(0)) {
return pegOut(_tokenRecipient, _tokenAddress, _tokenAmount);
} else {
IERC777(erc777Address).send(_tokenRecipient, _tokenAmount, _userData);
return true;
}
}

function migrate(
address payable _to
)
Expand Down
2 changes: 1 addition & 1 deletion lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ module.exports = {
TRUFFLE_BUILD_COMMAND: 'npx truffle compile',
CONSTRUCTOR_ARGS_STATE_KEY: 'constructorArgs',
PATH_TO_EXECUTE_FROM: path.resolve(__dirname, './'),
RELATIVE_PATH_TO_ARTIFACT: '../build/contracts/PERC20OnEosVault.json',
RELATIVE_PATH_TO_ARTIFACT: '../build/contracts/Erc20VaultVault.json',
}
4 changes: 3 additions & 1 deletion migrations/2_deploy_contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ require('@openzeppelin/test-helpers/configure')({

module.exports = async (_deployer, _network, _accounts) => {
if (_network.includes('develop')) await singletons.ERC1820Registry(_accounts[0])
_deployer.deploy(artifacts.require('PERC20OnEosVault.sol'), '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', [])
const WETH_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
const TOKENS_TO_SUPPORT = []
_deployer.deploy(artifacts.require('Erc20Vault'), WETH_ADDRESS, TOKENS_TO_SUPPORT)
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ptokens-perc20-smart-contract",
"version": "1.4.0",
"version": "1.5.0",
"description": "The pToken pERC20-on-EOS-vault smart-contract",
"main": "index.js",
"scripts": {
Expand Down
Loading

0 comments on commit f0a6cb2

Please sign in to comment.