@scallop-io/sui-scallop-sdk 3.0.2 → 4.1.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.
Files changed (283) hide show
  1. package/dist/Logger-Cg2iFdpH.d.ts +8 -0
  2. package/dist/builder.cjs +22 -0
  3. package/dist/builder.d.cts +28 -0
  4. package/dist/builder.d.ts +28 -0
  5. package/dist/builder.js +4 -0
  6. package/dist/chunk-33AK5RWM.js +15 -0
  7. package/dist/chunk-6UQ4NWEU.js +3 -0
  8. package/dist/chunk-DIC6P5HB.js +11 -0
  9. package/dist/chunk-S34VOEZN.js +3 -0
  10. package/dist/chunk-VTGQACWU.js +6 -0
  11. package/dist/client.cjs +21 -0
  12. package/dist/client.d.cts +401 -0
  13. package/dist/client.d.ts +401 -0
  14. package/dist/client.js +5 -0
  15. package/dist/errors.cjs +10 -0
  16. package/dist/errors.d.cts +32 -0
  17. package/dist/errors.d.ts +32 -0
  18. package/dist/errors.js +1 -0
  19. package/dist/index.cjs +51 -34
  20. package/dist/index.d.cts +130 -3145
  21. package/dist/index.d.ts +130 -3145
  22. package/dist/index.js +8 -12
  23. package/dist/logger.cjs +6 -0
  24. package/dist/logger.d.cts +7 -0
  25. package/dist/logger.d.ts +7 -0
  26. package/dist/logger.js +1 -0
  27. package/dist/query-DkitepDi.d.ts +3305 -0
  28. package/dist/query.cjs +19 -0
  29. package/dist/query.d.cts +9 -0
  30. package/dist/query.d.ts +9 -0
  31. package/dist/query.js +3 -0
  32. package/dist/types.cjs +2 -0
  33. package/dist/types.d.cts +90 -0
  34. package/dist/types.d.ts +90 -0
  35. package/dist/types.js +1 -0
  36. package/package.json +98 -56
  37. package/src/constants/api.ts +2 -0
  38. package/src/constants/coinType.ts +2 -0
  39. package/src/constants/common.ts +0 -7
  40. package/src/constants/index.ts +2 -0
  41. package/src/constants/queryKeys.ts +14 -7
  42. package/src/constants/testAddress.ts +1 -0
  43. package/src/datasources/api.ts +34 -0
  44. package/src/datasources/indexer.ts +8 -0
  45. package/src/datasources/onchain.ts +121 -0
  46. package/src/entries/builder.ts +5 -0
  47. package/src/entries/client.ts +3 -0
  48. package/src/entries/errors.ts +2 -0
  49. package/src/entries/index.ts +17 -0
  50. package/src/entries/logger.ts +2 -0
  51. package/src/entries/query.ts +6 -0
  52. package/src/entries/types.ts +2 -0
  53. package/src/errors/ScallopConfigError.ts +8 -0
  54. package/src/errors/ScallopError.ts +30 -0
  55. package/src/errors/ScallopIndexerError.ts +8 -0
  56. package/src/errors/ScallopParseError.ts +8 -0
  57. package/src/errors/ScallopRpcError.ts +8 -0
  58. package/src/errors/ScallopTransactionBuildError.ts +8 -0
  59. package/src/errors/index.ts +6 -0
  60. package/src/logger/Logger.ts +6 -0
  61. package/src/logger/consoleLogger.ts +13 -0
  62. package/src/logger/index.ts +3 -0
  63. package/src/logger/noopLogger.ts +8 -0
  64. package/src/mappers/index.ts +1 -0
  65. package/src/mappers/moveTypeMapper.ts +48 -0
  66. package/src/models/index.ts +8 -10
  67. package/src/models/interface.ts +9 -9
  68. package/src/models/scallop.ts +9 -16
  69. package/src/models/scallopAddress/const.ts +416 -0
  70. package/src/models/scallopAddress/index.ts +188 -0
  71. package/src/models/scallopAddress/types.ts +212 -0
  72. package/src/models/{scallopBuilder.ts → scallopBuilder/index.ts} +65 -29
  73. package/src/models/scallopBuilder/types.ts +37 -0
  74. package/src/models/{scallopClient.ts → scallopClient/index.ts} +157 -598
  75. package/src/models/scallopClient/types.ts +25 -0
  76. package/src/models/scallopConstants/config/AddressConfigSource.ts +13 -0
  77. package/src/models/scallopConstants/config/ConfigValidator.ts +70 -0
  78. package/src/models/scallopConstants/config/PoolAddressConfigSource.ts +12 -0
  79. package/src/models/scallopConstants/config/ScallopConfig.ts +80 -0
  80. package/src/models/scallopConstants/config/ScallopConfigSnapshot.ts +46 -0
  81. package/src/models/scallopConstants/config/WhitelistConfigSource.ts +16 -0
  82. package/src/models/scallopConstants/config/index.ts +6 -0
  83. package/src/models/scallopConstants/const.ts +19 -0
  84. package/src/models/scallopConstants/constantsSource.ts +98 -0
  85. package/src/models/scallopConstants/deriveConstants.ts +150 -0
  86. package/src/models/scallopConstants/index.ts +257 -0
  87. package/src/models/scallopConstants/loadConstantsState.ts +135 -0
  88. package/src/models/scallopConstants/types.ts +77 -0
  89. package/src/models/scallopConstants/utils.ts +69 -0
  90. package/src/models/scallopQuery/index.ts +1279 -0
  91. package/src/models/scallopQuery/types.ts +9 -0
  92. package/src/models/scallopQuery/utils.ts +13 -0
  93. package/src/models/scallopUtils/index.ts +505 -0
  94. package/src/models/scallopUtils/types.ts +30 -0
  95. package/src/models/transactionExecutor.ts +122 -0
  96. package/src/repositories/addressApi/helpers.ts +14 -0
  97. package/src/repositories/addressApi/index.ts +24 -0
  98. package/src/repositories/addressApi/schema.ts +0 -0
  99. package/src/repositories/addressApi/types.ts +177 -0
  100. package/src/repositories/base.ts +38 -0
  101. package/src/repositories/borrowIncentive/bcs.ts +11 -0
  102. package/src/repositories/borrowIncentive/helpers.ts +396 -0
  103. package/src/repositories/borrowIncentive/index.ts +52 -0
  104. package/src/{types/query/borrowIncentive.ts → repositories/borrowIncentive/types.ts} +69 -23
  105. package/src/repositories/borrowIncentive/utils.ts +234 -0
  106. package/src/repositories/cache.ts +4 -0
  107. package/src/repositories/coinBalance/helpers.ts +394 -0
  108. package/src/repositories/coinBalance/index.ts +69 -0
  109. package/src/repositories/coinBalance/types.ts +33 -0
  110. package/src/repositories/flashloan/const.ts +3 -0
  111. package/src/repositories/flashloan/helpers.ts +107 -0
  112. package/src/repositories/flashloan/index.ts +34 -0
  113. package/src/repositories/flashloan/types.ts +16 -0
  114. package/src/repositories/isolatedAssets/bcs.ts +4 -0
  115. package/src/repositories/isolatedAssets/const.ts +2 -0
  116. package/src/repositories/isolatedAssets/helpers.ts +91 -0
  117. package/src/repositories/isolatedAssets/index.ts +42 -0
  118. package/src/repositories/isolatedAssets/types.ts +35 -0
  119. package/src/repositories/loyaltyProgram/bcs.ts +7 -0
  120. package/src/repositories/loyaltyProgram/helpers.ts +117 -0
  121. package/src/repositories/loyaltyProgram/index.ts +28 -0
  122. package/src/repositories/loyaltyProgram/schema.ts +18 -0
  123. package/src/repositories/loyaltyProgram/types.ts +37 -0
  124. package/src/repositories/market/const.ts +6 -0
  125. package/src/repositories/market/helpers.ts +740 -0
  126. package/src/repositories/market/index.ts +137 -0
  127. package/src/repositories/market/mapper.ts +30 -0
  128. package/src/repositories/market/types.ts +443 -0
  129. package/src/repositories/market/utils.ts +285 -0
  130. package/src/repositories/obligation/helpers.ts +228 -0
  131. package/src/repositories/obligation/index.ts +51 -0
  132. package/src/repositories/obligation/types.ts +71 -0
  133. package/src/repositories/obligation/utils.ts +57 -0
  134. package/src/repositories/poolAddresses/const.ts +5 -0
  135. package/src/repositories/poolAddresses/helpers.ts +422 -0
  136. package/src/repositories/poolAddresses/index.ts +56 -0
  137. package/src/repositories/poolAddresses/schema.ts +34 -0
  138. package/src/repositories/poolAddresses/types.ts +69 -0
  139. package/src/repositories/price/const.ts +1 -0
  140. package/src/repositories/price/helpers.ts +237 -0
  141. package/src/repositories/price/index.ts +91 -0
  142. package/src/repositories/price/schema.ts +24 -0
  143. package/src/repositories/price/types.ts +56 -0
  144. package/src/repositories/price/utils.ts +21 -0
  145. package/src/repositories/referral/bcs.ts +3 -0
  146. package/src/repositories/referral/helper.ts +24 -0
  147. package/src/repositories/referral/index.ts +31 -0
  148. package/src/repositories/referral/types.ts +33 -0
  149. package/src/repositories/spool/const.ts +1 -0
  150. package/src/repositories/spool/helpers.ts +471 -0
  151. package/src/repositories/spool/index.ts +135 -0
  152. package/src/{types/query/spool.ts → repositories/spool/types.ts} +67 -2
  153. package/src/repositories/spool/utils.ts +215 -0
  154. package/src/repositories/types.ts +39 -0
  155. package/src/repositories/utils.ts +137 -0
  156. package/src/repositories/veSca/bcs.ts +6 -0
  157. package/src/repositories/veSca/helpers.ts +341 -0
  158. package/src/repositories/veSca/index.ts +57 -0
  159. package/src/repositories/veSca/types.ts +79 -0
  160. package/src/repositories/veScaLoyaltyProgram/bcs.ts +3 -0
  161. package/src/repositories/veScaLoyaltyProgram/helpers.ts +135 -0
  162. package/src/repositories/veScaLoyaltyProgram/index.ts +28 -0
  163. package/src/repositories/veScaLoyaltyProgram/schema.ts +15 -0
  164. package/src/repositories/veScaLoyaltyProgram/types.ts +47 -0
  165. package/src/repositories/wiring/datasources.ts +42 -0
  166. package/src/repositories/wiring/metadata.ts +292 -0
  167. package/src/repositories/wiring/registry.ts +194 -0
  168. package/src/repositories/wiring/source.ts +63 -0
  169. package/src/repositories/xOracle/bcs.ts +7 -0
  170. package/src/repositories/xOracle/const.ts +1 -0
  171. package/src/repositories/xOracle/helpers.ts +304 -0
  172. package/src/repositories/xOracle/index.ts +45 -0
  173. package/src/repositories/xOracle/types.ts +96 -0
  174. package/src/repositories/xOracle/utils.ts +3 -0
  175. package/src/services/client/BorrowService.ts +229 -0
  176. package/src/services/client/CollateralService.ts +76 -0
  177. package/src/services/client/LendingService.ts +75 -0
  178. package/src/services/client/ReferralService.ts +71 -0
  179. package/src/services/client/SpoolService.ts +170 -0
  180. package/src/services/client/VeScaService.ts +142 -0
  181. package/src/services/client/types.ts +44 -0
  182. package/src/services/index.ts +8 -0
  183. package/src/services/query/portfolioCalculations.ts +1171 -0
  184. package/src/txBuilders/borrowIncentive/index.ts +80 -0
  185. package/src/txBuilders/borrowIncentive/moveCalls.ts +124 -0
  186. package/src/txBuilders/borrowIncentive/quick.ts +207 -0
  187. package/src/txBuilders/context.ts +62 -0
  188. package/src/txBuilders/core/index.ts +95 -0
  189. package/src/txBuilders/core/moveCalls.ts +241 -0
  190. package/src/txBuilders/core/quick.ts +306 -0
  191. package/src/{builders → txBuilders}/index.ts +35 -9
  192. package/src/txBuilders/loyaltyProgram/index.ts +78 -0
  193. package/src/txBuilders/loyaltyProgram/moveCalls.ts +44 -0
  194. package/src/txBuilders/loyaltyProgram/quick.ts +58 -0
  195. package/src/txBuilders/manifest.ts +160 -0
  196. package/src/txBuilders/modules.ts +70 -0
  197. package/src/{builders → txBuilders}/oracles/index.ts +3 -2
  198. package/src/{builders → txBuilders}/oracles/pyth.ts +4 -3
  199. package/src/txBuilders/referral/index.ts +72 -0
  200. package/src/txBuilders/referral/moveCalls.ts +93 -0
  201. package/src/txBuilders/referral/quick.ts +57 -0
  202. package/src/txBuilders/sCoin/index.ts +72 -0
  203. package/src/txBuilders/sCoin/moveCalls.ts +36 -0
  204. package/src/txBuilders/sCoin/quick.ts +34 -0
  205. package/src/txBuilders/spool/index.ts +82 -0
  206. package/src/txBuilders/spool/moveCalls.ts +79 -0
  207. package/src/{builders/spoolBuilder.ts → txBuilders/spool/quick.ts} +22 -162
  208. package/src/txBuilders/utils.ts +36 -0
  209. package/src/txBuilders/verify.ts +45 -0
  210. package/src/txBuilders/vesca/index.ts +75 -0
  211. package/src/txBuilders/vesca/moveCalls.ts +147 -0
  212. package/src/{builders/vescaBuilder.ts → txBuilders/vesca/quick.ts} +85 -274
  213. package/src/types/address.ts +4 -178
  214. package/src/types/builder/borrowIncentive.ts +4 -3
  215. package/src/types/builder/core.ts +6 -33
  216. package/src/types/builder/index.ts +5 -1
  217. package/src/types/builder/loyaltyProgram.ts +4 -3
  218. package/src/types/builder/modules.ts +49 -0
  219. package/src/types/builder/referral.ts +5 -4
  220. package/src/types/builder/sCoin.ts +20 -2
  221. package/src/types/builder/spool.ts +22 -2
  222. package/src/types/builder/vesca.ts +4 -12
  223. package/src/types/constant/index.ts +3 -1
  224. package/src/types/constant/queryKeys.ts +15 -8
  225. package/src/types/index.ts +5 -6
  226. package/src/types/internal/dto.ts +46 -0
  227. package/src/types/internal/index.ts +2 -0
  228. package/src/types/internal/move.ts +13 -0
  229. package/src/types/public/index.ts +21 -0
  230. package/src/types/query/core.ts +0 -317
  231. package/src/types/query/index.ts +3 -4
  232. package/src/types/query/portfolio.ts +2 -15
  233. package/src/types/repositories/borrowIncentive.ts +12 -0
  234. package/src/types/repositories/index.ts +9 -0
  235. package/src/types/repositories/loyaltyProgram.ts +2 -0
  236. package/src/types/repositories/market.ts +13 -0
  237. package/src/types/repositories/spool.ts +21 -0
  238. package/src/types/repositories/veSca.ts +5 -0
  239. package/src/types/repositories/veScaLoyaltyProgram.ts +2 -0
  240. package/src/types/sui.ts +0 -1
  241. package/src/utils/array.ts +7 -0
  242. package/src/utils/cache.ts +17 -0
  243. package/src/utils/object.ts +30 -12
  244. package/src/utils/query.ts +9 -190
  245. package/src/utils/vesca.ts +0 -8
  246. package/src/builders/borrowIncentiveBuilder.ts +0 -372
  247. package/src/builders/coreBuilder.ts +0 -636
  248. package/src/builders/loyaltyProgramBuilder.ts +0 -142
  249. package/src/builders/referralBuilder.ts +0 -192
  250. package/src/builders/sCoinBuilder.ts +0 -124
  251. package/src/index.ts +0 -13
  252. package/src/models/scallopAddress.ts +0 -841
  253. package/src/models/scallopAxios.ts +0 -185
  254. package/src/models/scallopConstants.ts +0 -380
  255. package/src/models/scallopIndexer.ts +0 -226
  256. package/src/models/scallopQuery.ts +0 -974
  257. package/src/models/scallopQueryClient.ts +0 -29
  258. package/src/models/scallopSuiKit.ts +0 -480
  259. package/src/models/scallopUtils.ts +0 -734
  260. package/src/queries/borrowIncentiveQuery.ts +0 -361
  261. package/src/queries/borrowLimitQuery.ts +0 -33
  262. package/src/queries/coreQuery.ts +0 -1173
  263. package/src/queries/flashloanFeeQuery.ts +0 -92
  264. package/src/queries/index.ts +0 -15
  265. package/src/queries/isolatedAssetQuery.ts +0 -103
  266. package/src/queries/loyaltyProgramQuery.ts +0 -178
  267. package/src/queries/ownerQuery.ts +0 -32
  268. package/src/queries/poolAddressesQuery.ts +0 -340
  269. package/src/queries/portfolioQuery.ts +0 -1149
  270. package/src/queries/priceQuery.ts +0 -37
  271. package/src/queries/referralQuery.ts +0 -42
  272. package/src/queries/sCoinQuery.ts +0 -195
  273. package/src/queries/spoolQuery.ts +0 -542
  274. package/src/queries/supplyLimitQuery.ts +0 -32
  275. package/src/queries/switchboardQuery.ts +0 -65
  276. package/src/queries/vescaQuery.ts +0 -312
  277. package/src/queries/xOracleQuery.ts +0 -149
  278. package/src/types/constant/common.ts +0 -55
  279. package/src/types/query/loyaltyProgram.ts +0 -12
  280. package/src/types/query/vesca.ts +0 -27
  281. package/src/utils/index.ts +0 -7
  282. package/src/utils/indexer.ts +0 -47
  283. /package/src/{models → datasources}/rateLimiter.ts +0 -0
@@ -1,841 +0,0 @@
1
- import { NetworkType } from '@scallop-io/sui-kit';
2
- import { API_BASE_URL, queryKeys } from 'src/constants/index.js';
3
- import { AddressesInterface, AddressStringPath } from 'src/types/index.js';
4
- import ScallopAxios, { ScallopAxiosParams } from './scallopAxios.js';
5
- import { QueryKey } from '@tanstack/query-core';
6
- import { AxiosRequestConfig } from 'axios';
7
- import { parseUrl } from 'src/utils/url.js';
8
-
9
- export type ScallopAddressParams = {
10
- addressId?: string;
11
- urls?: {
12
- addresses?: string[];
13
- };
14
- auth?: string;
15
- networkType?: NetworkType;
16
- forceAddressesInterface?: Partial<Record<NetworkType, AddressesInterface>>;
17
- defaultValues?: {
18
- addresses?: Partial<Record<NetworkType, AddressesInterface>>;
19
- };
20
- } & ScallopAxiosParams;
21
-
22
- const EMPTY_ADDRESSES: AddressesInterface = {
23
- core: {
24
- version: '',
25
- versionCap: '',
26
- object: '',
27
- market: '',
28
- adminCap: '',
29
- coinDecimalsRegistry: '',
30
- obligationAccessStore: '',
31
- coins: {
32
- cetus: {
33
- id: '',
34
- metaData: '',
35
- treasury: '',
36
- symbol: '',
37
- coinType: '',
38
- decimals: 0,
39
- oracle: {
40
- supra: '',
41
- switchboard: '',
42
- pyth: {
43
- feed: '',
44
- feedObject: '',
45
- },
46
- },
47
- },
48
- wapt: {
49
- id: '',
50
- metaData: '',
51
- treasury: '',
52
- symbol: '',
53
- coinType: '',
54
- decimals: 0,
55
- oracle: {
56
- supra: '',
57
- switchboard: '',
58
- pyth: {
59
- feed: '',
60
- feedObject: '',
61
- },
62
- },
63
- },
64
- wsol: {
65
- id: '',
66
- metaData: '',
67
- treasury: '',
68
- symbol: '',
69
- coinType: '',
70
- decimals: 0,
71
- oracle: {
72
- supra: '',
73
- switchboard: '',
74
- pyth: {
75
- feed: '',
76
- feedObject: '',
77
- },
78
- },
79
- },
80
- wbtc: {
81
- id: '',
82
- metaData: '',
83
- treasury: '',
84
- symbol: '',
85
- coinType: '',
86
- decimals: 0,
87
- oracle: {
88
- supra: '',
89
- switchboard: '',
90
- pyth: {
91
- feed: '',
92
- feedObject: '',
93
- },
94
- },
95
- },
96
- weth: {
97
- id: '',
98
- metaData: '',
99
- treasury: '',
100
- symbol: '',
101
- coinType: '',
102
- decimals: 0,
103
- oracle: {
104
- supra: '',
105
- switchboard: '',
106
- pyth: {
107
- feed: '',
108
- feedObject: '',
109
- },
110
- },
111
- },
112
- wusdc: {
113
- id: '',
114
- metaData: '',
115
- treasury: '',
116
- symbol: '',
117
- coinType: '',
118
- decimals: 0,
119
- oracle: {
120
- supra: '',
121
- switchboard: '',
122
- pyth: {
123
- feed: '',
124
- feedObject: '',
125
- },
126
- },
127
- },
128
- wusdt: {
129
- id: '',
130
- metaData: '',
131
- treasury: '',
132
- symbol: '',
133
- coinType: '',
134
- decimals: 0,
135
- oracle: {
136
- supra: '',
137
- switchboard: '',
138
- pyth: {
139
- feed: '',
140
- feedObject: '',
141
- },
142
- },
143
- },
144
- sui: {
145
- id: '',
146
- metaData: '',
147
- treasury: '',
148
- symbol: '',
149
- coinType: '',
150
- decimals: 0,
151
- oracle: {
152
- supra: '',
153
- switchboard: '',
154
- pyth: {
155
- feed: '',
156
- feedObject: '',
157
- },
158
- },
159
- },
160
- afsui: {
161
- id: '',
162
- metaData: '',
163
- treasury: '',
164
- symbol: '',
165
- coinType: '',
166
- decimals: 0,
167
- oracle: {
168
- supra: '',
169
- switchboard: '',
170
- pyth: {
171
- feed: '',
172
- feedObject: '',
173
- },
174
- },
175
- },
176
- hasui: {
177
- id: '',
178
- metaData: '',
179
- treasury: '',
180
- symbol: '',
181
- coinType: '',
182
- decimals: 0,
183
- oracle: {
184
- supra: '',
185
- switchboard: '',
186
- pyth: {
187
- feed: '',
188
- feedObject: '',
189
- },
190
- },
191
- },
192
- vsui: {
193
- id: '',
194
- metaData: '',
195
- treasury: '',
196
- symbol: '',
197
- coinType: '',
198
- decimals: 0,
199
- oracle: {
200
- supra: '',
201
- switchboard: '',
202
- pyth: {
203
- feed: '',
204
- feedObject: '',
205
- },
206
- },
207
- },
208
- sca: {
209
- id: '',
210
- metaData: '',
211
- treasury: '',
212
- symbol: '',
213
- coinType: '',
214
- decimals: 0,
215
- oracle: {
216
- supra: '',
217
- switchboard: '',
218
- pyth: {
219
- feed: '',
220
- feedObject: '',
221
- },
222
- },
223
- },
224
- },
225
- oracles: {
226
- xOracle: '',
227
- xOracleCap: '',
228
- primaryPriceUpdatePolicyObject: '',
229
- secondaryPriceUpdatePolicyObject: '',
230
- primaryPriceUpdatePolicyVecsetId: '',
231
- secondaryPriceUpdatePolicyVecsetId: '',
232
- supra: { registry: '', registryCap: '', holder: '' },
233
- switchboard: {
234
- registry: '',
235
- registryCap: '',
236
- registryTableId: '',
237
- state: '',
238
- },
239
- pyth: {
240
- registry: '',
241
- registryCap: '',
242
- state: '',
243
- wormhole: '',
244
- wormholeState: '',
245
- },
246
- },
247
- packages: {
248
- coinDecimalsRegistry: {
249
- id: '',
250
- upgradeCap: '',
251
- },
252
- math: {
253
- id: '',
254
- upgradeCap: '',
255
- },
256
- whitelist: {
257
- id: '',
258
- upgradeCap: '',
259
- },
260
- x: {
261
- id: '',
262
- upgradeCap: '',
263
- },
264
- protocol: {
265
- id: '',
266
- upgradeCap: '',
267
- },
268
- protocolWhitelist: {
269
- id: '',
270
- upgradeCap: '',
271
- },
272
- query: {
273
- id: '',
274
- upgradeCap: '',
275
- },
276
- supra: { id: '', upgradeCap: '' },
277
- pyth: {
278
- id: '',
279
- upgradeCap: '',
280
- },
281
- switchboard: { id: '', upgradeCap: '' },
282
- xOracle: {
283
- id: '',
284
- upgradeCap: '',
285
- },
286
- testCoin: { id: '', upgradeCap: '' },
287
- },
288
- },
289
- spool: {
290
- id: '',
291
- adminCap: '',
292
- object: '',
293
- pools: {
294
- sweth: {
295
- id: '',
296
- rewardPoolId: '',
297
- },
298
- ssui: {
299
- id: '',
300
- rewardPoolId: '',
301
- },
302
- swusdc: {
303
- id: '',
304
- rewardPoolId: '',
305
- },
306
- swusdt: {
307
- id: '',
308
- rewardPoolId: '',
309
- },
310
- scetus: {
311
- id: '',
312
- rewardPoolId: '',
313
- },
314
- safsui: {
315
- id: '',
316
- rewardPoolId: '',
317
- },
318
- shasui: {
319
- id: '',
320
- rewardPoolId: '',
321
- },
322
- svsui: {
323
- id: '',
324
- rewardPoolId: '',
325
- },
326
- },
327
- config: '',
328
- },
329
- borrowIncentive: {
330
- id: '',
331
- adminCap: '',
332
- object: '',
333
- query: '',
334
- incentivePools: '',
335
- incentiveAccounts: '',
336
- config: '',
337
- },
338
- vesca: {
339
- id: '',
340
- object: '',
341
- adminCap: '',
342
- tableId: '',
343
- table: '',
344
- treasury: '',
345
- config: '',
346
- subsTable: '',
347
- subsTableId: '',
348
- subsWhitelist: '',
349
- },
350
- referral: {
351
- id: '',
352
- version: '',
353
- object: '',
354
- adminCap: '',
355
- referralBindings: '',
356
- bindingTableId: '',
357
- referralRevenuePool: '',
358
- revenueTableId: '',
359
- referralTiers: '',
360
- tiersTableId: '',
361
- authorizedWitnessList: '',
362
- },
363
- loyaltyProgram: {
364
- id: '',
365
- object: '',
366
- rewardPool: '',
367
- userRewardTableId: '',
368
- },
369
- veScaLoyaltyProgram: {
370
- id: '',
371
- object: '',
372
- veScaRewardPool: '',
373
- veScaRewardTableId: '',
374
- },
375
- scoin: {
376
- id: '',
377
- coins: {
378
- ssui: {
379
- coinType: '',
380
- treasury: '',
381
- metaData: '',
382
- symbol: '',
383
- },
384
- scetus: {
385
- coinType: '',
386
- treasury: '',
387
- metaData: '',
388
- symbol: '',
389
- },
390
- ssca: {
391
- coinType: '',
392
- treasury: '',
393
- metaData: '',
394
- symbol: '',
395
- },
396
- swusdc: {
397
- coinType: '',
398
- treasury: '',
399
- metaData: '',
400
- symbol: '',
401
- },
402
- swusdt: {
403
- coinType: '',
404
- treasury: '',
405
- metaData: '',
406
- symbol: '',
407
- },
408
- sweth: {
409
- coinType: '',
410
- treasury: '',
411
- metaData: '',
412
- symbol: '',
413
- },
414
- safsui: {
415
- coinType: '',
416
- treasury: '',
417
- metaData: '',
418
- symbol: '',
419
- },
420
- shasui: {
421
- coinType: '',
422
- treasury: '',
423
- metaData: '',
424
- symbol: '',
425
- },
426
- svsui: {
427
- coinType: '',
428
- treasury: '',
429
- metaData: '',
430
- symbol: '',
431
- },
432
- },
433
- },
434
- };
435
-
436
- class ScallopAddress {
437
- private currentAddresses?: AddressesInterface;
438
- private addressId?: string;
439
- private network: NetworkType;
440
- private auth: string;
441
-
442
- public readonly scallopAxios: ScallopAxios;
443
- private readonly addressMap = new Map<NetworkType, AddressesInterface>();
444
- private readonly defaultParamValues = {
445
- addressId: '695fcdc084f790c04eb068dc',
446
- network: 'mainnet' as NetworkType,
447
- } as const;
448
-
449
- constructor(public readonly params: ScallopAddressParams = {}) {
450
- this.scallopAxios = new ScallopAxios({
451
- ...this.defaultParamValues,
452
- ...params,
453
- });
454
-
455
- this.network = params.networkType ?? 'mainnet';
456
- this.addressId = params.addressId ?? this.defaultParamValues.addressId;
457
- this.auth = params.auth ?? '';
458
-
459
- if (params.forceAddressesInterface) {
460
- this.initializeForcedAddresses(params.forceAddressesInterface);
461
- }
462
- }
463
-
464
- private initializeForcedAddresses(
465
- forcedAddresses: Partial<Record<NetworkType, AddressesInterface>>
466
- ): void {
467
- const validNetworks: NetworkType[] = [
468
- 'localnet',
469
- 'devnet',
470
- 'testnet',
471
- 'mainnet',
472
- ];
473
-
474
- Object.entries(forcedAddresses).forEach(([network, addresses]) => {
475
- if (validNetworks.includes(network as NetworkType)) {
476
- const typedNetwork = network as NetworkType;
477
- this.addressMap.set(typedNetwork, addresses);
478
-
479
- if (typedNetwork === this.network) {
480
- this.currentAddresses = addresses;
481
- }
482
- }
483
- });
484
- }
485
-
486
- get axiosClient() {
487
- return this.scallopAxios;
488
- }
489
-
490
- get queryClient() {
491
- return this.axiosClient.queryClient;
492
- }
493
-
494
- get defaultValues() {
495
- return this.params.defaultValues;
496
- }
497
-
498
- getId() {
499
- return this.addressId;
500
- }
501
-
502
- /**
503
- * Get the address at the provided path.
504
- *
505
- * @param path - The path of the address to get.
506
- * @return The address at the provided path.
507
- */
508
- public get(path: AddressStringPath) {
509
- if (this.currentAddresses) {
510
- const value = path
511
- .split('.')
512
- .reduce(
513
- (nestedAddressObj: any, key: string) =>
514
- typeof nestedAddressObj === 'object'
515
- ? nestedAddressObj[key]
516
- : nestedAddressObj,
517
- this.currentAddresses
518
- );
519
- return value || undefined;
520
- } else {
521
- return undefined;
522
- }
523
- }
524
-
525
- /**
526
- * Sets the address for the specified path, it does not interact with the API.
527
- *
528
- * @param path - The path of the address to set.
529
- * @param address - The address be setted to the tartget path.
530
- * @return The addresses.
531
- */
532
- public set(path: AddressStringPath, address: string) {
533
- if (this.currentAddresses) {
534
- const keys = path.split('.');
535
- keys.reduce((nestedAddressObj: any, key: string, index) => {
536
- if (index === keys.length - 1) {
537
- nestedAddressObj[key] = address;
538
- } else {
539
- return nestedAddressObj[key];
540
- }
541
- }, this.currentAddresses);
542
- }
543
- return this.currentAddresses;
544
- }
545
-
546
- /**
547
- * Synchronize the specified network addresses from the addresses map to the
548
- * current addresses and change the default network to specified network.
549
- *
550
- * @param network - Specifies which network's addresses you want to get.
551
- * @return Current addresses.
552
- */
553
- public switchCurrentAddresses(network: NetworkType) {
554
- if (this.addressMap.has(network)) {
555
- this.currentAddresses = this.addressMap.get(network);
556
- this.network = network;
557
- }
558
- return this.currentAddresses;
559
- }
560
-
561
- /**
562
- * Get the addresses, If `network` is not provided, returns the current
563
- * addresses or the default network addresses in the addresses map.
564
- *
565
- * @param network - Specifies which network's addresses you want to get.
566
- */
567
- public getAddresses(network?: NetworkType) {
568
- if (network) {
569
- return this.addressMap.get(network);
570
- } else {
571
- return this.currentAddresses ?? this.addressMap.get(this.network);
572
- }
573
- }
574
-
575
- /**
576
- * Set the addresses into addresses map. If the specified network is the same
577
- * as the current network, the current addresses will be updated at the same time.
578
- *
579
- * @param addresses - The addresses be setted to the tartget network.
580
- * @param network - Specifies which network's addresses you want to set.
581
- * @return The addresses.
582
- */
583
- public setAddresses(addresses: AddressesInterface, network?: NetworkType) {
584
- const targetNetwork = network || this.network;
585
- if (targetNetwork === this.network) this.currentAddresses = addresses;
586
- this.addressMap.set(targetNetwork, addresses);
587
- }
588
-
589
- /**
590
- * Get all addresses.
591
- *
592
- * @return All addresses.
593
- */
594
- public getAllAddresses() {
595
- return Object.fromEntries(this.addressMap);
596
- }
597
-
598
- /**
599
- * Create a new addresses through the API and synchronize it back to the
600
- * instance.
601
- *
602
- * @description
603
- * If the `network` is not specified, the mainnet is used by default.
604
- * If no `addresses` from instance or parameter is provided, an addresses with
605
- * all empty strings is created by default.
606
- *
607
- * This function only allows for one addresses to be input into a specific network
608
- * at a time, and does not provide an addresses map for setting addresses
609
- * across all networks at once.
610
- *
611
- * @param params.addresses - The addresses be setted to the tartget network.
612
- * @param params.network - Specifies which network's addresses you want to set.
613
- * @param params.auth - The authentication API key.
614
- * @param params.memo - Add memo to the addresses created in the API.
615
- * @return All addresses.
616
- */
617
- async create(params?: {
618
- addresses?: AddressesInterface | undefined;
619
- network?: NetworkType | undefined;
620
- auth?: string | undefined;
621
- memo?: string | undefined;
622
- }) {
623
- const { addresses, network, auth, memo } = params ?? {};
624
- const apiKey = auth || this.auth || undefined;
625
- const targetNetwork = network || this.network;
626
- const targetAddresses =
627
- addresses ||
628
- this.currentAddresses ||
629
- this.addressMap.get(targetNetwork) ||
630
- EMPTY_ADDRESSES;
631
-
632
- if (apiKey !== undefined) {
633
- this.addressMap.clear();
634
- this.setAddresses(targetAddresses, targetNetwork);
635
- const response = await this.axiosClient.post(
636
- `/addresses`,
637
- JSON.stringify({ ...Object.fromEntries(this.addressMap), memo }),
638
- {
639
- headers: {
640
- 'Content-Type': 'application/json',
641
- 'api-key': auth || this.auth,
642
- },
643
- }
644
- );
645
-
646
- if (response.status === 201) {
647
- for (const [network, addresses] of Object.entries<AddressesInterface>(
648
- response.data
649
- )) {
650
- if (['localnet', 'devnet', 'testnet', 'mainnet'].includes(network)) {
651
- if (network === this.network) this.currentAddresses = addresses;
652
- this.addressMap.set(network as NetworkType, addresses);
653
- }
654
- }
655
- this.addressId = response.data.id;
656
- return this.getAllAddresses();
657
- } else {
658
- throw Error('Failed to create addresses.');
659
- }
660
- } else {
661
- throw Error("You don't have permission to access this request.");
662
- }
663
- }
664
-
665
- protected async readApi<T>({
666
- url,
667
- queryKey,
668
- config,
669
- }: {
670
- url: string;
671
- queryKey: QueryKey;
672
- config?: AxiosRequestConfig;
673
- }) {
674
- const resp = await this.axiosClient.get<T>(url, queryKey, config);
675
- if (resp.status === 200) {
676
- return resp.data as T;
677
- } else {
678
- throw Error(
679
- `Error: ${resp.status}; Failed to read ${url} ${resp.statusText}`
680
- );
681
- }
682
- }
683
-
684
- /**
685
- * Read and synchronizes all addresses from the API into instance.
686
- *
687
- * @param id - The id of the addresses to get.
688
- * @return All addresses.
689
- */
690
- async read(id?: string) {
691
- const addressId = id || this.addressId || undefined;
692
- if (addressId !== undefined) {
693
- const response = await (async () => {
694
- const urls = (this.params.urls?.addresses ?? [API_BASE_URL]).map(
695
- (url) => `${parseUrl(url)}/addresses/${addressId}`
696
- );
697
- for (const url of urls) {
698
- try {
699
- return await this.readApi<
700
- Record<NetworkType, AddressesInterface> & { id?: string }
701
- >({
702
- url,
703
- queryKey: queryKeys.api.getAddresses({ addressId }) as string[],
704
- });
705
- } catch (e) {
706
- console.error(`${e}`); // Trying next url in the list
707
- }
708
- }
709
-
710
- return {
711
- id: '',
712
- mainnet: this.defaultValues?.addresses?.mainnet ?? EMPTY_ADDRESSES,
713
- };
714
- })();
715
-
716
- const isNetworkValid = (network: string): network is NetworkType =>
717
- ['localnet', 'devnet', 'testnet', 'mainnet'].includes(network);
718
-
719
- for (const [network, addresses] of Object.entries(response)) {
720
- if (isNetworkValid(network) && typeof addresses === 'object') {
721
- if (network === this.network) this.currentAddresses = addresses;
722
-
723
- this.addressMap.set(network, addresses);
724
- }
725
- }
726
- this.addressId = response.id;
727
- return this.getAllAddresses();
728
- } else {
729
- throw Error('Please provide API addresses id.');
730
- }
731
- }
732
-
733
- /**
734
- * Update the addresses through the API and synchronize it back to the
735
- * instance.
736
- *
737
- * @description
738
- * If the `network` is not specified, the mainnet is used by default.
739
- * If no `addresses` from instance or parameter is provided, an addresses with
740
- * all empty strings is created by default.
741
- *
742
- * This function only allows for one addresses to be input into a specific network
743
- * at a time, and does not provide an addresses map for setting addresses
744
- * across all networks at once.
745
- *
746
- * @param params.id - The id of the addresses to update.
747
- * @param params.addresses - The addresses be setted to the tartget network.
748
- * @param params.network - Specifies which network's addresses you want to set.
749
- * @param params.auth - The authentication api key.
750
- * @param params.memo - Add memo to the addresses created in the API.
751
- * @return All addresses.
752
- */
753
- async update(params?: {
754
- id?: string;
755
- addresses?: AddressesInterface | undefined;
756
- network?: NetworkType | undefined;
757
- auth?: string | undefined;
758
- memo?: string | undefined;
759
- }) {
760
- const { id, addresses, network, auth, memo } = params ?? {};
761
- const apiKey = auth || this.auth || undefined;
762
- const targetId = id || this.addressId || undefined;
763
- const targetNetwork = network || this.network;
764
- const targetAddresses =
765
- addresses ||
766
- this.currentAddresses ||
767
- this.addressMap.get(targetNetwork) ||
768
- EMPTY_ADDRESSES;
769
-
770
- if (targetId === undefined)
771
- throw Error('Require specific addresses id to be updated.');
772
- if (apiKey !== undefined) {
773
- if (id !== this.addressId) {
774
- this.addressMap.clear();
775
- }
776
- this.setAddresses(targetAddresses, targetNetwork);
777
- const response = await this.axiosClient.put(
778
- `/addresses/${targetId}`,
779
- JSON.stringify({ ...Object.fromEntries(this.addressMap), memo }),
780
- {
781
- headers: {
782
- 'Content-Type': 'application/json',
783
- 'api-key': auth || this.auth,
784
- },
785
- }
786
- );
787
-
788
- if (response.status === 200) {
789
- for (const [network, addresses] of Object.entries<AddressesInterface>(
790
- response.data
791
- )) {
792
- if (['localnet', 'devnet', 'testnet', 'mainnet'].includes(network)) {
793
- if (network === this.network) this.currentAddresses = addresses;
794
- this.addressMap.set(network as NetworkType, addresses);
795
- }
796
- }
797
- this.addressId = response.data.id;
798
- return this.getAllAddresses();
799
- } else {
800
- throw Error('Failed to update addresses.');
801
- }
802
- } else {
803
- throw Error("You don't have permission to access this request.");
804
- }
805
- }
806
-
807
- /**
808
- * Deletes all addresses of a specified id through the API and clear all
809
- * addresses in the instance.
810
- *
811
- * @param id - The id of the addresses to delete.
812
- * @param auth - The authentication API key.
813
- */
814
- async delete(id?: string, auth?: string) {
815
- const apiKey = auth || this.auth || undefined;
816
- const targetId = id || this.addressId || undefined;
817
-
818
- if (targetId === undefined)
819
- throw Error('Require specific addresses id to be deleted.');
820
- if (apiKey !== undefined) {
821
- const response = await this.axiosClient.delete(`/addresses/${targetId}`, {
822
- headers: {
823
- 'Content-Type': 'application/json',
824
- 'api-key': auth || this.auth,
825
- },
826
- });
827
-
828
- if (response.status === 200) {
829
- this.addressId = undefined;
830
- this.currentAddresses = undefined;
831
- this.addressMap.clear();
832
- } else {
833
- throw Error('Failed to delete addresses.');
834
- }
835
- } else {
836
- throw Error("You don't have permission to access this request.");
837
- }
838
- }
839
- }
840
-
841
- export default ScallopAddress;