@evaafi/sdk 0.6.0 → 0.6.1
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/liquidation.d.ts +136 -0
- package/dist/api/liquidation.js +252 -0
- package/dist/api/math.d.ts +34 -7
- package/dist/api/math.js +100 -32
- package/dist/api/parser.js +4 -1
- package/dist/constants/assets.d.ts +12 -0
- package/dist/constants/assets.js +25 -13
- package/dist/constants/general.d.ts +3 -0
- package/dist/constants/general.js +5 -1
- package/dist/constants/pools.js +1 -1
- package/dist/contracts/MasterContract.d.ts +6 -1
- package/dist/contracts/MasterContract.js +17 -11
- package/dist/contracts/UserContract.d.ts +3 -2
- package/dist/contracts/UserContract.js +6 -5
- package/dist/index.d.ts +5 -4
- package/dist/index.js +20 -2
- package/dist/types/Master.d.ts +3 -0
- package/dist/types/User.d.ts +7 -0
- package/dist/utils/utils.d.ts +1 -0
- package/dist/utils/utils.js +6 -1
- package/package.json +3 -2
- package/src/api/liquidation.ts +346 -0
- package/src/api/math.ts +169 -76
- package/src/api/parser.ts +4 -1
- package/src/constants/assets.ts +26 -12
- package/src/constants/general.ts +7 -1
- package/src/constants/pools.ts +1 -1
- package/src/contracts/MasterContract.ts +21 -13
- package/src/contracts/UserContract.ts +8 -3
- package/src/index.ts +30 -6
- package/src/types/Master.ts +4 -1
- package/src/types/User.ts +8 -0
- package/src/utils/utils.ts +4 -0
|
@@ -20,7 +20,7 @@ import { parseMasterData } from '../api/parser';
|
|
|
20
20
|
import { MasterData, PoolAssetConfig, PoolConfig} from '../types/Master';
|
|
21
21
|
import { JettonWallet } from './JettonWallet';
|
|
22
22
|
import { getUserJettonWallet } from '../utils/userJettonWallet';
|
|
23
|
-
import { getPrices, isTonAsset, MAINNET_POOL_CONFIG } from '..';
|
|
23
|
+
import { getPrices, isTonAsset, isTonAssetId, MAINNET_POOL_CONFIG } from '..';
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Parameters for the Evaa contract
|
|
@@ -107,6 +107,7 @@ export type LiquidationParameters = LiquidationBaseData & {
|
|
|
107
107
|
includeUserCode: boolean;
|
|
108
108
|
priceData: Cell;
|
|
109
109
|
payload: Cell;
|
|
110
|
+
payloadForwardAmount: bigint;
|
|
110
111
|
};
|
|
111
112
|
|
|
112
113
|
/**
|
|
@@ -114,7 +115,7 @@ export type LiquidationParameters = LiquidationBaseData & {
|
|
|
114
115
|
*/
|
|
115
116
|
export class Evaa implements Contract {
|
|
116
117
|
readonly address: Address;
|
|
117
|
-
private
|
|
118
|
+
private _poolConfig: PoolConfig;
|
|
118
119
|
private readonly debug?: boolean;
|
|
119
120
|
private _data?: MasterData;
|
|
120
121
|
private lastSync = 0;
|
|
@@ -124,11 +125,18 @@ export class Evaa implements Contract {
|
|
|
124
125
|
* @param parameters Evaa contract parameters
|
|
125
126
|
*/
|
|
126
127
|
constructor(parameters?: EvaaParameters) {
|
|
127
|
-
this.
|
|
128
|
-
this.address = this.
|
|
128
|
+
this._poolConfig = parameters?.poolConfig ?? MAINNET_POOL_CONFIG;
|
|
129
|
+
this.address = this._poolConfig.masterAddress;
|
|
129
130
|
this.debug = parameters?.debug;
|
|
130
131
|
}
|
|
131
132
|
|
|
133
|
+
/**
|
|
134
|
+
* Returns pool config
|
|
135
|
+
*/
|
|
136
|
+
get poolConfig(): PoolConfig {
|
|
137
|
+
return this._poolConfig;
|
|
138
|
+
}
|
|
139
|
+
|
|
132
140
|
/**
|
|
133
141
|
* Create supply message
|
|
134
142
|
* @returns supply message as a cell
|
|
@@ -212,7 +220,7 @@ export class Evaa implements Contract {
|
|
|
212
220
|
// the exact amount of transferred jettons for liquidation is known
|
|
213
221
|
.storeUint(0, 64)
|
|
214
222
|
.storeRef(beginCell()
|
|
215
|
-
.storeUint(parameters.
|
|
223
|
+
.storeUint(parameters.payloadForwardAmount ?? 0, 64)
|
|
216
224
|
.storeRef(parameters.payload)
|
|
217
225
|
.endCell())
|
|
218
226
|
.storeRef(parameters.priceData)
|
|
@@ -230,7 +238,7 @@ export class Evaa implements Contract {
|
|
|
230
238
|
.storeInt(parameters.includeUserCode ? -1 : 0, 2)
|
|
231
239
|
.storeUint(parameters.liquidationAmount, 64)
|
|
232
240
|
.storeRef(beginCell()
|
|
233
|
-
.storeUint(parameters.
|
|
241
|
+
.storeUint(parameters.payloadForwardAmount ?? 0, 64)
|
|
234
242
|
.storeRef(parameters.payload)
|
|
235
243
|
.endCell())
|
|
236
244
|
.storeRef(parameters.priceData)
|
|
@@ -268,7 +276,7 @@ export class Evaa implements Contract {
|
|
|
268
276
|
* @returns user contract
|
|
269
277
|
*/
|
|
270
278
|
openUserContract(userAddress: Address): EvaaUser {
|
|
271
|
-
return EvaaUser.createFromAddress(this.calculateUserSCAddr(userAddress, this.
|
|
279
|
+
return EvaaUser.createFromAddress(this.calculateUserSCAddr(userAddress, this._poolConfig.lendingCode), this._poolConfig);
|
|
272
280
|
}
|
|
273
281
|
|
|
274
282
|
getOpenedUserContract(provider: ContractProvider, userAddress: Address): OpenedContract<EvaaUser> {
|
|
@@ -327,7 +335,7 @@ export class Evaa implements Contract {
|
|
|
327
335
|
) {
|
|
328
336
|
const message = this.createLiquidationMessage(parameters);
|
|
329
337
|
|
|
330
|
-
if (!
|
|
338
|
+
if (!isTonAssetId(parameters.loanAsset)) {
|
|
331
339
|
if (!via.address) {
|
|
332
340
|
throw Error('Via address is required for jetton liquidation');
|
|
333
341
|
}
|
|
@@ -373,10 +381,10 @@ export class Evaa implements Contract {
|
|
|
373
381
|
async getSync(provider: ContractProvider) {
|
|
374
382
|
const state = (await provider.getState()).state;
|
|
375
383
|
if (state.type === 'active') {
|
|
376
|
-
this._data = parseMasterData(state.data!.toString('base64'), this.
|
|
377
|
-
if (this._data.upgradeConfig.masterCodeVersion !== this.
|
|
384
|
+
this._data = parseMasterData(state.data!.toString('base64'), this._poolConfig.poolAssetsConfig, this._poolConfig.masterConstants);
|
|
385
|
+
if (this._data.upgradeConfig.masterCodeVersion !== this._poolConfig.masterVersion) {
|
|
378
386
|
throw Error(
|
|
379
|
-
`Outdated SDK pool version. It supports only master code version ${this.
|
|
387
|
+
`Outdated SDK pool version. It supports only master code version ${this._poolConfig.masterVersion}, but the current master code version is ${this._data.upgradeConfig.masterCodeVersion}`,
|
|
380
388
|
);
|
|
381
389
|
}
|
|
382
390
|
this.lastSync = Math.floor(Date.now() / 1000);
|
|
@@ -387,9 +395,9 @@ export class Evaa implements Contract {
|
|
|
387
395
|
|
|
388
396
|
async getPrices(provider: ContractProvider, endpoints?: string[]) {
|
|
389
397
|
if ((endpoints?.length ?? 0) > 0) {
|
|
390
|
-
return await getPrices(endpoints, this.
|
|
398
|
+
return await getPrices(endpoints, this._poolConfig);
|
|
391
399
|
} else {
|
|
392
|
-
return await getPrices(undefined, this.
|
|
400
|
+
return await getPrices(undefined, this._poolConfig);
|
|
393
401
|
}
|
|
394
402
|
}
|
|
395
403
|
}
|
|
@@ -20,6 +20,7 @@ export class EvaaUser implements Contract {
|
|
|
20
20
|
/**
|
|
21
21
|
* Create user contract wrapper from address
|
|
22
22
|
* @param address user contract address
|
|
23
|
+
* @param poolConfig pool config
|
|
23
24
|
*/
|
|
24
25
|
static createFromAddress(address: Address, poolConfig: PoolConfig = MAINNET_POOL_CONFIG) {
|
|
25
26
|
return new EvaaUser(address, poolConfig);
|
|
@@ -34,6 +35,7 @@ export class EvaaUser implements Contract {
|
|
|
34
35
|
provider: ContractProvider,
|
|
35
36
|
assetsData: ExtendedAssetsData,
|
|
36
37
|
assetsConfig: ExtendedAssetsConfig,
|
|
38
|
+
applyDust: boolean = false
|
|
37
39
|
) {
|
|
38
40
|
const state = (await provider.getState()).state;
|
|
39
41
|
if (state.type === 'active') {
|
|
@@ -41,7 +43,8 @@ export class EvaaUser implements Contract {
|
|
|
41
43
|
state.data!.toString('base64'),
|
|
42
44
|
assetsData,
|
|
43
45
|
assetsConfig,
|
|
44
|
-
this.poolConfig
|
|
46
|
+
this.poolConfig,
|
|
47
|
+
applyDust
|
|
45
48
|
);
|
|
46
49
|
this.lastSync = Math.floor(Date.now() / 1000);
|
|
47
50
|
} else {
|
|
@@ -96,6 +99,7 @@ export class EvaaUser implements Contract {
|
|
|
96
99
|
assetsData: ExtendedAssetsData,
|
|
97
100
|
assetsConfig: ExtendedAssetsConfig,
|
|
98
101
|
prices: Dictionary<bigint, bigint>,
|
|
102
|
+
applyDust: boolean = false
|
|
99
103
|
) {
|
|
100
104
|
const state = (await provider.getState()).state;
|
|
101
105
|
if (state.type === 'active') {
|
|
@@ -103,9 +107,10 @@ export class EvaaUser implements Contract {
|
|
|
103
107
|
state.data!.toString('base64'),
|
|
104
108
|
assetsData,
|
|
105
109
|
assetsConfig,
|
|
106
|
-
this.poolConfig
|
|
110
|
+
this.poolConfig,
|
|
111
|
+
applyDust
|
|
107
112
|
);
|
|
108
|
-
this._data = parseUserData(this._liteData, assetsData, assetsConfig, prices, this.poolConfig);
|
|
113
|
+
this._data = parseUserData(this._liteData, assetsData, assetsConfig, prices, this.poolConfig, applyDust);
|
|
109
114
|
this.lastSync = Math.floor(Date.now() / 1000);
|
|
110
115
|
} else {
|
|
111
116
|
this._data = { type: 'inactive' };
|
package/src/index.ts
CHANGED
|
@@ -12,9 +12,32 @@ export {
|
|
|
12
12
|
calculateMaximumWithdrawAmount,
|
|
13
13
|
presentValue,
|
|
14
14
|
calculateLiquidationData,
|
|
15
|
-
predictHealthFactor
|
|
15
|
+
predictHealthFactor,
|
|
16
|
+
calculateHealthParams,
|
|
17
|
+
BigMath,
|
|
16
18
|
} from './api/math';
|
|
17
19
|
|
|
20
|
+
export {
|
|
21
|
+
calculateLiquidationAmounts,
|
|
22
|
+
calculateMinCollateralByTransferredAmount,
|
|
23
|
+
isLiquidatable,
|
|
24
|
+
isBadDebt,
|
|
25
|
+
addReserve,
|
|
26
|
+
deductReserve,
|
|
27
|
+
addLiquidationBonus,
|
|
28
|
+
deductLiquidationBonus,
|
|
29
|
+
toAssetAmount,
|
|
30
|
+
toAssetWorth,
|
|
31
|
+
PreparedAssetInfo,
|
|
32
|
+
PreparedAssetInfoResult,
|
|
33
|
+
prepareAssetInfo,
|
|
34
|
+
findAssetById,
|
|
35
|
+
selectGreatestAssets,
|
|
36
|
+
calculateAssetsValues,
|
|
37
|
+
AssetsValues,
|
|
38
|
+
SelectedAssets,
|
|
39
|
+
} from './api/liquidation';
|
|
40
|
+
|
|
18
41
|
// Parser
|
|
19
42
|
export { createAssetData, createAssetConfig, parseMasterData, parseUserData, parseUserLiteData } from './api/parser';
|
|
20
43
|
|
|
@@ -28,7 +51,7 @@ export {
|
|
|
28
51
|
WithdrawParameters,
|
|
29
52
|
LiquidationBaseData,
|
|
30
53
|
LiquidationParameters,
|
|
31
|
-
Evaa
|
|
54
|
+
Evaa
|
|
32
55
|
} from './contracts/MasterContract';
|
|
33
56
|
export { EvaaUser } from './contracts/UserContract';
|
|
34
57
|
|
|
@@ -79,10 +102,11 @@ export {
|
|
|
79
102
|
export {
|
|
80
103
|
MAINNET_POOL_CONFIG,
|
|
81
104
|
TESTNET_POOL_CONFIG,
|
|
82
|
-
MAINNET_LP_POOL_CONFIG
|
|
105
|
+
MAINNET_LP_POOL_CONFIG
|
|
83
106
|
} from './constants/pools';
|
|
84
107
|
|
|
85
108
|
export {
|
|
109
|
+
ASSET_ID,
|
|
86
110
|
UNDEFINED_ASSET,
|
|
87
111
|
TON_MAINNET,
|
|
88
112
|
USDT_MAINNET,
|
|
@@ -95,11 +119,11 @@ export {
|
|
|
95
119
|
TSTON_MAINNET,
|
|
96
120
|
JUSDT_TESTNET,
|
|
97
121
|
JUSDC_TESTNET,
|
|
98
|
-
STTON_TESTNET
|
|
122
|
+
STTON_TESTNET
|
|
99
123
|
} from './constants/assets';
|
|
100
124
|
|
|
101
|
-
export * from './constants/assets'
|
|
102
|
-
export * from './utils/utils'
|
|
125
|
+
export * from './constants/assets';
|
|
126
|
+
export * from './utils/utils';
|
|
103
127
|
|
|
104
128
|
// Utils
|
|
105
129
|
export { getLastSentBoc, getTonConnectSender } from './utils/tonConnectSender';
|
package/src/types/Master.ts
CHANGED
|
@@ -8,7 +8,10 @@ export type MasterConstants = {
|
|
|
8
8
|
ASSET_LIQUIDATION_RESERVE_FACTOR_SCALE: bigint,
|
|
9
9
|
ASSET_LIQUIDATION_THRESHOLD_SCALE: bigint,
|
|
10
10
|
ASSET_LIQUIDATION_BONUS_SCALE: bigint,
|
|
11
|
-
ASSET_ORIGINATION_FEE_SCALE: bigint
|
|
11
|
+
ASSET_ORIGINATION_FEE_SCALE: bigint,
|
|
12
|
+
ASSET_SRATE_SCALE: bigint,
|
|
13
|
+
ASSET_BRATE_SCALE: bigint,
|
|
14
|
+
COLLATERAL_WORTH_THRESHOLD: bigint,
|
|
12
15
|
};
|
|
13
16
|
|
|
14
17
|
export type PoolAssetsConfig = PoolAssetConfig[];
|
package/src/types/User.ts
CHANGED
|
@@ -74,6 +74,14 @@ export type UserRewards = {
|
|
|
74
74
|
trackingAccured: bigint;
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
+
export type HealthParamsArgs = {
|
|
78
|
+
assetsData: ExtendedAssetsData;
|
|
79
|
+
assetsConfig: ExtendedAssetsConfig;
|
|
80
|
+
principals: Dictionary<bigint, bigint>;
|
|
81
|
+
prices: Dictionary<bigint, bigint>;
|
|
82
|
+
poolConfig: PoolConfig;
|
|
83
|
+
}
|
|
84
|
+
|
|
77
85
|
export enum BalanceChangeType {
|
|
78
86
|
Borrow = 0,
|
|
79
87
|
Repay = 1,
|
package/src/utils/utils.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { PoolAssetConfig } from "../types/Master";
|
|
2
|
+
import { ASSET_ID } from '../constants/assets';
|
|
2
3
|
|
|
3
4
|
export function isTonAsset(asset: PoolAssetConfig) {
|
|
4
5
|
return asset.name === 'TON';
|
|
5
6
|
}
|
|
6
7
|
|
|
8
|
+
export function isTonAssetId(assetId: bigint) {
|
|
9
|
+
return assetId === ASSET_ID.TON;
|
|
10
|
+
}
|