diff --git a/contracts/Admin.sol b/contracts/Admin.sol new file mode 100644 index 00000000..25766245 --- /dev/null +++ b/contracts/Admin.sol @@ -0,0 +1,41 @@ +// The Licensed Work is (c) 2022 Sygma +// SPDX-License-Identifier: LGPL-3.0-only + +pragma solidity 0.8.11; + +import "@openzeppelin/contracts/access/Ownable.sol"; + +contract Admin is Ownable { + + event StartedFROSTKeygen(); + event StartedFROSTRefresh(string publicKey); + event TransferLiquidity(uint8 domainID, bytes32 resourceID, uint256 amount, bytes32 destinationAddress); + + /** + @notice Emits {StartedFROSTKeygen} event + */ + function startFROSTKeygen() public onlyOwner { + emit StartedFROSTKeygen(); + } + + /** + @notice Emits {StartedFROSTRefresh} event + @param publicKey hex encoded public key of the subset to be refreshed + */ + function startFROSTRefresh(string calldata publicKey) public onlyOwner { + emit StartedFROSTRefresh(publicKey); + } + + /** + @notice Emits {TransferLiqudity} event that is used on relayer to move liquidity with the MPC address. + @notice Primarily used when switching MPC addresses and liquidity needs to be moved to the new address + on networks without smart contracts. + @param domainID domain ID of the network where the transfer should happen + @param resourceID resourceID of the token to be moved + @param amount amount of tokens to be moved + @param destinationAddress destination address where the tokens should end up + */ + function transferLiquidity(uint8 domainID, bytes32 resourceID, uint256 amount, bytes32 destinationAddress) public onlyOwner { + emit TransferLiquidity(domainID, resourceID, amount, destinationAddress); + } +} \ No newline at end of file diff --git a/contracts/FROSTKeygen.sol b/contracts/FROSTKeygen.sol deleted file mode 100644 index 8243b95c..00000000 --- a/contracts/FROSTKeygen.sol +++ /dev/null @@ -1,33 +0,0 @@ -// The Licensed Work is (c) 2022 Sygma -// SPDX-License-Identifier: LGPL-3.0-only - -pragma solidity 0.8.11; - -import "@openzeppelin/contracts/access/Ownable.sol"; - -contract FROSTKeygen is Ownable { - - bool private keygenEnded = false; - - event StartedFROSTKeygen(); - event EndedFROSTKeygen(); - - /** - @notice Emits {StartedFROSTKeygen} event - */ - function startFROSTKeygen() public onlyOwner { - require (!keygenEnded, "FROST keygen ended"); - - emit StartedFROSTKeygen(); - } - - /** - @notice Blocks further calls for starting keygen. - */ - function endFROSTKeygen() public onlyOwner { - keygenEnded = true; - - emit EndedFROSTKeygen(); - } - -} \ No newline at end of file diff --git a/migrations/9_deploy_admin.js b/migrations/9_deploy_admin.js new file mode 100644 index 00000000..5145d60f --- /dev/null +++ b/migrations/9_deploy_admin.js @@ -0,0 +1,17 @@ +const parseArgs = require("minimist"); + +const Admin = artifacts.require("Admin"); + +module.exports = async function (deployer) { + + const deployAdminContract = parseArgs(process.argv.slice(2))["deploy-admin"]; + + if (deployAdminContract){ + await deployer.deploy(Admin); + const adminInstance = await Admin.deployed(); + + console.table({ + "Admin Address": adminInstance.address, + }); + } +} diff --git a/migrations/9_deploy_frostKeygen.js b/migrations/9_deploy_frostKeygen.js deleted file mode 100644 index 651069c4..00000000 --- a/migrations/9_deploy_frostKeygen.js +++ /dev/null @@ -1,17 +0,0 @@ -const parseArgs = require("minimist"); - -const FROSTKeygenContract = artifacts.require("FROSTKeygen"); - -module.exports = async function (deployer) { - - const deployFrostKeygen = parseArgs(process.argv.slice(2))["deploy-frost-keygen"]; - - if (deployFrostKeygen){ - await deployer.deploy(FROSTKeygenContract); - const frostKeygenInstance = await FROSTKeygenContract.deployed(); - - console.table({ - "FROSTKeygen Address": frostKeygenInstance.address, - }); - } -} diff --git a/test/admin/frost.js b/test/admin/frost.js new file mode 100644 index 00000000..1b6a3ebe --- /dev/null +++ b/test/admin/frost.js @@ -0,0 +1,42 @@ +// The Licensed Work is (c) 2022 Sygma +// SPDX-License-Identifier: LGPL-3.0-only + +const TruffleAssert = require("truffle-assertions"); +const Helpers = require("../helpers"); +const Admin = artifacts.require("Admin") + +contract("Admin - [Frost]", (accounts) => { + let AdminInstance; + + const publicKey = "publicKey" + + beforeEach(async () => { + AdminInstance = await Admin.new(accounts[0]); + }); + + it("should emit StartedFROSTKeygen event when startFROSTKeygen is called by the owner", async () => { + const tx = await AdminInstance.startFROSTKeygen({from: accounts[0]}) + + TruffleAssert.eventEmitted(tx, "StartedFROSTKeygen"); + }); + + it("should revert when startFROSTKeygen is not called by the owner", async () => { + await Helpers.reverts( + AdminInstance.startFROSTKeygen({from: accounts[1]}), + ) + }); + + it("should emit StartedFrostRefresh event when startFROSTRefresh is called by the owner", async () => { + const tx = await AdminInstance.startFROSTRefresh(publicKey, {from: accounts[0]}) + + TruffleAssert.eventEmitted(tx, "StartedFROSTRefresh", (event) => { + return event.publicKey == publicKey + }); + }); + + it("should revert when startFROSTREfresh is not called by the owner", async () => { + await Helpers.reverts( + AdminInstance.startFROSTRefresh({from: accounts[1]}), + ) + }); +}) diff --git a/test/admin/transferLiquidity.js b/test/admin/transferLiquidity.js new file mode 100644 index 00000000..108b3d2d --- /dev/null +++ b/test/admin/transferLiquidity.js @@ -0,0 +1,45 @@ +// The Licensed Work is (c) 2022 Sygma +// SPDX-License-Identifier: LGPL-3.0-only + +const TruffleAssert = require("truffle-assertions"); +const Helpers = require("../helpers"); +const Admin = artifacts.require("Admin") +const Ethers = require("ethers"); + +contract("Admin - [Liqudity]", (accounts) => { + let AdminInstance; + + const domainID = 1; + const resourceID = "0x0000000000000000000000000000000000000000000000000000000000000650"; + const recipient = "bc1qs0fcdq73vgurej48yhtupzcv83un2p5qhsje7n"; + const amount = Ethers.utils.parseEther("1"); + + beforeEach(async () => { + AdminInstance = await Admin.new(accounts[0]); + }); + + it("should emit TransferLiqudity event when transferLiquidity is called by the owner", async () => { + const tx = await AdminInstance.transferLiquidity( + domainID, resourceID, amount, recipient, + {from: accounts[0]} + ) + + TruffleAssert.eventEmitted(tx, "TransferLiquidity", (event) => { + return ( + event.domainID === domainID && + event.resourceID === resourceID && + event.amount === amount && + event.destinationAddress === recipient + ) + }); + }); + + it("should revert when transferLiqudity is not called by the owner", async () => { + await Helpers.reverts( + AdminInstance.transferLiquidity( + domainID, resourceID, amount, recipient, + {from: accounts[1]} + ) + ) + }); +}) diff --git a/test/frostKeygen/frostKeygen.js b/test/frostKeygen/frostKeygen.js deleted file mode 100644 index 55953a65..00000000 --- a/test/frostKeygen/frostKeygen.js +++ /dev/null @@ -1,41 +0,0 @@ -// The Licensed Work is (c) 2022 Sygma -// SPDX-License-Identifier: LGPL-3.0-only - -const TruffleAssert = require("truffle-assertions"); -const Helpers = require("../helpers"); -const FROSTKeygen = artifacts.require("FROSTKeygen") - -contract("FROSTKeygen", (accounts) => { - let FROSTKeygenInstance; - - beforeEach(async () => { - FROSTKeygenInstance = await FROSTKeygen.new(accounts[0]); - }); - - it("should emit StartedFROSTKeygen event when startFROSTKeygen is called by the owner", async () => { - const tx = await FROSTKeygenInstance.startFROSTKeygen({from: accounts[0]}) - - TruffleAssert.eventEmitted(tx, "StartedFROSTKeygen"); - }); - - it("should revert when startFROSTKeygen is not called by the owner", async () => { - await Helpers.reverts( - FROSTKeygenInstance.startFROSTKeygen({from: accounts[1]}), - ) - }); - - it("should revert when keygen ended", async() => { - const tx = await FROSTKeygenInstance.endFROSTKeygen({from: accounts[0]}) - TruffleAssert.eventEmitted(tx, "EndedFROSTKeygen"); - - await Helpers.reverts( - FROSTKeygenInstance.startFROSTKeygen({from: accounts[0]}) - ) - }); - - it("should revert when end keygen not called by owner", async() => { - await Helpers.reverts( - FROSTKeygenInstance.endFROSTKeygen({from: accounts[1]}), - ) - }); -})