@scallop-io/sui-scallop-sdk 2.2.0 → 2.2.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 +33 -14
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +1 -1
- package/src/builders/oracles/index.ts +40 -9
- package/src/models/scallopBuilder.ts +3 -0
package/package.json
CHANGED
|
@@ -25,8 +25,24 @@ export const updateOracles = async (
|
|
|
25
25
|
options: {
|
|
26
26
|
usePythPullModel: boolean;
|
|
27
27
|
useOnChainXOracleList: boolean;
|
|
28
|
-
|
|
28
|
+
sponsoredFeeds: string[];
|
|
29
|
+
} = {
|
|
30
|
+
usePythPullModel: true,
|
|
31
|
+
useOnChainXOracleList: true,
|
|
32
|
+
sponsoredFeeds: [],
|
|
33
|
+
}
|
|
29
34
|
) => {
|
|
35
|
+
const sponsoredFeeds = new Set(
|
|
36
|
+
builder.sponsoredFeeds ?? options.sponsoredFeeds
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// Validate the sponsoredFeeds content.
|
|
40
|
+
sponsoredFeeds.forEach((feed) => {
|
|
41
|
+
if (!builder.constants.whitelist.lending.has(feed)) {
|
|
42
|
+
throw new Error(`${feed} is not valid feed`);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
30
46
|
const usePythPullModel = builder.usePythPullModel ?? options.usePythPullModel;
|
|
31
47
|
const useOnChainXOracleList =
|
|
32
48
|
builder.useOnChainXOracleList ?? options.useOnChainXOracleList;
|
|
@@ -55,17 +71,32 @@ export const updateOracles = async (
|
|
|
55
71
|
);
|
|
56
72
|
};
|
|
57
73
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
74
|
+
const updateAssetCoinNames = [...new Set(assetCoinNames)];
|
|
75
|
+
const pythAssetCoinNames = updateAssetCoinNames.filter((assetCoinName) =>
|
|
76
|
+
filterAssetCoinNames(assetCoinName, 'pyth')
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
if (flattenedRules.has('pyth')) {
|
|
80
|
+
const needToUpdatePythPriceFeeds: string[] = [];
|
|
81
|
+
for (const pythAssetCoinName of pythAssetCoinNames) {
|
|
82
|
+
/**
|
|
83
|
+
* Check if the Pyth pull model is not used but the feed is not sponsored.
|
|
84
|
+
* This is used to determine if we should update the Pyth price feeds.
|
|
85
|
+
*/
|
|
86
|
+
const notUsingPullAndNotSponsored =
|
|
87
|
+
!usePythPullModel && !sponsoredFeeds.has(pythAssetCoinName);
|
|
88
|
+
|
|
89
|
+
if (usePythPullModel || notUsingPullAndNotSponsored) {
|
|
90
|
+
needToUpdatePythPriceFeeds.push(pythAssetCoinName);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (needToUpdatePythPriceFeeds.length > 0) {
|
|
95
|
+
await updatePythPriceFeeds(builder, needToUpdatePythPriceFeeds, txBlock);
|
|
96
|
+
}
|
|
65
97
|
}
|
|
66
98
|
|
|
67
99
|
// Remove duplicate coin names.
|
|
68
|
-
const updateAssetCoinNames = [...new Set(assetCoinNames)];
|
|
69
100
|
for (const assetCoinName of updateAssetCoinNames) {
|
|
70
101
|
updateOracle(builder, txBlock, assetCoinName, xOracleList[assetCoinName]);
|
|
71
102
|
}
|
|
@@ -18,6 +18,7 @@ import { ScallopBuilderInterface } from './interface';
|
|
|
18
18
|
export type ScallopBuilderParams = {
|
|
19
19
|
query?: ScallopQuery;
|
|
20
20
|
usePythPullModel?: boolean;
|
|
21
|
+
sponsoredFeeds?: string[];
|
|
21
22
|
useOnChainXOracleList?: boolean;
|
|
22
23
|
} & ScallopQueryParams;
|
|
23
24
|
|
|
@@ -36,11 +37,13 @@ class ScallopBuilder implements ScallopBuilderInterface {
|
|
|
36
37
|
public readonly query: ScallopQuery;
|
|
37
38
|
public readonly usePythPullModel: boolean;
|
|
38
39
|
public readonly useOnChainXOracleList: boolean;
|
|
40
|
+
public readonly sponsoredFeeds: string[];
|
|
39
41
|
|
|
40
42
|
public constructor(params: ScallopBuilderParams) {
|
|
41
43
|
this.query = params.query ?? new ScallopQuery(params);
|
|
42
44
|
this.usePythPullModel = params.usePythPullModel ?? true;
|
|
43
45
|
this.useOnChainXOracleList = params.useOnChainXOracleList ?? true;
|
|
46
|
+
this.sponsoredFeeds = params.sponsoredFeeds ?? [];
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
get utils() {
|