-
Notifications
You must be signed in to change notification settings - Fork 3
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
script: map aprs and ygg token #13
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
script/20240308-maptoken-aperios/20240308-maptoken-aperios-mainchain.s.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import "../factories/factory-maptoken-mainchain.s.sol"; | ||
import "./base-maptoken.s.sol"; | ||
|
||
contract Migration__20240308_MapTokenAperiosMainchain is Base__MapToken, Factory__MapTokensMainchain { | ||
function _initCaller() internal override(Base__MapToken, Factory__MapTokensMainchain) returns (address) { | ||
return Base__MapToken._initCaller(); | ||
} | ||
|
||
function _initTokenList() | ||
internal | ||
override(Base__MapToken, Factory__MapTokensMainchain) | ||
returns (uint256 totalToken, MapTokenInfo[] memory infos) | ||
{ | ||
return Base__MapToken._initTokenList(); | ||
} | ||
|
||
function run() public override { | ||
super.run(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
script/20240308-maptoken-aperios/20240308-maptoken-aperios-roninchain.s.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import "../factories/factory-maptoken-roninchain.s.sol"; | ||
import "./base-maptoken.s.sol"; | ||
|
||
contract Migration__20240308_MapTokenAperiosRoninchain is Base__MapToken, Factory__MapTokensRoninchain { | ||
function _initCaller() internal override(Base__MapToken, Factory__MapTokensRoninchain) returns (address) { | ||
return Base__MapToken._initCaller(); | ||
} | ||
|
||
function _initTokenList() | ||
internal | ||
override(Base__MapToken, Factory__MapTokensRoninchain) | ||
returns (uint256 totalToken, MapTokenInfo[] memory infos) | ||
{ | ||
return Base__MapToken._initTokenList(); | ||
} | ||
|
||
function run() public override { | ||
super.run(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import "forge-std/console2.sol"; | ||
|
||
import "./caller-configs.s.sol"; | ||
import "./maptoken-aperios-configs.s.sol"; | ||
import "./maptoken-ygg-configs.s.sol"; | ||
|
||
contract Base__MapToken is | ||
Migration__Caller_Config, | ||
Migration__MapToken_Aperios_Config, | ||
Migration__MapToken_Ygg_Config | ||
{ | ||
function _initCaller() internal virtual returns(address) { | ||
return SM_GOVERNOR; | ||
} | ||
|
||
function _initTokenList() internal virtual returns (uint256 totalToken, MapTokenInfo[] memory infos) { | ||
totalToken = 2; | ||
|
||
infos = new MapTokenInfo[](totalToken); | ||
infos[0] = _aperiosInfo; | ||
infos[1] = _yggInfo; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
contract Migration__Caller_Config { | ||
address internal SM_GOVERNOR = 0xe880802580a1fbdeF67ACe39D1B21c5b2C74f059; // TODO: replace by address of the SV governor | ||
} |
18 changes: 18 additions & 0 deletions
18
script/20240308-maptoken-aperios/maptoken-aperios-configs.s.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import { MapTokenInfo } from "../libraries/MapTokenInfo.sol"; | ||
|
||
contract Migration__MapToken_Aperios_Config { | ||
MapTokenInfo _aperiosInfo; | ||
|
||
constructor () { | ||
_aperiosInfo.roninToken = address(0x7894b3088d069E70895EFfA4e8f7D2c243Fd04C1); | ||
_aperiosInfo.mainchainToken = address(0x95b4B8CaD3567B5d7EF7399C2aE1d7070692aB0D); | ||
_aperiosInfo.minThreshold = 10 ether; | ||
_aperiosInfo.highTierThreshold = 10_000_000 ether; | ||
_aperiosInfo.lockedThreshold = 40_000_000 ether; | ||
_aperiosInfo.dailyWithdrawalLimit = 30_000_000 ether; | ||
_aperiosInfo.unlockFeePercentages = 10; // 0.001%. Max percentage is 100_0000, so 10 is 0.001% (`10 / 1e6 = 0.001 * 100`) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
script/20240308-maptoken-aperios/maptoken-ygg-configs.s.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import { MapTokenInfo } from "../libraries/MapTokenInfo.sol"; | ||
|
||
contract Migration__MapToken_Ygg_Config { | ||
MapTokenInfo _yggInfo; | ||
|
||
constructor () { | ||
_yggInfo.roninToken = address(0x1c306872bC82525d72Bf3562E8F0aA3f8F26e857); | ||
_yggInfo.mainchainToken = address(0x25f8087EAD173b73D6e8B84329989A8eEA16CF73); | ||
_yggInfo.minThreshold = 20 ether; | ||
_yggInfo.highTierThreshold = 1_000_000 ether; | ||
_yggInfo.lockedThreshold = 2_000_000 ether; | ||
_yggInfo.dailyWithdrawalLimit = 2_000_000 ether; | ||
_yggInfo.unlockFeePercentages = 10; // 0.001%. Max percentage is 100_0000, so 10 is 0.001% (`10 / 1e6 = 0.001 * 100`) | ||
} | ||
Comment on lines
+9
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Matched |
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// 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 { MapTokenInfo } from "../libraries/MapTokenInfo.sol"; | ||
|
||
abstract contract Factory__MapTokensMainchain is BridgeMigration { | ||
RoninBridgeManager internal _roninBridgeManager; | ||
address internal _mainchainGatewayV3; | ||
address internal _mainchainBridgeManager; | ||
address private _governor; | ||
|
||
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() | ||
); | ||
|
||
_governor = _initCaller(); | ||
} | ||
|
||
function _initCaller() internal virtual returns (address); | ||
function _initTokenList() internal virtual returns (uint256 totalToken, MapTokenInfo[] memory infos); | ||
|
||
function run() public virtual { | ||
(uint256 N, MapTokenInfo[] memory tokenInfos) = _initTokenList(); | ||
|
||
address[] memory mainchainTokens = new address[](N); | ||
address[] memory roninTokens = new address[](N); | ||
Token.Standard[] memory standards = new Token.Standard[](N); | ||
uint256[][4] memory thresholds; | ||
thresholds[0] = new uint256[](N); | ||
thresholds[1] = new uint256[](N); | ||
thresholds[2] = new uint256[](N); | ||
thresholds[3] = new uint256[](N); | ||
|
||
uint256 expiredTime = block.timestamp + 14 days; | ||
address[] memory targets = new address[](1); | ||
uint256[] memory values = new uint256[](1); | ||
bytes[] memory calldatas = new bytes[](1); | ||
uint256[] memory gasAmounts = new uint256[](1); | ||
|
||
// ================ APERIOS AND YGG ERC-20 ====================== | ||
|
||
for (uint256 i; i < N; ++i) { | ||
mainchainTokens[i] = tokenInfos[i].mainchainToken; | ||
roninTokens[i] = tokenInfos[i].roninToken; | ||
standards[i] = Token.Standard.ERC20; | ||
thresholds[0][i] = tokenInfos[i].highTierThreshold; | ||
thresholds[1][i] = tokenInfos[i].lockedThreshold; | ||
thresholds[2][i] = tokenInfos[i].unlockFeePercentages; | ||
thresholds[3][i] = tokenInfos[i].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; | ||
|
||
// ================ 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// 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 { MapTokenInfo } from "../libraries/MapTokenInfo.sol"; | ||
|
||
abstract contract Factory__MapTokensRoninchain is BridgeMigration { | ||
RoninBridgeManager internal _roninBridgeManager; | ||
address internal _roninGatewayV3; | ||
address private _governor; | ||
|
||
function setUp() public override { | ||
super.setUp(); | ||
_roninBridgeManager = RoninBridgeManager(_config.getAddressFromCurrentNetwork(Contract.RoninBridgeManager.key())); | ||
_roninGatewayV3 = _config.getAddressFromCurrentNetwork(Contract.RoninGatewayV3.key()); | ||
|
||
_governor = _initCaller(); | ||
_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 _initCaller() internal virtual returns (address); | ||
function _initTokenList() internal virtual returns (uint256 totalToken, MapTokenInfo[] memory infos); | ||
|
||
function run() public virtual { | ||
(uint256 N, MapTokenInfo[] memory tokenInfos) = _initTokenList(); | ||
|
||
address[] memory roninTokens = new address[](N); | ||
address[] memory mainchainTokens = new address[](N); | ||
uint256[] memory chainIds = new uint256[](N); | ||
Token.Standard[] memory standards = new Token.Standard[](N); | ||
|
||
uint256 expiredTime = block.timestamp + 14 days; | ||
address[] memory targets = new address[](2); | ||
uint256[] memory values = new uint256[](2); | ||
bytes[] memory calldatas = new bytes[](2); | ||
uint256[] memory gasAmounts = new uint256[](2); | ||
|
||
// ============= MAP TOKENS =========== | ||
|
||
for (uint256 i; i < N; ++i) { | ||
roninTokens[i] = tokenInfos[i].roninToken; | ||
mainchainTokens[i] = tokenInfos[i].mainchainToken; | ||
chainIds[i] = _config.getCompanionNetwork(_config.getNetworkByChainId(block.chainid)).chainId(); | ||
standards[i] = 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; | ||
|
||
// ============= SET MIN THRESHOLD ============ | ||
// function setMinimumThresholds( | ||
// address[] calldata _tokens, | ||
// uint256[] calldata _thresholds | ||
// ); | ||
address[] memory mainchainTokensToSetMinThreshold = new address[](N); | ||
uint256[] memory minThresholds = new uint256[](N); | ||
|
||
for (uint256 i; i < N; ++i) { | ||
mainchainTokensToSetMinThreshold[i] = tokenInfos[i].mainchainToken; | ||
minThresholds[i] = tokenInfos[i].minThreshold; | ||
} | ||
|
||
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; | ||
|
||
// ================ VERIFY AND EXECUTE PROPOSAL =============== | ||
|
||
_verifyRoninProposalGasAmount(targets, values, calldatas, gasAmounts); | ||
|
||
vm.broadcast(_governor); | ||
_roninBridgeManager.propose(block.chainid, expiredTime, targets, values, calldatas, gasAmounts); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
struct MapTokenInfo { | ||
address roninToken; | ||
address mainchainToken; | ||
|
||
// Config on mainchain | ||
uint256 minThreshold; | ||
|
||
// Config on ronin chain | ||
uint256 highTierThreshold; | ||
uint256 lockedThreshold; | ||
uint256 dailyWithdrawalLimit; | ||
uint256 unlockFeePercentages; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Matched