@riftresearch/sdk 0.2.3 → 0.2.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.
package/README.md CHANGED
@@ -2,19 +2,15 @@
2
2
 
3
3
  SDK for swapping between Bitcoin and EVM chains.
4
4
 
5
- ## Installation
5
+ ## Quickstart
6
+
7
+ Install the SDK:
6
8
 
7
9
  ```bash
8
10
  npm install @riftresearch/sdk
9
- # or
10
- pnpm add @riftresearch/sdk
11
- # or
12
- yarn add @riftresearch/sdk
13
- # or
14
- bun add @riftresearch/sdk
15
11
  ```
16
12
 
17
- ## Quickstart
13
+ Then use it:
18
14
 
19
15
  ```ts
20
16
  import { RiftSdk, BTC, type Currency } from '@riftresearch/sdk'
@@ -46,8 +42,8 @@ const sdk = new RiftSdk({
46
42
  publicClient,
47
43
  walletClient,
48
44
  sendBitcoin: async ({ recipient, amountSats }) => {
49
- // Only needed for BTC -> ERC20 swaps
50
- throw new Error('Not implemented')
45
+ // Implement your Bitcoin wallet connection, e.g.:
46
+ // window.bitcoin.transfer({ recipient, amountSats })
51
47
  },
52
48
  })
53
49
 
@@ -71,13 +67,3 @@ console.log(`Swap ID: ${swap.swapId}`) // API order ID
71
67
  const status = await sdk.getOrderStatus(swap.swapId)
72
68
  console.log(`Status: ${status.status}`)
73
69
  ```
74
-
75
- ## Build & Publish
76
-
77
- The SDK uses **bunup**.
78
-
79
- - Build: `bun run --filter '@riftresearch/sdk' build`
80
- - Publish (from repo root): `bun run publish:sdk`
81
- - Release (version bump + build + publish): `bun run release:sdk`
82
-
83
- The `dist/` directory is what gets published to npm.
package/dist/index.d.ts CHANGED
@@ -460,6 +460,8 @@ declare class RiftSdk {
460
460
  private assertSufficientBalance;
461
461
  private getAddress;
462
462
  private getRefundAddress;
463
+ private assertEvmChainMatch;
464
+ private assertEvmChainMatchForSteps;
463
465
  /**
464
466
  * Get the current status of an order by its ID.
465
467
  */
package/dist/index.js CHANGED
@@ -192,6 +192,7 @@ class RiftSdk {
192
192
  refundAddress,
193
193
  approvalMode: params.approvalMode
194
194
  });
195
+ this.assertEvmChainMatchForSteps(orderResponse.executionSteps);
195
196
  for (const step of orderResponse.executionSteps) {
196
197
  const result = await this.executeStep(step);
197
198
  if (isMonochain && step.action === "evm_call" && step.kind === "oneinch_swap" && result.txHash) {
@@ -285,6 +286,7 @@ class RiftSdk {
285
286
  async assertSufficientBalance(currency, amount) {
286
287
  if (currency.chain.kind !== "EVM")
287
288
  return;
289
+ this.assertEvmChainMatch(currency.chain.chainId);
288
290
  const required = BigInt(amount);
289
291
  const owner = this.getAddress();
290
292
  if (currency.token.kind === "NATIVE") {
@@ -317,6 +319,35 @@ class RiftSdk {
317
319
  }
318
320
  return this.getAddress();
319
321
  }
322
+ assertEvmChainMatch(expectedChainId) {
323
+ const walletChainId = this.walletClient.chain?.id;
324
+ if (!walletChainId) {
325
+ throw new Error("Wallet client is missing an EVM chain configuration");
326
+ }
327
+ if (walletChainId !== expectedChainId) {
328
+ throw new Error(`Wallet client chain mismatch. Expected ${expectedChainId}, got ${walletChainId}`);
329
+ }
330
+ const publicChainId = this.publicClient.chain?.id;
331
+ if (!publicChainId) {
332
+ throw new Error("Public client is missing an EVM chain configuration");
333
+ }
334
+ if (publicChainId !== expectedChainId) {
335
+ throw new Error(`Public client chain mismatch. Expected ${expectedChainId}, got ${publicChainId}`);
336
+ }
337
+ }
338
+ assertEvmChainMatchForSteps(steps) {
339
+ const evmSteps = steps.filter((step) => step.action === "evm_call");
340
+ const firstStep = evmSteps[0];
341
+ if (!firstStep)
342
+ return;
343
+ const expectedChainId = firstStep.chainId;
344
+ for (const step of evmSteps) {
345
+ if (step.chainId !== expectedChainId) {
346
+ throw new Error(`Mixed EVM chain IDs in execution steps. Expected ${expectedChainId}, got ${step.chainId}`);
347
+ }
348
+ }
349
+ this.assertEvmChainMatch(expectedChainId);
350
+ }
320
351
  async getOrderStatus(orderId) {
321
352
  return this.riftClient.getOrder(orderId);
322
353
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riftresearch/sdk",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "SDK for swapping between bitcoin and evm chains",
5
5
  "license": "MIT",
6
6
  "files": [