@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,358 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.adaptAgenticResponse = adaptAgenticResponse;
|
|
4
|
+
exports.adaptTrackedResponse = adaptTrackedResponse;
|
|
5
|
+
exports.outboundResponseCall = outboundResponseCall;
|
|
6
|
+
const snapshot_1 = require("./reads/snapshot");
|
|
7
|
+
const prc20_metadata_1 = require("./contracts/prc20-metadata");
|
|
8
|
+
const svm_payload_1 = require("./execution/svm-payload");
|
|
9
|
+
const svm_accounts_1 = require("./codec/svm-accounts");
|
|
10
|
+
const chain_1 = require("../constants/chain");
|
|
11
|
+
const viem_1 = require("viem");
|
|
12
|
+
const viem_2 = require("viem");
|
|
13
|
+
const chain_2 = require("../constants/chain");
|
|
14
|
+
const helpers_1 = require("../orchestrator/internals/helpers");
|
|
15
|
+
const account_1 = require("../universal/account/account");
|
|
16
|
+
const chain_3 = require("./chain");
|
|
17
|
+
const abi_1 = require("../constants/abi");
|
|
18
|
+
const v5_1 = require("./contracts/v5");
|
|
19
|
+
const deployments_1 = require("./deployments");
|
|
20
|
+
/**
|
|
21
|
+
* Present an AGW send as the wallet's own transaction: `from` is the AGW and
|
|
22
|
+
* `to`/`data`/`value` are the logical call. The signer's `origin`, hashes,
|
|
23
|
+
* nonce, gas and the on-chain `raw` fields are kept untouched; the wrapped
|
|
24
|
+
* call the signer actually sent is recorded in `agentic.rawTo/rawData`.
|
|
25
|
+
* Mutates in place so `wait()` (which reads these fields) reports the same
|
|
26
|
+
* identity on the receipt.
|
|
27
|
+
*/
|
|
28
|
+
function adaptAgenticResponse(resp, meta) {
|
|
29
|
+
const rawTo = resp.to;
|
|
30
|
+
const rawData = resp.data;
|
|
31
|
+
if (!resp.raw) {
|
|
32
|
+
resp.raw = {
|
|
33
|
+
from: resp.from,
|
|
34
|
+
to: resp.to,
|
|
35
|
+
nonce: resp.nonce,
|
|
36
|
+
data: resp.data,
|
|
37
|
+
value: resp.value,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
resp.from = (0, viem_2.getAddress)(meta.wallet);
|
|
41
|
+
resp.to = meta.logical.to;
|
|
42
|
+
resp.data = meta.logical.data;
|
|
43
|
+
resp.value = meta.logical.value;
|
|
44
|
+
if (meta.route)
|
|
45
|
+
resp.route = meta.route;
|
|
46
|
+
if (meta.chain) {
|
|
47
|
+
resp.chain = meta.chain;
|
|
48
|
+
resp.chainNamespace = meta.chain;
|
|
49
|
+
}
|
|
50
|
+
resp.agentic = {
|
|
51
|
+
wallet: (0, viem_2.getAddress)(meta.wallet),
|
|
52
|
+
door: meta.door,
|
|
53
|
+
...(meta.rulesId ? { rulesId: meta.rulesId } : {}),
|
|
54
|
+
...(meta.chainNamespace ? { chainNamespace: meta.chainNamespace } : {}),
|
|
55
|
+
...(meta.destinationAccount
|
|
56
|
+
? { destinationAccount: meta.destinationAccount }
|
|
57
|
+
: {}),
|
|
58
|
+
...(meta.destinationCalls
|
|
59
|
+
? { destinationCalls: meta.destinationCalls.map((call) => ({ ...call })) }
|
|
60
|
+
: {}),
|
|
61
|
+
...(meta.destinationInstruction
|
|
62
|
+
? { destinationInstruction: meta.destinationInstruction }
|
|
63
|
+
: {}),
|
|
64
|
+
...(meta.destinationTransfer
|
|
65
|
+
? { destinationTransfer: { ...meta.destinationTransfer } }
|
|
66
|
+
: {}),
|
|
67
|
+
...(meta.nativeCalls
|
|
68
|
+
? { nativeCalls: meta.nativeCalls.map((call) => ({ ...call })) }
|
|
69
|
+
: {}),
|
|
70
|
+
rawTo,
|
|
71
|
+
rawData,
|
|
72
|
+
};
|
|
73
|
+
return resp;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* trackTransaction replay: if the tracked Push tx called execute/executeAsAgent
|
|
77
|
+
* on a wallet of a registered, verified generation, restore the same logical
|
|
78
|
+
* identity a live send reports. Anything unrecognised is returned unchanged.
|
|
79
|
+
*/
|
|
80
|
+
async function adaptTrackedResponse(runtime, resp) {
|
|
81
|
+
if (resp.agentic || (0, deployments_1.generationsFor)(runtime.network).length === 0)
|
|
82
|
+
return resp;
|
|
83
|
+
const batch = await adaptNativeAgentBatch(runtime, resp);
|
|
84
|
+
if (batch)
|
|
85
|
+
return batch;
|
|
86
|
+
const decoded = v5_1.v5.decodeWalletCall(resp.data);
|
|
87
|
+
if (!decoded ||
|
|
88
|
+
(decoded.kind !== 'execute' && decoded.kind !== 'executeAsAgent'))
|
|
89
|
+
return resp;
|
|
90
|
+
let wallet;
|
|
91
|
+
try {
|
|
92
|
+
wallet = (0, viem_2.getAddress)(resp.to);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return resp;
|
|
96
|
+
}
|
|
97
|
+
let gen;
|
|
98
|
+
try {
|
|
99
|
+
gen = await (0, deployments_1.resolveWalletGeneration)(runtime.reader, runtime.network, wallet);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return resp;
|
|
103
|
+
}
|
|
104
|
+
const door = decoded.kind === 'execute' ? 'owner' : 'agent';
|
|
105
|
+
const rulesId = decoded.kind === 'executeAsAgent'
|
|
106
|
+
? decoded.rulesId
|
|
107
|
+
: undefined;
|
|
108
|
+
const calls = decoded.calls;
|
|
109
|
+
const outbound = calls.find((c) => (0, viem_2.getAddress)(c.target) === gen.addresses.gateway &&
|
|
110
|
+
c.data.toLowerCase().startsWith(v5_1.SEND_OUTBOUND_SELECTOR));
|
|
111
|
+
if (outbound) {
|
|
112
|
+
const out = decodeOutbound(outbound.data);
|
|
113
|
+
const chain = await tokenChain(runtime, out.token);
|
|
114
|
+
if (chain?.startsWith('solana:')) {
|
|
115
|
+
if (door === 'owner' &&
|
|
116
|
+
out.payload === '0x' &&
|
|
117
|
+
out.amount > BigInt(0) &&
|
|
118
|
+
/^0x[0-9a-fA-F]{64}$/.test(out.recipient)) {
|
|
119
|
+
try {
|
|
120
|
+
const gas = await (0, prc20_metadata_1.readGasPrc20)(new snapshot_1.Snapshot(runtime.reader, resp.blockNumber), chain);
|
|
121
|
+
return adaptAgenticResponse(resp, {
|
|
122
|
+
wallet,
|
|
123
|
+
door,
|
|
124
|
+
chainNamespace: chain,
|
|
125
|
+
chain: chain,
|
|
126
|
+
route: 'UOA_TO_CEA',
|
|
127
|
+
destinationTransfer: {
|
|
128
|
+
recipient: out.recipient,
|
|
129
|
+
token: out.token,
|
|
130
|
+
amount: out.amount,
|
|
131
|
+
},
|
|
132
|
+
logical: {
|
|
133
|
+
to: out.recipient,
|
|
134
|
+
data: '0x',
|
|
135
|
+
value: (0, viem_2.getAddress)(gas) === out.token ? out.amount : BigInt(0),
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
// Preserve the actual gateway summary when historical token metadata
|
|
141
|
+
// cannot be read; destination polling below still uses the known chain.
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
const instruction = (0, svm_payload_1.parseAgwSvmPayload)(out.payload);
|
|
146
|
+
const destinationInstruction = {
|
|
147
|
+
program: instruction.program,
|
|
148
|
+
accounts: instruction.accounts.map(({ pubkey, isWritable }) => ({
|
|
149
|
+
pubkey,
|
|
150
|
+
isWritable,
|
|
151
|
+
})),
|
|
152
|
+
data: (0, viem_1.bytesToHex)(instruction.instructionData),
|
|
153
|
+
};
|
|
154
|
+
return adaptAgenticResponse(resp, {
|
|
155
|
+
wallet,
|
|
156
|
+
door,
|
|
157
|
+
rulesId,
|
|
158
|
+
chainNamespace: chain,
|
|
159
|
+
chain: chain,
|
|
160
|
+
route: 'UOA_TO_CEA',
|
|
161
|
+
destinationInstruction,
|
|
162
|
+
destinationAccount: (0, svm_accounts_1.deriveAgwSvmCea)(wallet, chain_1.CHAIN_INFO[chain].lockerContract ?? '').address,
|
|
163
|
+
logical: {
|
|
164
|
+
to: instruction.program,
|
|
165
|
+
data: destinationInstruction.data,
|
|
166
|
+
value: BigInt(0),
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
// Historical owner calls may use another payload format. Preserve the
|
|
172
|
+
// actual gateway call below instead of inventing instruction metadata.
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// The decoded wallet call is authoritative: core may have inferred a
|
|
176
|
+
// Push-only route from an incomplete Cosmos record, which would stop
|
|
177
|
+
// wait() from polling the destination leg.
|
|
178
|
+
return adaptAgenticResponse(resp, {
|
|
179
|
+
wallet,
|
|
180
|
+
door,
|
|
181
|
+
rulesId,
|
|
182
|
+
chainNamespace: chain,
|
|
183
|
+
logical: outboundResponseCall(out.calls, {
|
|
184
|
+
to: outbound.target,
|
|
185
|
+
data: outbound.data,
|
|
186
|
+
value: outbound.value,
|
|
187
|
+
}),
|
|
188
|
+
...(out.calls.length > 0 ? { destinationCalls: out.calls } : {}),
|
|
189
|
+
route: 'UOA_TO_CEA',
|
|
190
|
+
chain: chain ?? resp.chain,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
const single = calls.length === 1 ? calls[0] : undefined;
|
|
194
|
+
return adaptAgenticResponse(resp, {
|
|
195
|
+
wallet,
|
|
196
|
+
door,
|
|
197
|
+
rulesId,
|
|
198
|
+
chainNamespace: undefined,
|
|
199
|
+
logical: single
|
|
200
|
+
? { to: single.target, data: single.data, value: single.value }
|
|
201
|
+
: { to: wallet, data: resp.data, value: BigInt(0) },
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/** Decode only supported sender-account batches, never an arbitrary forwarding helper. */
|
|
205
|
+
async function adaptNativeAgentBatch(runtime, resp) {
|
|
206
|
+
let outer;
|
|
207
|
+
const isUea = resp.data.toLowerCase().startsWith(v5_1.UEA_MULTICALL_PREFIX);
|
|
208
|
+
try {
|
|
209
|
+
if (isUea) {
|
|
210
|
+
const [entries] = (0, viem_2.decodeAbiParameters)([
|
|
211
|
+
{
|
|
212
|
+
type: 'tuple[]',
|
|
213
|
+
components: [
|
|
214
|
+
{ name: 'to', type: 'address' },
|
|
215
|
+
{ name: 'value', type: 'uint256' },
|
|
216
|
+
{ name: 'data', type: 'bytes' },
|
|
217
|
+
],
|
|
218
|
+
},
|
|
219
|
+
], `0x${resp.data.slice(10)}`);
|
|
220
|
+
outer = entries.map((c) => ({
|
|
221
|
+
target: (0, viem_2.getAddress)(c.to),
|
|
222
|
+
value: c.value,
|
|
223
|
+
data: c.data,
|
|
224
|
+
}));
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
const batch = v5_1.v5.decodeWalletCall(resp.data);
|
|
228
|
+
if (batch?.kind !== 'execute' || batch.mode !== `0x01${'00'.repeat(31)}`)
|
|
229
|
+
return;
|
|
230
|
+
outer = batch.calls;
|
|
231
|
+
}
|
|
232
|
+
if (outer.length < 2 ||
|
|
233
|
+
outer.some((c) => c.value !== BigInt(0) || c.target !== outer[0].target))
|
|
234
|
+
return;
|
|
235
|
+
const inner = outer.map((c) => v5_1.v5.decodeWalletCall(c.data));
|
|
236
|
+
const first = inner[0];
|
|
237
|
+
if (first?.kind !== 'executeAsAgent' || first.calls.length !== 1)
|
|
238
|
+
return;
|
|
239
|
+
const nativeCalls = [];
|
|
240
|
+
for (const c of inner) {
|
|
241
|
+
if (c?.kind !== 'executeAsAgent' ||
|
|
242
|
+
c.calls.length !== 1 ||
|
|
243
|
+
c.rulesId !== first.rulesId ||
|
|
244
|
+
c.mode !== `0x${'00'.repeat(32)}`)
|
|
245
|
+
return;
|
|
246
|
+
const call = c.calls[0];
|
|
247
|
+
nativeCalls.push({ to: call.target, value: call.value, data: call.data });
|
|
248
|
+
}
|
|
249
|
+
const senderAccount = (0, viem_2.getAddress)(resp.from);
|
|
250
|
+
if (isUea) {
|
|
251
|
+
if ((0, viem_2.getAddress)(resp.raw?.to ?? resp.to) !== senderAccount)
|
|
252
|
+
return;
|
|
253
|
+
const origin = await (0, account_1.convertExecutorToOrigin)(senderAccount, {
|
|
254
|
+
_internal: true,
|
|
255
|
+
});
|
|
256
|
+
if (!origin.exists)
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
if ((0, viem_2.getAddress)(resp.to) !== senderAccount)
|
|
261
|
+
return;
|
|
262
|
+
const executor = (0, chain_2.getBatchExecutorAddress)((0, helpers_1.getPushChainForNetwork)(runtime.network));
|
|
263
|
+
if (!executor)
|
|
264
|
+
return;
|
|
265
|
+
const code = await runtime.reader.getCode({
|
|
266
|
+
address: senderAccount,
|
|
267
|
+
blockNumber: resp.blockNumber,
|
|
268
|
+
});
|
|
269
|
+
if (code?.toLowerCase() !== `0xef0100${executor.slice(2).toLowerCase()}`)
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const wallet = outer[0].target;
|
|
273
|
+
const gen = await (0, deployments_1.resolveWalletGeneration)(runtime.reader, runtime.network, wallet);
|
|
274
|
+
// This recognizer is only for native arrays; keep mixed/outbound batches raw.
|
|
275
|
+
if (nativeCalls.some((c) => c.to === gen.addresses.gateway))
|
|
276
|
+
return;
|
|
277
|
+
return adaptAgenticResponse(resp, {
|
|
278
|
+
wallet,
|
|
279
|
+
door: 'agent',
|
|
280
|
+
rulesId: first.rulesId,
|
|
281
|
+
chainNamespace: (0, chain_3.pushChainNamespaceFor)(runtime.network),
|
|
282
|
+
nativeCalls,
|
|
283
|
+
logical: { ...nativeCalls[0] },
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
catch {
|
|
287
|
+
// Unsupported payload or unverified sender/wallet: preserve the original response.
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Canonical outbound summary for both send and replay: the first actual
|
|
293
|
+
* destination call. The complete ordered calls live in agentic.destinationCalls.
|
|
294
|
+
* Identical calldata can come from explicit calls or generated transfers, so
|
|
295
|
+
* never infer the original input shape from a selector. For an unrecognized
|
|
296
|
+
* historical payload, retain the actual gateway call instead of inventing one.
|
|
297
|
+
*/
|
|
298
|
+
function outboundResponseCall(calls, fallback) {
|
|
299
|
+
const first = calls[0];
|
|
300
|
+
return first
|
|
301
|
+
? { to: first.to, data: first.data, value: first.value }
|
|
302
|
+
: fallback;
|
|
303
|
+
}
|
|
304
|
+
function decodeOutbound(data) {
|
|
305
|
+
const { args } = (0, viem_2.decodeFunctionData)({ abi: abi_1.UNIVERSAL_GATEWAY_PC, data });
|
|
306
|
+
const req = args?.[0];
|
|
307
|
+
let calls = [];
|
|
308
|
+
if (req.payload.toLowerCase().startsWith(v5_1.UEA_MULTICALL_PREFIX)) {
|
|
309
|
+
try {
|
|
310
|
+
const [decodedCalls] = (0, viem_2.decodeAbiParameters)([
|
|
311
|
+
{
|
|
312
|
+
type: 'tuple[]',
|
|
313
|
+
components: [
|
|
314
|
+
{ name: 'to', type: 'address' },
|
|
315
|
+
{ name: 'value', type: 'uint256' },
|
|
316
|
+
{ name: 'data', type: 'bytes' },
|
|
317
|
+
],
|
|
318
|
+
},
|
|
319
|
+
], `0x${req.payload.slice(10)}`);
|
|
320
|
+
calls = decodedCalls.map((c) => ({
|
|
321
|
+
to: (0, viem_2.getAddress)(c.to),
|
|
322
|
+
value: c.value,
|
|
323
|
+
data: c.data,
|
|
324
|
+
}));
|
|
325
|
+
}
|
|
326
|
+
catch {
|
|
327
|
+
calls = [];
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return {
|
|
331
|
+
token: (0, viem_2.getAddress)(req.token),
|
|
332
|
+
payload: req.payload,
|
|
333
|
+
recipient: req.recipient,
|
|
334
|
+
amount: req.amount,
|
|
335
|
+
calls,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
async function tokenChain(runtime, token) {
|
|
339
|
+
try {
|
|
340
|
+
return (await runtime.reader.readContract({
|
|
341
|
+
address: token,
|
|
342
|
+
abi: [
|
|
343
|
+
{
|
|
344
|
+
type: 'function',
|
|
345
|
+
name: 'SOURCE_CHAIN_NAMESPACE',
|
|
346
|
+
inputs: [],
|
|
347
|
+
outputs: [{ type: 'string' }],
|
|
348
|
+
stateMutability: 'view',
|
|
349
|
+
},
|
|
350
|
+
],
|
|
351
|
+
functionName: 'SOURCE_CHAIN_NAMESPACE',
|
|
352
|
+
}));
|
|
353
|
+
}
|
|
354
|
+
catch {
|
|
355
|
+
return undefined;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
//# sourceMappingURL=response.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Hex } from 'viem';
|
|
2
|
+
import type { DecodedErrorPayload } from '../orchestrator/internals/errors';
|
|
3
|
+
/** URP reverts reached through the engine are truncated to this wrapper. */
|
|
4
|
+
export declare const POLICY_CHECK_REVERTED_SELECTOR = "0xf4270752";
|
|
5
|
+
/** Decode raw revert data against the AGW/URP/factory/engine error ABIs. */
|
|
6
|
+
export declare function decodeAgwErrorData(data: Hex): DecodedErrorPayload | undefined;
|
|
7
|
+
export declare function decodeAgenticRevert(err: unknown): DecodedErrorPayload | undefined;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.POLICY_CHECK_REVERTED_SELECTOR = void 0;
|
|
4
|
+
exports.decodeAgwErrorData = decodeAgwErrorData;
|
|
5
|
+
exports.decodeAgenticRevert = decodeAgenticRevert;
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const utils_1 = require("viem/utils");
|
|
8
|
+
const v5_1 = require("./contracts/abi/v5");
|
|
9
|
+
/** URP reverts reached through the engine are truncated to this wrapper. */
|
|
10
|
+
exports.POLICY_CHECK_REVERTED_SELECTOR = '0xf4270752';
|
|
11
|
+
const ERROR_ABIS = [
|
|
12
|
+
v5_1.AGW_ABI,
|
|
13
|
+
v5_1.UNIVERSAL_RULES_POLICY_ABI,
|
|
14
|
+
v5_1.AGW_FACTORY_ABI,
|
|
15
|
+
v5_1.SMART_SESSION_ABI,
|
|
16
|
+
];
|
|
17
|
+
/** selector → error name across the AGW/URP/factory/engine ABIs. */
|
|
18
|
+
const ERROR_NAMES = new Map(ERROR_ABIS.flatMap((abi) => abi
|
|
19
|
+
.filter((item) => item.type === 'error')
|
|
20
|
+
.map((item) => {
|
|
21
|
+
const err = item;
|
|
22
|
+
return [
|
|
23
|
+
(0, viem_1.toFunctionSelector)((0, utils_1.formatAbiItem)(err)).toLowerCase(),
|
|
24
|
+
err.name,
|
|
25
|
+
];
|
|
26
|
+
})));
|
|
27
|
+
const HEX_DATA = /0x[0-9a-fA-F]{8,}/g;
|
|
28
|
+
const CUSTOM_ERROR_TEXT = /custom error (0x[0-9a-fA-F]{8}):?\s*([0-9a-fA-F]*)/g;
|
|
29
|
+
/** Pull candidate revert data out of an error (viem chains, nested causes, messages). */
|
|
30
|
+
function revertDataCandidates(err, depth = 0) {
|
|
31
|
+
if (!err || depth > 6)
|
|
32
|
+
return [];
|
|
33
|
+
const out = [];
|
|
34
|
+
const e = err;
|
|
35
|
+
if (typeof e.raw === 'string' && /^0x[0-9a-fA-F]{8,}$/.test(e.raw))
|
|
36
|
+
out.push(e.raw);
|
|
37
|
+
if (typeof e.data === 'string' && /^0x[0-9a-fA-F]{8,}$/.test(e.data))
|
|
38
|
+
out.push(e.data);
|
|
39
|
+
if (e.data &&
|
|
40
|
+
typeof e.data === 'object' &&
|
|
41
|
+
typeof e.data.data === 'string') {
|
|
42
|
+
out.push(e.data.data);
|
|
43
|
+
}
|
|
44
|
+
for (const text of [e.message, e.details]) {
|
|
45
|
+
if (typeof text !== 'string')
|
|
46
|
+
continue;
|
|
47
|
+
// viem renders unknown custom errors as "custom error 0x<selector>: <args hex>".
|
|
48
|
+
for (const m of text.matchAll(CUSTOM_ERROR_TEXT))
|
|
49
|
+
out.push(`${m[1]}${m[2] ?? ''}`);
|
|
50
|
+
out.push(...(text.match(HEX_DATA) ?? []));
|
|
51
|
+
}
|
|
52
|
+
out.push(...revertDataCandidates(e.cause, depth + 1));
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
/** Decode raw revert data against the AGW/URP/factory/engine error ABIs. */
|
|
56
|
+
function decodeAgwErrorData(data) {
|
|
57
|
+
const selector = data.slice(0, 10).toLowerCase();
|
|
58
|
+
if (selector === exports.POLICY_CHECK_REVERTED_SELECTOR && data.length >= 10 + 64) {
|
|
59
|
+
// bytes32 = 4-byte policy error selector ‖ 28 bytes of its first argument.
|
|
60
|
+
// The arguments are truncated, so the inner error is named by selector only.
|
|
61
|
+
const word = `0x${data.slice(10, 74)}`;
|
|
62
|
+
const innerName = ERROR_NAMES.get(word.slice(0, 10).toLowerCase());
|
|
63
|
+
return {
|
|
64
|
+
name: innerName
|
|
65
|
+
? `PolicyCheckReverted(${innerName})`
|
|
66
|
+
: 'PolicyCheckReverted',
|
|
67
|
+
selector,
|
|
68
|
+
decoded: word,
|
|
69
|
+
hint: 'URP rejected the action (truncated through the session engine). The inner selector names the gate; arguments are truncated to 28 bytes.',
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
for (const abi of ERROR_ABIS) {
|
|
73
|
+
try {
|
|
74
|
+
const r = (0, viem_1.decodeErrorResult)({ abi, data });
|
|
75
|
+
return {
|
|
76
|
+
name: r.errorName,
|
|
77
|
+
selector,
|
|
78
|
+
decoded: r.args && r.args.length ? stringifyArgs(r.args) : undefined,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// try the next ABI
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// Arguments lost (e.g. a node rendered them as text): name the error by its selector.
|
|
86
|
+
const name = ERROR_NAMES.get(selector);
|
|
87
|
+
return name
|
|
88
|
+
? { name, selector, hint: 'Error arguments were not available.' }
|
|
89
|
+
: undefined;
|
|
90
|
+
}
|
|
91
|
+
function decodeAgenticRevert(err) {
|
|
92
|
+
for (const data of revertDataCandidates(err)) {
|
|
93
|
+
const decoded = decodeAgwErrorData(data);
|
|
94
|
+
if (decoded)
|
|
95
|
+
return decoded;
|
|
96
|
+
}
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
function stringifyArgs(args) {
|
|
100
|
+
return JSON.stringify(args, (_k, v) => typeof v === 'bigint' ? v.toString() : v);
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=revert.js.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type Address } from 'viem';
|
|
2
|
+
import { CHAIN, PUSH_NETWORK } from '../constants/enums';
|
|
3
|
+
import type { MoveableToken } from '../constants/tokens';
|
|
4
|
+
import type { Orchestrator } from '../orchestrator/orchestrator';
|
|
5
|
+
import type { ExecuteParams, TransactionExecutionOptions, UniversalExecuteParams, UniversalTxResponse } from '../orchestrator/orchestrator.types';
|
|
6
|
+
import type { ProgressEvent } from '../progress-hook/progress-hook.types';
|
|
7
|
+
import { type ChainReader } from './contracts/reader';
|
|
8
|
+
import type { SvmMetadataProvider } from './management/svm-context';
|
|
9
|
+
import type { AgenticProgressHook } from './agentic.types';
|
|
10
|
+
/**
|
|
11
|
+
* Everything the AGW module needs from the surrounding client. Tests supply a
|
|
12
|
+
* mock; PushChain builds the real one from its orchestrator. Keeping this
|
|
13
|
+
* explicit is what separates the signer's identity (gas, account status,
|
|
14
|
+
* ownership derivation) from the AGW execution account.
|
|
15
|
+
*/
|
|
16
|
+
export interface AgenticRuntime {
|
|
17
|
+
readonly network: PUSH_NETWORK;
|
|
18
|
+
/** 'eip155:<id>' of the connected Push chain — the native rule chain. */
|
|
19
|
+
readonly pushChainNamespace: string;
|
|
20
|
+
readonly reader: ChainReader;
|
|
21
|
+
readonly isReadOnly: boolean;
|
|
22
|
+
readonly svmMetadata?: SvmMetadataProvider;
|
|
23
|
+
/** Connected signer's Push identity: its EOA, or its UEA for its actual origin chain. */
|
|
24
|
+
signerPushAccount(): Address;
|
|
25
|
+
/** Connected signer's origin account (universal.origin). */
|
|
26
|
+
signerOrigin(): {
|
|
27
|
+
chain: CHAIN;
|
|
28
|
+
address: string;
|
|
29
|
+
};
|
|
30
|
+
signerIsPushNative(): boolean;
|
|
31
|
+
/** The signer's ordinary transaction path (orchestrator.execute). */
|
|
32
|
+
execute(params: ExecuteParams | UniversalExecuteParams, options?: TransactionExecutionOptions): Promise<UniversalTxResponse>;
|
|
33
|
+
/** Sender-preserving UEA/7702 transport; native sequential fallback is forbidden. */
|
|
34
|
+
executeAtomicBatch(params: ExecuteParams, options?: TransactionExecutionOptions): Promise<UniversalTxResponse>;
|
|
35
|
+
/** Emit to the init-time hook and, if different, the per-call hook. */
|
|
36
|
+
emit(event: ProgressEvent, perCallHook?: AgenticProgressHook): void;
|
|
37
|
+
/** Whether the signer's own UEA is deployed (always true for a Push EOA). */
|
|
38
|
+
signerAccountDeployed(): Promise<boolean>;
|
|
39
|
+
signerBalance(): Promise<bigint>;
|
|
40
|
+
getGasPrice(): Promise<bigint>;
|
|
41
|
+
quoteOutbound(prc20: Address, gasLimit: bigint, chain: CHAIN, svm?: {
|
|
42
|
+
wallet: Address;
|
|
43
|
+
splMintBase58?: string;
|
|
44
|
+
burnAmount: bigint;
|
|
45
|
+
}): Promise<{
|
|
46
|
+
protocolFee: bigint;
|
|
47
|
+
nativeValueForGas: bigint;
|
|
48
|
+
gasLimitUsed: bigint;
|
|
49
|
+
}>;
|
|
50
|
+
resolveCEA(account: Address, chain: CHAIN): Promise<{
|
|
51
|
+
cea: Address;
|
|
52
|
+
isDeployed: boolean;
|
|
53
|
+
}>;
|
|
54
|
+
resolvePrc20(token: MoveableToken | string | undefined, chain: CHAIN): Address;
|
|
55
|
+
nowSeconds(): number;
|
|
56
|
+
}
|
|
57
|
+
/** Build the runtime over an orchestrator (the orchestrator IS the internal ctx). */
|
|
58
|
+
export declare function createAgenticRuntime(orchestrator: Orchestrator, isReadOnly: boolean): AgenticRuntime;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAgenticRuntime = createAgenticRuntime;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const enums_1 = require("../constants/enums");
|
|
6
|
+
const errors_1 = require("../orchestrator/internals/errors");
|
|
7
|
+
const errors_2 = require("./errors");
|
|
8
|
+
const cea_utils_1 = require("../orchestrator/cea-utils");
|
|
9
|
+
const uea_manager_1 = require("../orchestrator/internals/uea-manager");
|
|
10
|
+
const svm_rent_1 = require("../orchestrator/internals/svm-rent");
|
|
11
|
+
const gas_calculator_1 = require("../orchestrator/internals/gas-calculator");
|
|
12
|
+
const helpers_1 = require("../orchestrator/internals/helpers");
|
|
13
|
+
const chain_1 = require("./chain");
|
|
14
|
+
const prc20_address_1 = require("../universal/prc20-address");
|
|
15
|
+
const reader_1 = require("./contracts/reader");
|
|
16
|
+
const svm_metadata_1 = require("./management/svm-metadata");
|
|
17
|
+
const chain_2 = require("../constants/chain");
|
|
18
|
+
/** Build the runtime over an orchestrator (the orchestrator IS the internal ctx). */
|
|
19
|
+
function createAgenticRuntime(orchestrator, isReadOnly) {
|
|
20
|
+
const ctx = orchestrator;
|
|
21
|
+
const network = orchestrator.getNetwork();
|
|
22
|
+
return {
|
|
23
|
+
network,
|
|
24
|
+
pushChainNamespace: (0, chain_1.pushChainNamespaceFor)(network),
|
|
25
|
+
get reader() {
|
|
26
|
+
return (0, reader_1.chainReaderFromPublicClient)(ctx.pushClient.publicClient);
|
|
27
|
+
},
|
|
28
|
+
isReadOnly,
|
|
29
|
+
svmMetadata: (0, svm_metadata_1.createSvmMetadataProvider)({
|
|
30
|
+
[enums_1.CHAIN.SOLANA_DEVNET]: {
|
|
31
|
+
gatewayProgram: chain_2.CHAIN_INFO[enums_1.CHAIN.SOLANA_DEVNET].lockerContract ?? '',
|
|
32
|
+
rpcUrls: orchestrator.getRpcUrls()[enums_1.CHAIN.SOLANA_DEVNET] ??
|
|
33
|
+
chain_2.CHAIN_INFO[enums_1.CHAIN.SOLANA_DEVNET].defaultRPC,
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
signerPushAccount: () => (0, viem_1.getAddress)((0, uea_manager_1.computeUEAOffchain)(ctx)),
|
|
37
|
+
signerOrigin: () => orchestrator.getUOA(),
|
|
38
|
+
signerIsPushNative: () => (0, helpers_1.isPushChain)(ctx.universalSigner.account.chain),
|
|
39
|
+
execute: (params, options) => orchestrator.execute(params, options),
|
|
40
|
+
executeAtomicBatch: async (params, options) => {
|
|
41
|
+
try {
|
|
42
|
+
return await orchestrator.executeAtomicBatch(params, options);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (error instanceof errors_1.AtomicBatchUnavailableError) {
|
|
46
|
+
throw (0, errors_2.capabilityUnavailable)('atomicNativeAgentBatch', error.message);
|
|
47
|
+
}
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
emit: (event, perCallHook) => {
|
|
52
|
+
const base = orchestrator.getProgressHook();
|
|
53
|
+
base?.(event);
|
|
54
|
+
if (perCallHook && perCallHook !== base)
|
|
55
|
+
perCallHook(event);
|
|
56
|
+
},
|
|
57
|
+
signerAccountDeployed: async () => {
|
|
58
|
+
if ((0, helpers_1.isPushChain)(ctx.universalSigner.account.chain))
|
|
59
|
+
return true;
|
|
60
|
+
const status = await orchestrator.getAccountStatus();
|
|
61
|
+
return status.uea.deployed;
|
|
62
|
+
},
|
|
63
|
+
signerBalance: () => ctx.pushClient.getBalance((0, uea_manager_1.computeUEAOffchain)(ctx)),
|
|
64
|
+
getGasPrice: () => ctx.pushClient.getGasPrice(),
|
|
65
|
+
quoteOutbound: async (prc20, gasLimit, chain, svm) => {
|
|
66
|
+
let q = await (0, gas_calculator_1.queryOutboundGasFee)(ctx, prc20, gasLimit, chain);
|
|
67
|
+
if (svm) {
|
|
68
|
+
q = await (0, svm_rent_1.ensureSvmFinalizeGasBudgetQuote)({
|
|
69
|
+
ctx,
|
|
70
|
+
ueaAddress: svm.wallet,
|
|
71
|
+
targetChain: chain,
|
|
72
|
+
prc20Token: prc20,
|
|
73
|
+
quote: q,
|
|
74
|
+
splMintBase58: svm.splMintBase58,
|
|
75
|
+
burnAmount: svm.burnAmount,
|
|
76
|
+
pathTag: 'AGW_SVM',
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
protocolFee: q.protocolFee,
|
|
81
|
+
nativeValueForGas: q.nativeValueForGas,
|
|
82
|
+
gasLimitUsed: q.gasLimitUsed,
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
resolveCEA: async (account, chain) => {
|
|
86
|
+
const r = await (0, cea_utils_1.getCEAAddress)(account, chain, orchestrator.getRpcUrls()[chain]?.[0]);
|
|
87
|
+
return { cea: (0, viem_1.getAddress)(r.cea), isDeployed: r.isDeployed };
|
|
88
|
+
},
|
|
89
|
+
resolvePrc20: (token, chain) => (0, viem_1.getAddress)(token
|
|
90
|
+
? (0, prc20_address_1.getPRC20Address)(typeof token === 'string' ? { chain, address: token } : token, { network }).address
|
|
91
|
+
: (0, helpers_1.getNativePRC20ForChain)(chain, network)),
|
|
92
|
+
nowSeconds: () => Math.floor(Date.now() / 1000),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type Address, type Hex } from 'viem';
|
|
2
|
+
import { PUSH_NETWORK } from '../constants/enums';
|
|
3
|
+
import type { AgenticHex, InternalRule, Selector, DecodedSolanaRule } from './agentic.types';
|
|
4
|
+
import type { UniversalRule } from './agentic.types';
|
|
5
|
+
import type { ResolvedUniversalRule } from './codec/universal';
|
|
6
|
+
/**
|
|
7
|
+
* Internal generation context. Harsh H4.1 (October 4): deployment inputs
|
|
8
|
+
* are implementation details, not public helper parameters.
|
|
9
|
+
*/
|
|
10
|
+
export interface RulesEncodeContext {
|
|
11
|
+
/** Connected Push network, or an explicit 'eip155:<id>' native chain. */
|
|
12
|
+
network?: PUSH_NETWORK;
|
|
13
|
+
pushChainNamespace?: string;
|
|
14
|
+
validator: Address;
|
|
15
|
+
rulesPolicy: Address;
|
|
16
|
+
gateway?: Address;
|
|
17
|
+
universal?: ReadonlyMap<UniversalRule, ResolvedUniversalRule>;
|
|
18
|
+
/** Wallet owner, for the AGENT_IS_OWNER check. */
|
|
19
|
+
owner?: Address;
|
|
20
|
+
/** Defaults to the current time. */
|
|
21
|
+
nowSeconds?: number;
|
|
22
|
+
}
|
|
23
|
+
/** Internal codecs and identities — not exported from the package entry point. */
|
|
24
|
+
export declare const internalAgenticUtils: {
|
|
25
|
+
/** The ID a grant with this grantNonce produces. Chain is not part of the hash. */
|
|
26
|
+
rulesId(agent: Address, grantNonce: bigint | number, ctx: {
|
|
27
|
+
validator: Address;
|
|
28
|
+
}): AgenticHex;
|
|
29
|
+
/** Hash of one allowed call: keccak256(target ‖ selector). */
|
|
30
|
+
actionId(target: Address, selector: Selector | "value-only"): AgenticHex;
|
|
31
|
+
/** Key of one allowed call's stored config under one rule on one wallet. */
|
|
32
|
+
configId(wallet: Address, rulesId: Hex, actionId: Hex): AgenticHex;
|
|
33
|
+
/** Any-owner wallet address. */
|
|
34
|
+
deriveWallet(owner: Address, index: bigint | number, ctx: {
|
|
35
|
+
factory: Address;
|
|
36
|
+
walletImplementation: Address;
|
|
37
|
+
}): Address;
|
|
38
|
+
/**
|
|
39
|
+
* Encode rules into the grant `Session` bytes, one per rule, in order.
|
|
40
|
+
* EVM universal rules require wallet/token resolution in the internal context.
|
|
41
|
+
*/
|
|
42
|
+
encodeRules(rules: readonly InternalRule[], ctx: RulesEncodeContext): AgenticHex[];
|
|
43
|
+
/** Inverse of encodeRules for one Session encoding. */
|
|
44
|
+
decodeRules(bytes: Hex, ctx?: {
|
|
45
|
+
network?: PUSH_NETWORK;
|
|
46
|
+
pushChainNamespace?: string;
|
|
47
|
+
}): InternalRule | DecodedSolanaRule;
|
|
48
|
+
};
|
|
49
|
+
/** Public helpers requiring no contract deployment context. */
|
|
50
|
+
export declare const agenticUtils: {
|
|
51
|
+
actionId: (target: Address, selector: Selector | "value-only") => AgenticHex;
|
|
52
|
+
configId: (wallet: Address, rulesId: Hex, actionId: Hex) => AgenticHex;
|
|
53
|
+
decodeRules: (bytes: Hex, ctx?: {
|
|
54
|
+
network?: PUSH_NETWORK;
|
|
55
|
+
pushChainNamespace?: string;
|
|
56
|
+
}) => InternalRule | DecodedSolanaRule;
|
|
57
|
+
};
|