@pushchain/core 6.0.25 → 6.0.27-alpha.0
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 +194 -0
- package/CHANGELOG.md +74 -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 +409 -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 +15 -0
- package/src/lib/agentic/codec/abi-layout.js +121 -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 +75 -0
- package/src/lib/agentic/codec/native.js +328 -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 +242 -0
- package/src/lib/agentic/codec/universal-terms.d.ts +67 -0
- package/src/lib/agentic/codec/universal-terms.js +41 -0
- package/src/lib/agentic/codec/universal.d.ts +14 -0
- package/src/lib/agentic/codec/universal.js +157 -0
- package/src/lib/agentic/constants.d.ts +11 -0
- package/src/lib/agentic/constants.js +15 -0
- package/src/lib/agentic/context.d.ts +29 -0
- package/src/lib/agentic/context.js +56 -0
- package/src/lib/agentic/contracts/abi/v5/agent-validator.d.ts +105 -0
- package/src/lib/agentic/contracts/abi/v5/agent-validator.js +149 -0
- package/src/lib/agentic/contracts/abi/v5/agw-factory.d.ts +847 -0
- package/src/lib/agentic/contracts/abi/v5/agw-factory.js +1108 -0
- package/src/lib/agentic/contracts/abi/v5/agw.d.ts +1211 -0
- package/src/lib/agentic/contracts/abi/v5/agw.js +1588 -0
- package/src/lib/agentic/contracts/abi/v5/index.d.ts +6 -0
- package/src/lib/agentic/contracts/abi/v5/index.js +17 -0
- package/src/lib/agentic/contracts/abi/v5/smart-session.d.ts +1493 -0
- package/src/lib/agentic/contracts/abi/v5/smart-session.js +1965 -0
- package/src/lib/agentic/contracts/abi/v5/universal-rules-policy.d.ts +1640 -0
- package/src/lib/agentic/contracts/abi/v5/universal-rules-policy.js +2160 -0
- package/src/lib/agentic/contracts/donut-v5.d.ts +11 -0
- package/src/lib/agentic/contracts/donut-v5.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/v5.d.ts +5323 -0
- package/src/lib/agentic/contracts/v5.js +316 -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 +71 -0
- package/src/lib/agentic/errors.js +92 -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 +276 -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 +182 -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 +90 -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 +114 -0
- package/src/lib/agentic/management/create.d.ts +16 -0
- package/src/lib/agentic/management/create.js +271 -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 +21 -0
- package/src/lib/agentic/presets/catalog.js +10 -0
- package/src/lib/agentic/presets/index.d.ts +5 -0
- package/src/lib/agentic/presets/index.js +190 -0
- package/src/lib/agentic/presets/types.d.ts +44 -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 +342 -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 +286 -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 +95 -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/chain.js +1 -1
- package/src/lib/constants/enums.d.ts +6 -3
- package/src/lib/constants/enums.js +6 -3
- package/src/lib/constants/index.d.ts +65 -7
- package/src/lib/constants/index.js +18 -3
- package/src/lib/constants/read-state.d.ts +15 -2
- package/src/lib/constants/read-state.js +19 -3
- package/src/lib/index.d.ts +9 -3
- package/src/lib/index.js +11 -2
- 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 +84 -0
- package/src/lib/progress-hook/progress-hook.types.d.ts +14 -2
- package/src/lib/progress-hook/progress-hook.types.js +13 -0
- package/src/lib/push-chain/push-chain.d.ts +58 -16
- package/src/lib/push-chain/push-chain.js +68 -8
- package/src/lib/push-client/push-client.d.ts +7 -0
- package/src/lib/push-client/push-client.js +41 -15
- package/src/lib/read-state/destination.js +6 -1
- package/src/lib/read-state/envelopes/evm.js +2 -3
- package/src/lib/read-state/envelopes/svm.js +11 -1
- package/src/lib/read-state/read-executor.js +4 -0
- package/src/lib/read-state/read-params.d.ts +71 -26
- package/src/lib/read-state/read-params.js +60 -15
- package/src/lib/read-state/read-state.types.d.ts +44 -1
- package/src/lib/read-state/read-state.types.js +23 -1
- package/src/lib/read-state/read-tracker.d.ts +6 -1
- package/src/lib/read-state/read-tracker.js +83 -17
- package/src/lib/read-state/registry.js +2 -3
- package/src/lib/read-state/result-decoder.js +6 -0
- package/src/lib/read-state/spec-builder.js +2 -2
- package/src/lib/read-state/svm-account.d.ts +20 -0
- package/src/lib/read-state/svm-account.js +114 -0
- package/src/lib/read-state/svm-pda.d.ts +13 -0
- package/src/lib/read-state/svm-pda.js +147 -0
- 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,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareSvmAgentExecution = prepareSvmAgentExecution;
|
|
4
|
+
exports.sendSvmAgentWire = sendSvmAgentWire;
|
|
5
|
+
const svm_quote_1 = require("./svm-quote");
|
|
6
|
+
/** Prepared-wire agent execution used by the public Solana route. */
|
|
7
|
+
const viem_1 = require("viem");
|
|
8
|
+
const common_1 = require("../management/common");
|
|
9
|
+
const snapshot_1 = require("../reads/snapshot");
|
|
10
|
+
const svm_1 = require("../reads/svm");
|
|
11
|
+
const svm_context_1 = require("../management/svm-context");
|
|
12
|
+
const svm_outbound_1 = require("./svm-outbound");
|
|
13
|
+
const svm_instruction_1 = require("./svm-instruction");
|
|
14
|
+
const errors_1 = require("../errors");
|
|
15
|
+
const svm_2 = require("../management/svm");
|
|
16
|
+
async function prepareSvmAgentExecution(runtime, gen, input, metadata) {
|
|
17
|
+
(0, common_1.assertCanSign)(runtime, 'internal SVM send');
|
|
18
|
+
await (0, svm_2.verifySvmWallet)(runtime, gen, input.wallet);
|
|
19
|
+
const snap = await snapshot_1.Snapshot.at(runtime.reader);
|
|
20
|
+
const stored = await (0, svm_1.readSvmRule)(snap, gen, input.wallet, input.rulesId, runtime.pushChainNamespace);
|
|
21
|
+
if ((0, viem_1.getAddress)(stored.agent) !== (0, viem_1.getAddress)(runtime.signerPushAccount()))
|
|
22
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.NOT_OWNER_OR_AGENT, 'signer is not this SVM rule agent');
|
|
23
|
+
const chain = stored.chainNamespace;
|
|
24
|
+
const resolved = await (0, svm_context_1.resolveSvmContext)(snap, input.wallet, stored.chainNamespace, stored.config.assets, metadata);
|
|
25
|
+
if (resolved.expectedCEA.toLowerCase() !==
|
|
26
|
+
stored.config.expectedCEA.toLowerCase() ||
|
|
27
|
+
resolved.gatewayProgram.toLowerCase() !==
|
|
28
|
+
stored.config.gatewayProgram.toLowerCase() ||
|
|
29
|
+
resolved.ceaAccounts.some((a) => !stored.config.ceaAccounts.some((b) => a.toLowerCase() === b.toLowerCase())))
|
|
30
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'stored SVM context does not cover the wallet and every asset');
|
|
31
|
+
const instruction = (0, svm_instruction_1.resolveAgwSvmInstruction)({
|
|
32
|
+
wallet: input.wallet,
|
|
33
|
+
chain,
|
|
34
|
+
program: input.program,
|
|
35
|
+
instructionData: input.instructionData,
|
|
36
|
+
accounts: input.accounts,
|
|
37
|
+
}, stored.config);
|
|
38
|
+
const quote = await (0, svm_quote_1.quoteSvmRequest)(runtime, snap, input.wallet, (0, viem_1.getAddress)(input.token), chain, input.gasLimit, input.amount);
|
|
39
|
+
const call = (0, svm_outbound_1.buildAgwSvmAction)({
|
|
40
|
+
...input,
|
|
41
|
+
gateway: gen.addresses.gateway,
|
|
42
|
+
recipient: instruction.recipient,
|
|
43
|
+
payload: instruction.payload,
|
|
44
|
+
gasLimit: quote.gasLimitUsed,
|
|
45
|
+
protocolFee: quote.protocolFee,
|
|
46
|
+
maxPCForGas: quote.nativeValueForGas,
|
|
47
|
+
});
|
|
48
|
+
const walletPc = await runtime.reader.getBalance({
|
|
49
|
+
address: input.wallet,
|
|
50
|
+
blockNumber: snap.blockNumber,
|
|
51
|
+
});
|
|
52
|
+
if (walletPc < call.value)
|
|
53
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.WALLET_BALANCE_INSUFFICIENT, 'wallet PC is below the SVM outbound quote');
|
|
54
|
+
if (input.amount > BigInt(0)) {
|
|
55
|
+
const balance = await snap.read(input.token, viem_1.erc20Abi, 'balanceOf', [input.wallet]);
|
|
56
|
+
if (balance < input.amount)
|
|
57
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.WALLET_BALANCE_INSUFFICIENT, 'wallet token balance is below the SVM amount');
|
|
58
|
+
const allowance = await snap.read(input.token, viem_1.erc20Abi, 'allowance', [input.wallet, gen.addresses.gateway]);
|
|
59
|
+
if (allowance < input.amount)
|
|
60
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.GATEWAY_ALLOWANCE_INSUFFICIENT, 'owner must establish the SVM gateway allowance separately');
|
|
61
|
+
}
|
|
62
|
+
const signerPc = await runtime.signerBalance();
|
|
63
|
+
const gasReserve = (await runtime.getGasPrice()) * BigInt(10_000_000);
|
|
64
|
+
if ((await runtime.signerAccountDeployed()) && signerPc < gasReserve)
|
|
65
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.AGENT_GAS_INSUFFICIENT, 'deployed SVM agent identity has no Push gas balance');
|
|
66
|
+
return {
|
|
67
|
+
stored,
|
|
68
|
+
call,
|
|
69
|
+
instruction,
|
|
70
|
+
quote,
|
|
71
|
+
data: gen.contracts.encodeExecuteAsAgent(input.rulesId, call),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
async function sendSvmAgentWire(runtime, gen, input, metadata) {
|
|
75
|
+
const prepared = await prepareSvmAgentExecution(runtime, gen, input, metadata);
|
|
76
|
+
try {
|
|
77
|
+
const tx = await runtime.execute({
|
|
78
|
+
to: input.wallet,
|
|
79
|
+
value: BigInt(0),
|
|
80
|
+
data: prepared.data,
|
|
81
|
+
});
|
|
82
|
+
// Return the ordinary signer response and explicit wire context internally.
|
|
83
|
+
// The public wrapper applies the response presentation.
|
|
84
|
+
return { tx, context: prepared.stored, instruction: prepared.instruction };
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
throw (0, common_1.wrapSendError)(error);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=svm-send.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { AgenticAddress, AgenticHex, AgenticDoor, AgenticNamespace, AgenticProgressHook, AgenticTxMetadata, AgenticWallet, RuleCall as AllowedCall, RuleAsset as AssetCap, Checkpoint, CheckpointKind, CreateOptions, CreateResult, ForeignChainNamespace, DecodedSolanaRule, Rule, RuleInput, Pin, Spent, WalletMarker, RulesRecord, Selector, WalletInfo, WalletSummary, } from './agentic.types';
|
|
2
|
+
export { AGENTIC_ERROR_CODE, AgenticError, AgenticRevertError } from './errors';
|
|
3
|
+
export type { AgenticErrorCode } from './errors';
|
|
4
|
+
export { AGENTIC } from './constants';
|
|
5
|
+
export type { Preset, PresetCategory, PresetAsset, PresetOptions, ReadyPresetOptions, PresetRuleTemplate, AgenticPresets, } from './presets/types';
|
|
@@ -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,114 @@
|
|
|
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})`, { hint: 'Rule and label writes are owner-only. Initialize with the owner signer.' });
|
|
29
|
+
}
|
|
30
|
+
return owner;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Send owner calls through the signer's ordinary transaction path: one call
|
|
34
|
+
* as a plain transaction, several as the signer's batch (UEA multicall,
|
|
35
|
+
* EIP-7702 atomic batch, or the documented sequential fallback for a Push EOA
|
|
36
|
+
* without 7702 — reported through `atomic` / `transactionHashes`).
|
|
37
|
+
*/
|
|
38
|
+
async function sendOwnerCalls(runtime, calls, progressHook) {
|
|
39
|
+
if (calls.length === 0)
|
|
40
|
+
throw new Error('sendOwnerCalls needs at least one call');
|
|
41
|
+
const options = progressHook ? { progressHook } : undefined;
|
|
42
|
+
if (calls.length === 1) {
|
|
43
|
+
return runtime.execute({ to: calls[0].to, value: calls[0].value, data: calls[0].data }, options);
|
|
44
|
+
}
|
|
45
|
+
return runtime.execute({ to: calls[0].to, value: BigInt(0), data: calls }, options);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Wait for every Push transaction the operation produced and return their
|
|
49
|
+
* logs in submission order. A reverted transaction raises AgenticRevertError
|
|
50
|
+
* carrying all hashes.
|
|
51
|
+
*/
|
|
52
|
+
async function confirmedLogs(runtime, tx) {
|
|
53
|
+
const hashes = (tx.transactionHashes ?? [tx.hash]);
|
|
54
|
+
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)}`, {
|
|
55
|
+
hint: 'The transaction may still land. Check these hashes before retrying.',
|
|
56
|
+
details: { txHash: tx.hash, transactionHashes: hashes },
|
|
57
|
+
cause,
|
|
58
|
+
});
|
|
59
|
+
let receipt;
|
|
60
|
+
try {
|
|
61
|
+
receipt = await tx.wait();
|
|
62
|
+
}
|
|
63
|
+
catch (cause) {
|
|
64
|
+
throw unavailable(cause);
|
|
65
|
+
}
|
|
66
|
+
if (hashes.length === 1) {
|
|
67
|
+
if (receipt.status !== 1) {
|
|
68
|
+
throw new errors_2.AgenticRevertError(`Push transaction ${tx.hash} reverted`, {
|
|
69
|
+
transactionHashes: hashes,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return { logs: receipt.logs, hashes };
|
|
73
|
+
}
|
|
74
|
+
const logs = [];
|
|
75
|
+
for (const hash of hashes) {
|
|
76
|
+
let r;
|
|
77
|
+
try {
|
|
78
|
+
r = await runtime.reader.getTransactionReceipt({ hash });
|
|
79
|
+
}
|
|
80
|
+
catch (cause) {
|
|
81
|
+
throw unavailable(cause);
|
|
82
|
+
}
|
|
83
|
+
if (r.status !== 'success') {
|
|
84
|
+
throw new errors_2.AgenticRevertError(`Push transaction ${hash} reverted`, { transactionHashes: hashes });
|
|
85
|
+
}
|
|
86
|
+
logs.push(...r.logs);
|
|
87
|
+
}
|
|
88
|
+
return { logs, hashes };
|
|
89
|
+
}
|
|
90
|
+
/** Normalize a send failure: keep batch hashes and decoded revert data. */
|
|
91
|
+
function wrapSendError(err) {
|
|
92
|
+
if (err instanceof errors_2.AgenticError || err instanceof errors_2.AgenticRevertError)
|
|
93
|
+
return err;
|
|
94
|
+
const decoded = (0, revert_1.decodeAgenticRevert)(err);
|
|
95
|
+
if (err instanceof errors_1.PushChainBatchExecutionError) {
|
|
96
|
+
return new errors_2.AgenticRevertError(err.message, {
|
|
97
|
+
decodedError: decoded ?? err.decodedError,
|
|
98
|
+
transactionHashes: err.transactionHashes,
|
|
99
|
+
pendingTransactionHash: err.pendingTransactionHash,
|
|
100
|
+
cause: err,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (decoded || err instanceof errors_1.PushChainExecutionError) {
|
|
104
|
+
const e = err;
|
|
105
|
+
return new errors_2.AgenticRevertError(e?.message ?? decoded?.name ?? 'AGW revert', {
|
|
106
|
+
decodedError: decoded ?? e?.decodedError,
|
|
107
|
+
gatewayTxHash: e?.gatewayTxHash,
|
|
108
|
+
agenticCode: decoded?.name,
|
|
109
|
+
cause: err,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return err;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AgenticRuntime } from '../runtime';
|
|
2
|
+
import type { InternalCreateOptions, CreateResult } from '../agentic.types';
|
|
3
|
+
/**
|
|
4
|
+
* client.agentic.create(label, { rules }): deploy + grants only. Funding and
|
|
5
|
+
* approvals are separate ordinary sends. Every input is validated and every
|
|
6
|
+
* prediction re-read immediately before signing; IDs are returned from
|
|
7
|
+
* receipts in input order.
|
|
8
|
+
*
|
|
9
|
+
* Strategy follows the signer: an external owner's UEA batches atomically, a
|
|
10
|
+
* Push EOA uses an EIP-7702 batch when available and otherwise the documented
|
|
11
|
+
* sequential fallback. A sequential failure raises CREATE_PARTIAL with the
|
|
12
|
+
* deployed wallet, confirmed/pending hashes and granted IDs so the caller can
|
|
13
|
+
* finish with `wallet(w).rules.add(remaining)` — the SDK never deploys another
|
|
14
|
+
* wallet on its own.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createWallet(runtime: AgenticRuntime, label: string, options: InternalCreateOptions): Promise<CreateResult>;
|
|
@@ -0,0 +1,271 @@
|
|
|
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 errors_1 = require("../../orchestrator/internals/errors");
|
|
8
|
+
const capabilities_1 = require("../capabilities");
|
|
9
|
+
const deployments_1 = require("../deployments");
|
|
10
|
+
const ids_1 = require("../codec/ids");
|
|
11
|
+
const prepare_1 = require("./prepare");
|
|
12
|
+
const label_1 = require("./label");
|
|
13
|
+
const errors_2 = require("../errors");
|
|
14
|
+
const snapshot_1 = require("../reads/snapshot");
|
|
15
|
+
const wallets_1 = require("../reads/wallets");
|
|
16
|
+
const common_1 = require("./common");
|
|
17
|
+
/**
|
|
18
|
+
* client.agentic.create(label, { rules }): deploy + grants only. Funding and
|
|
19
|
+
* approvals are separate ordinary sends. Every input is validated and every
|
|
20
|
+
* prediction re-read immediately before signing; IDs are returned from
|
|
21
|
+
* receipts in input order.
|
|
22
|
+
*
|
|
23
|
+
* Strategy follows the signer: an external owner's UEA batches atomically, a
|
|
24
|
+
* Push EOA uses an EIP-7702 batch when available and otherwise the documented
|
|
25
|
+
* sequential fallback. A sequential failure raises CREATE_PARTIAL with the
|
|
26
|
+
* deployed wallet, confirmed/pending hashes and granted IDs so the caller can
|
|
27
|
+
* finish with `wallet(w).rules.add(remaining)` — the SDK never deploys another
|
|
28
|
+
* wallet on its own.
|
|
29
|
+
*/
|
|
30
|
+
async function createWallet(runtime, label, options) {
|
|
31
|
+
const hook = options?.progressHook;
|
|
32
|
+
(0, label_1.assertLabel)(label);
|
|
33
|
+
if (!options || !Array.isArray(options.rules)) {
|
|
34
|
+
throw new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.INVALID_RULE, 'options.rules is required (use [] for a bare wallet)');
|
|
35
|
+
}
|
|
36
|
+
(0, common_1.assertCanSign)(runtime, 'agentic.create');
|
|
37
|
+
const gen = (0, deployments_1.currentGeneration)(runtime.network);
|
|
38
|
+
(0, capabilities_1.requireCapability)(gen.capabilities, capabilities_1.AgenticCapability.WALLET_READS);
|
|
39
|
+
await (0, deployments_1.verifyFactoryWiring)(runtime.reader, gen);
|
|
40
|
+
const owner = runtime.signerPushAccount();
|
|
41
|
+
const snap = await snapshot_1.Snapshot.at(runtime.reader);
|
|
42
|
+
const index = await (0, wallets_1.walletCount)(snap, gen, owner);
|
|
43
|
+
const [predicted, deployed] = await snap.read(gen.addresses.factory, gen.contracts.abis.factory, 'predictWallet', [owner, index]);
|
|
44
|
+
const wallet = (0, viem_1.getAddress)(predicted);
|
|
45
|
+
const mirror = (0, ids_1.deriveWallet)({
|
|
46
|
+
factory: gen.addresses.factory,
|
|
47
|
+
walletImplementation: gen.addresses.walletImplementation,
|
|
48
|
+
owner,
|
|
49
|
+
index,
|
|
50
|
+
});
|
|
51
|
+
if (wallet !== mirror || deployed || (await snap.code(wallet))) {
|
|
52
|
+
throw new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.INDEX_RACE, `next wallet slot ${index} for ${owner} is not a fresh counterfactual address`, { details: { wallet, mirror, deployed } });
|
|
53
|
+
}
|
|
54
|
+
const prepared = await (0, prepare_1.prepareWalletRules)(runtime, gen, owner, wallet, options.rules, snap);
|
|
55
|
+
(0, duplicates_1.assertNoDuplicateRules)(prepared);
|
|
56
|
+
const selfTarget = prepared.findIndex((p) => p.nativeTerms?.some((t) => t.target === wallet));
|
|
57
|
+
if (selfTarget >= 0) {
|
|
58
|
+
throw new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.INVALID_RULE, `rules[${selfTarget}].target is the wallet being created; the contracts refuse it as a native target`);
|
|
59
|
+
}
|
|
60
|
+
(0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_101, wallet, Number(index), false);
|
|
61
|
+
// A fresh wallet's grant nonce starts at 0 and increments per grant.
|
|
62
|
+
const predictedIds = prepared.map((p, i) => (0, ids_1.rulesId)({
|
|
63
|
+
validator: gen.addresses.sessionValidator,
|
|
64
|
+
agent: p.agent,
|
|
65
|
+
grantNonce: BigInt(i),
|
|
66
|
+
}));
|
|
67
|
+
const calls = [
|
|
68
|
+
// Index-bound: reverts (nothing committed) if another creation took this slot.
|
|
69
|
+
{
|
|
70
|
+
to: gen.addresses.factory,
|
|
71
|
+
value: BigInt(0),
|
|
72
|
+
data: gen.contracts.encodeDeployWalletAt(owner, index, wallet, label),
|
|
73
|
+
},
|
|
74
|
+
...prepared.map((p) => ({
|
|
75
|
+
to: wallet,
|
|
76
|
+
value: BigInt(0),
|
|
77
|
+
data: gen.contracts.encodeGrantRules(p.session),
|
|
78
|
+
})),
|
|
79
|
+
];
|
|
80
|
+
const strategy = calls.length === 1
|
|
81
|
+
? 'single'
|
|
82
|
+
: runtime.signerIsPushNative()
|
|
83
|
+
? 'push-eoa-batch'
|
|
84
|
+
: 'uea-multicall';
|
|
85
|
+
(0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_102, wallet, strategy);
|
|
86
|
+
let tx;
|
|
87
|
+
try {
|
|
88
|
+
tx = await (0, common_1.sendOwnerCalls)(runtime, calls, hook);
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
const wrapped = await createFailure(runtime, gen, wallet, Number(index), owner, label, err);
|
|
92
|
+
emitFailure(runtime, hook, wrapped);
|
|
93
|
+
throw wrapped;
|
|
94
|
+
}
|
|
95
|
+
let logs;
|
|
96
|
+
try {
|
|
97
|
+
({ logs } = await (0, common_1.confirmedLogs)(runtime, tx));
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
const wrapped = await createFailure(runtime, gen, wallet, Number(index), owner, label, err);
|
|
101
|
+
emitFailure(runtime, hook, wrapped);
|
|
102
|
+
throw wrapped;
|
|
103
|
+
}
|
|
104
|
+
const deployedEv = gen.contracts.parseWalletDeployed(logs, gen.addresses.factory);
|
|
105
|
+
const granted = gen.contracts
|
|
106
|
+
.parseRulesGranted(logs, wallet)
|
|
107
|
+
.map((g) => g.rulesId);
|
|
108
|
+
if (deployedEv.length !== 1 ||
|
|
109
|
+
deployedEv[0].wallet !== wallet ||
|
|
110
|
+
deployedEv[0].index !== index) {
|
|
111
|
+
const err = new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.INDEX_RACE, `deployWallet produced ${deployedEv.map((d) => `${d.wallet}#${d.index}`).join(', ') ||
|
|
112
|
+
'no wallet'}, expected ${wallet}#${index}; grants targeted ${wallet}`, {
|
|
113
|
+
hint: 'Another deployment by this owner raced this call. Inspect both wallets with client.agentic.list() before retrying.',
|
|
114
|
+
details: {
|
|
115
|
+
expected: wallet,
|
|
116
|
+
deployed: deployedEv,
|
|
117
|
+
grantedRulesIds: granted,
|
|
118
|
+
txHash: tx.hash,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
emitFailure(runtime, hook, err);
|
|
122
|
+
throw err;
|
|
123
|
+
}
|
|
124
|
+
if (!sameIds(granted, predictedIds)) {
|
|
125
|
+
const err = new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.RECEIPT_MISMATCH, 'RulesGranted events do not match the requested rules in order', { details: { granted, predicted: predictedIds, txHash: tx.hash } });
|
|
126
|
+
emitFailure(runtime, hook, err);
|
|
127
|
+
throw err;
|
|
128
|
+
}
|
|
129
|
+
if (granted.length > 0)
|
|
130
|
+
(0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_104, granted);
|
|
131
|
+
(0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_199_01, 'create', tx.hash);
|
|
132
|
+
return {
|
|
133
|
+
wallet,
|
|
134
|
+
index: Number(index),
|
|
135
|
+
rulesIds: granted,
|
|
136
|
+
tx,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function sameIds(a, b) {
|
|
140
|
+
return (a.length === b.length &&
|
|
141
|
+
a.every((x, i) => x.toLowerCase() === b[i].toLowerCase()));
|
|
142
|
+
}
|
|
143
|
+
const RACE_ERRORS = new Set(['IndexMismatch', 'IntentWalletMismatch']);
|
|
144
|
+
/**
|
|
145
|
+
* Turn a create failure into an exact report. What committed is derived from
|
|
146
|
+
* THIS operation's own receipts, never from a later state read; when those
|
|
147
|
+
* receipts cannot be fetched the outcome is reported as unknown so callers do
|
|
148
|
+
* not retry a creation that may have landed.
|
|
149
|
+
*/
|
|
150
|
+
async function createFailure(runtime, gen, wallet, index, owner, label, err) {
|
|
151
|
+
const wrapped = (0, common_1.wrapSendError)(err);
|
|
152
|
+
const batch = err instanceof errors_1.PushChainBatchExecutionError ? err : undefined;
|
|
153
|
+
const confirmed = (batch?.transactionHashes ?? []);
|
|
154
|
+
const pending = batch?.pendingTransactionHash;
|
|
155
|
+
const receiptUnavailable = wrapped instanceof errors_2.AgenticError &&
|
|
156
|
+
wrapped.code === errors_2.AGENTIC_ERROR_CODE.RECEIPT_UNAVAILABLE;
|
|
157
|
+
// The index-bound deploy reverted: another creation took the slot first and
|
|
158
|
+
// nothing from this call committed.
|
|
159
|
+
const decodedName = wrapped
|
|
160
|
+
.decodedError?.name;
|
|
161
|
+
if (confirmed.length === 0 &&
|
|
162
|
+
!pending &&
|
|
163
|
+
decodedName &&
|
|
164
|
+
RACE_ERRORS.has(decodedName)) {
|
|
165
|
+
return new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.INDEX_RACE, `wallet slot ${index} (${wallet}) was taken by a concurrent creation; nothing was committed`, {
|
|
166
|
+
hint: 'Retry agentic.create; it re-reads the next slot.',
|
|
167
|
+
details: { wallet, index, committed: false },
|
|
168
|
+
cause: wrapped,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
if (confirmed.length === 0 && !pending && !receiptUnavailable) {
|
|
172
|
+
// Some send paths flatten the factory revert to a generic execution
|
|
173
|
+
// error, losing the IndexMismatch selector. If the owner's next index has
|
|
174
|
+
// moved and immutable deployment metadata proves another label owns the
|
|
175
|
+
// predicted slot, this call could not have deployed or granted.
|
|
176
|
+
try {
|
|
177
|
+
const snap = await snapshot_1.Snapshot.at(runtime.reader);
|
|
178
|
+
const next = await (0, wallets_1.walletCount)(snap, gen, owner);
|
|
179
|
+
if (next > BigInt(index)) {
|
|
180
|
+
const competing = await (0, wallets_1.walletInfo)(runtime.reader, gen, wallet);
|
|
181
|
+
// label() is mutable in v5: only the immutable deploy event proves
|
|
182
|
+
// which creation occupied this slot. A later rename proves nothing.
|
|
183
|
+
const logs = await (0, snapshot_1.scanLogs)(runtime.reader, {
|
|
184
|
+
address: gen.addresses.factory,
|
|
185
|
+
event: gen.contracts.events.walletDeployed,
|
|
186
|
+
args: { wallet },
|
|
187
|
+
}, gen.startBlock, snap.blockNumber);
|
|
188
|
+
const deployed = gen.contracts
|
|
189
|
+
.parseWalletDeployed(logs, gen.addresses.factory)
|
|
190
|
+
.find((entry) => entry.wallet === wallet);
|
|
191
|
+
const competingLabel = deployed?.label;
|
|
192
|
+
if (competing.deployed &&
|
|
193
|
+
competing.index === index &&
|
|
194
|
+
(0, viem_1.getAddress)(competing.owner) === owner &&
|
|
195
|
+
competingLabel !== undefined &&
|
|
196
|
+
competingLabel !== label) {
|
|
197
|
+
return new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.INDEX_RACE, 'wallet slot ' + index + ' was consumed by a concurrent deployment', {
|
|
198
|
+
hint: 'Slot ' +
|
|
199
|
+
index +
|
|
200
|
+
' belongs to "' +
|
|
201
|
+
competingLabel +
|
|
202
|
+
'". No wallet or rules from this create call were committed; retry agentic.create to use the next slot.',
|
|
203
|
+
details: {
|
|
204
|
+
wallet,
|
|
205
|
+
index,
|
|
206
|
+
committed: false,
|
|
207
|
+
competingLabel,
|
|
208
|
+
},
|
|
209
|
+
cause: wrapped,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
// If the owner counter/event cannot be reconciled, preserve the original
|
|
216
|
+
// error; never infer that a retry is safe from an incomplete read.
|
|
217
|
+
}
|
|
218
|
+
// Nothing was confirmed (pre-broadcast failure or a reverted atomic batch).
|
|
219
|
+
return wrapped;
|
|
220
|
+
}
|
|
221
|
+
let walletDeployed = 'unknown';
|
|
222
|
+
let grantedRulesIds;
|
|
223
|
+
let recoveryError;
|
|
224
|
+
if (!receiptUnavailable) {
|
|
225
|
+
try {
|
|
226
|
+
const logs = [];
|
|
227
|
+
for (const hash of confirmed) {
|
|
228
|
+
const r = await runtime.reader.getTransactionReceipt({ hash });
|
|
229
|
+
if (r.status === 'success')
|
|
230
|
+
logs.push(...r.logs);
|
|
231
|
+
}
|
|
232
|
+
const deployed = gen.contracts
|
|
233
|
+
.parseWalletDeployed(logs, gen.addresses.factory)
|
|
234
|
+
.some((d) => d.wallet === wallet);
|
|
235
|
+
grantedRulesIds = gen.contracts
|
|
236
|
+
.parseRulesGranted(logs, wallet)
|
|
237
|
+
.map((g) => g.rulesId);
|
|
238
|
+
// A pending hash may itself be the deployment; only a confirmed deploy is certain.
|
|
239
|
+
walletDeployed = deployed ? true : pending ? 'unknown' : false;
|
|
240
|
+
}
|
|
241
|
+
catch (e) {
|
|
242
|
+
recoveryError = e instanceof Error ? e.message : String(e);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const hint = walletDeployed === true
|
|
246
|
+
? `Wallet ${wallet} is deployed. Do not call create again; once any pending hash settles, finish with client.agentic.wallet('${wallet}').rules.add(<remaining rules>).`
|
|
247
|
+
: walletDeployed === false
|
|
248
|
+
? 'No wallet was deployed by this call; it is safe to retry.'
|
|
249
|
+
: 'The outcome is unknown. Do not retry create until the listed hashes are reconciled (client.agentic.list() shows deployed wallets).';
|
|
250
|
+
return new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.CREATE_PARTIAL, `agentic.create did not complete: ${wrapped?.message ?? String(err)}`, {
|
|
251
|
+
hint,
|
|
252
|
+
details: {
|
|
253
|
+
wallet,
|
|
254
|
+
index,
|
|
255
|
+
walletDeployed,
|
|
256
|
+
grantedRulesIds,
|
|
257
|
+
confirmedHashes: confirmed,
|
|
258
|
+
pendingHash: pending,
|
|
259
|
+
...(receiptUnavailable
|
|
260
|
+
? { submitted: wrapped.details }
|
|
261
|
+
: {}),
|
|
262
|
+
...(recoveryError ? { recoveryError } : {}),
|
|
263
|
+
},
|
|
264
|
+
cause: wrapped,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
function emitFailure(runtime, hook, err) {
|
|
268
|
+
const e = err;
|
|
269
|
+
(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);
|
|
270
|
+
}
|
|
271
|
+
//# 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[]>;
|