Skip to content

Instantly share code, notes, and snippets.

@0xAshish
Last active January 22, 2019 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xAshish/3cb784c09776163ab8900be5a1feaf6f to your computer and use it in GitHub Desktop.
Save 0xAshish/3cb784c09776163ab8900be5a1feaf6f to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.24;
//interface for parent contract of any child token
/*
parent contract interface for adding custom logic
before making transaction in erc721/erc20 child chain contract
transfer, transferFrom executes beforeTransfer of this interface contract
it must follow this interface and return a boolean and in case of ERC20 contracts
it should not have require statement and instead return false
IParentToken contract address in childchain contract can be updated by owner of contract only
while mapping new token in rootchain and child chain must add owner of parent contract
*/
interface IParentToken {
function beforeTransfer(address sender, address to, uint256 value) public returns(bool);
}
//
// sameple contract parentContract can contain any logic, it must implement beforeTransfer function
//
/*
pragma solidity ^0.4.24;
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "./IParentToken.sol";
// demo token parent contract
contract ParentTokenMock is IParentToken, Ownable {
mapping (address => bool) isAllowed;
function beforeTransfer(address sender, address to, uint256 value) public returns(bool) {
return isAllowed[sender];
}
function updatePermission(address user) public onlyOwner {
require(user != address(0x0));
isAllowed[user] = !isAllowed[user];
}
}*/
/*
steps to add token on matic chain
1) addtoken function in matic chain will take owner address,rootchain token address and metadata about rootToken
step one will give a chilToken contract on matic chain
2) for custom logic in transfer function you need to implement IParentToken interface's
beforeTransfer hook function (which is custom logic executed before each transfer)
3) owner from step 1 can add/update parent contract address(with beforeTransfer hook) in ChildToken contract from step 1
4) ownership can be transferd and parnet contract with before Transfer hook can be updated by owner
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment