-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement admin contract for FROST related activities
- Loading branch information
Showing
7 changed files
with
145 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]}), | ||
) | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]} | ||
) | ||
) | ||
}); | ||
}) |
This file was deleted.
Oops, something went wrong.