@evaafi/sdk 0.7.0 → 0.9.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.
Files changed (122) hide show
  1. package/dist/api/feeds.d.ts +30 -0
  2. package/dist/api/feeds.js +73 -0
  3. package/dist/api/liquidation.js +1 -1
  4. package/dist/api/math.js +1 -1
  5. package/dist/api/parser.d.ts +4 -2
  6. package/dist/api/parser.js +39 -18
  7. package/dist/api/parsers/AbstractOracleParser.d.ts +11 -0
  8. package/dist/api/parsers/AbstractOracleParser.js +9 -0
  9. package/dist/api/parsers/ClassicOracleParser.d.ts +10 -0
  10. package/dist/api/parsers/ClassicOracleParser.js +16 -0
  11. package/dist/api/parsers/PythOracleParser.d.ts +17 -0
  12. package/dist/api/parsers/PythOracleParser.js +22 -0
  13. package/dist/api/parsers/index.d.ts +3 -0
  14. package/dist/api/parsers/index.js +19 -0
  15. package/dist/api/prices.d.ts +6 -6
  16. package/dist/api/prices.js +37 -46
  17. package/dist/api/pyth.d.ts +16 -0
  18. package/dist/api/pyth.js +35 -0
  19. package/dist/constants/assets/assetId.d.ts +22 -0
  20. package/dist/constants/assets/assetId.js +29 -0
  21. package/dist/constants/assets/index.d.ts +3 -0
  22. package/dist/constants/assets/index.js +19 -0
  23. package/dist/constants/assets/mainnet.d.ts +19 -0
  24. package/dist/constants/assets/mainnet.js +114 -0
  25. package/dist/constants/assets/testnet.d.ts +14 -0
  26. package/dist/constants/assets/testnet.js +54 -0
  27. package/dist/constants/general/index.d.ts +65 -0
  28. package/dist/constants/general/index.js +93 -0
  29. package/dist/constants/general/mainnet.d.ts +24 -0
  30. package/dist/constants/general/mainnet.js +53 -0
  31. package/dist/constants/general/testnet.d.ts +12 -0
  32. package/dist/constants/general/testnet.js +15 -0
  33. package/dist/constants/general.d.ts +2 -2
  34. package/dist/constants/general.js +4 -4
  35. package/dist/constants/index.d.ts +3 -0
  36. package/dist/constants/index.js +19 -0
  37. package/dist/constants/pools/index.d.ts +2 -0
  38. package/dist/constants/pools/index.js +18 -0
  39. package/dist/constants/pools/mainnet.d.ts +14 -0
  40. package/dist/constants/pools/mainnet.js +145 -0
  41. package/dist/constants/pools/testnet.d.ts +9 -0
  42. package/dist/constants/pools/testnet.js +57 -0
  43. package/dist/constants/pools.js +7 -7
  44. package/dist/contracts/AbstractMaster.d.ts +185 -0
  45. package/dist/contracts/AbstractMaster.js +179 -0
  46. package/dist/contracts/ClassicMaster.d.ts +34 -0
  47. package/dist/contracts/ClassicMaster.js +87 -0
  48. package/dist/contracts/PythMaster.d.ts +61 -0
  49. package/dist/contracts/PythMaster.js +179 -0
  50. package/dist/contracts/UserContract.d.ts +1 -7
  51. package/dist/contracts/UserContract.js +1 -19
  52. package/dist/contracts/index.d.ts +5 -0
  53. package/dist/contracts/index.js +21 -0
  54. package/dist/index.d.ts +14 -14
  55. package/dist/index.js +20 -60
  56. package/dist/prices/Oracle.interface.d.ts +9 -0
  57. package/dist/prices/Oracle.interface.js +2 -0
  58. package/dist/prices/Prices.d.ts +5 -3
  59. package/dist/prices/Prices.js +13 -3
  60. package/dist/prices/PricesCollector.d.ts +17 -7
  61. package/dist/prices/PricesCollector.js +67 -51
  62. package/dist/prices/PythCollector.d.ts +22 -0
  63. package/dist/prices/PythCollector.js +217 -0
  64. package/dist/prices/Types.d.ts +17 -1
  65. package/dist/prices/Types.js +8 -1
  66. package/dist/prices/index.d.ts +4 -3
  67. package/dist/prices/index.js +4 -3
  68. package/dist/prices/sources/Backend.d.ts +5 -4
  69. package/dist/prices/sources/Backend.js +16 -13
  70. package/dist/prices/sources/Icp.d.ts +2 -1
  71. package/dist/prices/sources/Icp.js +12 -9
  72. package/dist/prices/sources/PriceSource.d.ts +7 -6
  73. package/dist/prices/utils.d.ts +10 -8
  74. package/dist/prices/utils.js +32 -46
  75. package/dist/types/Master.d.ts +10 -30
  76. package/dist/types/Master.js +3 -0
  77. package/dist/utils/userJettonWallet.js +0 -8
  78. package/dist/utils/utils.d.ts +8 -1
  79. package/dist/utils/utils.js +31 -2
  80. package/package.json +3 -2
  81. package/src/api/feeds.ts +90 -0
  82. package/src/api/liquidation.ts +1 -1
  83. package/src/api/math.ts +1 -1
  84. package/src/api/parser.ts +100 -38
  85. package/src/api/parsers/AbstractOracleParser.ts +16 -0
  86. package/src/api/parsers/ClassicOracleParser.ts +20 -0
  87. package/src/api/parsers/PythOracleParser.ts +34 -0
  88. package/src/api/parsers/index.ts +3 -0
  89. package/src/api/prices.ts +32 -41
  90. package/src/constants/assets/assetId.ts +30 -0
  91. package/src/constants/assets/index.ts +3 -0
  92. package/src/constants/{assets.ts → assets/mainnet.ts} +3 -96
  93. package/src/constants/assets/testnet.ts +74 -0
  94. package/src/constants/general/index.ts +91 -0
  95. package/src/constants/{general.ts → general/mainnet.ts} +48 -72
  96. package/src/constants/general/testnet.ts +25 -0
  97. package/src/constants/index.ts +3 -0
  98. package/src/constants/pools/index.ts +2 -0
  99. package/src/constants/pools/mainnet.ts +218 -0
  100. package/src/constants/pools/testnet.ts +75 -0
  101. package/src/contracts/AbstractMaster.ts +450 -0
  102. package/src/contracts/ClassicMaster.ts +149 -0
  103. package/src/contracts/PythMaster.ts +313 -0
  104. package/src/contracts/UserContract.ts +7 -28
  105. package/src/contracts/index.ts +7 -0
  106. package/src/index.ts +18 -85
  107. package/src/prices/Oracle.interface.ts +18 -0
  108. package/src/prices/Prices.ts +17 -4
  109. package/src/prices/PricesCollector.ts +91 -68
  110. package/src/prices/PythCollector.ts +294 -0
  111. package/src/prices/Types.ts +28 -6
  112. package/src/prices/index.ts +4 -3
  113. package/src/prices/sources/Backend.ts +21 -19
  114. package/src/prices/sources/Icp.ts +13 -10
  115. package/src/prices/sources/PriceSource.ts +6 -5
  116. package/src/prices/utils.ts +65 -68
  117. package/src/types/Master.ts +29 -52
  118. package/src/types/User.ts +15 -7
  119. package/src/utils/userJettonWallet.ts +0 -8
  120. package/src/utils/utils.ts +41 -2
  121. package/src/constants/pools.ts +0 -177
  122. package/src/contracts/MasterContract.ts +0 -410
@@ -0,0 +1,313 @@
1
+ import { HexString } from '@pythnetwork/hermes-client';
2
+ import { Address, beginCell, Cell, ContractProvider, Dictionary, Sender, SendMode } from '@ton/core';
3
+ import { PythOracleInfo, PythOracleParser } from '../api/parsers/PythOracleParser';
4
+ import { composeFeedsCell, packPythUpdatesData } from '../api/prices';
5
+ import { TON_MAINNET } from '../constants';
6
+ import { FEES, OPCODES } from '../constants/general';
7
+ import { isTonAsset } from '../utils/utils';
8
+ import {
9
+ AbstractEvaaMaster,
10
+ BaseMasterConfig,
11
+ BaseMasterData,
12
+ EvaaParameters,
13
+ LiquidationInnerParameters,
14
+ LiquidationOperationBuilderParameters,
15
+ LiquidationParameters,
16
+ SupplyWithdrawParameters,
17
+ WithdrawParameters,
18
+ } from './AbstractMaster';
19
+
20
+ /**
21
+ * pyth specific parameters
22
+ */
23
+ export type PythBaseData = {
24
+ priceData: Buffer | Cell;
25
+ targetFeeds: HexString[];
26
+ requestedRefTokens: bigint[];
27
+ };
28
+
29
+ export type ProxySpecificPythParams = {
30
+ pythAddress: Address;
31
+ minPublishTime: number | bigint;
32
+ maxPublishTime: number | bigint;
33
+ };
34
+
35
+ export type OnchainSpecificPythParams = {
36
+ publishGap: number | bigint;
37
+ maxStaleness: number | bigint;
38
+ };
39
+
40
+ export type JettonPythParams = PythBaseData & OnchainSpecificPythParams;
41
+
42
+ export type TonPythParams = PythBaseData & ProxySpecificPythParams;
43
+
44
+ export type PythProxyParams = {
45
+ pyth: PythBaseData & (ProxySpecificPythParams | OnchainSpecificPythParams) & { pythAddress: Address };
46
+ };
47
+
48
+ export type PythSupplyWithdrawParameters = SupplyWithdrawParameters & Partial<PythProxyParams>;
49
+
50
+ export type PythWithdrawParameters = WithdrawParameters & {
51
+ pyth: TonPythParams;
52
+ };
53
+
54
+ export type PythLiquidationOperationParameters = LiquidationOperationBuilderParameters &
55
+ LiquidationInnerParameters &
56
+ PythProxyParams;
57
+
58
+ export type PythLiquidationParameters = LiquidationParameters & PythLiquidationOperationParameters;
59
+
60
+ // Specific master configurations
61
+ export type PythMasterConfig = BaseMasterConfig & {
62
+ oraclesInfo: PythOracleInfo;
63
+ };
64
+
65
+ // Specific master data types
66
+ export type PythMasterData = BaseMasterData & {
67
+ masterConfig: PythMasterConfig;
68
+ };
69
+
70
+ export class EvaaMasterPyth extends AbstractEvaaMaster<PythMasterData> {
71
+ constructor(parameters: EvaaParameters) {
72
+ super(parameters);
73
+ }
74
+
75
+ protected buildPythMasterMessage(
76
+ args: {
77
+ queryId: number | bigint;
78
+ opCode: number | bigint;
79
+ updateDataCell: Cell;
80
+ targetFeedsCell: Cell;
81
+ publishGap: number | bigint;
82
+ maxStaleness: number | bigint;
83
+ },
84
+ operationPayload: Cell,
85
+ ): Cell {
86
+ return beginCell()
87
+ .storeUint(args.opCode, 32)
88
+ .storeUint(args.queryId, 64)
89
+ .storeRef(
90
+ beginCell()
91
+ .storeRef(args.updateDataCell)
92
+ .storeRef(args.targetFeedsCell)
93
+ .storeUint(args.publishGap, 64)
94
+ .storeUint(args.maxStaleness, 64)
95
+ .endCell(),
96
+ )
97
+ .storeRef(operationPayload)
98
+ .endCell();
99
+ }
100
+
101
+ protected buildPythProxyMessage(
102
+ targetAddress: Address,
103
+ priceUpdateData: Cell,
104
+ targetPythFeeds: Cell,
105
+ minPublishTime: number | bigint,
106
+ maxPublishTime: number | bigint,
107
+ operationPayload: Cell,
108
+ ): Cell {
109
+ return beginCell()
110
+ .storeUint(5, 32) // pyth::op_parse_price_feed_updates
111
+ .storeRef(priceUpdateData)
112
+ .storeRef(targetPythFeeds)
113
+ .storeUint(minPublishTime, 64)
114
+ .storeUint(maxPublishTime, 64)
115
+ .storeAddress(targetAddress)
116
+ .storeRef(operationPayload)
117
+ .endCell();
118
+ }
119
+
120
+ // TODO: support without OPCODES.SUPPLY_WITHDRAW_MASTER_WITHOUT_PRICES
121
+ createSupplyWithdrawMessage(parameters: PythSupplyWithdrawParameters): Cell {
122
+ const operationPayload = this.buildSupplyWithdrawOperationPayload(parameters);
123
+
124
+ if (!isTonAsset(parameters.supplyAsset)) {
125
+ const { priceData, targetFeeds, publishGap, maxStaleness } = parameters.pyth as JettonPythParams;
126
+ const masterMessage = this.buildPythMasterMessage(
127
+ {
128
+ queryId: parameters.queryID,
129
+ opCode: OPCODES.SUPPLY_WITHDRAW_MASTER_JETTON,
130
+ updateDataCell: packPythUpdatesData(priceData),
131
+ targetFeedsCell: composeFeedsCell(targetFeeds),
132
+ publishGap,
133
+ maxStaleness,
134
+ },
135
+ operationPayload,
136
+ );
137
+
138
+ return this.createJettonTransferMessage(parameters, FEES.SUPPLY_WITHDRAW, masterMessage);
139
+ } else {
140
+ const { priceData, targetFeeds, minPublishTime, maxPublishTime } = parameters.pyth as TonPythParams;
141
+ const wrappedOperationPayload = beginCell()
142
+ .storeUint(OPCODES.SUPPLY_WITHDRAW_MASTER, 32)
143
+ .storeUint(parameters.queryID, 64)
144
+ .storeRef(operationPayload)
145
+ .endCell();
146
+ return this.buildPythProxyMessage(
147
+ this.address,
148
+ packPythUpdatesData(priceData),
149
+ composeFeedsCell(targetFeeds),
150
+ minPublishTime,
151
+ maxPublishTime,
152
+ wrappedOperationPayload,
153
+ );
154
+ }
155
+ }
156
+
157
+ // private createPythWithdrawMessage(parameters: PythWithdrawParameters): Cell {
158
+ // const extraTail =
159
+ // (parameters.subaccountId ?? 0) == 0
160
+ // ? beginCell().endCell()
161
+ // : beginCell()
162
+ // .storeInt(parameters.subaccountId ?? 0, 16)
163
+ // .storeUint(0, 2)
164
+ // .endCell();
165
+
166
+ // const wrappedOperationPayload = beginCell()
167
+ // .storeUint(OPCODES.SUPPLY_WITHDRAW_MASTER, 32) // op_code: 0x4
168
+ // .storeUint(parameters.queryID, 64)
169
+ // .storeRef(
170
+ // beginCell()
171
+ // .storeUint(parameters.asset.assetId, 256)
172
+ // .storeUint(parameters.amount, 64)
173
+ // .storeAddress(parameters.userAddress)
174
+ // .storeInt(parameters.includeUserCode ? -1 : 0, 2)
175
+ // .storeUint(parameters.amountToTransfer, 64)
176
+ // .storeRef(parameters.payload)
177
+ // .storeSlice(extraTail.beginParse())
178
+ // .endCell(),
179
+ // )
180
+ // .endCell();
181
+
182
+ // const { priceData, targetFeeds, minPublishTime, maxPublishTime } = parameters.pyth as TonPythParams;
183
+
184
+ // return makePythProxyMessage(
185
+ // this.address,
186
+ // packPythUpdatesData(priceData),
187
+ // composeFeedsCell(targetFeeds),
188
+ // minPublishTime,
189
+ // maxPublishTime,
190
+ // wrappedOperationPayload,
191
+ // );
192
+ // }
193
+
194
+ buildRefTokensDict(requestedRefTokens: bigint[]): Dictionary<bigint, Buffer> {
195
+ const refsDict: Dictionary<bigint, Buffer> = Dictionary.empty(
196
+ Dictionary.Keys.BigUint(256),
197
+ Dictionary.Values.Buffer(0),
198
+ );
199
+ for (const refToken of requestedRefTokens) {
200
+ refsDict.set(refToken, Buffer.alloc(0));
201
+ }
202
+
203
+ return refsDict;
204
+ }
205
+
206
+ buildGeneralDataPayload(parameters: PythSupplyWithdrawParameters): Cell {
207
+ const refTokensDict = this.buildRefTokensDict(parameters.pyth?.requestedRefTokens ?? []);
208
+ return beginCell()
209
+ .storeInt(parameters.includeUserCode ? -1 : 0, 2)
210
+ .storeDict(refTokensDict, Dictionary.Keys.BigUint(256), Dictionary.Values.Buffer(0))
211
+ .storeUint(parameters.tonForRepayRemainings ?? 0n, 64)
212
+ .storeRef(parameters.payload)
213
+ .storeInt(parameters.subaccountId ?? 0, 16)
214
+ .storeInt(parameters.returnRepayRemainingsFlag ? -1 : 0, 2)
215
+ .storeInt(parameters.customPayloadSaturationFlag ? -1 : 0, 2)
216
+ .endCell();
217
+ }
218
+
219
+ async sendWithdraw(
220
+ provider: ContractProvider,
221
+ via: Sender,
222
+ value: bigint,
223
+ parameters: PythWithdrawParameters,
224
+ ): Promise<void> {
225
+ const message = this.createSupplyWithdrawMessage({
226
+ supplyAsset: TON_MAINNET,
227
+ supplyAmount: 0n,
228
+ queryID: parameters.queryID,
229
+ withdrawAsset: parameters.asset,
230
+ withdrawAmount: parameters.amount,
231
+ withdrawRecipient: parameters.userAddress,
232
+ includeUserCode: parameters.includeUserCode,
233
+ forwardAmount: parameters.forwardAmount,
234
+ payload: parameters.payload,
235
+ subaccountId: parameters.subaccountId ?? 0,
236
+ customPayloadSaturationFlag: parameters.customPayloadSaturationFlag ?? false,
237
+ returnRepayRemainingsFlag: parameters.returnRepayRemainingsFlag ?? false,
238
+ tonForRepayRemainings: 0n,
239
+ pyth: parameters.pyth,
240
+ });
241
+ await via.send({
242
+ value,
243
+ to: parameters.pyth.pythAddress,
244
+ sendMode: SendMode.PAY_GAS_SEPARATELY + SendMode.IGNORE_ERRORS,
245
+ body: message,
246
+ });
247
+ }
248
+
249
+ protected buildLiquidationOperationPayload(parameters: PythLiquidationOperationParameters): Cell {
250
+ const operationPayloadBuilder = this.buildLiquidationOperationPayloadBuilder(parameters);
251
+ const innerBuilder = this.buildLiquidationInnerBuilder(parameters);
252
+
253
+ const refTokensDict = this.buildRefTokensDict(parameters.pyth.requestedRefTokens);
254
+
255
+ return operationPayloadBuilder.storeDict(refTokensDict).storeRef(innerBuilder).endCell();
256
+ }
257
+
258
+ createLiquidationMessage(parameters: PythLiquidationParameters): Cell {
259
+ const isTon = isTonAsset(parameters.asset);
260
+
261
+ const operationPayload = this.buildLiquidationOperationPayload(parameters);
262
+
263
+ if (!isTon) {
264
+ const { priceData, targetFeeds, publishGap, maxStaleness } =
265
+ parameters.pyth as OnchainSpecificPythParams & { priceData: Buffer | Cell; targetFeeds: HexString[] };
266
+ const masterMessage = this.buildPythMasterMessage(
267
+ {
268
+ queryId: parameters.queryID,
269
+ opCode: OPCODES.LIQUIDATE_MASTER,
270
+ updateDataCell: packPythUpdatesData(priceData as Buffer | Cell),
271
+ targetFeedsCell: composeFeedsCell(targetFeeds),
272
+ publishGap,
273
+ maxStaleness,
274
+ },
275
+ operationPayload,
276
+ );
277
+ return this.createJettonTransferMessage(parameters, FEES.LIQUIDATION_JETTON_FWD, masterMessage);
278
+ } else {
279
+ const { priceData, targetFeeds, minPublishTime, maxPublishTime } = parameters.pyth as TonPythParams & {
280
+ priceData: Buffer | Cell;
281
+ targetFeeds: HexString[];
282
+ };
283
+ const wrappedOperationPayload = beginCell()
284
+ .storeUint(OPCODES.LIQUIDATE_MASTER, 32)
285
+ .storeUint(parameters.queryID, 64)
286
+ .storeRef(operationPayload)
287
+ .endCell();
288
+ return this.buildPythProxyMessage(
289
+ this.address,
290
+ packPythUpdatesData(priceData as Buffer | Cell),
291
+ composeFeedsCell(targetFeeds),
292
+ minPublishTime,
293
+ maxPublishTime,
294
+ wrappedOperationPayload,
295
+ );
296
+ }
297
+ }
298
+
299
+ async sendLiquidation(
300
+ provider: ContractProvider,
301
+ via: Sender,
302
+ value: bigint,
303
+ parameters: PythLiquidationParameters,
304
+ ): Promise<void> {
305
+ const message = this.createLiquidationMessage(parameters);
306
+
307
+ await this.sendTx(provider, via, value, message, parameters.asset);
308
+ }
309
+
310
+ async getSync(provider: ContractProvider) {
311
+ await this.syncMasterData(provider, new PythOracleParser());
312
+ }
313
+ }
@@ -1,11 +1,9 @@
1
1
  import { Address, beginCell, Cell, Contract, ContractProvider, Dictionary, Sender, SendMode } from '@ton/core';
2
- import { UserData, UserLiteData } from '../types/User';
3
2
  import { parseUserData, parseUserLiteData } from '../api/parser';
4
- import { ExtendedAssetsConfig, ExtendedAssetsData, PoolConfig } from '../types/Master';
5
- import { LiquidationBaseData } from './MasterContract';
6
3
  import { OPCODES } from '../constants/general';
7
4
  import { MAINNET_POOL_CONFIG } from '../constants/pools';
8
- import { TON_MAINNET } from '../constants/assets';
5
+ import { ExtendedAssetsConfig, ExtendedAssetsData, PoolConfig } from '../types/Master';
6
+ import { UserData, UserLiteData } from '../types/User';
9
7
 
10
8
  /**
11
9
  * User contract wrapper
@@ -35,7 +33,7 @@ export class EvaaUser implements Contract {
35
33
  provider: ContractProvider,
36
34
  assetsData: ExtendedAssetsData,
37
35
  assetsConfig: ExtendedAssetsConfig,
38
- applyDust: boolean = false
36
+ applyDust: boolean = false,
39
37
  ) {
40
38
  const state = (await provider.getState()).state;
41
39
  if (state.type === 'active') {
@@ -44,7 +42,7 @@ export class EvaaUser implements Contract {
44
42
  assetsData,
45
43
  assetsConfig,
46
44
  this.poolConfig,
47
- applyDust
45
+ applyDust,
48
46
  );
49
47
  this.lastSync = Math.floor(Date.now() / 1000);
50
48
  } else {
@@ -87,7 +85,7 @@ export class EvaaUser implements Contract {
87
85
  value,
88
86
  sendMode: SendMode.PAY_GAS_SEPARATELY + SendMode.IGNORE_ERRORS,
89
87
  body: beginCell()
90
- .storeCoins(BigInt(OPCODES.ONCHAIN_GETTER))
88
+ .storeUint(OPCODES.ONCHAIN_GETTER, 32)
91
89
  .storeUint(queryID, 64)
92
90
  .storeRef(forwardPayload)
93
91
  .endCell(),
@@ -99,7 +97,7 @@ export class EvaaUser implements Contract {
99
97
  assetsData: ExtendedAssetsData,
100
98
  assetsConfig: ExtendedAssetsConfig,
101
99
  prices: Dictionary<bigint, bigint>,
102
- applyDust: boolean = false
100
+ applyDust: boolean = false,
103
101
  ) {
104
102
  const state = (await provider.getState()).state;
105
103
  if (state.type === 'active') {
@@ -108,7 +106,7 @@ export class EvaaUser implements Contract {
108
106
  assetsData,
109
107
  assetsConfig,
110
108
  this.poolConfig,
111
- applyDust
109
+ applyDust,
112
110
  );
113
111
  this._data = parseUserData(this._liteData, assetsData, assetsConfig, prices, this.poolConfig, applyDust);
114
112
  this.lastSync = Math.floor(Date.now() / 1000);
@@ -144,23 +142,4 @@ export class EvaaUser implements Contract {
144
142
 
145
143
  return this._data.liquidationData.liquidable;
146
144
  }
147
-
148
- /**
149
- * Get liquidation parameters for passing to liquidation message
150
- * @returns liquidation parameters if user is liquidable, otherwise undefined
151
- */
152
- get liquidationParameters(): LiquidationBaseData | undefined {
153
- if (!this._data || this._data.type === 'inactive' || !this._data.liquidationData.liquidable) {
154
- return undefined;
155
- }
156
-
157
- return {
158
- borrowerAddress: this._data.ownerAddress,
159
- loanAsset: this._data.liquidationData.greatestLoanAsset.assetId,
160
- collateralAsset: this._data.liquidationData.greatestCollateralAsset.assetId,
161
- minCollateralAmount: this._data.liquidationData.minCollateralAmount,
162
- liquidationAmount: this._data.liquidationData.liquidationAmount,
163
- tonLiquidation: this._data.liquidationData.greatestLoanAsset.assetId === TON_MAINNET.assetId,
164
- };
165
- }
166
145
  }
@@ -0,0 +1,7 @@
1
+ export * from './AbstractMaster';
2
+ export * from './ClassicMaster';
3
+ export * from './PythMaster';
4
+
5
+ export * from './UserContract';
6
+
7
+ export * from './JettonWallet';
package/src/index.ts CHANGED
@@ -1,102 +1,35 @@
1
1
  // Math
2
- export {
3
- mulFactor,
4
- mulDiv,
5
- bigIntMin,
6
- bigIntMax,
7
- calculatePresentValue,
8
- calculateCurrentRates,
9
- calculateAssetData,
10
- calculateAssetInterest,
11
- getAvailableToBorrow,
12
- calculateMaximumWithdrawAmount,
13
- presentValue,
14
- calculateLiquidationData,
15
- predictHealthFactor,
16
- calculateHealthParams,
17
- calculateInterestWithSupplyBorrow,
18
- predictAPY,
19
- BigMath,
20
- getAssetLiquidityMinusReserves,
21
- } from './api/math';
2
+ export * from './api/math';
22
3
 
23
- export {
24
- calculateLiquidationAmounts,
25
- calculateMinCollateralByTransferredAmount,
26
- isLiquidatable,
27
- isBadDebt,
28
- addReserve,
29
- deductReserve,
30
- addLiquidationBonus,
31
- deductLiquidationBonus,
32
- toAssetAmount,
33
- toAssetWorth,
34
- PreparedAssetInfo,
35
- PreparedAssetInfoResult,
36
- prepareAssetInfo,
37
- findAssetById,
38
- selectGreatestAssets,
39
- calculateAssetsValues,
40
- AssetsValues,
41
- SelectedAssets,
42
- } from './api/liquidation';
4
+ export * from './api/liquidation';
43
5
 
44
6
  // Parser
45
- export { createAssetData, createAssetConfig, parseMasterData, parseUserData, parseUserLiteData } from './api/parser';
7
+ export * from './api/parser';
8
+
9
+ // Oracles
10
+ export * from './api/parsers';
46
11
 
47
12
  // Prices
48
- export { getPrices } from './api/prices';
13
+ export * from './api/prices';
14
+
15
+ // Feeds utils
16
+ export * from './api/feeds';
49
17
 
50
18
  // Contracts' wrappers
51
- export { JettonWallet } from './contracts/JettonWallet';
52
- export {
53
- EvaaParameters,
54
- WithdrawParameters,
55
- LiquidationBaseData,
56
- LiquidationParameters,
57
- Evaa
58
- } from './contracts/MasterContract';
59
- export { EvaaUser } from './contracts/UserContract';
19
+ export * from './contracts';
60
20
 
61
21
  // Rewards contracts wrappers
22
+ export { EvaaUserRewards } from './rewards/EvaaRewards';
23
+ export { JettonMinter as RewardJettonMinter, type JettonMinterConfig, type MintMessage } from './rewards/JettonMinter';
24
+ export { JettonWallet as RewardJettonWallet, type JettonWalletConfig } from './rewards/JettonWallet';
62
25
  export { RewardMaster } from './rewards/RewardMaster';
63
- export { type EvaaRewardsConfig } from './types/MasterRewards';
64
26
  export { RewardUser } from './rewards/RewardUser';
27
+ export { type EvaaRewardsConfig } from './types/MasterRewards';
65
28
  export { type EvaaUserRewardsConfig } from './types/UserRewards';
66
- export { JettonMinter as RewardJettonMinter, type JettonMinterConfig, type MintMessage } from './rewards/JettonMinter';
67
- export { JettonWallet as RewardJettonWallet, type JettonWalletConfig } from './rewards/JettonWallet';
68
- export { EvaaUserRewards } from './rewards/EvaaRewards';
69
29
 
70
30
  // Types
71
- export {
72
- UpgradeConfig,
73
- AssetConfig,
74
- MasterConfig,
75
- AssetData,
76
- AssetInterest,
77
- AssetApy,
78
- ExtendedAssetData,
79
- MasterData,
80
- PoolConfig,
81
- ExtendedAssetsData,
82
- ExtendedAssetsConfig,
83
- PoolAssetConfig,
84
- PoolAssetsConfig,
85
- MasterConstants
86
- } from './types/Master';
87
-
88
- export {
89
- BalanceType,
90
- UserBalance,
91
- UserLiqudationData,
92
- LiquidableData,
93
- NonLiquidableData,
94
- LiquidationData,
95
- UserDataInactive,
96
- UserDataActive,
97
- UserData,
98
- BalanceChangeType
99
- } from './types/User';
31
+ export * from './types/Master';
32
+ export * from './types/User';
100
33
 
101
34
  // Constants
102
35
  export * from './constants/general';
@@ -104,8 +37,8 @@ export * from './constants/general';
104
37
  export * from './constants/pools';
105
38
 
106
39
  export * from './constants/assets';
107
- export * from './utils/utils';
108
40
  export * from './prices';
41
+ export * from './utils/utils';
109
42
 
110
43
  // Utils
111
44
  export { getLastSentBoc, getTonConnectSender } from './utils/tonConnectSender';
@@ -0,0 +1,18 @@
1
+ import { Dictionary } from '@ton/core';
2
+ import { Prices } from '.';
3
+ import { PoolAssetConfig, PoolAssetsConfig } from '../types/Master';
4
+ import { FetchConfig } from '../utils/utils';
5
+
6
+ export interface Oracle {
7
+ getPricesForLiquidate(realPrincipals: Dictionary<bigint, bigint>, fetchConfig?: FetchConfig): Promise<Prices>;
8
+
9
+ getPricesForSupplyWithdraw(
10
+ realPrincipals: Dictionary<bigint, bigint>,
11
+ supplyAsset: PoolAssetConfig | undefined,
12
+ withdrawAsset: PoolAssetConfig | undefined,
13
+ collateralToDebt: boolean,
14
+ fetchConfig?: FetchConfig,
15
+ ): Promise<Prices>;
16
+
17
+ getPrices(assets: PoolAssetsConfig, fetchConfig?: FetchConfig): Promise<Prices>;
18
+ }
@@ -1,12 +1,17 @@
1
- import { Cell, Dictionary } from "@ton/core";
2
- import { PoolAssetConfig } from "../types/Master";
1
+ import { Cell, Dictionary } from '@ton/core';
2
+ import { PoolAssetConfig } from '../types/Master';
3
3
 
4
4
  export class Prices {
5
5
  #dict: Dictionary<bigint, bigint>;
6
6
  #dataCell: Cell;
7
- constructor(dict: Dictionary<bigint, bigint>, dataCell: Cell) {
7
+ #minPublishTime?: bigint;
8
+ #maxPublishTime?: bigint;
9
+
10
+ constructor(dict: Dictionary<bigint, bigint>, dataCell: Cell, minPublishTime?: bigint, maxPublishTime?: bigint) {
8
11
  this.#dict = dict;
9
12
  this.#dataCell = dataCell;
13
+ this.#minPublishTime = minPublishTime;
14
+ this.#maxPublishTime = maxPublishTime;
10
15
  }
11
16
 
12
17
  get dict() {
@@ -21,6 +26,14 @@ export class Prices {
21
26
  return new Cell(this.#dataCell);
22
27
  }
23
28
 
29
+ get minPublishTime(): bigint | undefined {
30
+ return this.#minPublishTime;
31
+ }
32
+
33
+ get maxPublishTime(): bigint | undefined {
34
+ return this.#maxPublishTime;
35
+ }
36
+
24
37
  getAssetPrice<T extends bigint | PoolAssetConfig>(asset: T): bigint | undefined {
25
38
  const assetId = this.#extractAssetId(asset);
26
39
  return this.#dict.get(assetId);
@@ -29,4 +42,4 @@ export class Prices {
29
42
  #extractAssetId(asset: bigint | PoolAssetConfig): bigint {
30
43
  return typeof asset === 'bigint' ? asset : asset.assetId;
31
44
  }
32
- }
45
+ }