From 6692291166c6d2641f503568e6c8a5bdd5a02ec2 Mon Sep 17 00:00:00 2001 From: nxqbao Date: Wed, 31 Jan 2024 15:39:49 +0700 Subject: [PATCH 1/8] fix(Gateway): chore add name in mapping --- src/extensions/MinimumWithdrawal.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/extensions/MinimumWithdrawal.sol b/src/extensions/MinimumWithdrawal.sol index f9ead8863..fa7179264 100644 --- a/src/extensions/MinimumWithdrawal.sol +++ b/src/extensions/MinimumWithdrawal.sol @@ -11,8 +11,8 @@ abstract contract MinimumWithdrawal is HasProxyAdmin { /// @dev Emitted when the minimum thresholds are updated event MinimumThresholdsUpdated(address[] tokens, uint256[] threshold); - /// @dev Mapping from token address => minimum thresholds - mapping(address => uint256) public minimumThreshold; + /// @dev Mapping from mainchain token address => minimum thresholds + mapping(address mainchainToken => uint256) public minimumThreshold; /** * @dev This empty reserved space is put in place to allow future versions to add new From ff67b749aea4789e18fa46716ae15932165ab4ae Mon Sep 17 00:00:00 2001 From: nxqbao Date: Wed, 31 Jan 2024 15:40:22 +0700 Subject: [PATCH 2/8] script: add proposal for mapping pixel token and update axie chat governor --- .../20240131-maptoken-pixel-mainchain.s.sol | 142 ++++++++++++++++++ .../20240131-maptoken-pixel-roninchain.s.sol | 140 +++++++++++++++++ .../20240131-update-axiechat-governor.s.sol | 94 ++++++++++++ .../maptoken-pixel-configs.s.sol | 24 +++ script/BridgeMigration.sol | 63 +++++++- 5 files changed, 461 insertions(+), 2 deletions(-) create mode 100644 script/20240131-maptoken-pixel/20240131-maptoken-pixel-mainchain.s.sol create mode 100644 script/20240131-maptoken-pixel/20240131-maptoken-pixel-roninchain.s.sol create mode 100644 script/20240131-maptoken-pixel/20240131-update-axiechat-governor.s.sol create mode 100644 script/20240131-maptoken-pixel/maptoken-pixel-configs.s.sol diff --git a/script/20240131-maptoken-pixel/20240131-maptoken-pixel-mainchain.s.sol b/script/20240131-maptoken-pixel/20240131-maptoken-pixel-mainchain.s.sol new file mode 100644 index 000000000..20e2dc27b --- /dev/null +++ b/script/20240131-maptoken-pixel/20240131-maptoken-pixel-mainchain.s.sol @@ -0,0 +1,142 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; + +import { console2 } from "forge-std/console2.sol"; +import { StdStyle } from "forge-std/StdStyle.sol"; +import { BaseMigration } from "foundry-deployment-kit/BaseMigration.s.sol"; +import { RoninBridgeManager } from "@ronin/contracts/ronin/gateway/RoninBridgeManager.sol"; +import { IMainchainGatewayV3 } from "@ronin/contracts/interfaces/IMainchainGatewayV3.sol"; +import { GlobalProposal } from "@ronin/contracts/libraries/GlobalProposal.sol"; +import { Token } from "@ronin/contracts/libraries/Token.sol"; +import { Contract } from "../utils/Contract.sol"; +import { BridgeMigration } from "../BridgeMigration.sol"; +import { Network } from "../utils/Network.sol"; +import { Contract } from "../utils/Contract.sol"; +import { IGeneralConfigExtended } from "../IGeneralConfigExtended.sol"; + +import "./maptoken-pixel-configs.s.sol"; +import "./update-axiechat-config.s.sol"; + +contract Migration__20240131_MapTokenPixelMainchain is BridgeMigration, Migration__MapToken_Pixel_Config, Migration__Update_AxieChat_Config { + RoninBridgeManager internal _roninBridgeManager; + address internal _mainchainGatewayV3; + address internal _mainchainBridgeManager; + + function setUp() public override { + super.setUp(); + + _roninBridgeManager = RoninBridgeManager(_config.getAddressFromCurrentNetwork(Contract.RoninBridgeManager.key())); + _mainchainGatewayV3 = _config.getAddress( + _config.getCompanionNetwork(_config.getNetworkByChainId(block.chainid)).key(), + Contract.MainchainGatewayV3.key() + ); + _mainchainBridgeManager = _config.getAddress( + _config.getCompanionNetwork(_config.getNetworkByChainId(block.chainid)).key(), + Contract.MainchainBridgeManager.key() + ); + } + + function run() public { + address[] memory mainchainTokens = new address[](1); + address[] memory roninTokens = new address[](1); + Token.Standard[] memory standards = new Token.Standard[](1); + uint256[][4] memory thresholds; + + uint256 expiredTime = block.timestamp + 10 days; + address[] memory targets = new address[](4); + uint256[] memory values = new uint256[](4); + bytes[] memory calldatas = new bytes[](4); + uint256[] memory gasAmounts = new uint256[](4); + + // ================ PIXEL ERC-20 ====================== + + mainchainTokens[0] = _pixelMainchainToken; + roninTokens[0] = _pixelRoninToken; + standards[0] = Token.Standard.ERC20; + // highTierThreshold + thresholds[0] = new uint256[](1); + thresholds[0][0] = _highTierThreshold; + // lockedThreshold + thresholds[1] = new uint256[](1); + thresholds[1][0] = _lockedThreshold; + // unlockFeePercentages + thresholds[2] = new uint256[](1); + thresholds[2][0] = _unlockFeePercentages; + // dailyWithdrawalLimit + thresholds[3] = new uint256[](1); + thresholds[3][0] = _dailyWithdrawalLimit; + + // function mapTokensAndThresholds( + // address[] calldata _mainchainTokens, + // address[] calldata _roninTokens, + // Token.Standard[] calldata _standards, + // uint256[][4] calldata _thresholds + // ) + + bytes memory innerData = abi.encodeCall(IMainchainGatewayV3.mapTokensAndThresholds, ( + mainchainTokens, + roninTokens, + standards, + thresholds + )); + + bytes memory proxyData = abi.encodeWithSignature("functionDelegateCall(bytes)", innerData); + + targets[0] = _mainchainGatewayV3; + values[0] = 0; + calldatas[0] = proxyData; + gasAmounts[0] = 1_000_000; + + // ================ FARMLAND ERC-20 ====================== + + mainchainTokens[0] = _farmlandMainchainToken; + roninTokens[0] = _farmlandRoninToken; + standards[0] = Token.Standard.ERC721; + + // function mapTokens( + // address[] calldata _mainchainTokens, + // address[] calldata _roninTokens, + // Token.Standard[] calldata _standards + // ) external; + + innerData = abi.encodeCall(IMainchainGatewayV3.mapTokens, ( + mainchainTokens, + roninTokens, + standards + )); + + proxyData = abi.encodeWithSignature("functionDelegateCall(bytes)", innerData); + + targets[1] = _mainchainGatewayV3; + values[1] = 0; + calldatas[1] = proxyData; + gasAmounts[1] = 1_000_000; + + // =============== AXIE CHAT UPDATE =========== + targets[2] = _mainchainBridgeManager; + values[2] = 0; + calldatas[2] = _addAxieChatGovernorAddress(); + gasAmounts[2] = 1_000_000; + + targets[3] = _mainchainBridgeManager; + values[3] = 0; + calldatas[3] = _removeAxieChatGovernorAddress(); + gasAmounts[3] = 1_000_000; + + // ================ VERIFY AND EXECUTE PROPOSAL =============== + + _verifyMainchainProposalGasAmount(targets, values, calldatas, gasAmounts); + + uint256 chainId = _config.getCompanionNetwork(_config.getNetworkByChainId(block.chainid)).chainId(); + + vm.broadcast(_governor); + _roninBridgeManager.propose( + chainId, + expiredTime, + targets, + values, + calldatas, + gasAmounts + ); + } +} diff --git a/script/20240131-maptoken-pixel/20240131-maptoken-pixel-roninchain.s.sol b/script/20240131-maptoken-pixel/20240131-maptoken-pixel-roninchain.s.sol new file mode 100644 index 000000000..b3c3d9c37 --- /dev/null +++ b/script/20240131-maptoken-pixel/20240131-maptoken-pixel-roninchain.s.sol @@ -0,0 +1,140 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; + +import { console2 } from "forge-std/console2.sol"; +import { StdStyle } from "forge-std/StdStyle.sol"; +import { BaseMigration } from "foundry-deployment-kit/BaseMigration.s.sol"; + +import { RoninBridgeManager } from "@ronin/contracts/ronin/gateway/RoninBridgeManager.sol"; +import { IRoninGatewayV3 } from "@ronin/contracts/interfaces/IRoninGatewayV3.sol"; +import { MinimumWithdrawal } from "@ronin/contracts/extensions/MinimumWithdrawal.sol"; +import { Token } from "@ronin/contracts/libraries/Token.sol"; +import { Ballot } from "@ronin/contracts/libraries/Ballot.sol"; +import { GlobalProposal } from "@ronin/contracts/libraries/GlobalProposal.sol"; + +import { Contract } from "../utils/Contract.sol"; +import { BridgeMigration } from "../BridgeMigration.sol"; +import { Network } from "../utils/Network.sol"; +import { Contract } from "../utils/Contract.sol"; +import { IGeneralConfigExtended } from "../IGeneralConfigExtended.sol"; + +import "forge-std/console2.sol"; + +import "./maptoken-pixel-configs.s.sol"; +import "./update-axiechat-config.s.sol"; + +contract Migration__20240131_MapTokenPixelRoninchain is BridgeMigration, Migration__MapToken_Pixel_Config, Migration__Update_AxieChat_Config { + RoninBridgeManager internal _roninBridgeManager; + address internal _roninGatewayV3; + + function setUp() public override { + super.setUp(); + _roninBridgeManager = RoninBridgeManager(_config.getAddressFromCurrentNetwork(Contract.RoninBridgeManager.key())); + _roninGatewayV3 = _config.getAddressFromCurrentNetwork(Contract.RoninGatewayV3.key()); + } + + function _cheatWeightOperator(address gov) internal { + bytes32 $ = keccak256(abi.encode(gov, 0x88547008e60f5748911f2e59feb3093b7e4c2e87b2dd69d61f112fcc932de8e3)); + bytes32 opAndWeight = vm.load(address(_roninBridgeManager), $); + + uint256 totalWeight = _roninBridgeManager.getTotalWeight(); + bytes32 newOpAndWeight = bytes32((totalWeight << 160) + uint160(uint256(opAndWeight))); + vm.store(address(_roninBridgeManager), $, newOpAndWeight); + } + + function run() public { + _cheatWeightOperator(_governor); + + address[] memory roninTokens = new address[](2); + address[] memory mainchainTokens = new address[](2); + uint256[] memory chainIds = new uint256[](2); + Token.Standard[] memory standards = new Token.Standard[](2); + + uint256 expiredTime = block.timestamp + 10 days; + address[] memory targets = new address[](4); + uint256[] memory values = new uint256[](4); + bytes[] memory calldatas = new bytes[](4); + uint256[] memory gasAmounts = new uint256[](4); + + // ============= MAP PIXEL TOKEN =========== + + roninTokens[0] = _pixelRoninToken; + mainchainTokens[0] = _pixelMainchainToken; + chainIds[0] = _config.getCompanionNetwork(_config.getNetworkByChainId(block.chainid)).chainId(); + standards[0] = Token.Standard.ERC20; + + roninTokens[1] = _farmlandRoninToken; + mainchainTokens[1] = _farmlandMainchainToken; + chainIds[1] = _config.getCompanionNetwork(_config.getNetworkByChainId(block.chainid)).chainId(); + standards[1] = Token.Standard.ERC721; + + // function mapTokens( + // address[] calldata _roninTokens, + // address[] calldata _mainchainTokens, + // uint256[] calldata chainIds, + // Token.Standard[] calldata _standards + // ) + bytes memory innerData = abi.encodeCall(IRoninGatewayV3.mapTokens, ( + roninTokens, + mainchainTokens, + chainIds, + standards + )); + bytes memory proxyData = abi.encodeWithSignature("functionDelegateCall(bytes)", innerData); + + targets[0] = _roninGatewayV3; + values[0] = 0; + calldatas[0] = proxyData; + gasAmounts[0] = 1_000_000; + + // ============= SET MIN THRESHOLD ============ + // function setMinimumThresholds( + // address[] calldata _tokens, + // uint256[] calldata _thresholds + // ); + address[] memory mainchainTokensToSetMinThreshold = new address[](2); + uint256[] memory minThresholds = new uint256[](2); + + mainchainTokensToSetMinThreshold[0] = _pixelMainchainToken; + minThresholds[0] = _minThreshold; + + mainchainTokensToSetMinThreshold[1] = _aggMainchainToken; + minThresholds[1] = _aggMinThreshold; + + innerData = abi.encodeCall(MinimumWithdrawal.setMinimumThresholds, ( + mainchainTokensToSetMinThreshold, + minThresholds + )); + proxyData = abi.encodeWithSignature("functionDelegateCall(bytes)", innerData); + + targets[1] = _roninGatewayV3; + values[1] = 0; + calldatas[1] = proxyData; + gasAmounts[1] = 1_000_000; + + // =============== AXIE CHAT UPDATE =========== + targets[2] = address(_roninBridgeManager); + values[2] = 0; + calldatas[2] = _addAxieChatGovernorAddress(); + gasAmounts[2] = 1_000_000; + + targets[3] = address(_roninBridgeManager); + values[3] = 0; + calldatas[3] = _removeAxieChatGovernorAddress(); + gasAmounts[3] = 1_000_000; + + // ================ VERIFY AND EXECUTE PROPOSAL =============== + + _verifyRoninProposalGasAmount(targets, values, calldatas, gasAmounts); + + vm.broadcast(_governor); + _roninBridgeManager.propose( + block.chainid, + expiredTime, + targets, + values, + calldatas, + gasAmounts + ); + } +} diff --git a/script/20240131-maptoken-pixel/20240131-update-axiechat-governor.s.sol b/script/20240131-maptoken-pixel/20240131-update-axiechat-governor.s.sol new file mode 100644 index 000000000..2366c8df4 --- /dev/null +++ b/script/20240131-maptoken-pixel/20240131-update-axiechat-governor.s.sol @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; + +import { console2 } from "forge-std/console2.sol"; +import { StdStyle } from "forge-std/StdStyle.sol"; +import { BaseMigration } from "foundry-deployment-kit/BaseMigration.s.sol"; + +import { RoninBridgeManager } from "@ronin/contracts/ronin/gateway/RoninBridgeManager.sol"; +import { IRoninGatewayV3 } from "@ronin/contracts/interfaces/IRoninGatewayV3.sol"; +import { MinimumWithdrawal } from "@ronin/contracts/extensions/MinimumWithdrawal.sol"; +import { Token } from "@ronin/contracts/libraries/Token.sol"; +import { Ballot } from "@ronin/contracts/libraries/Ballot.sol"; +import { GlobalProposal } from "@ronin/contracts/libraries/GlobalProposal.sol"; +import { SignatureConsumer } from "@ronin/contracts/interfaces/consumers/SignatureConsumer.sol"; +import { IBridgeManager } from "@ronin/contracts/interfaces/bridge/IBridgeManager.sol"; + +import { Contract } from "../utils/Contract.sol"; +import { BridgeMigration } from "../BridgeMigration.sol"; +import { Network } from "../utils/Network.sol"; +import { Contract } from "../utils/Contract.sol"; +import { IGeneralConfigExtended } from "../IGeneralConfigExtended.sol"; + +import "forge-std/console2.sol"; + +import "./maptoken-pixel-configs.s.sol"; +import "./update-axiechat-config.s.sol"; + + +contract Migration__20240131_MapTokenPixelRoninchain is BridgeMigration, Migration__MapToken_Pixel_Config, Migration__Update_AxieChat_Config { + RoninBridgeManager internal _roninBridgeManager; + address internal _roninGatewayV3; + + address _cheatingGovernor; + + function setUp() public override { + super.setUp(); + _roninBridgeManager = RoninBridgeManager(_config.getAddressFromCurrentNetwork(Contract.RoninBridgeManager.key())); + _roninGatewayV3 = _config.getAddressFromCurrentNetwork(Contract.RoninGatewayV3.key()); + + _cheatingGovernor = makeAddr("cheat-governor"); + } + + function _cheatWeightGovernor(address gov) internal { + bytes32 $ = keccak256(abi.encode(gov, 0x88547008e60f5748911f2e59feb3093b7e4c2e87b2dd69d61f112fcc932de8e3)); + bytes32 opAndWeight = vm.load(address(_roninBridgeManager), $); + + uint256 totalWeight = _roninBridgeManager.getTotalWeight(); + bytes32 newOpAndWeight = bytes32((totalWeight << 160) + uint160(uint256(opAndWeight))); + vm.store(address(_roninBridgeManager), $, newOpAndWeight); + } + + function run() public { + _cheatWeightGovernor(_governor); + _cheatWeightGovernor(_cheatingGovernor); + + uint256 expiredTime = block.timestamp + 10 days; + GlobalProposal.TargetOption[] memory targetOptions = new GlobalProposal.TargetOption[](2); + uint256[] memory values = new uint256[](2); + bytes[] memory calldatas = new bytes[](2); + uint256[] memory gasAmounts = new uint256[](2); + + targetOptions[0] = GlobalProposal.TargetOption.BridgeManager; + values[0] = 0; + calldatas[0] = _addAxieChatGovernorAddress(); + gasAmounts[0] = 1_000_000; + + targetOptions[1] = GlobalProposal.TargetOption.BridgeManager; + values[1] = 0; + calldatas[1] = _removeAxieChatGovernorAddress(); + gasAmounts[1] = 1_000_000; + + // ================ VERIFY AND EXECUTE PROPOSAL =============== + + _verifyGlobalProposalGasAmount(targetOptions, values, calldatas, gasAmounts); + + vm.broadcast(_governor); + + // function proposeGlobal( + // uint256 expiryTimestamp, + // GlobalProposal.TargetOption[] calldata targetOptions, + // uint256[] calldata values, + // bytes[] calldata calldatas, + // uint256[] calldata gasAmounts) + _roninBridgeManager.proposeGlobal( + expiredTime, + targetOptions, + values, + calldatas, + gasAmounts + ); + } + + +} diff --git a/script/20240131-maptoken-pixel/maptoken-pixel-configs.s.sol b/script/20240131-maptoken-pixel/maptoken-pixel-configs.s.sol new file mode 100644 index 000000000..75a1ccf1a --- /dev/null +++ b/script/20240131-maptoken-pixel/maptoken-pixel-configs.s.sol @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; + +contract Migration__MapToken_Pixel_Config { + address constant _pixelRoninToken = address(0x7EAe20d11Ef8c779433Eb24503dEf900b9d28ad7); + address constant _pixelMainchainToken = address(0x3429d03c6F7521AeC737a0BBF2E5ddcef2C3Ae31); + + address constant _farmlandRoninToken = address(0xF083289535052E8449D69e6dc41c0aE064d8e3f6); + address constant _farmlandMainchainToken = address(0x5C1A0CC6DAdf4d0fB31425461df35Ba80fCBc110); + + // The decimal of PIXEL token is 18 + uint256 constant _highTierThreshold = 100_000_000 ether; + uint256 constant _lockedThreshold = 400_000_000 ether; + // The MAX_PERCENTAGE is 100_0000 + uint256 constant _unlockFeePercentages = 10; // 0.001% + uint256 constant _dailyWithdrawalLimit = 300_000_000 ether; + + uint256 constant _minThreshold = 10 ether; + + address constant _aggMainchainToken = address(0xFB0489e9753B045DdB35e39c6B0Cc02EC6b99AC5); + uint256 constant _aggMinThreshold = 1000 ether; + + address internal _governor = 0xe880802580a1fbdeF67ACe39D1B21c5b2C74f059; // TODO: replace by address of the SV governor +} \ No newline at end of file diff --git a/script/BridgeMigration.sol b/script/BridgeMigration.sol index 2f8662ba1..00f697822 100644 --- a/script/BridgeMigration.sol +++ b/script/BridgeMigration.sol @@ -3,9 +3,14 @@ pragma solidity ^0.8.19; import { console2 } from "forge-std/console2.sol"; import { BaseMigration } from "foundry-deployment-kit/BaseMigration.s.sol"; -import { GeneralConfigExtended } from "./GeneralConfigExtended.sol"; +import { TNetwork } from "foundry-deployment-kit/types/Types.sol"; + + import { RoninBridgeManager } from "@ronin/contracts/ronin/gateway/RoninBridgeManager.sol"; import { ErrorHandler } from "@ronin/contracts/libraries/ErrorHandler.sol"; +import { GlobalProposal } from "@ronin/contracts/libraries/GlobalProposal.sol"; + +import { GeneralConfigExtended } from "./GeneralConfigExtended.sol"; import { IGeneralConfigExtended } from "./IGeneralConfigExtended.sol"; import { Network } from "./utils/Network.sol"; import { Contract } from "./utils/Contract.sol"; @@ -26,12 +31,62 @@ contract BridgeMigration is BaseMigration { return ""; } + function _verifyGlobalProposalGasAmount( + GlobalProposal.TargetOption[] memory targetOptions, + uint256[] memory values, + bytes[] memory calldatas, + uint256[] memory gasAmounts + ) internal { + address[] memory roninTargets = new address[](targetOptions.length); + address[] memory mainchainTargets = new address[](targetOptions.length); + for (uint i; i < roninTargets.length; i++) { + roninTargets[i] = _resolveRoninTarget(targetOptions[i]); + mainchainTargets[i] = _resolveMainchainTarget(targetOptions[i]); + } + _verifyRoninProposalGasAmount(roninTargets, values, calldatas, gasAmounts); + _verifyMainchainProposalGasAmount(mainchainTargets, values, calldatas, gasAmounts); + } + + function _resolveRoninTarget(GlobalProposal.TargetOption targetOption) internal returns (address) { + _config.switchTo(DefaultNetwork.RoninMainnet.key()); + if (targetOption == GlobalProposal.TargetOption.BridgeManager) + return _config.getAddressFromCurrentNetwork(Contract.RoninBridgeManager.key()); + + if (targetOption == GlobalProposal.TargetOption.GatewayContract) + return _config.getAddressFromCurrentNetwork(Contract.RoninBridgeManager.key()); + + if (targetOption == GlobalProposal.TargetOption.BridgeReward) + return _config.getAddressFromCurrentNetwork(Contract.BridgeReward.key()); + + if (targetOption == GlobalProposal.TargetOption.BridgeSlash) + return _config.getAddressFromCurrentNetwork(Contract.BridgeSlash.key()); + + if (targetOption == GlobalProposal.TargetOption.BridgeTracking) + return _config.getAddressFromCurrentNetwork(Contract.BridgeTracking.key()); + + return address(0); + } + + function _resolveMainchainTarget(GlobalProposal.TargetOption targetOption) internal returns (address) { + _config.createFork(Network.EthMainnet.key()); + _config.switchTo(Network.EthMainnet.key()); + if (targetOption == GlobalProposal.TargetOption.BridgeManager) + return _config.getAddressFromCurrentNetwork(Contract.MainchainBridgeManager.key()); + + if (targetOption == GlobalProposal.TargetOption.GatewayContract) + return _config.getAddressFromCurrentNetwork(Contract.MainchainBridgeManager.key()); + + return address(0); + } + function _verifyRoninProposalGasAmount( address[] memory targets, uint256[] memory values, bytes[] memory calldatas, uint256[] memory gasAmounts ) internal { + _config.switchTo(DefaultNetwork.RoninMainnet.key()); + address roninBridgeManager = _config.getAddressFromCurrentNetwork(Contract.RoninBridgeManager.key()); uint256 snapshotId = vm.snapshot(); vm.startPrank(address(roninBridgeManager)); @@ -72,9 +127,13 @@ contract BridgeMigration is BaseMigration { uint256 gasUsed = gasleft(); (bool success, bytes memory returnOrRevertData) = targets[i].call{value: values[i]}(calldatas[i]); gasUsed = gasUsed - gasleft(); + if (success) { + console2.log("Call", i, ": gasUsed", gasUsed); + } else { + console2.log("Call", i, unicode": reverted. ❗ GasUsed", gasUsed); + } success.handleRevert(bytes4(calldatas[i]), returnOrRevertData); - console2.log("Call", i, ": gasUsed", gasUsed); if (gasUsed > gasAmounts[i]) { revert ErrProposalOutOfGas(bytes4(calldatas[i]), gasUsed); } From 6d9699effeaa2047a6a1174632fc76549dc0f6d6 Mon Sep 17 00:00:00 2001 From: nxqbao Date: Wed, 31 Jan 2024 15:47:41 +0700 Subject: [PATCH 3/8] script: add axie chat config --- .../update-axiechat-config.s.sol | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 script/20240131-maptoken-pixel/update-axiechat-config.s.sol diff --git a/script/20240131-maptoken-pixel/update-axiechat-config.s.sol b/script/20240131-maptoken-pixel/update-axiechat-config.s.sol new file mode 100644 index 000000000..85afd74da --- /dev/null +++ b/script/20240131-maptoken-pixel/update-axiechat-config.s.sol @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; + +import { IBridgeManager } from "@ronin/contracts/interfaces/bridge/IBridgeManager.sol"; + +contract Migration__Update_AxieChat_Config { + address constant _axieChatBridgeOperator = address(0x772112C7e5dD4ed663e844e79d77c1569a2E88ce); + address constant _axieChatGovernor = address(0x5832C3219c1dA998e828E1a2406B73dbFC02a70C); + + function _removeAxieChatGovernorAddress() pure internal returns (bytes memory) { + address[] memory bridgeOperator = new address[](1); + bridgeOperator[0] = _axieChatBridgeOperator; + + // function removeBridgeOperators( + // address[] calldata bridgeOperators + // ) + + return abi.encodeCall(IBridgeManager.removeBridgeOperators, ( + bridgeOperator + )); + } + + function _addAxieChatGovernorAddress() pure internal returns (bytes memory) { + uint96[] memory voteWeight = new uint96[](1); + address[] memory governor = new address[](1); + address[] memory bridgeOperator = new address[](1); + + voteWeight[0] = 100; + governor[0] = _axieChatGovernor; + bridgeOperator[0] = _axieChatBridgeOperator; + + // function addBridgeOperators( + // uint96[] calldata voteWeights, + // address[] calldata governors, + // address[] calldata bridgeOperators + // ) + + return abi.encodeCall(IBridgeManager.addBridgeOperators, ( + voteWeight, + governor, + bridgeOperator + )); + } +} \ No newline at end of file From 3ac0f7db2952bc73e49898ccb707e4db634c4b4b Mon Sep 17 00:00:00 2001 From: nxqbao Date: Wed, 31 Jan 2024 15:48:14 +0700 Subject: [PATCH 4/8] script: remove redundant proposal --- .../20240131-update-axiechat-governor.s.sol | 94 ------------------- 1 file changed, 94 deletions(-) delete mode 100644 script/20240131-maptoken-pixel/20240131-update-axiechat-governor.s.sol diff --git a/script/20240131-maptoken-pixel/20240131-update-axiechat-governor.s.sol b/script/20240131-maptoken-pixel/20240131-update-axiechat-governor.s.sol deleted file mode 100644 index 2366c8df4..000000000 --- a/script/20240131-maptoken-pixel/20240131-update-axiechat-governor.s.sol +++ /dev/null @@ -1,94 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -import { console2 } from "forge-std/console2.sol"; -import { StdStyle } from "forge-std/StdStyle.sol"; -import { BaseMigration } from "foundry-deployment-kit/BaseMigration.s.sol"; - -import { RoninBridgeManager } from "@ronin/contracts/ronin/gateway/RoninBridgeManager.sol"; -import { IRoninGatewayV3 } from "@ronin/contracts/interfaces/IRoninGatewayV3.sol"; -import { MinimumWithdrawal } from "@ronin/contracts/extensions/MinimumWithdrawal.sol"; -import { Token } from "@ronin/contracts/libraries/Token.sol"; -import { Ballot } from "@ronin/contracts/libraries/Ballot.sol"; -import { GlobalProposal } from "@ronin/contracts/libraries/GlobalProposal.sol"; -import { SignatureConsumer } from "@ronin/contracts/interfaces/consumers/SignatureConsumer.sol"; -import { IBridgeManager } from "@ronin/contracts/interfaces/bridge/IBridgeManager.sol"; - -import { Contract } from "../utils/Contract.sol"; -import { BridgeMigration } from "../BridgeMigration.sol"; -import { Network } from "../utils/Network.sol"; -import { Contract } from "../utils/Contract.sol"; -import { IGeneralConfigExtended } from "../IGeneralConfigExtended.sol"; - -import "forge-std/console2.sol"; - -import "./maptoken-pixel-configs.s.sol"; -import "./update-axiechat-config.s.sol"; - - -contract Migration__20240131_MapTokenPixelRoninchain is BridgeMigration, Migration__MapToken_Pixel_Config, Migration__Update_AxieChat_Config { - RoninBridgeManager internal _roninBridgeManager; - address internal _roninGatewayV3; - - address _cheatingGovernor; - - function setUp() public override { - super.setUp(); - _roninBridgeManager = RoninBridgeManager(_config.getAddressFromCurrentNetwork(Contract.RoninBridgeManager.key())); - _roninGatewayV3 = _config.getAddressFromCurrentNetwork(Contract.RoninGatewayV3.key()); - - _cheatingGovernor = makeAddr("cheat-governor"); - } - - function _cheatWeightGovernor(address gov) internal { - bytes32 $ = keccak256(abi.encode(gov, 0x88547008e60f5748911f2e59feb3093b7e4c2e87b2dd69d61f112fcc932de8e3)); - bytes32 opAndWeight = vm.load(address(_roninBridgeManager), $); - - uint256 totalWeight = _roninBridgeManager.getTotalWeight(); - bytes32 newOpAndWeight = bytes32((totalWeight << 160) + uint160(uint256(opAndWeight))); - vm.store(address(_roninBridgeManager), $, newOpAndWeight); - } - - function run() public { - _cheatWeightGovernor(_governor); - _cheatWeightGovernor(_cheatingGovernor); - - uint256 expiredTime = block.timestamp + 10 days; - GlobalProposal.TargetOption[] memory targetOptions = new GlobalProposal.TargetOption[](2); - uint256[] memory values = new uint256[](2); - bytes[] memory calldatas = new bytes[](2); - uint256[] memory gasAmounts = new uint256[](2); - - targetOptions[0] = GlobalProposal.TargetOption.BridgeManager; - values[0] = 0; - calldatas[0] = _addAxieChatGovernorAddress(); - gasAmounts[0] = 1_000_000; - - targetOptions[1] = GlobalProposal.TargetOption.BridgeManager; - values[1] = 0; - calldatas[1] = _removeAxieChatGovernorAddress(); - gasAmounts[1] = 1_000_000; - - // ================ VERIFY AND EXECUTE PROPOSAL =============== - - _verifyGlobalProposalGasAmount(targetOptions, values, calldatas, gasAmounts); - - vm.broadcast(_governor); - - // function proposeGlobal( - // uint256 expiryTimestamp, - // GlobalProposal.TargetOption[] calldata targetOptions, - // uint256[] calldata values, - // bytes[] calldata calldatas, - // uint256[] calldata gasAmounts) - _roninBridgeManager.proposeGlobal( - expiredTime, - targetOptions, - values, - calldatas, - gasAmounts - ); - } - - -} From a84dc5b4f27333afb0b926e4116f8606dde556ed Mon Sep 17 00:00:00 2001 From: nxqbao Date: Wed, 31 Jan 2024 15:59:45 +0700 Subject: [PATCH 5/8] script: fix comments --- .../20240131-maptoken-pixel-mainchain.s.sol | 2 +- .../20240131-maptoken-pixel-roninchain.s.sol | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/script/20240131-maptoken-pixel/20240131-maptoken-pixel-mainchain.s.sol b/script/20240131-maptoken-pixel/20240131-maptoken-pixel-mainchain.s.sol index 20e2dc27b..7a77f6b38 100644 --- a/script/20240131-maptoken-pixel/20240131-maptoken-pixel-mainchain.s.sol +++ b/script/20240131-maptoken-pixel/20240131-maptoken-pixel-mainchain.s.sol @@ -87,7 +87,7 @@ contract Migration__20240131_MapTokenPixelMainchain is BridgeMigration, Migratio calldatas[0] = proxyData; gasAmounts[0] = 1_000_000; - // ================ FARMLAND ERC-20 ====================== + // ================ FARMLAND ERC-721 ====================== mainchainTokens[0] = _farmlandMainchainToken; roninTokens[0] = _farmlandRoninToken; diff --git a/script/20240131-maptoken-pixel/20240131-maptoken-pixel-roninchain.s.sol b/script/20240131-maptoken-pixel/20240131-maptoken-pixel-roninchain.s.sol index b3c3d9c37..7ab56fb35 100644 --- a/script/20240131-maptoken-pixel/20240131-maptoken-pixel-roninchain.s.sol +++ b/script/20240131-maptoken-pixel/20240131-maptoken-pixel-roninchain.s.sol @@ -31,6 +31,8 @@ contract Migration__20240131_MapTokenPixelRoninchain is BridgeMigration, Migrati super.setUp(); _roninBridgeManager = RoninBridgeManager(_config.getAddressFromCurrentNetwork(Contract.RoninBridgeManager.key())); _roninGatewayV3 = _config.getAddressFromCurrentNetwork(Contract.RoninGatewayV3.key()); + + _cheatWeightOperator(_governor); } function _cheatWeightOperator(address gov) internal { @@ -43,8 +45,6 @@ contract Migration__20240131_MapTokenPixelRoninchain is BridgeMigration, Migrati } function run() public { - _cheatWeightOperator(_governor); - address[] memory roninTokens = new address[](2); address[] memory mainchainTokens = new address[](2); uint256[] memory chainIds = new uint256[](2); @@ -56,7 +56,7 @@ contract Migration__20240131_MapTokenPixelRoninchain is BridgeMigration, Migrati bytes[] memory calldatas = new bytes[](4); uint256[] memory gasAmounts = new uint256[](4); - // ============= MAP PIXEL TOKEN =========== + // ============= MAP PIXEL TOKEN AND FARMLAND =========== roninTokens[0] = _pixelRoninToken; mainchainTokens[0] = _pixelMainchainToken; From a6a23b36237e8f7fdb635cb7b9c12cc74c2a7491 Mon Sep 17 00:00:00 2001 From: Bao Date: Wed, 31 Jan 2024 17:59:33 +0700 Subject: [PATCH 6/8] Update script/20240131-maptoken-pixel/maptoken-pixel-configs.s.sol Co-authored-by: Duke.ron --- script/20240131-maptoken-pixel/maptoken-pixel-configs.s.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/20240131-maptoken-pixel/maptoken-pixel-configs.s.sol b/script/20240131-maptoken-pixel/maptoken-pixel-configs.s.sol index 75a1ccf1a..332c59dc0 100644 --- a/script/20240131-maptoken-pixel/maptoken-pixel-configs.s.sol +++ b/script/20240131-maptoken-pixel/maptoken-pixel-configs.s.sol @@ -12,7 +12,7 @@ contract Migration__MapToken_Pixel_Config { uint256 constant _highTierThreshold = 100_000_000 ether; uint256 constant _lockedThreshold = 400_000_000 ether; // The MAX_PERCENTAGE is 100_0000 - uint256 constant _unlockFeePercentages = 10; // 0.001% + uint256 constant _unlockFeePercentages = 10; // 0.001%. Max percentage is 1e6 so 10 is 0.001% (`10 / 1e6 = 0.001 * 100`) uint256 constant _dailyWithdrawalLimit = 300_000_000 ether; uint256 constant _minThreshold = 10 ether; From cd90380cb82e7d2f8e9027ad22009de4770a5252 Mon Sep 17 00:00:00 2001 From: nxqbao Date: Wed, 31 Jan 2024 18:05:49 +0700 Subject: [PATCH 7/8] script: fix typo --- .../20240131-maptoken-pixel-roninchain.s.sol | 2 +- script/20240131-maptoken-pixel/maptoken-pixel-configs.s.sol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/script/20240131-maptoken-pixel/20240131-maptoken-pixel-roninchain.s.sol b/script/20240131-maptoken-pixel/20240131-maptoken-pixel-roninchain.s.sol index 7ab56fb35..5a2bbb970 100644 --- a/script/20240131-maptoken-pixel/20240131-maptoken-pixel-roninchain.s.sol +++ b/script/20240131-maptoken-pixel/20240131-maptoken-pixel-roninchain.s.sol @@ -96,7 +96,7 @@ contract Migration__20240131_MapTokenPixelRoninchain is BridgeMigration, Migrati uint256[] memory minThresholds = new uint256[](2); mainchainTokensToSetMinThreshold[0] = _pixelMainchainToken; - minThresholds[0] = _minThreshold; + minThresholds[0] = _pixelMinThreshold; mainchainTokensToSetMinThreshold[1] = _aggMainchainToken; minThresholds[1] = _aggMinThreshold; diff --git a/script/20240131-maptoken-pixel/maptoken-pixel-configs.s.sol b/script/20240131-maptoken-pixel/maptoken-pixel-configs.s.sol index 332c59dc0..7ba0fbfd9 100644 --- a/script/20240131-maptoken-pixel/maptoken-pixel-configs.s.sol +++ b/script/20240131-maptoken-pixel/maptoken-pixel-configs.s.sol @@ -15,7 +15,7 @@ contract Migration__MapToken_Pixel_Config { uint256 constant _unlockFeePercentages = 10; // 0.001%. Max percentage is 1e6 so 10 is 0.001% (`10 / 1e6 = 0.001 * 100`) uint256 constant _dailyWithdrawalLimit = 300_000_000 ether; - uint256 constant _minThreshold = 10 ether; + uint256 constant _pixelMinThreshold = 10 ether; address constant _aggMainchainToken = address(0xFB0489e9753B045DdB35e39c6B0Cc02EC6b99AC5); uint256 constant _aggMinThreshold = 1000 ether; From 212253079258c9bae5c187c270e8c7f00848588b Mon Sep 17 00:00:00 2001 From: nxqbao Date: Wed, 31 Jan 2024 18:09:00 +0700 Subject: [PATCH 8/8] script: swap remove and add --- .../20240131-maptoken-pixel-mainchain.s.sol | 4 ++-- .../20240131-maptoken-pixel-roninchain.s.sol | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/script/20240131-maptoken-pixel/20240131-maptoken-pixel-mainchain.s.sol b/script/20240131-maptoken-pixel/20240131-maptoken-pixel-mainchain.s.sol index 7a77f6b38..1101126ed 100644 --- a/script/20240131-maptoken-pixel/20240131-maptoken-pixel-mainchain.s.sol +++ b/script/20240131-maptoken-pixel/20240131-maptoken-pixel-mainchain.s.sol @@ -115,12 +115,12 @@ contract Migration__20240131_MapTokenPixelMainchain is BridgeMigration, Migratio // =============== AXIE CHAT UPDATE =========== targets[2] = _mainchainBridgeManager; values[2] = 0; - calldatas[2] = _addAxieChatGovernorAddress(); + calldatas[2] = _removeAxieChatGovernorAddress(); gasAmounts[2] = 1_000_000; targets[3] = _mainchainBridgeManager; values[3] = 0; - calldatas[3] = _removeAxieChatGovernorAddress(); + calldatas[3] = _addAxieChatGovernorAddress(); gasAmounts[3] = 1_000_000; // ================ VERIFY AND EXECUTE PROPOSAL =============== diff --git a/script/20240131-maptoken-pixel/20240131-maptoken-pixel-roninchain.s.sol b/script/20240131-maptoken-pixel/20240131-maptoken-pixel-roninchain.s.sol index 5a2bbb970..607a728fb 100644 --- a/script/20240131-maptoken-pixel/20240131-maptoken-pixel-roninchain.s.sol +++ b/script/20240131-maptoken-pixel/20240131-maptoken-pixel-roninchain.s.sol @@ -115,12 +115,12 @@ contract Migration__20240131_MapTokenPixelRoninchain is BridgeMigration, Migrati // =============== AXIE CHAT UPDATE =========== targets[2] = address(_roninBridgeManager); values[2] = 0; - calldatas[2] = _addAxieChatGovernorAddress(); + calldatas[2] = _removeAxieChatGovernorAddress(); gasAmounts[2] = 1_000_000; targets[3] = address(_roninBridgeManager); values[3] = 0; - calldatas[3] = _removeAxieChatGovernorAddress(); + calldatas[3] = _addAxieChatGovernorAddress(); gasAmounts[3] = 1_000_000; // ================ VERIFY AND EXECUTE PROPOSAL ===============