@gearbox-protocol/sdk 11.11.0-next.1 → 11.11.0-next.2
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/cjs/sdk/market/pricefeeds/updates/PriceUpdatesCache.js +17 -0
- package/dist/cjs/sdk/market/pricefeeds/updates/PythUpdater.js +1 -1
- package/dist/cjs/sdk/market/pricefeeds/updates/RedstoneUpdater.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/updates/PriceUpdatesCache.js +17 -0
- package/dist/esm/sdk/market/pricefeeds/updates/PythUpdater.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/updates/RedstoneUpdater.js +1 -1
- package/dist/types/sdk/market/pricefeeds/updates/PriceUpdatesCache.d.ts +8 -1
- package/package.json +1 -1
|
@@ -22,6 +22,23 @@ __export(PriceUpdatesCache_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(PriceUpdatesCache_exports);
|
|
24
24
|
class PriceUpdatesCache {
|
|
25
|
+
static #caches = /* @__PURE__ */ new Map();
|
|
26
|
+
/**
|
|
27
|
+
* Price update caches can be shared across networks
|
|
28
|
+
* @param id - unique key to identify the cache
|
|
29
|
+
* @param opts
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
static get(id, opts) {
|
|
33
|
+
const key = `${id}:${opts.historical ? "historical" : "latest"}:${opts.ttl}`;
|
|
34
|
+
const cache = PriceUpdatesCache.#caches.get(key);
|
|
35
|
+
if (cache) {
|
|
36
|
+
return cache;
|
|
37
|
+
}
|
|
38
|
+
const newCache = new PriceUpdatesCache(opts);
|
|
39
|
+
PriceUpdatesCache.#caches.set(key, newCache);
|
|
40
|
+
return newCache;
|
|
41
|
+
}
|
|
25
42
|
#cache = /* @__PURE__ */ new Map();
|
|
26
43
|
#ttlMs;
|
|
27
44
|
#historical;
|
|
@@ -72,7 +72,7 @@ class PythUpdater extends import_base.SDKConstruct {
|
|
|
72
72
|
`using historical timestamp ${this.#historicalTimestamp}`
|
|
73
73
|
);
|
|
74
74
|
}
|
|
75
|
-
this.#cache =
|
|
75
|
+
this.#cache = import_PriceUpdatesCache.PriceUpdatesCache.get("pyth", {
|
|
76
76
|
// currently staleness period is 240 seconds on all networks, add some buffer
|
|
77
77
|
// this period of 4 minutes is selected based on time that is required for user to sign transaction with wallet
|
|
78
78
|
// so it's unlikely to decrease
|
|
@@ -79,7 +79,7 @@ class RedstoneUpdater extends import_base.SDKConstruct {
|
|
|
79
79
|
`using historical timestamp ${this.#historicalTimestampMs}`
|
|
80
80
|
);
|
|
81
81
|
}
|
|
82
|
-
this.#cache =
|
|
82
|
+
this.#cache = import_PriceUpdatesCache.PriceUpdatesCache.get("redstone", {
|
|
83
83
|
// currently staleness period is 240 seconds on all networks, add some buffer
|
|
84
84
|
// this period of 4 minutes is selected based on time that is required for user to sign transaction with wallet
|
|
85
85
|
// so it's unlikely to decrease
|
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
class PriceUpdatesCache {
|
|
2
|
+
static #caches = /* @__PURE__ */ new Map();
|
|
3
|
+
/**
|
|
4
|
+
* Price update caches can be shared across networks
|
|
5
|
+
* @param id - unique key to identify the cache
|
|
6
|
+
* @param opts
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
static get(id, opts) {
|
|
10
|
+
const key = `${id}:${opts.historical ? "historical" : "latest"}:${opts.ttl}`;
|
|
11
|
+
const cache = PriceUpdatesCache.#caches.get(key);
|
|
12
|
+
if (cache) {
|
|
13
|
+
return cache;
|
|
14
|
+
}
|
|
15
|
+
const newCache = new PriceUpdatesCache(opts);
|
|
16
|
+
PriceUpdatesCache.#caches.set(key, newCache);
|
|
17
|
+
return newCache;
|
|
18
|
+
}
|
|
2
19
|
#cache = /* @__PURE__ */ new Map();
|
|
3
20
|
#ttlMs;
|
|
4
21
|
#historical;
|
|
@@ -52,7 +52,7 @@ class PythUpdater extends SDKConstruct {
|
|
|
52
52
|
`using historical timestamp ${this.#historicalTimestamp}`
|
|
53
53
|
);
|
|
54
54
|
}
|
|
55
|
-
this.#cache =
|
|
55
|
+
this.#cache = PriceUpdatesCache.get("pyth", {
|
|
56
56
|
// currently staleness period is 240 seconds on all networks, add some buffer
|
|
57
57
|
// this period of 4 minutes is selected based on time that is required for user to sign transaction with wallet
|
|
58
58
|
// so it's unlikely to decrease
|
|
@@ -57,7 +57,7 @@ class RedstoneUpdater extends SDKConstruct {
|
|
|
57
57
|
`using historical timestamp ${this.#historicalTimestampMs}`
|
|
58
58
|
);
|
|
59
59
|
}
|
|
60
|
-
this.#cache =
|
|
60
|
+
this.#cache = PriceUpdatesCache.get("redstone", {
|
|
61
61
|
// currently staleness period is 240 seconds on all networks, add some buffer
|
|
62
62
|
// this period of 4 minutes is selected based on time that is required for user to sign transaction with wallet
|
|
63
63
|
// so it's unlikely to decrease
|
|
@@ -11,7 +11,14 @@ export interface PriceUpdatesCacheOptions {
|
|
|
11
11
|
}
|
|
12
12
|
export declare class PriceUpdatesCache {
|
|
13
13
|
#private;
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Price update caches can be shared across networks
|
|
16
|
+
* @param id - unique key to identify the cache
|
|
17
|
+
* @param opts
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
static get(id: string, opts: PriceUpdatesCacheOptions): PriceUpdatesCache;
|
|
21
|
+
private constructor();
|
|
15
22
|
get(...path: Array<number | string>): Omit<TimestampedCalldata, "cached"> | undefined;
|
|
16
23
|
set(value: Omit<TimestampedCalldata, "cached">, ...path: Array<number | string>): void;
|
|
17
24
|
}
|