@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.
- package/dist/Logger-Cg2iFdpH.d.ts +8 -0
- package/dist/builder.cjs +22 -0
- package/dist/builder.d.cts +28 -0
- package/dist/builder.d.ts +28 -0
- package/dist/builder.js +4 -0
- package/dist/chunk-33AK5RWM.js +15 -0
- package/dist/chunk-6UQ4NWEU.js +3 -0
- package/dist/chunk-DIC6P5HB.js +11 -0
- package/dist/chunk-S34VOEZN.js +3 -0
- package/dist/chunk-VTGQACWU.js +6 -0
- package/dist/client.cjs +21 -0
- package/dist/client.d.cts +401 -0
- package/dist/client.d.ts +401 -0
- package/dist/client.js +5 -0
- package/dist/errors.cjs +10 -0
- package/dist/errors.d.cts +32 -0
- package/dist/errors.d.ts +32 -0
- package/dist/errors.js +1 -0
- package/dist/index.cjs +51 -34
- package/dist/index.d.cts +130 -3145
- package/dist/index.d.ts +130 -3145
- package/dist/index.js +8 -12
- package/dist/logger.cjs +6 -0
- package/dist/logger.d.cts +7 -0
- package/dist/logger.d.ts +7 -0
- package/dist/logger.js +1 -0
- package/dist/query-DkitepDi.d.ts +3305 -0
- package/dist/query.cjs +19 -0
- package/dist/query.d.cts +9 -0
- package/dist/query.d.ts +9 -0
- package/dist/query.js +3 -0
- package/dist/types.cjs +2 -0
- package/dist/types.d.cts +90 -0
- package/dist/types.d.ts +90 -0
- package/dist/types.js +1 -0
- package/package.json +98 -56
- package/src/constants/api.ts +2 -0
- package/src/constants/coinType.ts +2 -0
- package/src/constants/common.ts +0 -7
- package/src/constants/index.ts +2 -0
- package/src/constants/queryKeys.ts +14 -7
- package/src/constants/testAddress.ts +1 -0
- package/src/datasources/api.ts +34 -0
- package/src/datasources/indexer.ts +8 -0
- package/src/datasources/onchain.ts +121 -0
- package/src/entries/builder.ts +5 -0
- package/src/entries/client.ts +3 -0
- package/src/entries/errors.ts +2 -0
- package/src/entries/index.ts +17 -0
- package/src/entries/logger.ts +2 -0
- package/src/entries/query.ts +6 -0
- package/src/entries/types.ts +2 -0
- package/src/errors/ScallopConfigError.ts +8 -0
- package/src/errors/ScallopError.ts +30 -0
- package/src/errors/ScallopIndexerError.ts +8 -0
- package/src/errors/ScallopParseError.ts +8 -0
- package/src/errors/ScallopRpcError.ts +8 -0
- package/src/errors/ScallopTransactionBuildError.ts +8 -0
- package/src/errors/index.ts +6 -0
- package/src/logger/Logger.ts +6 -0
- package/src/logger/consoleLogger.ts +13 -0
- package/src/logger/index.ts +3 -0
- package/src/logger/noopLogger.ts +8 -0
- package/src/mappers/index.ts +1 -0
- package/src/mappers/moveTypeMapper.ts +48 -0
- package/src/models/index.ts +8 -10
- package/src/models/interface.ts +9 -9
- package/src/models/scallop.ts +9 -16
- package/src/models/scallopAddress/const.ts +416 -0
- package/src/models/scallopAddress/index.ts +188 -0
- package/src/models/scallopAddress/types.ts +212 -0
- package/src/models/{scallopBuilder.ts → scallopBuilder/index.ts} +65 -29
- package/src/models/scallopBuilder/types.ts +37 -0
- package/src/models/{scallopClient.ts → scallopClient/index.ts} +157 -598
- package/src/models/scallopClient/types.ts +25 -0
- package/src/models/scallopConstants/config/AddressConfigSource.ts +13 -0
- package/src/models/scallopConstants/config/ConfigValidator.ts +70 -0
- package/src/models/scallopConstants/config/PoolAddressConfigSource.ts +12 -0
- package/src/models/scallopConstants/config/ScallopConfig.ts +80 -0
- package/src/models/scallopConstants/config/ScallopConfigSnapshot.ts +46 -0
- package/src/models/scallopConstants/config/WhitelistConfigSource.ts +16 -0
- package/src/models/scallopConstants/config/index.ts +6 -0
- package/src/models/scallopConstants/const.ts +19 -0
- package/src/models/scallopConstants/constantsSource.ts +98 -0
- package/src/models/scallopConstants/deriveConstants.ts +150 -0
- package/src/models/scallopConstants/index.ts +257 -0
- package/src/models/scallopConstants/loadConstantsState.ts +135 -0
- package/src/models/scallopConstants/types.ts +77 -0
- package/src/models/scallopConstants/utils.ts +69 -0
- package/src/models/scallopQuery/index.ts +1279 -0
- package/src/models/scallopQuery/types.ts +9 -0
- package/src/models/scallopQuery/utils.ts +13 -0
- package/src/models/scallopUtils/index.ts +505 -0
- package/src/models/scallopUtils/types.ts +30 -0
- package/src/models/transactionExecutor.ts +122 -0
- package/src/repositories/addressApi/helpers.ts +14 -0
- package/src/repositories/addressApi/index.ts +24 -0
- package/src/repositories/addressApi/schema.ts +0 -0
- package/src/repositories/addressApi/types.ts +177 -0
- package/src/repositories/base.ts +38 -0
- package/src/repositories/borrowIncentive/bcs.ts +11 -0
- package/src/repositories/borrowIncentive/helpers.ts +396 -0
- package/src/repositories/borrowIncentive/index.ts +52 -0
- package/src/{types/query/borrowIncentive.ts → repositories/borrowIncentive/types.ts} +69 -23
- package/src/repositories/borrowIncentive/utils.ts +234 -0
- package/src/repositories/cache.ts +4 -0
- package/src/repositories/coinBalance/helpers.ts +394 -0
- package/src/repositories/coinBalance/index.ts +69 -0
- package/src/repositories/coinBalance/types.ts +33 -0
- package/src/repositories/flashloan/const.ts +3 -0
- package/src/repositories/flashloan/helpers.ts +107 -0
- package/src/repositories/flashloan/index.ts +34 -0
- package/src/repositories/flashloan/types.ts +16 -0
- package/src/repositories/isolatedAssets/bcs.ts +4 -0
- package/src/repositories/isolatedAssets/const.ts +2 -0
- package/src/repositories/isolatedAssets/helpers.ts +91 -0
- package/src/repositories/isolatedAssets/index.ts +42 -0
- package/src/repositories/isolatedAssets/types.ts +35 -0
- package/src/repositories/loyaltyProgram/bcs.ts +7 -0
- package/src/repositories/loyaltyProgram/helpers.ts +117 -0
- package/src/repositories/loyaltyProgram/index.ts +28 -0
- package/src/repositories/loyaltyProgram/schema.ts +18 -0
- package/src/repositories/loyaltyProgram/types.ts +37 -0
- package/src/repositories/market/const.ts +6 -0
- package/src/repositories/market/helpers.ts +740 -0
- package/src/repositories/market/index.ts +137 -0
- package/src/repositories/market/mapper.ts +30 -0
- package/src/repositories/market/types.ts +443 -0
- package/src/repositories/market/utils.ts +285 -0
- package/src/repositories/obligation/helpers.ts +228 -0
- package/src/repositories/obligation/index.ts +51 -0
- package/src/repositories/obligation/types.ts +71 -0
- package/src/repositories/obligation/utils.ts +57 -0
- package/src/repositories/poolAddresses/const.ts +5 -0
- package/src/repositories/poolAddresses/helpers.ts +422 -0
- package/src/repositories/poolAddresses/index.ts +56 -0
- package/src/repositories/poolAddresses/schema.ts +34 -0
- package/src/repositories/poolAddresses/types.ts +69 -0
- package/src/repositories/price/const.ts +1 -0
- package/src/repositories/price/helpers.ts +237 -0
- package/src/repositories/price/index.ts +91 -0
- package/src/repositories/price/schema.ts +24 -0
- package/src/repositories/price/types.ts +56 -0
- package/src/repositories/price/utils.ts +21 -0
- package/src/repositories/referral/bcs.ts +3 -0
- package/src/repositories/referral/helper.ts +24 -0
- package/src/repositories/referral/index.ts +31 -0
- package/src/repositories/referral/types.ts +33 -0
- package/src/repositories/spool/const.ts +1 -0
- package/src/repositories/spool/helpers.ts +471 -0
- package/src/repositories/spool/index.ts +135 -0
- package/src/{types/query/spool.ts → repositories/spool/types.ts} +67 -2
- package/src/repositories/spool/utils.ts +215 -0
- package/src/repositories/types.ts +39 -0
- package/src/repositories/utils.ts +137 -0
- package/src/repositories/veSca/bcs.ts +6 -0
- package/src/repositories/veSca/helpers.ts +341 -0
- package/src/repositories/veSca/index.ts +57 -0
- package/src/repositories/veSca/types.ts +79 -0
- package/src/repositories/veScaLoyaltyProgram/bcs.ts +3 -0
- package/src/repositories/veScaLoyaltyProgram/helpers.ts +135 -0
- package/src/repositories/veScaLoyaltyProgram/index.ts +28 -0
- package/src/repositories/veScaLoyaltyProgram/schema.ts +15 -0
- package/src/repositories/veScaLoyaltyProgram/types.ts +47 -0
- package/src/repositories/wiring/datasources.ts +42 -0
- package/src/repositories/wiring/metadata.ts +292 -0
- package/src/repositories/wiring/registry.ts +194 -0
- package/src/repositories/wiring/source.ts +63 -0
- package/src/repositories/xOracle/bcs.ts +7 -0
- package/src/repositories/xOracle/const.ts +1 -0
- package/src/repositories/xOracle/helpers.ts +304 -0
- package/src/repositories/xOracle/index.ts +45 -0
- package/src/repositories/xOracle/types.ts +96 -0
- package/src/repositories/xOracle/utils.ts +3 -0
- package/src/services/client/BorrowService.ts +229 -0
- package/src/services/client/CollateralService.ts +76 -0
- package/src/services/client/LendingService.ts +75 -0
- package/src/services/client/ReferralService.ts +71 -0
- package/src/services/client/SpoolService.ts +170 -0
- package/src/services/client/VeScaService.ts +142 -0
- package/src/services/client/types.ts +44 -0
- package/src/services/index.ts +8 -0
- package/src/services/query/portfolioCalculations.ts +1171 -0
- package/src/txBuilders/borrowIncentive/index.ts +80 -0
- package/src/txBuilders/borrowIncentive/moveCalls.ts +124 -0
- package/src/txBuilders/borrowIncentive/quick.ts +207 -0
- package/src/txBuilders/context.ts +62 -0
- package/src/txBuilders/core/index.ts +95 -0
- package/src/txBuilders/core/moveCalls.ts +241 -0
- package/src/txBuilders/core/quick.ts +306 -0
- package/src/{builders → txBuilders}/index.ts +35 -9
- package/src/txBuilders/loyaltyProgram/index.ts +78 -0
- package/src/txBuilders/loyaltyProgram/moveCalls.ts +44 -0
- package/src/txBuilders/loyaltyProgram/quick.ts +58 -0
- package/src/txBuilders/manifest.ts +160 -0
- package/src/txBuilders/modules.ts +70 -0
- package/src/{builders → txBuilders}/oracles/index.ts +3 -2
- package/src/{builders → txBuilders}/oracles/pyth.ts +4 -3
- package/src/txBuilders/referral/index.ts +72 -0
- package/src/txBuilders/referral/moveCalls.ts +93 -0
- package/src/txBuilders/referral/quick.ts +57 -0
- package/src/txBuilders/sCoin/index.ts +72 -0
- package/src/txBuilders/sCoin/moveCalls.ts +36 -0
- package/src/txBuilders/sCoin/quick.ts +34 -0
- package/src/txBuilders/spool/index.ts +82 -0
- package/src/txBuilders/spool/moveCalls.ts +79 -0
- package/src/{builders/spoolBuilder.ts → txBuilders/spool/quick.ts} +22 -162
- package/src/txBuilders/utils.ts +36 -0
- package/src/txBuilders/verify.ts +45 -0
- package/src/txBuilders/vesca/index.ts +75 -0
- package/src/txBuilders/vesca/moveCalls.ts +147 -0
- package/src/{builders/vescaBuilder.ts → txBuilders/vesca/quick.ts} +85 -274
- package/src/types/address.ts +4 -178
- package/src/types/builder/borrowIncentive.ts +4 -3
- package/src/types/builder/core.ts +6 -33
- package/src/types/builder/index.ts +5 -1
- package/src/types/builder/loyaltyProgram.ts +4 -3
- package/src/types/builder/modules.ts +49 -0
- package/src/types/builder/referral.ts +5 -4
- package/src/types/builder/sCoin.ts +20 -2
- package/src/types/builder/spool.ts +22 -2
- package/src/types/builder/vesca.ts +4 -12
- package/src/types/constant/index.ts +3 -1
- package/src/types/constant/queryKeys.ts +15 -8
- package/src/types/index.ts +5 -6
- package/src/types/internal/dto.ts +46 -0
- package/src/types/internal/index.ts +2 -0
- package/src/types/internal/move.ts +13 -0
- package/src/types/public/index.ts +21 -0
- package/src/types/query/core.ts +0 -317
- package/src/types/query/index.ts +3 -4
- package/src/types/query/portfolio.ts +2 -15
- package/src/types/repositories/borrowIncentive.ts +12 -0
- package/src/types/repositories/index.ts +9 -0
- package/src/types/repositories/loyaltyProgram.ts +2 -0
- package/src/types/repositories/market.ts +13 -0
- package/src/types/repositories/spool.ts +21 -0
- package/src/types/repositories/veSca.ts +5 -0
- package/src/types/repositories/veScaLoyaltyProgram.ts +2 -0
- package/src/types/sui.ts +0 -1
- package/src/utils/array.ts +7 -0
- package/src/utils/cache.ts +17 -0
- package/src/utils/object.ts +30 -12
- package/src/utils/query.ts +9 -190
- package/src/utils/vesca.ts +0 -8
- package/src/builders/borrowIncentiveBuilder.ts +0 -372
- package/src/builders/coreBuilder.ts +0 -636
- package/src/builders/loyaltyProgramBuilder.ts +0 -142
- package/src/builders/referralBuilder.ts +0 -192
- package/src/builders/sCoinBuilder.ts +0 -124
- package/src/index.ts +0 -13
- package/src/models/scallopAddress.ts +0 -841
- package/src/models/scallopAxios.ts +0 -185
- package/src/models/scallopConstants.ts +0 -380
- package/src/models/scallopIndexer.ts +0 -226
- package/src/models/scallopQuery.ts +0 -974
- package/src/models/scallopQueryClient.ts +0 -29
- package/src/models/scallopSuiKit.ts +0 -480
- package/src/models/scallopUtils.ts +0 -734
- package/src/queries/borrowIncentiveQuery.ts +0 -361
- package/src/queries/borrowLimitQuery.ts +0 -33
- package/src/queries/coreQuery.ts +0 -1173
- package/src/queries/flashloanFeeQuery.ts +0 -92
- package/src/queries/index.ts +0 -15
- package/src/queries/isolatedAssetQuery.ts +0 -103
- package/src/queries/loyaltyProgramQuery.ts +0 -178
- package/src/queries/ownerQuery.ts +0 -32
- package/src/queries/poolAddressesQuery.ts +0 -340
- package/src/queries/portfolioQuery.ts +0 -1149
- package/src/queries/priceQuery.ts +0 -37
- package/src/queries/referralQuery.ts +0 -42
- package/src/queries/sCoinQuery.ts +0 -195
- package/src/queries/spoolQuery.ts +0 -542
- package/src/queries/supplyLimitQuery.ts +0 -32
- package/src/queries/switchboardQuery.ts +0 -65
- package/src/queries/vescaQuery.ts +0 -312
- package/src/queries/xOracleQuery.ts +0 -149
- package/src/types/constant/common.ts +0 -55
- package/src/types/query/loyaltyProgram.ts +0 -12
- package/src/types/query/vesca.ts +0 -27
- package/src/utils/index.ts +0 -7
- package/src/utils/indexer.ts +0 -47
- /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;
|