Skip to content

Instantly share code, notes, and snippets.

@krebernisak
Last active September 22, 2020 07:34
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 krebernisak/c55b8267b0721b55f5100cd3f7a0be5f to your computer and use it in GitHub Desktop.
Save krebernisak/c55b8267b0721b55f5100cd3f7a0be5f to your computer and use it in GitHub Desktop.
pragma solidity ^0.6.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.2.0/contracts/token/ERC20/IERC20.sol";
contract LinkTokenOnMatic {
IERC20 public token;
// child chain manager
address public depositor;
address public deployer;
// This is the address of deployed & unchanged v4 LinkToken
constructor(address _token) public {
token = IERC20(_token);
require(token.totalSupply() == token.balanceOf(address(this)), "I need to have it all.");
// child chain manager proxy
depositor = 0xb5505a6d998549090530911180f38aC5130101c6;
deployer = msg.sender;
}
function updateDepositor(address newDespositor) external {
require(msg.sender == deployer, "You can't update me");
depositor = newDespositor;
}
// additional methods needed for enabling cross chain asset transfer
function deposit(address user, bytes calldata depositData) external {
require(msg.sender == depositor, "Only ChildChainManager can deposit");
require(user != address(0), "Not a valid address");
uint256 amount = abi.decode(depositData, (uint256));
token.transfer(user, amount);
}
function withdraw(uint256 amount) external {
token.transferFrom(msg.sender, address(this), amount);
}
}
@itzmeanjan
Copy link

Yes we can do this 👍

Are you also emitting Transfer event from withdraw ?

I think Openzeppelin has it. Still just to confirm.

@krebernisak
Copy link
Author

krebernisak commented Sep 11, 2020

Yes, the Transfer event is emitted, but from the LinkToken not LinkTokenOnMatic (this) contract.

Also, the Transfer will not be from 0x0 but from the address of LinkTokenOnMatic holding contract.

One more thing, the withdraw function will need to be a 2-step in this case. The transferFrom will first need to be approved by the token holder.

@itzmeanjan
Copy link

Well not associating address 0x0, in events will cause issue, and it'll not get included in checkpoint. That's the idea while check pointing. Can you fix that ?

@krebernisak
Copy link
Author

@itzmeanjan consider this proposal and discussion deprecated. I am working on a new implementation that will hopefully be ready for a test run in a day or two.

You can take a peek here.

@itzmeanjan
Copy link

Alright 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment