@evaafi/sdk 0.5.1 → 0.5.4
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.d.ts +8 -8
- package/dist/api/math.js +30 -31
- package/dist/api/parser.d.ts +4 -4
- package/dist/api/parser.js +42 -46
- package/dist/api/prices.d.ts +1 -1
- package/dist/api/prices.js +21 -25
- package/dist/constants/assets.d.ts +16 -0
- package/dist/constants/assets.js +77 -0
- package/dist/constants/general.d.ts +38 -0
- package/dist/constants/general.js +41 -0
- package/dist/constants/pools.d.ts +5 -0
- package/dist/constants/pools.js +60 -0
- package/dist/contracts/MasterContract.d.ts +13 -11
- package/dist/contracts/MasterContract.js +39 -35
- package/dist/contracts/UserContract.d.ts +6 -7
- package/dist/contracts/UserContract.js +13 -13
- package/dist/index.d.ts +7 -4
- package/dist/index.js +45 -12
- package/dist/types/Master.d.ts +32 -2
- package/dist/types/User.d.ts +4 -3
- package/dist/utils/userJettonWallet.d.ts +2 -1
- package/dist/utils/userJettonWallet.js +45 -61
- package/package.json +8 -1
- package/src/api/math.ts +38 -36
- package/src/api/parser.ts +51 -52
- package/src/api/prices.ts +23 -25
- package/src/constants/assets.ts +117 -0
- package/src/constants/general.ts +54 -0
- package/src/constants/pools.ts +63 -0
- package/src/contracts/MasterContract.ts +51 -43
- package/src/contracts/UserContract.ts +24 -21
- package/src/index.ts +33 -4
- package/src/types/Master.ts +37 -2
- package/src/types/User.ts +4 -3
- package/src/utils/userJettonWallet.ts +67 -63
- package/src/constants.ts +0 -127
|
@@ -1,46 +1,48 @@
|
|
|
1
1
|
import { Address, beginCell, Cell, Contract, ContractProvider, Dictionary, Sender, SendMode } from '@ton/core';
|
|
2
2
|
import { UserData, UserLiteData } from '../types/User';
|
|
3
3
|
import { parseUserData, parseUserLiteData } from '../api/parser';
|
|
4
|
-
import { AssetConfig, ExtendedAssetData } from '../types/Master';
|
|
4
|
+
import { AssetConfig, ExtendedAssetData, ExtendedAssetsConfig, ExtendedAssetsData, PoolConfig } from '../types/Master';
|
|
5
5
|
import { LiquidationBaseData } from './MasterContract';
|
|
6
|
-
import {
|
|
6
|
+
import { OPCODES } from '../constants/general';
|
|
7
|
+
import { MAINNET_POOL_CONFIG } from '../constants/pools';
|
|
8
|
+
import { TON_MAINNET } from '../constants/assets';
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* User contract wrapper
|
|
10
12
|
*/
|
|
11
13
|
export class EvaaUser implements Contract {
|
|
12
14
|
readonly address: Address;
|
|
13
|
-
readonly testnet: boolean = false;
|
|
14
15
|
private lastSync = 0;
|
|
15
16
|
private _liteData?: UserLiteData;
|
|
16
17
|
private _data?: UserData;
|
|
18
|
+
private poolConfig: PoolConfig;
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* Create user contract wrapper from address
|
|
20
22
|
* @param address user contract address
|
|
21
|
-
* @param testnet testnet flag
|
|
22
23
|
*/
|
|
23
|
-
static createFromAddress(address: Address,
|
|
24
|
-
return new EvaaUser(address,
|
|
24
|
+
static createFromAddress(address: Address, poolConfig: PoolConfig = MAINNET_POOL_CONFIG) {
|
|
25
|
+
return new EvaaUser(address, poolConfig);
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
private constructor(address: Address,
|
|
28
|
+
private constructor(address: Address, poolConfig: PoolConfig = MAINNET_POOL_CONFIG) {
|
|
28
29
|
this.address = address;
|
|
29
|
-
this.
|
|
30
|
+
this.poolConfig = poolConfig;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
async getSyncLite(
|
|
33
34
|
provider: ContractProvider,
|
|
34
|
-
assetsData:
|
|
35
|
-
assetsConfig:
|
|
35
|
+
assetsData: ExtendedAssetsData,
|
|
36
|
+
assetsConfig: ExtendedAssetsConfig,
|
|
36
37
|
) {
|
|
37
38
|
const state = (await provider.getState()).state;
|
|
38
39
|
if (state.type === 'active') {
|
|
39
40
|
this._liteData = parseUserLiteData(
|
|
40
|
-
state.data!.toString('
|
|
41
|
+
state.data!.toString('base64'),
|
|
41
42
|
assetsData,
|
|
42
43
|
assetsConfig,
|
|
43
|
-
this.
|
|
44
|
+
this.poolConfig.poolAssetsConfig,
|
|
45
|
+
this.poolConfig.masterConstants
|
|
44
46
|
);
|
|
45
47
|
this.lastSync = Math.floor(Date.now() / 1000);
|
|
46
48
|
} else {
|
|
@@ -57,12 +59,12 @@ export class EvaaUser implements Contract {
|
|
|
57
59
|
* @returns true if user data was calculated
|
|
58
60
|
*/
|
|
59
61
|
calculateUserData(
|
|
60
|
-
assetsData:
|
|
61
|
-
assetsConfig:
|
|
62
|
+
assetsData: ExtendedAssetsData,
|
|
63
|
+
assetsConfig: ExtendedAssetsConfig,
|
|
62
64
|
prices: Dictionary<bigint, bigint>,
|
|
63
65
|
): boolean {
|
|
64
66
|
if (this._liteData) {
|
|
65
|
-
this._data = parseUserData(this._liteData, assetsData, assetsConfig, prices, this.
|
|
67
|
+
this._data = parseUserData(this._liteData, assetsData, assetsConfig, prices, this.poolConfig.poolAssetsConfig, this.poolConfig.masterConstants);
|
|
66
68
|
return true;
|
|
67
69
|
}
|
|
68
70
|
return false;
|
|
@@ -92,19 +94,20 @@ export class EvaaUser implements Contract {
|
|
|
92
94
|
|
|
93
95
|
async getSync(
|
|
94
96
|
provider: ContractProvider,
|
|
95
|
-
assetsData:
|
|
96
|
-
assetsConfig:
|
|
97
|
+
assetsData: ExtendedAssetsData,
|
|
98
|
+
assetsConfig: ExtendedAssetsConfig,
|
|
97
99
|
prices: Dictionary<bigint, bigint>,
|
|
98
100
|
) {
|
|
99
101
|
const state = (await provider.getState()).state;
|
|
100
102
|
if (state.type === 'active') {
|
|
101
103
|
this._liteData = parseUserLiteData(
|
|
102
|
-
state.data!.toString('
|
|
104
|
+
state.data!.toString('base64'),
|
|
103
105
|
assetsData,
|
|
104
106
|
assetsConfig,
|
|
105
|
-
this.
|
|
107
|
+
this.poolConfig.poolAssetsConfig,
|
|
108
|
+
this.poolConfig.masterConstants
|
|
106
109
|
);
|
|
107
|
-
this._data = parseUserData(this._liteData, assetsData, assetsConfig, prices, this.
|
|
110
|
+
this._data = parseUserData(this._liteData, assetsData, assetsConfig, prices, this.poolConfig.poolAssetsConfig, this.poolConfig.masterConstants);
|
|
108
111
|
this.lastSync = Math.floor(Date.now() / 1000);
|
|
109
112
|
} else {
|
|
110
113
|
this._data = { type: 'inactive' };
|
|
@@ -154,7 +157,7 @@ export class EvaaUser implements Contract {
|
|
|
154
157
|
collateralAsset: this._data.liquidationData.greatestCollateralAsset,
|
|
155
158
|
minCollateralAmount: this._data.liquidationData.minCollateralAmount,
|
|
156
159
|
liquidationAmount: this._data.liquidationData.liquidationAmount,
|
|
157
|
-
tonLiquidation: this._data.liquidationData.greatestLoanAsset ===
|
|
160
|
+
tonLiquidation: this._data.liquidationData.greatestLoanAsset === TON_MAINNET.assetId,
|
|
158
161
|
};
|
|
159
162
|
}
|
|
160
163
|
}
|
package/src/index.ts
CHANGED
|
@@ -17,7 +17,7 @@ export {
|
|
|
17
17
|
export { createAssetData, createAssetConfig, parseMasterData, parseUserData, parseUserLiteData } from './api/parser';
|
|
18
18
|
|
|
19
19
|
// Prices
|
|
20
|
-
export {
|
|
20
|
+
export { getPricesByNft } from './api/prices';
|
|
21
21
|
|
|
22
22
|
// Contracts' wrappers
|
|
23
23
|
export { JettonWallet } from './contracts/JettonWallet';
|
|
@@ -45,6 +45,11 @@ export {
|
|
|
45
45
|
AssetApy,
|
|
46
46
|
ExtendedAssetData,
|
|
47
47
|
MasterData,
|
|
48
|
+
PoolConfig,
|
|
49
|
+
ExtendedAssetsData,
|
|
50
|
+
ExtendedAssetsConfig,
|
|
51
|
+
PoolAssetConfig,
|
|
52
|
+
PoolAssetsConfig,
|
|
48
53
|
} from './types/Master';
|
|
49
54
|
export {
|
|
50
55
|
BalanceType,
|
|
@@ -56,6 +61,7 @@ export {
|
|
|
56
61
|
UserDataInactive,
|
|
57
62
|
UserDataActive,
|
|
58
63
|
UserData,
|
|
64
|
+
BalanceChangeType
|
|
59
65
|
} from './types/User';
|
|
60
66
|
|
|
61
67
|
// Constants
|
|
@@ -64,12 +70,35 @@ export {
|
|
|
64
70
|
MAINNET_VERSION,
|
|
65
71
|
EVAA_MASTER_TESTNET,
|
|
66
72
|
TESTNET_VERSION,
|
|
67
|
-
JETTON_MASTER_ADDRESSES,
|
|
68
|
-
MASTER_CONSTANTS,
|
|
69
73
|
LENDING_CODE,
|
|
70
74
|
OPCODES,
|
|
71
75
|
FEES,
|
|
72
|
-
|
|
76
|
+
MASTER_CONSTANTS
|
|
77
|
+
} from './constants/general';
|
|
78
|
+
|
|
79
|
+
export {
|
|
80
|
+
MAINNET_POOL_CONFIG,
|
|
81
|
+
TESTNET_POOL_CONFIG,
|
|
82
|
+
MAINNET_LP_POOL_CONFIG,
|
|
83
|
+
TESTNET_LP_POOL_CONFIG
|
|
84
|
+
} from './constants/pools';
|
|
85
|
+
|
|
86
|
+
export {
|
|
87
|
+
TON_MAINNET,
|
|
88
|
+
USDT_MAINNET,
|
|
89
|
+
TONUSDT_DEDUST_MAINNET,
|
|
90
|
+
TON_STORM_MAINNET,
|
|
91
|
+
USDT_STORM_MAINNET,
|
|
92
|
+
JUSDT_MAINNET,
|
|
93
|
+
JUSDC_MAINNET,
|
|
94
|
+
STTON_MAINNET,
|
|
95
|
+
TSTON_MAINNET,
|
|
96
|
+
JUSDT_TESTNET,
|
|
97
|
+
JUSDC_TESTNET,
|
|
98
|
+
STTON_TESTNET,
|
|
99
|
+
} from './constants/assets';
|
|
100
|
+
|
|
101
|
+
export * from './constants/assets'
|
|
73
102
|
|
|
74
103
|
// Utils
|
|
75
104
|
export { getLastSentBoc, getTonConnectSender } from './utils/tonConnectSender';
|
package/src/types/Master.ts
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
import { Address, Cell, Dictionary } from '@ton/core';
|
|
2
2
|
|
|
3
|
+
export type MasterConstants = {
|
|
4
|
+
FACTOR_SCALE: bigint,
|
|
5
|
+
ASSET_COEFFICIENT_SCALE: bigint,
|
|
6
|
+
ASSET_PRICE_SCALE: bigint,
|
|
7
|
+
ASSET_RESERVE_FACTOR_SCALE: bigint,
|
|
8
|
+
ASSET_LIQUIDATION_RESERVE_FACTOR_SCALE: bigint,
|
|
9
|
+
ASSET_ORIGINATION_FEE_SCALE: bigint
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type PoolAssetConfig = (PoolTonAssetConfig | PoolJettonAssetConfig) & {
|
|
13
|
+
name: string;
|
|
14
|
+
};
|
|
15
|
+
export type PoolAssetsConfig = PoolAssetConfig[];
|
|
16
|
+
|
|
17
|
+
export type PoolTonAssetConfig = {
|
|
18
|
+
assetId: bigint;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type PoolJettonAssetConfig = {
|
|
22
|
+
assetId: bigint;
|
|
23
|
+
jettonMasterAddress: Address;
|
|
24
|
+
jettonWalletCode: Cell;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type PoolConfig = {
|
|
28
|
+
masterAddress: Address;
|
|
29
|
+
masterVersion: number;
|
|
30
|
+
masterConstants: MasterConstants;
|
|
31
|
+
nftId: string;
|
|
32
|
+
poolAssetsConfig: PoolAssetsConfig;
|
|
33
|
+
lendingCode: Cell;
|
|
34
|
+
};
|
|
35
|
+
|
|
3
36
|
export type UpgradeConfig = {
|
|
4
37
|
masterCodeVersion: number;
|
|
5
38
|
userCodeVersion: number;
|
|
@@ -67,13 +100,15 @@ export type AssetApy = {
|
|
|
67
100
|
};
|
|
68
101
|
|
|
69
102
|
export type ExtendedAssetData = AssetData & AssetInterest & AssetApy;
|
|
103
|
+
export type ExtendedAssetsData = Dictionary<bigint, ExtendedAssetData>;
|
|
104
|
+
export type ExtendedAssetsConfig = Dictionary<bigint, AssetConfig>;
|
|
70
105
|
|
|
71
106
|
export type MasterData = {
|
|
72
107
|
meta: string;
|
|
73
108
|
upgradeConfig: UpgradeConfig;
|
|
74
109
|
masterConfig: MasterConfig;
|
|
75
|
-
assetsConfig:
|
|
76
|
-
assetsData:
|
|
110
|
+
assetsConfig: ExtendedAssetsConfig;
|
|
111
|
+
assetsData: ExtendedAssetsData;
|
|
77
112
|
assetsReserves: Dictionary<bigint, bigint>;
|
|
78
113
|
apy: {
|
|
79
114
|
supply: Dictionary<bigint, number>;
|
package/src/types/User.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Address, Cell, Dictionary } from '@ton/core';
|
|
2
|
-
import { AssetConfig, ExtendedAssetData } from './Master';
|
|
2
|
+
import { AssetConfig, ExtendedAssetData, ExtendedAssetsConfig, ExtendedAssetsData, MasterConfig, MasterConstants } from './Master';
|
|
3
3
|
|
|
4
4
|
export enum BalanceType {
|
|
5
5
|
supply = 'supply',
|
|
@@ -88,6 +88,7 @@ export type PredictHealthFactorArgs = {
|
|
|
88
88
|
tokenSymbol: string;
|
|
89
89
|
balances: Dictionary<bigint, bigint>;
|
|
90
90
|
prices: Dictionary<bigint, bigint>;
|
|
91
|
-
assetsData:
|
|
92
|
-
assetsConfig:
|
|
91
|
+
assetsData: ExtendedAssetsData;
|
|
92
|
+
assetsConfig: ExtendedAssetsConfig;
|
|
93
|
+
masterConstants: MasterConstants;
|
|
93
94
|
};
|
|
@@ -1,68 +1,72 @@
|
|
|
1
1
|
import { Address, beginCell, Cell, storeStateInit } from '@ton/core';
|
|
2
|
-
import {
|
|
2
|
+
import { PoolAssetConfig, PoolJettonAssetConfig } from '../types/Master';
|
|
3
|
+
|
|
4
|
+
export function getUserJettonWallet(ownerAddress: Address, poolAssetConfig: PoolAssetConfig & PoolJettonAssetConfig) {
|
|
5
|
+
const jettonMasterAddress = poolAssetConfig.jettonMasterAddress;
|
|
6
|
+
const jettonWalletCode = poolAssetConfig.jettonWalletCode;
|
|
7
|
+
|
|
8
|
+
if (poolAssetConfig.name === 'USDT') {
|
|
9
|
+
const lib_prep = beginCell().storeUint(2, 8).storeBuffer(jettonWalletCode.hash()).endCell();
|
|
10
|
+
const jwallet_code = new Cell({ exotic: true, bits: lib_prep.bits, refs: lib_prep.refs });
|
|
11
|
+
|
|
12
|
+
const jettonData = beginCell()
|
|
13
|
+
.storeUint(0, 4)
|
|
14
|
+
.storeCoins(0)
|
|
15
|
+
.storeAddress(ownerAddress)
|
|
16
|
+
.storeAddress(jettonMasterAddress)
|
|
17
|
+
.endCell();
|
|
18
|
+
|
|
19
|
+
const stateInit = beginCell()
|
|
20
|
+
.store(
|
|
21
|
+
storeStateInit({
|
|
22
|
+
code: jwallet_code,
|
|
23
|
+
data: jettonData
|
|
24
|
+
})
|
|
25
|
+
)
|
|
26
|
+
.endCell();
|
|
27
|
+
return new Address(0, stateInit.hash());
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (poolAssetConfig.name === 'tsTON') {
|
|
31
|
+
const lib_prep = beginCell().storeUint(2, 8).storeBuffer(jettonWalletCode.hash()).endCell();
|
|
32
|
+
const jwallet_code = new Cell({ exotic: true, bits: lib_prep.bits, refs: lib_prep.refs });
|
|
33
|
+
|
|
34
|
+
const jettonData = beginCell()
|
|
35
|
+
.storeCoins(0)
|
|
36
|
+
.storeAddress(ownerAddress)
|
|
37
|
+
.storeAddress(jettonMasterAddress)
|
|
38
|
+
.storeRef(jwallet_code)
|
|
39
|
+
.storeCoins(0)
|
|
40
|
+
.storeUint(0, 48)
|
|
41
|
+
.endCell();
|
|
3
42
|
|
|
4
|
-
export function getUserJettonWallet(ownerAddress: Address, assetID: bigint, network: 'mainnet' | 'testnet'): Address {
|
|
5
|
-
const builder = beginCell().storeCoins(0).storeAddress(ownerAddress);
|
|
6
|
-
let jettonWalletCode: Cell;
|
|
7
|
-
switch (assetID) {
|
|
8
|
-
case MAINNET_ASSETS_ID.jUSDT:
|
|
9
|
-
if (network === 'mainnet') {
|
|
10
|
-
builder.storeAddress(JETTON_MASTER_ADDRESSES.jUSDT_MAINNET);
|
|
11
|
-
jettonWalletCode = JETTON_WALLETS_CODE.jUSDT_MAINNET;
|
|
12
|
-
} else {
|
|
13
|
-
builder.storeAddress(JETTON_MASTER_ADDRESSES.jUSDT_TESTNET);
|
|
14
|
-
jettonWalletCode = JETTON_WALLETS_CODE.jUSDT_TESTNET;
|
|
15
|
-
}
|
|
16
|
-
break;
|
|
17
|
-
case MAINNET_ASSETS_ID.jUSDC:
|
|
18
|
-
if (network === 'mainnet') {
|
|
19
|
-
builder.storeAddress(JETTON_MASTER_ADDRESSES.jUSDC_MAINNET);
|
|
20
|
-
jettonWalletCode = JETTON_WALLETS_CODE.jUSDC_MAINNET;
|
|
21
|
-
} else {
|
|
22
|
-
builder.storeAddress(JETTON_MASTER_ADDRESSES.jUSDC_TESTNET);
|
|
23
|
-
jettonWalletCode = JETTON_WALLETS_CODE.jUSDC_TESTNET;
|
|
24
|
-
}
|
|
25
|
-
break;
|
|
26
|
-
case MAINNET_ASSETS_ID.stTON:
|
|
27
|
-
if (network === 'mainnet') {
|
|
28
|
-
builder.storeAddress(JETTON_MASTER_ADDRESSES.stTON_MAINNET);
|
|
29
|
-
jettonWalletCode = JETTON_WALLETS_CODE.stTON_MAINNET;
|
|
30
|
-
} else {
|
|
31
|
-
builder.storeAddress(JETTON_MASTER_ADDRESSES.stTON_TESTNET);
|
|
32
|
-
jettonWalletCode = JETTON_WALLETS_CODE.stTON_TESTNET;
|
|
33
|
-
}
|
|
34
|
-
break;
|
|
35
|
-
case MAINNET_ASSETS_ID.tsTON:
|
|
36
|
-
if (network === 'mainnet') {
|
|
37
|
-
builder.storeAddress(JETTON_MASTER_ADDRESSES.tsTON_MAINNET);
|
|
38
|
-
jettonWalletCode = JETTON_WALLETS_CODE.tsTON_MAINNET;
|
|
39
|
-
} else {
|
|
40
|
-
// builder.storeAddress(JETTON_MASTER_ADDRESSES.tsTON_TESTNET);
|
|
41
|
-
// jettonWalletCode = JETTON_WALLETS_CODE.tsTON_TESTNET;
|
|
42
|
-
throw new Error('tsTON is not supported on testnet');
|
|
43
|
-
}
|
|
44
|
-
break;
|
|
45
|
-
case MAINNET_ASSETS_ID.USDT:
|
|
46
|
-
if (network === 'mainnet') {
|
|
47
|
-
builder.storeAddress(JETTON_MASTER_ADDRESSES.USDT_MAINNET);
|
|
48
|
-
jettonWalletCode = JETTON_WALLETS_CODE.USDT_MAINNET;
|
|
49
|
-
} else {
|
|
50
|
-
// builder.storeAddress(JETTON_MASTER_ADDRESSES.USDT_TESTNET);
|
|
51
|
-
// jettonWalletCode = JETTON_WALLETS_CODE.USDT_TESTNET;
|
|
52
|
-
throw new Error('USDT is not supported on testnet');
|
|
53
|
-
}
|
|
54
|
-
break;
|
|
55
|
-
default:
|
|
56
|
-
throw new Error('Unsupported asset');
|
|
57
|
-
}
|
|
58
|
-
const data = builder.storeRef(jettonWalletCode).endCell();
|
|
59
43
|
const stateInit = beginCell()
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
44
|
+
.store(
|
|
45
|
+
storeStateInit({
|
|
46
|
+
code: jwallet_code,
|
|
47
|
+
data: jettonData
|
|
48
|
+
})
|
|
49
|
+
)
|
|
50
|
+
.endCell();
|
|
51
|
+
|
|
67
52
|
return new Address(0, stateInit.hash());
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const jettonData = beginCell()
|
|
56
|
+
.storeCoins(0)
|
|
57
|
+
.storeAddress(ownerAddress)
|
|
58
|
+
.storeAddress(jettonMasterAddress)
|
|
59
|
+
.storeRef(jettonWalletCode)
|
|
60
|
+
.endCell();
|
|
61
|
+
|
|
62
|
+
const stateInit = beginCell()
|
|
63
|
+
.store(
|
|
64
|
+
storeStateInit({
|
|
65
|
+
code: jettonWalletCode,
|
|
66
|
+
data: jettonData
|
|
67
|
+
})
|
|
68
|
+
)
|
|
69
|
+
.endCell();
|
|
70
|
+
|
|
71
|
+
return new Address(0, stateInit.hash());
|
|
68
72
|
}
|
package/src/constants.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { Address, Cell, toNano } from '@ton/core';
|
|
2
|
-
import { sha256Hash } from './utils/sha256BigInt';
|
|
3
|
-
|
|
4
|
-
export const EVAA_MASTER_MAINNET = Address.parse('EQC8rUZqR_pWV1BylWUlPNBzyiTYVoBEmQkMIQDZXICfnuRr');
|
|
5
|
-
export const MAINNET_VERSION = 5;
|
|
6
|
-
export const EVAA_MASTER_TESTNET = Address.parse('kQCj7qf3i2Cbf1GVtZCinla7lIvE7l3MBMsJMTfAja3BdoRP');
|
|
7
|
-
export const TESTNET_VERSION = 5;
|
|
8
|
-
|
|
9
|
-
export const NFT_ID = '0xfb9874544d76ca49c5db9cc3e5121e4c018bc8a2fb2bfe8f2a38c5b9963492f5';
|
|
10
|
-
|
|
11
|
-
export const MAINNET_ASSETS_ID = {
|
|
12
|
-
TON: sha256Hash('TON'),
|
|
13
|
-
jUSDT: sha256Hash('jUSDT'),
|
|
14
|
-
jUSDC: sha256Hash('jUSDC'),
|
|
15
|
-
stTON: sha256Hash('stTON'),
|
|
16
|
-
tsTON: sha256Hash('tsTON'),
|
|
17
|
-
USDT: sha256Hash('USDT'),
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const TESTNET_ASSETS_ID = {
|
|
21
|
-
TON: sha256Hash('TON'),
|
|
22
|
-
jUSDT: sha256Hash('jUSDT'),
|
|
23
|
-
jUSDC: sha256Hash('jUSDC'),
|
|
24
|
-
stTON: sha256Hash('stTON'),
|
|
25
|
-
// tsTON: sha256Hash('tsTON'),
|
|
26
|
-
// USDT: sha256Hash('USDT'),
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const JETTON_MASTER_ADDRESSES = {
|
|
30
|
-
jUSDT_MAINNET: Address.parse('EQBynBO23ywHy_CgarY9NK9FTz0yDsG82PtcbSTQgGoXwiuA'),
|
|
31
|
-
jUSDT_TESTNET: Address.parse('kQBe4gtSQMxM5RpMYLr4ydNY72F8JkY-icZXG1NJcsju8XM7'),
|
|
32
|
-
jUSDC_MAINNET: Address.parse('EQB-MPwrd1G6WKNkLz_VnV6WqBDd142KMQv-g1O-8QUA3728'),
|
|
33
|
-
jUSDC_TESTNET: Address.parse('kQDaY5yUatYnHei73HBqRX_Ox9LK2XnR7XuCY9MFC2INbfYI'),
|
|
34
|
-
stTON_MAINNET: Address.parse('EQDNhy-nxYFgUqzfUzImBEP67JqsyMIcyk2S5_RwNNEYku0k'),
|
|
35
|
-
stTON_TESTNET: Address.parse('kQC3Duw3dg8k98xf5S7Bm7YOWVJ5QW8hm3iLqFfJfa_g9h07'),
|
|
36
|
-
tsTON_MAINNET: Address.parse('EQC98_qAmNEptUtPc7W6xdHh_ZHrBUFpw5Ft_IzNU20QAJav'),
|
|
37
|
-
tsTON_TESTNET: null,
|
|
38
|
-
USDT_MAINNET: Address.parse('EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs'),
|
|
39
|
-
USDT_TESTNET: null,
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export const MASTER_CONSTANTS = {
|
|
43
|
-
FACTOR_SCALE: BigInt(1e12),
|
|
44
|
-
ASSET_COEFFICIENT_SCALE: 10000n,
|
|
45
|
-
ASSET_PRICE_SCALE: BigInt(1e8),
|
|
46
|
-
ASSET_RESERVE_FACTOR_SCALE: 10000n,
|
|
47
|
-
ASSET_LIQUIDATION_RESERVE_FACTOR_SCALE: 10000n,
|
|
48
|
-
ASSET_ORIGINATION_FEE_SCALE: BigInt(1e9)
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export const LENDING_CODE = Cell.fromBoc(
|
|
52
|
-
Buffer.from(
|
|
53
|
-
'b5ee9c72c1010e0100fd000d12182a555a6065717691969efd0114ff00f4a413f4bcf2c80b010202c8050202039f740403001ff2f8276a2687d2018fd201800f883b840051d38642c678b64e4400780e58fc10802faf07f80e59fa801e78b096664c02078067c07c100627a7978402014807060007a0ddb0c60201c709080013a0fd007a026900aa90400201200b0a0031b8e1002191960aa00b9e2ca007f4042796d225e8019203f6010201200d0c000bf7c147d2218400b9d10e86981fd201840b07f8138d809797976a2687d2029116382f970fd9178089910374daf81b619fd20182c7883b8701981684100627910eba56001797a6a6ba610fd8200e8768f76a9f6aa00cc2a32a8292878809bef2f1889f883bbcdeb86f01',
|
|
54
|
-
'hex',
|
|
55
|
-
),
|
|
56
|
-
)[0];
|
|
57
|
-
|
|
58
|
-
export const JETTON_WALLETS_CODE = {
|
|
59
|
-
jUSDT_MAINNET: Cell.fromBoc(
|
|
60
|
-
Buffer.from(
|
|
61
|
-
'b5ee9c7201021301000385000114ff00f4a413f4bcf2c80b0102016202030202cb0405001ba0f605da89a1f401f481f481a9a30201ce06070201580a0b02f70831c02497c138007434c0c05c6c2544d7c0fc07783e903e900c7e800c5c75c87e800c7e800c1cea6d0000b4c7c076cf16cc8d0d0d09208403e29fa96ea68c1b088d978c4408fc06b809208405e351466ea6cc1b08978c840910c03c06f80dd6cda0841657c1ef2ea7c09c6c3cb4b01408eebcb8b1807c073817c160080900113e910c30003cb85360005c804ff833206e953080b1f833de206ef2d29ad0d30731d3ffd3fff404d307d430d0fa00fa00fa00fa00fa00fa00300008840ff2f00201580c0d020148111201f70174cfc0407e803e90087c007b51343e803e903e903534544da8548b31c17cb8b04ab0bffcb8b0950d109c150804d50500f214013e809633c58073c5b33248b232c044bd003d0032c032481c007e401d3232c084b281f2fff274013e903d010c7e800835d270803cb8b13220060072c15401f3c59c3e809dc072dae00e02f33b51343e803e903e90353442b4cfc0407e80145468017e903e9014d771c1551cdbdc150804d50500f214013e809633c58073c5b33248b232c044bd003d0032c0325c007e401d3232c084b281f2fff2741403f1c147ac7cb8b0c33e801472a84a6d8206685401e8062849a49b1578c34975c2c070c00870802c200f1000aa13ccc88210178d4519580a02cb1fcb3f5007fa0222cf165006cf1625fa025003cf16c95005cc2391729171e25007a813a008aa005004a017a014bcf2e2c501c98040fb004300c85004fa0258cf1601cf16ccc9ed5400725269a018a1c882107362d09c2902cb1fcb3f5007fa025004cf165007cf16c9c8801001cb0527cf165004fa027101cb6a13ccc971fb0050421300748e23c8801001cb055006cf165005fa027001cb6a8210d53276db580502cb1fcb3fc972fb00925b33e24003c85004fa0258cf1601cf16ccc9ed5400eb3b51343e803e903e9035344174cfc0407e800870803cb8b0be903d01007434e7f440745458a8549631c17cb8b049b0bffcb8b0b220841ef765f7960100b2c7f2cfc07e8088f3c58073c584f2e7f27220060072c148f3c59c3e809c4072dab33260103ec01004f214013e809633c58073c5b3327b55200087200835c87b51343e803e903e9035344134c7c06103c8608405e351466e80a0841ef765f7ae84ac7cbd34cfc04c3e800c04e81408f214013e809633c58073c5b3327b5520',
|
|
62
|
-
'hex',
|
|
63
|
-
),
|
|
64
|
-
)[0],
|
|
65
|
-
jUSDT_TESTNET: Cell.fromBoc(
|
|
66
|
-
Buffer.from(
|
|
67
|
-
'b5ee9c7201021101000323000114ff00f4a413f4bcf2c80b0102016202030202cc0405001ba0f605da89a1f401f481f481a8610201d40607020120080900c30831c02497c138007434c0c05c6c2544d7c0fc03383e903e900c7e800c5c75c87e800c7e800c1cea6d0000b4c7e08403e29fa954882ea54c4d167c0278208405e3514654882ea58c511100fc02b80d60841657c1ef2ea4d67c02f817c12103fcbc2000113e910c1c2ebcb853600201200a0b0083d40106b90f6a2687d007d207d206a1802698fc1080bc6a28ca9105d41083deecbef09dd0958f97162e99f98fd001809d02811e428027d012c678b00e78b6664f6aa401f1503d33ffa00fa4021f001ed44d0fa00fa40fa40d4305136a1522ac705f2e2c128c2fff2e2c254344270542013541403c85004fa0258cf1601cf16ccc922c8cb0112f400f400cb00c920f9007074c8cb02ca07cbffc9d004fa40f40431fa0020d749c200f2e2c4778018c8cb055008cf1670fa0217cb6b13cc80c0201200d0e009e8210178d4519c8cb1f19cb3f5007fa0222cf165006cf1625fa025003cf16c95005cc2391729171e25008a813a08209c9c380a014bcf2e2c504c98040fb001023c85004fa0258cf1601cf16ccc9ed5402f73b51343e803e903e90350c0234cffe80145468017e903e9014d6f1c1551cdb5c150804d50500f214013e809633c58073c5b33248b232c044bd003d0032c0327e401c1d3232c0b281f2fff274140371c1472c7cb8b0c2be80146a2860822625a019ad822860822625a028062849e5c412440e0dd7c138c34975c2c0600f1000d73b51343e803e903e90350c01f4cffe803e900c145468549271c17cb8b049f0bffcb8b08160824c4b402805af3cb8b0e0841ef765f7b232c7c572cfd400fe8088b3c58073c5b25c60063232c14933c59c3e80b2dab33260103ec01004f214013e809633c58073c5b3327b552000705279a018a182107362d09cc8cb1f5230cb3f58fa025007cf165007cf16c9718010c8cb0524cf165006fa0215cb6a14ccc971fb0010241023007cc30023c200b08e218210d53276db708010c8cb055008cf165004fa0216cb6a12cb1f12cb3fc972fb0093356c21e203c85004fa0258cf1601cf16ccc9ed54',
|
|
68
|
-
'hex',
|
|
69
|
-
),
|
|
70
|
-
)[0],
|
|
71
|
-
jUSDC_MAINNET: Cell.fromBoc(
|
|
72
|
-
Buffer.from(
|
|
73
|
-
'b5ee9c7201021301000385000114ff00f4a413f4bcf2c80b0102016202030202cb0405001ba0f605da89a1f401f481f481a9a30201ce06070201580a0b02f70831c02497c138007434c0c05c6c2544d7c0fc07783e903e900c7e800c5c75c87e800c7e800c1cea6d0000b4c7c076cf16cc8d0d0d09208403e29fa96ea68c1b088d978c4408fc06b809208405e351466ea6cc1b08978c840910c03c06f80dd6cda0841657c1ef2ea7c09c6c3cb4b01408eebcb8b1807c073817c160080900113e910c30003cb85360005c804ff833206e953080b1f833de206ef2d29ad0d30731d3ffd3fff404d307d430d0fa00fa00fa00fa00fa00fa00300008840ff2f00201580c0d020148111201f70174cfc0407e803e90087c007b51343e803e903e903534544da8548b31c17cb8b04ab0bffcb8b0950d109c150804d50500f214013e809633c58073c5b33248b232c044bd003d0032c032481c007e401d3232c084b281f2fff274013e903d010c7e800835d270803cb8b13220060072c15401f3c59c3e809dc072dae00e02f33b51343e803e903e90353442b4cfc0407e80145468017e903e9014d771c1551cdbdc150804d50500f214013e809633c58073c5b33248b232c044bd003d0032c0325c007e401d3232c084b281f2fff2741403f1c147ac7cb8b0c33e801472a84a6d8206685401e8062849a49b1578c34975c2c070c00870802c200f1000aa13ccc88210178d4519580a02cb1fcb3f5007fa0222cf165006cf1625fa025003cf16c95005cc2391729171e25007a813a008aa005004a017a014bcf2e2c501c98040fb004300c85004fa0258cf1601cf16ccc9ed5400725269a018a1c882107362d09c2902cb1fcb3f5007fa025004cf165007cf16c9c8801001cb0527cf165004fa027101cb6a13ccc971fb0050421300748e23c8801001cb055006cf165005fa027001cb6a8210d53276db580502cb1fcb3fc972fb00925b33e24003c85004fa0258cf1601cf16ccc9ed5400eb3b51343e803e903e9035344174cfc0407e800870803cb8b0be903d01007434e7f440745458a8549631c17cb8b049b0bffcb8b0b220841ef765f7960100b2c7f2cfc07e8088f3c58073c584f2e7f27220060072c148f3c59c3e809c4072dab33260103ec01004f214013e809633c58073c5b3327b55200087200835c87b51343e803e903e9035344134c7c06103c8608405e351466e80a0841ef765f7ae84ac7cbd34cfc04c3e800c04e81408f214013e809633c58073c5b3327b5520',
|
|
74
|
-
'hex',
|
|
75
|
-
),
|
|
76
|
-
)[0],
|
|
77
|
-
jUSDC_TESTNET: Cell.fromBoc(
|
|
78
|
-
Buffer.from(
|
|
79
|
-
'b5ee9c7201021101000323000114ff00f4a413f4bcf2c80b0102016202030202cc0405001ba0f605da89a1f401f481f481a8610201d40607020120080900c30831c02497c138007434c0c05c6c2544d7c0fc03383e903e900c7e800c5c75c87e800c7e800c1cea6d0000b4c7e08403e29fa954882ea54c4d167c0278208405e3514654882ea58c511100fc02b80d60841657c1ef2ea4d67c02f817c12103fcbc2000113e910c1c2ebcb853600201200a0b0083d40106b90f6a2687d007d207d206a1802698fc1080bc6a28ca9105d41083deecbef09dd0958f97162e99f98fd001809d02811e428027d012c678b00e78b6664f6aa401f1503d33ffa00fa4021f001ed44d0fa00fa40fa40d4305136a1522ac705f2e2c128c2fff2e2c254344270542013541403c85004fa0258cf1601cf16ccc922c8cb0112f400f400cb00c920f9007074c8cb02ca07cbffc9d004fa40f40431fa0020d749c200f2e2c4778018c8cb055008cf1670fa0217cb6b13cc80c0201200d0e009e8210178d4519c8cb1f19cb3f5007fa0222cf165006cf1625fa025003cf16c95005cc2391729171e25008a813a08209c9c380a014bcf2e2c504c98040fb001023c85004fa0258cf1601cf16ccc9ed5402f73b51343e803e903e90350c0234cffe80145468017e903e9014d6f1c1551cdb5c150804d50500f214013e809633c58073c5b33248b232c044bd003d0032c0327e401c1d3232c0b281f2fff274140371c1472c7cb8b0c2be80146a2860822625a019ad822860822625a028062849e5c412440e0dd7c138c34975c2c0600f1000d73b51343e803e903e90350c01f4cffe803e900c145468549271c17cb8b049f0bffcb8b08160824c4b402805af3cb8b0e0841ef765f7b232c7c572cfd400fe8088b3c58073c5b25c60063232c14933c59c3e80b2dab33260103ec01004f214013e809633c58073c5b3327b552000705279a018a182107362d09cc8cb1f5230cb3f58fa025007cf165007cf16c9718010c8cb0524cf165006fa0215cb6a14ccc971fb0010241023007cc30023c200b08e218210d53276db708010c8cb055008cf165004fa0216cb6a12cb1f12cb3fc972fb0093356c21e203c85004fa0258cf1601cf16ccc9ed54',
|
|
80
|
-
'hex',
|
|
81
|
-
),
|
|
82
|
-
)[0],
|
|
83
|
-
stTON_MAINNET: Cell.fromBoc(
|
|
84
|
-
Buffer.from(
|
|
85
|
-
'b5ee9c7201021201000362000114ff00f4a413f4bcf2c80b0102016202030202cc0405001ba0f605da89a1f401f481f481a8610201d40607020120090a01cf0831c02497c138007434c0c05c6c2544d7c0fc03783e903e900c7e800c5c75c87e800c7e800c1cea6d0000b4c7c8608403e29fa96ea54c4d167c02b808608405e351466ea58c511100fc02f80860841657c1ef2ea54c4d167c03380517c1300138c08c2103fcbc200800113e910c30003cb85360007ced44d0fa00fa40fa40d43010235f03018208989680a16d801072226eb32091719170e203c8cb055006cf165004fa02cb6a039358cc019130e201c901fb000201580b0c020148101101f100f4cffe803e90087c007b51343e803e903e90350c144da8548ab1c17cb8b04a30bffcb8b0950d109c150804d50500f214013e809633c58073c5b33248b232c044bd003d0032c032483e401c1d3232c0b281f2fff274013e903d010c7e800835d270803cb8b11de0063232c1540233c59c3e8085f2dac4f3200d02f73b51343e803e903e90350c0234cffe80145468017e903e9014d6f1c1551cdb5c150804d50500f214013e809633c58073c5b33248b232c044bd003d0032c0327e401c1d3232c0b281f2fff274140371c1472c7cb8b0c2be80146a2860822625a019ad8228608239387028062849e5c412440e0dd7c138c34975c2c0600e0f009e8210178d4519c8cb1f19cb3f5007fa0222cf165006cf1625fa025003cf16c95005cc2391729171e25008a813a0820a625a00a014bcf2e2c504c98040fb001023c85004fa0258cf1601cf16ccc9ed5400705279a018a182107362d09cc8cb1f5230cb3f58fa025007cf165007cf16c9718010c8cb0524cf165006fa0215cb6a14ccc971fb0010241023007cc30023c200b08e218210d53276db708010c8cb055008cf165004fa0216cb6a12cb1f12cb3fc972fb0093356c21e203c85004fa0258cf1601cf16ccc9ed5400c90c3b51343e803e903e90350c01b4cffe800c145128548df1c17cb8b04970bffcb8b0812082e4e1c02fbcb8b160841ef765f7b232c7c532cfd63e808873c5b25c60063232c14933c59c3e80b2dab33260103ec01004f214013e809633c58073c5b3327b55200081200835c87b51343e803e903e90350c0134c7c8608405e351466e80a0841ef765f7ae84ac7cb83234cfcc7e800c04e81408f214013e809633c58073c5b3327b5520',
|
|
86
|
-
'hex',
|
|
87
|
-
),
|
|
88
|
-
)[0],
|
|
89
|
-
stTON_TESTNET: Cell.fromBoc(
|
|
90
|
-
Buffer.from(
|
|
91
|
-
'b5ee9c7201021201000362000114ff00f4a413f4bcf2c80b0102016202030202cc0405001ba0f605da89a1f401f481f481a8610201d40607020120090a01cf0831c02497c138007434c0c05c6c2544d7c0fc03383e903e900c7e800c5c75c87e800c7e800c1cea6d0000b4c7c8608403e29fa96ea54c4d167c027808608405e351466ea58c511100fc02b80860841657c1ef2ea54c4d167c02f80517c1300138c08c2103fcbc200800113e910c30003cb85360007ced44d0fa00fa40fa40d43010235f03018208989680a16d801072226eb32091719170e203c8cb055006cf165004fa02cb6a039358cc019130e201c901fb000201200b0c0081d40106b90f6a2687d007d207d206a1802698f90c1080bc6a28cdd0141083deecbef5d0958f97064699f98fd001809d02811e428027d012c678b00e78b6664f6aa401f1503d33ffa00fa4021f001ed44d0fa00fa40fa40d4305136a1522ac705f2e2c128c2fff2e2c254344270542013541403c85004fa0258cf1601cf16ccc922c8cb0112f400f400cb00c920f9007074c8cb02ca07cbffc9d004fa40f40431fa0020d749c200f2e2c4778018c8cb055008cf1670fa0217cb6b13cc80d0201200e0f009e8210178d4519c8cb1f19cb3f5007fa0222cf165006cf1625fa025003cf16c95005cc2391729171e25008a813a0820a625a00a014bcf2e2c504c98040fb001023c85004fa0258cf1601cf16ccc9ed5402f73b51343e803e903e90350c0234cffe80145468017e903e9014d6f1c1551cdb5c150804d50500f214013e809633c58073c5b33248b232c044bd003d0032c0327e401c1d3232c0b281f2fff274140371c1472c7cb8b0c2be80146a2860822625a019ad8228608239387028062849e5c412440e0dd7c138c34975c2c060101100c90c3b51343e803e903e90350c01b4cffe800c145128548df1c17cb8b04970bffcb8b0812082e4e1c02fbcb8b160841ef765f7b232c7c532cfd63e808873c5b25c60063232c14933c59c3e80b2dab33260103ec01004f214013e809633c58073c5b3327b552000705279a018a182107362d09cc8cb1f5230cb3f58fa025007cf165007cf16c9718010c8cb0524cf165006fa0215cb6a14ccc971fb0010241023007cc30023c200b08e218210d53276db708010c8cb055008cf165004fa0216cb6a12cb1f12cb3fc972fb0093356c21e203c85004fa0258cf1601cf16ccc9ed54',
|
|
92
|
-
'hex',
|
|
93
|
-
),
|
|
94
|
-
)[0],
|
|
95
|
-
tsTON_MAINNET: Cell.fromBoc(
|
|
96
|
-
Buffer.from(
|
|
97
|
-
'b5ee9c720101010100230000420212bebb0dc8e202b7e26f721e2547e16bb9ebaec934f657d19f22e76d62bec878',
|
|
98
|
-
'hex',
|
|
99
|
-
),
|
|
100
|
-
)[0],
|
|
101
|
-
tsTON_TESTNET: null,
|
|
102
|
-
USDT_MAINNET: Cell.fromBoc(
|
|
103
|
-
Buffer.from(
|
|
104
|
-
'b5ee9c72010101010023000042028f452d7a4dfd74066b682365177259ed05734435be76b5fd4bd5d8af2b7c3d68',
|
|
105
|
-
'hex',
|
|
106
|
-
),
|
|
107
|
-
)[0],
|
|
108
|
-
USDT_TESTNET: null,
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
export const OPCODES = {
|
|
112
|
-
SUPPLY: 0x1,
|
|
113
|
-
WITHDRAW: 0x2,
|
|
114
|
-
LIQUIDATE: 0x3,
|
|
115
|
-
JETTON_TRANSFER: 0xf8a7ea5,
|
|
116
|
-
ONCHAIN_GETTER: 0x9998,
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export const FEES = {
|
|
120
|
-
SUPPLY: toNano('0.3'),
|
|
121
|
-
WITHDRAW: toNano('0.5'),
|
|
122
|
-
SUPPLY_JETTON: toNano('0.8'),
|
|
123
|
-
SUPPLY_JETTON_FWD: toNano('0.5'),
|
|
124
|
-
LIQUIDATION: toNano('0.8'),
|
|
125
|
-
LIQUIDATION_JETTON: toNano('1'),
|
|
126
|
-
LIQUIDATION_JETTON_FWD: toNano('0.8'),
|
|
127
|
-
};
|