Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bdd3cce
feat: fees changes, WIP
tHeMaskedMan981 Apr 16, 2025
5f293e0
fix: changes till auction
ameeshaagrawal Apr 17, 2025
aef1ebb
feat: watcher precompile fees and callback fees
ameeshaagrawal Apr 17, 2025
b9ca484
feat: callback fees in finalize
ameeshaagrawal Apr 18, 2025
2a7a8e8
fix: unblock and assign fees
ameeshaagrawal Apr 18, 2025
b2b49b0
feat: deduct fees from gateway
ameeshaagrawal Apr 18, 2025
9c39bd0
fix: remove token and chain context from evmx
ameeshaagrawal Apr 18, 2025
e38a395
fix: remove old structs
ameeshaagrawal Apr 18, 2025
6a399f0
fix: wip build fix
ameeshaagrawal Apr 18, 2025
fceb0df
fix: build, wip
tHeMaskedMan981 Apr 21, 2025
f525c11
fix: test build
ameeshaagrawal Apr 21, 2025
c38aeeb
fix: script and test build
ameeshaagrawal Apr 21, 2025
8c48ba3
wip: consume limit
ameeshaagrawal Apr 21, 2025
a807b55
Merge pull request #115 from SocketDotTech/fees-after-auction
arthcp Apr 22, 2025
8b63382
Merge pull request #116 from SocketDotTech/trigger-fees
arthcp Apr 22, 2025
6c803eb
Merge pull request #117 from SocketDotTech/fees-management
arthcp Apr 22, 2025
5e3a9c9
Merge pull request #118 from SocketDotTech/fees-test
arthcp Apr 22, 2025
8658b95
fix: fee tests
tHeMaskedMan981 Apr 22, 2025
6651506
fix: tests
tHeMaskedMan981 Apr 22, 2025
15ae407
fix: renames
tHeMaskedMan981 Apr 23, 2025
f23d9ea
Merge branch 'dev' into fees-test
ameeshaagrawal Apr 23, 2025
0613efa
feat: wrap unwrap fees
ameeshaagrawal Apr 23, 2025
02e9067
fix: tests
ameeshaagrawal Apr 24, 2025
f1a6ce3
fix: payable deposit credit
ameeshaagrawal Apr 24, 2025
91dbe9d
fix: remove approval data from middleware and watcher
ameeshaagrawal Apr 24, 2025
eb419c3
feat: modifier with consume from in case gateways resolve it
ameeshaagrawal Apr 24, 2025
28e678e
Merge pull request #121 from SocketDotTech/fees-test
ameeshaagrawal Apr 24, 2025
581971e
Merge branch 'dev' into fees
ameeshaagrawal Apr 25, 2025
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
2 changes: 1 addition & 1 deletion FunctionSignatures.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
| `requestOwnershipHandover` | `0x25692962` |
| `sbType` | `0x745de344` |
| `transferOwnership` | `0xf2fde38b` |
| `transmitterFees` | `0xefb4cdea` |
| `transmitterCredits` | `0xefb4cdea` |
| `unblockAndAssignFees` | `0x3c5366a2` |
| `unblockFees` | `0xc1867a4b` |
| `watcherPrecompileConfig` | `0x8618a912` |
Expand Down
63 changes: 44 additions & 19 deletions contracts/base/AppGatewayBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,64 @@ import "../interfaces/IForwarder.sol";
import "../interfaces/IMiddleware.sol";
import "../interfaces/IPromise.sol";

import {FeesPlugin} from "../protocol/utils/FeesPlugin.sol";
import {InvalidPromise, FeesNotSet, AsyncModifierNotUsed} from "../protocol/utils/common/Errors.sol";
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 {
abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway {
OverrideParams public overrideParams;
bool public isAsyncModifierSet;
address public auctionManager;
bytes32 public sbType;
bytes public onCompleteData;
uint256 public maxFees;

mapping(address => bool) public isValidPromise;
mapping(bytes32 => mapping(uint32 => address)) public override forwarderAddresses;
mapping(bytes32 => bytes) public creationCodeWithArgs;

address public consumeFrom;

/// @notice Modifier to treat functions async
modifier async() {
if (fees.feePoolChain == 0) revert FeesNotSet();
modifier async(bytes memory feesApprovalData_) {
_preAsync(feesApprovalData_);
_;
_postAsync();
}

// todo: can't overload modifier with same name, can rename later
/// @notice Modifier to treat functions async with consume from address
modifier asyncWithConsume(address consumeFrom_) {
_preAsync(new bytes(0));
consumeFrom = consumeFrom_;
_;
_postAsync();
}

function _postAsync() internal {
isAsyncModifierSet = false;

deliveryHelper__().batch(maxFees, auctionManager, consumeFrom, onCompleteData);
_markValidPromises();
onCompleteData = bytes("");
}

function _preAsync(bytes memory feesApprovalData_) internal {
isAsyncModifierSet = true;
_clearOverrides();
deliveryHelper__().clearQueue();
addressResolver__.clearPromises();

_;
_handleFeesApproval(feesApprovalData_);
}

isAsyncModifierSet = false;
deliveryHelper__().batch(fees, auctionManager, onCompleteData);
_markValidPromises();
onCompleteData = bytes("");
function _handleFeesApproval(bytes memory feesApprovalData_) internal {
if (feesApprovalData_.length > 0) {
(consumeFrom, , ) = IFeesManager(addressResolver__.feesManager())
.whitelistAppGatewayWithSignature(feesApprovalData_);
} else consumeFrom = address(this);
}

/// @notice Modifier to ensure only valid promises can call the function
Expand Down Expand Up @@ -190,19 +215,19 @@ abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway, FeesPlugin

/// @notice Sets multiple overrides in one call
/// @param isReadCall_ The read call flag
/// @param fees_ The fees configuration
/// @param fees_ The maxFees configuration
/// @param gasLimit_ The gas limit
/// @param isParallelCall_ The sequential call flag
function _setOverrides(
Read isReadCall_,
Parallel isParallelCall_,
uint256 gasLimit_,
Fees memory fees_
uint256 fees_
) internal {
overrideParams.isReadCall = isReadCall_;
overrideParams.isParallelCall = isParallelCall_;
overrideParams.gasLimit = gasLimit_;
fees = fees_;
maxFees = fees_;
}

function _clearOverrides() internal {
Expand All @@ -214,7 +239,7 @@ abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway, FeesPlugin
overrideParams.writeFinality = WriteFinality.LOW;
}

/// @notice Sets isReadCall, fees and gasLimit overrides
/// @notice Sets isReadCall, maxFees and gasLimit overrides
/// @param isReadCall_ The read call flag
/// @param isParallelCall_ The sequential call flag
/// @param gasLimit_ The gas limit
Expand Down Expand Up @@ -276,10 +301,10 @@ abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway, FeesPlugin
overrideParams.value = value_;
}

/// @notice Sets fees overrides
/// @param fees_ The fees configuration
function _setOverrides(Fees memory fees_) internal {
fees = fees_;
/// @notice Sets maxFees overrides
/// @param fees_ The maxFees configuration
function _setMaxFees(uint256 fees_) internal {
maxFees = fees_;
}

function getOverrideParams()
Expand Down Expand Up @@ -308,7 +333,7 @@ abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway, FeesPlugin
deliveryHelper__().cancelRequest(requestCount_);
}

/// @notice increases the transaction fees
/// @notice increases the transaction maxFees
/// @param requestCount_ The async ID
function _increaseFees(uint40 requestCount_, uint256 newMaxFees_) internal {
deliveryHelper__().increaseFees(requestCount_, newMaxFees_);
Expand All @@ -332,7 +357,7 @@ abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway, FeesPlugin
amount_,
receiver_,
auctionManager,
fees
maxFees
);
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IAppGateway.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.21;

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

/// @title IAppGateway
/// @notice Interface for the app gateway
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IAuctionManager.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.21;

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

interface IAuctionManager {
/// @notice Bids for an auction
Expand Down
59 changes: 47 additions & 12 deletions contracts/interfaces/IFeesManager.sol
Original file line number Diff line number Diff line change
@@ -1,31 +1,66 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.21;

import {Fees, Bid, QueuePayloadParams} from "../protocol/utils/common/Structs.sol";
import {Bid, QueuePayloadParams, PayloadSubmitParams, AppGatewayWhitelistParams} from "../protocol/utils/common/Structs.sol";

interface IFeesManager {
function blockFees(
function blockCredits(
address consumeFrom_,
uint256 transmitterCredits_,
uint40 requestCount_
) external;

function unblockCredits(uint40 requestCount_) external;

function isUserCreditsEnough(
address consumeFrom_,
address appGateway_,
Fees memory fees_,
Bid memory winningBid_,
uint256 amount_
) external view returns (bool);

function unblockAndAssignCredits(uint40 requestCount_, address transmitter_) external;

function assignWatcherPrecompileCreditsFromRequestCount(
uint256 fees_,
uint40 requestCount_
) external;

function unblockFees(uint40 requestCount_) external;
function assignWatcherPrecompileCreditsFromAddress(
uint256 fees_,
address consumeFrom_
) external;

function whitelistAppGatewayWithSignature(
bytes memory feeApprovalData_
) external returns (address consumeFrom, address appGateway, bool isApproved);

function isFeesEnough(address appGateway_, Fees memory fees_) external view returns (bool);
function whitelistAppGateways(AppGatewayWhitelistParams[] calldata params_) external;

function unblockAndAssignFees(
uint40 requestCount_,
function getWithdrawTransmitterCreditsPayloadParams(
address transmitter_,
address appGateway_
) external;
uint32 chainSlug_,
address token_,
address receiver_,
uint256 amount_
) external returns (PayloadSubmitParams[] memory);

function withdrawFees(
address appGateway_,
function getMaxCreditsAvailableForWithdraw(
address transmitter_
) external view returns (uint256);

function withdrawCredits(
address originAppGatewayOrUser_,
uint32 chainSlug_,
address token_,
uint256 amount_,
address receiver_
) external;

function depositCredits(
address depositTo_,
uint32 chainSlug_,
address token_,
uint256 signatureNonce_,
bytes memory signature_
) external payable;
}
15 changes: 4 additions & 11 deletions contracts/interfaces/IFeesPlug.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@
pragma solidity ^0.8.21;

interface IFeesPlug {
function balanceOf(address token_) external view returns (uint256);
function depositToFee(address token_, address receiver_, uint256 amount_) external;

function feesRedeemed(bytes32 feesId_) external view returns (bool);
function depositToFeeAndNative(address token_, address receiver_, uint256 amount_) external;

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

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

function withdrawFees(address token_, uint256 amount_, address receiver_) external;
function withdrawFees(address token_, address receiver_, uint256 amount_) external;
}
9 changes: 5 additions & 4 deletions contracts/interfaces/IMiddleware.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.21;
import {PayloadSubmitParams, QueuePayloadParams, Bid, Fees, WriteFinality, CallType, Parallel, IsPlug, RequestMetadata} from "../protocol/utils/common/Structs.sol";
import {PayloadSubmitParams, QueuePayloadParams, Bid, WriteFinality, BatchParams, CallType, Parallel, IsPlug, RequestMetadata} from "../protocol/utils/common/Structs.sol";

/// @title IMiddleware
/// @notice Interface for the Middleware contract
Expand Down Expand Up @@ -28,8 +28,9 @@ interface IMiddleware {
/// @param onCompleteData_ The data to be passed to the onComplete callback
/// @return requestCount The request id
function batch(
Fees memory fees_,
uint256 fees_,
address auctionManager_,
address consumeFrom_,
bytes memory onCompleteData_
) external returns (uint40 requestCount);

Expand All @@ -46,7 +47,7 @@ interface IMiddleware {
uint256 amount_,
address receiver_,
address auctionManager_,
Fees memory fees_
uint256 fees_
) external returns (uint40);

/// @notice Cancels a request
Expand All @@ -64,7 +65,7 @@ interface IMiddleware {
function startRequestProcessing(uint40 requestCount_, Bid memory winningBid_) external;

/// @notice Returns the fees for a request
function getFees(uint40 requestCount_) external view returns (Fees memory);
function getFees(uint40 requestCount_) external view returns (uint256);

/// @notice Finishes a request by assigning fees and calling the onComplete callback
/// @param requestCount_ The request id
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IWatcherPrecompile.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.21;

import {DigestParams, ResolvedPromises, PayloadParams, TriggerParams, PayloadSubmitParams, RequestParams} from "../protocol/utils/common/Structs.sol";
import {DigestParams, ResolvedPromises, PayloadParams, TriggerParams, PayloadSubmitParams, Bid, RequestParams, RequestMetadata} from "../protocol/utils/common/Structs.sol";
import {IWatcherPrecompileLimits} from "./IWatcherPrecompileLimits.sol";
import {IWatcherPrecompileConfig} from "./IWatcherPrecompileConfig.sol";

Expand Down
12 changes: 12 additions & 0 deletions contracts/interfaces/IWatcherPrecompileLimits.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ interface IWatcherPrecompileLimits {
/// @param consumeLimit_ The amount of limit to consume
function consumeLimit(address appGateway_, bytes32 limitType_, uint256 consumeLimit_) external;

function getTotalFeesRequired(
uint256 queryCount_,
uint256 finalizeCount_,
uint256 scheduleCount_,
uint256 callbackCount_
) external view returns (uint256);

function queryFees() external view returns (uint256);
function finalizeFees() external view returns (uint256);
function timeoutFees() external view returns (uint256);
function callBackFees() external view returns (uint256);

/// @notice Emitted when limit parameters are updated
event LimitParamsUpdated(UpdateLimitParams[] updates);

Expand Down
Loading