@pushchain/core 6.0.26 → 6.0.27-alpha.1
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 +226 -0
- package/CHANGELOG.md +18 -0
- package/README.md +2 -0
- package/package.json +7 -1
- package/src/lib/agentic/agentic.d.ts +23 -0
- package/src/lib/agentic/agentic.js +51 -0
- package/src/lib/agentic/agentic.types.d.ts +414 -0
- package/src/lib/agentic/agentic.types.js +3 -0
- package/src/lib/agentic/capabilities.d.ts +37 -0
- package/src/lib/agentic/capabilities.js +64 -0
- package/src/lib/agentic/chain.d.ts +3 -0
- package/src/lib/agentic/chain.js +15 -0
- package/src/lib/agentic/codec/abi-layout.d.ts +20 -0
- package/src/lib/agentic/codec/abi-layout.js +168 -0
- package/src/lib/agentic/codec/defaults.d.ts +51 -0
- package/src/lib/agentic/codec/defaults.js +53 -0
- package/src/lib/agentic/codec/ids.d.ts +35 -0
- package/src/lib/agentic/codec/ids.js +74 -0
- package/src/lib/agentic/codec/native.d.ts +73 -0
- package/src/lib/agentic/codec/native.js +341 -0
- package/src/lib/agentic/codec/pins.d.ts +20 -0
- package/src/lib/agentic/codec/pins.js +29 -0
- package/src/lib/agentic/codec/rules.d.ts +45 -0
- package/src/lib/agentic/codec/rules.js +110 -0
- package/src/lib/agentic/codec/selectors.d.ts +19 -0
- package/src/lib/agentic/codec/selectors.js +60 -0
- package/src/lib/agentic/codec/session.d.ts +54 -0
- package/src/lib/agentic/codec/session.js +65 -0
- package/src/lib/agentic/codec/svm-accounts.d.ts +35 -0
- package/src/lib/agentic/codec/svm-accounts.js +68 -0
- package/src/lib/agentic/codec/svm-idl.d.ts +11 -0
- package/src/lib/agentic/codec/svm-idl.js +226 -0
- package/src/lib/agentic/codec/svm-terms.d.ts +157 -0
- package/src/lib/agentic/codec/svm-terms.js +246 -0
- package/src/lib/agentic/codec/universal-terms.d.ts +82 -0
- package/src/lib/agentic/codec/universal-terms.js +43 -0
- package/src/lib/agentic/codec/universal.d.ts +14 -0
- package/src/lib/agentic/codec/universal.js +173 -0
- package/src/lib/agentic/constants.d.ts +12 -0
- package/src/lib/agentic/constants.js +16 -0
- package/src/lib/agentic/context.d.ts +29 -0
- package/src/lib/agentic/context.js +56 -0
- package/src/lib/agentic/contracts/abi/v6/agent-validator.d.ts +105 -0
- package/src/lib/agentic/contracts/abi/v6/agent-validator.js +149 -0
- package/src/lib/agentic/contracts/abi/v6/agw-factory.d.ts +1146 -0
- package/src/lib/agentic/contracts/abi/v6/agw-factory.js +1499 -0
- package/src/lib/agentic/contracts/abi/v6/agw.d.ts +1306 -0
- package/src/lib/agentic/contracts/abi/v6/agw.js +1713 -0
- package/src/lib/agentic/contracts/abi/v6/index.d.ts +6 -0
- package/src/lib/agentic/contracts/abi/v6/index.js +17 -0
- package/src/lib/agentic/contracts/abi/v6/smart-session.d.ts +1493 -0
- package/src/lib/agentic/contracts/abi/v6/smart-session.js +1965 -0
- package/src/lib/agentic/contracts/abi/v6/universal-rules-policy.d.ts +1661 -0
- package/src/lib/agentic/contracts/abi/v6/universal-rules-policy.js +2187 -0
- package/src/lib/agentic/contracts/donut-v6.d.ts +11 -0
- package/src/lib/agentic/contracts/donut-v6.js +15 -0
- package/src/lib/agentic/contracts/prc20-metadata.d.ts +26 -0
- package/src/lib/agentic/contracts/prc20-metadata.js +87 -0
- package/src/lib/agentic/contracts/reader.d.ts +35 -0
- package/src/lib/agentic/contracts/reader.js +16 -0
- package/src/lib/agentic/contracts/v6.d.ts +5739 -0
- package/src/lib/agentic/contracts/v6.js +343 -0
- package/src/lib/agentic/deployments.d.ts +61 -0
- package/src/lib/agentic/deployments.js +203 -0
- package/src/lib/agentic/errors.d.ts +65 -0
- package/src/lib/agentic/errors.js +84 -0
- package/src/lib/agentic/execution/guards.d.ts +9 -0
- package/src/lib/agentic/execution/guards.js +30 -0
- package/src/lib/agentic/execution/outbound.d.ts +55 -0
- package/src/lib/agentic/execution/outbound.js +187 -0
- package/src/lib/agentic/execution/send.d.ts +9 -0
- package/src/lib/agentic/execution/send.js +268 -0
- package/src/lib/agentic/execution/svm-instruction.d.ts +24 -0
- package/src/lib/agentic/execution/svm-instruction.js +40 -0
- package/src/lib/agentic/execution/svm-outbound.d.ts +18 -0
- package/src/lib/agentic/execution/svm-outbound.js +86 -0
- package/src/lib/agentic/execution/svm-payload.d.ts +18 -0
- package/src/lib/agentic/execution/svm-payload.js +136 -0
- package/src/lib/agentic/execution/svm-public.d.ts +5 -0
- package/src/lib/agentic/execution/svm-public.js +176 -0
- package/src/lib/agentic/execution/svm-quote.d.ts +11 -0
- package/src/lib/agentic/execution/svm-quote.js +24 -0
- package/src/lib/agentic/execution/svm-send.d.ts +44 -0
- package/src/lib/agentic/execution/svm-send.js +87 -0
- package/src/lib/agentic/index.d.ts +5 -0
- package/src/lib/agentic/index.js +10 -0
- package/src/lib/agentic/management/common.d.ts +29 -0
- package/src/lib/agentic/management/common.js +116 -0
- package/src/lib/agentic/management/create.d.ts +4 -0
- package/src/lib/agentic/management/create.js +138 -0
- package/src/lib/agentic/management/duplicates.d.ts +4 -0
- package/src/lib/agentic/management/duplicates.js +20 -0
- package/src/lib/agentic/management/label.d.ts +3 -0
- package/src/lib/agentic/management/label.js +17 -0
- package/src/lib/agentic/management/prepare.d.ts +7 -0
- package/src/lib/agentic/management/prepare.js +95 -0
- package/src/lib/agentic/management/rules-write.d.ts +42 -0
- package/src/lib/agentic/management/rules-write.js +279 -0
- package/src/lib/agentic/management/svm-context.d.ts +25 -0
- package/src/lib/agentic/management/svm-context.js +55 -0
- package/src/lib/agentic/management/svm-metadata.d.ts +10 -0
- package/src/lib/agentic/management/svm-metadata.js +56 -0
- package/src/lib/agentic/management/svm-public.d.ts +6 -0
- package/src/lib/agentic/management/svm-public.js +125 -0
- package/src/lib/agentic/management/svm.d.ts +27 -0
- package/src/lib/agentic/management/svm.js +150 -0
- package/src/lib/agentic/presets/catalog.d.ts +26 -0
- package/src/lib/agentic/presets/catalog.js +307 -0
- package/src/lib/agentic/presets/index.d.ts +5 -0
- package/src/lib/agentic/presets/index.js +265 -0
- package/src/lib/agentic/presets/types.d.ts +48 -0
- package/src/lib/agentic/presets/types.js +3 -0
- package/src/lib/agentic/public-rule.d.ts +9 -0
- package/src/lib/agentic/public-rule.js +326 -0
- package/src/lib/agentic/reads/checkpoints.d.ts +17 -0
- package/src/lib/agentic/reads/checkpoints.js +109 -0
- package/src/lib/agentic/reads/rules.d.ts +42 -0
- package/src/lib/agentic/reads/rules.js +302 -0
- package/src/lib/agentic/reads/snapshot.d.ts +28 -0
- package/src/lib/agentic/reads/snapshot.js +85 -0
- package/src/lib/agentic/reads/svm.d.ts +17 -0
- package/src/lib/agentic/reads/svm.js +52 -0
- package/src/lib/agentic/reads/wallets.d.ts +25 -0
- package/src/lib/agentic/reads/wallets.js +122 -0
- package/src/lib/agentic/response.d.ts +41 -0
- package/src/lib/agentic/response.js +358 -0
- package/src/lib/agentic/revert.d.ts +7 -0
- package/src/lib/agentic/revert.js +102 -0
- package/src/lib/agentic/runtime.d.ts +58 -0
- package/src/lib/agentic/runtime.js +104 -0
- package/src/lib/agentic/utils.d.ts +57 -0
- package/src/lib/agentic/utils.js +165 -0
- package/src/lib/agentic/wallet.d.ts +32 -0
- package/src/lib/agentic/wallet.js +130 -0
- package/src/lib/constants/enums.d.ts +6 -3
- package/src/lib/constants/enums.js +6 -3
- package/src/lib/constants/index.d.ts +61 -4
- package/src/lib/constants/index.js +17 -3
- package/src/lib/constants/read-state.d.ts +9 -0
- package/src/lib/constants/read-state.js +13 -1
- package/src/lib/index.d.ts +8 -2
- package/src/lib/index.js +9 -1
- package/src/lib/orchestrator/internals/errors.d.ts +7 -0
- package/src/lib/orchestrator/internals/errors.js +13 -1
- package/src/lib/orchestrator/internals/execute-standard.d.ts +3 -1
- package/src/lib/orchestrator/internals/execute-standard.js +3 -3
- package/src/lib/orchestrator/internals/outbound-sync.js +52 -7
- package/src/lib/orchestrator/internals/push-chain-tx.d.ts +1 -1
- package/src/lib/orchestrator/internals/push-chain-tx.js +13 -1
- package/src/lib/orchestrator/orchestrator.d.ts +3 -0
- package/src/lib/orchestrator/orchestrator.js +13 -1
- package/src/lib/orchestrator/orchestrator.types.d.ts +8 -0
- package/src/lib/orchestrator/route-detector.js +3 -2
- package/src/lib/orchestrator/svm-idl/resolve.d.ts +2 -0
- package/src/lib/orchestrator/svm-idl/resolve.js +11 -1
- package/src/lib/progress-hook/progress-hook.js +63 -0
- package/src/lib/progress-hook/progress-hook.types.d.ts +10 -1
- package/src/lib/progress-hook/progress-hook.types.js +10 -0
- package/src/lib/push-chain/push-chain.d.ts +57 -15
- package/src/lib/push-chain/push-chain.js +66 -7
- package/src/lib/read-state/destination.js +6 -1
- package/src/lib/read-state/read-params.d.ts +3 -3
- package/src/lib/read-state/read-params.js +3 -2
- package/src/lib/read-state/read-state.types.d.ts +3 -1
- package/src/lib/read-state/read-tracker.js +2 -2
- package/src/lib/read-state/spec-builder.js +1 -1
- package/src/lib/universal/prc20-address.d.ts +15 -0
- package/src/lib/universal/prc20-address.js +135 -0
- package/src/lib/utils.d.ts +6 -13
- package/src/lib/utils.js +5 -128
- package/src/lib/vm-client/evm-client.js +34 -20
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AGENTIC = exports.AgenticRevertError = exports.AgenticError = exports.AGENTIC_ERROR_CODE = void 0;
|
|
4
|
+
var errors_1 = require("./errors");
|
|
5
|
+
Object.defineProperty(exports, "AGENTIC_ERROR_CODE", { enumerable: true, get: function () { return errors_1.AGENTIC_ERROR_CODE; } });
|
|
6
|
+
Object.defineProperty(exports, "AgenticError", { enumerable: true, get: function () { return errors_1.AgenticError; } });
|
|
7
|
+
Object.defineProperty(exports, "AgenticRevertError", { enumerable: true, get: function () { return errors_1.AgenticRevertError; } });
|
|
8
|
+
var constants_1 = require("./constants");
|
|
9
|
+
Object.defineProperty(exports, "AGENTIC", { enumerable: true, get: function () { return constants_1.AGENTIC; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Address, type Hex, type Log } from 'viem';
|
|
2
|
+
import type { MultiCall, UniversalTxResponse } from '../../orchestrator/orchestrator.types';
|
|
3
|
+
import { PROGRESS_HOOK } from '../../progress-hook/progress-hook.types';
|
|
4
|
+
import type { AgenticGeneration } from '../deployments';
|
|
5
|
+
import type { AgenticRuntime } from '../runtime';
|
|
6
|
+
import type { AgenticProgressHook } from '../agentic.types';
|
|
7
|
+
import { Snapshot } from '../reads/snapshot';
|
|
8
|
+
export declare function emitAgentic(runtime: AgenticRuntime, perCall: AgenticProgressHook | undefined, id: PROGRESS_HOOK, ...args: unknown[]): void;
|
|
9
|
+
export declare function assertCanSign(runtime: AgenticRuntime, operation: string): void;
|
|
10
|
+
/** Owner-only management writes: the connected signer's Push identity must be the stored owner. */
|
|
11
|
+
export declare function assertOwner(runtime: AgenticRuntime, gen: AgenticGeneration, wallet: Address, snap: Snapshot): Promise<Address>;
|
|
12
|
+
/**
|
|
13
|
+
* Send owner calls through the signer's ordinary transaction path: one call
|
|
14
|
+
* as a plain transaction, several as the signer's batch (UEA multicall,
|
|
15
|
+
* EIP-7702 atomic batch, or the documented sequential fallback for a Push EOA
|
|
16
|
+
* without 7702 — reported through `atomic` / `transactionHashes`).
|
|
17
|
+
*/
|
|
18
|
+
export declare function sendOwnerCalls(runtime: AgenticRuntime, calls: MultiCall[], progressHook: AgenticProgressHook | undefined): Promise<UniversalTxResponse>;
|
|
19
|
+
/**
|
|
20
|
+
* Wait for every Push transaction the operation produced and return their
|
|
21
|
+
* logs in submission order. A reverted transaction raises AgenticRevertError
|
|
22
|
+
* carrying all hashes.
|
|
23
|
+
*/
|
|
24
|
+
export declare function confirmedLogs(runtime: AgenticRuntime, tx: UniversalTxResponse): Promise<{
|
|
25
|
+
logs: Log[];
|
|
26
|
+
hashes: Hex[];
|
|
27
|
+
}>;
|
|
28
|
+
/** Normalize a send failure: keep batch hashes and decoded revert data. */
|
|
29
|
+
export declare function wrapSendError(err: unknown): unknown;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.emitAgentic = emitAgentic;
|
|
4
|
+
exports.assertCanSign = assertCanSign;
|
|
5
|
+
exports.assertOwner = assertOwner;
|
|
6
|
+
exports.sendOwnerCalls = sendOwnerCalls;
|
|
7
|
+
exports.confirmedLogs = confirmedLogs;
|
|
8
|
+
exports.wrapSendError = wrapSendError;
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const viem_1 = require("viem");
|
|
11
|
+
const errors_1 = require("../../orchestrator/internals/errors");
|
|
12
|
+
const progress_hook_1 = tslib_1.__importDefault(require("../../progress-hook/progress-hook"));
|
|
13
|
+
const errors_2 = require("../errors");
|
|
14
|
+
const revert_1 = require("../revert");
|
|
15
|
+
function emitAgentic(runtime, perCall, id, ...args) {
|
|
16
|
+
runtime.emit(progress_hook_1.default[id](...args), perCall);
|
|
17
|
+
}
|
|
18
|
+
function assertCanSign(runtime, operation) {
|
|
19
|
+
if (runtime.isReadOnly) {
|
|
20
|
+
throw new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.READ_ONLY, `${operation} needs a signer; this client was initialized read-only`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** Owner-only management writes: the connected signer's Push identity must be the stored owner. */
|
|
24
|
+
async function assertOwner(runtime, gen, wallet, snap) {
|
|
25
|
+
const owner = (0, viem_1.getAddress)(await snap.read(wallet, gen.contracts.abis.wallet, 'owner'));
|
|
26
|
+
const signer = runtime.signerPushAccount();
|
|
27
|
+
if (owner !== signer) {
|
|
28
|
+
throw new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.NOT_WALLET_OWNER, `${signer} is not the owner of ${wallet} (owner is ${owner})`, {
|
|
29
|
+
hint: 'Rule and label writes are owner-only. Initialize with the owner signer.',
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return owner;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Send owner calls through the signer's ordinary transaction path: one call
|
|
36
|
+
* as a plain transaction, several as the signer's batch (UEA multicall,
|
|
37
|
+
* EIP-7702 atomic batch, or the documented sequential fallback for a Push EOA
|
|
38
|
+
* without 7702 — reported through `atomic` / `transactionHashes`).
|
|
39
|
+
*/
|
|
40
|
+
async function sendOwnerCalls(runtime, calls, progressHook) {
|
|
41
|
+
if (calls.length === 0)
|
|
42
|
+
throw new Error('sendOwnerCalls needs at least one call');
|
|
43
|
+
const options = progressHook ? { progressHook } : undefined;
|
|
44
|
+
if (calls.length === 1) {
|
|
45
|
+
return runtime.execute({ to: calls[0].to, value: calls[0].value, data: calls[0].data }, options);
|
|
46
|
+
}
|
|
47
|
+
return runtime.execute({ to: calls[0].to, value: BigInt(0), data: calls }, options);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Wait for every Push transaction the operation produced and return their
|
|
51
|
+
* logs in submission order. A reverted transaction raises AgenticRevertError
|
|
52
|
+
* carrying all hashes.
|
|
53
|
+
*/
|
|
54
|
+
async function confirmedLogs(runtime, tx) {
|
|
55
|
+
const hashes = (tx.transactionHashes ?? [tx.hash]);
|
|
56
|
+
const unavailable = (cause) => new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.RECEIPT_UNAVAILABLE, `submitted ${tx.hash} but could not read its receipt: ${cause instanceof Error ? cause.message : String(cause)}`, {
|
|
57
|
+
hint: 'The transaction may still land. Check these hashes before retrying.',
|
|
58
|
+
details: { txHash: tx.hash, transactionHashes: hashes },
|
|
59
|
+
cause,
|
|
60
|
+
});
|
|
61
|
+
let receipt;
|
|
62
|
+
try {
|
|
63
|
+
receipt = await tx.wait();
|
|
64
|
+
}
|
|
65
|
+
catch (cause) {
|
|
66
|
+
throw unavailable(cause);
|
|
67
|
+
}
|
|
68
|
+
if (hashes.length === 1) {
|
|
69
|
+
if (receipt.status !== 1) {
|
|
70
|
+
throw new errors_2.AgenticRevertError(`Push transaction ${tx.hash} reverted`, {
|
|
71
|
+
cause: { txHash: tx.hash },
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return { logs: receipt.logs, hashes };
|
|
75
|
+
}
|
|
76
|
+
const logs = [];
|
|
77
|
+
for (const hash of hashes) {
|
|
78
|
+
let r;
|
|
79
|
+
try {
|
|
80
|
+
r = await runtime.reader.getTransactionReceipt({ hash });
|
|
81
|
+
}
|
|
82
|
+
catch (cause) {
|
|
83
|
+
throw unavailable(cause);
|
|
84
|
+
}
|
|
85
|
+
if (r.status !== 'success') {
|
|
86
|
+
throw new errors_2.AgenticRevertError(`Push transaction ${hash} reverted`, {
|
|
87
|
+
cause: { txHash: hash },
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
logs.push(...r.logs);
|
|
91
|
+
}
|
|
92
|
+
return { logs, hashes };
|
|
93
|
+
}
|
|
94
|
+
/** Normalize a send failure: keep batch hashes and decoded revert data. */
|
|
95
|
+
function wrapSendError(err) {
|
|
96
|
+
if (err instanceof errors_2.AgenticError || err instanceof errors_2.AgenticRevertError)
|
|
97
|
+
return err;
|
|
98
|
+
const decoded = (0, revert_1.decodeAgenticRevert)(err);
|
|
99
|
+
if (err instanceof errors_1.PushChainBatchExecutionError) {
|
|
100
|
+
return new errors_2.AgenticRevertError(err.message, {
|
|
101
|
+
decodedError: decoded ?? err.decodedError,
|
|
102
|
+
cause: err,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
if (decoded || err instanceof errors_1.PushChainExecutionError) {
|
|
106
|
+
const e = err;
|
|
107
|
+
return new errors_2.AgenticRevertError(e?.message ?? decoded?.name ?? 'AGW revert', {
|
|
108
|
+
decodedError: decoded ?? e?.decodedError,
|
|
109
|
+
gatewayTxHash: e?.gatewayTxHash,
|
|
110
|
+
agenticCode: decoded?.name,
|
|
111
|
+
cause: err,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return err;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AgenticRuntime } from '../runtime';
|
|
2
|
+
import type { InternalCreateOptions, CreateResult } from '../agentic.types';
|
|
3
|
+
/** One index-bound v6 factory call deploys and grants atomically for EOA/UEA owners. */
|
|
4
|
+
export declare function createWallet(runtime: AgenticRuntime, label: string, options: InternalCreateOptions): Promise<CreateResult>;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createWallet = createWallet;
|
|
4
|
+
const duplicates_1 = require("./duplicates");
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const progress_hook_types_1 = require("../../progress-hook/progress-hook.types");
|
|
7
|
+
const capabilities_1 = require("../capabilities");
|
|
8
|
+
const deployments_1 = require("../deployments");
|
|
9
|
+
const ids_1 = require("../codec/ids");
|
|
10
|
+
const prepare_1 = require("./prepare");
|
|
11
|
+
const label_1 = require("./label");
|
|
12
|
+
const errors_1 = require("../errors");
|
|
13
|
+
const snapshot_1 = require("../reads/snapshot");
|
|
14
|
+
const wallets_1 = require("../reads/wallets");
|
|
15
|
+
const common_1 = require("./common");
|
|
16
|
+
/** One index-bound v6 factory call deploys and grants atomically for EOA/UEA owners. */
|
|
17
|
+
async function createWallet(runtime, label, options) {
|
|
18
|
+
const hook = options?.progressHook;
|
|
19
|
+
(0, label_1.assertLabel)(label);
|
|
20
|
+
if (!options || !Array.isArray(options.rules)) {
|
|
21
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'options.rules is required (use [] for a bare wallet)');
|
|
22
|
+
}
|
|
23
|
+
(0, common_1.assertCanSign)(runtime, 'agentic.create');
|
|
24
|
+
const gen = (0, deployments_1.currentGeneration)(runtime.network);
|
|
25
|
+
(0, capabilities_1.requireCapability)(gen.capabilities, capabilities_1.AgenticCapability.WALLET_READS);
|
|
26
|
+
await (0, deployments_1.verifyFactoryWiring)(runtime.reader, gen);
|
|
27
|
+
const owner = runtime.signerPushAccount();
|
|
28
|
+
const snap = await snapshot_1.Snapshot.at(runtime.reader);
|
|
29
|
+
const index = await (0, wallets_1.walletCount)(snap, gen, owner);
|
|
30
|
+
const [predicted, deployed] = await snap.read(gen.addresses.factory, gen.contracts.abis.factory, 'predictWallet', [owner, index]);
|
|
31
|
+
const wallet = (0, viem_1.getAddress)(predicted);
|
|
32
|
+
const mirror = (0, ids_1.deriveWallet)({
|
|
33
|
+
factory: gen.addresses.factory,
|
|
34
|
+
walletImplementation: gen.addresses.walletImplementation,
|
|
35
|
+
owner,
|
|
36
|
+
index,
|
|
37
|
+
});
|
|
38
|
+
if (wallet !== mirror || deployed || (await snap.code(wallet))) {
|
|
39
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INDEX_RACE, `next wallet slot ${index} for ${owner} is not a fresh counterfactual address`, { details: { wallet, mirror, deployed } });
|
|
40
|
+
}
|
|
41
|
+
const prepared = await (0, prepare_1.prepareWalletRules)(runtime, gen, owner, wallet, options.rules, snap);
|
|
42
|
+
(0, duplicates_1.assertNoDuplicateRules)(prepared);
|
|
43
|
+
const selfTarget = prepared.findIndex((p) => p.nativeTerms?.some((t) => t.target === wallet));
|
|
44
|
+
if (selfTarget >= 0) {
|
|
45
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, `rules[${selfTarget}].target is the wallet being created; the contracts refuse it as a native target`);
|
|
46
|
+
}
|
|
47
|
+
(0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_101, wallet, Number(index), false);
|
|
48
|
+
// A fresh wallet's grant nonce starts at 0 and increments per grant.
|
|
49
|
+
const predictedIds = prepared.map((p, i) => (0, ids_1.rulesId)({
|
|
50
|
+
validator: gen.addresses.sessionValidator,
|
|
51
|
+
agent: p.agent,
|
|
52
|
+
grantNonce: BigInt(i),
|
|
53
|
+
}));
|
|
54
|
+
if (prepared.length > 8)
|
|
55
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'create accepts at most eight initial rules');
|
|
56
|
+
const calls = [
|
|
57
|
+
{
|
|
58
|
+
to: gen.addresses.factory,
|
|
59
|
+
value: BigInt(0),
|
|
60
|
+
data: gen.contracts.encodeCreateWalletAt(owner, index, wallet, label, prepared.map((p) => p.session)),
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
(0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_102, wallet, 'single');
|
|
64
|
+
let tx;
|
|
65
|
+
try {
|
|
66
|
+
tx = await (0, common_1.sendOwnerCalls)(runtime, calls, hook);
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
const wrapped = atomicCreateFailure(err);
|
|
70
|
+
emitFailure(runtime, hook, wrapped);
|
|
71
|
+
throw wrapped;
|
|
72
|
+
}
|
|
73
|
+
let logs;
|
|
74
|
+
try {
|
|
75
|
+
({ logs } = await (0, common_1.confirmedLogs)(runtime, tx));
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
const wrapped = atomicCreateFailure(err);
|
|
79
|
+
emitFailure(runtime, hook, wrapped);
|
|
80
|
+
throw wrapped;
|
|
81
|
+
}
|
|
82
|
+
const deployedEv = gen.contracts.parseWalletDeployed(logs, gen.addresses.factory);
|
|
83
|
+
const granted = gen.contracts
|
|
84
|
+
.parseRulesGranted(logs, wallet)
|
|
85
|
+
.map((g) => g.rulesId);
|
|
86
|
+
if (deployedEv.length !== 1 ||
|
|
87
|
+
deployedEv[0].wallet !== wallet ||
|
|
88
|
+
deployedEv[0].index !== index) {
|
|
89
|
+
const err = new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.RECEIPT_MISMATCH, `createWallet produced ${deployedEv.map((d) => `${d.wallet}#${d.index}`).join(', ') ||
|
|
90
|
+
'no wallet'}, expected ${wallet}#${index}; grants targeted ${wallet}`, {
|
|
91
|
+
hint: 'The receipt does not describe the requested atomic creation. Inspect the submitted hash before retrying.',
|
|
92
|
+
details: {
|
|
93
|
+
expected: wallet,
|
|
94
|
+
deployed: deployedEv,
|
|
95
|
+
grantedRulesIds: granted,
|
|
96
|
+
txHash: tx.hash,
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
emitFailure(runtime, hook, err);
|
|
100
|
+
throw err;
|
|
101
|
+
}
|
|
102
|
+
if (!sameIds(granted, predictedIds)) {
|
|
103
|
+
const err = new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.RECEIPT_MISMATCH, 'RulesGranted events do not match the requested rules in order', { details: { granted, predicted: predictedIds, txHash: tx.hash } });
|
|
104
|
+
emitFailure(runtime, hook, err);
|
|
105
|
+
throw err;
|
|
106
|
+
}
|
|
107
|
+
if (granted.length > 0)
|
|
108
|
+
(0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_104, granted);
|
|
109
|
+
(0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_199_01, 'create', tx.hash);
|
|
110
|
+
return {
|
|
111
|
+
wallet,
|
|
112
|
+
index: Number(index),
|
|
113
|
+
rulesIds: granted,
|
|
114
|
+
tx,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function sameIds(a, b) {
|
|
118
|
+
return (a.length === b.length &&
|
|
119
|
+
a.every((x, i) => x.toLowerCase() === b[i].toLowerCase()));
|
|
120
|
+
}
|
|
121
|
+
function atomicCreateFailure(error) {
|
|
122
|
+
const wrapped = (0, common_1.wrapSendError)(error);
|
|
123
|
+
if (['IndexMismatch', 'IntentWalletMismatch'].includes(wrapped?.decodedError?.name ?? ''))
|
|
124
|
+
return new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INDEX_RACE, 'the predicted wallet slot changed; atomic creation committed nothing', {
|
|
125
|
+
cause: wrapped,
|
|
126
|
+
details: {
|
|
127
|
+
committed: false,
|
|
128
|
+
walletDeployed: false,
|
|
129
|
+
grantedRulesIds: [],
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
return wrapped;
|
|
133
|
+
}
|
|
134
|
+
function emitFailure(runtime, hook, err) {
|
|
135
|
+
const e = err;
|
|
136
|
+
(0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_199_02, 'create', e?.code ?? 'UNKNOWN', e?.message ?? String(err), e?.decodedError);
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { PreparedRule } from '../codec/rules';
|
|
2
|
+
import type { ActiveRule } from '../reads/rules';
|
|
3
|
+
/** SDK creation policy; existing contract overlaps still use AMBIGUOUS_RULE at send. */
|
|
4
|
+
export declare function assertNoDuplicateRules(prepared: readonly PreparedRule[], existing?: readonly ActiveRule[]): void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertNoDuplicateRules = assertNoDuplicateRules;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const rules_1 = require("../codec/rules");
|
|
6
|
+
const errors_1 = require("../errors");
|
|
7
|
+
/** SDK creation policy; existing contract overlaps still use AMBIGUOUS_RULE at send. */
|
|
8
|
+
function assertNoDuplicateRules(prepared, existing = []) {
|
|
9
|
+
const keys = new Set(existing.map((r) => `${(0, viem_1.getAddress)(r.agent)}:${r.chainHash}`));
|
|
10
|
+
for (const rule of prepared) {
|
|
11
|
+
const key = `${(0, viem_1.getAddress)(rule.agent)}:${(0, rules_1.chainHash)(rule.chainNamespace)}`;
|
|
12
|
+
if (keys.has(key))
|
|
13
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.DUPLICATE_RULE, `an enabled rule already names ${rule.agent} for ${rule.chainNamespace}`, {
|
|
14
|
+
hint: 'Put multiple allowed calls in one rule or update the existing rule.',
|
|
15
|
+
details: { agent: rule.agent, chainNamespace: rule.chainNamespace },
|
|
16
|
+
});
|
|
17
|
+
keys.add(key);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=duplicates.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_LABEL_BYTES = void 0;
|
|
4
|
+
exports.assertLabel = assertLabel;
|
|
5
|
+
const errors_1 = require("../errors");
|
|
6
|
+
/** AGW MAX_LABEL_BYTES. Empty resets the default; lengths count UTF-8 bytes. */
|
|
7
|
+
exports.MAX_LABEL_BYTES = 64;
|
|
8
|
+
function assertLabel(label) {
|
|
9
|
+
if (typeof label !== 'string') {
|
|
10
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'label must be a string');
|
|
11
|
+
}
|
|
12
|
+
const length = new TextEncoder().encode(label).length;
|
|
13
|
+
if (length > exports.MAX_LABEL_BYTES) {
|
|
14
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, `label must be at most ${exports.MAX_LABEL_BYTES} UTF-8 bytes (received ${length})`, { details: { length, maxLength: exports.MAX_LABEL_BYTES } });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=label.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Address } from 'viem';
|
|
2
|
+
import { type AgenticGeneration } from '../deployments';
|
|
3
|
+
import type { InternalRule } from '../agentic.types';
|
|
4
|
+
import type { AgenticRuntime } from '../runtime';
|
|
5
|
+
import { Snapshot } from '../reads/snapshot';
|
|
6
|
+
/** Resolve wallet-dependent wire inputs without signing or mutating authority. */
|
|
7
|
+
export declare function prepareWalletRules(runtime: AgenticRuntime, gen: AgenticGeneration, owner: Address, wallet: Address, inputs: readonly InternalRule[], snap: Snapshot): Promise<import("../codec/rules").PreparedRule[]>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareWalletRules = prepareWalletRules;
|
|
4
|
+
const public_rule_1 = require("../public-rule");
|
|
5
|
+
const svm_public_1 = require("./svm-public");
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const enums_1 = require("../../constants/enums");
|
|
8
|
+
const chain_1 = require("../../constants/chain");
|
|
9
|
+
const defaults_1 = require("../codec/defaults");
|
|
10
|
+
const rules_1 = require("../codec/rules");
|
|
11
|
+
const universal_1 = require("../codec/universal");
|
|
12
|
+
const deployments_1 = require("../deployments");
|
|
13
|
+
const capabilities_1 = require("../capabilities");
|
|
14
|
+
const errors_1 = require("../errors");
|
|
15
|
+
const prc20_metadata_1 = require("../contracts/prc20-metadata");
|
|
16
|
+
/** Resolve wallet-dependent wire inputs without signing or mutating authority. */
|
|
17
|
+
async function prepareWalletRules(runtime, gen, owner, wallet, inputs, snap) {
|
|
18
|
+
const rules = await Promise.all(inputs.map((rule) => (0, public_rule_1.isPublicRule)(rule) ? (0, public_rule_1.normalizePublicRule)(rule, wallet, runtime) : rule));
|
|
19
|
+
if (rules.length)
|
|
20
|
+
await (0, deployments_1.verifyPolicyVersion)(runtime.reader, gen);
|
|
21
|
+
const svm = new Map();
|
|
22
|
+
const universal = new Map();
|
|
23
|
+
for (const rule of rules) {
|
|
24
|
+
if (rule && (0, rules_1.isSolanaRule)(rule)) {
|
|
25
|
+
(0, capabilities_1.requireCapability)(gen.capabilities, capabilities_1.AgenticCapability.UNIVERSAL_SVM_RULES);
|
|
26
|
+
svm.set(rule, await (0, svm_public_1.preparePublicSvmRule)(runtime, snap, wallet, rule));
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (!(0, rules_1.isUniversalRule)(rule))
|
|
30
|
+
continue;
|
|
31
|
+
if (rule.chainNamespace.startsWith('solana:'))
|
|
32
|
+
(0, capabilities_1.requireCapability)(gen.capabilities, capabilities_1.AgenticCapability.UNIVERSAL_SVM_RULES);
|
|
33
|
+
(0, universal_1.validateUniversalRuleShape)(rule, runtime.nowSeconds());
|
|
34
|
+
(0, capabilities_1.requireCapability)(gen.capabilities, rule.chainNamespace.startsWith('solana:')
|
|
35
|
+
? capabilities_1.AgenticCapability.UNIVERSAL_SVM_RULES
|
|
36
|
+
: capabilities_1.AgenticCapability.UNIVERSAL_EVM_RULES);
|
|
37
|
+
const chain = rule.chainNamespace;
|
|
38
|
+
if (chain_1.CHAIN_INFO[chain]?.vm !== enums_1.VM.EVM)
|
|
39
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, `unsupported EVM rule chain ${chain}`);
|
|
40
|
+
const { cea } = await runtime.resolveCEA(wallet, chain);
|
|
41
|
+
const assets = rule.assets.length
|
|
42
|
+
? rule.assets.map((a) => ({
|
|
43
|
+
token: typeof a.token === 'string' && (0, viem_1.getAddress)(a.token) === viem_1.zeroAddress
|
|
44
|
+
? undefined
|
|
45
|
+
: a.token,
|
|
46
|
+
maxPerCall: a.maxPerCall,
|
|
47
|
+
maxTotal: (0, defaults_1.withDefault)(a.maxTotal, defaults_1.AGENTIC_DEFAULTS.universal.assetMaxTotal),
|
|
48
|
+
}))
|
|
49
|
+
: [{ token: undefined, maxPerCall: BigInt(0), maxTotal: BigInt(0) }];
|
|
50
|
+
const resolved = [];
|
|
51
|
+
for (const asset of assets) {
|
|
52
|
+
const token = asset.token === undefined
|
|
53
|
+
? await (0, prc20_metadata_1.readGasPrc20)(snap, chain)
|
|
54
|
+
: runtime.resolvePrc20(asset.token, chain);
|
|
55
|
+
if (token === viem_1.zeroAddress)
|
|
56
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, `no gas PRC20 registered for ${chain}`);
|
|
57
|
+
const namespace = await snap.read(token, prc20_metadata_1.PRC20_SOURCE_ABI, 'SOURCE_CHAIN_NAMESPACE');
|
|
58
|
+
if (namespace !== chain)
|
|
59
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.ASSET_CHAIN_MISMATCH, `PRC20 ${token} belongs to ${namespace}, not ${chain}`);
|
|
60
|
+
if (asset.token !== undefined) {
|
|
61
|
+
const expected = typeof asset.token === 'string'
|
|
62
|
+
? (0, viem_1.getAddress)(asset.token)
|
|
63
|
+
: (0, viem_1.getAddress)(asset.token.address);
|
|
64
|
+
if (expected === viem_1.zeroAddress) {
|
|
65
|
+
if ((await (0, prc20_metadata_1.readGasPrc20)(snap, chain)) !== (0, viem_1.getAddress)(token))
|
|
66
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'resolved token is not the registered native gas token');
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const source = await (0, prc20_metadata_1.readOriginToken)(snap, token, chain);
|
|
70
|
+
if (source !== expected)
|
|
71
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, `PRC20 ${token} represents ${source}, not requested token ${expected}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
resolved.push({
|
|
75
|
+
token: (0, viem_1.getAddress)(token),
|
|
76
|
+
maxPerCall: asset.maxPerCall,
|
|
77
|
+
maxTotal: asset.maxTotal,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
universal.set(rule, { expectedCEA: (0, viem_1.getAddress)(cea), assets: resolved });
|
|
81
|
+
}
|
|
82
|
+
return (0, rules_1.prepareRules)(rules, {
|
|
83
|
+
owner,
|
|
84
|
+
pushChainNamespace: runtime.pushChainNamespace,
|
|
85
|
+
validator: gen.addresses.sessionValidator,
|
|
86
|
+
rulesPolicy: gen.addresses.rulesPolicy,
|
|
87
|
+
gateway: gen.addresses.gateway,
|
|
88
|
+
capabilities: gen.capabilities,
|
|
89
|
+
nowSeconds: runtime.nowSeconds(),
|
|
90
|
+
forbiddenTargets: (0, deployments_1.forbiddenTargets)(gen, wallet),
|
|
91
|
+
universal,
|
|
92
|
+
svm,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=prepare.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Address } from 'viem';
|
|
2
|
+
import type { UniversalTxResponse } from '../../orchestrator/orchestrator.types';
|
|
3
|
+
import { type AgenticGeneration } from '../deployments';
|
|
4
|
+
import type { AgenticRuntime } from '../runtime';
|
|
5
|
+
import type { AgenticHex, AgenticProgressHook, InternalRule } from '../agentic.types';
|
|
6
|
+
/** w.rules.add(rules): owner grants on an existing wallet, IDs in input order. */
|
|
7
|
+
export declare function addRules(runtime: AgenticRuntime, gen: AgenticGeneration, wallet: Address, rules: readonly InternalRule[], hook?: AgenticProgressHook): Promise<{
|
|
8
|
+
rulesIds: AgenticHex[];
|
|
9
|
+
tx: UniversalTxResponse;
|
|
10
|
+
}>;
|
|
11
|
+
/** Bare revoke (no IDs, empty list, or anything but { all: true }) is refused. */
|
|
12
|
+
export declare function assertRevokeTarget(target: unknown): {
|
|
13
|
+
all: boolean;
|
|
14
|
+
ids?: AgenticHex[];
|
|
15
|
+
};
|
|
16
|
+
/** w.rules.delete(ids) / w.rules.delete({ all: true }). Bare revoke is refused. */
|
|
17
|
+
export declare function revokeRules(runtime: AgenticRuntime, gen: AgenticGeneration, wallet: Address, target: AgenticHex[] | {
|
|
18
|
+
all: true;
|
|
19
|
+
progressHook?: AgenticProgressHook;
|
|
20
|
+
} | undefined, hook?: AgenticProgressHook): Promise<UniversalTxResponse>;
|
|
21
|
+
/**
|
|
22
|
+
* w.rules.update({ rules: [{ rulesId, rule }] }): for every pair, inside ONE
|
|
23
|
+
* owner `execute` batch: assertSpent(expected) → revokeRules(old) →
|
|
24
|
+
* grantRules(new). Never falls back to sequential sends. An agent spending
|
|
25
|
+
* between the read and inclusion makes the whole batch revert; retry needs a
|
|
26
|
+
* fresh read and a new owner signature. New counters start at zero.
|
|
27
|
+
*/
|
|
28
|
+
export declare function updateRules(runtime: AgenticRuntime, gen: AgenticGeneration, wallet: Address, params: {
|
|
29
|
+
rules: {
|
|
30
|
+
rulesId: AgenticHex;
|
|
31
|
+
rule: InternalRule;
|
|
32
|
+
}[];
|
|
33
|
+
progressHook?: AgenticProgressHook;
|
|
34
|
+
}): Promise<{
|
|
35
|
+
rules: {
|
|
36
|
+
rulesId: AgenticHex;
|
|
37
|
+
replaced: AgenticHex;
|
|
38
|
+
}[];
|
|
39
|
+
tx: UniversalTxResponse;
|
|
40
|
+
}>;
|
|
41
|
+
/** Direct owner rename; empty resets the default label without a checkpoint. */
|
|
42
|
+
export declare function setLabel(runtime: AgenticRuntime, gen: AgenticGeneration, wallet: Address, label: string, hook?: AgenticProgressHook): Promise<UniversalTxResponse>;
|