@gearbox-protocol/sdk 3.0.4 → 3.1.0
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/oracle/PriceOracleBaseContract.js +11 -0
- package/dist/cjs/sdk/utils/viem/getLogsSafe.js +2 -2
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +11 -0
- package/dist/esm/sdk/utils/viem/getLogsSafe.js +2 -2
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +7 -0
- package/dist/types/sdk/market/oracle/types.d.ts +2 -0
- package/package.json +1 -1
|
@@ -211,6 +211,17 @@ class PriceOracleBaseContract extends import_base.BaseContract {
|
|
|
211
211
|
const scale = 10n ** BigInt(this.sdk.tokensMeta.decimals(from));
|
|
212
212
|
return amount * price / scale;
|
|
213
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* Tries to convert amount of USD to token, using latest known prices
|
|
216
|
+
* @param to
|
|
217
|
+
* @param amount
|
|
218
|
+
* @param reserve
|
|
219
|
+
*/
|
|
220
|
+
convertFromUSD(to, amount, reserve = false) {
|
|
221
|
+
const price = reserve ? this.reservePrice(to) : this.mainPrice(to);
|
|
222
|
+
const scale = 10n ** BigInt(this.sdk.tokensMeta.decimals(to));
|
|
223
|
+
return amount * scale / price;
|
|
224
|
+
}
|
|
214
225
|
/**
|
|
215
226
|
* Loads new prices for this oracle from PriceFeedCompressor
|
|
216
227
|
* Does not update price feeds, only updates prices
|
|
@@ -35,8 +35,8 @@ async function getLogsSafe(client, params = {}) {
|
|
|
35
35
|
throw e;
|
|
36
36
|
}
|
|
37
37
|
const [left, right] = await Promise.all([
|
|
38
|
-
(
|
|
39
|
-
(
|
|
38
|
+
getLogsSafe(client, { ...params, ...bisected[0] }),
|
|
39
|
+
getLogsSafe(client, { ...params, ...bisected[1] })
|
|
40
40
|
]);
|
|
41
41
|
return [...left, ...right];
|
|
42
42
|
}
|
|
@@ -178,6 +178,17 @@ class PriceOracleBaseContract extends BaseContract {
|
|
|
178
178
|
const scale = 10n ** BigInt(this.sdk.tokensMeta.decimals(from));
|
|
179
179
|
return amount * price / scale;
|
|
180
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Tries to convert amount of USD to token, using latest known prices
|
|
183
|
+
* @param to
|
|
184
|
+
* @param amount
|
|
185
|
+
* @param reserve
|
|
186
|
+
*/
|
|
187
|
+
convertFromUSD(to, amount, reserve = false) {
|
|
188
|
+
const price = reserve ? this.reservePrice(to) : this.mainPrice(to);
|
|
189
|
+
const scale = 10n ** BigInt(this.sdk.tokensMeta.decimals(to));
|
|
190
|
+
return amount * scale / price;
|
|
191
|
+
}
|
|
181
192
|
/**
|
|
182
193
|
* Loads new prices for this oracle from PriceFeedCompressor
|
|
183
194
|
* Does not update price feeds, only updates prices
|
|
@@ -14,8 +14,8 @@ async function getLogsSafe(client, params = {}) {
|
|
|
14
14
|
throw e;
|
|
15
15
|
}
|
|
16
16
|
const [left, right] = await Promise.all([
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
getLogsSafe(client, { ...params, ...bisected[0] }),
|
|
18
|
+
getLogsSafe(client, { ...params, ...bisected[1] })
|
|
19
19
|
]);
|
|
20
20
|
return [...left, ...right];
|
|
21
21
|
}
|
|
@@ -95,6 +95,13 @@ export declare class PriceOracleBaseContract<abi extends Abi | readonly unknown[
|
|
|
95
95
|
* @param reserve
|
|
96
96
|
*/
|
|
97
97
|
convertToUSD(from: Address, amount: bigint, reserve?: boolean): bigint;
|
|
98
|
+
/**
|
|
99
|
+
* Tries to convert amount of USD to token, using latest known prices
|
|
100
|
+
* @param to
|
|
101
|
+
* @param amount
|
|
102
|
+
* @param reserve
|
|
103
|
+
*/
|
|
104
|
+
convertFromUSD(to: Address, amount: bigint, reserve?: boolean): bigint;
|
|
98
105
|
/**
|
|
99
106
|
* Loads new prices for this oracle from PriceFeedCompressor
|
|
100
107
|
* Does not update price feeds, only updates prices
|
|
@@ -24,4 +24,6 @@ export interface IPriceOracleContract extends IBaseContract {
|
|
|
24
24
|
onDemandPriceUpdates: (updates?: UpdatePriceFeedsResult) => OnDemandPriceUpdate[];
|
|
25
25
|
convertToUnderlying: (token: Address, amount: bigint, reserve?: boolean) => bigint;
|
|
26
26
|
convert: (from: Address, to: Address, amount: bigint, reserve?: boolean) => bigint;
|
|
27
|
+
convertToUSD: (from: Address, amount: bigint, reserve?: boolean) => bigint;
|
|
28
|
+
convertFromUSD: (to: Address, amount: bigint, reserve?: boolean) => bigint;
|
|
27
29
|
}
|