Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding transferShieldBalance #649

Merged
merged 1 commit into from
May 13, 2022
Merged

Conversation

ChaitanyaKonda
Copy link
Contributor

This PR provides the deployer of the contract the capability to transfer the balance of the shield contract to their address as requested by Polygon. This is meant to be only used in the event of an attack during which this could be used to save funds in shield contract. This will later be moved into the control of a DAO or be removed after sufficient testing on mainnet and security audit.

Only the address (called owner address here) that deploys the Shield contract can transfer the funds to itself by calling transferShieldBalance(address ercAddress, uint256 value). If the value is 0, then the entire balance for that token will be transferred.

Test:

  • Copy the below specified code in nightfall-deployer/migrations/3_test_tokens_migration.js at Line 36
  • Then run ./start-nightfall -g -d -s
  • In the deployer's console logs during the start up script, you will see the following tests running successfully
  • transferShieldBalance successfully transferring entire balance to Shield contract owner's address
  • transferShieldBalance successfully transferring specific balance to Shield contract owner's address
  • transferShieldBalance failing when called by a non owner address

Test Output:
Screenshot 2022-05-10 at 14 09 32

Test code:

    console.log(“\nBalance of owner address at the beginning”, (await ERC20deployed.balanceOf(accounts[0])).toNumber());
    console.log(“Balance of shield contract at the beginning”, (await ERC20deployed.balanceOf(restrictions.address)).toNumber());
    await ERC20deployed.transfer(restrictions.address, 6000000000000);
    console.log(“\nBalance of owner address after transfer to shield address”, (await ERC20deployed.balanceOf(accounts[0])).toNumber());
    console.log(“Balance of shield contract after receipt from owner”, (await ERC20deployed.balanceOf(restrictions.address)).toNumber());
    await restrictions.transferShieldBalance(ERC20deployed.address, 0);
    console.log(“\nBalance of owner after calling transferShieldBalance”, (await ERC20deployed.balanceOf(accounts[0])).toNumber());
    console.log(“Balance of shield contract after calling transferShieldBalance”, (await ERC20deployed.balanceOf(restrictions.address)).toNumber());
    await ERC20deployed.transfer(restrictions.address, 3000000000000);
    console.log(“\nBalance of owner address after transfer to shield address again”, (await ERC20deployed.balanceOf(accounts[0])).toNumber());
    console.log(“Balance of non owner address after transfer to shield address again”, (await ERC20deployed.balanceOf(accounts[1])).toNumber())
    console.log(“Balance of shield contract after receipt from owner again”, (await ERC20deployed.balanceOf(restrictions.address)).toNumber());
    restrictions.transferShieldBalance(ERC20deployed.address, 0, {from: accounts[1]}).then(receipt => console.log(receipt)).catch(err => {
      console.log(“\nWhen a non owner calls transferShieldBalance:“)
      console.log(err.message);
    })
    console.log(“\nBalance of owner address after wrong transferShieldBalance”, (await ERC20deployed.balanceOf(accounts[0])).toNumber());
    console.log(“Balance of non owner address after wrong transferShieldBalance”, (await ERC20deployed.balanceOf(accounts[1])).toNumber());
    console.log(“Balance of shield contract after wrong transferShieldBalance”, (await ERC20deployed.balanceOf(restrictions.address)).toNumber());
    await restrictions.transferShieldBalance(ERC20deployed.address, 50000000000);
    console.log(“\nBalance of owner address after transferShieldBalance of specific value 50", (await ERC20deployed.balanceOf(accounts[0])).toNumber());
    console.log(“Balance of shield contract after transferShieldBalance of specific value 50”, (await ERC20deployed.balanceOf(restrictions.address)).toNumber());

@druiz0992 druiz0992 removed the DNM Do not merge label May 12, 2022
@Westlad Westlad merged commit 6427a4a into master May 13, 2022
@Westlad Westlad deleted the chait/balanceOwnership branch May 13, 2022 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants