@rhinestone/sdk 1.5.1 → 2.0.0-beta.1

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 (136) hide show
  1. package/README.md +1 -1
  2. package/dist/src/accounts/error.d.ts +1 -1
  3. package/dist/src/accounts/error.js +1 -19
  4. package/dist/src/accounts/index.d.ts +5 -5
  5. package/dist/src/accounts/index.js +121 -157
  6. package/dist/src/accounts/json-rpc/index.d.ts +1 -1
  7. package/dist/src/accounts/json-rpc/index.js +8 -10
  8. package/dist/src/accounts/json-rpc/providers.d.ts +1 -1
  9. package/dist/src/accounts/json-rpc/providers.d.ts.map +1 -1
  10. package/dist/src/accounts/json-rpc/providers.js +7 -9
  11. package/dist/src/accounts/kernel.d.ts +3 -3
  12. package/dist/src/accounts/kernel.js +66 -75
  13. package/dist/src/accounts/nexus.d.ts +3 -3
  14. package/dist/src/accounts/nexus.js +62 -73
  15. package/dist/src/accounts/passport.d.ts +3 -3
  16. package/dist/src/accounts/passport.js +9 -13
  17. package/dist/src/accounts/safe.d.ts +3 -3
  18. package/dist/src/accounts/safe.js +54 -63
  19. package/dist/src/accounts/signing/common.d.ts +2 -2
  20. package/dist/src/accounts/signing/common.js +30 -36
  21. package/dist/src/accounts/signing/message.d.ts +2 -2
  22. package/dist/src/accounts/signing/message.js +10 -12
  23. package/dist/src/accounts/signing/passkeys.js +11 -17
  24. package/dist/src/accounts/signing/typedData.d.ts +1 -1
  25. package/dist/src/accounts/signing/typedData.js +6 -8
  26. package/dist/src/accounts/startale.d.ts +3 -3
  27. package/dist/src/accounts/startale.js +37 -47
  28. package/dist/src/accounts/utils.d.ts +2 -2
  29. package/dist/src/accounts/utils.js +22 -28
  30. package/dist/src/accounts/walletClient.js +4 -8
  31. package/dist/src/actions/compact.d.ts +1 -1
  32. package/dist/src/actions/compact.js +22 -35
  33. package/dist/src/actions/deployment.d.ts +1 -1
  34. package/dist/src/actions/deployment.js +11 -13
  35. package/dist/src/actions/ecdsa.d.ts +1 -1
  36. package/dist/src/actions/ecdsa.js +14 -20
  37. package/dist/src/actions/index.d.ts +2 -2
  38. package/dist/src/actions/index.js +6 -10
  39. package/dist/src/actions/mfa.d.ts +1 -1
  40. package/dist/src/actions/mfa.js +18 -24
  41. package/dist/src/actions/passkeys.d.ts +2 -2
  42. package/dist/src/actions/passkeys.js +14 -20
  43. package/dist/src/actions/recovery.d.ts +1 -1
  44. package/dist/src/actions/recovery.js +25 -29
  45. package/dist/src/actions/smart-sessions.d.ts +1 -1
  46. package/dist/src/actions/smart-sessions.js +8 -12
  47. package/dist/src/auth/provider.d.ts +1 -1
  48. package/dist/src/auth/provider.js +1 -4
  49. package/dist/src/errors/index.d.ts +4 -4
  50. package/dist/src/errors/index.d.ts.map +1 -1
  51. package/dist/src/errors/index.js +12 -54
  52. package/dist/src/execution/compact.d.ts +1 -144
  53. package/dist/src/execution/compact.d.ts.map +1 -1
  54. package/dist/src/execution/compact.js +1 -117
  55. package/dist/src/execution/error.d.ts +10 -1
  56. package/dist/src/execution/error.d.ts.map +1 -1
  57. package/dist/src/execution/error.js +9 -11
  58. package/dist/src/execution/index.d.ts +10 -11
  59. package/dist/src/execution/index.d.ts.map +1 -1
  60. package/dist/src/execution/index.js +64 -75
  61. package/dist/src/execution/permit2.d.ts +2 -138
  62. package/dist/src/execution/permit2.d.ts.map +1 -1
  63. package/dist/src/execution/permit2.js +5 -239
  64. package/dist/src/execution/utils.d.ts +31 -15
  65. package/dist/src/execution/utils.d.ts.map +1 -1
  66. package/dist/src/execution/utils.js +283 -256
  67. package/dist/src/index.d.ts +15 -14
  68. package/dist/src/index.d.ts.map +1 -1
  69. package/dist/src/index.js +57 -68
  70. package/dist/src/jwt-server/digest.js +3 -6
  71. package/dist/src/jwt-server/express.d.ts +1 -1
  72. package/dist/src/jwt-server/express.d.ts.map +1 -1
  73. package/dist/src/jwt-server/express.js +6 -7
  74. package/dist/src/jwt-server/handlers.d.ts +1 -1
  75. package/dist/src/jwt-server/handlers.js +7 -11
  76. package/dist/src/jwt-server/index.d.ts +7 -7
  77. package/dist/src/jwt-server/index.js +6 -17
  78. package/dist/src/jwt-server/jcs.js +1 -4
  79. package/dist/src/jwt-server/signer.d.ts +1 -1
  80. package/dist/src/jwt-server/signer.js +10 -13
  81. package/dist/src/jwt-server/sponsorship.js +2 -7
  82. package/dist/src/jwt-server/web.d.ts +1 -1
  83. package/dist/src/jwt-server/web.js +5 -9
  84. package/dist/src/modules/abi/smart-session-emissary.js +1 -3
  85. package/dist/src/modules/abi/smart-sessions.js +1 -4
  86. package/dist/src/modules/chain-abstraction.js +1 -5
  87. package/dist/src/modules/common.d.ts +1 -1
  88. package/dist/src/modules/common.js +1 -13
  89. package/dist/src/modules/index.d.ts +5 -5
  90. package/dist/src/modules/index.js +35 -50
  91. package/dist/src/modules/legacy.d.ts +2 -2
  92. package/dist/src/modules/legacy.js +11 -14
  93. package/dist/src/modules/read.d.ts +1 -1
  94. package/dist/src/modules/read.js +11 -15
  95. package/dist/src/modules/validators/core.d.ts +2 -2
  96. package/dist/src/modules/validators/core.js +26 -44
  97. package/dist/src/modules/validators/index.d.ts +2 -2
  98. package/dist/src/modules/validators/index.js +3 -19
  99. package/dist/src/modules/validators/policies/claim/permit2.d.ts +1 -1
  100. package/dist/src/modules/validators/policies/claim/permit2.js +39 -44
  101. package/dist/src/modules/validators/policies/claim/types.js +11 -14
  102. package/dist/src/modules/validators/smart-sessions.d.ts +3 -3
  103. package/dist/src/modules/validators/smart-sessions.js +65 -94
  104. package/dist/src/orchestrator/caip2.d.ts +7 -0
  105. package/dist/src/orchestrator/caip2.d.ts.map +1 -0
  106. package/dist/src/orchestrator/caip2.js +17 -0
  107. package/dist/src/orchestrator/client.d.ts +12 -12
  108. package/dist/src/orchestrator/client.d.ts.map +1 -1
  109. package/dist/src/orchestrator/client.js +199 -305
  110. package/dist/src/orchestrator/consts.d.ts +2 -2
  111. package/dist/src/orchestrator/consts.d.ts.map +1 -1
  112. package/dist/src/orchestrator/consts.js +3 -9
  113. package/dist/src/orchestrator/error.d.ts +72 -217
  114. package/dist/src/orchestrator/error.d.ts.map +1 -1
  115. package/dist/src/orchestrator/error.js +117 -227
  116. package/dist/src/orchestrator/index.d.ts +9 -9
  117. package/dist/src/orchestrator/index.d.ts.map +1 -1
  118. package/dist/src/orchestrator/index.js +7 -56
  119. package/dist/src/orchestrator/registry.d.ts +2 -2
  120. package/dist/src/orchestrator/registry.js +19 -33
  121. package/dist/src/orchestrator/types.d.ts +97 -232
  122. package/dist/src/orchestrator/types.d.ts.map +1 -1
  123. package/dist/src/orchestrator/types.js +1 -17
  124. package/dist/src/orchestrator/utils.js +1 -3
  125. package/dist/src/types.d.ts +5 -7
  126. package/dist/src/types.d.ts.map +1 -1
  127. package/dist/src/types.js +1 -2
  128. package/dist/src/utils/index.d.ts +2 -2
  129. package/dist/src/utils/index.js +9 -15
  130. package/package.json +15 -98
  131. package/dist/src/execution/singleChainOps.d.ts +0 -41
  132. package/dist/src/execution/singleChainOps.d.ts.map +0 -1
  133. package/dist/src/execution/singleChainOps.js +0 -44
  134. package/dist/src/execution/types.d.ts +0 -36
  135. package/dist/src/execution/types.d.ts.map +0 -1
  136. package/dist/src/execution/types.js +0 -2
@@ -1,29 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SignerNotSupportedError = exports.SessionChainRequiredError = exports.OrderPathRequiredForIntentsError = exports.IntentStatusTimeoutError = exports.IntentFailedError = exports.ExecutionError = exports.isExecutionError = void 0;
4
- exports.sendTransaction = sendTransaction;
5
- exports.sendTransactionInternal = sendTransactionInternal;
6
- exports.sendUserOperation = sendUserOperation;
7
- exports.sendUserOperationInternal = sendUserOperationInternal;
8
- exports.waitForExecution = waitForExecution;
9
- exports.getPortfolio = getPortfolio;
10
- exports.getIntentStatus = getIntentStatus;
11
- exports.splitIntents = splitIntents;
12
- const viem_1 = require("viem");
13
- const accounts_1 = require("../accounts");
14
- const utils_1 = require("../accounts/utils");
15
- const provider_1 = require("../auth/provider");
16
- const orchestrator_1 = require("../orchestrator");
17
- const registry_1 = require("../orchestrator/registry");
18
- const error_1 = require("./error");
19
- Object.defineProperty(exports, "ExecutionError", { enumerable: true, get: function () { return error_1.ExecutionError; } });
20
- Object.defineProperty(exports, "IntentFailedError", { enumerable: true, get: function () { return error_1.IntentFailedError; } });
21
- Object.defineProperty(exports, "IntentStatusTimeoutError", { enumerable: true, get: function () { return error_1.IntentStatusTimeoutError; } });
22
- Object.defineProperty(exports, "isExecutionError", { enumerable: true, get: function () { return error_1.isExecutionError; } });
23
- Object.defineProperty(exports, "OrderPathRequiredForIntentsError", { enumerable: true, get: function () { return error_1.OrderPathRequiredForIntentsError; } });
24
- Object.defineProperty(exports, "SessionChainRequiredError", { enumerable: true, get: function () { return error_1.SessionChainRequiredError; } });
25
- Object.defineProperty(exports, "SignerNotSupportedError", { enumerable: true, get: function () { return error_1.SignerNotSupportedError; } });
26
- const utils_2 = require("./utils");
1
+ import { createPublicClient } from 'viem';
2
+ import { deploy, getAddress } from '../accounts/index.js';
3
+ import { createTransport, getBundlerClient } from '../accounts/utils.js';
4
+ import { createAuthProvider } from '../auth/provider.js';
5
+ import { getOrchestrator, INTENT_STATUS_COMPLETED, INTENT_STATUS_FAILED, INTENT_STATUS_FILLED, INTENT_STATUS_PRECONFIRMED, isRateLimited, isRetryable, } from '../orchestrator/index.js';
6
+ import { getChainById, getSupportedChainIds, isTestnet, } from '../orchestrator/registry.js';
7
+ import { ExecutionError, IntentFailedError, IntentStatusTimeoutError, isExecutionError, OrderPathRequiredForIntentsError, QuoteNotInPreparedTransactionError, SessionChainRequiredError, SignerNotSupportedError, } from './error.js';
8
+ import { getTargetExecutionSignature, getTokenRequests, getValidatorAccount, parseCalls, prepareTransactionAsIntent, resolveCallInputs, signAuthorizationsInternal, signIntent, submitIntentInternal, } from './utils.js';
27
9
  const POLL_INITIAL_MS = 500;
28
10
  const POLL_SLOW_AFTER_MS = 15000;
29
11
  const POLL_SLOW_MS = 2000;
@@ -36,7 +18,7 @@ async function sendTransaction(config, transaction) {
36
18
  const { calls, gasLimit, tokenRequests, recipient, signers, sponsored, eip7702InitSignature, settlementLayers, sourceAssets, feeAsset, } = transaction;
37
19
  const isUserOpSigner = signers?.type === 'guardians';
38
20
  if (isUserOpSigner) {
39
- throw new error_1.SignerNotSupportedError();
21
+ throw new SignerNotSupportedError();
40
22
  }
41
23
  return await sendTransactionInternal(config, sourceChains, targetChain, {
42
24
  callInputs: calls,
@@ -52,35 +34,35 @@ async function sendTransaction(config, transaction) {
52
34
  });
53
35
  }
54
36
  async function sendUserOperation(config, transaction) {
55
- const accountAddress = (0, accounts_1.getAddress)(config);
56
- const resolvedCalls = await (0, utils_2.resolveCallInputs)(transaction.calls, config, transaction.chain, accountAddress);
37
+ const accountAddress = getAddress(config);
38
+ const resolvedCalls = await resolveCallInputs(transaction.calls, config, transaction.chain, accountAddress);
57
39
  return await sendUserOperationInternal(config, transaction.chain, resolvedCalls, transaction.signers);
58
40
  }
59
41
  async function sendTransactionInternal(config, sourceChains, targetChain, options) {
60
- const accountAddress = (0, accounts_1.getAddress)(config);
61
- const resolvedCalls = await (0, utils_2.resolveCallInputs)(options.callInputs, config, targetChain, accountAddress);
62
- const tokenRequests = (0, utils_2.getTokenRequests)(targetChain, options.initialTokenRequests);
42
+ const accountAddress = getAddress(config);
43
+ const resolvedCalls = await resolveCallInputs(options.callInputs, config, targetChain, accountAddress);
44
+ const tokenRequests = getTokenRequests(targetChain, options.initialTokenRequests);
63
45
  const sendAsUserOp = options.signers?.type === 'guardians';
64
46
  if (sendAsUserOp) {
65
- throw new error_1.SignerNotSupportedError();
47
+ throw new SignerNotSupportedError();
66
48
  }
67
49
  else {
68
- return await sendTransactionAsIntent(config, sourceChains, targetChain, resolvedCalls, options.gasLimit, tokenRequests, options.recipient, options.signers, options.sponsored, options.eip7702InitSignature, options.settlementLayers, options.sourceAssets, options.feeAsset, options.lockFunds);
50
+ return await sendTransactionAsIntent(config, sourceChains, targetChain, resolvedCalls, options.gasLimit, tokenRequests, options.recipient, options.signers, options.sponsored, options.eip7702InitSignature, options.settlementLayers, options.sourceAssets, options.feeAsset);
69
51
  }
70
52
  }
71
53
  async function sendUserOperationInternal(config, chain, callInputs, signers) {
72
54
  // Make sure the account is deployed
73
- await (0, accounts_1.deploy)(config, chain);
74
- const publicClient = (0, viem_1.createPublicClient)({
55
+ await deploy(config, chain);
56
+ const publicClient = createPublicClient({
75
57
  chain,
76
- transport: (0, utils_1.createTransport)(chain, config.provider),
58
+ transport: createTransport(chain, config.provider),
77
59
  });
78
- const validatorAccount = await (0, utils_2.getValidatorAccount)(config, signers, publicClient, chain);
60
+ const validatorAccount = await getValidatorAccount(config, signers, publicClient, chain);
79
61
  if (!validatorAccount) {
80
62
  throw new Error('No validator account found');
81
63
  }
82
- const bundlerClient = (0, utils_1.getBundlerClient)(config, publicClient);
83
- const calls = (0, utils_2.parseCalls)(callInputs, chain.id);
64
+ const bundlerClient = getBundlerClient(config, publicClient);
65
+ const calls = parseCalls(callInputs, chain.id);
84
66
  const hash = await bundlerClient.sendUserOperation({
85
67
  account: validatorAccount,
86
68
  calls,
@@ -91,27 +73,32 @@ async function sendUserOperationInternal(config, chain, callInputs, signers) {
91
73
  chain: chain.id,
92
74
  };
93
75
  }
94
- async function sendTransactionAsIntent(config, sourceChains, targetChain, callInputs, gasLimit, tokenRequests, recipient, signers, sponsored, eip7702InitSignature, settlementLayers, sourceAssets, feeAsset, lockFunds) {
95
- const prepared = await (0, utils_2.prepareTransactionAsIntent)(config, sourceChains, targetChain, callInputs, gasLimit, tokenRequests, recipient, sponsored ?? false, eip7702InitSignature, settlementLayers, sourceAssets, feeAsset, lockFunds, undefined, undefined, signers);
76
+ async function sendTransactionAsIntent(config, sourceChains, targetChain, callInputs, gasLimit, tokenRequests, recipient, signers, sponsored, eip7702InitSignature, settlementLayers, sourceAssets, feeAsset) {
77
+ const prepared = await prepareTransactionAsIntent(config, sourceChains, targetChain, callInputs, gasLimit, tokenRequests, recipient, sponsored ?? false, eip7702InitSignature, settlementLayers, sourceAssets, feeAsset, undefined, undefined, signers);
96
78
  if (!prepared) {
97
- throw new error_1.OrderPathRequiredForIntentsError();
79
+ throw new OrderPathRequiredForIntentsError();
98
80
  }
99
- const { intentRoute, intentInput } = prepared;
100
- const { originSignatures, destinationSignature } = await (0, utils_2.signIntent)(config, intentRoute.intentOp, targetChain, signers);
101
- const targetExecutionSignature = await (0, utils_2.getTargetExecutionSignature)(config, intentRoute.intentOp, targetChain, signers);
81
+ const { quotes, intentInput } = prepared;
82
+ const quote = quotes.best;
83
+ const { originSignatures, destinationSignature } = await signIntent(config, quote.signData, targetChain, signers);
84
+ const targetExecutionSignature = await getTargetExecutionSignature(config, quote.signData, targetChain, signers);
102
85
  const authorizations = config.eoa
103
- ? await (0, utils_2.signAuthorizationsInternal)(config, intentRoute)
86
+ ? await signAuthorizationsInternal(config, {
87
+ sourceChains,
88
+ targetChain,
89
+ eip7702InitSignature,
90
+ })
104
91
  : [];
105
- return await (0, utils_2.submitIntentInternal)(config, sourceChains, targetChain, intentRoute.intentOp, originSignatures, destinationSignature, targetExecutionSignature, authorizations, false, intentInput);
92
+ return await submitIntentInternal(config, sourceChains, targetChain, quote, originSignatures, destinationSignature, targetExecutionSignature, authorizations, false, intentInput);
106
93
  }
107
94
  async function waitForExecution(config, result, acceptsPreconfirmations) {
108
95
  const validStatuses = new Set([
109
- orchestrator_1.INTENT_STATUS_FAILED,
110
- orchestrator_1.INTENT_STATUS_COMPLETED,
111
- orchestrator_1.INTENT_STATUS_FILLED,
96
+ INTENT_STATUS_FAILED,
97
+ INTENT_STATUS_COMPLETED,
98
+ INTENT_STATUS_FILLED,
112
99
  ]);
113
100
  if (acceptsPreconfirmations) {
114
- validStatuses.add(orchestrator_1.INTENT_STATUS_PRECONFIRMED);
101
+ validStatuses.add(INTENT_STATUS_PRECONFIRMED);
115
102
  }
116
103
  switch (result.type) {
117
104
  case 'intent': {
@@ -122,15 +109,15 @@ async function waitForExecution(config, result, acceptsPreconfirmations) {
122
109
  while (intentStatus === null || !validStatuses.has(intentStatus.status)) {
123
110
  const now = Date.now();
124
111
  if (now - startTs >= POLL_MAX_WAIT_MS) {
125
- throw new error_1.IntentStatusTimeoutError({
112
+ throw new IntentStatusTimeoutError({
126
113
  context: {
127
- intentId: result.id.toString(),
114
+ intentId: result.id,
128
115
  },
129
116
  });
130
117
  }
131
- const orchestrator = (0, orchestrator_1.getOrchestrator)(config._authProvider ?? (0, provider_1.createAuthProvider)(config), config.endpointUrl, config.headers);
118
+ const orchestrator = getOrchestrator(config._authProvider ?? createAuthProvider(config), config.endpointUrl, config.headers);
132
119
  try {
133
- intentStatus = await orchestrator.getIntentOpStatus(result.id);
120
+ intentStatus = await orchestrator.getIntent(result.id);
134
121
  // reset error backoff on success
135
122
  errorBackoffMs = POLL_ERROR_BACKOFF_MS;
136
123
  const elapsed = Date.now() - startTs;
@@ -139,8 +126,8 @@ async function waitForExecution(config, result, acceptsPreconfirmations) {
139
126
  await new Promise((resolve) => setTimeout(resolve, nextDelayMs));
140
127
  }
141
128
  catch (err) {
142
- if ((0, orchestrator_1.isRateLimited)(err)) {
143
- const retryAfter = err?.context?.retryAfter;
129
+ if (isRateLimited(err)) {
130
+ const retryAfter = err.retryAfter;
144
131
  let retryMs = nextDelayMs;
145
132
  if (retryAfter) {
146
133
  const parsed = Number(retryAfter);
@@ -160,7 +147,7 @@ async function waitForExecution(config, result, acceptsPreconfirmations) {
160
147
  await new Promise((resolve) => setTimeout(resolve, retryMs));
161
148
  continue;
162
149
  }
163
- if ((0, orchestrator_1.isRetryable)(err)) {
150
+ if (isRetryable(err)) {
164
151
  const backoff = Math.min(errorBackoffMs, POLL_ERROR_BACKOFF_MAX_MS);
165
152
  errorBackoffMs = Math.min(errorBackoffMs * 2, POLL_ERROR_BACKOFF_MAX_MS);
166
153
  await new Promise((resolve) => setTimeout(resolve, backoff));
@@ -169,11 +156,10 @@ async function waitForExecution(config, result, acceptsPreconfirmations) {
169
156
  throw err;
170
157
  }
171
158
  }
172
- if (intentStatus.status === orchestrator_1.INTENT_STATUS_FAILED) {
173
- const intentId = result.id.toString();
174
- throw new error_1.IntentFailedError({
159
+ if (intentStatus.status === INTENT_STATUS_FAILED) {
160
+ throw new IntentFailedError({
175
161
  context: {
176
- intentId,
162
+ intentId: result.id,
177
163
  },
178
164
  });
179
165
  }
@@ -189,12 +175,12 @@ async function waitForExecution(config, result, acceptsPreconfirmations) {
189
175
  };
190
176
  }
191
177
  case 'userop': {
192
- const targetChain = (0, registry_1.getChainById)(result.chain);
193
- const publicClient = (0, viem_1.createPublicClient)({
178
+ const targetChain = getChainById(result.chain);
179
+ const publicClient = createPublicClient({
194
180
  chain: targetChain,
195
- transport: (0, utils_1.createTransport)(targetChain, config.provider),
181
+ transport: createTransport(targetChain, config.provider),
196
182
  });
197
- const bundlerClient = (0, utils_1.getBundlerClient)(config, publicClient);
183
+ const bundlerClient = getBundlerClient(config, publicClient);
198
184
  const receipt = await bundlerClient.waitForUserOperationReceipt({
199
185
  hash: result.hash,
200
186
  });
@@ -203,12 +189,12 @@ async function waitForExecution(config, result, acceptsPreconfirmations) {
203
189
  }
204
190
  }
205
191
  async function getPortfolio(config, onTestnets) {
206
- const address = (0, accounts_1.getAddress)(config);
207
- const orchestrator = (0, orchestrator_1.getOrchestrator)(config._authProvider ?? (0, provider_1.createAuthProvider)(config), config.endpointUrl, config.headers);
208
- const supportedChainIds = (0, registry_1.getSupportedChainIds)();
192
+ const address = getAddress(config);
193
+ const orchestrator = getOrchestrator(config._authProvider ?? createAuthProvider(config), config.endpointUrl, config.headers);
194
+ const supportedChainIds = getSupportedChainIds();
209
195
  const filteredChainIds = supportedChainIds.filter((id) => {
210
196
  try {
211
- return (0, registry_1.isTestnet)(id) === onTestnets;
197
+ return isTestnet(id) === onTestnets;
212
198
  }
213
199
  catch {
214
200
  return false;
@@ -217,8 +203,8 @@ async function getPortfolio(config, onTestnets) {
217
203
  return orchestrator.getPortfolio(address, { chainIds: filteredChainIds });
218
204
  }
219
205
  async function getIntentStatus(authProvider, endpointUrl, intentId, headers) {
220
- const orchestrator = (0, orchestrator_1.getOrchestrator)(authProvider, endpointUrl, headers);
221
- const internalStatus = await orchestrator.getIntentOpStatus(intentId);
206
+ const orchestrator = getOrchestrator(authProvider, endpointUrl, headers);
207
+ const internalStatus = await orchestrator.getIntent(intentId);
222
208
  return {
223
209
  status: internalStatus.status,
224
210
  fill: {
@@ -232,6 +218,9 @@ async function getIntentStatus(authProvider, endpointUrl, intentId, headers) {
232
218
  };
233
219
  }
234
220
  async function splitIntents(authProvider, endpointUrl, input, headers) {
235
- const orchestrator = (0, orchestrator_1.getOrchestrator)(authProvider, endpointUrl, headers);
236
- return orchestrator.splitIntents(input);
221
+ const orchestrator = getOrchestrator(authProvider, endpointUrl, headers);
222
+ return orchestrator.getSplit(input);
237
223
  }
224
+ export { sendTransaction, sendTransactionInternal, sendUserOperation, sendUserOperationInternal, waitForExecution, getPortfolio, getIntentStatus, splitIntents,
225
+ // Errors
226
+ isExecutionError, ExecutionError, IntentFailedError, IntentStatusTimeoutError, OrderPathRequiredForIntentsError, QuoteNotInPreparedTransactionError, SessionChainRequiredError, SignerNotSupportedError, };
@@ -1,143 +1,7 @@
1
1
  import { type Address, type Chain } from 'viem';
2
- import type { IntentOpElement } from '../orchestrator/types';
3
- import type { RhinestoneConfig } from '../types';
4
- import type { BatchPermit2Result, MultiChainPermit2Config, MultiChainPermit2Result, TokenPermissions } from './types';
5
- declare function getTypedData(element: IntentOpElement, nonce: bigint, expires: bigint): {
6
- readonly domain: {
7
- readonly name: "Permit2";
8
- readonly chainId: number;
9
- readonly verifyingContract: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
10
- };
11
- readonly types: {
12
- readonly TokenPermissions: readonly [{
13
- readonly name: "token";
14
- readonly type: "address";
15
- }, {
16
- readonly name: "amount";
17
- readonly type: "uint256";
18
- }];
19
- readonly Token: readonly [{
20
- readonly name: "token";
21
- readonly type: "address";
22
- }, {
23
- readonly name: "amount";
24
- readonly type: "uint256";
25
- }];
26
- readonly Target: readonly [{
27
- readonly name: "recipient";
28
- readonly type: "address";
29
- }, {
30
- readonly name: "tokenOut";
31
- readonly type: "Token[]";
32
- }, {
33
- readonly name: "targetChain";
34
- readonly type: "uint256";
35
- }, {
36
- readonly name: "fillExpiry";
37
- readonly type: "uint256";
38
- }];
39
- readonly Ops: readonly [{
40
- readonly name: "to";
41
- readonly type: "address";
42
- }, {
43
- readonly name: "value";
44
- readonly type: "uint256";
45
- }, {
46
- readonly name: "data";
47
- readonly type: "bytes";
48
- }];
49
- readonly Op: readonly [{
50
- readonly name: "vt";
51
- readonly type: "bytes32";
52
- }, {
53
- readonly name: "ops";
54
- readonly type: "Ops[]";
55
- }];
56
- readonly Mandate: readonly [{
57
- readonly name: "target";
58
- readonly type: "Target";
59
- }, {
60
- readonly name: "minGas";
61
- readonly type: "uint128";
62
- }, {
63
- readonly name: "originOps";
64
- readonly type: "Op";
65
- }, {
66
- readonly name: "destOps";
67
- readonly type: "Op";
68
- }, {
69
- readonly name: "q";
70
- readonly type: "bytes32";
71
- }];
72
- readonly PermitBatchWitnessTransferFrom: readonly [{
73
- readonly name: "permitted";
74
- readonly type: "TokenPermissions[]";
75
- }, {
76
- readonly name: "spender";
77
- readonly type: "address";
78
- }, {
79
- readonly name: "nonce";
80
- readonly type: "uint256";
81
- }, {
82
- readonly name: "deadline";
83
- readonly type: "uint256";
84
- }, {
85
- readonly name: "mandate";
86
- readonly type: "Mandate";
87
- }];
88
- };
89
- readonly primaryType: "PermitBatchWitnessTransferFrom";
90
- readonly message: {
91
- readonly permitted: TokenPermissions[];
92
- readonly spender: `0x${string}`;
93
- readonly nonce: bigint;
94
- readonly deadline: bigint;
95
- readonly mandate: {
96
- readonly target: {
97
- readonly recipient: `0x${string}`;
98
- readonly tokenOut: {
99
- token: `0x${string}`;
100
- amount: bigint;
101
- }[];
102
- readonly targetChain: bigint;
103
- readonly fillExpiry: bigint;
104
- };
105
- readonly minGas: bigint;
106
- readonly originOps: import("../orchestrator/types").Op;
107
- readonly destOps: import("../orchestrator/types").Op;
108
- readonly q: `0x${string}`;
109
- };
110
- };
111
- };
2
+ import type { RhinestoneConfig } from '../types.js';
112
3
  declare function checkERC20AllowanceDirect(owner: Address, spender: Address, tokenAddress: Address, publicClient: any): Promise<bigint>;
113
4
  declare function checkERC20Allowance(tokenAddress: Address, chain: Chain, config: RhinestoneConfig): Promise<bigint>;
114
- /**
115
- * Get the Permit2 contract address
116
- * @returns The Permit2 contract address
117
- */
118
5
  declare function getPermit2Address(): Address;
119
- /**
120
- * Signs permit2 calls across multiple chains using batch approach.
121
- * Collects all signatures first, then returns them all at once.
122
- *
123
- * This approach is efficient for backend signers but may be memory-intensive
124
- * for frontend applications with many chains.
125
- *
126
- * @param configs - Array of permit2 signing configurations for different chains
127
- * @returns Promise<BatchPermit2Result> - All signatures collected
128
- */
129
- declare function signPermit2Batch(configs: MultiChainPermit2Config[]): Promise<BatchPermit2Result>;
130
- /**
131
- * Signs permit2 calls across multiple chains sequentially.
132
- * Signs one by one, useful for frontend applications to avoid memory issues.
133
- *
134
- * This approach is more memory-efficient for frontend applications but slower
135
- * due to sequential processing.
136
- *
137
- * @param configs - Array of permit2 signing configurations for different chains
138
- * @param onProgress - Optional callback for progress updates
139
- * @returns Promise<BatchPermit2Result> - All signatures collected
140
- */
141
- declare function signPermit2Sequential(configs: MultiChainPermit2Config[], onProgress?: (completed: number, total: number, current: MultiChainPermit2Result) => void): Promise<BatchPermit2Result>;
142
- export { getTypedData, checkERC20Allowance, checkERC20AllowanceDirect, getPermit2Address, signPermit2Batch, signPermit2Sequential, type MultiChainPermit2Config, type MultiChainPermit2Result, type BatchPermit2Result, };
6
+ export { checkERC20Allowance, checkERC20AllowanceDirect, getPermit2Address };
143
7
  //# sourceMappingURL=permit2.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"permit2.d.ts","sourceRoot":"","sources":["../../../execution/permit2.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,KAAK,EAIX,MAAM,MAAM,CAAA;AAEb,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAChD,OAAO,KAAK,EACV,kBAAkB,EAClB,uBAAuB,EACvB,uBAAuB,EACvB,gBAAgB,EACjB,MAAM,SAAS,CAAA;AAQhB,iBAAS,YAAY,CACnB,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwFhB;AAED,iBAAe,yBAAyB,CACtC,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,OAAO,EACrB,YAAY,EAAE,GAAG,GAChB,OAAO,CAAC,MAAM,CAAC,CAyBjB;AAED,iBAAe,mBAAmB,CAChC,YAAY,EAAE,OAAO,EACrB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,MAAM,CAAC,CAuBjB;AAED;;;GAGG;AACH,iBAAS,iBAAiB,IAAI,OAAO,CAEpC;AAED;;;;;;;;;GASG;AACH,iBAAe,gBAAgB,CAC7B,OAAO,EAAE,uBAAuB,EAAE,GACjC,OAAO,CAAC,kBAAkB,CAAC,CAyE7B;AAED;;;;;;;;;;GAUG;AACH,iBAAe,qBAAqB,CAClC,OAAO,EAAE,uBAAuB,EAAE,EAClC,UAAU,CAAC,EAAE,CACX,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,uBAAuB,KAC7B,IAAI,GACR,OAAO,CAAC,kBAAkB,CAAC,CA8D7B;AAED,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB,EAEjB,gBAAgB,EAChB,qBAAqB,EAErB,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,GACxB,CAAA"}
1
+ {"version":3,"file":"permit2.d.ts","sourceRoot":"","sources":["../../../execution/permit2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,KAAK,EAAsB,MAAM,MAAM,CAAA;AAEnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAIhD,iBAAe,yBAAyB,CACtC,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,OAAO,EACrB,YAAY,EAAE,GAAG,GAChB,OAAO,CAAC,MAAM,CAAC,CAyBjB;AAED,iBAAe,mBAAmB,CAChC,YAAY,EAAE,OAAO,EACrB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,MAAM,CAAC,CAuBjB;AAED,iBAAS,iBAAiB,IAAI,OAAO,CAEpC;AAED,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,CAAA"}
@@ -1,101 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTypedData = getTypedData;
4
- exports.checkERC20Allowance = checkERC20Allowance;
5
- exports.checkERC20AllowanceDirect = checkERC20AllowanceDirect;
6
- exports.getPermit2Address = getPermit2Address;
7
- exports.signPermit2Batch = signPermit2Batch;
8
- exports.signPermit2Sequential = signPermit2Sequential;
9
- const viem_1 = require("viem");
10
- const utils_1 = require("../accounts/utils");
1
+ import { createPublicClient } from 'viem';
2
+ import { createTransport } from '../accounts/utils.js';
11
3
  const PERMIT2_ADDRESS = '0x000000000022D473030F116dDEE9F6B43aC78BA3';
12
- function toToken(id) {
13
- return `0x${(id & ((1n << 160n) - 1n)).toString(16).padStart(40, '0')}`;
14
- }
15
- function getTypedData(element, nonce, expires) {
16
- const tokens = element.idsAndAmounts.map(([id, amount]) => [
17
- BigInt(id),
18
- BigInt(amount),
19
- ]);
20
- const tokenPermissions = tokens.reduce((permissions, [id, amountIn]) => {
21
- const token = toToken(BigInt(id));
22
- const amount = BigInt(amountIn);
23
- const permission = { token, amount };
24
- permissions.push(permission);
25
- return permissions;
26
- }, []);
27
- const spender = element.arbiter;
28
- const mandate = element.mandate;
29
- const typedData = {
30
- domain: {
31
- name: 'Permit2',
32
- chainId: Number(element.chainId),
33
- verifyingContract: PERMIT2_ADDRESS,
34
- },
35
- types: {
36
- TokenPermissions: [
37
- { name: 'token', type: 'address' },
38
- { name: 'amount', type: 'uint256' },
39
- ],
40
- Token: [
41
- { name: 'token', type: 'address' },
42
- { name: 'amount', type: 'uint256' },
43
- ],
44
- Target: [
45
- { name: 'recipient', type: 'address' },
46
- { name: 'tokenOut', type: 'Token[]' },
47
- { name: 'targetChain', type: 'uint256' },
48
- { name: 'fillExpiry', type: 'uint256' },
49
- ],
50
- Ops: [
51
- { name: 'to', type: 'address' },
52
- { name: 'value', type: 'uint256' },
53
- { name: 'data', type: 'bytes' },
54
- ],
55
- Op: [
56
- { name: 'vt', type: 'bytes32' },
57
- { name: 'ops', type: 'Ops[]' },
58
- ],
59
- Mandate: [
60
- { name: 'target', type: 'Target' },
61
- { name: 'minGas', type: 'uint128' },
62
- { name: 'originOps', type: 'Op' },
63
- { name: 'destOps', type: 'Op' },
64
- { name: 'q', type: 'bytes32' },
65
- ],
66
- PermitBatchWitnessTransferFrom: [
67
- { name: 'permitted', type: 'TokenPermissions[]' },
68
- { name: 'spender', type: 'address' },
69
- { name: 'nonce', type: 'uint256' },
70
- { name: 'deadline', type: 'uint256' },
71
- { name: 'mandate', type: 'Mandate' },
72
- ],
73
- },
74
- primaryType: 'PermitBatchWitnessTransferFrom',
75
- message: {
76
- permitted: tokenPermissions,
77
- spender: spender,
78
- nonce: nonce,
79
- deadline: expires,
80
- mandate: {
81
- target: {
82
- recipient: mandate.recipient,
83
- tokenOut: mandate.tokenOut.map((token) => ({
84
- token: toToken(BigInt(token[0])),
85
- amount: BigInt(token[1]),
86
- })),
87
- targetChain: BigInt(mandate.destinationChainId),
88
- fillExpiry: BigInt(mandate.fillDeadline),
89
- },
90
- minGas: BigInt(mandate.minGas),
91
- originOps: mandate.preClaimOps,
92
- destOps: mandate.destinationOps,
93
- q: (0, viem_1.keccak256)(mandate.qualifier.encodedVal),
94
- },
95
- },
96
- };
97
- return typedData;
98
- }
99
4
  async function checkERC20AllowanceDirect(owner, spender, tokenAddress, publicClient) {
100
5
  try {
101
6
  const allowance = await publicClient.readContract({
@@ -124,9 +29,9 @@ async function checkERC20AllowanceDirect(owner, spender, tokenAddress, publicCli
124
29
  }
125
30
  async function checkERC20Allowance(tokenAddress, chain, config) {
126
31
  try {
127
- const publicClient = (0, viem_1.createPublicClient)({
32
+ const publicClient = createPublicClient({
128
33
  chain,
129
- transport: (0, utils_1.createTransport)(chain, config.provider),
34
+ transport: createTransport(chain, config.provider),
130
35
  });
131
36
  // Get the account owner from the config
132
37
  const owner = config.eoa?.address;
@@ -140,146 +45,7 @@ async function checkERC20Allowance(tokenAddress, chain, config) {
140
45
  throw new Error('Failed to check ERC20 allowance');
141
46
  }
142
47
  }
143
- /**
144
- * Get the Permit2 contract address
145
- * @returns The Permit2 contract address
146
- */
147
48
  function getPermit2Address() {
148
49
  return PERMIT2_ADDRESS;
149
50
  }
150
- /**
151
- * Signs permit2 calls across multiple chains using batch approach.
152
- * Collects all signatures first, then returns them all at once.
153
- *
154
- * This approach is efficient for backend signers but may be memory-intensive
155
- * for frontend applications with many chains.
156
- *
157
- * @param configs - Array of permit2 signing configurations for different chains
158
- * @returns Promise<BatchPermit2Result> - All signatures collected
159
- */
160
- async function signPermit2Batch(configs) {
161
- const results = [];
162
- let successfulSignatures = 0;
163
- let failedSignatures = 0;
164
- // Process all signing operations in parallel
165
- const signingPromises = configs.map(async (config) => {
166
- try {
167
- // sign each element individually for this chain sequentially to preserve order
168
- if (!config.eoaAccount.signTypedData) {
169
- throw new Error('EOA account does not support typed data signing');
170
- }
171
- const originSignatures = [];
172
- for (const element of config.intentOp.elements) {
173
- const typedData = getTypedData(element, BigInt(config.intentOp.nonce), BigInt(config.intentOp.expires));
174
- const sig = await config.eoaAccount.signTypedData(typedData);
175
- originSignatures.push(sig);
176
- }
177
- const result = {
178
- chainId: config.chain.id,
179
- originSignatures,
180
- destinationSignature: originSignatures[0] ?? '0x',
181
- success: true,
182
- };
183
- successfulSignatures++;
184
- return result;
185
- }
186
- catch (error) {
187
- const result = {
188
- chainId: config.chain.id,
189
- originSignatures: [],
190
- destinationSignature: '0x',
191
- success: false,
192
- error: error instanceof Error ? error : new Error(String(error)),
193
- };
194
- failedSignatures++;
195
- return result;
196
- }
197
- });
198
- // Wait for all signing operations to complete
199
- const signingResults = await Promise.allSettled(signingPromises);
200
- for (const result of signingResults) {
201
- if (result.status === 'fulfilled') {
202
- results.push(result.value);
203
- }
204
- else {
205
- // This shouldn't happen since we catch errors in the promise
206
- failedSignatures++;
207
- results.push({
208
- chainId: 0,
209
- originSignatures: [],
210
- destinationSignature: '0x',
211
- success: false,
212
- error: result.reason,
213
- });
214
- }
215
- }
216
- return {
217
- results,
218
- totalChains: configs.length,
219
- successfulSignatures,
220
- failedSignatures,
221
- allSuccessful: failedSignatures === 0,
222
- };
223
- }
224
- /**
225
- * Signs permit2 calls across multiple chains sequentially.
226
- * Signs one by one, useful for frontend applications to avoid memory issues.
227
- *
228
- * This approach is more memory-efficient for frontend applications but slower
229
- * due to sequential processing.
230
- *
231
- * @param configs - Array of permit2 signing configurations for different chains
232
- * @param onProgress - Optional callback for progress updates
233
- * @returns Promise<BatchPermit2Result> - All signatures collected
234
- */
235
- async function signPermit2Sequential(configs, onProgress) {
236
- const results = [];
237
- let successfulSignatures = 0;
238
- let failedSignatures = 0;
239
- // Process signing operations sequentially
240
- for (let i = 0; i < configs.length; i++) {
241
- const config = configs[i];
242
- try {
243
- // sign each element for this chain sequentially to preserve order
244
- if (!config.eoaAccount.signTypedData) {
245
- throw new Error('EOA account does not support typed data signing');
246
- }
247
- const originSignatures = [];
248
- for (const element of config.intentOp.elements) {
249
- const typedData = getTypedData(element, BigInt(config.intentOp.nonce), BigInt(config.intentOp.expires));
250
- const sig = await config.eoaAccount.signTypedData(typedData);
251
- originSignatures.push(sig);
252
- }
253
- const result = {
254
- chainId: config.chain.id,
255
- originSignatures,
256
- destinationSignature: originSignatures[0] ?? '0x',
257
- success: true,
258
- };
259
- results.push(result);
260
- successfulSignatures++;
261
- // Call progress callback if provided
262
- onProgress?.(i + 1, configs.length, result);
263
- }
264
- catch (error) {
265
- const result = {
266
- chainId: config.chain.id,
267
- originSignatures: [],
268
- destinationSignature: '0x',
269
- success: false,
270
- error: error instanceof Error ? error : new Error(String(error)),
271
- };
272
- results.push(result);
273
- failedSignatures++;
274
- // Call progress callback if provided
275
- onProgress?.(i + 1, configs.length, result);
276
- }
277
- }
278
- return {
279
- results,
280
- totalChains: configs.length,
281
- successfulSignatures,
282
- failedSignatures,
283
- allSuccessful: failedSignatures === 0,
284
- };
285
- }
51
+ export { checkERC20Allowance, checkERC20AllowanceDirect, getPermit2Address };