Skip to content

Commit

Permalink
Implement admin contract for FROST related activities
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetrun5 committed Aug 28, 2024
1 parent 0234458 commit 9b47702
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 91 deletions.
41 changes: 41 additions & 0 deletions contracts/Admin.sol
Original file line number Diff line number Diff line change
@@ -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);
}
}
33 changes: 0 additions & 33 deletions contracts/FROSTKeygen.sol

This file was deleted.

17 changes: 17 additions & 0 deletions migrations/9_deploy_admin.js
Original file line number Diff line number Diff line change
@@ -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,
});
}
}
17 changes: 0 additions & 17 deletions migrations/9_deploy_frostKeygen.js

This file was deleted.

42 changes: 42 additions & 0 deletions test/admin/frost.js
Original file line number Diff line number Diff line change
@@ -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]}),
)
});
})
45 changes: 45 additions & 0 deletions test/admin/transferLiquidity.js
Original file line number Diff line number Diff line change
@@ -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]}
)
)
});
})
41 changes: 0 additions & 41 deletions test/frostKeygen/frostKeygen.js

This file was deleted.

0 comments on commit 9b47702

Please sign in to comment.