stable-layer-sdk 1.0.6 → 2.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 +147 -0
- package/dist/cjs/index.cjs +18 -26
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/esm/index.mjs +18 -26
- package/dist/esm/index.mjs.map +2 -2
- package/dist/types/index.d.ts +5 -5
- package/dist/types/interface.d.ts +3 -4
- package/dist/types/libs/constants.d.ts +3 -6
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
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 { Transaction, coinWithBalance } 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(
|
|
100
|
+
"0x6d9fc...::btc_usdc::BtcUSDC",
|
|
101
|
+
);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Signing and Executing
|
|
105
|
+
|
|
106
|
+
All `build*` methods return a `Transaction` that you sign and execute with the Sui SDK:
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
import { SuiClient, getFullnodeUrl } from "@mysten/sui/client";
|
|
110
|
+
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
111
|
+
|
|
112
|
+
const suiClient = new SuiClient({ url: getFullnodeUrl("mainnet") });
|
|
113
|
+
const keypair = Ed25519Keypair.fromSecretKey(YOUR_PRIVATE_KEY);
|
|
114
|
+
|
|
115
|
+
const tx = new Transaction();
|
|
116
|
+
await client.buildMintTx({ tx, /* ... */ });
|
|
117
|
+
|
|
118
|
+
const result = await suiClient.signAndExecuteTransaction({
|
|
119
|
+
transaction: tx,
|
|
120
|
+
signer: keypair,
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## API
|
|
125
|
+
|
|
126
|
+
### `new StableLayerClient(config)`
|
|
127
|
+
|
|
128
|
+
| Parameter | Type | Description |
|
|
129
|
+
|-----------|------|-------------|
|
|
130
|
+
| `config.network` | `"mainnet" \| "testnet"` | Sui network |
|
|
131
|
+
| `config.sender` | `string` | Default sender address |
|
|
132
|
+
|
|
133
|
+
### Transaction Methods
|
|
134
|
+
|
|
135
|
+
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.
|
|
136
|
+
|
|
137
|
+
| Method | Description |
|
|
138
|
+
|--------|-------------|
|
|
139
|
+
| `buildMintTx(params)` | Mint stablecoins from USDC |
|
|
140
|
+
| `buildBurnTx(params)` | Burn stablecoins to redeem USDC |
|
|
141
|
+
| `buildClaimTx(params)` | Claim yield farming rewards |
|
|
142
|
+
| `getTotalSupply()` | Get total supply from registry |
|
|
143
|
+
| `getTotalSupplyByCoinType(type)` | Get total supply for a specific coin type |
|
|
144
|
+
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
MIT
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -30,18 +30,14 @@ var STABLE_VAULT = "0x65f38160110cd6859d05f338ff54b4f462883bb6f87c667a65c0fb0e53
|
|
|
30
30
|
var USDC_TYPE = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
|
|
31
31
|
var STABLE_LP_TYPE = "0xb75744fadcbfc174627567ca29645d0af8f6e6fd01b6f57c75a08cd3fb97c567::lake_usdc::LakeUSDC";
|
|
32
32
|
var YUSDB_TYPE = "0xac718b4b672d7f461fe7e86847166ff9c23cadba217397f0848a95bdea1f1051::yesusdb::YesUSDB";
|
|
33
|
-
var STABLE_LAYER_PACKAGE_ID = "
|
|
34
|
-
var STABLE_VAULT_FARM_PACKAGE_ID = "
|
|
33
|
+
var STABLE_LAYER_PACKAGE_ID = "0xa4a78d8d3d1df62fb81d10068142e79b0d30ad4e3f578060487e36ed9ea764da";
|
|
34
|
+
var STABLE_VAULT_FARM_PACKAGE_ID = "0x00d31ddaa73a56abcc3e2d885ac1e1d90f9ae0e38bbef2ba2923550c8250de4d";
|
|
35
35
|
var SAVING_TYPE = "0x38f61c75fa8407140294c84167dd57684580b55c3066883b48dedc344b1cde1e::susdb::SUSDB";
|
|
36
36
|
var YIELD_VAULT = "0x0a7f6325253157cd437812fea0ceee9a6b96f2ec5eac410da6df39558ff3a4d1";
|
|
37
37
|
var STABLE_REGISTRY = "0x213f4d584c0770f455bb98c94a4ee5ea9ddbc3d4ebb98a0ad6d093eb6da41642";
|
|
38
38
|
var STABLE_VAULT_FARM_ENTITY_TYPE = `0xc1025fe014b03d33b207b5afb0ba04293be87fab438c1418a26a75c2fe05c223::stable_vault_farm::StableVaultFarmEntity<${STABLE_LP_TYPE}, ${USDC_TYPE}>`;
|
|
39
39
|
var STABLE_VAULT_FARM = "0xe958b7d102b33bf3c09addb0e2cdff102ff2c93afe407ec5c2a541e8959a650c";
|
|
40
|
-
var YIELD_USDB_PACKAGE_ID = "
|
|
41
|
-
var BTC_USD_TYPE = "0x6d9fc33611f4881a3f5c0cd4899d95a862236ce52b3a38fef039077b0c5b5834::btc_usdc::BtcUSDC";
|
|
42
|
-
var STABLE_COIN_TYPES = {
|
|
43
|
-
btcUSDC: BTC_USD_TYPE
|
|
44
|
-
};
|
|
40
|
+
var YIELD_USDB_PACKAGE_ID = "0x3dcbf82f7e3b80ed65cee596612602a6c7e78c71fd40f6455b40ad033ed04786";
|
|
45
41
|
|
|
46
42
|
// src/index.ts
|
|
47
43
|
var import_client = require("@mysten/sui/client");
|
|
@@ -642,7 +638,7 @@ var StableLayerClient = class {
|
|
|
642
638
|
}
|
|
643
639
|
async buildMintTx({
|
|
644
640
|
tx,
|
|
645
|
-
|
|
641
|
+
stableCoinType,
|
|
646
642
|
usdcCoin,
|
|
647
643
|
sender,
|
|
648
644
|
autoTransfer = true
|
|
@@ -655,7 +651,7 @@ var StableLayerClient = class {
|
|
|
655
651
|
uCoin: usdcCoin
|
|
656
652
|
},
|
|
657
653
|
typeArguments: [
|
|
658
|
-
|
|
654
|
+
stableCoinType,
|
|
659
655
|
USDC_TYPE,
|
|
660
656
|
STABLE_VAULT_FARM_ENTITY_TYPE
|
|
661
657
|
]
|
|
@@ -668,7 +664,7 @@ var StableLayerClient = class {
|
|
|
668
664
|
typeArguments: [
|
|
669
665
|
STABLE_LP_TYPE,
|
|
670
666
|
USDC_TYPE,
|
|
671
|
-
|
|
667
|
+
stableCoinType,
|
|
672
668
|
YUSDB_TYPE,
|
|
673
669
|
SAVING_TYPE
|
|
674
670
|
],
|
|
@@ -693,7 +689,7 @@ var StableLayerClient = class {
|
|
|
693
689
|
}
|
|
694
690
|
async buildBurnTx({
|
|
695
691
|
tx,
|
|
696
|
-
|
|
692
|
+
stableCoinType,
|
|
697
693
|
amount,
|
|
698
694
|
all,
|
|
699
695
|
sender,
|
|
@@ -707,10 +703,10 @@ var StableLayerClient = class {
|
|
|
707
703
|
balance: all ? BigInt(
|
|
708
704
|
(await this.suiClient.getBalance({
|
|
709
705
|
owner: sender ?? this.sender,
|
|
710
|
-
coinType:
|
|
706
|
+
coinType: stableCoinType
|
|
711
707
|
})).totalBalance
|
|
712
708
|
) : amount,
|
|
713
|
-
type:
|
|
709
|
+
type: stableCoinType
|
|
714
710
|
});
|
|
715
711
|
this.releaseRewards(tx);
|
|
716
712
|
const burnRequest = requestBurn({
|
|
@@ -719,10 +715,7 @@ var StableLayerClient = class {
|
|
|
719
715
|
registry: STABLE_REGISTRY,
|
|
720
716
|
stableCoin: btcUsdCoin
|
|
721
717
|
},
|
|
722
|
-
typeArguments: [
|
|
723
|
-
STABLE_COIN_TYPES[lpToken],
|
|
724
|
-
USDC_TYPE
|
|
725
|
-
]
|
|
718
|
+
typeArguments: [stableCoinType, USDC_TYPE]
|
|
726
719
|
})(tx);
|
|
727
720
|
const [uPrice] = await this.bucketClient.aggregatePrices(tx, {
|
|
728
721
|
coinTypes: [USDC_TYPE]
|
|
@@ -742,7 +735,7 @@ var StableLayerClient = class {
|
|
|
742
735
|
typeArguments: [
|
|
743
736
|
STABLE_LP_TYPE,
|
|
744
737
|
USDC_TYPE,
|
|
745
|
-
|
|
738
|
+
stableCoinType,
|
|
746
739
|
YUSDB_TYPE,
|
|
747
740
|
SAVING_TYPE
|
|
748
741
|
]
|
|
@@ -754,10 +747,7 @@ var StableLayerClient = class {
|
|
|
754
747
|
registry: STABLE_REGISTRY,
|
|
755
748
|
burnRequest
|
|
756
749
|
},
|
|
757
|
-
typeArguments: [
|
|
758
|
-
STABLE_COIN_TYPES[lpToken],
|
|
759
|
-
USDC_TYPE
|
|
760
|
-
]
|
|
750
|
+
typeArguments: [stableCoinType, USDC_TYPE]
|
|
761
751
|
})(tx);
|
|
762
752
|
if (autoTransfer) {
|
|
763
753
|
tx.transferObjects([usdcCoin], sender ?? this.sender);
|
|
@@ -768,7 +758,7 @@ var StableLayerClient = class {
|
|
|
768
758
|
}
|
|
769
759
|
async buildClaimTx({
|
|
770
760
|
tx,
|
|
771
|
-
|
|
761
|
+
stableCoinType,
|
|
772
762
|
sender,
|
|
773
763
|
autoTransfer = true
|
|
774
764
|
}) {
|
|
@@ -787,7 +777,7 @@ var StableLayerClient = class {
|
|
|
787
777
|
typeArguments: [
|
|
788
778
|
STABLE_LP_TYPE,
|
|
789
779
|
USDC_TYPE,
|
|
790
|
-
|
|
780
|
+
stableCoinType,
|
|
791
781
|
YUSDB_TYPE,
|
|
792
782
|
SAVING_TYPE
|
|
793
783
|
]
|
|
@@ -810,12 +800,14 @@ var StableLayerClient = class {
|
|
|
810
800
|
const content = result.data?.content;
|
|
811
801
|
return content?.fields?.total_supply;
|
|
812
802
|
}
|
|
813
|
-
async
|
|
803
|
+
async getTotalSupplyByCoinType(stableCoinType) {
|
|
814
804
|
const result = await this.suiClient.getDynamicFieldObject({
|
|
815
805
|
parentId: STABLE_REGISTRY,
|
|
816
806
|
name: {
|
|
817
807
|
type: "0x1::type_name::TypeName",
|
|
818
|
-
value:
|
|
808
|
+
value: {
|
|
809
|
+
name: stableCoinType.slice(2)
|
|
810
|
+
}
|
|
819
811
|
}
|
|
820
812
|
});
|
|
821
813
|
const content = result.data?.content;
|