stable-layer-sdk 1.1.0 → 3.0.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 +148 -0
- package/dist/cjs/index.cjs +292 -303
- package/dist/cjs/index.cjs.map +4 -4
- package/dist/esm/index.mjs +293 -306
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/index.d.ts +5 -5
- package/dist/types/interface.d.ts +3 -4
- package/dist/types/libs/constants.d.ts +2 -5
- package/package.json +12 -8
package/README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# Stable Layer SDK
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the [Stable Layer](https://github.com/StableLayer/stable-layer-sdk) protocol on Sui blockchain. Mint and burn stablecoins, and claim yield farming rewards.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install stable-layer-sdk @mysten/sui @mysten/bcs
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { StableLayerClient } from "stable-layer-sdk";
|
|
15
|
+
|
|
16
|
+
const client = new StableLayerClient({
|
|
17
|
+
network: "mainnet",
|
|
18
|
+
sender: "0xYOUR_ADDRESS",
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Examples
|
|
23
|
+
|
|
24
|
+
### Mint Stablecoins
|
|
25
|
+
|
|
26
|
+
Deposit USDC to mint stablecoins. The SDK builds a transaction that mints via Stable Layer and deposits into the vault farm.
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { coinWithBalance, Transaction } from "@mysten/sui/transactions";
|
|
30
|
+
|
|
31
|
+
const tx = new Transaction();
|
|
32
|
+
|
|
33
|
+
// Mint with auto-transfer (coin sent to sender automatically)
|
|
34
|
+
await client.buildMintTx({
|
|
35
|
+
tx,
|
|
36
|
+
stableCoinType: "0x6d9fc...::btc_usdc::BtcUSDC",
|
|
37
|
+
usdcCoin: coinWithBalance({
|
|
38
|
+
balance: BigInt(1_000_000),
|
|
39
|
+
type: "0xdba34...::usdc::USDC",
|
|
40
|
+
})(tx),
|
|
41
|
+
amount: BigInt(1_000_000),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Or get the coin back for further composition
|
|
45
|
+
const coin = await client.buildMintTx({
|
|
46
|
+
tx,
|
|
47
|
+
stableCoinType: "0x6d9fc...::btc_usdc::BtcUSDC",
|
|
48
|
+
usdcCoin: coinWithBalance({
|
|
49
|
+
balance: BigInt(1_000_000),
|
|
50
|
+
type: "0xdba34...::usdc::USDC",
|
|
51
|
+
})(tx),
|
|
52
|
+
amount: BigInt(1_000_000),
|
|
53
|
+
autoTransfer: false,
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Burn Stablecoins
|
|
58
|
+
|
|
59
|
+
Burn stablecoins to redeem USDC.
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
const tx = new Transaction();
|
|
63
|
+
|
|
64
|
+
// Burn a specific amount
|
|
65
|
+
await client.buildBurnTx({
|
|
66
|
+
tx,
|
|
67
|
+
stableCoinType: "0x6d9fc...::btc_usdc::BtcUSDC",
|
|
68
|
+
amount: BigInt(1_000_000),
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Or burn entire balance
|
|
72
|
+
await client.buildBurnTx({
|
|
73
|
+
tx,
|
|
74
|
+
stableCoinType: "0x6d9fc...::btc_usdc::BtcUSDC",
|
|
75
|
+
all: true,
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Claim Rewards
|
|
80
|
+
|
|
81
|
+
Claim accumulated yield farming rewards.
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
const tx = new Transaction();
|
|
85
|
+
|
|
86
|
+
await client.buildClaimTx({
|
|
87
|
+
tx,
|
|
88
|
+
stableCoinType: "0x6d9fc...::btc_usdc::BtcUSDC",
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Query Total Supply
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
// Total supply across all coin types
|
|
96
|
+
const totalSupply = await client.getTotalSupply();
|
|
97
|
+
|
|
98
|
+
// Total supply for a specific coin type
|
|
99
|
+
const btcUsdcSupply = await client.getTotalSupplyByCoinType("0x6d9fc...::btc_usdc::BtcUSDC");
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Signing and Executing
|
|
103
|
+
|
|
104
|
+
All `build*` methods return a `Transaction` that you sign and execute with the Sui SDK:
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
108
|
+
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
109
|
+
|
|
110
|
+
const suiClient = new SuiGrpcClient({
|
|
111
|
+
network: "mainnet",
|
|
112
|
+
baseUrl: "https://fullnode.mainnet.sui.io:443",
|
|
113
|
+
});
|
|
114
|
+
const keypair = Ed25519Keypair.fromSecretKey(YOUR_PRIVATE_KEY);
|
|
115
|
+
|
|
116
|
+
const tx = new Transaction();
|
|
117
|
+
await client.buildMintTx({ tx /* ... */ });
|
|
118
|
+
|
|
119
|
+
const result = await suiClient.signAndExecuteTransaction({
|
|
120
|
+
transaction: tx,
|
|
121
|
+
signer: keypair,
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## API
|
|
126
|
+
|
|
127
|
+
### `new StableLayerClient(config)`
|
|
128
|
+
|
|
129
|
+
| Parameter | Type | Description |
|
|
130
|
+
| ---------------- | ------------------------ | ---------------------- |
|
|
131
|
+
| `config.network` | `"mainnet" \| "testnet"` | Sui network |
|
|
132
|
+
| `config.sender` | `string` | Default sender address |
|
|
133
|
+
|
|
134
|
+
### Transaction Methods
|
|
135
|
+
|
|
136
|
+
All methods accept a `tx` (Transaction) and optional `sender` to override the default. Set `autoTransfer: false` to get the resulting coin back instead of auto-transferring.
|
|
137
|
+
|
|
138
|
+
| Method | Description |
|
|
139
|
+
| -------------------------------- | ----------------------------------------- |
|
|
140
|
+
| `buildMintTx(params)` | Mint stablecoins from USDC |
|
|
141
|
+
| `buildBurnTx(params)` | Burn stablecoins to redeem USDC |
|
|
142
|
+
| `buildClaimTx(params)` | Claim yield farming rewards |
|
|
143
|
+
| `getTotalSupply()` | Get total supply from registry |
|
|
144
|
+
| `getTotalSupplyByCoinType(type)` | Get total supply for a specific coin type |
|
|
145
|
+
|
|
146
|
+
## License
|
|
147
|
+
|
|
148
|
+
MIT
|