@evaafi/sdk 0.7.0 → 0.9.0-a
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/api/feeds.d.ts +31 -0
- package/dist/api/feeds.js +73 -0
- package/dist/api/liquidation.js +1 -1
- package/dist/api/math.js +1 -1
- package/dist/api/parser.d.ts +4 -2
- package/dist/api/parser.js +39 -18
- package/dist/api/parsers/AbstractOracleParser.d.ts +11 -0
- package/dist/api/parsers/AbstractOracleParser.js +9 -0
- package/dist/api/parsers/ClassicOracleParser.d.ts +10 -0
- package/dist/api/parsers/ClassicOracleParser.js +16 -0
- package/dist/api/parsers/PythOracleParser.d.ts +18 -0
- package/dist/api/parsers/PythOracleParser.js +22 -0
- package/dist/api/parsers/index.d.ts +3 -0
- package/dist/api/parsers/index.js +19 -0
- package/dist/api/prices.d.ts +7 -6
- package/dist/api/prices.js +37 -46
- package/dist/constants/assets/assetId.d.ts +22 -0
- package/dist/constants/assets/assetId.js +29 -0
- package/dist/constants/assets/index.d.ts +3 -0
- package/dist/constants/assets/index.js +19 -0
- package/dist/constants/{assets.d.ts → assets/mainnet.d.ts} +1 -30
- package/dist/constants/{assets.js → assets/mainnet.js} +20 -82
- package/dist/constants/assets/testnet.d.ts +14 -0
- package/dist/constants/assets/testnet.js +54 -0
- package/dist/constants/general/index.d.ts +65 -0
- package/dist/constants/general/index.js +93 -0
- package/dist/constants/general/mainnet.d.ts +24 -0
- package/dist/constants/{general.js → general/mainnet.js} +38 -60
- package/dist/constants/general/testnet.d.ts +12 -0
- package/dist/constants/general/testnet.js +15 -0
- package/dist/constants/index.d.ts +3 -0
- package/dist/constants/index.js +19 -0
- package/dist/constants/pools/index.d.ts +2 -0
- package/dist/constants/pools/index.js +18 -0
- package/dist/constants/pools/mainnet.d.ts +14 -0
- package/dist/constants/pools/mainnet.js +145 -0
- package/dist/constants/pools/testnet.d.ts +9 -0
- package/dist/constants/pools/testnet.js +57 -0
- package/dist/contracts/AbstractMaster.d.ts +185 -0
- package/dist/contracts/AbstractMaster.js +179 -0
- package/dist/contracts/ClassicMaster.d.ts +34 -0
- package/dist/contracts/ClassicMaster.js +87 -0
- package/dist/contracts/PythMaster.d.ts +62 -0
- package/dist/contracts/PythMaster.js +179 -0
- package/dist/contracts/UserContract.d.ts +1 -7
- package/dist/contracts/UserContract.js +1 -19
- package/dist/contracts/index.d.ts +5 -0
- package/dist/contracts/index.js +21 -0
- package/dist/index.d.ts +14 -14
- package/dist/index.js +20 -60
- package/dist/prices/Oracle.interface.d.ts +9 -0
- package/dist/prices/Oracle.interface.js +2 -0
- package/dist/prices/Prices.d.ts +5 -3
- package/dist/prices/Prices.js +13 -3
- package/dist/prices/PricesCollector.d.ts +17 -7
- package/dist/prices/PricesCollector.js +67 -51
- package/dist/prices/PythCollector.d.ts +22 -0
- package/dist/prices/PythCollector.js +217 -0
- package/dist/prices/Types.d.ts +18 -1
- package/dist/prices/Types.js +8 -1
- package/dist/prices/index.d.ts +4 -3
- package/dist/prices/index.js +4 -3
- package/dist/prices/sources/Backend.d.ts +5 -4
- package/dist/prices/sources/Backend.js +16 -13
- package/dist/prices/sources/Icp.d.ts +2 -1
- package/dist/prices/sources/Icp.js +12 -9
- package/dist/prices/sources/PriceSource.d.ts +7 -6
- package/dist/prices/utils.d.ts +11 -8
- package/dist/prices/utils.js +32 -46
- package/dist/rewards/RewardMaster.d.ts +1 -0
- package/dist/rewards/RewardUser.d.ts +1 -0
- package/dist/types/Master.d.ts +11 -30
- package/dist/types/Master.js +3 -0
- package/dist/types/MasterRewards.d.ts +1 -0
- package/dist/types/UserRewards.d.ts +1 -0
- package/dist/utils/sha256BigInt.d.ts +1 -0
- package/dist/utils/userJettonWallet.js +0 -8
- package/dist/utils/utils.d.ts +8 -1
- package/dist/utils/utils.js +31 -2
- package/package.json +3 -2
- package/src/api/feeds.ts +90 -0
- package/src/api/liquidation.ts +1 -1
- package/src/api/math.ts +1 -1
- package/src/api/parser.ts +100 -38
- package/src/api/parsers/AbstractOracleParser.ts +16 -0
- package/src/api/parsers/ClassicOracleParser.ts +20 -0
- package/src/api/parsers/PythOracleParser.ts +34 -0
- package/src/api/parsers/index.ts +3 -0
- package/src/api/prices.ts +32 -41
- package/src/constants/assets/assetId.ts +30 -0
- package/src/constants/assets/index.ts +3 -0
- package/src/constants/{assets.ts → assets/mainnet.ts} +3 -96
- package/src/constants/assets/testnet.ts +74 -0
- package/src/constants/general/index.ts +91 -0
- package/src/constants/{general.ts → general/mainnet.ts} +48 -72
- package/src/constants/general/testnet.ts +25 -0
- package/src/constants/index.ts +3 -0
- package/src/constants/pools/index.ts +2 -0
- package/src/constants/pools/mainnet.ts +218 -0
- package/src/constants/pools/testnet.ts +75 -0
- package/src/contracts/AbstractMaster.ts +450 -0
- package/src/contracts/ClassicMaster.ts +149 -0
- package/src/contracts/PythMaster.ts +313 -0
- package/src/contracts/UserContract.ts +7 -28
- package/src/contracts/index.ts +7 -0
- package/src/index.ts +18 -85
- package/src/prices/Oracle.interface.ts +18 -0
- package/src/prices/Prices.ts +17 -4
- package/src/prices/PricesCollector.ts +91 -68
- package/src/prices/PythCollector.ts +294 -0
- package/src/prices/Types.ts +28 -6
- package/src/prices/index.ts +4 -3
- package/src/prices/sources/Backend.ts +21 -19
- package/src/prices/sources/Icp.ts +13 -10
- package/src/prices/sources/PriceSource.ts +6 -5
- package/src/prices/utils.ts +65 -68
- package/src/types/Master.ts +29 -52
- package/src/types/User.ts +15 -7
- package/src/utils/userJettonWallet.ts +0 -8
- package/src/utils/utils.ts +41 -2
- package/dist/constants/general.d.ts +0 -67
- package/dist/constants/pools.d.ts +0 -13
- package/dist/constants/pools.js +0 -120
- package/dist/contracts/MasterContract.d.ts +0 -156
- package/dist/contracts/MasterContract.js +0 -260
- package/src/constants/pools.ts +0 -177
- package/src/contracts/MasterContract.ts +0 -410
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
1
|
+
export * from './api/math';
|
|
2
|
+
export * from './api/liquidation';
|
|
3
|
+
export * from './api/parser';
|
|
4
|
+
export * from './api/parsers';
|
|
5
|
+
export * from './api/prices';
|
|
6
|
+
export * from './api/feeds';
|
|
7
|
+
export * from './contracts';
|
|
8
|
+
export { EvaaUserRewards } from './rewards/EvaaRewards';
|
|
9
|
+
export { JettonMinter as RewardJettonMinter, type JettonMinterConfig, type MintMessage } from './rewards/JettonMinter';
|
|
10
|
+
export { JettonWallet as RewardJettonWallet, type JettonWalletConfig } from './rewards/JettonWallet';
|
|
8
11
|
export { RewardMaster } from './rewards/RewardMaster';
|
|
9
|
-
export { type EvaaRewardsConfig } from './types/MasterRewards';
|
|
10
12
|
export { RewardUser } from './rewards/RewardUser';
|
|
13
|
+
export { type EvaaRewardsConfig } from './types/MasterRewards';
|
|
11
14
|
export { type EvaaUserRewardsConfig } from './types/UserRewards';
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export { EvaaUserRewards } from './rewards/EvaaRewards';
|
|
15
|
-
export { UpgradeConfig, AssetConfig, MasterConfig, AssetData, AssetInterest, AssetApy, ExtendedAssetData, MasterData, PoolConfig, ExtendedAssetsData, ExtendedAssetsConfig, PoolAssetConfig, PoolAssetsConfig, MasterConstants } from './types/Master';
|
|
16
|
-
export { BalanceType, UserBalance, UserLiqudationData, LiquidableData, NonLiquidableData, LiquidationData, UserDataInactive, UserDataActive, UserData, BalanceChangeType } from './types/User';
|
|
15
|
+
export * from './types/Master';
|
|
16
|
+
export * from './types/User';
|
|
17
17
|
export * from './constants/general';
|
|
18
18
|
export * from './constants/pools';
|
|
19
19
|
export * from './constants/assets';
|
|
20
|
-
export * from './utils/utils';
|
|
21
20
|
export * from './prices';
|
|
21
|
+
export * from './utils/utils';
|
|
22
22
|
export { getLastSentBoc, getTonConnectSender } from './utils/tonConnectSender';
|
|
23
23
|
export { getUserJettonWallet } from './utils/userJettonWallet';
|
package/dist/index.js
CHANGED
|
@@ -14,80 +14,40 @@ 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.
|
|
18
|
-
exports.getUserJettonWallet = void 0;
|
|
17
|
+
exports.getUserJettonWallet = exports.getTonConnectSender = exports.getLastSentBoc = exports.RewardUser = exports.RewardMaster = exports.RewardJettonWallet = exports.RewardJettonMinter = exports.EvaaUserRewards = void 0;
|
|
19
18
|
// Math
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
Object.defineProperty(exports, "mulDiv", { enumerable: true, get: function () { return math_1.mulDiv; } });
|
|
23
|
-
Object.defineProperty(exports, "bigIntMin", { enumerable: true, get: function () { return math_1.bigIntMin; } });
|
|
24
|
-
Object.defineProperty(exports, "bigIntMax", { enumerable: true, get: function () { return math_1.bigIntMax; } });
|
|
25
|
-
Object.defineProperty(exports, "calculatePresentValue", { enumerable: true, get: function () { return math_1.calculatePresentValue; } });
|
|
26
|
-
Object.defineProperty(exports, "calculateCurrentRates", { enumerable: true, get: function () { return math_1.calculateCurrentRates; } });
|
|
27
|
-
Object.defineProperty(exports, "calculateAssetData", { enumerable: true, get: function () { return math_1.calculateAssetData; } });
|
|
28
|
-
Object.defineProperty(exports, "calculateAssetInterest", { enumerable: true, get: function () { return math_1.calculateAssetInterest; } });
|
|
29
|
-
Object.defineProperty(exports, "getAvailableToBorrow", { enumerable: true, get: function () { return math_1.getAvailableToBorrow; } });
|
|
30
|
-
Object.defineProperty(exports, "calculateMaximumWithdrawAmount", { enumerable: true, get: function () { return math_1.calculateMaximumWithdrawAmount; } });
|
|
31
|
-
Object.defineProperty(exports, "presentValue", { enumerable: true, get: function () { return math_1.presentValue; } });
|
|
32
|
-
Object.defineProperty(exports, "calculateLiquidationData", { enumerable: true, get: function () { return math_1.calculateLiquidationData; } });
|
|
33
|
-
Object.defineProperty(exports, "predictHealthFactor", { enumerable: true, get: function () { return math_1.predictHealthFactor; } });
|
|
34
|
-
Object.defineProperty(exports, "calculateHealthParams", { enumerable: true, get: function () { return math_1.calculateHealthParams; } });
|
|
35
|
-
Object.defineProperty(exports, "calculateInterestWithSupplyBorrow", { enumerable: true, get: function () { return math_1.calculateInterestWithSupplyBorrow; } });
|
|
36
|
-
Object.defineProperty(exports, "predictAPY", { enumerable: true, get: function () { return math_1.predictAPY; } });
|
|
37
|
-
Object.defineProperty(exports, "BigMath", { enumerable: true, get: function () { return math_1.BigMath; } });
|
|
38
|
-
Object.defineProperty(exports, "getAssetLiquidityMinusReserves", { enumerable: true, get: function () { return math_1.getAssetLiquidityMinusReserves; } });
|
|
39
|
-
var liquidation_1 = require("./api/liquidation");
|
|
40
|
-
Object.defineProperty(exports, "calculateLiquidationAmounts", { enumerable: true, get: function () { return liquidation_1.calculateLiquidationAmounts; } });
|
|
41
|
-
Object.defineProperty(exports, "calculateMinCollateralByTransferredAmount", { enumerable: true, get: function () { return liquidation_1.calculateMinCollateralByTransferredAmount; } });
|
|
42
|
-
Object.defineProperty(exports, "isLiquidatable", { enumerable: true, get: function () { return liquidation_1.isLiquidatable; } });
|
|
43
|
-
Object.defineProperty(exports, "isBadDebt", { enumerable: true, get: function () { return liquidation_1.isBadDebt; } });
|
|
44
|
-
Object.defineProperty(exports, "addReserve", { enumerable: true, get: function () { return liquidation_1.addReserve; } });
|
|
45
|
-
Object.defineProperty(exports, "deductReserve", { enumerable: true, get: function () { return liquidation_1.deductReserve; } });
|
|
46
|
-
Object.defineProperty(exports, "addLiquidationBonus", { enumerable: true, get: function () { return liquidation_1.addLiquidationBonus; } });
|
|
47
|
-
Object.defineProperty(exports, "deductLiquidationBonus", { enumerable: true, get: function () { return liquidation_1.deductLiquidationBonus; } });
|
|
48
|
-
Object.defineProperty(exports, "toAssetAmount", { enumerable: true, get: function () { return liquidation_1.toAssetAmount; } });
|
|
49
|
-
Object.defineProperty(exports, "toAssetWorth", { enumerable: true, get: function () { return liquidation_1.toAssetWorth; } });
|
|
50
|
-
Object.defineProperty(exports, "prepareAssetInfo", { enumerable: true, get: function () { return liquidation_1.prepareAssetInfo; } });
|
|
51
|
-
Object.defineProperty(exports, "findAssetById", { enumerable: true, get: function () { return liquidation_1.findAssetById; } });
|
|
52
|
-
Object.defineProperty(exports, "selectGreatestAssets", { enumerable: true, get: function () { return liquidation_1.selectGreatestAssets; } });
|
|
53
|
-
Object.defineProperty(exports, "calculateAssetsValues", { enumerable: true, get: function () { return liquidation_1.calculateAssetsValues; } });
|
|
19
|
+
__exportStar(require("./api/math"), exports);
|
|
20
|
+
__exportStar(require("./api/liquidation"), exports);
|
|
54
21
|
// Parser
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
Object.defineProperty(exports, "parseMasterData", { enumerable: true, get: function () { return parser_1.parseMasterData; } });
|
|
59
|
-
Object.defineProperty(exports, "parseUserData", { enumerable: true, get: function () { return parser_1.parseUserData; } });
|
|
60
|
-
Object.defineProperty(exports, "parseUserLiteData", { enumerable: true, get: function () { return parser_1.parseUserLiteData; } });
|
|
22
|
+
__exportStar(require("./api/parser"), exports);
|
|
23
|
+
// Oracles
|
|
24
|
+
__exportStar(require("./api/parsers"), exports);
|
|
61
25
|
// Prices
|
|
62
|
-
|
|
63
|
-
|
|
26
|
+
__exportStar(require("./api/prices"), exports);
|
|
27
|
+
// Feeds utils
|
|
28
|
+
__exportStar(require("./api/feeds"), exports);
|
|
64
29
|
// Contracts' wrappers
|
|
65
|
-
|
|
66
|
-
Object.defineProperty(exports, "JettonWallet", { enumerable: true, get: function () { return JettonWallet_1.JettonWallet; } });
|
|
67
|
-
var MasterContract_1 = require("./contracts/MasterContract");
|
|
68
|
-
Object.defineProperty(exports, "Evaa", { enumerable: true, get: function () { return MasterContract_1.Evaa; } });
|
|
69
|
-
var UserContract_1 = require("./contracts/UserContract");
|
|
70
|
-
Object.defineProperty(exports, "EvaaUser", { enumerable: true, get: function () { return UserContract_1.EvaaUser; } });
|
|
30
|
+
__exportStar(require("./contracts"), exports);
|
|
71
31
|
// Rewards contracts wrappers
|
|
32
|
+
var EvaaRewards_1 = require("./rewards/EvaaRewards");
|
|
33
|
+
Object.defineProperty(exports, "EvaaUserRewards", { enumerable: true, get: function () { return EvaaRewards_1.EvaaUserRewards; } });
|
|
34
|
+
var JettonMinter_1 = require("./rewards/JettonMinter");
|
|
35
|
+
Object.defineProperty(exports, "RewardJettonMinter", { enumerable: true, get: function () { return JettonMinter_1.JettonMinter; } });
|
|
36
|
+
var JettonWallet_1 = require("./rewards/JettonWallet");
|
|
37
|
+
Object.defineProperty(exports, "RewardJettonWallet", { enumerable: true, get: function () { return JettonWallet_1.JettonWallet; } });
|
|
72
38
|
var RewardMaster_1 = require("./rewards/RewardMaster");
|
|
73
39
|
Object.defineProperty(exports, "RewardMaster", { enumerable: true, get: function () { return RewardMaster_1.RewardMaster; } });
|
|
74
40
|
var RewardUser_1 = require("./rewards/RewardUser");
|
|
75
41
|
Object.defineProperty(exports, "RewardUser", { enumerable: true, get: function () { return RewardUser_1.RewardUser; } });
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
Object.defineProperty(exports, "RewardJettonWallet", { enumerable: true, get: function () { return JettonWallet_2.JettonWallet; } });
|
|
80
|
-
var EvaaRewards_1 = require("./rewards/EvaaRewards");
|
|
81
|
-
Object.defineProperty(exports, "EvaaUserRewards", { enumerable: true, get: function () { return EvaaRewards_1.EvaaUserRewards; } });
|
|
82
|
-
var User_1 = require("./types/User");
|
|
83
|
-
Object.defineProperty(exports, "BalanceType", { enumerable: true, get: function () { return User_1.BalanceType; } });
|
|
84
|
-
Object.defineProperty(exports, "BalanceChangeType", { enumerable: true, get: function () { return User_1.BalanceChangeType; } });
|
|
42
|
+
// Types
|
|
43
|
+
__exportStar(require("./types/Master"), exports);
|
|
44
|
+
__exportStar(require("./types/User"), exports);
|
|
85
45
|
// Constants
|
|
86
46
|
__exportStar(require("./constants/general"), exports);
|
|
87
47
|
__exportStar(require("./constants/pools"), exports);
|
|
88
48
|
__exportStar(require("./constants/assets"), exports);
|
|
89
|
-
__exportStar(require("./utils/utils"), exports);
|
|
90
49
|
__exportStar(require("./prices"), exports);
|
|
50
|
+
__exportStar(require("./utils/utils"), exports);
|
|
91
51
|
// Utils
|
|
92
52
|
var tonConnectSender_1 = require("./utils/tonConnectSender");
|
|
93
53
|
Object.defineProperty(exports, "getLastSentBoc", { enumerable: true, get: function () { return tonConnectSender_1.getLastSentBoc; } });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Dictionary } from '@ton/core';
|
|
2
|
+
import { Prices } from '.';
|
|
3
|
+
import { PoolAssetConfig, PoolAssetsConfig } from '../types/Master';
|
|
4
|
+
import { FetchConfig } from '../utils/utils';
|
|
5
|
+
export interface Oracle {
|
|
6
|
+
getPricesForLiquidate(realPrincipals: Dictionary<bigint, bigint>, fetchConfig?: FetchConfig): Promise<Prices>;
|
|
7
|
+
getPricesForSupplyWithdraw(realPrincipals: Dictionary<bigint, bigint>, supplyAsset: PoolAssetConfig | undefined, withdrawAsset: PoolAssetConfig | undefined, collateralToDebt: boolean, fetchConfig?: FetchConfig): Promise<Prices>;
|
|
8
|
+
getPrices(assets: PoolAssetsConfig, fetchConfig?: FetchConfig): Promise<Prices>;
|
|
9
|
+
}
|
package/dist/prices/Prices.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { Cell, Dictionary } from
|
|
2
|
-
import { PoolAssetConfig } from
|
|
1
|
+
import { Cell, Dictionary } from '@ton/core';
|
|
2
|
+
import { PoolAssetConfig } from '../types/Master';
|
|
3
3
|
export declare class Prices {
|
|
4
4
|
#private;
|
|
5
|
-
constructor(dict: Dictionary<bigint, bigint>, dataCell: Cell);
|
|
5
|
+
constructor(dict: Dictionary<bigint, bigint>, dataCell: Cell, minPublishTime?: bigint, maxPublishTime?: bigint);
|
|
6
6
|
get dict(): Dictionary<bigint, bigint>;
|
|
7
7
|
get dataCell(): Cell;
|
|
8
|
+
get minPublishTime(): bigint | undefined;
|
|
9
|
+
get maxPublishTime(): bigint | undefined;
|
|
8
10
|
getAssetPrice<T extends bigint | PoolAssetConfig>(asset: T): bigint | undefined;
|
|
9
11
|
}
|
package/dist/prices/Prices.js
CHANGED
|
@@ -10,17 +10,21 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _Prices_instances, _Prices_dict, _Prices_dataCell, _Prices_extractAssetId;
|
|
13
|
+
var _Prices_instances, _Prices_dict, _Prices_dataCell, _Prices_minPublishTime, _Prices_maxPublishTime, _Prices_extractAssetId;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.Prices = void 0;
|
|
16
16
|
const core_1 = require("@ton/core");
|
|
17
17
|
class Prices {
|
|
18
|
-
constructor(dict, dataCell) {
|
|
18
|
+
constructor(dict, dataCell, minPublishTime, maxPublishTime) {
|
|
19
19
|
_Prices_instances.add(this);
|
|
20
20
|
_Prices_dict.set(this, void 0);
|
|
21
21
|
_Prices_dataCell.set(this, void 0);
|
|
22
|
+
_Prices_minPublishTime.set(this, void 0);
|
|
23
|
+
_Prices_maxPublishTime.set(this, void 0);
|
|
22
24
|
__classPrivateFieldSet(this, _Prices_dict, dict, "f");
|
|
23
25
|
__classPrivateFieldSet(this, _Prices_dataCell, dataCell, "f");
|
|
26
|
+
__classPrivateFieldSet(this, _Prices_minPublishTime, minPublishTime, "f");
|
|
27
|
+
__classPrivateFieldSet(this, _Prices_maxPublishTime, maxPublishTime, "f");
|
|
24
28
|
}
|
|
25
29
|
get dict() {
|
|
26
30
|
const dict = core_1.Dictionary.empty();
|
|
@@ -32,12 +36,18 @@ class Prices {
|
|
|
32
36
|
get dataCell() {
|
|
33
37
|
return new core_1.Cell(__classPrivateFieldGet(this, _Prices_dataCell, "f"));
|
|
34
38
|
}
|
|
39
|
+
get minPublishTime() {
|
|
40
|
+
return __classPrivateFieldGet(this, _Prices_minPublishTime, "f");
|
|
41
|
+
}
|
|
42
|
+
get maxPublishTime() {
|
|
43
|
+
return __classPrivateFieldGet(this, _Prices_maxPublishTime, "f");
|
|
44
|
+
}
|
|
35
45
|
getAssetPrice(asset) {
|
|
36
46
|
const assetId = __classPrivateFieldGet(this, _Prices_instances, "m", _Prices_extractAssetId).call(this, asset);
|
|
37
47
|
return __classPrivateFieldGet(this, _Prices_dict, "f").get(assetId);
|
|
38
48
|
}
|
|
39
49
|
}
|
|
40
50
|
exports.Prices = Prices;
|
|
41
|
-
_Prices_dict = new WeakMap(), _Prices_dataCell = new WeakMap(), _Prices_instances = new WeakSet(), _Prices_extractAssetId = function _Prices_extractAssetId(asset) {
|
|
51
|
+
_Prices_dict = new WeakMap(), _Prices_dataCell = new WeakMap(), _Prices_minPublishTime = new WeakMap(), _Prices_maxPublishTime = new WeakMap(), _Prices_instances = new WeakSet(), _Prices_extractAssetId = function _Prices_extractAssetId(asset) {
|
|
42
52
|
return typeof asset === 'bigint' ? asset : asset.assetId;
|
|
43
53
|
};
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import { Dictionary } from "@ton/core";
|
|
2
|
-
import { PoolAssetConfig, PoolAssetsConfig
|
|
2
|
+
import { ExtendedEvaaOracle, PoolAssetConfig, PoolAssetsConfig } from "../types/Master";
|
|
3
|
+
import { FetchConfig } from '../utils/utils';
|
|
4
|
+
import { Oracle } from "./Oracle.interface";
|
|
5
|
+
import { Prices } from "./Prices";
|
|
3
6
|
import { PriceSource } from "./sources";
|
|
4
7
|
import { PriceSourcesConfig } from "./Types";
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
export type PricesCollectorConfig = {
|
|
9
|
+
poolAssetsConfig: PoolAssetsConfig;
|
|
10
|
+
minimalOracles: number;
|
|
11
|
+
evaaOracles: ExtendedEvaaOracle[];
|
|
12
|
+
sourcesConfig?: PriceSourcesConfig;
|
|
13
|
+
additionalPriceSources?: PriceSource[];
|
|
14
|
+
};
|
|
15
|
+
export declare class PricesCollector implements Oracle {
|
|
7
16
|
#private;
|
|
8
|
-
constructor(
|
|
9
|
-
getPricesForLiquidate(realPrincipals: Dictionary<bigint, bigint>,
|
|
10
|
-
getPricesForWithdraw(realPrincipals: Dictionary<bigint, bigint>, withdrawAsset: PoolAssetConfig, collateralToDebt?: boolean,
|
|
11
|
-
|
|
17
|
+
constructor(config: PricesCollectorConfig);
|
|
18
|
+
getPricesForLiquidate(realPrincipals: Dictionary<bigint, bigint>, fetchConfig?: FetchConfig): Promise<Prices>;
|
|
19
|
+
getPricesForWithdraw(realPrincipals: Dictionary<bigint, bigint>, withdrawAsset: PoolAssetConfig, collateralToDebt?: boolean, fetchConfig?: FetchConfig): Promise<Prices>;
|
|
20
|
+
getPricesForSupplyWithdraw(realPrincipals: Dictionary<bigint, bigint>, supplyAsset: PoolAssetConfig | undefined, withdrawAsset: PoolAssetConfig | undefined, collateralToDebt: boolean, fetchConfig?: FetchConfig): Promise<Prices>;
|
|
21
|
+
getPrices(assets?: PoolAssetsConfig, fetchConfig?: FetchConfig): Promise<Prices>;
|
|
12
22
|
}
|
|
@@ -10,40 +10,40 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _PricesCollector_instances, _PricesCollector_prices,
|
|
13
|
+
var _PricesCollector_instances, _PricesCollector_prices, _PricesCollector_poolAssetsConfig, _PricesCollector_sourcesConfig, _PricesCollector_priceSources, _PricesCollector_minimalOracles, _PricesCollector_getPricesByAssetList, _PricesCollector_collectPrices, _PricesCollector_collectPricesWithValidation, _PricesCollector_filterPrices, _PricesCollector_filterEmptyPrincipalsAndAssets;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.PricesCollector = void 0;
|
|
16
16
|
const core_1 = require("@ton/core");
|
|
17
|
-
const pools_1 = require("../constants/pools");
|
|
18
|
-
const Types_1 = require("./Types");
|
|
19
|
-
const utils_1 = require("./utils");
|
|
20
|
-
const utils_2 = require("../utils/utils");
|
|
21
|
-
const Prices_1 = require("./Prices");
|
|
22
17
|
const math_1 = require("../api/math");
|
|
18
|
+
const utils_1 = require("../utils/utils");
|
|
19
|
+
const Prices_1 = require("./Prices");
|
|
20
|
+
const Types_1 = require("./Types");
|
|
21
|
+
const utils_2 = require("./utils");
|
|
23
22
|
class PricesCollector {
|
|
24
|
-
constructor(
|
|
23
|
+
constructor(config) {
|
|
25
24
|
_PricesCollector_instances.add(this);
|
|
26
25
|
_PricesCollector_prices.set(this, void 0);
|
|
27
|
-
|
|
26
|
+
_PricesCollector_poolAssetsConfig.set(this, void 0);
|
|
28
27
|
_PricesCollector_sourcesConfig.set(this, void 0);
|
|
29
28
|
_PricesCollector_priceSources.set(this, void 0);
|
|
30
|
-
|
|
31
|
-
__classPrivateFieldSet(this,
|
|
32
|
-
__classPrivateFieldSet(this,
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
_PricesCollector_minimalOracles.set(this, void 0);
|
|
30
|
+
__classPrivateFieldSet(this, _PricesCollector_poolAssetsConfig, config.poolAssetsConfig, "f");
|
|
31
|
+
__classPrivateFieldSet(this, _PricesCollector_sourcesConfig, config.sourcesConfig ?? Types_1.DefaultPriceSourcesConfig, "f");
|
|
32
|
+
__classPrivateFieldSet(this, _PricesCollector_priceSources, (0, utils_2.generatePriceSources)(__classPrivateFieldGet(this, _PricesCollector_sourcesConfig, "f"), config.evaaOracles), "f");
|
|
33
|
+
__classPrivateFieldSet(this, _PricesCollector_minimalOracles, config.minimalOracles, "f");
|
|
34
|
+
if (config.additionalPriceSources) {
|
|
35
|
+
__classPrivateFieldGet(this, _PricesCollector_priceSources, "f").push(...config.additionalPriceSources);
|
|
35
36
|
}
|
|
36
37
|
__classPrivateFieldSet(this, _PricesCollector_prices, [], "f");
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
-
async getPricesForLiquidate(realPrincipals, retries = 1, timeout = 3000) {
|
|
39
|
+
async getPricesForLiquidate(realPrincipals, fetchConfig) {
|
|
40
40
|
const assets = __classPrivateFieldGet(this, _PricesCollector_instances, "m", _PricesCollector_filterEmptyPrincipalsAndAssets).call(this, realPrincipals);
|
|
41
41
|
if (assets.includes(undefined)) {
|
|
42
42
|
throw new Error("User from another pool");
|
|
43
43
|
}
|
|
44
|
-
return await this.getPrices(assets.map(x => x),
|
|
44
|
+
return await this.getPrices(assets.map(x => x), fetchConfig);
|
|
45
45
|
}
|
|
46
|
-
async getPricesForWithdraw(realPrincipals, withdrawAsset, collateralToDebt = false,
|
|
46
|
+
async getPricesForWithdraw(realPrincipals, withdrawAsset, collateralToDebt = false, fetchConfig) {
|
|
47
47
|
let assets = __classPrivateFieldGet(this, _PricesCollector_instances, "m", _PricesCollector_filterEmptyPrincipalsAndAssets).call(this, realPrincipals);
|
|
48
48
|
if ((0, math_1.checkNotInDebtAtAll)(realPrincipals) && (realPrincipals.get(withdrawAsset.assetId) ?? 0n) > 0n && !collateralToDebt) {
|
|
49
49
|
return new Prices_1.Prices(core_1.Dictionary.empty(), core_1.Cell.EMPTY);
|
|
@@ -57,74 +57,90 @@ class PricesCollector {
|
|
|
57
57
|
if (collateralToDebt && assets.length == 1) {
|
|
58
58
|
throw new Error("Cannot debt only one supplied asset");
|
|
59
59
|
}
|
|
60
|
-
return await this.getPrices(assets.map(x => x),
|
|
60
|
+
return await this.getPrices(assets.map(x => x), fetchConfig);
|
|
61
61
|
}
|
|
62
|
-
async
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
async getPricesForSupplyWithdraw(realPrincipals, supplyAsset, withdrawAsset, collateralToDebt, fetchConfig) {
|
|
63
|
+
// Используем ту же логику, что и getPricesForWithdraw, но supplyAsset не используется
|
|
64
|
+
let assets = __classPrivateFieldGet(this, _PricesCollector_instances, "m", _PricesCollector_filterEmptyPrincipalsAndAssets).call(this, realPrincipals);
|
|
65
|
+
if ((0, math_1.checkNotInDebtAtAll)(realPrincipals) && withdrawAsset && (realPrincipals.get(withdrawAsset.assetId) ?? 0n) > 0n && !collateralToDebt) {
|
|
65
66
|
return new Prices_1.Prices(core_1.Dictionary.empty(), core_1.Cell.EMPTY);
|
|
66
67
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
//console.debug('[getPrices] Load prices attemp', i + 1)
|
|
70
|
-
if (i > 0) {
|
|
71
|
-
await (0, utils_2.delay)(timeout);
|
|
72
|
-
}
|
|
73
|
-
await __classPrivateFieldGet(this, _PricesCollector_instances, "m", _PricesCollector_collectPrices).call(this);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
68
|
+
if (assets.includes(undefined)) {
|
|
69
|
+
throw new Error("User from another pool");
|
|
78
70
|
}
|
|
79
|
-
if (
|
|
80
|
-
|
|
71
|
+
if (withdrawAsset && !assets.includes(withdrawAsset)) {
|
|
72
|
+
assets.push(withdrawAsset);
|
|
73
|
+
}
|
|
74
|
+
if (collateralToDebt && assets.length == 1) {
|
|
75
|
+
throw new Error("Cannot debt only one supplied asset");
|
|
76
|
+
}
|
|
77
|
+
return await this.getPrices(assets.map(x => x), fetchConfig);
|
|
78
|
+
}
|
|
79
|
+
async getPrices(assets = __classPrivateFieldGet(this, _PricesCollector_poolAssetsConfig, "f"), fetchConfig) {
|
|
80
|
+
if (assets.length == 0) {
|
|
81
|
+
return new Prices_1.Prices(core_1.Dictionary.empty(), core_1.Cell.EMPTY);
|
|
82
|
+
}
|
|
83
|
+
await __classPrivateFieldGet(this, _PricesCollector_instances, "m", _PricesCollector_collectPricesWithValidation).call(this, fetchConfig);
|
|
84
|
+
if (__classPrivateFieldGet(this, _PricesCollector_prices, "f").length < __classPrivateFieldGet(this, _PricesCollector_minimalOracles, "f")) {
|
|
85
|
+
throw new Error(`Error per updating prices, valid ${__classPrivateFieldGet(this, _PricesCollector_prices, "f").length} of ${__classPrivateFieldGet(this, _PricesCollector_minimalOracles, "f")}`);
|
|
81
86
|
}
|
|
82
87
|
const prices = __classPrivateFieldGet(this, _PricesCollector_instances, "m", _PricesCollector_getPricesByAssetList).call(this, assets);
|
|
83
88
|
return new Prices_1.Prices(prices.dict, prices.dataCell);
|
|
84
89
|
}
|
|
85
90
|
}
|
|
86
91
|
exports.PricesCollector = PricesCollector;
|
|
87
|
-
_PricesCollector_prices = new WeakMap(),
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (pricesFiltered.length < __classPrivateFieldGet(this, _PricesCollector_poolConfig, "f").minimalOracles) {
|
|
92
|
+
_PricesCollector_prices = new WeakMap(), _PricesCollector_poolAssetsConfig = new WeakMap(), _PricesCollector_sourcesConfig = new WeakMap(), _PricesCollector_priceSources = new WeakMap(), _PricesCollector_minimalOracles = new WeakMap(), _PricesCollector_instances = new WeakSet(), _PricesCollector_getPricesByAssetList = function _PricesCollector_getPricesByAssetList(assets) {
|
|
93
|
+
let pricesFiltered = __classPrivateFieldGet(this, _PricesCollector_prices, "f");
|
|
94
|
+
if (pricesFiltered.length < __classPrivateFieldGet(this, _PricesCollector_minimalOracles, "f")) {
|
|
91
95
|
throw new Error("Not enough price data");
|
|
92
96
|
}
|
|
93
|
-
if (pricesFiltered.length > __classPrivateFieldGet(this,
|
|
97
|
+
if (pricesFiltered.length > __classPrivateFieldGet(this, _PricesCollector_minimalOracles, "f")) {
|
|
94
98
|
const sortedByTimestamp = pricesFiltered.slice().sort((a, b) => b.timestamp - a.timestamp);
|
|
95
|
-
const newerPrices = sortedByTimestamp.slice(0, __classPrivateFieldGet(this,
|
|
99
|
+
const newerPrices = sortedByTimestamp.slice(0, __classPrivateFieldGet(this, _PricesCollector_minimalOracles, "f"));
|
|
96
100
|
pricesFiltered = newerPrices.sort((a, b) => a.oracleId - b.oracleId);
|
|
97
101
|
}
|
|
98
102
|
const medianData = assets.map((asset) => ({
|
|
99
103
|
assetId: asset.assetId,
|
|
100
|
-
medianPrice: (0,
|
|
104
|
+
medianPrice: (0, utils_2.getMedianPrice)(pricesFiltered, asset.assetId),
|
|
101
105
|
}));
|
|
102
106
|
const nonEmptymedianData = medianData.filter(x => x.medianPrice != null);
|
|
103
|
-
const packedMedianData = (0,
|
|
107
|
+
const packedMedianData = (0, utils_2.packAssetsData)(nonEmptymedianData);
|
|
104
108
|
const oraclesData = pricesFiltered.map((x) => ({
|
|
105
109
|
oracle: { id: x.oracleId, pubkey: x.pubkey },
|
|
106
110
|
data: { timestamp: x.timestamp, prices: x.dict },
|
|
107
111
|
signature: x.signature,
|
|
108
112
|
}));
|
|
109
|
-
const packedOracleData = (0,
|
|
113
|
+
const packedOracleData = (0, utils_2.packOraclesData)(oraclesData, nonEmptymedianData.map(x => x.assetId));
|
|
110
114
|
const dict = core_1.Dictionary.empty();
|
|
111
115
|
for (const medianDataAsset of nonEmptymedianData) {
|
|
112
116
|
dict.set(medianDataAsset.assetId, medianDataAsset.medianPrice);
|
|
113
117
|
}
|
|
114
118
|
return {
|
|
115
119
|
dict: dict,
|
|
116
|
-
dataCell: (0,
|
|
120
|
+
dataCell: (0, utils_2.packPrices)(packedMedianData, packedOracleData)
|
|
117
121
|
};
|
|
118
|
-
}, _PricesCollector_collectPrices = async function _PricesCollector_collectPrices() {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
+
}, _PricesCollector_collectPrices = async function _PricesCollector_collectPrices(fetchConfig) {
|
|
123
|
+
for (const priceSource of __classPrivateFieldGet(this, _PricesCollector_priceSources, "f")) {
|
|
124
|
+
try {
|
|
125
|
+
__classPrivateFieldSet(this, _PricesCollector_prices, await (0, utils_1.proxyFetchRetries)((0, utils_2.collectAndFilterPrices)(priceSource, __classPrivateFieldGet(this, _PricesCollector_minimalOracles, "f"), fetchConfig), fetchConfig), "f");
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
// Try next source
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
122
132
|
}
|
|
123
|
-
catch { }
|
|
124
133
|
return false;
|
|
134
|
+
}, _PricesCollector_collectPricesWithValidation = async function _PricesCollector_collectPricesWithValidation(fetchConfig) {
|
|
135
|
+
if (!__classPrivateFieldGet(this, _PricesCollector_prices, "f") || __classPrivateFieldGet(this, _PricesCollector_instances, "m", _PricesCollector_filterPrices).call(this) < __classPrivateFieldGet(this, _PricesCollector_minimalOracles, "f")) {
|
|
136
|
+
const success = await __classPrivateFieldGet(this, _PricesCollector_instances, "m", _PricesCollector_collectPrices).call(this, fetchConfig);
|
|
137
|
+
if (!success || __classPrivateFieldGet(this, _PricesCollector_prices, "f").length < __classPrivateFieldGet(this, _PricesCollector_minimalOracles, "f")) {
|
|
138
|
+
throw new Error(`Failed to collect sufficient prices: ${__classPrivateFieldGet(this, _PricesCollector_prices, "f")?.length || 0} of ${__classPrivateFieldGet(this, _PricesCollector_minimalOracles, "f")}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
125
141
|
}, _PricesCollector_filterPrices = function _PricesCollector_filterPrices() {
|
|
126
|
-
__classPrivateFieldSet(this, _PricesCollector_prices, __classPrivateFieldGet(this, _PricesCollector_prices, "f").filter((0,
|
|
142
|
+
__classPrivateFieldSet(this, _PricesCollector_prices, __classPrivateFieldGet(this, _PricesCollector_prices, "f").filter((0, utils_2.verifyPricesTimestamp)()), "f");
|
|
127
143
|
return __classPrivateFieldGet(this, _PricesCollector_prices, "f").length;
|
|
128
144
|
}, _PricesCollector_filterEmptyPrincipalsAndAssets = function _PricesCollector_filterEmptyPrincipalsAndAssets(principals) {
|
|
129
|
-
return principals.keys().filter(x => principals.get(x) != 0n).map(x => __classPrivateFieldGet(this,
|
|
145
|
+
return principals.keys().filter(x => principals.get(x) != 0n).map(x => __classPrivateFieldGet(this, _PricesCollector_poolAssetsConfig, "f").find(asset => asset.assetId == x));
|
|
130
146
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { HexString } from '@pythnetwork/hermes-client';
|
|
2
|
+
import { Dictionary } from '@ton/core';
|
|
3
|
+
import { OracleConfig } from '../api/parsers/PythOracleParser';
|
|
4
|
+
import { PoolAssetConfig, PoolAssetsConfig } from '../types/Master';
|
|
5
|
+
import { FetchConfig } from '../utils/utils';
|
|
6
|
+
import { Oracle } from './Oracle.interface';
|
|
7
|
+
import { Prices } from './Prices';
|
|
8
|
+
import { PythPriceSourcesConfig } from './Types';
|
|
9
|
+
export type PythCollectorConfig = {
|
|
10
|
+
poolAssetsConfig: PoolAssetsConfig;
|
|
11
|
+
pythOracle: OracleConfig;
|
|
12
|
+
pythConfig: PythPriceSourcesConfig;
|
|
13
|
+
};
|
|
14
|
+
export declare class PythCollector implements Oracle {
|
|
15
|
+
#private;
|
|
16
|
+
constructor(config: PythCollectorConfig);
|
|
17
|
+
getPricesForLiquidate(realPrincipals: Dictionary<bigint, bigint>, fetchConfig?: FetchConfig): Promise<Prices>;
|
|
18
|
+
getPricesForSupplyWithdraw(realPrincipals: Dictionary<bigint, bigint>, supplyAsset: PoolAssetConfig | undefined, withdrawAsset: PoolAssetConfig | undefined, collateralToDebt: boolean, fetchConfig?: FetchConfig): Promise<Prices>;
|
|
19
|
+
getPrices(assets?: PoolAssetsConfig, fetchConfig?: FetchConfig): Promise<Prices>;
|
|
20
|
+
getPricesForWithdraw(realPrincipals: Dictionary<bigint, bigint>, withdrawAsset: PoolAssetConfig, collateralToDebt?: boolean, fetchConfig?: FetchConfig): Promise<Prices>;
|
|
21
|
+
createRequiredFeedsList(evaaIds: bigint[]): HexString[];
|
|
22
|
+
}
|