Skip to content

Commit

Permalink
Merge pull request #80 from ronin-chain/script/rework-factory-script
Browse files Browse the repository at this point in the history
Script(Factories): Accept private keys via terminal input for signature signing.
  • Loading branch information
tringuyenskymavis authored Aug 28, 2024
2 parents 06042a6 + 81b12db commit 5b14d5c
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 35 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/post-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly-2b1f8d6dd90f9790faf0528e05e60e573a7569ce

- name: Update package with soldeer
run: forge soldeer update
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/slither-analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ jobs:

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly-2b1f8d6dd90f9790faf0528e05e60e573a7569ce

- name: Update package with soldeer
run: forge soldeer update
- name: Install package with soldeer
run: forge soldeer install

- name: Recursively update dependencies
run: |
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ jobs:

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly-2b1f8d6dd90f9790faf0528e05e60e573a7569ce

- name: Update package with soldeer
run: forge soldeer update
- name: Install package with soldeer
run: forge soldeer install

- name: Recursively update dependencies
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ contract Migration__20242606_MapTokenAnimaMainchain is Base__MapToken, Factory__
return Base__MapToken._initGovernors();
}

function _initGovernorPKs() internal override(Base__MapToken, Factory__MapTokensMainchain_Sepolia) returns (uint256[] memory) {
return Base__MapToken._initGovernorPKs();
}

function run() public override {
Factory__MapTokensMainchain_Sepolia.run();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ import "../simulation/factory-maptoken-simulation-mainchain.s.sol";
abstract contract Factory__MapTokensMainchain_Ethereum is Factory__MapTokensMainchain {
using LibCompanionNetwork for *;

function setUp() public override {
super.setUp();
function run() public virtual override {
super.run();
_roninBridgeManager = RoninBridgeManager(config.getAddressFromCurrentNetwork(Contract.RoninBridgeManager.key()));
_mainchainGatewayV3 = config.getAddress(network().companionNetwork(), Contract.MainchainGatewayV3.key());
_mainchainBridgeManager = config.getAddress(network().companionNetwork(), Contract.MainchainBridgeManager.key());
}

function run() public virtual override {
uint256 chainId = network().companionChainId();
uint256 nonce = _roninBridgeManager.round(chainId) + 1;
Proposal.ProposalDetail memory proposal = _createAndVerifyProposalOnMainchain(chainId, nonce);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,17 @@ import "./factory-maptoken-mainchain.s.sol";
import "../simulation/factory-maptoken-simulation-mainchain.s.sol";

abstract contract Factory__MapTokensMainchain_Sepolia is Factory__MapTokensMainchain {
function setUp() public override {
super.setUp();
_mainchainGatewayV3 = config.getAddressFromCurrentNetwork(Contract.MainchainGatewayV3.key());
_mainchainBridgeManager = config.getAddressFromCurrentNetwork(Contract.MainchainBridgeManager.key());
}

function _initGovernorPKs() internal virtual returns (uint256[] memory);
function _initGovernors() internal virtual returns (address[] memory);

function run() public virtual override {
super.run();
_mainchainGatewayV3 = config.getAddressFromCurrentNetwork(Contract.MainchainGatewayV3.key());
_mainchainBridgeManager = config.getAddressFromCurrentNetwork(Contract.MainchainBridgeManager.key());
address[] memory mGovernors;
uint256[] memory mGovernorsPk;

mGovernors = _initGovernors();
mGovernorsPk = _initGovernorPKs();

for (uint256 i; i < mGovernors.length; ++i) {
_governors.push(mGovernors[i]);
_governorPKs.push(mGovernorsPk[i]);
}

uint256 chainId = block.chainid;
Expand Down
12 changes: 3 additions & 9 deletions script/factories/mainchain/factory-maptoken-mainchain.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,11 @@ abstract contract Factory__MapTokensMainchain is Migration {
address internal _mainchainBridgeManager;
address internal _specifiedCaller;
address[] internal _governors;
uint256[] internal _governorPKs;

function setUp() public virtual override {
super.setUp();
function run() public virtual {
_specifiedCaller = _initCaller();
}

function run() public virtual;
function _initCaller() internal virtual returns (address);
function _initTokenList() internal virtual returns (uint256 totalToken, MapTokenInfo[] memory infos);

Expand All @@ -50,17 +47,14 @@ abstract contract Factory__MapTokensMainchain is Migration {
}

function _relayProposal(Proposal.ProposalDetail memory proposal) internal {
MainchainBridgeAdminUtils mainchainProposalUtils =
new MainchainBridgeAdminUtils(2021, _governorPKs, IMainchainBridgeManager(_mainchainBridgeManager), _governors[0]);

Ballot.VoteType[] memory supports_ = new Ballot.VoteType[](_governors.length);
require(_governors.length > 0 && _governors.length == _governorPKs.length, "Invalid governors information");
require(_governors.length > 0, "Invalid number of governors");

for (uint256 i; i < _governors.length; ++i) {
supports_[i] = Ballot.VoteType.For;
}

Signature[] memory signatures = mainchainProposalUtils.generateSignatures(proposal, _governorPKs);
Signature[] memory signatures = LibProposal.generateSignatures(proposal, _governors, Ballot.VoteType.For);

uint256 gasAmounts = 1_000_000;
for (uint256 i; i < proposal.gasAmounts.length; ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ abstract contract Factory__MapTokensRonin_Mainnet is Factory__MapTokensRoninchai
using LibCompanionNetwork for *;

function run() public virtual override {
super.run();
Proposal.ProposalDetail memory proposal = _createAndVerifyProposalOnRonin();
// Simulate execute proposal
new Factory__MapTokensSimulation_Roninchain().simulate(proposal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ abstract contract Factory__MapTokensRonin_Testnet is Factory__MapTokensRoninchai
function _initGovernors() internal virtual returns (address[] memory);

function run() public virtual override {
super.run();
address[] memory mGovernors = _initGovernors();

for (uint256 i; i < mGovernors.length; ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ abstract contract Factory__MapTokensRoninchain is Migration {
address internal _specifiedCaller;
address[] internal _governors;

function setUp() public virtual override {
super.setUp();
function run() public virtual {
_roninBridgeManager = RoninBridgeManager(config.getAddressFromCurrentNetwork(Contract.RoninBridgeManager.key()));
_roninGatewayV3 = config.getAddressFromCurrentNetwork(Contract.RoninGatewayV3.key());
_specifiedCaller = _initCaller();
}

function run() public virtual;
function _initCaller() internal virtual returns (address);
function _initTokenList() internal virtual returns (uint256 totalToken, MapTokenInfo[] memory infos);

Expand Down

0 comments on commit 5b14d5c

Please sign in to comment.