@evaafi/sdk 0.6.2 → 0.6.3-a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +2 -1
  2. package/dist/api/math.d.ts +12 -2
  3. package/dist/api/math.js +56 -4
  4. package/dist/api/parser.js +48 -20
  5. package/dist/constants/assets.d.ts +5 -1
  6. package/dist/constants/assets.js +24 -9
  7. package/dist/constants/general.d.ts +16 -0
  8. package/dist/constants/general.js +18 -2
  9. package/dist/constants/pools.d.ts +6 -1
  10. package/dist/constants/pools.js +46 -26
  11. package/dist/index.d.ts +10 -3
  12. package/dist/index.js +25 -2
  13. package/dist/prices/PricesCollector.d.ts +2 -2
  14. package/dist/prices/PricesCollector.js +8 -6
  15. package/dist/rewards/EvaaRewards.d.ts +10 -0
  16. package/dist/rewards/EvaaRewards.js +21 -0
  17. package/dist/rewards/JettonMinter.d.ts +30 -0
  18. package/dist/rewards/JettonMinter.js +83 -0
  19. package/dist/rewards/JettonWallet.d.ts +23 -0
  20. package/dist/rewards/JettonWallet.js +60 -0
  21. package/dist/rewards/RewardMaster.d.ts +26 -0
  22. package/dist/rewards/RewardMaster.js +83 -0
  23. package/dist/rewards/RewardUser.d.ts +23 -0
  24. package/dist/rewards/RewardUser.js +70 -0
  25. package/dist/types/MasterRewards.d.ts +13 -0
  26. package/dist/types/User.d.ts +11 -1
  27. package/dist/types/UserRewards.d.ts +10 -0
  28. package/dist/types/UserRewards.js +2 -0
  29. package/dist/utils/sha256BigInt.d.ts +2 -0
  30. package/dist/utils/sha256BigInt.js +9 -1
  31. package/dist/utils/userJettonWallet.js +7 -0
  32. package/package.json +42 -42
  33. package/src/api/math.ts +78 -3
  34. package/src/api/parser.ts +57 -22
  35. package/src/constants/assets.ts +91 -65
  36. package/src/constants/general.ts +30 -2
  37. package/src/constants/pools.ts +91 -28
  38. package/src/index.ts +23 -2
  39. package/src/prices/PricesCollector.ts +9 -5
  40. package/src/rewards/EvaaRewards.ts +23 -0
  41. package/src/rewards/JettonMinter.ts +113 -0
  42. package/src/rewards/JettonWallet.ts +77 -0
  43. package/src/rewards/RewardMaster.ts +110 -0
  44. package/src/rewards/RewardUser.ts +90 -0
  45. package/src/types/Master.ts +1 -1
  46. package/src/types/MasterRewards.ts +13 -0
  47. package/src/types/User.ts +13 -3
  48. package/src/types/UserRewards.ts +10 -0
  49. package/src/utils/sha256BigInt.ts +8 -0
  50. package/src/utils/userJettonWallet.ts +39 -33
  51. package/CHANGELOG.md +0 -240
  52. package/dist/config.d.ts +0 -1
  53. package/dist/config.js +0 -4
  54. package/dist/constants.d.ts +0 -69
  55. package/dist/constants.js +0 -83
  56. package/dist/types/Common.d.ts +0 -14
  57. package/dist/utils/priceUtils.d.ts +0 -55
  58. package/dist/utils/priceUtils.js +0 -117
  59. /package/dist/types/{Common.js → MasterRewards.js} +0 -0
package/CHANGELOG.md DELETED
@@ -1,240 +0,0 @@
1
- # Changelog
2
- All notable changes to this project will be documented in this file.
3
-
4
- The format is based on [Keep a Changelog](https://keepachangelog.com/)
5
- and this project adheres to [Semantic Versioning](https://semver.org/).
6
-
7
- ## 0.6.2 - 2024-11-21
8
- ### Added
9
- - ALTS Pool
10
- - PricesCollector class
11
- - Supports multiple prices sources [iota nft, evaa backend, internetcomputer (icp) http backend] (sources can be configured)
12
- - Updates prices only when needed, prices may expire no earlier than a minute later
13
- - Ability to cut prices and resign it and send only the necessary ones in order to reduce fee
14
- - ```typescript
15
- async getPricesForWithdraw(userPrincipals: Dictionary<bigint, bigint>, withdrawAsset: PoolAssetConfig, collateralToDebt = false, ....)
16
- ```
17
- collateralToDebt param responsible for the fact that supply can go to borrow (there is no such case at the front end)
18
- - ```typescript
19
- async getPricesForLiquidate(userPrincipals: Dictionary<bigint, bigint> ...)
20
- ```
21
- - Price Signature Vrification
22
- - Minimal Oracles Number Verification
23
- - Independent and parallel loading of prices (now the fastest but invalid response won't break anything)
24
- - Support for partial number of assets from price sources
25
- - Updated examples in docs/examples
26
- - PricesCollector test coverage
27
- - If the price is missing (for example, for security reasons), then there will be no error, it will simply NOT be added to the result dict
28
-
29
- ### Changed
30
- - getPrices is deprecated use PricesCollector instead
31
-
32
- ## 0.6.1-a - 2024-10-29
33
- ### Changed
34
- - updated `EVAA_LP_MAINNET_VERSION` to `3`
35
- - `awaitedSupply` is always defined
36
- ### Fixed
37
- - `applyDust` is `false` by default in `parseUserLiteData` and `parseUserData`
38
- - `minimalOracles` is `3` in all pools
39
-
40
-
41
- ## 0.6.1 - 2024-10-22
42
- ### Changed
43
- - added liquidation.ts with ```findAssetById```, ```calculateAssetsValues```, ```selectGreatestAssets```, ```calculateMinCollateralByTransferredAmount```, ```calculateLiquidationAmounts```, ```isLiquidatable```, ```isBadDebt```, ```addReserve```, ```deductReserve```, ```toAssetAmount```, ```toAssetWorth```, ```addLiquidationBonus```, ```deductLiquidationBonus```, ```PreparedAssetInfo```, ```prepareAssetInfo``` functions required or flexible liquidations calculation.
44
- - user. ```getSync``` and ```getSyncLite``` new argument ```applyDust``` by default is ```false```;
45
- - updated sdk usage example
46
- ### Fixed
47
-
48
-
49
- ## 0.6.0a - 2024-10-14
50
- ### Changed
51
- - user. ```getSync``` and ```getSyncLite``` new argument ```applyDust``` by default is ```false```
52
- ### Fixed
53
- - Healthfactor calculation minor bug
54
- - createLiquidationMessage fix new field payloadForwardAmount
55
-
56
- ## 0.6.0 - 2024-10-10
57
- ### Added
58
- - SDK Supports Evaa v6 smart contracts
59
- ### Fixed
60
- - Updated documentation and examples for v6 interactions
61
- - User Withdrawal and Borrow limits
62
- ## 0.5.6a - 2024-10-09
63
- ### Fixed
64
- - Fix typo in ```calculateMaximumWithdrawAmount```
65
-
66
- ## 0.5.6 - 2024-09-28
67
-
68
- ### Added
69
- - ```isTonAsset(PoolAssetConfig)``` function
70
- ### Fixed
71
- Dust is a small amount of principal that is ignored
72
- - ```parseUserLiteData``` (dust) & ```parseUserData``` (dust and withdrawLimits) calculations problem
73
- - ```user.data.withdrawalLimits```, ```user.data.balance```, ```user.data.principals``` calculation for LP pool contract and main pool contract
74
- ### Changed
75
- - ```parseUserLiteData``` (without prices), ```parseUserData``` applyDust argument default value changed to ```True```
76
- - Many composite types were removed from sdk
77
- - ```PoolTonAssetConfig, PoolJettonAssetConfig``` -> ```PoolAssetConfig```,
78
- - ```JettonMessageParameters, SupplyBaseParameters, TonSupplyParameters, JettonSupplyParameters``` -> ```SupplyParameters```,
79
- - ```LiquidationBasePrameters, TonLiquidationParameters, JettonLiquidationParameters``` -> ```LiquidationParameters```
80
-
81
- ## 0.5.5
82
-
83
- ### Added
84
- - calculateMaximumWithdrawAmount function
85
- ### Fixed
86
- - parseUserLiteData (dust) & parseUserData (dust and withdrawLimits) calculations problem
87
-
88
- ## 0.5.4 - 2024-09-09
89
-
90
- check ```tests\supply_withdraw_test.ts``` for new examples
91
-
92
- ### Added
93
-
94
- - Pools supports (new argument for Evaa master contract) + LP_POOL constants, default is MAINNET_POOL_CONFIG, default pool is MAINNET_POOL_CONFIG
95
- ```typescript
96
- const evaa = client.open(new Evaa({poolConfig: TESTNET_LP_POOL_CONFIG}));
97
-
98
- const evaaMainNet = clientMainNet.open(new Evaa({poolConfig: MAINNET_LP_POOL_CONFIG}));
99
- ```
100
- - New types for pools initializtion, for assets
101
- check ```constants\assets.ts``` for new examples
102
-
103
- - getPrices - a new function inside Evaa, returns prices of current pool
104
-
105
- ```typescript
106
- await evaaMainNet.getPrices()
107
- ```
108
- ### Changed
109
- - New argument nftId (depends on pool) for getPrices
110
- ```typescript
111
- export async function getPrices(endpoints: string[] = ["api.stardust-mainnet.iotaledger.net"], nftId: string = MAIN_POOL_NFT_ID) {
112
- ```
113
-
114
- - Everything about working with assets, new assets list
115
- ```typescript
116
- import { JUSDC_MAINNET, JUSDC_TESTNET, JUSDT_MAINNET, JUSDT_TESTNET, STTON_MAINNET, STTON_TESTNET, TON_MAINNET, TON_STORM_MAINNET, TONUSDT_DEDUST_MAINNET, TSTON_MAINNET, USDT_MAINNET, USDT_STORM_MAINNET } from "@evaafi/sdk";
117
- ```
118
-
119
- ```typescript
120
- await evaaMainNet.sendSupply(sender_mainnet, toNano(1), {
121
- queryID: 0n,
122
- includeUserCode: true,
123
- amount: 500_000_000n,
124
- userAddress: address_mainnet,
125
- asset: TON_MAINNET
126
- });
127
- ```
128
- ### Fixed
129
- - predictHealthFactor minor fixes
130
- - getUserJettonWallet all currencies support
131
-
132
- ## 0.5.3 - 2024-08-20
133
-
134
- ### Fixed
135
- - getPrices now supports several endpoints (works on the principle of which one will answer faster, whose answer is used) and throws an exception if prices are not loaded
136
-
137
- ## 0.5.2 - 2024-08-19
138
-
139
- ### Fixed
140
- - predictHealthFactor argument processing improving
141
- - getSync fixed parsing contract state, base64url was replaced to base64 encoding which has much higher support
142
-
143
- ## 0.5.1 - 2024-07-05
144
-
145
- ### Added
146
- - predictHealthFactor function to predict a change in a health factor after repay, borrow, supply, withdraw
147
-
148
- ## 0.5.0 - 2024-06-29
149
- This release contains breaking changes.
150
-
151
- ### Added
152
- - Reserve variables parsing on user & master sc
153
- - Added endpoint argument for getPrices, default api.stardust-mainnet.iotaledger.net
154
- - Added applyDust (default false) option in parseUserLiteData and parseUserData
155
-
156
- ### Changed
157
- - Master contracts' version
158
- - Testnet master contract address
159
- - Parsers on master sc
160
- - Parsers on user sc
161
- - Liquidation calculations now counts with reserve factor from master config
162
-
163
- ### Fixed
164
- - UserBalance calculation was fixed
165
-
166
- ## 0.4.0 - 2024-06-01
167
- This release contains breaking changes.
168
-
169
- ### Added
170
- - Master storage onchain getter
171
- - User storage onchain getter
172
- - Testnet flag for `parseMasterData`, `parseUserData` and `parseUserLiteData` functions
173
- - `maxTotalSupply` field to Assets Config
174
- - Seperate Assets ID for Mainnet and Testnet
175
-
176
- ### Changed
177
- - Master contracts' version
178
- - Testnet master contract address
179
-
180
- ### Removed
181
- - `ASSET_ID` constant
182
-
183
- ### Fixed
184
- - Jetton wallets address calculation
185
- - Field names in Assets Config and Assets Data serialization functions
186
-
187
- ## 0.3.2 - 2024-04-20
188
- ### Added
189
- - New asset - Tether USD
190
-
191
- ## 0.3.1 - 2024-04-19
192
- ### Added
193
- - New asset - tsTON
194
-
195
- ## 0.3.0 - 2024-04-04
196
- ### Added
197
- - New asset - stTON
198
-
199
- ### Changed
200
- - Price fetching from another source
201
- - Testnet master contract address
202
- - Master contracts' version
203
-
204
- ### Removed
205
- - Ethereum dependencies
206
-
207
- ## 0.2.0 - 2024-03-13
208
- This release contains breaking changes.
209
-
210
- ### Added
211
- - BOC of last sent message via TonConnect. Can be obtained by `getLastSentBoc` function
212
- - Calculation of user's health factor
213
-
214
- ### Changed
215
- - Testnet master contract address and version
216
- - Supply fee from 0.5 TON to 0.3 TON
217
- - APY moved from user data to master data
218
-
219
- ### Removed
220
- - Description of some methods in `UserContract` and `MasterContract`
221
-
222
- ### Fixed
223
- - Calculation of borrow limits
224
-
225
- ## 0.1.0 - 2024-03-11
226
- ### Added
227
- - Parsing user lite data, which does not require prices
228
- - Assets reserves to `MasterData`
229
- - Types and methods descriptions in `MasterContract` and `UserContract`
230
-
231
- ### Changed
232
- - Added parallel price fetching
233
- - Crypto library to 'crypto-js' for compatibility with browser
234
- - Testnet Master version to 2
235
-
236
- ### Removed
237
- - `sort-deep-object-arrays` dependency
238
-
239
- ### Fixed
240
- - Getting user's jetton wallet
package/dist/config.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare const TTL_ORACLE_DATA_SEC = 120;
package/dist/config.js DELETED
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TTL_ORACLE_DATA_SEC = void 0;
4
- exports.TTL_ORACLE_DATA_SEC = 120; // todo back to 120
@@ -1,69 +0,0 @@
1
- import { Address, Cell } from '@ton/core';
2
- import { OracleNFT } from './types/Master';
3
- export declare const EVAA_MASTER_MAINNET: Address;
4
- export declare const MAINNET_VERSION = 0;
5
- export declare const EVAA_MASTER_TESTNET: Address;
6
- export declare const TESTNET_VERSION = 6;
7
- export declare const ORACLE_NFTS: OracleNFT[];
8
- export declare const MAINNET_ASSETS_ID: {
9
- TON: bigint;
10
- jUSDT: bigint;
11
- jUSDC: bigint;
12
- stTON: bigint;
13
- tsTON: bigint;
14
- };
15
- export declare const TESTNET_ASSETS_ID: {
16
- TON: bigint;
17
- jUSDT: bigint;
18
- jUSDC: bigint;
19
- stTON: bigint;
20
- };
21
- export declare const JETTON_MASTER_ADDRESSES: {
22
- jUSDT_MAINNET: Address;
23
- jUSDT_TESTNET: Address;
24
- jUSDC_MAINNET: Address;
25
- jUSDC_TESTNET: Address;
26
- stTON_MAINNET: Address;
27
- stTON_TESTNET: Address;
28
- tsTON_MAINNET: Address;
29
- tsTON_TESTNET: null;
30
- USDT_MAINNET: Address;
31
- USDT_TESTNET: null;
32
- };
33
- export declare const MASTER_CONSTANTS: {
34
- FACTOR_SCALE: bigint;
35
- ASSET_COEFFICIENT_SCALE: bigint;
36
- ASSET_PRICE_SCALE: bigint;
37
- ASSET_RESERVE_FACTOR_SCALE: bigint;
38
- ASSET_LIQUIDATION_RESERVE_FACTOR_SCALE: bigint;
39
- ASSET_ORIGINATION_FEE_SCALE: bigint;
40
- };
41
- export declare const LENDING_CODE: Cell;
42
- export declare const JETTON_WALLETS_CODE: {
43
- jUSDT_MAINNET: Cell;
44
- jUSDT_TESTNET: Cell;
45
- jUSDC_MAINNET: Cell;
46
- jUSDC_TESTNET: Cell;
47
- stTON_MAINNET: Cell;
48
- stTON_TESTNET: Cell;
49
- tsTON_MAINNET: Cell;
50
- tsTON_TESTNET: null;
51
- USDT_MAINNET: Cell;
52
- USDT_TESTNET: null;
53
- };
54
- export declare const OPCODES: {
55
- SUPPLY: number;
56
- WITHDRAW: number;
57
- LIQUIDATE: number;
58
- JETTON_TRANSFER: number;
59
- ONCHAIN_GETTER: number;
60
- };
61
- export declare const FEES: {
62
- SUPPLY: bigint;
63
- WITHDRAW: bigint;
64
- SUPPLY_JETTON: bigint;
65
- SUPPLY_JETTON_FWD: bigint;
66
- LIQUIDATION: bigint;
67
- LIQUIDATION_JETTON: bigint;
68
- LIQUIDATION_JETTON_FWD: bigint;
69
- };
package/dist/constants.js DELETED
@@ -1,83 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FEES = exports.OPCODES = exports.JETTON_WALLETS_CODE = exports.LENDING_CODE = exports.MASTER_CONSTANTS = exports.JETTON_MASTER_ADDRESSES = exports.TESTNET_ASSETS_ID = exports.MAINNET_ASSETS_ID = exports.ORACLE_NFTS = exports.TESTNET_VERSION = exports.EVAA_MASTER_TESTNET = exports.MAINNET_VERSION = exports.EVAA_MASTER_MAINNET = void 0;
4
- const core_1 = require("@ton/core");
5
- const sha256BigInt_1 = require("./utils/sha256BigInt");
6
- //todo set back to EQC8rUZqR_pWV1BylWUlPNBzyiTYVoBEmQkMIQDZXICfnuRr
7
- exports.EVAA_MASTER_MAINNET = core_1.Address.parse('EQC_hR5L4G3vkPG0VODURYoohp_3hlMW-gZiGp89HwyulZK4');
8
- //todo set back to 5 (todo set at 6 on 10.10.2024)
9
- exports.MAINNET_VERSION = 0;
10
- exports.EVAA_MASTER_TESTNET = core_1.Address.parse('kQC92pF4XWatZY9-ZS6SGW6s-dCpjk9NtEkdXQ7vFHJUAdT9');
11
- exports.TESTNET_VERSION = 6;
12
- exports.ORACLE_NFTS = [
13
- { id: 0, address: '0xd3a8c0b9fd44fd25a49289c631e3ac45689281f2f8cf0744400b4c65bed38e5d' },
14
- { id: 1, address: '0x2c21cabdaa89739de16bde7bc44e86401fac334a3c7e55305fe5e7563043e191' },
15
- { id: 2, address: '0x2eb258ce7b5d02466ab8a178ad8b0ba6ffa7b58ef21de3dc3b6dd359a1e16af0' },
16
- { id: 3, address: '0xf9a0769954b4430bca95149fb3d876deb7799d8f74852e0ad4ccc5778ce68b52' },
17
- ];
18
- exports.MAINNET_ASSETS_ID = {
19
- TON: (0, sha256BigInt_1.sha256Hash)('TON'),
20
- jUSDT: (0, sha256BigInt_1.sha256Hash)('jUSDT'),
21
- jUSDC: (0, sha256BigInt_1.sha256Hash)('jUSDC'),
22
- stTON: (0, sha256BigInt_1.sha256Hash)('stTON'),
23
- tsTON: (0, sha256BigInt_1.sha256Hash)('tsTON'),
24
- //todo uncomment
25
- // USDT: sha256Hash('USDT'),
26
- };
27
- exports.TESTNET_ASSETS_ID = {
28
- TON: (0, sha256BigInt_1.sha256Hash)('TON'),
29
- jUSDT: (0, sha256BigInt_1.sha256Hash)('jUSDT'),
30
- jUSDC: (0, sha256BigInt_1.sha256Hash)('jUSDC'),
31
- stTON: (0, sha256BigInt_1.sha256Hash)('stTON'),
32
- // tsTON: sha256Hash('tsTON'),
33
- // USDT: sha256Hash('USDT'),
34
- };
35
- exports.JETTON_MASTER_ADDRESSES = {
36
- jUSDT_MAINNET: core_1.Address.parse('EQBynBO23ywHy_CgarY9NK9FTz0yDsG82PtcbSTQgGoXwiuA'),
37
- jUSDT_TESTNET: core_1.Address.parse('kQBe4gtSQMxM5RpMYLr4ydNY72F8JkY-icZXG1NJcsju8XM7'),
38
- jUSDC_MAINNET: core_1.Address.parse('EQB-MPwrd1G6WKNkLz_VnV6WqBDd142KMQv-g1O-8QUA3728'),
39
- jUSDC_TESTNET: core_1.Address.parse('kQDaY5yUatYnHei73HBqRX_Ox9LK2XnR7XuCY9MFC2INbfYI'),
40
- stTON_MAINNET: core_1.Address.parse('EQDNhy-nxYFgUqzfUzImBEP67JqsyMIcyk2S5_RwNNEYku0k'),
41
- stTON_TESTNET: core_1.Address.parse('kQC3Duw3dg8k98xf5S7Bm7YOWVJ5QW8hm3iLqFfJfa_g9h07'),
42
- tsTON_MAINNET: core_1.Address.parse('EQC98_qAmNEptUtPc7W6xdHh_ZHrBUFpw5Ft_IzNU20QAJav'),
43
- tsTON_TESTNET: null,
44
- USDT_MAINNET: core_1.Address.parse('EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs'),
45
- USDT_TESTNET: null,
46
- };
47
- exports.MASTER_CONSTANTS = {
48
- FACTOR_SCALE: BigInt(1e12),
49
- ASSET_COEFFICIENT_SCALE: 10000n,
50
- ASSET_PRICE_SCALE: BigInt(1e8),
51
- ASSET_RESERVE_FACTOR_SCALE: 10000n,
52
- ASSET_LIQUIDATION_RESERVE_FACTOR_SCALE: 10000n,
53
- ASSET_ORIGINATION_FEE_SCALE: BigInt(1e9)
54
- };
55
- exports.LENDING_CODE = core_1.Cell.fromBoc(Buffer.from('b5ee9c72c1010e0100fd000d12182a555a6065717691969efd0114ff00f4a413f4bcf2c80b010202c8050202039f740403001ff2f8276a2687d2018fd201800f883b840051d38642c678b64e4400780e58fc10802faf07f80e59fa801e78b096664c02078067c07c100627a7978402014807060007a0ddb0c60201c709080013a0fd007a026900aa90400201200b0a0031b8e1002191960aa00b9e2ca007f4042796d225e8019203f6010201200d0c000bf7c147d2218400b9d10e86981fd201840b07f8138d809797976a2687d2029116382f970fd9178089910374daf81b619fd20182c7883b8701981684100627910eba56001797a6a6ba610fd8200e8768f76a9f6aa00cc2a32a8292878809bef2f1889f883bbcdeb86f01', 'hex'))[0];
56
- exports.JETTON_WALLETS_CODE = {
57
- jUSDT_MAINNET: core_1.Cell.fromBoc(Buffer.from('b5ee9c7201021301000385000114ff00f4a413f4bcf2c80b0102016202030202cb0405001ba0f605da89a1f401f481f481a9a30201ce06070201580a0b02f70831c02497c138007434c0c05c6c2544d7c0fc07783e903e900c7e800c5c75c87e800c7e800c1cea6d0000b4c7c076cf16cc8d0d0d09208403e29fa96ea68c1b088d978c4408fc06b809208405e351466ea6cc1b08978c840910c03c06f80dd6cda0841657c1ef2ea7c09c6c3cb4b01408eebcb8b1807c073817c160080900113e910c30003cb85360005c804ff833206e953080b1f833de206ef2d29ad0d30731d3ffd3fff404d307d430d0fa00fa00fa00fa00fa00fa00300008840ff2f00201580c0d020148111201f70174cfc0407e803e90087c007b51343e803e903e903534544da8548b31c17cb8b04ab0bffcb8b0950d109c150804d50500f214013e809633c58073c5b33248b232c044bd003d0032c032481c007e401d3232c084b281f2fff274013e903d010c7e800835d270803cb8b13220060072c15401f3c59c3e809dc072dae00e02f33b51343e803e903e90353442b4cfc0407e80145468017e903e9014d771c1551cdbdc150804d50500f214013e809633c58073c5b33248b232c044bd003d0032c0325c007e401d3232c084b281f2fff2741403f1c147ac7cb8b0c33e801472a84a6d8206685401e8062849a49b1578c34975c2c070c00870802c200f1000aa13ccc88210178d4519580a02cb1fcb3f5007fa0222cf165006cf1625fa025003cf16c95005cc2391729171e25007a813a008aa005004a017a014bcf2e2c501c98040fb004300c85004fa0258cf1601cf16ccc9ed5400725269a018a1c882107362d09c2902cb1fcb3f5007fa025004cf165007cf16c9c8801001cb0527cf165004fa027101cb6a13ccc971fb0050421300748e23c8801001cb055006cf165005fa027001cb6a8210d53276db580502cb1fcb3fc972fb00925b33e24003c85004fa0258cf1601cf16ccc9ed5400eb3b51343e803e903e9035344174cfc0407e800870803cb8b0be903d01007434e7f440745458a8549631c17cb8b049b0bffcb8b0b220841ef765f7960100b2c7f2cfc07e8088f3c58073c584f2e7f27220060072c148f3c59c3e809c4072dab33260103ec01004f214013e809633c58073c5b3327b55200087200835c87b51343e803e903e9035344134c7c06103c8608405e351466e80a0841ef765f7ae84ac7cbd34cfc04c3e800c04e81408f214013e809633c58073c5b3327b5520', 'hex'))[0],
58
- jUSDT_TESTNET: core_1.Cell.fromBoc(Buffer.from('b5ee9c7201021101000323000114ff00f4a413f4bcf2c80b0102016202030202cc0405001ba0f605da89a1f401f481f481a8610201d40607020120080900c30831c02497c138007434c0c05c6c2544d7c0fc03383e903e900c7e800c5c75c87e800c7e800c1cea6d0000b4c7e08403e29fa954882ea54c4d167c0278208405e3514654882ea58c511100fc02b80d60841657c1ef2ea4d67c02f817c12103fcbc2000113e910c1c2ebcb853600201200a0b0083d40106b90f6a2687d007d207d206a1802698fc1080bc6a28ca9105d41083deecbef09dd0958f97162e99f98fd001809d02811e428027d012c678b00e78b6664f6aa401f1503d33ffa00fa4021f001ed44d0fa00fa40fa40d4305136a1522ac705f2e2c128c2fff2e2c254344270542013541403c85004fa0258cf1601cf16ccc922c8cb0112f400f400cb00c920f9007074c8cb02ca07cbffc9d004fa40f40431fa0020d749c200f2e2c4778018c8cb055008cf1670fa0217cb6b13cc80c0201200d0e009e8210178d4519c8cb1f19cb3f5007fa0222cf165006cf1625fa025003cf16c95005cc2391729171e25008a813a08209c9c380a014bcf2e2c504c98040fb001023c85004fa0258cf1601cf16ccc9ed5402f73b51343e803e903e90350c0234cffe80145468017e903e9014d6f1c1551cdb5c150804d50500f214013e809633c58073c5b33248b232c044bd003d0032c0327e401c1d3232c0b281f2fff274140371c1472c7cb8b0c2be80146a2860822625a019ad822860822625a028062849e5c412440e0dd7c138c34975c2c0600f1000d73b51343e803e903e90350c01f4cffe803e900c145468549271c17cb8b049f0bffcb8b08160824c4b402805af3cb8b0e0841ef765f7b232c7c572cfd400fe8088b3c58073c5b25c60063232c14933c59c3e80b2dab33260103ec01004f214013e809633c58073c5b3327b552000705279a018a182107362d09cc8cb1f5230cb3f58fa025007cf165007cf16c9718010c8cb0524cf165006fa0215cb6a14ccc971fb0010241023007cc30023c200b08e218210d53276db708010c8cb055008cf165004fa0216cb6a12cb1f12cb3fc972fb0093356c21e203c85004fa0258cf1601cf16ccc9ed54', 'hex'))[0],
59
- jUSDC_MAINNET: core_1.Cell.fromBoc(Buffer.from('b5ee9c7201021301000385000114ff00f4a413f4bcf2c80b0102016202030202cb0405001ba0f605da89a1f401f481f481a9a30201ce06070201580a0b02f70831c02497c138007434c0c05c6c2544d7c0fc07783e903e900c7e800c5c75c87e800c7e800c1cea6d0000b4c7c076cf16cc8d0d0d09208403e29fa96ea68c1b088d978c4408fc06b809208405e351466ea6cc1b08978c840910c03c06f80dd6cda0841657c1ef2ea7c09c6c3cb4b01408eebcb8b1807c073817c160080900113e910c30003cb85360005c804ff833206e953080b1f833de206ef2d29ad0d30731d3ffd3fff404d307d430d0fa00fa00fa00fa00fa00fa00300008840ff2f00201580c0d020148111201f70174cfc0407e803e90087c007b51343e803e903e903534544da8548b31c17cb8b04ab0bffcb8b0950d109c150804d50500f214013e809633c58073c5b33248b232c044bd003d0032c032481c007e401d3232c084b281f2fff274013e903d010c7e800835d270803cb8b13220060072c15401f3c59c3e809dc072dae00e02f33b51343e803e903e90353442b4cfc0407e80145468017e903e9014d771c1551cdbdc150804d50500f214013e809633c58073c5b33248b232c044bd003d0032c0325c007e401d3232c084b281f2fff2741403f1c147ac7cb8b0c33e801472a84a6d8206685401e8062849a49b1578c34975c2c070c00870802c200f1000aa13ccc88210178d4519580a02cb1fcb3f5007fa0222cf165006cf1625fa025003cf16c95005cc2391729171e25007a813a008aa005004a017a014bcf2e2c501c98040fb004300c85004fa0258cf1601cf16ccc9ed5400725269a018a1c882107362d09c2902cb1fcb3f5007fa025004cf165007cf16c9c8801001cb0527cf165004fa027101cb6a13ccc971fb0050421300748e23c8801001cb055006cf165005fa027001cb6a8210d53276db580502cb1fcb3fc972fb00925b33e24003c85004fa0258cf1601cf16ccc9ed5400eb3b51343e803e903e9035344174cfc0407e800870803cb8b0be903d01007434e7f440745458a8549631c17cb8b049b0bffcb8b0b220841ef765f7960100b2c7f2cfc07e8088f3c58073c584f2e7f27220060072c148f3c59c3e809c4072dab33260103ec01004f214013e809633c58073c5b3327b55200087200835c87b51343e803e903e9035344134c7c06103c8608405e351466e80a0841ef765f7ae84ac7cbd34cfc04c3e800c04e81408f214013e809633c58073c5b3327b5520', 'hex'))[0],
60
- jUSDC_TESTNET: core_1.Cell.fromBoc(Buffer.from('b5ee9c7201021101000323000114ff00f4a413f4bcf2c80b0102016202030202cc0405001ba0f605da89a1f401f481f481a8610201d40607020120080900c30831c02497c138007434c0c05c6c2544d7c0fc03383e903e900c7e800c5c75c87e800c7e800c1cea6d0000b4c7e08403e29fa954882ea54c4d167c0278208405e3514654882ea58c511100fc02b80d60841657c1ef2ea4d67c02f817c12103fcbc2000113e910c1c2ebcb853600201200a0b0083d40106b90f6a2687d007d207d206a1802698fc1080bc6a28ca9105d41083deecbef09dd0958f97162e99f98fd001809d02811e428027d012c678b00e78b6664f6aa401f1503d33ffa00fa4021f001ed44d0fa00fa40fa40d4305136a1522ac705f2e2c128c2fff2e2c254344270542013541403c85004fa0258cf1601cf16ccc922c8cb0112f400f400cb00c920f9007074c8cb02ca07cbffc9d004fa40f40431fa0020d749c200f2e2c4778018c8cb055008cf1670fa0217cb6b13cc80c0201200d0e009e8210178d4519c8cb1f19cb3f5007fa0222cf165006cf1625fa025003cf16c95005cc2391729171e25008a813a08209c9c380a014bcf2e2c504c98040fb001023c85004fa0258cf1601cf16ccc9ed5402f73b51343e803e903e90350c0234cffe80145468017e903e9014d6f1c1551cdb5c150804d50500f214013e809633c58073c5b33248b232c044bd003d0032c0327e401c1d3232c0b281f2fff274140371c1472c7cb8b0c2be80146a2860822625a019ad822860822625a028062849e5c412440e0dd7c138c34975c2c0600f1000d73b51343e803e903e90350c01f4cffe803e900c145468549271c17cb8b049f0bffcb8b08160824c4b402805af3cb8b0e0841ef765f7b232c7c572cfd400fe8088b3c58073c5b25c60063232c14933c59c3e80b2dab33260103ec01004f214013e809633c58073c5b3327b552000705279a018a182107362d09cc8cb1f5230cb3f58fa025007cf165007cf16c9718010c8cb0524cf165006fa0215cb6a14ccc971fb0010241023007cc30023c200b08e218210d53276db708010c8cb055008cf165004fa0216cb6a12cb1f12cb3fc972fb0093356c21e203c85004fa0258cf1601cf16ccc9ed54', 'hex'))[0],
61
- stTON_MAINNET: core_1.Cell.fromBoc(Buffer.from('b5ee9c7201021201000362000114ff00f4a413f4bcf2c80b0102016202030202cc0405001ba0f605da89a1f401f481f481a8610201d40607020120090a01cf0831c02497c138007434c0c05c6c2544d7c0fc03783e903e900c7e800c5c75c87e800c7e800c1cea6d0000b4c7c8608403e29fa96ea54c4d167c02b808608405e351466ea58c511100fc02f80860841657c1ef2ea54c4d167c03380517c1300138c08c2103fcbc200800113e910c30003cb85360007ced44d0fa00fa40fa40d43010235f03018208989680a16d801072226eb32091719170e203c8cb055006cf165004fa02cb6a039358cc019130e201c901fb000201580b0c020148101101f100f4cffe803e90087c007b51343e803e903e90350c144da8548ab1c17cb8b04a30bffcb8b0950d109c150804d50500f214013e809633c58073c5b33248b232c044bd003d0032c032483e401c1d3232c0b281f2fff274013e903d010c7e800835d270803cb8b11de0063232c1540233c59c3e8085f2dac4f3200d02f73b51343e803e903e90350c0234cffe80145468017e903e9014d6f1c1551cdb5c150804d50500f214013e809633c58073c5b33248b232c044bd003d0032c0327e401c1d3232c0b281f2fff274140371c1472c7cb8b0c2be80146a2860822625a019ad8228608239387028062849e5c412440e0dd7c138c34975c2c0600e0f009e8210178d4519c8cb1f19cb3f5007fa0222cf165006cf1625fa025003cf16c95005cc2391729171e25008a813a0820a625a00a014bcf2e2c504c98040fb001023c85004fa0258cf1601cf16ccc9ed5400705279a018a182107362d09cc8cb1f5230cb3f58fa025007cf165007cf16c9718010c8cb0524cf165006fa0215cb6a14ccc971fb0010241023007cc30023c200b08e218210d53276db708010c8cb055008cf165004fa0216cb6a12cb1f12cb3fc972fb0093356c21e203c85004fa0258cf1601cf16ccc9ed5400c90c3b51343e803e903e90350c01b4cffe800c145128548df1c17cb8b04970bffcb8b0812082e4e1c02fbcb8b160841ef765f7b232c7c532cfd63e808873c5b25c60063232c14933c59c3e80b2dab33260103ec01004f214013e809633c58073c5b3327b55200081200835c87b51343e803e903e90350c0134c7c8608405e351466e80a0841ef765f7ae84ac7cb83234cfcc7e800c04e81408f214013e809633c58073c5b3327b5520', 'hex'))[0],
62
- stTON_TESTNET: core_1.Cell.fromBoc(Buffer.from('b5ee9c7201021201000362000114ff00f4a413f4bcf2c80b0102016202030202cc0405001ba0f605da89a1f401f481f481a8610201d40607020120090a01cf0831c02497c138007434c0c05c6c2544d7c0fc03383e903e900c7e800c5c75c87e800c7e800c1cea6d0000b4c7c8608403e29fa96ea54c4d167c027808608405e351466ea58c511100fc02b80860841657c1ef2ea54c4d167c02f80517c1300138c08c2103fcbc200800113e910c30003cb85360007ced44d0fa00fa40fa40d43010235f03018208989680a16d801072226eb32091719170e203c8cb055006cf165004fa02cb6a039358cc019130e201c901fb000201200b0c0081d40106b90f6a2687d007d207d206a1802698f90c1080bc6a28cdd0141083deecbef5d0958f97064699f98fd001809d02811e428027d012c678b00e78b6664f6aa401f1503d33ffa00fa4021f001ed44d0fa00fa40fa40d4305136a1522ac705f2e2c128c2fff2e2c254344270542013541403c85004fa0258cf1601cf16ccc922c8cb0112f400f400cb00c920f9007074c8cb02ca07cbffc9d004fa40f40431fa0020d749c200f2e2c4778018c8cb055008cf1670fa0217cb6b13cc80d0201200e0f009e8210178d4519c8cb1f19cb3f5007fa0222cf165006cf1625fa025003cf16c95005cc2391729171e25008a813a0820a625a00a014bcf2e2c504c98040fb001023c85004fa0258cf1601cf16ccc9ed5402f73b51343e803e903e90350c0234cffe80145468017e903e9014d6f1c1551cdb5c150804d50500f214013e809633c58073c5b33248b232c044bd003d0032c0327e401c1d3232c0b281f2fff274140371c1472c7cb8b0c2be80146a2860822625a019ad8228608239387028062849e5c412440e0dd7c138c34975c2c060101100c90c3b51343e803e903e90350c01b4cffe800c145128548df1c17cb8b04970bffcb8b0812082e4e1c02fbcb8b160841ef765f7b232c7c532cfd63e808873c5b25c60063232c14933c59c3e80b2dab33260103ec01004f214013e809633c58073c5b3327b552000705279a018a182107362d09cc8cb1f5230cb3f58fa025007cf165007cf16c9718010c8cb0524cf165006fa0215cb6a14ccc971fb0010241023007cc30023c200b08e218210d53276db708010c8cb055008cf165004fa0216cb6a12cb1f12cb3fc972fb0093356c21e203c85004fa0258cf1601cf16ccc9ed54', 'hex'))[0],
63
- tsTON_MAINNET: core_1.Cell.fromBoc(Buffer.from('b5ee9c720101010100230000420212bebb0dc8e202b7e26f721e2547e16bb9ebaec934f657d19f22e76d62bec878', 'hex'))[0],
64
- tsTON_TESTNET: null,
65
- USDT_MAINNET: core_1.Cell.fromBoc(Buffer.from('b5ee9c72010101010023000042028f452d7a4dfd74066b682365177259ed05734435be76b5fd4bd5d8af2b7c3d68', 'hex'))[0],
66
- USDT_TESTNET: null,
67
- };
68
- exports.OPCODES = {
69
- SUPPLY: 0x1,
70
- WITHDRAW: 0x2,
71
- LIQUIDATE: 0x3,
72
- JETTON_TRANSFER: 0xf8a7ea5,
73
- ONCHAIN_GETTER: 0x9998,
74
- };
75
- exports.FEES = {
76
- SUPPLY: (0, core_1.toNano)('0.3'),
77
- WITHDRAW: (0, core_1.toNano)('0.5'),
78
- SUPPLY_JETTON: (0, core_1.toNano)('0.8'),
79
- SUPPLY_JETTON_FWD: (0, core_1.toNano)('0.5'),
80
- LIQUIDATION: (0, core_1.toNano)('0.8'),
81
- LIQUIDATION_JETTON: (0, core_1.toNano)('1'),
82
- LIQUIDATION_JETTON_FWD: (0, core_1.toNano)('0.8'),
83
- };
@@ -1,14 +0,0 @@
1
- /// <reference types="node" />
2
- import { Cell, Dictionary } from '@ton/core';
3
- export type RawPriceData = {
4
- dict: Dictionary<bigint, bigint>;
5
- dataCell: Cell;
6
- oracleId: number;
7
- signature: Buffer;
8
- pubkey: Buffer;
9
- timestamp: number;
10
- };
11
- export type PriceData = {
12
- dict: Dictionary<bigint, bigint>;
13
- dataCell: Cell;
14
- };
@@ -1,55 +0,0 @@
1
- /// <reference types="node" />
2
- import { Cell, Dictionary, Slice } from "@ton/core";
3
- import { PriceData, RawPriceData } from "../types/Common";
4
- import { Oracle, PoolAssetsConfig } from "../types/Master";
5
- type OutputData = {
6
- metadata: {
7
- blockId: string;
8
- transactionId: string;
9
- outputIndex: number;
10
- isSpent: boolean;
11
- milestoneIndexSpent: number;
12
- milestoneTimestampSpent: number;
13
- transactionIdSpent: string;
14
- milestoneIndexBooked: number;
15
- milestoneTimestampBooked: number;
16
- ledgerIndex: number;
17
- };
18
- output: {
19
- type: number;
20
- amount: string;
21
- nftId: string;
22
- unlockConditions: {
23
- type: number;
24
- address: {
25
- type: number;
26
- pubKeyHash: string;
27
- };
28
- }[];
29
- features: {
30
- type: number;
31
- data: string;
32
- }[];
33
- };
34
- };
35
- export type OraclePricesData = {
36
- timestamp: number;
37
- prices: Dictionary<bigint, bigint>;
38
- };
39
- export declare function loadPrices(oracleNftId: String, endpoints: String[]): Promise<OutputData>;
40
- export declare function parsePrices(outputData: OutputData, oracleId: number): Promise<RawPriceData>;
41
- export declare function verifyPrices(assets: PoolAssetsConfig): (priceData: RawPriceData) => boolean;
42
- export declare function getMedianPrice(pricesData: PriceData[], asset: bigint): bigint;
43
- export declare function packAssetsData(assetsData: {
44
- assetId: bigint;
45
- medianPrice: bigint;
46
- }[]): Cell;
47
- export declare function packPrices(assetsDataCell: Cell, oraclesDataCell: Cell): Cell;
48
- export declare function createOracleDataProof(oracle: Oracle, data: OraclePricesData, signature: Buffer, assets: Array<bigint>): Slice;
49
- export declare function packOraclesData(oraclesData: {
50
- oracle: Oracle;
51
- data: OraclePricesData;
52
- signature: Buffer;
53
- }[], assets: Array<bigint>): Cell;
54
- export declare function sumDicts(result: Dictionary<bigint, bigint>, addendum: Dictionary<bigint, bigint>): void;
55
- export {};
@@ -1,117 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sumDicts = exports.packOraclesData = exports.createOracleDataProof = exports.packPrices = exports.packAssetsData = exports.getMedianPrice = exports.verifyPrices = exports.parsePrices = exports.loadPrices = void 0;
4
- const core_1 = require("@ton/core");
5
- const config_1 = require("../config");
6
- const merkleProof_1 = require("./merkleProof");
7
- async function loadPrices(oracleNftId, endpoints) {
8
- return await Promise.any(endpoints.map(x => loadOracleData(oracleNftId, x)));
9
- }
10
- exports.loadPrices = loadPrices;
11
- async function loadOracleData(oracleNftId, endpoint) {
12
- let result = await fetch(`https://${endpoint}/api/indexer/v1/outputs/nft/${oracleNftId}`, {
13
- headers: { accept: 'application/json' },
14
- signal: AbortSignal.timeout(5000)
15
- });
16
- let outputId = (await result.json());
17
- result = await fetch(`https://${endpoint}/api/core/v2/outputs/${outputId.items[0]}`, {
18
- headers: { accept: 'application/json' },
19
- signal: AbortSignal.timeout(5000)
20
- });
21
- return await result.json();
22
- }
23
- async function parsePrices(outputData, oracleId) {
24
- const data = JSON.parse(decodeURIComponent(outputData.output.features[0].data.replace('0x', '').replace(/[0-9a-f]{2}/g, '%$&')));
25
- try {
26
- const pricesCell = core_1.Cell.fromBoc(Buffer.from(data['packedPrices'], 'hex'))[0];
27
- const signature = Buffer.from(data['signature'], 'hex');
28
- const publicKey = Buffer.from(data['publicKey'], 'hex');
29
- const timestamp = Number(data['timestamp']);
30
- return {
31
- dict: pricesCell.beginParse().loadRef().beginParse().loadDictDirect(core_1.Dictionary.Keys.BigUint(256), core_1.Dictionary.Values.BigVarUint(4)),
32
- dataCell: (0, core_1.beginCell)().storeRef(pricesCell).storeBuffer(signature).endCell(),
33
- oracleId: oracleId,
34
- signature: signature,
35
- pubkey: publicKey,
36
- timestamp: timestamp,
37
- };
38
- }
39
- catch (error) {
40
- console.log(oracleId, data, error);
41
- throw Error();
42
- }
43
- }
44
- exports.parsePrices = parsePrices;
45
- function verifyPrices(assets) {
46
- return function (priceData) {
47
- const timestamp = Date.now() / 1000;
48
- const pricesTime = priceData.timestamp;
49
- for (const asset of assets) {
50
- if (!priceData.dict.has(asset.assetId)) {
51
- return false;
52
- }
53
- }
54
- // console.log('timestamp', timestamp, 'pricestime', pricesTime, timestamp - pricesTime);
55
- return timestamp - pricesTime < config_1.TTL_ORACLE_DATA_SEC;
56
- };
57
- }
58
- exports.verifyPrices = verifyPrices;
59
- function getMedianPrice(pricesData, asset) {
60
- const sorted = pricesData.map(x => x.dict.get(asset)).sort((a, b) => Number(a) - Number(b));
61
- const mid = Math.floor(sorted.length / 2);
62
- if (sorted.length % 2 === 0) {
63
- return (sorted[mid - 1] + sorted[mid]) / 2n;
64
- }
65
- else {
66
- return sorted[mid];
67
- }
68
- }
69
- exports.getMedianPrice = getMedianPrice;
70
- function packAssetsData(assetsData) {
71
- if (assetsData.length == 0) {
72
- throw new Error("No assets data to pack");
73
- }
74
- return assetsData.reduceRight((acc, { assetId, medianPrice }) => (0, core_1.beginCell)()
75
- .storeUint(assetId, 256)
76
- .storeCoins(medianPrice)
77
- .storeMaybeRef(acc)
78
- .endCell(), null);
79
- }
80
- exports.packAssetsData = packAssetsData;
81
- function packPrices(assetsDataCell, oraclesDataCell) {
82
- let pricesCell = (0, core_1.beginCell)()
83
- .storeRef(assetsDataCell)
84
- .storeRef(oraclesDataCell)
85
- .endCell();
86
- return pricesCell;
87
- }
88
- exports.packPrices = packPrices;
89
- function createOracleDataProof(oracle, data, signature, assets) {
90
- let prunedDict = (0, merkleProof_1.generateMerkleProofDirect)(data.prices, assets, core_1.Dictionary.Keys.BigUint(256));
91
- let prunedData = (0, core_1.beginCell)().storeUint(data.timestamp, 32).storeMaybeRef(prunedDict).endCell();
92
- let merkleProof = (0, merkleProof_1.convertToMerkleProof)(prunedData);
93
- let oracleDataProof = (0, core_1.beginCell)().storeUint(oracle.id, 32).storeRef(merkleProof).storeBuffer(signature).asSlice();
94
- return oracleDataProof;
95
- }
96
- exports.createOracleDataProof = createOracleDataProof;
97
- function packOraclesData(oraclesData, assets) {
98
- if (oraclesData.length == 0) {
99
- throw new Error("no oracles data to pack");
100
- }
101
- let proofs = oraclesData.sort((d1, d2) => d1.oracle.id - d2.oracle.id).map(({ oracle, data, signature }) => createOracleDataProof(oracle, data, signature, assets));
102
- return proofs.reduceRight((acc, val) => (0, core_1.beginCell)().storeSlice(val).storeMaybeRef(acc).endCell(), null);
103
- }
104
- exports.packOraclesData = packOraclesData;
105
- // : String = "api.stardust-mainnet.iotaledger.net"
106
- function sumDicts(result, addendum) {
107
- for (const key of addendum.keys()) {
108
- const current = result.get(key);
109
- const value = addendum.get(key);
110
- if (current === undefined) {
111
- result.set(key, value);
112
- continue;
113
- }
114
- result.set(key, current + value);
115
- }
116
- }
117
- exports.sumDicts = sumDicts;
File without changes