Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test + script: remove address precomputation, setup test for withdrawal #20

Merged
merged 11 commits into from
Jan 22, 2024
Merged
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ jobs:

- name: Run Forge tests
run: |
anvil --chain-id 2024 --port 8546 &
anvil --chain-id 2 --port 8547 &
forge test -vvv
id: test
5 changes: 4 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ src = 'src'
out = 'out'
optimizer = true
optimizer_runs = 200
ffi = true

libs = [
'lib',
Expand Down Expand Up @@ -51,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"
2 changes: 1 addition & 1 deletion lib/foundry-deployment-kit
8 changes: 5 additions & 3 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,17 +15,19 @@
| ERC20PresetMinterPauser | 6.368 | 18.208 |
| EnumerableSet | 0.086 | 24.49 |
| ErrorHandler | 0.086 | 24.49 |
| GeneralConfig | 20.129 | 4.447 |
| GeneralConfigExtended | 20.351 | 4.225 |
| GeneralConfig | 20.616 | 3.96 |
| GeneralConfigExtended | 20.35 | 4.226 |
| GlobalProposal | 0.166 | 24.41 |
| HasBridgeDeprecated | 0.063 | 24.513 |
| HasValidatorDeprecated | 0.063 | 24.513 |
| IsolatedGovernance | 0.086 | 24.49 |
| JSONParserLib | 0.086 | 24.49 |
| LibArray | 0.086 | 24.49 |
| LibArrayUtils | 0.086 | 24.49 |
| LibErrorHandler | 0.086 | 24.49 |
| LibProxy | 0.086 | 24.49 |
| LibSharedAddress | 0.086 | 24.49 |
| LibSort | 0.086 | 24.49 |
| LibString | 0.086 | 24.49 |
| LibTUint256Slot | 0.086 | 24.49 |
| MainchainBridgeManager | 19.361 | 5.215 |
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)");
}
}
182 changes: 64 additions & 118 deletions script/Migration.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { ISharedArgument } from "./interfaces/ISharedArgument.sol";
import { Network } from "./utils/Network.sol";
import { Utils } from "./utils/Utils.sol";
import { Contract } from "./utils/Contract.sol";

import { GlobalProposal } from "@ronin/contracts/libraries/GlobalProposal.sol";
import { Token } from "@ronin/contracts/libraries/Token.sol";
import { LibArray } from "./libraries/LibArray.sol";

contract Migration is BaseMigration, Utils {
ISharedArgument public constant config = ISharedArgument(address(CONFIG));
Expand All @@ -21,152 +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;
}

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.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.bridgeContract = loadContract(Contract.MainchainGatewayV3.key());
param.mainchainBridgeManager.callbackRegisters = getEmptyAddressArray();
param.mainchainBridgeManager.roninChainId = param.test.roninChainId;
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 @@ -175,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));
}
}
Loading