Skip to content

Commit

Permalink
rename constants, remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
kovalgek committed Jun 18, 2024
1 parent 40f0e78 commit 1f8bdf8
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 105 deletions.
16 changes: 0 additions & 16 deletions contracts/lib/UnstructuredStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ library UnstructuredStorage {
assembly { data := sload(position) }
}

function getStorageAddress(bytes32 position) internal view returns (address data) {
assembly { data := sload(position) }
}

function getStorageBytes32(bytes32 position) internal view returns (bytes32 data) {
assembly { data := sload(position) }
}

function getStorageUint256(bytes32 position) internal view returns (uint256 data) {
assembly { data := sload(position) }
}
Expand All @@ -26,14 +18,6 @@ library UnstructuredStorage {
assembly { sstore(position, data) }
}

function setStorageAddress(bytes32 position, address data) internal {
assembly { sstore(position, data) }
}

function setStorageBytes32(bytes32 position, bytes32 data) internal {
assembly { sstore(position, data) }
}

function setStorageUint256(bytes32 position, uint256 data) internal {
assembly { sstore(position, data) }
}
Expand Down
12 changes: 6 additions & 6 deletions contracts/optimism/TokenRateOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ contract TokenRateOracle is ITokenRateOracle, CrossDomainEnabled, AccessControl,
/// See the 'pauseTokenRateUpdates()' method
uint256 public immutable OLDEST_RATE_ALLOWED_IN_PAUSE_TIME_SPAN;

/// @notice The maximum delta time that is allowed between two L1 timestamps of token rate updates.
uint256 public immutable MAX_ALLOWED_TIME_BETWEEN_TOKEN_RATE_UPDATES;
/// @notice The minimum delta time between two L1 timestamps of token rate updates.
uint256 public immutable MIN_TIME_BETWEEN_TOKEN_RATE_UPDATES;

/// @notice Decimals of the oracle response.
uint8 public constant DECIMALS = 27;
Expand Down Expand Up @@ -95,7 +95,7 @@ contract TokenRateOracle is ITokenRateOracle, CrossDomainEnabled, AccessControl,
/// Can't be bigger than BASIS_POINT_SCALE.
/// @param oldestRateAllowedInPauseTimeSpan_ Maximum allowed time difference between the current time
/// and the last received token rate update that can be set during a pause.
/// @param maxAllowedTimeBetweenTokenRateUpdates_ the maximum delta time that is allowed between two
/// @param minTimeBetweenTokenRateUpdates_ Minimum delta time between two
/// L1 timestamps of token rate updates.
constructor(
address messenger_,
Expand All @@ -105,7 +105,7 @@ contract TokenRateOracle is ITokenRateOracle, CrossDomainEnabled, AccessControl,
uint256 maxAllowedL2ToL1ClockLag_,
uint256 maxAllowedTokenRateDeviationPerDayBp_,
uint256 oldestRateAllowedInPauseTimeSpan_,
uint256 maxAllowedTimeBetweenTokenRateUpdates_
uint256 minTimeBetweenTokenRateUpdates_
) CrossDomainEnabled(messenger_) {
if (l2ERC20TokenBridge_ == address(0)) {
revert ErrorZeroAddressL2ERC20TokenBridge();
Expand All @@ -122,7 +122,7 @@ contract TokenRateOracle is ITokenRateOracle, CrossDomainEnabled, AccessControl,
MAX_ALLOWED_L2_TO_L1_CLOCK_LAG = maxAllowedL2ToL1ClockLag_;
MAX_ALLOWED_TOKEN_RATE_DEVIATION_PER_DAY_BP = maxAllowedTokenRateDeviationPerDayBp_;
OLDEST_RATE_ALLOWED_IN_PAUSE_TIME_SPAN = oldestRateAllowedInPauseTimeSpan_;
MAX_ALLOWED_TIME_BETWEEN_TOKEN_RATE_UPDATES = maxAllowedTimeBetweenTokenRateUpdates_;
MIN_TIME_BETWEEN_TOKEN_RATE_UPDATES = minTimeBetweenTokenRateUpdates_;
}

/// @notice Initializes the contract from scratch.
Expand Down Expand Up @@ -267,7 +267,7 @@ contract TokenRateOracle is ITokenRateOracle, CrossDomainEnabled, AccessControl,
}

/// @dev This condition was made under the assumption that the L1 timestamps can be manipulated.
if (rateUpdatedL1Timestamp_ < tokenRateData.rateUpdatedL1Timestamp + MAX_ALLOWED_TIME_BETWEEN_TOKEN_RATE_UPDATES) {
if (rateUpdatedL1Timestamp_ < tokenRateData.rateUpdatedL1Timestamp + MIN_TIME_BETWEEN_TOKEN_RATE_UPDATES) {
emit UpdateRateIsTooOften(rateUpdatedL1Timestamp_, tokenRateData.rateUpdatedL1Timestamp);
return;
}
Expand Down
1 change: 0 additions & 1 deletion contracts/token/ERC20RebasableBridged.sol
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ contract ERC20RebasableBridged is IERC20, IERC20Wrapper, IBridgeWrapper, ERC20Me
error ErrorZeroSharesWrap();
error ErrorZeroTokensUnwrap();
error ErrorZeroSharesUnwrap();
error ErrorTokenRateDecimalsIsZero();
error ErrorTransferToRebasableContract();
error ErrorNotEnoughBalance();
error ErrorNotEnoughAllowance();
Expand Down
4 changes: 2 additions & 2 deletions scripts/optimism/deploy-scratch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function main() {
l1TokenRebasable: deploymentConfig.l1RebasableToken,
accountingOracle: deploymentConfig.accountingOracle,
l2GasLimitForPushingTokenRate: deploymentConfig.l2GasLimitForPushingTokenRate,
l1AuthorizedRebaseCaller: deploymentConfig.l1AuthorizedRebaseCaller,
lido: deploymentConfig.lido,

deployer: ethDeployer,
admins: {
Expand All @@ -43,7 +43,7 @@ async function main() {
maxAllowedL2ToL1ClockLag: deploymentConfig.maxAllowedL2ToL1ClockLag,
maxAllowedTokenRateDeviationPerDayBp: deploymentConfig.maxAllowedTokenRateDeviationPerDayBp,
oldestRateAllowedInPauseTimeSpan: deploymentConfig.oldestRateAllowedInPauseTimeSpan,
maxAllowedTimeBetweenTokenRateUpdates: deploymentConfig.maxAllowedTimeBetweenTokenRateUpdates,
minTimeBetweenTokenRateUpdates: deploymentConfig.minTimeBetweenTokenRateUpdates,
tokenRate: deploymentConfig.tokenRateValue,
l1Timestamp: deploymentConfig.tokenRateL1Timestamp
},
Expand Down
2 changes: 1 addition & 1 deletion scripts/optimism/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function main() {
maxAllowedL2ToL1ClockLag: deploymentConfig.maxAllowedL2ToL1ClockLag,
maxAllowedTokenRateDeviationPerDayBp: deploymentConfig.maxAllowedTokenRateDeviationPerDayBp,
oldestRateAllowedInPauseTimeSpan: deploymentConfig.oldestRateAllowedInPauseTimeSpan,
maxAllowedTimeBetweenTokenRateUpdates: deploymentConfig.maxAllowedTimeBetweenTokenRateUpdates
minTimeBetweenTokenRateUpdates: deploymentConfig.minTimeBetweenTokenRateUpdates
},
initialize: {
tokenRate: deploymentConfig.tokenRateValue,
Expand Down
4 changes: 2 additions & 2 deletions test/bridge-executor/optimism.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ async function ctxFactory() {
const maxAllowedL2ToL1ClockLag = BigNumber.from(86400);
const maxAllowedTokenRateDeviationPerDay = BigNumber.from(500);
const oldestRateAllowedInPauseTimeSpan = BigNumber.from(86400*3);
const maxAllowedTimeBetweenTokenRateUpdates = BigNumber.from(3600);
const minTimeBetweenTokenRateUpdates = BigNumber.from(3600);
const exchangeRate = getExchangeRate(tokenRateDecimals, totalPooledEther, totalShares);

const l1Deployer = testing.accounts.deployer(l1Provider);
Expand Down Expand Up @@ -273,7 +273,7 @@ async function ctxFactory() {
maxAllowedL2ToL1ClockLag: maxAllowedL2ToL1ClockLag,
maxAllowedTokenRateDeviationPerDayBp: maxAllowedTokenRateDeviationPerDay,
oldestRateAllowedInPauseTimeSpan: oldestRateAllowedInPauseTimeSpan,
maxAllowedTimeBetweenTokenRateUpdates: maxAllowedTimeBetweenTokenRateUpdates,
minTimeBetweenTokenRateUpdates: minTimeBetweenTokenRateUpdates,
tokenRate: exchangeRate,
l1Timestamp: BigNumber.from('1000')
},
Expand Down
8 changes: 4 additions & 4 deletions test/optimism/L2ERC20ExtendedTokensBridge.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ async function ctxFactory() {
const maxAllowedL2ToL1ClockLag = BigNumber.from(86400);
const maxAllowedTokenRateDeviationPerDay = BigNumber.from(500);
const oldestRateAllowedInPauseTimeSpan = BigNumber.from(86400*3);
const maxAllowedTimeBetweenTokenRateUpdates = BigNumber.from(3600);
const minTimeBetweenTokenRateUpdates = BigNumber.from(3600);

const l2MessengerStub = await new CrossDomainMessengerStub__factory(
deployer
Expand Down Expand Up @@ -1284,7 +1284,7 @@ async function ctxFactory() {
maxAllowedL2ToL1ClockLag,
maxAllowedTokenRateDeviationPerDay,
oldestRateAllowedInPauseTimeSpan,
maxAllowedTimeBetweenTokenRateUpdates
minTimeBetweenTokenRateUpdates
);

const provider = await hre.ethers.provider;
Expand Down Expand Up @@ -1416,7 +1416,7 @@ async function getL2TokenBridgeImpl(deployer: SignerWithAddress, l1TokenBridge:
const maxAllowedL2ToL1ClockLag = BigNumber.from(86400);
const maxAllowedTokenRateDeviationPerDay = BigNumber.from(500);
const oldestRateAllowedInPauseTimeSpan = BigNumber.from(86400*3);
const maxAllowedTimeBetweenTokenRateUpdates = BigNumber.from(3600);
const minTimeBetweenTokenRateUpdates = BigNumber.from(3600);

const l2MessengerStub = await new CrossDomainMessengerStub__factory(
deployer
Expand Down Expand Up @@ -1459,7 +1459,7 @@ async function getL2TokenBridgeImpl(deployer: SignerWithAddress, l1TokenBridge:
maxAllowedL2ToL1ClockLag,
maxAllowedTokenRateDeviationPerDay,
oldestRateAllowedInPauseTimeSpan,
maxAllowedTimeBetweenTokenRateUpdates
minTimeBetweenTokenRateUpdates
);

const provider = await hre.ethers.provider;
Expand Down
34 changes: 17 additions & 17 deletions test/optimism/TokenRateNotifier.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import {
unit("TokenRateNotifier", ctxFactory)

.test("deploy with zero address owner", async (ctx) => {
const { deployer, l1AuthorizedRebaseCaller } = ctx.accounts;
const { deployer, lido } = ctx.accounts;

await assert.revertsWith(
new TokenRateNotifier__factory(deployer).deploy(ethers.constants.AddressZero, l1AuthorizedRebaseCaller.address),
new TokenRateNotifier__factory(deployer).deploy(ethers.constants.AddressZero, lido.address),
"ErrorZeroAddressOwner()"
);
})
Expand Down Expand Up @@ -72,9 +72,9 @@ unit("TokenRateNotifier", ctxFactory)

.test("addObserver() :: revert on adding observer with bad interface", async (ctx) => {
const { tokenRateNotifier } = ctx.contracts;
const { deployer, l1AuthorizedRebaseCaller } = ctx.accounts;
const { deployer, lido } = ctx.accounts;

const observer = await new TokenRateNotifier__factory(deployer).deploy(deployer.address, l1AuthorizedRebaseCaller.address);
const observer = await new TokenRateNotifier__factory(deployer).deploy(deployer.address, lido.address);
await assert.revertsWith(
tokenRateNotifier
.connect(ctx.accounts.owner)
Expand All @@ -85,7 +85,7 @@ unit("TokenRateNotifier", ctxFactory)

.test("addObserver() :: revert on adding too many observers", async (ctx) => {
const { tokenRateNotifier, opStackTokenRatePusher } = ctx.contracts;
const { deployer, owner, tokenRateOracle, l1AuthorizedRebaseCaller } = ctx.accounts;
const { deployer, owner, tokenRateOracle, lido } = ctx.accounts;
const { l2GasLimitForPushingTokenRate, tokenRate, totalPooledEther, totalShares, genesisTime, secondsPerSlot, lastProcessingRefSlot } = ctx.constants;

assert.equalBN(await tokenRateNotifier.observersLength(), 0);
Expand All @@ -105,7 +105,7 @@ unit("TokenRateNotifier", ctxFactory)
owner,
tokenRateOracle,
l2GasLimitForPushingTokenRate,
l1AuthorizedRebaseCaller
lido
);

await tokenRateNotifier
Expand Down Expand Up @@ -205,29 +205,29 @@ unit("TokenRateNotifier", ctxFactory)

.test("handlePostTokenRebase() :: failed with some error", async (ctx) => {
const { tokenRateNotifier } = ctx.contracts;
const { deployer, l1AuthorizedRebaseCaller } = ctx.accounts;
const { deployer, lido } = ctx.accounts;

const observer = await new OpStackTokenRatePusherWithSomeErrorStub__factory(deployer).deploy();
await tokenRateNotifier
.connect(ctx.accounts.owner)
.addObserver(observer.address);

const tx = await tokenRateNotifier.connect(l1AuthorizedRebaseCaller).handlePostTokenRebase(1, 2, 3, 4, 5, 6, 7);
const tx = await tokenRateNotifier.connect(lido).handlePostTokenRebase(1, 2, 3, 4, 5, 6, 7);

await assert.emits(tokenRateNotifier, tx, "PushTokenRateFailed", [observer.address, "0x332e27d2"]);
})

.test("handlePostTokenRebase() :: revert when observer has out of gas error", async (ctx) => {
const { tokenRateNotifier } = ctx.contracts;
const { deployer, l1AuthorizedRebaseCaller } = ctx.accounts;
const { deployer, lido } = ctx.accounts;

const observer = await new OpStackTokenRatePusherWithOutOfGasErrorStub__factory(deployer).deploy();
await tokenRateNotifier
.connect(ctx.accounts.owner)
.addObserver(observer.address);

await assert.revertsWith(
tokenRateNotifier.connect(l1AuthorizedRebaseCaller).handlePostTokenRebase(1, 2, 3, 4, 5, 6, 7),
tokenRateNotifier.connect(lido).handlePostTokenRebase(1, 2, 3, 4, 5, 6, 7),
"ErrorTokenRateNotifierRevertedWithNoData()"
);
})
Expand All @@ -238,15 +238,15 @@ unit("TokenRateNotifier", ctxFactory)
l1MessengerStub,
opStackTokenRatePusher
} = ctx.contracts;
const { tokenRateOracle, l1AuthorizedRebaseCaller } = ctx.accounts;
const { tokenRateOracle, lido } = ctx.accounts;
const { l2GasLimitForPushingTokenRate, tokenRate, genesisTime, secondsPerSlot, lastProcessingRefSlot } = ctx.constants;

const updateRateTime = genesisTime.add(secondsPerSlot.mul(lastProcessingRefSlot));

await tokenRateNotifier
.connect(ctx.accounts.owner)
.addObserver(opStackTokenRatePusher.address);
let tx = await tokenRateNotifier.connect(l1AuthorizedRebaseCaller).handlePostTokenRebase(1, 2, 3, 4, 5, 6, 7);
let tx = await tokenRateNotifier.connect(lido).handlePostTokenRebase(1, 2, 3, 4, 5, 6, 7);

await assert.emits(l1MessengerStub, tx, "SentMessage", [
tokenRateOracle.address,
Expand All @@ -266,7 +266,7 @@ unit("TokenRateNotifier", ctxFactory)
.run();

async function ctxFactory() {
const [deployer, owner, stranger, tokenRateOracle, l1AuthorizedRebaseCaller] = await ethers.getSigners();
const [deployer, owner, stranger, tokenRateOracle, lido] = await ethers.getSigners();
const totalPooledEther = BigNumber.from('9309904612343950493629678');
const totalShares = BigNumber.from('7975822843597609202337218');
const tokenRateDecimals = BigNumber.from(27);
Expand All @@ -291,7 +291,7 @@ async function ctxFactory() {
owner,
tokenRateOracle,
l2GasLimitForPushingTokenRate,
l1AuthorizedRebaseCaller
lido
);

return {
Expand All @@ -300,7 +300,7 @@ async function ctxFactory() {
owner,
stranger,
tokenRateOracle,
l1AuthorizedRebaseCaller
lido
},
contracts: {
tokenRateNotifier,
Expand Down Expand Up @@ -330,11 +330,11 @@ async function createContracts(
owner: SignerWithAddress,
tokenRateOracle: SignerWithAddress,
l2GasLimitForPushingTokenRate: number,
l1AuthorizedRebaseCaller: SignerWithAddress) {
lido: SignerWithAddress) {

const tokenRateNotifier = await new TokenRateNotifier__factory(deployer).deploy(
owner.address,
l1AuthorizedRebaseCaller.address
lido.address
);

const l1MessengerStub = await new CrossDomainMessengerStub__factory(deployer)
Expand Down
Loading

0 comments on commit 1f8bdf8

Please sign in to comment.