Skip to content

Commit

Permalink
[Functions] Various changes from review #2 (#10014)
Browse files Browse the repository at this point in the history
* Move FulfillResultCodes to interfaces folder

* Rename Function.sol setArgs -> addArgs

* Rename Routable s_config_hash -> s_configHash

* Make Routable updateConfig public for re-use in constructor

* Move comment out of IConfigurable

* Make Routable s_router private with an internal getter

* Rename constant to ROUTER_ID

* Rename RouterBase  s_config_hash -> s_configHash

* Rename Routable.sol -> HasRouter.sol

* Add IOwnableRouter interface

* FunctionsSubscriptions MustBeSubOwner -> MustBeSubscriptionOwner

* Make RouterBase variable private

* RouterBase togglePause -> pause/unpause

* Use full semantic version in typeAndVersion

* ToS Allow List rename proof -> signature

* Change acceptTermsOfService arguments from signature to raw r,s,v

* Prettier format 💅

* Remove RouterBase versioning

* Move RequestTimedOut event to Router

* Rename requestSubscriptionOwnerTransfer -> proposeSubscriptionOwnerTransfer

* (test): Update tests for changes

* (test): Add v0 gas test

* Regenerate geth wrappers

* Use FulfillResult within FunctionsRouter

* FunctionsRouter getConfig getter

* Strip down FunctionsClient.sol

* Rename GAS_FLAX_INDEX -> MAX_CALLBACK_GAS_LIMIT_FLAGS_INDEX

* Use named params in structs in FunctionsRouter

* Use named params in RouterBase.sol

* Split overloaded getContractById into getContractById & getProposedContractById

* Cast IFunctionsCoordinator earlier in the sendRequest flow

* Split updateConfig flow into updateConfigSelf vs. updateConfig

* Reduce contract size by removing Router's config hash getter

* Remove second ToS Allow List message helper

* FunctionsRouter assign variable for fulfillmentCost

* Use abi.encode to convert bytes32 -> bytes

* Turn RouterBase.validateProposedContracts -> FunctionsRouter.sendRequestToProposed

* Add extra guards against double applying config updates

* Delete contract proposal set once applied

* Re-use _onlySubscriptionOwner

* Pass _pay gasUsed as uint96

* Remove config hashes

* Regenerate geth wrappers

* Amend merge conflict

* Regenerate geth wrappers

* Prettier & gethwrappers

* (test): amend foundry test
  • Loading branch information
justinkaseman committed Aug 2, 2023
1 parent a5f343e commit 600365a
Show file tree
Hide file tree
Showing 25 changed files with 409 additions and 571 deletions.
15 changes: 7 additions & 8 deletions contracts/src/v0.8/functions/dev/1_0_0/FunctionsBilling.sol
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ abstract contract FunctionsBilling is HasRouter, IFunctionsBilling {
* @inheritdoc IFunctionsBilling
*/
function getAdminFee() public view override returns (uint96) {
IFunctionsRouter.Config memory config = _getRouter().getConfig();
return config.adminFee;
(, uint96 adminFee, , ) = _getRouter().getConfig();
return adminFee;
}

function getFeedData() public view returns (int256) {
Expand Down Expand Up @@ -288,10 +288,10 @@ abstract contract FunctionsBilling is HasRouter, IFunctionsBilling {
billing.adminFee
);
IFunctionsSubscriptions subscriptions = IFunctionsSubscriptions(address(_getRouter()));
(uint96 balance, uint96 blockedBalance, , , ) = subscriptions.getSubscription(billing.subscriptionId);
IFunctionsSubscriptions.Subscription memory subscription = subscriptions.getSubscription(billing.subscriptionId);
(, uint64 initiatedRequests, ) = subscriptions.getConsumer(billing.client, billing.subscriptionId);

if (balance - blockedBalance < estimatedCost) {
if (subscription.balance - subscription.blockedBalance < estimatedCost) {
revert InsufficientBalance();
}

Expand Down Expand Up @@ -364,7 +364,7 @@ abstract contract FunctionsBilling is HasRouter, IFunctionsBilling {
);

// The Functions Router will perform the callback to the client contract
(uint8 result, uint96 callbackCostJuels) = _getRouter().fulfill(
(FulfillResult resultCode, uint96 callbackCostJuels) = _getRouter().fulfill(
response,
err,
uint96(juelsPerGas),
Expand All @@ -373,8 +373,7 @@ abstract contract FunctionsBilling is HasRouter, IFunctionsBilling {
commitment
);

FulfillResult fulfillResult = FulfillResult(result);
if (fulfillResult == FulfillResult.USER_SUCCESS || fulfillResult == FulfillResult.USER_ERROR) {
if (resultCode == FulfillResult.USER_SUCCESS || resultCode == FulfillResult.USER_ERROR) {
delete s_requestCommitments[requestId];
// Reimburse the transmitter for the fulfillment gas cost
s_withdrawableTokens[msg.sender] = gasOverheadJuels + callbackCostJuels;
Expand All @@ -383,7 +382,7 @@ abstract contract FunctionsBilling is HasRouter, IFunctionsBilling {
s_feePool += commitment.donFee;
}

return fulfillResult;
return resultCode;
}

// ================================================================
Expand Down
23 changes: 2 additions & 21 deletions contracts/src/v0.8/functions/dev/1_0_0/FunctionsClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,10 @@ abstract contract FunctionsClient is IFunctionsClient {
/**
* @inheritdoc IFunctionsClient
*/
function handleOracleFulfillment(
bytes32 requestId,
bytes memory response,
bytes memory err
) external override onlyRouter {
fulfillRequest(requestId, response, err);
}

/**
* @notice Gets the stored address of the router contract
* @return The address of the router contract
*/
function getRouter() internal view returns (address) {
return address(s_router);
}

/**
* @dev Reverts if the request is not from the Router
*/
modifier onlyRouter() {
function handleOracleFulfillment(bytes32 requestId, bytes memory response, bytes memory err) external override {
if (msg.sender != address(s_router)) {
revert OnlyRouterCanFufill();
}
_;
fulfillRequest(requestId, response, err);
}
}
Loading

0 comments on commit 600365a

Please sign in to comment.