@defisaver/positions-sdk 0.0.5 → 0.0.6

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.
Files changed (54) hide show
  1. package/cjs/aaveV2/index.d.ts +2 -2
  2. package/cjs/aaveV2/index.js +5 -3
  3. package/cjs/compoundV3/index.d.ts +2 -2
  4. package/cjs/compoundV3/index.js +8 -5
  5. package/cjs/config/contracts.d.ts +144 -0
  6. package/cjs/config/contracts.js +18 -0
  7. package/cjs/contracts.d.ts +3 -0
  8. package/cjs/contracts.js +4 -1
  9. package/cjs/helpers/compoundHelpers/index.d.ts +2 -2
  10. package/cjs/helpers/compoundHelpers/index.js +5 -4
  11. package/cjs/morphoAaveV2/index.d.ts +2 -2
  12. package/cjs/morphoAaveV2/index.js +5 -3
  13. package/cjs/services/priceService.d.ts +4 -0
  14. package/cjs/services/priceService.js +36 -0
  15. package/cjs/types/contracts/generated/COMPPriceFeed.d.ts +135 -0
  16. package/cjs/types/contracts/generated/COMPPriceFeed.js +5 -0
  17. package/cjs/types/contracts/generated/ETHPriceFeed.d.ts +135 -0
  18. package/cjs/types/contracts/generated/ETHPriceFeed.js +5 -0
  19. package/cjs/types/contracts/generated/USDCPriceFeed.d.ts +135 -0
  20. package/cjs/types/contracts/generated/USDCPriceFeed.js +5 -0
  21. package/cjs/types/contracts/generated/index.d.ts +3 -0
  22. package/esm/aaveV2/index.d.ts +2 -2
  23. package/esm/aaveV2/index.js +5 -3
  24. package/esm/compoundV3/index.d.ts +2 -2
  25. package/esm/compoundV3/index.js +8 -5
  26. package/esm/config/contracts.d.ts +144 -0
  27. package/esm/config/contracts.js +18 -0
  28. package/esm/contracts.d.ts +3 -0
  29. package/esm/contracts.js +3 -0
  30. package/esm/helpers/compoundHelpers/index.d.ts +2 -2
  31. package/esm/helpers/compoundHelpers/index.js +5 -4
  32. package/esm/morphoAaveV2/index.d.ts +2 -2
  33. package/esm/morphoAaveV2/index.js +5 -3
  34. package/esm/services/priceService.d.ts +4 -0
  35. package/esm/services/priceService.js +27 -0
  36. package/esm/types/contracts/generated/COMPPriceFeed.d.ts +135 -0
  37. package/esm/types/contracts/generated/COMPPriceFeed.js +4 -0
  38. package/esm/types/contracts/generated/ETHPriceFeed.d.ts +135 -0
  39. package/esm/types/contracts/generated/ETHPriceFeed.js +4 -0
  40. package/esm/types/contracts/generated/USDCPriceFeed.d.ts +135 -0
  41. package/esm/types/contracts/generated/USDCPriceFeed.js +4 -0
  42. package/esm/types/contracts/generated/index.d.ts +3 -0
  43. package/package.json +1 -1
  44. package/src/aaveV2/index.ts +5 -3
  45. package/src/compoundV3/index.ts +8 -5
  46. package/src/config/contracts.js +18 -0
  47. package/src/contracts.ts +5 -1
  48. package/src/helpers/compoundHelpers/index.ts +5 -2
  49. package/src/morphoAaveV2/index.ts +5 -3
  50. package/src/services/priceService.ts +22 -0
  51. package/src/types/contracts/generated/COMPPriceFeed.ts +202 -0
  52. package/src/types/contracts/generated/ETHPriceFeed.ts +202 -0
  53. package/src/types/contracts/generated/USDCPriceFeed.ts +202 -0
  54. package/src/types/contracts/generated/index.ts +3 -0
@@ -39,3 +39,6 @@ export declare const McdJugContract: (web3: Web3, network: NetworkNumber, block?
39
39
  export declare const McdVatContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.McdVat;
40
40
  export declare const ChickenBondsViewContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.ChickenBondsView;
41
41
  export declare const ChickenBondsManagerContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.ChickenBondsManager;
42
+ export declare const ETHPriceFeedContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.ETHPriceFeed;
43
+ export declare const COMPPriceFeedContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.COMPPriceFeed;
44
+ export declare const USDCPriceFeedContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.USDCPriceFeed;
package/esm/contracts.js CHANGED
@@ -54,3 +54,6 @@ export const McdJugContract = createContractFromConfigFunc('McdJug');
54
54
  export const McdVatContract = createContractFromConfigFunc('McdVat');
55
55
  export const ChickenBondsViewContract = createContractFromConfigFunc('ChickenBondsView');
56
56
  export const ChickenBondsManagerContract = createContractFromConfigFunc('ChickenBondsManager');
57
+ export const ETHPriceFeedContract = createContractFromConfigFunc('ETHPriceFeed');
58
+ export const COMPPriceFeedContract = createContractFromConfigFunc('COMPPriceFeed');
59
+ export const USDCPriceFeedContract = createContractFromConfigFunc('USDCPriceFeed');
@@ -1,7 +1,7 @@
1
1
  import { BaseAdditionalAssetData, CompoundAggregatedPositionData, CompoundMarketData, CompoundV2AssetsData, CompoundV2UsedAssets, CompoundV3AssetData, CompoundV3AssetsData, CompoundV3UsedAssets } from '../../types';
2
2
  import { NetworkNumber } from '../../types/common';
3
- export declare const formatMarketData: (data: any, network: NetworkNumber) => CompoundV3AssetData;
4
- export declare const formatBaseData: (data: any, network: NetworkNumber) => CompoundV3AssetData & BaseAdditionalAssetData;
3
+ export declare const formatMarketData: (data: any, network: NetworkNumber, baseAssetPrice: string) => CompoundV3AssetData;
4
+ export declare const formatBaseData: (data: any, network: NetworkNumber, baseAssetPrice: string) => CompoundV3AssetData & BaseAdditionalAssetData;
5
5
  export declare const getIncentiveApys: (baseData: CompoundV3AssetData & BaseAdditionalAssetData, compPrice: string) => {
6
6
  incentiveSupplyApy: string;
7
7
  incentiveBorrowApy: string;
@@ -16,13 +16,14 @@ import { getEthAmountForDecimals, handleWbtcLegacy, wethToEth } from '../../serv
16
16
  import { SECONDS_PER_YEAR } from '../../constants';
17
17
  import { aprToApy, calcLeverageLiqPrice, calculateBorrowingAssetLimit, getAssetsTotal, isLeveragedPos, } from '../../moneymarket';
18
18
  import { calculateNetApy } from '../../staking';
19
- export const formatMarketData = (data, network) => {
19
+ export const formatMarketData = (data, network, baseAssetPrice) => {
20
20
  const assetInfo = getAssetInfoByAddress(data.tokenAddr, network);
21
21
  const isWETH = assetInfo.symbol === 'WETH';
22
- return (Object.assign(Object.assign({}, data), { price: getEthAmountForDecimals(data.price, 8), collateralFactor: getEthAmountForDecimals(data.borrowCollateralFactor, 18), liquidationRatio: getEthAmountForDecimals(data.liquidateCollateralFactor, 18), supplyCap: getEthAmountForDecimals(data.supplyCap, assetInfo.decimals), totalSupply: getEthAmountForDecimals(data.totalSupply, assetInfo.decimals), symbol: isWETH ? 'ETH' : assetInfo.symbol, supplyRate: '0', borrowRate: '0', canBeBorrowed: false, canBeSupplied: true }));
22
+ const price = getEthAmountForDecimals(data.price, 8);
23
+ return (Object.assign(Object.assign({}, data), { price: getEthAmountForDecimals(data.price, 8), priceUSD: new Dec(price).mul(baseAssetPrice).toString(), collateralFactor: getEthAmountForDecimals(data.borrowCollateralFactor, 18), liquidationRatio: getEthAmountForDecimals(data.liquidateCollateralFactor, 18), supplyCap: getEthAmountForDecimals(data.supplyCap, assetInfo.decimals), totalSupply: getEthAmountForDecimals(data.totalSupply, assetInfo.decimals), symbol: isWETH ? 'ETH' : assetInfo.symbol, supplyRate: '0', borrowRate: '0', canBeBorrowed: false, canBeSupplied: true }));
23
24
  };
24
25
  // TODO: maybe not hardcode decimals
25
- export const formatBaseData = (data, network) => {
26
+ export const formatBaseData = (data, network, baseAssetPrice) => {
26
27
  const assetInfo = getAssetInfoByAddress(data.tokenAddr, network);
27
28
  const totalSupply = getEthAmountForDecimals(new Dec(data.totalSupply).mul(data.supplyIndex).toString(), 15 + assetInfo.decimals);
28
29
  const totalBorrow = getEthAmountForDecimals(new Dec(data.totalBorrow).mul(data.borrowIndex).toString(), 15 + assetInfo.decimals);
@@ -30,7 +31,7 @@ export const formatBaseData = (data, network) => {
30
31
  .toString()), borrowRate: aprToApy(new Dec(data.borrowRate).div(1e18).mul(SECONDS_PER_YEAR).mul(100)
31
32
  .toString()), utilization: getEthAmountForDecimals(data.utilization, 16), // utilization is totalSupply/totalBorrow in 1e18, but we need % so when we mul with 100 it's 16 decimals
32
33
  totalSupply,
33
- totalBorrow, marketLiquidity: new Dec(totalSupply).minus(totalBorrow).toString(), symbol: wethToEth(assetInfo.symbol), price: getEthAmountForDecimals(data.price, 8), collateralFactor: '0', liquidationRatio: '0', canBeBorrowed: true, canBeSupplied: true, supplyCap: '0', rewardSupplySpeed: getEthAmountForDecimals(data.baseTrackingSupplyRewardsSpeed, 15), rewardBorrowSpeed: getEthAmountForDecimals(data.baseTrackingBorrowRewardsSpeed, 15), minDebt: getEthAmountForDecimals(data.baseBorrowMin, assetInfo.decimals), isBase: true }));
34
+ totalBorrow, marketLiquidity: new Dec(totalSupply).minus(totalBorrow).toString(), symbol: wethToEth(assetInfo.symbol), price: getEthAmountForDecimals(data.price, 8), priceUSD: baseAssetPrice, collateralFactor: '0', liquidationRatio: '0', canBeBorrowed: true, canBeSupplied: true, supplyCap: '0', rewardSupplySpeed: getEthAmountForDecimals(data.baseTrackingSupplyRewardsSpeed, 15), rewardBorrowSpeed: getEthAmountForDecimals(data.baseTrackingBorrowRewardsSpeed, 15), minDebt: getEthAmountForDecimals(data.baseBorrowMin, assetInfo.decimals), isBase: true }));
34
35
  };
35
36
  export const getIncentiveApys = (baseData, compPrice) => {
36
37
  const incentiveSupplyApy = aprToApy((100 * SECONDS_PER_YEAR * +baseData.rewardSupplySpeed * +compPrice) / +baseData.price / +baseData.totalSupply).toString();
@@ -1,7 +1,7 @@
1
1
  import Web3 from 'web3';
2
2
  import { Blockish, EthAddress, NetworkNumber, PositionBalances } from '../types/common';
3
3
  import { MorphoAaveV2AssetsData, MorphoAaveV2MarketData, MorphoAaveV2PositionData } from '../types';
4
- export declare const getMorphoAaveV2MarketsData: (web3: Web3, network: NetworkNumber, ethPrice: string, mainnetWeb3: Web3) => Promise<MorphoAaveV2MarketData>;
4
+ export declare const getMorphoAaveV2MarketsData: (web3: Web3, network: NetworkNumber, mainnetWeb3: Web3) => Promise<MorphoAaveV2MarketData>;
5
5
  export declare const getMorphoAaveV2AccountBalances: (web3: Web3, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress) => Promise<PositionBalances>;
6
6
  export declare const getMorphoAaveV2AccountData: (web3: Web3, network: NetworkNumber, address: string, assetsData: MorphoAaveV2AssetsData) => Promise<MorphoAaveV2PositionData>;
7
- export declare const getMorphoAaveV2FullPositionData: (web3: Web3, network: NetworkNumber, address: string, ethPrice: string, mainnetWeb3: Web3) => Promise<MorphoAaveV2PositionData>;
7
+ export declare const getMorphoAaveV2FullPositionData: (web3: Web3, network: NetworkNumber, address: string, mainnetWeb3: Web3) => Promise<MorphoAaveV2PositionData>;
@@ -16,7 +16,9 @@ import { AaveVersions, } from '../types';
16
16
  import { calculateBorrowingAssetLimit } from '../moneymarket';
17
17
  import { EMPTY_AAVE_DATA } from '../aaveV3';
18
18
  import { aaveAnyGetAggregatedPositionData } from '../helpers/aaveHelpers';
19
- export const getMorphoAaveV2MarketsData = (web3, network, ethPrice, mainnetWeb3) => __awaiter(void 0, void 0, void 0, function* () {
19
+ import { getEthPrice } from '../services/priceService';
20
+ export const getMorphoAaveV2MarketsData = (web3, network, mainnetWeb3) => __awaiter(void 0, void 0, void 0, function* () {
21
+ const ethPrice = yield getEthPrice(mainnetWeb3);
20
22
  const morphoAaveV2ViewContract = MorphoAaveV2ViewContract(web3, network);
21
23
  const [contractData, morphoRewardsRes] = yield Promise.allSettled([
22
24
  morphoAaveV2ViewContract.methods.getAllMarketsInfo().call(),
@@ -192,8 +194,8 @@ export const getMorphoAaveV2AccountData = (web3, network, address, assetsData) =
192
194
  });
193
195
  return payload;
194
196
  });
195
- export const getMorphoAaveV2FullPositionData = (web3, network, address, ethPrice, mainnetWeb3) => __awaiter(void 0, void 0, void 0, function* () {
196
- const marketData = yield getMorphoAaveV2MarketsData(web3, network, ethPrice, mainnetWeb3);
197
+ export const getMorphoAaveV2FullPositionData = (web3, network, address, mainnetWeb3) => __awaiter(void 0, void 0, void 0, function* () {
198
+ const marketData = yield getMorphoAaveV2MarketsData(web3, network, mainnetWeb3);
197
199
  const positionData = yield getMorphoAaveV2AccountData(web3, network, address, marketData.assetsData);
198
200
  return positionData;
199
201
  });
@@ -0,0 +1,4 @@
1
+ import Web3 from 'web3';
2
+ export declare const getEthPrice: (web3: Web3) => Promise<string>;
3
+ export declare const getUSDCPrice: (web3: Web3) => Promise<string>;
4
+ export declare const getCompPrice: (web3: Web3) => Promise<string>;
@@ -0,0 +1,27 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import Dec from 'decimal.js';
11
+ import { COMPPriceFeedContract, ETHPriceFeedContract, USDCPriceFeedContract } from '../contracts';
12
+ import { NetworkNumber } from '../types/common';
13
+ export const getEthPrice = (web3) => __awaiter(void 0, void 0, void 0, function* () {
14
+ const contract = ETHPriceFeedContract(web3, NetworkNumber.Eth);
15
+ const price = yield contract.methods.latestAnswer().call();
16
+ return new Dec(price).div(1e8).toString();
17
+ });
18
+ export const getUSDCPrice = (web3) => __awaiter(void 0, void 0, void 0, function* () {
19
+ const contract = USDCPriceFeedContract(web3, NetworkNumber.Eth);
20
+ const price = yield contract.methods.latestAnswer().call();
21
+ return new Dec(price).div(1e8).toString();
22
+ });
23
+ export const getCompPrice = (web3) => __awaiter(void 0, void 0, void 0, function* () {
24
+ const contract = COMPPriceFeedContract(web3, NetworkNumber.Eth);
25
+ const price = yield contract.methods.latestAnswer().call();
26
+ return new Dec(price).div(1e8).toString();
27
+ });
@@ -0,0 +1,135 @@
1
+ /// <reference types="node" />
2
+ import type BN from "bn.js";
3
+ import type { ContractOptions } from "web3-eth-contract";
4
+ import type { EventLog } from "web3-core";
5
+ import type { EventEmitter } from "events";
6
+ import type { Callback, NonPayableTransactionObject, BlockType, ContractEventLog, BaseContract } from "./types";
7
+ export interface EventOptions {
8
+ filter?: object;
9
+ fromBlock?: BlockType;
10
+ topics?: string[];
11
+ }
12
+ export type AnswerUpdated = ContractEventLog<{
13
+ current: string;
14
+ roundId: string;
15
+ updatedAt: string;
16
+ 0: string;
17
+ 1: string;
18
+ 2: string;
19
+ }>;
20
+ export type NewRound = ContractEventLog<{
21
+ roundId: string;
22
+ startedBy: string;
23
+ startedAt: string;
24
+ 0: string;
25
+ 1: string;
26
+ 2: string;
27
+ }>;
28
+ export type OwnershipTransferRequested = ContractEventLog<{
29
+ from: string;
30
+ to: string;
31
+ 0: string;
32
+ 1: string;
33
+ }>;
34
+ export type OwnershipTransferred = ContractEventLog<{
35
+ from: string;
36
+ to: string;
37
+ 0: string;
38
+ 1: string;
39
+ }>;
40
+ export interface COMPPriceFeed extends BaseContract {
41
+ constructor(jsonInterface: any[], address?: string, options?: ContractOptions): COMPPriceFeed;
42
+ clone(): COMPPriceFeed;
43
+ methods: {
44
+ acceptOwnership(): NonPayableTransactionObject<void>;
45
+ accessController(): NonPayableTransactionObject<string>;
46
+ aggregator(): NonPayableTransactionObject<string>;
47
+ confirmAggregator(_aggregator: string): NonPayableTransactionObject<void>;
48
+ decimals(): NonPayableTransactionObject<string>;
49
+ description(): NonPayableTransactionObject<string>;
50
+ getAnswer(_roundId: number | string | BN): NonPayableTransactionObject<string>;
51
+ getRoundData(_roundId: number | string | BN): NonPayableTransactionObject<[
52
+ string,
53
+ string,
54
+ string,
55
+ string,
56
+ string
57
+ ] & {
58
+ roundId: string;
59
+ answer: string;
60
+ startedAt: string;
61
+ updatedAt: string;
62
+ answeredInRound: string;
63
+ }>;
64
+ getTimestamp(_roundId: number | string | BN): NonPayableTransactionObject<string>;
65
+ latestAnswer(): NonPayableTransactionObject<string>;
66
+ latestRound(): NonPayableTransactionObject<string>;
67
+ latestRoundData(): NonPayableTransactionObject<[
68
+ string,
69
+ string,
70
+ string,
71
+ string,
72
+ string
73
+ ] & {
74
+ roundId: string;
75
+ answer: string;
76
+ startedAt: string;
77
+ updatedAt: string;
78
+ answeredInRound: string;
79
+ }>;
80
+ latestTimestamp(): NonPayableTransactionObject<string>;
81
+ owner(): NonPayableTransactionObject<string>;
82
+ phaseAggregators(arg0: number | string | BN): NonPayableTransactionObject<string>;
83
+ phaseId(): NonPayableTransactionObject<string>;
84
+ proposeAggregator(_aggregator: string): NonPayableTransactionObject<void>;
85
+ proposedAggregator(): NonPayableTransactionObject<string>;
86
+ proposedGetRoundData(_roundId: number | string | BN): NonPayableTransactionObject<[
87
+ string,
88
+ string,
89
+ string,
90
+ string,
91
+ string
92
+ ] & {
93
+ roundId: string;
94
+ answer: string;
95
+ startedAt: string;
96
+ updatedAt: string;
97
+ answeredInRound: string;
98
+ }>;
99
+ proposedLatestRoundData(): NonPayableTransactionObject<[
100
+ string,
101
+ string,
102
+ string,
103
+ string,
104
+ string
105
+ ] & {
106
+ roundId: string;
107
+ answer: string;
108
+ startedAt: string;
109
+ updatedAt: string;
110
+ answeredInRound: string;
111
+ }>;
112
+ setController(_accessController: string): NonPayableTransactionObject<void>;
113
+ transferOwnership(_to: string): NonPayableTransactionObject<void>;
114
+ version(): NonPayableTransactionObject<string>;
115
+ };
116
+ events: {
117
+ AnswerUpdated(cb?: Callback<AnswerUpdated>): EventEmitter;
118
+ AnswerUpdated(options?: EventOptions, cb?: Callback<AnswerUpdated>): EventEmitter;
119
+ NewRound(cb?: Callback<NewRound>): EventEmitter;
120
+ NewRound(options?: EventOptions, cb?: Callback<NewRound>): EventEmitter;
121
+ OwnershipTransferRequested(cb?: Callback<OwnershipTransferRequested>): EventEmitter;
122
+ OwnershipTransferRequested(options?: EventOptions, cb?: Callback<OwnershipTransferRequested>): EventEmitter;
123
+ OwnershipTransferred(cb?: Callback<OwnershipTransferred>): EventEmitter;
124
+ OwnershipTransferred(options?: EventOptions, cb?: Callback<OwnershipTransferred>): EventEmitter;
125
+ allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
126
+ };
127
+ once(event: "AnswerUpdated", cb: Callback<AnswerUpdated>): void;
128
+ once(event: "AnswerUpdated", options: EventOptions, cb: Callback<AnswerUpdated>): void;
129
+ once(event: "NewRound", cb: Callback<NewRound>): void;
130
+ once(event: "NewRound", options: EventOptions, cb: Callback<NewRound>): void;
131
+ once(event: "OwnershipTransferRequested", cb: Callback<OwnershipTransferRequested>): void;
132
+ once(event: "OwnershipTransferRequested", options: EventOptions, cb: Callback<OwnershipTransferRequested>): void;
133
+ once(event: "OwnershipTransferred", cb: Callback<OwnershipTransferred>): void;
134
+ once(event: "OwnershipTransferred", options: EventOptions, cb: Callback<OwnershipTransferred>): void;
135
+ }
@@ -0,0 +1,4 @@
1
+ /* Autogenerated file. Do not edit manually. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ export {};
@@ -0,0 +1,135 @@
1
+ /// <reference types="node" />
2
+ import type BN from "bn.js";
3
+ import type { ContractOptions } from "web3-eth-contract";
4
+ import type { EventLog } from "web3-core";
5
+ import type { EventEmitter } from "events";
6
+ import type { Callback, NonPayableTransactionObject, BlockType, ContractEventLog, BaseContract } from "./types";
7
+ export interface EventOptions {
8
+ filter?: object;
9
+ fromBlock?: BlockType;
10
+ topics?: string[];
11
+ }
12
+ export type AnswerUpdated = ContractEventLog<{
13
+ current: string;
14
+ roundId: string;
15
+ updatedAt: string;
16
+ 0: string;
17
+ 1: string;
18
+ 2: string;
19
+ }>;
20
+ export type NewRound = ContractEventLog<{
21
+ roundId: string;
22
+ startedBy: string;
23
+ startedAt: string;
24
+ 0: string;
25
+ 1: string;
26
+ 2: string;
27
+ }>;
28
+ export type OwnershipTransferRequested = ContractEventLog<{
29
+ from: string;
30
+ to: string;
31
+ 0: string;
32
+ 1: string;
33
+ }>;
34
+ export type OwnershipTransferred = ContractEventLog<{
35
+ from: string;
36
+ to: string;
37
+ 0: string;
38
+ 1: string;
39
+ }>;
40
+ export interface ETHPriceFeed extends BaseContract {
41
+ constructor(jsonInterface: any[], address?: string, options?: ContractOptions): ETHPriceFeed;
42
+ clone(): ETHPriceFeed;
43
+ methods: {
44
+ acceptOwnership(): NonPayableTransactionObject<void>;
45
+ accessController(): NonPayableTransactionObject<string>;
46
+ aggregator(): NonPayableTransactionObject<string>;
47
+ confirmAggregator(_aggregator: string): NonPayableTransactionObject<void>;
48
+ decimals(): NonPayableTransactionObject<string>;
49
+ description(): NonPayableTransactionObject<string>;
50
+ getAnswer(_roundId: number | string | BN): NonPayableTransactionObject<string>;
51
+ getRoundData(_roundId: number | string | BN): NonPayableTransactionObject<[
52
+ string,
53
+ string,
54
+ string,
55
+ string,
56
+ string
57
+ ] & {
58
+ roundId: string;
59
+ answer: string;
60
+ startedAt: string;
61
+ updatedAt: string;
62
+ answeredInRound: string;
63
+ }>;
64
+ getTimestamp(_roundId: number | string | BN): NonPayableTransactionObject<string>;
65
+ latestAnswer(): NonPayableTransactionObject<string>;
66
+ latestRound(): NonPayableTransactionObject<string>;
67
+ latestRoundData(): NonPayableTransactionObject<[
68
+ string,
69
+ string,
70
+ string,
71
+ string,
72
+ string
73
+ ] & {
74
+ roundId: string;
75
+ answer: string;
76
+ startedAt: string;
77
+ updatedAt: string;
78
+ answeredInRound: string;
79
+ }>;
80
+ latestTimestamp(): NonPayableTransactionObject<string>;
81
+ owner(): NonPayableTransactionObject<string>;
82
+ phaseAggregators(arg0: number | string | BN): NonPayableTransactionObject<string>;
83
+ phaseId(): NonPayableTransactionObject<string>;
84
+ proposeAggregator(_aggregator: string): NonPayableTransactionObject<void>;
85
+ proposedAggregator(): NonPayableTransactionObject<string>;
86
+ proposedGetRoundData(_roundId: number | string | BN): NonPayableTransactionObject<[
87
+ string,
88
+ string,
89
+ string,
90
+ string,
91
+ string
92
+ ] & {
93
+ roundId: string;
94
+ answer: string;
95
+ startedAt: string;
96
+ updatedAt: string;
97
+ answeredInRound: string;
98
+ }>;
99
+ proposedLatestRoundData(): NonPayableTransactionObject<[
100
+ string,
101
+ string,
102
+ string,
103
+ string,
104
+ string
105
+ ] & {
106
+ roundId: string;
107
+ answer: string;
108
+ startedAt: string;
109
+ updatedAt: string;
110
+ answeredInRound: string;
111
+ }>;
112
+ setController(_accessController: string): NonPayableTransactionObject<void>;
113
+ transferOwnership(_to: string): NonPayableTransactionObject<void>;
114
+ version(): NonPayableTransactionObject<string>;
115
+ };
116
+ events: {
117
+ AnswerUpdated(cb?: Callback<AnswerUpdated>): EventEmitter;
118
+ AnswerUpdated(options?: EventOptions, cb?: Callback<AnswerUpdated>): EventEmitter;
119
+ NewRound(cb?: Callback<NewRound>): EventEmitter;
120
+ NewRound(options?: EventOptions, cb?: Callback<NewRound>): EventEmitter;
121
+ OwnershipTransferRequested(cb?: Callback<OwnershipTransferRequested>): EventEmitter;
122
+ OwnershipTransferRequested(options?: EventOptions, cb?: Callback<OwnershipTransferRequested>): EventEmitter;
123
+ OwnershipTransferred(cb?: Callback<OwnershipTransferred>): EventEmitter;
124
+ OwnershipTransferred(options?: EventOptions, cb?: Callback<OwnershipTransferred>): EventEmitter;
125
+ allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
126
+ };
127
+ once(event: "AnswerUpdated", cb: Callback<AnswerUpdated>): void;
128
+ once(event: "AnswerUpdated", options: EventOptions, cb: Callback<AnswerUpdated>): void;
129
+ once(event: "NewRound", cb: Callback<NewRound>): void;
130
+ once(event: "NewRound", options: EventOptions, cb: Callback<NewRound>): void;
131
+ once(event: "OwnershipTransferRequested", cb: Callback<OwnershipTransferRequested>): void;
132
+ once(event: "OwnershipTransferRequested", options: EventOptions, cb: Callback<OwnershipTransferRequested>): void;
133
+ once(event: "OwnershipTransferred", cb: Callback<OwnershipTransferred>): void;
134
+ once(event: "OwnershipTransferred", options: EventOptions, cb: Callback<OwnershipTransferred>): void;
135
+ }
@@ -0,0 +1,4 @@
1
+ /* Autogenerated file. Do not edit manually. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ export {};
@@ -0,0 +1,135 @@
1
+ /// <reference types="node" />
2
+ import type BN from "bn.js";
3
+ import type { ContractOptions } from "web3-eth-contract";
4
+ import type { EventLog } from "web3-core";
5
+ import type { EventEmitter } from "events";
6
+ import type { Callback, NonPayableTransactionObject, BlockType, ContractEventLog, BaseContract } from "./types";
7
+ export interface EventOptions {
8
+ filter?: object;
9
+ fromBlock?: BlockType;
10
+ topics?: string[];
11
+ }
12
+ export type AnswerUpdated = ContractEventLog<{
13
+ current: string;
14
+ roundId: string;
15
+ updatedAt: string;
16
+ 0: string;
17
+ 1: string;
18
+ 2: string;
19
+ }>;
20
+ export type NewRound = ContractEventLog<{
21
+ roundId: string;
22
+ startedBy: string;
23
+ startedAt: string;
24
+ 0: string;
25
+ 1: string;
26
+ 2: string;
27
+ }>;
28
+ export type OwnershipTransferRequested = ContractEventLog<{
29
+ from: string;
30
+ to: string;
31
+ 0: string;
32
+ 1: string;
33
+ }>;
34
+ export type OwnershipTransferred = ContractEventLog<{
35
+ from: string;
36
+ to: string;
37
+ 0: string;
38
+ 1: string;
39
+ }>;
40
+ export interface USDCPriceFeed extends BaseContract {
41
+ constructor(jsonInterface: any[], address?: string, options?: ContractOptions): USDCPriceFeed;
42
+ clone(): USDCPriceFeed;
43
+ methods: {
44
+ acceptOwnership(): NonPayableTransactionObject<void>;
45
+ accessController(): NonPayableTransactionObject<string>;
46
+ aggregator(): NonPayableTransactionObject<string>;
47
+ confirmAggregator(_aggregator: string): NonPayableTransactionObject<void>;
48
+ decimals(): NonPayableTransactionObject<string>;
49
+ description(): NonPayableTransactionObject<string>;
50
+ getAnswer(_roundId: number | string | BN): NonPayableTransactionObject<string>;
51
+ getRoundData(_roundId: number | string | BN): NonPayableTransactionObject<[
52
+ string,
53
+ string,
54
+ string,
55
+ string,
56
+ string
57
+ ] & {
58
+ roundId: string;
59
+ answer: string;
60
+ startedAt: string;
61
+ updatedAt: string;
62
+ answeredInRound: string;
63
+ }>;
64
+ getTimestamp(_roundId: number | string | BN): NonPayableTransactionObject<string>;
65
+ latestAnswer(): NonPayableTransactionObject<string>;
66
+ latestRound(): NonPayableTransactionObject<string>;
67
+ latestRoundData(): NonPayableTransactionObject<[
68
+ string,
69
+ string,
70
+ string,
71
+ string,
72
+ string
73
+ ] & {
74
+ roundId: string;
75
+ answer: string;
76
+ startedAt: string;
77
+ updatedAt: string;
78
+ answeredInRound: string;
79
+ }>;
80
+ latestTimestamp(): NonPayableTransactionObject<string>;
81
+ owner(): NonPayableTransactionObject<string>;
82
+ phaseAggregators(arg0: number | string | BN): NonPayableTransactionObject<string>;
83
+ phaseId(): NonPayableTransactionObject<string>;
84
+ proposeAggregator(_aggregator: string): NonPayableTransactionObject<void>;
85
+ proposedAggregator(): NonPayableTransactionObject<string>;
86
+ proposedGetRoundData(_roundId: number | string | BN): NonPayableTransactionObject<[
87
+ string,
88
+ string,
89
+ string,
90
+ string,
91
+ string
92
+ ] & {
93
+ roundId: string;
94
+ answer: string;
95
+ startedAt: string;
96
+ updatedAt: string;
97
+ answeredInRound: string;
98
+ }>;
99
+ proposedLatestRoundData(): NonPayableTransactionObject<[
100
+ string,
101
+ string,
102
+ string,
103
+ string,
104
+ string
105
+ ] & {
106
+ roundId: string;
107
+ answer: string;
108
+ startedAt: string;
109
+ updatedAt: string;
110
+ answeredInRound: string;
111
+ }>;
112
+ setController(_accessController: string): NonPayableTransactionObject<void>;
113
+ transferOwnership(_to: string): NonPayableTransactionObject<void>;
114
+ version(): NonPayableTransactionObject<string>;
115
+ };
116
+ events: {
117
+ AnswerUpdated(cb?: Callback<AnswerUpdated>): EventEmitter;
118
+ AnswerUpdated(options?: EventOptions, cb?: Callback<AnswerUpdated>): EventEmitter;
119
+ NewRound(cb?: Callback<NewRound>): EventEmitter;
120
+ NewRound(options?: EventOptions, cb?: Callback<NewRound>): EventEmitter;
121
+ OwnershipTransferRequested(cb?: Callback<OwnershipTransferRequested>): EventEmitter;
122
+ OwnershipTransferRequested(options?: EventOptions, cb?: Callback<OwnershipTransferRequested>): EventEmitter;
123
+ OwnershipTransferred(cb?: Callback<OwnershipTransferred>): EventEmitter;
124
+ OwnershipTransferred(options?: EventOptions, cb?: Callback<OwnershipTransferred>): EventEmitter;
125
+ allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
126
+ };
127
+ once(event: "AnswerUpdated", cb: Callback<AnswerUpdated>): void;
128
+ once(event: "AnswerUpdated", options: EventOptions, cb: Callback<AnswerUpdated>): void;
129
+ once(event: "NewRound", cb: Callback<NewRound>): void;
130
+ once(event: "NewRound", options: EventOptions, cb: Callback<NewRound>): void;
131
+ once(event: "OwnershipTransferRequested", cb: Callback<OwnershipTransferRequested>): void;
132
+ once(event: "OwnershipTransferRequested", options: EventOptions, cb: Callback<OwnershipTransferRequested>): void;
133
+ once(event: "OwnershipTransferred", cb: Callback<OwnershipTransferred>): void;
134
+ once(event: "OwnershipTransferred", options: EventOptions, cb: Callback<OwnershipTransferred>): void;
135
+ }
@@ -0,0 +1,4 @@
1
+ /* Autogenerated file. Do not edit manually. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ export {};
@@ -7,6 +7,7 @@ export type { AaveV3PoolAddressesProvider } from "./AaveV3PoolAddressesProvider"
7
7
  export type { AaveV3ProtocolDataProvider } from "./AaveV3ProtocolDataProvider";
8
8
  export type { AaveV3View } from "./AaveV3View";
9
9
  export type { BalanceScanner } from "./BalanceScanner";
10
+ export type { COMPPriceFeed } from "./COMPPriceFeed";
10
11
  export type { CbEth } from "./CbEth";
11
12
  export type { ChickenBondsManager } from "./ChickenBondsManager";
12
13
  export type { ChickenBondsView } from "./ChickenBondsView";
@@ -17,6 +18,7 @@ export type { CompV3USDbCBulker } from "./CompV3USDbCBulker";
17
18
  export type { CompV3View } from "./CompV3View";
18
19
  export type { CompoundLoanInfo } from "./CompoundLoanInfo";
19
20
  export type { Comptroller } from "./Comptroller";
21
+ export type { ETHPriceFeed } from "./ETHPriceFeed";
20
22
  export type { Erc20 } from "./Erc20";
21
23
  export type { GHO } from "./GHO";
22
24
  export type { GhoDiscountRateStrategy } from "./GhoDiscountRateStrategy";
@@ -43,6 +45,7 @@ export type { SparkPoolAddressesProvider } from "./SparkPoolAddressesProvider";
43
45
  export type { SparkProtocolDataProvider } from "./SparkProtocolDataProvider";
44
46
  export type { SparkView } from "./SparkView";
45
47
  export type { TroveManager } from "./TroveManager";
48
+ export type { USDCPriceFeed } from "./USDCPriceFeed";
46
49
  export type { UniMulticall } from "./UniMulticall";
47
50
  export type { CETHv3 } from "./CETHv3";
48
51
  export type { CUSDCv3 } from "./CUSDCv3";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/positions-sdk",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -15,8 +15,10 @@ import {
15
15
  import { EMPTY_AAVE_DATA } from '../aaveV3';
16
16
  import { AAVE_V2 } from '../markets/aave';
17
17
  import { aaveAnyGetAggregatedPositionData } from '../helpers/aaveHelpers';
18
+ import { getEthPrice } from '../services/priceService';
18
19
 
19
- export const getAaveV2MarketsData = async (web3: Web3, network: NetworkNumber, selectedMarket: AaveMarketInfo, ethPrice: string, mainnetWeb3: Web3) => {
20
+ export const getAaveV2MarketsData = async (web3: Web3, network: NetworkNumber, selectedMarket: AaveMarketInfo, mainnetWeb3: Web3) => {
21
+ const ethPrice = await getEthPrice(mainnetWeb3);
20
22
  const _addresses = selectedMarket.assets.map(a => getAssetInfo(ethToWeth(a)).address);
21
23
  const loanInfoContract = AaveLoanInfoV2Contract(web3, network);
22
24
  const marketAddress = selectedMarket.providerAddress;
@@ -212,8 +214,8 @@ export const getAaveV2AccountData = async (web3: Web3, network: NetworkNumber, a
212
214
  return payload;
213
215
  };
214
216
 
215
- export const getAaveV2FullPositionData = async (web3: Web3, network: NetworkNumber, address: string, market: AaveMarketInfo, ethPrice: string, mainnetWeb3: Web3): Promise<AaveV2PositionData> => {
216
- const marketData = await getAaveV2MarketsData(web3, network, market, ethPrice, mainnetWeb3);
217
+ export const getAaveV2FullPositionData = async (web3: Web3, network: NetworkNumber, address: string, market: AaveMarketInfo, mainnetWeb3: Web3): Promise<AaveV2PositionData> => {
218
+ const marketData = await getAaveV2MarketsData(web3, network, market, mainnetWeb3);
217
219
  const positionData = await getAaveV2AccountData(web3, network, address, marketData.assetsData, market);
218
220
  return positionData;
219
221
  };
@@ -21,8 +21,11 @@ import {
21
21
  formatBaseData, formatMarketData, getCompoundV3AggregatedData, getIncentiveApys,
22
22
  } from '../helpers/compoundHelpers';
23
23
  import { COMPOUND_V3_ETH, COMPOUND_V3_USDBC, COMPOUND_V3_USDC } from '../markets/compound';
24
+ import { getEthPrice, getCompPrice, getUSDCPrice } from '../services/priceService';
24
25
 
25
- export const getCompoundV3MarketsData = async (web3: Web3, network: NetworkNumber, selectedMarket: CompoundMarketData, compPrice: string, defaultWeb3: Web3): Promise<CompoundV3MarketsData> => {
26
+ export const getCompoundV3MarketsData = async (web3: Web3, network: NetworkNumber, selectedMarket: CompoundMarketData, defaultWeb3: Web3): Promise<CompoundV3MarketsData> => {
27
+ const baseAssetPrice = selectedMarket.baseAsset === 'ETH' ? await getEthPrice(defaultWeb3) : await getUSDCPrice(defaultWeb3);
28
+ const compPrice = await getCompPrice(defaultWeb3);
26
29
  const contract = CompV3ViewContract(web3, network);
27
30
  const CompV3ViewAddress = contract.options.address;
28
31
  const calls = [
@@ -38,7 +41,7 @@ export const getCompoundV3MarketsData = async (web3: Web3, network: NetworkNumbe
38
41
  },
39
42
  ];
40
43
  const data = await multicall(calls, web3, network);
41
- const colls = data[1].colls.map((coll: any) => formatMarketData(coll, network)) as CompoundV3AssetData[];
44
+ const colls = data[1].colls.map((coll: any) => formatMarketData(coll, network, baseAssetPrice)) as CompoundV3AssetData[];
42
45
  if (selectedMarket.value === CompoundVersions.CompoundV3ETH) {
43
46
  for (const coll of colls) {
44
47
  if (coll.symbol === 'wstETH') {
@@ -65,7 +68,7 @@ export const getCompoundV3MarketsData = async (web3: Web3, network: NetworkNumbe
65
68
  }
66
69
  }
67
70
  }
68
- const base = formatBaseData(data[0].baseToken, network);
71
+ const base = formatBaseData(data[0].baseToken, network, baseAssetPrice);
69
72
 
70
73
  const payload: CompoundV3AssetsData = {};
71
74
 
@@ -252,8 +255,8 @@ export const getCompoundV3AccountData = async (
252
255
  return payload;
253
256
  };
254
257
 
255
- export const getCompoundV3FullPositionData = async (web3: Web3, network: NetworkNumber, address: string, proxyAddress: string, selectedMarket: CompoundMarketData, compPrice: string, mainnetWeb3: Web3): Promise<CompoundV3PositionData> => {
256
- const marketData = await getCompoundV3MarketsData(web3, network, selectedMarket, compPrice, mainnetWeb3);
258
+ export const getCompoundV3FullPositionData = async (web3: Web3, network: NetworkNumber, address: string, proxyAddress: string, selectedMarket: CompoundMarketData, mainnetWeb3: Web3): Promise<CompoundV3PositionData> => {
259
+ const marketData = await getCompoundV3MarketsData(web3, network, selectedMarket, mainnetWeb3);
257
260
  const positionData = await getCompoundV3AccountData(web3, network, address, proxyAddress, { selectedMarket, assetsData: marketData.assetsData });
258
261
  return positionData;
259
262
  };