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

Added SystemSettings.crossDomainMessageGasLimit #962

Merged
merged 8 commits into from Dec 11, 2020
5 changes: 5 additions & 0 deletions contracts/MixinSystemSettings.sol
Expand Up @@ -24,6 +24,7 @@ contract MixinSystemSettings is MixinResolver {
bytes32 internal constant SETTING_AGGREGATOR_WARNING_FLAGS = "aggregatorWarningFlags";
bytes32 internal constant SETTING_TRADING_REWARDS_ENABLED = "tradingRewardsEnabled";
bytes32 internal constant SETTING_DEBT_SNAPSHOT_STALE_TIME = "debtSnapshotStaleTime";
bytes32 internal constant SETTING_CROSS_DOMAIN_MESSAGE_GAS_LIMIT = "crossDomainMessageGasLimit";

bytes32 internal constant CONTRACT_FLEXIBLESTORAGE = "FlexibleStorage";

Expand All @@ -38,6 +39,10 @@ contract MixinSystemSettings is MixinResolver {
return IFlexibleStorage(requireAndGetAddress(CONTRACT_FLEXIBLESTORAGE));
}

function getCrossDomainMessageGasLimit() internal view returns (uint) {
return flexibleStorage().getUIntValue(SETTING_CONTRACT_NAME, SETTING_CROSS_DOMAIN_MESSAGE_GAS_LIMIT);
}

function getTradingRewardsEnabled() internal view returns (bool) {
return flexibleStorage().getBoolValue(SETTING_CONTRACT_NAME, SETTING_TRADING_REWARDS_ENABLED);
}
Expand Down
15 changes: 8 additions & 7 deletions contracts/SynthetixBridgeToBase.sol
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.5.16;
// Inheritance
import "./Owned.sol";
import "./MixinResolver.sol";
import "./MixinSystemSettings.sol";
import "./interfaces/ISynthetixBridgeToBase.sol";

// Internal references
Expand All @@ -13,9 +14,7 @@ import "./interfaces/IIssuer.sol";
import "@eth-optimism/contracts/build/contracts/iOVM/bridge/iOVM_BaseCrossDomainMessenger.sol";


contract SynthetixBridgeToBase is Owned, MixinResolver, ISynthetixBridgeToBase {
uint32 private constant CROSS_DOMAIN_MESSAGE_GAS_LIMIT = 3e6; //TODO: make this updateable

contract SynthetixBridgeToBase is Owned, MixinSystemSettings, ISynthetixBridgeToBase {
/* ========== ADDRESS RESOLVER CONFIGURATION ========== */
bytes32 private constant CONTRACT_EXT_MESSENGER = "ext:Messenger";
bytes32 private constant CONTRACT_SYNTHETIX = "Synthetix";
Expand All @@ -24,7 +23,7 @@ contract SynthetixBridgeToBase is Owned, MixinResolver, ISynthetixBridgeToBase {

// ========== CONSTRUCTOR ==========

constructor(address _owner, address _resolver) public Owned(_owner) MixinResolver(_resolver) {}
constructor(address _owner, address _resolver) public Owned(_owner) MixinSystemSettings(_resolver) {}

//
// ========== INTERNALS ============
Expand Down Expand Up @@ -59,12 +58,14 @@ contract SynthetixBridgeToBase is Owned, MixinResolver, ISynthetixBridgeToBase {

// ========== VIEWS ==========

function resolverAddressesRequired() public view returns (bytes32[] memory addresses) {
addresses = new bytes32[](4);
function resolverAddressesRequired() public view returns (bytes32[] memory) {
bytes32[] memory existingAddresses = MixinSystemSettings.resolverAddressesRequired();
bytes32[] memory addresses = new bytes32[](4);
addresses[0] = CONTRACT_EXT_MESSENGER;
addresses[1] = CONTRACT_SYNTHETIX;
addresses[2] = CONTRACT_BASE_SYNTHETIXBRIDGETOOPTIMISM;
addresses[3] = CONTRACT_ISSUER;
return combineArrays(existingAddresses, addresses);
}

// ========== PUBLIC FUNCTIONS =========
Expand All @@ -80,7 +81,7 @@ contract SynthetixBridgeToBase is Owned, MixinResolver, ISynthetixBridgeToBase {
bytes memory messageData = abi.encodeWithSignature("completeWithdrawal(address,uint256)", msg.sender, amount);

// relay the message to Bridge on L1 via L2 Messenger
messenger().sendMessage(synthetixBridgeToOptimism(), messageData, CROSS_DOMAIN_MESSAGE_GAS_LIMIT);
messenger().sendMessage(synthetixBridgeToOptimism(), messageData, uint32(getCrossDomainMessageGasLimit()));

emit WithdrawalInitiated(msg.sender, amount);
}
Expand Down
17 changes: 9 additions & 8 deletions contracts/SynthetixBridgeToOptimism.sol
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.5.16;
// Inheritance
import "./Owned.sol";
import "./MixinResolver.sol";
import "./MixinSystemSettings.sol";
import "./interfaces/ISynthetixBridgeToOptimism.sol";

// Internal references
Expand All @@ -14,9 +15,7 @@ import "./interfaces/IIssuer.sol";
import "@eth-optimism/contracts/build/contracts/iOVM/bridge/iOVM_BaseCrossDomainMessenger.sol";


contract SynthetixBridgeToOptimism is Owned, MixinResolver, ISynthetixBridgeToOptimism {
uint32 private constant CROSS_DOMAIN_MESSAGE_GAS_LIMIT = 3e6; //TODO: from constant to an updateable value

contract SynthetixBridgeToOptimism is Owned, MixinSystemSettings, ISynthetixBridgeToOptimism {
/* ========== ADDRESS RESOLVER CONFIGURATION ========== */
bytes32 private constant CONTRACT_EXT_MESSENGER = "ext:Messenger";
bytes32 private constant CONTRACT_SYNTHETIX = "Synthetix";
Expand All @@ -28,7 +27,7 @@ contract SynthetixBridgeToOptimism is Owned, MixinResolver, ISynthetixBridgeToOp

// ========== CONSTRUCTOR ==========

constructor(address _owner, address _resolver) public Owned(_owner) MixinResolver(_resolver) {
constructor(address _owner, address _resolver) public Owned(_owner) MixinSystemSettings(_resolver) {
activated = true;
}

Expand Down Expand Up @@ -68,20 +67,22 @@ contract SynthetixBridgeToOptimism is Owned, MixinResolver, ISynthetixBridgeToOp
bytes memory messageData = abi.encodeWithSignature("completeRewardDeposit(uint256)", amount);

// relay the message to this contract on L2 via L1 Messenger
messenger().sendMessage(synthetixBridgeToBase(), messageData, CROSS_DOMAIN_MESSAGE_GAS_LIMIT);
messenger().sendMessage(synthetixBridgeToBase(), messageData, uint32(getCrossDomainMessageGasLimit()));

emit RewardDeposit(msg.sender, amount);
}

/* ========== VIEWS ========== */

function resolverAddressesRequired() public view returns (bytes32[] memory addresses) {
addresses = new bytes32[](5);
function resolverAddressesRequired() public view returns (bytes32[] memory) {
bytes32[] memory existingAddresses = MixinSystemSettings.resolverAddressesRequired();
bytes32[] memory addresses = new bytes32[](5);
addresses[0] = CONTRACT_EXT_MESSENGER;
addresses[1] = CONTRACT_SYNTHETIX;
addresses[2] = CONTRACT_ISSUER;
addresses[3] = CONTRACT_REWARDSDISTRIBUTION;
addresses[4] = CONTRACT_OVM_SYNTHETIXBRIDGETOBASE;
return combineArrays(existingAddresses, addresses);
}

// ========== MODIFIERS ============
Expand All @@ -108,7 +109,7 @@ contract SynthetixBridgeToOptimism is Owned, MixinResolver, ISynthetixBridgeToOp
bytes memory messageData = abi.encodeWithSignature("completeDeposit(address,uint256)", msg.sender, amount);

// relay the message to this contract on L2 via L1 Messenger
messenger().sendMessage(synthetixBridgeToBase(), messageData, CROSS_DOMAIN_MESSAGE_GAS_LIMIT);
messenger().sendMessage(synthetixBridgeToBase(), messageData, uint32(getCrossDomainMessageGasLimit()));

emit Deposit(msg.sender, amount);
}
Expand Down
14 changes: 14 additions & 0 deletions contracts/SystemSettings.sol
Expand Up @@ -122,8 +122,21 @@ contract SystemSettings is Owned, MixinSystemSettings, ISystemSettings {
return getTradingRewardsEnabled();
}

function crossDomainMessageGasLimit() external view returns (uint) {
return getCrossDomainMessageGasLimit();
}

// ========== RESTRICTED ==========

function setCrossDomainMessageGasLimit(uint _crossDomainMessageGasLimit) external onlyOwner {
flexibleStorage().setUIntValue(
SETTING_CONTRACT_NAME,
SETTING_CROSS_DOMAIN_MESSAGE_GAS_LIMIT,
_crossDomainMessageGasLimit
);
emit CrossDomainMessageGasLimitChanged(_crossDomainMessageGasLimit);
}

function setTradingRewardsEnabled(bool _tradingRewardsEnabled) external onlyOwner {
flexibleStorage().setBoolValue(SETTING_CONTRACT_NAME, SETTING_TRADING_REWARDS_ENABLED, _tradingRewardsEnabled);
emit TradingRewardsEnabled(_tradingRewardsEnabled);
Expand Down Expand Up @@ -243,6 +256,7 @@ contract SystemSettings is Owned, MixinSystemSettings, ISystemSettings {
}

// ========== EVENTS ==========
event CrossDomainMessageGasLimitChanged(uint newLimit);
event TradingRewardsEnabled(bool enabled);
event WaitingPeriodSecsUpdated(uint waitingPeriodSecs);
event PriceDeviationThresholdUpdated(uint threshold);
Expand Down
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -81,6 +81,7 @@ const defaults = {
kovan: '0x6292aa9a6650ae14fbf974e5029f36f95a1848fd',
},
INITIAL_ISSUANCE: w3utils.toWei(`${100e6}`),
CROSS_DOMAIN_MESSAGE_GAS_LIMIT: `${3e6}`,
};

/**
Expand Down