@evaafi/sdk 0.3.2 → 0.4.0
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/parser.d.ts +3 -3
- package/dist/api/parser.js +18 -12
- package/dist/constants.d.ts +22 -4
- package/dist/constants.js +34 -14
- package/dist/contracts/MasterContract.d.ts +5 -0
- package/dist/contracts/MasterContract.js +17 -2
- package/dist/contracts/UserContract.d.ts +9 -2
- package/dist/contracts/UserContract.js +27 -8
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -3
- package/dist/types/Master.d.ts +1 -0
- package/dist/utils/userJettonWallet.js +22 -9
- package/package.json +1 -1
- package/src/api/parser.ts +287 -279
- package/src/constants.ts +75 -15
- package/src/contracts/MasterContract.ts +409 -387
- package/src/contracts/UserContract.ts +160 -125
- package/src/index.ts +76 -78
- package/src/types/Master.ts +72 -71
- package/src/utils/userJettonWallet.ts +24 -11
|
@@ -1,125 +1,160 @@
|
|
|
1
|
-
import { Address, Contract, ContractProvider, Dictionary } from '@ton/core';
|
|
2
|
-
import { UserData, UserLiteData } from '../types/User';
|
|
3
|
-
import { parseUserData, parseUserLiteData } from '../api/parser';
|
|
4
|
-
import { AssetConfig, ExtendedAssetData } from '../types/Master';
|
|
5
|
-
import { LiquidationBaseData } from './MasterContract';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* User contract wrapper
|
|
10
|
-
*/
|
|
11
|
-
export class EvaaUser implements Contract {
|
|
12
|
-
readonly address: Address;
|
|
13
|
-
|
|
14
|
-
private
|
|
15
|
-
private
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
this._liteData =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
1
|
+
import { Address, beginCell, Cell, Contract, ContractProvider, Dictionary, Sender, SendMode } from '@ton/core';
|
|
2
|
+
import { UserData, UserLiteData } from '../types/User';
|
|
3
|
+
import { parseUserData, parseUserLiteData } from '../api/parser';
|
|
4
|
+
import { AssetConfig, ExtendedAssetData } from '../types/Master';
|
|
5
|
+
import { LiquidationBaseData } from './MasterContract';
|
|
6
|
+
import { MAINNET_ASSETS_ID, OPCODES } from '../constants';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* User contract wrapper
|
|
10
|
+
*/
|
|
11
|
+
export class EvaaUser implements Contract {
|
|
12
|
+
readonly address: Address;
|
|
13
|
+
readonly testnet: boolean = false;
|
|
14
|
+
private lastSync = 0;
|
|
15
|
+
private _liteData?: UserLiteData;
|
|
16
|
+
private _data?: UserData;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create user contract wrapper from address
|
|
20
|
+
* @param address user contract address
|
|
21
|
+
* @param testnet testnet flag
|
|
22
|
+
*/
|
|
23
|
+
static createFromAddress(address: Address, testnet: boolean = false) {
|
|
24
|
+
return new EvaaUser(address, testnet);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private constructor(address: Address, testnet: boolean = false) {
|
|
28
|
+
this.address = address;
|
|
29
|
+
this.testnet = testnet;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async getSyncLite(
|
|
33
|
+
provider: ContractProvider,
|
|
34
|
+
assetsData: Dictionary<bigint, ExtendedAssetData>,
|
|
35
|
+
assetsConfig: Dictionary<bigint, AssetConfig>,
|
|
36
|
+
) {
|
|
37
|
+
const state = (await provider.getState()).state;
|
|
38
|
+
if (state.type === 'active') {
|
|
39
|
+
this._liteData = parseUserLiteData(
|
|
40
|
+
state.data!.toString('base64url'),
|
|
41
|
+
assetsData,
|
|
42
|
+
assetsConfig,
|
|
43
|
+
this.testnet,
|
|
44
|
+
);
|
|
45
|
+
this.lastSync = Math.floor(Date.now() / 1000);
|
|
46
|
+
} else {
|
|
47
|
+
this._liteData = undefined;
|
|
48
|
+
this._data = { type: 'inactive' };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Calculate full user data from lite data and prices
|
|
54
|
+
* @param assetsData assets data
|
|
55
|
+
* @param assetsConfig assets config
|
|
56
|
+
* @param prices prices
|
|
57
|
+
* @returns true if user data was calculated
|
|
58
|
+
*/
|
|
59
|
+
calculateUserData(
|
|
60
|
+
assetsData: Dictionary<bigint, ExtendedAssetData>,
|
|
61
|
+
assetsConfig: Dictionary<bigint, AssetConfig>,
|
|
62
|
+
prices: Dictionary<bigint, bigint>,
|
|
63
|
+
): boolean {
|
|
64
|
+
if (this._liteData) {
|
|
65
|
+
this._data = parseUserData(this._liteData, assetsData, assetsConfig, prices, this.testnet);
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Open user contract wrapper
|
|
73
|
+
* @param forwardPayload - payload that will be forwarded to the address which requested the data
|
|
74
|
+
*/
|
|
75
|
+
async sendOnchainGetter(
|
|
76
|
+
provider: ContractProvider,
|
|
77
|
+
via: Sender,
|
|
78
|
+
value: bigint,
|
|
79
|
+
queryID: bigint,
|
|
80
|
+
forwardPayload: Cell,
|
|
81
|
+
) {
|
|
82
|
+
await provider.internal(via, {
|
|
83
|
+
value,
|
|
84
|
+
sendMode: SendMode.PAY_GAS_SEPARATELY + SendMode.IGNORE_ERRORS,
|
|
85
|
+
body: beginCell()
|
|
86
|
+
.storeCoins(BigInt(OPCODES.ONCHAIN_GETTER))
|
|
87
|
+
.storeUint(queryID, 64)
|
|
88
|
+
.storeRef(forwardPayload)
|
|
89
|
+
.endCell(),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async getSync(
|
|
94
|
+
provider: ContractProvider,
|
|
95
|
+
assetsData: Dictionary<bigint, ExtendedAssetData>,
|
|
96
|
+
assetsConfig: Dictionary<bigint, AssetConfig>,
|
|
97
|
+
prices: Dictionary<bigint, bigint>,
|
|
98
|
+
) {
|
|
99
|
+
const state = (await provider.getState()).state;
|
|
100
|
+
if (state.type === 'active') {
|
|
101
|
+
this._liteData = parseUserLiteData(
|
|
102
|
+
state.data!.toString('base64url'),
|
|
103
|
+
assetsData,
|
|
104
|
+
assetsConfig,
|
|
105
|
+
this.testnet,
|
|
106
|
+
);
|
|
107
|
+
this._data = parseUserData(this._liteData, assetsData, assetsConfig, prices, this.testnet);
|
|
108
|
+
this.lastSync = Math.floor(Date.now() / 1000);
|
|
109
|
+
} else {
|
|
110
|
+
this._data = { type: 'inactive' };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Get user contract lite data
|
|
116
|
+
* @returns user lite data if available, otherwise undefined
|
|
117
|
+
*/
|
|
118
|
+
get liteData(): UserLiteData | undefined {
|
|
119
|
+
return this._liteData;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Get user contract full data
|
|
124
|
+
* @returns user data if available , otherwise undefined
|
|
125
|
+
*/
|
|
126
|
+
get data(): UserData | undefined {
|
|
127
|
+
return this._data;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Get if user is liquidable
|
|
132
|
+
* @returns true if user is liquidable
|
|
133
|
+
*/
|
|
134
|
+
get isLiquidable(): boolean {
|
|
135
|
+
if (!this._data || this._data.type === 'inactive') {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return this._data.liquidationData.liquidable;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Get liquidation parameters for passing to liquidation message
|
|
144
|
+
* @returns liquidation parameters if user is liquidable, otherwise undefined
|
|
145
|
+
*/
|
|
146
|
+
get liquidationParameters(): LiquidationBaseData | undefined {
|
|
147
|
+
if (!this._data || this._data.type === 'inactive' || !this._data.liquidationData.liquidable) {
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
borrowerAddress: this._data.ownerAddress,
|
|
153
|
+
loanAsset: this._data.liquidationData.greatestLoanAsset,
|
|
154
|
+
collateralAsset: this._data.liquidationData.greatestCollateralAsset,
|
|
155
|
+
minCollateralAmount: this._data.liquidationData.minCollateralAmount,
|
|
156
|
+
liquidationAmount: this._data.liquidationData.liquidationAmount,
|
|
157
|
+
tonLiquidation: this._data.liquidationData.greatestLoanAsset === MAINNET_ASSETS_ID.TON,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,78 +1,76 @@
|
|
|
1
|
-
// Math
|
|
2
|
-
export {
|
|
3
|
-
mulFactor,
|
|
4
|
-
mulDiv,
|
|
5
|
-
bigIntMin,
|
|
6
|
-
bigIntMax,
|
|
7
|
-
calculatePresentValue,
|
|
8
|
-
calculateCurrentRates,
|
|
9
|
-
calculateAssetData,
|
|
10
|
-
calculateAssetInterest,
|
|
11
|
-
getAvailableToBorrow,
|
|
12
|
-
presentValue,
|
|
13
|
-
calculateLiquidationData,
|
|
14
|
-
} from './api/math';
|
|
15
|
-
|
|
16
|
-
// Parser
|
|
17
|
-
export { createAssetData, createAssetConfig, parseMasterData, parseUserData } from './api/parser';
|
|
18
|
-
|
|
19
|
-
// Prices
|
|
20
|
-
export { getPrices } from './api/prices';
|
|
21
|
-
|
|
22
|
-
// Contracts' wrappers
|
|
23
|
-
export { JettonWallet } from './contracts/JettonWallet';
|
|
24
|
-
export {
|
|
25
|
-
EvaaParameters,
|
|
26
|
-
JettonMessageParameters,
|
|
27
|
-
TonSupplyParameters,
|
|
28
|
-
JettonSupplyParameters,
|
|
29
|
-
WithdrawParameters,
|
|
30
|
-
LiquidationBaseData,
|
|
31
|
-
TonLiquidationParameters,
|
|
32
|
-
JettonLiquidationParameters,
|
|
33
|
-
Evaa,
|
|
34
|
-
} from './contracts/MasterContract';
|
|
35
|
-
export { EvaaUser } from './contracts/UserContract';
|
|
36
|
-
|
|
37
|
-
// Types
|
|
38
|
-
export { PriceData } from './types/Common';
|
|
39
|
-
export {
|
|
40
|
-
UpgradeConfig,
|
|
41
|
-
AssetConfig,
|
|
42
|
-
MasterConfig,
|
|
43
|
-
AssetData,
|
|
44
|
-
AssetInterest,
|
|
45
|
-
AssetApy,
|
|
46
|
-
ExtendedAssetData,
|
|
47
|
-
MasterData,
|
|
48
|
-
} from './types/Master';
|
|
49
|
-
export {
|
|
50
|
-
BalanceType,
|
|
51
|
-
UserBalance,
|
|
52
|
-
UserLiqudationData,
|
|
53
|
-
LiquidableData,
|
|
54
|
-
NonLiquidableData,
|
|
55
|
-
LiquidationData,
|
|
56
|
-
UserDataInactive,
|
|
57
|
-
UserDataActive,
|
|
58
|
-
UserData,
|
|
59
|
-
} from './types/User';
|
|
60
|
-
|
|
61
|
-
// Constants
|
|
62
|
-
export {
|
|
63
|
-
EVAA_MASTER_MAINNET,
|
|
64
|
-
MAINNET_VERSION,
|
|
65
|
-
EVAA_MASTER_TESTNET,
|
|
66
|
-
TESTNET_VERSION,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
export { getLastSentBoc, getTonConnectSender } from './utils/tonConnectSender';
|
|
78
|
-
export { getUserJettonWallet } from './utils/userJettonWallet';
|
|
1
|
+
// Math
|
|
2
|
+
export {
|
|
3
|
+
mulFactor,
|
|
4
|
+
mulDiv,
|
|
5
|
+
bigIntMin,
|
|
6
|
+
bigIntMax,
|
|
7
|
+
calculatePresentValue,
|
|
8
|
+
calculateCurrentRates,
|
|
9
|
+
calculateAssetData,
|
|
10
|
+
calculateAssetInterest,
|
|
11
|
+
getAvailableToBorrow,
|
|
12
|
+
presentValue,
|
|
13
|
+
calculateLiquidationData,
|
|
14
|
+
} from './api/math';
|
|
15
|
+
|
|
16
|
+
// Parser
|
|
17
|
+
export { createAssetData, createAssetConfig, parseMasterData, parseUserData, parseUserLiteData } from './api/parser';
|
|
18
|
+
|
|
19
|
+
// Prices
|
|
20
|
+
export { getPrices } from './api/prices';
|
|
21
|
+
|
|
22
|
+
// Contracts' wrappers
|
|
23
|
+
export { JettonWallet } from './contracts/JettonWallet';
|
|
24
|
+
export {
|
|
25
|
+
EvaaParameters,
|
|
26
|
+
JettonMessageParameters,
|
|
27
|
+
TonSupplyParameters,
|
|
28
|
+
JettonSupplyParameters,
|
|
29
|
+
WithdrawParameters,
|
|
30
|
+
LiquidationBaseData,
|
|
31
|
+
TonLiquidationParameters,
|
|
32
|
+
JettonLiquidationParameters,
|
|
33
|
+
Evaa,
|
|
34
|
+
} from './contracts/MasterContract';
|
|
35
|
+
export { EvaaUser } from './contracts/UserContract';
|
|
36
|
+
|
|
37
|
+
// Types
|
|
38
|
+
export { PriceData } from './types/Common';
|
|
39
|
+
export {
|
|
40
|
+
UpgradeConfig,
|
|
41
|
+
AssetConfig,
|
|
42
|
+
MasterConfig,
|
|
43
|
+
AssetData,
|
|
44
|
+
AssetInterest,
|
|
45
|
+
AssetApy,
|
|
46
|
+
ExtendedAssetData,
|
|
47
|
+
MasterData,
|
|
48
|
+
} from './types/Master';
|
|
49
|
+
export {
|
|
50
|
+
BalanceType,
|
|
51
|
+
UserBalance,
|
|
52
|
+
UserLiqudationData,
|
|
53
|
+
LiquidableData,
|
|
54
|
+
NonLiquidableData,
|
|
55
|
+
LiquidationData,
|
|
56
|
+
UserDataInactive,
|
|
57
|
+
UserDataActive,
|
|
58
|
+
UserData,
|
|
59
|
+
} from './types/User';
|
|
60
|
+
|
|
61
|
+
// Constants
|
|
62
|
+
export {
|
|
63
|
+
EVAA_MASTER_MAINNET,
|
|
64
|
+
MAINNET_VERSION,
|
|
65
|
+
EVAA_MASTER_TESTNET,
|
|
66
|
+
TESTNET_VERSION,
|
|
67
|
+
JETTON_MASTER_ADDRESSES,
|
|
68
|
+
MASTER_CONSTANTS,
|
|
69
|
+
LENDING_CODE,
|
|
70
|
+
OPCODES,
|
|
71
|
+
FEES,
|
|
72
|
+
} from './constants';
|
|
73
|
+
|
|
74
|
+
// Utils
|
|
75
|
+
export { getLastSentBoc, getTonConnectSender } from './utils/tonConnectSender';
|
|
76
|
+
export { getUserJettonWallet } from './utils/userJettonWallet';
|
package/src/types/Master.ts
CHANGED
|
@@ -1,71 +1,72 @@
|
|
|
1
|
-
import { Address, Cell, Dictionary } from '@ton/core';
|
|
2
|
-
|
|
3
|
-
export type UpgradeConfig = {
|
|
4
|
-
masterCodeVersion: number;
|
|
5
|
-
userCodeVersion: number;
|
|
6
|
-
timeout: number;
|
|
7
|
-
updateTime: number;
|
|
8
|
-
freezeTime: number;
|
|
9
|
-
userCode: Cell;
|
|
10
|
-
blankCode: Cell;
|
|
11
|
-
newMasterCode: Cell | null;
|
|
12
|
-
newUserCode: Cell | null;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type AssetConfig = {
|
|
16
|
-
oracle: bigint;
|
|
17
|
-
decimals: bigint;
|
|
18
|
-
collateralFactor: bigint;
|
|
19
|
-
liquidationThreshold: bigint;
|
|
20
|
-
liquidationBonus: bigint;
|
|
21
|
-
baseBorrowRate: bigint;
|
|
22
|
-
borrowRateSlopeLow: bigint;
|
|
23
|
-
borrowRateSlopeHigh: bigint;
|
|
24
|
-
supplyRateSlopeLow: bigint;
|
|
25
|
-
supplyRateSlopeHigh: bigint;
|
|
26
|
-
targetUtilization: bigint;
|
|
27
|
-
originationFee: bigint;
|
|
28
|
-
dust: bigint;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
};
|
|
1
|
+
import { Address, Cell, Dictionary } from '@ton/core';
|
|
2
|
+
|
|
3
|
+
export type UpgradeConfig = {
|
|
4
|
+
masterCodeVersion: number;
|
|
5
|
+
userCodeVersion: number;
|
|
6
|
+
timeout: number;
|
|
7
|
+
updateTime: number;
|
|
8
|
+
freezeTime: number;
|
|
9
|
+
userCode: Cell;
|
|
10
|
+
blankCode: Cell;
|
|
11
|
+
newMasterCode: Cell | null;
|
|
12
|
+
newUserCode: Cell | null;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type AssetConfig = {
|
|
16
|
+
oracle: bigint;
|
|
17
|
+
decimals: bigint;
|
|
18
|
+
collateralFactor: bigint;
|
|
19
|
+
liquidationThreshold: bigint;
|
|
20
|
+
liquidationBonus: bigint;
|
|
21
|
+
baseBorrowRate: bigint;
|
|
22
|
+
borrowRateSlopeLow: bigint;
|
|
23
|
+
borrowRateSlopeHigh: bigint;
|
|
24
|
+
supplyRateSlopeLow: bigint;
|
|
25
|
+
supplyRateSlopeHigh: bigint;
|
|
26
|
+
targetUtilization: bigint;
|
|
27
|
+
originationFee: bigint;
|
|
28
|
+
dust: bigint;
|
|
29
|
+
maxTotalSupply: bigint;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type MasterConfig = {
|
|
33
|
+
ifActive: number;
|
|
34
|
+
admin: Address;
|
|
35
|
+
adminPK: bigint;
|
|
36
|
+
tokenKeys: Cell | null;
|
|
37
|
+
walletToMaster: Cell | null;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type AssetData = {
|
|
41
|
+
sRate: bigint;
|
|
42
|
+
bRate: bigint;
|
|
43
|
+
totalSupply: bigint;
|
|
44
|
+
totalBorrow: bigint;
|
|
45
|
+
lastAccural: bigint;
|
|
46
|
+
balance: bigint;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export type AssetInterest = {
|
|
50
|
+
supplyInterest: bigint;
|
|
51
|
+
borrowInterest: bigint;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type AssetApy = {
|
|
55
|
+
supplyApy: number;
|
|
56
|
+
borrowApy: number;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type ExtendedAssetData = AssetData & AssetInterest & AssetApy;
|
|
60
|
+
|
|
61
|
+
export type MasterData = {
|
|
62
|
+
meta: string;
|
|
63
|
+
upgradeConfig: UpgradeConfig;
|
|
64
|
+
masterConfig: MasterConfig;
|
|
65
|
+
assetsConfig: Dictionary<bigint, AssetConfig>;
|
|
66
|
+
assetsData: Dictionary<bigint, ExtendedAssetData>;
|
|
67
|
+
assetsReserves: Dictionary<bigint, bigint>;
|
|
68
|
+
apy: {
|
|
69
|
+
supply: Dictionary<bigint, number>;
|
|
70
|
+
borrow: Dictionary<bigint, number>;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
@@ -1,52 +1,65 @@
|
|
|
1
|
-
import { Address, beginCell, storeStateInit } from '@ton/core';
|
|
2
|
-
import {
|
|
1
|
+
import { Address, beginCell, Cell, storeStateInit } from '@ton/core';
|
|
2
|
+
import { JETTON_MASTER_ADDRESSES, JETTON_WALLETS_CODE, MAINNET_ASSETS_ID } from '../constants';
|
|
3
3
|
|
|
4
4
|
export function getUserJettonWallet(ownerAddress: Address, assetID: bigint, network: 'mainnet' | 'testnet'): Address {
|
|
5
5
|
const builder = beginCell().storeCoins(0).storeAddress(ownerAddress);
|
|
6
|
+
let jettonWalletCode: Cell;
|
|
6
7
|
switch (assetID) {
|
|
7
|
-
case
|
|
8
|
+
case MAINNET_ASSETS_ID.jUSDT:
|
|
8
9
|
if (network === 'mainnet') {
|
|
9
10
|
builder.storeAddress(JETTON_MASTER_ADDRESSES.jUSDT_MAINNET);
|
|
11
|
+
jettonWalletCode = JETTON_WALLETS_CODE.jUSDT_MAINNET;
|
|
10
12
|
} else {
|
|
11
13
|
builder.storeAddress(JETTON_MASTER_ADDRESSES.jUSDT_TESTNET);
|
|
14
|
+
jettonWalletCode = JETTON_WALLETS_CODE.jUSDT_TESTNET;
|
|
12
15
|
}
|
|
13
16
|
break;
|
|
14
|
-
case
|
|
17
|
+
case MAINNET_ASSETS_ID.jUSDC:
|
|
15
18
|
if (network === 'mainnet') {
|
|
16
19
|
builder.storeAddress(JETTON_MASTER_ADDRESSES.jUSDC_MAINNET);
|
|
20
|
+
jettonWalletCode = JETTON_WALLETS_CODE.jUSDC_MAINNET;
|
|
17
21
|
} else {
|
|
18
22
|
builder.storeAddress(JETTON_MASTER_ADDRESSES.jUSDC_TESTNET);
|
|
23
|
+
jettonWalletCode = JETTON_WALLETS_CODE.jUSDC_TESTNET;
|
|
19
24
|
}
|
|
20
25
|
break;
|
|
21
|
-
case
|
|
26
|
+
case MAINNET_ASSETS_ID.stTON:
|
|
22
27
|
if (network === 'mainnet') {
|
|
23
28
|
builder.storeAddress(JETTON_MASTER_ADDRESSES.stTON_MAINNET);
|
|
29
|
+
jettonWalletCode = JETTON_WALLETS_CODE.stTON_MAINNET;
|
|
24
30
|
} else {
|
|
25
31
|
builder.storeAddress(JETTON_MASTER_ADDRESSES.stTON_TESTNET);
|
|
32
|
+
jettonWalletCode = JETTON_WALLETS_CODE.stTON_TESTNET;
|
|
26
33
|
}
|
|
27
34
|
break;
|
|
28
|
-
case
|
|
35
|
+
case MAINNET_ASSETS_ID.tsTON:
|
|
29
36
|
if (network === 'mainnet') {
|
|
30
37
|
builder.storeAddress(JETTON_MASTER_ADDRESSES.tsTON_MAINNET);
|
|
38
|
+
jettonWalletCode = JETTON_WALLETS_CODE.tsTON_MAINNET;
|
|
31
39
|
} else {
|
|
32
|
-
builder.storeAddress(JETTON_MASTER_ADDRESSES.tsTON_TESTNET);
|
|
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');
|
|
33
43
|
}
|
|
34
44
|
break;
|
|
35
|
-
case
|
|
45
|
+
case MAINNET_ASSETS_ID.USDT:
|
|
36
46
|
if (network === 'mainnet') {
|
|
37
47
|
builder.storeAddress(JETTON_MASTER_ADDRESSES.USDT_MAINNET);
|
|
48
|
+
jettonWalletCode = JETTON_WALLETS_CODE.USDT_MAINNET;
|
|
38
49
|
} else {
|
|
39
|
-
builder.storeAddress(JETTON_MASTER_ADDRESSES.USDT_TESTNET);
|
|
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');
|
|
40
53
|
}
|
|
41
54
|
break;
|
|
42
55
|
default:
|
|
43
56
|
throw new Error('Unsupported asset');
|
|
44
57
|
}
|
|
45
|
-
const data = builder.storeRef(
|
|
58
|
+
const data = builder.storeRef(jettonWalletCode).endCell();
|
|
46
59
|
const stateInit = beginCell()
|
|
47
60
|
.store(
|
|
48
61
|
storeStateInit({
|
|
49
|
-
code:
|
|
62
|
+
code: jettonWalletCode,
|
|
50
63
|
data: data,
|
|
51
64
|
}),
|
|
52
65
|
)
|