@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,157 @@
|
|
|
1
|
+
/** Internal v5 SVM wire representation; not a proposed public Rule API. */
|
|
2
|
+
import { type Hex } from 'viem';
|
|
3
|
+
import { AgenticError } from '../errors';
|
|
4
|
+
import type { AssetCapWire } from './universal-terms';
|
|
5
|
+
export declare enum SvmDataPinMode {
|
|
6
|
+
EQ = 0,
|
|
7
|
+
GTE_LE = 1,
|
|
8
|
+
LTE_LE = 2,
|
|
9
|
+
RATIO_GTE_LE = 3
|
|
10
|
+
}
|
|
11
|
+
export interface AllowedProgramWire {
|
|
12
|
+
program: Hex;
|
|
13
|
+
discriminator: Hex;
|
|
14
|
+
discriminatorLen: number;
|
|
15
|
+
dataless: boolean;
|
|
16
|
+
maxAccounts: number;
|
|
17
|
+
}
|
|
18
|
+
export interface SvmAccountPinWire {
|
|
19
|
+
ruleIndex: number;
|
|
20
|
+
accountIndex: number;
|
|
21
|
+
expected: Hex;
|
|
22
|
+
}
|
|
23
|
+
export interface SvmDataPinWire {
|
|
24
|
+
ruleIndex: number;
|
|
25
|
+
fromEnd: boolean;
|
|
26
|
+
offset: number;
|
|
27
|
+
offsetB: number;
|
|
28
|
+
len: number;
|
|
29
|
+
mode: SvmDataPinMode;
|
|
30
|
+
expected: Hex;
|
|
31
|
+
num: bigint;
|
|
32
|
+
den: bigint;
|
|
33
|
+
}
|
|
34
|
+
export interface SvmTermsWire {
|
|
35
|
+
validUntil: number;
|
|
36
|
+
expectedCEA: Hex;
|
|
37
|
+
gatewayProgram: Hex;
|
|
38
|
+
assets: readonly AssetCapWire[];
|
|
39
|
+
maxGasPerCall: bigint;
|
|
40
|
+
ceaAccounts: readonly Hex[];
|
|
41
|
+
programs: readonly AllowedProgramWire[];
|
|
42
|
+
pins: readonly SvmAccountPinWire[];
|
|
43
|
+
dataPins: readonly SvmDataPinWire[];
|
|
44
|
+
}
|
|
45
|
+
export declare const SVM_LIMITS: {
|
|
46
|
+
readonly assets: 8;
|
|
47
|
+
readonly programs: 32;
|
|
48
|
+
readonly pins: 16;
|
|
49
|
+
readonly dataPins: 8;
|
|
50
|
+
readonly ceaAccounts: 16;
|
|
51
|
+
readonly accounts: 64;
|
|
52
|
+
readonly ixData: 1024;
|
|
53
|
+
};
|
|
54
|
+
export declare const UINT64_MAX: bigint;
|
|
55
|
+
export declare const FORBIDDEN_SVM_PROGRAMS: readonly Hex[];
|
|
56
|
+
export declare const SVM_TERMS_PARAM: {
|
|
57
|
+
readonly type: "tuple";
|
|
58
|
+
readonly components: readonly [{
|
|
59
|
+
readonly name: "validUntil";
|
|
60
|
+
readonly type: "uint48";
|
|
61
|
+
}, {
|
|
62
|
+
readonly name: "expectedCEA";
|
|
63
|
+
readonly type: "bytes32";
|
|
64
|
+
}, {
|
|
65
|
+
readonly name: "gatewayProgram";
|
|
66
|
+
readonly type: "bytes32";
|
|
67
|
+
}, {
|
|
68
|
+
readonly name: "assets";
|
|
69
|
+
readonly type: "tuple[]";
|
|
70
|
+
readonly components: readonly [{
|
|
71
|
+
readonly name: "token";
|
|
72
|
+
readonly type: "address";
|
|
73
|
+
}, {
|
|
74
|
+
readonly name: "maxPerCall";
|
|
75
|
+
readonly type: "uint256";
|
|
76
|
+
}, {
|
|
77
|
+
readonly name: "maxTotal";
|
|
78
|
+
readonly type: "uint256";
|
|
79
|
+
}];
|
|
80
|
+
}, {
|
|
81
|
+
readonly name: "maxGasPerCall";
|
|
82
|
+
readonly type: "uint256";
|
|
83
|
+
}, {
|
|
84
|
+
readonly name: "ceaAccounts";
|
|
85
|
+
readonly type: "bytes32[]";
|
|
86
|
+
}, {
|
|
87
|
+
readonly name: "programs";
|
|
88
|
+
readonly type: "tuple[]";
|
|
89
|
+
readonly components: readonly [{
|
|
90
|
+
readonly name: "program";
|
|
91
|
+
readonly type: "bytes32";
|
|
92
|
+
}, {
|
|
93
|
+
readonly name: "discriminator";
|
|
94
|
+
readonly type: "bytes8";
|
|
95
|
+
}, {
|
|
96
|
+
readonly name: "discriminatorLen";
|
|
97
|
+
readonly type: "uint8";
|
|
98
|
+
}, {
|
|
99
|
+
readonly name: "dataless";
|
|
100
|
+
readonly type: "bool";
|
|
101
|
+
}, {
|
|
102
|
+
readonly name: "maxAccounts";
|
|
103
|
+
readonly type: "uint8";
|
|
104
|
+
}];
|
|
105
|
+
}, {
|
|
106
|
+
readonly name: "pins";
|
|
107
|
+
readonly type: "tuple[]";
|
|
108
|
+
readonly components: readonly [{
|
|
109
|
+
readonly name: "ruleIndex";
|
|
110
|
+
readonly type: "uint8";
|
|
111
|
+
}, {
|
|
112
|
+
readonly name: "accountIndex";
|
|
113
|
+
readonly type: "uint8";
|
|
114
|
+
}, {
|
|
115
|
+
readonly name: "expected";
|
|
116
|
+
readonly type: "bytes32";
|
|
117
|
+
}];
|
|
118
|
+
}, {
|
|
119
|
+
readonly name: "dataPins";
|
|
120
|
+
readonly type: "tuple[]";
|
|
121
|
+
readonly components: readonly [{
|
|
122
|
+
readonly name: "ruleIndex";
|
|
123
|
+
readonly type: "uint8";
|
|
124
|
+
}, {
|
|
125
|
+
readonly name: "fromEnd";
|
|
126
|
+
readonly type: "bool";
|
|
127
|
+
}, {
|
|
128
|
+
readonly name: "offset";
|
|
129
|
+
readonly type: "uint16";
|
|
130
|
+
}, {
|
|
131
|
+
readonly name: "offsetB";
|
|
132
|
+
readonly type: "uint16";
|
|
133
|
+
}, {
|
|
134
|
+
readonly name: "len";
|
|
135
|
+
readonly type: "uint8";
|
|
136
|
+
}, {
|
|
137
|
+
readonly name: "mode";
|
|
138
|
+
readonly type: "uint8";
|
|
139
|
+
}, {
|
|
140
|
+
readonly name: "expected";
|
|
141
|
+
readonly type: "bytes32";
|
|
142
|
+
}, {
|
|
143
|
+
readonly name: "num";
|
|
144
|
+
readonly type: "uint64";
|
|
145
|
+
}, {
|
|
146
|
+
readonly name: "den";
|
|
147
|
+
readonly type: "uint64";
|
|
148
|
+
}];
|
|
149
|
+
}];
|
|
150
|
+
};
|
|
151
|
+
export declare function svmInvalid(message: string): AgenticError;
|
|
152
|
+
export declare function exactHex(value: unknown, bytes: number, field: string): asserts value is Hex;
|
|
153
|
+
export declare function isForbiddenSvmProgram(program: Hex, terms: Pick<SvmTermsWire, 'expectedCEA' | 'gatewayProgram'>): boolean;
|
|
154
|
+
/** Grant-time structural rules. Chain/token/mint correctness requires resolved on-chain inputs. */
|
|
155
|
+
export declare function validateSvmTerms(t: SvmTermsWire, nowSeconds: number): void;
|
|
156
|
+
export declare function encodeSvmTerms(terms: SvmTermsWire, nowSeconds: number): Hex;
|
|
157
|
+
export declare function decodeSvmTerms(body: Hex): SvmTermsWire;
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SVM_TERMS_PARAM = exports.FORBIDDEN_SVM_PROGRAMS = exports.UINT64_MAX = exports.SVM_LIMITS = exports.SvmDataPinMode = void 0;
|
|
4
|
+
exports.svmInvalid = svmInvalid;
|
|
5
|
+
exports.exactHex = exactHex;
|
|
6
|
+
exports.isForbiddenSvmProgram = isForbiddenSvmProgram;
|
|
7
|
+
exports.validateSvmTerms = validateSvmTerms;
|
|
8
|
+
exports.encodeSvmTerms = encodeSvmTerms;
|
|
9
|
+
exports.decodeSvmTerms = decodeSvmTerms;
|
|
10
|
+
/** Internal v5 SVM wire representation; not a proposed public Rule API. */
|
|
11
|
+
const viem_1 = require("viem");
|
|
12
|
+
const errors_1 = require("../errors");
|
|
13
|
+
const defaults_1 = require("./defaults");
|
|
14
|
+
var SvmDataPinMode;
|
|
15
|
+
(function (SvmDataPinMode) {
|
|
16
|
+
SvmDataPinMode[SvmDataPinMode["EQ"] = 0] = "EQ";
|
|
17
|
+
SvmDataPinMode[SvmDataPinMode["GTE_LE"] = 1] = "GTE_LE";
|
|
18
|
+
SvmDataPinMode[SvmDataPinMode["LTE_LE"] = 2] = "LTE_LE";
|
|
19
|
+
SvmDataPinMode[SvmDataPinMode["RATIO_GTE_LE"] = 3] = "RATIO_GTE_LE";
|
|
20
|
+
})(SvmDataPinMode || (exports.SvmDataPinMode = SvmDataPinMode = {}));
|
|
21
|
+
exports.SVM_LIMITS = {
|
|
22
|
+
assets: 8,
|
|
23
|
+
programs: 32,
|
|
24
|
+
pins: 16,
|
|
25
|
+
dataPins: 8,
|
|
26
|
+
ceaAccounts: 16,
|
|
27
|
+
accounts: 64,
|
|
28
|
+
ixData: 1024,
|
|
29
|
+
};
|
|
30
|
+
exports.UINT64_MAX = BigInt(2) ** BigInt(64) - BigInt(1);
|
|
31
|
+
exports.FORBIDDEN_SVM_PROGRAMS = [
|
|
32
|
+
`0x${'00'.repeat(32)}`,
|
|
33
|
+
'0x06ddf6e1d765a193d9cbe146ceeb79ac1cb485ed5f5b37913a8cf5857eff00a9',
|
|
34
|
+
'0x06ddf6e1ee758fde18425dbce46ccddab61afc4d83b90d27febdf928d8a18bfc',
|
|
35
|
+
'0x06a1d8179137542a983437bdfe2a7ab2557f535c8a78722b68a49dc000000000',
|
|
36
|
+
'0x02a8f6914e88a1b0e210153ef763ae2b00c2b93d16c124d2c0537a1004800000',
|
|
37
|
+
'0x0277a6af97339b7ac88d1892c90446f50002309266f62e53c118244982000000',
|
|
38
|
+
];
|
|
39
|
+
exports.SVM_TERMS_PARAM = {
|
|
40
|
+
type: 'tuple',
|
|
41
|
+
components: [
|
|
42
|
+
{ name: 'validUntil', type: 'uint48' },
|
|
43
|
+
{ name: 'expectedCEA', type: 'bytes32' },
|
|
44
|
+
{ name: 'gatewayProgram', type: 'bytes32' },
|
|
45
|
+
{
|
|
46
|
+
name: 'assets',
|
|
47
|
+
type: 'tuple[]',
|
|
48
|
+
components: [
|
|
49
|
+
{ name: 'token', type: 'address' },
|
|
50
|
+
{ name: 'maxPerCall', type: 'uint256' },
|
|
51
|
+
{ name: 'maxTotal', type: 'uint256' },
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
{ name: 'maxGasPerCall', type: 'uint256' },
|
|
55
|
+
{ name: 'ceaAccounts', type: 'bytes32[]' },
|
|
56
|
+
{
|
|
57
|
+
name: 'programs',
|
|
58
|
+
type: 'tuple[]',
|
|
59
|
+
components: [
|
|
60
|
+
{ name: 'program', type: 'bytes32' },
|
|
61
|
+
{ name: 'discriminator', type: 'bytes8' },
|
|
62
|
+
{ name: 'discriminatorLen', type: 'uint8' },
|
|
63
|
+
{ name: 'dataless', type: 'bool' },
|
|
64
|
+
{ name: 'maxAccounts', type: 'uint8' },
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: 'pins',
|
|
69
|
+
type: 'tuple[]',
|
|
70
|
+
components: [
|
|
71
|
+
{ name: 'ruleIndex', type: 'uint8' },
|
|
72
|
+
{ name: 'accountIndex', type: 'uint8' },
|
|
73
|
+
{ name: 'expected', type: 'bytes32' },
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: 'dataPins',
|
|
78
|
+
type: 'tuple[]',
|
|
79
|
+
components: [
|
|
80
|
+
{ name: 'ruleIndex', type: 'uint8' },
|
|
81
|
+
{ name: 'fromEnd', type: 'bool' },
|
|
82
|
+
{ name: 'offset', type: 'uint16' },
|
|
83
|
+
{ name: 'offsetB', type: 'uint16' },
|
|
84
|
+
{ name: 'len', type: 'uint8' },
|
|
85
|
+
{ name: 'mode', type: 'uint8' },
|
|
86
|
+
{ name: 'expected', type: 'bytes32' },
|
|
87
|
+
{ name: 'num', type: 'uint64' },
|
|
88
|
+
{ name: 'den', type: 'uint64' },
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
};
|
|
93
|
+
function svmInvalid(message) {
|
|
94
|
+
return new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, message);
|
|
95
|
+
}
|
|
96
|
+
function exactHex(value, bytes, field) {
|
|
97
|
+
if (typeof value !== 'string' ||
|
|
98
|
+
!new RegExp(`^0x[0-9a-fA-F]{${bytes * 2}}$`).test(value))
|
|
99
|
+
throw svmInvalid(`${field} must contain exactly ${bytes} bytes`);
|
|
100
|
+
}
|
|
101
|
+
function integer(value, max, field) {
|
|
102
|
+
if (!Number.isInteger(value) || value < 0 || value > max)
|
|
103
|
+
throw svmInvalid(`${field} is out of range`);
|
|
104
|
+
}
|
|
105
|
+
function uint(value, max, field) {
|
|
106
|
+
if (typeof value !== 'bigint' || value < BigInt(0) || value > max)
|
|
107
|
+
throw svmInvalid(`${field} is out of range`);
|
|
108
|
+
}
|
|
109
|
+
function isForbiddenSvmProgram(program, terms) {
|
|
110
|
+
return [
|
|
111
|
+
...exports.FORBIDDEN_SVM_PROGRAMS,
|
|
112
|
+
terms.gatewayProgram,
|
|
113
|
+
terms.expectedCEA,
|
|
114
|
+
].some((x) => x.toLowerCase() === program.toLowerCase());
|
|
115
|
+
}
|
|
116
|
+
function offsetValid(fromEnd, offset, len) {
|
|
117
|
+
return fromEnd
|
|
118
|
+
? offset >= len && offset <= exports.SVM_LIMITS.ixData
|
|
119
|
+
: offset + len <= exports.SVM_LIMITS.ixData;
|
|
120
|
+
}
|
|
121
|
+
/** Grant-time structural rules. Chain/token/mint correctness requires resolved on-chain inputs. */
|
|
122
|
+
function validateSvmTerms(t, nowSeconds) {
|
|
123
|
+
integer(t.validUntil, 2 ** 48 - 1, 'validUntil');
|
|
124
|
+
if (t.validUntil <= nowSeconds)
|
|
125
|
+
throw svmInvalid('validUntil must be in the future');
|
|
126
|
+
exactHex(t.expectedCEA, 32, 'expectedCEA');
|
|
127
|
+
exactHex(t.gatewayProgram, 32, 'gatewayProgram');
|
|
128
|
+
if (BigInt(t.expectedCEA) === BigInt(0) ||
|
|
129
|
+
BigInt(t.gatewayProgram) === BigInt(0))
|
|
130
|
+
throw svmInvalid('CEA/gateway cannot be zero');
|
|
131
|
+
uint(t.maxGasPerCall, defaults_1.UINT256_MAX, 'maxGasPerCall');
|
|
132
|
+
if (!t.assets.length || t.assets.length > exports.SVM_LIMITS.assets)
|
|
133
|
+
throw svmInvalid('assets must contain 1..8 entries');
|
|
134
|
+
const tokens = new Set();
|
|
135
|
+
for (const a of t.assets) {
|
|
136
|
+
if (!(0, viem_1.isAddress)(a.token, { strict: false }) || BigInt(a.token) === BigInt(0))
|
|
137
|
+
throw svmInvalid('asset token must be a non-zero PRC20');
|
|
138
|
+
if (tokens.has(a.token.toLowerCase()))
|
|
139
|
+
throw svmInvalid('duplicate asset');
|
|
140
|
+
tokens.add(a.token.toLowerCase());
|
|
141
|
+
uint(a.maxPerCall, defaults_1.UINT256_MAX, 'maxPerCall');
|
|
142
|
+
uint(a.maxTotal, defaults_1.UINT256_MAX, 'maxTotal');
|
|
143
|
+
}
|
|
144
|
+
if (!t.programs.length || t.programs.length > exports.SVM_LIMITS.programs)
|
|
145
|
+
throw svmInvalid('programs must contain 1..32 entries');
|
|
146
|
+
t.programs.forEach((r, i) => {
|
|
147
|
+
exactHex(r.program, 32, 'program');
|
|
148
|
+
exactHex(r.discriminator, 8, 'discriminator');
|
|
149
|
+
if (typeof r.dataless !== 'boolean')
|
|
150
|
+
throw svmInvalid('dataless must be boolean');
|
|
151
|
+
integer(r.discriminatorLen, 8, 'discriminatorLen');
|
|
152
|
+
integer(r.maxAccounts, exports.SVM_LIMITS.accounts, 'maxAccounts');
|
|
153
|
+
if (r.dataless !== (r.discriminatorLen === 0))
|
|
154
|
+
throw svmInvalid('dataless and discriminator length disagree');
|
|
155
|
+
if (isForbiddenSvmProgram(r.program, t))
|
|
156
|
+
throw svmInvalid('forbidden program');
|
|
157
|
+
for (const earlier of t.programs.slice(0, i)) {
|
|
158
|
+
if (earlier.program.toLowerCase() !== r.program.toLowerCase())
|
|
159
|
+
continue;
|
|
160
|
+
const overlap = earlier.dataless || r.dataless
|
|
161
|
+
? earlier.dataless && r.dataless
|
|
162
|
+
: earlier.discriminator
|
|
163
|
+
.slice(0, 2 + 2 * Math.min(earlier.discriminatorLen, r.discriminatorLen))
|
|
164
|
+
.toLowerCase() ===
|
|
165
|
+
r.discriminator
|
|
166
|
+
.slice(0, 2 + 2 * Math.min(earlier.discriminatorLen, r.discriminatorLen))
|
|
167
|
+
.toLowerCase();
|
|
168
|
+
if (overlap)
|
|
169
|
+
throw svmInvalid('ambiguous instruction discriminator prefixes');
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
if (t.pins.length > exports.SVM_LIMITS.pins)
|
|
173
|
+
throw svmInvalid('too many account pins');
|
|
174
|
+
const positions = new Set(), covered = new Set();
|
|
175
|
+
for (const p of t.pins) {
|
|
176
|
+
integer(p.ruleIndex, t.programs.length - 1, 'pin ruleIndex');
|
|
177
|
+
integer(p.accountIndex, exports.SVM_LIMITS.accounts - 1, 'accountIndex');
|
|
178
|
+
exactHex(p.expected, 32, 'pin expected');
|
|
179
|
+
const count = t.programs[p.ruleIndex].maxAccounts;
|
|
180
|
+
if (count && p.accountIndex >= count)
|
|
181
|
+
throw svmInvalid('pin outside fixed account count');
|
|
182
|
+
const key = `${p.ruleIndex}:${p.accountIndex}`;
|
|
183
|
+
if (positions.has(key))
|
|
184
|
+
throw svmInvalid('duplicate account pin');
|
|
185
|
+
positions.add(key);
|
|
186
|
+
covered.add(p.ruleIndex);
|
|
187
|
+
}
|
|
188
|
+
if (covered.size !== t.programs.length)
|
|
189
|
+
throw svmInvalid('every program rule needs an account pin');
|
|
190
|
+
if (t.dataPins.length > exports.SVM_LIMITS.dataPins)
|
|
191
|
+
throw svmInvalid('too many data pins');
|
|
192
|
+
for (const p of t.dataPins) {
|
|
193
|
+
integer(p.ruleIndex, t.programs.length - 1, 'data pin ruleIndex');
|
|
194
|
+
integer(p.mode, 3, 'data pin mode');
|
|
195
|
+
integer(p.len, p.mode === SvmDataPinMode.EQ ? 32 : 8, 'data pin len');
|
|
196
|
+
integer(p.offset, 65535, 'offset');
|
|
197
|
+
integer(p.offsetB, 65535, 'offsetB');
|
|
198
|
+
exactHex(p.expected, 32, 'data pin expected');
|
|
199
|
+
uint(p.num, exports.UINT64_MAX, 'num');
|
|
200
|
+
uint(p.den, exports.UINT64_MAX, 'den');
|
|
201
|
+
if (typeof p.fromEnd !== 'boolean' ||
|
|
202
|
+
!p.len ||
|
|
203
|
+
t.programs[p.ruleIndex].dataless ||
|
|
204
|
+
!offsetValid(p.fromEnd, p.offset, p.len))
|
|
205
|
+
throw svmInvalid('invalid data pin shape');
|
|
206
|
+
if (p.mode === SvmDataPinMode.EQ &&
|
|
207
|
+
!/^0*$/.test(p.expected.slice(2 + p.len * 2)))
|
|
208
|
+
throw svmInvalid('EQ expected must be left-aligned');
|
|
209
|
+
if ((p.mode === SvmDataPinMode.GTE_LE || p.mode === SvmDataPinMode.LTE_LE) &&
|
|
210
|
+
BigInt(p.expected) >= BigInt(1) << BigInt(p.len * 8))
|
|
211
|
+
throw svmInvalid('integer expected exceeds field width');
|
|
212
|
+
if (p.mode === SvmDataPinMode.RATIO_GTE_LE &&
|
|
213
|
+
(!p.num || !p.den || !offsetValid(p.fromEnd, p.offsetB, p.len)))
|
|
214
|
+
throw svmInvalid('invalid ratio pin');
|
|
215
|
+
}
|
|
216
|
+
if (t.ceaAccounts.length > exports.SVM_LIMITS.ceaAccounts)
|
|
217
|
+
throw svmInvalid('too many CEA accounts');
|
|
218
|
+
const accounts = new Set();
|
|
219
|
+
for (const key of t.ceaAccounts) {
|
|
220
|
+
exactHex(key, 32, 'CEA account');
|
|
221
|
+
if (BigInt(key) === BigInt(0) ||
|
|
222
|
+
accounts.has(key.toLowerCase()) ||
|
|
223
|
+
t.programs.some((p) => p.program.toLowerCase() === key.toLowerCase()))
|
|
224
|
+
throw svmInvalid('invalid CEA account list');
|
|
225
|
+
accounts.add(key.toLowerCase());
|
|
226
|
+
}
|
|
227
|
+
if (!accounts.has(t.expectedCEA.toLowerCase()))
|
|
228
|
+
throw svmInvalid('CEA account list must include expectedCEA');
|
|
229
|
+
}
|
|
230
|
+
function encodeSvmTerms(terms, nowSeconds) {
|
|
231
|
+
validateSvmTerms(terms, nowSeconds);
|
|
232
|
+
return (0, viem_1.encodeAbiParameters)([exports.SVM_TERMS_PARAM], [terms]);
|
|
233
|
+
}
|
|
234
|
+
function decodeSvmTerms(body) {
|
|
235
|
+
try {
|
|
236
|
+
return (0, viem_1.decodeAbiParameters)([exports.SVM_TERMS_PARAM], body)[0];
|
|
237
|
+
}
|
|
238
|
+
catch (cause) {
|
|
239
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.RULE_READ_FAILED, 'malformed SVM terms', { cause });
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=svm-terms.js.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type Address, type Hex } from 'viem';
|
|
2
|
+
export interface AssetCapWire {
|
|
3
|
+
token: Address;
|
|
4
|
+
maxPerCall: bigint;
|
|
5
|
+
maxTotal: bigint;
|
|
6
|
+
}
|
|
7
|
+
export interface AllowedCallWire {
|
|
8
|
+
target: Address;
|
|
9
|
+
selector: Hex;
|
|
10
|
+
beneficiaryOffset: number;
|
|
11
|
+
hasBeneficiary: boolean;
|
|
12
|
+
maxValue: bigint;
|
|
13
|
+
}
|
|
14
|
+
export interface UniversalTermsWire {
|
|
15
|
+
validUntil: number;
|
|
16
|
+
expectedCEA: Address;
|
|
17
|
+
assets: readonly AssetCapWire[];
|
|
18
|
+
maxGasPerCall: bigint;
|
|
19
|
+
allowedCalls: readonly AllowedCallWire[];
|
|
20
|
+
}
|
|
21
|
+
export declare const UNIVERSAL_TERMS_PARAM: {
|
|
22
|
+
readonly type: "tuple";
|
|
23
|
+
readonly components: readonly [{
|
|
24
|
+
readonly name: "validUntil";
|
|
25
|
+
readonly type: "uint48";
|
|
26
|
+
}, {
|
|
27
|
+
readonly name: "expectedCEA";
|
|
28
|
+
readonly type: "address";
|
|
29
|
+
}, {
|
|
30
|
+
readonly name: "assets";
|
|
31
|
+
readonly type: "tuple[]";
|
|
32
|
+
readonly components: readonly [{
|
|
33
|
+
readonly name: "token";
|
|
34
|
+
readonly type: "address";
|
|
35
|
+
}, {
|
|
36
|
+
readonly name: "maxPerCall";
|
|
37
|
+
readonly type: "uint256";
|
|
38
|
+
}, {
|
|
39
|
+
readonly name: "maxTotal";
|
|
40
|
+
readonly type: "uint256";
|
|
41
|
+
}];
|
|
42
|
+
}, {
|
|
43
|
+
readonly name: "maxGasPerCall";
|
|
44
|
+
readonly type: "uint256";
|
|
45
|
+
}, {
|
|
46
|
+
readonly name: "allowedCalls";
|
|
47
|
+
readonly type: "tuple[]";
|
|
48
|
+
readonly components: readonly [{
|
|
49
|
+
readonly name: "target";
|
|
50
|
+
readonly type: "address";
|
|
51
|
+
}, {
|
|
52
|
+
readonly name: "selector";
|
|
53
|
+
readonly type: "bytes4";
|
|
54
|
+
}, {
|
|
55
|
+
readonly name: "beneficiaryOffset";
|
|
56
|
+
readonly type: "uint16";
|
|
57
|
+
}, {
|
|
58
|
+
readonly name: "hasBeneficiary";
|
|
59
|
+
readonly type: "bool";
|
|
60
|
+
}, {
|
|
61
|
+
readonly name: "maxValue";
|
|
62
|
+
readonly type: "uint256";
|
|
63
|
+
}];
|
|
64
|
+
}];
|
|
65
|
+
};
|
|
66
|
+
export declare function encodeUniversalTerms(terms: UniversalTermsWire): Hex;
|
|
67
|
+
export declare function decodeUniversalTerms(body: Hex): UniversalTermsWire;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UNIVERSAL_TERMS_PARAM = void 0;
|
|
4
|
+
exports.encodeUniversalTerms = encodeUniversalTerms;
|
|
5
|
+
exports.decodeUniversalTerms = decodeUniversalTerms;
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
exports.UNIVERSAL_TERMS_PARAM = {
|
|
8
|
+
type: 'tuple',
|
|
9
|
+
components: [
|
|
10
|
+
{ name: 'validUntil', type: 'uint48' },
|
|
11
|
+
{ name: 'expectedCEA', type: 'address' },
|
|
12
|
+
{
|
|
13
|
+
name: 'assets',
|
|
14
|
+
type: 'tuple[]',
|
|
15
|
+
components: [
|
|
16
|
+
{ name: 'token', type: 'address' },
|
|
17
|
+
{ name: 'maxPerCall', type: 'uint256' },
|
|
18
|
+
{ name: 'maxTotal', type: 'uint256' },
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
{ name: 'maxGasPerCall', type: 'uint256' },
|
|
22
|
+
{
|
|
23
|
+
name: 'allowedCalls',
|
|
24
|
+
type: 'tuple[]',
|
|
25
|
+
components: [
|
|
26
|
+
{ name: 'target', type: 'address' },
|
|
27
|
+
{ name: 'selector', type: 'bytes4' },
|
|
28
|
+
{ name: 'beneficiaryOffset', type: 'uint16' },
|
|
29
|
+
{ name: 'hasBeneficiary', type: 'bool' },
|
|
30
|
+
{ name: 'maxValue', type: 'uint256' },
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
function encodeUniversalTerms(terms) {
|
|
36
|
+
return (0, viem_1.encodeAbiParameters)([exports.UNIVERSAL_TERMS_PARAM], [terms]);
|
|
37
|
+
}
|
|
38
|
+
function decodeUniversalTerms(body) {
|
|
39
|
+
return (0, viem_1.decodeAbiParameters)([exports.UNIVERSAL_TERMS_PARAM], body)[0];
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=universal-terms.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Address } from 'viem';
|
|
2
|
+
import type { UniversalRule } from '../agentic.types';
|
|
3
|
+
import type { RuleEncodeContext, PreparedRule } from './rules';
|
|
4
|
+
import { type AssetCapWire, type UniversalTermsWire } from './universal-terms';
|
|
5
|
+
export declare const MAX_ASSETS = 8;
|
|
6
|
+
export declare const MAX_ALLOWED_CALLS = 32;
|
|
7
|
+
export interface ResolvedUniversalRule {
|
|
8
|
+
expectedCEA: Address;
|
|
9
|
+
assets: readonly AssetCapWire[];
|
|
10
|
+
}
|
|
11
|
+
export declare function validateUniversalRuleShape(rule: UniversalRule, nowSeconds: number): void;
|
|
12
|
+
export declare function encodeUniversalRule(rule: UniversalRule, ctx: RuleEncodeContext): PreparedRule;
|
|
13
|
+
/** Source token addresses must be resolved from each PRC20 before calling this. */
|
|
14
|
+
export declare function universalTermsToRule(terms: UniversalTermsWire, agent: Address, chainNamespace: UniversalRule['chainNamespace'], tokens: readonly Address[]): UniversalRule;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_ALLOWED_CALLS = exports.MAX_ASSETS = void 0;
|
|
4
|
+
exports.validateUniversalRuleShape = validateUniversalRuleShape;
|
|
5
|
+
exports.encodeUniversalRule = encodeUniversalRule;
|
|
6
|
+
exports.universalTermsToRule = universalTermsToRule;
|
|
7
|
+
const viem_1 = require("viem");
|
|
8
|
+
const capabilities_1 = require("../capabilities");
|
|
9
|
+
const errors_1 = require("../errors");
|
|
10
|
+
const abi_layout_1 = require("./abi-layout");
|
|
11
|
+
const selectors_1 = require("./selectors");
|
|
12
|
+
const defaults_1 = require("./defaults");
|
|
13
|
+
const session_1 = require("./session");
|
|
14
|
+
const v5_1 = require("../contracts/v5");
|
|
15
|
+
const universal_terms_1 = require("./universal-terms");
|
|
16
|
+
exports.MAX_ASSETS = 8;
|
|
17
|
+
exports.MAX_ALLOWED_CALLS = 32;
|
|
18
|
+
const CAIP2 = /^(eip155:[0-9]+|solana:[1-9A-HJ-NP-Za-km-z]{32,44})$/;
|
|
19
|
+
const UINT48_MAX = 2 ** 48 - 1;
|
|
20
|
+
function cap(value, what) {
|
|
21
|
+
if (typeof value !== 'bigint' || value < BigInt(0) || value > defaults_1.UINT256_MAX)
|
|
22
|
+
throw invalid(`${what} must be a uint256 bigint`);
|
|
23
|
+
}
|
|
24
|
+
function validateUniversalRuleShape(rule, nowSeconds) {
|
|
25
|
+
if (typeof rule.chainNamespace !== 'string' ||
|
|
26
|
+
!CAIP2.test(rule.chainNamespace))
|
|
27
|
+
throw invalid('chainNamespace must be a CAIP-2 eip155/solana chain');
|
|
28
|
+
if (!Number.isSafeInteger(rule.validUntil) ||
|
|
29
|
+
rule.validUntil <= nowSeconds ||
|
|
30
|
+
rule.validUntil > UINT48_MAX)
|
|
31
|
+
throw invalid('validUntil must be a future uint48 unix timestamp');
|
|
32
|
+
if (!Array.isArray(rule.assets) || rule.assets.length > exports.MAX_ASSETS)
|
|
33
|
+
throw invalid(`assets must be an array of at most ${exports.MAX_ASSETS} caps`);
|
|
34
|
+
cap(rule.maxGasPerCall, 'maxGasPerCall');
|
|
35
|
+
if (rule.maxGasPerCall === BigInt(0))
|
|
36
|
+
throw invalid('maxGasPerCall must be positive');
|
|
37
|
+
if (!Array.isArray(rule.allowedCalls) ||
|
|
38
|
+
rule.allowedCalls.length < 1 ||
|
|
39
|
+
rule.allowedCalls.length > exports.MAX_ALLOWED_CALLS)
|
|
40
|
+
throw invalid(`allowedCalls must contain 1..${exports.MAX_ALLOWED_CALLS} entries`);
|
|
41
|
+
const seen = new Set();
|
|
42
|
+
rule.allowedCalls.forEach((call, i) => {
|
|
43
|
+
if (!(0, viem_1.isAddress)(call.target, { strict: false }))
|
|
44
|
+
throw invalid(`allowedCalls[${i}].target is not an EVM address`);
|
|
45
|
+
const parsed = (0, selectors_1.parseSelector)(call.selector);
|
|
46
|
+
if (parsed.valueOnly)
|
|
47
|
+
throw invalid(`allowedCalls[${i}] cannot be value-only`);
|
|
48
|
+
if (call.beneficiary !== undefined && call.beneficiaryOffset !== undefined)
|
|
49
|
+
throw invalid('beneficiary and beneficiaryOffset are mutually exclusive');
|
|
50
|
+
if (call.beneficiary !== undefined) {
|
|
51
|
+
(0, abi_layout_1.argumentOffset)(parsed.inputs, call.beneficiary, `allowedCalls[${i}].beneficiary`);
|
|
52
|
+
if (parsed.inputs?.[call.beneficiary]?.type !== 'address')
|
|
53
|
+
throw invalid(`allowedCalls[${i}].beneficiary must be an address argument`);
|
|
54
|
+
}
|
|
55
|
+
if (call.beneficiaryOffset !== undefined)
|
|
56
|
+
(0, abi_layout_1.rawOffset)(call.beneficiaryOffset, `allowedCalls[${i}].beneficiary`);
|
|
57
|
+
cap(call.maxValue ?? defaults_1.AGENTIC_DEFAULTS.universal.allowedCallMaxValue.value, `allowedCalls[${i}].maxValue`);
|
|
58
|
+
const key = `${call.target.toLowerCase()}:${parsed.selector}`;
|
|
59
|
+
if (seen.has(key))
|
|
60
|
+
throw invalid(`allowedCalls[${i}] duplicates an earlier target/selector`);
|
|
61
|
+
seen.add(key);
|
|
62
|
+
});
|
|
63
|
+
const tokens = new Set();
|
|
64
|
+
rule.assets.forEach((a, i) => {
|
|
65
|
+
const address = typeof a.token === 'string' ? a.token : a.token?.address;
|
|
66
|
+
if (typeof address !== 'string')
|
|
67
|
+
throw invalid(`assets[${i}].token is missing an address`);
|
|
68
|
+
const key = address.toLowerCase();
|
|
69
|
+
if (tokens.has(key))
|
|
70
|
+
throw invalid(`assets[${i}] duplicates an earlier token`);
|
|
71
|
+
tokens.add(key);
|
|
72
|
+
cap(a.maxPerCall, `assets[${i}].maxPerCall`);
|
|
73
|
+
cap((0, defaults_1.withDefault)(a.maxTotal, defaults_1.AGENTIC_DEFAULTS.universal.assetMaxTotal), `assets[${i}].maxTotal`);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function encodeUniversalRule(rule, ctx) {
|
|
77
|
+
if (rule.chainNamespace.startsWith('solana:'))
|
|
78
|
+
(0, capabilities_1.requireCapability)(ctx.capabilities, capabilities_1.AgenticCapability.UNIVERSAL_SVM_RULES);
|
|
79
|
+
validateUniversalRuleShape(rule, ctx.nowSeconds);
|
|
80
|
+
(0, capabilities_1.requireCapability)(ctx.capabilities, rule.chainNamespace.startsWith('solana:')
|
|
81
|
+
? capabilities_1.AgenticCapability.UNIVERSAL_SVM_RULES
|
|
82
|
+
: capabilities_1.AgenticCapability.UNIVERSAL_EVM_RULES);
|
|
83
|
+
const resolved = ctx.universal?.get(rule);
|
|
84
|
+
if (!resolved || !ctx.gateway)
|
|
85
|
+
throw invalid('universal encoding requires resolved wallet CEA, PRC20 assets and gateway context');
|
|
86
|
+
if (resolved.assets.length < 1 ||
|
|
87
|
+
resolved.assets.length > exports.MAX_ASSETS ||
|
|
88
|
+
new Set(resolved.assets.map((a) => a.token.toLowerCase())).size !==
|
|
89
|
+
resolved.assets.length)
|
|
90
|
+
throw invalid('resolved assets must be 1..8 distinct PRC20s');
|
|
91
|
+
if (!(0, viem_1.isAddress)(resolved.expectedCEA) ||
|
|
92
|
+
/^0x0{40}$/i.test(resolved.expectedCEA))
|
|
93
|
+
throw invalid('expectedCEA must be a non-zero wallet destination account');
|
|
94
|
+
const terms = {
|
|
95
|
+
validUntil: rule.validUntil,
|
|
96
|
+
expectedCEA: (0, viem_1.getAddress)(resolved.expectedCEA),
|
|
97
|
+
assets: resolved.assets,
|
|
98
|
+
maxGasPerCall: rule.maxGasPerCall,
|
|
99
|
+
allowedCalls: rule.allowedCalls.map((call) => ({
|
|
100
|
+
target: (0, viem_1.getAddress)(call.target),
|
|
101
|
+
selector: (0, selectors_1.parseSelector)(call.selector).selector,
|
|
102
|
+
hasBeneficiary: call.beneficiary !== undefined || call.beneficiaryOffset !== undefined,
|
|
103
|
+
beneficiaryOffset: call.beneficiaryOffset ??
|
|
104
|
+
(call.beneficiary === undefined
|
|
105
|
+
? 0
|
|
106
|
+
: (0, abi_layout_1.argumentOffset)((0, selectors_1.parseSelector)(call.selector).inputs, call.beneficiary, 'beneficiary')),
|
|
107
|
+
maxValue: (0, defaults_1.withDefault)(call.maxValue, defaults_1.AGENTIC_DEFAULTS.universal.allowedCallMaxValue),
|
|
108
|
+
})),
|
|
109
|
+
};
|
|
110
|
+
const agent = (0, viem_1.getAddress)(rule.agent);
|
|
111
|
+
return {
|
|
112
|
+
rule,
|
|
113
|
+
agent,
|
|
114
|
+
chainNamespace: rule.chainNamespace,
|
|
115
|
+
universalTerms: terms,
|
|
116
|
+
session: (0, session_1.buildSession)({
|
|
117
|
+
validator: ctx.validator,
|
|
118
|
+
agent,
|
|
119
|
+
rulesPolicy: ctx.rulesPolicy,
|
|
120
|
+
actions: [
|
|
121
|
+
{
|
|
122
|
+
target: ctx.gateway,
|
|
123
|
+
selector: v5_1.SEND_OUTBOUND_SELECTOR,
|
|
124
|
+
initData: (0, session_1.encodeEnvelope)(rule.chainNamespace, (0, universal_terms_1.encodeUniversalTerms)(terms)),
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
}),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/** Source token addresses must be resolved from each PRC20 before calling this. */
|
|
131
|
+
function universalTermsToRule(terms, agent, chainNamespace, tokens) {
|
|
132
|
+
if (tokens.length !== terms.assets.length)
|
|
133
|
+
throw invalid('origin-token list does not match stored asset order');
|
|
134
|
+
return {
|
|
135
|
+
agent,
|
|
136
|
+
chainNamespace,
|
|
137
|
+
validUntil: Number(terms.validUntil),
|
|
138
|
+
maxGasPerCall: terms.maxGasPerCall,
|
|
139
|
+
assets: terms.assets.map((a, i) => ({
|
|
140
|
+
token: tokens[i],
|
|
141
|
+
maxPerCall: a.maxPerCall,
|
|
142
|
+
maxTotal: a.maxTotal,
|
|
143
|
+
})),
|
|
144
|
+
allowedCalls: terms.allowedCalls.map((c) => ({
|
|
145
|
+
target: c.target,
|
|
146
|
+
selector: c.selector,
|
|
147
|
+
maxValue: c.maxValue,
|
|
148
|
+
...(c.hasBeneficiary
|
|
149
|
+
? { beneficiaryOffset: Number(c.beneficiaryOffset) }
|
|
150
|
+
: {}),
|
|
151
|
+
})),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function invalid(message) {
|
|
155
|
+
return new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, message);
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=universal.js.map
|