@riftresearch/sdk 0.1.1 → 0.1.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 +108 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,24 +1,125 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @riftresearch/sdk
|
|
2
2
|
|
|
3
|
-
SDK for swapping between
|
|
3
|
+
SDK for swapping between Bitcoin and EVM chains.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
|
|
8
|
+
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
|
|
9
15
|
```
|
|
10
16
|
|
|
11
17
|
## Usage
|
|
12
18
|
|
|
19
|
+
### USDC → BTC Swap (Base)
|
|
20
|
+
|
|
13
21
|
```typescript
|
|
14
|
-
import {
|
|
22
|
+
import { RiftSdk, BTC, type Currency } from '@riftresearch/sdk'
|
|
23
|
+
import { createPublicClient, createWalletClient, http } from 'viem'
|
|
24
|
+
import { privateKeyToAccount } from 'viem/accounts'
|
|
25
|
+
import { base } from 'viem/chains'
|
|
26
|
+
|
|
27
|
+
// Define USDC on Base
|
|
28
|
+
const USDC_BASE: Currency = {
|
|
29
|
+
chain: { kind: 'EVM', chainId: 8453 },
|
|
30
|
+
token: {
|
|
31
|
+
kind: 'TOKEN',
|
|
32
|
+
address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
|
|
33
|
+
decimals: 6,
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Setup viem clients
|
|
38
|
+
const account = privateKeyToAccount('0x...')
|
|
39
|
+
const publicClient = createPublicClient({ chain: base, transport: http() })
|
|
40
|
+
const walletClient = createWalletClient({
|
|
41
|
+
account,
|
|
42
|
+
chain: base,
|
|
43
|
+
transport: http(),
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
// Initialize SDK
|
|
47
|
+
const sdk = new RiftSdk({
|
|
48
|
+
publicClient,
|
|
49
|
+
walletClient,
|
|
50
|
+
sendBitcoin: async ({ recipient, amountSats }) => {
|
|
51
|
+
// Only needed for BTC → ERC20 swaps
|
|
52
|
+
throw new Error('Not implemented')
|
|
53
|
+
},
|
|
54
|
+
})
|
|
15
55
|
|
|
16
|
-
|
|
56
|
+
// Get quote for swapping 100 USDC to BTC
|
|
57
|
+
const { quote, executeSwap } = await sdk.getQuote({
|
|
58
|
+
from: USDC_BASE,
|
|
59
|
+
to: BTC,
|
|
60
|
+
amount: '100000000', // 100 USDC (6 decimals)
|
|
61
|
+
mode: 'exact_input',
|
|
62
|
+
destinationAddress: 'bc1q...', // Your Bitcoin address
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
console.log(`Swapping ${quote.from.amount} USDC for ${quote.to.amount} sats`)
|
|
66
|
+
console.log(`Fees: $${quote.fees.totalUsd.toFixed(2)}`)
|
|
67
|
+
|
|
68
|
+
// Execute the swap (routes through CowSwap → Rift)
|
|
69
|
+
const swap = await executeSwap()
|
|
70
|
+
console.log(`Swap ID: ${swap.swapId}`)
|
|
71
|
+
|
|
72
|
+
// Check status
|
|
73
|
+
const status = await sdk.getSwapStatus(swap.swapId)
|
|
74
|
+
console.log(`Status: ${status.status}`)
|
|
17
75
|
```
|
|
18
76
|
|
|
19
|
-
|
|
77
|
+
### BTC → ETH Swap (Ethereum Mainnet)
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { RiftSdk, BTC, type Currency } from '@riftresearch/sdk'
|
|
81
|
+
import { createPublicClient, createWalletClient, http } from 'viem'
|
|
82
|
+
import { privateKeyToAccount } from 'viem/accounts'
|
|
83
|
+
import { mainnet } from 'viem/chains'
|
|
84
|
+
|
|
85
|
+
// Define ETH on Ethereum mainnet
|
|
86
|
+
const ETH_MAINNET: Currency = {
|
|
87
|
+
chain: { kind: 'EVM', chainId: 1 },
|
|
88
|
+
token: { kind: 'NATIVE', decimals: 18 },
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const account = privateKeyToAccount('0x...')
|
|
92
|
+
const publicClient = createPublicClient({ chain: mainnet, transport: http() })
|
|
93
|
+
const walletClient = createWalletClient({
|
|
94
|
+
account,
|
|
95
|
+
chain: mainnet,
|
|
96
|
+
transport: http(),
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
const sdk = new RiftSdk({
|
|
100
|
+
publicClient,
|
|
101
|
+
walletClient,
|
|
102
|
+
sendBitcoin: async ({ recipient, amountSats }) => {
|
|
103
|
+
// Implement using your Bitcoin wallet (Xverse, Leather, etc.)
|
|
104
|
+
await sendBitcoinTransaction(recipient, amountSats)
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
// Get quote for swapping 0.01 BTC to ETH
|
|
109
|
+
const { quote, executeSwap } = await sdk.getQuote({
|
|
110
|
+
from: BTC,
|
|
111
|
+
to: ETH_MAINNET,
|
|
112
|
+
amount: '1000000', // 0.01 BTC (8 decimals = 1,000,000 sats)
|
|
113
|
+
mode: 'exact_input',
|
|
114
|
+
destinationAddress: '0x...', // Your Ethereum address
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
console.log(`Swapping ${quote.from.amount} sats for ${quote.to.amount} wei`)
|
|
118
|
+
|
|
119
|
+
const swap = await executeSwap()
|
|
120
|
+
console.log(`Swap ID: ${swap.swapId}`)
|
|
121
|
+
```
|
|
20
122
|
|
|
21
|
-
Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for contribution guidelines.
|
|
22
123
|
|
|
23
124
|
## License
|
|
24
125
|
|