Skip to content

Commit

Permalink
test(bridge-setup): setup 2 local chains + remove pre-compute address…
Browse files Browse the repository at this point in the history
…es before actually deploy
  • Loading branch information
huyhuynh3103 committed Jan 20, 2024
1 parent dab5239 commit 21784ee
Show file tree
Hide file tree
Showing 19 changed files with 530 additions and 276 deletions.
4 changes: 3 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@ ethereum = "https://eth.llamarpc.com"
goerli = "https://ethereum-goerli.publicnode.com"
ronin-mainnet = "https://api-partner.roninchain.com/rpc"
ronin-testnet = "https://saigon-archive.roninchain.com/rpc"
localhost = "http://localhost:8545"

ronin-local = "http://localhost:8546"
ethereum-local = "http://localhost:8547"
4 changes: 2 additions & 2 deletions logs/contract-code-sizes.log
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
| AddressArrayUtils | 0.086 | 24.49 |
| ArtifactFactory | 9.155 | 15.421 |
| Ballot | 0.086 | 24.49 |
| BaseGeneralConfig | 20.129 | 4.447 |
| BaseGeneralConfig | 20.128 | 4.448 |
| BridgeOperatorsBallot | 0.166 | 24.41 |
| BridgeReward | 6.032 | 18.544 |
| BridgeSlash | 5.639 | 18.937 |
Expand All @@ -15,7 +15,7 @@
| ERC20PresetMinterPauser | 6.368 | 18.208 |
| EnumerableSet | 0.086 | 24.49 |
| ErrorHandler | 0.086 | 24.49 |
| GeneralConfig | 20.129 | 4.447 |
| GeneralConfig | 20.128 | 4.448 |
| GeneralConfigExtended | 20.35 | 4.226 |
| GlobalProposal | 0.166 | 24.41 |
| HasBridgeDeprecated | 0.063 | 24.513 |
Expand Down
49 changes: 26 additions & 23 deletions script/GeneralConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ contract GeneralConfig is BaseGeneralConfig, Utils {
Network.RoninDevnet.envLabel(),
Network.RoninDevnet.explorer()
);

setNetworkInfo(
Network.RoninLocal.chainId(),
Network.RoninLocal.key(),
Network.RoninLocal.chainAlias(),
Network.RoninLocal.deploymentDir(),
Network.RoninLocal.envLabel(),
Network.RoninLocal.explorer()
);

setNetworkInfo(
Network.EthLocal.chainId(),
Network.EthLocal.key(),
Network.EthLocal.chainAlias(),
Network.EthLocal.deploymentDir(),
Network.EthLocal.envLabel(),
Network.EthLocal.explorer()
);
}

function _setUpContracts() internal virtual override {
Expand All @@ -53,32 +71,17 @@ contract GeneralConfig is BaseGeneralConfig, Utils {
_contractNameMap[Contract.AXS.key()] = "MockERC20";
_contractNameMap[Contract.SLP.key()] = "MockERC20";
_contractNameMap[Contract.USDC.key()] = "MockERC20";

if (getCurrentNetwork() == DefaultNetwork.Local.key()) {
address deployer = getSender();

// ronin bridge contracts
setAddress(DefaultNetwork.Local.key(), Contract.RoninGatewayV3.key(), vm.computeCreateAddress(deployer, 4));
setAddress(DefaultNetwork.Local.key(), Contract.BridgeTracking.key(), vm.computeCreateAddress(deployer, 6));
setAddress(DefaultNetwork.Local.key(), Contract.BridgeSlash.key(), vm.computeCreateAddress(deployer, 8));
setAddress(DefaultNetwork.Local.key(), Contract.BridgeReward.key(), vm.computeCreateAddress(deployer, 10));
setAddress(DefaultNetwork.Local.key(), Contract.RoninBridgeManager.key(), vm.computeCreateAddress(deployer, 11));

//mainchain bridge contracts
setAddress(DefaultNetwork.Local.key(), Contract.MainchainGatewayV3.key(), vm.computeCreateAddress(deployer, 13));
setAddress(
DefaultNetwork.Local.key(), Contract.MainchainBridgeManager.key(), vm.computeCreateAddress(deployer, 14)
);

// ronin tokens
setAddress(DefaultNetwork.Local.key(), Contract.WETH.key(), vm.computeCreateAddress(deployer, 15));
setAddress(DefaultNetwork.Local.key(), Contract.AXS.key(), vm.computeCreateAddress(deployer, 16));
setAddress(DefaultNetwork.Local.key(), Contract.SLP.key(), vm.computeCreateAddress(deployer, 17));
setAddress(DefaultNetwork.Local.key(), Contract.USDC.key(), vm.computeCreateAddress(deployer, 18));
}
}

function _mapContractName(Contract contractEnum) internal {
_contractNameMap[contractEnum.key()] = contractEnum.name();
}

function getSender() public view virtual override returns (address payable sender) {
sender = _option.trezor ? payable(_trezorSender) : payable(_envSender);
bool isLocalNetwork = getCurrentNetwork() == DefaultNetwork.Local.key()
|| getCurrentNetwork() == Network.RoninLocal.key() || getCurrentNetwork() == Network.EthLocal.key();
if (sender == address(0x0) && isLocalNetwork) sender = payable(DEFAULT_SENDER);
require(sender != address(0x0), "GeneralConfig: Sender is address(0x0)");
}
}
186 changes: 63 additions & 123 deletions script/Migration.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,158 +21,98 @@ contract Migration is BaseMigration, Utils {

function _sharedArguments() internal virtual override returns (bytes memory rawArgs) {
ISharedArgument.SharedParameter memory param;
param.test.proxyAdmin = makeAddr("proxy-admin");
param.test.dposGA = makeAddr("governance-admin");
param.test.mainchainChainId = Network.EthLocal.chainId();
param.test.roninChainId = Network.RoninLocal.chainId();

// tokens
param.weth.name = "Wrapped WETH";
param.weth.symbol = "WETH";
param.wron.name = "Wrapped RON";
param.wron.symbol = "WRON";
param.axs.name = "Axie Infinity Shard";
param.axs.symbol = "AXS";
param.slp.name = "Smooth Love Potion";
param.slp.symbol = "SLP";
param.usdc.name = "USD Coin";
param.usdc.symbol = "USDC";

uint256 num = 6;
address[] memory operatorAddrs = new address[](num);
address[] memory governorAddrs = new address[](num);
uint256[] memory operatorPKs = new uint256[](num);
uint256[] memory governorPKs = new uint256[](num);
uint96[] memory voteWeights = new uint96[](num);
GlobalProposal.TargetOption[] memory options = new GlobalProposal.TargetOption[](0);
address[] memory targets = new address[](0);

for (uint256 i; i < num; i++) {
(address addrOperator, uint256 pkOperator) = makeAddrAndKey(string.concat("operator-", vm.toString(i + 1)));
(address addrGovernor, uint256 pkGovernor) = makeAddrAndKey(string.concat("governor-", vm.toString(i + 1)));

operatorAddrs[i] = addrOperator;
governorAddrs[i] = addrGovernor;
operatorPKs[i] = pkOperator;
governorPKs[i] = pkGovernor;
voteWeights[i] = 100;
}

LibArray.inlineSortByValue(operatorPKs, LibArray.toUint256s(operatorAddrs));
LibArray.inlineSortByValue(governorPKs, LibArray.toUint256s(governorAddrs));

param.test.operatorPKs = operatorPKs;
param.test.governorPKs = governorPKs;

if (network() == Network.Goerli.key()) {
// Undefined
} else if (network() == DefaultNetwork.RoninTestnet.key()) {
// Undefined
} else if (network() == DefaultNetwork.Local.key()) {
uint256 num = 6;
address[] memory operatorAddrs = new address[](num);
address[] memory governorAddrs = new address[](num);
uint256[] memory operatorPKs = new uint256[](num);
uint256[] memory governorPKs = new uint256[](num);
uint96[] memory voteWeights = new uint96[](num);

for (uint256 i; i < num; i++) {
(address addrOperator, uint256 pkOperator) = makeAddrAndKey(string.concat("operator-", vm.toString(i + 1)));
(address addrGovernor, uint256 pkGovernor) = makeAddrAndKey(string.concat("governor-", vm.toString(i + 1)));

operatorAddrs[i] = addrOperator;
governorAddrs[i] = addrGovernor;
operatorPKs[i] = pkOperator;
governorPKs[i] = pkGovernor;
voteWeights[i] = 100;
}

LibArray.inlineSortByValue(operatorPKs, LibArray.toUint256s(operatorAddrs));
LibArray.inlineSortByValue(governorPKs, LibArray.toUint256s(governorAddrs));

address governanceAdmin = makeAddr("governance-admin");
address validatorSetContract = makeAddr("validator-set-contract");
Token.Standard[] memory standards = new Token.Standard[](1);
standards[0] = Token.Standard.ERC20;

GlobalProposal.TargetOption[] memory options = new GlobalProposal.TargetOption[](4);
address[] memory targets = new address[](4);

options[0] = GlobalProposal.TargetOption.GatewayContract;
targets[0] = loadContract(Contract.RoninGatewayV3.key());

options[1] = GlobalProposal.TargetOption.BridgeReward;
targets[1] = loadContract(Contract.BridgeReward.key());

options[2] = GlobalProposal.TargetOption.BridgeSlash;
targets[2] = loadContract(Contract.BridgeSlash.key());

options[3] = GlobalProposal.TargetOption.BridgeTracking;
targets[3] = loadContract(Contract.BridgeTracking.key());

// test
param.test.proxyAdmin = makeAddr("proxy-admin");
param.test.roninChainId = 0;
param.test.operatorPKs = operatorPKs;
param.test.governorPKs = governorPKs;

} else if (network() == Network.RoninLocal.key() || network() == Network.EthLocal.key()) {
// Bridge rewards
param.bridgeReward.bridgeManagerContract = loadContract(Contract.RoninBridgeManager.key());
param.bridgeReward.bridgeTrackingContract = loadContract(Contract.BridgeTracking.key());
param.bridgeReward.bridgeSlashContract = loadContract(Contract.BridgeSlash.key());
param.bridgeReward.validatorSetContract = validatorSetContract;
param.bridgeReward.dposGA = governanceAdmin;
param.bridgeReward.dposGA = param.test.dposGA;
param.bridgeReward.rewardPerPeriod = 5_000;

// Bridge Slash
param.bridgeSlash.validatorContract = validatorSetContract;
param.bridgeSlash.bridgeManagerContract = loadContract(Contract.RoninBridgeManager.key());
param.bridgeSlash.bridgeTrackingContract = loadContract(Contract.BridgeTracking.key());
param.bridgeSlash.dposGA = governanceAdmin;
param.bridgeSlash.dposGA = param.test.dposGA;

// Bridge Tracking
param.bridgeTracking.bridgeContract = loadContract(Contract.RoninGatewayV3.key());
param.bridgeTracking.validatorContract = validatorSetContract;

// Ronin Gateway V3
param.roninGatewayV3.numerator = 3;
param.roninGatewayV3.denominator = 6;
param.roninGatewayV3.trustedNumerator = 2;
param.roninGatewayV3.trustedDenominator = 3;

// Ronin Bridge Manager
param.roninBridgeManager.num = 2;
param.roninBridgeManager.denom = 4;
param.roninBridgeManager.roninChainId = 0;
param.roninBridgeManager.roninChainId = param.test.roninChainId;
param.roninBridgeManager.expiryDuration = 60 * 60 * 24 * 14; // 14 days
param.roninBridgeManager.bridgeContract = loadContract(Contract.RoninGatewayV3.key());
param.roninBridgeManager.callbackRegisters = wrapAddress(loadContract(Contract.BridgeSlash.key()));
param.roninBridgeManager.bridgeOperators = operatorAddrs;
param.roninBridgeManager.governors = governorAddrs;
param.roninBridgeManager.voteWeights = voteWeights;
param.roninBridgeManager.targetOptions = options;
param.roninBridgeManager.targets = targets;

// Ronin Gateway V3
param.roninGatewayV3.roleSetter = address(0);
param.roninGatewayV3.numerator = 3;
param.roninGatewayV3.denominator = 6;
param.roninGatewayV3.trustedNumerator = 2;
param.roninGatewayV3.trustedDenominator = 3;
param.roninGatewayV3.withdrawalMigrators = getEmptyAddressArray();
param.roninGatewayV3.packedAddresses[0] = wrapAddress(address(0));
param.roninGatewayV3.packedAddresses[1] = wrapAddress(address(0));
param.roninGatewayV3.packedNumbers[0] = wrapUint(1);
param.roninGatewayV3.packedNumbers[1] = wrapUint(0);
param.roninGatewayV3.standards = standards;
// Mainchain Gateway V3
param.mainchainGatewayV3.roninChainId = param.test.roninChainId;
param.mainchainGatewayV3.numerator = 1;
param.mainchainGatewayV3.highTierVWNumerator = 10;
param.mainchainGatewayV3.denominator = 10;

// Mainchain Bridge Manager
delete options;
delete targets;

options = new GlobalProposal.TargetOption[](1);
targets = new address[](1);

options[0] = GlobalProposal.TargetOption.GatewayContract;
targets[0] = loadContract(Contract.MainchainGatewayV3.key());

param.mainchainBridgeManager.num = 2;
param.mainchainBridgeManager.denom = 4;
param.mainchainBridgeManager.roninChainId = 0;
param.mainchainBridgeManager.roninChainId = param.test.roninChainId;
param.mainchainBridgeManager.bridgeContract = loadContract(Contract.MainchainGatewayV3.key());
param.mainchainBridgeManager.callbackRegisters = getEmptyAddressArray();
param.mainchainBridgeManager.bridgeOperators = operatorAddrs;
param.mainchainBridgeManager.governors = governorAddrs;
param.mainchainBridgeManager.voteWeights = voteWeights;
param.mainchainBridgeManager.targetOptions = options;
param.mainchainBridgeManager.targets = targets;

// Mainchain Gateway V3
delete standards;
standards = new Token.Standard[](2);

standards[0] = Token.Standard.ERC20;
standards[1] = Token.Standard.ERC20;

param.mainchainGatewayV3.roleSetter = address(0);
param.mainchainGatewayV3.roninChainId = 0;
param.mainchainGatewayV3.numerator = 1;
param.mainchainGatewayV3.highTierVWNumerator = 10;
param.mainchainGatewayV3.denominator = 10;
param.mainchainGatewayV3.addresses[0] =
wrapAddress(loadContract(Contract.WETH.key()), loadContract(Contract.USDC.key())); // mainchain tokens
param.mainchainGatewayV3.addresses[1] =
wrapAddress(loadContract(Contract.WETH.key()), loadContract(Contract.USDC.key())); // ronin tokens
param.mainchainGatewayV3.addresses[2] = getEmptyAddressArray(); //withdrawalUnlockers
param.mainchainGatewayV3.thresholds[0] = wrapUint(10, 0); // highTierThreshold
param.mainchainGatewayV3.thresholds[1] = wrapUint(20, 0); // lockedThreshold
param.mainchainGatewayV3.thresholds[2] = wrapUint(100_000, 0); // unlockFeePercentages
param.mainchainGatewayV3.thresholds[3] = wrapUint(12, 0); // dailyWithdrawalLimits
param.mainchainGatewayV3.standards = standards;

// tokens
param.weth.name = "Wrapped WETH";
param.weth.symbol = "WETH";
param.wron.name = "Wrapped RON";
param.wron.symbol = "WRON";
param.axs.name = "Axie Infinity Shard";
param.axs.symbol = "AXS";
param.slp.name = "Smooth Love Potion";
param.slp.symbol = "SLP";
param.usdc.name = "USD Coin";
param.usdc.symbol = "USDC";
} else if (network() == DefaultNetwork.Local.key()) {
// Undefined
} else {
revert("Migration: Network Unknown Shared Parameters Unimplemented!");
}
Expand All @@ -181,8 +121,8 @@ contract Migration is BaseMigration, Utils {
}

function _getProxyAdmin() internal virtual override returns (address payable) {
return network() == DefaultNetwork.Local.key()
? payable(config.sharedArguments().test.proxyAdmin)
: super._getProxyAdmin();
bool isLocalNetwork = network() == DefaultNetwork.Local.key() || network() == Network.RoninLocal.key()
|| network() == Network.EthLocal.key();
return isLocalNetwork ? payable(config.sharedArguments().test.proxyAdmin) : super._getProxyAdmin();
}
}
18 changes: 1 addition & 17 deletions script/contracts/BridgeRewardDeploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,7 @@ import { RoninBridgeManagerDeploy } from "./RoninBridgeManagerDeploy.s.sol";
import { BridgeSlashDeploy } from "./BridgeSlashDeploy.s.sol";

contract BridgeRewardDeploy is Migration {
function _defaultArguments() internal virtual override returns (bytes memory args) {
ISharedArgument.BridgeRewardParam memory param = config.sharedArguments().bridgeReward;

args = abi.encodeCall(
BridgeReward.initialize,
(
param.bridgeManagerContract,
param.bridgeTrackingContract,
param.bridgeSlashContract,
param.validatorSetContract,
param.dposGA,
param.rewardPerPeriod
)
);
}

function run() public virtual returns (BridgeReward) {
return BridgeReward(_deployProxy(Contract.BridgeReward.key()));
return BridgeReward(_deployProxy(Contract.BridgeReward.key(), EMPTY_ARGS));
}
}
11 changes: 1 addition & 10 deletions script/contracts/BridgeSlashDeploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,7 @@ import { BridgeTrackingDeploy } from "./BridgeTrackingDeploy.s.sol";
import { RoninBridgeManagerDeploy } from "./RoninBridgeManagerDeploy.s.sol";

contract BridgeSlashDeploy is Migration {
function _defaultArguments() internal virtual override returns (bytes memory args) {
ISharedArgument.BridgeSlashParam memory param = config.sharedArguments().bridgeSlash;

args = abi.encodeCall(
BridgeSlash.initialize,
(param.validatorContract, param.bridgeManagerContract, param.bridgeTrackingContract, param.dposGA)
);
}

function run() public virtual returns (BridgeSlash) {
return BridgeSlash(_deployProxy(Contract.BridgeSlash.key()));
return BridgeSlash(_deployProxy(Contract.BridgeSlash.key(), EMPTY_ARGS));
}
}
9 changes: 1 addition & 8 deletions script/contracts/BridgeTrackingDeploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@ import { Migration } from "../Migration.s.sol";
import { RoninGatewayV3Deploy } from "./RoninGatewayV3Deploy.s.sol";

contract BridgeTrackingDeploy is Migration {
function _defaultArguments() internal virtual override returns (bytes memory args) {
ISharedArgument.BridgeTrackingParam memory param = config.sharedArguments().bridgeTracking;

args =
abi.encodeCall(BridgeTracking.initialize, (param.bridgeContract, param.validatorContract, param.startedAtBlock));
}

function run() public virtual returns (BridgeTracking) {
return BridgeTracking(_deployProxy(Contract.BridgeTracking.key()));
return BridgeTracking(_deployProxy(Contract.BridgeTracking.key(), EMPTY_ARGS));
}
}
Loading

0 comments on commit 21784ee

Please sign in to comment.