@realmint/sdk 0.2.0 → 0.2.2
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 +5 -0
- package/dist/client.js +31 -3
- package/dist/types.d.ts +5 -5
- package/package.json +1 -1
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:
|
|
215
|
+
source_tx_hash: sourceTxHash,
|
|
190
216
|
});
|
|
191
217
|
return this.waitForSettlement(created.intent_id, opts);
|
|
192
218
|
}
|
|
@@ -205,9 +231,11 @@ export class RealmintClient {
|
|
|
205
231
|
* → poll. One Solana signature; gas is relayer-sponsored.
|
|
206
232
|
*/
|
|
207
233
|
async sellSolana(params, signWire, opts = {}) {
|
|
208
|
-
|
|
234
|
+
// destination_chain_id 0 selects the Solana sell lane (else the deployment
|
|
235
|
+
// lookup excludes Solana and 422s with no_sell_deployment).
|
|
236
|
+
const created = await this.createIntent({ destination_chain_id: 0, ...params, action: "sell" });
|
|
209
237
|
const prep = await this.prepareSolanaSell(created.intent_id);
|
|
210
|
-
const signed = await signWire(prep.
|
|
238
|
+
const signed = await signWire(prep.transaction);
|
|
211
239
|
await this.submitSolanaSell(created.intent_id, signed);
|
|
212
240
|
return this.waitForSettlement(created.intent_id, opts);
|
|
213
241
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -96,11 +96,11 @@ export interface GetIntentResponse {
|
|
|
96
96
|
steps: unknown[];
|
|
97
97
|
}
|
|
98
98
|
export interface PrepareSolanaSellResponse {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
/** Base64 V0 transaction wire, partially signed (relayer); the user co-signs it. */
|
|
100
|
+
transaction: string;
|
|
101
|
+
min_usdc_out_raw: string;
|
|
102
|
+
/** The Solana pubkey expected to co-sign (the seller's Realmint Wallet). */
|
|
103
|
+
signer: string;
|
|
104
104
|
}
|
|
105
105
|
/** Terminal-ish states the SDK's waiters stop on. */
|
|
106
106
|
export declare const TERMINAL_STATES: readonly ["completed", "terminal_failed", "expired", "cancelled"];
|
package/package.json
CHANGED