@dhedge/backend-flatcoin-core 0.3.24 → 0.3.26
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/constants/enum.d.ts
CHANGED
package/dist/constants/enum.js
CHANGED
|
@@ -13,6 +13,7 @@ var PERIODS;
|
|
|
13
13
|
var BlockchainCode;
|
|
14
14
|
(function (BlockchainCode) {
|
|
15
15
|
BlockchainCode["BASE"] = "BASE";
|
|
16
|
+
BlockchainCode["OPTIMISM"] = "OPTIMISM";
|
|
16
17
|
BlockchainCode["ARBITRUM"] = "ARBITRUM";
|
|
17
18
|
})(BlockchainCode || (exports.BlockchainCode = BlockchainCode = {}));
|
|
18
19
|
var Market;
|
|
@@ -4,13 +4,12 @@ import { BigNumber } from 'ethers';
|
|
|
4
4
|
export declare class AppPriceService {
|
|
5
5
|
private readonly connection;
|
|
6
6
|
private readonly logger;
|
|
7
|
-
private readonly priceIds;
|
|
8
7
|
constructor(connection: EvmPriceServiceConnection, logger: Logger);
|
|
9
|
-
getPriceUpdates(): Promise<string[]>;
|
|
10
|
-
getPrice(): Promise<BigNumber>;
|
|
11
|
-
getPriceByTimestamp(timestamp: number): Promise<BigNumber>;
|
|
12
|
-
getPriceUpdatesWithRetry(maxRetries: number, timeoutMillis: number): Promise<string[]>;
|
|
13
|
-
getPriceWithRetry(maxRetries: number, timeoutMillis: number): Promise<BigNumber>;
|
|
14
|
-
getPriceByTimestampWithRetry(timestamp: number, maxRetries: number, timeoutMillis: number): Promise<BigNumber>;
|
|
8
|
+
getPriceUpdates(priceIds: string[]): Promise<string[]>;
|
|
9
|
+
getPrice(priceIds: string[]): Promise<BigNumber>;
|
|
10
|
+
getPriceByTimestamp(priceIds: string[], timestamp: number): Promise<BigNumber>;
|
|
11
|
+
getPriceUpdatesWithRetry(priceIds: string[], maxRetries: number, timeoutMillis: number): Promise<string[]>;
|
|
12
|
+
getPriceWithRetry(priceIds: string[], maxRetries: number, timeoutMillis: number): Promise<BigNumber>;
|
|
13
|
+
getPriceByTimestampWithRetry(priceIds: string[], timestamp: number, maxRetries: number, timeoutMillis: number): Promise<BigNumber>;
|
|
15
14
|
retry<T>(func: () => Promise<T>, maxRetries: number, timeoutMillis: number): Promise<T>;
|
|
16
15
|
}
|
|
@@ -14,45 +14,40 @@ const common_1 = require("@nestjs/common");
|
|
|
14
14
|
const pyth_evm_js_1 = require("@pythnetwork/pyth-evm-js");
|
|
15
15
|
const ethers_1 = require("ethers");
|
|
16
16
|
let AppPriceService = class AppPriceService {
|
|
17
|
+
// You can find the ids of prices at https://pyth.network/developers/price-feed-ids#pyth-evm-testnet
|
|
17
18
|
constructor(connection, logger) {
|
|
18
19
|
this.connection = connection;
|
|
19
20
|
this.logger = logger;
|
|
20
|
-
if (process.env.PYTH_NETWORK_PRICE_ID) {
|
|
21
|
-
this.priceIds = [process.env.PYTH_NETWORK_PRICE_ID];
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
throw new Error('env property PYTH_NETWORK_PRICE_ID is not configured');
|
|
25
|
-
}
|
|
26
21
|
}
|
|
27
|
-
async getPriceUpdates() {
|
|
22
|
+
async getPriceUpdates(priceIds) {
|
|
28
23
|
// In order to use Pyth prices in your protocol you need to submit the price update data to Pyth contract in your target
|
|
29
24
|
// chain. `getPriceFeedsUpdateData` creates the update data which can be submitted to your contract. Then your contract should
|
|
30
25
|
// call the Pyth Contract with this data.
|
|
31
|
-
const priceUpdates = await this.connection.getPriceFeedsUpdateData(
|
|
26
|
+
const priceUpdates = await this.connection.getPriceFeedsUpdateData(priceIds);
|
|
32
27
|
if (!priceUpdates) {
|
|
33
28
|
throw new Error('failed to get PriceFeedsUpdateData');
|
|
34
29
|
}
|
|
35
30
|
return priceUpdates;
|
|
36
31
|
}
|
|
37
|
-
async getPrice() {
|
|
38
|
-
const priceFeeds = await this.connection.getLatestPriceFeeds(
|
|
32
|
+
async getPrice(priceIds) {
|
|
33
|
+
const priceFeeds = await this.connection.getLatestPriceFeeds(priceIds);
|
|
39
34
|
if (!priceFeeds) {
|
|
40
35
|
throw new Error('failed to get LatestPriceFeeds');
|
|
41
36
|
}
|
|
42
37
|
return ethers_1.BigNumber.from(priceFeeds[0].getPriceUnchecked().price).mul(ethers_1.BigNumber.from(10).pow(10));
|
|
43
38
|
}
|
|
44
|
-
async getPriceByTimestamp(timestamp) {
|
|
45
|
-
const priceFeed = await this.connection.getPriceFeed(
|
|
39
|
+
async getPriceByTimestamp(priceIds, timestamp) {
|
|
40
|
+
const priceFeed = await this.connection.getPriceFeed(priceIds[0], timestamp);
|
|
46
41
|
return ethers_1.BigNumber.from(priceFeed.getPriceUnchecked().price).mul(ethers_1.BigNumber.from(10).pow(10));
|
|
47
42
|
}
|
|
48
|
-
async getPriceUpdatesWithRetry(maxRetries, timeoutMillis) {
|
|
49
|
-
return this.retry(this.getPriceUpdates.bind(this), maxRetries, timeoutMillis);
|
|
43
|
+
async getPriceUpdatesWithRetry(priceIds, maxRetries, timeoutMillis) {
|
|
44
|
+
return this.retry(() => this.getPriceUpdates.bind(this)(priceIds), maxRetries, timeoutMillis);
|
|
50
45
|
}
|
|
51
|
-
async getPriceWithRetry(maxRetries, timeoutMillis) {
|
|
52
|
-
return this.retry(this.getPrice.bind(this), maxRetries, timeoutMillis);
|
|
46
|
+
async getPriceWithRetry(priceIds, maxRetries, timeoutMillis) {
|
|
47
|
+
return this.retry(() => this.getPrice.bind(this)(priceIds), maxRetries, timeoutMillis);
|
|
53
48
|
}
|
|
54
|
-
async getPriceByTimestampWithRetry(timestamp, maxRetries, timeoutMillis) {
|
|
55
|
-
return this.retry(() => this.getPriceByTimestamp.bind(this)(timestamp), maxRetries, timeoutMillis);
|
|
49
|
+
async getPriceByTimestampWithRetry(priceIds, timestamp, maxRetries, timeoutMillis) {
|
|
50
|
+
return this.retry(() => this.getPriceByTimestamp.bind(this)(priceIds, timestamp), maxRetries, timeoutMillis);
|
|
56
51
|
}
|
|
57
52
|
async retry(func, maxRetries, timeoutMillis) {
|
|
58
53
|
for (let retries = 0; retries < maxRetries; retries++) {
|