@riftresearch/sdk 0.2.4 → 0.3.0
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 +14 -16
- package/dist/index.d.ts +28 -9
- package/dist/index.js +69 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,28 +13,19 @@ npm install @riftresearch/sdk
|
|
|
13
13
|
Then use it:
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
|
-
import { RiftSdk,
|
|
16
|
+
import { RiftSdk, Currencies, createCurrency } from '@riftresearch/sdk'
|
|
17
17
|
import { createPublicClient, createWalletClient, http } from 'viem'
|
|
18
18
|
import { privateKeyToAccount } from 'viem/accounts'
|
|
19
|
-
import {
|
|
19
|
+
import { ethereum } from 'viem/chains'
|
|
20
20
|
|
|
21
|
-
// Define USDC on Base
|
|
22
|
-
const USDC_BASE: Currency = {
|
|
23
|
-
chain: { kind: 'EVM', chainId: 8453 },
|
|
24
|
-
token: {
|
|
25
|
-
kind: 'TOKEN',
|
|
26
|
-
address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
|
|
27
|
-
decimals: 6,
|
|
28
|
-
},
|
|
29
|
-
}
|
|
30
21
|
|
|
31
22
|
// Setup viem clients
|
|
32
23
|
const account = privateKeyToAccount('0x...')
|
|
33
|
-
const publicClient = createPublicClient({ chain:
|
|
24
|
+
const publicClient = createPublicClient({ chain: ethereum, transport: http(process.env.ETH_RPC) })
|
|
34
25
|
const walletClient = createWalletClient({
|
|
35
26
|
account,
|
|
36
|
-
chain:
|
|
37
|
-
transport: http(),
|
|
27
|
+
chain: ethereum,
|
|
28
|
+
transport: http(process.env.ETH_RPC),
|
|
38
29
|
})
|
|
39
30
|
|
|
40
31
|
// Initialize SDK
|
|
@@ -47,10 +38,17 @@ const sdk = new RiftSdk({
|
|
|
47
38
|
},
|
|
48
39
|
})
|
|
49
40
|
|
|
41
|
+
// Optionally create a custom ERC-20
|
|
42
|
+
const ethereumPepe = createCurrency({
|
|
43
|
+
chainId: 1,
|
|
44
|
+
address: '0x6982508145454Ce325dDbE47a25d4ec3d2311933',
|
|
45
|
+
decimals: 18,
|
|
46
|
+
})
|
|
47
|
+
|
|
50
48
|
// Get a quote
|
|
51
49
|
const { quote, executeSwap } = await sdk.getQuote({
|
|
52
|
-
from:
|
|
53
|
-
to: BTC,
|
|
50
|
+
from: Currencies.Ethereum.USDC,
|
|
51
|
+
to: Currencies.Bitcoin.BTC,
|
|
54
52
|
amount: '100000000', // 100 USDC (6 decimals)
|
|
55
53
|
mode: 'exact_input',
|
|
56
54
|
destinationAddress: 'bc1q...',
|
package/dist/index.d.ts
CHANGED
|
@@ -202,12 +202,31 @@ interface OrderResponse {
|
|
|
202
202
|
/** Ordered list of steps the client must execute */
|
|
203
203
|
executionSteps: ExecutionStep[];
|
|
204
204
|
}
|
|
205
|
-
/**
|
|
206
|
-
declare
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
205
|
+
/** Create an ERC-20 currency on an EVM chain */
|
|
206
|
+
declare function createCurrency(params: {
|
|
207
|
+
chainId: number;
|
|
208
|
+
address: string;
|
|
209
|
+
decimals: number;
|
|
210
|
+
}): Currency;
|
|
211
|
+
declare const Currencies: {
|
|
212
|
+
Bitcoin: {
|
|
213
|
+
BTC: Currency;
|
|
214
|
+
};
|
|
215
|
+
Ethereum: {
|
|
216
|
+
ETH: Currency;
|
|
217
|
+
WETH: Currency;
|
|
218
|
+
USDC: Currency;
|
|
219
|
+
USDT: Currency;
|
|
220
|
+
CBBTC: Currency;
|
|
221
|
+
WBTC: Currency;
|
|
222
|
+
};
|
|
223
|
+
Base: {
|
|
224
|
+
ETH: Currency;
|
|
225
|
+
WETH: Currency;
|
|
226
|
+
USDC: Currency;
|
|
227
|
+
CBBTC: Currency;
|
|
228
|
+
};
|
|
229
|
+
};
|
|
211
230
|
import { treaty } from "@elysiajs/eden";
|
|
212
231
|
import { Elysia } from "elysia";
|
|
213
232
|
declare const app: Elysia;
|
|
@@ -430,8 +449,8 @@ declare class RiftSdk {
|
|
|
430
449
|
*
|
|
431
450
|
* @example
|
|
432
451
|
* const { quote, executeSwap } = await sdk.getQuote({
|
|
433
|
-
* from:
|
|
434
|
-
* to: BTC,
|
|
452
|
+
* from: Currencies.Base.CBBTC,
|
|
453
|
+
* to: Currencies.Bitcoin.BTC,
|
|
435
454
|
* amount: '100000000', // 1 cbBTC
|
|
436
455
|
* mode: 'exact_input',
|
|
437
456
|
* destinationAddress: 'bc1q...',
|
|
@@ -467,4 +486,4 @@ declare class RiftSdk {
|
|
|
467
486
|
*/
|
|
468
487
|
getOrderStatus(orderId: string): Promise<OrderStatusResponse>;
|
|
469
488
|
}
|
|
470
|
-
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,
|
|
489
|
+
export { getSupportedModes, detectRoute, createCurrency, 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, Currencies, Chain, BtcTransferStep, BtcTransferKind, BitcoinChain, App };
|
package/dist/index.js
CHANGED
|
@@ -17,17 +17,73 @@ var CBBTC_TOKEN = {
|
|
|
17
17
|
address: CBBTC_ADDRESS,
|
|
18
18
|
decimals: 8
|
|
19
19
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
function createCurrency(params) {
|
|
21
|
+
return {
|
|
22
|
+
chain: { kind: "EVM", chainId: params.chainId },
|
|
23
|
+
token: {
|
|
24
|
+
kind: "TOKEN",
|
|
25
|
+
address: params.address,
|
|
26
|
+
decimals: params.decimals
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
var Currencies = {
|
|
31
|
+
Bitcoin: {
|
|
32
|
+
BTC: {
|
|
33
|
+
chain: BTC_CHAIN,
|
|
34
|
+
token: { kind: "NATIVE", decimals: 8 }
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
Ethereum: {
|
|
38
|
+
ETH: {
|
|
39
|
+
chain: ETH_CHAIN,
|
|
40
|
+
token: { kind: "NATIVE", decimals: 18 }
|
|
41
|
+
},
|
|
42
|
+
WETH: createCurrency({
|
|
43
|
+
chainId: 1,
|
|
44
|
+
address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
45
|
+
decimals: 18
|
|
46
|
+
}),
|
|
47
|
+
USDC: createCurrency({
|
|
48
|
+
chainId: 1,
|
|
49
|
+
address: "0xA0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
|
50
|
+
decimals: 6
|
|
51
|
+
}),
|
|
52
|
+
USDT: createCurrency({
|
|
53
|
+
chainId: 1,
|
|
54
|
+
address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
|
|
55
|
+
decimals: 6
|
|
56
|
+
}),
|
|
57
|
+
CBBTC: {
|
|
58
|
+
chain: ETH_CHAIN,
|
|
59
|
+
token: CBBTC_TOKEN
|
|
60
|
+
},
|
|
61
|
+
WBTC: createCurrency({
|
|
62
|
+
chainId: 1,
|
|
63
|
+
address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
|
|
64
|
+
decimals: 8
|
|
65
|
+
})
|
|
66
|
+
},
|
|
67
|
+
Base: {
|
|
68
|
+
ETH: {
|
|
69
|
+
chain: BASE_CHAIN,
|
|
70
|
+
token: { kind: "NATIVE", decimals: 18 }
|
|
71
|
+
},
|
|
72
|
+
WETH: createCurrency({
|
|
73
|
+
chainId: 8453,
|
|
74
|
+
address: "0x4200000000000000000000000000000000000006",
|
|
75
|
+
decimals: 18
|
|
76
|
+
}),
|
|
77
|
+
USDC: createCurrency({
|
|
78
|
+
chainId: 8453,
|
|
79
|
+
address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
80
|
+
decimals: 6
|
|
81
|
+
}),
|
|
82
|
+
CBBTC: {
|
|
83
|
+
chain: BASE_CHAIN,
|
|
84
|
+
token: CBBTC_TOKEN
|
|
85
|
+
}
|
|
86
|
+
}
|
|
31
87
|
};
|
|
32
88
|
// src/apiClient.ts
|
|
33
89
|
class SwapRouterApiError extends Error {
|
|
@@ -355,9 +411,8 @@ class RiftSdk {
|
|
|
355
411
|
export {
|
|
356
412
|
getSupportedModes,
|
|
357
413
|
detectRoute,
|
|
414
|
+
createCurrency,
|
|
358
415
|
createClient,
|
|
359
416
|
RiftSdk,
|
|
360
|
-
|
|
361
|
-
CBBTC_BASE,
|
|
362
|
-
BTC
|
|
417
|
+
Currencies
|
|
363
418
|
};
|