Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

feat: implement admin contract for FROST related activities #267

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, bytes 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, bytes calldata 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(publicKey, {from: accounts[2]}),
)
});
})
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 = "0x62633171733066636471373376677572656A343879687475707A63763833756E3270357168736A65376E";
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.toString() == amount.toString() &&
event.destinationAddress === recipient.toLowerCase()
)
});
});

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.

Loading