@pushchain/core 6.0.27-alpha.3 → 6.0.27-alpha.4

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.
Files changed (90) hide show
  1. package/AGW.md +27 -6
  2. package/CHANGELOG.md +7 -0
  3. package/MARKETPLACE.md +206 -0
  4. package/package.json +2 -1
  5. package/src/lib/agentic/codec/rules.js +74 -69
  6. package/src/lib/agentic/codec/universal.js +15 -3
  7. package/src/lib/agentic/constants.d.ts +36 -1
  8. package/src/lib/agentic/constants.js +14 -1
  9. package/src/lib/agentic/contracts/reader.d.ts +21 -0
  10. package/src/lib/agentic/contracts/reader.js +3 -0
  11. package/src/lib/agentic/error-messages.d.ts +3 -0
  12. package/src/lib/agentic/error-messages.js +125 -0
  13. package/src/lib/agentic/errors.d.ts +12 -3
  14. package/src/lib/agentic/errors.js +76 -0
  15. package/src/lib/agentic/management/common.js +6 -0
  16. package/src/lib/agentic/management/destination.d.ts +5 -0
  17. package/src/lib/agentic/management/destination.js +32 -0
  18. package/src/lib/agentic/management/prepare.js +80 -55
  19. package/src/lib/agentic/management/svm-public.js +13 -4
  20. package/src/lib/agentic/presets/index.js +7 -8
  21. package/src/lib/agentic/presets/routes.d.ts +1 -1
  22. package/src/lib/agentic/presets/routes.js +6 -7
  23. package/src/lib/agentic/presets/types.d.ts +1 -6
  24. package/src/lib/agentic/public-rule.js +13 -2
  25. package/src/lib/constants/index.d.ts +35 -0
  26. package/src/lib/index.d.ts +4 -0
  27. package/src/lib/index.js +6 -2
  28. package/src/lib/job/job.d.ts +35 -0
  29. package/src/lib/job/job.js +382 -0
  30. package/src/lib/job/types.d.ts +94 -0
  31. package/src/lib/job/types.js +3 -0
  32. package/src/lib/job/watch.d.ts +3 -0
  33. package/src/lib/job/watch.js +169 -0
  34. package/src/lib/job-spec/codec.d.ts +18 -0
  35. package/src/lib/job-spec/codec.js +348 -0
  36. package/src/lib/job-spec/constants.d.ts +32 -0
  37. package/src/lib/job-spec/constants.js +36 -0
  38. package/src/lib/job-spec/helpers.d.ts +19 -0
  39. package/src/lib/job-spec/helpers.js +138 -0
  40. package/src/lib/job-spec/index.d.ts +14 -0
  41. package/src/lib/job-spec/index.js +17 -0
  42. package/src/lib/job-spec/preview.d.ts +8 -0
  43. package/src/lib/job-spec/preview.js +298 -0
  44. package/src/lib/job-spec/read.d.ts +20 -0
  45. package/src/lib/job-spec/read.js +224 -0
  46. package/src/lib/job-spec/schema.d.ts +290 -0
  47. package/src/lib/job-spec/schema.js +70 -0
  48. package/src/lib/job-spec/types.d.ts +139 -0
  49. package/src/lib/job-spec/types.js +3 -0
  50. package/src/lib/market/contracts/AgenticCommerce.d.ts +1026 -0
  51. package/src/lib/market/contracts/AgenticCommerce.js +1317 -0
  52. package/src/lib/market/contracts/RulesBindingHook.d.ts +235 -0
  53. package/src/lib/market/contracts/RulesBindingHook.js +314 -0
  54. package/src/lib/market/contracts/UniversalMarketplace.d.ts +1770 -0
  55. package/src/lib/market/contracts/UniversalMarketplace.js +2295 -0
  56. package/src/lib/market/contracts/UniversalMarketplaceErrors.d.ts +309 -0
  57. package/src/lib/market/contracts/UniversalMarketplaceErrors.js +416 -0
  58. package/src/lib/market/contracts/UniversalMarketplaceRules.d.ts +241 -0
  59. package/src/lib/market/contracts/UniversalMarketplaceRules.js +323 -0
  60. package/src/lib/market/data.d.ts +8 -0
  61. package/src/lib/market/data.js +60 -0
  62. package/src/lib/market/deployment.d.ts +14 -0
  63. package/src/lib/market/deployment.js +23 -0
  64. package/src/lib/market/deposit.d.ts +24 -0
  65. package/src/lib/market/deposit.js +271 -0
  66. package/src/lib/market/errors.d.ts +13 -0
  67. package/src/lib/market/errors.js +81 -0
  68. package/src/lib/market/history.d.ts +6 -0
  69. package/src/lib/market/history.js +83 -0
  70. package/src/lib/market/index.d.ts +4 -0
  71. package/src/lib/market/index.js +12 -0
  72. package/src/lib/market/kernel-wire.d.ts +15 -0
  73. package/src/lib/market/kernel-wire.js +41 -0
  74. package/src/lib/market/market.d.ts +55 -0
  75. package/src/lib/market/market.js +635 -0
  76. package/src/lib/market/rules.d.ts +106 -0
  77. package/src/lib/market/rules.js +293 -0
  78. package/src/lib/market/runtime.d.ts +35 -0
  79. package/src/lib/market/runtime.js +130 -0
  80. package/src/lib/market/types.d.ts +180 -0
  81. package/src/lib/market/types.js +3 -0
  82. package/src/lib/orchestrator/internals/errors.d.ts +9 -2
  83. package/src/lib/orchestrator/internals/errors.js +9 -2
  84. package/src/lib/orchestrator/internals/push-chain-tx.js +17 -3
  85. package/src/lib/push-chain/push-chain.d.ts +44 -1
  86. package/src/lib/push-chain/push-chain.js +23 -3
  87. package/src/lib/read-state/read-params.d.ts +9 -0
  88. package/src/lib/read-state/read-params.js +5 -1
  89. package/src/lib/utils.d.ts +15 -0
  90. package/src/lib/utils.js +4 -0
@@ -7,10 +7,13 @@ function chainReaderFromPublicClient(client) {
7
7
  return {
8
8
  readContract: (args) => client.readContract(args),
9
9
  getBlockNumber: () => client.getBlockNumber({ cacheTime: 0 }),
10
+ getBlock: (args) => client.getBlock(args),
10
11
  getCode: (args) => client.getCode(args),
11
12
  getBalance: (args) => client.getBalance(args),
12
13
  getLogs: (args) => client.getLogs(args),
13
14
  getTransactionReceipt: (args) => client.getTransactionReceipt(args),
15
+ getTransaction: (args) => client.getTransaction(args),
16
+ call: (args) => client.call(args),
14
17
  };
15
18
  }
16
19
  //# sourceMappingURL=reader.js.map
@@ -0,0 +1,3 @@
1
+ import type { AgenticErrorCode } from './errors';
2
+ export declare function agenticUserMessage(code: AgenticErrorCode, diagnostic: string, details?: Readonly<Record<string, unknown>>): string;
3
+ export declare function agenticRevertUserMessage(name?: string): string;
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.agenticUserMessage = agenticUserMessage;
4
+ exports.agenticRevertUserMessage = agenticRevertUserMessage;
5
+ /** UI copy only. Codes, original messages, hints and causes remain diagnostic data. */
6
+ const MESSAGES = {
7
+ DUPLICATE_RULE: 'Keep one rule per agent and network. Edit the existing rule or remove the duplicate.',
8
+ AGENT_IS_OWNER: 'Choose an agent address different from the wallet owner.',
9
+ AMBIGUOUS_RULE: 'More than one rule matches this agent and network. Keep one active matching rule before sending.',
10
+ TARGET_NOT_ON_RULE_CHAIN: 'Choose an app on the network selected for this rule.',
11
+ ASSET_CHAIN_MISMATCH: 'The selected token belongs to a different network. Choose a token on this rule’s network.',
12
+ TOKEN_ROUTE_UNAVAILABLE: 'This token cannot currently be transferred from Push to the selected network. Choose a token with a supported Push route.',
13
+ REQUEST_REJECTED: 'The wallet request was cancelled. Check wallet activity before trying again.',
14
+ NOT_OWNER_OR_AGENT: 'Connect the wallet owner or an agent authorized by its rules.',
15
+ WALLET_NOT_DEPLOYED: 'This agentic wallet has not been created yet.',
16
+ NOT_AGENTIC_WALLET: 'This address is not a supported agentic wallet.',
17
+ DELETE_NEEDS_TARGET: 'Choose which rules to remove.',
18
+ NO_RULES_FOR_CHAIN: 'This agent has no active rule for the selected network.',
19
+ FROM_NOT_ALLOWED: 'The agentic wallet is the sender. Remove the custom sender selection.',
20
+ NOT_ALLOWED_IN_AGENTIC_MODE: 'This action is unavailable while using an agentic wallet.',
21
+ INVALID_RULE: 'Some rule settings are invalid. Review the rule and try again.',
22
+ CAPABILITY_UNAVAILABLE: 'This feature is not available for this wallet or network yet.',
23
+ READ_ONLY: 'Connect a signing wallet to continue.',
24
+ NOT_WALLET_OWNER: 'Connect the owner wallet to change these permissions.',
25
+ RULE_NOT_FOUND: 'This rule could not be found. Refresh the wallet’s rules and try again.',
26
+ RULE_READ_FAILED: 'The wallet’s current state could not be loaded. Refresh and try again.',
27
+ INCONSISTENT_READ: 'The wallet changed while it was being checked. Refresh before trying again.',
28
+ INDEX_RACE: 'The expected wallet address changed. Refresh wallet information before trying again.',
29
+ RECEIPT_MISMATCH: 'The transaction result needs verification. Check its status before retrying.',
30
+ RECEIPT_UNAVAILABLE: 'The transaction was submitted, but its status could not be confirmed. Check its status before trying again.',
31
+ AGENT_GAS_INSUFFICIENT: 'The agent needs more Push coins to pay transaction fees.',
32
+ WALLET_BALANCE_INSUFFICIENT: 'The agentic wallet does not have enough funds for this action.',
33
+ };
34
+ function agenticUserMessage(code, diagnostic, details) {
35
+ if (code === 'CAPABILITY_UNAVAILABLE') {
36
+ if (details?.['capability'] === 'nativeActions')
37
+ return 'A Push rule can allow at most eight functions. Select fewer functions.';
38
+ if (details?.['capability'] === 'presetCalls')
39
+ return 'Choose a preset configuration with 1 to 32 allowed functions.';
40
+ if (details?.['capability'] === 'presetChain' ||
41
+ details?.['capability'] === 'presetCatalog')
42
+ return 'This preset is unavailable for the selected network.';
43
+ }
44
+ if (code !== 'INVALID_RULE')
45
+ return MESSAGES[code];
46
+ if (/validUntil|expiry|expired|future.*timestamp/i.test(diagnostic))
47
+ return 'Choose an expiry date in the future.';
48
+ if (/label.*(64|length|most)/i.test(diagnostic))
49
+ return 'The wallet name is too long. Shorten it and try again.';
50
+ if (/label/i.test(diagnostic))
51
+ return 'Enter a valid wallet name.';
52
+ if (/maxGasPerCall.*positive/i.test(diagnostic))
53
+ return 'Set a gas budget greater than zero for this rule.';
54
+ if (/allowedCalls.*(1\.\.32|contain|array)/i.test(diagnostic))
55
+ return 'Select between 1 and 32 allowed functions for this rule.';
56
+ if (/rules.*(eight|8)|eight initial rules/i.test(diagnostic))
57
+ return 'A wallet can be created with at most eight rules. Remove some rules before creating it.';
58
+ if (/assets.*(eight|8)/i.test(diagnostic))
59
+ return 'A rule can include at most eight tokens. Select fewer tokens.';
60
+ if (/duplicate.*pin|pin.*duplicate/i.test(diagnostic))
61
+ return 'The same function input has more than one condition. Keep one condition for each input.';
62
+ if (/pins.*(eight|8)/i.test(diagnostic))
63
+ return 'A function can have at most eight conditions. Choose a simpler function configuration.';
64
+ if (/pins.*32|32.*pins/i.test(diagnostic))
65
+ return 'This rule has too many conditions. Select fewer tokens or allowed functions.';
66
+ if (/selector|function signature/i.test(diagnostic))
67
+ return 'The selected function format is invalid. Select the function again or check its signature.';
68
+ if (/dynamic|static|offset|argument.*range|tuple/i.test(diagnostic))
69
+ return 'This function input cannot be constrained in that format. Choose a supported input or function.';
70
+ if (/uint256|bigint|non-negative/i.test(diagnostic))
71
+ return 'One of the spending limits is invalid. Review the amounts and try again.';
72
+ if (/chainNamespace|unsupported.*chain/i.test(diagnostic))
73
+ return 'Choose a supported network for this rule.';
74
+ if (/address/i.test(diagnostic))
75
+ return 'Enter a valid wallet, token or app address for this rule.';
76
+ return MESSAGES.INVALID_RULE;
77
+ }
78
+ function agenticRevertUserMessage(name) {
79
+ if (!name)
80
+ return 'The transaction could not be completed. Check wallet activity before trying again.';
81
+ if (/TooManyAllowedCallPins/.test(name))
82
+ return 'This rule has more than 32 conditions. Select fewer tokens or allowed functions.';
83
+ if (/TooMany.*Pins|PinRuleOutOfRange/.test(name))
84
+ return 'This function has too many conditions. Choose a simpler rule configuration.';
85
+ if (/TooManyActions|TooManyInitialRules|BatchSizeOutOfRange/.test(name))
86
+ return 'Too many rules or functions are selected. Reduce the selection and try again.';
87
+ if (/LabelTooLong/.test(name))
88
+ return 'The wallet name is too long. Shorten it and try again.';
89
+ if (/DuplicateAction|DuplicateAsset|DuplicateSvmPin/.test(name))
90
+ return 'This rule contains duplicate functions, tokens or conditions. Remove the duplicate selection.';
91
+ if (/SpentMismatch|SpentLengthMismatch|AssetSpentMismatch|IndexMismatch|InvalidNonce|IntentGrantNonceMismatch|IntentWalletMismatch/.test(name))
92
+ return 'The wallet changed while this action was being prepared. Refresh its state before trying again.';
93
+ if (/EnforcedPause/.test(name))
94
+ return 'This operation is temporarily paused. Try again later.';
95
+ if (/OwnerSigExpired|SignatureExpired/.test(name))
96
+ return 'The wallet approval has expired. Review and sign a new request.';
97
+ if (/OutsideTimeWindow/.test(name))
98
+ return 'This request is outside its valid time window. Refresh and approve a new request.';
99
+ if (/InvalidExpiry/.test(name))
100
+ return 'Choose a valid future expiry for this rule.';
101
+ if (/Allowance|Approval/.test(name))
102
+ return 'The token spending approval is missing or too small. Review the token approvals.';
103
+ if (/RuleWithoutPin|CeaAccountsMissExpectedCEA|CeaAccountAtUnpinnedIndex/.test(name))
104
+ return 'The rule is missing a required wallet-recipient restriction. Review its recipient settings.';
105
+ if (/Unsupported|WrongVmForCall|WrongModeForCall/.test(name))
106
+ return 'This action is not supported on the selected network or wallet version.';
107
+ if (/InvalidOwnerSignature|InvalidEnableSignature|InvalidSessionKeySignature|SignerNotFound/.test(name))
108
+ return 'The signature could not be verified. Reconnect the authorized wallet and try again.';
109
+ if (/PCValueExceedsCap|Gas.*Cap/.test(name ?? ''))
110
+ return 'The required gas exceeds this rule’s gas budget. Review the budget before trying again.';
111
+ if (/ArgPinAboveMax|AmountExceedsCap|TotalSpendCapExceeded|Value.*Cap|MaxCalls|CallLimitReached|TotalNativeAmountExceeded|TotalValueExceeded/.test(name ?? ''))
112
+ return 'This action exceeds a rule’s spending or usage limit. Reduce the amount or ask the owner to update the rule.';
113
+ if (/Expired|Expiry/.test(name ?? ''))
114
+ return 'This rule has expired. Ask the owner to renew it.';
115
+ if (/ArgPinMismatch|Beneficiary|NotAllowed|NotEnabled|Permission|RuleNot|RulesNot|RecipientTargetMismatch|TargetMismatch|SelectorMismatch|SvmAccountPinMismatch|SvmDataPinMismatch/.test(name ?? ''))
116
+ return 'This action does not match the wallet’s permissions. Check the token, recipient and allowed function.';
117
+ if (/CallerIsNotOwner|UnauthorizedOwner|OwnerLaneRequired/.test(name ?? ''))
118
+ return 'Connect the owner wallet to make this change.';
119
+ if (/CallerIsNotAgent/.test(name ?? ''))
120
+ return 'Connect the agent authorized by this rule.';
121
+ if (/Insufficient|Balance/.test(name ?? ''))
122
+ return 'There are not enough funds for this action. Check the wallet balance and fees.';
123
+ return 'The wallet contract rejected this transaction. Review the permissions and transaction details before trying again.';
124
+ }
125
+ //# sourceMappingURL=error-messages.js.map
@@ -10,6 +10,8 @@ export declare const AGENTIC_ERROR_CODE: {
10
10
  readonly AMBIGUOUS_RULE: "AMBIGUOUS_RULE";
11
11
  readonly TARGET_NOT_ON_RULE_CHAIN: "TARGET_NOT_ON_RULE_CHAIN";
12
12
  readonly ASSET_CHAIN_MISMATCH: "ASSET_CHAIN_MISMATCH";
13
+ readonly TOKEN_ROUTE_UNAVAILABLE: "TOKEN_ROUTE_UNAVAILABLE";
14
+ readonly REQUEST_REJECTED: "REQUEST_REJECTED";
13
15
  readonly NOT_OWNER_OR_AGENT: "NOT_OWNER_OR_AGENT";
14
16
  readonly WALLET_NOT_DEPLOYED: "WALLET_NOT_DEPLOYED";
15
17
  readonly NOT_AGENTIC_WALLET: "NOT_AGENTIC_WALLET";
@@ -36,15 +38,18 @@ export type AgenticErrorCode = (typeof AGENTIC_ERROR_CODE)[keyof typeof AGENTIC_
36
38
  * eligibility or a read that cannot be trusted. Nothing was signed or sent
37
39
  * except receipt errors, which retain the submitted transaction hash.
38
40
  */
39
- export declare class AgenticError extends Error {
40
- readonly code: AgenticErrorCode;
41
+ export declare class AgenticError<Code extends string = AgenticErrorCode> extends Error {
42
+ readonly code: Code;
43
+ /** Safe end-user copy; message/cause retain technical diagnostics. */
44
+ readonly userMessage: string;
41
45
  readonly hint?: string;
42
46
  readonly details?: Readonly<Record<string, unknown>>;
43
47
  readonly cause?: unknown;
44
- constructor(code: AgenticErrorCode, message: string, opts?: {
48
+ constructor(code: Code, message: string, opts?: {
45
49
  hint?: string;
46
50
  details?: Record<string, unknown>;
47
51
  cause?: unknown;
52
+ userMessage?: string;
48
53
  });
49
54
  }
50
55
  /**
@@ -55,6 +60,7 @@ export declare class AgenticError extends Error {
55
60
  */
56
61
  export declare class AgenticRevertError extends PushChainExecutionError {
57
62
  readonly agenticCode?: string;
63
+ readonly userMessage: string;
58
64
  constructor(message: string, opts?: {
59
65
  decodedError?: DecodedErrorPayload;
60
66
  gatewayTxHash?: string;
@@ -62,4 +68,7 @@ export declare class AgenticRevertError extends PushChainExecutionError {
62
68
  cause?: unknown;
63
69
  });
64
70
  }
71
+ export declare function ruleConstraintLimit(actual: number, callCount: number, chainNamespace?: string): AgenticError;
72
+ export declare function ruleErrorContext(error: unknown, ruleIndex: number, chainNamespace?: string): unknown;
73
+ export declare function tokenRouteUnavailable(cause: unknown, token: string, chainNamespace: string, assetIndex: number): AgenticError;
65
74
  export declare function capabilityUnavailable(capability: string, dependency: string, hint?: string): AgenticError;
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AgenticRevertError = exports.AgenticError = exports.AGENTIC_ERROR_CODE = void 0;
4
+ exports.ruleConstraintLimit = ruleConstraintLimit;
5
+ exports.ruleErrorContext = ruleErrorContext;
6
+ exports.tokenRouteUnavailable = tokenRouteUnavailable;
4
7
  exports.capabilityUnavailable = capabilityUnavailable;
5
8
  const errors_1 = require("../orchestrator/internals/errors");
9
+ const error_messages_1 = require("./error-messages");
6
10
  /**
7
11
  * Stable AGW error codes. The first groups are specified by the AGW SDK page
8
12
  * (section 3.f); the remainder are SDK-owned codes that keep unsupported or
@@ -15,6 +19,8 @@ exports.AGENTIC_ERROR_CODE = {
15
19
  AMBIGUOUS_RULE: 'AMBIGUOUS_RULE',
16
20
  TARGET_NOT_ON_RULE_CHAIN: 'TARGET_NOT_ON_RULE_CHAIN',
17
21
  ASSET_CHAIN_MISMATCH: 'ASSET_CHAIN_MISMATCH',
22
+ TOKEN_ROUTE_UNAVAILABLE: 'TOKEN_ROUTE_UNAVAILABLE',
23
+ REQUEST_REJECTED: 'REQUEST_REJECTED',
18
24
  // initialize with agenticWallet (spec 3.f)
19
25
  NOT_OWNER_OR_AGENT: 'NOT_OWNER_OR_AGENT',
20
26
  WALLET_NOT_DEPLOYED: 'WALLET_NOT_DEPLOYED',
@@ -46,6 +52,8 @@ exports.AGENTIC_ERROR_CODE = {
46
52
  */
47
53
  class AgenticError extends Error {
48
54
  code;
55
+ /** Safe end-user copy; message/cause retain technical diagnostics. */
56
+ userMessage;
49
57
  hint;
50
58
  details;
51
59
  cause;
@@ -53,6 +61,11 @@ class AgenticError extends Error {
53
61
  super(message);
54
62
  this.name = 'AgenticError';
55
63
  this.code = code;
64
+ this.userMessage =
65
+ opts.userMessage ??
66
+ (Object.prototype.hasOwnProperty.call(exports.AGENTIC_ERROR_CODE, code)
67
+ ? (0, error_messages_1.agenticUserMessage)(code, message, opts.details)
68
+ : message);
56
69
  this.hint = opts.hint;
57
70
  this.details = opts.details;
58
71
  this.cause = opts.cause;
@@ -67,6 +80,7 @@ exports.AgenticError = AgenticError;
67
80
  */
68
81
  class AgenticRevertError extends errors_1.PushChainExecutionError {
69
82
  agenticCode;
83
+ userMessage;
70
84
  constructor(message, opts = {}) {
71
85
  super(message, {
72
86
  decodedError: opts.decodedError,
@@ -75,9 +89,71 @@ class AgenticRevertError extends errors_1.PushChainExecutionError {
75
89
  });
76
90
  this.name = 'AgenticRevertError';
77
91
  this.agenticCode = opts.agenticCode;
92
+ this.userMessage = (0, error_messages_1.agenticRevertUserMessage)(opts.decodedError?.name ?? opts.agenticCode);
78
93
  }
79
94
  }
80
95
  exports.AgenticRevertError = AgenticRevertError;
96
+ function ruleConstraintLimit(actual, callCount, chainNamespace) {
97
+ const message = `This rule has ${actual} conditions. The maximum is 32. Remove duplicate functions or select fewer tokens or functions.`;
98
+ return new AgenticError(exports.AGENTIC_ERROR_CODE.INVALID_RULE, message, {
99
+ userMessage: message,
100
+ hint: 'Regenerate the preset after changing selections. Do not drop individual conditions or bypass the contract limit.',
101
+ details: {
102
+ reason: 'RULE_CONSTRAINT_LIMIT',
103
+ field: 'allowedCalls',
104
+ actual,
105
+ limit: 32,
106
+ callCount,
107
+ chainNamespace,
108
+ },
109
+ });
110
+ }
111
+ function ruleErrorContext(error, ruleIndex, chainNamespace) {
112
+ if (!(error instanceof AgenticError))
113
+ return error;
114
+ if (error.details?.['ruleIndex'] !== undefined)
115
+ return error;
116
+ return new AgenticError(error.code, error.message, {
117
+ hint: error.hint,
118
+ userMessage: `Rule ${ruleIndex + 1}: ${error.userMessage}`,
119
+ cause: error.cause ?? error,
120
+ details: {
121
+ ...error.details,
122
+ ruleIndex,
123
+ ...(chainNamespace ? { chainNamespace } : {}),
124
+ },
125
+ });
126
+ }
127
+ function tokenRouteUnavailable(cause, token, chainNamespace, assetIndex) {
128
+ if (cause instanceof AgenticError)
129
+ return cause;
130
+ const names = {
131
+ 'eip155:1': 'Ethereum',
132
+ 'eip155:11155111': 'Ethereum Sepolia',
133
+ 'eip155:8453': 'Base',
134
+ 'eip155:84532': 'Base Sepolia',
135
+ 'eip155:42161': 'Arbitrum',
136
+ 'eip155:421614': 'Arbitrum Sepolia',
137
+ 'eip155:56': 'BNB Chain',
138
+ 'eip155:97': 'BNB Testnet',
139
+ };
140
+ const network = names[chainNamespace] ??
141
+ (chainNamespace.startsWith('solana:')
142
+ ? 'the selected Solana network'
143
+ : 'the selected network');
144
+ const message = `This token cannot be sent from Push to ${network}. Choose a token with a supported Push route.`;
145
+ return new AgenticError(exports.AGENTIC_ERROR_CODE.TOKEN_ROUTE_UNAVAILABLE, message, {
146
+ userMessage: message,
147
+ hint: 'Choose a supported token on this network, or wait for a verified PRC20 route for this exact token address. Token symbols alone do not identify a route.',
148
+ details: {
149
+ token,
150
+ chainNamespace,
151
+ assetIndex,
152
+ field: `assets[${assetIndex}].token`,
153
+ },
154
+ cause,
155
+ });
156
+ }
81
157
  function capabilityUnavailable(capability, dependency, hint) {
82
158
  return new AgenticError(exports.AGENTIC_ERROR_CODE.CAPABILITY_UNAVAILABLE, `AGW capability "${capability}" is not available: ${dependency}`, { hint, details: { capability, dependency } });
83
159
  }
@@ -102,6 +102,12 @@ function wrapSendError(err) {
102
102
  cause: err,
103
103
  });
104
104
  }
105
+ if (err &&
106
+ typeof err === 'object' &&
107
+ (('code' in err && err.code === 4001) ||
108
+ ('name' in err && err.name === 'UserRejectedRequestError'))) {
109
+ return new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.REQUEST_REJECTED, 'The wallet request was cancelled.', { cause: err });
110
+ }
105
111
  if (decoded || err instanceof errors_1.PushChainExecutionError) {
106
112
  const e = err;
107
113
  return new errors_2.AgenticRevertError(e?.message ?? decoded?.name ?? 'AGW revert', {
@@ -0,0 +1,5 @@
1
+ import { type Address } from 'viem';
2
+ import type { CHAIN } from '../../constants/enums';
3
+ import type { AgenticRuntime } from '../runtime';
4
+ /** Preserve read failures as read failures; never report them as bad token routes. */
5
+ export declare function resolveRuleDestination(runtime: AgenticRuntime, wallet: Address, chain: CHAIN): Promise<Address>;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveRuleDestination = resolveRuleDestination;
4
+ const viem_1 = require("viem");
5
+ const errors_1 = require("../errors");
6
+ /** Preserve read failures as read failures; never report them as bad token routes. */
7
+ async function resolveRuleDestination(runtime, wallet, chain) {
8
+ try {
9
+ return (0, viem_1.getAddress)((await runtime.resolveCEA(wallet, chain)).cea);
10
+ }
11
+ catch (cause) {
12
+ if (cause instanceof errors_1.AgenticError)
13
+ throw cause;
14
+ const unavailable = cause instanceof Error &&
15
+ cause.message.includes('CEAFactory not available on chain');
16
+ const message = unavailable
17
+ ? 'Agentic wallets are not available on this destination network yet. Choose a supported network.'
18
+ : 'The wallet’s destination account could not be loaded. Try again shortly.';
19
+ throw new errors_1.AgenticError(unavailable
20
+ ? errors_1.AGENTIC_ERROR_CODE.CAPABILITY_UNAVAILABLE
21
+ : errors_1.AGENTIC_ERROR_CODE.RULE_READ_FAILED, message, {
22
+ userMessage: message,
23
+ cause,
24
+ details: {
25
+ chainNamespace: chain,
26
+ field: 'chainNamespace',
27
+ stage: 'destinationAccount',
28
+ },
29
+ });
30
+ }
31
+ }
32
+ //# sourceMappingURL=destination.js.map
@@ -12,72 +12,97 @@ const universal_1 = require("../codec/universal");
12
12
  const deployments_1 = require("../deployments");
13
13
  const capabilities_1 = require("../capabilities");
14
14
  const errors_1 = require("../errors");
15
+ const destination_1 = require("./destination");
15
16
  const prc20_metadata_1 = require("../contracts/prc20-metadata");
16
17
  /** Resolve wallet-dependent wire inputs without signing or mutating authority. */
17
18
  async function prepareWalletRules(runtime, gen, owner, wallet, inputs, snap) {
18
- const rules = await Promise.all(inputs.map((rule) => (0, public_rule_1.isPublicRule)(rule) ? (0, public_rule_1.normalizePublicRule)(rule, wallet, runtime) : rule));
19
+ const rules = await Promise.all(inputs.map(async (rule, ruleIndex) => {
20
+ try {
21
+ return (0, public_rule_1.isPublicRule)(rule)
22
+ ? await (0, public_rule_1.normalizePublicRule)(rule, wallet, runtime)
23
+ : rule;
24
+ }
25
+ catch (error) {
26
+ throw (0, errors_1.ruleErrorContext)(error, ruleIndex, rule?.chainNamespace);
27
+ }
28
+ }));
19
29
  if (rules.length)
20
30
  await (0, deployments_1.verifyPolicyVersion)(runtime.reader, gen);
21
31
  const svm = new Map();
22
32
  const universal = new Map();
23
- for (const rule of rules) {
24
- if (rule && (0, rules_1.isSolanaRule)(rule)) {
25
- (0, capabilities_1.requireCapability)(gen.capabilities, capabilities_1.AgenticCapability.UNIVERSAL_SVM_RULES);
26
- svm.set(rule, await (0, svm_public_1.preparePublicSvmRule)(runtime, snap, wallet, rule));
27
- continue;
28
- }
29
- if (!(0, rules_1.isUniversalRule)(rule))
30
- continue;
31
- if (rule.chainNamespace.startsWith('solana:'))
32
- (0, capabilities_1.requireCapability)(gen.capabilities, capabilities_1.AgenticCapability.UNIVERSAL_SVM_RULES);
33
- (0, universal_1.validateUniversalRuleShape)(rule, runtime.nowSeconds());
34
- (0, capabilities_1.requireCapability)(gen.capabilities, rule.chainNamespace.startsWith('solana:')
35
- ? capabilities_1.AgenticCapability.UNIVERSAL_SVM_RULES
36
- : capabilities_1.AgenticCapability.UNIVERSAL_EVM_RULES);
37
- const chain = rule.chainNamespace;
38
- if (chain_1.CHAIN_INFO[chain]?.vm !== enums_1.VM.EVM)
39
- throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, `unsupported EVM rule chain ${chain}`);
40
- const { cea } = await runtime.resolveCEA(wallet, chain);
41
- const assets = rule.assets.length
42
- ? rule.assets.map((a) => ({
43
- token: typeof a.token === 'string' && (0, viem_1.getAddress)(a.token) === viem_1.zeroAddress
44
- ? undefined
45
- : a.token,
46
- maxPerCall: a.maxPerCall,
47
- maxTotal: (0, defaults_1.withDefault)(a.maxTotal, defaults_1.AGENTIC_DEFAULTS.universal.assetMaxTotal),
48
- }))
49
- : [{ token: undefined, maxPerCall: BigInt(0), maxTotal: BigInt(0) }];
50
- const resolved = [];
51
- for (const asset of assets) {
52
- const token = asset.token === undefined
53
- ? await (0, prc20_metadata_1.readGasPrc20)(snap, chain)
54
- : runtime.resolvePrc20(asset.token, chain);
55
- if (token === viem_1.zeroAddress)
56
- throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, `no gas PRC20 registered for ${chain}`);
57
- const namespace = await snap.read(token, prc20_metadata_1.PRC20_SOURCE_ABI, 'SOURCE_CHAIN_NAMESPACE');
58
- if (namespace !== chain)
59
- throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.ASSET_CHAIN_MISMATCH, `PRC20 ${token} belongs to ${namespace}, not ${chain}`);
60
- if (asset.token !== undefined) {
61
- const expected = typeof asset.token === 'string'
62
- ? (0, viem_1.getAddress)(asset.token)
63
- : (0, viem_1.getAddress)(asset.token.address);
64
- if (expected === viem_1.zeroAddress) {
65
- if ((await (0, prc20_metadata_1.readGasPrc20)(snap, chain)) !== (0, viem_1.getAddress)(token))
66
- throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'resolved token is not the registered native gas token');
67
- }
33
+ for (const [ruleIndex, rule] of rules.entries()) {
34
+ try {
35
+ if (rule && (0, rules_1.isSolanaRule)(rule)) {
36
+ (0, capabilities_1.requireCapability)(gen.capabilities, capabilities_1.AgenticCapability.UNIVERSAL_SVM_RULES);
37
+ svm.set(rule, await (0, svm_public_1.preparePublicSvmRule)(runtime, snap, wallet, rule));
38
+ continue;
39
+ }
40
+ if (!(0, rules_1.isUniversalRule)(rule))
41
+ continue;
42
+ if (rule.chainNamespace.startsWith('solana:'))
43
+ (0, capabilities_1.requireCapability)(gen.capabilities, capabilities_1.AgenticCapability.UNIVERSAL_SVM_RULES);
44
+ (0, universal_1.validateUniversalRuleShape)(rule, runtime.nowSeconds());
45
+ (0, capabilities_1.requireCapability)(gen.capabilities, rule.chainNamespace.startsWith('solana:')
46
+ ? capabilities_1.AgenticCapability.UNIVERSAL_SVM_RULES
47
+ : capabilities_1.AgenticCapability.UNIVERSAL_EVM_RULES);
48
+ const chain = rule.chainNamespace;
49
+ if (chain_1.CHAIN_INFO[chain]?.vm !== enums_1.VM.EVM)
50
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, `unsupported EVM rule chain ${chain}`);
51
+ const cea = await (0, destination_1.resolveRuleDestination)(runtime, wallet, chain);
52
+ const assets = rule.assets.length
53
+ ? rule.assets.map((a) => ({
54
+ token: typeof a.token === 'string' && (0, viem_1.getAddress)(a.token) === viem_1.zeroAddress
55
+ ? undefined
56
+ : a.token,
57
+ maxPerCall: a.maxPerCall,
58
+ maxTotal: (0, defaults_1.withDefault)(a.maxTotal, defaults_1.AGENTIC_DEFAULTS.universal.assetMaxTotal),
59
+ }))
60
+ : [{ token: undefined, maxPerCall: BigInt(0), maxTotal: BigInt(0) }];
61
+ const resolved = [];
62
+ for (const [assetIndex, asset] of assets.entries()) {
63
+ let token;
64
+ if (asset.token === undefined)
65
+ token = await (0, prc20_metadata_1.readGasPrc20)(snap, chain);
68
66
  else {
69
- const source = await (0, prc20_metadata_1.readOriginToken)(snap, token, chain);
70
- if (source !== expected)
71
- throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, `PRC20 ${token} represents ${source}, not requested token ${expected}`);
67
+ try {
68
+ token = runtime.resolvePrc20(asset.token, chain);
69
+ }
70
+ catch (cause) {
71
+ throw (0, errors_1.tokenRouteUnavailable)(cause, typeof asset.token === 'string'
72
+ ? asset.token
73
+ : asset.token.address, chain, assetIndex);
74
+ }
75
+ }
76
+ if (token === viem_1.zeroAddress)
77
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, `no gas PRC20 registered for ${chain}`);
78
+ const namespace = await snap.read(token, prc20_metadata_1.PRC20_SOURCE_ABI, 'SOURCE_CHAIN_NAMESPACE');
79
+ if (namespace !== chain)
80
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.ASSET_CHAIN_MISMATCH, `PRC20 ${token} belongs to ${namespace}, not ${chain}`);
81
+ if (asset.token !== undefined) {
82
+ const expected = typeof asset.token === 'string'
83
+ ? (0, viem_1.getAddress)(asset.token)
84
+ : (0, viem_1.getAddress)(asset.token.address);
85
+ if (expected === viem_1.zeroAddress) {
86
+ if ((await (0, prc20_metadata_1.readGasPrc20)(snap, chain)) !== (0, viem_1.getAddress)(token))
87
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'resolved token is not the registered native gas token');
88
+ }
89
+ else {
90
+ const source = await (0, prc20_metadata_1.readOriginToken)(snap, token, chain);
91
+ if (source !== expected)
92
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, `PRC20 ${token} represents ${source}, not requested token ${expected}`);
93
+ }
72
94
  }
95
+ resolved.push({
96
+ token: (0, viem_1.getAddress)(token),
97
+ maxPerCall: asset.maxPerCall,
98
+ maxTotal: asset.maxTotal,
99
+ });
73
100
  }
74
- resolved.push({
75
- token: (0, viem_1.getAddress)(token),
76
- maxPerCall: asset.maxPerCall,
77
- maxTotal: asset.maxTotal,
78
- });
101
+ universal.set(rule, { expectedCEA: (0, viem_1.getAddress)(cea), assets: resolved });
102
+ }
103
+ catch (error) {
104
+ throw (0, errors_1.ruleErrorContext)(error, ruleIndex, rule?.chainNamespace);
79
105
  }
80
- universal.set(rule, { expectedCEA: (0, viem_1.getAddress)(cea), assets: resolved });
81
106
  }
82
107
  return (0, rules_1.prepareRules)(rules, {
83
108
  owner,
@@ -36,6 +36,7 @@ const svm_accounts_1 = require("../codec/svm-accounts");
36
36
  const svm_idl_1 = require("../codec/svm-idl");
37
37
  const svm_terms_1 = require("../codec/svm-terms");
38
38
  const svm_terms_2 = require("../codec/svm-terms");
39
+ const errors_1 = require("../errors");
39
40
  function svmMetadata(runtime) {
40
41
  return (runtime.svmMetadata ??
41
42
  (0, svm_metadata_1.createSvmMetadataProvider)({
@@ -62,7 +63,7 @@ async function preparePublicSvmRule(runtime, snap, wallet, rule) {
62
63
  const caps = [];
63
64
  const tokenAccounts = new Map(), mints = new Set();
64
65
  const sources = [];
65
- for (const asset of requested) {
66
+ for (const [assetIndex, asset] of requested.entries()) {
66
67
  const source = typeof asset.token === 'string' ? asset.token : asset.token?.address;
67
68
  if (typeof source !== 'string')
68
69
  throw (0, svm_terms_1.svmInvalid)('asset token requires an address');
@@ -77,9 +78,17 @@ async function preparePublicSvmRule(runtime, snap, wallet, rule) {
77
78
  const sourceToken = typeof asset.token === 'string' && key
78
79
  ? new web3_js_1.PublicKey((0, viem_1.hexToBytes)(key)).toBase58()
79
80
  : asset.token;
80
- const token = native
81
- ? await (0, prc20_metadata_1.readGasPrc20)(snap, chain)
82
- : runtime.resolvePrc20(sourceToken, chain);
81
+ let token;
82
+ if (native)
83
+ token = await (0, prc20_metadata_1.readGasPrc20)(snap, chain);
84
+ else {
85
+ try {
86
+ token = runtime.resolvePrc20(sourceToken, chain);
87
+ }
88
+ catch (cause) {
89
+ throw (0, errors_1.tokenRouteUnavailable)(cause, source, chain, assetIndex);
90
+ }
91
+ }
83
92
  if (caps.some((c) => c.token === (0, viem_1.getAddress)(token)))
84
93
  throw (0, svm_terms_1.svmInvalid)('duplicate SVM asset');
85
94
  caps.push({
@@ -99,11 +99,10 @@ function buildPresetApi(catalog) {
99
99
  throw invalid('preset options must be an object');
100
100
  const now = Math.floor(Date.now() / 1000);
101
101
  const network = options.network ?? enums_1.PUSH_NETWORK.TESTNET_DONUT;
102
- const funding = options.funding ?? 'push';
103
102
  if (!Object.values(enums_1.PUSH_NETWORK).includes(network))
104
103
  throw invalid('unknown preset Push network');
105
- if (funding !== 'push' && funding !== 'destination')
106
- throw invalid('preset funding must be push or destination');
104
+ if ('funding' in options)
105
+ throw invalid('The preset funding option is no longer supported. Remove it; preset assets and limits are always preserved.');
107
106
  if (options.agent !== undefined &&
108
107
  (!(0, viem_1.isAddress)(options.agent, { strict: false }) ||
109
108
  (0, viem_1.getAddress)(options.agent) === viem_1.zeroAddress))
@@ -281,8 +280,9 @@ function buildPresetApi(catalog) {
281
280
  }
282
281
  if (!calls.length || calls.length > 32)
283
282
  throw (0, errors_1.capabilityUnavailable)('presetCalls', 'preset must contain 1..32 allowed calls including approvals');
284
- if (calls.reduce((n, c) => n + (c.pins?.length ?? 0), 0) > 32)
285
- throw (0, errors_1.capabilityUnavailable)('presetPins', 'preset expansion exceeds 32 pins; reduce the token list or split rules across wallets');
283
+ const conditionCount = calls.reduce((n, c) => n + (c.pins?.length ?? 0), 0);
284
+ if (conditionCount > 32)
285
+ throw (0, errors_1.ruleConstraintLimit)(conditionCount, calls.length, chain.chainNamespace);
286
286
  const pairs = new Map();
287
287
  for (const call of calls) {
288
288
  if (!/^[A-Za-z_$][\w$]*\(.*\)$/.test(call.selector))
@@ -326,14 +326,13 @@ function buildPresetApi(catalog) {
326
326
  message: 'No asset operation has a positive per-call limit.',
327
327
  });
328
328
  const configurationReady = issues.length === 0;
329
- const routes = (0, routes_1.presetRoutes)(chain.chainNamespace, selectedAssets, network, funding);
329
+ const routes = (0, routes_1.presetRoutes)(chain.chainNamespace, selectedAssets, network);
330
330
  issues.push(...routes.issues);
331
- const bridgeAssets = funding === 'destination' ? [] : selectedAssets;
331
+ const bridgeAssets = selectedAssets;
332
332
  readiness.push({
333
333
  chainNamespace: chain.chainNamespace,
334
334
  ready: issues.length === 0,
335
335
  configurationReady,
336
- funding,
337
336
  selectedAssets: selectedAssets.map((a) => ({
338
337
  ...a,
339
338
  token: typeof a.token === 'string' ? a.token : { ...a.token },
@@ -3,7 +3,7 @@ import type { RuleAsset } from '../agentic.types';
3
3
  import type { PresetChainReadiness, PresetConfigurationIssue } from './types';
4
4
  /** Offline registry checks only. Grant preparation still verifies source metadata
5
5
  * and wiring against chain state before any signature or transaction. */
6
- export declare function presetRoutes(chain: string, assets: RuleAsset[], network: PUSH_NETWORK, funding: 'push' | 'destination'): {
6
+ export declare function presetRoutes(chain: string, assets: RuleAsset[], network: PUSH_NETWORK): {
7
7
  bridgeAssets: PresetChainReadiness['bridgeAssets'];
8
8
  issues: PresetConfigurationIssue[];
9
9
  };