@satora/swap 0.0.4 → 0.0.5
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 +96 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# @satora/swap
|
|
2
|
+
|
|
3
|
+
The Satora swap client — a Lightning / on-chain BTC / Arkade ↔ EVM on/off-ramp.
|
|
4
|
+
Pure TypeScript, works in every JS environment (browser, Node, React Native).
|
|
5
|
+
|
|
6
|
+
This is the `@satora`-scoped name for the swap client and re-exports the
|
|
7
|
+
[`@lendasat/lendaswap-sdk-pure`](https://www.npmjs.com/package/@lendasat/lendaswap-sdk-pure)
|
|
8
|
+
bundle verbatim (`Client`, `ClientBuilder`, `Asset`, `EvmSigner`, storage
|
|
9
|
+
backends, …). New code should import `@satora/swap`.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install @satora/swap
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Supported swaps
|
|
18
|
+
|
|
19
|
+
| Direction | Source | Target |
|
|
20
|
+
| --------- | --------------------------- | --------------------------- |
|
|
21
|
+
| BTC → EVM | Lightning, Arkade, on-chain | Ethereum, Polygon, Arbitrum |
|
|
22
|
+
| EVM → BTC | Ethereum, Polygon, Arbitrum | Lightning, Arkade, on-chain |
|
|
23
|
+
|
|
24
|
+
Refunds: Lightning auto-expires; Arkade refunds off-chain; on-chain BTC and EVM
|
|
25
|
+
refund after their timelock.
|
|
26
|
+
|
|
27
|
+
## Quick start
|
|
28
|
+
|
|
29
|
+
### Build a client
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { Client, IdbWalletStorage, IdbSwapStorage } from "@satora/swap";
|
|
33
|
+
|
|
34
|
+
// Browser, persistent storage (IndexedDB). Omit the storages for a fresh
|
|
35
|
+
// ephemeral wallet, or pass .withMnemonic("abandon abandon …") to import one.
|
|
36
|
+
const client = await Client.builder()
|
|
37
|
+
.withSignerStorage(new IdbWalletStorage())
|
|
38
|
+
.withSwapStorage(new IdbSwapStorage())
|
|
39
|
+
.build();
|
|
40
|
+
|
|
41
|
+
const mnemonic = client.getMnemonic(); // back this up
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Quote and create a swap
|
|
45
|
+
|
|
46
|
+
`createSwap` handles every direction; the SDK routes by source/target asset.
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { Asset } from "@satora/swap";
|
|
50
|
+
|
|
51
|
+
const quote = await client.getQuote({
|
|
52
|
+
sourceChain: Asset.BTC_ARKADE.chain,
|
|
53
|
+
sourceToken: Asset.BTC_ARKADE.tokenId,
|
|
54
|
+
targetChain: Asset.USDC_POLYGON.chain,
|
|
55
|
+
targetToken: Asset.USDC_POLYGON.tokenId,
|
|
56
|
+
sourceAmount: 100_000, // sats
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// BTC → EVM: Arkade BTC to USDC on Polygon
|
|
60
|
+
const {response} = await client.createSwap({
|
|
61
|
+
source: Asset.BTC_ARKADE,
|
|
62
|
+
target: Asset.USDC_POLYGON,
|
|
63
|
+
sourceAmount: 100_000, // sats
|
|
64
|
+
targetAddress: "0x…", // your EVM address
|
|
65
|
+
});
|
|
66
|
+
const swapId = response.id;
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Fund EVM-sourced swaps
|
|
70
|
+
|
|
71
|
+
EVM-sourced swaps are funded after creation. The SDK runs the full Permit2 flow
|
|
72
|
+
(allowance, ERC-20 approval, EIP-712 signing, submission) in one call — you
|
|
73
|
+
provide an `EvmSigner` (a small wallet abstraction; adapters for viem/wagmi and
|
|
74
|
+
ethers v6 are a few lines — see the underlying SDK's README).
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
const {txHash} = await client.fundSwap(swapId, signer);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Monitor, claim, refund
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
const swap = await client.getSwap(swapId);
|
|
84
|
+
// pending → clientfunded → serverfunded → clientredeemed → serverredeemed
|
|
85
|
+
|
|
86
|
+
// BTC → EVM: once serverfunded, claim your tokens
|
|
87
|
+
await client.claim(swapId);
|
|
88
|
+
|
|
89
|
+
// Refund after timeout
|
|
90
|
+
await client.refundSwap(swapId, {destinationAddress: "bc1q…"}); // or "ark1…"
|
|
91
|
+
await client.collabRefundEvmWithSigner(swapId, signer, "swap-back"); // EVM, instant/gasless
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
MIT
|