@riftresearch/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/README.md CHANGED
@@ -68,7 +68,7 @@ const swap = await executeSwap()
68
68
  console.log(`Swap ID: ${swap.swapId}`) // API order ID
69
69
 
70
70
  // Check status
71
- const status = await sdk.getSwapStatus(swap.swapId)
71
+ const status = await sdk.getOrderStatus(swap.swapId)
72
72
  console.log(`Status: ${status.status}`)
73
73
  ```
74
74
 
package/dist/index.d.ts CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Core domain types for Rift Swap Router.
3
+ * Shared between SDK and server packages.
4
+ */
5
+ type Address = string;
6
+ type TxHash = string;
1
7
  type U256 = string;
2
8
  type BitcoinChain = {
3
9
  kind: "BITCOIN";
@@ -124,6 +130,10 @@ type QuoteResponse = ExactInputQuoteResponse | ExactOutputQuoteResponse;
124
130
  type OrderStatus = "waiting_for_deposit" | "deposit_confirming" | "initiating_transfer" | "confirming_transfer" | "swap_complete" | "refunding_user" | "failed";
125
131
  interface OrderStatusResponse {
126
132
  status: OrderStatus;
133
+ destinationAddress: Address;
134
+ payoutTransaction?: TxHash;
135
+ depositTransaction?: TxHash;
136
+ quote: QuoteResponse;
127
137
  }
128
138
  /**
129
139
  * Execution actions - the mechanism by which a step is executed.
@@ -359,9 +369,9 @@ interface ExactOutputQuoteResult extends QuoteResultBase {
359
369
  type QuoteResult = ExactInputQuoteResult | ExactOutputQuoteResult;
360
370
  interface GetQuoteResult {
361
371
  quote: QuoteResult;
362
- executeSwap: () => Promise<SwapResult>;
372
+ executeSwap: () => Promise<OrderResult>;
363
373
  }
364
- interface SwapResult {
374
+ interface OrderResult {
365
375
  swapId: string;
366
376
  status: SwapStatus2;
367
377
  rift: RiftOrder;
@@ -440,12 +450,12 @@ declare class RiftSdk {
440
450
  */
441
451
  private executeBtcTransferStep;
442
452
  private buildQuoteResult;
443
- private buildSwapResult;
453
+ private buildOrderResult;
444
454
  private getAddress;
445
455
  private getRefundAddress;
446
456
  /**
447
- * Get the current status of a swap by its ID.
457
+ * Get the current status of an order by its ID.
448
458
  */
449
- getSwapStatus(swapId: string): Promise<SwapResult>;
459
+ getOrderStatus(orderId: string): Promise<OrderStatusResponse>;
450
460
  }
451
- export { getSupportedModes, detectRoute, createClient, TradeParameters, TokenIdentifier, SwapStatus2 as SwapStatus, SwapRoute, SwapResult, SupportedModes, SendBitcoinFn, RiftSdkOptions, RiftSdk, RiftOrder, RiftClient, QuoteResult, OrderResponse, NativeToken, GetQuoteResult, ExecutionStep, ExecutionAction, EvmChain, EvmCallStep, EvmCallKind, Erc20Token, Currency, Chain, CBBTC_ETHEREUM, CBBTC_BASE, BtcTransferStep, BtcTransferKind, BitcoinChain, BTC, App };
461
+ export { getSupportedModes, detectRoute, createClient, TradeParameters, TokenIdentifier, SwapStatus2 as SwapStatus, SwapRoute, SupportedModes, SendBitcoinFn, RiftSdkOptions, RiftSdk, RiftOrder, RiftClient, QuoteResult, OrderResult, OrderResponse, NativeToken, GetQuoteResult, ExecutionStep, ExecutionAction, EvmChain, EvmCallStep, EvmCallKind, Erc20Token, Currency, Chain, CBBTC_ETHEREUM, CBBTC_BASE, BtcTransferStep, BtcTransferKind, BitcoinChain, BTC, App };
package/dist/index.js CHANGED
@@ -1,6 +1,35 @@
1
+ // ../common/src/constants.ts
2
+ var CBBTC_ADDRESS = "0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf";
3
+ var CBBTC_ADDRESS_LOWER = CBBTC_ADDRESS.toLowerCase();
4
+ var BTC_CHAIN = {
5
+ kind: "BITCOIN"
6
+ };
7
+ var ETH_CHAIN = {
8
+ kind: "EVM",
9
+ chainId: 1
10
+ };
11
+ var BASE_CHAIN = {
12
+ kind: "EVM",
13
+ chainId: 8453
14
+ };
15
+ var CBBTC_TOKEN = {
16
+ kind: "TOKEN",
17
+ address: CBBTC_ADDRESS,
18
+ decimals: 8
19
+ };
20
+ var BTC = {
21
+ chain: BTC_CHAIN,
22
+ token: { kind: "NATIVE", decimals: 8 }
23
+ };
24
+ var CBBTC_ETHEREUM = {
25
+ chain: ETH_CHAIN,
26
+ token: CBBTC_TOKEN
27
+ };
28
+ var CBBTC_BASE = {
29
+ chain: BASE_CHAIN,
30
+ token: CBBTC_TOKEN
31
+ };
1
32
  // src/apiClient.ts
2
- import { BTC, CBBTC_BASE, CBBTC_ETHEREUM } from "@riftresearch/common";
3
-
4
33
  class SwapRouterApiError extends Error {
5
34
  status;
6
35
  body;
@@ -67,20 +96,20 @@ function createClient(baseUrl) {
67
96
  }
68
97
  // src/router.ts
69
98
  import { match, P } from "ts-pattern";
70
- var CBBTC_ADDRESS = "0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf";
99
+ var CBBTC_ADDRESS2 = "0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf";
71
100
  var isBitcoin = (currency) => currency.chain.kind === "BITCOIN";
72
- var isCbBtc = (currency) => currency.chain.kind === "EVM" && currency.token.kind === "TOKEN" && currency.token.address.toLowerCase() === CBBTC_ADDRESS;
73
- var isEvmToken = (currency) => currency.chain.kind === "EVM";
74
- var isSameEvmChain = (a, b) => a.chain.kind === "EVM" && b.chain.kind === "EVM" && a.chain.chainId === b.chain.chainId;
101
+ var isCbBtc = (currency) => currency.chain.kind === "EVM" && currency.token.kind === "TOKEN" && currency.token.address.toLowerCase() === CBBTC_ADDRESS2;
102
+ var isEvmToken2 = (currency) => currency.chain.kind === "EVM";
103
+ var isSameEvmChain2 = (a, b) => a.chain.kind === "EVM" && b.chain.kind === "EVM" && a.chain.chainId === b.chain.chainId;
75
104
  function detectRoute(from, to) {
76
105
  return match({ from, to }).with({ from: P.when(isCbBtc), to: P.when(isBitcoin) }, () => ({
77
106
  type: "direct_rift",
78
107
  direction: "to_btc"
79
- })).with({ from: P.when(isBitcoin), to: P.when(isEvmToken) }, () => ({
108
+ })).with({ from: P.when(isBitcoin), to: P.when(isEvmToken2) }, () => ({
80
109
  type: "direct_rift",
81
110
  direction: "from_btc"
82
111
  })).with({
83
- from: P.when((c) => isEvmToken(c) && !isCbBtc(c)),
112
+ from: P.when((c) => isEvmToken2(c) && !isCbBtc(c)),
84
113
  to: P.when(isBitcoin)
85
114
  }, ({ from: from2 }) => {
86
115
  if (from2.chain.kind !== "EVM") {
@@ -91,8 +120,8 @@ function detectRoute(from, to) {
91
120
  evmChainId: from2.chain.chainId
92
121
  };
93
122
  }).with({
94
- from: P.when(isEvmToken),
95
- to: P.when((c) => isEvmToken(c) && isSameEvmChain(from, to))
123
+ from: P.when(isEvmToken2),
124
+ to: P.when((c) => isEvmToken2(c) && isSameEvmChain2(from, to))
96
125
  }, ({ from: from2 }) => {
97
126
  if (from2.chain.kind !== "EVM") {
98
127
  throw new Error("Expected EVM chain");
@@ -168,7 +197,7 @@ class RiftSdk {
168
197
  }
169
198
  }
170
199
  const swap = await this.riftClient.getOrder(orderResponse.swapId);
171
- return this.buildSwapResult(swap, {
200
+ return this.buildOrderResult(swap, {
172
201
  chained: isChained,
173
202
  riftOrderId: orderResponse.swapId
174
203
  });
@@ -237,10 +266,10 @@ class RiftSdk {
237
266
  };
238
267
  }
239
268
  }
240
- buildSwapResult(swap, options) {
269
+ buildOrderResult(swap, options) {
241
270
  const riftOrderId = options?.riftOrderId;
242
271
  if (!riftOrderId) {
243
- throw new Error("Missing rift order id for swap result.");
272
+ throw new Error("Missing rift order id for order result.");
244
273
  }
245
274
  return {
246
275
  swapId: riftOrderId,
@@ -261,13 +290,8 @@ class RiftSdk {
261
290
  }
262
291
  return this.getAddress();
263
292
  }
264
- async getSwapStatus(swapId) {
265
- const rift = await this.riftClient.getOrder(swapId);
266
- return {
267
- swapId,
268
- status: rift.status,
269
- rift
270
- };
293
+ async getOrderStatus(orderId) {
294
+ return this.riftClient.getOrder(orderId);
271
295
  }
272
296
  }
273
297
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riftresearch/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "SDK for swapping between bitcoin and evm chains",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -12,9 +12,12 @@
12
12
  "test": "bun test",
13
13
  "test:coverage": "bun test --coverage",
14
14
  "test:watch": "bun test --watch",
15
- "type-check": "tsc --noEmit"
15
+ "type-check": "tsc --noEmit",
16
+ "verify:publish": "node ../../scripts/verify-publish.mjs package.json",
17
+ "prepublishOnly": "bun run build && node ../../scripts/verify-publish.mjs package.json"
16
18
  },
17
19
  "devDependencies": {
20
+ "@riftresearch/common": "workspace:*",
18
21
  "@riftresearch/server": "workspace:*",
19
22
  "@types/bun": "^1.3.6",
20
23
  "bunup": "^0.16.20",
@@ -44,7 +47,6 @@
44
47
  "types": "./dist/index.d.ts",
45
48
  "dependencies": {
46
49
  "@elysiajs/eden": "^1.4.5",
47
- "@riftresearch/common": "workspace:*",
48
50
  "@scure/base": "^2.0.0",
49
51
  "@scure/btc-signer": "^2.0.1",
50
52
  "ts-pattern": "^5.9.0"