@scallop-io/sui-scallop-sdk 0.47.6 → 0.47.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/index.js +56 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -5
- package/dist/index.mjs.map +1 -1
- package/dist/types/model.d.ts +2 -2
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/indexer.d.ts +17 -0
- package/package.json +1 -1
- package/src/models/scallopBuilder.ts +1 -0
- package/src/models/scallopClient.ts +1 -1
- package/src/models/scallopQuery.ts +34 -0
- package/src/models/scallopUtils.ts +1 -0
- package/src/types/model.ts +2 -2
- package/src/utils/index.ts +1 -0
- package/src/utils/indexer.ts +39 -0
package/dist/types/model.d.ts
CHANGED
|
@@ -36,11 +36,11 @@ export type ScallopAddressParams = {
|
|
|
36
36
|
id: string;
|
|
37
37
|
auth?: string;
|
|
38
38
|
network?: NetworkType;
|
|
39
|
-
forceInterface?: Record<NetworkType, AddressesInterface
|
|
39
|
+
forceInterface?: Partial<Record<NetworkType, AddressesInterface>>;
|
|
40
40
|
};
|
|
41
41
|
export type ScallopParams = {
|
|
42
42
|
addressesId?: string;
|
|
43
|
-
forceAddressesInterface?: Record<NetworkType, AddressesInterface
|
|
43
|
+
forceAddressesInterface?: Partial<Record<NetworkType, AddressesInterface>>;
|
|
44
44
|
walletAddress?: string;
|
|
45
45
|
} & SuiKitParams;
|
|
46
46
|
export type ScallopClientParams = ScallopParams & ScallopBuilderParams & ScallopQueryParams & ScallopUtilsParams;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic wrapper for methods with indexer fallback.
|
|
3
|
+
*
|
|
4
|
+
* @param method - The method to call with fallback behavior.
|
|
5
|
+
* @param context - The context (`this`) of the class instance.
|
|
6
|
+
* @param args - The arguments to pass to the method.
|
|
7
|
+
* @returns The result of the method call.
|
|
8
|
+
*/
|
|
9
|
+
export declare function callMethodWithIndexerFallback(method: Function, context: any, ...args: any[]): Promise<any>;
|
|
10
|
+
/**
|
|
11
|
+
* This function creates a wrapper for methods that have an indexer parameter.
|
|
12
|
+
* It ensures fallback behavior if indexer fails.
|
|
13
|
+
*
|
|
14
|
+
* @param method - The method to wrap.
|
|
15
|
+
* @returns A function that applies indexer fallback.
|
|
16
|
+
*/
|
|
17
|
+
export declare function withIndexerFallback(method: Function): (...args: any[]) => Promise<any>;
|
package/package.json
CHANGED
|
@@ -84,8 +84,8 @@ export class ScallopClient {
|
|
|
84
84
|
this.address = new ScallopAddress(
|
|
85
85
|
{
|
|
86
86
|
id: params?.addressesId || ADDRESSES_ID,
|
|
87
|
-
forceInterface: params?.forceAddressesInterface,
|
|
88
87
|
network: params?.networkType,
|
|
88
|
+
forceInterface: params?.forceAddressesInterface,
|
|
89
89
|
},
|
|
90
90
|
{
|
|
91
91
|
cache: this.cache,
|
|
@@ -62,6 +62,7 @@ import {
|
|
|
62
62
|
} from 'src/queries/sCoinQuery';
|
|
63
63
|
import { normalizeSuiAddress } from '@mysten/sui.js/utils';
|
|
64
64
|
import { getSupplyLimit } from 'src/queries/supplyLimit';
|
|
65
|
+
import { withIndexerFallback } from 'src/utils/indexer';
|
|
65
66
|
|
|
66
67
|
/**
|
|
67
68
|
* @description
|
|
@@ -111,6 +112,7 @@ export class ScallopQuery {
|
|
|
111
112
|
{
|
|
112
113
|
id: params?.addressesId || ADDRESSES_ID,
|
|
113
114
|
network: params?.networkType,
|
|
115
|
+
forceInterface: params?.forceAddressesInterface,
|
|
114
116
|
},
|
|
115
117
|
{
|
|
116
118
|
cache: this.cache,
|
|
@@ -123,8 +125,40 @@ export class ScallopQuery {
|
|
|
123
125
|
this.indexer =
|
|
124
126
|
instance?.indexer ??
|
|
125
127
|
new ScallopIndexer(this.params, { cache: this.cache });
|
|
128
|
+
|
|
129
|
+
// Wrap any method that has an indexer parameter as the last parameter
|
|
130
|
+
this.queryMarket = withIndexerFallback.call(this, this.queryMarket);
|
|
131
|
+
this.getMarketPools = withIndexerFallback.call(this, this.getMarketPools);
|
|
132
|
+
this.getMarketPool = withIndexerFallback.call(this, this.getMarketPool);
|
|
133
|
+
this.getMarketCollaterals = withIndexerFallback.call(
|
|
134
|
+
this,
|
|
135
|
+
this.getMarketCollaterals
|
|
136
|
+
);
|
|
137
|
+
this.getMarketCollateral = withIndexerFallback.call(
|
|
138
|
+
this,
|
|
139
|
+
this.getMarketCollateral
|
|
140
|
+
);
|
|
141
|
+
this.getSpools = withIndexerFallback.call(this, this.getSpools);
|
|
142
|
+
this.getSpool = withIndexerFallback.call(this, this.getSpool);
|
|
143
|
+
this.getBorrowIncentivePools = withIndexerFallback.call(
|
|
144
|
+
this,
|
|
145
|
+
this.getBorrowIncentivePools
|
|
146
|
+
);
|
|
147
|
+
this.getLendings = withIndexerFallback.call(this, this.getLendings);
|
|
148
|
+
this.getLending = withIndexerFallback.call(this, this.getLending);
|
|
149
|
+
this.getObligationAccounts = withIndexerFallback.call(
|
|
150
|
+
this,
|
|
151
|
+
this.getObligationAccounts
|
|
152
|
+
);
|
|
153
|
+
this.getObligationAccount = withIndexerFallback.call(
|
|
154
|
+
this,
|
|
155
|
+
this.getObligationAccount
|
|
156
|
+
);
|
|
157
|
+
this.getTvl = withIndexerFallback.call(this, this.getTvl);
|
|
126
158
|
}
|
|
127
159
|
|
|
160
|
+
/* ========================================================== */
|
|
161
|
+
|
|
128
162
|
/**
|
|
129
163
|
* Request the scallop API to initialize data.
|
|
130
164
|
*
|
package/src/types/model.ts
CHANGED
|
@@ -60,12 +60,12 @@ export type ScallopAddressParams = {
|
|
|
60
60
|
id: string;
|
|
61
61
|
auth?: string;
|
|
62
62
|
network?: NetworkType;
|
|
63
|
-
forceInterface?: Record<NetworkType, AddressesInterface
|
|
63
|
+
forceInterface?: Partial<Record<NetworkType, AddressesInterface>>;
|
|
64
64
|
};
|
|
65
65
|
|
|
66
66
|
export type ScallopParams = {
|
|
67
67
|
addressesId?: string;
|
|
68
|
-
forceAddressesInterface?: Record<NetworkType, AddressesInterface
|
|
68
|
+
forceAddressesInterface?: Partial<Record<NetworkType, AddressesInterface>>;
|
|
69
69
|
walletAddress?: string;
|
|
70
70
|
} & SuiKitParams;
|
|
71
71
|
|
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic wrapper for methods with indexer fallback.
|
|
3
|
+
*
|
|
4
|
+
* @param method - The method to call with fallback behavior.
|
|
5
|
+
* @param context - The context (`this`) of the class instance.
|
|
6
|
+
* @param args - The arguments to pass to the method.
|
|
7
|
+
* @returns The result of the method call.
|
|
8
|
+
*/
|
|
9
|
+
export async function callMethodWithIndexerFallback(
|
|
10
|
+
method: Function,
|
|
11
|
+
context: any,
|
|
12
|
+
...args: any[]
|
|
13
|
+
) {
|
|
14
|
+
const indexer = args[args.length - 1]; // Assume last argument is always `indexer`
|
|
15
|
+
|
|
16
|
+
if (indexer) {
|
|
17
|
+
try {
|
|
18
|
+
return await method.apply(context, args);
|
|
19
|
+
} catch (_e) {
|
|
20
|
+
console.warn('Indexer requests failed. Retrying without indexer..');
|
|
21
|
+
return await method.apply(context, [...args.slice(0, -1), false]);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return await method.apply(context, args);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* This function creates a wrapper for methods that have an indexer parameter.
|
|
29
|
+
* It ensures fallback behavior if indexer fails.
|
|
30
|
+
*
|
|
31
|
+
* @param method - The method to wrap.
|
|
32
|
+
* @returns A function that applies indexer fallback.
|
|
33
|
+
*/
|
|
34
|
+
export function withIndexerFallback(method: Function) {
|
|
35
|
+
return (...args: any[]) => {
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
return callMethodWithIndexerFallback(method, this, ...args); // Preserve `this` with arrow function
|
|
38
|
+
};
|
|
39
|
+
}
|