From 2d885a8819cf1df7580b8ede7aa0114288b2b79c Mon Sep 17 00:00:00 2001 From: nxqbao Date: Tue, 6 Feb 2024 14:10:12 +0700 Subject: [PATCH] proposal: mapping token for banana, vx, genkai and change stable node GV --- .../20240206-maptoken-banana-roninchain.s.sol | 154 ++++++++++++++++++ .../changeGV-stablenode-config.s.sol | 38 +++++ .../maptoken-banana-configs.s.sol | 18 ++ .../maptoken-genkai-configs.s.sol | 7 + .../maptoken-vx-configs.s.sol | 7 + 5 files changed, 224 insertions(+) create mode 100644 script/20240206-maptoken-banana/20240206-maptoken-banana-roninchain.s.sol create mode 100644 script/20240206-maptoken-banana/changeGV-stablenode-config.s.sol create mode 100644 script/20240206-maptoken-banana/maptoken-banana-configs.s.sol create mode 100644 script/20240206-maptoken-banana/maptoken-genkai-configs.s.sol create mode 100644 script/20240206-maptoken-banana/maptoken-vx-configs.s.sol diff --git a/script/20240206-maptoken-banana/20240206-maptoken-banana-roninchain.s.sol b/script/20240206-maptoken-banana/20240206-maptoken-banana-roninchain.s.sol new file mode 100644 index 00000000..5e53e1ae --- /dev/null +++ b/script/20240206-maptoken-banana/20240206-maptoken-banana-roninchain.s.sol @@ -0,0 +1,154 @@ +// 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 {Proposal} from "@ronin/contracts/libraries/Proposal.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-banana-configs.s.sol"; +import "./maptoken-genkai-configs.s.sol"; +import "./maptoken-vx-configs.s.sol"; +import "./changeGV-stablenode-config.s.sol"; + +contract Migration__20240206_MapTokenBananaRoninChain is + BridgeMigration, + Migration__MapToken_Banana_Config, + Migration__MapToken_Vx_Config, + Migration__MapToken_Genkai_Config, + Migration__ChangeGV_StableNode_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 { + address[] memory roninTokens = new address[](3); + address[] memory mainchainTokens = new address[](3); + uint256[] memory chainIds = new uint256[](3); + Token.Standard[] memory standards = new Token.Standard[](3); + + 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 NEW BANANA, VX, GENKAI TOKEN =========== + + roninTokens[0] = _bananaRoninToken; + mainchainTokens[0] = _bananaMainchainToken; + chainIds[0] = _config.getCompanionNetwork(_config.getNetworkByChainId(block.chainid)).chainId(); + standards[0] = Token.Standard.ERC20; + + roninTokens[1] = _VxRoninToken; + mainchainTokens[1] = _VxMainchainToken; + chainIds[1] = _config.getCompanionNetwork(_config.getNetworkByChainId(block.chainid)).chainId(); + standards[1] = Token.Standard.ERC721; + + roninTokens[2] = _genkaiRoninToken; + mainchainTokens[2] = _genkaiMainchainToken; + chainIds[2] = _config.getCompanionNetwork(_config.getNetworkByChainId(block.chainid)).chainId(); + standards[2] = 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 FOR BANANA ============ + // function setMinimumThresholds( + // address[] calldata _tokens, + // uint256[] calldata _thresholds + // ); + address[] memory mainchainTokensToSetMinThreshold = new address[](1); + uint256[] memory minThresholds = new uint256[](1); + + mainchainTokensToSetMinThreshold[0] = _bananaMainchainToken; + minThresholds[0] = _bananaMinThreshold; + + 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] = _removeStableNodeGovernorAddress(); + gasAmounts[2] = 1_000_000; + + targets[3] = address(_roninBridgeManager); + values[3] = 0; + calldatas[3] = _addStableNodeGovernorAddress(); + 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); + + + // ============= LOCAL SIMULATION ================== + _cheatWeightOperator(_governor); + + Proposal.ProposalDetail memory cheatingProposal; + cheatingProposal.nonce = 3; + cheatingProposal.chainId = block.chainid; + cheatingProposal.expiryTimestamp = expiredTime; + cheatingProposal.targets = targets; + cheatingProposal.values = values; + cheatingProposal.calldatas = calldatas; + cheatingProposal.gasAmounts = gasAmounts; + + Ballot.VoteType cheatingSupport = Ballot.VoteType.For; + + vm.prank(_governor); + _roninBridgeManager.castProposalVoteForCurrentNetwork(cheatingProposal, cheatingSupport); + } +} + +// ./run.sh script/20240206-maptoken-banana/20240206-maptoken-banana-roninchain.s.sol -f ronin-mainnet --fork-block-number 31791206 -vvvv diff --git a/script/20240206-maptoken-banana/changeGV-stablenode-config.s.sol b/script/20240206-maptoken-banana/changeGV-stablenode-config.s.sol new file mode 100644 index 00000000..ce9ce487 --- /dev/null +++ b/script/20240206-maptoken-banana/changeGV-stablenode-config.s.sol @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; + +import {IBridgeManager} from "@ronin/contracts/interfaces/bridge/IBridgeManager.sol"; + +contract Migration__ChangeGV_StableNode_Config { + address constant _stableNodeBridgeOperator = address(0x564DcB855Eb360826f27D1Eb9c57cbbe6C76F50F); + address constant _stableNodeGovernor = address(0x3C583c0c97646a73843aE57b93f33e1995C8DC80); + + function _removeStableNodeGovernorAddress() internal pure returns (bytes memory) { + address[] memory bridgeOperator = new address[](1); + bridgeOperator[0] = _stableNodeBridgeOperator; + + // function removeBridgeOperators( + // address[] calldata bridgeOperators + // ) + + return abi.encodeCall(IBridgeManager.removeBridgeOperators, (bridgeOperator)); + } + + function _addStableNodeGovernorAddress() internal pure 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] = _stableNodeGovernor; + bridgeOperator[0] = _stableNodeBridgeOperator; + + // function addBridgeOperators( + // uint96[] calldata voteWeights, + // address[] calldata governors, + // address[] calldata bridgeOperators + // ) + + return abi.encodeCall(IBridgeManager.addBridgeOperators, (voteWeight, governor, bridgeOperator)); + } +} diff --git a/script/20240206-maptoken-banana/maptoken-banana-configs.s.sol b/script/20240206-maptoken-banana/maptoken-banana-configs.s.sol new file mode 100644 index 00000000..e27d3176 --- /dev/null +++ b/script/20240206-maptoken-banana/maptoken-banana-configs.s.sol @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; + +contract Migration__MapToken_Banana_Config { + address constant _bananaRoninToken = address(0x1a89ecd466a23e98f07111b0510a2D6c1cd5E400); + address constant _bananaMainchainToken = address(0x94e496474F1725f1c1824cB5BDb92d7691A4F03a); + + // The decimal of BANANA token is 18 + uint256 constant _highTierThreshold = 100_000 ether; + uint256 constant _lockedThreshold = 600_000 ether; + // The MAX_PERCENTAGE is 100_0000 + uint256 constant _unlockFeePercentages = 10; // 0.001%. Max percentage is 1e6 so 10 is 0.001% (`10 / 1e6 = 0.001 * 100`) + uint256 constant _dailyWithdrawalLimit = 500_000 ether; + + uint256 constant _bananaMinThreshold = 10 ether; + + address internal _governor = 0xe880802580a1fbdeF67ACe39D1B21c5b2C74f059; // TODO: replace by address of the SV governor +} diff --git a/script/20240206-maptoken-banana/maptoken-genkai-configs.s.sol b/script/20240206-maptoken-banana/maptoken-genkai-configs.s.sol new file mode 100644 index 00000000..6d526790 --- /dev/null +++ b/script/20240206-maptoken-banana/maptoken-genkai-configs.s.sol @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; + +contract Migration__MapToken_Genkai_Config { + address constant _genkaiRoninToken = address(0x1F7c16FCe4fC894143aFB5545Bf04f676bf7DCf3); + address constant _genkaiMainchainToken = address(0x1F7c16FCe4fC894143aFB5545Bf04f676bf7DCf3); +} diff --git a/script/20240206-maptoken-banana/maptoken-vx-configs.s.sol b/script/20240206-maptoken-banana/maptoken-vx-configs.s.sol new file mode 100644 index 00000000..b712c7bc --- /dev/null +++ b/script/20240206-maptoken-banana/maptoken-vx-configs.s.sol @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; + +contract Migration__MapToken_Vx_Config { + address constant _VxRoninToken = address(0x241A81fC0d6692707DAd2B5025a3a7CF2CF25aCF); + address constant _VxMainchainToken = address(0x7EA3Cca10668B8346aeC0bf1844A49e995527c8B); +}