Skip to content

Commit 200454e

Browse files
authored
Merge pull request #134 from SocketDotTech/new-contract-structure
Contract Structure
2 parents 3a4ef8a + 0aba364 commit 200454e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1450
-1711
lines changed

contracts/evmx/payload-delivery/app-gateway/DeliveryHelper.sol renamed to contracts/app-gateway/DeliveryHelper.sol

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,6 @@ import "./FeesHelpers.sol";
66
/// @title DeliveryHelper
77
/// @notice Contract for managing payload delivery
88
contract DeliveryHelper is FeesHelpers {
9-
constructor() {
10-
_disableInitializers(); // disable for implementation
11-
}
12-
13-
/// @notice Initializer function to replace constructor
14-
/// @param addressResolver_ The address resolver contract
15-
/// @param owner_ The owner address
16-
function initialize(
17-
address addressResolver_,
18-
address owner_,
19-
uint128 bidTimeout_
20-
) public reinitializer(1) {
21-
_setAddressResolver(addressResolver_);
22-
_initializeOwner(owner_);
23-
24-
bidTimeout = bidTimeout_;
25-
}
269

2710
/// @notice Calls the watcher precompile to start processing a request
2811
/// @dev If a transmitter was already assigned, it updates the transmitter in watcher precompile too
@@ -104,12 +87,4 @@ contract DeliveryHelper is FeesHelpers {
10487
}
10588
}
10689

107-
/// @notice Returns the request metadata
108-
/// @param requestCount_ The ID of the request
109-
/// @return requestMetadata The request metadata
110-
function getRequestMetadata(
111-
uint40 requestCount_
112-
) external view returns (RequestMetadata memory) {
113-
return requests[requestCount_];
114-
}
11590
}

contracts/evmx/payload-delivery/app-gateway/RequestQueue.sol renamed to contracts/app-gateway/RequestQueue.sol

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,7 @@ abstract contract RequestQueue is DeliveryUtils {
88
// slots [207-257] reserved for gap
99
uint256[50] _gap_queue_async;
1010

11-
/// @notice Clears the call parameters array
12-
function clearQueue() public {
13-
delete queuePayloadParams;
14-
}
15-
16-
/// @notice Queues a new payload
17-
/// @param queuePayloadParams_ The call parameters
18-
function queue(QueuePayloadParams memory queuePayloadParams_) external {
19-
queuePayloadParams.push(queuePayloadParams_);
20-
}
21-
11+
2212
/// @notice Initiates a batch of payloads
2313
/// @param maxFees_ The fees data
2414
/// @param auctionManager_ The auction manager address
@@ -69,7 +59,6 @@ abstract contract RequestQueue is DeliveryUtils {
6959
params.finalizeCount = finalizeCount;
7060

7161
_checkBatch(consumeFrom_, params.appGateway, params.maxFees);
72-
7362
return _submitBatchRequest(payloadSubmitParamsArray, consumeFrom_, params);
7463
}
7564

@@ -209,7 +198,6 @@ abstract contract RequestQueue is DeliveryUtils {
209198
(payload, target) = _createDeployPayloadDetails(queuePayloadParams_);
210199
}
211200

212-
if (payload.length > PAYLOAD_SIZE_LIMIT) revert PayloadTooLarge();
213201
if (queuePayloadParams_.value > chainMaxMsgValueLimit[queuePayloadParams_.chainSlug])
214202
revert MaxMsgValueLimitExceeded();
215203

contracts/evmx/watcherPrecompile/core/RequestHandler.sol renamed to contracts/core/RequestHandler.sol

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ abstract contract RequestHandler is WatcherPrecompileCore {
135135
/// @dev It verifies that the caller is the middleware and that the request hasn't been started yet
136136
function startProcessingRequest(uint40 requestCount, address transmitter_) public {
137137
RequestParams storage r = requestParams[requestCount];
138-
if (r.middleware != msg.sender) revert InvalidCaller();
139138
if (r.transmitter != address(0)) revert AlreadyStarted();
140139
if (r.currentBatchPayloadsLeft > 0) revert AlreadyStarted();
141140

@@ -171,10 +170,5 @@ abstract contract RequestHandler is WatcherPrecompileCore {
171170
r.currentBatchPayloadsLeft = totalPayloads;
172171
}
173172

174-
/// @notice Gets the current request count
175-
/// @return The current request count
176-
/// @dev This function returns the next request count, which is the current request count
177-
function getCurrentRequestCount() external view returns (uint40) {
178-
return nextRequestCount;
179-
}
173+
180174
}

contracts/evmx/watcherPrecompile/core/WatcherPrecompileCore.sol renamed to contracts/core/WatcherPrecompileCore.sol

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ abstract contract WatcherPrecompileCore is
115115
payloads[params_.payloadId].prevDigestsHash = _getPreviousDigestsHash(
116116
params_.payloadHeader.getBatchCount()
117117
);
118-
emit QueryRequested(params_);
119118
}
120119

121120
// ================== Helper functions ==================
@@ -185,37 +184,7 @@ abstract contract WatcherPrecompileCore is
185184
return payloadParamsArray;
186185
}
187186

188-
/// @notice Encodes an ID for a timeout or payload
189-
/// @return The encoded ID
190-
/// @dev This function creates a unique ID by combining the chain slug, address, and a counter
191-
function _encodeTimeoutId() internal returns (bytes32) {
192-
// Encode timeout ID by bit-shifting and combining:
193-
// EVMx chainSlug (32 bits) | watcher precompile address (160 bits) | counter (64 bits)
194-
return bytes32(timeoutIdPrefix | payloadCounter++);
195-
}
196-
197-
/// @notice Verifies that a watcher signature is valid
198-
/// @param inputData_ The input data to verify
199-
/// @param signatureNonce_ The nonce of the signature
200-
/// @param signature_ The signature to verify
201-
/// @dev This function verifies that the signature was created by the watcher and that the nonce has not been used before
202-
function _isWatcherSignatureValid(
203-
bytes memory inputData_,
204-
uint256 signatureNonce_,
205-
bytes memory signature_
206-
) internal {
207-
if (isNonceUsed[signatureNonce_]) revert NonceUsed();
208-
isNonceUsed[signatureNonce_] = true;
209-
210-
bytes32 digest = keccak256(
211-
abi.encode(address(this), evmxSlug, signatureNonce_, inputData_)
212-
);
213-
digest = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", digest));
214-
215-
// recovered signer is checked for the valid roles later
216-
address signer = ECDSA.recover(digest, signature_);
217-
if (signer != owner()) revert InvalidWatcherSignature();
218-
}
187+
219188

220189
function _consumeCallbackFeesFromRequestCount(uint256 fees_, uint40 requestCount_) internal {
221190
// for callbacks in all precompiles
@@ -233,24 +202,4 @@ abstract contract WatcherPrecompileCore is
233202
);
234203
}
235204

236-
/// @notice Gets the batch IDs for a request
237-
/// @param requestCount_ The request count to get the batch IDs for
238-
/// @return An array of batch IDs for the given request
239-
function getBatches(uint40 requestCount_) external view returns (uint40[] memory) {
240-
return requestBatchIds[requestCount_];
241-
}
242-
243-
/// @notice Gets the payload IDs for a batch
244-
/// @param batchCount_ The batch count to get the payload IDs for
245-
/// @return An array of payload IDs for the given batch
246-
function getBatchPayloadIds(uint40 batchCount_) external view returns (bytes32[] memory) {
247-
return batchPayloadIds[batchCount_];
248-
}
249-
250-
/// @notice Gets the payload parameters for a payload ID
251-
/// @param payloadId_ The payload ID to get the parameters for
252-
/// @return The payload parameters for the given payload ID
253-
function getPayloadParams(bytes32 payloadId_) external view returns (PayloadParams memory) {
254-
return payloads[payloadId_];
255-
}
256205
}

contracts/evmx/AddressResolverUtil.sol

Lines changed: 0 additions & 104 deletions
This file was deleted.

contracts/evmx/payload-delivery/AuctionManager.sol renamed to contracts/evmx/app-gateways/AuctionManager.sol

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ pragma solidity ^0.8.21;
44
import {ECDSA} from "solady/utils/ECDSA.sol";
55
import "solady/utils/Initializable.sol";
66
import "../interfaces/IAuctionManager.sol";
7-
import {IMiddleware} from "../interfaces/IMiddleware.sol";
8-
import {IFeesManager} from "../interfaces/IFeesManager.sol";
97
import "../../utils/AccessControl.sol";
10-
import {AddressResolverUtil} from "../AddressResolverUtil.sol";
118
import {AuctionClosed, AuctionAlreadyStarted, BidExceedsMaxFees, LowerBidAlreadyExists, InvalidTransmitter} from "../../utils/common/Errors.sol";
129
import {TRANSMITTER_ROLE} from "../../utils/common/AccessRoles.sol";
10+
import {AppGatewayBase} from "../base/AppGatewayBase.sol";
1311

1412
/// @title AuctionManagerStorage
1513
/// @notice Storage for the AuctionManager contract
@@ -20,6 +18,10 @@ abstract contract AuctionManagerStorage is IAuctionManager {
2018
// slot 50
2119
uint32 public evmxSlug;
2220

21+
// slot 50
22+
/// @notice The timeout after which a bid expires
23+
uint128 public bidTimeout;
24+
2325
// slot 51
2426
uint256 public maxReAuctionCount;
2527

@@ -48,12 +50,7 @@ abstract contract AuctionManagerStorage is IAuctionManager {
4850

4951
/// @title AuctionManager
5052
/// @notice Contract for managing auctions and placing bids
51-
contract AuctionManager is
52-
AuctionManagerStorage,
53-
Initializable,
54-
AccessControl,
55-
AddressResolverUtil
56-
{
53+
contract AuctionManager is AuctionManagerStorage, Initializable, AccessControl, AppGatewayBase {
5754
event AuctionRestarted(uint40 requestCount);
5855
event AuctionStarted(uint40 requestCount);
5956
event AuctionEnded(uint40 requestCount, Bid winningBid);
@@ -132,6 +129,7 @@ contract AuctionManager is
132129
// end the auction if the no auction end delay
133130
if (auctionEndDelaySeconds > 0) {
134131
_startAuction(requestCount_);
132+
// queue and create request
135133
watcherPrecompile__().setTimeout(
136134
auctionEndDelaySeconds,
137135
abi.encodeWithSelector(this.endAuction.selector, requestCount_)
@@ -150,11 +148,8 @@ contract AuctionManager is
150148
if (requestMetadata.auctionManager != address(this)) revert InvalidBid();
151149

152150
// get the total fees required for the watcher precompile ops
153-
uint256 watcherFees = watcherPrecompileLimits().getTotalFeesRequired(
154-
requestMetadata.queryCount,
155-
requestMetadata.finalizeCount,
156-
0,
157-
0
151+
uint256 watcherFees = watcherPrecompile().getMaxFees(
152+
requestCount_
158153
);
159154
return requestMetadata.maxFees - watcherFees;
160155
}
@@ -173,25 +168,35 @@ contract AuctionManager is
173168

174169
auctionClosed[requestCount_] = true;
175170
RequestMetadata memory requestMetadata = _getRequestMetadata(requestCount_);
171+
176172
// block the fees
177-
IFeesManager(addressResolver__.feesManager()).blockCredits(
178-
requestMetadata.consumeFrom,
179-
winningBid.fee,
180-
requestCount_
181-
);
173+
// in startRequestProcessing, block the fees from bid
174+
// IFeesManager(addressResolver__.feesManager()).blockCredits(
175+
// requestMetadata.consumeFrom,
176+
// winningBid.fee,
177+
// requestCount_
178+
// );
182179

183180
// set the timeout for the bid expiration
184181
// useful in case a transmitter did bid but did not execute payloads
185-
watcherPrecompile__().setTimeout(
186-
IMiddleware(addressResolver__.deliveryHelper()).bidTimeout(),
187-
abi.encodeWithSelector(this.expireBid.selector, requestCount_)
188-
);
182+
// todo: queue and submit timeouts
183+
// watcherPrecompile__().timeout(
184+
// address(this),
185+
// abi.encodeWithSelector(this.expireBid.selector, requestCount_)
186+
// );
189187

190188
// start the request processing, it will finalize the request
191-
IMiddleware(addressResolver__.deliveryHelper()).startRequestProcessing(
192-
requestCount_,
193-
winningBid
194-
);
189+
if(requestMetadata.transmitter != address(0)) {
190+
IWatcherPrecompile(addressResolver__.watcherPrecompile()).updateTransmitter(
191+
requestCount_,
192+
winningBid
193+
);
194+
} else
195+
IWatcherPrecompile(addressResolver__.watcherPrecompile()).startRequestProcessing(
196+
requestCount_,
197+
winningBid
198+
);
199+
}
195200

196201
emit AuctionEnded(requestCount_, winningBid);
197202
}
@@ -210,7 +215,8 @@ contract AuctionManager is
210215
auctionClosed[requestCount_] = false;
211216
reAuctionCount[requestCount_]++;
212217

213-
IFeesManager(addressResolver__.feesManager()).unblockCredits(requestCount_);
218+
// todo: unblock credits by calling watcher for updating transmitter to addr(0)
219+
// IFeesManager(addressResolver__.feesManager()).unblockCredits(requestCount_);
214220
emit AuctionRestarted(requestCount_);
215221
}
216222

0 commit comments

Comments
 (0)