@riftresearch/sdk 0.4.0 → 0.4.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/README.md CHANGED
@@ -28,14 +28,10 @@ const walletClient = createWalletClient({
28
28
  transport: http(process.env.ETH_RPC),
29
29
  })
30
30
 
31
- // Bitcoin sender implementation
32
- const sendBitcoin = async ({ recipient, amountSats }) => {
33
- // Implement your Bitcoin wallet connection, e.g.:
34
- // window.bitcoin.transfer({ recipient, amountSats })
35
- }
36
-
37
- // Initialize SDK
38
- const sdk = new RiftSdk({})
31
+ // Initialize SDK (use your app name for analytics/support)
32
+ const sdk = new RiftSdk({
33
+ integratorName: "sdk-demo",
34
+ })
39
35
 
40
36
  // Optionally create a custom ERC-20
41
37
  const ethereumPepe = createCurrency({
@@ -60,7 +56,9 @@ console.log(`Fees: $${quote.fees.totalUsd.toFixed(2)}`)
60
56
  const swap = await executeSwap({
61
57
  publicClient,
62
58
  walletClient,
63
- sendBitcoin,
59
+ sendBitcoin: async ({ recipient, amountSats }) => {
60
+ // Call your bitcoin wallet's transfer function here
61
+ },
64
62
  })
65
63
  console.log(`Swap ID: ${swap.swapId}`)
66
64
 
package/dist/index.d.ts CHANGED
@@ -430,6 +430,8 @@ type ExecuteSwapContext<chain extends Chain2 | undefined = Chain2 | undefined> =
430
430
  interface RiftSdkOptions {
431
431
  /** Rift API URL. Defaults to production API */
432
432
  apiUrl?: string;
433
+ /** Enable verbose debug logging for swap execution */
434
+ debug?: boolean;
433
435
  /** Optional preflight checks before executing swaps */
434
436
  preflight?: {
435
437
  /** Check sender balance before executing EVM steps (default: true) */
@@ -442,7 +444,9 @@ declare class RiftSdk {
442
444
  private riftClient;
443
445
  private preflightCheckBalances;
444
446
  private integratorName;
447
+ private debug;
445
448
  constructor(options: RiftSdkOptions);
449
+ private logDebug;
446
450
  /**
447
451
  * Get a quote for a swap and return a function to execute it.
448
452
  *
package/dist/index.js CHANGED
@@ -212,12 +212,23 @@ class RiftSdk {
212
212
  riftClient;
213
213
  preflightCheckBalances;
214
214
  integratorName;
215
+ debug;
215
216
  constructor(options) {
216
217
  this.riftClient = new SwapRouterClient({
217
218
  baseUrl: options.apiUrl ?? "https://router-api-v2-production.up.railway.app"
218
219
  });
219
220
  this.preflightCheckBalances = options.preflight?.checkBalances !== false;
220
221
  this.integratorName = options.integratorName;
222
+ this.debug = options.debug ?? false;
223
+ }
224
+ logDebug(message, data) {
225
+ if (!this.debug)
226
+ return;
227
+ if (data) {
228
+ console.log(`[RiftSdk] ${message}`, data);
229
+ return;
230
+ }
231
+ console.log(`[RiftSdk] ${message}`);
221
232
  }
222
233
  async getQuote(params) {
223
234
  const route = detectRoute(params.from, params.to);
@@ -234,10 +245,20 @@ class RiftSdk {
234
245
  return {
235
246
  quote,
236
247
  executeSwap: async (context = {}) => {
248
+ this.logDebug("executeSwap called", {
249
+ route: route.type,
250
+ mode: params.mode,
251
+ from: params.from,
252
+ to: params.to,
253
+ amount: params.amount
254
+ });
237
255
  const refundAddress = params.refundAddress ?? this.getRefundAddress(params, context);
256
+ this.logDebug("resolved refund address", { refundAddress });
238
257
  if (this.preflightCheckBalances) {
258
+ this.logDebug("running preflight balance check");
239
259
  await this.assertSufficientBalance(params.from, quote.from.amount, context);
240
260
  }
261
+ this.logDebug("creating swap", { quoteId: riftQuote.id });
241
262
  const swapResponse = await this.riftClient.createSwap({
242
263
  id: riftQuote.id,
243
264
  destinationAddress: params.destinationAddress,
@@ -245,17 +266,42 @@ class RiftSdk {
245
266
  integratorName: this.integratorName,
246
267
  approvalMode: params.approvalMode
247
268
  });
269
+ this.logDebug("swap created", {
270
+ swapId: swapResponse.swapId,
271
+ steps: swapResponse.executionSteps.length
272
+ });
248
273
  this.assertEvmChainMatchForSteps(swapResponse.executionSteps, context);
249
274
  for (const step of swapResponse.executionSteps) {
275
+ this.logDebug("executing step", {
276
+ stepId: step.id,
277
+ action: step.action,
278
+ kind: "kind" in step ? step.kind : undefined,
279
+ chainId: "chainId" in step ? step.chainId : undefined
280
+ });
250
281
  const result = await this.executeStep(step, context);
282
+ this.logDebug("step completed", {
283
+ stepId: step.id,
284
+ txHash: result.txHash
285
+ });
251
286
  if (isMonochain && step.action === "evm_call" && step.kind === "oneinch_swap" && result.txHash) {
287
+ this.logDebug("reporting step result", {
288
+ stepId: step.id,
289
+ oneinchSwap: true
290
+ });
252
291
  await this.riftClient.reportStepResult(swapResponse.swapId, {
253
292
  stepId: step.id,
254
293
  ...result
255
294
  });
256
295
  }
257
296
  }
297
+ this.logDebug("fetching swap status", {
298
+ swapId: swapResponse.swapId
299
+ });
258
300
  const swap = await this.riftClient.getSwap(swapResponse.swapId);
301
+ this.logDebug("swap fetched", {
302
+ swapId: swapResponse.swapId,
303
+ status: swap.status
304
+ });
259
305
  return this.buildSwapResult(swap, {
260
306
  chained: isChained,
261
307
  riftSwapId: swapResponse.swapId
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riftresearch/sdk",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "SDK for swapping between bitcoin and evm chains",
5
5
  "license": "MIT",
6
6
  "files": [