Skip to content

Commit

Permalink
Merge pull request #24 from axieinfinity/proposal/map-pixel-token-and…
Browse files Browse the repository at this point in the history
…-change-governor-axiechat

proposal: map pixel token and change governor axiechat
  • Loading branch information
ducthotran2010 authored Jan 31, 2024
2 parents 610076e + 2122530 commit 111de60
Show file tree
Hide file tree
Showing 6 changed files with 413 additions and 4 deletions.
142 changes: 142 additions & 0 deletions script/20240131-maptoken-pixel/20240131-maptoken-pixel-mainchain.s.sol
Original file line number Diff line number Diff line change
@@ -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-721 ======================

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] = _removeAxieChatGovernorAddress();
gasAmounts[2] = 1_000_000;

targets[3] = _mainchainBridgeManager;
values[3] = 0;
calldatas[3] = _addAxieChatGovernorAddress();
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
);
}
}
Original file line number Diff line number Diff line change
@@ -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());

_cheatWeightOperator(_governor);
}

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[](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 AND FARMLAND ===========

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] = _pixelMinThreshold;

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] = _removeAxieChatGovernorAddress();
gasAmounts[2] = 1_000_000;

targets[3] = address(_roninBridgeManager);
values[3] = 0;
calldatas[3] = _addAxieChatGovernorAddress();
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
);
}
}
24 changes: 24 additions & 0 deletions script/20240131-maptoken-pixel/maptoken-pixel-configs.s.sol
Original file line number Diff line number Diff line change
@@ -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%. Max percentage is 1e6 so 10 is 0.001% (`10 / 1e6 = 0.001 * 100`)
uint256 constant _dailyWithdrawalLimit = 300_000_000 ether;

uint256 constant _pixelMinThreshold = 10 ether;

address constant _aggMainchainToken = address(0xFB0489e9753B045DdB35e39c6B0Cc02EC6b99AC5);
uint256 constant _aggMinThreshold = 1000 ether;

address internal _governor = 0xe880802580a1fbdeF67ACe39D1B21c5b2C74f059; // TODO: replace by address of the SV governor
}
44 changes: 44 additions & 0 deletions script/20240131-maptoken-pixel/update-axiechat-config.s.sol
Original file line number Diff line number Diff line change
@@ -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
));
}
}
Loading

0 comments on commit 111de60

Please sign in to comment.