Skip to content

Commit

Permalink
refactor: make nextNonce implementation common
Browse files Browse the repository at this point in the history
while the overrides still need to be present to inform the compiler
about the base class whose function should be called, the implementation
can still be made common in the base class.
  • Loading branch information
MaxMustermann2 committed Jun 27, 2024
1 parent 6c13c59 commit a40ff77
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/core/BootstrapLzReceiver.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
pragma solidity ^0.8.19;

import {OAppReceiverUpgradeable, Origin} from "../lzApp/OAppReceiverUpgradeable.sol";

import {BootstrapStorage} from "../storage/BootstrapStorage.sol";
import {GatewayStorage} from "../storage/GatewayStorage.sol";
import {PausableUpgradeable} from "@openzeppelin-upgradeable/contracts/utils/PausableUpgradeable.sol";

abstract contract BootstrapLzReceiver is PausableUpgradeable, OAppReceiverUpgradeable, BootstrapStorage {
Expand Down Expand Up @@ -35,10 +37,10 @@ abstract contract BootstrapLzReceiver is PausableUpgradeable, OAppReceiverUpgrad
public
view
virtual
override(OAppReceiverUpgradeable)
override(GatewayStorage, OAppReceiverUpgradeable)
returns (uint64)
{
return inboundNonce[srcEid][sender] + 1;
return GatewayStorage.nextNonce(srcEid, sender);
}

}
13 changes: 13 additions & 0 deletions src/core/ClientChainGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import {OAppReceiverUpgradeable} from "../lzApp/OAppReceiverUpgradeable.sol";
import {MessagingFee, OAppSenderUpgradeable} from "../lzApp/OAppSenderUpgradeable.sol";

import {ClientChainGatewayStorage} from "../storage/ClientChainGatewayStorage.sol";

import {GatewayStorage} from "../storage/GatewayStorage.sol";
import {ClientGatewayLzReceiver} from "./ClientGatewayLzReceiver.sol";
import {LSTRestakingController} from "./LSTRestakingController.sol";
import {NativeRestakingController} from "./NativeRestakingController.sol";

import {IOAppCore} from "@layerzero-v2/oapp/contracts/oapp/interfaces/IOAppCore.sol";
import {OptionsBuilder} from "@layerzero-v2/oapp/contracts/oapp/libs/OptionsBuilder.sol";
import {ILayerZeroReceiver} from "@layerzero-v2/protocol/contracts/interfaces/ILayerZeroReceiver.sol";
import {OwnableUpgradeable} from "@openzeppelin-upgradeable/contracts/access/OwnableUpgradeable.sol";
import {Initializable} from "@openzeppelin-upgradeable/contracts/proxy/utils/Initializable.sol";
import {PausableUpgradeable} from "@openzeppelin-upgradeable/contracts/utils/PausableUpgradeable.sol";
Expand Down Expand Up @@ -167,4 +170,14 @@ contract ClientChainGateway is
return (SENDER_VERSION, RECEIVER_VERSION);
}

function nextNonce(uint32 srcEid, bytes32 sender)
public
view
virtual
override(ClientGatewayLzReceiver, GatewayStorage, ILayerZeroReceiver)
returns (uint64)
{
return GatewayStorage.nextNonce(srcEid, sender);
}

}
6 changes: 4 additions & 2 deletions src/core/ClientGatewayLzReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ pragma solidity ^0.8.19;
import {IExoCapsule} from "../interfaces/IExoCapsule.sol";
import {IVault} from "../interfaces/IVault.sol";
import {OAppReceiverUpgradeable, Origin} from "../lzApp/OAppReceiverUpgradeable.sol";

import {ClientChainGatewayStorage} from "../storage/ClientChainGatewayStorage.sol";
import {GatewayStorage} from "../storage/GatewayStorage.sol";

import {PausableUpgradeable} from "@openzeppelin-upgradeable/contracts/utils/PausableUpgradeable.sol";

Expand Down Expand Up @@ -69,10 +71,10 @@ abstract contract ClientGatewayLzReceiver is PausableUpgradeable, OAppReceiverUp
public
view
virtual
override(OAppReceiverUpgradeable)
override(GatewayStorage, OAppReceiverUpgradeable)
returns (uint64)
{
return inboundNonce[srcEid][sender] + 1;
return GatewayStorage.nextNonce(srcEid, sender);
}

function afterReceiveDepositResponse(bytes memory requestPayload, bytes calldata responsePayload)
Expand Down
8 changes: 6 additions & 2 deletions src/core/ExocoreGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import {
OAppUpgradeable,
Origin
} from "../lzApp/OAppUpgradeable.sol";

import {ExocoreGatewayStorage} from "../storage/ExocoreGatewayStorage.sol";
import {GatewayStorage} from "../storage/GatewayStorage.sol";

import {OAppCoreUpgradeable} from "../lzApp/OAppCoreUpgradeable.sol";
import {IOAppCore} from "@layerzero-v2/oapp/contracts/oapp/interfaces/IOAppCore.sol";
Expand Down Expand Up @@ -344,10 +346,12 @@ contract ExocoreGateway is
public
view
virtual
override(ILayerZeroReceiver, OAppReceiverUpgradeable)
// since there are 3 contracts with this function, it must be defined so that
// the compiler knows which one to call
override(GatewayStorage, ILayerZeroReceiver, OAppReceiverUpgradeable)
returns (uint64)
{
return inboundNonce[srcEid][sender] + 1;
return GatewayStorage.nextNonce(srcEid, sender);
}

}
4 changes: 4 additions & 0 deletions src/storage/GatewayStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ contract GatewayStorage {
inboundNonce[srcChainId][srcAddress] = nonce;
}

function nextNonce(uint32 srcEid, bytes32 sender) public view virtual returns (uint64) {
return inboundNonce[srcEid][sender] + 1;
}

}
6 changes: 4 additions & 2 deletions test/mocks/ExocoreGatewayMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import {
OAppUpgradeable,
Origin
} from "src/lzApp/OAppUpgradeable.sol";

import {ExocoreGatewayStorage} from "src/storage/ExocoreGatewayStorage.sol";
import {GatewayStorage} from "src/storage/GatewayStorage.sol";

import {IOAppCore} from "@layerzero-v2/oapp/contracts/oapp/interfaces/IOAppCore.sol";
import {OptionsBuilder} from "@layerzero-v2/oapp/contracts/oapp/libs/OptionsBuilder.sol";
Expand Down Expand Up @@ -335,10 +337,10 @@ contract ExocoreGatewayMock is
public
view
virtual
override(ILayerZeroReceiver, OAppReceiverUpgradeable)
override(GatewayStorage, ILayerZeroReceiver, OAppReceiverUpgradeable)
returns (uint64)
{
return inboundNonce[srcEid][sender] + 1;
return GatewayStorage.nextNonce(srcEid, sender);
}

}

0 comments on commit a40ff77

Please sign in to comment.