@dhedge/backend-flatcoin-core 0.3.25 → 0.3.27

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.
@@ -527,11 +527,6 @@ exports.FlatcoinErrors = [
527
527
  name: 'AddressInsufficientBalance',
528
528
  type: 'error',
529
529
  },
530
- {
531
- inputs: [{ internalType: 'uint256', name: 'tokenId', type: 'uint256' }],
532
- name: 'LimitOrderInvalid',
533
- type: 'error',
534
- },
535
530
  { inputs: [], name: 'ReentrancyGuardReentrantCall', type: 'error' },
536
531
  {
537
532
  inputs: [{ internalType: 'address', name: 'token', type: 'address' }],
@@ -539,11 +534,6 @@ exports.FlatcoinErrors = [
539
534
  type: 'error',
540
535
  },
541
536
  { inputs: [{ internalType: 'address', name: 'target', type: 'address' }], name: 'AddressEmptyCode', type: 'error' },
542
- {
543
- inputs: [{ internalType: 'address', name: 'account', type: 'address' }],
544
- name: 'AddressInsufficientBalance',
545
- type: 'error',
546
- },
547
537
  { inputs: [], name: 'FailedInnerCall', type: 'error' },
548
538
  { inputs: [], name: 'InvalidInitialization', type: 'error' },
549
539
  {
@@ -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(this.priceIds);
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(this.priceIds);
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(this.priceIds[0], timestamp);
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++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhedge/backend-flatcoin-core",
3
- "version": "0.3.25",
3
+ "version": "0.3.27",
4
4
  "description": "Backend Flatcoin Core",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",