@scallop-io/sui-scallop-sdk 2.2.0 → 2.2.1-sponsored-feeds-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "2.2.0",
3
+ "version": "2.2.1-sponsored-feeds-alpha.1",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -25,8 +25,24 @@ export const updateOracles = async (
25
25
  options: {
26
26
  usePythPullModel: boolean;
27
27
  useOnChainXOracleList: boolean;
28
- } = { usePythPullModel: true, useOnChainXOracleList: true }
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
- // Handle Pyth price feed
59
- if (flattenedRules.has('pyth') && usePythPullModel) {
60
- const pythAssetCoinNames = assetCoinNames.filter((assetCoinName) =>
61
- filterAssetCoinNames(assetCoinName, 'pyth')
62
- );
63
- if (pythAssetCoinNames.length > 0)
64
- await updatePythPriceFeeds(builder, assetCoinNames, txBlock);
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 notUsingPullButNotSponsored =
87
+ !usePythPullModel && !sponsoredFeeds.has(pythAssetCoinName);
88
+
89
+ if (usePythPullModel || notUsingPullButNotSponsored) {
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() {