@scallop-io/sui-scallop-sdk 2.0.0 → 2.0.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/README.md +8 -7
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/builders/oracles/index.ts +0 -15
- package/src/constants/common.ts +0 -125
- package/src/models/scallop.ts +14 -1
- package/src/models/scallopBuilder.ts +0 -42
- package/src/models/scallopConstants.ts +3 -1
- package/src/models/scallopQuery.ts +0 -7
- package/src/queries/coreQuery.ts +0 -15
- package/src/queries/poolAddressesQuery.ts +0 -2
- package/src/queries/portfolioQuery.ts +0 -2
- package/src/queries/xOracleQuery.ts +0 -10
- package/src/types/builder/core.ts +2 -23
- package/src/builders/oracles/switchboard.ts +0 -270
- package/src/constants/pyth.ts +0 -25
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
// import { ScallopBuilder } from 'src/models';
|
|
2
|
-
// import {
|
|
3
|
-
// // SUI_CLOCK_OBJECT_ID,
|
|
4
|
-
// // SUI_TYPE_ARG,
|
|
5
|
-
// type SuiTxBlock as SuiKitTxBlock,
|
|
6
|
-
// } from '@scallop-io/sui-kit';
|
|
7
|
-
// import {
|
|
8
|
-
// Aggregator,
|
|
9
|
-
// AggregatorData,
|
|
10
|
-
// ObjectParsingHelper,
|
|
11
|
-
// // AggregatorData,
|
|
12
|
-
// // FeedEvalResponse,
|
|
13
|
-
// // ObjectParsingHelper,
|
|
14
|
-
// // Queue,
|
|
15
|
-
// SwitchboardClient,
|
|
16
|
-
// } from '@switchboard-xyz/sui-sdk';
|
|
17
|
-
// import { queryMultipleObjects } from 'src/queries';
|
|
18
|
-
// import { MoveValue, SuiParsedData } from '@mysten/sui/client';
|
|
19
|
-
// import { toHex } from '@mysten/bcs';
|
|
20
|
-
// // import { CrossbarClient, IOracleJob, OracleJob } from '@switchboard-xyz/common';
|
|
21
|
-
// // import axios from 'axios';
|
|
22
|
-
|
|
23
|
-
// const getFieldsFromObject = (
|
|
24
|
-
// response: SuiParsedData
|
|
25
|
-
// ): {
|
|
26
|
-
// [key: string]: MoveValue;
|
|
27
|
-
// } => {
|
|
28
|
-
// // Check if 'data' and 'content' exist and are of the expected type
|
|
29
|
-
// if (response.dataType === 'moveObject') {
|
|
30
|
-
// // Safely return 'fields' from 'content'
|
|
31
|
-
// return response.fields as any;
|
|
32
|
-
// }
|
|
33
|
-
|
|
34
|
-
// throw new Error('Invalid response data');
|
|
35
|
-
// };
|
|
36
|
-
|
|
37
|
-
// const parseFeedConfigs = (responses: SuiParsedData[]): AggregatorData[] => {
|
|
38
|
-
// return responses.map(getFieldsFromObject).map((aggregatorData) => {
|
|
39
|
-
// const currentResult = (aggregatorData.current_result as any).fields;
|
|
40
|
-
// const updateState = (aggregatorData.update_state as any).fields;
|
|
41
|
-
|
|
42
|
-
// // build the data object
|
|
43
|
-
// const data: AggregatorData = {
|
|
44
|
-
// id: ObjectParsingHelper.asId(aggregatorData.id),
|
|
45
|
-
// authority: ObjectParsingHelper.asString(aggregatorData.authority),
|
|
46
|
-
// createdAtMs: ObjectParsingHelper.asNumber(aggregatorData.created_at_ms),
|
|
47
|
-
// currentResult: {
|
|
48
|
-
// maxResult: ObjectParsingHelper.asBN(currentResult.max_result),
|
|
49
|
-
// maxTimestamp: ObjectParsingHelper.asNumber(
|
|
50
|
-
// currentResult.max_timestamp_ms
|
|
51
|
-
// ),
|
|
52
|
-
// mean: ObjectParsingHelper.asBN(currentResult.mean),
|
|
53
|
-
// minResult: ObjectParsingHelper.asBN(currentResult.min_result),
|
|
54
|
-
// minTimestamp: ObjectParsingHelper.asNumber(
|
|
55
|
-
// currentResult.min_timestamp_ms
|
|
56
|
-
// ),
|
|
57
|
-
// range: ObjectParsingHelper.asBN(currentResult.range),
|
|
58
|
-
// result: ObjectParsingHelper.asBN(currentResult.result),
|
|
59
|
-
// stdev: ObjectParsingHelper.asBN(currentResult.stdev),
|
|
60
|
-
// },
|
|
61
|
-
// feedHash: toHex(
|
|
62
|
-
// ObjectParsingHelper.asUint8Array(aggregatorData.feed_hash)
|
|
63
|
-
// ),
|
|
64
|
-
// maxStalenessSeconds: ObjectParsingHelper.asNumber(
|
|
65
|
-
// aggregatorData.max_staleness_seconds
|
|
66
|
-
// ),
|
|
67
|
-
// maxVariance: ObjectParsingHelper.asNumber(aggregatorData.max_variance),
|
|
68
|
-
// minResponses: ObjectParsingHelper.asNumber(aggregatorData.min_responses),
|
|
69
|
-
// minSampleSize: ObjectParsingHelper.asNumber(
|
|
70
|
-
// aggregatorData.min_sample_size
|
|
71
|
-
// ),
|
|
72
|
-
// name: ObjectParsingHelper.asString(aggregatorData.name),
|
|
73
|
-
// queue: ObjectParsingHelper.asString(aggregatorData.queue),
|
|
74
|
-
// updateState: {
|
|
75
|
-
// currIdx: ObjectParsingHelper.asNumber(updateState.curr_idx),
|
|
76
|
-
// results: updateState.results.map((r: any) => {
|
|
77
|
-
// const oracleId = r.fields.oracle;
|
|
78
|
-
// const value = ObjectParsingHelper.asBN(r.fields.result.fields);
|
|
79
|
-
// const timestamp = parseInt(r.fields.timestamp_ms);
|
|
80
|
-
// return {
|
|
81
|
-
// oracle: oracleId,
|
|
82
|
-
// value,
|
|
83
|
-
// timestamp,
|
|
84
|
-
// };
|
|
85
|
-
// }),
|
|
86
|
-
// },
|
|
87
|
-
// };
|
|
88
|
-
|
|
89
|
-
// return data;
|
|
90
|
-
// });
|
|
91
|
-
// };
|
|
92
|
-
|
|
93
|
-
// // const encodeJobs = (jobArray: OracleJob[]) => {
|
|
94
|
-
// // return jobArray.map((job) => serializeOracleJob(job).toString('base64'));
|
|
95
|
-
// // };
|
|
96
|
-
|
|
97
|
-
// // const normalizeOracleJob = (
|
|
98
|
-
// // data: string | IOracleJob | Record<string, any>
|
|
99
|
-
// // ): OracleJob => {
|
|
100
|
-
// // const parseJobObject = (jobData: Record<string, any>) => {
|
|
101
|
-
// // if (!jobData) {
|
|
102
|
-
// // throw new Error(`No job data provided: ${jobData}`);
|
|
103
|
-
// // } else if (!('tasks' in jobData)) {
|
|
104
|
-
// // throw new Error('"tasks" property is required');
|
|
105
|
-
// // } else if (!(Array.isArray(jobData.tasks) && jobData.tasks.length > 0)) {
|
|
106
|
-
// // throw new Error('"tasks" property must be a non-empty array');
|
|
107
|
-
// // }
|
|
108
|
-
// // return OracleJob.fromObject(jobData);
|
|
109
|
-
// // };
|
|
110
|
-
// // const parseJobString = (jobString: string) => {
|
|
111
|
-
// // // Strip comments using regex from https://regex101.com/r/B8WkuX/1
|
|
112
|
-
// // const cleanJson = jobString.replace(
|
|
113
|
-
// // /\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/g,
|
|
114
|
-
// // ''
|
|
115
|
-
// // );
|
|
116
|
-
// // return parseJobObject(JSON.parse(cleanJson));
|
|
117
|
-
// // };
|
|
118
|
-
// // return typeof data === 'string' ? parseJobString(data) : parseJobObject(data);
|
|
119
|
-
// // };
|
|
120
|
-
|
|
121
|
-
// // const serializeOracleJob = (
|
|
122
|
-
// // data: string | IOracleJob | Record<string, any>
|
|
123
|
-
// // ): Buffer => {
|
|
124
|
-
// // const job = normalizeOracleJob(data);
|
|
125
|
-
// // return Buffer.from(OracleJob.encodeDelimited(job).finish());
|
|
126
|
-
// // };
|
|
127
|
-
|
|
128
|
-
// // const fetchSignatures = async (
|
|
129
|
-
// // feedConfig: AggregatorData
|
|
130
|
-
// // ): Promise<{
|
|
131
|
-
// // responses: FeedEvalResponse[];
|
|
132
|
-
// // failures: string[];
|
|
133
|
-
// // }> => {
|
|
134
|
-
// // const crossbarClient = new CrossbarClient('https://crossbar.switchboard.xyz');
|
|
135
|
-
|
|
136
|
-
// // const jobs: OracleJob[] = await crossbarClient
|
|
137
|
-
// // .fetch(feedConfig.feedHash)
|
|
138
|
-
// // .then((res) => res.jobs.map((job) => OracleJob.fromObject(job)));
|
|
139
|
-
|
|
140
|
-
// // const encodedJobs = encodeJobs(jobs);
|
|
141
|
-
// // const maxVariance = Math.floor(feedConfig.maxVariance / 1e9) * 1e9;
|
|
142
|
-
// // const minResponses = feedConfig.minResponses;
|
|
143
|
-
// // const numSignatures = feedConfig.minSampleSize;
|
|
144
|
-
// // const recentHash = toBase58(new Uint8Array(32));
|
|
145
|
-
// // const useTimestamp = true;
|
|
146
|
-
|
|
147
|
-
// // const GATEWAY_URL = 'https://api.mainnet-beta.solana.com';
|
|
148
|
-
// // const TIMEOUT = 10000;
|
|
149
|
-
// // const url = `${GATEWAY_URL}/gateway/api/v1/fetch_signatures`;
|
|
150
|
-
// // const headers = { 'Content-Type': 'application/json' };
|
|
151
|
-
|
|
152
|
-
// // const body = JSON.stringify({
|
|
153
|
-
// // api_version: '1.0.0',
|
|
154
|
-
// // jobs_b64_encoded: encodedJobs,
|
|
155
|
-
// // recent_chainhash: recentHash,
|
|
156
|
-
// // signature_scheme: 'Secp256k1',
|
|
157
|
-
// // hash_scheme: 'Sha256',
|
|
158
|
-
// // num_oracles: numSignatures,
|
|
159
|
-
// // max_variance: maxVariance,
|
|
160
|
-
// // min_responses: minResponses,
|
|
161
|
-
// // use_timestamp: useTimestamp,
|
|
162
|
-
// // });
|
|
163
|
-
|
|
164
|
-
// // return await axios
|
|
165
|
-
// // .post(url, body, {
|
|
166
|
-
// // headers,
|
|
167
|
-
// // timeout: TIMEOUT,
|
|
168
|
-
// // })
|
|
169
|
-
// // .then((r) => r.data);
|
|
170
|
-
// // };
|
|
171
|
-
|
|
172
|
-
// export const updateSwitchboardAggregators = async (
|
|
173
|
-
// builder: ScallopBuilder,
|
|
174
|
-
// assetCoinNames: string[],
|
|
175
|
-
// txBlock: SuiKitTxBlock
|
|
176
|
-
// ) => {
|
|
177
|
-
// const switchboardClient = new SwitchboardClient(builder.suiKit.client());
|
|
178
|
-
// const onDemandAggObjects = await queryMultipleObjects(
|
|
179
|
-
// builder.cache,
|
|
180
|
-
// await builder.query.getSwitchboardOnDemandAggregatorObjectIds(
|
|
181
|
-
// assetCoinNames
|
|
182
|
-
// )
|
|
183
|
-
// );
|
|
184
|
-
|
|
185
|
-
// const feedConfigs = parseFeedConfigs(
|
|
186
|
-
// onDemandAggObjects.map((t) => t.content) as SuiParsedData[]
|
|
187
|
-
// );
|
|
188
|
-
|
|
189
|
-
// for (const idx in assetCoinNames) {
|
|
190
|
-
// // const { switchboardAddress, oracleQueueId } =
|
|
191
|
-
// // await switchboardClient.fetchState();
|
|
192
|
-
|
|
193
|
-
// // const feedConfig = feedConfigs[idx];
|
|
194
|
-
|
|
195
|
-
// // const suiQueue = await new Queue(
|
|
196
|
-
// // switchboardClient,
|
|
197
|
-
// // oracleQueueId
|
|
198
|
-
// // ).loadData();
|
|
199
|
-
|
|
200
|
-
// // const { responses, failures } = await fetchSignatures(feedConfig);
|
|
201
|
-
// // const validOracles = new Set(
|
|
202
|
-
// // suiQueue.existingOracles.map((o) => o.oracleKey)
|
|
203
|
-
// // );
|
|
204
|
-
|
|
205
|
-
// // const validResponses = responses.filter((r) => {
|
|
206
|
-
// // return validOracles.has(toBase58(fromHex(r.oracle_pubkey)));
|
|
207
|
-
// // });
|
|
208
|
-
|
|
209
|
-
// // // if we have no valid responses (or not enough), fail out
|
|
210
|
-
// // if (
|
|
211
|
-
// // !validResponses.length ||
|
|
212
|
-
// // validResponses.length < feedConfig.minSampleSize
|
|
213
|
-
// // ) {
|
|
214
|
-
// // // maybe retry by recursing into the same function / add a retry count
|
|
215
|
-
// // throw new Error('Not enough valid oracle responses.');
|
|
216
|
-
// // }
|
|
217
|
-
|
|
218
|
-
// // // split the gas coin into the right amount for each response
|
|
219
|
-
// // const coins = txBlock.splitCoins(
|
|
220
|
-
// // txBlock.gas,
|
|
221
|
-
// // validResponses.map(() => suiQueue.fee)
|
|
222
|
-
// // );
|
|
223
|
-
|
|
224
|
-
// // // map the responses into the tx
|
|
225
|
-
// // validResponses.forEach((response, i) => {
|
|
226
|
-
// // const oracle = suiQueue.existingOracles.find(
|
|
227
|
-
// // (o) => o.oracleKey === toBase58(fromHex(response.oracle_pubkey))
|
|
228
|
-
// // )!;
|
|
229
|
-
|
|
230
|
-
// // const signature = Array.from(fromBase64(response.signature));
|
|
231
|
-
// // signature.push(response.recovery_id);
|
|
232
|
-
|
|
233
|
-
// // txBlock.moveCall(
|
|
234
|
-
// // `${switchboardAddress}::aggregator_submit_result_action::run`,
|
|
235
|
-
// // [
|
|
236
|
-
// // txBlock.object(onDemandAggObjects[idx].objectId),
|
|
237
|
-
// // txBlock.object(suiQueue.id),
|
|
238
|
-
// // txBlock.pure.u128(response.success_value),
|
|
239
|
-
// // txBlock.pure.bool(response.success_value.startsWith('-')),
|
|
240
|
-
// // txBlock.pure.u64(response.timestamp!),
|
|
241
|
-
// // txBlock.object(oracle.oracleId),
|
|
242
|
-
// // txBlock.pure.vector('u8', signature),
|
|
243
|
-
// // txBlock.sharedObjectRef({
|
|
244
|
-
// // objectId: SUI_CLOCK_OBJECT_ID,
|
|
245
|
-
// // initialSharedVersion: '1',
|
|
246
|
-
// // mutable: false,
|
|
247
|
-
// // }),
|
|
248
|
-
// // coins[i],
|
|
249
|
-
// // ],
|
|
250
|
-
// // [SUI_TYPE_ARG]
|
|
251
|
-
// // );
|
|
252
|
-
// // });
|
|
253
|
-
|
|
254
|
-
// // return { responses, failures };
|
|
255
|
-
|
|
256
|
-
// const switchboardAgg = new Aggregator(
|
|
257
|
-
// switchboardClient,
|
|
258
|
-
// onDemandAggObjects[idx].objectId
|
|
259
|
-
// );
|
|
260
|
-
|
|
261
|
-
// const { responses, failures } = await switchboardAgg.fetchUpdateTx(
|
|
262
|
-
// txBlock.txBlock,
|
|
263
|
-
// {
|
|
264
|
-
// feedConfigs: feedConfigs[idx],
|
|
265
|
-
// }
|
|
266
|
-
// );
|
|
267
|
-
|
|
268
|
-
// return { responses, failures };
|
|
269
|
-
// }
|
|
270
|
-
// };
|
package/src/constants/pyth.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// export const PYTH_FEED_IDS: Record<string, string> = {
|
|
2
|
-
// usdc: 'eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a',
|
|
3
|
-
// sbeth: 'ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace',
|
|
4
|
-
// sbusdt: '2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b',
|
|
5
|
-
// sbwbtc: 'e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43',
|
|
6
|
-
// weth: 'ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace',
|
|
7
|
-
// wbtc: 'e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43',
|
|
8
|
-
// wusdc: 'eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a',
|
|
9
|
-
// wusdt: '2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b',
|
|
10
|
-
// sui: '23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744',
|
|
11
|
-
// wapt: '03ae4db29ed4ae33d323568895aa00337e658e348b37509f5372ae51f0af00d5',
|
|
12
|
-
// wsol: 'ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d',
|
|
13
|
-
// cetus: 'e5b274b2611143df055d6e7cd8d93fe1961716bcd4dca1cad87a83bc1e78c1ef',
|
|
14
|
-
// afsui: '23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744',
|
|
15
|
-
// hasui: '23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744',
|
|
16
|
-
// vsui: '23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744',
|
|
17
|
-
// sca: '7e17f0ac105abe9214deb9944c30264f5986bf292869c6bd8e8da3ccd92d79bc',
|
|
18
|
-
// fdusd: 'ccdc1a08923e2e4f4b1e6ea89de6acbc5fe1948e9706f5604b8cb50bc1ed3979',
|
|
19
|
-
// deep: '29bdd5248234e33bd93d3b81100b5fa32eaa5997843847e2c2cb16d7c6d9f7ff',
|
|
20
|
-
// fud: '6a4090703da959247727f2b490eb21aea95c8684ecfac675f432008830890c75',
|
|
21
|
-
// blub: '5fc11ffe4975b624be495be038da30e30bee2004d8ae6282b5364577ef4ca92c',
|
|
22
|
-
// musd: '2ee09cdb656959379b9262f89de5ff3d4dfed0dd34c072b3e22518496a65249c',
|
|
23
|
-
// ns: 'bb5ff26e47a3a6cc7ec2fce1db996c2a145300edc5acaabe43bf9ff7c5dd5d32',
|
|
24
|
-
// usdy: 'e3d1723999820435ebab53003a542ff26847720692af92523eea613a9a28d500',
|
|
25
|
-
// };
|