@evaafi/sdk 0.6.2 → 0.6.3-b
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/CHANGELOG.md +57 -17
- package/README.md +2 -1
- package/dist/api/math.d.ts +12 -2
- package/dist/api/math.js +56 -4
- package/dist/api/parser.js +48 -20
- package/dist/constants/assets.d.ts +9 -1
- package/dist/constants/assets.js +38 -9
- package/dist/constants/general.d.ts +18 -0
- package/dist/constants/general.js +20 -2
- package/dist/constants/pools.d.ts +7 -1
- package/dist/constants/pools.js +60 -26
- package/dist/index.d.ts +10 -3
- package/dist/index.js +26 -2
- package/dist/prices/PricesCollector.d.ts +2 -2
- package/dist/prices/PricesCollector.js +8 -6
- package/dist/prices/utils.js +1 -1
- package/dist/rewards/EvaaRewards.d.ts +10 -0
- package/dist/rewards/EvaaRewards.js +21 -0
- package/dist/rewards/JettonMinter.d.ts +30 -0
- package/dist/rewards/JettonMinter.js +83 -0
- package/dist/rewards/JettonWallet.d.ts +23 -0
- package/dist/rewards/JettonWallet.js +60 -0
- package/dist/rewards/RewardMaster.d.ts +26 -0
- package/dist/rewards/RewardMaster.js +83 -0
- package/dist/rewards/RewardUser.d.ts +23 -0
- package/dist/rewards/RewardUser.js +70 -0
- package/dist/types/MasterRewards.d.ts +13 -0
- package/dist/types/User.d.ts +11 -1
- package/dist/types/UserRewards.d.ts +10 -0
- package/dist/types/UserRewards.js +2 -0
- package/dist/utils/sha256BigInt.d.ts +2 -0
- package/dist/utils/sha256BigInt.js +9 -1
- package/dist/utils/userJettonWallet.js +17 -0
- package/package.json +42 -42
- package/src/api/math.ts +78 -3
- package/src/api/parser.ts +57 -22
- package/src/constants/assets.ts +117 -65
- package/src/constants/general.ts +33 -2
- package/src/constants/pools.ts +110 -28
- package/src/index.ts +24 -2
- package/src/prices/PricesCollector.ts +10 -6
- package/src/prices/utils.ts +1 -1
- package/src/rewards/EvaaRewards.ts +23 -0
- package/src/rewards/JettonMinter.ts +113 -0
- package/src/rewards/JettonWallet.ts +77 -0
- package/src/rewards/RewardMaster.ts +110 -0
- package/src/rewards/RewardUser.ts +90 -0
- package/src/types/Master.ts +1 -1
- package/src/types/MasterRewards.ts +13 -0
- package/src/types/User.ts +13 -3
- package/src/types/UserRewards.ts +10 -0
- package/src/utils/sha256BigInt.ts +8 -0
- package/src/utils/userJettonWallet.ts +43 -27
- package/dist/config.d.ts +0 -1
- package/dist/config.js +0 -4
- package/dist/constants.d.ts +0 -69
- package/dist/constants.js +0 -83
- package/dist/types/Common.d.ts +0 -14
- package/dist/utils/priceUtils.d.ts +0 -55
- package/dist/utils/priceUtils.js +0 -117
- /package/dist/types/{Common.js → MasterRewards.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,47 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/)
|
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
-
## 0.6.
|
|
7
|
+
## 0.6.3-b — 2025-04-30
|
|
8
|
+
### Added
|
|
9
|
+
- ```USDe and tsUSDe``` new tokens in Main ```PoolConfig```
|
|
10
|
+
- Minor bug fixes
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## 0.6.3 — 2025-04-01
|
|
14
|
+
### Added
|
|
15
|
+
- ```EvaaRewards``` wrapper of RewardUser contract with ```PoolAssetConfig```
|
|
16
|
+
- ```RewardUser``` wrapper of reward user contract
|
|
17
|
+
- ```RewardMaster``` wrapper of reward master contract
|
|
18
|
+
- ```JettonMinget``` wrapper of jetton master contract
|
|
19
|
+
- ```JettonWallet``` wrapper of jetton wallet contract
|
|
20
|
+
- ```EVAA_REWARDS_MASTER_CODE_MAINNET``` and ```EVAA_REWARDS_MASTER_CODE_TESTNET``` is constants for reward master code
|
|
21
|
+
- ```EVAA_REWARDS_USER_CODE_TESTNET``` and ```EVAA_REWARDS_USER_CODE_MAINNET``` is constants for reward user code
|
|
22
|
+
- ```TESTNET_MASTER_REWARD_CONFIG``` testnet TON config of reward
|
|
23
|
+
- ```TESTNET_MASTER_EUSDT_REWARD_CONFIG``` testnet EUSDT config of reward
|
|
24
|
+
- ```MAINNET_MASTER_TON_REWARD_CONFIG``` mainnet TON config of reward
|
|
25
|
+
- ```MAINNET_MASTER_USDT_REWARD_CONFIG``` mainnet USDT config of reward
|
|
26
|
+
|
|
27
|
+
## 0.6.2-c — 2025-01-07
|
|
28
|
+
### Added
|
|
29
|
+
- ```getAssetLiquidityMinusReserves``` function needed to count the amount of free amount for withdrawal
|
|
30
|
+
### Fixed
|
|
31
|
+
- ```borrowLimits``` function now take into account the amount available for withdrawal
|
|
32
|
+
|
|
33
|
+
## 0.6.2-b — 2024-12-17
|
|
34
|
+
### Added
|
|
35
|
+
- new field in ```UserLiteData``` . ```fullyParsed``` and ```havePrincipalWithoutPrice```
|
|
36
|
+
true if all prices for user parsing were provided or true if have a principal without price
|
|
37
|
+
now user.getSync and parseUserData can work without some prices
|
|
38
|
+
- ```predictAPY``` - function that predicts a change in apy after supply or withdraw
|
|
39
|
+
|
|
40
|
+
## 0.6.2-a — 2024-12-13
|
|
41
|
+
### Added
|
|
42
|
+
- new field in UserLiteData ```user.data.realPrincipals``` -
|
|
43
|
+
principals before applying dusts
|
|
44
|
+
### Fixed
|
|
45
|
+
- getPricesForWithdraw/getPricesForLiquidate they should now be called with a different argument
|
|
46
|
+
|
|
47
|
+
## 0.6.2 — 2024-11-21
|
|
8
48
|
### Added
|
|
9
49
|
- ALTS Pool
|
|
10
50
|
- PricesCollector class
|
|
@@ -29,7 +69,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
|
29
69
|
### Changed
|
|
30
70
|
- getPrices is deprecated use PricesCollector instead
|
|
31
71
|
|
|
32
|
-
## 0.6.1-a
|
|
72
|
+
## 0.6.1-a — 2024-10-29
|
|
33
73
|
### Changed
|
|
34
74
|
- updated `EVAA_LP_MAINNET_VERSION` to `3`
|
|
35
75
|
- `awaitedSupply` is always defined
|
|
@@ -38,7 +78,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
|
38
78
|
- `minimalOracles` is `3` in all pools
|
|
39
79
|
|
|
40
80
|
|
|
41
|
-
## 0.6.1
|
|
81
|
+
## 0.6.1 — 2024-10-22
|
|
42
82
|
### Changed
|
|
43
83
|
- added liquidation.ts with ```findAssetById```, ```calculateAssetsValues```, ```selectGreatestAssets```, ```calculateMinCollateralByTransferredAmount```, ```calculateLiquidationAmounts```, ```isLiquidatable```, ```isBadDebt```, ```addReserve```, ```deductReserve```, ```toAssetAmount```, ```toAssetWorth```, ```addLiquidationBonus```, ```deductLiquidationBonus```, ```PreparedAssetInfo```, ```prepareAssetInfo``` functions required or flexible liquidations calculation.
|
|
44
84
|
- user. ```getSync``` and ```getSyncLite``` new argument ```applyDust``` by default is ```false```;
|
|
@@ -46,14 +86,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
|
46
86
|
### Fixed
|
|
47
87
|
|
|
48
88
|
|
|
49
|
-
## 0.6.0a
|
|
89
|
+
## 0.6.0a — 2024-10-14
|
|
50
90
|
### Changed
|
|
51
91
|
- user. ```getSync``` and ```getSyncLite``` new argument ```applyDust``` by default is ```false```
|
|
52
92
|
### Fixed
|
|
53
93
|
- Healthfactor calculation minor bug
|
|
54
94
|
- createLiquidationMessage fix new field payloadForwardAmount
|
|
55
95
|
|
|
56
|
-
## 0.6.0
|
|
96
|
+
## 0.6.0 — 2024-10-10
|
|
57
97
|
### Added
|
|
58
98
|
- SDK Supports Evaa v6 smart contracts
|
|
59
99
|
### Fixed
|
|
@@ -63,7 +103,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
|
63
103
|
### Fixed
|
|
64
104
|
- Fix typo in ```calculateMaximumWithdrawAmount```
|
|
65
105
|
|
|
66
|
-
## 0.5.6
|
|
106
|
+
## 0.5.6 — 2024-09-28
|
|
67
107
|
|
|
68
108
|
### Added
|
|
69
109
|
- ```isTonAsset(PoolAssetConfig)``` function
|
|
@@ -85,7 +125,7 @@ Dust is a small amount of principal that is ignored
|
|
|
85
125
|
### Fixed
|
|
86
126
|
- parseUserLiteData (dust) & parseUserData (dust and withdrawLimits) calculations problem
|
|
87
127
|
|
|
88
|
-
## 0.5.4
|
|
128
|
+
## 0.5.4 — 2024-09-09
|
|
89
129
|
|
|
90
130
|
check ```tests\supply_withdraw_test.ts``` for new examples
|
|
91
131
|
|
|
@@ -129,23 +169,23 @@ await evaaMainNet.sendSupply(sender_mainnet, toNano(1), {
|
|
|
129
169
|
- predictHealthFactor minor fixes
|
|
130
170
|
- getUserJettonWallet all currencies support
|
|
131
171
|
|
|
132
|
-
## 0.5.3
|
|
172
|
+
## 0.5.3 — 2024-08-20
|
|
133
173
|
|
|
134
174
|
### Fixed
|
|
135
175
|
- getPrices now supports several endpoints (works on the principle of which one will answer faster, whose answer is used) and throws an exception if prices are not loaded
|
|
136
176
|
|
|
137
|
-
## 0.5.2
|
|
177
|
+
## 0.5.2 — 2024-08-19
|
|
138
178
|
|
|
139
179
|
### Fixed
|
|
140
180
|
- predictHealthFactor argument processing improving
|
|
141
181
|
- getSync fixed parsing contract state, base64url was replaced to base64 encoding which has much higher support
|
|
142
182
|
|
|
143
|
-
## 0.5.1
|
|
183
|
+
## 0.5.1 — 2024-07-05
|
|
144
184
|
|
|
145
185
|
### Added
|
|
146
186
|
- predictHealthFactor function to predict a change in a health factor after repay, borrow, supply, withdraw
|
|
147
187
|
|
|
148
|
-
## 0.5.0
|
|
188
|
+
## 0.5.0 — 2024-06-29
|
|
149
189
|
This release contains breaking changes.
|
|
150
190
|
|
|
151
191
|
### Added
|
|
@@ -163,7 +203,7 @@ This release contains breaking changes.
|
|
|
163
203
|
### Fixed
|
|
164
204
|
- UserBalance calculation was fixed
|
|
165
205
|
|
|
166
|
-
## 0.4.0
|
|
206
|
+
## 0.4.0 — 2024-06-01
|
|
167
207
|
This release contains breaking changes.
|
|
168
208
|
|
|
169
209
|
### Added
|
|
@@ -184,15 +224,15 @@ This release contains breaking changes.
|
|
|
184
224
|
- Jetton wallets address calculation
|
|
185
225
|
- Field names in Assets Config and Assets Data serialization functions
|
|
186
226
|
|
|
187
|
-
## 0.3.2
|
|
227
|
+
## 0.3.2 — 2024-04-20
|
|
188
228
|
### Added
|
|
189
229
|
- New asset - Tether USD
|
|
190
230
|
|
|
191
|
-
## 0.3.1
|
|
231
|
+
## 0.3.1 — 2024-04-19
|
|
192
232
|
### Added
|
|
193
233
|
- New asset - tsTON
|
|
194
234
|
|
|
195
|
-
## 0.3.0
|
|
235
|
+
## 0.3.0 — 2024-04-04
|
|
196
236
|
### Added
|
|
197
237
|
- New asset - stTON
|
|
198
238
|
|
|
@@ -204,7 +244,7 @@ This release contains breaking changes.
|
|
|
204
244
|
### Removed
|
|
205
245
|
- Ethereum dependencies
|
|
206
246
|
|
|
207
|
-
## 0.2.0
|
|
247
|
+
## 0.2.0 — 2024-03-13
|
|
208
248
|
This release contains breaking changes.
|
|
209
249
|
|
|
210
250
|
### Added
|
|
@@ -222,7 +262,7 @@ This release contains breaking changes.
|
|
|
222
262
|
### Fixed
|
|
223
263
|
- Calculation of borrow limits
|
|
224
264
|
|
|
225
|
-
## 0.1.0
|
|
265
|
+
## 0.1.0 — 2024-03-11
|
|
226
266
|
### Added
|
|
227
267
|
- Parsing user lite data, which does not require prices
|
|
228
268
|
- Assets reserves to `MasterData`
|
package/README.md
CHANGED
|
@@ -3,5 +3,6 @@
|
|
|
3
3
|
The EVAA SDK is designed to easily integrate with the EVAA lending protocol on TON blockchain.
|
|
4
4
|
|
|
5
5
|
## Documentation
|
|
6
|
+
You can find the Typedoc documentation [here](https://evaafi.github.io/sdk/).
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
Additional (older) documentation can also be found in the [docs](./docs) folder.
|
package/dist/api/math.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AgregatedBalances, AssetConfig, AssetData, AssetInterest, ExtendedAssetData, ExtendedAssetsConfig, ExtendedAssetsData, MasterConstants, PoolConfig } from '../types/Master';
|
|
1
|
+
import { AgregatedBalances, AssetApy, AssetConfig, AssetData, AssetInterest, ExtendedAssetData, ExtendedAssetsConfig, ExtendedAssetsData, MasterConstants, PoolConfig } from '../types/Master';
|
|
2
2
|
import { Dictionary } from '@ton/core';
|
|
3
|
-
import { HealthParamsArgs, LiquidationData, PredictHealthFactorArgs, UserBalance } from '../types/User';
|
|
3
|
+
import { HealthParamsArgs, LiquidationData, PredictAPYArgs, PredictHealthFactorArgs, UserBalance } from '../types/User';
|
|
4
4
|
export declare function mulFactor(decimal: bigint, a: bigint, b: bigint): bigint;
|
|
5
5
|
export declare function mulDiv(x: bigint, y: bigint, z: bigint): bigint;
|
|
6
6
|
export declare function mulDivC(x: bigint, y: bigint, z: bigint): bigint;
|
|
@@ -16,6 +16,7 @@ export declare const BigMath: {
|
|
|
16
16
|
max: typeof bigIntMax;
|
|
17
17
|
};
|
|
18
18
|
export declare function calculatePresentValue(index: bigint, principalValue: bigint, masterConstants: MasterConstants): bigint;
|
|
19
|
+
export declare function getAssetLiquidityMinusReserves(assetData: AssetData, masterConstants: MasterConstants): bigint;
|
|
19
20
|
export declare function calculateCurrentRates(assetConfig: AssetConfig, assetData: AssetData, masterConstants: MasterConstants): {
|
|
20
21
|
sRate: bigint;
|
|
21
22
|
bRate: bigint;
|
|
@@ -25,6 +26,7 @@ export declare function calculateCurrentRates(assetConfig: AssetConfig, assetDat
|
|
|
25
26
|
};
|
|
26
27
|
export declare function calculateAssetData(assetsConfigDict: ExtendedAssetsConfig, assetsDataDict: Dictionary<bigint, AssetData>, assetId: bigint, masterConstants: MasterConstants): ExtendedAssetData;
|
|
27
28
|
export declare function calculateAssetInterest(assetConfig: AssetConfig, assetData: AssetData, masterConstants: MasterConstants): AssetInterest;
|
|
29
|
+
export declare function calculateInterestWithSupplyBorrow(totalSupply: bigint, totalBorrow: bigint, assetConfig: AssetConfig, masterConstants: MasterConstants): AssetInterest;
|
|
28
30
|
export declare function checkNotInDebtAtAll(principals: Dictionary<bigint, bigint>): boolean;
|
|
29
31
|
export declare function getAgregatedBalances(assetsData: ExtendedAssetsData, assetsConfig: ExtendedAssetsConfig, principals: Dictionary<bigint, bigint>, prices: Dictionary<bigint, bigint>, masterConstants: MasterConstants): AgregatedBalances;
|
|
30
32
|
export declare function calculateMaximumWithdrawAmount(assetsConfig: ExtendedAssetsConfig, assetsData: ExtendedAssetsData, principals: Dictionary<bigint, bigint>, prices: Dictionary<bigint, bigint>, masterConstants: MasterConstants, assetId: bigint): bigint;
|
|
@@ -59,3 +61,11 @@ export declare function calculateHealthParams(parameters: HealthParamsArgs): {
|
|
|
59
61
|
*/
|
|
60
62
|
export declare function calculateLiquidationData(assetsConfig: ExtendedAssetsConfig, assetsData: ExtendedAssetsData, principals: Dictionary<bigint, bigint>, prices: Dictionary<bigint, bigint>, poolConfig: PoolConfig): LiquidationData;
|
|
61
63
|
export declare function predictHealthFactor(args: PredictHealthFactorArgs): number;
|
|
64
|
+
/**
|
|
65
|
+
* Predicts how APY will change as a result of one of the actions Borrow, Supply, Withdraw or Repay.
|
|
66
|
+
*
|
|
67
|
+
* Used on the front-end.
|
|
68
|
+
*
|
|
69
|
+
* @returns Estimated APYs for Supply and Borrow
|
|
70
|
+
*/
|
|
71
|
+
export declare function predictAPY(args: PredictAPYArgs): AssetInterest & AssetApy;
|
package/dist/api/math.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.predictHealthFactor = exports.calculateLiquidationData = exports.calculateHealthParams = exports.presentValue = exports.getAvailableToBorrow = exports.calculateMaximumWithdrawAmount = exports.getAgregatedBalances = exports.checkNotInDebtAtAll = exports.calculateAssetInterest = exports.calculateAssetData = exports.calculateCurrentRates = exports.calculatePresentValue = exports.BigMath = exports.bigIntMin = exports.bigIntMax = exports.bigAbs = exports.mulDivC = exports.mulDiv = exports.mulFactor = void 0;
|
|
3
|
+
exports.predictAPY = exports.predictHealthFactor = exports.calculateLiquidationData = exports.calculateHealthParams = exports.presentValue = exports.getAvailableToBorrow = exports.calculateMaximumWithdrawAmount = exports.getAgregatedBalances = exports.checkNotInDebtAtAll = exports.calculateInterestWithSupplyBorrow = exports.calculateAssetInterest = exports.calculateAssetData = exports.calculateCurrentRates = exports.getAssetLiquidityMinusReserves = exports.calculatePresentValue = exports.BigMath = exports.bigIntMin = exports.bigIntMax = exports.bigAbs = exports.mulDivC = exports.mulDiv = exports.mulFactor = void 0;
|
|
4
4
|
const User_1 = require("../types/User");
|
|
5
5
|
const assets_1 = require("../constants/assets");
|
|
6
6
|
const liquidation_1 = require("./liquidation");
|
|
@@ -35,6 +35,12 @@ function calculatePresentValue(index, principalValue, masterConstants) {
|
|
|
35
35
|
return (principalValue * index) / masterConstants.FACTOR_SCALE;
|
|
36
36
|
}
|
|
37
37
|
exports.calculatePresentValue = calculatePresentValue;
|
|
38
|
+
function getAssetLiquidityMinusReserves(assetData, masterConstants) {
|
|
39
|
+
const total_supply = calculatePresentValue(assetData.sRate, assetData.totalSupply, masterConstants);
|
|
40
|
+
const total_borrow = calculatePresentValue(assetData.bRate, assetData.totalBorrow, masterConstants);
|
|
41
|
+
return bigIntMin(total_supply - total_borrow, assetData.balance);
|
|
42
|
+
}
|
|
43
|
+
exports.getAssetLiquidityMinusReserves = getAssetLiquidityMinusReserves;
|
|
38
44
|
function calculateCurrentRates(assetConfig, assetData, masterConstants) {
|
|
39
45
|
const now = BigInt(Math.floor(Date.now() / 1000));
|
|
40
46
|
const timeElapsed = now - assetData.lastAccural;
|
|
@@ -81,6 +87,10 @@ exports.calculateAssetData = calculateAssetData;
|
|
|
81
87
|
function calculateAssetInterest(assetConfig, assetData, masterConstants) {
|
|
82
88
|
const totalSupply = calculatePresentValue(assetData.sRate, assetData.totalSupply, masterConstants);
|
|
83
89
|
const totalBorrow = calculatePresentValue(assetData.bRate, assetData.totalBorrow, masterConstants);
|
|
90
|
+
return calculateInterestWithSupplyBorrow(totalSupply, totalBorrow, assetConfig, masterConstants);
|
|
91
|
+
}
|
|
92
|
+
exports.calculateAssetInterest = calculateAssetInterest;
|
|
93
|
+
function calculateInterestWithSupplyBorrow(totalSupply, totalBorrow, assetConfig, masterConstants) {
|
|
84
94
|
let utilization = 0n;
|
|
85
95
|
let supplyInterest = 0n;
|
|
86
96
|
let borrowInterest = 0n;
|
|
@@ -104,7 +114,7 @@ function calculateAssetInterest(assetConfig, assetData, masterConstants) {
|
|
|
104
114
|
borrowInterest
|
|
105
115
|
};
|
|
106
116
|
}
|
|
107
|
-
exports.
|
|
117
|
+
exports.calculateInterestWithSupplyBorrow = calculateInterestWithSupplyBorrow;
|
|
108
118
|
function checkNotInDebtAtAll(principals) {
|
|
109
119
|
return principals.values().every(x => x >= 0n);
|
|
110
120
|
}
|
|
@@ -173,10 +183,16 @@ function getAvailableToBorrow(assetsConfig, assetsData, principals, prices, mast
|
|
|
173
183
|
let borrowLimit = 0n;
|
|
174
184
|
let borrowAmount = 0n;
|
|
175
185
|
for (const assetID of principals.keys()) {
|
|
186
|
+
const principal = principals.get(assetID);
|
|
187
|
+
if (principal == 0n) {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (!prices.has(assetID)) {
|
|
191
|
+
return 0n;
|
|
192
|
+
}
|
|
176
193
|
const assetConfig = assetsConfig.get(assetID);
|
|
177
194
|
const assetData = assetsData.get(assetID);
|
|
178
195
|
const price = prices.get(assetID);
|
|
179
|
-
const principal = principals.get(assetID);
|
|
180
196
|
if (principal < 0n) {
|
|
181
197
|
borrowAmount += mulDiv(calculatePresentValue(assetData.bRate, -principal, masterConstants), price, 10n ** assetConfig.decimals);
|
|
182
198
|
}
|
|
@@ -359,7 +375,6 @@ function predictHealthFactor(args) {
|
|
|
359
375
|
const assetId = args.asset.assetId;
|
|
360
376
|
const assetConfig = args.assetsConfig.get(assetId);
|
|
361
377
|
const assetPrice = Number(args.prices.get(assetId));
|
|
362
|
-
const assetData = args.assetsData.get(assetId);
|
|
363
378
|
let totalLimit = Number(healthParams.totalLimit);
|
|
364
379
|
let totalBorrow = Number(healthParams.totalDebt);
|
|
365
380
|
const currentAmount = args.amount;
|
|
@@ -386,3 +401,40 @@ function predictHealthFactor(args) {
|
|
|
386
401
|
return Math.min(Math.max(1 - totalBorrow / totalLimit, 0), 1); // let's limit a result to zero below and one above
|
|
387
402
|
}
|
|
388
403
|
exports.predictHealthFactor = predictHealthFactor;
|
|
404
|
+
/**
|
|
405
|
+
* Predicts how APY will change as a result of one of the actions Borrow, Supply, Withdraw or Repay.
|
|
406
|
+
*
|
|
407
|
+
* Used on the front-end.
|
|
408
|
+
*
|
|
409
|
+
* @returns Estimated APYs for Supply and Borrow
|
|
410
|
+
*/
|
|
411
|
+
function predictAPY(args) {
|
|
412
|
+
const assetConfig = args.assetConfig;
|
|
413
|
+
const assetData = args.assetData;
|
|
414
|
+
const masterConstants = args.masterConstants;
|
|
415
|
+
let totalSupply = calculatePresentValue(assetData.sRate, assetData.totalSupply, masterConstants);
|
|
416
|
+
let totalBorrow = calculatePresentValue(assetData.bRate, assetData.totalBorrow, masterConstants);
|
|
417
|
+
const currentAmount = args.amount;
|
|
418
|
+
const changeType = args.balanceChangeType;
|
|
419
|
+
if (currentAmount != null && currentAmount != 0n) {
|
|
420
|
+
if (changeType == User_1.BalanceChangeType.Borrow) {
|
|
421
|
+
totalBorrow += currentAmount;
|
|
422
|
+
}
|
|
423
|
+
else if (changeType == User_1.BalanceChangeType.Repay) {
|
|
424
|
+
totalBorrow -= currentAmount;
|
|
425
|
+
}
|
|
426
|
+
else if (changeType == User_1.BalanceChangeType.Withdraw) {
|
|
427
|
+
totalSupply -= currentAmount;
|
|
428
|
+
}
|
|
429
|
+
else if (changeType == User_1.BalanceChangeType.Supply) {
|
|
430
|
+
totalSupply += currentAmount;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
const interest = calculateInterestWithSupplyBorrow(totalSupply, totalBorrow, assetConfig, masterConstants);
|
|
434
|
+
return {
|
|
435
|
+
...interest,
|
|
436
|
+
supplyApy: (1 + (Number(interest.supplyInterest) / 1e12) * 24 * 3600) ** 365 - 1,
|
|
437
|
+
borrowApy: (1 + (Number(interest.borrowInterest) / 1e12) * 24 * 3600) ** 365 - 1
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
exports.predictAPY = predictAPY;
|
package/dist/api/parser.js
CHANGED
|
@@ -24,8 +24,8 @@ function createAssetData() {
|
|
|
24
24
|
serialize: (src, buidler) => {
|
|
25
25
|
buidler.storeUint(src.sRate, 64);
|
|
26
26
|
buidler.storeUint(src.bRate, 64);
|
|
27
|
-
buidler.
|
|
28
|
-
buidler.
|
|
27
|
+
buidler.storeInt(src.totalSupply, 64);
|
|
28
|
+
buidler.storeInt(src.totalBorrow, 64);
|
|
29
29
|
buidler.storeUint(src.lastAccural, 32);
|
|
30
30
|
buidler.storeUint(src.balance, 64);
|
|
31
31
|
buidler.storeUint(src.trackingSupplyIndex, 64);
|
|
@@ -33,15 +33,15 @@ function createAssetData() {
|
|
|
33
33
|
buidler.storeUint(src.awaitedSupply, 64);
|
|
34
34
|
},
|
|
35
35
|
parse: (src) => {
|
|
36
|
-
const sRate = BigInt(src.
|
|
37
|
-
const bRate = BigInt(src.
|
|
38
|
-
const totalSupply = BigInt(src.
|
|
39
|
-
const totalBorrow = BigInt(src.
|
|
40
|
-
const lastAccural = BigInt(src.
|
|
41
|
-
const balance = BigInt(src.
|
|
42
|
-
const trackingSupplyIndex = BigInt(src.
|
|
43
|
-
const trackingBorrowIndex = BigInt(src.
|
|
44
|
-
const awaitedSupply = BigInt(src.
|
|
36
|
+
const sRate = BigInt(src.loadUintBig(64));
|
|
37
|
+
const bRate = BigInt(src.loadUintBig(64));
|
|
38
|
+
const totalSupply = BigInt(src.loadIntBig(64));
|
|
39
|
+
const totalBorrow = BigInt(src.loadIntBig(64));
|
|
40
|
+
const lastAccural = BigInt(src.loadUintBig(32));
|
|
41
|
+
const balance = BigInt(src.loadUintBig(64));
|
|
42
|
+
const trackingSupplyIndex = BigInt(src.loadUintBig(64));
|
|
43
|
+
const trackingBorrowIndex = BigInt(src.loadUintBig(64));
|
|
44
|
+
const awaitedSupply = BigInt(src.loadUintBig(64));
|
|
45
45
|
return { sRate, bRate, totalSupply, totalBorrow, lastAccural, balance, trackingSupplyIndex, trackingBorrowIndex, awaitedSupply };
|
|
46
46
|
},
|
|
47
47
|
};
|
|
@@ -183,7 +183,8 @@ function parseUserLiteData(userDataBOC, assetsData, assetsConfig, poolConfig, ap
|
|
|
183
183
|
const codeVersion = userSlice.loadCoins();
|
|
184
184
|
const masterAddress = userSlice.loadAddress();
|
|
185
185
|
const userAddress = userSlice.loadAddress();
|
|
186
|
-
const
|
|
186
|
+
const realPrincipals = userSlice.loadDict(core_1.Dictionary.Keys.BigUint(256), core_1.Dictionary.Values.BigInt(64));
|
|
187
|
+
const principalsDict = core_1.Dictionary.empty(core_1.Dictionary.Keys.BigUint(256), core_1.Dictionary.Values.BigInt(64));
|
|
187
188
|
const userState = userSlice.loadInt(64);
|
|
188
189
|
let trackingSupplyIndex = 0n;
|
|
189
190
|
let trackingBorrowIndex = 0n;
|
|
@@ -209,7 +210,7 @@ function parseUserLiteData(userDataBOC, assetsData, assetsConfig, poolConfig, ap
|
|
|
209
210
|
for (const [_, asset] of Object.entries(poolAssetsConfig)) {
|
|
210
211
|
const assetData = assetsData.get(asset.assetId);
|
|
211
212
|
const assetConfig = assetsConfig.get(asset.assetId);
|
|
212
|
-
let principal =
|
|
213
|
+
let principal = realPrincipals.get(asset.assetId) || 0n;
|
|
213
214
|
let balance = (0, math_1.presentValue)(assetData.sRate, assetData.bRate, principal, masterConstants);
|
|
214
215
|
if (applyDust && (principal > 0 && (principal < assetConfig.dust))) {
|
|
215
216
|
principal = 0n;
|
|
@@ -219,6 +220,9 @@ function parseUserLiteData(userDataBOC, assetsData, assetsConfig, poolConfig, ap
|
|
|
219
220
|
};
|
|
220
221
|
principalsDict.set(asset.assetId, 0n);
|
|
221
222
|
}
|
|
223
|
+
else {
|
|
224
|
+
principalsDict.set(asset.assetId, principal);
|
|
225
|
+
}
|
|
222
226
|
userBalances.set(asset.assetId, balance);
|
|
223
227
|
}
|
|
224
228
|
return {
|
|
@@ -227,12 +231,14 @@ function parseUserLiteData(userDataBOC, assetsData, assetsConfig, poolConfig, ap
|
|
|
227
231
|
masterAddress: masterAddress,
|
|
228
232
|
ownerAddress: userAddress,
|
|
229
233
|
principals: principalsDict,
|
|
234
|
+
realPrincipals: realPrincipals,
|
|
230
235
|
state: userState,
|
|
231
236
|
balances: userBalances,
|
|
232
237
|
trackingSupplyIndex: trackingSupplyIndex,
|
|
233
238
|
trackingBorrowIndex: trackingBorrowIndex,
|
|
234
239
|
dutchAuctionStart: dutchAuctionStart,
|
|
235
240
|
backupCell: backupCell,
|
|
241
|
+
fullyParsed: false,
|
|
236
242
|
rewards: rewards,
|
|
237
243
|
backupCell1: backupCell1,
|
|
238
244
|
backupCell2: backupCell2,
|
|
@@ -240,12 +246,22 @@ function parseUserLiteData(userDataBOC, assetsData, assetsConfig, poolConfig, ap
|
|
|
240
246
|
}
|
|
241
247
|
exports.parseUserLiteData = parseUserLiteData;
|
|
242
248
|
function parseUserData(userLiteData, assetsData, assetsConfig, prices, poolConfig, applyDust = false) {
|
|
249
|
+
userLiteData.fullyParsed = true;
|
|
250
|
+
let havePrincipalWithoutPrice = false;
|
|
243
251
|
const poolAssetsConfig = poolConfig.poolAssetsConfig;
|
|
244
252
|
const masterConstants = poolConfig.masterConstants;
|
|
245
253
|
const withdrawalLimits = core_1.Dictionary.empty();
|
|
246
254
|
const borrowLimits = core_1.Dictionary.empty();
|
|
247
255
|
let supplyBalance = 0n;
|
|
248
256
|
let borrowBalance = 0n;
|
|
257
|
+
for (const [assetId, principal] of userLiteData.realPrincipals) {
|
|
258
|
+
if (!prices.has(assetId)) {
|
|
259
|
+
userLiteData.fullyParsed = false;
|
|
260
|
+
if (principal != 0n) {
|
|
261
|
+
havePrincipalWithoutPrice = true;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
249
265
|
for (const [_, asset] of Object.entries(poolAssetsConfig)) {
|
|
250
266
|
const assetData = assetsData.get(asset.assetId);
|
|
251
267
|
const assetConfig = assetsConfig.get(asset.assetId);
|
|
@@ -258,6 +274,9 @@ function parseUserData(userLiteData, assetsData, assetsConfig, prices, poolConfi
|
|
|
258
274
|
userLiteData.balances.set(asset.assetId, balance);
|
|
259
275
|
}
|
|
260
276
|
for (const [_, asset] of Object.entries(poolAssetsConfig)) {
|
|
277
|
+
if (!prices.has(asset.assetId)) {
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
261
280
|
const assetConfig = assetsConfig.get(asset.assetId);
|
|
262
281
|
const balance = userLiteData.balances.get(asset.assetId);
|
|
263
282
|
if (balance.type === User_1.BalanceType.supply) {
|
|
@@ -267,24 +286,32 @@ function parseUserData(userLiteData, assetsData, assetsConfig, prices, poolConfi
|
|
|
267
286
|
borrowBalance += (balance.amount * prices.get(asset.assetId)) / 10n ** assetConfig.decimals;
|
|
268
287
|
}
|
|
269
288
|
}
|
|
270
|
-
const availableToBorrow = (0, math_1.getAvailableToBorrow)(assetsConfig, assetsData, userLiteData.
|
|
289
|
+
const availableToBorrow = (0, math_1.getAvailableToBorrow)(assetsConfig, assetsData, userLiteData.realPrincipals, prices, masterConstants);
|
|
271
290
|
for (const [_, asset] of Object.entries(poolAssetsConfig)) {
|
|
291
|
+
const balance = userLiteData.balances.get(asset.assetId);
|
|
272
292
|
const assetConfig = assetsConfig.get(asset.assetId);
|
|
273
293
|
const assetData = assetsData.get(asset.assetId);
|
|
274
|
-
const
|
|
294
|
+
const assetLiquidityMinusReserves = (0, math_1.getAssetLiquidityMinusReserves)(assetData, masterConstants);
|
|
275
295
|
if (balance.type === User_1.BalanceType.supply) {
|
|
276
|
-
withdrawalLimits.set(asset.assetId, (0, math_1.bigIntMin)((0, math_1.calculateMaximumWithdrawAmount)(assetsConfig, assetsData, userLiteData.
|
|
296
|
+
withdrawalLimits.set(asset.assetId, (0, math_1.bigIntMin)((0, math_1.calculateMaximumWithdrawAmount)(assetsConfig, assetsData, userLiteData.realPrincipals, prices, masterConstants, asset.assetId), assetData.balance));
|
|
277
297
|
}
|
|
278
|
-
|
|
298
|
+
if (!prices.has(asset.assetId)) {
|
|
299
|
+
borrowLimits.set(asset.assetId, 0n);
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
borrowLimits.set(asset.assetId, (0, math_1.bigIntMax)(0n, (0, math_1.bigIntMin)((availableToBorrow * 10n ** assetConfig.decimals) / prices.get(asset.assetId), assetLiquidityMinusReserves)));
|
|
279
303
|
}
|
|
280
304
|
const limitUsed = borrowBalance + availableToBorrow;
|
|
281
305
|
const limitUsedPercent = limitUsed === 0n
|
|
282
306
|
? 0
|
|
283
307
|
: Number(BigInt(1e9) - (availableToBorrow * BigInt(1e9)) / (borrowBalance + availableToBorrow)) / 1e7;
|
|
284
|
-
const liquidationData = (0, math_1.calculateLiquidationData)(assetsConfig, assetsData, userLiteData.principals, prices, poolConfig);
|
|
285
308
|
let healthFactor = 1;
|
|
286
|
-
|
|
287
|
-
|
|
309
|
+
let liquidationData;
|
|
310
|
+
if (!havePrincipalWithoutPrice) {
|
|
311
|
+
liquidationData = (0, math_1.calculateLiquidationData)(assetsConfig, assetsData, userLiteData.realPrincipals, prices, poolConfig);
|
|
312
|
+
if (liquidationData.totalLimit != 0n) {
|
|
313
|
+
healthFactor = 1 - Number(liquidationData.totalDebt) / Number(liquidationData.totalLimit);
|
|
314
|
+
}
|
|
288
315
|
}
|
|
289
316
|
return {
|
|
290
317
|
...userLiteData,
|
|
@@ -297,6 +324,7 @@ function parseUserData(userLiteData, assetsData, assetsConfig, prices, poolConfi
|
|
|
297
324
|
limitUsed: limitUsed,
|
|
298
325
|
liquidationData: liquidationData,
|
|
299
326
|
healthFactor: healthFactor,
|
|
327
|
+
havePrincipalWithoutPrice: havePrincipalWithoutPrice
|
|
300
328
|
};
|
|
301
329
|
}
|
|
302
330
|
exports.parseUserData = parseUserData;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PoolAssetConfig } from
|
|
1
|
+
import { PoolAssetConfig } from '../types/Master';
|
|
2
2
|
export declare const ASSET_ID: {
|
|
3
3
|
TON: bigint;
|
|
4
4
|
USDT: bigint;
|
|
@@ -7,6 +7,9 @@ export declare const ASSET_ID: {
|
|
|
7
7
|
stTON: bigint;
|
|
8
8
|
tsTON: bigint;
|
|
9
9
|
uTON: bigint;
|
|
10
|
+
tgBTC: bigint;
|
|
11
|
+
USDe: bigint;
|
|
12
|
+
tsUSDe: bigint;
|
|
10
13
|
TONUSDT_DEDUST: bigint;
|
|
11
14
|
TONUSDT_STONFI: bigint;
|
|
12
15
|
TON_STORM: bigint;
|
|
@@ -14,6 +17,7 @@ export declare const ASSET_ID: {
|
|
|
14
17
|
NOT: bigint;
|
|
15
18
|
DOGS: bigint;
|
|
16
19
|
CATI: bigint;
|
|
20
|
+
EUSDT: bigint;
|
|
17
21
|
};
|
|
18
22
|
export declare const UNDEFINED_ASSET: PoolAssetConfig;
|
|
19
23
|
export declare const TON_MAINNET: PoolAssetConfig;
|
|
@@ -33,3 +37,7 @@ export declare const CATI_MAINNET: PoolAssetConfig;
|
|
|
33
37
|
export declare const DOGS_MAINNET: PoolAssetConfig;
|
|
34
38
|
export declare const NOT_MAINNET: PoolAssetConfig;
|
|
35
39
|
export declare const UTON_MAINNET: PoolAssetConfig;
|
|
40
|
+
export declare const TGBTC_TESTNET: PoolAssetConfig;
|
|
41
|
+
export declare const EUSDT_TESTNET: PoolAssetConfig;
|
|
42
|
+
export declare const USDE_MAINNET: PoolAssetConfig;
|
|
43
|
+
export declare const TSUSDE_MAINNET: PoolAssetConfig;
|