@scallop-io/sui-scallop-sdk 2.2.3-pyth-sponsored-transaction-alpha.1 → 2.3.0-lst-x-oracle-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/address-Bp_gAUMw.d.ts +165 -0
- package/dist/chunk-4GSK5DO7.js +25 -0
- package/dist/chunk-B4M6FI47.mjs +5 -0
- package/dist/constants/index.d.mts +262 -0
- package/dist/constants/index.d.ts +262 -0
- package/dist/constants/index.js +86 -0
- package/dist/constants/index.mjs +5 -0
- package/dist/models/index.d.mts +393 -0
- package/dist/models/index.d.ts +393 -0
- package/dist/models/index.js +34 -0
- package/dist/models/index.mjs +16 -0
- package/dist/queryKeys-AaZqDYle.d.ts +43 -0
- package/dist/{index.d.mts → scallopUtils-Cxm9zldY.d.ts} +1748 -2586
- package/dist/types/index.d.mts +9 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.mjs +1 -0
- package/package.json +23 -11
- package/src/builders/borrowIncentiveBuilder.ts +2 -2
- package/src/builders/coreBuilder.ts +5 -14
- package/src/builders/index.ts +2 -2
- package/src/builders/oracles/error.ts +29 -0
- package/src/builders/oracles/index.ts +114 -365
- package/src/builders/oracles/oraclePackageRegistry.ts +323 -0
- package/src/builders/oracles/priceFeedUpdater.ts +112 -0
- package/src/builders/oracles/priceUpdateRequester.ts +50 -0
- package/src/builders/oracles/xOracleUpdateStrategy.ts +178 -0
- package/src/builders/oracles/xOracleUpdater.ts +160 -0
- package/src/builders/vescaBuilder.ts +2 -2
- package/src/constants/api.ts +2 -0
- package/src/constants/common.ts +0 -3
- package/src/constants/index.ts +2 -1
- package/src/constants/package.ts +14 -0
- package/src/constants/testAddress.ts +190 -105
- package/src/constants/xoracle.ts +8 -2
- package/src/models/scallopAddress.ts +24 -4
- package/src/models/scallopBuilder.ts +4 -4
- package/src/models/scallopClient.ts +1 -1
- package/src/models/scallopConstants.ts +2 -2
- package/src/models/scallopIndexer.ts +3 -2
- package/src/models/scallopQuery.ts +52 -36
- package/src/models/scallopQueryClient.ts +1 -1
- package/src/models/scallopSuiKit.ts +1 -1
- package/src/models/scallopUtils.ts +5 -8
- package/src/queries/borrowIncentiveQuery.ts +2 -3
- package/src/queries/coreQuery.ts +2 -3
- package/src/queries/index.ts +4 -3
- package/src/queries/loyaltyProgramQuery.ts +1 -1
- package/src/queries/portfolioQuery.ts +13 -13
- package/src/queries/sCoinQuery.ts +2 -2
- package/src/queries/spoolQuery.ts +8 -8
- package/src/queries/vescaQuery.ts +2 -2
- package/src/queries/xOracleQuery.ts +20 -3
- package/src/types/address.ts +85 -47
- package/src/types/builder/core.ts +2 -4
- package/src/types/constant/index.ts +2 -1
- package/src/types/constant/package.ts +3 -0
- package/src/types/constant/xOracle.ts +10 -7
- package/src/types/query/index.ts +0 -1
- package/src/utils/builder.ts +1 -1
- package/src/utils/index.ts +2 -2
- package/src/utils/query.ts +6 -6
- package/src/utils/util.ts +1 -1
- package/dist/index.d.ts +0 -3242
- package/dist/index.js +0 -49
- package/dist/index.mjs +0 -15
- package/src/builders/oracles/pyth.ts +0 -52
- package/src/index.ts +0 -13
- package/src/queries/ownerQuery.ts +0 -32
- package/src/types/constant/enum.ts +0 -64
- package/src/types/query/sCoin.ts +0 -1
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { X_ORACLE_LIST } from 'src/constants/xoracle';
|
|
2
|
+
import { createXOracleUpdater, IXOracleUpdater } from './xOracleUpdater';
|
|
3
|
+
import {
|
|
4
|
+
createPackageRegistry,
|
|
5
|
+
XOraclePackageRegistry,
|
|
6
|
+
} from './oraclePackageRegistry';
|
|
7
|
+
import {
|
|
8
|
+
createPriceFeedUpdater,
|
|
9
|
+
PriceFeedUpdateOptions,
|
|
10
|
+
} from './priceFeedUpdater';
|
|
3
11
|
import type { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
|
|
4
12
|
import type { ScallopBuilder } from 'src/models';
|
|
5
|
-
import type {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
xOracleRuleType,
|
|
9
|
-
} from 'src/types';
|
|
10
|
-
import { xOracleList as X_ORACLE_LIST } from 'src/constants';
|
|
11
|
-
import { updatePythPriceFeeds } from './pyth';
|
|
13
|
+
import type { SupportOracleType, xOracleRuleType } from 'src/types';
|
|
14
|
+
import { PriceUpdateRequester } from './priceUpdateRequester';
|
|
15
|
+
import { UnsupportedOracleError } from './error';
|
|
12
16
|
|
|
13
17
|
/**
|
|
14
18
|
* Update the price of the oracle for multiple coin.
|
|
@@ -22,381 +26,126 @@ export const updateOracles = async (
|
|
|
22
26
|
builder: ScallopBuilder,
|
|
23
27
|
txBlock: SuiKitTxBlock,
|
|
24
28
|
assetCoinNames: string[] = [...builder.constants.whitelist.lending],
|
|
25
|
-
options
|
|
26
|
-
usePythPullModel?: boolean;
|
|
27
|
-
useOnChainXOracleList?: boolean;
|
|
28
|
-
sponsoredFeeds?: string[];
|
|
29
|
-
isSponsoredTx?: boolean;
|
|
30
|
-
}
|
|
29
|
+
options: Partial<PriceFeedUpdateOptions> = {}
|
|
31
30
|
) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
if (!builder.constants.whitelist.lending.has(feed)) {
|
|
44
|
-
throw new Error(`${feed} is not valid feed`);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const xOracleList = useOnChainXOracleList
|
|
31
|
+
// Validate the options
|
|
32
|
+
assetCoinNames = [...new Set(assetCoinNames)]; // Remove duplicates
|
|
33
|
+
const mergedOptions = {
|
|
34
|
+
usePythPullModel: builder.usePythPullModel,
|
|
35
|
+
useOnChainXOracleList: builder.useOnChainXOracleList,
|
|
36
|
+
pythSponsoredFeeds: builder.pythSponsoredFeeds,
|
|
37
|
+
...options,
|
|
38
|
+
} as PriceFeedUpdateOptions;
|
|
39
|
+
|
|
40
|
+
// Retrieve the xOracle list from the builder or use the default one.
|
|
41
|
+
const xOracleList = mergedOptions.useOnChainXOracleList
|
|
49
42
|
? await builder.query.getAssetOracles()
|
|
50
|
-
: X_ORACLE_LIST;
|
|
43
|
+
: X_ORACLE_LIST; // Record<coinName, Record<xOracleRuleType, SupportOracleType[]>>
|
|
44
|
+
|
|
45
|
+
const xOracleListAsSet = Object.entries(xOracleList).reduce(
|
|
46
|
+
(acc, [coinName, { primary, secondary }]) => {
|
|
47
|
+
acc[coinName] = {
|
|
48
|
+
primary: new Set(primary),
|
|
49
|
+
secondary: new Set(secondary),
|
|
50
|
+
};
|
|
51
|
+
return acc;
|
|
52
|
+
},
|
|
53
|
+
{} as Record<string, Record<xOracleRuleType, Set<SupportOracleType>>>
|
|
54
|
+
);
|
|
51
55
|
|
|
52
|
-
//
|
|
53
|
-
const
|
|
56
|
+
// Get all oracle types no duplicates from all rules (primary and secondary).
|
|
57
|
+
const oracleTypesSet = new Set(
|
|
54
58
|
Object.values(xOracleList).flatMap(({ primary, secondary }) => [
|
|
55
59
|
...primary,
|
|
56
60
|
...secondary,
|
|
57
61
|
])
|
|
58
62
|
);
|
|
59
63
|
|
|
60
|
-
const
|
|
64
|
+
const getRuleType = (
|
|
61
65
|
assetCoinName: string,
|
|
62
|
-
|
|
66
|
+
oracleType: SupportOracleType
|
|
63
67
|
) => {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
const ruleSet = xOracleListAsSet[assetCoinName];
|
|
69
|
+
if (!ruleSet)
|
|
70
|
+
return {
|
|
71
|
+
isPrimary: false,
|
|
72
|
+
isSecondary: false,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const { primary, secondary } = ruleSet;
|
|
76
|
+
const isPrimary = primary.has(oracleType);
|
|
77
|
+
const isSecondary = secondary.has(oracleType);
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
isPrimary,
|
|
81
|
+
isSecondary,
|
|
82
|
+
};
|
|
70
83
|
};
|
|
71
84
|
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (needToUpdatePythPriceFeeds.length > 0) {
|
|
93
|
-
await updatePythPriceFeeds(
|
|
94
|
-
builder,
|
|
95
|
-
needToUpdatePythPriceFeeds,
|
|
85
|
+
// Create a package registry for xOracle
|
|
86
|
+
const xOraclePackageRegistry = new XOraclePackageRegistry(builder.utils);
|
|
87
|
+
|
|
88
|
+
// Create xOracle updater for each oracle type
|
|
89
|
+
const xOracleUpdaters: Partial<Record<SupportOracleType, IXOracleUpdater>> =
|
|
90
|
+
{};
|
|
91
|
+
|
|
92
|
+
// Iterate through oracle set
|
|
93
|
+
for (const oracleType of oracleTypesSet) {
|
|
94
|
+
const filteredAssetCoinNames = assetCoinNames.filter((assetCoinName) => {
|
|
95
|
+
const { isPrimary, isSecondary } = getRuleType(assetCoinName, oracleType);
|
|
96
|
+
if (!isPrimary && !isSecondary) return false;
|
|
97
|
+
return true;
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
if (filteredAssetCoinNames.length > 0) {
|
|
101
|
+
// Update all necessary price feeds
|
|
102
|
+
await createPriceFeedUpdater(
|
|
103
|
+
oracleType,
|
|
96
104
|
txBlock,
|
|
97
|
-
|
|
98
|
-
|
|
105
|
+
builder,
|
|
106
|
+
filteredAssetCoinNames,
|
|
107
|
+
mergedOptions
|
|
108
|
+
).updatePriceFeeds();
|
|
99
109
|
}
|
|
100
|
-
}
|
|
101
110
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
111
|
+
// Create the xOracle updater for the current oracle type
|
|
112
|
+
xOracleUpdaters[oracleType] = createXOracleUpdater(
|
|
113
|
+
txBlock,
|
|
114
|
+
createPackageRegistry(oracleType, xOraclePackageRegistry)
|
|
115
|
+
);
|
|
105
116
|
}
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Update the price of the oracle for specific coin.
|
|
110
|
-
*
|
|
111
|
-
* @param builder - The scallop builder.
|
|
112
|
-
* @param txBlock - TxBlock created by SuiKit.
|
|
113
|
-
* @param assetCoinName - Specific support asset coin name.
|
|
114
|
-
*/
|
|
115
|
-
const updateOracle = (
|
|
116
|
-
builder: ScallopBuilder,
|
|
117
|
-
txBlock: SuiKitTxBlock,
|
|
118
|
-
assetCoinName: string,
|
|
119
|
-
rules: xOracleRules
|
|
120
|
-
) => {
|
|
121
|
-
const coinType = builder.utils.parseCoinType(assetCoinName);
|
|
122
117
|
|
|
123
|
-
|
|
118
|
+
// Create a price update requester
|
|
119
|
+
const priceUpdateRequester = new PriceUpdateRequester(
|
|
124
120
|
txBlock,
|
|
125
|
-
|
|
126
|
-
builder.address.get('core.packages.xOracle.id'),
|
|
127
|
-
builder.address.get('core.oracles.xOracle'),
|
|
128
|
-
builder.address.get('core.packages.pyth.id'),
|
|
129
|
-
builder.address.get('core.oracles.pyth.registry'),
|
|
130
|
-
builder.address.get('core.oracles.pyth.state'),
|
|
131
|
-
builder.address.get(`core.coins.${assetCoinName}.oracle.pyth.feedObject`),
|
|
132
|
-
builder.address.get('core.packages.switchboard.id'),
|
|
133
|
-
builder.address.get('core.oracles.switchboard.registry'),
|
|
134
|
-
builder.address.get(`core.coins.${assetCoinName}.oracle.switchboard`),
|
|
135
|
-
builder.address.get('core.packages.supra.id'),
|
|
136
|
-
builder.address.get('core.oracles.supra.registry'),
|
|
137
|
-
builder.address.get(`core.oracles.supra.holder`),
|
|
138
|
-
coinType
|
|
121
|
+
xOraclePackageRegistry
|
|
139
122
|
);
|
|
140
|
-
};
|
|
141
123
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
pythStateId: TransactionArgument | string,
|
|
170
|
-
pythFeedObjectId: TransactionArgument | string,
|
|
171
|
-
switchboardPackageId: string,
|
|
172
|
-
switchboardRegistryId: TransactionArgument | string,
|
|
173
|
-
switchboardAggregatorId: TransactionArgument | string,
|
|
174
|
-
supraPackageId: string,
|
|
175
|
-
supraRegistryId: TransactionArgument | string,
|
|
176
|
-
supraHolderId: TransactionArgument | string,
|
|
177
|
-
coinType: string
|
|
178
|
-
) => {
|
|
179
|
-
const request = priceUpdateRequest(
|
|
180
|
-
txBlock,
|
|
181
|
-
xOraclePackageId,
|
|
182
|
-
xOracleId,
|
|
183
|
-
coinType
|
|
184
|
-
);
|
|
185
|
-
Object.entries(rules).forEach(([type, rule]: [any, string[]]) => {
|
|
186
|
-
if (rule.includes('pyth')) {
|
|
187
|
-
updatePythPrice(
|
|
188
|
-
type,
|
|
189
|
-
txBlock,
|
|
190
|
-
pythPackageId,
|
|
191
|
-
request,
|
|
192
|
-
pythStateId,
|
|
193
|
-
pythFeedObjectId,
|
|
194
|
-
pythRegistryId,
|
|
195
|
-
coinType
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
if (rule.includes('supra')) {
|
|
199
|
-
updateSupraPrice(
|
|
200
|
-
type,
|
|
201
|
-
txBlock,
|
|
202
|
-
supraPackageId,
|
|
203
|
-
request,
|
|
204
|
-
supraHolderId,
|
|
205
|
-
supraRegistryId,
|
|
206
|
-
coinType
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
if (rule.includes('switchboard')) {
|
|
210
|
-
updateSwitchboardPrice(
|
|
211
|
-
type,
|
|
212
|
-
txBlock,
|
|
213
|
-
switchboardPackageId,
|
|
214
|
-
request,
|
|
215
|
-
switchboardAggregatorId,
|
|
216
|
-
switchboardRegistryId,
|
|
217
|
-
coinType
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
confirmPriceUpdateRequest(
|
|
223
|
-
txBlock,
|
|
224
|
-
xOraclePackageId,
|
|
225
|
-
xOracleId,
|
|
226
|
-
request,
|
|
227
|
-
coinType
|
|
228
|
-
);
|
|
229
|
-
return txBlock;
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Construct a transaction block for request price update.
|
|
234
|
-
*
|
|
235
|
-
* @param txBlock - The transaction block.
|
|
236
|
-
* @param packageId - The xOracle package id.
|
|
237
|
-
* @param xOracleId - The xOracle Id from xOracle package.
|
|
238
|
-
* @param coinType - The type of coin.
|
|
239
|
-
* @return TxBlock created by SuiKit.
|
|
240
|
-
*/
|
|
241
|
-
const priceUpdateRequest = (
|
|
242
|
-
txBlock: SuiKitTxBlock,
|
|
243
|
-
packageId: string,
|
|
244
|
-
xOracleId: TransactionArgument | string,
|
|
245
|
-
coinType: string
|
|
246
|
-
) => {
|
|
247
|
-
const target = `${packageId}::x_oracle::price_update_request`;
|
|
248
|
-
const typeArgs = [coinType];
|
|
249
|
-
return txBlock.moveCall(target, [xOracleId], typeArgs);
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Construct a transaction block for confirm price update request.
|
|
254
|
-
*
|
|
255
|
-
* @param txBlock - The transaction block.
|
|
256
|
-
* @param packageId - The xOracle package id.
|
|
257
|
-
* @param xOracleId - The xOracle Id from xOracle package.
|
|
258
|
-
* @param request - The result of the request.
|
|
259
|
-
* @param coinType - The type of coin.
|
|
260
|
-
* @return TxBlock created by SuiKit.
|
|
261
|
-
*/
|
|
262
|
-
const confirmPriceUpdateRequest = (
|
|
263
|
-
txBlock: SuiKitTxBlock,
|
|
264
|
-
packageId: string,
|
|
265
|
-
xOracleId: TransactionArgument | string,
|
|
266
|
-
request: TransactionArgument,
|
|
267
|
-
coinType: string
|
|
268
|
-
) => {
|
|
269
|
-
const target = `${packageId}::x_oracle::confirm_price_update_request`;
|
|
270
|
-
const typeArgs = [coinType];
|
|
271
|
-
txBlock.moveCall(
|
|
272
|
-
target,
|
|
273
|
-
[
|
|
274
|
-
xOracleId,
|
|
275
|
-
request,
|
|
276
|
-
txBlock.sharedObjectRef({
|
|
277
|
-
objectId: SUI_CLOCK_OBJECT_ID,
|
|
278
|
-
mutable: false,
|
|
279
|
-
initialSharedVersion: '1',
|
|
280
|
-
}),
|
|
281
|
-
],
|
|
282
|
-
typeArgs
|
|
283
|
-
);
|
|
284
|
-
return txBlock;
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* Construct a transaction block for update supra price.
|
|
289
|
-
*
|
|
290
|
-
* @param type - The type of price rule.
|
|
291
|
-
* @param txBlock - The transaction block.
|
|
292
|
-
* @param packageId - The supra package id.
|
|
293
|
-
* @param request - The result of the request.
|
|
294
|
-
* @param holderId - The holder id from supra package.
|
|
295
|
-
* @param registryId - The registry id from supra package.
|
|
296
|
-
* @param coinType - The type of coin.
|
|
297
|
-
* @return TxBlock created by SuiKit.
|
|
298
|
-
*/
|
|
299
|
-
const updateSupraPrice = (
|
|
300
|
-
type: xOracleRuleType,
|
|
301
|
-
txBlock: SuiKitTxBlock,
|
|
302
|
-
packageId: string,
|
|
303
|
-
request: TransactionArgument,
|
|
304
|
-
holderId: TransactionArgument | string,
|
|
305
|
-
registryId: TransactionArgument | string,
|
|
306
|
-
coinType: string
|
|
307
|
-
) => {
|
|
308
|
-
txBlock.moveCall(
|
|
309
|
-
`${packageId}::rule::set_price_as_${type}`,
|
|
310
|
-
[
|
|
311
|
-
request,
|
|
312
|
-
holderId,
|
|
313
|
-
registryId,
|
|
314
|
-
txBlock.sharedObjectRef({
|
|
315
|
-
objectId: SUI_CLOCK_OBJECT_ID,
|
|
316
|
-
initialSharedVersion: '1',
|
|
317
|
-
mutable: false,
|
|
318
|
-
}),
|
|
319
|
-
],
|
|
320
|
-
[coinType]
|
|
321
|
-
);
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* Construct a transaction block for update switchboard price.
|
|
326
|
-
*
|
|
327
|
-
* @param type - The type of price rule.
|
|
328
|
-
* @param txBlock - The transaction block.
|
|
329
|
-
* @param packageId - The switchboard package id.
|
|
330
|
-
* @param request - The result of the request.
|
|
331
|
-
* @param aggregatorId - The aggregator id from switchboard package.
|
|
332
|
-
* @param registryId - The registry id from switchboard package.
|
|
333
|
-
* @param coinType - The type of coin.
|
|
334
|
-
* @return TxBlock created by SuiKit.
|
|
335
|
-
*/
|
|
336
|
-
const updateSwitchboardPrice = (
|
|
337
|
-
type: xOracleRuleType,
|
|
338
|
-
txBlock: SuiKitTxBlock,
|
|
339
|
-
packageId: string,
|
|
340
|
-
request: TransactionArgument,
|
|
341
|
-
aggregatorId: TransactionArgument | string,
|
|
342
|
-
registryId: TransactionArgument | string,
|
|
343
|
-
coinType: string
|
|
344
|
-
) => {
|
|
345
|
-
txBlock.moveCall(
|
|
346
|
-
// `${packageId}::rule::set_price_as_${type}`,
|
|
347
|
-
`${packageId}::rule::set_as_${type}_price`,
|
|
348
|
-
[
|
|
349
|
-
request,
|
|
350
|
-
aggregatorId,
|
|
351
|
-
registryId,
|
|
352
|
-
txBlock.sharedObjectRef({
|
|
353
|
-
objectId: SUI_CLOCK_OBJECT_ID,
|
|
354
|
-
initialSharedVersion: '1',
|
|
355
|
-
mutable: false,
|
|
356
|
-
}),
|
|
357
|
-
],
|
|
358
|
-
[coinType]
|
|
359
|
-
);
|
|
360
|
-
};
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* Construct a transaction block for update pyth price.
|
|
364
|
-
*
|
|
365
|
-
* @param type - The type of price rule.
|
|
366
|
-
* @param txBlock - The transaction block.
|
|
367
|
-
* @param packageId - The pyth package id.
|
|
368
|
-
* @param request - The result of the request.
|
|
369
|
-
* @param stateId - The price state id from pyth package.
|
|
370
|
-
* @param wormholeStateId - The whormhole state id from pyth package.
|
|
371
|
-
* @param feedObjectId - The feed object id from pyth package.
|
|
372
|
-
* @param vaaFromFeeId - The vaa from pyth api with feed id.
|
|
373
|
-
* @param registryId - The registry id from pyth package.
|
|
374
|
-
* @param coinType - The type of coin.
|
|
375
|
-
* @return TxBlock created by SuiKit.
|
|
376
|
-
*/
|
|
377
|
-
const updatePythPrice = (
|
|
378
|
-
type: xOracleRuleType,
|
|
379
|
-
txBlock: SuiKitTxBlock,
|
|
380
|
-
packageId: string,
|
|
381
|
-
request: TransactionArgument,
|
|
382
|
-
stateId: TransactionArgument | string,
|
|
383
|
-
feedObjectId: TransactionArgument | string,
|
|
384
|
-
registryId: TransactionArgument | string,
|
|
385
|
-
coinType: string
|
|
386
|
-
) => {
|
|
387
|
-
txBlock.moveCall(
|
|
388
|
-
`${packageId}::rule::set_price_as_${type}`,
|
|
389
|
-
[
|
|
390
|
-
request,
|
|
391
|
-
stateId,
|
|
392
|
-
feedObjectId,
|
|
393
|
-
registryId,
|
|
394
|
-
txBlock.sharedObjectRef({
|
|
395
|
-
objectId: SUI_CLOCK_OBJECT_ID,
|
|
396
|
-
initialSharedVersion: '1',
|
|
397
|
-
mutable: false,
|
|
398
|
-
}),
|
|
399
|
-
],
|
|
400
|
-
[coinType]
|
|
401
|
-
);
|
|
124
|
+
for (const assetCoinName of assetCoinNames) {
|
|
125
|
+
const rules = xOracleList[assetCoinName];
|
|
126
|
+
|
|
127
|
+
// build the price update request for the asset coin
|
|
128
|
+
// Each coin name has its own price update request
|
|
129
|
+
const updateRequest = priceUpdateRequester.buildRequest(assetCoinName);
|
|
130
|
+
|
|
131
|
+
// Iterate through each rule and update the xOracle for each oracle type
|
|
132
|
+
Object.keys(rules).forEach((rule) => {
|
|
133
|
+
const oracles = rules[rule as xOracleRuleType];
|
|
134
|
+
oracles.forEach((oracleType) => {
|
|
135
|
+
const updater = xOracleUpdaters[oracleType];
|
|
136
|
+
if (!updater) {
|
|
137
|
+
// Should never happen if ORACLE_TYPES is the source of truth
|
|
138
|
+
throw new UnsupportedOracleError(oracleType);
|
|
139
|
+
}
|
|
140
|
+
updater.updateXOracle(
|
|
141
|
+
assetCoinName,
|
|
142
|
+
rule as xOracleRuleType,
|
|
143
|
+
updateRequest
|
|
144
|
+
);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Confirm the price update request for all oracles
|
|
149
|
+
priceUpdateRequester.confirmRequest(assetCoinName, updateRequest);
|
|
150
|
+
}
|
|
402
151
|
};
|