Skip to content
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

fix(RoninBridgeManager, MainchainBridgeManager): expose map tokens fu… #53

Merged
84 changes: 49 additions & 35 deletions src/mainchain/MainchainBridgeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { CoreGovernance } from "../extensions/sequential-governance/CoreGovernan
import { GlobalCoreGovernance, GlobalGovernanceRelay } from "../extensions/sequential-governance/governance-relay/GlobalGovernanceRelay.sol";
import { GovernanceRelay } from "../extensions/sequential-governance/governance-relay/GovernanceRelay.sol";
import { ContractType, BridgeManager } from "../extensions/bridge-operator-governance/BridgeManager.sol";
import { IMainchainGatewayV3 } from "../interfaces/IMainchainGatewayV3.sol";
import { TokenStandard } from "../libraries/LibTokenInfo.sol";
import { Ballot } from "../libraries/Ballot.sol";
import { Proposal } from "../libraries/Proposal.sol";
import { GlobalProposal } from "../libraries/GlobalProposal.sol";
Expand All @@ -24,10 +26,44 @@ contract MainchainBridgeManager is BridgeManager, GovernanceRelay, GlobalGoverna
uint96[] memory voteWeights,
GlobalProposal.TargetOption[] memory targetOptions,
address[] memory targets
) external initializer {
__CoreGovernance_init(DEFAULT_EXPIRY_DURATION);
__GlobalCoreGovernance_init(targetOptions, targets);
__BridgeManager_init(num, denom, roninChainId, bridgeContract, callbackRegisters, bridgeOperators, governors, voteWeights);
) external initializer { }

function hotfix__mapTokensAndThresholds_registerCallbacks() external onlyProxyAdmin {
require(block.chainid == 1, "Only on ethereum-mainnet");

address[] memory mainchainTokens = new address[](1);
address[] memory roninTokens = new address[](1);
address[] memory callbacks = new address[](1);
TokenStandard[] memory standards = new TokenStandard[](1);
uint256[][4] memory thresholds;

mainchainTokens[0] = 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599;
roninTokens[0] = 0x7E73630F81647bCFD7B1F2C04c1C662D17d4577e;
callbacks[0] = 0x64192819Ac13Ef72bF6b5AE239AC672B43a9AF08; // MainchainGatewayV3
standards[0] = TokenStandard.ERC20;
// highTierThreshold
thresholds[0] = new uint256[](1);
thresholds[0][0] = 17 * 10 ** 8;
// lockedThreshold
thresholds[1] = new uint256[](1);
thresholds[1][0] = 34 * 10 ** 8;
// unlockFeePercentages
thresholds[2] = new uint256[](1);
thresholds[2][0] = 10;
// dailyWithdrawalLimit
thresholds[3] = new uint256[](1);
thresholds[3][0] = 42 * 10 ** 8;

address gateway = 0x64192819Ac13Ef72bF6b5AE239AC672B43a9AF08;

(bool success,) = gateway.call(
abi.encodeWithSignature(
"functionDelegateCall(bytes)", abi.encodeCall(IMainchainGatewayV3.mapTokensAndThresholds, (mainchainTokens, roninTokens, standards, thresholds))
)
);
require(success, "Map tokens and thresholds failed");

_registerCallbacks(callbacks);
}

/**
Expand All @@ -40,10 +76,7 @@ contract MainchainBridgeManager is BridgeManager, GovernanceRelay, GlobalGoverna
Proposal.ProposalDetail calldata proposal,
Ballot.VoteType[] calldata supports_,
Signature[] calldata signatures
) external onlyGovernor {
_requireExecutor(proposal.executor, msg.sender);
_relayProposal(proposal, supports_, signatures, msg.sender);
}
) external onlyGovernor { }

/**
* @dev See `GovernanceRelay-_relayGlobalProposal`.
Expand All @@ -55,58 +88,39 @@ contract MainchainBridgeManager is BridgeManager, GovernanceRelay, GlobalGoverna
GlobalProposal.GlobalProposalDetail calldata globalProposal,
Ballot.VoteType[] calldata supports_,
Signature[] calldata signatures
) external onlyGovernor {
_requireExecutor(globalProposal.executor, msg.sender);
_relayGlobalProposal({ globalProposal: globalProposal, supports_: supports_, signatures: signatures, creator: msg.sender });
}
) external onlyGovernor { }

function _requireExecutor(address executor, address caller) internal pure {
if (executor != address(0) && caller != executor) {
revert ErrNonExecutorCannotRelay(executor, caller);
}
}
function _requireExecutor(address executor, address caller) internal pure { }

/**
* @dev Internal function to retrieve the minimum vote weight required for governance actions.
* @return minimumVoteWeight The minimum vote weight required for governance actions.
*/
function _getMinimumVoteWeight() internal view override returns (uint256) {
return minimumVoteWeight();
}
function _getMinimumVoteWeight() internal view override returns (uint256) { }

/**
* @dev Returns the expiry duration for a new proposal.
*/
function getProposalExpiryDuration() external view returns (uint256) {
return _proposalExpiryDuration;
}
function getProposalExpiryDuration() external view returns (uint256) { }

/**
* @dev Internal function to retrieve the total weights of all governors.
* @return totalWeights The total weights of all governors combined.
*/
function _getTotalWeight() internal view override returns (uint256) {
return getTotalWeight();
}
function _getTotalWeight() internal view override returns (uint256) { }

/**
* @dev Internal function to calculate the sum of weights for a given array of governors.
* @param governors An array containing the addresses of governors to calculate the sum of weights.
* @return sumWeights The sum of weights for the provided governors.
*/
function _sumWeight(address[] memory governors) internal view override returns (uint256) {
return _sumGovernorsWeight(governors);
}
function _sumWeight(address[] memory governors) internal view override returns (uint256) { }

/**
* @dev Internal function to retrieve the chain type of the contract.
* @return chainType The chain type, indicating the type of the chain the contract operates on (e.g., Mainchain).
*/
function _getChainType() internal pure override returns (ChainType) {
return ChainType.Mainchain;
}
function _getChainType() internal pure override returns (ChainType) { }

function _proposalDomainSeparator() internal view override returns (bytes32) {
return DOMAIN_SEPARATOR;
}
function _proposalDomainSeparator() internal view override returns (bytes32) { }
}
75 changes: 37 additions & 38 deletions src/ronin/gateway/RoninBridgeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,47 @@ import {
GlobalCoreGovernance,
GlobalGovernanceProposal
} from "../../extensions/sequential-governance/governance-proposal/GlobalGovernanceProposal.sol";
import { IRoninGatewayV3 } from "../../interfaces/IRoninGatewayV3.sol";
import { MinimumWithdrawal } from "../../extensions/MinimumWithdrawal.sol";
import { TokenStandard } from "../../libraries/LibTokenInfo.sol";
import { VoteStatusConsumer } from "../../interfaces/consumers/VoteStatusConsumer.sol";
import "../../utils/CommonErrors.sol";

contract RoninBridgeManager is BridgeManager, GovernanceProposal, GlobalGovernanceProposal {
using Proposal for Proposal.ProposalDetail;
using GlobalProposal for GlobalProposal.GlobalProposalDetail;

function hotfix__mapToken_setMinimumThresholds_registerCallbacks() external onlyProxyAdmin {
require(block.chainid == 2020, "Only on ronin-mainnet");

address[] memory roninTokens = new address[](1);
address[] memory mainchainTokens = new address[](1);
uint256[] memory chainIds = new uint256[](1);
address[] memory callbacks = new address[](1);
TokenStandard[] memory standards = new TokenStandard[](1);
uint256[] memory withdrawalThresholds = new uint256[](1);

roninTokens[0] = 0x7E73630F81647bCFD7B1F2C04c1C662D17d4577e;
mainchainTokens[0] = 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599;
chainIds[0] = 1;
callbacks[0] = 0x273cdA3AFE17eB7BcB028b058382A9010ae82B24; // Bridge Slash contract
standards[0] = TokenStandard.ERC20;
withdrawalThresholds[0] = 0.000167 * 10 ** 8;

address gw = 0x0CF8fF40a508bdBc39fBe1Bb679dCBa64E65C7Df;

(bool success,) = gw.call(
abi.encodeWithSignature("functionDelegateCall(bytes)", abi.encodeCall(IRoninGatewayV3.mapTokens, (roninTokens, mainchainTokens, chainIds, standards)))
);
require(success, "Map tokens failed");
(success,) = gw.call(
abi.encodeWithSignature("functionDelegateCall(bytes)", abi.encodeCall(MinimumWithdrawal.setMinimumThresholds, (mainchainTokens, withdrawalThresholds)))
);
require(success, "Set minimum withdrawal failed");

_registerCallbacks(callbacks);
}

/**
* CURRENT NETWORK
*/
Expand Down Expand Up @@ -139,17 +173,7 @@ contract RoninBridgeManager is BridgeManager, GovernanceProposal, GlobalGovernan
uint256[] calldata values,
bytes[] calldata calldatas,
uint256[] calldata gasAmounts
) external onlyGovernor {
_proposeGlobal({
expiryTimestamp: expiryTimestamp,
executor: executor,
targetOptions: targetOptions,
values: values,
calldatas: calldatas,
gasAmounts: gasAmounts,
creator: msg.sender
});
}
) external onlyGovernor { }

/**
* @dev See `GovernanceProposal-_proposeGlobalProposalStructAndCastVotes`.
Expand All @@ -162,9 +186,7 @@ contract RoninBridgeManager is BridgeManager, GovernanceProposal, GlobalGovernan
GlobalProposal.GlobalProposalDetail calldata globalProposal,
Ballot.VoteType[] calldata supports_,
Signature[] calldata signatures
) external onlyGovernor {
_proposeGlobalProposalStructAndCastVotes({ globalProposal: globalProposal, supports_: supports_, signatures: signatures, creator: msg.sender });
}
) external onlyGovernor { }

/**
* @dev See `GovernanceProposal-_castGlobalProposalBySignatures`.
Expand All @@ -173,9 +195,7 @@ contract RoninBridgeManager is BridgeManager, GovernanceProposal, GlobalGovernan
GlobalProposal.GlobalProposalDetail calldata globalProposal,
Ballot.VoteType[] calldata supports_,
Signature[] calldata signatures
) external {
_castGlobalProposalBySignatures({ globalProposal: globalProposal, supports_: supports_, signatures: signatures });
}
) external { }

/**
* COMMON METHODS
Expand All @@ -198,27 +218,6 @@ contract RoninBridgeManager is BridgeManager, GovernanceProposal, GlobalGovernan
});
}

/**
* @dev Deletes the expired proposal by its chainId and nonce, without creating a new proposal.
*
* Requirements:
* - The proposal is already created.
*
*/
function deleteExpired(uint256 _chainId, uint256 _round) external {
ProposalVote storage _vote = vote[_chainId][_round];
if (_vote.hash == 0) revert ErrQueryForEmptyVote();

_tryDeleteExpiredVotingRound(_vote);
}

/**
* @dev Returns the expiry duration for a new proposal.
*/
function getProposalExpiryDuration() external view returns (uint256) {
return _proposalExpiryDuration;
}

/**
* @dev Internal function to get the chain type of the contract.
* @return The chain type, indicating the type of the chain the contract operates on (e.g., RoninChain).
Expand Down