@dhedge/backend-flatcoin-core 0.2.95 → 0.2.96

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.
@@ -0,0 +1,43 @@
1
+ export declare const PythPriceFeed: ({
2
+ inputs: {
3
+ internalType: string;
4
+ name: string;
5
+ type: string;
6
+ }[];
7
+ name: string;
8
+ outputs: {
9
+ components: ({
10
+ internalType: string;
11
+ name: string;
12
+ type: string;
13
+ components?: undefined;
14
+ } | {
15
+ components: {
16
+ internalType: string;
17
+ name: string;
18
+ type: string;
19
+ }[];
20
+ internalType: string;
21
+ name: string;
22
+ type: string;
23
+ })[];
24
+ internalType: string;
25
+ name: string;
26
+ type: string;
27
+ }[];
28
+ stateMutability: string;
29
+ type: string;
30
+ anonymous?: undefined;
31
+ } | {
32
+ anonymous: boolean;
33
+ inputs: {
34
+ indexed: boolean;
35
+ internalType: string;
36
+ name: string;
37
+ type: string;
38
+ }[];
39
+ name: string;
40
+ type: string;
41
+ outputs?: undefined;
42
+ stateMutability?: undefined;
43
+ })[];
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PythPriceFeed = void 0;
4
+ exports.PythPriceFeed = [
5
+ {
6
+ inputs: [
7
+ {
8
+ internalType: 'bytes32',
9
+ name: 'id',
10
+ type: 'bytes32',
11
+ },
12
+ ],
13
+ name: 'queryPriceFeed',
14
+ outputs: [
15
+ {
16
+ components: [
17
+ {
18
+ internalType: 'bytes32',
19
+ name: 'id',
20
+ type: 'bytes32',
21
+ },
22
+ {
23
+ components: [
24
+ {
25
+ internalType: 'int64',
26
+ name: 'price',
27
+ type: 'int64',
28
+ },
29
+ {
30
+ internalType: 'uint64',
31
+ name: 'conf',
32
+ type: 'uint64',
33
+ },
34
+ {
35
+ internalType: 'int32',
36
+ name: 'expo',
37
+ type: 'int32',
38
+ },
39
+ {
40
+ internalType: 'uint256',
41
+ name: 'publishTime',
42
+ type: 'uint256',
43
+ },
44
+ ],
45
+ internalType: 'struct PythStructs.Price',
46
+ name: 'price',
47
+ type: 'tuple',
48
+ },
49
+ {
50
+ components: [
51
+ {
52
+ internalType: 'int64',
53
+ name: 'price',
54
+ type: 'int64',
55
+ },
56
+ {
57
+ internalType: 'uint64',
58
+ name: 'conf',
59
+ type: 'uint64',
60
+ },
61
+ {
62
+ internalType: 'int32',
63
+ name: 'expo',
64
+ type: 'int32',
65
+ },
66
+ {
67
+ internalType: 'uint256',
68
+ name: 'publishTime',
69
+ type: 'uint256',
70
+ },
71
+ ],
72
+ internalType: 'struct PythStructs.Price',
73
+ name: 'emaPrice',
74
+ type: 'tuple',
75
+ },
76
+ ],
77
+ internalType: 'struct PythStructs.PriceFeed',
78
+ name: 'priceFeed',
79
+ type: 'tuple',
80
+ },
81
+ ],
82
+ stateMutability: 'view',
83
+ type: 'function',
84
+ },
85
+ {
86
+ anonymous: false,
87
+ inputs: [
88
+ {
89
+ indexed: true,
90
+ internalType: 'address',
91
+ name: 'owner',
92
+ type: 'address',
93
+ },
94
+ {
95
+ indexed: true,
96
+ internalType: 'address',
97
+ name: 'spender',
98
+ type: 'address',
99
+ },
100
+ {
101
+ indexed: false,
102
+ internalType: 'uint256',
103
+ name: 'value',
104
+ type: 'uint256',
105
+ },
106
+ ],
107
+ name: 'Approval',
108
+ type: 'event',
109
+ },
110
+ ];
@@ -10,5 +10,5 @@ export { LimitOrder } from './abi/limit-order';
10
10
  export { DelayedOrder } from './abi/delayed-order';
11
11
  export { FlatcoinVault } from './abi/flatcoin-vault';
12
12
  export { CanLiquidateWithPriceFeeds } from './abi/liquidation-module';
13
- export { AssetHandler } from './abi/asset-handler';
13
+ export { PythPriceFeed } from './abi/pyth-price-feed';
14
14
  export * from './helpers';
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.AssetHandler = exports.CanLiquidateWithPriceFeeds = exports.FlatcoinVault = exports.DelayedOrder = exports.LimitOrder = exports.LiquidateWithoutPriceFeeds = exports.Liquidate = exports.LiquidationModule = exports.LeverageModule = exports.FlatcoinErrors = exports.ViewerGetPositionData = exports.Viewer = exports.StableModule = void 0;
17
+ exports.PythPriceFeed = exports.CanLiquidateWithPriceFeeds = exports.FlatcoinVault = exports.DelayedOrder = exports.LimitOrder = exports.LiquidateWithoutPriceFeeds = exports.Liquidate = exports.LiquidationModule = exports.LeverageModule = exports.FlatcoinErrors = exports.ViewerGetPositionData = exports.Viewer = exports.StableModule = void 0;
18
18
  var stable_module_1 = require("./abi/stable-module");
19
19
  Object.defineProperty(exports, "StableModule", { enumerable: true, get: function () { return stable_module_1.StableModule; } });
20
20
  var viewer_1 = require("./abi/viewer");
@@ -39,6 +39,6 @@ var flatcoin_vault_1 = require("./abi/flatcoin-vault");
39
39
  Object.defineProperty(exports, "FlatcoinVault", { enumerable: true, get: function () { return flatcoin_vault_1.FlatcoinVault; } });
40
40
  var liquidation_module_4 = require("./abi/liquidation-module");
41
41
  Object.defineProperty(exports, "CanLiquidateWithPriceFeeds", { enumerable: true, get: function () { return liquidation_module_4.CanLiquidateWithPriceFeeds; } });
42
- var asset_handler_1 = require("./abi/asset-handler");
43
- Object.defineProperty(exports, "AssetHandler", { enumerable: true, get: function () { return asset_handler_1.AssetHandler; } });
42
+ var pyth_price_feed_1 = require("./abi/pyth-price-feed");
43
+ Object.defineProperty(exports, "PythPriceFeed", { enumerable: true, get: function () { return pyth_price_feed_1.PythPriceFeed; } });
44
44
  __exportStar(require("./helpers"), exports);
@@ -19,11 +19,11 @@ let AvgDepositPriceService = class AvgDepositPriceService {
19
19
  this.graphQueryService = graphQueryService;
20
20
  this.logger = logger;
21
21
  this.blockchainPriceService = blockchainPriceService;
22
- if (process.env.ASSET_HANDLER_ETH_ADDRESS) {
23
- this.ethAddress = process.env.ASSET_HANDLER_ETH_ADDRESS;
22
+ if (process.env.PYTH_PRICE_FEED_ETH_ADDRESS) {
23
+ this.ethAddress = process.env.PYTH_PRICE_FEED_ETH_ADDRESS;
24
24
  }
25
25
  else {
26
- throw new Error('env property ASSET_HANDLER_ETH_ADDRESS is not configured');
26
+ throw new Error('env property PYTH_PRICE_FEED_ETH_ADDRESS is not configured');
27
27
  }
28
28
  }
29
29
  async getAverageDepositPriceInEth(tokenId) {
@@ -9,4 +9,5 @@ export declare class BlockchainPriceService {
9
9
  private readonly assetHandlerContract;
10
10
  constructor(graphQueryService: GraphQueryService, customProvider: JsonRpcProvider, logger: Logger);
11
11
  getUsdPriceAtBlock(assetAddress: string, blockNumber: number): Promise<BigNumber>;
12
+ private getUsdPriceAtBlockUnformatted;
12
13
  }
@@ -16,7 +16,7 @@ exports.BlockchainPriceService = void 0;
16
16
  const common_1 = require("@nestjs/common");
17
17
  const graph_query_service_1 = require("./graph-query.service");
18
18
  const ethers_1 = require("ethers");
19
- const asset_handler_1 = require("../contracts/abi/asset-handler");
19
+ const pyth_price_feed_1 = require("../contracts/abi/pyth-price-feed");
20
20
  const nestjs_ethers_1 = require("nestjs-ethers");
21
21
  const providers_1 = require("@ethersproject/providers");
22
22
  let BlockchainPriceService = class BlockchainPriceService {
@@ -24,16 +24,25 @@ let BlockchainPriceService = class BlockchainPriceService {
24
24
  this.graphQueryService = graphQueryService;
25
25
  this.customProvider = customProvider;
26
26
  this.logger = logger;
27
- if (process.env.ASSET_HANDLER_CONTRACT_ADDRESS) {
28
- this.assetHandlerContract = new ethers_1.Contract(process.env.ASSET_HANDLER_CONTRACT_ADDRESS, asset_handler_1.AssetHandler, this.customProvider);
27
+ if (process.env.PYHT_PRICE_FEED_CONTRACT_ADDRESS) {
28
+ this.assetHandlerContract = new ethers_1.Contract(process.env.PYHT_PRICE_FEED_CONTRACT_ADDRESS, pyth_price_feed_1.PythPriceFeed, this.customProvider);
29
29
  }
30
30
  else {
31
- throw new Error('env property ASSET_HANDLER_CONTRACT_ADDRESS is not configured');
31
+ throw new Error('env property PYHT_PRICE_FEED_CONTRACT_ADDRESS is not configured');
32
32
  }
33
33
  }
34
34
  async getUsdPriceAtBlock(assetAddress, blockNumber) {
35
35
  try {
36
- return await this.assetHandlerContract.callStatic['getUSDPrice'](assetAddress, {
36
+ return (await this.getUsdPriceAtBlockUnformatted(assetAddress, blockNumber)).mul(ethers_1.BigNumber.from('10000000000'));
37
+ }
38
+ catch (err) {
39
+ this.logger.error(`Error calling getUSDPrice with asset address ${assetAddress}:`, err);
40
+ throw err;
41
+ }
42
+ }
43
+ async getUsdPriceAtBlockUnformatted(assetAddress, blockNumber) {
44
+ try {
45
+ return await this.assetHandlerContract.callStatic['queryPriceFeed'](assetAddress, {
37
46
  blockTag: blockNumber,
38
47
  });
39
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhedge/backend-flatcoin-core",
3
- "version": "0.2.95",
3
+ "version": "0.2.96",
4
4
  "description": "Backend Flatcoin Core",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,15 +0,0 @@
1
- export declare const AssetHandler: {
2
- inputs: {
3
- internalType: string;
4
- name: string;
5
- type: string;
6
- }[];
7
- name: string;
8
- outputs: {
9
- internalType: string;
10
- name: string;
11
- type: string;
12
- }[];
13
- stateMutability: string;
14
- type: string;
15
- }[];
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AssetHandler = void 0;
4
- exports.AssetHandler = [
5
- {
6
- inputs: [
7
- {
8
- internalType: 'address',
9
- name: 'asset',
10
- type: 'address',
11
- },
12
- ],
13
- name: 'getUSDPrice',
14
- outputs: [
15
- {
16
- internalType: 'uint256',
17
- name: 'price',
18
- type: 'uint256',
19
- },
20
- ],
21
- stateMutability: 'view',
22
- type: 'function',
23
- },
24
- ];