@alphafi/alphafi-sdk 0.0.24 → 0.0.26

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 (75) hide show
  1. package/dist/cjs/common/coins.d.ts.map +1 -1
  2. package/dist/cjs/common/coins.js +6 -0
  3. package/dist/cjs/common/coins.js.map +1 -1
  4. package/dist/cjs/common/constants.d.ts.map +1 -1
  5. package/dist/cjs/common/constants.js +64 -10
  6. package/dist/cjs/common/constants.js.map +1 -1
  7. package/dist/cjs/common/maps.d.ts.map +1 -1
  8. package/dist/cjs/common/maps.js +64 -2
  9. package/dist/cjs/common/maps.js.map +1 -1
  10. package/dist/cjs/common/types.d.ts.map +1 -1
  11. package/dist/cjs/common/types.js +1 -0
  12. package/dist/cjs/common/types.js.map +1 -1
  13. package/dist/cjs/index.d.ts.map +1 -1
  14. package/dist/cjs/index.js +6 -1
  15. package/dist/cjs/index.js.map +1 -1
  16. package/dist/cjs/sui-sdk/events/fetchAutoCompoundingEvents.d.ts.map +1 -1
  17. package/dist/cjs/sui-sdk/events/fetchAutoCompoundingEvents.js +140 -71
  18. package/dist/cjs/sui-sdk/events/fetchAutoCompoundingEvents.js.map +1 -1
  19. package/dist/cjs/sui-sdk/events/fetchEvents.d.ts.map +1 -1
  20. package/dist/cjs/sui-sdk/events/fetchEvents.js +11 -0
  21. package/dist/cjs/sui-sdk/events/fetchEvents.js.map +1 -1
  22. package/dist/cjs/sui-sdk/events/types.d.ts.map +1 -1
  23. package/dist/cjs/sui-sdk/events/types.js.map +1 -1
  24. package/dist/cjs/sui-sdk/functions/getPortfolioAmounts.d.ts.map +1 -1
  25. package/dist/cjs/sui-sdk/functions/getPortfolioAmounts.js +10 -6
  26. package/dist/cjs/sui-sdk/functions/getPortfolioAmounts.js.map +1 -1
  27. package/dist/cjs/utils/clmm/prices.js +3 -3
  28. package/dist/cjs/utils/clmm/prices.js.map +1 -1
  29. package/dist/cjs/utils/hop.d.ts.map +1 -1
  30. package/dist/cjs/utils/hop.js +4 -5
  31. package/dist/cjs/utils/hop.js.map +1 -1
  32. package/dist/cjs/utils/prices.d.ts.map +1 -1
  33. package/dist/cjs/utils/prices.js +34 -120
  34. package/dist/cjs/utils/prices.js.map +1 -1
  35. package/dist/cjs/utils/userHoldings.d.ts.map +1 -1
  36. package/dist/cjs/utils/userHoldings.js +3 -1
  37. package/dist/cjs/utils/userHoldings.js.map +1 -1
  38. package/dist/esm/common/coins.d.ts.map +1 -1
  39. package/dist/esm/common/coins.js +6 -0
  40. package/dist/esm/common/coins.js.map +1 -1
  41. package/dist/esm/common/constants.d.ts.map +1 -1
  42. package/dist/esm/common/constants.js +64 -10
  43. package/dist/esm/common/constants.js.map +1 -1
  44. package/dist/esm/common/maps.d.ts.map +1 -1
  45. package/dist/esm/common/maps.js +64 -2
  46. package/dist/esm/common/maps.js.map +1 -1
  47. package/dist/esm/common/types.d.ts.map +1 -1
  48. package/dist/esm/common/types.js +1 -0
  49. package/dist/esm/common/types.js.map +1 -1
  50. package/dist/esm/index.d.ts.map +1 -1
  51. package/dist/esm/index.js +3 -1
  52. package/dist/esm/index.js.map +1 -1
  53. package/dist/esm/sui-sdk/events/fetchAutoCompoundingEvents.d.ts.map +1 -1
  54. package/dist/esm/sui-sdk/events/fetchAutoCompoundingEvents.js +140 -71
  55. package/dist/esm/sui-sdk/events/fetchAutoCompoundingEvents.js.map +1 -1
  56. package/dist/esm/sui-sdk/events/fetchEvents.d.ts.map +1 -1
  57. package/dist/esm/sui-sdk/events/fetchEvents.js +11 -0
  58. package/dist/esm/sui-sdk/events/fetchEvents.js.map +1 -1
  59. package/dist/esm/sui-sdk/events/types.d.ts.map +1 -1
  60. package/dist/esm/sui-sdk/events/types.js.map +1 -1
  61. package/dist/esm/sui-sdk/functions/getPortfolioAmounts.d.ts.map +1 -1
  62. package/dist/esm/sui-sdk/functions/getPortfolioAmounts.js +8 -4
  63. package/dist/esm/sui-sdk/functions/getPortfolioAmounts.js.map +1 -1
  64. package/dist/esm/utils/clmm/prices.js +4 -4
  65. package/dist/esm/utils/clmm/prices.js.map +1 -1
  66. package/dist/esm/utils/hop.d.ts.map +1 -1
  67. package/dist/esm/utils/hop.js +5 -6
  68. package/dist/esm/utils/hop.js.map +1 -1
  69. package/dist/esm/utils/prices.d.ts.map +1 -1
  70. package/dist/esm/utils/prices.js +34 -118
  71. package/dist/esm/utils/prices.js.map +1 -1
  72. package/dist/esm/utils/userHoldings.d.ts.map +1 -1
  73. package/dist/esm/utils/userHoldings.js +4 -2
  74. package/dist/esm/utils/userHoldings.js.map +1 -1
  75. package/package.json +1 -1
@@ -3,7 +3,7 @@ import { getInvestorPoolMap, poolCoinMap, poolInfo, } from "../../common/maps.js
3
3
  import { fetchEvents } from "./fetchEvents.js";
4
4
  export async function fetchAutoCompoundingEvents(params) {
5
5
  const eventTypesSet = new Set();
6
- const rebalanceEventTypesSet = new Set();
6
+ // const rebalanceEventTypesSet = new Set<string>();
7
7
  if (params.poolNames) {
8
8
  params.poolNames.forEach((poolName) => {
9
9
  const eventType = poolInfo[poolName].autoCompoundingEventType;
@@ -22,25 +22,24 @@ export async function fetchAutoCompoundingEvents(params) {
22
22
  });
23
23
  }
24
24
  // for rebalance
25
- if (params.poolNames) {
26
- params.poolNames.forEach((poolName) => {
27
- const eventType = poolInfo[poolName].rebalanceEventType;
28
- if (eventType !== undefined && eventType !== null && eventType !== "") {
29
- rebalanceEventTypesSet.add(eventType);
30
- }
31
- });
32
- }
33
- else {
34
- // Iterate over all the values in poolInfo and add each autoCompoundingEventType to the Set
35
- Object.values(poolInfo).forEach((info) => {
36
- const eventType = info.rebalanceEventType;
37
- if (eventType !== undefined && eventType !== null && eventType !== "") {
38
- rebalanceEventTypesSet.add(eventType);
39
- }
40
- });
41
- }
25
+ // if (params.poolNames) {
26
+ // params.poolNames.forEach((poolName) => {
27
+ // const eventType = poolInfo[poolName].rebalanceEventType;
28
+ // if (eventType !== undefined && eventType !== null && eventType !== "") {
29
+ // rebalanceEventTypesSet.add(eventType);
30
+ // }
31
+ // });
32
+ // } else {
33
+ // // Iterate over all the values in poolInfo and add each autoCompoundingEventType to the Set
34
+ // Object.values(poolInfo).forEach((info) => {
35
+ // const eventType = info.rebalanceEventType;
36
+ // if (eventType !== undefined && eventType !== null && eventType !== "") {
37
+ // rebalanceEventTypesSet.add(eventType);
38
+ // }
39
+ // });
40
+ // }
42
41
  const eventTypes = Array.from(eventTypesSet);
43
- const rebalanceEventTypes = Array.from(rebalanceEventTypesSet);
42
+ // const rebalanceEventTypes = Array.from(rebalanceEventTypesSet);
44
43
  const eventsPromises = eventTypes.map(async (eventType) => {
45
44
  const events = (await fetchEvents({
46
45
  startTime: params.startTime,
@@ -58,49 +57,54 @@ export async function fetchAutoCompoundingEvents(params) {
58
57
  });
59
58
  return events;
60
59
  });
61
- const rebalanceEventsPromises = rebalanceEventTypes.map(async (eventType) => {
62
- const events = (await fetchEvents({
63
- startTime: params.startTime,
64
- endTime: params.endTime,
65
- eventTypes: [eventType],
66
- })).filter((e) => {
67
- if (params.poolNames) {
68
- return params.poolNames
69
- .map((poolName) => poolInfo[poolName].investorId)
70
- .includes(e.investor_id);
71
- }
72
- else {
73
- return true;
74
- }
75
- });
76
- return events;
77
- });
60
+ // const rebalanceEventsPromises = rebalanceEventTypes.map(async (eventType) => {
61
+ // const events = (
62
+ // await fetchEvents({
63
+ // startTime: params.startTime,
64
+ // endTime: params.endTime,
65
+ // eventTypes: [eventType],
66
+ // })
67
+ // ).filter((e) => {
68
+ // if (params.poolNames) {
69
+ // return params.poolNames
70
+ // .map((poolName) => poolInfo[poolName].investorId)
71
+ // .includes((e as AutoCompoundingEventNode).investor_id);
72
+ // } else {
73
+ // return true;
74
+ // }
75
+ // });
76
+ // return events;
77
+ // });
78
78
  const events = (await Promise.all(eventsPromises)).flat();
79
79
  const autoCompoundingEvents = events.map((e) => {
80
80
  return e;
81
81
  });
82
- const rebalanceEvents = (await Promise.all(rebalanceEventsPromises)).flat();
83
- const rebalancingEvents = rebalanceEvents.map((e) => {
84
- return e;
85
- });
86
- const investorPoolMap = await getInvestorPoolMap();
87
- for (const x of autoCompoundingEvents) {
88
- if (investorPoolMap.get(x.investor_id) &&
89
- poolInfo[investorPoolMap.get(x.investor_id)].parentProtocolName ==
90
- "CETUS") {
91
- if ("total_amount_a" in x &&
92
- x.total_amount_a == 0n &&
93
- x.total_amount_b == 0n) {
94
- for (const y of rebalancingEvents) {
95
- if (y.investor_id == x.investor_id && y.timestamp == x.timestamp) {
96
- // works if its guaranteed that for one timestamp there is only one rebalance for one pool
97
- x.total_amount_a = BigInt(y.amount_a_before);
98
- x.total_amount_b = BigInt(y.amount_b_before);
99
- }
100
- }
101
- }
102
- }
103
- }
82
+ // const rebalanceEvents = (await Promise.all(rebalanceEventsPromises)).flat();
83
+ // const rebalancingEvents = rebalanceEvents.map((e) => {
84
+ // return e as RebalanceEventNode;
85
+ // });
86
+ // const investorPoolMap = await getInvestorPoolMap();
87
+ // for (const x of autoCompoundingEvents) {
88
+ // if (
89
+ // investorPoolMap.get(x.investor_id) &&
90
+ // poolInfo[investorPoolMap.get(x.investor_id)!].parentProtocolName ==
91
+ // "CETUS"
92
+ // ) {
93
+ // if (
94
+ // "total_amount_a" in x &&
95
+ // x.total_amount_a == 0n &&
96
+ // x.total_amount_b == 0n
97
+ // ) {
98
+ // for (const y of rebalancingEvents) {
99
+ // if (y.investor_id == x.investor_id && y.timestamp == x.timestamp) {
100
+ // // works if its guaranteed that for one timestamp there is only one rebalance for one pool
101
+ // x.total_amount_a = BigInt(y.amount_a_before);
102
+ // x.total_amount_b = BigInt(y.amount_b_before);
103
+ // }
104
+ // }
105
+ // }
106
+ // }
107
+ // }
104
108
  return autoCompoundingEvents;
105
109
  }
106
110
  export async function calculateAprForInvestor(events) {
@@ -110,35 +114,99 @@ export async function calculateAprForInvestor(events) {
110
114
  let totalTimeSpan = 0;
111
115
  let previousTimestamp = events[0].timestamp; // Start with the timestamp of the first event
112
116
  let previousGrowthRate = 0;
117
+ let previousTimeDiff = 0;
118
+ let prevCompoundA = 0n;
119
+ let prevCompoundB = 0n;
113
120
  const investorPoolMap = await getInvestorPoolMap();
121
+ // const matchInvestor =
122
+ // "0x05fa099d1df7b5bfb2e420d5ee2d63508db17c40ce7c4e0ca0305cd5df974e43";
123
+ // if (events && events.length > 0 && events[0].investor_id === matchInvestor) {
124
+ // console.log(
125
+ // "Compund A,Total A,Compound B,Total B,Freebalance A,Freebalance B,GrowthA,GrowthB,AvgGrowth,Timestamp,TimeDiff (Min)",
126
+ // );
127
+ // }
114
128
  for (const event of events) {
115
129
  // Calculate the time difference from the previous event
116
- const timeDiff = event.timestamp - previousTimestamp; // / (1000 * 60 * 60 * 24);
130
+ let timeDiff = event.timestamp - previousTimestamp; // / (1000 * 60 * 60 * 24);
117
131
  // Calculate growth rate
118
132
  let growthRate = 0;
119
133
  if ("total_amount_a" in event && "total_amount_b" in event) {
120
134
  let growthA = 0;
121
135
  let growthB = 0;
122
- growthA =
123
- Number(event.total_amount_a) === 0
124
- ? 0
125
- : Number(event.compound_amount_a) / Number(event.total_amount_a);
126
- growthB =
127
- Number(event.total_amount_b) == 0
128
- ? 0
129
- : Number(event.compound_amount_b) / Number(event.total_amount_b);
130
- growthRate = (growthA + growthB) / 2; // Averaging growth rates for token A and B
136
+ if (Number(event.total_amount_a) === 0) {
137
+ prevCompoundA += event.compound_amount_a;
138
+ }
139
+ else {
140
+ prevCompoundA = 0n;
141
+ }
142
+ if (prevCompoundA > 0n) {
143
+ growthA =
144
+ Number(event.total_amount_a) === 0
145
+ ? 0
146
+ : Number(event.compound_amount_a + prevCompoundA) /
147
+ Number(event.total_amount_a - prevCompoundA);
148
+ }
149
+ else {
150
+ growthA =
151
+ Number(event.total_amount_a) === 0
152
+ ? 0
153
+ : Number(event.compound_amount_a) / Number(event.total_amount_a);
154
+ }
155
+ if (Number(event.total_amount_b) === 0) {
156
+ prevCompoundB += event.compound_amount_b;
157
+ }
158
+ else {
159
+ prevCompoundB = 0n;
160
+ }
161
+ if (prevCompoundB > 0n) {
162
+ growthB =
163
+ Number(event.total_amount_b) == 0
164
+ ? 0
165
+ : Number(event.compound_amount_b + prevCompoundB) /
166
+ Number(event.total_amount_b - prevCompoundB);
167
+ }
168
+ else {
169
+ growthB =
170
+ Number(event.total_amount_b) == 0
171
+ ? 0
172
+ : Number(event.compound_amount_b) / Number(event.total_amount_b);
173
+ }
174
+ // if (
175
+ // event.investor_id ===
176
+ // "0xd060e81548aee885bd3d37ae0caec181185be792bf45412e0d0acccd1e0174e6"
177
+ // ) {
178
+ // console.log(
179
+ // timeDiff / (1000 * 60),
180
+ // event.timestamp,
181
+ // event.timestamp - previousTimestamp,
182
+ // );
183
+ // }
131
184
  // if (
132
185
  // event.investor_id ===
133
- // "0xba6acd0350eab1c6bc433b6c869e5592fe0667ae96a3115f89d5c79dd78396ef"
186
+ // "0xd060e81548aee885bd3d37ae0caec181185be792bf45412e0d0acccd1e0174e6"
134
187
  // ) {
135
188
  // console.log(
136
- // `${event.compound_amount_a},${event.total_amount_a},${event.compound_amount_b},${event.total_amount_b},${event.timestamp},${event.free_balance_a},${event.free_balance_b}`,
189
+ // event.compound_amount_a,
190
+ // event.total_amount_a,
191
+ // growthA,
192
+ // event.compound_amount_b,
193
+ // event.total_amount_b,
194
+ // growthB,
195
+ // );
196
+ // }
197
+ growthRate = (growthA + growthB) / 2; // Averaging growth rates for token A and B
198
+ // if (event.investor_id === matchInvestor) {
199
+ // console.log(
200
+ // `${event.compound_amount_a},${event.total_amount_a},${event.compound_amount_b},${event.total_amount_b},${event.free_balance_a},${event.free_balance_b},${growthA},${growthB},${growthRate},${event.timestamp},${(event.timestamp - previousTimestamp) / (1000 * 60)}`,
137
201
  // );
138
202
  // }
139
203
  if (Math.abs(growthA - growthB) > 0.5) {
140
204
  // skip row, fill with previous event
141
205
  growthRate = previousGrowthRate;
206
+ timeDiff = previousTimeDiff;
207
+ }
208
+ if (growthRate > 0.005) {
209
+ growthRate = 0;
142
210
  }
143
211
  }
144
212
  else if ("total_amount" in event) {
@@ -157,10 +225,11 @@ export async function calculateAprForInvestor(events) {
157
225
  growthRate = growthRate * Math.pow(10, 9 - coins[coinName].expo);
158
226
  }
159
227
  // Accumulate the time-weighted growth
160
- totalGrowth += growthRate;
228
+ totalGrowth = (totalGrowth + 1) * (1 + growthRate) - 1;
161
229
  previousGrowthRate = growthRate;
162
230
  // Accumulate the total time span
163
231
  totalTimeSpan += timeDiff;
232
+ previousTimeDiff = timeDiff;
164
233
  // Update the previous timestamp to the current event's timestamp
165
234
  previousTimestamp = event.timestamp;
166
235
  }
@@ -1 +1 @@
1
- {"version":3,"file":"fetchAutoCompoundingEvents.js","sourceRoot":"","sources":["../../../../src/sui-sdk/events/fetchAutoCompoundingEvents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,QAAQ,GACT,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAO/C,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,MAAwC;IAExC,MAAM,aAAa,GAAG,IAAI,GAAG,EAAU,CAAC;IACxC,MAAM,sBAAsB,GAAG,IAAI,GAAG,EAAU,CAAC;IACjD,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QACrB,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YACpC,MAAM,SAAS,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC,wBAAwB,CAAC;YAC9D,IAAI,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,IAAI,IAAI,SAAS,KAAK,EAAE,EAAE,CAAC;gBACtE,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,2FAA2F;QAC3F,MAAM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EAAE,EAAE;QACd,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC;QACpC,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAA4B,CAC7B,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAAkC;IAElC,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,MAAM,mBAAmB,GAAG,MAAM,kBAAkB,EAAE,CAAC;IACvD,MAAM,cAAc,GAAG,MAAM,wBAAwB,CAAC,MAAM,CAAC,CAAC;IAC9D,KAAK,MAAM,UAAU,IAAI,cAAc,EAAE,CAAC;QACxC,MAAM,QAAQ,GAAG,mBAAmB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACrD,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,CAAC,QAAQ,CAAC,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { coins } from \"../../common/coins.js\";\nimport {\n getInvestorPoolMap,\n poolCoinMap,\n poolInfo,\n} from \"../../common/maps.js\";\nimport { PoolName, SingleAssetPoolNames } from \"../../common/types.js\";\nimport { fetchEvents } from \"./fetchEvents.js\";\nimport {\n AutoCompoundingEventNode,\n FetchAutoCompoundingEventsParams,\n RebalanceEventNode,\n} from \"./types.js\";\n\nexport async function fetchAutoCompoundingEvents(\n params: FetchAutoCompoundingEventsParams,\n): Promise<AutoCompoundingEventNode[]> {\n const eventTypesSet = new Set<string>();\n const rebalanceEventTypesSet = new Set<string>();\n if (params.poolNames) {\n params.poolNames.forEach((poolName) => {\n const eventType = poolInfo[poolName].autoCompoundingEventType;\n if (eventType !== undefined && eventType !== null && eventType !== \"\") {\n eventTypesSet.add(eventType);\n }\n });\n } else {\n // Iterate over all the values in poolInfo and add each autoCompoundingEventType to the Set\n Object.values(poolInfo).forEach((info) => {\n const eventType = info.autoCompoundingEventType;\n if (eventType !== undefined && eventType !== null && eventType !== \"\") {\n eventTypesSet.add(eventType);\n }\n });\n }\n // for rebalance\n if (params.poolNames) {\n params.poolNames.forEach((poolName) => {\n const eventType = poolInfo[poolName].rebalanceEventType;\n if (eventType !== undefined && eventType !== null && eventType !== \"\") {\n rebalanceEventTypesSet.add(eventType);\n }\n });\n } else {\n // Iterate over all the values in poolInfo and add each autoCompoundingEventType to the Set\n Object.values(poolInfo).forEach((info) => {\n const eventType = info.rebalanceEventType;\n if (eventType !== undefined && eventType !== null && eventType !== \"\") {\n rebalanceEventTypesSet.add(eventType);\n }\n });\n }\n\n const eventTypes = Array.from(eventTypesSet);\n const rebalanceEventTypes = Array.from(rebalanceEventTypesSet);\n\n const eventsPromises = eventTypes.map(async (eventType) => {\n const events = (\n await fetchEvents({\n startTime: params.startTime,\n endTime: params.endTime,\n eventTypes: [eventType],\n })\n ).filter((e) => {\n if (params.poolNames) {\n return params.poolNames\n .map((poolName) => poolInfo[poolName].investorId)\n .includes((e as AutoCompoundingEventNode).investor_id);\n } else {\n return true;\n }\n });\n return events;\n });\n const rebalanceEventsPromises = rebalanceEventTypes.map(async (eventType) => {\n const events = (\n await fetchEvents({\n startTime: params.startTime,\n endTime: params.endTime,\n eventTypes: [eventType],\n })\n ).filter((e) => {\n if (params.poolNames) {\n return params.poolNames\n .map((poolName) => poolInfo[poolName].investorId)\n .includes((e as AutoCompoundingEventNode).investor_id);\n } else {\n return true;\n }\n });\n return events;\n });\n\n const events = (await Promise.all(eventsPromises)).flat();\n\n const autoCompoundingEvents = events.map((e) => {\n return e as AutoCompoundingEventNode;\n });\n\n const rebalanceEvents = (await Promise.all(rebalanceEventsPromises)).flat();\n\n const rebalancingEvents = rebalanceEvents.map((e) => {\n return e as RebalanceEventNode;\n });\n\n const investorPoolMap = await getInvestorPoolMap();\n\n for (const x of autoCompoundingEvents) {\n if (\n investorPoolMap.get(x.investor_id) &&\n poolInfo[investorPoolMap.get(x.investor_id)!].parentProtocolName ==\n \"CETUS\"\n ) {\n if (\n \"total_amount_a\" in x &&\n x.total_amount_a == 0n &&\n x.total_amount_b == 0n\n ) {\n for (const y of rebalancingEvents) {\n if (y.investor_id == x.investor_id && y.timestamp == x.timestamp) {\n // works if its guaranteed that for one timestamp there is only one rebalance for one pool\n x.total_amount_a = BigInt(y.amount_a_before);\n x.total_amount_b = BigInt(y.amount_b_before);\n }\n }\n }\n }\n }\n\n return autoCompoundingEvents;\n}\n\nexport async function calculateAprForInvestor(\n events: AutoCompoundingEventNode[],\n): Promise<number> {\n // Sort events by timestamp to process them in order\n events.sort((a, b) => a.timestamp - b.timestamp);\n\n let totalGrowth = 0;\n let totalTimeSpan = 0;\n let previousTimestamp = events[0].timestamp; // Start with the timestamp of the first event\n let previousGrowthRate = 0;\n\n const investorPoolMap = await getInvestorPoolMap();\n\n for (const event of events) {\n // Calculate the time difference from the previous event\n const timeDiff = event.timestamp - previousTimestamp; // / (1000 * 60 * 60 * 24);\n\n // Calculate growth rate\n let growthRate = 0;\n if (\"total_amount_a\" in event && \"total_amount_b\" in event) {\n let growthA = 0;\n let growthB = 0;\n growthA =\n Number(event.total_amount_a) === 0\n ? 0\n : Number(event.compound_amount_a) / Number(event.total_amount_a);\n\n growthB =\n Number(event.total_amount_b) == 0\n ? 0\n : Number(event.compound_amount_b) / Number(event.total_amount_b);\n\n growthRate = (growthA + growthB) / 2; // Averaging growth rates for token A and B\n // if (\n // event.investor_id ===\n // \"0xba6acd0350eab1c6bc433b6c869e5592fe0667ae96a3115f89d5c79dd78396ef\"\n // ) {\n // console.log(\n // `${event.compound_amount_a},${event.total_amount_a},${event.compound_amount_b},${event.total_amount_b},${event.timestamp},${event.free_balance_a},${event.free_balance_b}`,\n // );\n // }\n if (Math.abs(growthA - growthB) > 0.5) {\n // skip row, fill with previous event\n growthRate = previousGrowthRate;\n }\n } else if (\"total_amount\" in event) {\n let compoundAmount: number = Number(event.compound_amount);\n let totalAmount: number = Number(event.total_amount);\n if (\"cur_total_debt\" in event && \"accrued_interest\" in event) {\n compoundAmount = Number(event.compound_amount - event.accrued_interest);\n totalAmount = Number(event.total_amount - event.cur_total_debt);\n }\n // NaviAutoCompoundingEvent\n growthRate = isNaN(compoundAmount / totalAmount)\n ? 0\n : compoundAmount / totalAmount;\n const poolName = investorPoolMap.get(\n event.investor_id,\n ) as SingleAssetPoolNames;\n const coinName = poolCoinMap[poolName];\n\n growthRate = growthRate * Math.pow(10, 9 - coins[coinName].expo);\n }\n\n // Accumulate the time-weighted growth\n totalGrowth += growthRate;\n previousGrowthRate = growthRate;\n\n // Accumulate the total time span\n totalTimeSpan += timeDiff;\n\n // Update the previous timestamp to the current event's timestamp\n previousTimestamp = event.timestamp;\n }\n\n const apr = (totalGrowth / totalTimeSpan) * (1000 * 60 * 60 * 24 * 365) * 100;\n\n return apr;\n}\n\nasync function calculateAprForInvestors(\n events: AutoCompoundingEventNode[],\n): Promise<Record<string, number>> {\n const investorEvents: Record<string, AutoCompoundingEventNode[]> = {};\n\n // Step 1: Segregate events by investor_id\n for (const event of events) {\n const investorId = event.investor_id;\n if (!investorEvents[investorId]) {\n investorEvents[investorId] = [];\n }\n investorEvents[investorId].push(event);\n }\n\n // Step 2: Calculate APR for each event and aggregate for each investor\n const aprPromises: Promise<{ investorId: string; apr: number }>[] = [];\n\n for (const investorId in investorEvents) {\n const investorEventList = investorEvents[investorId];\n // Push a promise that resolves to an object containing the investorId and the corresponding APR\n aprPromises.push(\n calculateAprForInvestor(investorEventList).then((apr) => ({\n investorId,\n apr,\n })),\n );\n }\n\n // Resolve all promises and map them to the corresponding APR\n const aprs = await Promise.all(aprPromises);\n\n // Convert the array of results into an object mapping investorId to APR\n const aprMap = aprs.reduce(\n (map, result) => {\n map[result.investorId] = result.apr;\n return map;\n },\n {} as Record<string, number>,\n );\n\n return aprMap;\n}\n\nexport async function calculateAprForPools(\n events: AutoCompoundingEventNode[],\n): Promise<Record<PoolName, number>> {\n const aprMap: Record<string, number> = {};\n const investorPoolNameMap = await getInvestorPoolMap();\n const investorAprMap = await calculateAprForInvestors(events);\n for (const investorId in investorAprMap) {\n const poolName = investorPoolNameMap.get(investorId);\n if (poolName) {\n aprMap[poolName] = investorAprMap[investorId];\n }\n }\n return aprMap;\n}\n"]}
1
+ {"version":3,"file":"fetchAutoCompoundingEvents.js","sourceRoot":"","sources":["../../../../src/sui-sdk/events/fetchAutoCompoundingEvents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,QAAQ,GACT,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAO/C,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,MAAwC;IAExC,MAAM,aAAa,GAAG,IAAI,GAAG,EAAU,CAAC;IACxC,oDAAoD;IACpD,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QACrB,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YACpC,MAAM,SAAS,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC,wBAAwB,CAAC;YAC9D,IAAI,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,IAAI,IAAI,SAAS,KAAK,EAAE,EAAE,CAAC;gBACtE,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,2FAA2F;QAC3F,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACvC,MAAM,SAAS,GAAG,IAAI,CAAC,wBAAwB,CAAC;YAChD,IAAI,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,IAAI,IAAI,SAAS,KAAK,EAAE,EAAE,CAAC;gBACtE,aAAa,CAAC,GAAG,CAA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M,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAAkC;IAElC,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,MAAM,mBAAmB,GAAG,MAAM,kBAAkB,EAAE,CAAC;IACvD,MAAM,cAAc,GAAG,MAAM,wBAAwB,CAAC,MAAM,CAAC,CAAC;IAC9D,KAAK,MAAM,UAAU,IAAI,cAAc,EAAE,CAAC;QACxC,MAAM,QAAQ,GAAG,mBAAmB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACrD,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,CAAC,QAAQ,CAAC,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { coins } from \"../../common/coins.js\";\nimport {\n getInvestorPoolMap,\n poolCoinMap,\n poolInfo,\n} from \"../../common/maps.js\";\nimport { PoolName, SingleAssetPoolNames } from \"../../common/types.js\";\nimport { fetchEvents } from \"./fetchEvents.js\";\nimport {\n AutoCompoundingEventNode,\n FetchAutoCompoundingEventsParams,\n //RebalanceEventNode,\n} from \"./types.js\";\n\nexport async function fetchAutoCompoundingEvents(\n params: FetchAutoCompoundingEventsParams,\n): Promise<AutoCompoundingEventNode[]> {\n const eventTypesSet = new Set<string>();\n // const rebalanceEventTypesSet = new Set<string>();\n if (params.poolNames) {\n params.poolNames.forEach((poolName) => {\n const eventType = poolInfo[poolName].autoCompoundingEventType;\n if (eventType !== undefined && eventType !== null && eventType !== \"\") {\n eventTypesSet.add(eventType);\n }\n });\n } else {\n // Iterate over all the values in poolInfo and add each autoCompoundingEventType to the Set\n Object.values(poolInfo).forEach((info) => {\n const eventType = info.autoCompoundingEventType;\n if (eventType !== undefined && eventType !== null && eventType !== \"\") {\n eventTypesSet.add(eventType);\n }\n });\n }\n // for rebalance\n // if (params.poolNames) {\n // params.poolNames.forEach((poolName) => {\n // const eventType = poolInfo[poolName].rebalanceEventType;\n // if (eventType !== undefined && eventType !== null && eventType !== \"\") {\n // rebalanceEventTypesSet.add(eventType);\n // }\n // });\n // } else {\n // // Iterate over all the values in poolInfo and add each autoCompoundingEventType to the Set\n // Object.values(poolInfo).forEach((info) => {\n // const eventType = info.rebalanceEventType;\n // if (eventType !== undefined && eventType !== null && eventType !== \"\") {\n // rebalanceEventTypesSet.add(eventType);\n // }\n // });\n // }\n\n const eventTypes = Array.from(eventTypesSet);\n // const rebalanceEventTypes = Array.from(rebalanceEventTypesSet);\n\n const eventsPromises = eventTypes.map(async (eventType) => {\n const events = (\n await fetchEvents({\n startTime: params.startTime,\n endTime: params.endTime,\n eventTypes: [eventType],\n })\n ).filter((e) => {\n if (params.poolNames) {\n return params.poolNames\n .map((poolName) => poolInfo[poolName].investorId)\n .includes((e as AutoCompoundingEventNode).investor_id);\n } else {\n return true;\n }\n });\n return events;\n });\n // const rebalanceEventsPromises = rebalanceEventTypes.map(async (eventType) => {\n // const events = (\n // await fetchEvents({\n // startTime: params.startTime,\n // endTime: params.endTime,\n // eventTypes: [eventType],\n // })\n // ).filter((e) => {\n // if (params.poolNames) {\n // return params.poolNames\n // .map((poolName) => poolInfo[poolName].investorId)\n // .includes((e as AutoCompoundingEventNode).investor_id);\n // } else {\n // return true;\n // }\n // });\n // return events;\n // });\n\n const events = (await Promise.all(eventsPromises)).flat();\n\n const autoCompoundingEvents = events.map((e) => {\n return e as AutoCompoundingEventNode;\n });\n\n // const rebalanceEvents = (await Promise.all(rebalanceEventsPromises)).flat();\n\n // const rebalancingEvents = rebalanceEvents.map((e) => {\n // return e as RebalanceEventNode;\n // });\n\n // const investorPoolMap = await getInvestorPoolMap();\n\n // for (const x of autoCompoundingEvents) {\n // if (\n // investorPoolMap.get(x.investor_id) &&\n // poolInfo[investorPoolMap.get(x.investor_id)!].parentProtocolName ==\n // \"CETUS\"\n // ) {\n // if (\n // \"total_amount_a\" in x &&\n // x.total_amount_a == 0n &&\n // x.total_amount_b == 0n\n // ) {\n // for (const y of rebalancingEvents) {\n // if (y.investor_id == x.investor_id && y.timestamp == x.timestamp) {\n // // works if its guaranteed that for one timestamp there is only one rebalance for one pool\n // x.total_amount_a = BigInt(y.amount_a_before);\n // x.total_amount_b = BigInt(y.amount_b_before);\n // }\n // }\n // }\n // }\n // }\n\n return autoCompoundingEvents;\n}\n\nexport async function calculateAprForInvestor(\n events: AutoCompoundingEventNode[],\n): Promise<number> {\n // Sort events by timestamp to process them in order\n events.sort((a, b) => a.timestamp - b.timestamp);\n\n let totalGrowth = 0;\n let totalTimeSpan = 0;\n let previousTimestamp = events[0].timestamp; // Start with the timestamp of the first event\n let previousGrowthRate = 0;\n let previousTimeDiff = 0;\n let prevCompoundA = 0n;\n let prevCompoundB = 0n;\n\n const investorPoolMap = await getInvestorPoolMap();\n\n // const matchInvestor =\n // \"0x05fa099d1df7b5bfb2e420d5ee2d63508db17c40ce7c4e0ca0305cd5df974e43\";\n // if (events && events.length > 0 && events[0].investor_id === matchInvestor) {\n // console.log(\n // \"Compund A,Total A,Compound B,Total B,Freebalance A,Freebalance B,GrowthA,GrowthB,AvgGrowth,Timestamp,TimeDiff (Min)\",\n // );\n // }\n for (const event of events) {\n // Calculate the time difference from the previous event\n let timeDiff = event.timestamp - previousTimestamp; // / (1000 * 60 * 60 * 24);\n\n // Calculate growth rate\n let growthRate = 0;\n if (\"total_amount_a\" in event && \"total_amount_b\" in event) {\n let growthA = 0;\n let growthB = 0;\n\n if (Number(event.total_amount_a) === 0) {\n prevCompoundA += event.compound_amount_a;\n } else {\n prevCompoundA = 0n;\n }\n if (prevCompoundA > 0n) {\n growthA =\n Number(event.total_amount_a) === 0\n ? 0\n : Number(event.compound_amount_a + prevCompoundA) /\n Number(event.total_amount_a - prevCompoundA);\n } else {\n growthA =\n Number(event.total_amount_a) === 0\n ? 0\n : Number(event.compound_amount_a) / Number(event.total_amount_a);\n }\n\n if (Number(event.total_amount_b) === 0) {\n prevCompoundB += event.compound_amount_b;\n } else {\n prevCompoundB = 0n;\n }\n\n if (prevCompoundB > 0n) {\n growthB =\n Number(event.total_amount_b) == 0\n ? 0\n : Number(event.compound_amount_b + prevCompoundB) /\n Number(event.total_amount_b - prevCompoundB);\n } else {\n growthB =\n Number(event.total_amount_b) == 0\n ? 0\n : Number(event.compound_amount_b) / Number(event.total_amount_b);\n }\n\n // if (\n // event.investor_id ===\n // \"0xd060e81548aee885bd3d37ae0caec181185be792bf45412e0d0acccd1e0174e6\"\n // ) {\n // console.log(\n // timeDiff / (1000 * 60),\n // event.timestamp,\n // event.timestamp - previousTimestamp,\n // );\n // }\n // if (\n // event.investor_id ===\n // \"0xd060e81548aee885bd3d37ae0caec181185be792bf45412e0d0acccd1e0174e6\"\n // ) {\n // console.log(\n // event.compound_amount_a,\n // event.total_amount_a,\n // growthA,\n // event.compound_amount_b,\n // event.total_amount_b,\n // growthB,\n // );\n // }\n growthRate = (growthA + growthB) / 2; // Averaging growth rates for token A and B\n // if (event.investor_id === matchInvestor) {\n // console.log(\n // `${event.compound_amount_a},${event.total_amount_a},${event.compound_amount_b},${event.total_amount_b},${event.free_balance_a},${event.free_balance_b},${growthA},${growthB},${growthRate},${event.timestamp},${(event.timestamp - previousTimestamp) / (1000 * 60)}`,\n // );\n // }\n if (Math.abs(growthA - growthB) > 0.5) {\n // skip row, fill with previous event\n growthRate = previousGrowthRate;\n timeDiff = previousTimeDiff;\n }\n if (growthRate > 0.005) {\n growthRate = 0;\n }\n } else if (\"total_amount\" in event) {\n let compoundAmount: number = Number(event.compound_amount);\n let totalAmount: number = Number(event.total_amount);\n if (\"cur_total_debt\" in event && \"accrued_interest\" in event) {\n compoundAmount = Number(event.compound_amount - event.accrued_interest);\n totalAmount = Number(event.total_amount - event.cur_total_debt);\n }\n // NaviAutoCompoundingEvent\n growthRate = isNaN(compoundAmount / totalAmount)\n ? 0\n : compoundAmount / totalAmount;\n const poolName = investorPoolMap.get(\n event.investor_id,\n ) as SingleAssetPoolNames;\n const coinName = poolCoinMap[poolName];\n\n growthRate = growthRate * Math.pow(10, 9 - coins[coinName].expo);\n }\n\n // Accumulate the time-weighted growth\n totalGrowth = (totalGrowth + 1) * (1 + growthRate) - 1;\n previousGrowthRate = growthRate;\n\n // Accumulate the total time span\n totalTimeSpan += timeDiff;\n previousTimeDiff = timeDiff;\n\n // Update the previous timestamp to the current event's timestamp\n previousTimestamp = event.timestamp;\n }\n\n const apr = (totalGrowth / totalTimeSpan) * (1000 * 60 * 60 * 24 * 365) * 100;\n\n return apr;\n}\n\nasync function calculateAprForInvestors(\n events: AutoCompoundingEventNode[],\n): Promise<Record<string, number>> {\n const investorEvents: Record<string, AutoCompoundingEventNode[]> = {};\n\n // Step 1: Segregate events by investor_id\n for (const event of events) {\n const investorId = event.investor_id;\n if (!investorEvents[investorId]) {\n investorEvents[investorId] = [];\n }\n investorEvents[investorId].push(event);\n }\n\n // Step 2: Calculate APR for each event and aggregate for each investor\n const aprPromises: Promise<{ investorId: string; apr: number }>[] = [];\n\n for (const investorId in investorEvents) {\n const investorEventList = investorEvents[investorId];\n // Push a promise that resolves to an object containing the investorId and the corresponding APR\n aprPromises.push(\n calculateAprForInvestor(investorEventList).then((apr) => ({\n investorId,\n apr,\n })),\n );\n }\n\n // Resolve all promises and map them to the corresponding APR\n const aprs = await Promise.all(aprPromises);\n\n // Convert the array of results into an object mapping investorId to APR\n const aprMap = aprs.reduce(\n (map, result) => {\n map[result.investorId] = result.apr;\n return map;\n },\n {} as Record<string, number>,\n );\n\n return aprMap;\n}\n\nexport async function calculateAprForPools(\n events: AutoCompoundingEventNode[],\n): Promise<Record<PoolName, number>> {\n const aprMap: Record<string, number> = {};\n const investorPoolNameMap = await getInvestorPoolMap();\n const investorAprMap = await calculateAprForInvestors(events);\n for (const investorId in investorAprMap) {\n const poolName = investorPoolNameMap.get(investorId);\n if (poolName) {\n aprMap[poolName] = investorAprMap[investorId];\n }\n }\n return aprMap;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"fetchEvents.d.ts","sourceRoot":"","sources":["../../../../src/sui-sdk/events/fetchEvents.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,SAAS,EACT,iBAAiB,EAOlB,MAAM,YAAY,CAAC;AAIpB,wBAAsB,WAAW,CAC/B,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,SAAS,EAAE,CAAC,CA4LtB"}
1
+ {"version":3,"file":"fetchEvents.d.ts","sourceRoot":"","sources":["../../../../src/sui-sdk/events/fetchEvents.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,SAAS,EACT,iBAAiB,EAOlB,MAAM,YAAY,CAAC;AAIpB,wBAAsB,WAAW,CAC/B,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,SAAS,EAAE,CAAC,CAwMtB"}
@@ -19,6 +19,7 @@ export async function fetchEvents(params) {
19
19
  throw new Error("startTime must be less than endTime");
20
20
  }
21
21
  const suiClient = getSuiClient();
22
+ //const prevTS = 0;
22
23
  while (hasNextPage) {
23
24
  const result = await suiClient.queryEvents({
24
25
  cursor: startCursor,
@@ -57,6 +58,16 @@ export async function fetchEvents(params) {
57
58
  total_amount_a: BigInt(suiEventJson.total_amount_a.toString()),
58
59
  total_amount_b: BigInt(suiEventJson.total_amount_b.toString()),
59
60
  };
61
+ // if (
62
+ // eventNode.investor_id ===
63
+ // "0xd060e81548aee885bd3d37ae0caec181185be792bf45412e0d0acccd1e0174e6"
64
+ // ) {
65
+ // console.log(
66
+ // eventNode.timestamp,
67
+ // (prevTS - eventNode.timestamp) / (1000 * 60),
68
+ // );
69
+ // prevTS = eventNode.timestamp;
70
+ // }
60
71
  }
61
72
  else if (isAutoCompoundingEvent(suiEvent.type) &&
62
73
  "compound_amount" in suiEventJson) {
@@ -1 +1 @@
1
- {"version":3,"file":"fetchEvents.js","sourceRoot":"","sources":["../../../../src/sui-sdk/events/fetchEvents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAgB5C,OAA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from \"../client.js\";\nimport { EventId, PaginatedEvents } from \"@mysten/sui/client\";\nimport {\n AlphaLiquidityChangeEvent,\n AlphaAutoCompoundingEvent,\n CetusAutoCompoundingEvent,\n CetusLiquidityChangeEvent,\n EventNode,\n FetchEventsParams,\n LiquidityChangeEventNode,\n NaviAutoCompoundingEvent,\n NaviLoopAutoCompoundingEvent,\n NaviLiquidityChangeEvent,\n RebalanceEvent,\n AutoCompoundingEventNode,\n} from \"./types.js\";\nimport { poolInfo } from \"../../common/maps.js\";\nimport { conf, CONF_ENV } from \"../../common/constants.js\";\n\nexport async function fetchEvents(\n params: FetchEventsParams,\n): Promise<EventNode[]> {\n const allEvents: EventNode[] = [];\n let hasNextPage = true;\n let startCursor: EventId | null | undefined = null;\n\n if (params.eventTypes.length > 1) {\n console.warn(\n \"Multiple eventTypes not supported right now, pass only one element in the array.\",\n );\n }\n\n if (params.eventTypes.length < 1) {\n hasNextPage = false;\n }\n\n const now = Date.now();\n const twentyFourHoursAgo = now - 24 * 60 * 60 * 1000; // timestamp for 24 hours ago\n const startTime = params.startTime ? params.startTime : twentyFourHoursAgo;\n const endTime = params.endTime ? params.endTime : now;\n\n if (startTime >= endTime) {\n throw new Error(\"startTime must be less than endTime\");\n }\n\n const suiClient = getSuiClient();\n\n while (hasNextPage) {\n const result: PaginatedEvents = await suiClient.queryEvents({\n cursor: startCursor,\n order: \"descending\",\n query: {\n MoveEventType: params.eventTypes[0],\n },\n });\n\n const se = result.data;\n for (let i = 0; i < se.length; i++) {\n const suiEvent = se[i];\n\n if (Number(suiEvent.timestampMs) > endTime) {\n continue;\n }\n\n if (Number(suiEvent.timestampMs) < startTime) {\n hasNextPage = false; // Stop further pagination\n break; // Exit the loop\n }\n\n const suiEventJson = suiEvent.parsedJson as\n | CetusAutoCompoundingEvent\n | NaviAutoCompoundingEvent\n | NaviLoopAutoCompoundingEvent\n | RebalanceEvent\n | CetusLiquidityChangeEvent\n | AlphaLiquidityChangeEvent\n | NaviLiquidityChangeEvent\n | AlphaAutoCompoundingEvent;\n\n let eventNode: EventNode;\n\n if (\n isAutoCompoundingEvent(suiEvent.type) &&\n \"compound_amount_a\" in suiEventJson &&\n \"compound_amount_b\" in suiEventJson\n ) {\n // Handling CetusAutoCompoundingEvent\n eventNode = {\n type: suiEvent.type,\n timestamp: Number(suiEvent.timestampMs),\n compound_amount_a: BigInt(suiEventJson.compound_amount_a.toString()),\n compound_amount_b: BigInt(suiEventJson.compound_amount_b.toString()),\n current_liquidity: BigInt(suiEventJson.current_liquidity.toString()),\n fee_collected_a: BigInt(suiEventJson.fee_collected_a.toString()),\n fee_collected_b: BigInt(suiEventJson.fee_collected_b.toString()),\n free_balance_a: BigInt(suiEventJson.free_balance_a.toString()),\n free_balance_b: BigInt(suiEventJson.free_balance_b.toString()),\n investor_id: suiEventJson.investor_id,\n total_amount_a: BigInt(suiEventJson.total_amount_a.toString()),\n total_amount_b: BigInt(suiEventJson.total_amount_b.toString()),\n };\n } else if (\n isAutoCompoundingEvent(suiEvent.type) &&\n \"compound_amount\" in suiEventJson\n ) {\n // Handling NaviAutoCompoundingEvent\n eventNode = {\n type: suiEvent.type,\n timestamp: Number(suiEvent.timestampMs),\n compound_amount: BigInt(suiEventJson.compound_amount.toString()),\n fee_collected: BigInt(suiEventJson.fee_collected.toString()),\n investor_id: suiEventJson.investor_id,\n location: suiEventJson.location,\n total_amount: BigInt(suiEventJson.total_amount.toString()),\n };\n if (\n \"cur_total_debt\" in suiEventJson &&\n \"accrued_interest\" in suiEventJson\n ) {\n const loopEvent: AutoCompoundingEventNode = {\n ...eventNode,\n cur_total_debt: BigInt(suiEventJson.cur_total_debt.toString()),\n accrued_interest: BigInt(suiEventJson.accrued_interest.toString()),\n };\n eventNode = loopEvent;\n }\n } else if (\n isAutoCompoundingEvent(suiEvent.type) &&\n \"amount\" in suiEventJson\n ) {\n eventNode = {\n type: suiEvent.type,\n timestamp: Number(suiEvent.timestampMs),\n amount: suiEventJson.amount,\n investor_id: conf[CONF_ENV].ALPHA_POOL,\n };\n } else if (\n isRebalanceEvent(suiEvent.type) &&\n \"lower_tick_after\" in suiEventJson\n ) {\n // Handling RebalanceEvent\n eventNode = {\n type: suiEvent.type,\n timestamp: Number(suiEvent.timestampMs),\n investor_id: suiEventJson.investor_id.toString(),\n lower_tick_after: suiEventJson.lower_tick_after.toString(),\n upper_tick_after: suiEventJson.upper_tick_after.toString(),\n sqrt_price_after: suiEventJson.sqrt_price_after.toString(),\n amount_a_before: suiEventJson.amount_a_before.toString(),\n amount_b_before: suiEventJson.amount_b_before.toString(),\n amount_a_after: suiEventJson.amount_a_after.toString(),\n amount_b_after: suiEventJson.amount_b_after.toString(),\n };\n } else if (\n isLiquidityChangeEvent(suiEvent.type) &&\n \"amount_a\" in suiEventJson\n ) {\n // Handling CetusLiquidityChangeEvent\n eventNode = {\n type: suiEvent.type,\n timestamp: Number(suiEvent.timestampMs),\n amount_a: suiEventJson.amount_a,\n amount_b: suiEventJson.amount_b,\n event_type: suiEventJson.event_type,\n fee_collected_a: suiEventJson.fee_collected_a,\n fee_collected_b: suiEventJson.fee_collected_b,\n pool_id: suiEventJson.pool_id,\n sender: suiEventJson.sender,\n tokens_invested: suiEventJson.tokens_invested,\n total_amount_a: suiEventJson.total_amount_a,\n total_amount_b: suiEventJson.total_amount_b,\n user_total_x_token_balance: suiEventJson.user_total_x_token_balance,\n x_token_supply: suiEventJson.x_token_supply,\n } as LiquidityChangeEventNode;\n } else if (\n isLiquidityChangeEvent(suiEvent.type) &&\n \"amount\" in suiEventJson &&\n !(\"investor_id\" in suiEventJson)\n ) {\n // Handling NaviLiquidityChangeEvent and AlphaLiquidityChangeEvent\n eventNode = {\n type: suiEvent.type,\n timestamp: Number(suiEvent.timestampMs),\n amount: suiEventJson.amount,\n event_type: suiEventJson.event_type,\n fee_collected: suiEventJson.fee_collected,\n pool_id: suiEventJson.pool_id,\n sender: suiEventJson.sender,\n tokens_invested: suiEventJson.tokens_invested,\n user_total_x_token_balance: suiEventJson.user_total_x_token_balance,\n x_token_supply: suiEventJson.x_token_supply,\n } as LiquidityChangeEventNode;\n } else {\n throw new Error(\"Unknown event type\");\n }\n\n allEvents.push(eventNode);\n }\n\n // If we set hasPreviousPage to false, exit the outer loop as well\n if (!hasNextPage) {\n break;\n }\n\n hasNextPage = result.hasNextPage;\n startCursor = result.nextCursor;\n }\n\n return allEvents;\n}\n\nconst isAutoCompoundingEvent = (eventType: string) => {\n const eventTypes: string[] = Object.values(poolInfo).map((info) => {\n return info.autoCompoundingEventType;\n });\n return eventTypes.includes(eventType);\n};\n\nconst isRebalanceEvent = (eventType: string) => {\n const eventTypes: string[] = Object.values(poolInfo)\n .filter((info) => {\n return info.rebalanceEventType ? true : false;\n })\n .map((info) => {\n return info.rebalanceEventType as string;\n });\n return eventTypes.includes(eventType);\n};\n\nconst isLiquidityChangeEvent = (eventType: string) => {\n const eventTypes: string[] = Object.values(poolInfo).map((info) => {\n return info.liquidityChangeEventType;\n });\n return eventTypes.includes(eventType);\n};\n"]}
1
+ {"version":3,"file":"fetchEvents.js","sourceRoot":"","sources":["../../../../src/sui-sdk/events/fetchEvents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAgB5C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAE3D,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAAyB;IAEzB,MAAM,SAAS,GAAgB,EAAE,CAAC;IAClC,IAAI,WAAW,GAAG,IAAI,CAAC;IACvB,IAAI,WAAW,GAA+B,IAAI,CAAC;IAEnD,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACjC,OAAO,CAAC,IAAI,CACV,kFAAkF,CACnF,CAAC;IACJ,CAAC;IAED,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC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AAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QAChE,OAAO,IAAI,CAAC,wBAAwB,CAAC;IACvC,CAAC,CAAC,CAAC;IACH,OAAO,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AACxC,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAG,CAAC,SAAiB,EAAE,EAAE;IAC7C,MAAM,UAAU,GAAa,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC;SACjD,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;QACf,OAAO,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;IAChD,CAAC,CAAC;SACD,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACZ,OAAO,IAAI,CAAC,kBAA4B,CAAC;IAC3C,CAAC,CAAC,CAAC;IACL,OAAO,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AACxC,CAAC,CAAC;AAEF,MAAM,sBAAsB,GAAG,CAAC,SAAiB,EAAE,EAAE;IACnD,MAAM,UAAU,GAAa,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QAChE,OAAO,IAAI,CAAC,wBAAwB,CAAC;IACvC,CAAC,CAAC,CAAC;IACH,OAAO,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AACxC,CAAC,CAAC","sourcesContent":["import { getSuiClient } from \"../client.js\";\nimport { EventId, PaginatedEvents } from \"@mysten/sui/client\";\nimport {\n AlphaLiquidityChangeEvent,\n AlphaAutoCompoundingEvent,\n CetusAutoCompoundingEvent,\n CetusLiquidityChangeEvent,\n EventNode,\n FetchEventsParams,\n LiquidityChangeEventNode,\n NaviAutoCompoundingEvent,\n NaviLoopAutoCompoundingEvent,\n NaviLiquidityChangeEvent,\n RebalanceEvent,\n AutoCompoundingEventNode,\n} from \"./types.js\";\nimport { poolInfo } from \"../../common/maps.js\";\nimport { conf, CONF_ENV } from \"../../common/constants.js\";\n\nexport async function fetchEvents(\n params: FetchEventsParams,\n): Promise<EventNode[]> {\n const allEvents: EventNode[] = [];\n let hasNextPage = true;\n let startCursor: EventId | null | undefined = null;\n\n if (params.eventTypes.length > 1) {\n console.warn(\n \"Multiple eventTypes not supported right now, pass only one element in the array.\",\n );\n }\n\n if (params.eventTypes.length < 1) {\n hasNextPage = false;\n }\n\n const now = Date.now();\n const twentyFourHoursAgo = now - 24 * 60 * 60 * 1000; // timestamp for 24 hours ago\n const startTime = params.startTime ? params.startTime : twentyFourHoursAgo;\n const endTime = params.endTime ? params.endTime : now;\n\n if (startTime >= endTime) {\n throw new Error(\"startTime must be less than endTime\");\n }\n\n const suiClient = getSuiClient();\n //const prevTS = 0;\n\n while (hasNextPage) {\n const result: PaginatedEvents = await suiClient.queryEvents({\n cursor: startCursor,\n order: \"descending\",\n query: {\n MoveEventType: params.eventTypes[0],\n },\n });\n\n const se = result.data;\n for (let i = 0; i < se.length; i++) {\n const suiEvent = se[i];\n\n if (Number(suiEvent.timestampMs) > endTime) {\n continue;\n }\n\n if (Number(suiEvent.timestampMs) < startTime) {\n hasNextPage = false; // Stop further pagination\n break; // Exit the loop\n }\n\n const suiEventJson = suiEvent.parsedJson as\n | CetusAutoCompoundingEvent\n | NaviAutoCompoundingEvent\n | NaviLoopAutoCompoundingEvent\n | RebalanceEvent\n | CetusLiquidityChangeEvent\n | AlphaLiquidityChangeEvent\n | NaviLiquidityChangeEvent\n | AlphaAutoCompoundingEvent;\n\n let eventNode: EventNode;\n\n if (\n isAutoCompoundingEvent(suiEvent.type) &&\n \"compound_amount_a\" in suiEventJson &&\n \"compound_amount_b\" in suiEventJson\n ) {\n // Handling CetusAutoCompoundingEvent\n eventNode = {\n type: suiEvent.type,\n timestamp: Number(suiEvent.timestampMs),\n compound_amount_a: BigInt(suiEventJson.compound_amount_a.toString()),\n compound_amount_b: BigInt(suiEventJson.compound_amount_b.toString()),\n current_liquidity: BigInt(suiEventJson.current_liquidity.toString()),\n fee_collected_a: BigInt(suiEventJson.fee_collected_a.toString()),\n fee_collected_b: BigInt(suiEventJson.fee_collected_b.toString()),\n free_balance_a: BigInt(suiEventJson.free_balance_a.toString()),\n free_balance_b: BigInt(suiEventJson.free_balance_b.toString()),\n investor_id: suiEventJson.investor_id,\n total_amount_a: BigInt(suiEventJson.total_amount_a.toString()),\n total_amount_b: BigInt(suiEventJson.total_amount_b.toString()),\n };\n\n // if (\n // eventNode.investor_id ===\n // \"0xd060e81548aee885bd3d37ae0caec181185be792bf45412e0d0acccd1e0174e6\"\n // ) {\n // console.log(\n // eventNode.timestamp,\n // (prevTS - eventNode.timestamp) / (1000 * 60),\n // );\n // prevTS = eventNode.timestamp;\n // }\n } else if (\n isAutoCompoundingEvent(suiEvent.type) &&\n \"compound_amount\" in suiEventJson\n ) {\n // Handling NaviAutoCompoundingEvent\n eventNode = {\n type: suiEvent.type,\n timestamp: Number(suiEvent.timestampMs),\n compound_amount: BigInt(suiEventJson.compound_amount.toString()),\n fee_collected: BigInt(suiEventJson.fee_collected.toString()),\n investor_id: suiEventJson.investor_id,\n location: suiEventJson.location,\n total_amount: BigInt(suiEventJson.total_amount.toString()),\n };\n if (\n \"cur_total_debt\" in suiEventJson &&\n \"accrued_interest\" in suiEventJson\n ) {\n const loopEvent: AutoCompoundingEventNode = {\n ...eventNode,\n cur_total_debt: BigInt(suiEventJson.cur_total_debt.toString()),\n accrued_interest: BigInt(suiEventJson.accrued_interest.toString()),\n };\n eventNode = loopEvent;\n }\n } else if (\n isAutoCompoundingEvent(suiEvent.type) &&\n \"amount\" in suiEventJson\n ) {\n eventNode = {\n type: suiEvent.type,\n timestamp: Number(suiEvent.timestampMs),\n amount: suiEventJson.amount,\n investor_id: conf[CONF_ENV].ALPHA_POOL,\n };\n } else if (\n isRebalanceEvent(suiEvent.type) &&\n \"lower_tick_after\" in suiEventJson\n ) {\n // Handling RebalanceEvent\n eventNode = {\n type: suiEvent.type,\n timestamp: Number(suiEvent.timestampMs),\n investor_id: suiEventJson.investor_id.toString(),\n lower_tick_after: suiEventJson.lower_tick_after.toString(),\n upper_tick_after: suiEventJson.upper_tick_after.toString(),\n sqrt_price_after: suiEventJson.sqrt_price_after.toString(),\n amount_a_before: suiEventJson.amount_a_before.toString(),\n amount_b_before: suiEventJson.amount_b_before.toString(),\n amount_a_after: suiEventJson.amount_a_after.toString(),\n amount_b_after: suiEventJson.amount_b_after.toString(),\n };\n } else if (\n isLiquidityChangeEvent(suiEvent.type) &&\n \"amount_a\" in suiEventJson\n ) {\n // Handling CetusLiquidityChangeEvent\n eventNode = {\n type: suiEvent.type,\n timestamp: Number(suiEvent.timestampMs),\n amount_a: suiEventJson.amount_a,\n amount_b: suiEventJson.amount_b,\n event_type: suiEventJson.event_type,\n fee_collected_a: suiEventJson.fee_collected_a,\n fee_collected_b: suiEventJson.fee_collected_b,\n pool_id: suiEventJson.pool_id,\n sender: suiEventJson.sender,\n tokens_invested: suiEventJson.tokens_invested,\n total_amount_a: suiEventJson.total_amount_a,\n total_amount_b: suiEventJson.total_amount_b,\n user_total_x_token_balance: suiEventJson.user_total_x_token_balance,\n x_token_supply: suiEventJson.x_token_supply,\n } as LiquidityChangeEventNode;\n } else if (\n isLiquidityChangeEvent(suiEvent.type) &&\n \"amount\" in suiEventJson &&\n !(\"investor_id\" in suiEventJson)\n ) {\n // Handling NaviLiquidityChangeEvent and AlphaLiquidityChangeEvent\n eventNode = {\n type: suiEvent.type,\n timestamp: Number(suiEvent.timestampMs),\n amount: suiEventJson.amount,\n event_type: suiEventJson.event_type,\n fee_collected: suiEventJson.fee_collected,\n pool_id: suiEventJson.pool_id,\n sender: suiEventJson.sender,\n tokens_invested: suiEventJson.tokens_invested,\n user_total_x_token_balance: suiEventJson.user_total_x_token_balance,\n x_token_supply: suiEventJson.x_token_supply,\n } as LiquidityChangeEventNode;\n } else {\n throw new Error(\"Unknown event type\");\n }\n\n allEvents.push(eventNode);\n }\n\n // If we set hasPreviousPage to false, exit the outer loop as well\n if (!hasNextPage) {\n break;\n }\n\n hasNextPage = result.hasNextPage;\n startCursor = result.nextCursor;\n }\n\n return allEvents;\n}\n\nconst isAutoCompoundingEvent = (eventType: string) => {\n const eventTypes: string[] = Object.values(poolInfo).map((info) => {\n return info.autoCompoundingEventType;\n });\n return eventTypes.includes(eventType);\n};\n\nconst isRebalanceEvent = (eventType: string) => {\n const eventTypes: string[] = Object.values(poolInfo)\n .filter((info) => {\n return info.rebalanceEventType ? true : false;\n })\n .map((info) => {\n return info.rebalanceEventType as string;\n });\n return eventTypes.includes(eventType);\n};\n\nconst isLiquidityChangeEvent = (eventType: string) => {\n const eventTypes: string[] = Object.values(poolInfo).map((info) => {\n return info.liquidityChangeEventType;\n });\n return eventTypes.includes(eventType);\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/sui-sdk/events/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,UAAU,qBAAqB;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,yBAAyB;IACxC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,wBAAwB;IACvC,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAA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C;AAExD,MAAM,MAAM,SAAS,GACjB,wBAAwB,GACxB,kBAAkB,GAClB,wBAAwB,CAAC;AAG7B,MAAM,MAAM,gCAAgC,GAAG;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG,gCAAgC,CAAC;AAE1E,MAAM,MAAM,gCAAgC,GAAG,gCAAgC,CAAC;AAEhF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/sui-sdk/events/types.ts"],"names":[],"mappings":"","sourcesContent":["import { PoolName } from \"../../common/types.js\";\n\ninterface CommonEventAttributes {\n type: string;\n timestamp: number;\n}\n\nexport interface CetusAutoCompoundingEvent {\n compound_amount_a: bigint;\n compound_amount_b: bigint;\n current_liquidity: bigint;\n fee_collected_a: bigint;\n fee_collected_b: bigint;\n free_balance_a: bigint;\n free_balance_b: bigint;\n investor_id: string;\n total_amount_a: bigint;\n total_amount_b: bigint;\n}\n\nexport interface NaviAutoCompoundingEvent {\n compound_amount: bigint;\n fee_collected: bigint;\n investor_id: string;\n location: number;\n total_amount: bigint;\n}\n\nexport interface NaviLoopAutoCompoundingEvent extends NaviAutoCompoundingEvent {\n cur_total_debt: bigint;\n accrued_interest: bigint;\n}\n\nexport interface RebalanceEvent {\n investor_id: string;\n lower_tick_after: string;\n upper_tick_after: string;\n sqrt_price_after: string;\n amount_a_before: string;\n amount_b_before: string;\n amount_a_after: string;\n amount_b_after: string;\n}\n\nexport interface AlphaAutoCompoundingEvent {\n amount: string;\n investor_id: string;\n}\n\nexport interface CetusLiquidityChangeEvent {\n amount_a: string;\n amount_b: string;\n event_type: number;\n fee_collected_a: string;\n fee_collected_b: string;\n pool_id: string;\n sender: string;\n tokens_invested: string;\n total_amount_a: string;\n total_amount_b: string;\n user_total_x_token_balance: string;\n x_token_supply: string;\n}\n\nexport interface NaviLiquidityChangeEvent {\n amount: string;\n event_type: number;\n fee_collected: string;\n pool_id: string;\n sender: string;\n tokens_invested: string;\n user_total_x_token_balance: string;\n x_token_supply: string;\n}\n\nexport interface AlphaLiquidityChangeEvent {\n amount: string;\n event_type: number;\n fee_collected: string;\n pool_id: string;\n sender: string;\n tokens_invested: string;\n user_total_x_token_balance: string;\n x_token_supply: string;\n}\n\nexport type AutoCompoundingEventNode =\n | (CetusAutoCompoundingEvent & CommonEventAttributes)\n | (NaviAutoCompoundingEvent & CommonEventAttributes)\n | (NaviLoopAutoCompoundingEvent & CommonEventAttributes)\n | (AlphaAutoCompoundingEvent & CommonEventAttributes);\n\nexport type RebalanceEventNode = RebalanceEvent & CommonEventAttributes;\n\nexport type LiquidityChangeEventNode =\n | (CetusLiquidityChangeEvent & CommonEventAttributes)\n | (NaviLiquidityChangeEvent & CommonEventAttributes)\n | (AlphaLiquidityChangeEvent & CommonEventAttributes);\n\nexport type EventNode =\n | AutoCompoundingEventNode\n | RebalanceEventNode\n | LiquidityChangeEventNode;\n// export type EventNode = AutoCompoundingEventNode | RebalanceEventNode;\n\nexport type FetchAutoCompoundingEventsParams = {\n startTime?: number;\n endTime?: number;\n poolNames?: PoolName[];\n};\n\nexport type FetchRebalanceEventsParams = FetchAutoCompoundingEventsParams;\n\nexport type FetchLiquidityChangeEventsParams = FetchAutoCompoundingEventsParams;\n\nexport type FetchEventsParams = {\n eventTypes: string[];\n startTime?: number;\n endTime?: number;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/sui-sdk/events/types.ts"],"names":[],"mappings":"","sourcesContent":["import { PoolName } from \"../../common/types.js\";\n\ninterface CommonEventAttributes {\n type: string;\n timestamp: number;\n}\n\nexport interface CetusAutoCompoundingEvent {\n compound_amount_a: bigint;\n compound_amount_b: bigint;\n current_liquidity: bigint;\n fee_collected_a: bigint;\n fee_collected_b: bigint;\n free_balance_a: bigint;\n free_balance_b: bigint;\n investor_id: string;\n total_amount_a: bigint;\n total_amount_b: bigint;\n}\n\nexport interface NaviAutoCompoundingEvent {\n compound_amount: bigint;\n fee_collected: bigint;\n investor_id: string;\n location: number;\n total_amount: bigint;\n}\n\nexport interface NaviLoopAutoCompoundingEvent extends NaviAutoCompoundingEvent {\n cur_total_debt: bigint;\n accrued_interest: bigint;\n}\n\nexport interface RebalanceEvent {\n investor_id: string;\n lower_tick_after: string;\n upper_tick_after: string;\n sqrt_price_after: string;\n amount_a_before: string;\n amount_b_before: string;\n amount_a_after: string;\n amount_b_after: string;\n}\n\n//verify, this might be wrong, alphapool reward event is defined as alpha autocompounding event\nexport interface AlphaAutoCompoundingEvent {\n amount: string;\n investor_id: string;\n}\n\nexport interface CetusLiquidityChangeEvent {\n amount_a: string;\n amount_b: string;\n event_type: number;\n fee_collected_a: string;\n fee_collected_b: string;\n pool_id: string;\n sender: string;\n tokens_invested: string;\n total_amount_a: string;\n total_amount_b: string;\n user_total_x_token_balance: string;\n x_token_supply: string;\n}\n\nexport interface NaviLiquidityChangeEvent {\n amount: string;\n event_type: number;\n fee_collected: string;\n pool_id: string;\n sender: string;\n tokens_invested: string;\n user_total_x_token_balance: string;\n x_token_supply: string;\n}\n\nexport interface AlphaLiquidityChangeEvent {\n amount: string;\n event_type: number;\n fee_collected: string;\n pool_id: string;\n sender: string;\n tokens_invested: string;\n user_total_x_token_balance: string;\n x_token_supply: string;\n}\n\nexport type AutoCompoundingEventNode =\n | (CetusAutoCompoundingEvent & CommonEventAttributes)\n | (NaviAutoCompoundingEvent & CommonEventAttributes)\n | (NaviLoopAutoCompoundingEvent & CommonEventAttributes)\n | (AlphaAutoCompoundingEvent & CommonEventAttributes);\n\nexport type RebalanceEventNode = RebalanceEvent & CommonEventAttributes;\n\nexport type LiquidityChangeEventNode =\n | (CetusLiquidityChangeEvent & CommonEventAttributes)\n | (NaviLiquidityChangeEvent & CommonEventAttributes)\n | (AlphaLiquidityChangeEvent & CommonEventAttributes);\n\nexport type EventNode =\n | AutoCompoundingEventNode\n | RebalanceEventNode\n | LiquidityChangeEventNode;\n// export type EventNode = AutoCompoundingEventNode | RebalanceEventNode;\n\nexport type FetchAutoCompoundingEventsParams = {\n startTime?: number;\n endTime?: number;\n poolNames?: PoolName[];\n};\n\nexport type FetchRebalanceEventsParams = FetchAutoCompoundingEventsParams;\n\nexport type FetchLiquidityChangeEventsParams = FetchAutoCompoundingEventsParams;\n\nexport type FetchEventsParams = {\n eventTypes: string[];\n startTime?: number;\n endTime?: number;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"getPortfolioAmounts.d.ts","sourceRoot":"","sources":["../../../../src/sui-sdk/functions/getPortfolioAmounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAEL,QAAQ,EAIR,oBAAoB,EACrB,MAAM,gBAAgB,CAAC;AAgBxB,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE;IAAE,SAAS,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,+BA+CvE;AAED,wBAAsB,4BAA4B,CAChD,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE;IAAE,SAAS,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,+BASvE;AAMD,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE;IAAE,SAAS,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,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leCache.js";
4
4
  import { coins } from "../../common/coins.js";
5
5
  import { poolCoinMap, poolCoinPairMap } from "../../common/maps.js";
6
- import { getLatestPrice } from "../../utils/prices.js";
7
6
  import { getAlphaPrice } from "../../utils/clmm/prices.js";
7
+ import { getLatestPrices } from "../../utils/prices.js";
8
8
  export async function getAlphaPortfolioAmount(poolName, options) {
9
9
  const receipts = await getReceipts(poolName, options.address);
10
10
  const pool = await getPool(poolName);
@@ -121,8 +121,10 @@ export async function getDoubleAssetPortfolioAmountInUSD(poolName, options, igno
121
121
  const amount0 = new Decimal(amounts[0]).div(ten.pow(coins[pool1].expo));
122
122
  const amount1 = new Decimal(amounts[1]).div(ten.pow(coins[pool2].expo));
123
123
  const tokens = poolName.split("-");
124
- const priceOfCoin0 = await getLatestPrice(`${tokens[0]}/USD`);
125
- const priceOfCoin1 = await getLatestPrice(`${tokens[1]}/USD`);
124
+ const [priceOfCoin0, priceOfCoin1] = await getLatestPrices([
125
+ `${tokens[0]}/USD`,
126
+ `${tokens[1]}/USD`,
127
+ ], false);
126
128
  if (priceOfCoin0 && priceOfCoin1) {
127
129
  const amount = amount0.mul(priceOfCoin0).add(amount1.mul(priceOfCoin1));
128
130
  return amount.toString();
@@ -224,7 +226,9 @@ export async function getSingleAssetPortfolioAmountInUSD(poolName, options, igno
224
226
  const amounts = await getSingleAssetPortfolioAmount(poolName, options, ignoreCache);
225
227
  if (amounts !== undefined) {
226
228
  const amount = new Decimal(amounts).div(new Decimal(Math.pow(10, coins[poolCoinMap[poolName]].expo)));
227
- const priceOfCoin = await getLatestPrice(`${poolCoinMap[poolName]}/USD`);
229
+ const [priceOfCoin] = await getLatestPrices([
230
+ `${poolCoinMap[poolName]}/USD`,
231
+ ], false);
228
232
  if (priceOfCoin) {
229
233
  const amountInUSD = amount.mul(priceOfCoin);
230
234
  return amountInUSD.toString();