@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,24 @@
|
|
|
1
|
+
import type { CHAIN } from '../../constants/enums';
|
|
2
|
+
import type { SvmTermsWire } from '../codec/svm-terms';
|
|
3
|
+
import { type SvmPayloadAccount } from './svm-payload';
|
|
4
|
+
import type { Address } from 'viem';
|
|
5
|
+
/** Resolve IDL accounts with the wallet authority; granted permissions are checked by URP. */
|
|
6
|
+
export declare function resolveAgwSvmInstruction(input: {
|
|
7
|
+
wallet: Address;
|
|
8
|
+
chain: CHAIN;
|
|
9
|
+
program: string;
|
|
10
|
+
instructionData: Uint8Array;
|
|
11
|
+
accounts?: readonly SvmPayloadAccount[];
|
|
12
|
+
}, terms: SvmTermsWire): {
|
|
13
|
+
recipient: `0x${string}`;
|
|
14
|
+
payload: `0x${string}`;
|
|
15
|
+
accounts: SvmPayloadAccount[];
|
|
16
|
+
instructionData: Uint8Array;
|
|
17
|
+
};
|
|
18
|
+
/** Diagnostic-only local policy preview. Sends use the resolver and contract enforcement. */
|
|
19
|
+
export declare function prepareAgwSvmInstruction(input: Parameters<typeof resolveAgwSvmInstruction>[0], terms: SvmTermsWire): {
|
|
20
|
+
recipient: `0x${string}`;
|
|
21
|
+
payload: `0x${string}`;
|
|
22
|
+
accounts: SvmPayloadAccount[];
|
|
23
|
+
instructionData: Uint8Array;
|
|
24
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveAgwSvmInstruction = resolveAgwSvmInstruction;
|
|
4
|
+
exports.prepareAgwSvmInstruction = prepareAgwSvmInstruction;
|
|
5
|
+
const resolve_1 = require("../../orchestrator/svm-idl/resolve");
|
|
6
|
+
const svm_accounts_1 = require("../codec/svm-accounts");
|
|
7
|
+
const svm_payload_1 = require("./svm-payload");
|
|
8
|
+
/** Resolve IDL accounts with the wallet authority; granted permissions are checked by URP. */
|
|
9
|
+
function resolveAgwSvmInstruction(input, terms) {
|
|
10
|
+
const program = (0, svm_accounts_1.svmKey)(input.program);
|
|
11
|
+
if (input.accounts) {
|
|
12
|
+
const payload = (0, svm_payload_1.encodeAgwSvmPayload)(program, input.accounts, input.instructionData);
|
|
13
|
+
return {
|
|
14
|
+
recipient: program,
|
|
15
|
+
payload,
|
|
16
|
+
accounts: [...input.accounts],
|
|
17
|
+
instructionData: input.instructionData,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const resolved = (0, resolve_1.resolveSvmCallForCea)({
|
|
21
|
+
programAddress: program,
|
|
22
|
+
data: input.instructionData,
|
|
23
|
+
senderUea: input.wallet,
|
|
24
|
+
targetChain: input.chain,
|
|
25
|
+
}, terms.expectedCEA);
|
|
26
|
+
const payload = (0, svm_payload_1.encodeAgwSvmPayload)(resolved.targetProgram, resolved.accounts, resolved.ixData);
|
|
27
|
+
return {
|
|
28
|
+
recipient: program,
|
|
29
|
+
payload,
|
|
30
|
+
accounts: resolved.accounts,
|
|
31
|
+
instructionData: resolved.ixData,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** Diagnostic-only local policy preview. Sends use the resolver and contract enforcement. */
|
|
35
|
+
function prepareAgwSvmInstruction(input, terms) {
|
|
36
|
+
const resolved = resolveAgwSvmInstruction(input, terms);
|
|
37
|
+
(0, svm_payload_1.validateAgwSvmPayload)(terms, resolved.recipient, resolved.payload);
|
|
38
|
+
return resolved;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=svm-instruction.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Outbound encoding plus a diagnostic-only policy preview. */
|
|
2
|
+
import { type Address, type Hex } from 'viem';
|
|
3
|
+
import type { Call, SvmConfigRead } from '../contracts/v5';
|
|
4
|
+
export interface SvmOutboundInput {
|
|
5
|
+
wallet: Address;
|
|
6
|
+
gateway: Address;
|
|
7
|
+
token: Address;
|
|
8
|
+
amount: bigint;
|
|
9
|
+
recipient: Hex;
|
|
10
|
+
payload: Hex;
|
|
11
|
+
gasLimit: bigint;
|
|
12
|
+
protocolFee: bigint;
|
|
13
|
+
maxPCForGas: bigint;
|
|
14
|
+
}
|
|
15
|
+
/** Diagnostic-only local preview; production sends use buildAgwSvmAction. */
|
|
16
|
+
export declare function composeAgwSvmAction(input: SvmOutboundInput, config: SvmConfigRead, nowSeconds: number): Call;
|
|
17
|
+
/** Encode an outbound without evaluating the granted policy; the wallet/URP enforces it. */
|
|
18
|
+
export declare function buildAgwSvmAction(input: SvmOutboundInput): Call;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.composeAgwSvmAction = composeAgwSvmAction;
|
|
4
|
+
exports.buildAgwSvmAction = buildAgwSvmAction;
|
|
5
|
+
/** Outbound encoding plus a diagnostic-only policy preview. */
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const abi_1 = require("../../constants/abi");
|
|
8
|
+
const errors_1 = require("../errors");
|
|
9
|
+
const defaults_1 = require("../codec/defaults");
|
|
10
|
+
const svm_terms_1 = require("../codec/svm-terms");
|
|
11
|
+
const svm_payload_1 = require("./svm-payload");
|
|
12
|
+
/** Diagnostic-only local preview; production sends use buildAgwSvmAction. */
|
|
13
|
+
function composeAgwSvmAction(input, config, nowSeconds) {
|
|
14
|
+
function fail(name) {
|
|
15
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, name, {
|
|
16
|
+
details: { contractError: name },
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
if (!config.initialized)
|
|
20
|
+
fail('NotInitialized');
|
|
21
|
+
if (nowSeconds > config.validUntil)
|
|
22
|
+
fail('RulesExpired');
|
|
23
|
+
for (const [name, value] of Object.entries({
|
|
24
|
+
amount: input.amount,
|
|
25
|
+
gasLimit: input.gasLimit,
|
|
26
|
+
protocolFee: input.protocolFee,
|
|
27
|
+
maxPCForGas: input.maxPCForGas,
|
|
28
|
+
})) {
|
|
29
|
+
if (typeof value !== 'bigint' || value < BigInt(0) || value > defaults_1.UINT256_MAX)
|
|
30
|
+
fail(`${name}OutOfRange`);
|
|
31
|
+
}
|
|
32
|
+
const token = (0, viem_1.getAddress)(input.token), cap = config.assets.find((a) => (0, viem_1.getAddress)(a.token) === token);
|
|
33
|
+
if (!cap)
|
|
34
|
+
fail('AssetNotAllowed');
|
|
35
|
+
if (input.amount > svm_terms_1.UINT64_MAX)
|
|
36
|
+
fail('AmountExceedsU64');
|
|
37
|
+
if (input.amount > cap.maxPerCall)
|
|
38
|
+
fail('AmountExceedsCap');
|
|
39
|
+
if (cap.spent + input.amount > cap.maxTotal)
|
|
40
|
+
fail('TotalSpendCapExceeded');
|
|
41
|
+
const value = input.protocolFee + input.maxPCForGas;
|
|
42
|
+
if (value > defaults_1.UINT256_MAX || value > config.maxGasPerCall)
|
|
43
|
+
fail('PCValueExceedsCap');
|
|
44
|
+
if (!input.maxPCForGas)
|
|
45
|
+
fail('UncappedGasSwapRejected');
|
|
46
|
+
(0, svm_payload_1.validateAgwSvmPayload)(config, input.recipient, input.payload);
|
|
47
|
+
return buildAgwSvmAction(input);
|
|
48
|
+
}
|
|
49
|
+
/** Encode an outbound without evaluating the granted policy; the wallet/URP enforces it. */
|
|
50
|
+
function buildAgwSvmAction(input) {
|
|
51
|
+
for (const [name, value] of Object.entries({
|
|
52
|
+
amount: input.amount,
|
|
53
|
+
gasLimit: input.gasLimit,
|
|
54
|
+
protocolFee: input.protocolFee,
|
|
55
|
+
maxPCForGas: input.maxPCForGas,
|
|
56
|
+
})) {
|
|
57
|
+
if (typeof value !== 'bigint' || value < BigInt(0) || value > defaults_1.UINT256_MAX)
|
|
58
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, `${name} must fit uint256`);
|
|
59
|
+
}
|
|
60
|
+
if (input.amount > svm_terms_1.UINT64_MAX)
|
|
61
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'Solana amount must fit uint64');
|
|
62
|
+
const value = input.protocolFee + input.maxPCForGas;
|
|
63
|
+
if (value > defaults_1.UINT256_MAX || input.maxPCForGas === BigInt(0))
|
|
64
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'invalid outbound gas quote');
|
|
65
|
+
const token = (0, viem_1.getAddress)(input.token);
|
|
66
|
+
const request = {
|
|
67
|
+
recipient: input.recipient,
|
|
68
|
+
token,
|
|
69
|
+
amount: input.amount,
|
|
70
|
+
gasLimit: input.gasLimit,
|
|
71
|
+
gasPrice: BigInt(0),
|
|
72
|
+
maxPCForGas: input.maxPCForGas,
|
|
73
|
+
payload: input.payload,
|
|
74
|
+
revertRecipient: (0, viem_1.getAddress)(input.wallet),
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
target: (0, viem_1.getAddress)(input.gateway),
|
|
78
|
+
value,
|
|
79
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
80
|
+
abi: abi_1.UNIVERSAL_GATEWAY_PC,
|
|
81
|
+
functionName: 'sendUniversalTxOutbound',
|
|
82
|
+
args: [request],
|
|
83
|
+
}),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=svm-outbound.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Parser/validator for the deployed S12–S18 instruction grammar. */
|
|
2
|
+
import { type Hex } from 'viem';
|
|
3
|
+
import { type SvmTermsWire } from '../codec/svm-terms';
|
|
4
|
+
export interface SvmPayloadAccount {
|
|
5
|
+
pubkey: Hex;
|
|
6
|
+
isWritable: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface ParsedSvmPayload {
|
|
9
|
+
program: Hex;
|
|
10
|
+
accounts: (SvmPayloadAccount & {
|
|
11
|
+
writableFlag: number;
|
|
12
|
+
})[];
|
|
13
|
+
instructionData: Uint8Array;
|
|
14
|
+
}
|
|
15
|
+
export declare function parseAgwSvmPayload(payload: Hex): ParsedSvmPayload;
|
|
16
|
+
export declare function encodeAgwSvmPayload(program: Hex, accounts: readonly SvmPayloadAccount[], instructionData: Uint8Array): Hex;
|
|
17
|
+
/** Terms must have passed grant-shape validation. On-chain URP remains the enforcement authority. */
|
|
18
|
+
export declare function validateAgwSvmPayload(terms: SvmTermsWire, recipient: Hex, payload: Hex): number;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseAgwSvmPayload = parseAgwSvmPayload;
|
|
4
|
+
exports.encodeAgwSvmPayload = encodeAgwSvmPayload;
|
|
5
|
+
exports.validateAgwSvmPayload = validateAgwSvmPayload;
|
|
6
|
+
/** Parser/validator for the deployed S12–S18 instruction grammar. */
|
|
7
|
+
const viem_1 = require("viem");
|
|
8
|
+
const payload_builders_1 = require("../../orchestrator/payload-builders");
|
|
9
|
+
const errors_1 = require("../errors");
|
|
10
|
+
const svm_terms_1 = require("../codec/svm-terms");
|
|
11
|
+
function fail(name) {
|
|
12
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, name, {
|
|
13
|
+
details: { contractError: name },
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function parseAgwSvmPayload(payload) {
|
|
17
|
+
if (!/^0x(?:[0-9a-fA-F]{2})*$/.test(payload))
|
|
18
|
+
fail('MalformedSvmPayload');
|
|
19
|
+
const bytes = (0, viem_1.hexToBytes)(payload);
|
|
20
|
+
if (!bytes.length)
|
|
21
|
+
fail('SvmPayloadEmpty');
|
|
22
|
+
if (bytes.length < 41)
|
|
23
|
+
fail('MalformedSvmPayload');
|
|
24
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength), count = view.getUint32(0, false);
|
|
25
|
+
if (count > svm_terms_1.SVM_LIMITS.accounts)
|
|
26
|
+
fail('SvmAccountsOutOfRange');
|
|
27
|
+
const lenOffset = 4 + count * 33;
|
|
28
|
+
if (bytes.length < lenOffset + 4)
|
|
29
|
+
fail('MalformedSvmPayload');
|
|
30
|
+
const length = view.getUint32(lenOffset, false);
|
|
31
|
+
if (length > svm_terms_1.SVM_LIMITS.ixData)
|
|
32
|
+
fail('SvmIxDataTooLong');
|
|
33
|
+
const dataOffset = lenOffset + 4;
|
|
34
|
+
if (bytes.length !== dataOffset + length + 33)
|
|
35
|
+
fail('MalformedSvmPayload');
|
|
36
|
+
if (bytes[dataOffset + length] !== 2)
|
|
37
|
+
fail('SvmInstructionNotExecute');
|
|
38
|
+
const accounts = Array.from({ length: count }, (_, i) => {
|
|
39
|
+
const offset = 4 + i * 33, writableFlag = bytes[offset + 32];
|
|
40
|
+
// URP does not judge this flag. Preserve the raw value for diagnostics.
|
|
41
|
+
return {
|
|
42
|
+
pubkey: (0, viem_1.bytesToHex)(bytes.slice(offset, offset + 32)),
|
|
43
|
+
isWritable: writableFlag === 1,
|
|
44
|
+
writableFlag,
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
program: (0, viem_1.bytesToHex)(bytes.slice(dataOffset + length + 1)),
|
|
49
|
+
accounts,
|
|
50
|
+
instructionData: bytes.slice(dataOffset, dataOffset + length),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function encodeAgwSvmPayload(program, accounts, instructionData) {
|
|
54
|
+
(0, svm_terms_1.exactHex)(program, 32, 'target program');
|
|
55
|
+
if (accounts.length > svm_terms_1.SVM_LIMITS.accounts)
|
|
56
|
+
fail('SvmAccountsOutOfRange');
|
|
57
|
+
if (instructionData.length > svm_terms_1.SVM_LIMITS.ixData)
|
|
58
|
+
fail('SvmIxDataTooLong');
|
|
59
|
+
accounts.forEach((a) => {
|
|
60
|
+
(0, svm_terms_1.exactHex)(a.pubkey, 32, 'account');
|
|
61
|
+
if (typeof a.isWritable !== 'boolean')
|
|
62
|
+
fail('MalformedSvmPayload');
|
|
63
|
+
});
|
|
64
|
+
return (0, payload_builders_1.encodeSvmExecutePayload)({
|
|
65
|
+
targetProgram: program,
|
|
66
|
+
accounts: [...accounts],
|
|
67
|
+
ixData: instructionData,
|
|
68
|
+
instructionId: 2,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function uintLE(data) {
|
|
72
|
+
return data.reduceRight((v, b) => (v << BigInt(8)) + BigInt(b), BigInt(0));
|
|
73
|
+
}
|
|
74
|
+
/** Terms must have passed grant-shape validation. On-chain URP remains the enforcement authority. */
|
|
75
|
+
function validateAgwSvmPayload(terms, recipient, payload) {
|
|
76
|
+
(0, svm_terms_1.exactHex)(recipient, 32, 'recipient');
|
|
77
|
+
if (BigInt(recipient) === BigInt(0))
|
|
78
|
+
fail('RecipientNotPubkey');
|
|
79
|
+
const v = parseAgwSvmPayload(payload), data = v.instructionData;
|
|
80
|
+
if (v.program.toLowerCase() !== recipient.toLowerCase())
|
|
81
|
+
fail('RecipientTargetMismatch');
|
|
82
|
+
if ((0, svm_terms_1.isForbiddenSvmProgram)(v.program, terms))
|
|
83
|
+
fail('ForbiddenTargetProgram');
|
|
84
|
+
const rule = terms.programs.findIndex((p) => p.program.toLowerCase() === v.program.toLowerCase() &&
|
|
85
|
+
(p.dataless
|
|
86
|
+
? data.length === 0
|
|
87
|
+
: data.length >= p.discriminatorLen &&
|
|
88
|
+
(0, viem_1.bytesToHex)(data.slice(0, p.discriminatorLen)).toLowerCase() ===
|
|
89
|
+
p.discriminator.slice(0, 2 + p.discriminatorLen * 2).toLowerCase()));
|
|
90
|
+
if (rule < 0)
|
|
91
|
+
fail('ProgramNotAllowed');
|
|
92
|
+
const fixed = terms.programs[rule].maxAccounts;
|
|
93
|
+
if (fixed && fixed !== v.accounts.length)
|
|
94
|
+
fail('SvmAccountCountMismatch');
|
|
95
|
+
const pins = terms.pins.filter((p) => p.ruleIndex === rule);
|
|
96
|
+
for (const p of pins) {
|
|
97
|
+
if (p.accountIndex >= v.accounts.length)
|
|
98
|
+
fail('SvmAccountCountBelowPin');
|
|
99
|
+
if (v.accounts[p.accountIndex].pubkey.toLowerCase() !==
|
|
100
|
+
p.expected.toLowerCase())
|
|
101
|
+
fail('SvmAccountPinMismatch');
|
|
102
|
+
}
|
|
103
|
+
function field(fromEnd, offset, len) {
|
|
104
|
+
const start = fromEnd ? data.length - offset : offset;
|
|
105
|
+
if (start < 0 || start + len > data.length)
|
|
106
|
+
fail('SvmDataTooShortForPin');
|
|
107
|
+
return data.slice(start, start + len);
|
|
108
|
+
}
|
|
109
|
+
for (const p of terms.dataPins.filter((p) => p.ruleIndex === rule)) {
|
|
110
|
+
const a = field(p.fromEnd, p.offset, p.len);
|
|
111
|
+
if (p.mode === svm_terms_1.SvmDataPinMode.EQ) {
|
|
112
|
+
if ((0, viem_1.bytesToHex)(a).toLowerCase() !==
|
|
113
|
+
p.expected.slice(0, 2 + p.len * 2).toLowerCase())
|
|
114
|
+
fail('SvmDataPinMismatch');
|
|
115
|
+
}
|
|
116
|
+
else if (p.mode === svm_terms_1.SvmDataPinMode.GTE_LE) {
|
|
117
|
+
if (uintLE(a) < BigInt(p.expected))
|
|
118
|
+
fail('SvmDataFloorNotMet');
|
|
119
|
+
}
|
|
120
|
+
else if (p.mode === svm_terms_1.SvmDataPinMode.LTE_LE) {
|
|
121
|
+
if (uintLE(a) > BigInt(p.expected))
|
|
122
|
+
fail('SvmDataCeilingExceeded');
|
|
123
|
+
}
|
|
124
|
+
else if (uintLE(a) * p.den <
|
|
125
|
+
uintLE(field(p.fromEnd, p.offsetB, p.len)) * p.num)
|
|
126
|
+
fail('SvmDataRatioNotMet');
|
|
127
|
+
}
|
|
128
|
+
const protectedKeys = new Set(terms.ceaAccounts.map((k) => k.toLowerCase()));
|
|
129
|
+
v.accounts.forEach((a, i) => {
|
|
130
|
+
if (protectedKeys.has(a.pubkey.toLowerCase()) &&
|
|
131
|
+
!pins.some((p) => p.accountIndex === i))
|
|
132
|
+
fail('CeaAccountAtUnpinnedIndex');
|
|
133
|
+
});
|
|
134
|
+
return rule;
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=svm-payload.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type UniversalExecuteParams, type TransactionExecutionOptions } from '../../orchestrator/orchestrator.types';
|
|
2
|
+
import type { AgenticRuntime } from '../runtime';
|
|
3
|
+
import type { AgenticExecutionContext } from '../context';
|
|
4
|
+
/** Public single-instruction route; the contract enforces the supplied rule. */
|
|
5
|
+
export declare function sendPublicSvm(runtime: AgenticRuntime, actx: AgenticExecutionContext, p: UniversalExecuteParams, options?: TransactionExecutionOptions): Promise<import("../../orchestrator/orchestrator.types").UniversalTxResponse>;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendPublicSvm = sendPublicSvm;
|
|
4
|
+
const progress_hook_types_1 = require("../../progress-hook/progress-hook.types");
|
|
5
|
+
const common_1 = require("../management/common");
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const orchestrator_types_1 = require("../../orchestrator/orchestrator.types");
|
|
8
|
+
const resolve_1 = require("../../orchestrator/svm-idl/resolve");
|
|
9
|
+
const capabilities_1 = require("../capabilities");
|
|
10
|
+
const rules_1 = require("../reads/rules");
|
|
11
|
+
const svm_1 = require("../reads/svm");
|
|
12
|
+
const snapshot_1 = require("../reads/snapshot");
|
|
13
|
+
const svm_public_1 = require("../management/svm-public");
|
|
14
|
+
const common_2 = require("../management/common");
|
|
15
|
+
const svm_accounts_1 = require("../codec/svm-accounts");
|
|
16
|
+
const svm_terms_1 = require("../codec/svm-terms");
|
|
17
|
+
const errors_1 = require("../errors");
|
|
18
|
+
const svm_send_1 = require("./svm-send");
|
|
19
|
+
const svm_payload_1 = require("./svm-payload");
|
|
20
|
+
const svm_quote_1 = require("./svm-quote");
|
|
21
|
+
const svm_outbound_1 = require("./svm-outbound");
|
|
22
|
+
const response_1 = require("../response");
|
|
23
|
+
/** Public single-instruction route; the contract enforces the supplied rule. */
|
|
24
|
+
async function sendPublicSvm(runtime, actx, p, options) {
|
|
25
|
+
const gen = actx.generation, wallet = actx.wallet;
|
|
26
|
+
(0, capabilities_1.requireCapability)(gen.capabilities, capabilities_1.AgenticCapability.UNIVERSAL_SVM_RULES);
|
|
27
|
+
(0, capabilities_1.requireCapability)(gen.capabilities, actx.door === 'agent'
|
|
28
|
+
? capabilities_1.AgenticCapability.AGENT_EXECUTE
|
|
29
|
+
: capabilities_1.AgenticCapability.OWNER_EXECUTE);
|
|
30
|
+
const to = p.to;
|
|
31
|
+
const target = (0, svm_accounts_1.svmKey)(to.address);
|
|
32
|
+
if (Array.isArray(p.data))
|
|
33
|
+
throw (0, svm_terms_1.svmInvalid)('Solana AGW sends do not support instruction arrays');
|
|
34
|
+
const hasInstruction = p.data !== undefined && p.data !== '0x';
|
|
35
|
+
if (hasInstruction &&
|
|
36
|
+
(typeof p.data !== 'string' || !/^0x(?:[0-9a-fA-F]{2})+$/.test(p.data)))
|
|
37
|
+
throw (0, svm_terms_1.svmInvalid)('invalid Solana instruction bytes');
|
|
38
|
+
if (!hasInstruction && actx.door === 'agent')
|
|
39
|
+
throw (0, svm_terms_1.svmInvalid)('Solana agent sends require an encoded instruction');
|
|
40
|
+
if (p.funds && (0, orchestrator_types_1.isPC20Reference)(p.funds.token))
|
|
41
|
+
throw (0, svm_terms_1.svmInvalid)('PC20 SVM outbound is not supported');
|
|
42
|
+
if (p.funds && (p.value ?? BigInt(0)) !== BigInt(0))
|
|
43
|
+
throw (0, svm_terms_1.svmInvalid)('use either funds or value for the bridged amount');
|
|
44
|
+
const amount = p.funds?.amount ?? p.value ?? BigInt(0);
|
|
45
|
+
if (typeof amount !== 'bigint' || amount < BigInt(0) || amount > svm_terms_1.UINT64_MAX)
|
|
46
|
+
throw (0, svm_terms_1.svmInvalid)('Solana outbound amount must fit uint64');
|
|
47
|
+
if (!hasInstruction && amount === BigInt(0))
|
|
48
|
+
throw (0, svm_terms_1.svmInvalid)('a funds-only send requires a positive amount');
|
|
49
|
+
const metadata = (0, svm_public_1.svmMetadata)(runtime), snap = await snapshot_1.Snapshot.at(runtime.reader);
|
|
50
|
+
let rulesId, data, instruction, cea;
|
|
51
|
+
let destinationTransfer;
|
|
52
|
+
let transferValue = BigInt(0);
|
|
53
|
+
const gasLimit = p.gasLimit ?? BigInt(1_000_000);
|
|
54
|
+
if (actx.door === 'agent') {
|
|
55
|
+
const active = await (0, rules_1.selectRuleForSend)(snap, gen, wallet, actx.signerPushAccount, to.chain);
|
|
56
|
+
const stored = await (0, svm_1.readSvmConfig)(snap, gen, wallet, active, runtime.pushChainNamespace);
|
|
57
|
+
const token = p.funds || amount > BigInt(0)
|
|
58
|
+
? runtime.resolvePrc20(p.funds?.token, to.chain)
|
|
59
|
+
: (0, viem_1.getAddress)(stored.config.assets[0].token);
|
|
60
|
+
const prepared = await (0, svm_send_1.prepareSvmAgentExecution)(runtime, gen, {
|
|
61
|
+
wallet,
|
|
62
|
+
rulesId: active.rulesId,
|
|
63
|
+
token,
|
|
64
|
+
amount,
|
|
65
|
+
gasLimit,
|
|
66
|
+
program: target,
|
|
67
|
+
instructionData: (0, viem_1.hexToBytes)(p.data),
|
|
68
|
+
}, metadata);
|
|
69
|
+
data = prepared.data;
|
|
70
|
+
instruction = prepared.instruction;
|
|
71
|
+
cea = stored.config.expectedCEA;
|
|
72
|
+
rulesId = active.rulesId;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
const gateway = await metadata.gateway(to.chain);
|
|
76
|
+
cea = (0, svm_accounts_1.deriveAgwSvmCea)(wallet, gateway.program).address;
|
|
77
|
+
const resolved = hasInstruction
|
|
78
|
+
? (0, resolve_1.resolveSvmCallForCea)({
|
|
79
|
+
programAddress: target,
|
|
80
|
+
data: (0, viem_1.hexToBytes)(p.data),
|
|
81
|
+
senderUea: wallet,
|
|
82
|
+
targetChain: to.chain,
|
|
83
|
+
}, cea)
|
|
84
|
+
: undefined;
|
|
85
|
+
if (resolved)
|
|
86
|
+
instruction = {
|
|
87
|
+
recipient: resolved.targetProgram,
|
|
88
|
+
instructionData: resolved.ixData,
|
|
89
|
+
accounts: resolved.accounts,
|
|
90
|
+
};
|
|
91
|
+
const token = runtime.resolvePrc20(p.funds?.token, to.chain);
|
|
92
|
+
const quote = await (0, svm_quote_1.quoteSvmRequest)(runtime, snap, wallet, token, to.chain, gasLimit, amount);
|
|
93
|
+
if (!hasInstruction) {
|
|
94
|
+
destinationTransfer = { recipient: target, token, amount };
|
|
95
|
+
transferValue = quote.isNative ? amount : BigInt(0);
|
|
96
|
+
}
|
|
97
|
+
const [pc, balance, allowance] = await Promise.all([
|
|
98
|
+
runtime.reader.getBalance({
|
|
99
|
+
address: wallet,
|
|
100
|
+
blockNumber: snap.blockNumber,
|
|
101
|
+
}),
|
|
102
|
+
snap.read(token, viem_1.erc20Abi, 'balanceOf', [wallet]),
|
|
103
|
+
snap.read(token, viem_1.erc20Abi, 'allowance', [
|
|
104
|
+
wallet,
|
|
105
|
+
gen.addresses.gateway,
|
|
106
|
+
]),
|
|
107
|
+
]);
|
|
108
|
+
const value = quote.protocolFee + quote.nativeValueForGas;
|
|
109
|
+
if (pc < value || balance < amount)
|
|
110
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.WALLET_BALANCE_INSUFFICIENT, 'wallet cannot cover Solana outbound');
|
|
111
|
+
if (allowance < amount)
|
|
112
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.GATEWAY_ALLOWANCE_INSUFFICIENT, 'set the wallet gateway allowance separately');
|
|
113
|
+
const call = (0, svm_outbound_1.buildAgwSvmAction)({
|
|
114
|
+
wallet,
|
|
115
|
+
gateway: gen.addresses.gateway,
|
|
116
|
+
token,
|
|
117
|
+
amount,
|
|
118
|
+
recipient: target,
|
|
119
|
+
payload: resolved
|
|
120
|
+
? (0, svm_payload_1.encodeAgwSvmPayload)(resolved.targetProgram, resolved.accounts, resolved.ixData)
|
|
121
|
+
: '0x',
|
|
122
|
+
gasLimit: quote.gasLimitUsed,
|
|
123
|
+
protocolFee: quote.protocolFee,
|
|
124
|
+
maxPCForGas: quote.nativeValueForGas,
|
|
125
|
+
});
|
|
126
|
+
data = gen.contracts.encodeExecute([call]);
|
|
127
|
+
}
|
|
128
|
+
const hook = options?.progressHook ?? p.progressHook;
|
|
129
|
+
(0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_107, rulesId, to.chain, actx.door);
|
|
130
|
+
let response;
|
|
131
|
+
try {
|
|
132
|
+
response = await runtime.execute({
|
|
133
|
+
to: wallet,
|
|
134
|
+
value: BigInt(0),
|
|
135
|
+
data,
|
|
136
|
+
...(p.nonce === undefined ? {} : { nonce: p.nonce }),
|
|
137
|
+
...(p.maxFeePerGas === undefined
|
|
138
|
+
? {}
|
|
139
|
+
: { maxFeePerGas: p.maxFeePerGas }),
|
|
140
|
+
...(p.maxPriorityFeePerGas === undefined
|
|
141
|
+
? {}
|
|
142
|
+
: { maxPriorityFeePerGas: p.maxPriorityFeePerGas }),
|
|
143
|
+
...(p.deadline === undefined ? {} : { deadline: p.deadline }),
|
|
144
|
+
...(p.feeLockTxHash === undefined
|
|
145
|
+
? {}
|
|
146
|
+
: { feeLockTxHash: p.feeLockTxHash }),
|
|
147
|
+
}, { ...options, progressHook: options?.progressHook ?? p.progressHook });
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
const wrapped = (0, common_2.wrapSendError)(error);
|
|
151
|
+
(0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_199_02, 'sendTransaction', wrapped.code ?? 'UNKNOWN', wrapped.message, wrapped.decodedError);
|
|
152
|
+
throw wrapped;
|
|
153
|
+
}
|
|
154
|
+
const result = (0, response_1.adaptAgenticResponse)(response, {
|
|
155
|
+
wallet,
|
|
156
|
+
door: actx.door,
|
|
157
|
+
rulesId,
|
|
158
|
+
chainNamespace: to.chain,
|
|
159
|
+
chain: to.chain,
|
|
160
|
+
route: 'UOA_TO_CEA',
|
|
161
|
+
...(instruction
|
|
162
|
+
? {
|
|
163
|
+
destinationAccount: cea,
|
|
164
|
+
destinationInstruction: {
|
|
165
|
+
program: instruction.recipient,
|
|
166
|
+
data: (0, viem_1.bytesToHex)(instruction.instructionData),
|
|
167
|
+
accounts: instruction.accounts,
|
|
168
|
+
},
|
|
169
|
+
}
|
|
170
|
+
: { destinationTransfer }),
|
|
171
|
+
logical: instruction
|
|
172
|
+
? {
|
|
173
|
+
to: instruction.recipient,
|
|
174
|
+
data: (0, viem_1.bytesToHex)(instruction.instructionData),
|
|
175
|
+
value: BigInt(0),
|
|
176
|
+
}
|
|
177
|
+
: { to: target, data: '0x', value: transferValue },
|
|
178
|
+
});
|
|
179
|
+
(0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_199_01, 'sendTransaction', response.hash);
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=svm-public.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Address } from 'viem';
|
|
2
|
+
import type { CHAIN } from '../../constants/enums';
|
|
3
|
+
import type { AgenticRuntime } from '../runtime';
|
|
4
|
+
import type { Snapshot } from '../reads/snapshot';
|
|
5
|
+
/** Route/fee validation, independent of the selected rule's permissions. */
|
|
6
|
+
export declare function quoteSvmRequest(runtime: AgenticRuntime, snap: Snapshot, wallet: Address, token: Address, chain: CHAIN, gasLimit: bigint, amount: bigint): Promise<{
|
|
7
|
+
isNative: boolean;
|
|
8
|
+
protocolFee: bigint;
|
|
9
|
+
nativeValueForGas: bigint;
|
|
10
|
+
gasLimitUsed: bigint;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.quoteSvmRequest = quoteSvmRequest;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const prc20_metadata_1 = require("../contracts/prc20-metadata");
|
|
7
|
+
const errors_1 = require("../errors");
|
|
8
|
+
/** Route/fee validation, independent of the selected rule's permissions. */
|
|
9
|
+
async function quoteSvmRequest(runtime, snap, wallet, token, chain, gasLimit, amount) {
|
|
10
|
+
if ((await snap.read(token, prc20_metadata_1.PRC20_SOURCE_ABI, 'SOURCE_CHAIN_NAMESPACE')) !== chain) {
|
|
11
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.ASSET_CHAIN_MISMATCH, 'outbound asset belongs to another chain');
|
|
12
|
+
}
|
|
13
|
+
const isNative = (0, viem_1.getAddress)(token) === (0, viem_1.getAddress)(await (0, prc20_metadata_1.readGasPrc20)(snap, chain));
|
|
14
|
+
const splMintBase58 = !isNative && amount > BigInt(0)
|
|
15
|
+
? new web3_js_1.PublicKey((0, viem_1.hexToBytes)(await (0, prc20_metadata_1.readSvmSourceToken)(snap, token, chain, runtime.network))).toBase58()
|
|
16
|
+
: undefined;
|
|
17
|
+
const quote = await runtime.quoteOutbound(token, gasLimit, chain, {
|
|
18
|
+
wallet,
|
|
19
|
+
splMintBase58,
|
|
20
|
+
burnAmount: amount,
|
|
21
|
+
});
|
|
22
|
+
return { ...quote, isNative };
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=svm-quote.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** Prepared-wire agent execution used by the public Solana route. */
|
|
2
|
+
import { type Address, type Hex } from 'viem';
|
|
3
|
+
import type { AgenticGeneration } from '../deployments';
|
|
4
|
+
import type { AgenticRuntime } from '../runtime';
|
|
5
|
+
import { type SvmMetadataProvider } from '../management/svm-context';
|
|
6
|
+
import type { SvmPayloadAccount } from './svm-payload';
|
|
7
|
+
export interface PreparedSvmRequest {
|
|
8
|
+
wallet: Address;
|
|
9
|
+
rulesId: Hex;
|
|
10
|
+
token: Address;
|
|
11
|
+
amount: bigint;
|
|
12
|
+
gasLimit: bigint;
|
|
13
|
+
program: string;
|
|
14
|
+
instructionData: Uint8Array;
|
|
15
|
+
/** Already-resolved wire accounts for non-Anchor/dataless programs. */
|
|
16
|
+
accounts?: readonly SvmPayloadAccount[];
|
|
17
|
+
}
|
|
18
|
+
export declare function prepareSvmAgentExecution(runtime: AgenticRuntime, gen: AgenticGeneration, input: PreparedSvmRequest, metadata: SvmMetadataProvider): Promise<{
|
|
19
|
+
stored: import("../reads/svm").SvmRuleSnapshot;
|
|
20
|
+
call: import("../contracts/v5").Call;
|
|
21
|
+
instruction: {
|
|
22
|
+
recipient: `0x${string}`;
|
|
23
|
+
payload: `0x${string}`;
|
|
24
|
+
accounts: SvmPayloadAccount[];
|
|
25
|
+
instructionData: Uint8Array;
|
|
26
|
+
};
|
|
27
|
+
quote: {
|
|
28
|
+
isNative: boolean;
|
|
29
|
+
protocolFee: bigint;
|
|
30
|
+
nativeValueForGas: bigint;
|
|
31
|
+
gasLimitUsed: bigint;
|
|
32
|
+
};
|
|
33
|
+
data: `0x${string}`;
|
|
34
|
+
}>;
|
|
35
|
+
export declare function sendSvmAgentWire(runtime: AgenticRuntime, gen: AgenticGeneration, input: PreparedSvmRequest, metadata: SvmMetadataProvider): Promise<{
|
|
36
|
+
tx: import("../../orchestrator/orchestrator.types").UniversalTxResponse;
|
|
37
|
+
context: import("../reads/svm").SvmRuleSnapshot;
|
|
38
|
+
instruction: {
|
|
39
|
+
recipient: `0x${string}`;
|
|
40
|
+
payload: `0x${string}`;
|
|
41
|
+
accounts: SvmPayloadAccount[];
|
|
42
|
+
instructionData: Uint8Array;
|
|
43
|
+
};
|
|
44
|
+
}>;
|