@evaafi/sdk 0.9.0 → 0.9.2
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 +16 -24
- package/dist/api/feeds.js +22 -49
- package/dist/api/math.d.ts +1 -1
- package/dist/api/math.js +55 -38
- package/dist/api/parser.d.ts +2 -2
- package/dist/api/parser.js +3 -3
- package/dist/api/parsers/PythOracleParser.d.ts +3 -2
- package/dist/api/parsers/PythOracleParser.js +2 -1
- package/dist/api/prices.d.ts +1 -0
- package/dist/api/prices.js +2 -1
- package/dist/constants/assets/assetId.d.ts +3 -1
- package/dist/constants/assets/assetId.js +5 -1
- package/dist/constants/assets/mainnet.d.ts +2 -0
- package/dist/constants/assets/mainnet.js +13 -1
- package/dist/constants/general/index.d.ts +25 -11
- package/dist/constants/general/index.js +15 -1
- package/dist/constants/general/mainnet.d.ts +1 -0
- package/dist/constants/general/mainnet.js +2 -1
- package/dist/constants/pools/mainnet.d.ts +4 -0
- package/dist/constants/pools/mainnet.js +45 -28
- package/dist/constants/pools/testnet.js +14 -6
- package/dist/contracts/AbstractMaster.d.ts +239 -127
- package/dist/contracts/AbstractMaster.js +101 -16
- package/dist/contracts/ClassicMaster.d.ts +12 -12
- package/dist/contracts/PythMaster.d.ts +41 -24
- package/dist/contracts/PythMaster.js +61 -76
- package/dist/contracts/PythOracle.d.ts +16 -0
- package/dist/contracts/PythOracle.js +19 -0
- package/dist/contracts/index.d.ts +1 -0
- package/dist/contracts/index.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{prices → oracles}/Types.d.ts +1 -4
- package/dist/oracles/collectors/AbstractCollector.d.ts +10 -0
- package/dist/oracles/collectors/AbstractCollector.js +6 -0
- package/dist/oracles/collectors/ClassicCollector.d.ts +22 -0
- package/dist/oracles/collectors/ClassicCollector.js +192 -0
- package/dist/oracles/collectors/PythCollector.d.ts +27 -0
- package/dist/oracles/collectors/PythCollector.js +252 -0
- package/dist/oracles/collectors/index.d.ts +3 -0
- package/dist/oracles/collectors/index.js +19 -0
- package/dist/{prices → oracles}/index.d.ts +2 -3
- package/dist/{prices → oracles}/index.js +2 -3
- package/dist/oracles/prices/AbstractPrices.d.ts +33 -0
- package/dist/oracles/prices/AbstractPrices.js +40 -0
- package/dist/oracles/prices/ClassicPrices.d.ts +19 -0
- package/dist/oracles/prices/ClassicPrices.js +48 -0
- package/dist/oracles/prices/PythPrices.d.ts +18 -0
- package/dist/oracles/prices/PythPrices.js +32 -0
- package/dist/oracles/prices/index.d.ts +3 -0
- package/dist/oracles/prices/index.js +19 -0
- package/dist/{prices → oracles}/utils.d.ts +7 -1
- package/dist/{prices → oracles}/utils.js +10 -1
- package/dist/rewards/RewardMaster.d.ts +1 -0
- package/dist/rewards/RewardUser.d.ts +1 -0
- package/dist/types/Master.d.ts +5 -5
- package/dist/types/MasterRewards.d.ts +1 -0
- package/dist/types/UserRewards.d.ts +1 -0
- package/dist/utils/fivaUtils.d.ts +2 -0
- package/dist/utils/fivaUtils.js +19 -0
- package/dist/utils/sha256BigInt.d.ts +1 -0
- package/dist/utils/userJettonWallet.js +15 -1
- package/package.json +2 -3
- package/src/api/feeds.ts +24 -60
- package/src/api/math.ts +118 -90
- package/src/api/parser.ts +5 -5
- package/src/api/parsers/PythOracleParser.ts +6 -2
- package/src/api/prices.ts +2 -1
- package/src/constants/assets/assetId.ts +7 -1
- package/src/constants/assets/mainnet.ts +24 -0
- package/src/constants/general/index.ts +16 -1
- package/src/constants/general/mainnet.ts +1 -0
- package/src/constants/pools/mainnet.ts +42 -38
- package/src/constants/pools/testnet.ts +17 -8
- package/src/contracts/AbstractMaster.ts +272 -144
- package/src/contracts/ClassicMaster.ts +12 -12
- package/src/contracts/PythMaster.ts +130 -123
- package/src/contracts/PythOracle.ts +20 -0
- package/src/contracts/index.ts +2 -0
- package/src/index.ts +1 -1
- package/src/{prices → oracles}/Types.ts +0 -5
- package/src/oracles/collectors/AbstractCollector.ts +22 -0
- package/src/oracles/collectors/ClassicCollector.ts +263 -0
- package/src/oracles/collectors/PythCollector.ts +358 -0
- package/src/oracles/collectors/index.ts +3 -0
- package/src/{prices → oracles}/index.ts +2 -3
- package/src/oracles/prices/AbstractPrices.ts +59 -0
- package/src/oracles/prices/ClassicPrices.ts +52 -0
- package/src/oracles/prices/PythPrices.ts +40 -0
- package/src/oracles/prices/index.ts +3 -0
- package/src/{prices → oracles}/utils.ts +12 -1
- package/src/types/Master.ts +4 -6
- package/src/utils/fivaUtils.ts +19 -0
- package/src/utils/userJettonWallet.ts +18 -1
- package/dist/api/pyth.d.ts +0 -16
- package/dist/api/pyth.js +0 -35
- package/dist/constants/assets.d.ts +0 -48
- package/dist/constants/assets.js +0 -176
- package/dist/constants/general.d.ts +0 -67
- package/dist/constants/general.js +0 -75
- 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/dist/prices/Oracle.interface.d.ts +0 -9
- package/dist/prices/Oracle.interface.js +0 -2
- package/dist/prices/Prices.d.ts +0 -11
- package/dist/prices/Prices.js +0 -53
- package/dist/prices/PricesCollector.d.ts +0 -22
- package/dist/prices/PricesCollector.js +0 -146
- package/dist/prices/PythCollector.d.ts +0 -22
- package/dist/prices/PythCollector.js +0 -217
- package/src/prices/Oracle.interface.ts +0 -18
- package/src/prices/Prices.ts +0 -45
- package/src/prices/PricesCollector.ts +0 -169
- package/src/prices/PythCollector.ts +0 -294
- /package/dist/{prices → oracles}/Types.js +0 -0
- /package/dist/{prices → oracles}/constants.d.ts +0 -0
- /package/dist/{prices → oracles}/constants.js +0 -0
- /package/dist/{prices → oracles}/sources/Backend.d.ts +0 -0
- /package/dist/{prices → oracles}/sources/Backend.js +0 -0
- /package/dist/{prices → oracles}/sources/Icp.d.ts +0 -0
- /package/dist/{prices → oracles}/sources/Icp.js +0 -0
- /package/dist/{prices → oracles}/sources/PriceSource.d.ts +0 -0
- /package/dist/{prices → oracles}/sources/PriceSource.js +0 -0
- /package/dist/{prices → oracles}/sources/index.d.ts +0 -0
- /package/dist/{prices → oracles}/sources/index.js +0 -0
- /package/src/{prices → oracles}/constants.ts +0 -0
- /package/src/{prices → oracles}/sources/Backend.ts +0 -0
- /package/src/{prices → oracles}/sources/Icp.ts +0 -0
- /package/src/{prices → oracles}/sources/PriceSource.ts +0 -0
- /package/src/{prices → oracles}/sources/index.ts +0 -0
|
@@ -16,7 +16,7 @@ import { parseMasterData } from '../api/parser';
|
|
|
16
16
|
import { OracleParser } from '../api/parsers/AbstractOracleParser';
|
|
17
17
|
import { ClassicOracleInfo } from '../api/parsers/ClassicOracleParser';
|
|
18
18
|
import { PythOracleInfo } from '../api/parsers/PythOracleParser';
|
|
19
|
-
import { FEES, OPCODES } from '../constants/general';
|
|
19
|
+
import { FEES, OPCODES, VALIDATION } from '../constants/general';
|
|
20
20
|
import { ExtendedAssetsConfig, ExtendedAssetsData, PoolAssetConfig, PoolConfig, UpgradeConfig } from '../types/Master';
|
|
21
21
|
import { getUserJettonWallet } from '../utils/userJettonWallet';
|
|
22
22
|
import {
|
|
@@ -35,168 +35,200 @@ import {
|
|
|
35
35
|
import { EvaaUser } from './UserContract';
|
|
36
36
|
|
|
37
37
|
// Internal
|
|
38
|
-
|
|
39
|
-
queryID: bigint;
|
|
40
|
-
amount?: bigint;
|
|
41
|
-
liquidationAmount?: bigint;
|
|
42
|
-
supplyAmount?: bigint;
|
|
43
|
-
responseAddress?: Address;
|
|
44
|
-
userAddress?: Address;
|
|
45
|
-
liquidatorAddress?: Address;
|
|
46
|
-
forwardAmount?: bigint;
|
|
47
|
-
destinationAddress?: Address;
|
|
48
|
-
}
|
|
38
|
+
export interface JettonParams {
|
|
39
|
+
readonly queryID: bigint;
|
|
40
|
+
readonly amount?: bigint;
|
|
41
|
+
readonly liquidationAmount?: bigint;
|
|
42
|
+
readonly supplyAmount?: bigint;
|
|
43
|
+
readonly responseAddress?: Address;
|
|
44
|
+
readonly userAddress?: Address;
|
|
45
|
+
readonly liquidatorAddress?: Address;
|
|
46
|
+
readonly forwardAmount?: bigint;
|
|
47
|
+
readonly destinationAddress?: Address;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type RequireAtLeastOne<T, K extends keyof T> = T & { [P in K]: Required<T>[P] }[K];
|
|
51
|
+
export type ValidJettonParams = RequireAtLeastOne<JettonParams, 'amount' | 'liquidationAmount' | 'supplyAmount'>;
|
|
49
52
|
|
|
50
53
|
/**
|
|
51
|
-
* Parameters for
|
|
52
|
-
* @
|
|
53
|
-
* @property debug - true to enable debug mode (optional)
|
|
54
|
+
* Parameters for initializing an Evaa contract instance
|
|
55
|
+
* @interface EvaaParameters
|
|
54
56
|
*/
|
|
55
|
-
export
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
export interface EvaaParameters {
|
|
58
|
+
/** Pool configuration containing contract addresses and settings */
|
|
59
|
+
readonly poolConfig: PoolConfig;
|
|
60
|
+
/** Optional debug mode flag for development purposes */
|
|
61
|
+
readonly debug?: boolean;
|
|
62
|
+
}
|
|
59
63
|
|
|
60
64
|
/**
|
|
61
|
-
*
|
|
62
|
-
* @
|
|
63
|
-
* @property includeUserCode - true to include user code for update (needed when user contract code version is outdated)
|
|
64
|
-
* @property amount - amount to supply
|
|
65
|
-
* @property userAddress - user address
|
|
66
|
-
* @property asset
|
|
65
|
+
* Parameters for supply operations
|
|
66
|
+
* @interface SupplyParameters
|
|
67
67
|
*/
|
|
68
|
-
export
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
68
|
+
export interface SupplyParameters {
|
|
69
|
+
/** Asset configuration for the supply operation */
|
|
70
|
+
readonly asset: PoolAssetConfig;
|
|
71
|
+
/** Unique identifier for this operation */
|
|
72
|
+
readonly queryID: bigint;
|
|
73
|
+
/** Whether to include user contract code update */
|
|
74
|
+
readonly includeUserCode: boolean;
|
|
75
|
+
/** Amount to supply (must be positive) */
|
|
76
|
+
readonly amount: bigint;
|
|
77
|
+
/** Address of the user performing the supply */
|
|
78
|
+
readonly userAddress: Address;
|
|
79
|
+
/** Optional address for operation response */
|
|
80
|
+
readonly responseAddress?: Address;
|
|
81
|
+
/** Optional forward amount for transaction fees */
|
|
82
|
+
readonly forwardAmount?: bigint;
|
|
83
|
+
/** Operation payload cell */
|
|
84
|
+
readonly payload: Cell;
|
|
85
|
+
/** Optional subaccount identifier (0-255) */
|
|
86
|
+
readonly subaccountId?: number;
|
|
87
|
+
/** Whether to return repay remainings */
|
|
88
|
+
readonly returnRepayRemainingsFlag?: boolean;
|
|
89
|
+
/** Optional custom payload recipient address */
|
|
90
|
+
readonly customPayloadRecipient?: Address;
|
|
91
|
+
/** Whether to saturate custom payload */
|
|
92
|
+
readonly customPayloadSaturationFlag?: boolean;
|
|
93
|
+
}
|
|
82
94
|
|
|
83
95
|
/**
|
|
84
|
-
* Parameters for
|
|
85
|
-
* @
|
|
86
|
-
* @property asset - asset config
|
|
87
|
-
* @property amount - amount to withdraw
|
|
88
|
-
* @property userAddress - user address
|
|
89
|
-
* @property includeUserCode - true to include user code for update (needed when user contract code version is outdated)
|
|
96
|
+
* Parameters for withdraw operations
|
|
97
|
+
* @interface WithdrawParameters
|
|
90
98
|
*/
|
|
91
|
-
export
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
export interface WithdrawParameters {
|
|
100
|
+
/** Unique identifier for this operation */
|
|
101
|
+
readonly queryID: bigint;
|
|
102
|
+
/** Amount to withdraw (must be positive) */
|
|
103
|
+
readonly amount: bigint;
|
|
104
|
+
/** Address of the user performing the withdrawal */
|
|
105
|
+
readonly userAddress: Address;
|
|
106
|
+
/** Whether to include user contract code update */
|
|
107
|
+
readonly includeUserCode: boolean;
|
|
108
|
+
/** Asset configuration for the withdrawal */
|
|
109
|
+
readonly asset: PoolAssetConfig;
|
|
110
|
+
/** Operation payload cell */
|
|
111
|
+
readonly payload: Cell;
|
|
112
|
+
/** Optional subaccount identifier (0-255) */
|
|
113
|
+
readonly subaccountId?: number;
|
|
114
|
+
/** Optional forward amount for transaction fees */
|
|
115
|
+
readonly forwardAmount?: bigint;
|
|
116
|
+
/** Actual amount to transfer after calculations */
|
|
117
|
+
readonly amountToTransfer: bigint;
|
|
118
|
+
/** Whether to saturate custom payload */
|
|
119
|
+
readonly customPayloadSaturationFlag: boolean;
|
|
120
|
+
/** Whether to return repay remainings */
|
|
121
|
+
readonly returnRepayRemainingsFlag: boolean;
|
|
122
|
+
}
|
|
104
123
|
|
|
105
124
|
/**
|
|
106
125
|
* Parameters for liquidation inner operations
|
|
107
126
|
* @interface LiquidationInnerParameters
|
|
108
127
|
*/
|
|
109
|
-
export
|
|
128
|
+
export interface LiquidationInnerParameters {
|
|
110
129
|
/** Liquidation operation payload cell */
|
|
111
|
-
payload: Cell;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
130
|
+
readonly payload: Cell;
|
|
131
|
+
/** Subaccount identifier for the operation */
|
|
132
|
+
readonly subaccountId: number;
|
|
133
|
+
/** Address to receive custom payload */
|
|
134
|
+
readonly customPayloadRecipient: Address;
|
|
135
|
+
/** Whether to saturate the custom payload */
|
|
136
|
+
readonly customPayloadSaturationFlag: boolean;
|
|
137
|
+
}
|
|
116
138
|
|
|
117
139
|
/**
|
|
118
|
-
* Base
|
|
119
|
-
* @
|
|
120
|
-
* @
|
|
121
|
-
* @property liquidatorAddress - liquidator address, where and collateral will be sent
|
|
140
|
+
* Base parameters for liquidation operations
|
|
141
|
+
* @interface LiquidationParameters
|
|
142
|
+
* @description Can be obtained from the user contract liquidationParameters getter
|
|
122
143
|
*/
|
|
123
|
-
export
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
144
|
+
export interface LiquidationParameters {
|
|
145
|
+
/** Asset ID of the loan being liquidated */
|
|
146
|
+
readonly loanAsset: bigint;
|
|
147
|
+
/** Unique identifier for this operation */
|
|
148
|
+
readonly queryID: bigint;
|
|
149
|
+
/** Address where collateral will be sent upon liquidation */
|
|
150
|
+
readonly liquidatorAddress: Address;
|
|
151
|
+
}
|
|
128
152
|
|
|
129
153
|
/**
|
|
130
|
-
*
|
|
131
|
-
* @
|
|
132
|
-
* @property collateralAsset - collateral asset ID
|
|
133
|
-
* @property minCollateralAmount - minimal amount to receive from the liquidation
|
|
134
|
-
* @property liquidationAmount - amount to liquidate
|
|
135
|
-
* @property includeUserCode - true to include user code for update (needed when user contract code version is outdated)
|
|
154
|
+
* Parameters for building liquidation operations
|
|
155
|
+
* @interface LiquidationOperationBuilderParameters
|
|
136
156
|
*/
|
|
137
|
-
export
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
157
|
+
export interface LiquidationOperationBuilderParameters {
|
|
158
|
+
/** Asset configuration for the liquidation */
|
|
159
|
+
readonly asset: PoolAssetConfig;
|
|
160
|
+
/** Address of the borrower being liquidated */
|
|
161
|
+
readonly borrowerAddress: Address;
|
|
162
|
+
/** Asset ID of the collateral to be seized */
|
|
163
|
+
readonly collateralAsset: bigint;
|
|
164
|
+
/** Minimum collateral amount expected from liquidation */
|
|
165
|
+
readonly minCollateralAmount: bigint;
|
|
166
|
+
/** Amount of debt to liquidate */
|
|
167
|
+
readonly liquidationAmount: bigint;
|
|
168
|
+
/** Whether to include user contract code update */
|
|
169
|
+
readonly includeUserCode: boolean;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface SupplyWithdrawParameters {
|
|
173
|
+
readonly queryID: bigint;
|
|
174
|
+
readonly supplyAmount: bigint;
|
|
175
|
+
readonly supplyAsset: PoolAssetConfig;
|
|
176
|
+
readonly withdrawAmount: bigint;
|
|
177
|
+
readonly withdrawAsset: PoolAssetConfig;
|
|
178
|
+
readonly withdrawRecipient: Address;
|
|
179
|
+
readonly includeUserCode: boolean;
|
|
180
|
+
readonly tonForRepayRemainings?: bigint;
|
|
181
|
+
readonly payload: Cell;
|
|
182
|
+
readonly subaccountId?: number;
|
|
183
|
+
readonly returnRepayRemainingsFlag?: boolean;
|
|
184
|
+
readonly customPayloadSaturationFlag?: boolean;
|
|
185
|
+
readonly forwardAmount?: bigint;
|
|
186
|
+
readonly responseAddress?: Address;
|
|
187
|
+
}
|
|
162
188
|
|
|
163
189
|
// Base shared configuration for all master types
|
|
164
|
-
export
|
|
165
|
-
ifActive: number;
|
|
166
|
-
admin: Address;
|
|
167
|
-
tokenKeys: Cell | null;
|
|
168
|
-
supervisor: Address | null;
|
|
169
|
-
}
|
|
190
|
+
export interface BaseMasterConfig {
|
|
191
|
+
readonly ifActive: number;
|
|
192
|
+
readonly admin: Address;
|
|
193
|
+
readonly tokenKeys: Cell | null;
|
|
194
|
+
readonly supervisor: Address | null;
|
|
195
|
+
}
|
|
170
196
|
|
|
171
197
|
export type OracleInfo = PythOracleInfo | ClassicOracleInfo;
|
|
172
198
|
|
|
173
199
|
// Generic master configuration with oracle info
|
|
174
|
-
export
|
|
175
|
-
oraclesInfo: T;
|
|
176
|
-
}
|
|
200
|
+
export interface MasterConfig<T extends OracleInfo> extends BaseMasterConfig {
|
|
201
|
+
readonly oraclesInfo: T;
|
|
202
|
+
}
|
|
177
203
|
|
|
178
204
|
// Base shared data for all master types
|
|
179
|
-
export
|
|
180
|
-
meta: string;
|
|
181
|
-
upgradeConfig: UpgradeConfig;
|
|
182
|
-
assetsConfig: ExtendedAssetsConfig;
|
|
183
|
-
assetsData: ExtendedAssetsData;
|
|
184
|
-
assetsReserves: Dictionary<bigint, bigint>;
|
|
185
|
-
apy: {
|
|
186
|
-
supply: Dictionary<bigint, number>;
|
|
187
|
-
borrow: Dictionary<bigint, number>;
|
|
205
|
+
export interface BaseMasterData {
|
|
206
|
+
readonly meta: string;
|
|
207
|
+
readonly upgradeConfig: UpgradeConfig;
|
|
208
|
+
readonly assetsConfig: ExtendedAssetsConfig;
|
|
209
|
+
readonly assetsData: ExtendedAssetsData;
|
|
210
|
+
readonly assetsReserves: Dictionary<bigint, bigint>;
|
|
211
|
+
readonly apy: {
|
|
212
|
+
readonly supply: Dictionary<bigint, number>;
|
|
213
|
+
readonly borrow: Dictionary<bigint, number>;
|
|
188
214
|
};
|
|
189
|
-
}
|
|
215
|
+
}
|
|
190
216
|
|
|
191
217
|
// Generic master data with config
|
|
192
|
-
export
|
|
193
|
-
masterConfig: T;
|
|
194
|
-
}
|
|
218
|
+
export interface MasterData<T extends MasterConfig<OracleInfo>> extends BaseMasterData {
|
|
219
|
+
readonly masterConfig: T;
|
|
220
|
+
}
|
|
195
221
|
|
|
196
222
|
/**
|
|
197
|
-
* Abstract
|
|
198
|
-
*
|
|
199
|
-
*
|
|
223
|
+
* Abstract base class for EVAA Master contracts
|
|
224
|
+
*
|
|
225
|
+
* This class provides shared functionality for both Classic and Pyth master implementations,
|
|
226
|
+
* including message creation, validation, and transaction handling. Concrete implementations
|
|
227
|
+
* must override oracle-specific methods for withdraw/liquidation operations.
|
|
228
|
+
*
|
|
229
|
+
* @template T - Master data type extending MasterData with specific oracle configuration
|
|
230
|
+
* @abstract
|
|
231
|
+
* @implements {Contract}
|
|
200
232
|
*/
|
|
201
233
|
export abstract class AbstractEvaaMaster<T extends MasterData<MasterConfig<OracleInfo>>> implements Contract {
|
|
202
234
|
readonly address: Address;
|
|
@@ -205,42 +237,89 @@ export abstract class AbstractEvaaMaster<T extends MasterData<MasterConfig<Oracl
|
|
|
205
237
|
protected _data?: T;
|
|
206
238
|
protected lastSync = 0;
|
|
207
239
|
|
|
240
|
+
/**
|
|
241
|
+
* Initialize the abstract master contract
|
|
242
|
+
* @param parameters - Configuration parameters for the Evaa master
|
|
243
|
+
*/
|
|
208
244
|
constructor(parameters: EvaaParameters) {
|
|
209
245
|
this._poolConfig = parameters.poolConfig;
|
|
210
246
|
this.address = this._poolConfig.masterAddress;
|
|
211
247
|
this.debug = parameters?.debug;
|
|
212
248
|
}
|
|
213
249
|
|
|
250
|
+
/**
|
|
251
|
+
* Get the current pool configuration
|
|
252
|
+
* @returns {PoolConfig} The pool configuration object
|
|
253
|
+
*/
|
|
214
254
|
get poolConfig(): PoolConfig {
|
|
215
255
|
return this._poolConfig;
|
|
216
256
|
}
|
|
217
257
|
|
|
258
|
+
/**
|
|
259
|
+
* Get the synchronized master data
|
|
260
|
+
* @returns {T | undefined} Master data if available, undefined otherwise
|
|
261
|
+
*/
|
|
218
262
|
get data(): T | undefined {
|
|
219
263
|
return this._data;
|
|
220
264
|
}
|
|
221
265
|
|
|
222
|
-
//
|
|
223
|
-
|
|
266
|
+
// ========== VALIDATION METHODS ==========
|
|
267
|
+
/**
|
|
268
|
+
* Validates jetton parameters ensuring at least one amount field is provided
|
|
269
|
+
* @private
|
|
270
|
+
* @static
|
|
271
|
+
* @param parameters - Jetton parameters to validate
|
|
272
|
+
* @returns {ValidJettonParams} Validated parameters
|
|
273
|
+
* @throws {Error} When no amount fields are provided
|
|
274
|
+
*/
|
|
275
|
+
private static validateJettonParams(parameters: JettonParams): ValidJettonParams {
|
|
224
276
|
if (
|
|
225
277
|
parameters.amount == undefined &&
|
|
226
278
|
parameters.liquidationAmount == undefined &&
|
|
227
279
|
parameters.supplyAmount == undefined
|
|
228
280
|
) {
|
|
229
|
-
throw new Error(
|
|
281
|
+
throw new Error(`JettonParams validation failed: ${VALIDATION.ERRORS.MISSING_JETTON_AMOUNT}`);
|
|
282
|
+
}
|
|
283
|
+
return parameters as ValidJettonParams;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Creates a jetton transfer message with the provided parameters
|
|
288
|
+
* @protected
|
|
289
|
+
* @param parameters - Jetton transfer parameters
|
|
290
|
+
* @param defaultFees - Default fee amount for the operation
|
|
291
|
+
* @param message - Operation message cell to include
|
|
292
|
+
* @returns {Cell} Complete jetton transfer message cell
|
|
293
|
+
* @throws {Error} When validation fails or required addresses are missing
|
|
294
|
+
*/
|
|
295
|
+
protected createJettonTransferMessage(parameters: JettonParams, defaultFees: bigint, message: Cell): Cell {
|
|
296
|
+
const validParams = AbstractEvaaMaster.validateJettonParams(parameters);
|
|
297
|
+
const amount = validParams.amount ?? validParams.liquidationAmount ?? validParams.supplyAmount ?? 0n;
|
|
298
|
+
const responseAddress = validParams.responseAddress ?? validParams.userAddress ?? validParams.liquidatorAddress;
|
|
299
|
+
|
|
300
|
+
if (!responseAddress) {
|
|
301
|
+
throw new Error(`JettonTransfer validation failed: ${VALIDATION.ERRORS.MISSING_RESPONSE_ADDRESS}`);
|
|
230
302
|
}
|
|
303
|
+
|
|
231
304
|
return beginCell()
|
|
232
305
|
.storeUint(OPCODES.JETTON_TRANSFER, 32)
|
|
233
|
-
.storeUint(
|
|
234
|
-
.storeCoins(
|
|
235
|
-
.storeAddress(
|
|
236
|
-
.storeAddress(
|
|
306
|
+
.storeUint(validParams.queryID, 64)
|
|
307
|
+
.storeCoins(amount)
|
|
308
|
+
.storeAddress(validParams.destinationAddress ?? this.address)
|
|
309
|
+
.storeAddress(responseAddress)
|
|
237
310
|
.storeBit(0)
|
|
238
|
-
.storeCoins(
|
|
311
|
+
.storeCoins(validParams.forwardAmount ?? defaultFees)
|
|
239
312
|
.storeBit(1)
|
|
240
313
|
.storeRef(message)
|
|
241
314
|
.endCell();
|
|
242
315
|
}
|
|
243
316
|
|
|
317
|
+
/**
|
|
318
|
+
* Builds general data payload for supply-withdraw operations
|
|
319
|
+
* @abstract
|
|
320
|
+
* @param parameters - Supply-withdraw parameters (oracle-specific)
|
|
321
|
+
* @returns {Cell} General data payload cell
|
|
322
|
+
*/
|
|
244
323
|
abstract buildGeneralDataPayload(parameters: PythSupplyWithdrawParameters | ClassicSupplyWithdrawParameters): Cell;
|
|
245
324
|
|
|
246
325
|
protected buildSupplyWithdrawOperationPayload(
|
|
@@ -262,8 +341,29 @@ export abstract class AbstractEvaaMaster<T extends MasterData<MasterConfig<Oracl
|
|
|
262
341
|
return beginCell().storeRef(supplyData).storeRef(withdrawData).storeRef(generalData).endCell();
|
|
263
342
|
}
|
|
264
343
|
|
|
265
|
-
//
|
|
344
|
+
// ========== MESSAGE BUILDERS ==========
|
|
345
|
+
/**
|
|
346
|
+
* Validates supply operation parameters
|
|
347
|
+
* @private
|
|
348
|
+
* @static
|
|
349
|
+
* @param parameters - Supply parameters to validate
|
|
350
|
+
* @throws {Error} When amount is invalid or subaccount ID is out of range
|
|
351
|
+
*/
|
|
352
|
+
private static validateSupplyParameters(parameters: SupplyParameters): void {
|
|
353
|
+
if (parameters.subaccountId !== undefined && !isValidSubaccountId(parameters.subaccountId)) {
|
|
354
|
+
throw new Error(`Supply validation failed: ${VALIDATION.ERRORS.INVALID_SUBACCOUNT_ID}`);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Creates a supply operation message
|
|
360
|
+
* @param parameters - Supply operation parameters
|
|
361
|
+
* @returns {Cell} Complete supply message cell
|
|
362
|
+
* @throws {Error} When validation fails
|
|
363
|
+
*/
|
|
266
364
|
createSupplyMessage(parameters: SupplyParameters): Cell {
|
|
365
|
+
AbstractEvaaMaster.validateSupplyParameters(parameters);
|
|
366
|
+
|
|
267
367
|
const subaccountId = parameters.subaccountId ?? 0;
|
|
268
368
|
const isTon = isTonAsset(parameters.asset);
|
|
269
369
|
|
|
@@ -287,12 +387,26 @@ export abstract class AbstractEvaaMaster<T extends MasterData<MasterConfig<Oracl
|
|
|
287
387
|
}
|
|
288
388
|
}
|
|
289
389
|
|
|
290
|
-
|
|
390
|
+
/**
|
|
391
|
+
* Creates a supply-withdraw operation message
|
|
392
|
+
* @abstract
|
|
393
|
+
* @param parameters - Oracle-specific supply-withdraw parameters
|
|
394
|
+
* @returns {Cell} Complete supply-withdraw message cell
|
|
395
|
+
* @remarks Concrete classes must wrap the operation payload correctly for their oracle
|
|
396
|
+
*/
|
|
291
397
|
abstract createSupplyWithdrawMessage(
|
|
292
398
|
parameters: ClassicSupplyWithdrawParameters | PythSupplyWithdrawParameters,
|
|
293
399
|
): Cell;
|
|
294
400
|
|
|
295
|
-
//
|
|
401
|
+
// ========== TRANSACTION OPERATIONS ==========
|
|
402
|
+
/**
|
|
403
|
+
* Sends a supply operation to the master contract
|
|
404
|
+
* @param provider - Contract provider instance
|
|
405
|
+
* @param via - Sender instance
|
|
406
|
+
* @param value - Transaction value in nanoTON
|
|
407
|
+
* @param parameters - Supply operation parameters
|
|
408
|
+
* @throws {Error} When validation fails or transaction fails
|
|
409
|
+
*/
|
|
296
410
|
async sendSupply(provider: ContractProvider, via: Sender, value: bigint, parameters: SupplyParameters) {
|
|
297
411
|
const message = this.createSupplyMessage(parameters);
|
|
298
412
|
|
|
@@ -350,7 +464,15 @@ export abstract class AbstractEvaaMaster<T extends MasterData<MasterConfig<Oracl
|
|
|
350
464
|
parameters: ClassicLiquidationParameters | PythLiquidationParameters,
|
|
351
465
|
): Promise<void>;
|
|
352
466
|
|
|
353
|
-
//
|
|
467
|
+
// ========== CONTRACT INTERACTION HELPERS ==========
|
|
468
|
+
/**
|
|
469
|
+
* Calculates the user smart contract address for a given user and subaccount
|
|
470
|
+
* @param userAddress - The user's wallet address
|
|
471
|
+
* @param lendingCode - The user contract code cell
|
|
472
|
+
* @param subaccountId - Optional subaccount identifier (default: 0)
|
|
473
|
+
* @returns {Address} The calculated user contract address
|
|
474
|
+
* @throws {Error} When subaccount ID is invalid
|
|
475
|
+
*/
|
|
354
476
|
calculateUserSCAddr(userAddress: Address, lendingCode: Cell, subaccountId: number = 0): Address {
|
|
355
477
|
const subaccount = beginCell();
|
|
356
478
|
if (subaccountId !== 0) {
|
|
@@ -378,6 +500,12 @@ export abstract class AbstractEvaaMaster<T extends MasterData<MasterConfig<Oracl
|
|
|
378
500
|
return new Address(0, stateInit.hash());
|
|
379
501
|
}
|
|
380
502
|
|
|
503
|
+
/**
|
|
504
|
+
* Creates a user contract instance for the given address and subaccount
|
|
505
|
+
* @param userAddress - The user's wallet address
|
|
506
|
+
* @param subaccountId - Optional subaccount identifier (default: 0)
|
|
507
|
+
* @returns {EvaaUser} User contract instance
|
|
508
|
+
*/
|
|
381
509
|
openUserContract(userAddress: Address, subaccountId: number = 0): EvaaUser {
|
|
382
510
|
return EvaaUser.createFromAddress(
|
|
383
511
|
this.calculateUserSCAddr(userAddress, this._poolConfig.lendingCode, subaccountId),
|
|
@@ -436,13 +564,13 @@ export abstract class AbstractEvaaMaster<T extends MasterData<MasterConfig<Oracl
|
|
|
436
564
|
oracleParser,
|
|
437
565
|
) as T;
|
|
438
566
|
if (this._data.upgradeConfig.masterCodeVersion !== this._poolConfig.masterVersion) {
|
|
439
|
-
throw Error(
|
|
440
|
-
|
|
567
|
+
throw new Error(
|
|
568
|
+
`${VALIDATION.ERRORS.OUTDATED_SDK_VERSION}. SDK supports version ${this._poolConfig.masterVersion}, but contract version is ${this._data.upgradeConfig.masterCodeVersion}`,
|
|
441
569
|
);
|
|
442
570
|
}
|
|
443
571
|
this.lastSync = Math.floor(Date.now() / 1000);
|
|
444
572
|
} else {
|
|
445
|
-
throw Error(
|
|
573
|
+
throw new Error(VALIDATION.ERRORS.MASTER_CONTRACT_INACTIVE);
|
|
446
574
|
}
|
|
447
575
|
}
|
|
448
576
|
|
|
@@ -13,17 +13,17 @@ import {
|
|
|
13
13
|
WithdrawParameters,
|
|
14
14
|
} from './AbstractMaster';
|
|
15
15
|
|
|
16
|
-
export
|
|
17
|
-
priceData?: Cell;
|
|
18
|
-
}
|
|
16
|
+
export interface ClassicSupplyWithdrawParameters extends SupplyWithdrawParameters {
|
|
17
|
+
readonly priceData?: Cell;
|
|
18
|
+
}
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Parameters for the withdraw message
|
|
22
22
|
* @property priceData - price data cell. Can be obtained from the getPrices function
|
|
23
23
|
*/
|
|
24
|
-
export
|
|
25
|
-
priceData
|
|
26
|
-
}
|
|
24
|
+
export interface ClassicWithdrawParameters extends WithdrawParameters {
|
|
25
|
+
readonly priceData?: Cell;
|
|
26
|
+
}
|
|
27
27
|
|
|
28
28
|
export type ClassicLiquidationOperationParameters = LiquidationOperationBuilderParameters &
|
|
29
29
|
LiquidationInnerParameters & {
|
|
@@ -32,13 +32,13 @@ export type ClassicLiquidationOperationParameters = LiquidationOperationBuilderP
|
|
|
32
32
|
|
|
33
33
|
export type ClassicLiquidationParameters = LiquidationParameters & ClassicLiquidationOperationParameters;
|
|
34
34
|
|
|
35
|
-
export
|
|
36
|
-
oraclesInfo: ClassicOracleInfo;
|
|
37
|
-
}
|
|
35
|
+
export interface ClassicMasterConfig extends BaseMasterConfig {
|
|
36
|
+
readonly oraclesInfo: ClassicOracleInfo;
|
|
37
|
+
}
|
|
38
38
|
|
|
39
|
-
export
|
|
40
|
-
masterConfig: ClassicMasterConfig;
|
|
41
|
-
}
|
|
39
|
+
export interface ClassicMasterData extends BaseMasterData {
|
|
40
|
+
readonly masterConfig: ClassicMasterConfig;
|
|
41
|
+
}
|
|
42
42
|
|
|
43
43
|
export class EvaaMasterClassic extends AbstractEvaaMaster<ClassicMasterData> {
|
|
44
44
|
constructor(parameters: EvaaParameters) {
|