@evaafi/sdk 0.5.1 → 0.5.3
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/math.js +2 -1
- package/dist/api/prices.d.ts +1 -1
- package/dist/api/prices.js +19 -22
- package/dist/contracts/MasterContract.js +1 -1
- package/dist/contracts/UserContract.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/package.json +1 -1
- package/src/api/math.ts +2 -1
- package/src/api/prices.ts +23 -24
- package/src/contracts/MasterContract.ts +1 -1
- package/src/contracts/UserContract.ts +2 -2
- package/src/index.ts +1 -0
package/dist/api/math.js
CHANGED
|
@@ -222,7 +222,8 @@ function predictHealthFactor(args) {
|
|
|
222
222
|
const decimals = Number(assetConfig.decimals);
|
|
223
223
|
const currentBalance = assetPrice * Number(currentAmount) / Math.pow(10, decimals);
|
|
224
224
|
const changeType = args.balanceChangeType;
|
|
225
|
-
if (currentAmount != null && currentAmount
|
|
225
|
+
if (currentAmount != null && !Number.isNaN(currentAmount) &&
|
|
226
|
+
Number.isFinite(currentAmount) && currentAmount != 0n) {
|
|
226
227
|
if (changeType == User_1.BalanceChangeType.Borrow) {
|
|
227
228
|
totalBorrow += currentBalance * (1 + Number(assetConfig.originationFee) / Number(constants_1.MASTER_CONSTANTS.ASSET_ORIGINATION_FEE_SCALE));
|
|
228
229
|
}
|
package/dist/api/prices.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { PriceData } from '../types/Common';
|
|
2
|
-
export declare function getPrices(
|
|
2
|
+
export declare function getPrices(endpoints?: string[]): Promise<PriceData>;
|
package/dist/api/prices.js
CHANGED
|
@@ -3,27 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getPrices = void 0;
|
|
4
4
|
const core_1 = require("@ton/core");
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
|
-
async function getPrices(
|
|
7
|
-
|
|
8
|
-
let result = await fetch(`https://${endpoint}/api/indexer/v1/outputs/nft/${constants_1.NFT_ID}`, {
|
|
9
|
-
headers: { accept: 'application/json' },
|
|
10
|
-
});
|
|
11
|
-
let outputId = (await result.json());
|
|
12
|
-
result = await fetch(`https://${endpoint}/api/core/v2/outputs/${outputId.items[0]}`, {
|
|
13
|
-
headers: { accept: 'application/json' },
|
|
14
|
-
});
|
|
15
|
-
let resData = (await result.json());
|
|
16
|
-
const data = JSON.parse(decodeURIComponent(resData.output.features[0].data.replace('0x', '').replace(/[0-9a-f]{2}/g, '%$&')));
|
|
17
|
-
const pricesCell = core_1.Cell.fromBoc(Buffer.from(data['packedPrices'], 'hex'))[0];
|
|
18
|
-
const signature = Buffer.from(data['signature'], 'hex');
|
|
19
|
-
return {
|
|
20
|
-
dict: pricesCell.beginParse().loadDictDirect(core_1.Dictionary.Keys.BigUint(256), core_1.Dictionary.Values.BigUint(64)),
|
|
21
|
-
dataCell: (0, core_1.beginCell)().storeRef(pricesCell).storeBuffer(signature).endCell(),
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
console.error(error);
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
6
|
+
async function getPrices(endpoints = ["api.stardust-mainnet.iotaledger.net"]) {
|
|
7
|
+
return await Promise.any(endpoints.map(x => loadPrices(x)));
|
|
28
8
|
}
|
|
29
9
|
exports.getPrices = getPrices;
|
|
10
|
+
async function loadPrices(endpoint = "api.stardust-mainnet.iotaledger.net") {
|
|
11
|
+
let result = await fetch(`https://${endpoint}/api/indexer/v1/outputs/nft/${constants_1.NFT_ID}`, {
|
|
12
|
+
headers: { accept: 'application/json' },
|
|
13
|
+
});
|
|
14
|
+
let outputId = (await result.json());
|
|
15
|
+
result = await fetch(`https://${endpoint}/api/core/v2/outputs/${outputId.items[0]}`, {
|
|
16
|
+
headers: { accept: 'application/json' },
|
|
17
|
+
});
|
|
18
|
+
let resData = (await result.json());
|
|
19
|
+
const data = JSON.parse(decodeURIComponent(resData.output.features[0].data.replace('0x', '').replace(/[0-9a-f]{2}/g, '%$&')));
|
|
20
|
+
const pricesCell = core_1.Cell.fromBoc(Buffer.from(data['packedPrices'], 'hex'))[0];
|
|
21
|
+
const signature = Buffer.from(data['signature'], 'hex');
|
|
22
|
+
return {
|
|
23
|
+
dict: pricesCell.beginParse().loadDictDirect(core_1.Dictionary.Keys.BigUint(256), core_1.Dictionary.Values.BigUint(64)),
|
|
24
|
+
dataCell: (0, core_1.beginCell)().storeRef(pricesCell).storeBuffer(signature).endCell(),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -224,7 +224,7 @@ class Evaa {
|
|
|
224
224
|
async getSync(provider) {
|
|
225
225
|
const state = (await provider.getState()).state;
|
|
226
226
|
if (state.type === 'active') {
|
|
227
|
-
this._data = (0, parser_1.parseMasterData)(state.data.toString('
|
|
227
|
+
this._data = (0, parser_1.parseMasterData)(state.data.toString('base64'), this.network === 'testnet');
|
|
228
228
|
if (this.network === 'testnet' && this._data.upgradeConfig.masterCodeVersion !== constants_1.TESTNET_VERSION) {
|
|
229
229
|
throw Error(`Outdated SDK version. It supports only master code version ${constants_1.TESTNET_VERSION} on testnet, but the current master code version is ${this._data.upgradeConfig.masterCodeVersion}`);
|
|
230
230
|
}
|
|
@@ -25,7 +25,7 @@ class EvaaUser {
|
|
|
25
25
|
async getSyncLite(provider, assetsData, assetsConfig) {
|
|
26
26
|
const state = (await provider.getState()).state;
|
|
27
27
|
if (state.type === 'active') {
|
|
28
|
-
this._liteData = (0, parser_1.parseUserLiteData)(state.data.toString('
|
|
28
|
+
this._liteData = (0, parser_1.parseUserLiteData)(state.data.toString('base64'), assetsData, assetsConfig, this.testnet);
|
|
29
29
|
this.lastSync = Math.floor(Date.now() / 1000);
|
|
30
30
|
}
|
|
31
31
|
else {
|
|
@@ -65,7 +65,7 @@ class EvaaUser {
|
|
|
65
65
|
async getSync(provider, assetsData, assetsConfig, prices) {
|
|
66
66
|
const state = (await provider.getState()).state;
|
|
67
67
|
if (state.type === 'active') {
|
|
68
|
-
this._liteData = (0, parser_1.parseUserLiteData)(state.data.toString('
|
|
68
|
+
this._liteData = (0, parser_1.parseUserLiteData)(state.data.toString('base64'), assetsData, assetsConfig, this.testnet);
|
|
69
69
|
this._data = (0, parser_1.parseUserData)(this._liteData, assetsData, assetsConfig, prices, this.testnet);
|
|
70
70
|
this.lastSync = Math.floor(Date.now() / 1000);
|
|
71
71
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { EvaaParameters, JettonMessageParameters, TonSupplyParameters, JettonSup
|
|
|
6
6
|
export { EvaaUser } from './contracts/UserContract';
|
|
7
7
|
export { PriceData } from './types/Common';
|
|
8
8
|
export { UpgradeConfig, AssetConfig, MasterConfig, AssetData, AssetInterest, AssetApy, ExtendedAssetData, MasterData, } from './types/Master';
|
|
9
|
-
export { BalanceType, UserBalance, UserLiqudationData, LiquidableData, NonLiquidableData, LiquidationData, UserDataInactive, UserDataActive, UserData, } from './types/User';
|
|
9
|
+
export { BalanceType, UserBalance, UserLiqudationData, LiquidableData, NonLiquidableData, LiquidationData, UserDataInactive, UserDataActive, UserData, BalanceChangeType } from './types/User';
|
|
10
10
|
export { EVAA_MASTER_MAINNET, MAINNET_VERSION, EVAA_MASTER_TESTNET, TESTNET_VERSION, JETTON_MASTER_ADDRESSES, MASTER_CONSTANTS, LENDING_CODE, OPCODES, FEES, } from './constants';
|
|
11
11
|
export { getLastSentBoc, getTonConnectSender } from './utils/tonConnectSender';
|
|
12
12
|
export { getUserJettonWallet } from './utils/userJettonWallet';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getUserJettonWallet = exports.getTonConnectSender = exports.getLastSentBoc = exports.FEES = exports.OPCODES = exports.LENDING_CODE = exports.MASTER_CONSTANTS = exports.JETTON_MASTER_ADDRESSES = exports.TESTNET_VERSION = exports.EVAA_MASTER_TESTNET = exports.MAINNET_VERSION = exports.EVAA_MASTER_MAINNET = exports.BalanceType = exports.EvaaUser = exports.Evaa = exports.JettonWallet = exports.getPrices = exports.parseUserLiteData = exports.parseUserData = exports.parseMasterData = exports.createAssetConfig = exports.createAssetData = exports.calculateLiquidationData = exports.presentValue = exports.getAvailableToBorrow = exports.calculateAssetInterest = exports.calculateAssetData = exports.calculateCurrentRates = exports.calculatePresentValue = exports.bigIntMax = exports.bigIntMin = exports.mulDiv = exports.mulFactor = void 0;
|
|
3
|
+
exports.getUserJettonWallet = exports.getTonConnectSender = exports.getLastSentBoc = exports.FEES = exports.OPCODES = exports.LENDING_CODE = exports.MASTER_CONSTANTS = exports.JETTON_MASTER_ADDRESSES = exports.TESTNET_VERSION = exports.EVAA_MASTER_TESTNET = exports.MAINNET_VERSION = exports.EVAA_MASTER_MAINNET = exports.BalanceChangeType = exports.BalanceType = exports.EvaaUser = exports.Evaa = exports.JettonWallet = exports.getPrices = exports.parseUserLiteData = exports.parseUserData = exports.parseMasterData = exports.createAssetConfig = exports.createAssetData = exports.calculateLiquidationData = exports.presentValue = exports.getAvailableToBorrow = exports.calculateAssetInterest = exports.calculateAssetData = exports.calculateCurrentRates = exports.calculatePresentValue = exports.bigIntMax = exports.bigIntMin = exports.mulDiv = exports.mulFactor = void 0;
|
|
4
4
|
// Math
|
|
5
5
|
var math_1 = require("./api/math");
|
|
6
6
|
Object.defineProperty(exports, "mulFactor", { enumerable: true, get: function () { return math_1.mulFactor; } });
|
|
@@ -33,6 +33,7 @@ var UserContract_1 = require("./contracts/UserContract");
|
|
|
33
33
|
Object.defineProperty(exports, "EvaaUser", { enumerable: true, get: function () { return UserContract_1.EvaaUser; } });
|
|
34
34
|
var User_1 = require("./types/User");
|
|
35
35
|
Object.defineProperty(exports, "BalanceType", { enumerable: true, get: function () { return User_1.BalanceType; } });
|
|
36
|
+
Object.defineProperty(exports, "BalanceChangeType", { enumerable: true, get: function () { return User_1.BalanceChangeType; } });
|
|
36
37
|
// Constants
|
|
37
38
|
var constants_1 = require("./constants");
|
|
38
39
|
Object.defineProperty(exports, "EVAA_MASTER_MAINNET", { enumerable: true, get: function () { return constants_1.EVAA_MASTER_MAINNET; } });
|
package/package.json
CHANGED
package/src/api/math.ts
CHANGED
|
@@ -267,7 +267,8 @@ export function predictHealthFactor(args: PredictHealthFactorArgs): number {
|
|
|
267
267
|
const currentBalance = assetPrice * Number(currentAmount) / Math.pow(10, decimals);
|
|
268
268
|
const changeType = args.balanceChangeType;
|
|
269
269
|
|
|
270
|
-
if (currentAmount != null && currentAmount
|
|
270
|
+
if (currentAmount != null && !Number.isNaN(currentAmount) &&
|
|
271
|
+
Number.isFinite(currentAmount) && currentAmount != 0n) {
|
|
271
272
|
if (changeType == BalanceChangeType.Borrow) {
|
|
272
273
|
totalBorrow += currentBalance * (1 + Number(assetConfig.originationFee) / Number(MASTER_CONSTANTS.ASSET_ORIGINATION_FEE_SCALE));
|
|
273
274
|
} else if (changeType == BalanceChangeType.Repay) {
|
package/src/api/prices.ts
CHANGED
|
@@ -37,34 +37,33 @@ type OutputData = {
|
|
|
37
37
|
data: string;
|
|
38
38
|
}[];
|
|
39
39
|
};
|
|
40
|
-
}
|
|
40
|
+
}
|
|
41
41
|
|
|
42
|
-
export async function getPrices(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
headers: { accept: 'application/json' },
|
|
46
|
-
});
|
|
47
|
-
let outputId = (await result.json()) as NftData;
|
|
42
|
+
export async function getPrices(endpoints: string[] = ["api.stardust-mainnet.iotaledger.net"]) {
|
|
43
|
+
return await Promise.any(endpoints.map(x => loadPrices(x)));
|
|
44
|
+
}
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
46
|
+
async function loadPrices(endpoint: String = "api.stardust-mainnet.iotaledger.net"): Promise<PriceData> {
|
|
47
|
+
let result = await fetch(`https://${endpoint}/api/indexer/v1/outputs/nft/${NFT_ID}`, {
|
|
48
|
+
headers: { accept: 'application/json' },
|
|
49
|
+
});
|
|
50
|
+
let outputId = (await result.json()) as NftData;
|
|
52
51
|
|
|
53
|
-
|
|
52
|
+
result = await fetch(`https://${endpoint}/api/core/v2/outputs/${outputId.items[0]}`, {
|
|
53
|
+
headers: { accept: 'application/json' },
|
|
54
|
+
});
|
|
54
55
|
|
|
55
|
-
|
|
56
|
-
decodeURIComponent(resData.output.features[0].data.replace('0x', '').replace(/[0-9a-f]{2}/g, '%$&')),
|
|
57
|
-
);
|
|
56
|
+
let resData = (await result.json()) as OutputData;
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
const data = JSON.parse(
|
|
59
|
+
decodeURIComponent(resData.output.features[0].data.replace('0x', '').replace(/[0-9a-f]{2}/g, '%$&')),
|
|
60
|
+
);
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
62
|
+
const pricesCell = Cell.fromBoc(Buffer.from(data['packedPrices'], 'hex'))[0];
|
|
63
|
+
const signature = Buffer.from(data['signature'], 'hex');
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
dict: pricesCell.beginParse().loadDictDirect(Dictionary.Keys.BigUint(256), Dictionary.Values.BigUint(64)),
|
|
67
|
+
dataCell: beginCell().storeRef(pricesCell).storeBuffer(signature).endCell(),
|
|
68
|
+
};
|
|
70
69
|
}
|
|
@@ -405,7 +405,7 @@ export class Evaa implements Contract {
|
|
|
405
405
|
async getSync(provider: ContractProvider) {
|
|
406
406
|
const state = (await provider.getState()).state;
|
|
407
407
|
if (state.type === 'active') {
|
|
408
|
-
this._data = parseMasterData(state.data!.toString('
|
|
408
|
+
this._data = parseMasterData(state.data!.toString('base64'), this.network === 'testnet');
|
|
409
409
|
if (this.network === 'testnet' && this._data.upgradeConfig.masterCodeVersion !== TESTNET_VERSION) {
|
|
410
410
|
throw Error(
|
|
411
411
|
`Outdated SDK version. It supports only master code version ${TESTNET_VERSION} on testnet, but the current master code version is ${this._data.upgradeConfig.masterCodeVersion}`,
|
|
@@ -37,7 +37,7 @@ export class EvaaUser implements Contract {
|
|
|
37
37
|
const state = (await provider.getState()).state;
|
|
38
38
|
if (state.type === 'active') {
|
|
39
39
|
this._liteData = parseUserLiteData(
|
|
40
|
-
state.data!.toString('
|
|
40
|
+
state.data!.toString('base64'),
|
|
41
41
|
assetsData,
|
|
42
42
|
assetsConfig,
|
|
43
43
|
this.testnet,
|
|
@@ -99,7 +99,7 @@ export class EvaaUser implements Contract {
|
|
|
99
99
|
const state = (await provider.getState()).state;
|
|
100
100
|
if (state.type === 'active') {
|
|
101
101
|
this._liteData = parseUserLiteData(
|
|
102
|
-
state.data!.toString('
|
|
102
|
+
state.data!.toString('base64'),
|
|
103
103
|
assetsData,
|
|
104
104
|
assetsConfig,
|
|
105
105
|
this.testnet,
|