Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion FunctionSignatures.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@
| `completeOwnershipHandover` | `0xf04e283e` |
| `grantRole` | `0x2f2ff15d` |
| `hasRole` | `0x91d14854` |
| `initialPacketCount` | `0x7c138814` |
| `isAttested` | `0xc13c2396` |
| `nextNonce` | `0x0cd55abf` |
| `owner` | `0x8da5cb5b` |
Expand Down
33 changes: 20 additions & 13 deletions contracts/base/AppGatewayBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import {FAST} from "../protocol/utils/common/Constants.sol";

/// @title AppGatewayBase
/// @notice Abstract contract for the app gateway
/// @dev This contract contains helpers for contract deployment, overrides, hooks and request processing
abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway, FeesPlugin {
OverrideParams public overrideParams;
bool public isAsyncModifierSet;
address public auctionManager;
bytes public onCompleteData;
bytes32 public sbType;
bool public isAsyncModifierSet;
bytes public onCompleteData;

mapping(address => bool) public isValidPromise;
mapping(bytes32 => mapping(uint32 => address)) public override forwarderAddresses;
Expand All @@ -27,11 +28,14 @@ abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway, FeesPlugin
/// @notice Modifier to treat functions async
modifier async() {
if (fees.feePoolChain == 0) revert FeesNotSet();

isAsyncModifierSet = true;
deliveryHelper__().clearQueue();
addressResolver__.clearPromises();
_clearOverrides();

_;

isAsyncModifierSet = false;
deliveryHelper__().batch(fees, auctionManager, onCompleteData);
_markValidPromises();
Expand Down Expand Up @@ -87,13 +91,6 @@ abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway, FeesPlugin
}
}

/// @notice Gets the socket address
/// @param chainSlug_ The chain slug
/// @return socketAddress_ The socket address
function getSocketAddress(uint32 chainSlug_) public view returns (address) {
return watcherPrecompileConfig().sockets(chainSlug_);
}

/// @notice Sets the validity of an onchain contract (plug) to authorize it to send information to a specific AppGateway
/// @param chainSlug_ The unique identifier of the chain where the contract resides
/// @param contractId The bytes32 identifier of the contract to be validated
Expand Down Expand Up @@ -127,9 +124,9 @@ abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway, FeesPlugin
if (!isAsyncModifierSet) revert AsyncModifierNotUsed();

address asyncPromise = addressResolver__.deployAsyncPromiseContract(address(this));
isValidPromise[asyncPromise] = true;
IPromise(asyncPromise).then(this.setAddress.selector, abi.encode(chainSlug_, contractId_));

isValidPromise[asyncPromise] = true;
onCompleteData = abi.encode(chainSlug_, true);

QueuePayloadParams memory queuePayloadParams = QueuePayloadParams({
Expand All @@ -156,7 +153,6 @@ abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway, FeesPlugin
/// @param returnData_ The return data
function setAddress(bytes memory data_, bytes memory returnData_) external onlyPromises {
(uint32 chainSlug, bytes32 contractId) = abi.decode(data_, (uint32, bytes32));

address forwarderContractAddress = addressResolver__.getOrDeployForwarderContract(
address(this),
abi.decode(returnData_, (address)),
Expand All @@ -166,6 +162,13 @@ abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway, FeesPlugin
forwarderAddresses[contractId][chainSlug] = forwarderContractAddress;
}

/// @notice Gets the socket address
/// @param chainSlug_ The chain slug
/// @return socketAddress_ The socket address
function getSocketAddress(uint32 chainSlug_) public view returns (address) {
return watcherPrecompileConfig().sockets(chainSlug_);
}

/// @notice Gets the on-chain address
/// @param contractId_ The contract ID
/// @param chainSlug_ The chain slug
Expand Down Expand Up @@ -342,15 +345,19 @@ abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway, FeesPlugin
/// @param onCompleteData_ The on complete data
/// @dev only payload delivery can call this
/// @dev callback in pd promise to be called after all contracts are deployed
function onRequestComplete(uint40, bytes calldata onCompleteData_) external override {
function onRequestComplete(
uint40,
bytes calldata onCompleteData_
) external override onlyDeliveryHelper {
if (onCompleteData_.length == 0) return;
(uint32 chainSlug, bool isDeploy) = abi.decode(onCompleteData_, (uint32, bool));
if (isDeploy) {
initialize(chainSlug);
}
}

/// @notice Initializes the contract
/// @notice Initializes the contract after deployment
/// @dev can be overridden by the app gateway to add custom logic
/// @param chainSlug_ The chain slug
function initialize(uint32 chainSlug_) public virtual {}

Expand Down
3 changes: 2 additions & 1 deletion contracts/base/PlugBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {NotSocket} from "../protocol/utils/common/Errors.sol";

/// @title PlugBase
/// @notice Abstract contract for plugs
/// @dev This contract contains helpers for socket connection, disconnection, and overrides
abstract contract PlugBase is IPlug {
ISocket public socket__;
bytes32 public appGatewayId;
Expand All @@ -23,7 +24,7 @@ abstract contract PlugBase is IPlug {
_;
}

/// @notice Modifier to ensure the socket is initialized
/// @notice Modifier to ensure the socket is initialized and if not already initialized, it will be initialized
modifier socketInitializer() {
if (isSocketInitialized == 1) revert SocketAlreadyInitialized();
isSocketInitialized = 1;
Expand Down
4 changes: 1 addition & 3 deletions contracts/base/ProxyFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ pragma solidity ^0.8.0;

import {ERC1967Factory} from "solady/utils/ERC1967Factory.sol";

contract ProxyFactory is ERC1967Factory {
constructor() {}
}
contract ProxyFactory is ERC1967Factory {}
59 changes: 34 additions & 25 deletions contracts/interfaces/IAddressResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,45 @@ interface IAddressResolver {
/// @param newAddress The new address of the contract
event AddressSet(bytes32 indexed name, address oldAddress, address newAddress);

/// @notice Emitted when a new plug is added to the resolver
/// @param appGateway The address of the app gateway
/// @param chainSlug The chain slug
/// @param plug The address of the plug
event PlugAdded(address appGateway, uint32 chainSlug, address plug);

/// @notice Emitted when a new forwarder is deployed
/// @param newForwarder The address of the new forwarder
/// @param salt The salt used to deploy the forwarder
event ForwarderDeployed(address newForwarder, bytes32 salt);

/// @notice Emitted when a new async promise is deployed
/// @param newAsyncPromise The address of the new async promise
/// @param salt The salt used to deploy the async promise
event AsyncPromiseDeployed(address newAsyncPromise, bytes32 salt);

/// @notice Emitted when an implementation is updated
/// @param contractName The name of the contract
/// @param newImplementation The new implementation address
event ImplementationUpdated(string contractName, address newImplementation);

/// @notice Gets the address of the delivery helper contract
/// @return IMiddleware The delivery helper interface
/// @dev Returns interface pointing to zero address if not configured
/// @return The delivery helper contract address
/// @dev Returns zero address if not configured
function deliveryHelper() external view returns (address);

/// @notice Gets the address of the fees manager contract
/// @return IFeesManager The fees manager interface
/// @dev Returns interface pointing to zero address if not configured
/// @return The fees manager contract address
/// @dev Returns zero address if not configured
function feesManager() external view returns (address);

/// @notice Gets the address of the default auction manager contract
/// @return IAuctionManager The auction manager interface
/// @dev Returns interface pointing to zero address if not configured
/// @return The auction manager contract address
/// @dev Returns zero address if not configured
function defaultAuctionManager() external view returns (address);

/// @notice Gets the watcher precompile contract interface
/// @return IWatcherPrecompile The watcher precompile interface
/// @dev Returns interface pointing to zero address if not configured
/// @notice Gets the watcher precompile contract instance
/// @return The watcher precompile contract instance
/// @dev Returns instance with zero address if not configured
function watcherPrecompile__() external view returns (IWatcherPrecompile);

/// @notice Maps contract addresses to their corresponding gateway addresses
Expand All @@ -41,29 +62,17 @@ interface IAddressResolver {
/// @return Array of async promise contract addresses
function getPromises() external view returns (address[] memory);

// State-changing functions
/// @notice Sets the auction house contract address
/// @param deliveryHelper_ The new delivery helper contract address
/// @dev Only callable by contract owner
function setDeliveryHelper(address deliveryHelper_) external;

/// @notice Sets the watcher precompile contract address
/// @param watcherPrecompile_ The new watcher precompile contract address
/// @dev Only callable by contract owner
function setWatcherPrecompile(address watcherPrecompile_) external;

/// @notice Maps a contract address to its gateway
/// @param contractAddress_ The contract address to map
/// @dev Creates bidirectional mapping between contract and gateway
function setContractsToGateways(address contractAddress_) external;

/// @notice Clears the list of deployed async promise contracts
/// @dev Only callable by contract owner
/// @notice Clears the list of deployed async promise contracts array
function clearPromises() external;

/// @notice Deploys a new forwarder contract if not already deployed
/// @param chainContractAddress_ The contract address on the destination chain
/// @param chainSlug_ The identifier of the destination chain
/// @notice Deploys or returns the address of a new forwarder contract if not already deployed
/// @param chainContractAddress_ The contract address on the `chainSlug_`
/// @param chainSlug_ The identifier of the chain
/// @return The address of the newly deployed forwarder contract
function getOrDeployForwarderContract(
address appGateway_,
Expand Down
26 changes: 26 additions & 0 deletions contracts/interfaces/IAppGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,57 @@ pragma solidity ^0.8.21;

import {Fees, Read, Parallel, QueuePayloadParams, OverrideParams, CallType, WriteFinality, PayloadParams} from "../protocol/utils/common/Structs.sol";

/// @title IAppGateway
/// @notice Interface for the app gateway
interface IAppGateway {
/// @notice Checks if the async modifier is set
/// @return isAsyncModifierSet_ True if the async modifier is set, false otherwise
function isAsyncModifierSet() external view returns (bool);

/// @notice Gets the override parameters
/// @return read_ The read parameters
/// @return parallel_ The parallel parameters
/// @return writeFinality_ The write finality parameters
/// @return readTimeout_ The read timeout
/// @return writeTimeout_ The write timeout
/// @return writeFinalityTimeout_ The write finality timeout
/// @return sbType_ The switchboard type
function getOverrideParams()
external
view
returns (Read, Parallel, WriteFinality, uint256, uint256, uint256, bytes32);

/// @notice Handles the request complete event
/// @param requestCount_ The request count
/// @param onCompleteData_ The on complete data
function onRequestComplete(uint40 requestCount_, bytes calldata onCompleteData_) external;

/// @notice Handles the revert event
/// @param requestCount_ The request count
/// @param payloadId_ The payload id
function handleRevert(uint40 requestCount_, bytes32 payloadId_) external;

/// @notice initialize the contracts on chain
/// @param chainSlug_ The chain slug
function initialize(uint32 chainSlug_) external;

/// @notice deploy contracts to chain
/// @param chainSlug_ The chain slug
function deployContracts(uint32 chainSlug_) external;

/// @notice get the on-chain address of a contract
/// @param contractId_ The contract id
/// @param chainSlug_ The chain slug
/// @return onChainAddress The on-chain address
function getOnChainAddress(
bytes32 contractId_,
uint32 chainSlug_
) external view returns (address onChainAddress);

/// @notice get the forwarder address of a contract
/// @param contractId_ The contract id
/// @param chainSlug_ The chain slug
/// @return forwarderAddress The forwarder address
function forwarderAddresses(
bytes32 contractId_,
uint32 chainSlug_
Expand Down
15 changes: 14 additions & 1 deletion contracts/interfaces/IAuctionManager.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.3;

import {Bid, Fees} from "../protocol/utils/common/Structs.sol";
import {Bid, Fees, RequestMetadata, RequestParams} from "../protocol/utils/common/Structs.sol";

interface IAuctionManager {
/// @notice Bids for an auction
/// @param requestCount_ The request count
/// @param fee_ The fee
/// @param transmitterSignature_ The transmitter signature
/// @param extraData_ The extra data
function bid(
uint40 requestCount_,
uint256 fee_,
bytes memory transmitterSignature_,
bytes memory extraData_
) external;

/// @notice Ends an auction
/// @param requestCount_ The request count
function endAuction(uint40 requestCount_) external;

/// @notice Checks if an auction is closed
/// @param requestCount_ The request count
/// @return isClosed_ Whether the auction is closed
function auctionClosed(uint40 requestCount_) external view returns (bool);

/// @notice Checks if an auction is started
/// @param requestCount_ The request count
/// @return isStarted_ Whether the auction is started
function auctionStarted(uint40 requestCount_) external view returns (bool);
}
8 changes: 3 additions & 5 deletions contracts/interfaces/IFeesPlug.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
pragma solidity ^0.8.21;

interface IFeesPlug {
function balanceOf(address appGateway_, address token_) external view returns (uint256);
function balanceOf(address token_) external view returns (uint256);

function feesRedeemed(uint256 feesCounter_) external view returns (bool);
function feesRedeemed(bytes32 feesId_) external view returns (bool);

function deposit(address token_, address appGateway_, uint256 amount_) external payable;

function connect(address appGateway_, address switchboard_) external;

function distributeFee(
address feeToken_,
uint256 fee_,
address transmitter_,
bytes32 feesCounter_
bytes32 feesId_
) external;

function withdrawFees(address token_, uint256 amount_, address receiver_) external;
Expand Down
7 changes: 6 additions & 1 deletion contracts/interfaces/IForwarder.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;

/// @title IForwarder
/// @notice Interface for the Forwarder contract that allows contracts to call async promises
interface IForwarder {
// View functions
/// @notice Returns the on-chain address of the contract being referenced
/// @return The on-chain address
function getOnChainAddress() external view returns (address);

/// @notice Returns the chain slug of the on chain contract
/// @return The chain slug
function getChainSlug() external view returns (uint32);
}
Loading