@scallop-io/sui-scallop-sdk 4.2.0 → 4.4.0-alpha.1
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 +357 -139
- package/dist/builder.cjs +20 -5
- package/dist/builder.d.cts +3 -2
- package/dist/builder.d.ts +3 -2
- package/dist/builder.js +2 -2
- package/dist/chunk-H2NF725V.js +30 -0
- package/dist/{chunk-4IC4UXW5.js → chunk-HQFMP3PN.js} +2 -2
- package/dist/chunk-XP3YYPCP.js +11 -0
- package/dist/client.cjs +19 -4
- package/dist/client.d.cts +2 -1
- package/dist/client.d.ts +2 -1
- package/dist/client.js +3 -3
- package/dist/index.cjs +52 -37
- package/dist/index.d.cts +12 -10
- package/dist/index.d.ts +12 -10
- package/dist/index.js +4 -4
- package/dist/{query-CXvcpnYj.d.ts → query-BqdO3ECh.d.ts} +135 -11
- package/dist/query.cjs +19 -4
- package/dist/query.d.cts +2 -1
- package/dist/query.d.ts +2 -1
- package/dist/query.js +1 -1
- package/dist/types.d.cts +2 -1
- package/dist/types.d.ts +2 -1
- package/package.json +9 -6
- package/src/constants/queryKeys.ts +11 -20
- package/src/constants/testAddress.ts +2 -0
- package/src/datasources/api.ts +3 -3
- package/src/datasources/onchain.ts +193 -10
- package/src/models/scallopAddress/const.ts +1 -0
- package/src/models/scallopAddress/index.ts +2 -2
- package/src/models/scallopAddress/types.ts +1 -0
- package/src/models/scallopBuilder/index.ts +9 -3
- package/src/models/scallopConstants/index.ts +35 -7
- package/src/models/scallopQuery/index.ts +47 -0
- package/src/models/scallopQuery/types.ts +13 -0
- package/src/models/scallopUtils/index.ts +7 -3
- package/src/models/scallopUtils/types.ts +7 -1
- package/src/repositories/borrowIncentive/helpers.ts +2 -2
- package/src/repositories/coinBalance/helpers.ts +364 -49
- package/src/repositories/coinBalance/index.ts +24 -1
- package/src/repositories/coinBalance/types.ts +16 -0
- package/src/repositories/obligation/helpers.ts +59 -0
- package/src/repositories/obligation/index.ts +5 -0
- package/src/repositories/obligation/types.ts +17 -1
- package/src/repositories/obligation/utils.ts +22 -0
- package/src/repositories/price/const.ts +7 -0
- package/src/repositories/price/helpers.ts +54 -37
- package/src/repositories/price/index.ts +5 -1
- package/src/repositories/price/types.ts +11 -3
- package/src/repositories/veSca/helpers.ts +1 -1
- package/src/repositories/wiring/datasources.ts +29 -1
- package/src/repositories/wiring/metadata.ts +1 -0
- package/src/repositories/wiring/registry.ts +41 -2
- package/src/txBuilders/oracles/pyth.ts +1 -5
- package/src/txBuilders/vesca/quick.ts +9 -3
- package/src/types/constant/queryKeys.ts +7 -3
- package/src/utils/object.ts +9 -1
- package/dist/chunk-3T4T4AON.js +0 -15
- package/dist/chunk-6YLMI74S.js +0 -11
package/README.md
CHANGED
|
@@ -4,149 +4,367 @@
|
|
|
4
4
|
</a>
|
|
5
5
|
</p>
|
|
6
6
|
<p align="center">
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
<a style="padding-right: 5px;" href="https://github.com/scallop-io/sui-scallop-sdk/releases">
|
|
8
|
+
<img alt="GitHub release" src="https://img.shields.io/github/v/release/scallop-io/sui-scallop-sdk?display_name=tag">
|
|
9
|
+
</a>
|
|
10
|
+
<a href="https://github.com/scallop-io/sui-scallop-sdk/blob/main/LICENSE">
|
|
11
|
+
<img alt="GitHub licence" src="https://img.shields.io/github/license/scallop-io/sui-scallop-sdk?logoColor=blue">
|
|
12
|
+
</a>
|
|
13
13
|
</p>
|
|
14
14
|
|
|
15
|
-
#
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
15
|
+
# Scallop TypeScript SDK
|
|
16
|
+
|
|
17
|
+
TypeScript SDK for integrating with the Scallop lending protocol on Sui.
|
|
18
|
+
|
|
19
|
+
Current package: `@scallop-io/sui-scallop-sdk` v4.x. ESM package, Node `>=22`, peer dependency `@mysten/sui@^2.0.0`.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pnpm add @scallop-io/sui-scallop-sdk @mysten/sui
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Public Entry Points
|
|
28
|
+
|
|
29
|
+
Root export:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import {
|
|
33
|
+
Scallop,
|
|
34
|
+
ScallopClient,
|
|
35
|
+
ScallopBuilder,
|
|
36
|
+
ScallopQuery,
|
|
37
|
+
ScallopUtils,
|
|
38
|
+
ScallopConstants,
|
|
39
|
+
ScallopAddress,
|
|
40
|
+
} from '@scallop-io/sui-scallop-sdk';
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Subpath exports:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { ScallopClient } from '@scallop-io/sui-scallop-sdk/client';
|
|
47
|
+
import { ScallopBuilder } from '@scallop-io/sui-scallop-sdk/builder';
|
|
48
|
+
import { ScallopQuery } from '@scallop-io/sui-scallop-sdk/query';
|
|
49
|
+
import type { ScallopTxBlock } from '@scallop-io/sui-scallop-sdk/types';
|
|
50
|
+
import { ScallopError } from '@scallop-io/sui-scallop-sdk/errors';
|
|
51
|
+
import { consoleLogger } from '@scallop-io/sui-scallop-sdk/logger';
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Supported subpaths:
|
|
55
|
+
|
|
56
|
+
- `@scallop-io/sui-scallop-sdk`
|
|
57
|
+
- `@scallop-io/sui-scallop-sdk/client`
|
|
58
|
+
- `@scallop-io/sui-scallop-sdk/query`
|
|
59
|
+
- `@scallop-io/sui-scallop-sdk/builder`
|
|
60
|
+
- `@scallop-io/sui-scallop-sdk/errors`
|
|
61
|
+
- `@scallop-io/sui-scallop-sdk/logger`
|
|
62
|
+
- `@scallop-io/sui-scallop-sdk/types`
|
|
63
|
+
|
|
64
|
+
## Main Models
|
|
65
|
+
|
|
66
|
+
`Scallop` is the convenience factory. It owns one initialized `ScallopClient` and exposes factory methods for the other facades.
|
|
67
|
+
|
|
68
|
+
```text
|
|
69
|
+
Scallop
|
|
70
|
+
-> ScallopClient write facade; signs/sends user actions
|
|
71
|
+
-> ScallopBuilder tx-block builder; owns SuiKit + TransactionExecutor
|
|
72
|
+
-> ScallopQuery read facade; delegates to repositories
|
|
73
|
+
-> ScallopUtils
|
|
74
|
+
-> ScallopConstants
|
|
75
|
+
-> ScallopAddress
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Important v4 details:
|
|
79
|
+
|
|
80
|
+
- `ScallopIndexer` model was removed. Query/indexer access is internal to repositories.
|
|
81
|
+
- `ScallopConstants` composes `ScallopAddress`; use `constants.address` for the address adapter.
|
|
82
|
+
- Back-compatible address forwarders remain on constants: `get`, `set`, `getAddresses`, `setAddresses`, `getId`, `getAllAddresses`, `switchCurrentAddresses`.
|
|
83
|
+
- Write-path signer/executor lives on `builder.executor`; raw SuiKit lives on `builder.suiKit`.
|
|
84
|
+
|
|
85
|
+
## Create SDK
|
|
86
|
+
|
|
87
|
+
Mainnet example:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import { Scallop } from '@scallop-io/sui-scallop-sdk';
|
|
91
|
+
|
|
92
|
+
const sdk = new Scallop({
|
|
93
|
+
addressId: '695fcdc084f790c04eb068dc',
|
|
94
|
+
network: 'mainnet',
|
|
95
|
+
fullnodeUrl: 'https://fullnode.mainnet.sui.io:443',
|
|
96
|
+
secretKey: process.env.SECRET_KEY,
|
|
97
|
+
pythEndpoints: ['https://hermes.pyth.network'],
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const client = await sdk.createScallopClient();
|
|
101
|
+
const query = await sdk.createScallopQuery();
|
|
102
|
+
const builder = await sdk.createScallopBuilder();
|
|
103
|
+
const utils = await sdk.createScallopUtils();
|
|
104
|
+
const constants = await sdk.getScallopConstants();
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Read-only example:
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
const sdk = new Scallop({
|
|
111
|
+
addressId: '695fcdc084f790c04eb068dc',
|
|
112
|
+
network: 'mainnet',
|
|
113
|
+
fullnodeUrl: 'https://fullnode.mainnet.sui.io:443',
|
|
114
|
+
walletAddress: '0x...',
|
|
115
|
+
pythEndpoints: ['https://hermes.pyth.network'],
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const query = await sdk.createScallopQuery();
|
|
119
|
+
const pools = await query.getMarketPools();
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Manual construction is supported. Call `.init()` before use:
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import { ScallopQuery } from '@scallop-io/sui-scallop-sdk/query';
|
|
126
|
+
|
|
127
|
+
const query = new ScallopQuery({
|
|
128
|
+
addressId: '695fcdc084f790c04eb068dc',
|
|
129
|
+
network: 'mainnet',
|
|
130
|
+
fullnodeUrl: 'https://fullnode.mainnet.sui.io:443',
|
|
131
|
+
walletAddress: '0x...',
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
await query.init();
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Constructor Options
|
|
138
|
+
|
|
139
|
+
Common required options:
|
|
140
|
+
|
|
141
|
+
- `addressId`: Scallop API address config id.
|
|
142
|
+
- `network`: Sui network, usually `'mainnet'`.
|
|
143
|
+
- `fullnodeUrl`: Sui RPC URL.
|
|
144
|
+
- `walletAddress`: required for read-only/wallet-scoped queries when no signer is supplied.
|
|
145
|
+
- `secretKey` or `mnemonics`: required for signing via `ScallopClient`.
|
|
146
|
+
|
|
147
|
+
Common optional options:
|
|
148
|
+
|
|
149
|
+
- `pythEndpoints`: Pyth Hermes endpoints for price-update flows.
|
|
150
|
+
- `queryClient` / `queryClientConfig`: custom `@tanstack/query-core` cache.
|
|
151
|
+
- `priceTimeout`: cache lifetime (ms) for the full Pyth price-feed list. Default `5_000`. Within this window, single/subset price reads are served from one cached full-list fetch instead of re-hitting the Pyth API; a longer value cuts API traffic at the cost of price staleness.
|
|
152
|
+
- `logger`: SDK logger. Default is silent `noopLogger`; pass `consoleLogger` to opt into console output.
|
|
153
|
+
- `strictInit`: when `true`, `init()` throws `ScallopConfigError` if required config is missing.
|
|
154
|
+
- `tokensPerSecond`: RPC read rate limit.
|
|
155
|
+
- `usePythPullModel`, `useOnChainXOracleList`, `sponsoredFeeds`: tx-builder oracle behavior.
|
|
156
|
+
|
|
157
|
+
### Overriding the underlying clients
|
|
158
|
+
|
|
159
|
+
The SDK builds its own transport clients by default, but you can inject your own:
|
|
160
|
+
|
|
161
|
+
- `suiClient` (`ClientWithCoreApi` from `@mysten/sui`): overrides the Sui RPC client used for on-chain reads. When omitted, the SDK builds a `SuiGrpcClient` from `network` + `fullnodeUrl`. Accepted by `ScallopUtils` / `ScallopQuery` / `ScallopBuilder` / `ScallopClient` / `Scallop`.
|
|
162
|
+
- `httpClient` (`AxiosInstance`): overrides the HTTP client used for Scallop API / address-config fetches. When omitted, the SDK creates an Axios instance from the API `url` + `timeout`. Accepted anywhere `ScallopAddress` config flows (`Scallop`, `ScallopConstants`, `ScallopAddress`).
|
|
163
|
+
- `client` (`ScallopClient`): only on the top-level `Scallop` constructor — reuse an already-built `ScallopClient` instead of constructing a new one. Unrelated to the two transport clients above.
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
import { Scallop } from '@scallop-io/sui-scallop-sdk';
|
|
167
|
+
import { SuiClient } from '@mysten/sui/client';
|
|
168
|
+
import axios from 'axios';
|
|
169
|
+
|
|
170
|
+
const sdk = new Scallop({
|
|
171
|
+
addressId: '695fcdc084f790c04eb068dc',
|
|
172
|
+
network: 'mainnet',
|
|
173
|
+
fullnodeUrl: 'https://fullnode.mainnet.sui.io:443',
|
|
174
|
+
walletAddress: '0x...',
|
|
175
|
+
suiClient: new SuiClient({ url: 'https://fullnode.mainnet.sui.io:443' }), // custom Sui RPC client
|
|
176
|
+
httpClient: axios.create({ timeout: 15_000 }), // custom HTTP client for API/address fetches
|
|
177
|
+
});
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
> Note: prior to v4.3.0 these were all named `client` and collided into an unusable intersection type. Use `suiClient` / `httpClient` (and the top-level `client`) on v4.3.0+.
|
|
181
|
+
|
|
182
|
+
## Query Examples
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
const marketPools = await query.getMarketPools();
|
|
186
|
+
const suiPool = await query.getMarketPool('sui');
|
|
187
|
+
const collaterals = await query.getMarketCollaterals();
|
|
188
|
+
|
|
189
|
+
const obligations = await query.getObligations('0xOwner');
|
|
190
|
+
const obligation = await query.queryObligation('0xObligationId');
|
|
191
|
+
const portfolio = await query.getUserPortfolio({ walletAddress: '0xOwner' });
|
|
192
|
+
|
|
193
|
+
const prices = await query.getPythCoinPrices({ coinNames: ['sui', 'usdc'] });
|
|
194
|
+
const allPrices = await query.getAllCoinPrices();
|
|
195
|
+
|
|
196
|
+
const stakeAccounts = await query.getAllStakeAccounts('0xOwner');
|
|
197
|
+
const tvl = await query.getTvl();
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Read source selection is available on supported facade methods via legacy-compatible flags:
|
|
201
|
+
|
|
202
|
+
```ts
|
|
203
|
+
await query.getMarketPools(undefined, { source: 'rpc' }); // on-chain RPC
|
|
204
|
+
await query.getMarketPools(undefined, { source: 'indexer' }); // API/indexer only
|
|
205
|
+
await query.getMarketPools(undefined, { source: 'indexer-first' }); // API/indexer with RPC fallback
|
|
206
|
+
await query.getMarketPools(undefined, { indexer: true }); // same as indexer-first
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Repository internals normalize those values to `onchain`, `api`, or `api-first`.
|
|
210
|
+
|
|
211
|
+
## Client Examples
|
|
212
|
+
|
|
213
|
+
`ScallopClient` methods sign and execute by default. Pass `false` where supported to receive an unsigned transaction instead.
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
const result = await client.openObligation();
|
|
217
|
+
|
|
218
|
+
await client.supply('sui', 1_000_000_000);
|
|
219
|
+
await client.depositCollateral('sui', 1_000_000_000);
|
|
220
|
+
await client.withdraw('sui', 1_000_000_000);
|
|
221
|
+
await client.withdrawCollateral('sui', 1_000_000_000);
|
|
222
|
+
|
|
223
|
+
await client.borrow(
|
|
224
|
+
'usdc',
|
|
225
|
+
1_000_000,
|
|
226
|
+
true,
|
|
227
|
+
'0xObligationId',
|
|
228
|
+
'0xObligationKey'
|
|
229
|
+
);
|
|
230
|
+
await client.repay(
|
|
231
|
+
'usdc',
|
|
232
|
+
1_000_000,
|
|
233
|
+
true,
|
|
234
|
+
'0xObligationId',
|
|
235
|
+
'0xObligationKey'
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
const tx = await client.supply('sui', 1_000_000_000, false);
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Other write helpers include:
|
|
242
|
+
|
|
243
|
+
- lending: `supply`, `withdraw`, `flashLoan`
|
|
244
|
+
- collateral: `depositCollateral`, `withdrawCollateral`
|
|
245
|
+
- borrow: `openObligation`, `borrow`, `repay`
|
|
246
|
+
- spool: `createStakeAccount`, `stake`, `unstake`, `claim`, `supplyAndStake`, `unstakeAndWithdraw`
|
|
247
|
+
- veSCA / incentives: `stakeObligation`, `unstakeObligation`, `claimBorrowIncentive`, `claimAllUnlockedSca`
|
|
248
|
+
- migration/test helpers: `migrateAllMarketCoin`, `mintTestCoin`
|
|
249
|
+
|
|
250
|
+
## Transaction Builder
|
|
251
|
+
|
|
252
|
+
Use `ScallopBuilder` for custom transaction composition.
|
|
253
|
+
|
|
254
|
+
```ts
|
|
255
|
+
const tx = builder.createTxBlock();
|
|
256
|
+
|
|
257
|
+
await tx.supplyQuick('sui', 1_000_000_000);
|
|
258
|
+
await tx.depositCollateralQuick('sui', 1_000_000_000);
|
|
259
|
+
|
|
260
|
+
const result = await builder.executor.signAndSendTxn(tx);
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
`ScallopTxBlock` exposes both flat methods and module-grouped methods. References are identity-equal:
|
|
264
|
+
|
|
265
|
+
```ts
|
|
266
|
+
tx.supplyQuick === tx.core.supplyQuick; // true
|
|
267
|
+
tx.stake === tx.spool.stake; // true
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
Modules:
|
|
271
|
+
|
|
272
|
+
- `tx.core`: lending, collateral, borrow, liquidations, flash loans
|
|
273
|
+
- `tx.spool`: staking market coins
|
|
274
|
+
- `tx.vesca`: veSCA lock/split/merge/redeem flows
|
|
275
|
+
- `tx.borrowIncentive`: obligation staking and incentive claims
|
|
276
|
+
- `tx.referral`: referral binding/revenue flows
|
|
277
|
+
- `tx.loyalty`: loyalty reward claims
|
|
278
|
+
- `tx.sCoin`: sCoin mint/burn
|
|
279
|
+
|
|
280
|
+
Method conventions:
|
|
281
|
+
|
|
282
|
+
- normal methods are synchronous Move-call wrappers and return `TransactionResult`.
|
|
283
|
+
- `*Quick` methods are async helpers that fetch required coins/objects/oracle updates, call normal methods, and return leftovers where needed.
|
|
284
|
+
- canonical lending names are `supply` / `supplyQuick` / `depositCollateral` / `depositCollateralQuick`.
|
|
285
|
+
- legacy `deposit*` and `addCollateral*` names are deprecated.
|
|
286
|
+
|
|
287
|
+
## Constants And Addresses
|
|
288
|
+
|
|
289
|
+
```ts
|
|
290
|
+
const constants = await sdk.getScallopConstants();
|
|
291
|
+
|
|
292
|
+
const corePackage = constants.get('core.packages.protocol.id');
|
|
293
|
+
const allAddresses = constants.getAddresses();
|
|
294
|
+
|
|
295
|
+
const addressAdapter = constants.address;
|
|
296
|
+
const addressId = addressAdapter.addressId;
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
`constants.whitelist` and `constants.poolAddresses` are frozen snapshots after `init()`.
|
|
300
|
+
|
|
301
|
+
## Errors And Logging
|
|
302
|
+
|
|
303
|
+
SDK internals throw typed errors:
|
|
304
|
+
|
|
305
|
+
- `ScallopRpcError`: Sui RPC / gRPC failures
|
|
306
|
+
- `ScallopIndexerError`: Scallop API/indexer HTTP failures
|
|
307
|
+
- `ScallopParseError`: invalid or unexpected payload
|
|
308
|
+
- `ScallopConfigError`: config validation failure
|
|
309
|
+
- `ScallopTransactionBuildError`: tx construction failure
|
|
310
|
+
|
|
311
|
+
```ts
|
|
312
|
+
import { ScallopError } from '@scallop-io/sui-scallop-sdk/errors';
|
|
313
|
+
import { consoleLogger } from '@scallop-io/sui-scallop-sdk/logger';
|
|
314
|
+
|
|
315
|
+
const sdk = new Scallop({
|
|
316
|
+
addressId: '695fcdc084f790c04eb068dc',
|
|
317
|
+
network: 'mainnet',
|
|
318
|
+
fullnodeUrl: 'https://fullnode.mainnet.sui.io:443',
|
|
319
|
+
walletAddress: '0x...',
|
|
320
|
+
logger: consoleLogger,
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
try {
|
|
324
|
+
await query.getMarketPools();
|
|
325
|
+
} catch (error) {
|
|
326
|
+
if (error instanceof ScallopError) {
|
|
327
|
+
// error.cause and error.context are available where provided
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
## Local Development
|
|
333
|
+
|
|
334
|
+
```bash
|
|
335
|
+
pnpm install
|
|
336
|
+
pnpm run build
|
|
337
|
+
pnpm run test:typecheck
|
|
338
|
+
pnpm run test:unit
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
Useful scripts:
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
pnpm run build # production build
|
|
345
|
+
pnpm run build:dev # development build
|
|
346
|
+
pnpm run test:typecheck # TypeScript checks for tests
|
|
347
|
+
pnpm run test:no-console # no console.* in SDK internals
|
|
348
|
+
pnpm run test:unit # network-free unit tests
|
|
349
|
+
pnpm run test:integration # integration tests; needs network + local env setup
|
|
350
|
+
pnpm run lint:fix
|
|
351
|
+
pnpm run format:fix
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
Integration/query/full test runs require local environment variables such as `SECRET_KEY`. Do not commit secrets.
|
|
355
|
+
|
|
356
|
+
## More Docs
|
|
357
|
+
|
|
358
|
+
- Contributor architecture: [`docs/SDK_STRUCTURE.md`](docs/SDK_STRUCTURE.md)
|
|
359
|
+
- Client guide: [`document/client.md`](document/client.md)
|
|
360
|
+
- Query guide: [`document/query.md`](document/query.md)
|
|
361
|
+
- Address guide: [`document/address.md`](document/address.md)
|
|
362
|
+
- Builder guide: [`document/builder.md`](document/builder.md)
|
|
363
|
+
- Utils guide: [`document/utils.md`](document/utils.md)
|
|
364
|
+
- Constants guide: [`document/constants.md`](document/constants.md)
|
|
147
365
|
|
|
148
366
|
## License
|
|
149
367
|
|
|
150
|
-
[
|
|
368
|
+
[Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
|
151
369
|
|
|
152
370
|
[](https://deepwiki.com/scallop-io/sui-scallop-sdk)
|