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
25 changes: 19 additions & 6 deletions contracts/BaseACPHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ pragma solidity ^0.8.20;

import "./IACPHook.sol";

/// @dev Local mirror of AgenticCommerceHooked.Job for ABI-decoding getJob() return data.
/// getJob returns a struct (dynamic tuple because of `string`), so abi.decode must
/// use a matching struct type — flat-tuple decoding skips the offset wrapper and reverts.
struct ACPJob {
uint256 id;
address client;
address provider;
address evaluator;
address hook;
string description;
uint256 budget;
uint256 expiredAt;
uint8 status;
}

/**
* @title BaseACPHook
* @dev Abstract convenience base for ACP hooks. Routes the generic
Expand Down Expand Up @@ -46,7 +61,7 @@ abstract contract BaseACPHook is IACPHook {
// These match AgenticCommerceHooked function selectors.
bytes4 private constant SEL_SET_PROVIDER = bytes4(keccak256("setProvider(uint256,address,bytes)"));
bytes4 private constant SEL_SET_BUDGET = bytes4(keccak256("setBudget(uint256,uint256,bytes)"));
bytes4 private constant SEL_FUND = bytes4(keccak256("fund(uint256,bytes)"));
bytes4 private constant SEL_FUND = bytes4(keccak256("fund(uint256,uint256,bytes)"));
bytes4 private constant SEL_SUBMIT = bytes4(keccak256("submit(uint256,bytes32,bytes)"));
bytes4 private constant SEL_COMPLETE = bytes4(keccak256("complete(uint256,bytes32,bytes)"));
bytes4 private constant SEL_REJECT = bytes4(keccak256("reject(uint256,bytes32,bytes)"));
Expand Down Expand Up @@ -117,14 +132,12 @@ abstract contract BaseACPHook is IACPHook {

// --- Helper: read job from ACP contract ----------------------------------

function _getJobClient(uint256 jobId) internal view returns (address client) {
function _getJobClient(uint256 jobId) internal view returns (address) {
(bool ok, bytes memory data) = acpContract.staticcall(
abi.encodeWithSignature("getJob(uint256)", jobId)
);
require(ok, "getJob failed");
// Job struct: (id, client, provider, evaluator, hook, description, budget, expiredAt, status)
(, client,,,,,,, ) = abi.decode(
data, (uint256, address, address, address, address, string, uint256, uint256, uint8)
);
ACPJob memory job = abi.decode(data, (ACPJob));
return job.client;
}
}
8 changes: 3 additions & 5 deletions contracts/hooks/BiddingHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,12 @@ contract BiddingHook is BaseACPHook {

// --- Helper --------------------------------------------------------------

function _getJobBudget(uint256 jobId) internal view returns (uint256 budget) {
function _getJobBudget(uint256 jobId) internal view returns (uint256) {
(bool ok, bytes memory data) = acpContract.staticcall(
abi.encodeWithSignature("getJob(uint256)", jobId)
);
require(ok, "getJob failed");
// Job struct: (id, client, provider, evaluator, hook, description, budget, expiredAt, status)
(,,,,,, budget,,) = abi.decode(
data, (uint256, address, address, address, address, string, uint256, uint256, uint8)
);
ACPJob memory job = abi.decode(data, (ACPJob));
return job.budget;
}
}
8 changes: 3 additions & 5 deletions contracts/hooks/FundTransferHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,12 @@ contract FundTransferHook is BaseACPHook {
// Internal helpers
// -------------------------------------------------------------------------

function _getJobProviderAndStatus(uint256 jobId) internal view returns (address provider, uint8 status) {
function _getJobProviderAndStatus(uint256 jobId) internal view returns (address, uint8) {
(bool ok, bytes memory data) = acpContract.staticcall(
abi.encodeWithSignature("getJob(uint256)", jobId)
);
require(ok, "getJob failed");
// Job struct: (id, client, provider, evaluator, hook, description, budget, expiredAt, status)
(,, provider,,,,,, status) = abi.decode(
data, (uint256, address, address, address, address, string, uint256, uint256, uint8)
);
ACPJob memory job = abi.decode(data, (ACPJob));
return (job.provider, job.status);
}
}