@scallop-io/sui-scallop-sdk 1.4.5 → 1.4.7
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/dist/constants/index.d.ts +0 -1
- package/dist/constants/poolAddress.d.ts +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1644 -1478
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1848 -1678
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallop.d.ts +1 -2
- package/dist/models/scallopCache.d.ts +16 -11
- package/dist/models/scallopQuery.d.ts +67 -3
- package/dist/queries/poolAddressesQuery.d.ts +2 -0
- package/dist/queries/portfolioQuery.d.ts +60 -3
- package/dist/types/model.d.ts +8 -2
- package/dist/utils/index.d.ts +0 -2
- package/package.json +1 -1
- package/src/constants/index.ts +0 -1
- package/src/constants/poolAddress.ts +93 -25
- package/src/constants/queryKeys.ts +1 -1
- package/src/index.ts +0 -1
- package/src/models/scallop.ts +8 -13
- package/src/models/scallopAddress.ts +2 -9
- package/src/models/scallopBuilder.ts +3 -6
- package/src/models/scallopCache.ts +96 -55
- package/src/models/scallopClient.ts +3 -6
- package/src/models/scallopIndexer.ts +1 -5
- package/src/models/scallopQuery.ts +42 -16
- package/src/models/scallopUtils.ts +7 -11
- package/src/queries/coreQuery.ts +4 -4
- package/src/queries/poolAddressesQuery.ts +6 -0
- package/src/queries/portfolioQuery.ts +209 -8
- package/src/queries/sCoinQuery.ts +2 -2
- package/src/types/model.ts +13 -2
- package/src/utils/index.ts +0 -2
- package/src/utils/indexer.ts +3 -1
- package/dist/constants/tokenBucket.d.ts +0 -2
- package/dist/utils/tokenBucket.d.ts +0 -11
- package/src/constants/tokenBucket.ts +0 -2
- package/src/utils/tokenBucket.ts +0 -68
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { API_BASE_URL, USE_TEST_ADDRESS } from '../constants';
|
|
2
|
-
import {
|
|
2
|
+
import { type NetworkType } from '@scallop-io/sui-kit';
|
|
3
3
|
import type {
|
|
4
4
|
ScallopAddressParams,
|
|
5
5
|
AddressesInterface,
|
|
@@ -7,7 +7,6 @@ import type {
|
|
|
7
7
|
ScallopAddressInstanceParams,
|
|
8
8
|
} from '../types';
|
|
9
9
|
import { ScallopCache } from './scallopCache';
|
|
10
|
-
import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
|
|
11
10
|
import axios, { AxiosInstance } from 'axios';
|
|
12
11
|
import { TEST_ADDRESSES } from 'src/constants/testAddress';
|
|
13
12
|
import { queryKeys } from 'src/constants';
|
|
@@ -379,13 +378,7 @@ export class ScallopAddress {
|
|
|
379
378
|
instance?: ScallopAddressInstanceParams
|
|
380
379
|
) {
|
|
381
380
|
const { id, auth, network, forceInterface } = params;
|
|
382
|
-
this.cache =
|
|
383
|
-
instance?.cache ??
|
|
384
|
-
new ScallopCache(
|
|
385
|
-
instance?.suiKit ?? new SuiKit({}),
|
|
386
|
-
undefined,
|
|
387
|
-
DEFAULT_CACHE_OPTIONS
|
|
388
|
-
);
|
|
381
|
+
this.cache = instance?.cache ?? new ScallopCache({});
|
|
389
382
|
|
|
390
383
|
this._requestClient = axios.create({
|
|
391
384
|
baseURL: API_BASE_URL,
|
|
@@ -24,7 +24,6 @@ import type {
|
|
|
24
24
|
SelectCoinReturnType,
|
|
25
25
|
} from '../types';
|
|
26
26
|
import { ScallopCache } from './scallopCache';
|
|
27
|
-
import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
|
|
28
27
|
import { newSuiKit } from './suiKit';
|
|
29
28
|
|
|
30
29
|
/**
|
|
@@ -66,11 +65,9 @@ export class ScallopBuilder {
|
|
|
66
65
|
this.address = this.utils.address;
|
|
67
66
|
this.cache = this.address.cache;
|
|
68
67
|
} else {
|
|
69
|
-
this.cache = new ScallopCache(
|
|
70
|
-
this.suiKit,
|
|
71
|
-
|
|
72
|
-
DEFAULT_CACHE_OPTIONS
|
|
73
|
-
);
|
|
68
|
+
this.cache = new ScallopCache(this.params, {
|
|
69
|
+
suiKit: this.suiKit,
|
|
70
|
+
});
|
|
74
71
|
this.address = new ScallopAddress(
|
|
75
72
|
{
|
|
76
73
|
id: params?.addressesId ?? ADDRESSES_ID,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { QueryClient
|
|
1
|
+
import { QueryClient } from '@tanstack/query-core';
|
|
2
2
|
import {
|
|
3
3
|
SuiObjectArg,
|
|
4
4
|
SuiTxBlock,
|
|
@@ -17,14 +17,12 @@ import type {
|
|
|
17
17
|
GetDynamicFieldObjectParams,
|
|
18
18
|
GetBalanceParams,
|
|
19
19
|
SuiClient,
|
|
20
|
+
CoinBalance,
|
|
20
21
|
} from '@mysten/sui/client';
|
|
21
22
|
import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
|
|
22
|
-
import { callWithRateLimit, TokenBucket } from 'src/utils';
|
|
23
|
-
import {
|
|
24
|
-
DEFAULT_INTERVAL_IN_MS,
|
|
25
|
-
DEFAULT_TOKENS_PER_INTERVAL,
|
|
26
|
-
} from 'src/constants/tokenBucket';
|
|
27
23
|
import { queryKeys } from 'src/constants';
|
|
24
|
+
import { ScallopCacheInstanceParams, ScallopCacheParams } from 'src/types';
|
|
25
|
+
import { newSuiKit } from './suiKit';
|
|
28
26
|
|
|
29
27
|
type QueryInspectTxnParams = {
|
|
30
28
|
queryTarget: string;
|
|
@@ -32,6 +30,9 @@ type QueryInspectTxnParams = {
|
|
|
32
30
|
typeArgs?: any[];
|
|
33
31
|
};
|
|
34
32
|
|
|
33
|
+
const DEFAULT_TOKENS_PER_INTERVAL = 10;
|
|
34
|
+
const DEFAULT_INTERVAL_IN_MS = 250;
|
|
35
|
+
|
|
35
36
|
/**
|
|
36
37
|
* @description
|
|
37
38
|
* It provides caching for moveCall, RPC Request, and API Request.
|
|
@@ -46,20 +47,26 @@ type QueryInspectTxnParams = {
|
|
|
46
47
|
*/
|
|
47
48
|
|
|
48
49
|
export class ScallopCache {
|
|
49
|
-
public readonly
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
public readonly params: ScallopCacheParams;
|
|
51
|
+
|
|
52
|
+
public queryClient: QueryClient;
|
|
53
|
+
public suiKit: SuiKit;
|
|
54
|
+
// private tokenBucket: TokenBucket;
|
|
52
55
|
public walletAddress: string;
|
|
56
|
+
private tokensPerInterval: number = DEFAULT_TOKENS_PER_INTERVAL;
|
|
57
|
+
private interval: number = DEFAULT_INTERVAL_IN_MS;
|
|
58
|
+
private tokens: number;
|
|
59
|
+
private lastRefill: number;
|
|
53
60
|
|
|
54
61
|
public constructor(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
cacheOptions?: QueryClientConfig,
|
|
58
|
-
tokenBucket?: TokenBucket,
|
|
59
|
-
queryClient?: QueryClient
|
|
62
|
+
params: ScallopCacheParams,
|
|
63
|
+
instance?: ScallopCacheInstanceParams
|
|
60
64
|
) {
|
|
65
|
+
this.params = params;
|
|
66
|
+
this.suiKit = instance?.suiKit ?? newSuiKit(params);
|
|
61
67
|
this.queryClient =
|
|
62
|
-
queryClient ??
|
|
68
|
+
instance?.queryClient ??
|
|
69
|
+
new QueryClient(params?.cacheOptions ?? DEFAULT_CACHE_OPTIONS);
|
|
63
70
|
|
|
64
71
|
// handle case where there's existing queryClient and cacheOptions is also passed
|
|
65
72
|
// if (queryClient && cacheOptions) {
|
|
@@ -71,22 +78,62 @@ export class ScallopCache {
|
|
|
71
78
|
// // if(cacheOptions.mutations)this.queryClient.setMutationDefaults(cacheOptions.mutations);
|
|
72
79
|
// }
|
|
73
80
|
|
|
74
|
-
this.
|
|
75
|
-
this.
|
|
76
|
-
|
|
77
|
-
new TokenBucket(DEFAULT_TOKENS_PER_INTERVAL, DEFAULT_INTERVAL_IN_MS);
|
|
78
|
-
this.walletAddress = walletAddress ?? suiKit.currentAddress();
|
|
81
|
+
this.tokens = this.tokensPerInterval;
|
|
82
|
+
this.lastRefill = Date.now();
|
|
83
|
+
this.walletAddress = params.walletAddress ?? this.suiKit.currentAddress();
|
|
79
84
|
}
|
|
80
85
|
|
|
81
|
-
private get
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
private get client(): SuiClient {
|
|
87
|
+
return this.suiKit.client();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private refill() {
|
|
91
|
+
const now = Date.now();
|
|
92
|
+
const elapsed = now - this.lastRefill;
|
|
93
|
+
|
|
94
|
+
if (elapsed >= this.interval) {
|
|
95
|
+
const tokensToAdd =
|
|
96
|
+
Math.floor(elapsed / this.interval) * this.tokensPerInterval;
|
|
97
|
+
this.tokens = Math.min(this.tokens + tokensToAdd, this.tokensPerInterval);
|
|
98
|
+
|
|
99
|
+
// Update lastRefill to reflect the exact time of the last "refill"
|
|
100
|
+
this.lastRefill += Math.floor(elapsed / this.interval) * this.interval;
|
|
84
101
|
}
|
|
85
|
-
return this._suiKit;
|
|
86
102
|
}
|
|
87
103
|
|
|
88
|
-
private
|
|
89
|
-
|
|
104
|
+
private removeTokens(count: number) {
|
|
105
|
+
this.refill();
|
|
106
|
+
if (this.tokens >= count) {
|
|
107
|
+
this.tokens -= count;
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private async callWithRateLimit<T>(
|
|
114
|
+
fn: () => Promise<T>,
|
|
115
|
+
maxRetries = 15,
|
|
116
|
+
backoffFactor = 1.25 // The factor by which to increase the delay
|
|
117
|
+
): Promise<T | null> {
|
|
118
|
+
let retries = 0;
|
|
119
|
+
|
|
120
|
+
const tryRequest = async (): Promise<T | null> => {
|
|
121
|
+
if (this.removeTokens(1)) {
|
|
122
|
+
const result = await fn();
|
|
123
|
+
return result;
|
|
124
|
+
} else if (retries < maxRetries) {
|
|
125
|
+
retries++;
|
|
126
|
+
const delay = this.interval * Math.pow(backoffFactor, retries);
|
|
127
|
+
// console.error(`Rate limit exceeded, retrying in ${delay} ms`);
|
|
128
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
129
|
+
return tryRequest();
|
|
130
|
+
} else {
|
|
131
|
+
console.error('Maximum retries reached');
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
return tryRequest();
|
|
90
137
|
}
|
|
91
138
|
|
|
92
139
|
/**
|
|
@@ -98,14 +145,14 @@ export class ScallopCache {
|
|
|
98
145
|
* - `all`: All queries that match the refetch predicate will be refetched in the background.
|
|
99
146
|
* - `none`: No queries will be refetched. Queries that match the refetch predicate will only be marked as invalid.
|
|
100
147
|
*/
|
|
101
|
-
public async invalidateAllCache() {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
148
|
+
// public async invalidateAllCache() {
|
|
149
|
+
// return Object.values(queryKeys.rpc).map((t) =>
|
|
150
|
+
// this.queryClient.invalidateQueries({
|
|
151
|
+
// queryKey: t(),
|
|
152
|
+
// type: 'all',
|
|
153
|
+
// })
|
|
154
|
+
// );
|
|
155
|
+
// }
|
|
109
156
|
|
|
110
157
|
private retryFn(errCount: number, e: any) {
|
|
111
158
|
if (errCount === 5) return false;
|
|
@@ -168,8 +215,7 @@ export class ScallopCache {
|
|
|
168
215
|
retryDelay: 1000,
|
|
169
216
|
queryKey: queryKeys.rpc.getInspectTxn(queryTarget, args, typeArgs),
|
|
170
217
|
queryFn: async () => {
|
|
171
|
-
return await callWithRateLimit(
|
|
172
|
-
this.tokenBucket,
|
|
218
|
+
return await this.callWithRateLimit(
|
|
173
219
|
async () => await this.suiKit.inspectTxn(txBlock)
|
|
174
220
|
);
|
|
175
221
|
},
|
|
@@ -182,8 +228,7 @@ export class ScallopCache {
|
|
|
182
228
|
return this.queryClient.fetchQuery({
|
|
183
229
|
queryKey: queryKeys.rpc.getNormalizedMoveFunction(target),
|
|
184
230
|
queryFn: async () => {
|
|
185
|
-
return await callWithRateLimit(
|
|
186
|
-
this.tokenBucket,
|
|
231
|
+
return await this.callWithRateLimit(
|
|
187
232
|
async () =>
|
|
188
233
|
await this.suiKit.client().getNormalizedMoveFunction({
|
|
189
234
|
package: address,
|
|
@@ -215,8 +260,7 @@ export class ScallopCache {
|
|
|
215
260
|
retryDelay: 1000,
|
|
216
261
|
queryKey: queryKeys.rpc.getObject(objectId, options),
|
|
217
262
|
queryFn: async () => {
|
|
218
|
-
return await callWithRateLimit(
|
|
219
|
-
this.tokenBucket,
|
|
263
|
+
return await this.callWithRateLimit(
|
|
220
264
|
async () =>
|
|
221
265
|
await this.client.getObject({
|
|
222
266
|
id: objectId,
|
|
@@ -250,8 +294,7 @@ export class ScallopCache {
|
|
|
250
294
|
options
|
|
251
295
|
),
|
|
252
296
|
queryFn: async () => {
|
|
253
|
-
const results = await callWithRateLimit(
|
|
254
|
-
this.tokenBucket,
|
|
297
|
+
const results = await this.callWithRateLimit(
|
|
255
298
|
async () => await this.suiKit.getObjects(objectIds, options)
|
|
256
299
|
);
|
|
257
300
|
if (results) {
|
|
@@ -288,8 +331,7 @@ export class ScallopCache {
|
|
|
288
331
|
retryDelay: 1000,
|
|
289
332
|
queryKey: queryKeys.rpc.getOwnedObjects(input),
|
|
290
333
|
queryFn: async () => {
|
|
291
|
-
const results = await callWithRateLimit(
|
|
292
|
-
this.tokenBucket,
|
|
334
|
+
const results = await this.callWithRateLimit(
|
|
293
335
|
async () => await this.client.getOwnedObjects(input)
|
|
294
336
|
);
|
|
295
337
|
if (results && results.data.length > 0) {
|
|
@@ -332,8 +374,7 @@ export class ScallopCache {
|
|
|
332
374
|
retryDelay: 1000,
|
|
333
375
|
queryKey: queryKeys.rpc.getDynamicFields(input),
|
|
334
376
|
queryFn: async () => {
|
|
335
|
-
return await callWithRateLimit(
|
|
336
|
-
this.tokenBucket,
|
|
377
|
+
return await this.callWithRateLimit(
|
|
337
378
|
async () => await this.client.getDynamicFields(input)
|
|
338
379
|
);
|
|
339
380
|
},
|
|
@@ -348,7 +389,7 @@ export class ScallopCache {
|
|
|
348
389
|
retryDelay: (attemptIndex) => Math.min(1000 * attemptIndex, 8000),
|
|
349
390
|
queryKey: queryKeys.rpc.getDynamicFieldObject(input),
|
|
350
391
|
queryFn: async () => {
|
|
351
|
-
const result = await
|
|
392
|
+
const result = await this.callWithRateLimit(() =>
|
|
352
393
|
this.client.getDynamicFieldObject(input)
|
|
353
394
|
);
|
|
354
395
|
if (result?.data) {
|
|
@@ -376,26 +417,24 @@ export class ScallopCache {
|
|
|
376
417
|
|
|
377
418
|
public async queryGetAllCoinBalances(
|
|
378
419
|
owner: string
|
|
379
|
-
): Promise<{ [k: string]:
|
|
420
|
+
): Promise<{ [k: string]: CoinBalance }> {
|
|
380
421
|
return this.queryClient.fetchQuery({
|
|
381
422
|
retry: this.retryFn,
|
|
382
423
|
retryDelay: 1000,
|
|
383
424
|
queryKey: queryKeys.rpc.getAllCoinBalances(owner),
|
|
384
425
|
queryFn: async () => {
|
|
385
|
-
const allBalances = await callWithRateLimit(
|
|
386
|
-
this.tokenBucket,
|
|
426
|
+
const allBalances = await this.callWithRateLimit(
|
|
387
427
|
async () => await this.client.getAllBalances({ owner })
|
|
388
428
|
);
|
|
389
429
|
if (!allBalances) return {};
|
|
390
430
|
const balances = allBalances.reduce(
|
|
391
431
|
(acc, coinBalance) => {
|
|
392
432
|
if (coinBalance.totalBalance !== '0') {
|
|
393
|
-
acc[normalizeStructTag(coinBalance.coinType)] =
|
|
394
|
-
coinBalance.totalBalance;
|
|
433
|
+
acc[normalizeStructTag(coinBalance.coinType)] = coinBalance;
|
|
395
434
|
}
|
|
396
435
|
return acc;
|
|
397
436
|
},
|
|
398
|
-
{} as { [k: string]:
|
|
437
|
+
{} as { [k: string]: CoinBalance }
|
|
399
438
|
);
|
|
400
439
|
|
|
401
440
|
return balances;
|
|
@@ -403,8 +442,10 @@ export class ScallopCache {
|
|
|
403
442
|
});
|
|
404
443
|
}
|
|
405
444
|
|
|
406
|
-
public async queryGetCoinBalance(
|
|
407
|
-
|
|
445
|
+
public async queryGetCoinBalance(
|
|
446
|
+
input: GetBalanceParams
|
|
447
|
+
): Promise<CoinBalance | null> {
|
|
448
|
+
if (!input.coinType) return null;
|
|
408
449
|
|
|
409
450
|
return (
|
|
410
451
|
((await this.queryGetAllCoinBalances(input.owner)) ?? {})[
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { normalizeSuiAddress } from '@mysten/sui/utils';
|
|
2
2
|
import { SuiKit } from '@scallop-io/sui-kit';
|
|
3
|
-
import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
|
|
4
3
|
import {
|
|
5
4
|
ADDRESSES_ID,
|
|
6
5
|
SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
@@ -75,11 +74,9 @@ export class ScallopClient {
|
|
|
75
74
|
this.address = this.utils.address;
|
|
76
75
|
this.cache = this.address.cache;
|
|
77
76
|
} else {
|
|
78
|
-
this.cache = new ScallopCache(
|
|
79
|
-
this.suiKit,
|
|
80
|
-
|
|
81
|
-
DEFAULT_CACHE_OPTIONS
|
|
82
|
-
);
|
|
77
|
+
this.cache = new ScallopCache(this.params, {
|
|
78
|
+
suiKit: this.suiKit,
|
|
79
|
+
});
|
|
83
80
|
this.address = new ScallopAddress(
|
|
84
81
|
{
|
|
85
82
|
id: params?.addressesId ?? ADDRESSES_ID,
|
|
@@ -22,8 +22,6 @@ import type {
|
|
|
22
22
|
ScallopIndexerInstanceParams,
|
|
23
23
|
} from '../types';
|
|
24
24
|
import { ScallopCache } from './scallopCache';
|
|
25
|
-
import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
|
|
26
|
-
import { SuiKit } from '@scallop-io/sui-kit';
|
|
27
25
|
import { queryKeys } from 'src/constants';
|
|
28
26
|
|
|
29
27
|
/**
|
|
@@ -48,9 +46,7 @@ export class ScallopIndexer {
|
|
|
48
46
|
instance?: ScallopIndexerInstanceParams
|
|
49
47
|
) {
|
|
50
48
|
this.params = params;
|
|
51
|
-
this.cache =
|
|
52
|
-
instance?.cache ??
|
|
53
|
-
new ScallopCache(new SuiKit({}), undefined, DEFAULT_CACHE_OPTIONS);
|
|
49
|
+
this.cache = instance?.cache ?? new ScallopCache(this.params);
|
|
54
50
|
this._requestClient = axios.create({
|
|
55
51
|
baseURL: SDK_API_BASE_URL,
|
|
56
52
|
headers: {
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { SuiKit, SuiObjectArg } from '@scallop-io/sui-kit';
|
|
2
|
-
import {
|
|
3
|
-
ADDRESSES_ID,
|
|
4
|
-
SUPPORT_POOLS,
|
|
5
|
-
SUPPORT_SPOOLS,
|
|
6
|
-
DEFAULT_CACHE_OPTIONS,
|
|
7
|
-
} from '../constants';
|
|
2
|
+
import { ADDRESSES_ID, SUPPORT_POOLS, SUPPORT_SPOOLS } from '../constants';
|
|
8
3
|
import {
|
|
9
4
|
queryMarket,
|
|
10
5
|
getObligations,
|
|
@@ -47,6 +42,7 @@ import {
|
|
|
47
42
|
getAllCoinPrices,
|
|
48
43
|
getAllAddresses,
|
|
49
44
|
isIsolatedAsset,
|
|
45
|
+
getUserPortfolio,
|
|
50
46
|
} from '../queries';
|
|
51
47
|
import {
|
|
52
48
|
ScallopQueryParams,
|
|
@@ -63,6 +59,7 @@ import {
|
|
|
63
59
|
MarketPool,
|
|
64
60
|
CoinPrices,
|
|
65
61
|
MarketPools,
|
|
62
|
+
MarketCollaterals,
|
|
66
63
|
} from '../types';
|
|
67
64
|
import { ScallopAddress } from './scallopAddress';
|
|
68
65
|
import { ScallopUtils } from './scallopUtils';
|
|
@@ -112,11 +109,9 @@ export class ScallopQuery {
|
|
|
112
109
|
this.address = instance.utils.address;
|
|
113
110
|
this.cache = this.address.cache;
|
|
114
111
|
} else {
|
|
115
|
-
this.cache = new ScallopCache(
|
|
116
|
-
this.suiKit,
|
|
117
|
-
|
|
118
|
-
DEFAULT_CACHE_OPTIONS
|
|
119
|
-
);
|
|
112
|
+
this.cache = new ScallopCache(this.params, {
|
|
113
|
+
suiKit: this.suiKit,
|
|
114
|
+
});
|
|
120
115
|
this.address = new ScallopAddress(
|
|
121
116
|
{
|
|
122
117
|
id: params?.addressesId ?? ADDRESSES_ID,
|
|
@@ -582,9 +577,15 @@ export class ScallopQuery {
|
|
|
582
577
|
public async getLendings(
|
|
583
578
|
poolCoinNames?: SupportPoolCoins[],
|
|
584
579
|
ownerAddress: string = this.walletAddress,
|
|
585
|
-
args?: { indexer?: boolean }
|
|
580
|
+
args?: { indexer?: boolean; marketPools?: MarketPools }
|
|
586
581
|
) {
|
|
587
|
-
return await getLendings(
|
|
582
|
+
return await getLendings(
|
|
583
|
+
this,
|
|
584
|
+
poolCoinNames,
|
|
585
|
+
ownerAddress,
|
|
586
|
+
args?.marketPools,
|
|
587
|
+
args?.indexer
|
|
588
|
+
);
|
|
588
589
|
}
|
|
589
590
|
|
|
590
591
|
/**
|
|
@@ -615,9 +616,20 @@ export class ScallopQuery {
|
|
|
615
616
|
*/
|
|
616
617
|
public async getObligationAccounts(
|
|
617
618
|
ownerAddress: string = this.walletAddress,
|
|
618
|
-
args?: {
|
|
619
|
+
args?: {
|
|
620
|
+
indexer?: boolean;
|
|
621
|
+
market?: {
|
|
622
|
+
collaterals: MarketCollaterals;
|
|
623
|
+
pools: MarketPools;
|
|
624
|
+
};
|
|
625
|
+
}
|
|
619
626
|
) {
|
|
620
|
-
return await getObligationAccounts(
|
|
627
|
+
return await getObligationAccounts(
|
|
628
|
+
this,
|
|
629
|
+
ownerAddress,
|
|
630
|
+
args?.market,
|
|
631
|
+
args?.indexer
|
|
632
|
+
);
|
|
621
633
|
}
|
|
622
634
|
|
|
623
635
|
/**
|
|
@@ -844,10 +856,24 @@ export class ScallopQuery {
|
|
|
844
856
|
}
|
|
845
857
|
|
|
846
858
|
/**
|
|
847
|
-
* Query all address (lending pool, collateral pool, borrow dynamics, interest models) of all pool
|
|
859
|
+
* Query all address (lending pool, collateral pool, borrow dynamics, interest models, etc.) of all pool
|
|
848
860
|
* @returns
|
|
849
861
|
*/
|
|
850
862
|
public async getPoolAddresses() {
|
|
851
863
|
return getAllAddresses(this);
|
|
852
864
|
}
|
|
865
|
+
|
|
866
|
+
/**
|
|
867
|
+
* Get user portfolio
|
|
868
|
+
*/
|
|
869
|
+
public async getUserPortfolio(args?: {
|
|
870
|
+
walletAddress?: string;
|
|
871
|
+
indexer?: boolean;
|
|
872
|
+
}) {
|
|
873
|
+
return getUserPortfolio(
|
|
874
|
+
this,
|
|
875
|
+
args?.walletAddress ?? this.walletAddress,
|
|
876
|
+
args?.indexer ?? false
|
|
877
|
+
);
|
|
878
|
+
}
|
|
853
879
|
}
|
|
@@ -33,7 +33,6 @@ import {
|
|
|
33
33
|
} from '../utils';
|
|
34
34
|
import { PYTH_ENDPOINTS, PYTH_FEED_IDS } from 'src/constants/pyth';
|
|
35
35
|
import { ScallopCache } from './scallopCache';
|
|
36
|
-
import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
|
|
37
36
|
import type {
|
|
38
37
|
ScallopUtilsParams,
|
|
39
38
|
SupportCoins,
|
|
@@ -81,21 +80,18 @@ export class ScallopUtils {
|
|
|
81
80
|
pythEndpoints: params.pythEndpoints ?? PYTH_ENDPOINTS['mainnet'],
|
|
82
81
|
...params,
|
|
83
82
|
};
|
|
83
|
+
this.walletAddress =
|
|
84
|
+
params.walletAddress ?? instance?.suiKit?.currentAddress() ?? '';
|
|
84
85
|
this.suiKit =
|
|
85
|
-
instance?.suiKit ?? instance?.address?.cache.
|
|
86
|
-
|
|
87
|
-
this.walletAddress = params.walletAddress ?? this.suiKit.currentAddress();
|
|
86
|
+
instance?.suiKit ?? instance?.address?.cache.suiKit ?? newSuiKit(params);
|
|
88
87
|
|
|
89
88
|
if (instance?.address) {
|
|
90
89
|
this.address = instance.address;
|
|
91
90
|
this.cache = this.address.cache;
|
|
92
|
-
this.suiKit = this.address.cache._suiKit;
|
|
93
91
|
} else {
|
|
94
|
-
this.cache = new ScallopCache(
|
|
95
|
-
this.suiKit,
|
|
96
|
-
|
|
97
|
-
DEFAULT_CACHE_OPTIONS
|
|
98
|
-
);
|
|
92
|
+
this.cache = new ScallopCache(this.params, {
|
|
93
|
+
suiKit: this.suiKit,
|
|
94
|
+
});
|
|
99
95
|
this.address =
|
|
100
96
|
instance?.address ??
|
|
101
97
|
new ScallopAddress(
|
|
@@ -450,7 +446,7 @@ export class ScallopUtils {
|
|
|
450
446
|
coinType: string = SUI_TYPE_ARG,
|
|
451
447
|
ownerAddress?: string
|
|
452
448
|
) {
|
|
453
|
-
ownerAddress = ownerAddress ?? this.
|
|
449
|
+
ownerAddress = ownerAddress ?? this.walletAddress;
|
|
454
450
|
const coins = await this.suiKit.suiInteractor.selectCoins(
|
|
455
451
|
ownerAddress,
|
|
456
452
|
amount,
|
package/src/queries/coreQuery.ts
CHANGED
|
@@ -1079,11 +1079,11 @@ export const getCoinAmount = async (
|
|
|
1079
1079
|
) => {
|
|
1080
1080
|
const owner = ownerAddress ?? query.suiKit.currentAddress();
|
|
1081
1081
|
const coinType = query.utils.parseCoinType(assetCoinName);
|
|
1082
|
-
const
|
|
1082
|
+
const coinBalance = await query.cache.queryGetCoinBalance({
|
|
1083
1083
|
owner,
|
|
1084
1084
|
coinType: coinType,
|
|
1085
1085
|
});
|
|
1086
|
-
return BigNumber(
|
|
1086
|
+
return BigNumber(coinBalance?.totalBalance ?? '0').toNumber();
|
|
1087
1087
|
};
|
|
1088
1088
|
|
|
1089
1089
|
/**
|
|
@@ -1136,11 +1136,11 @@ export const getMarketCoinAmount = async (
|
|
|
1136
1136
|
) => {
|
|
1137
1137
|
const owner = ownerAddress ?? query.suiKit.currentAddress();
|
|
1138
1138
|
const marketCoinType = query.utils.parseMarketCoinType(marketCoinName);
|
|
1139
|
-
const
|
|
1139
|
+
const coinBalance = await query.cache.queryGetCoinBalance({
|
|
1140
1140
|
owner,
|
|
1141
1141
|
coinType: marketCoinType,
|
|
1142
1142
|
});
|
|
1143
|
-
return BigNumber(
|
|
1143
|
+
return BigNumber(coinBalance?.totalBalance ?? '0').toNumber();
|
|
1144
1144
|
};
|
|
1145
1145
|
|
|
1146
1146
|
/**
|
|
@@ -12,6 +12,7 @@ export const getAllAddresses = async (query: ScallopQuery) => {
|
|
|
12
12
|
borrowDynamic?: string;
|
|
13
13
|
spoolReward?: string;
|
|
14
14
|
spool?: string;
|
|
15
|
+
sCoinType?: string;
|
|
15
16
|
sCoinTreasury?: string;
|
|
16
17
|
interestModel?: string;
|
|
17
18
|
riskModel?: string;
|
|
@@ -21,6 +22,7 @@ export const getAllAddresses = async (query: ScallopQuery) => {
|
|
|
21
22
|
isolatedAssetKey?: string;
|
|
22
23
|
coinDecimalId?: string;
|
|
23
24
|
borrowIncentivePoolId?: string;
|
|
25
|
+
coinType?: string;
|
|
24
26
|
}
|
|
25
27
|
>
|
|
26
28
|
> = {};
|
|
@@ -115,6 +117,8 @@ export const getAllAddresses = async (query: ScallopQuery) => {
|
|
|
115
117
|
// @ts-ignore
|
|
116
118
|
`spool.pools.s${coinName}.rewardPoolId`
|
|
117
119
|
);
|
|
120
|
+
// @ts-ignore
|
|
121
|
+
const sCoinType = query.address.get(`scoin.coins.s${coinName}.coinType`);
|
|
118
122
|
const sCoinTreasury = query.address.get(
|
|
119
123
|
// @ts-ignore
|
|
120
124
|
`scoin.coins.s${coinName}.treasury`
|
|
@@ -135,7 +139,9 @@ export const getAllAddresses = async (query: ScallopQuery) => {
|
|
|
135
139
|
spool,
|
|
136
140
|
spoolReward: rewardPool,
|
|
137
141
|
sCoinTreasury,
|
|
142
|
+
sCoinType,
|
|
138
143
|
coinDecimalId,
|
|
144
|
+
coinType,
|
|
139
145
|
};
|
|
140
146
|
|
|
141
147
|
await new Promise((resolve) => setTimeout(resolve, 200));
|