Skip to content
Closed
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ broadcast/
.gas-snapshot

.cursorrules

deployments/local_addresses.json
deployments/local_verification.json

testScript.sh
101 changes: 73 additions & 28 deletions contracts/base/AppGatewayBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,13 @@ import "../interfaces/IPromise.sol";
import {FeesPlugin} from "../protocol/utils/FeesPlugin.sol";
import {InvalidPromise, FeesNotSet} from "../protocol/utils/common/Errors.sol";
import {FAST} from "../protocol/utils/common/Constants.sol";

/// @title AppGatewayBase
/// @notice Abstract contract for the app gateway
abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway, FeesPlugin {
Read public override isReadCall;
Parallel public override isParallelCall;
uint256 public override gasLimit;

OverrideParams public overrideParams;
address public auctionManager;
bytes public onCompleteData;
bytes32 public sbType;

bool public isAsyncModifierSet;

mapping(address => bool) public isValidPromise;
Expand All @@ -34,6 +29,7 @@ abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway, FeesPlugin
isAsyncModifierSet = true;
deliveryHelper().clearQueue();
addressResolver__.clearPromises();
_clearOverrides();
_;
isAsyncModifierSet = false;
deliveryHelper().batch(fees, auctionManager, onCompleteData, sbType);
Expand Down Expand Up @@ -120,17 +116,22 @@ abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway, FeesPlugin
IPromise(asyncPromise).then(this.setAddress.selector, abi.encode(chainSlug_, contractId_));

onCompleteData = abi.encode(chainSlug_, true);
IDeliveryHelper(deliveryHelper()).queue(
isPlug_,
isParallelCall,
chainSlug_,
address(0),
asyncPromise,
0,
CallType.DEPLOY,
creationCodeWithArgs[contractId_],
initCallData_
);

CallParams memory callParams = CallParams({
isPlug: isPlug_,
isParallel: overrideParams.isParallelCall,
chainSlug: chainSlug_,
target: address(0),
asyncPromise: asyncPromise,
value: 0,
gasLimit: overrideParams.gasLimit,
callType: CallType.DEPLOY,
writeFinality: overrideParams.writeFinality,
readAt: overrideParams.readAt,
payload: creationCodeWithArgs[contractId_],
initCallData: initCallData_
});
IDeliveryHelper(deliveryHelper()).queue(callParams);
}

/// @notice Sets the address for a deployed contract
Expand Down Expand Up @@ -179,46 +180,76 @@ abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway, FeesPlugin
uint256 gasLimit_,
Fees memory fees_
) internal {
isReadCall = isReadCall_;
isParallelCall = isParallelCall_;
gasLimit = gasLimit_;
overrideParams.isReadCall = isReadCall_;
overrideParams.isParallelCall = isParallelCall_;
overrideParams.gasLimit = gasLimit_;
fees = fees_;
}

function _clearOverrides() internal {
overrideParams.isReadCall = Read.OFF;
overrideParams.isParallelCall = Parallel.OFF;
overrideParams.gasLimit = 0;
overrideParams.readAt = 0;
overrideParams.writeFinality = WriteFinality.LOW;
}

/// @notice Sets isReadCall, fees and gasLimit overrides
/// @param isReadCall_ The read call flag
/// @param isParallelCall_ The sequential call flag
/// @param gasLimit_ The gas limit
function _setOverrides(Read isReadCall_, Parallel isParallelCall_, uint256 gasLimit_) internal {
isReadCall = isReadCall_;
isParallelCall = isParallelCall_;
gasLimit = gasLimit_;
overrideParams.isReadCall = isReadCall_;
overrideParams.isParallelCall = isParallelCall_;
overrideParams.gasLimit = gasLimit_;
}

/// @notice Sets isReadCall and isParallelCall overrides
/// @param isReadCall_ The read call flag
/// @param isParallelCall_ The sequential call flag
function _setOverrides(Read isReadCall_, Parallel isParallelCall_) internal {
isReadCall = isReadCall_;
isParallelCall = isParallelCall_;
overrideParams.isReadCall = isReadCall_;
overrideParams.isParallelCall = isParallelCall_;
}

/// @notice Sets isParallelCall overrides
/// @param writeFinality_ The write finality
function _setOverrides(WriteFinality writeFinality_) internal {
overrideParams.writeFinality = writeFinality_;
}

/// @notice Sets isParallelCall overrides
/// @param isParallelCall_ The sequential call flag
function _setOverrides(Parallel isParallelCall_) internal {
isParallelCall = isParallelCall_;
overrideParams.isParallelCall = isParallelCall_;
}

/// @notice Sets isParallelCall overrides
/// @param isParallelCall_ The sequential call flag
/// @param readAt_ The read anchor value. Currently block number.
function _setOverrides(Parallel isParallelCall_, uint256 readAt_) internal {
overrideParams.isParallelCall = isParallelCall_;
overrideParams.readAt = readAt_;
}

/// @notice Sets isReadCall overrides
/// @param isReadCall_ The read call flag
function _setOverrides(Read isReadCall_) internal {
isReadCall = isReadCall_;
overrideParams.isReadCall = isReadCall_;
}

/// @notice Sets isReadCall overrides
/// @param isReadCall_ The read call flag
/// @param readAt_ The read anchor value. Currently block number.
function _setOverrides(Read isReadCall_, uint256 readAt_) internal {
overrideParams.isReadCall = isReadCall_;
overrideParams.readAt = readAt_;
}

/// @notice Sets gasLimit overrides
/// @param gasLimit_ The gas limit
function _setOverrides(uint256 gasLimit_) internal {
gasLimit = gasLimit_;
overrideParams.gasLimit = gasLimit_;
}

/// @notice Sets fees overrides
Expand All @@ -227,6 +258,20 @@ abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway, FeesPlugin
fees = fees_;
}

function getOverrideParams()
public
view
returns (Read, Parallel, WriteFinality, uint256, uint256)
{
return (
overrideParams.isReadCall,
overrideParams.isParallelCall,
overrideParams.writeFinality,
overrideParams.readAt,
overrideParams.gasLimit
);
}

////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////// ASYNC BATCH HELPERS /////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
12 changes: 5 additions & 7 deletions contracts/interfaces/IAppGateway.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.21;

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

interface IAppGateway {
function isReadCall() external view returns (Read);

function isParallelCall() external view returns (Parallel);

function gasLimit() external view returns (uint256);

function isAsyncModifierSet() external view returns (bool);
function getOverrideParams()
external
view
returns (Read, Parallel, WriteFinality, uint256, uint256);

function onBatchComplete(bytes32 asyncId_, PayloadBatch memory payloadBatch_) external;

Expand Down
14 changes: 2 additions & 12 deletions contracts/interfaces/IDeliveryHelper.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.3;
import {PayloadDetails, Bid, Fees, DeployParams, CallType, PayloadBatch, Parallel, IsPlug} from "../protocol/utils/common/Structs.sol";
import {PayloadDetails, CallParams, Bid, Fees, WriteFinality, DeployParams, CallType, PayloadBatch, Parallel, IsPlug} from "../protocol/utils/common/Structs.sol";

interface IDeliveryHelper {
event BidPlaced(
Expand All @@ -19,17 +19,7 @@ interface IDeliveryHelper {

function clearQueue() external;

function queue(
IsPlug isPlug_,
Parallel isParallel_,
uint32 chainSlug_,
address target_,
address asyncPromise_,
uint256 value_,
CallType callType_,
bytes memory payload_,
bytes memory initCallData_
) external;
function queue(CallParams memory callParams_) external;

function batch(
Fees memory fees_,
Expand Down
5 changes: 3 additions & 2 deletions contracts/interfaces/IWatcherPrecompile.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.21;

import {PayloadDetails, AsyncRequest, FinalizeParams, PayloadDigestParams, AppGatewayConfig, PlugConfig, ResolvedPromises} from "../protocol/utils/common/Structs.sol";
import {PayloadDetails, AsyncRequest, FinalizeParams, WriteFinality, PayloadDigestParams, AppGatewayConfig, PlugConfig, ResolvedPromises} from "../protocol/utils/common/Structs.sol";

/// @title IWatcherPrecompile
/// @notice Interface for the Watcher Precompile system that handles payload verification and execution
Expand Down Expand Up @@ -59,7 +59,8 @@ interface IWatcherPrecompile {
address targetAddress_,
address appGateway_,
address[] memory asyncPromises_,
bytes memory payload_
bytes memory payload_,
uint256 readAt_
) external returns (bytes32 payloadId);

/// @notice Marks a request as finalized with a proof
Expand Down
32 changes: 21 additions & 11 deletions contracts/protocol/Forwarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,30 @@ contract Forwarder is ForwarderStorage, Initializable {
);

// Determine if the call is a read or write operation.
Read isReadCall = IAppGateway(msg.sender).isReadCall();
Parallel isParallelCall = IAppGateway(msg.sender).isParallelCall();
(
Read isReadCall,
Parallel isParallelCall,
WriteFinality writeFinality,
uint256 readAt,
uint256 gasLimit
) = IAppGateway(msg.sender).getOverrideParams();

// Queue the call in the auction house.
IDeliveryHelper(deliveryHelper).queue(
IsPlug.NO,
isParallelCall,
chainSlug,
onChainAddress,
latestAsyncPromise,
0,
isReadCall == Read.ON ? CallType.READ : CallType.WRITE,
msg.data,
bytes("")
CallParams({
isPlug: IsPlug.NO,
isParallel: isParallelCall,
chainSlug: chainSlug,
target: onChainAddress,
asyncPromise: latestAsyncPromise,
value: 0,
gasLimit: gasLimit,
callType: isReadCall == Read.ON ? CallType.READ : CallType.WRITE,
writeFinality: writeFinality,
readAt: readAt,
payload: msg.data,
initCallData: bytes("")
})
);
}

Expand Down
4 changes: 3 additions & 1 deletion contracts/protocol/payload-delivery/FeesManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {IFeesManager} from "../../interfaces/IFeesManager.sol";
import {AddressResolverUtil} from "../utils/AddressResolverUtil.sol";
import {WITHDRAW} from "../utils/common/Constants.sol";
import {NotAuctionManager} from "../utils/common/Errors.sol";
import {Bid, Fees, PayloadDetails, CallType, FinalizeParams, Parallel} from "../utils/common/Structs.sol";
import {Bid, Fees, PayloadDetails, CallType, FinalizeParams, Parallel, WriteFinality} from "../utils/common/Structs.sol";

abstract contract FeesManagerStorage is IFeesManager {
// slots [0-49] reserved for gap
Expand Down Expand Up @@ -331,6 +331,8 @@ contract FeesManager is FeesManagerStorage, Initializable, Ownable, AddressResol
target: _getFeesPlugAddress(chainSlug_),
payload: payload_,
callType: callType_,
writeFinality: WriteFinality.LOW,
readAt: 0,
value: 0,
executionGasLimit: 1000000,
next: new address[](2),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ abstract contract BatchAsync is QueueAsync {
payloadDetails_[i].target,
payloadDetails_[i].appGateway,
payloadDetails_[i].next,
payloadDetails_[i].payload
payloadDetails_[i].payload,
payloadDetails_[i].readAt
);
payloadIdToBatchHash[payloadId] = asyncId;
payloadBatchDetails[asyncId].push(payloadDetails_[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ contract DeliveryHelper is BatchAsync {
payloadDetails_.target,
payloadDetails_.appGateway,
payloadDetails_.next,
payloadDetails_.payload
payloadDetails_.payload,
payloadDetails_.readAt
);
digest = bytes32(0);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {IAddressResolver} from "../../../interfaces/IAddressResolver.sol";
import {IAuctionManager} from "../../../interfaces/IAuctionManager.sol";
import {IFeesManager} from "../../../interfaces/IFeesManager.sol";

import {CallParams, Fees, PayloadDetails, CallType, Bid, PayloadBatch, Parallel, IsPlug, FinalizeParams} from "../../utils/common/Structs.sol";
import {CallParams, Fees, PayloadDetails, CallType, Bid, PayloadBatch, Parallel, IsPlug, FinalizeParams, WriteFinality} from "../../utils/common/Structs.sol";
import {NotAuctionManager, InvalidPromise, InvalidIndex, PromisesNotResolved, InvalidTransmitter} from "../../utils/common/Errors.sol";
import {FORWARD_CALL, DISTRIBUTE_FEE, DEPLOY, WITHDRAW, QUERY, FINALIZE} from "../../utils/common/Constants.sol";

Expand Down
38 changes: 6 additions & 32 deletions contracts/protocol/payload-delivery/app-gateway/QueueAsync.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import "solady/utils/Initializable.sol";
import {AddressResolverUtil} from "../../utils/AddressResolverUtil.sol";

import "./DeliveryHelperStorage.sol";

/// @notice Abstract contract for managing asynchronous payloads
abstract contract QueueAsync is DeliveryHelperStorage, Initializable, Ownable, AddressResolverUtil {
// slots [0-108] reserved for delivery helper storage and [109-159] reserved for addr resolver util
Expand Down Expand Up @@ -41,37 +40,10 @@ abstract contract QueueAsync is DeliveryHelperStorage, Initializable, Ownable, A
}

/// @notice Queues a new payload
/// @param chainSlug_ The chain identifier
/// @param target_ The target address
/// @param asyncPromise_ The async promise or ID
/// @param callType_ The call type
/// @param payload_ The payload
function queue(
IsPlug isPlug_,
Parallel isParallel_,
uint32 chainSlug_,
address target_,
address asyncPromise_,
uint256 value_,
CallType callType_,
bytes memory payload_,
bytes memory initCallData_
) external {
// todo: sb related details
callParamsArray.push(
CallParams({
isPlug: isPlug_,
callType: callType_,
asyncPromise: asyncPromise_,
chainSlug: chainSlug_,
target: target_,
payload: payload_,
value: value_,
gasLimit: 10000000,
isParallel: isParallel_,
initCallData: initCallData_
})
);
/// @param callParams_ The call parameters
function queue(CallParams memory callParams_) external {
callParams_.gasLimit = callParams_.gasLimit == 0 ? 10_000_000 : callParams_.gasLimit;
callParamsArray.push(callParams_);
}

/// @notice Creates an array of payload details
Expand Down Expand Up @@ -138,6 +110,8 @@ abstract contract QueueAsync is DeliveryHelperStorage, Initializable, Ownable, A
value: params_.value,
payload: payload_,
callType: params_.callType,
writeFinality: params_.writeFinality,
readAt: params_.readAt,
executionGasLimit: params_.gasLimit == 0 ? 1_000_000 : params_.gasLimit,
next: next,
isParallel: params_.isParallel
Expand Down
Loading
Loading