@pushchain/core 6.0.27-alpha.3 → 6.0.27-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGW.md +27 -6
- package/CHANGELOG.md +7 -0
- package/MARKETPLACE.md +206 -0
- package/package.json +2 -1
- package/src/lib/agentic/codec/rules.js +74 -69
- package/src/lib/agentic/codec/universal.js +15 -3
- package/src/lib/agentic/constants.d.ts +36 -1
- package/src/lib/agentic/constants.js +14 -1
- package/src/lib/agentic/contracts/reader.d.ts +21 -0
- package/src/lib/agentic/contracts/reader.js +3 -0
- package/src/lib/agentic/error-messages.d.ts +3 -0
- package/src/lib/agentic/error-messages.js +125 -0
- package/src/lib/agentic/errors.d.ts +12 -3
- package/src/lib/agentic/errors.js +76 -0
- package/src/lib/agentic/management/common.js +6 -0
- package/src/lib/agentic/management/destination.d.ts +5 -0
- package/src/lib/agentic/management/destination.js +32 -0
- package/src/lib/agentic/management/prepare.js +80 -55
- package/src/lib/agentic/management/svm-public.js +13 -4
- package/src/lib/agentic/presets/index.js +7 -8
- package/src/lib/agentic/presets/routes.d.ts +1 -1
- package/src/lib/agentic/presets/routes.js +6 -7
- package/src/lib/agentic/presets/types.d.ts +1 -6
- package/src/lib/agentic/public-rule.js +13 -2
- package/src/lib/constants/index.d.ts +35 -0
- package/src/lib/index.d.ts +4 -0
- package/src/lib/index.js +6 -2
- package/src/lib/job/job.d.ts +35 -0
- package/src/lib/job/job.js +382 -0
- package/src/lib/job/types.d.ts +94 -0
- package/src/lib/job/types.js +3 -0
- package/src/lib/job/watch.d.ts +3 -0
- package/src/lib/job/watch.js +169 -0
- package/src/lib/job-spec/codec.d.ts +18 -0
- package/src/lib/job-spec/codec.js +348 -0
- package/src/lib/job-spec/constants.d.ts +32 -0
- package/src/lib/job-spec/constants.js +36 -0
- package/src/lib/job-spec/helpers.d.ts +19 -0
- package/src/lib/job-spec/helpers.js +138 -0
- package/src/lib/job-spec/index.d.ts +14 -0
- package/src/lib/job-spec/index.js +17 -0
- package/src/lib/job-spec/preview.d.ts +8 -0
- package/src/lib/job-spec/preview.js +298 -0
- package/src/lib/job-spec/read.d.ts +20 -0
- package/src/lib/job-spec/read.js +224 -0
- package/src/lib/job-spec/schema.d.ts +290 -0
- package/src/lib/job-spec/schema.js +70 -0
- package/src/lib/job-spec/types.d.ts +139 -0
- package/src/lib/job-spec/types.js +3 -0
- package/src/lib/market/contracts/AgenticCommerce.d.ts +1026 -0
- package/src/lib/market/contracts/AgenticCommerce.js +1317 -0
- package/src/lib/market/contracts/RulesBindingHook.d.ts +235 -0
- package/src/lib/market/contracts/RulesBindingHook.js +314 -0
- package/src/lib/market/contracts/UniversalMarketplace.d.ts +1770 -0
- package/src/lib/market/contracts/UniversalMarketplace.js +2295 -0
- package/src/lib/market/contracts/UniversalMarketplaceErrors.d.ts +309 -0
- package/src/lib/market/contracts/UniversalMarketplaceErrors.js +416 -0
- package/src/lib/market/contracts/UniversalMarketplaceRules.d.ts +241 -0
- package/src/lib/market/contracts/UniversalMarketplaceRules.js +323 -0
- package/src/lib/market/data.d.ts +8 -0
- package/src/lib/market/data.js +60 -0
- package/src/lib/market/deployment.d.ts +14 -0
- package/src/lib/market/deployment.js +23 -0
- package/src/lib/market/deposit.d.ts +24 -0
- package/src/lib/market/deposit.js +271 -0
- package/src/lib/market/errors.d.ts +13 -0
- package/src/lib/market/errors.js +81 -0
- package/src/lib/market/history.d.ts +6 -0
- package/src/lib/market/history.js +83 -0
- package/src/lib/market/index.d.ts +4 -0
- package/src/lib/market/index.js +12 -0
- package/src/lib/market/kernel-wire.d.ts +15 -0
- package/src/lib/market/kernel-wire.js +41 -0
- package/src/lib/market/market.d.ts +55 -0
- package/src/lib/market/market.js +635 -0
- package/src/lib/market/rules.d.ts +106 -0
- package/src/lib/market/rules.js +293 -0
- package/src/lib/market/runtime.d.ts +35 -0
- package/src/lib/market/runtime.js +130 -0
- package/src/lib/market/types.d.ts +180 -0
- package/src/lib/market/types.js +3 -0
- package/src/lib/orchestrator/internals/errors.d.ts +9 -2
- package/src/lib/orchestrator/internals/errors.js +9 -2
- package/src/lib/orchestrator/internals/push-chain-tx.js +17 -3
- package/src/lib/push-chain/push-chain.d.ts +44 -1
- package/src/lib/push-chain/push-chain.js +23 -3
- package/src/lib/read-state/read-params.d.ts +9 -0
- package/src/lib/read-state/read-params.js +5 -1
- package/src/lib/utils.d.ts +15 -0
- package/src/lib/utils.js +4 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import type { Address, Hex } from 'viem';
|
|
2
|
+
import type { AgentCardRules } from './rules';
|
|
3
|
+
import type { JobSpec, JobSpecTemplate } from '../job-spec/types';
|
|
4
|
+
import type { SessionWire } from '../agentic/codec/session';
|
|
5
|
+
import type { StackProgressHook } from './runtime';
|
|
6
|
+
import type { UniversalTxResponse } from '../orchestrator/orchestrator.types';
|
|
7
|
+
export interface AgentCardInput {
|
|
8
|
+
/** A name is hashed on write; reads retain the canonical bytes32 jobType. */
|
|
9
|
+
jobType: string;
|
|
10
|
+
metadataURI: string;
|
|
11
|
+
metadataHash: Hex;
|
|
12
|
+
chain: string;
|
|
13
|
+
providerFee: bigint;
|
|
14
|
+
paymentToken: Address;
|
|
15
|
+
principalMin: bigint;
|
|
16
|
+
principalMax: bigint;
|
|
17
|
+
minDuration: number;
|
|
18
|
+
maxDuration: number;
|
|
19
|
+
minExecuteWindow: number;
|
|
20
|
+
settleWindow: number;
|
|
21
|
+
}
|
|
22
|
+
export interface AgentCard extends AgentCardInput {
|
|
23
|
+
cardId: bigint;
|
|
24
|
+
provider: Address;
|
|
25
|
+
active: boolean;
|
|
26
|
+
version: bigint;
|
|
27
|
+
verified: boolean;
|
|
28
|
+
disabled: boolean;
|
|
29
|
+
rating: bigint;
|
|
30
|
+
rules: AgentCardRules;
|
|
31
|
+
jobSpecTemplate: JobSpecTemplate;
|
|
32
|
+
/** Canonical on-chain bytes retained for exact matching and unknown token metadata. */
|
|
33
|
+
rulesBytes: Hex;
|
|
34
|
+
jobSpecTemplateBytes: Hex;
|
|
35
|
+
}
|
|
36
|
+
export type AgentCardSummary = Omit<AgentCard, 'rules' | 'jobSpecTemplate' | 'rulesBytes' | 'jobSpecTemplateBytes'>;
|
|
37
|
+
export interface MarketJobInputs {
|
|
38
|
+
principal: bigint;
|
|
39
|
+
expiredAt: number;
|
|
40
|
+
executeBy: number;
|
|
41
|
+
params: bigint[];
|
|
42
|
+
}
|
|
43
|
+
export interface OwnerIntent {
|
|
44
|
+
owner: Address;
|
|
45
|
+
wallet: Address;
|
|
46
|
+
executor: Address;
|
|
47
|
+
index: bigint;
|
|
48
|
+
sessionHash: Hex;
|
|
49
|
+
mode: Hex;
|
|
50
|
+
execCalldataHash: Hex;
|
|
51
|
+
nonceKey: bigint;
|
|
52
|
+
nonceSeq: bigint;
|
|
53
|
+
grantNonce: bigint;
|
|
54
|
+
deadline: number;
|
|
55
|
+
signerChainId: bigint;
|
|
56
|
+
}
|
|
57
|
+
export interface JobPlan {
|
|
58
|
+
cardId: bigint;
|
|
59
|
+
cardVersion: bigint;
|
|
60
|
+
wallet: Address;
|
|
61
|
+
walletDeployed: boolean;
|
|
62
|
+
session: SessionWire;
|
|
63
|
+
intent: OwnerIntent;
|
|
64
|
+
calldata: Hex;
|
|
65
|
+
jobSpec: {
|
|
66
|
+
spec: JobSpec;
|
|
67
|
+
bytes: Hex;
|
|
68
|
+
};
|
|
69
|
+
job: MarketJobInputs;
|
|
70
|
+
label: string;
|
|
71
|
+
/** Reference deposit amounts; no principal or fee is moved by openJob. */
|
|
72
|
+
deposit: {
|
|
73
|
+
principal: {
|
|
74
|
+
prc20: Address;
|
|
75
|
+
amount: bigint;
|
|
76
|
+
};
|
|
77
|
+
providerFee: {
|
|
78
|
+
token: Address;
|
|
79
|
+
amount: bigint;
|
|
80
|
+
};
|
|
81
|
+
pc: bigint;
|
|
82
|
+
};
|
|
83
|
+
preview: {
|
|
84
|
+
mayDo: string[];
|
|
85
|
+
mayMove: string[];
|
|
86
|
+
judgedBy: string[];
|
|
87
|
+
until: string;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export interface MarketPreviewOptions extends Omit<MarketJobInputs, 'params'> {
|
|
91
|
+
params?: bigint[];
|
|
92
|
+
walletIndex?: number;
|
|
93
|
+
deadline?: number;
|
|
94
|
+
label?: string;
|
|
95
|
+
}
|
|
96
|
+
export interface MarketWriteOptions {
|
|
97
|
+
progressHook?: StackProgressHook;
|
|
98
|
+
}
|
|
99
|
+
export interface MarketOpenOptions extends MarketWriteOptions {
|
|
100
|
+
relay?: boolean;
|
|
101
|
+
/** Recover a submitted opening, without signing or sending again. Rehydrate a hash with trackTransaction. */
|
|
102
|
+
resume?: UniversalTxResponse;
|
|
103
|
+
}
|
|
104
|
+
export interface MarketDepositStep {
|
|
105
|
+
/** PRINCIPAL_AND_FEE combines requirements when both use the same token. */
|
|
106
|
+
step: 'PRINCIPAL' | 'PROVIDER_FEE' | 'PRINCIPAL_AND_FEE' | 'PC';
|
|
107
|
+
token?: Address;
|
|
108
|
+
amount: bigint;
|
|
109
|
+
tx: UniversalTxResponse;
|
|
110
|
+
}
|
|
111
|
+
export interface MarketDepositOptions extends MarketWriteOptions {
|
|
112
|
+
/** Token transfers use Push holdings by default. Origin explicitly bridges matching registered assets; PC always uses Push holdings. */
|
|
113
|
+
funding?: 'push' | 'origin';
|
|
114
|
+
/** Wallet PC balance to reach. Defaults to the opened card's per-call gas cap. */
|
|
115
|
+
pcAmount?: bigint;
|
|
116
|
+
/** Wallet fee reserve to reach. Defaults to the opened card's reference fee; does not accept a kernel price. */
|
|
117
|
+
providerFee?: bigint;
|
|
118
|
+
/** Previously submitted steps. Their waits must settle before any further transfer. */
|
|
119
|
+
resume?: readonly MarketDepositStep[];
|
|
120
|
+
}
|
|
121
|
+
export interface MarketDepositResult {
|
|
122
|
+
jobId: bigint;
|
|
123
|
+
wallet: Address;
|
|
124
|
+
cardId: bigint;
|
|
125
|
+
cardVersion: bigint;
|
|
126
|
+
/** Includes resumed transactions, in submission order. */
|
|
127
|
+
txs: MarketDepositStep[];
|
|
128
|
+
/** A broadcast that failed before returning a response. Track it before resuming. */
|
|
129
|
+
pending?: Omit<MarketDepositStep, 'tx'> & {
|
|
130
|
+
txHash: string;
|
|
131
|
+
chain: string;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
export interface MarketNamespace {
|
|
135
|
+
cards(options?: {
|
|
136
|
+
provider?: Address;
|
|
137
|
+
chain?: string;
|
|
138
|
+
active?: boolean;
|
|
139
|
+
}): Promise<{
|
|
140
|
+
cards: AgentCardSummary[];
|
|
141
|
+
}>;
|
|
142
|
+
card(cardId: bigint): Promise<AgentCard>;
|
|
143
|
+
preview(cardId: bigint, options: MarketPreviewOptions): Promise<JobPlan>;
|
|
144
|
+
openJob(plan: JobPlan, options?: MarketOpenOptions): Promise<{
|
|
145
|
+
jobId: bigint;
|
|
146
|
+
wallet: Address;
|
|
147
|
+
rulesId: Hex;
|
|
148
|
+
tx: UniversalTxResponse;
|
|
149
|
+
}>;
|
|
150
|
+
deposit(jobId: bigint, options?: MarketDepositOptions): Promise<MarketDepositResult>;
|
|
151
|
+
job(jobId: bigint): Promise<{
|
|
152
|
+
cardId: bigint;
|
|
153
|
+
cardVersion: bigint;
|
|
154
|
+
wallet: Address;
|
|
155
|
+
rulesId: Hex;
|
|
156
|
+
}>;
|
|
157
|
+
activeJob(wallet: Address): Promise<{
|
|
158
|
+
jobId: bigint;
|
|
159
|
+
}>;
|
|
160
|
+
agent: {
|
|
161
|
+
register(card: AgentCardInput, options: MarketWriteOptions & {
|
|
162
|
+
rules: AgentCardRules;
|
|
163
|
+
jobSpecTemplate: JobSpecTemplate;
|
|
164
|
+
}): Promise<{
|
|
165
|
+
cardId: bigint;
|
|
166
|
+
version: bigint;
|
|
167
|
+
tx: UniversalTxResponse;
|
|
168
|
+
}>;
|
|
169
|
+
update(cardId: bigint, card: AgentCardInput, options: MarketWriteOptions & {
|
|
170
|
+
rules: AgentCardRules;
|
|
171
|
+
jobSpecTemplate: JobSpecTemplate;
|
|
172
|
+
}): Promise<{
|
|
173
|
+
cardId: bigint;
|
|
174
|
+
version: bigint;
|
|
175
|
+
tx: UniversalTxResponse;
|
|
176
|
+
}>;
|
|
177
|
+
setActive(cardId: bigint, active: boolean, options?: MarketWriteOptions): Promise<UniversalTxResponse>;
|
|
178
|
+
card(): Promise<AgentCard | undefined>;
|
|
179
|
+
};
|
|
180
|
+
}
|
|
@@ -27,8 +27,10 @@ export interface DecodedErrorPayload {
|
|
|
27
27
|
* discriminator lets callers classify via `instanceof PushChainExecutionError`
|
|
28
28
|
* instead of sniffing error messages.
|
|
29
29
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
30
|
+
* A failed universal execution can carry its origin-chain gateway hash. Native
|
|
31
|
+
* confirmation/indexing errors retain the submitted Push hash instead; those
|
|
32
|
+
* errors do not prove that the transaction reverted. Track a retained hash
|
|
33
|
+
* before retrying an operation with side effects.
|
|
32
34
|
*
|
|
33
35
|
* `decodedError`: optional structured payload that flows through to terminal
|
|
34
36
|
* failure hook payloads (199-02 / 299-02 / 399-02 / 999-02). Set by the
|
|
@@ -38,11 +40,16 @@ export interface DecodedErrorPayload {
|
|
|
38
40
|
export declare class PushChainExecutionError extends Error {
|
|
39
41
|
readonly code: "PUSH_CHAIN_EXECUTION_FAILED";
|
|
40
42
|
readonly gatewayTxHash?: string;
|
|
43
|
+
/** Native Push transaction already broadcast before confirmation/indexing failed. */
|
|
44
|
+
readonly txHash?: `0x${string}`;
|
|
45
|
+
readonly pendingTransactionHash?: `0x${string}`;
|
|
41
46
|
readonly decodedError?: DecodedErrorPayload;
|
|
42
47
|
/** Underlying transport/RPC error, kept so raw revert data is not lost. */
|
|
43
48
|
readonly cause?: unknown;
|
|
44
49
|
constructor(message: string, opts?: {
|
|
45
50
|
gatewayTxHash?: string;
|
|
51
|
+
txHash?: `0x${string}`;
|
|
52
|
+
pendingTransactionHash?: `0x${string}`;
|
|
46
53
|
decodedError?: DecodedErrorPayload;
|
|
47
54
|
cause?: unknown;
|
|
48
55
|
});
|
|
@@ -19,8 +19,10 @@ const formatters_1 = require("../../formatters");
|
|
|
19
19
|
* discriminator lets callers classify via `instanceof PushChainExecutionError`
|
|
20
20
|
* instead of sniffing error messages.
|
|
21
21
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
22
|
+
* A failed universal execution can carry its origin-chain gateway hash. Native
|
|
23
|
+
* confirmation/indexing errors retain the submitted Push hash instead; those
|
|
24
|
+
* errors do not prove that the transaction reverted. Track a retained hash
|
|
25
|
+
* before retrying an operation with side effects.
|
|
24
26
|
*
|
|
25
27
|
* `decodedError`: optional structured payload that flows through to terminal
|
|
26
28
|
* failure hook payloads (199-02 / 299-02 / 399-02 / 999-02). Set by the
|
|
@@ -30,6 +32,9 @@ const formatters_1 = require("../../formatters");
|
|
|
30
32
|
class PushChainExecutionError extends Error {
|
|
31
33
|
code = 'PUSH_CHAIN_EXECUTION_FAILED';
|
|
32
34
|
gatewayTxHash;
|
|
35
|
+
/** Native Push transaction already broadcast before confirmation/indexing failed. */
|
|
36
|
+
txHash;
|
|
37
|
+
pendingTransactionHash;
|
|
33
38
|
decodedError;
|
|
34
39
|
/** Underlying transport/RPC error, kept so raw revert data is not lost. */
|
|
35
40
|
cause;
|
|
@@ -37,6 +42,8 @@ class PushChainExecutionError extends Error {
|
|
|
37
42
|
super((0, formatters_1.normalizePublicErrorMessage)(message));
|
|
38
43
|
this.name = 'PushChainExecutionError';
|
|
39
44
|
this.gatewayTxHash = opts.gatewayTxHash;
|
|
45
|
+
this.txHash = opts.txHash;
|
|
46
|
+
this.pendingTransactionHash = opts.pendingTransactionHash;
|
|
40
47
|
this.decodedError = opts.decodedError;
|
|
41
48
|
if (opts.cause !== undefined)
|
|
42
49
|
this.cause = opts.cause;
|
|
@@ -37,7 +37,7 @@ async function getIndexedPushTransaction(ctx, txHash, label) {
|
|
|
37
37
|
});
|
|
38
38
|
receiptWaited = true;
|
|
39
39
|
if (receipt.status === 'reverted') {
|
|
40
|
-
throw new errors_1.PushChainExecutionError(`${label} — Push Chain transaction ${txHash} reverted
|
|
40
|
+
throw new errors_1.PushChainExecutionError(`${label} — Push Chain transaction ${txHash} reverted`, { txHash });
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
return await ctx.pushClient.getTransaction(txHash);
|
|
@@ -92,6 +92,7 @@ async function sendPushTx(ctx, execute, eventBuffer, transformFn, requireAtomicB
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
if (executor && ctx.universalSigner.signAuthorization) {
|
|
95
|
+
let submittedHash;
|
|
95
96
|
try {
|
|
96
97
|
(0, context_1.printLog)(ctx, `sendPushTx — executing ${calls.length} call(s) atomically via EIP-7702 (executor: ${executor})`);
|
|
97
98
|
const txHash = await ctx.pushClient.sendBatch7702({
|
|
@@ -99,10 +100,16 @@ async function sendPushTx(ctx, execute, eventBuffer, transformFn, requireAtomicB
|
|
|
99
100
|
calls,
|
|
100
101
|
signer: ctx.universalSigner,
|
|
101
102
|
});
|
|
103
|
+
submittedHash = txHash;
|
|
102
104
|
const txResponse = await getIndexedPushTransaction(ctx, txHash, 'sendPushTx');
|
|
103
105
|
return await transformFn(txResponse, eventBuffer);
|
|
104
106
|
}
|
|
105
107
|
catch (err) {
|
|
108
|
+
if (submittedHash) {
|
|
109
|
+
if (err instanceof errors_1.PushChainExecutionError && err.txHash === submittedHash)
|
|
110
|
+
throw err;
|
|
111
|
+
throw new errors_1.PushChainExecutionError((0, formatters_1.normalizePublicErrorMessage)(err), { txHash: submittedHash, pendingTransactionHash: submittedHash, cause: err });
|
|
112
|
+
}
|
|
106
113
|
// Only fall back when the wallet genuinely can't sign a 7702
|
|
107
114
|
// authorization. This is raised before any broadcast, so falling back
|
|
108
115
|
// to sequential execution cannot double-execute. Any other error
|
|
@@ -224,8 +231,15 @@ async function sendPushTx(ctx, execute, eventBuffer, transformFn, requireAtomicB
|
|
|
224
231
|
value: execute.value,
|
|
225
232
|
signer: ctx.universalSigner,
|
|
226
233
|
});
|
|
227
|
-
|
|
228
|
-
|
|
234
|
+
try {
|
|
235
|
+
const txResponse = await getIndexedPushTransaction(ctx, txHash, 'sendPushTx');
|
|
236
|
+
return await transformFn(txResponse, eventBuffer);
|
|
237
|
+
}
|
|
238
|
+
catch (cause) {
|
|
239
|
+
if (cause instanceof errors_1.PushChainExecutionError && cause.txHash === txHash)
|
|
240
|
+
throw cause;
|
|
241
|
+
throw new errors_1.PushChainExecutionError((0, formatters_1.normalizePublicErrorMessage)(cause), { txHash, pendingTransactionHash: txHash, cause });
|
|
242
|
+
}
|
|
229
243
|
}
|
|
230
244
|
// ============================================================================
|
|
231
245
|
// sendUniversalTx
|
|
@@ -11,6 +11,10 @@ import type { Hex } from 'viem';
|
|
|
11
11
|
import type { BatchReadResponse, PreparedRead, UniversalReadResponse } from '../read-state/read-state.types';
|
|
12
12
|
import { type ReadOptions, type ReadPrepareOptions, type ReadValue, type ValidateReadCall, type ReadTrackOptions, type ReadExecuteOptions } from '../read-state/read-params';
|
|
13
13
|
import type { AgenticNamespace } from '../agentic/agentic.types';
|
|
14
|
+
import type { MarketNamespace } from '../market/types';
|
|
15
|
+
import type { JobNamespace } from '../job/types';
|
|
16
|
+
import { prepareJobRead } from '../job-spec/read';
|
|
17
|
+
import type { ExecuteJobReadOptions, PreparedJobRead } from '../job-spec/types';
|
|
14
18
|
/** Options accepted by `PushChain.initialize` / `reinitialize`. */
|
|
15
19
|
export interface PushChainInitializeOptions {
|
|
16
20
|
network: PUSH_NETWORK;
|
|
@@ -96,6 +100,41 @@ export declare class PushChain {
|
|
|
96
100
|
};
|
|
97
101
|
AGENTIC: Readonly<{
|
|
98
102
|
WALLET: "agentic:wallet";
|
|
103
|
+
PRINCIPAL: "agentic:principal";
|
|
104
|
+
JOB: Readonly<{
|
|
105
|
+
ADDRESS: Readonly<{
|
|
106
|
+
'eip155:42101': Readonly<{
|
|
107
|
+
KERNEL: "0x977cf1AC973E9eC4332791d531507575006157Ed";
|
|
108
|
+
HOOK: "0xDe7A94e510b6C571DE7880d441349689F73A32b3";
|
|
109
|
+
EVALUATOR: "0x1afC81396f1bb36F91f74506284952b81e4bd47c";
|
|
110
|
+
}>;
|
|
111
|
+
}>;
|
|
112
|
+
EVALUATION: Readonly<{
|
|
113
|
+
readonly BOOLEAN: "BOOLEAN";
|
|
114
|
+
readonly COMPARE: "COMPARE";
|
|
115
|
+
readonly NUMBER: "NUMBER";
|
|
116
|
+
readonly PERCENTAGE: "PERCENTAGE";
|
|
117
|
+
}>;
|
|
118
|
+
OPERATION: Readonly<{
|
|
119
|
+
readonly EQUAL: "EQUAL";
|
|
120
|
+
readonly NOT_EQUAL: "NOT_EQUAL";
|
|
121
|
+
readonly GREATER_THAN: "GREATER_THAN";
|
|
122
|
+
readonly GREATER_OR_EQUAL: "GREATER_OR_EQUAL";
|
|
123
|
+
readonly LESS_THAN: "LESS_THAN";
|
|
124
|
+
readonly LESS_OR_EQUAL: "LESS_OR_EQUAL";
|
|
125
|
+
}>;
|
|
126
|
+
LOGIC: Readonly<{
|
|
127
|
+
readonly ALL: "ALL";
|
|
128
|
+
readonly ANY: "ANY";
|
|
129
|
+
readonly AT_LEAST: "AT_LEAST";
|
|
130
|
+
}>;
|
|
131
|
+
ALLOWED_MUTABILITY: Readonly<{
|
|
132
|
+
readonly NONE: "NONE";
|
|
133
|
+
readonly CLIENT: "CLIENT";
|
|
134
|
+
readonly PROVIDER: "PROVIDER";
|
|
135
|
+
readonly BOTH: "BOTH";
|
|
136
|
+
}>;
|
|
137
|
+
}>;
|
|
99
138
|
PRESETS: Readonly<{
|
|
100
139
|
CATEGORY: Readonly<{
|
|
101
140
|
DEXES: "DEXES";
|
|
@@ -202,7 +241,9 @@ export declare class PushChain {
|
|
|
202
241
|
* Defaults to the canonical registry on Donut. For your own application receiver,
|
|
203
242
|
* pass callback.target, gasLimit, abi and functionName, plus an optional args mapper.
|
|
204
243
|
*/
|
|
205
|
-
read: <const O extends ReadOptions>(subject: string, options: O & ValidateReadCall<O>) => Promise<UniversalReadResponse<ReadValue<O
|
|
244
|
+
read: (<const O extends ReadOptions>(subject: string, options: O & ValidateReadCall<O>) => Promise<UniversalReadResponse<ReadValue<O>>>) & ((read: PreparedJobRead, options?: ExecuteJobReadOptions) => Promise<UniversalReadResponse<`0x${string}`>>) & {
|
|
245
|
+
prepare: typeof prepareJobRead;
|
|
246
|
+
};
|
|
206
247
|
/**
|
|
207
248
|
* Build a validated `ReadSpec` for `subject` on `options.chain`: preflight (oracle
|
|
208
249
|
* height, protocol fee, gas price), envelope encoding, budget sizing, expiry math.
|
|
@@ -297,6 +338,8 @@ export declare class PushChain {
|
|
|
297
338
|
* handles. Ownership is the connected signer's Push identity.
|
|
298
339
|
*/
|
|
299
340
|
agentic: AgenticNamespace;
|
|
341
|
+
market: MarketNamespace;
|
|
342
|
+
job: JobNamespace;
|
|
300
343
|
/** @internal AGW execution context when initialized with `agenticWallet`. */
|
|
301
344
|
private agenticContext?;
|
|
302
345
|
private readonly agenticRuntime;
|
|
@@ -19,6 +19,10 @@ const send_1 = require("../agentic/execution/send");
|
|
|
19
19
|
const guards_1 = require("../agentic/execution/guards");
|
|
20
20
|
const response_1 = require("../agentic/response");
|
|
21
21
|
const runtime_1 = require("../agentic/runtime");
|
|
22
|
+
const market_1 = require("../market/market");
|
|
23
|
+
const job_1 = require("../job/job");
|
|
24
|
+
const preview_1 = require("../job-spec/preview");
|
|
25
|
+
const read_1 = require("../job-spec/read");
|
|
22
26
|
/**
|
|
23
27
|
* @class PushChain
|
|
24
28
|
*
|
|
@@ -63,6 +67,8 @@ class PushChain {
|
|
|
63
67
|
* handles. Ownership is the connected signer's Push identity.
|
|
64
68
|
*/
|
|
65
69
|
agentic;
|
|
70
|
+
market;
|
|
71
|
+
job;
|
|
66
72
|
/** @internal AGW execution context when initialized with `agenticWallet`. */
|
|
67
73
|
agenticContext;
|
|
68
74
|
agenticRuntime;
|
|
@@ -97,6 +103,17 @@ class PushChain {
|
|
|
97
103
|
this.accountStatusReady = Promise.resolve();
|
|
98
104
|
this.agenticRuntime = (0, runtime_1.createAgenticRuntime)(orchestrator, isReadMode);
|
|
99
105
|
this.agentic = new agentic_1.AgenticNamespaceImpl(this.agenticRuntime);
|
|
106
|
+
const stackRuntime = {
|
|
107
|
+
agw: this.agenticRuntime,
|
|
108
|
+
jobBlocks: new Map(),
|
|
109
|
+
account: () => this.universal.account,
|
|
110
|
+
wallet: () => this.agenticContext?.wallet,
|
|
111
|
+
send: (params, options) => this.universal.sendTransaction(params, options),
|
|
112
|
+
signTypedData: (data) => this.universal.signTypedData(data),
|
|
113
|
+
canSignTypedData: () => typeof this.universalSigner.signTypedData === 'function',
|
|
114
|
+
};
|
|
115
|
+
this.market = new market_1.MarketNamespaceImpl(stackRuntime);
|
|
116
|
+
this.job = new job_1.JobNamespaceImpl(stackRuntime);
|
|
100
117
|
// eslint-disable-next-line @typescript-eslint/no-this-alias -- getters below need the instance
|
|
101
118
|
const self = this;
|
|
102
119
|
// In agenticWallet mode, request transactions execute through the wallet
|
|
@@ -167,15 +184,17 @@ class PushChain {
|
|
|
167
184
|
return orchestrator.rescueFunds.bind(orchestrator)(params);
|
|
168
185
|
},
|
|
169
186
|
// Only read()/executeReads() send transactions; prepare/simulate/track remain read-only.
|
|
170
|
-
read: async (subject,
|
|
171
|
-
const
|
|
187
|
+
read: Object.assign(async (subject, input) => {
|
|
188
|
+
const options = typeof subject === 'string' ? input : (0, read_1.jobReadOptions)(subject, input);
|
|
189
|
+
const target = typeof subject === 'string' ? subject : subject.target;
|
|
190
|
+
const params = await (0, read_params_1.resolveReadSpecParams)(target, withReadRefund(options), orchestrator.getNetwork(), orchestrator.getRpcUrls());
|
|
172
191
|
(0, read_executor_1.assertRequestEntrypoint)(params.callback, 'read');
|
|
173
192
|
if (this.isReadMode)
|
|
174
193
|
throw new Error('Read only mode cannot call read function');
|
|
175
194
|
const prepared = await orchestrator.prepareRead(params, options.progressHook);
|
|
176
195
|
const { reads: [response] } = await (0, read_executor_1.executeReads)(readDeps(), [prepared], options);
|
|
177
196
|
return response;
|
|
178
|
-
},
|
|
197
|
+
}, { prepare: read_1.prepareJobRead }),
|
|
179
198
|
prepareRead: async (subject, options) => {
|
|
180
199
|
const params = await (0, read_params_1.resolveReadSpecParams)(subject, withReadRefund(options), orchestrator.getNetwork(), orchestrator.getRpcUrls());
|
|
181
200
|
return orchestrator.prepareRead(params);
|
|
@@ -214,6 +233,7 @@ class PushChain {
|
|
|
214
233
|
return (0, viem_1.bytesToHex)(signBytes);
|
|
215
234
|
},
|
|
216
235
|
};
|
|
236
|
+
(0, preview_1.bindJobPreviewAccounts)(this.universal, async (wallet, chain) => (await this.agenticRuntime.resolveCEA(wallet, chain)).cea);
|
|
217
237
|
const network = orchestrator.getNetwork() === enums_1.PUSH_NETWORK.MAINNET
|
|
218
238
|
? 'mainnet'
|
|
219
239
|
: 'testnet';
|
|
@@ -44,6 +44,8 @@ interface ReadOptionsInput {
|
|
|
44
44
|
idl?: Idl;
|
|
45
45
|
/** Typed contract call — encodes the call and decodes the result. */
|
|
46
46
|
abi?: Abi;
|
|
47
|
+
/** Encoded EVM view call. The result is returned as raw consensus bytes. */
|
|
48
|
+
callData?: Hex;
|
|
47
49
|
/**
|
|
48
50
|
* With `abi`: the function to call (required). With `idl`: the account layout
|
|
49
51
|
* (optional — inferred from the discriminator; snake_case or camelCase).
|
|
@@ -79,6 +81,7 @@ type NoQuery = {
|
|
|
79
81
|
idl?: never;
|
|
80
82
|
accountName?: never;
|
|
81
83
|
abi?: never;
|
|
84
|
+
callData?: never;
|
|
82
85
|
functionName?: never;
|
|
83
86
|
args?: never;
|
|
84
87
|
storageSlot?: never;
|
|
@@ -113,6 +116,10 @@ export type ReadQueryOptions = ({
|
|
|
113
116
|
args?: readonly unknown[];
|
|
114
117
|
}>) | ({
|
|
115
118
|
chain: EvmChain;
|
|
119
|
+
} & Query<'callData', {
|
|
120
|
+
callData: Hex;
|
|
121
|
+
}>) | ({
|
|
122
|
+
chain: EvmChain;
|
|
116
123
|
} & Query<'storageSlot', {
|
|
117
124
|
storageSlot: Hex | bigint;
|
|
118
125
|
}>) | ({
|
|
@@ -191,6 +198,8 @@ export type ReadValue<O> = O extends {
|
|
|
191
198
|
readonly [K in keyof E]: Web2Value<E[K]>;
|
|
192
199
|
} : O extends {
|
|
193
200
|
storageSlot: unknown;
|
|
201
|
+
} | {
|
|
202
|
+
callData: unknown;
|
|
194
203
|
} ? Hex : O extends {
|
|
195
204
|
idl: infer I extends Idl;
|
|
196
205
|
} ? IdlReadValue<I, O extends {
|
|
@@ -27,7 +27,7 @@ exports.ERC20_BALANCE_OF_ABI = [
|
|
|
27
27
|
outputs: [{ name: '', type: 'uint256' }],
|
|
28
28
|
},
|
|
29
29
|
];
|
|
30
|
-
const QUERY_KEYS = ['token', 'abi', 'idl', 'storageSlot', 'web2'];
|
|
30
|
+
const QUERY_KEYS = ['token', 'abi', 'callData', 'idl', 'storageSlot', 'web2'];
|
|
31
31
|
function queryKind(o) {
|
|
32
32
|
if ('tokenProgram' in o)
|
|
33
33
|
throw new errors_1.InvalidReadQueryError('tokenProgram is detected from the mint; remove options.tokenProgram');
|
|
@@ -75,6 +75,10 @@ function toReadQuery(subject, o, resolvedTokenProgram) {
|
|
|
75
75
|
if (!o.functionName)
|
|
76
76
|
throw new errors_1.InvalidReadQueryError('abi needs functionName');
|
|
77
77
|
return { type: 'contractCall', target: subject, abi: o.abi, functionName: o.functionName, args: o.args };
|
|
78
|
+
case 'callData':
|
|
79
|
+
if (!/^0x(?:[\da-f]{2}){4,}$/i.test(o.callData ?? ''))
|
|
80
|
+
throw new errors_1.InvalidReadQueryError('callData must contain a function selector and complete bytes');
|
|
81
|
+
return { type: 'contractCall', target: subject, callData: o.callData };
|
|
78
82
|
case 'storageSlot':
|
|
79
83
|
return { type: 'storageSlot', target: subject, slot: o.storageSlot };
|
|
80
84
|
default:
|
package/src/lib/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { validateAgentCardRules, encodeAgentCardRules, decodeAgentCardRules } from './market/rules';
|
|
1
2
|
import { convertOriginToExecutor, fromChainAgnostic, convertExecutorToOriginAccount, toChainAgnostic, toUniversal, deriveExecutorAccount, resolveControllerAccount } from './universal/account';
|
|
2
3
|
import { construct, toUniversal as toUniversalSigner, toUniversalFromKeypair } from './universal/signer';
|
|
3
4
|
import { CHAIN, PUSH_NETWORK } from './constants/enums';
|
|
@@ -323,6 +324,20 @@ export declare class Utils {
|
|
|
323
324
|
static readonly agentic: Readonly<{
|
|
324
325
|
presets: import("./agentic").AgenticPresets;
|
|
325
326
|
}>;
|
|
327
|
+
static readonly job: Readonly<{
|
|
328
|
+
buildJobSpec: typeof import("./job-spec/codec").buildJobSpec;
|
|
329
|
+
buildJobSpecTemplate: typeof import("./job-spec/codec").buildJobSpecTemplate;
|
|
330
|
+
encodeJobSpec: typeof import("./job-spec/codec").encodeJobSpec;
|
|
331
|
+
decodeJobSpec: typeof import("./job-spec/codec").decodeJobSpec;
|
|
332
|
+
describeJobSpec: typeof import("./job-spec/helpers").describeJobSpec;
|
|
333
|
+
prepareRead: typeof import("./job-spec/read").prepareJobRead;
|
|
334
|
+
previewJobSpec: typeof import("./job-spec/preview").previewJobSpec;
|
|
335
|
+
}>;
|
|
336
|
+
static readonly market: Readonly<{
|
|
337
|
+
validateAgentCardRules: typeof validateAgentCardRules;
|
|
338
|
+
encodeAgentCardRules: typeof encodeAgentCardRules;
|
|
339
|
+
decodeAgentCardRules: typeof decodeAgentCardRules;
|
|
340
|
+
}>;
|
|
326
341
|
/**
|
|
327
342
|
* Internal: resolves a CHAIN enum from either a CHAIN value or a PushChain client instance.
|
|
328
343
|
*/
|
package/src/lib/utils.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Utils = void 0;
|
|
4
4
|
const presets_1 = require("./agentic/presets");
|
|
5
|
+
const job_spec_1 = require("./job-spec");
|
|
6
|
+
const rules_1 = require("./market/rules");
|
|
5
7
|
const account_1 = require("./universal/account");
|
|
6
8
|
const signer_1 = require("./universal/signer");
|
|
7
9
|
const enums_1 = require("./constants/enums");
|
|
@@ -665,6 +667,8 @@ class Utils {
|
|
|
665
667
|
};
|
|
666
668
|
/** Pure preset discovery/templates; internal encoders and identifiers stay private. */
|
|
667
669
|
static agentic = Object.freeze({ presets: presets_1.agenticPresets });
|
|
670
|
+
static job = job_spec_1.jobSpecUtils;
|
|
671
|
+
static market = Object.freeze({ validateAgentCardRules: rules_1.validateAgentCardRules, encodeAgentCardRules: rules_1.encodeAgentCardRules, decodeAgentCardRules: rules_1.decodeAgentCardRules });
|
|
668
672
|
/**
|
|
669
673
|
* Internal: resolves a CHAIN enum from either a CHAIN value or a PushChain client instance.
|
|
670
674
|
*/
|