@scallop-io/sui-scallop-sdk 2.0.13-merge-split-ve-sca-alpha.4 → 2.1.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/dist/index.d.mts +622 -697
- package/dist/index.d.ts +622 -697
- package/dist/index.js +32 -33
- package/dist/index.mjs +10 -10
- package/package.json +8 -18
- package/src/builders/borrowIncentiveBuilder.ts +8 -18
- package/src/builders/coreBuilder.ts +2 -2
- package/src/builders/index.ts +2 -2
- package/src/builders/oracles/index.ts +2 -3
- package/src/builders/oracles/pyth.ts +2 -2
- package/src/builders/spoolBuilder.ts +2 -2
- package/src/builders/vescaBuilder.ts +14 -132
- package/src/constants/queryKeys.ts +29 -54
- package/src/constants/testAddress.ts +6 -12
- package/src/index.ts +11 -1
- package/src/models/index.ts +11 -9
- package/src/models/interface.ts +36 -0
- package/src/models/scallop.ts +38 -133
- package/src/models/scallopAddress.ts +127 -142
- package/src/models/scallopAxios.ts +185 -0
- package/src/models/scallopBuilder.ts +45 -75
- package/src/models/scallopClient.ts +124 -154
- package/src/models/scallopConstants.ts +248 -323
- package/src/models/scallopIndexer.ts +54 -98
- package/src/models/scallopQuery.ts +145 -190
- package/src/models/scallopQueryClient.ts +29 -0
- package/src/models/scallopSuiKit.ts +432 -0
- package/src/models/scallopUtils.ts +260 -164
- package/src/queries/borrowIncentiveQuery.ts +28 -16
- package/src/queries/borrowLimitQuery.ts +1 -1
- package/src/queries/coreQuery.ts +148 -107
- package/src/queries/flashloanFeeQuery.ts +12 -6
- package/src/queries/index.ts +0 -1
- package/src/queries/isolatedAssetQuery.ts +3 -3
- package/src/queries/loyaltyProgramQuery.ts +10 -8
- package/src/queries/ownerQuery.ts +32 -0
- package/src/queries/portfolioQuery.ts +4 -5
- package/src/queries/priceQuery.ts +14 -8
- package/src/queries/referralQuery.ts +9 -3
- package/src/queries/sCoinQuery.ts +4 -4
- package/src/queries/spoolQuery.ts +11 -11
- package/src/queries/supplyLimitQuery.ts +1 -1
- package/src/queries/switchboardQuery.ts +1 -1
- package/src/queries/vescaQuery.ts +31 -27
- package/src/queries/xOracleQuery.ts +13 -8
- package/src/types/address.ts +0 -3
- package/src/types/builder/core.ts +1 -1
- package/src/types/builder/vesca.ts +10 -20
- package/src/types/constant/queryKeys.ts +48 -0
- package/src/types/index.ts +0 -1
- package/src/utils/builder.ts +1 -1
- package/src/utils/util.ts +1 -33
- package/src/models/scallopCache.ts +0 -428
- package/src/queries/objectsQuery.ts +0 -18
- package/src/types/model.ts +0 -117
|
@@ -1,102 +1,106 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PoolAddress, Whitelist } from 'src/types';
|
|
2
|
+
import ScallopAddress, { ScallopAddressParams } from './scallopAddress';
|
|
3
|
+
import { NetworkType, parseStructTag } from '@scallop-io/sui-kit';
|
|
4
|
+
import ScallopAxios from './scallopAxios';
|
|
2
5
|
import { queryKeys } from 'src/constants';
|
|
3
|
-
import {
|
|
4
|
-
PoolAddress,
|
|
5
|
-
ScallopConstantsInstanceParams,
|
|
6
|
-
ScallopConstantsParams,
|
|
7
|
-
Whitelist,
|
|
8
|
-
} from 'src/types';
|
|
9
|
-
import { ScallopCache } from './scallopCache';
|
|
10
6
|
import { QueryKey } from '@tanstack/query-core';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
|
|
8
|
+
const isEmptyObject = (obj: object) => {
|
|
9
|
+
return Object.keys(obj).length === 0;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type CoinName = string;
|
|
13
|
+
type CoinType = string;
|
|
14
|
+
type SCoinType = string;
|
|
15
|
+
type OldMarketCoinType = string;
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
|
-
*
|
|
17
|
-
* It provides methods to construct constants for Scallop SDK instances.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* const scallopConstants = new ScallopConstants();
|
|
22
|
-
* await scallopConstants.init();
|
|
23
|
-
* ```
|
|
18
|
+
* @description `scallop_sui`, `scallop_usdt`, etc (parsed directly from coin type, ex: `0x...::scallop_sui::SCALLOP_SUI`)
|
|
24
19
|
*/
|
|
25
|
-
|
|
26
|
-
private readonly _requestClient: AxiosInstance;
|
|
27
|
-
public address: ScallopAddress;
|
|
28
|
-
public cache: ScallopCache;
|
|
20
|
+
type SCoinRawName = string;
|
|
29
21
|
|
|
22
|
+
/**
|
|
23
|
+
* @description `ssui`, `susdc`, etc..
|
|
24
|
+
*/
|
|
25
|
+
type SCoinName = string;
|
|
26
|
+
|
|
27
|
+
export type ScallopConstantsParams = {
|
|
28
|
+
poolAddressesApiUrl?: string;
|
|
29
|
+
whitelistApiUrl?: string;
|
|
30
|
+
forcePoolAddressInterface?: Record<string, PoolAddress>;
|
|
31
|
+
forceWhitelistInterface?: Whitelist;
|
|
32
|
+
} & ScallopAddressParams;
|
|
33
|
+
|
|
34
|
+
const DEFAULT_WHITELIST = {
|
|
35
|
+
lending: new Set(),
|
|
36
|
+
borrowing: new Set(),
|
|
37
|
+
collateral: new Set(),
|
|
38
|
+
packages: new Set(),
|
|
39
|
+
scoin: new Set(),
|
|
40
|
+
spool: new Set(),
|
|
41
|
+
borrowIncentiveRewards: new Set(),
|
|
42
|
+
rewardsAsPoint: new Set(),
|
|
43
|
+
suiBridge: new Set(),
|
|
44
|
+
wormhole: new Set(),
|
|
45
|
+
oracles: new Set(),
|
|
46
|
+
pythEndpoints: new Set(),
|
|
47
|
+
deprecated: new Set(),
|
|
48
|
+
emerging: new Set(),
|
|
49
|
+
} as Whitelist;
|
|
50
|
+
|
|
51
|
+
class ScallopConstants extends ScallopAddress {
|
|
30
52
|
private _poolAddresses: Record<string, PoolAddress | undefined> = {};
|
|
31
|
-
private _whitelist: Whitelist =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
private _coinDecimals: Record<string, number | undefined> = {};
|
|
49
|
-
private _coinNameToOldMarketCoinTypeMap: Record<string, string | undefined> =
|
|
50
|
-
{};
|
|
51
|
-
private _scoinRawNameToSCoinNameMap: Record<string, string | undefined> = {};
|
|
52
|
-
private _scoinTypeToSCoinNameMap: Record<string, string | undefined> = {};
|
|
53
|
-
private _wormholeCoinTypeToCoinNameMap: Record<string, string | undefined> =
|
|
54
|
-
{};
|
|
55
|
-
private _voloCoinTypeToCoinNameMap: Record<string, string | undefined> = {};
|
|
56
|
-
private _suiBridgeCoinTypeToCoinNameMap: Record<string, string | undefined> =
|
|
53
|
+
private _whitelist: Whitelist = DEFAULT_WHITELIST;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @description coin names to coin decimal map
|
|
57
|
+
*/
|
|
58
|
+
public coinDecimals: Record<CoinName, number | undefined> = {};
|
|
59
|
+
public coinNameToOldMarketCoinTypeMap: Record<
|
|
60
|
+
CoinName,
|
|
61
|
+
OldMarketCoinType | undefined
|
|
62
|
+
> = {};
|
|
63
|
+
public scoinRawNameToSCoinNameMap: Record<
|
|
64
|
+
SCoinRawName,
|
|
65
|
+
SCoinName | undefined
|
|
66
|
+
> = {};
|
|
67
|
+
public scoinTypeToSCoinNameMap: Record<SCoinType, SCoinName | undefined> = {};
|
|
68
|
+
public wormholeCoinTypeToCoinNameMap: Record<CoinType, CoinName | undefined> =
|
|
57
69
|
{};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
constructor(
|
|
64
|
-
public readonly params: ScallopConstantsParams,
|
|
65
|
-
instance?: ScallopConstantsInstanceParams
|
|
66
|
-
) {
|
|
67
|
-
this.params = params;
|
|
68
|
-
this._requestClient = axios.create({
|
|
69
|
-
headers: {
|
|
70
|
-
'Content-Type': 'application/json',
|
|
71
|
-
Accept: 'application/json',
|
|
72
|
-
},
|
|
73
|
-
timeout: 8000,
|
|
74
|
-
});
|
|
70
|
+
public voloCoinTypeToCoinNameMap: Record<CoinType, CoinName | undefined> = {};
|
|
71
|
+
public suiBridgeCoinTypeToCoinNameMap: Record<
|
|
72
|
+
CoinType,
|
|
73
|
+
CoinName | undefined
|
|
74
|
+
> = {};
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
suiKit: newSuiKit(this.params),
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
this.address =
|
|
84
|
-
instance?.address ??
|
|
85
|
-
new ScallopAddress(this.params, {
|
|
86
|
-
cache: this.cache,
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
if (params.forcePoolAddressInterface) {
|
|
90
|
-
this._poolAddresses = params.forcePoolAddressInterface;
|
|
91
|
-
}
|
|
76
|
+
/**
|
|
77
|
+
* @description coin names to coin types map
|
|
78
|
+
*/
|
|
79
|
+
public coinTypes: Record<CoinName, CoinType | undefined> = {};
|
|
92
80
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
81
|
+
/**
|
|
82
|
+
* @description scoin names to scoin types map
|
|
83
|
+
*/
|
|
84
|
+
public sCoinTypes: Record<SCoinName, SCoinType | undefined> = {};
|
|
85
|
+
public coinTypeToCoinNameMap: Record<CoinType, CoinName | undefined> = {};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @description Supported borrow incentive reward coin names
|
|
89
|
+
*/
|
|
90
|
+
public supportedBorrowIncentiveRewards: Set<CoinName> = new Set();
|
|
91
|
+
|
|
92
|
+
private scallopConstantAxios: ScallopAxios;
|
|
93
|
+
|
|
94
|
+
constructor(public readonly params: ScallopConstantsParams = {}) {
|
|
95
|
+
super(params);
|
|
96
|
+
this.scallopConstantAxios = new ScallopAxios();
|
|
96
97
|
}
|
|
97
98
|
|
|
98
|
-
get
|
|
99
|
-
return
|
|
99
|
+
get protocolObjectId() {
|
|
100
|
+
return (
|
|
101
|
+
(this.get('core.object') as string | undefined) ??
|
|
102
|
+
('0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf' as const)
|
|
103
|
+
);
|
|
100
104
|
}
|
|
101
105
|
|
|
102
106
|
get isInitialized() {
|
|
@@ -112,210 +116,193 @@ export class ScallopConstants {
|
|
|
112
116
|
'emerging',
|
|
113
117
|
] as const;
|
|
114
118
|
return (
|
|
115
|
-
this.isAddressInitialized && // address is initialized
|
|
116
|
-
!
|
|
117
|
-
REQUIRED_WHITELIST_KEYS.every(
|
|
118
|
-
(t) => this.whitelist[t] && this.whitelist[t].size > 0
|
|
119
|
-
) // whitelist is initialized
|
|
119
|
+
this.isAddressInitialized() && // address is initialized
|
|
120
|
+
!isEmptyObject(this.poolAddresses) && // poolAddresses is initialized
|
|
121
|
+
REQUIRED_WHITELIST_KEYS.every((t) => this.whitelist[t].size > 0) // whitelist is initialized
|
|
120
122
|
);
|
|
121
123
|
}
|
|
122
124
|
|
|
123
|
-
get
|
|
124
|
-
return this.
|
|
125
|
+
get whitelist() {
|
|
126
|
+
return new Proxy(this._whitelist, {
|
|
127
|
+
get: (target, key: keyof Whitelist) => {
|
|
128
|
+
return target[key] ?? DEFAULT_WHITELIST[key];
|
|
129
|
+
},
|
|
130
|
+
});
|
|
125
131
|
}
|
|
126
132
|
|
|
127
133
|
get poolAddresses() {
|
|
128
|
-
return this._poolAddresses
|
|
134
|
+
return new Proxy(this._poolAddresses, {
|
|
135
|
+
get: (target, key: string) => {
|
|
136
|
+
return target[key] ?? undefined;
|
|
137
|
+
},
|
|
138
|
+
});
|
|
129
139
|
}
|
|
130
140
|
|
|
131
|
-
|
|
132
|
-
|
|
141
|
+
private isAddressInitialized({
|
|
142
|
+
networkType = 'mainnet',
|
|
143
|
+
}: {
|
|
144
|
+
networkType?: NetworkType;
|
|
145
|
+
} = {}) {
|
|
146
|
+
const addresses = this.getAddresses(networkType);
|
|
147
|
+
return !addresses || isEmptyObject(addresses);
|
|
133
148
|
}
|
|
134
149
|
|
|
135
150
|
parseToOldMarketCoin(coinType: string) {
|
|
136
151
|
return `${this.protocolObjectId}::reserve::MarketCoin<${coinType}>`;
|
|
137
152
|
}
|
|
138
153
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
154
|
+
async init({
|
|
155
|
+
networkType = 'mainnet',
|
|
156
|
+
force = false,
|
|
157
|
+
addressId,
|
|
158
|
+
constantsParams = this.params,
|
|
159
|
+
}: {
|
|
160
|
+
networkType?: NetworkType;
|
|
161
|
+
force?: boolean;
|
|
162
|
+
addressId?: string;
|
|
163
|
+
constantsParams?: Partial<ScallopConstantsParams>;
|
|
164
|
+
} = {}) {
|
|
165
|
+
// check if scallop address is initialized
|
|
166
|
+
const addresses = this.getAddresses(networkType);
|
|
167
|
+
if (!addresses || Object.keys(addresses).length === 0 || force) {
|
|
168
|
+
await this.read(addressId); // ScallopAddress read()
|
|
169
|
+
}
|
|
145
170
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
*/
|
|
150
|
-
get coinDecimals() {
|
|
151
|
-
if (this.isEmptyObject(this._coinDecimals)) {
|
|
152
|
-
this._coinDecimals = Object.fromEntries([
|
|
153
|
-
...Object.entries(this.poolAddresses)
|
|
154
|
-
.filter(([_, value]) => !!value)
|
|
155
|
-
.map(([key, value]) => [key, value!.decimals]),
|
|
156
|
-
...Object.entries(this.poolAddresses)
|
|
157
|
-
.filter(([_, value]) => !!value?.sCoinName)
|
|
158
|
-
.map(([_, value]) => [value!.sCoinName, value!.decimals]),
|
|
159
|
-
]);
|
|
171
|
+
// Initialization function
|
|
172
|
+
if (constantsParams.forcePoolAddressInterface) {
|
|
173
|
+
this._poolAddresses = constantsParams.forcePoolAddressInterface;
|
|
160
174
|
}
|
|
161
|
-
return this._coinDecimals;
|
|
162
|
-
}
|
|
163
175
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
*/
|
|
168
|
-
get coinTypes() {
|
|
169
|
-
if (this.isEmptyObject(this._coinTypes))
|
|
170
|
-
this._coinTypes = Object.fromEntries([
|
|
171
|
-
...Object.entries(this.poolAddresses)
|
|
172
|
-
.filter(([_, value]) => !!value)
|
|
173
|
-
.map(([key, value]) => [key, value?.coinType]),
|
|
174
|
-
...Object.entries(this.poolAddresses)
|
|
175
|
-
.filter(([_, value]) => !!value && value.sCoinName && value.sCoinType)
|
|
176
|
-
.map(([_, value]) => [value!.sCoinName, value!.sCoinType]),
|
|
177
|
-
]);
|
|
178
|
-
return this._coinTypes;
|
|
179
|
-
}
|
|
176
|
+
if (constantsParams.forceWhitelistInterface) {
|
|
177
|
+
this._whitelist = constantsParams.forceWhitelistInterface;
|
|
178
|
+
}
|
|
180
179
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
*/
|
|
185
|
-
get coinTypeToCoinNameMap() {
|
|
186
|
-
if (this.isEmptyObject(this._coinTypeToCoinNameMap))
|
|
187
|
-
this._coinTypeToCoinNameMap = Object.fromEntries(
|
|
188
|
-
Object.entries(this.coinTypes).map(([key, val]) => [val, key])
|
|
189
|
-
);
|
|
190
|
-
return this._coinTypeToCoinNameMap;
|
|
191
|
-
}
|
|
180
|
+
if (this.isInitialized && !force) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
192
183
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
get wormholeCoinTypeToCoinName() {
|
|
198
|
-
if (this.isEmptyObject(this._wormholeCoinTypeToCoinNameMap))
|
|
199
|
-
this._wormholeCoinTypeToCoinNameMap = Object.fromEntries(
|
|
200
|
-
Object.entries(this.poolAddresses)
|
|
201
|
-
.filter(([key, value]) => !!value && this.whitelist.wormhole.has(key))
|
|
202
|
-
.map(([_, value]) => [value!.coinType, value!.coinName])
|
|
203
|
-
);
|
|
204
|
-
return this._wormholeCoinTypeToCoinNameMap;
|
|
205
|
-
}
|
|
184
|
+
const [whitelistResponse, poolAddressesResponse] = await Promise.all([
|
|
185
|
+
this.readWhiteList(),
|
|
186
|
+
this.readPoolAddresses(),
|
|
187
|
+
]);
|
|
206
188
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
189
|
+
if (!this.params.forceWhitelistInterface) {
|
|
190
|
+
this._whitelist = Object.keys(this._whitelist).reduce(
|
|
191
|
+
(acc, key: unknown) => {
|
|
192
|
+
const whiteListKey = key as keyof Whitelist;
|
|
193
|
+
const whiteListValue = whitelistResponse[whiteListKey];
|
|
194
|
+
acc[whiteListKey] =
|
|
195
|
+
whiteListValue instanceof Set
|
|
196
|
+
? whiteListValue
|
|
197
|
+
: Array.isArray(whiteListValue)
|
|
198
|
+
? new Set(whiteListValue)
|
|
199
|
+
: new Set();
|
|
200
|
+
return acc;
|
|
201
|
+
},
|
|
202
|
+
{} as Whitelist
|
|
220
203
|
);
|
|
221
|
-
|
|
222
|
-
}
|
|
204
|
+
}
|
|
223
205
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
206
|
+
if (!this.params.forcePoolAddressInterface) {
|
|
207
|
+
this._poolAddresses = Object.fromEntries(
|
|
208
|
+
Object.entries(poolAddressesResponse)
|
|
209
|
+
.filter(([key]) =>
|
|
210
|
+
Object.values(this._whitelist).some((set) => set.has(key))
|
|
211
|
+
)
|
|
212
|
+
.map(([key, value]) => {
|
|
213
|
+
const parsedValue = Object.fromEntries(
|
|
214
|
+
Object.entries(value).map(([k, v]) => [
|
|
215
|
+
k,
|
|
216
|
+
typeof v === 'boolean' ? (v ?? false) : v || undefined,
|
|
217
|
+
])
|
|
218
|
+
);
|
|
219
|
+
return [key, parsedValue as PoolAddress];
|
|
236
220
|
})
|
|
237
221
|
);
|
|
238
|
-
|
|
239
|
-
|
|
222
|
+
}
|
|
223
|
+
this.initConstants();
|
|
240
224
|
}
|
|
241
225
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
.map(([_, value]) => [value!.sCoinType!, value!.sCoinName!])
|
|
252
|
-
);
|
|
226
|
+
private initConstants() {
|
|
227
|
+
this.coinDecimals = Object.fromEntries([
|
|
228
|
+
...Object.entries(this.poolAddresses)
|
|
229
|
+
.filter(([_, value]) => !!value)
|
|
230
|
+
.map(([key, value]) => [key, value!.decimals]),
|
|
231
|
+
...Object.entries(this.poolAddresses)
|
|
232
|
+
.filter(([_, value]) => !!value?.sCoinName)
|
|
233
|
+
.map(([_, value]) => [value!.sCoinName, value!.decimals]),
|
|
234
|
+
]);
|
|
253
235
|
|
|
254
|
-
|
|
255
|
-
|
|
236
|
+
this.coinTypes = Object.fromEntries([
|
|
237
|
+
...Object.entries(this.poolAddresses)
|
|
238
|
+
.filter(([_, value]) => !!value)
|
|
239
|
+
.map(([key, value]) => [key, value?.coinType]),
|
|
240
|
+
...Object.entries(this.poolAddresses)
|
|
241
|
+
.filter(([_, value]) => !!value && value.sCoinName && value.sCoinType)
|
|
242
|
+
.map(([_, value]) => [value!.sCoinName, value!.sCoinType]),
|
|
243
|
+
]);
|
|
256
244
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
*/
|
|
261
|
-
get voloCoinTypeToCoinNameMap() {
|
|
262
|
-
if (this.isEmptyObject(this._voloCoinTypeToCoinNameMap))
|
|
263
|
-
this._voloCoinTypeToCoinNameMap = {
|
|
264
|
-
[this.poolAddresses['vsui']!.coinType]: 'vsui',
|
|
265
|
-
};
|
|
266
|
-
return this._voloCoinTypeToCoinNameMap;
|
|
267
|
-
}
|
|
245
|
+
this.coinTypeToCoinNameMap = Object.fromEntries(
|
|
246
|
+
Object.entries(this.coinTypes).map(([key, val]) => [val, key])
|
|
247
|
+
);
|
|
268
248
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
if (this.isEmptyObject(this._suiBridgeCoinTypeToCoinNameMap))
|
|
275
|
-
this._suiBridgeCoinTypeToCoinNameMap = Object.fromEntries(
|
|
276
|
-
Object.entries(this.poolAddresses)
|
|
277
|
-
.filter(
|
|
278
|
-
([_, value]) =>
|
|
279
|
-
!!value && this.whitelist.suiBridge.has(value.coinName)
|
|
280
|
-
)
|
|
281
|
-
.map(([_, value]) => [value!.coinType, value!.coinName])
|
|
282
|
-
);
|
|
283
|
-
return this._suiBridgeCoinTypeToCoinNameMap;
|
|
284
|
-
}
|
|
249
|
+
this.wormholeCoinTypeToCoinNameMap = Object.fromEntries(
|
|
250
|
+
Object.entries(this.poolAddresses)
|
|
251
|
+
.filter(([key, value]) => !!value && this.whitelist.wormhole.has(key))
|
|
252
|
+
.map(([_, value]) => [value!.coinType, value!.coinName])
|
|
253
|
+
);
|
|
285
254
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
.filter(([_, value]) => !!value && value.sCoinName && value.sCoinType)
|
|
295
|
-
.map(([_, value]) => [value!.sCoinName, value!.sCoinType!])
|
|
296
|
-
);
|
|
255
|
+
this.coinNameToOldMarketCoinTypeMap = Object.fromEntries(
|
|
256
|
+
Object.entries(this.poolAddresses)
|
|
257
|
+
.filter(([_, value]) => !!value)
|
|
258
|
+
.map(([_, value]) => [
|
|
259
|
+
value!.coinName,
|
|
260
|
+
this.parseToOldMarketCoin(value!.coinType),
|
|
261
|
+
])
|
|
262
|
+
);
|
|
297
263
|
|
|
298
|
-
|
|
299
|
-
|
|
264
|
+
this.scoinRawNameToSCoinNameMap = Object.fromEntries(
|
|
265
|
+
Object.entries(this.poolAddresses)
|
|
266
|
+
.filter(([_, value]) => !!value && value.sCoinType && value.sCoinName)
|
|
267
|
+
.map(([_, value]) => {
|
|
268
|
+
const scoinRawName = parseStructTag(value!.sCoinType!).name;
|
|
269
|
+
return [scoinRawName, value!.sCoinName!];
|
|
270
|
+
})
|
|
271
|
+
);
|
|
300
272
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
.flat(),
|
|
313
|
-
]);
|
|
314
|
-
return this._supportedBorrowIncentiveRewards;
|
|
315
|
-
}
|
|
273
|
+
this.scoinTypeToSCoinNameMap = Object.fromEntries(
|
|
274
|
+
Object.entries(this.poolAddresses)
|
|
275
|
+
.filter(([_, value]) => !!value && value.sCoinType && value.sCoinName)
|
|
276
|
+
.map(([_, value]) => [value!.sCoinType!, value!.sCoinName!])
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
const vSuiCoinType = this.poolAddresses['vsui']?.coinType;
|
|
280
|
+
if (vSuiCoinType)
|
|
281
|
+
this.voloCoinTypeToCoinNameMap = {
|
|
282
|
+
[vSuiCoinType]: 'vsui',
|
|
283
|
+
};
|
|
316
284
|
|
|
317
|
-
|
|
318
|
-
|
|
285
|
+
this.suiBridgeCoinTypeToCoinNameMap = Object.fromEntries(
|
|
286
|
+
Object.entries(this.poolAddresses)
|
|
287
|
+
.filter(
|
|
288
|
+
([_, value]) =>
|
|
289
|
+
!!value && this.whitelist.suiBridge.has(value.coinName)
|
|
290
|
+
)
|
|
291
|
+
.map(([_, value]) => [value!.coinType, value!.coinName])
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
this.sCoinTypes = Object.fromEntries(
|
|
295
|
+
Object.entries(this.poolAddresses)
|
|
296
|
+
.filter(([_, value]) => !!value && value.sCoinName && value.sCoinType)
|
|
297
|
+
.map(([_, value]) => [value!.sCoinName, value!.sCoinType!])
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
this.supportedBorrowIncentiveRewards = new Set([
|
|
301
|
+
...Object.values(this.poolAddresses)
|
|
302
|
+
.filter((t) => !!t)
|
|
303
|
+
.map((t) => (t.sCoinName ? [t.coinName, t.sCoinName] : [t.coinName]))
|
|
304
|
+
.flat(),
|
|
305
|
+
]);
|
|
319
306
|
}
|
|
320
307
|
|
|
321
308
|
private async readApi<T>({
|
|
@@ -325,15 +312,7 @@ export class ScallopConstants {
|
|
|
325
312
|
url: string;
|
|
326
313
|
queryKey: QueryKey;
|
|
327
314
|
}) {
|
|
328
|
-
const resp = await this.
|
|
329
|
-
queryKey,
|
|
330
|
-
queryFn: async () => {
|
|
331
|
-
return await this._requestClient.get(url, {
|
|
332
|
-
timeout: 4000,
|
|
333
|
-
});
|
|
334
|
-
},
|
|
335
|
-
});
|
|
336
|
-
|
|
315
|
+
const resp = await this.scallopConstantAxios.get<T>(url, queryKey);
|
|
337
316
|
if (resp.status === 200) {
|
|
338
317
|
return resp.data as T;
|
|
339
318
|
} else {
|
|
@@ -366,60 +345,6 @@ export class ScallopConstants {
|
|
|
366
345
|
queryKey: queryKeys.api.getPoolAddresses(),
|
|
367
346
|
});
|
|
368
347
|
}
|
|
369
|
-
|
|
370
|
-
async init(params?: Partial<ScallopConstantsParams>) {
|
|
371
|
-
if (!this.isAddressInitialized) {
|
|
372
|
-
await this.address.read();
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
if (params?.forcePoolAddressInterface) {
|
|
376
|
-
this._poolAddresses = params?.forcePoolAddressInterface;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
if (params?.forceWhitelistInterface) {
|
|
380
|
-
this._whitelist = params?.forceWhitelistInterface;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
if (this.isInitialized) return;
|
|
384
|
-
|
|
385
|
-
const [whitelistResponse, poolAddressesResponse] = await Promise.all([
|
|
386
|
-
this.readWhiteList(),
|
|
387
|
-
this.readPoolAddresses(),
|
|
388
|
-
]);
|
|
389
|
-
|
|
390
|
-
if (!this.params.forceWhitelistInterface) {
|
|
391
|
-
this._whitelist = Object.keys(this._whitelist).reduce(
|
|
392
|
-
(acc, key: unknown) => {
|
|
393
|
-
const whiteListKey = key as keyof Whitelist;
|
|
394
|
-
const whiteListValue = whitelistResponse[whiteListKey];
|
|
395
|
-
acc[whiteListKey] =
|
|
396
|
-
whiteListValue instanceof Set
|
|
397
|
-
? whiteListValue
|
|
398
|
-
: Array.isArray(whiteListValue)
|
|
399
|
-
? new Set(whiteListValue)
|
|
400
|
-
: new Set();
|
|
401
|
-
return acc;
|
|
402
|
-
},
|
|
403
|
-
{} as Whitelist
|
|
404
|
-
);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
if (!this.params.forcePoolAddressInterface) {
|
|
408
|
-
this._poolAddresses = Object.fromEntries(
|
|
409
|
-
Object.entries(poolAddressesResponse)
|
|
410
|
-
.filter(([key]) =>
|
|
411
|
-
Object.values(this.whitelist).some((set) => set.has(key))
|
|
412
|
-
)
|
|
413
|
-
.map(([key, value]) => {
|
|
414
|
-
const parsedValue = Object.fromEntries(
|
|
415
|
-
Object.entries(value).map(([k, v]) => [
|
|
416
|
-
k,
|
|
417
|
-
typeof v === 'boolean' ? (v ?? false) : v || undefined,
|
|
418
|
-
])
|
|
419
|
-
);
|
|
420
|
-
return [key, parsedValue as PoolAddress];
|
|
421
|
-
})
|
|
422
|
-
);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
348
|
}
|
|
349
|
+
|
|
350
|
+
export default ScallopConstants;
|