@evaafi/sdk 0.5.6 → 0.6.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/helpers.js +3 -2
- package/dist/api/math.d.ts +1 -10
- package/dist/api/math.js +32 -76
- package/dist/api/parser.d.ts +2 -1
- package/dist/api/parser.js +46 -57
- package/dist/api/prices.d.ts +2 -1
- package/dist/api/prices.js +29 -19
- package/dist/config.d.ts +1 -2
- package/dist/config.js +2 -3
- package/dist/constants/general.d.ts +7 -5
- package/dist/constants/general.js +29 -10
- package/dist/constants/pools.js +6 -3
- package/dist/constants.d.ts +35 -6
- package/dist/constants.js +47 -92
- package/dist/contracts/MasterContract.d.ts +9 -3
- package/dist/contracts/MasterContract.js +13 -8
- package/dist/contracts/UserContract.d.ts +2 -2
- package/dist/contracts/UserContract.js +5 -5
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -1
- package/dist/types/Common.d.ts +9 -0
- package/dist/types/Master.d.ts +23 -4
- package/dist/types/User.d.ts +4 -1
- package/dist/utils/merkleProof.js +4 -3
- package/dist/utils/priceUtils.d.ts +2 -2
- package/dist/utils/priceUtils.js +16 -16
- package/dist/utils/sha256BigInt.js +2 -1
- package/dist/utils/tonConnectSender.js +3 -2
- package/dist/utils/userJettonWallet.js +2 -1
- package/dist/utils/utils.js +2 -1
- package/package.json +2 -2
- package/src/api/math.ts +22 -84
- package/src/api/parser.ts +37 -52
- package/src/api/prices.ts +33 -57
- package/src/config.ts +1 -0
- package/src/constants/general.ts +32 -9
- package/src/constants/pools.ts +7 -4
- package/src/contracts/MasterContract.ts +23 -17
- package/src/contracts/UserContract.ts +7 -3
- package/src/index.ts +4 -0
- package/src/types/Common.ts +10 -0
- package/src/types/Master.ts +23 -9
- package/src/types/User.ts +2 -3
- package/src/utils/merkleProof.ts +141 -0
- package/src/utils/priceUtils.ts +177 -0
package/src/api/parser.ts
CHANGED
|
@@ -6,10 +6,8 @@ import {
|
|
|
6
6
|
calculateAssetData,
|
|
7
7
|
calculateLiquidationData,
|
|
8
8
|
calculateMaximumWithdrawAmount,
|
|
9
|
-
calculateMaximumWithdrawAmountOld,
|
|
10
9
|
calculatePresentValue,
|
|
11
10
|
getAvailableToBorrow,
|
|
12
|
-
isV5MainPoolContract,
|
|
13
11
|
presentValue,
|
|
14
12
|
} from './math';
|
|
15
13
|
import { loadMaybeMyRef, loadMyRef } from './helpers';
|
|
@@ -17,8 +15,7 @@ import { BalanceType, UserBalance, UserData, UserLiteData, UserRewards } from '.
|
|
|
17
15
|
import { MAINNET_POOL_CONFIG, TESTNET_POOL_CONFIG } from '../constants/pools';
|
|
18
16
|
import { basename } from 'path';
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
/* export function createUserRewards(): DictionaryValue<UserRewards> {
|
|
18
|
+
export function createUserRewards(): DictionaryValue<UserRewards> {
|
|
22
19
|
return {
|
|
23
20
|
serialize: (src: any, buidler: any) => {
|
|
24
21
|
buidler.storeUint(src.trackingIndex, 64);
|
|
@@ -30,7 +27,7 @@ import { basename } from 'path';
|
|
|
30
27
|
return { trackingIndex, trackingAccured };
|
|
31
28
|
},
|
|
32
29
|
};
|
|
33
|
-
}
|
|
30
|
+
}
|
|
34
31
|
|
|
35
32
|
export function createAssetData(): DictionaryValue<AssetData> {
|
|
36
33
|
return {
|
|
@@ -41,10 +38,11 @@ export function createAssetData(): DictionaryValue<AssetData> {
|
|
|
41
38
|
buidler.storeUint(src.totalBorrow, 64);
|
|
42
39
|
buidler.storeUint(src.lastAccural, 32);
|
|
43
40
|
buidler.storeUint(src.balance, 64);
|
|
44
|
-
/* Will be in v6
|
|
45
41
|
buidler.storeUint(src.trackingSupplyIndex, 64);
|
|
46
42
|
buidler.storeUint(src.trackingBorrowIndex, 64);
|
|
47
|
-
|
|
43
|
+
if (src.awaitedSupply) {
|
|
44
|
+
buidler.storeUint(src.awaitedSupply, 64);
|
|
45
|
+
}
|
|
48
46
|
},
|
|
49
47
|
parse: (src: Slice) => {
|
|
50
48
|
const sRate = BigInt(src.loadInt(64));
|
|
@@ -53,13 +51,15 @@ export function createAssetData(): DictionaryValue<AssetData> {
|
|
|
53
51
|
const totalBorrow = BigInt(src.loadInt(64));
|
|
54
52
|
const lastAccural = BigInt(src.loadInt(32));
|
|
55
53
|
const balance = BigInt(src.loadInt(64));
|
|
56
|
-
/* Will be in v6
|
|
57
54
|
const trackingSupplyIndex = BigInt(src.loadUint(64));
|
|
58
55
|
const trackingBorrowIndex = BigInt(src.loadUint(64));
|
|
59
|
-
|
|
56
|
+
let awaitedSupply: bigint | undefined = undefined;
|
|
57
|
+
if (src.remainingBits == 64) {
|
|
58
|
+
awaitedSupply = BigInt(src.loadUint(64));
|
|
59
|
+
}
|
|
60
60
|
|
|
61
|
-
return { sRate, bRate, totalSupply, totalBorrow, lastAccural, balance, trackingSupplyIndex, trackingBorrowIndex,
|
|
62
|
-
|
|
61
|
+
return { sRate, bRate, totalSupply, totalBorrow, lastAccural, balance, trackingSupplyIndex, trackingBorrowIndex, awaitedSupply};
|
|
62
|
+
},
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
|
|
@@ -83,10 +83,9 @@ export function createAssetConfig(): DictionaryValue<AssetConfig> {
|
|
|
83
83
|
refBuild.storeUint(src.maxTotalSupply, 64);
|
|
84
84
|
refBuild.storeUint(src.reserveFactor, 16);
|
|
85
85
|
refBuild.storeUint(src.liquidationReserveFactor, 16);
|
|
86
|
-
/* Will be in v6
|
|
87
86
|
refBuild.storeUint(src.minPrincipalForRewards, 64);
|
|
88
87
|
refBuild.storeUint(src.baseTrackingSupplySpeed, 64);
|
|
89
|
-
refBuild.storeUint(src.baseTrackingBorrowSpeed, 64);
|
|
88
|
+
refBuild.storeUint(src.baseTrackingBorrowSpeed, 64);
|
|
90
89
|
builder.storeRef(refBuild.endCell());
|
|
91
90
|
},
|
|
92
91
|
parse: (src: Slice) => {
|
|
@@ -107,10 +106,9 @@ export function createAssetConfig(): DictionaryValue<AssetConfig> {
|
|
|
107
106
|
const maxTotalSupply = ref.loadUintBig(64);
|
|
108
107
|
const reserveFactor = ref.loadUintBig(16);
|
|
109
108
|
const liquidationReserveFactor = ref.loadUintBig(16);
|
|
110
|
-
/* Will be in v6
|
|
111
109
|
const minPrincipalForRewards = ref.loadUintBig(64);
|
|
112
110
|
const baseTrackingSupplySpeed = ref.loadUintBig(64);
|
|
113
|
-
const baseTrackingBorrowSpeed = ref.loadUintBig(64);
|
|
111
|
+
const baseTrackingBorrowSpeed = ref.loadUintBig(64);
|
|
114
112
|
|
|
115
113
|
return {
|
|
116
114
|
oracle,
|
|
@@ -129,10 +127,9 @@ export function createAssetConfig(): DictionaryValue<AssetConfig> {
|
|
|
129
127
|
maxTotalSupply,
|
|
130
128
|
reserveFactor,
|
|
131
129
|
liquidationReserveFactor,
|
|
132
|
-
/* Will be in v6
|
|
133
130
|
minPrincipalForRewards,
|
|
134
131
|
baseTrackingSupplySpeed,
|
|
135
|
-
baseTrackingBorrowSpeed
|
|
132
|
+
baseTrackingBorrowSpeed
|
|
136
133
|
};
|
|
137
134
|
},
|
|
138
135
|
};
|
|
@@ -150,16 +147,15 @@ export function parseMasterData(masterDataBOC: string, poolAssetsConfig: PoolAss
|
|
|
150
147
|
updateTime: upgradeConfigParser.loadUint(64),
|
|
151
148
|
freezeTime: upgradeConfigParser.loadUint(64),
|
|
152
149
|
userCode: loadMyRef(upgradeConfigParser),
|
|
153
|
-
blankCode: loadMyRef(upgradeConfigParser),
|
|
154
150
|
newMasterCode: loadMaybeMyRef(upgradeConfigParser),
|
|
155
151
|
newUserCode: loadMaybeMyRef(upgradeConfigParser),
|
|
156
152
|
};
|
|
157
|
-
upgradeConfigParser.endParse();
|
|
153
|
+
// upgradeConfigParser.endParse(); todo fix with new testnet contract
|
|
158
154
|
|
|
159
155
|
const masterConfigSlice = masterSlice.loadRef().beginParse();
|
|
160
|
-
|
|
161
156
|
const assetsConfigDict = masterConfigSlice.loadDict(Dictionary.Keys.BigUint(256), createAssetConfig());
|
|
162
157
|
const assetsDataDict = masterSlice.loadDict(Dictionary.Keys.BigUint(256), createAssetData());
|
|
158
|
+
|
|
163
159
|
const assetsExtendedData = Dictionary.empty<bigint, ExtendedAssetData>();
|
|
164
160
|
const assetsReserves = Dictionary.empty<bigint, bigint>();
|
|
165
161
|
const apy = {
|
|
@@ -171,15 +167,16 @@ export function parseMasterData(masterDataBOC: string, poolAssetsConfig: PoolAss
|
|
|
171
167
|
const assetData = calculateAssetData(assetsConfigDict, assetsDataDict, asset.assetId, masterConstants);
|
|
172
168
|
assetsExtendedData.set(asset.assetId, assetData);
|
|
173
169
|
}
|
|
174
|
-
|
|
175
170
|
const masterConfig = {
|
|
176
171
|
ifActive: masterConfigSlice.loadInt(8),
|
|
177
172
|
admin: masterConfigSlice.loadAddress(),
|
|
178
|
-
|
|
173
|
+
oraclesInfo: {
|
|
174
|
+
numOracles: masterConfigSlice.loadUint(16),
|
|
175
|
+
threshold: masterConfigSlice.loadUint(16),
|
|
176
|
+
oracles: loadMaybeMyRef(masterConfigSlice)
|
|
177
|
+
},
|
|
179
178
|
tokenKeys: loadMaybeMyRef(masterConfigSlice),
|
|
180
|
-
walletToMaster: loadMaybeMyRef(masterConfigSlice),
|
|
181
179
|
};
|
|
182
|
-
|
|
183
180
|
masterConfigSlice.endParse();
|
|
184
181
|
|
|
185
182
|
for (const [_, asset] of Object.entries(poolAssetsConfig)) {
|
|
@@ -220,11 +217,7 @@ export function parseUserLiteData(
|
|
|
220
217
|
const userAddress = userSlice.loadAddress();
|
|
221
218
|
const principalsDict = userSlice.loadDict(Dictionary.Keys.BigUint(256), Dictionary.Values.BigInt(64));
|
|
222
219
|
const userState = userSlice.loadInt(64);
|
|
223
|
-
|
|
224
|
-
const trackingBorrowIndex = userSlice.loadUintBig(64);
|
|
225
|
-
const dutchAuctionStart = userSlice.loadUint(32);
|
|
226
|
-
const backupCell = loadMyRef(userSlice);
|
|
227
|
-
/* Will be in v6
|
|
220
|
+
|
|
228
221
|
let trackingSupplyIndex = 0n;
|
|
229
222
|
let trackingBorrowIndex = 0n;
|
|
230
223
|
let dutchAuctionStart = 0;
|
|
@@ -243,9 +236,8 @@ export function parseUserLiteData(
|
|
|
243
236
|
backupCell1 = userSlice.loadMaybeRef();
|
|
244
237
|
backupCell2 = userSlice.loadMaybeRef();
|
|
245
238
|
}
|
|
246
|
-
|
|
239
|
+
|
|
247
240
|
userSlice.endParse();
|
|
248
|
-
const isV5Main = isV5MainPoolContract(poolConfig);
|
|
249
241
|
const userBalances = Dictionary.empty<bigint, UserBalance>();
|
|
250
242
|
|
|
251
243
|
for (const [_, asset] of Object.entries(poolAssetsConfig)) {
|
|
@@ -254,9 +246,8 @@ export function parseUserLiteData(
|
|
|
254
246
|
|
|
255
247
|
let principal = principalsDict.get(asset.assetId) || 0n;
|
|
256
248
|
let balance = presentValue(assetData.sRate, assetData.bRate, principal, masterConstants);
|
|
257
|
-
let leftBorder = isV5Main ? balance.amount : principal;
|
|
258
249
|
|
|
259
|
-
if (applyDust && (principal > 0 && (
|
|
250
|
+
if (applyDust && (principal > 0 && (principal < assetConfig.dust))) {
|
|
260
251
|
principal = 0n;
|
|
261
252
|
balance = {
|
|
262
253
|
amount: 0n,
|
|
@@ -279,10 +270,10 @@ export function parseUserLiteData(
|
|
|
279
270
|
trackingBorrowIndex: trackingBorrowIndex,
|
|
280
271
|
dutchAuctionStart: dutchAuctionStart,
|
|
281
272
|
backupCell: backupCell,
|
|
282
|
-
|
|
273
|
+
|
|
283
274
|
rewards: rewards,
|
|
284
275
|
backupCell1: backupCell1,
|
|
285
|
-
backupCell2: backupCell2,
|
|
276
|
+
backupCell2: backupCell2,
|
|
286
277
|
};
|
|
287
278
|
}
|
|
288
279
|
|
|
@@ -302,7 +293,6 @@ export function parseUserData(
|
|
|
302
293
|
|
|
303
294
|
let supplyBalance = 0n;
|
|
304
295
|
let borrowBalance = 0n;
|
|
305
|
-
const isV5Main = isV5MainPoolContract(poolConfig);
|
|
306
296
|
|
|
307
297
|
for (const [_, asset] of Object.entries(poolAssetsConfig)) {
|
|
308
298
|
const assetData = assetsData.get(asset.assetId) as ExtendedAssetData;
|
|
@@ -310,9 +300,8 @@ export function parseUserData(
|
|
|
310
300
|
|
|
311
301
|
let principal = userLiteData.principals.get(asset.assetId) || 0n;
|
|
312
302
|
const balance = presentValue(assetData.sRate, assetData.bRate, principal, masterConstants);
|
|
313
|
-
let leftBorder = isV5Main ? balance.amount : principal;
|
|
314
303
|
|
|
315
|
-
if (applyDust && (principal > 0 && (
|
|
304
|
+
if (applyDust && (principal > 0 && (principal < assetConfig.dust))) {
|
|
316
305
|
principal = 0n;
|
|
317
306
|
userLiteData.principals.set(asset.assetId, 0n);
|
|
318
307
|
}
|
|
@@ -339,22 +328,15 @@ export function parseUserData(
|
|
|
339
328
|
const balance = userLiteData.balances.get(asset.assetId) as UserBalance;
|
|
340
329
|
|
|
341
330
|
if (balance.type === BalanceType.supply) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
);
|
|
347
|
-
}
|
|
348
|
-
else {
|
|
349
|
-
withdrawalLimits.set(
|
|
350
|
-
asset.assetId,
|
|
351
|
-
calculateMaximumWithdrawAmount(assetsConfig, assetsData, userLiteData.principals, prices, masterConstants, asset.assetId)
|
|
352
|
-
);
|
|
353
|
-
}
|
|
331
|
+
withdrawalLimits.set(
|
|
332
|
+
asset.assetId,
|
|
333
|
+
bigIntMin(calculateMaximumWithdrawAmount(assetsConfig, assetsData, userLiteData.principals, prices, masterConstants, asset.assetId), assetData.balance)
|
|
334
|
+
);
|
|
354
335
|
}
|
|
336
|
+
|
|
355
337
|
borrowLimits.set(
|
|
356
338
|
asset.assetId,
|
|
357
|
-
bigIntMin((availableToBorrow * 10n ** assetConfig.decimals) / prices.get(asset.assetId)!, assetData.balance),
|
|
339
|
+
bigIntMax(0n, bigIntMin((availableToBorrow * 10n ** assetConfig.decimals) / prices.get(asset.assetId)!, assetData.balance, assetData.totalSupply - assetData.totalBorrow)),
|
|
358
340
|
);
|
|
359
341
|
}
|
|
360
342
|
|
|
@@ -365,7 +347,10 @@ export function parseUserData(
|
|
|
365
347
|
: Number(BigInt(1e9) - (availableToBorrow * BigInt(1e9)) / (borrowBalance + availableToBorrow)) / 1e7;
|
|
366
348
|
|
|
367
349
|
const liquidationData = calculateLiquidationData(assetsConfig, assetsData, userLiteData.principals, prices, poolConfig);
|
|
368
|
-
|
|
350
|
+
let healthFactor = 1;
|
|
351
|
+
if (liquidationData.totalLimit != 0n) {
|
|
352
|
+
healthFactor = 1 - Number(liquidationData.totalDebt) / Number(liquidationData.totalLimit);
|
|
353
|
+
}
|
|
369
354
|
|
|
370
355
|
return {
|
|
371
356
|
...userLiteData,
|
package/src/api/prices.ts
CHANGED
|
@@ -1,69 +1,45 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PriceData } from '../types/Common';
|
|
3
|
-
import {
|
|
1
|
+
import { Dictionary } from '@ton/core';
|
|
2
|
+
import { PriceData, RawPriceData } from '../types/Common';
|
|
3
|
+
import { getMedianPrice, loadPrices, packAssetsData, packOraclesData, packPrices, parsePrices, verifyPrices } from '../utils/priceUtils';
|
|
4
|
+
import { OracleNFT, PoolConfig } from '../types/Master';
|
|
5
|
+
import { MAINNET_POOL_CONFIG } from '../constants/pools';
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
export async function getPrices(endpoints: String[] = ["api.stardust-mainnet.iotaledger.net", "iota.evaa.finance"], poolConfig: PoolConfig = MAINNET_POOL_CONFIG): Promise<PriceData> {
|
|
8
|
+
if (endpoints.length == 0) {
|
|
9
|
+
throw new Error("Empty endpoint list");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const prices = await Promise.all(poolConfig.oracles.map(async x => await parsePrices(await loadPrices(x.address, endpoints), x.id)));
|
|
13
|
+
|
|
14
|
+
let acceptedPrices: RawPriceData[] = prices.filter(verifyPrices(poolConfig.poolAssetsConfig));
|
|
10
15
|
|
|
11
|
-
type OutputData = {
|
|
12
|
-
metadata: {
|
|
13
|
-
blockId: string;
|
|
14
|
-
transactionId: string;
|
|
15
|
-
outputIndex: number;
|
|
16
|
-
isSpent: boolean;
|
|
17
|
-
milestoneIndexSpent: number;
|
|
18
|
-
milestoneTimestampSpent: number;
|
|
19
|
-
transactionIdSpent: string;
|
|
20
|
-
milestoneIndexBooked: number;
|
|
21
|
-
milestoneTimestampBooked: number;
|
|
22
|
-
ledgerIndex: number;
|
|
23
|
-
};
|
|
24
|
-
output: {
|
|
25
|
-
type: number;
|
|
26
|
-
amount: string;
|
|
27
|
-
nftId: string;
|
|
28
|
-
unlockConditions: {
|
|
29
|
-
type: number;
|
|
30
|
-
address: {
|
|
31
|
-
type: number;
|
|
32
|
-
pubKeyHash: string;
|
|
33
|
-
};
|
|
34
|
-
}[];
|
|
35
|
-
features: {
|
|
36
|
-
type: number;
|
|
37
|
-
data: string;
|
|
38
|
-
}[];
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
16
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
17
|
+
if (acceptedPrices.length < poolConfig.minimalOracles) {
|
|
18
|
+
throw new Error("Prices are outdated");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (acceptedPrices.length > poolConfig.minimalOracles && acceptedPrices.length % 2 == 0) {
|
|
22
|
+
acceptedPrices = acceptedPrices.slice(0, acceptedPrices.length - 1); // to reduce fees, MINIMAL_ORACLES_NUMBER is odd
|
|
23
|
+
}
|
|
45
24
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
25
|
+
if (acceptedPrices.length != poolConfig.minimalOracles) {
|
|
26
|
+
const sortedByTimestamp = acceptedPrices.slice().sort((a, b) => b.timestamp - a.timestamp);
|
|
27
|
+
const newerPrices = sortedByTimestamp.slice(0, poolConfig.minimalOracles);
|
|
28
|
+
acceptedPrices = newerPrices.sort((a, b) => a.oracleId - b.oracleId);
|
|
29
|
+
}
|
|
51
30
|
|
|
52
|
-
result = await fetch(`https://${endpoint}/api/core/v2/outputs/${outputId.items[0]}`, {
|
|
53
|
-
headers: { accept: 'application/json' },
|
|
54
|
-
});
|
|
55
31
|
|
|
56
|
-
|
|
32
|
+
const medianData = poolConfig.poolAssetsConfig.map(asset => ({ assetId: asset.assetId, medianPrice: getMedianPrice(acceptedPrices, asset.assetId)}));
|
|
33
|
+
const packedMedianData = packAssetsData(medianData);
|
|
57
34
|
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
);
|
|
35
|
+
const oraclesData = acceptedPrices.map(x => ({oracle: {id: x.oracleId, pubkey: x.pubkey}, data: {timestamp: x.timestamp, prices: x.dict}, signature: x.signature}));
|
|
36
|
+
const packedOracleData = packOraclesData(oraclesData, poolConfig.poolAssetsConfig.map(x => x.assetId));
|
|
61
37
|
|
|
62
|
-
const
|
|
63
|
-
|
|
38
|
+
const dict = Dictionary.empty<bigint, bigint>();
|
|
39
|
+
medianData.forEach(x => dict.set(x.assetId, x.medianPrice));
|
|
64
40
|
|
|
65
41
|
return {
|
|
66
|
-
dict:
|
|
67
|
-
dataCell:
|
|
42
|
+
dict: dict,
|
|
43
|
+
dataCell: packPrices(packedMedianData, packedOracleData)
|
|
68
44
|
};
|
|
69
45
|
}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const TTL_ORACLE_DATA_SEC = 120; // todo back to 120
|
package/src/constants/general.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Address, Cell, toNano } from '@ton/core';
|
|
2
2
|
import { sha256Hash } from '../utils/sha256BigInt';
|
|
3
|
+
import { OracleNFT } from '../types/Master';
|
|
3
4
|
|
|
4
5
|
export const MASTER_CONSTANTS = {
|
|
5
6
|
FACTOR_SCALE: BigInt(1e12),
|
|
@@ -14,15 +15,37 @@ export const MASTER_CONSTANTS = {
|
|
|
14
15
|
|
|
15
16
|
export const NULL_ADDRESS = Address.parse('UQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJKZ');
|
|
16
17
|
|
|
18
|
+
|
|
17
19
|
export const EVAA_MASTER_MAINNET = Address.parse('EQC8rUZqR_pWV1BylWUlPNBzyiTYVoBEmQkMIQDZXICfnuRr');
|
|
18
|
-
export const MAINNET_VERSION =
|
|
19
|
-
export const EVAA_MASTER_TESTNET = Address.parse('
|
|
20
|
-
export const TESTNET_VERSION =
|
|
20
|
+
export const MAINNET_VERSION = 6;
|
|
21
|
+
export const EVAA_MASTER_TESTNET = Address.parse('EQDLsg3w-iBj26Gww7neYoJAxiT2t77Zo8ro56b0yuHsPp3C');
|
|
22
|
+
export const TESTNET_VERSION = 0;
|
|
21
23
|
export const EVAA_LP_MAINNET = Address.parse('EQBIlZX2URWkXCSg3QF2MJZU-wC5XkBoLww-hdWk2G37Jc6N');
|
|
22
|
-
export const EVAA_LP_MAINNET_VERSION =
|
|
24
|
+
export const EVAA_LP_MAINNET_VERSION = 2;
|
|
25
|
+
|
|
26
|
+
export const ORACLES_MAINNET: OracleNFT[] = [
|
|
27
|
+
{id: 0, address: '0xd3a8c0b9fd44fd25a49289c631e3ac45689281f2f8cf0744400b4c65bed38e5d'},
|
|
28
|
+
{id: 1, address: '0x2c21cabdaa89739de16bde7bc44e86401fac334a3c7e55305fe5e7563043e191'},
|
|
29
|
+
{id: 2, address: '0x2eb258ce7b5d02466ab8a178ad8b0ba6ffa7b58ef21de3dc3b6dd359a1e16af0'},
|
|
30
|
+
{id: 3, address: '0xf9a0769954b4430bca95149fb3d876deb7799d8f74852e0ad4ccc5778ce68b52'},
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
export const ORACLES_TESTNET: OracleNFT[] = [
|
|
34
|
+
{id: 0, address: '0x3bb147a37b7a7f874c39320440f352bddd2c9337e31a778731910f0266391650'},
|
|
35
|
+
{id: 1, address: '0x676767e93b05a21aec9023a65f73cffe1c725709c3c964a7c3f0fd4229089bfe'},
|
|
36
|
+
{id: 2, address: '0x9c9e65951b0c5920c286bdb3410babcaf21f85bc9c90c13172988630f1244e0f'},
|
|
37
|
+
{id: 3, address: '0x9dcf880229bfb68d7344fd294624b64f1e0b43b9d858f0fdb1bc6434616c08f5'},
|
|
38
|
+
{id: 4, address: '0x4d1afcf7c0426ca61c405c8cfaef0053a0f0d143740ffed04c8716beb99cd614'},
|
|
39
|
+
{id: 5, address: '0x11c6baa608ed10733051fd74134441d384e471722fbc496b43ea4e3c6652485f'},
|
|
40
|
+
{id: 6, address: '0x2b685672f38dc2fce59013bb740bf24c6037049a1c267bb3b5f6f55d5b195f5f'},
|
|
41
|
+
];
|
|
23
42
|
|
|
24
|
-
export const
|
|
25
|
-
|
|
43
|
+
export const ORACLES_LP: OracleNFT[] = [
|
|
44
|
+
{id: 0, address: '0xd3a8c0b9fd44fd25a49289c631e3ac45689281f2f8cf0744400b4c65bed38e5d'},
|
|
45
|
+
{id: 1, address: '0x2c21cabdaa89739de16bde7bc44e86401fac334a3c7e55305fe5e7563043e191'},
|
|
46
|
+
{id: 2, address: '0x2eb258ce7b5d02466ab8a178ad8b0ba6ffa7b58ef21de3dc3b6dd359a1e16af0'},
|
|
47
|
+
{id: 3, address: '0xf9a0769954b4430bca95149fb3d876deb7799d8f74852e0ad4ccc5778ce68b52'},
|
|
48
|
+
];
|
|
26
49
|
|
|
27
50
|
export const LENDING_CODE = Cell.fromBoc(
|
|
28
51
|
Buffer.from(
|
|
@@ -47,9 +70,9 @@ export const OPCODES = {
|
|
|
47
70
|
|
|
48
71
|
export const FEES = {
|
|
49
72
|
SUPPLY: toNano('0.3'),
|
|
50
|
-
WITHDRAW: toNano('0.
|
|
51
|
-
SUPPLY_JETTON: toNano('0.
|
|
52
|
-
SUPPLY_JETTON_FWD: toNano('0.
|
|
73
|
+
WITHDRAW: toNano('0.35'),
|
|
74
|
+
SUPPLY_JETTON: toNano('0.35'),
|
|
75
|
+
SUPPLY_JETTON_FWD: toNano('0.3'),
|
|
53
76
|
LIQUIDATION: toNano('0.8'),
|
|
54
77
|
LIQUIDATION_JETTON: toNano('1'),
|
|
55
78
|
LIQUIDATION_JETTON_FWD: toNano('0.8'),
|
package/src/constants/pools.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Address } from "@ton/core";
|
|
2
2
|
import { JUSDC_MAINNET, JUSDC_TESTNET, JUSDT_MAINNET, JUSDT_TESTNET, STTON_MAINNET, STTON_TESTNET, TON_MAINNET, TON_STORM_MAINNET, TONUSDT_DEDUST_MAINNET, TSTON_MAINNET, USDT_MAINNET, USDT_STORM_MAINNET } from "./assets";
|
|
3
3
|
import { PoolConfig } from "../types/Master";
|
|
4
|
-
import { EVAA_MASTER_MAINNET, EVAA_MASTER_TESTNET, LENDING_CODE, MAINNET_VERSION, MASTER_CONSTANTS,
|
|
4
|
+
import { EVAA_MASTER_MAINNET, EVAA_MASTER_TESTNET, LENDING_CODE, MAINNET_VERSION, MASTER_CONSTANTS, TESTNET_VERSION, EVAA_LP_MAINNET, EVAA_LP_MAINNET_VERSION, ORACLES_MAINNET, ORACLES_LP, ORACLES_TESTNET } from "./general";
|
|
5
5
|
|
|
6
6
|
export const MAINNET_POOL_CONFIG: PoolConfig = {
|
|
7
7
|
masterAddress: EVAA_MASTER_MAINNET,
|
|
8
8
|
masterVersion: MAINNET_VERSION,
|
|
9
9
|
masterConstants: MASTER_CONSTANTS,
|
|
10
|
-
|
|
10
|
+
oracles: ORACLES_MAINNET,
|
|
11
|
+
minimalOracles: 3,
|
|
11
12
|
poolAssetsConfig: [
|
|
12
13
|
TON_MAINNET,
|
|
13
14
|
JUSDT_MAINNET,
|
|
@@ -23,7 +24,8 @@ export const TESTNET_POOL_CONFIG: PoolConfig = {
|
|
|
23
24
|
masterAddress: EVAA_MASTER_TESTNET,
|
|
24
25
|
masterVersion: TESTNET_VERSION,
|
|
25
26
|
masterConstants: MASTER_CONSTANTS,
|
|
26
|
-
|
|
27
|
+
oracles: ORACLES_TESTNET,
|
|
28
|
+
minimalOracles: 5,
|
|
27
29
|
poolAssetsConfig: [
|
|
28
30
|
TON_MAINNET,
|
|
29
31
|
JUSDT_TESTNET,
|
|
@@ -37,7 +39,8 @@ export const MAINNET_LP_POOL_CONFIG: PoolConfig = {
|
|
|
37
39
|
masterAddress: EVAA_LP_MAINNET,
|
|
38
40
|
masterVersion: EVAA_LP_MAINNET_VERSION,
|
|
39
41
|
masterConstants: MASTER_CONSTANTS,
|
|
40
|
-
|
|
42
|
+
oracles: ORACLES_LP,
|
|
43
|
+
minimalOracles: 3,
|
|
41
44
|
poolAssetsConfig: [
|
|
42
45
|
TON_MAINNET,
|
|
43
46
|
USDT_MAINNET,
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
Sender,
|
|
9
9
|
SendMode,
|
|
10
10
|
storeStateInit,
|
|
11
|
+
toNano,
|
|
11
12
|
} from '@ton/core';
|
|
12
13
|
import {
|
|
13
14
|
FEES,
|
|
@@ -47,10 +48,9 @@ export type SupplyParameters = {
|
|
|
47
48
|
userAddress: Address;
|
|
48
49
|
responseAddress?: Address;
|
|
49
50
|
forwardAmount?: bigint;
|
|
50
|
-
/* Will be in v6
|
|
51
51
|
amountToTransfer: bigint;
|
|
52
|
-
payload: Cell;
|
|
53
|
-
}
|
|
52
|
+
payload: Cell;
|
|
53
|
+
};
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
56
|
* Parameters for the withdraw message
|
|
@@ -67,11 +67,10 @@ export type WithdrawParameters = {
|
|
|
67
67
|
amount: bigint;
|
|
68
68
|
userAddress: Address;
|
|
69
69
|
includeUserCode: boolean;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
/* Will be in v6
|
|
70
|
+
asset: PoolAssetConfig
|
|
71
|
+
priceData: Cell;
|
|
73
72
|
amountToTransfer: bigint;
|
|
74
|
-
payload: Cell;
|
|
73
|
+
payload: Cell;
|
|
75
74
|
};
|
|
76
75
|
|
|
77
76
|
/**
|
|
@@ -90,6 +89,7 @@ export type LiquidationBaseData = {
|
|
|
90
89
|
minCollateralAmount: bigint;
|
|
91
90
|
liquidationAmount: bigint;
|
|
92
91
|
tonLiquidation: boolean;
|
|
92
|
+
forwardAmount?: bigint;
|
|
93
93
|
};
|
|
94
94
|
|
|
95
95
|
/**
|
|
@@ -103,10 +103,11 @@ export type LiquidationParameters = LiquidationBaseData & {
|
|
|
103
103
|
asset: PoolAssetConfig;
|
|
104
104
|
queryID: bigint;
|
|
105
105
|
liquidatorAddress: Address;
|
|
106
|
+
responseAddress: Address;
|
|
106
107
|
includeUserCode: boolean;
|
|
107
108
|
priceData: Cell;
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
payload: Cell;
|
|
110
|
+
payloadForwardAmount: bigint;
|
|
110
111
|
};
|
|
111
112
|
|
|
112
113
|
/**
|
|
@@ -149,9 +150,8 @@ export class Evaa implements Contract {
|
|
|
149
150
|
.storeUint(OPCODES.SUPPLY, 32)
|
|
150
151
|
.storeInt(parameters.includeUserCode ? -1 : 0, 2)
|
|
151
152
|
.storeAddress(parameters.userAddress)
|
|
152
|
-
/* Will be in v6
|
|
153
153
|
.storeUint(parameters.amountToTransfer, 64)
|
|
154
|
-
.storeRef(parameters.payload)
|
|
154
|
+
.storeRef(parameters.payload)
|
|
155
155
|
.endCell(),
|
|
156
156
|
)
|
|
157
157
|
.endCell();
|
|
@@ -162,9 +162,8 @@ export class Evaa implements Contract {
|
|
|
162
162
|
.storeInt(parameters.includeUserCode ? -1 : 0, 2)
|
|
163
163
|
.storeUint(parameters.amount, 64)
|
|
164
164
|
.storeAddress(parameters.userAddress)
|
|
165
|
-
/* Will be in v6
|
|
166
165
|
.storeUint(parameters.amountToTransfer, 64)
|
|
167
|
-
.storeRef(parameters.payload)
|
|
166
|
+
.storeRef(parameters.payload)
|
|
168
167
|
.endCell();
|
|
169
168
|
}
|
|
170
169
|
}
|
|
@@ -181,9 +180,8 @@ export class Evaa implements Contract {
|
|
|
181
180
|
.storeUint(parameters.amount, 64)
|
|
182
181
|
.storeAddress(parameters.userAddress)
|
|
183
182
|
.storeInt(parameters.includeUserCode ? -1 : 0, 2)
|
|
184
|
-
/* Will be in v6
|
|
185
183
|
.storeUint(parameters.amountToTransfer, 64)
|
|
186
|
-
.storeRef(parameters.payload)
|
|
184
|
+
.storeRef(parameters.payload)
|
|
187
185
|
.storeRef(parameters.priceData)
|
|
188
186
|
.endCell();
|
|
189
187
|
}
|
|
@@ -214,6 +212,10 @@ export class Evaa implements Contract {
|
|
|
214
212
|
// do not need liquidationAmount in case of jetton liquidation because
|
|
215
213
|
// the exact amount of transferred jettons for liquidation is known
|
|
216
214
|
.storeUint(0, 64)
|
|
215
|
+
.storeRef(beginCell()
|
|
216
|
+
.storeUint(parameters.payloadForwardAmount ?? 0, 64)
|
|
217
|
+
.storeRef(parameters.payload)
|
|
218
|
+
.endCell())
|
|
217
219
|
.storeRef(parameters.priceData)
|
|
218
220
|
.endCell(),
|
|
219
221
|
)
|
|
@@ -228,6 +230,10 @@ export class Evaa implements Contract {
|
|
|
228
230
|
.storeUint(parameters.minCollateralAmount, 64)
|
|
229
231
|
.storeInt(parameters.includeUserCode ? -1 : 0, 2)
|
|
230
232
|
.storeUint(parameters.liquidationAmount, 64)
|
|
233
|
+
.storeRef(beginCell()
|
|
234
|
+
.storeUint(parameters.payloadForwardAmount ?? 0, 64)
|
|
235
|
+
.storeRef(parameters.payload)
|
|
236
|
+
.endCell())
|
|
231
237
|
.storeRef(parameters.priceData)
|
|
232
238
|
.endCell();
|
|
233
239
|
}
|
|
@@ -382,9 +388,9 @@ export class Evaa implements Contract {
|
|
|
382
388
|
|
|
383
389
|
async getPrices(provider: ContractProvider, endpoints?: string[]) {
|
|
384
390
|
if ((endpoints?.length ?? 0) > 0) {
|
|
385
|
-
return await getPrices(endpoints, this.poolConfig
|
|
391
|
+
return await getPrices(endpoints, this.poolConfig);
|
|
386
392
|
} else {
|
|
387
|
-
return await getPrices(undefined, this.poolConfig
|
|
393
|
+
return await getPrices(undefined, this.poolConfig);
|
|
388
394
|
}
|
|
389
395
|
}
|
|
390
396
|
}
|
|
@@ -34,6 +34,7 @@ export class EvaaUser implements Contract {
|
|
|
34
34
|
provider: ContractProvider,
|
|
35
35
|
assetsData: ExtendedAssetsData,
|
|
36
36
|
assetsConfig: ExtendedAssetsConfig,
|
|
37
|
+
applyDust: boolean = false
|
|
37
38
|
) {
|
|
38
39
|
const state = (await provider.getState()).state;
|
|
39
40
|
if (state.type === 'active') {
|
|
@@ -41,7 +42,8 @@ export class EvaaUser implements Contract {
|
|
|
41
42
|
state.data!.toString('base64'),
|
|
42
43
|
assetsData,
|
|
43
44
|
assetsConfig,
|
|
44
|
-
this.poolConfig
|
|
45
|
+
this.poolConfig,
|
|
46
|
+
applyDust
|
|
45
47
|
);
|
|
46
48
|
this.lastSync = Math.floor(Date.now() / 1000);
|
|
47
49
|
} else {
|
|
@@ -96,6 +98,7 @@ export class EvaaUser implements Contract {
|
|
|
96
98
|
assetsData: ExtendedAssetsData,
|
|
97
99
|
assetsConfig: ExtendedAssetsConfig,
|
|
98
100
|
prices: Dictionary<bigint, bigint>,
|
|
101
|
+
applyDust: boolean = false
|
|
99
102
|
) {
|
|
100
103
|
const state = (await provider.getState()).state;
|
|
101
104
|
if (state.type === 'active') {
|
|
@@ -103,9 +106,10 @@ export class EvaaUser implements Contract {
|
|
|
103
106
|
state.data!.toString('base64'),
|
|
104
107
|
assetsData,
|
|
105
108
|
assetsConfig,
|
|
106
|
-
this.poolConfig
|
|
109
|
+
this.poolConfig,
|
|
110
|
+
applyDust
|
|
107
111
|
);
|
|
108
|
-
this._data = parseUserData(this._liteData, assetsData, assetsConfig, prices, this.poolConfig);
|
|
112
|
+
this._data = parseUserData(this._liteData, assetsData, assetsConfig, prices, this.poolConfig, applyDust);
|
|
109
113
|
this.lastSync = Math.floor(Date.now() / 1000);
|
|
110
114
|
} else {
|
|
111
115
|
this._data = { type: 'inactive' };
|
package/src/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ export {
|
|
|
12
12
|
calculateMaximumWithdrawAmount,
|
|
13
13
|
presentValue,
|
|
14
14
|
calculateLiquidationData,
|
|
15
|
+
predictHealthFactor
|
|
15
16
|
} from './api/math';
|
|
16
17
|
|
|
17
18
|
// Parser
|
|
@@ -26,6 +27,7 @@ export {
|
|
|
26
27
|
EvaaParameters,
|
|
27
28
|
WithdrawParameters,
|
|
28
29
|
LiquidationBaseData,
|
|
30
|
+
LiquidationParameters,
|
|
29
31
|
Evaa,
|
|
30
32
|
} from './contracts/MasterContract';
|
|
31
33
|
export { EvaaUser } from './contracts/UserContract';
|
|
@@ -46,7 +48,9 @@ export {
|
|
|
46
48
|
ExtendedAssetsConfig,
|
|
47
49
|
PoolAssetConfig,
|
|
48
50
|
PoolAssetsConfig,
|
|
51
|
+
MasterConstants
|
|
49
52
|
} from './types/Master';
|
|
53
|
+
|
|
50
54
|
export {
|
|
51
55
|
BalanceType,
|
|
52
56
|
UserBalance,
|
package/src/types/Common.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { Cell, Dictionary } from '@ton/core';
|
|
2
2
|
|
|
3
|
+
export type RawPriceData = {
|
|
4
|
+
dict: Dictionary<bigint, bigint>;
|
|
5
|
+
dataCell: Cell;
|
|
6
|
+
oracleId: number;
|
|
7
|
+
signature: Buffer;
|
|
8
|
+
pubkey: Buffer;
|
|
9
|
+
timestamp: number;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
|
|
3
13
|
export type PriceData = {
|
|
4
14
|
dict: Dictionary<bigint, bigint>;
|
|
5
15
|
dataCell: Cell;
|