@evaafi/sdk 0.6.4 → 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} +3 -29
- package/dist/constants/{assets.js → assets/mainnet.js} +30 -79
- 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 +17 -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 +10 -8
- package/dist/prices/utils.js +32 -46
- package/dist/types/Master.d.ts +10 -30
- package/dist/types/Master.js +3 -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 +4 -3
- 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} +27 -94
- 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 -175
- package/src/contracts/MasterContract.ts +0 -410
package/dist/constants/pools.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ALL_MAINNET_POOLS = exports.MAINNET_MASTER_USDT_REWARD_CONFIG = exports.MAINNET_MASTER_TON_REWARD_CONFIG = exports.TESTNET_MASTER_EUSDT_REWARD_CONFIG = exports.TESTNET_MASTER_REWARD_CONFIG = exports.MAINNET_ALTS_POOL_CONFIG = exports.MAINNET_LP_POOL_CONFIG = exports.TESTNET_POOL_CONFIG = exports.MAINNET_TEST_ETHENA_POOL_CONFIG = exports.MAINNET_STABLE_POOL_CONFIG = exports.MAINNET_POOL_CONFIG = void 0;
|
|
4
|
-
const core_1 = require("@ton/core");
|
|
5
|
-
const assets_1 = require("./assets");
|
|
6
|
-
const general_1 = require("./general");
|
|
7
|
-
exports.MAINNET_POOL_CONFIG = {
|
|
8
|
-
masterAddress: general_1.EVAA_MASTER_MAINNET,
|
|
9
|
-
masterVersion: general_1.MAINNET_VERSION,
|
|
10
|
-
masterConstants: general_1.MASTER_CONSTANTS,
|
|
11
|
-
oracles: general_1.ORACLES_MAINNET,
|
|
12
|
-
minimalOracles: 3,
|
|
13
|
-
poolAssetsConfig: [
|
|
14
|
-
assets_1.TON_MAINNET,
|
|
15
|
-
assets_1.JUSDT_MAINNET,
|
|
16
|
-
assets_1.JUSDC_MAINNET,
|
|
17
|
-
assets_1.STTON_MAINNET,
|
|
18
|
-
assets_1.TSTON_MAINNET,
|
|
19
|
-
assets_1.USDT_MAINNET,
|
|
20
|
-
assets_1.USDE_MAINNET,
|
|
21
|
-
assets_1.TSUSDE_MAINNET,
|
|
22
|
-
// UTON_MAINNET // announce xdddd fake announce
|
|
23
|
-
],
|
|
24
|
-
lendingCode: general_1.LENDING_CODE,
|
|
25
|
-
};
|
|
26
|
-
exports.MAINNET_STABLE_POOL_CONFIG = {
|
|
27
|
-
masterAddress: general_1.EVAA_STABLE_MAINNET,
|
|
28
|
-
masterVersion: general_1.STABLE_VERSION,
|
|
29
|
-
masterConstants: general_1.MASTER_CONSTANTS,
|
|
30
|
-
oracles: general_1.ORACLES_MAINNET,
|
|
31
|
-
minimalOracles: 3,
|
|
32
|
-
poolAssetsConfig: [
|
|
33
|
-
assets_1.USDT_MAINNET,
|
|
34
|
-
assets_1.USDE_MAINNET,
|
|
35
|
-
assets_1.TSUSDE_MAINNET,
|
|
36
|
-
assets_1.PT_tsUSDe_01Sep2025_MAINNET
|
|
37
|
-
],
|
|
38
|
-
lendingCode: general_1.LENDING_CODE,
|
|
39
|
-
};
|
|
40
|
-
exports.MAINNET_TEST_ETHENA_POOL_CONFIG = {
|
|
41
|
-
masterAddress: general_1.EVAA_ETHENA_MAINNET,
|
|
42
|
-
masterVersion: general_1.EVAA_ETHENA_VERSION,
|
|
43
|
-
masterConstants: general_1.MASTER_CONSTANTS,
|
|
44
|
-
oracles: general_1.ORACLES_MAINNET,
|
|
45
|
-
minimalOracles: 3,
|
|
46
|
-
poolAssetsConfig: [
|
|
47
|
-
assets_1.TON_MAINNET,
|
|
48
|
-
assets_1.USDE_MAINNET,
|
|
49
|
-
],
|
|
50
|
-
lendingCode: general_1.LENDING_CODE,
|
|
51
|
-
};
|
|
52
|
-
exports.TESTNET_POOL_CONFIG = {
|
|
53
|
-
masterAddress: general_1.EVAA_MASTER_TESTNET,
|
|
54
|
-
masterVersion: general_1.TESTNET_VERSION,
|
|
55
|
-
masterConstants: general_1.MASTER_CONSTANTS,
|
|
56
|
-
oracles: general_1.ORACLES_TESTNET,
|
|
57
|
-
minimalOracles: 3,
|
|
58
|
-
poolAssetsConfig: [assets_1.TON_TESTNET, assets_1.TGBTC_TESTNET],
|
|
59
|
-
lendingCode: general_1.LENDING_CODE,
|
|
60
|
-
};
|
|
61
|
-
exports.MAINNET_LP_POOL_CONFIG = {
|
|
62
|
-
masterAddress: general_1.EVAA_LP_MAINNET,
|
|
63
|
-
masterVersion: general_1.EVAA_LP_MAINNET_VERSION,
|
|
64
|
-
masterConstants: general_1.MASTER_CONSTANTS,
|
|
65
|
-
oracles: general_1.ORACLES_LP,
|
|
66
|
-
minimalOracles: 3,
|
|
67
|
-
poolAssetsConfig: [assets_1.TON_MAINNET, assets_1.USDT_MAINNET, assets_1.TONUSDT_DEDUST_MAINNET, assets_1.TON_STORM_MAINNET, assets_1.USDT_STORM_MAINNET],
|
|
68
|
-
lendingCode: general_1.LENDING_CODE,
|
|
69
|
-
};
|
|
70
|
-
exports.MAINNET_ALTS_POOL_CONFIG = {
|
|
71
|
-
masterAddress: general_1.EVAA_ALTS_MAINNET,
|
|
72
|
-
masterVersion: general_1.EVAA_ALTS_MAINNET_VERSION,
|
|
73
|
-
masterConstants: general_1.MASTER_CONSTANTS,
|
|
74
|
-
oracles: general_1.ORACLES_ALTS,
|
|
75
|
-
minimalOracles: 3,
|
|
76
|
-
poolAssetsConfig: [assets_1.TON_MAINNET, assets_1.USDT_MAINNET, assets_1.CATI_MAINNET, assets_1.NOT_MAINNET, assets_1.DOGS_MAINNET],
|
|
77
|
-
lendingCode: general_1.LENDING_CODE,
|
|
78
|
-
};
|
|
79
|
-
exports.TESTNET_MASTER_REWARD_CONFIG = {
|
|
80
|
-
adminAddress: general_1.EVAA_REWARDS_MASTER_TESTNET,
|
|
81
|
-
evaaMasterAddress: new core_1.Address(0, Buffer.alloc(32, 0)),
|
|
82
|
-
rewardMasterCode: general_1.EVAA_REWARDS_MASTER_CODE_TESTNET,
|
|
83
|
-
rewardUserCode: general_1.EVAA_REWARDS_USER_CODE_TESTNET,
|
|
84
|
-
asset: assets_1.TON_TESTNET,
|
|
85
|
-
availableReward: 0,
|
|
86
|
-
publicKey: Buffer.from('c38be45e033419b49cd22c97fbd23610fbc851a931208f8b4a1817dd11cb63ac', 'hex'), // adminAddress publicKey
|
|
87
|
-
};
|
|
88
|
-
exports.TESTNET_MASTER_EUSDT_REWARD_CONFIG = {
|
|
89
|
-
adminAddress: general_1.EVAA_REWARDS_MASTER_TESTNET,
|
|
90
|
-
evaaMasterAddress: new core_1.Address(0, Buffer.alloc(32, 0)),
|
|
91
|
-
rewardMasterCode: general_1.EVAA_REWARDS_MASTER_CODE_TESTNET,
|
|
92
|
-
rewardUserCode: general_1.EVAA_REWARDS_USER_CODE_TESTNET,
|
|
93
|
-
asset: assets_1.EUSDT_TESTNET,
|
|
94
|
-
availableReward: 0,
|
|
95
|
-
publicKey: Buffer.from('c38be45e033419b49cd22c97fbd23610fbc851a931208f8b4a1817dd11cb63ac', 'hex'), // adminAddress publicKey
|
|
96
|
-
};
|
|
97
|
-
exports.MAINNET_MASTER_TON_REWARD_CONFIG = {
|
|
98
|
-
adminAddress: general_1.EVAA_TON_REWARDS_MASTER_MAINNET,
|
|
99
|
-
evaaMasterAddress: new core_1.Address(0, Buffer.alloc(32, 0)),
|
|
100
|
-
rewardMasterCode: general_1.EVAA_REWARDS_MASTER_CODE_MAINNET,
|
|
101
|
-
rewardUserCode: general_1.EVAA_REWARDS_USER_CODE_MAINNET,
|
|
102
|
-
asset: assets_1.TON_MAINNET,
|
|
103
|
-
availableReward: 0,
|
|
104
|
-
publicKey: Buffer.from('bfe9a30221db4dff4c17e55d985e0b13a8f597bbb28002f311dc4429dad1ca95', 'hex'), // adminAddress publicKey
|
|
105
|
-
};
|
|
106
|
-
exports.MAINNET_MASTER_USDT_REWARD_CONFIG = {
|
|
107
|
-
adminAddress: general_1.EVAA_USDT_REWARDS_MASTER_MAINNET,
|
|
108
|
-
evaaMasterAddress: new core_1.Address(0, Buffer.alloc(32, 0)),
|
|
109
|
-
rewardMasterCode: general_1.EVAA_REWARDS_MASTER_CODE_MAINNET,
|
|
110
|
-
rewardUserCode: general_1.EVAA_REWARDS_USER_CODE_MAINNET,
|
|
111
|
-
asset: assets_1.USDT_MAINNET,
|
|
112
|
-
availableReward: 0,
|
|
113
|
-
publicKey: Buffer.from('9813725d6cead1c9bbc0e24b21d4fc62a7fa8ac4bb01b6758df30169a71dba67', 'hex'), // adminAddress publicKey
|
|
114
|
-
};
|
|
115
|
-
exports.ALL_MAINNET_POOLS = [
|
|
116
|
-
exports.MAINNET_POOL_CONFIG,
|
|
117
|
-
exports.MAINNET_LP_POOL_CONFIG,
|
|
118
|
-
exports.MAINNET_ALTS_POOL_CONFIG,
|
|
119
|
-
exports.MAINNET_STABLE_POOL_CONFIG,
|
|
120
|
-
];
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { Address, Cell, Contract, ContractProvider, OpenedContract, Sender } from '@ton/core';
|
|
2
|
-
import { Maybe } from '@ton/core/dist/utils/maybe';
|
|
3
|
-
import { EvaaUser } from './UserContract';
|
|
4
|
-
import { MasterData, PoolAssetConfig, PoolConfig } from '../types/Master';
|
|
5
|
-
import { PricesCollector, PriceSourcesConfig } from '..';
|
|
6
|
-
/**
|
|
7
|
-
* Parameters for the Evaa contract
|
|
8
|
-
* @property testnet - true for testnet, false for mainnet
|
|
9
|
-
* @property debug - true to enable debug mode (optional)
|
|
10
|
-
*/
|
|
11
|
-
export type EvaaParameters = {
|
|
12
|
-
poolConfig: PoolConfig;
|
|
13
|
-
debug?: boolean;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Base parameters for supply
|
|
17
|
-
* @property queryID - unique query ID
|
|
18
|
-
* @property includeUserCode - true to include user code for update (needed when user contract code version is outdated)
|
|
19
|
-
* @property amount - amount to supply
|
|
20
|
-
* @property userAddress - user address
|
|
21
|
-
* @property asset
|
|
22
|
-
*/
|
|
23
|
-
export type SupplyParameters = {
|
|
24
|
-
asset: PoolAssetConfig;
|
|
25
|
-
queryID: bigint;
|
|
26
|
-
includeUserCode: boolean;
|
|
27
|
-
amount: bigint;
|
|
28
|
-
userAddress: Address;
|
|
29
|
-
responseAddress?: Address;
|
|
30
|
-
forwardAmount?: bigint;
|
|
31
|
-
amountToTransfer: bigint;
|
|
32
|
-
payload: Cell;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Parameters for the withdraw message
|
|
36
|
-
* @property queryID - unique query ID
|
|
37
|
-
* * @property assetID - asset ID
|
|
38
|
-
* @property assetID - asset ID
|
|
39
|
-
* @property amount - amount to withdraw
|
|
40
|
-
* @property userAddress - user address
|
|
41
|
-
* @property includeUserCode - true to include user code for update (needed when user contract code version is outdated)
|
|
42
|
-
* @property priceData - price data cell. Can be obtained from the getPrices function
|
|
43
|
-
*/
|
|
44
|
-
export type WithdrawParameters = {
|
|
45
|
-
queryID: bigint;
|
|
46
|
-
amount: bigint;
|
|
47
|
-
userAddress: Address;
|
|
48
|
-
includeUserCode: boolean;
|
|
49
|
-
asset: PoolAssetConfig;
|
|
50
|
-
priceData: Cell;
|
|
51
|
-
amountToTransfer: bigint;
|
|
52
|
-
payload: Cell;
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* Base data for liquidation. Can be obtained from the user contract liquidationParameters getter
|
|
56
|
-
* @property borrowerAddress - borrower address (user address that is being liquidated)
|
|
57
|
-
* @property loanAsset - loan asset ID
|
|
58
|
-
* @property collateralAsset - collateral asset ID
|
|
59
|
-
* @property minCollateralAmount - minimal amount to receive from the liquidation
|
|
60
|
-
* @property liquidationAmount - amount to liquidate
|
|
61
|
-
* @property tonLiquidation - true if the loan asset is TON
|
|
62
|
-
*/
|
|
63
|
-
export type LiquidationBaseData = {
|
|
64
|
-
borrowerAddress: Address;
|
|
65
|
-
loanAsset: bigint;
|
|
66
|
-
collateralAsset: bigint;
|
|
67
|
-
minCollateralAmount: bigint;
|
|
68
|
-
liquidationAmount: bigint;
|
|
69
|
-
tonLiquidation: boolean;
|
|
70
|
-
forwardAmount?: bigint;
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* Base parameters for liquidation
|
|
74
|
-
* @property queryID - unique query ID
|
|
75
|
-
* @property liquidatorAddress - liquidator address, where and collateral will be sent
|
|
76
|
-
* @property includeUserCode - true to include user code for update (needed when user contract code version is outdated)
|
|
77
|
-
* @property priceData - price data cell. Can be obtained from the getPrices function
|
|
78
|
-
*/
|
|
79
|
-
export type LiquidationParameters = LiquidationBaseData & {
|
|
80
|
-
asset: PoolAssetConfig;
|
|
81
|
-
queryID: bigint;
|
|
82
|
-
liquidatorAddress: Address;
|
|
83
|
-
responseAddress: Address;
|
|
84
|
-
includeUserCode: boolean;
|
|
85
|
-
priceData: Cell;
|
|
86
|
-
payload: Cell;
|
|
87
|
-
payloadForwardAmount: bigint;
|
|
88
|
-
};
|
|
89
|
-
/**
|
|
90
|
-
* Evaa master contract wrapper
|
|
91
|
-
*/
|
|
92
|
-
export declare class Evaa implements Contract {
|
|
93
|
-
readonly address: Address;
|
|
94
|
-
private _poolConfig;
|
|
95
|
-
private readonly debug?;
|
|
96
|
-
private _data?;
|
|
97
|
-
private lastSync;
|
|
98
|
-
/**
|
|
99
|
-
* Create Evaa contract wrapper
|
|
100
|
-
* @param parameters Evaa contract parameters
|
|
101
|
-
*/
|
|
102
|
-
constructor(parameters?: EvaaParameters);
|
|
103
|
-
/**
|
|
104
|
-
* Returns pool config
|
|
105
|
-
*/
|
|
106
|
-
get poolConfig(): PoolConfig;
|
|
107
|
-
/**
|
|
108
|
-
* Create supply message
|
|
109
|
-
* @returns supply message as a cell
|
|
110
|
-
*/
|
|
111
|
-
createSupplyMessage(parameters: SupplyParameters): Cell;
|
|
112
|
-
/**
|
|
113
|
-
* Create withdraw message
|
|
114
|
-
* @returns withdraw message as a cell
|
|
115
|
-
*/
|
|
116
|
-
createWithdrawMessage(parameters: WithdrawParameters): Cell;
|
|
117
|
-
/**
|
|
118
|
-
* Create liquidation message
|
|
119
|
-
* @returns liquidation message as a cell
|
|
120
|
-
*/
|
|
121
|
-
createLiquidationMessage(parameters: LiquidationParameters): Cell;
|
|
122
|
-
/**
|
|
123
|
-
* Calculate user contract address
|
|
124
|
-
* @param userAddress
|
|
125
|
-
* @returns user contract address
|
|
126
|
-
*/
|
|
127
|
-
calculateUserSCAddr(userAddress: Address, lendingCode: Cell): Address;
|
|
128
|
-
/**
|
|
129
|
-
* Open user contract wrapper
|
|
130
|
-
* @param userAddress
|
|
131
|
-
* @returns user contract
|
|
132
|
-
*/
|
|
133
|
-
openUserContract(userAddress: Address): EvaaUser;
|
|
134
|
-
getOpenedUserContract(provider: ContractProvider, userAddress: Address): OpenedContract<EvaaUser>;
|
|
135
|
-
/**
|
|
136
|
-
* Get master contract data
|
|
137
|
-
*/
|
|
138
|
-
get data(): Maybe<MasterData>;
|
|
139
|
-
sendSupply(provider: ContractProvider, via: Sender, value: bigint, parameters: SupplyParameters): Promise<void>;
|
|
140
|
-
sendWithdraw(provider: ContractProvider, via: Sender, value: bigint, parameters: WithdrawParameters): Promise<void>;
|
|
141
|
-
sendLiquidation(provider: ContractProvider, via: Sender, value: bigint, parameters: LiquidationParameters): Promise<void>;
|
|
142
|
-
/**
|
|
143
|
-
* Open user contract wrapper
|
|
144
|
-
* @param forwardPayload - payload that will be forwarded to the address which requested the data
|
|
145
|
-
*/
|
|
146
|
-
sendOnchainGetter(provider: ContractProvider, via: Sender, value: bigint, queryID: bigint, forwardPayload: Cell): Promise<void>;
|
|
147
|
-
/**
|
|
148
|
-
* Sync master contract data
|
|
149
|
-
*/
|
|
150
|
-
getSync(provider: ContractProvider): Promise<void>;
|
|
151
|
-
/**
|
|
152
|
-
* @deprecated Use PriceCollector (createPriceCollector) istead of getPrices
|
|
153
|
-
*/
|
|
154
|
-
getPrices(provider: ContractProvider, endpoints?: string[]): Promise<import("..").PriceData>;
|
|
155
|
-
createPriceCollector(priceSourcesConfig?: PriceSourcesConfig): PricesCollector;
|
|
156
|
-
}
|
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Evaa = void 0;
|
|
4
|
-
const core_1 = require("@ton/core");
|
|
5
|
-
const general_1 = require("../constants/general");
|
|
6
|
-
const UserContract_1 = require("./UserContract");
|
|
7
|
-
const parser_1 = require("../api/parser");
|
|
8
|
-
const JettonWallet_1 = require("./JettonWallet");
|
|
9
|
-
const userJettonWallet_1 = require("../utils/userJettonWallet");
|
|
10
|
-
const __1 = require("..");
|
|
11
|
-
/**
|
|
12
|
-
* Evaa master contract wrapper
|
|
13
|
-
*/
|
|
14
|
-
class Evaa {
|
|
15
|
-
/**
|
|
16
|
-
* Create Evaa contract wrapper
|
|
17
|
-
* @param parameters Evaa contract parameters
|
|
18
|
-
*/
|
|
19
|
-
constructor(parameters) {
|
|
20
|
-
this.lastSync = 0;
|
|
21
|
-
this._poolConfig = parameters?.poolConfig ?? __1.MAINNET_POOL_CONFIG;
|
|
22
|
-
this.address = this._poolConfig.masterAddress;
|
|
23
|
-
this.debug = parameters?.debug;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Returns pool config
|
|
27
|
-
*/
|
|
28
|
-
get poolConfig() {
|
|
29
|
-
return this._poolConfig;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Create supply message
|
|
33
|
-
* @returns supply message as a cell
|
|
34
|
-
*/
|
|
35
|
-
createSupplyMessage(parameters) {
|
|
36
|
-
if (!(0, __1.isTonAsset)(parameters.asset)) {
|
|
37
|
-
return (0, core_1.beginCell)()
|
|
38
|
-
.storeUint(general_1.OPCODES.JETTON_TRANSFER, 32)
|
|
39
|
-
.storeUint(parameters.queryID, 64)
|
|
40
|
-
.storeCoins(parameters.amount)
|
|
41
|
-
.storeAddress(this.address)
|
|
42
|
-
.storeAddress(parameters.responseAddress ?? parameters.userAddress)
|
|
43
|
-
.storeBit(0)
|
|
44
|
-
.storeCoins(parameters.forwardAmount ?? general_1.FEES.SUPPLY_JETTON_FWD)
|
|
45
|
-
.storeBit(1)
|
|
46
|
-
.storeRef((0, core_1.beginCell)()
|
|
47
|
-
.storeUint(general_1.OPCODES.SUPPLY, 32)
|
|
48
|
-
.storeInt(parameters.includeUserCode ? -1 : 0, 2)
|
|
49
|
-
.storeAddress(parameters.userAddress)
|
|
50
|
-
.storeUint(parameters.amountToTransfer, 64)
|
|
51
|
-
.storeRef(parameters.payload)
|
|
52
|
-
.endCell())
|
|
53
|
-
.endCell();
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
return (0, core_1.beginCell)()
|
|
57
|
-
.storeUint(general_1.OPCODES.SUPPLY, 32)
|
|
58
|
-
.storeUint(parameters.queryID, 64)
|
|
59
|
-
.storeInt(parameters.includeUserCode ? -1 : 0, 2)
|
|
60
|
-
.storeUint(parameters.amount, 64)
|
|
61
|
-
.storeAddress(parameters.userAddress)
|
|
62
|
-
.storeUint(parameters.amountToTransfer, 64)
|
|
63
|
-
.storeRef(parameters.payload)
|
|
64
|
-
.endCell();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Create withdraw message
|
|
69
|
-
* @returns withdraw message as a cell
|
|
70
|
-
*/
|
|
71
|
-
createWithdrawMessage(parameters) {
|
|
72
|
-
return (0, core_1.beginCell)()
|
|
73
|
-
.storeUint(general_1.OPCODES.WITHDRAW, 32)
|
|
74
|
-
.storeUint(parameters.queryID, 64)
|
|
75
|
-
.storeUint(parameters.asset.assetId, 256)
|
|
76
|
-
.storeUint(parameters.amount, 64)
|
|
77
|
-
.storeAddress(parameters.userAddress)
|
|
78
|
-
.storeInt(parameters.includeUserCode ? -1 : 0, 2)
|
|
79
|
-
.storeUint(parameters.amountToTransfer, 64)
|
|
80
|
-
.storeRef(parameters.payload)
|
|
81
|
-
.storeRef(parameters.priceData)
|
|
82
|
-
.endCell();
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Create liquidation message
|
|
86
|
-
* @returns liquidation message as a cell
|
|
87
|
-
*/
|
|
88
|
-
createLiquidationMessage(parameters) {
|
|
89
|
-
if (!(0, __1.isTonAsset)(parameters.asset)) {
|
|
90
|
-
return (0, core_1.beginCell)()
|
|
91
|
-
.storeUint(general_1.OPCODES.JETTON_TRANSFER, 32)
|
|
92
|
-
.storeUint(parameters.queryID, 64)
|
|
93
|
-
.storeCoins(parameters.liquidationAmount)
|
|
94
|
-
.storeAddress(this.address)
|
|
95
|
-
.storeAddress(parameters.responseAddress ?? parameters.liquidatorAddress)
|
|
96
|
-
.storeBit(0)
|
|
97
|
-
.storeCoins(parameters.forwardAmount ?? general_1.FEES.LIQUIDATION_JETTON_FWD)
|
|
98
|
-
.storeBit(1)
|
|
99
|
-
.storeRef((0, core_1.beginCell)()
|
|
100
|
-
.storeUint(general_1.OPCODES.LIQUIDATE, 32)
|
|
101
|
-
.storeAddress(parameters.borrowerAddress)
|
|
102
|
-
.storeAddress(parameters.liquidatorAddress)
|
|
103
|
-
.storeUint(parameters.collateralAsset, 256)
|
|
104
|
-
.storeUint(parameters.minCollateralAmount, 64)
|
|
105
|
-
.storeInt(parameters.includeUserCode ? -1 : 0, 2)
|
|
106
|
-
// do not need liquidationAmount in case of jetton liquidation because
|
|
107
|
-
// the exact amount of transferred jettons for liquidation is known
|
|
108
|
-
.storeUint(0, 64)
|
|
109
|
-
.storeRef((0, core_1.beginCell)()
|
|
110
|
-
.storeUint(parameters.payloadForwardAmount ?? 0, 64)
|
|
111
|
-
.storeRef(parameters.payload)
|
|
112
|
-
.endCell())
|
|
113
|
-
.storeRef(parameters.priceData)
|
|
114
|
-
.endCell())
|
|
115
|
-
.endCell();
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
return (0, core_1.beginCell)()
|
|
119
|
-
.storeUint(general_1.OPCODES.LIQUIDATE, 32)
|
|
120
|
-
.storeUint(parameters.queryID, 64)
|
|
121
|
-
.storeAddress(parameters.borrowerAddress)
|
|
122
|
-
.storeAddress(parameters.liquidatorAddress)
|
|
123
|
-
.storeUint(parameters.collateralAsset, 256)
|
|
124
|
-
.storeUint(parameters.minCollateralAmount, 64)
|
|
125
|
-
.storeInt(parameters.includeUserCode ? -1 : 0, 2)
|
|
126
|
-
.storeUint(parameters.liquidationAmount, 64)
|
|
127
|
-
.storeRef((0, core_1.beginCell)()
|
|
128
|
-
.storeUint(parameters.payloadForwardAmount ?? 0, 64)
|
|
129
|
-
.storeRef(parameters.payload)
|
|
130
|
-
.endCell())
|
|
131
|
-
.storeRef(parameters.priceData)
|
|
132
|
-
.endCell();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Calculate user contract address
|
|
137
|
-
* @param userAddress
|
|
138
|
-
* @returns user contract address
|
|
139
|
-
*/
|
|
140
|
-
calculateUserSCAddr(userAddress, lendingCode) {
|
|
141
|
-
const lendingData = (0, core_1.beginCell)()
|
|
142
|
-
.storeAddress(this.address)
|
|
143
|
-
.storeAddress(userAddress)
|
|
144
|
-
.storeUint(0, 8)
|
|
145
|
-
.storeBit(0)
|
|
146
|
-
.endCell();
|
|
147
|
-
const stateInit = (0, core_1.beginCell)()
|
|
148
|
-
.store((0, core_1.storeStateInit)({
|
|
149
|
-
code: lendingCode,
|
|
150
|
-
data: lendingData,
|
|
151
|
-
}))
|
|
152
|
-
.endCell();
|
|
153
|
-
return new core_1.Address(0, stateInit.hash());
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Open user contract wrapper
|
|
157
|
-
* @param userAddress
|
|
158
|
-
* @returns user contract
|
|
159
|
-
*/
|
|
160
|
-
openUserContract(userAddress) {
|
|
161
|
-
return UserContract_1.EvaaUser.createFromAddress(this.calculateUserSCAddr(userAddress, this._poolConfig.lendingCode), this._poolConfig);
|
|
162
|
-
}
|
|
163
|
-
getOpenedUserContract(provider, userAddress) {
|
|
164
|
-
return provider.open(this.openUserContract(userAddress));
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Get master contract data
|
|
168
|
-
*/
|
|
169
|
-
get data() {
|
|
170
|
-
return this._data;
|
|
171
|
-
}
|
|
172
|
-
async sendSupply(provider, via, value, parameters) {
|
|
173
|
-
const message = this.createSupplyMessage(parameters);
|
|
174
|
-
if (!(0, __1.isTonAsset)(parameters.asset)) {
|
|
175
|
-
if (!via.address) {
|
|
176
|
-
throw Error('Via address is required for jetton supply');
|
|
177
|
-
}
|
|
178
|
-
const jettonWallet = provider.open(JettonWallet_1.JettonWallet.createFromAddress((0, userJettonWallet_1.getUserJettonWallet)(via.address, parameters.asset)));
|
|
179
|
-
await jettonWallet.sendTransfer(via, value, message);
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
await provider.internal(via, {
|
|
183
|
-
value,
|
|
184
|
-
sendMode: core_1.SendMode.PAY_GAS_SEPARATELY + core_1.SendMode.IGNORE_ERRORS,
|
|
185
|
-
body: message,
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
async sendWithdraw(provider, via, value, parameters) {
|
|
190
|
-
const message = this.createWithdrawMessage(parameters);
|
|
191
|
-
await provider.internal(via, {
|
|
192
|
-
value,
|
|
193
|
-
sendMode: core_1.SendMode.PAY_GAS_SEPARATELY + core_1.SendMode.IGNORE_ERRORS,
|
|
194
|
-
body: message,
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
async sendLiquidation(provider, via, value, parameters) {
|
|
198
|
-
const message = this.createLiquidationMessage(parameters);
|
|
199
|
-
if (!(0, __1.isTonAssetId)(parameters.loanAsset)) {
|
|
200
|
-
if (!via.address) {
|
|
201
|
-
throw Error('Via address is required for jetton liquidation');
|
|
202
|
-
}
|
|
203
|
-
const jettonWallet = provider.open(JettonWallet_1.JettonWallet.createFromAddress((0, userJettonWallet_1.getUserJettonWallet)(via.address, parameters.asset)));
|
|
204
|
-
await jettonWallet.sendTransfer(via, value, message);
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
await provider.internal(via, {
|
|
208
|
-
value,
|
|
209
|
-
sendMode: core_1.SendMode.PAY_GAS_SEPARATELY + core_1.SendMode.IGNORE_ERRORS,
|
|
210
|
-
body: message,
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Open user contract wrapper
|
|
216
|
-
* @param forwardPayload - payload that will be forwarded to the address which requested the data
|
|
217
|
-
*/
|
|
218
|
-
async sendOnchainGetter(provider, via, value, queryID, forwardPayload) {
|
|
219
|
-
await provider.internal(via, {
|
|
220
|
-
value,
|
|
221
|
-
sendMode: core_1.SendMode.PAY_GAS_SEPARATELY + core_1.SendMode.IGNORE_ERRORS,
|
|
222
|
-
body: (0, core_1.beginCell)()
|
|
223
|
-
.storeUint(general_1.OPCODES.ONCHAIN_GETTER, 32)
|
|
224
|
-
.storeUint(queryID, 64)
|
|
225
|
-
.storeRef(forwardPayload)
|
|
226
|
-
.endCell(),
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Sync master contract data
|
|
231
|
-
*/
|
|
232
|
-
async getSync(provider) {
|
|
233
|
-
const state = (await provider.getState()).state;
|
|
234
|
-
if (state.type === 'active') {
|
|
235
|
-
this._data = (0, parser_1.parseMasterData)(state.data.toString('base64'), this._poolConfig.poolAssetsConfig, this._poolConfig.masterConstants);
|
|
236
|
-
if (this._data.upgradeConfig.masterCodeVersion !== this._poolConfig.masterVersion) {
|
|
237
|
-
throw Error(`Outdated SDK pool version. It supports only master code version ${this._poolConfig.masterVersion}, but the current master code version is ${this._data.upgradeConfig.masterCodeVersion}`);
|
|
238
|
-
}
|
|
239
|
-
this.lastSync = Math.floor(Date.now() / 1000);
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
throw Error('Master contract is not active');
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* @deprecated Use PriceCollector (createPriceCollector) istead of getPrices
|
|
247
|
-
*/
|
|
248
|
-
async getPrices(provider, endpoints) {
|
|
249
|
-
if ((endpoints?.length ?? 0) > 0) {
|
|
250
|
-
return await (0, __1.getPrices)(endpoints, this._poolConfig);
|
|
251
|
-
}
|
|
252
|
-
else {
|
|
253
|
-
return await (0, __1.getPrices)(undefined, this._poolConfig);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
createPriceCollector(priceSourcesConfig = __1.DefaultPriceSourcesConfig) {
|
|
257
|
-
return new __1.PricesCollector(this._poolConfig, priceSourcesConfig);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
exports.Evaa = Evaa;
|