Skip to content

Commit

Permalink
Merge pull request #26 from axieinfinity/proposal/map-pixel-token-tes…
Browse files Browse the repository at this point in the history
…tnet

script: change pixel saigon token
  • Loading branch information
nxqbao authored Feb 6, 2024
2 parents 610076e + f3a0b42 commit 524527c
Show file tree
Hide file tree
Showing 5 changed files with 559 additions and 3 deletions.
332 changes: 332 additions & 0 deletions deployments/ronin-testnet/RoninGatewayV3Proxy.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// 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";

contract Migration__20240201_MapTokenPixelMainchainTestnet is BridgeMigration, Migration__MapToken_Pixel_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 expiredTime = block.timestamp + 10 minutes;
address[] memory targets = new address[](1);
uint256[] memory values = new uint256[](1);
bytes[] memory calldatas = new bytes[](1);
uint256[] memory gasAmounts = new uint256[](1);

// ================ PIXEL ERC-20 ======================

mainchainTokens[0] = _pixelMainchainToken;
roninTokens[0] = _pixelNewRoninToken;
standards[0] = Token.Standard.ERC20;

// function mapTokens(
// address[] calldata _mainchainTokens,
// address[] calldata _roninTokens,
// Token.Standard[] calldata _standards
// )

bytes memory innerData = abi.encodeCall(IMainchainGatewayV3.mapTokens, (
mainchainTokens,
roninTokens,
standards
));

bytes memory proxyData = abi.encodeWithSignature("functionDelegateCall(bytes)", innerData);

targets[0] = _mainchainGatewayV3;
values[0] = 0;
calldatas[0] = proxyData;
gasAmounts[0] = 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,109 @@
// 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";

contract Migration__20240201_MapTokenPixelRoninchainTestnet is BridgeMigration, Migration__MapToken_Pixel_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 minutes;
address[] memory targets = new address[](1);
uint256[] memory values = new uint256[](1);
bytes[] memory calldatas = new bytes[](1);
uint256[] memory gasAmounts = new uint256[](1);



// ============= DELETE OLD PIXEL TOKEN ===========

roninTokens[0] = _pixelOldRoninToken;
mainchainTokens[0] = address(0);
chainIds[0] = _config.getCompanionNetwork(_config.getNetworkByChainId(block.chainid)).chainId();
standards[0] = Token.Standard.ERC20;

// ============= MAP NEW PIXEL TOKEN ===========

roninTokens[1] = _pixelNewRoninToken;
mainchainTokens[1] = _pixelMainchainToken;
chainIds[1] = _config.getCompanionNetwork(_config.getNetworkByChainId(block.chainid)).chainId();
standards[1] = Token.Standard.ERC20;

// 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;

// ================ VERIFY AND EXECUTE PROPOSAL ===============

_verifyRoninProposalGasAmount(targets, values, calldatas, gasAmounts);

vm.broadcast(_governor);
_roninBridgeManager.propose(
block.chainid,
expiredTime,
targets,
values,
calldatas,
gasAmounts
);
}
}

// ./run.sh script/20240201-maptoken-pixel-saigon/20240201-maptoken-pixel-roninchain.s.sol -f ronin-testnet --fork-block-number 24353280 -vvvv
19 changes: 19 additions & 0 deletions script/20240201-maptoken-pixel-saigon/maptoken-pixel-configs.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

contract Migration__MapToken_Pixel_Config {
address constant _pixelOldRoninToken = address(0xfBca6b939E2c4D86477a1E836372f9936ABB8245);
address constant _pixelNewRoninToken = address(0x253eF7651433ca9cA5dE487e1661a27080E85A83);
address constant _pixelMainchainToken = address(0x49337E7414F8B968EA5478B68F1b6D0A2706cba1);

// 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 internal _governor = 0xd24D87DDc1917165435b306aAC68D99e0F49A3Fa; // TODO: replace by address of the SV governor
}
12 changes: 9 additions & 3 deletions script/BridgeMigration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { IGeneralConfigExtended } from "./IGeneralConfigExtended.sol";
import { Network } from "./utils/Network.sol";
import { Contract } from "./utils/Contract.sol";
import { DefaultNetwork } from "foundry-deployment-kit/utils/DefaultNetwork.sol";
import { TNetwork } from "foundry-deployment-kit/types/Types.sol";

contract BridgeMigration is BaseMigration {
using ErrorHandler for bool;
Expand Down Expand Up @@ -46,8 +47,11 @@ contract BridgeMigration is BaseMigration {
bytes[] memory calldatas,
uint256[] memory gasAmounts
) internal {
_config.createFork(Network.EthMainnet.key());
_config.switchTo(Network.EthMainnet.key());
TNetwork roninNetwork = _config.getNetworkByChainId(block.chainid);
TNetwork companionNetwork = _config.getCompanionNetwork(roninNetwork).key();

_config.createFork(companionNetwork);
_config.switchTo(companionNetwork);

address mainchainBridgeManager = _config.getAddressFromCurrentNetwork(Contract.MainchainBridgeManager.key());
uint256 snapshotId = vm.snapshot();
Expand All @@ -57,7 +61,7 @@ contract BridgeMigration is BaseMigration {
vm.stopPrank();
vm.revertTo(snapshotId);

_config.switchTo(DefaultNetwork.RoninMainnet.key());
_config.switchTo(roninNetwork);
}

function _verifyProposalGasAmount(
Expand All @@ -67,6 +71,8 @@ contract BridgeMigration is BaseMigration {
bytes[] memory calldatas,
uint256[] memory gasAmounts
) private {
console2.log("Verifying proposal gas amount...");

for (uint256 i; i < targets.length; i++) {
vm.deal(address(bridgeManager), values[i]);
uint256 gasUsed = gasleft();
Expand Down

0 comments on commit 524527c

Please sign in to comment.