@evaafi/sdk 0.6.2 → 0.6.3-b

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 (61) hide show
  1. package/CHANGELOG.md +57 -17
  2. package/README.md +2 -1
  3. package/dist/api/math.d.ts +12 -2
  4. package/dist/api/math.js +56 -4
  5. package/dist/api/parser.js +48 -20
  6. package/dist/constants/assets.d.ts +9 -1
  7. package/dist/constants/assets.js +38 -9
  8. package/dist/constants/general.d.ts +18 -0
  9. package/dist/constants/general.js +20 -2
  10. package/dist/constants/pools.d.ts +7 -1
  11. package/dist/constants/pools.js +60 -26
  12. package/dist/index.d.ts +10 -3
  13. package/dist/index.js +26 -2
  14. package/dist/prices/PricesCollector.d.ts +2 -2
  15. package/dist/prices/PricesCollector.js +8 -6
  16. package/dist/prices/utils.js +1 -1
  17. package/dist/rewards/EvaaRewards.d.ts +10 -0
  18. package/dist/rewards/EvaaRewards.js +21 -0
  19. package/dist/rewards/JettonMinter.d.ts +30 -0
  20. package/dist/rewards/JettonMinter.js +83 -0
  21. package/dist/rewards/JettonWallet.d.ts +23 -0
  22. package/dist/rewards/JettonWallet.js +60 -0
  23. package/dist/rewards/RewardMaster.d.ts +26 -0
  24. package/dist/rewards/RewardMaster.js +83 -0
  25. package/dist/rewards/RewardUser.d.ts +23 -0
  26. package/dist/rewards/RewardUser.js +70 -0
  27. package/dist/types/MasterRewards.d.ts +13 -0
  28. package/dist/types/User.d.ts +11 -1
  29. package/dist/types/UserRewards.d.ts +10 -0
  30. package/dist/types/UserRewards.js +2 -0
  31. package/dist/utils/sha256BigInt.d.ts +2 -0
  32. package/dist/utils/sha256BigInt.js +9 -1
  33. package/dist/utils/userJettonWallet.js +17 -0
  34. package/package.json +42 -42
  35. package/src/api/math.ts +78 -3
  36. package/src/api/parser.ts +57 -22
  37. package/src/constants/assets.ts +117 -65
  38. package/src/constants/general.ts +33 -2
  39. package/src/constants/pools.ts +110 -28
  40. package/src/index.ts +24 -2
  41. package/src/prices/PricesCollector.ts +10 -6
  42. package/src/prices/utils.ts +1 -1
  43. package/src/rewards/EvaaRewards.ts +23 -0
  44. package/src/rewards/JettonMinter.ts +113 -0
  45. package/src/rewards/JettonWallet.ts +77 -0
  46. package/src/rewards/RewardMaster.ts +110 -0
  47. package/src/rewards/RewardUser.ts +90 -0
  48. package/src/types/Master.ts +1 -1
  49. package/src/types/MasterRewards.ts +13 -0
  50. package/src/types/User.ts +13 -3
  51. package/src/types/UserRewards.ts +10 -0
  52. package/src/utils/sha256BigInt.ts +8 -0
  53. package/src/utils/userJettonWallet.ts +43 -27
  54. package/dist/config.d.ts +0 -1
  55. package/dist/config.js +0 -4
  56. package/dist/constants.d.ts +0 -69
  57. package/dist/constants.js +0 -83
  58. package/dist/types/Common.d.ts +0 -14
  59. package/dist/utils/priceUtils.d.ts +0 -55
  60. package/dist/utils/priceUtils.js +0 -117
  61. /package/dist/types/{Common.js → MasterRewards.js} +0 -0
@@ -1,7 +1,6 @@
1
1
  import { Address, Cell, toNano } from '@ton/core';
2
2
  import { OracleNFT } from '../types/Master';
3
3
 
4
-
5
4
  const ASSET_PRICE_SCALE = BigInt(1e9);
6
5
 
7
6
  export const MASTER_CONSTANTS = {
@@ -22,13 +21,20 @@ export const NULL_ADDRESS = Address.parse('UQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
22
21
 
23
22
  export const EVAA_MASTER_MAINNET = Address.parse('EQC8rUZqR_pWV1BylWUlPNBzyiTYVoBEmQkMIQDZXICfnuRr');
24
23
  export const MAINNET_VERSION = 6;
25
- export const EVAA_MASTER_TESTNET = Address.parse('EQDLsg3w-iBj26Gww7neYoJAxiT2t77Zo8ro56b0yuHsPp3C');
24
+ export const EVAA_MASTER_TESTNET = Address.parse('kQBae_Pt-NcxX0yhNnsYyK-Kh6ZBnIUQhxheKTvNLTgZf7AV');
26
25
  export const TESTNET_VERSION = 0;
27
26
  export const EVAA_LP_MAINNET = Address.parse('EQBIlZX2URWkXCSg3QF2MJZU-wC5XkBoLww-hdWk2G37Jc6N');
28
27
  export const EVAA_LP_MAINNET_VERSION = 3;
29
28
  export const EVAA_ALTS_MAINNET = Address.parse('EQANURVS3fhBO9bivig34iyJQi97FhMbpivo1aUEAS2GYSu-');
30
29
  export const EVAA_ALTS_MAINNET_VERSION = 0;
31
30
 
31
+ export const EVAA_ETHENA_MAINNET = Address.parse('EQCn95X_qLJa5VUXfyIQkWDH2iq3PTatsO4esunMaIsnyyeW');
32
+ export const EVAA_ETHENA_VERSION = 0;
33
+
34
+ export const EVAA_REWARDS_MASTER_TESTNET = Address.parse('EQCnp0iRGcfDJAvnKhAEN9sB-nPYSPuc83Ff4y75s8AtoSW1');
35
+ export const EVAA_USDT_REWARDS_MASTER_MAINNET = Address.parse('EQD22Fhylp1tX-xoVX81aMTSJNPV8j9klwApTLgjGmofISVD');
36
+ export const EVAA_TON_REWARDS_MASTER_MAINNET = Address.parse('EQDM_gdrntBg4fy5Rg9DgDF0AUu3FYoqxHEOsHNIC4_DTDuC');
37
+
32
38
  export const ORACLES_MAINNET: OracleNFT[] = [
33
39
  {id: 0, address: '0xd3a8c0b9fd44fd25a49289c631e3ac45689281f2f8cf0744400b4c65bed38e5d', pubkey: Buffer.from('b404f4a2ebb62f2623b370c89189748a0276c071965b1646b996407f10d72eb9', 'hex') },
34
40
  {id: 1, address: '0x2c21cabdaa89739de16bde7bc44e86401fac334a3c7e55305fe5e7563043e191', pubkey: Buffer.from('9ad115087520d91b6b45d6a8521eb4616ee6914af07fabdc2e9d1826dbb17078', 'hex') },
@@ -54,12 +60,32 @@ export const JETTON_WALLET_STANDART_CODE = Cell.fromBase64(
54
60
  export const JETTON_WALLET_STANDART_CODE_TESTNET = Cell.fromBase64(
55
61
  'te6cckECEQEAAyMAART/APSkE/S88sgLAQIBYgIDAgLMBAUAG6D2BdqJofQB9IH0gahhAgHUBgcCASAICQDDCDHAJJfBOAB0NMDAXGwlRNfA/AM4PpA+kAx+gAxcdch+gAx+gAwc6m0AALTH4IQD4p+pVIgupUxNFnwCeCCEBeNRRlSILqWMUREA/AK4DWCEFlfB7y6k1nwC+BfBIQP8vCAAET6RDBwuvLhTYAIBIAoLAIPUAQa5D2omh9AH0gfSBqGAJpj8EIC8aijKkQXUEIPe7L7wndCVj5cWLpn5j9ABgJ0CgR5CgCfQEsZ4sA54tmZPaqQB8VA9M/+gD6QCHwAe1E0PoA+kD6QNQwUTahUirHBfLiwSjC//LiwlQ0QnBUIBNUFAPIUAT6AljPFgHPFszJIsjLARL0APQAywDJIPkAcHTIywLKB8v/ydAE+kD0BDH6ACDXScIA8uLEd4AYyMsFUAjPFnD6AhfLaxPMgMAgEgDQ4AnoIQF41FGcjLHxnLP1AH+gIizxZQBs8WJfoCUAPPFslQBcwjkXKRceJQCKgToIIJycOAoBS88uLFBMmAQPsAECPIUAT6AljPFgHPFszJ7VQC9ztRND6APpA+kDUMAjTP/oAUVGgBfpA+kBTW8cFVHNtcFQgE1QUA8hQBPoCWM8WAc8WzMkiyMsBEvQA9ADLAMn5AHB0yMsCygfL/8nQUA3HBRyx8uLDCvoAUaihggiYloBmtgihggiYloCgGKEnlxBJEDg3XwTjDSXXCwGAPEADXO1E0PoA+kD6QNQwB9M/+gD6QDBRUaFSSccF8uLBJ8L/8uLCBYIJMS0AoBa88uLDghB73ZfeyMsfFcs/UAP6AiLPFgHPFslxgBjIywUkzxZw+gLLaszJgED7AEATyFAE+gJYzxYBzxbMye1UgAHBSeaAYoYIQc2LQnMjLH1Iwyz9Y+gJQB88WUAfPFslxgBDIywUkzxZQBvoCFctqFMzJcfsAECQQIwB8wwAjwgCwjiGCENUydttwgBDIywVQCM8WUAT6AhbLahLLHxLLP8ly+wCTNWwh4gPIUAT6AljPFgHPFszJ7VSV6u3X');
56
62
 
63
+ export const EVAA_REWARDS_MASTER_CODE_TESTNET = Cell.fromBoc(
64
+ Buffer.from(
65
+ 'b5ee9c7241020e01000386000114ff00f4a413f4bcf2c80b01020162020b046ad03322c700925f03e0d0d3030171b0925f03e0fa403002d31fd33f715230bae302725230bae30282107362d09c5230bae3027413ba0304070800c46c21ed44d0fa40fa00fa40d4d401d001d1fa40d3ffd3ffd11034102307fa40308103e8820afaf0801abe19f2f48103ea5196c70519f2f48103ee8b0212c705f2f41036453304c85004cf16cbff12cbffc9c85005cf165003fa0258cf16ccccc9ed5402fe6c22ed44d0fa40fa00fa40d4d401d001d1fa40d3ffd3ffd11034102307fa40fa003021ed44d0fa40fa00fa40d4d401d001d1fa40d3ffd3ffd11034102335355bc8f828cf1613cbffcbffc9c85003cf1670fa0212ccc97020c8cb0113f400f400cb00c9f9007074c8cb02ca07cbffc9d08103ea51c1c7051cf2f45306bce302050600466c810173c8cb1fcb3f01fa02c9718018c8cb055003cf1670fa0212cb6accc98040fb0001d23a8b3544f4e8f9025220ba8e16385288708018c8cb0558cf1658fa02cb6ac98040fb008e3b22544a030a702082100f8a7ea5c8cb1f13cb3f5004fa0222cf1658cf16cb0021fa02cb1fc9718018c8cb055003cf1670fa0212cb6accc98040fb00e25037a110365e40010a00ec6c21ed44d0fa40fa00fa40d4d401d001d1fa40d3ffd3ffd1103410238103e8820afaf08052a0bef2f48b3544f4e8f9025220ba993738068209c9c380a18e11388103ea5192c70519f2f405fa00301056e213a010364515503304c85004cf16cbff12cbffc9c85005cf165003fa0258cf16ccccc9ed5402ea8f6ced44d0fa40fa00fa40d4d401d001d1fa40d3ffd3ffd11034102308fa40fa00308103e8821005f5e1001cbe1bf2f48103ea51b7c7051bf2f48103ed5395bbf2f48b3544f4e8f9025210ba8e16365279708018c8cb0558cf1658fa02cb6ac98040fb00e30e5026a14615503304e05f04840ff2f0090a00745468281b702082100f8a7ea5c8cb1f13cb3f5004fa0222cf1658cf16cb0021fa02cb1fc9718018c8cb055003cf1670fa0212cb6accc98040fb000038c85004cf16cbff12cbffc9c85005cf165003fa0258cf16ccccc9ed540201580c0d0039bbc24ed44d0fa40fa00fa40d4d401d001d1fa40d3ffd3ffd1103410238009fb87b6ed44d0fa40fa00fa40d4d401d001d1fa40d3ffd3ffd11034102335355bc8f828cf1613cbffcbffc9c85003cf1670fa0212ccc97020c8cb0113f400f400cb00c9f9007074c8cb02ca07cbffc9d0872ac1c8c',
66
+ 'hex',
67
+ ),
68
+ )[0];
69
+ export const EVAA_REWARDS_MASTER_CODE_MAINNET = EVAA_REWARDS_MASTER_CODE_TESTNET;
70
+
71
+ export const EVAA_REWARDS_USER_CODE_TESTNET = Cell.fromBoc(
72
+ Buffer.from(
73
+ 'b5ee9c724102060100014e000114ff00f4a413f4bcf2c80b01020162020502f8d03322c700925f03e0d0d3030171b0925f03e0fa403002d31fd33f725230ba8ed63233ed44d0fa40fa00d401d001d1fa40d3ffd3ffd1058308d718d430d08103e8821005f5e10019be18f2f48103e927f901541027f910f2f405fa40fa00308103eaf82813c70512f2f48103ec5313bcf2f45203a15006e0313273ba030400b8ed44d0fa40fa00d401d001d1fa40d3ffd3ffd110235f0372c8cb1f13cb3f01cf1658fa02c9718018c8cb055003cf1670fa0212cb6accc9820a625a0070fb02810080fb005521c85003cf16cbffcbffc9c85003cf1601fa02ccc9ed5400888e3ced44d0fa40fa00d401d001d1fa40d3ffd3ffd105fa00308103ea5173c70517f2f45025a14143c85003cf16cbffcbffc9c85003cf1601fa02ccc9ed54e05b840ff2f0002ba17849da89a1f481f401a803a003a3f481a7ffa7ffa333f41908',
74
+ 'hex',
75
+ ),
76
+ )[0];
77
+ export const EVAA_REWARDS_USER_CODE_MAINNET = EVAA_REWARDS_USER_CODE_TESTNET;
78
+
57
79
  export const OPCODES = {
58
80
  SUPPLY: 0x1,
59
81
  WITHDRAW: 0x2,
60
82
  LIQUIDATE: 0x3,
61
83
  JETTON_TRANSFER: 0xf8a7ea5,
62
84
  ONCHAIN_GETTER: 0x9998,
85
+ REWARD_CLAIM: 0x2,
86
+ REWARD_TON_TOP_UP: 0x7362d09c,
87
+ REWARD_JETTON_MINT: 0x178d4519,
88
+ REWARD_JETTON_TRANSFER: 0x0f8a7ea5,
63
89
  };
64
90
 
65
91
  export const FEES = {
@@ -70,4 +96,9 @@ export const FEES = {
70
96
  LIQUIDATION: toNano('0.8'),
71
97
  LIQUIDATION_JETTON: toNano('1'),
72
98
  LIQUIDATION_JETTON_FWD: toNano('0.8'),
99
+ REWARD_MASTER_TON_TOP_UP: toNano('0.03'),
100
+ REWARD_MASTER_DEPLOY: toNano('0.05'),
101
+ REWARD_MASTER_WITHDRAW: toNano('0.1'),
102
+ REWARD_USER_DEPLOY: toNano('0.05'),
103
+ REWARD_USER_CLAIM: toNano('0.1'),
73
104
  };
@@ -1,6 +1,50 @@
1
- import { CATI_MAINNET, DOGS_MAINNET, JUSDC_MAINNET, JUSDC_TESTNET, JUSDT_MAINNET, JUSDT_TESTNET, NOT_MAINNET, STTON_MAINNET, STTON_TESTNET, TON_MAINNET, TON_STORM_MAINNET, TONUSDT_DEDUST_MAINNET, TSTON_MAINNET, USDT_MAINNET, USDT_STORM_MAINNET, UTON_MAINNET } from "./assets";
2
- import { PoolConfig } from "../types/Master";
3
- import { EVAA_MASTER_MAINNET, EVAA_MASTER_TESTNET, LENDING_CODE, MAINNET_VERSION, MASTER_CONSTANTS, TESTNET_VERSION, EVAA_LP_MAINNET, EVAA_LP_MAINNET_VERSION, ORACLES_MAINNET, ORACLES_LP, ORACLES_TESTNET, EVAA_ALTS_MAINNET, EVAA_ALTS_MAINNET_VERSION, ORACLES_ALTS } from "./general";
1
+ import { Address } from '@ton/core';
2
+ import { PoolConfig } from '../types/Master';
3
+ import { EvaaRewardsConfig } from '../types/MasterRewards';
4
+ import {
5
+ CATI_MAINNET,
6
+ DOGS_MAINNET,
7
+ EUSDT_TESTNET,
8
+ JUSDC_MAINNET,
9
+ JUSDT_MAINNET,
10
+ NOT_MAINNET,
11
+ STTON_MAINNET,
12
+ TGBTC_TESTNET,
13
+ TON_MAINNET,
14
+ TON_STORM_MAINNET,
15
+ TON_TESTNET,
16
+ TONUSDT_DEDUST_MAINNET,
17
+ TSTON_MAINNET,
18
+ TSUSDE_MAINNET,
19
+ USDE_MAINNET,
20
+ USDT_MAINNET,
21
+ USDT_STORM_MAINNET,
22
+ } from './assets';
23
+ import {
24
+ EVAA_ALTS_MAINNET,
25
+ EVAA_ALTS_MAINNET_VERSION,
26
+ EVAA_ETHENA_MAINNET,
27
+ EVAA_ETHENA_VERSION,
28
+ EVAA_LP_MAINNET,
29
+ EVAA_LP_MAINNET_VERSION,
30
+ EVAA_MASTER_MAINNET,
31
+ EVAA_MASTER_TESTNET,
32
+ EVAA_REWARDS_MASTER_CODE_MAINNET,
33
+ EVAA_REWARDS_MASTER_CODE_TESTNET,
34
+ EVAA_REWARDS_MASTER_TESTNET,
35
+ EVAA_REWARDS_USER_CODE_MAINNET,
36
+ EVAA_REWARDS_USER_CODE_TESTNET,
37
+ EVAA_TON_REWARDS_MASTER_MAINNET,
38
+ EVAA_USDT_REWARDS_MASTER_MAINNET,
39
+ LENDING_CODE,
40
+ MAINNET_VERSION,
41
+ MASTER_CONSTANTS,
42
+ ORACLES_ALTS,
43
+ ORACLES_LP,
44
+ ORACLES_MAINNET,
45
+ ORACLES_TESTNET,
46
+ TESTNET_VERSION,
47
+ } from './general';
4
48
 
5
49
  export const MAINNET_POOL_CONFIG: PoolConfig = {
6
50
  masterAddress: EVAA_MASTER_MAINNET,
@@ -15,9 +59,24 @@ export const MAINNET_POOL_CONFIG: PoolConfig = {
15
59
  STTON_MAINNET,
16
60
  TSTON_MAINNET,
17
61
  USDT_MAINNET,
18
- UTON_MAINNET // announce
62
+ USDE_MAINNET,
63
+ TSUSDE_MAINNET,
64
+ // UTON_MAINNET // announce xdddd fake announce
19
65
  ],
20
- lendingCode: LENDING_CODE
66
+ lendingCode: LENDING_CODE,
67
+ };
68
+
69
+ export const MAINNET_TEST_ETHENA_POOL_CONFIG: PoolConfig = {
70
+ masterAddress: EVAA_ETHENA_MAINNET,
71
+ masterVersion: EVAA_ETHENA_VERSION,
72
+ masterConstants: MASTER_CONSTANTS,
73
+ oracles: ORACLES_MAINNET,
74
+ minimalOracles: 3,
75
+ poolAssetsConfig: [
76
+ TON_MAINNET,
77
+ USDE_MAINNET,
78
+ ],
79
+ lendingCode: LENDING_CODE,
21
80
  };
22
81
 
23
82
  export const TESTNET_POOL_CONFIG: PoolConfig = {
@@ -26,13 +85,8 @@ export const TESTNET_POOL_CONFIG: PoolConfig = {
26
85
  masterConstants: MASTER_CONSTANTS,
27
86
  oracles: ORACLES_TESTNET,
28
87
  minimalOracles: 3,
29
- poolAssetsConfig: [
30
- TON_MAINNET,
31
- JUSDT_TESTNET,
32
- JUSDC_TESTNET,
33
- STTON_TESTNET
34
- ],
35
- lendingCode: LENDING_CODE
88
+ poolAssetsConfig: [TON_TESTNET, TGBTC_TESTNET],
89
+ lendingCode: LENDING_CODE,
36
90
  };
37
91
 
38
92
  export const MAINNET_LP_POOL_CONFIG: PoolConfig = {
@@ -41,14 +95,8 @@ export const MAINNET_LP_POOL_CONFIG: PoolConfig = {
41
95
  masterConstants: MASTER_CONSTANTS,
42
96
  oracles: ORACLES_LP,
43
97
  minimalOracles: 3,
44
- poolAssetsConfig: [
45
- TON_MAINNET,
46
- USDT_MAINNET,
47
- TONUSDT_DEDUST_MAINNET,
48
- TON_STORM_MAINNET,
49
- USDT_STORM_MAINNET
50
- ],
51
- lendingCode: LENDING_CODE
98
+ poolAssetsConfig: [TON_MAINNET, USDT_MAINNET, TONUSDT_DEDUST_MAINNET, TON_STORM_MAINNET, USDT_STORM_MAINNET],
99
+ lendingCode: LENDING_CODE,
52
100
  };
53
101
 
54
102
  export const MAINNET_ALTS_POOL_CONFIG: PoolConfig = {
@@ -57,12 +105,46 @@ export const MAINNET_ALTS_POOL_CONFIG: PoolConfig = {
57
105
  masterConstants: MASTER_CONSTANTS,
58
106
  oracles: ORACLES_ALTS,
59
107
  minimalOracles: 3,
60
- poolAssetsConfig: [
61
- TON_MAINNET,
62
- USDT_MAINNET,
63
- CATI_MAINNET,
64
- NOT_MAINNET,
65
- DOGS_MAINNET
66
- ],
67
- lendingCode: LENDING_CODE
108
+ poolAssetsConfig: [TON_MAINNET, USDT_MAINNET, CATI_MAINNET, NOT_MAINNET, DOGS_MAINNET],
109
+ lendingCode: LENDING_CODE,
110
+ };
111
+
112
+ export const TESTNET_MASTER_REWARD_CONFIG: EvaaRewardsConfig = {
113
+ adminAddress: EVAA_REWARDS_MASTER_TESTNET,
114
+ evaaMasterAddress: new Address(0, Buffer.alloc(32, 0)),
115
+ rewardMasterCode: EVAA_REWARDS_MASTER_CODE_TESTNET,
116
+ rewardUserCode: EVAA_REWARDS_USER_CODE_TESTNET,
117
+ asset: TON_TESTNET,
118
+ availableReward: 0,
119
+ publicKey: Buffer.from('c38be45e033419b49cd22c97fbd23610fbc851a931208f8b4a1817dd11cb63ac', 'hex'), // adminAddress publicKey
120
+ };
121
+
122
+ export const TESTNET_MASTER_EUSDT_REWARD_CONFIG: EvaaRewardsConfig = {
123
+ adminAddress: EVAA_REWARDS_MASTER_TESTNET,
124
+ evaaMasterAddress: new Address(0, Buffer.alloc(32, 0)),
125
+ rewardMasterCode: EVAA_REWARDS_MASTER_CODE_TESTNET,
126
+ rewardUserCode: EVAA_REWARDS_USER_CODE_TESTNET,
127
+ asset: EUSDT_TESTNET,
128
+ availableReward: 0,
129
+ publicKey: Buffer.from('c38be45e033419b49cd22c97fbd23610fbc851a931208f8b4a1817dd11cb63ac', 'hex'), // adminAddress publicKey
130
+ };
131
+
132
+ export const MAINNET_MASTER_TON_REWARD_CONFIG: EvaaRewardsConfig = {
133
+ adminAddress: EVAA_TON_REWARDS_MASTER_MAINNET,
134
+ evaaMasterAddress: new Address(0, Buffer.alloc(32, 0)),
135
+ rewardMasterCode: EVAA_REWARDS_MASTER_CODE_MAINNET,
136
+ rewardUserCode: EVAA_REWARDS_USER_CODE_MAINNET,
137
+ asset: TON_MAINNET,
138
+ availableReward: 0,
139
+ publicKey: Buffer.from('bfe9a30221db4dff4c17e55d985e0b13a8f597bbb28002f311dc4429dad1ca95', 'hex'), // adminAddress publicKey
140
+ };
141
+
142
+ export const MAINNET_MASTER_USDT_REWARD_CONFIG: EvaaRewardsConfig = {
143
+ adminAddress: EVAA_USDT_REWARDS_MASTER_MAINNET,
144
+ evaaMasterAddress: new Address(0, Buffer.alloc(32, 0)),
145
+ rewardMasterCode: EVAA_REWARDS_MASTER_CODE_MAINNET,
146
+ rewardUserCode: EVAA_REWARDS_USER_CODE_MAINNET,
147
+ asset: USDT_MAINNET,
148
+ availableReward: 0,
149
+ publicKey: Buffer.from('9813725d6cead1c9bbc0e24b21d4fc62a7fa8ac4bb01b6758df30169a71dba67', 'hex'), // adminAddress publicKey
68
150
  };
package/src/index.ts CHANGED
@@ -14,7 +14,10 @@ export {
14
14
  calculateLiquidationData,
15
15
  predictHealthFactor,
16
16
  calculateHealthParams,
17
+ calculateInterestWithSupplyBorrow,
18
+ predictAPY,
17
19
  BigMath,
20
+ getAssetLiquidityMinusReserves,
18
21
  } from './api/math';
19
22
 
20
23
  export {
@@ -55,6 +58,15 @@ export {
55
58
  } from './contracts/MasterContract';
56
59
  export { EvaaUser } from './contracts/UserContract';
57
60
 
61
+ // Rewards contracts wrappers
62
+ export { RewardMaster } from './rewards/RewardMaster';
63
+ export { type EvaaRewardsConfig } from './types/MasterRewards';
64
+ export { RewardUser } from './rewards/RewardUser';
65
+ 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
+
58
70
  // Types
59
71
  export {
60
72
  UpgradeConfig,
@@ -95,14 +107,24 @@ export {
95
107
  LENDING_CODE,
96
108
  OPCODES,
97
109
  FEES,
98
- MASTER_CONSTANTS
110
+ MASTER_CONSTANTS,
111
+ EVAA_REWARDS_MASTER_TESTNET,
112
+ EVAA_REWARDS_MASTER_CODE_TESTNET,
113
+ EVAA_REWARDS_USER_CODE_TESTNET,
114
+ EVAA_REWARDS_MASTER_CODE_MAINNET,
115
+ EVAA_REWARDS_USER_CODE_MAINNET,
99
116
  } from './constants/general';
100
117
 
101
118
  export {
102
119
  MAINNET_POOL_CONFIG,
103
120
  TESTNET_POOL_CONFIG,
104
121
  MAINNET_LP_POOL_CONFIG,
105
- MAINNET_ALTS_POOL_CONFIG
122
+ MAINNET_ALTS_POOL_CONFIG,
123
+ MAINNET_TEST_ETHENA_POOL_CONFIG,
124
+ // Reward Pools
125
+ TESTNET_MASTER_REWARD_CONFIG,
126
+ MAINNET_MASTER_TON_REWARD_CONFIG,
127
+ MAINNET_MASTER_USDT_REWARD_CONFIG,
106
128
  } from './constants/pools';
107
129
 
108
130
  export {
@@ -29,8 +29,8 @@ export class PricesCollector {
29
29
 
30
30
  // TODO Make UserData class and incapsulate raw bigintegers
31
31
 
32
- async getPricesForLiquidate(userPrincipals: Dictionary<bigint, bigint>, retries: number = 1, timeout: number = 3000): Promise<Prices> {
33
- const assets = userPrincipals.keys().map(x => this.#poolConfig.poolAssetsConfig.find(asset => asset.assetId == x));
32
+ async getPricesForLiquidate(realPrincipals: Dictionary<bigint, bigint>, retries: number = 1, timeout: number = 3000): Promise<Prices> {
33
+ const assets = this.#filterEmptyPrincipalsAndAssets(realPrincipals);
34
34
  if (assets.includes(undefined)) {
35
35
  throw new Error("User from another pool");
36
36
  }
@@ -38,9 +38,9 @@ export class PricesCollector {
38
38
  }
39
39
 
40
40
 
41
- async getPricesForWithdraw(userPrincipals: Dictionary<bigint, bigint>, withdrawAsset: PoolAssetConfig, collateralToDebt = false, retries: number = 1, timeout: number = 3000): Promise<Prices> {
42
- let assets = userPrincipals.keys().map(x => this.#poolConfig.poolAssetsConfig.find(asset => asset.assetId == x));
43
- if (checkNotInDebtAtAll(userPrincipals) && userPrincipals.has(withdrawAsset.assetId) && !collateralToDebt) {
41
+ async getPricesForWithdraw(realPrincipals: Dictionary<bigint, bigint>, withdrawAsset: PoolAssetConfig, collateralToDebt = false, retries: number = 1, timeout: number = 3000): Promise<Prices> {
42
+ let assets = this.#filterEmptyPrincipalsAndAssets(realPrincipals);
43
+ if (checkNotInDebtAtAll(realPrincipals) && (realPrincipals.get(withdrawAsset.assetId) ?? 0n) > 0n && !collateralToDebt) {
44
44
  return new Prices(Dictionary.empty<bigint, bigint>(), Cell.EMPTY);
45
45
  }
46
46
 
@@ -100,7 +100,7 @@ export class PricesCollector {
100
100
  }
101
101
 
102
102
  const medianData = assets.map(asset => ({ assetId: asset.assetId, medianPrice: getMedianPrice(this.#prices, asset.assetId)}));
103
-
103
+
104
104
  const nonEmptymedianData = medianData.filter(x => x.medianPrice != null) as { assetId: bigint, medianPrice: bigint }[];
105
105
 
106
106
  const packedMedianData = packAssetsData(nonEmptymedianData);
@@ -132,4 +132,8 @@ export class PricesCollector {
132
132
  this.#prices = this.#prices.filter(verifyPricesTimestamp());
133
133
  return this.#prices.length;
134
134
  }
135
+
136
+ #filterEmptyPrincipalsAndAssets(principals: Dictionary<bigint, bigint>) {
137
+ return principals.keys().filter(x => principals.get(x)! != 0n).map(x => this.#poolConfig.poolAssetsConfig.find(asset => asset.assetId == x));
138
+ }
135
139
  }
@@ -128,7 +128,7 @@ export async function collectAndFilterPrices(priceSource: PriceSource, poolConfi
128
128
  const prices = await priceSource.getPrices();
129
129
 
130
130
  //console.debug('[FILTERING] before filtering prices len ', priceSource.sourceName, prices.length);
131
- return await (async () => {
131
+ return (async () => {
132
132
  const acceptedPrices: RawPriceData[] = prices.filter(
133
133
  price => verifyPricesTimestamp()(price) && verifyPricesSign(poolConfig.oracles)(price)
134
134
  );
@@ -0,0 +1,23 @@
1
+ import { Address, Contract } from '@ton/ton';
2
+ import { EvaaRewardsConfig } from '../types/MasterRewards';
3
+ import { RewardUser } from './RewardUser';
4
+
5
+ export class EvaaUserRewards implements Contract {
6
+ readonly address: Address;
7
+ constructor(
8
+ readonly userAddress: Address,
9
+ readonly config: Omit<EvaaRewardsConfig, 'userAddress'>,
10
+ ) {
11
+ this.address = this.userAddress;
12
+ }
13
+
14
+ openContract() {
15
+ return RewardUser.createFromConfig({
16
+ asset: this.config.asset,
17
+ rewardMasterAddress: this.config.adminAddress,
18
+ rewardUserCode: this.config.rewardUserCode,
19
+ userAddress: this.userAddress,
20
+ publicKey: this.config.publicKey,
21
+ });
22
+ }
23
+ }
@@ -0,0 +1,113 @@
1
+ import { Address, beginCell, Cell, Contract, contractAddress, ContractProvider, Sender, SendMode } from '@ton/ton';
2
+ import { OPCODES } from '../constants/general';
3
+
4
+ export type JettonMinterConfig = {
5
+ address: Address;
6
+ content: Cell;
7
+ walletCode: Cell;
8
+ };
9
+
10
+ export type MintMessage = {
11
+ address: Address;
12
+ forwardValue: bigint;
13
+ amount: bigint;
14
+ };
15
+
16
+ export class JettonMinter implements Contract {
17
+ constructor(
18
+ readonly address: Address,
19
+ readonly init?: { code: Cell; data: Cell },
20
+ ) {}
21
+
22
+ static createFromAddress(address: Address) {
23
+ return new JettonMinter(address);
24
+ }
25
+
26
+ static jettonMinterConfigToCell(config: JettonMinterConfig): Cell {
27
+ return beginCell()
28
+ .storeCoins(0)
29
+ .storeAddress(config.address)
30
+ .storeRef(config.content)
31
+ .storeRef(config.walletCode)
32
+ .endCell();
33
+ }
34
+
35
+ static createFromConfig(config: JettonMinterConfig, code: Cell, workchain = 0) {
36
+ const data = this.jettonMinterConfigToCell(config);
37
+ const init = { code, data };
38
+ return new JettonMinter(contractAddress(workchain, init), init);
39
+ }
40
+
41
+ async sendDeploy(provider: ContractProvider, via: Sender, value: bigint) {
42
+ await provider.internal(via, {
43
+ value,
44
+ sendMode: SendMode.PAY_GAS_SEPARATELY,
45
+ body: beginCell().endCell(),
46
+ });
47
+ }
48
+
49
+ sendMintMessage(payload: MintMessage) {
50
+ return beginCell()
51
+ .storeUint(21, 32)
52
+ .storeUint(0, 64)
53
+ .storeAddress(payload.address)
54
+ .storeCoins(payload.forwardValue)
55
+ .storeRef(
56
+ beginCell()
57
+ .storeUint(OPCODES.REWARD_JETTON_MINT, 32)
58
+ .storeUint(0, 64)
59
+ .storeCoins(payload.amount)
60
+ .storeAddress(this.address)
61
+ .storeAddress(this.address)
62
+ .storeCoins(0)
63
+ .storeUint(0, 1)
64
+ .endCell(),
65
+ )
66
+ .endCell();
67
+ }
68
+
69
+ async sendMint(
70
+ provider: ContractProvider,
71
+ via: Sender,
72
+ value: bigint,
73
+ forwardValue: bigint,
74
+ recipient: Address,
75
+ amount: bigint,
76
+ ) {
77
+ await provider.internal(via, {
78
+ sendMode: SendMode.PAY_GAS_SEPARATELY,
79
+ body: beginCell()
80
+ .storeUint(21, 32)
81
+ .storeUint(0, 64)
82
+ .storeAddress(recipient)
83
+ .storeCoins(forwardValue)
84
+ .storeRef(
85
+ beginCell()
86
+ .storeUint(OPCODES.REWARD_JETTON_MINT, 32)
87
+ .storeUint(0, 64)
88
+ .storeCoins(amount)
89
+ .storeAddress(this.address)
90
+ .storeAddress(this.address)
91
+ .storeCoins(0)
92
+ .storeUint(0, 1)
93
+ .endCell(),
94
+ )
95
+ .endCell(),
96
+ value: value + forwardValue,
97
+ });
98
+ }
99
+
100
+ async getWalletAddressOf(provider: ContractProvider, address: Address) {
101
+ return (
102
+ await provider.get('get_wallet_address', [
103
+ { type: 'slice', cell: beginCell().storeAddress(address).endCell() },
104
+ ])
105
+ ).stack.readAddress();
106
+ }
107
+
108
+ async getWalletCode(provider: ContractProvider) {
109
+ let stack = (await provider.get('get_jetton_data', [])).stack;
110
+ stack.skip(4);
111
+ return stack.readCell();
112
+ }
113
+ }
@@ -0,0 +1,77 @@
1
+ import { Address, beginCell, Cell, Contract, contractAddress, ContractProvider, Sender, SendMode } from '@ton/ton';
2
+ import { OPCODES } from '../constants/general';
3
+
4
+ export type JettonWalletConfig = {
5
+ owner: Address;
6
+ minter: Address;
7
+ walletCode: Cell;
8
+ };
9
+
10
+ export class JettonWallet implements Contract {
11
+ constructor(
12
+ readonly address: Address,
13
+ readonly init?: { code: Cell; data: Cell },
14
+ ) {}
15
+
16
+ static createFromAddress(address: Address) {
17
+ return new JettonWallet(address);
18
+ }
19
+
20
+ static jettonWalletConfigToCell(config: JettonWalletConfig): Cell {
21
+ return beginCell()
22
+ .storeCoins(0) // baseTrackingAccured always is 0, check smartcontract
23
+ .storeAddress(config.owner)
24
+ .storeAddress(config.minter)
25
+ .storeRef(config.walletCode)
26
+ .endCell();
27
+ }
28
+
29
+ static createFromConfig(config: JettonWalletConfig, code: Cell, workchain = 0) {
30
+ const data = this.jettonWalletConfigToCell(config);
31
+ const init = { code, data };
32
+ return new JettonWallet(contractAddress(workchain, init), init);
33
+ }
34
+
35
+ async sendDeploy(provider: ContractProvider, via: Sender, value: bigint) {
36
+ await provider.internal(via, {
37
+ value,
38
+ sendMode: SendMode.PAY_GAS_SEPARATELY,
39
+ body: beginCell().endCell(),
40
+ });
41
+ }
42
+
43
+ async sendTransfer(
44
+ provider: ContractProvider,
45
+ via: Sender,
46
+ value: bigint,
47
+ forwardValue: bigint,
48
+ recipient: Address,
49
+ amount: bigint,
50
+ forwardPayload: Cell,
51
+ ) {
52
+ await provider.internal(via, {
53
+ sendMode: SendMode.PAY_GAS_SEPARATELY,
54
+ body: beginCell()
55
+ .storeUint(OPCODES.REWARD_JETTON_TRANSFER, 32)
56
+ .storeUint(0, 64)
57
+ .storeCoins(amount)
58
+ .storeAddress(recipient)
59
+ .storeAddress(via.address)
60
+ .storeUint(0, 1)
61
+ .storeCoins(forwardValue)
62
+ .storeUint(1, 1)
63
+ .storeRef(forwardPayload)
64
+ .endCell(),
65
+ value: value + forwardValue,
66
+ });
67
+ }
68
+
69
+ async getJettonBalance(provider: ContractProvider) {
70
+ let state = await provider.getState();
71
+ if (state.state.type !== 'active') {
72
+ return 0n;
73
+ }
74
+ let res = await provider.get('get_wallet_data', []);
75
+ return res.stack.readBigNumber();
76
+ }
77
+ }
@@ -0,0 +1,110 @@
1
+ import {
2
+ Address,
3
+ beginCell,
4
+ Cell,
5
+ Contract,
6
+ contractAddress,
7
+ ContractProvider,
8
+ fromNano,
9
+ Sender,
10
+ SendMode,
11
+ StateInit,
12
+ toNano,
13
+ } from '@ton/ton';
14
+ import { Maybe } from '@ton/ton/dist/utils/maybe';
15
+ import { FEES, OPCODES } from '../constants/general';
16
+ import { EvaaRewardsConfig } from '../types/MasterRewards';
17
+ import { bigIntToBuffer } from '../utils/sha256BigInt';
18
+
19
+ export class RewardMaster implements Contract {
20
+ constructor(
21
+ readonly address: Address,
22
+ readonly init?: Maybe<StateInit>,
23
+ ) {}
24
+
25
+ static createFromAddress(address: Address) {
26
+ return new RewardMaster(address);
27
+ }
28
+
29
+ static rewardMasterConfigToCell(config: EvaaRewardsConfig): Cell {
30
+ return beginCell()
31
+ .storeAddress(config.adminAddress)
32
+ .storeCoins(config.availableReward)
33
+ .storeAddress(null) // The addres null for TON
34
+ .storeRef(config.rewardUserCode)
35
+ .storeRef(
36
+ beginCell()
37
+ .storeAddress(config.evaaMasterAddress)
38
+ .storeBuffer(bigIntToBuffer(config.asset.assetId), 256 / 8)
39
+ .storeBuffer(config.publicKey, 256 / 8)
40
+ .endCell(),
41
+ )
42
+ .endCell();
43
+ }
44
+
45
+ static createFromConfig(config: EvaaRewardsConfig, workchain = 0) {
46
+ const data = this.rewardMasterConfigToCell(config);
47
+ const init = { code: config.rewardMasterCode, data };
48
+ return new RewardMaster(contractAddress(workchain, init), init);
49
+ }
50
+
51
+ async sendDeploy(provider: ContractProvider, via: Sender, rewardTokenJettonWalletAddress: Address | null) {
52
+ await provider.internal(via, {
53
+ value: FEES.REWARD_MASTER_DEPLOY,
54
+ sendMode: SendMode.PAY_GAS_SEPARATELY,
55
+ body: beginCell().storeUint(1, 32).storeUint(0, 64).storeAddress(rewardTokenJettonWalletAddress).endCell(),
56
+ });
57
+ }
58
+
59
+ async sendTonTopUp(provider: ContractProvider, via: Sender, topUpRewardAmount: number) {
60
+ await provider.internal(via, {
61
+ value: toNano(topUpRewardAmount) + FEES.REWARD_MASTER_TON_TOP_UP,
62
+ sendMode: SendMode.PAY_GAS_SEPARATELY,
63
+ body: beginCell().storeUint(OPCODES.REWARD_TON_TOP_UP, 32).storeUint(0, 64).endCell(),
64
+ });
65
+ }
66
+
67
+ private adminWithdrawMessage(destinationAddress: Address, jettonAmount: number) {
68
+ return beginCell()
69
+ .storeUint(4, 32)
70
+ .storeUint(0, 64)
71
+ .storeAddress(destinationAddress)
72
+ .storeCoins(toNano(jettonAmount))
73
+ .endCell();
74
+ }
75
+
76
+ async sendAdminWithdraw(
77
+ provider: ContractProvider,
78
+ via: Sender,
79
+ destinationAddress: Address,
80
+ jettonAmount: number,
81
+ ) {
82
+ await provider.internal(via, {
83
+ value: FEES.REWARD_MASTER_WITHDRAW,
84
+ sendMode: SendMode.PAY_GAS_SEPARATELY,
85
+ body: this.adminWithdrawMessage(destinationAddress, jettonAmount),
86
+ });
87
+ }
88
+
89
+ async getData(provider: ContractProvider) {
90
+ const result = await provider.get('load_data', []);
91
+ const data = {
92
+ // TODO: maybe it will be typed
93
+ adminAddress: result.stack.readAddress(),
94
+ availableReward: Number(fromNano(result.stack.readBigNumber())),
95
+ rewardUserCode: result.stack.readCell(),
96
+ evaaMasterAddress: result.stack.readAddress(),
97
+ rewardTokenJettonWalletAddress: result.stack.readAddressOpt(),
98
+ assetId: Buffer.from(result.stack.readBigNumber().toString(16), 'hex'),
99
+ publicKey: Buffer.from(result.stack.readBigNumber().toString(16), 'hex'),
100
+ };
101
+ return data;
102
+ }
103
+
104
+ async getRewardUserAddress(provider: ContractProvider, userAddress: Address): Promise<Address> {
105
+ const result = await provider.get('calculate_reward_user_address', [
106
+ { type: 'slice', cell: beginCell().storeAddress(userAddress).endCell() },
107
+ ]);
108
+ return result.stack.readAddress();
109
+ }
110
+ }