@realmint/sdk 0.2.0 → 0.2.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.
package/dist/client.d.ts CHANGED
@@ -56,6 +56,11 @@ export declare class RealmintClient {
56
56
  }>;
57
57
  /** Submit a signed UserOp directly to the bundler; returns the userOp hash. */
58
58
  submitUserOp(bundlerUrl: string, signedUserOp: Record<string, unknown>, entrypoint: string): Promise<Hex>;
59
+ /**
60
+ * Poll the bundler for a UserOp receipt until it's mined; returns the source
61
+ * transaction hash (what `execute` needs). Throws if the UserOp reverts.
62
+ */
63
+ waitForUserOp(bundlerUrl: string, userOpHash: Hex, opts?: WaitOptions): Promise<string>;
59
64
  private bundlerRpc;
60
65
  /** Poll the intent until it reaches a terminal state (or times out). */
61
66
  waitForSettlement(intentId: string, opts?: WaitOptions): Promise<RouteIntent>;
package/dist/client.js CHANGED
@@ -133,6 +133,28 @@ export class RealmintClient {
133
133
  ]);
134
134
  return result;
135
135
  }
136
+ /**
137
+ * Poll the bundler for a UserOp receipt until it's mined; returns the source
138
+ * transaction hash (what `execute` needs). Throws if the UserOp reverts.
139
+ */
140
+ async waitForUserOp(bundlerUrl, userOpHash, opts = {}) {
141
+ const timeoutMs = opts.timeoutMs ?? 120_000;
142
+ const pollMs = opts.pollMs ?? 2_000;
143
+ const deadline = Date.now() + timeoutMs;
144
+ while (Date.now() < deadline) {
145
+ const receipt = (await this.bundlerRpc(bundlerUrl, "eth_getUserOperationReceipt", [
146
+ userOpHash,
147
+ ]));
148
+ if (receipt) {
149
+ if (receipt.success === false) {
150
+ throw new RealmintError("Source UserOp reverted on-chain", 200, receipt);
151
+ }
152
+ return receipt.receipt?.transactionHash ?? userOpHash;
153
+ }
154
+ await sleep(pollMs);
155
+ }
156
+ throw new RealmintError(`Timed out waiting for UserOp ${userOpHash} to be mined`, 408, null);
157
+ }
136
158
  async bundlerRpc(bundlerUrl, method, params) {
137
159
  const res = await this.fetchImpl(bundlerUrl, {
138
160
  method: "POST",
@@ -184,9 +206,13 @@ export class RealmintClient {
184
206
  const signedUserOp = { ...prep.source_user_op, signature };
185
207
  const entrypoint = prep.entrypoint_address ?? account.entrypoint_address;
186
208
  const userOpHash = await this.submitUserOp(account.bundler_url, signedUserOp, entrypoint);
209
+ // `execute` requires the source tx to be MINED (else 400 source_tx_not_mined);
210
+ // a UserOp hash is not a tx hash. Wait for inclusion, then execute with the
211
+ // real source tx hash before the quote expires.
212
+ const sourceTxHash = await this.waitForUserOp(account.bundler_url, userOpHash, opts);
187
213
  await this.executeIntent(created.intent_id, {
188
214
  agent_wallet: params.agent_wallet,
189
- source_tx_hash: userOpHash,
215
+ source_tx_hash: sourceTxHash,
190
216
  });
191
217
  return this.waitForSettlement(created.intent_id, opts);
192
218
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realmint/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "TypeScript SDK for the Realmint API — list, buy, and sell tokenized RWAs (non-custodial; the partner's signer signs).",
5
5
  "license": "MIT",
6
6
  "type": "module",