@rainlanguage/ui-components 0.0.1-alpha.10

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 (236) hide show
  1. package/README.md +58 -0
  2. package/dist/__fixtures__/orderDetail.d.ts +99 -0
  3. package/dist/__fixtures__/orderDetail.js +204 -0
  4. package/dist/__fixtures__/settings-12-11-24.json +160 -0
  5. package/dist/__mocks__/MockComponent.d.ts +1 -0
  6. package/dist/__mocks__/MockComponent.js +2 -0
  7. package/dist/__mocks__/MockComponent.svelte +3 -0
  8. package/dist/__mocks__/MockComponent.svelte.d.ts +18 -0
  9. package/dist/__mocks__/mockTransactionStore.d.ts +22 -0
  10. package/dist/__mocks__/mockTransactionStore.js +56 -0
  11. package/dist/__mocks__/mockWeb3Config.d.ts +2 -0
  12. package/dist/__mocks__/mockWeb3Config.js +15 -0
  13. package/dist/__mocks__/queries.d.ts +13 -0
  14. package/dist/__mocks__/queries.js +64 -0
  15. package/dist/__mocks__/settings.d.ts +3 -0
  16. package/dist/__mocks__/settings.js +37 -0
  17. package/dist/__mocks__/stores.d.ts +94 -0
  18. package/dist/__mocks__/stores.js +113 -0
  19. package/dist/app.css +3 -0
  20. package/dist/assets/ledger.svg +6 -0
  21. package/dist/assets/logo-dark.svg +15 -0
  22. package/dist/assets/logo-light.svg +15 -0
  23. package/dist/assets/walletconnect.svg +1 -0
  24. package/dist/components/BadgeActive.svelte +9 -0
  25. package/dist/components/BadgeActive.svelte.d.ts +19 -0
  26. package/dist/components/BlockQuote.svelte +1 -0
  27. package/dist/components/BlockQuote.svelte.d.ts +29 -0
  28. package/dist/components/ButtonDarkMode.svelte +14 -0
  29. package/dist/components/ButtonDarkMode.svelte.d.ts +18 -0
  30. package/dist/components/ButtonLoading.svelte +11 -0
  31. package/dist/components/ButtonLoading.svelte.d.ts +24 -0
  32. package/dist/components/ButtonTab.svelte +7 -0
  33. package/dist/components/ButtonTab.svelte.d.ts +23 -0
  34. package/dist/components/ButtonVaultLink.svelte +29 -0
  35. package/dist/components/ButtonVaultLink.svelte.d.ts +22 -0
  36. package/dist/components/CardProperty.svelte +11 -0
  37. package/dist/components/CardProperty.svelte.d.ts +31 -0
  38. package/dist/components/CheckboxMyItemsOnly.svelte +23 -0
  39. package/dist/components/CheckboxMyItemsOnly.svelte.d.ts +21 -0
  40. package/dist/components/CheckboxZeroBalanceVault.svelte +20 -0
  41. package/dist/components/CheckboxZeroBalanceVault.svelte.d.ts +19 -0
  42. package/dist/components/CodeMirrorDotrain.svelte +35 -0
  43. package/dist/components/CodeMirrorDotrain.svelte.d.ts +23 -0
  44. package/dist/components/CodeMirrorRainlang.svelte +34 -0
  45. package/dist/components/CodeMirrorRainlang.svelte.d.ts +23 -0
  46. package/dist/components/DropdownProperty.svelte +12 -0
  47. package/dist/components/DropdownProperty.svelte.d.ts +19 -0
  48. package/dist/components/EditableSpan.svelte +46 -0
  49. package/dist/components/EditableSpan.svelte.d.ts +21 -0
  50. package/dist/components/Hash.svelte +85 -0
  51. package/dist/components/Hash.svelte.d.ts +28 -0
  52. package/dist/components/Heading.svelte +19 -0
  53. package/dist/components/Heading.svelte.d.ts +29 -0
  54. package/dist/components/IconError.svelte +8 -0
  55. package/dist/components/IconError.svelte.d.ts +16 -0
  56. package/dist/components/IconExternalLink.svelte +18 -0
  57. package/dist/components/IconExternalLink.svelte.d.ts +18 -0
  58. package/dist/components/IconInfo.svelte +8 -0
  59. package/dist/components/IconInfo.svelte.d.ts +16 -0
  60. package/dist/components/IconLedger.svelte +13 -0
  61. package/dist/components/IconLedger.svelte.d.ts +16 -0
  62. package/dist/components/IconSuccess.svelte +8 -0
  63. package/dist/components/IconSuccess.svelte.d.ts +16 -0
  64. package/dist/components/IconTelegram.svelte +12 -0
  65. package/dist/components/IconTelegram.svelte.d.ts +25 -0
  66. package/dist/components/IconWalletConnect.svelte +13 -0
  67. package/dist/components/IconWalletConnect.svelte.d.ts +16 -0
  68. package/dist/components/IconWarning.svelte +8 -0
  69. package/dist/components/IconWarning.svelte.d.ts +16 -0
  70. package/dist/components/License.svelte +29 -0
  71. package/dist/components/License.svelte.d.ts +25 -0
  72. package/dist/components/ListViewOrderbookFilters.svelte +58 -0
  73. package/dist/components/ListViewOrderbookFilters.svelte.d.ts +28 -0
  74. package/dist/components/OrderOrVaultHash.svelte +24 -0
  75. package/dist/components/OrderOrVaultHash.svelte.d.ts +22 -0
  76. package/dist/components/PageHeader.svelte +33 -0
  77. package/dist/components/PageHeader.svelte.d.ts +21 -0
  78. package/dist/components/TanstackAppTable.svelte +73 -0
  79. package/dist/components/TanstackAppTable.svelte.d.ts +30 -0
  80. package/dist/components/Text.svelte +12 -0
  81. package/dist/components/Text.svelte.d.ts +31 -0
  82. package/dist/components/charts/APYTimeFilters.svelte +47 -0
  83. package/dist/components/charts/APYTimeFilters.svelte.d.ts +19 -0
  84. package/dist/components/charts/ChartTimeFilters.svelte +35 -0
  85. package/dist/components/charts/ChartTimeFilters.svelte.d.ts +18 -0
  86. package/dist/components/charts/LightweightChart.svelte +110 -0
  87. package/dist/components/charts/LightweightChart.svelte.d.ts +29 -0
  88. package/dist/components/charts/OrderTradesChart.svelte +36 -0
  89. package/dist/components/charts/OrderTradesChart.svelte.d.ts +21 -0
  90. package/dist/components/charts/TableTimeFilters.svelte +48 -0
  91. package/dist/components/charts/TableTimeFilters.svelte.d.ts +19 -0
  92. package/dist/components/charts/TanstackLightweightChartLine.svelte +24 -0
  93. package/dist/components/charts/TanstackLightweightChartLine.svelte.d.ts +23 -0
  94. package/dist/components/charts/VaultBalanceChart.svelte +37 -0
  95. package/dist/components/charts/VaultBalanceChart.svelte.d.ts +22 -0
  96. package/dist/components/checkbox/Checkbox.svelte +17 -0
  97. package/dist/components/checkbox/Checkbox.svelte.d.ts +21 -0
  98. package/dist/components/deployment/ButtonSelectOption.svelte +14 -0
  99. package/dist/components/deployment/ButtonSelectOption.svelte.d.ts +20 -0
  100. package/dist/components/deployment/ComposedRainlangModal.svelte +35 -0
  101. package/dist/components/deployment/ComposedRainlangModal.svelte.d.ts +19 -0
  102. package/dist/components/deployment/DeploymentSectionHeader.svelte +14 -0
  103. package/dist/components/deployment/DeploymentSectionHeader.svelte.d.ts +19 -0
  104. package/dist/components/deployment/DeploymentSteps.svelte +252 -0
  105. package/dist/components/deployment/DeploymentSteps.svelte.d.ts +38 -0
  106. package/dist/components/deployment/DeploymentTile.svelte +19 -0
  107. package/dist/components/deployment/DeploymentTile.svelte.d.ts +21 -0
  108. package/dist/components/deployment/DeploymentsSection.svelte +20 -0
  109. package/dist/components/deployment/DeploymentsSection.svelte.d.ts +19 -0
  110. package/dist/components/deployment/DepositInput.svelte +93 -0
  111. package/dist/components/deployment/DepositInput.svelte.d.ts +20 -0
  112. package/dist/components/deployment/DepositsSection.svelte +8 -0
  113. package/dist/components/deployment/DepositsSection.svelte.d.ts +20 -0
  114. package/dist/components/deployment/DisclaimerModal.svelte +54 -0
  115. package/dist/components/deployment/DisclaimerModal.svelte.d.ts +19 -0
  116. package/dist/components/deployment/FieldDefinitionInput.svelte +66 -0
  117. package/dist/components/deployment/FieldDefinitionInput.svelte.d.ts +20 -0
  118. package/dist/components/deployment/FieldDefinitionsSection.svelte +9 -0
  119. package/dist/components/deployment/FieldDefinitionsSection.svelte.d.ts +20 -0
  120. package/dist/components/deployment/InvalidStrategiesSection.svelte +19 -0
  121. package/dist/components/deployment/InvalidStrategiesSection.svelte.d.ts +19 -0
  122. package/dist/components/deployment/SelectToken.svelte +88 -0
  123. package/dist/components/deployment/SelectToken.svelte.d.ts +21 -0
  124. package/dist/components/deployment/SelectTokensSection.svelte +17 -0
  125. package/dist/components/deployment/SelectTokensSection.svelte.d.ts +21 -0
  126. package/dist/components/deployment/ShareChoicesButton.svelte +26 -0
  127. package/dist/components/deployment/ShareChoicesButton.svelte.d.ts +18 -0
  128. package/dist/components/deployment/StrategyPage.svelte +70 -0
  129. package/dist/components/deployment/StrategyPage.svelte.d.ts +19 -0
  130. package/dist/components/deployment/TokenIOInput.svelte +62 -0
  131. package/dist/components/deployment/TokenIOInput.svelte.d.ts +22 -0
  132. package/dist/components/deployment/TokenIOSection.svelte +17 -0
  133. package/dist/components/deployment/TokenIOSection.svelte.d.ts +21 -0
  134. package/dist/components/deployment/ValidStrategiesSection.svelte +25 -0
  135. package/dist/components/deployment/ValidStrategiesSection.svelte.d.ts +19 -0
  136. package/dist/components/deployment/getDeploymentTransactionArgs.d.ts +17 -0
  137. package/dist/components/deployment/getDeploymentTransactionArgs.js +24 -0
  138. package/dist/components/detail/DepositOrWithdrawButtons.svelte +44 -0
  139. package/dist/components/detail/DepositOrWithdrawButtons.svelte.d.ts +26 -0
  140. package/dist/components/detail/OrderDetail.svelte +195 -0
  141. package/dist/components/detail/OrderDetail.svelte.d.ts +36 -0
  142. package/dist/components/detail/TanstackOrderQuote.svelte +173 -0
  143. package/dist/components/detail/TanstackOrderQuote.svelte.d.ts +22 -0
  144. package/dist/components/detail/TanstackPageContentDetail.svelte +56 -0
  145. package/dist/components/detail/TanstackPageContentDetail.svelte.d.ts +31 -0
  146. package/dist/components/detail/VaultDetail.svelte +178 -0
  147. package/dist/components/detail/VaultDetail.svelte.d.ts +35 -0
  148. package/dist/components/dropdown/DropdownActiveSubgraphs.svelte +38 -0
  149. package/dist/components/dropdown/DropdownActiveSubgraphs.svelte.d.ts +21 -0
  150. package/dist/components/dropdown/DropdownCheckbox.svelte +77 -0
  151. package/dist/components/dropdown/DropdownCheckbox.svelte.d.ts +26 -0
  152. package/dist/components/dropdown/DropdownOrderListAccounts.svelte +15 -0
  153. package/dist/components/dropdown/DropdownOrderListAccounts.svelte.d.ts +20 -0
  154. package/dist/components/dropdown/DropdownOrderStatus.svelte +31 -0
  155. package/dist/components/dropdown/DropdownOrderStatus.svelte.d.ts +19 -0
  156. package/dist/components/dropdown/DropdownRadio.svelte +45 -0
  157. package/dist/components/dropdown/DropdownRadio.svelte.d.ts +30 -0
  158. package/dist/components/icon/RainLogo.svelte +54 -0
  159. package/dist/components/icon/RainLogo.svelte.d.ts +25 -0
  160. package/dist/components/icon/Refresh.svelte +57 -0
  161. package/dist/components/icon/Refresh.svelte.d.ts +40 -0
  162. package/dist/components/input/InputHex.svelte +42 -0
  163. package/dist/components/input/InputHex.svelte.d.ts +19 -0
  164. package/dist/components/input/InputOrderHash.svelte +22 -0
  165. package/dist/components/input/InputOrderHash.svelte.d.ts +20 -0
  166. package/dist/components/input/InputRegistryUrl.svelte +18 -0
  167. package/dist/components/input/InputRegistryUrl.svelte.d.ts +16 -0
  168. package/dist/components/input/InputToken.svelte +53 -0
  169. package/dist/components/input/InputToken.svelte.d.ts +19 -0
  170. package/dist/components/input/InputTokenAmount.svelte +63 -0
  171. package/dist/components/input/InputTokenAmount.svelte.d.ts +21 -0
  172. package/dist/components/tables/OrderAPY.svelte +57 -0
  173. package/dist/components/tables/OrderAPY.svelte.d.ts +19 -0
  174. package/dist/components/tables/OrderTradesListTable.svelte +145 -0
  175. package/dist/components/tables/OrderTradesListTable.svelte.d.ts +21 -0
  176. package/dist/components/tables/OrderVaultsVolTable.svelte +67 -0
  177. package/dist/components/tables/OrderVaultsVolTable.svelte.d.ts +19 -0
  178. package/dist/components/tables/OrdersListTable.svelte +181 -0
  179. package/dist/components/tables/OrdersListTable.svelte.d.ts +35 -0
  180. package/dist/components/tables/VaultBalanceChangesTable.svelte +74 -0
  181. package/dist/components/tables/VaultBalanceChangesTable.svelte.d.ts +17 -0
  182. package/dist/components/tables/VaultsListTable.svelte +229 -0
  183. package/dist/components/tables/VaultsListTable.svelte.d.ts +40 -0
  184. package/dist/components/wallet/WalletConnect.svelte +28 -0
  185. package/dist/components/wallet/WalletConnect.svelte.d.ts +23 -0
  186. package/dist/errors/DeploymentStepsError.d.ts +24 -0
  187. package/dist/errors/DeploymentStepsError.js +45 -0
  188. package/dist/errors/index.d.ts +1 -0
  189. package/dist/errors/index.js +1 -0
  190. package/dist/index.d.ts +89 -0
  191. package/dist/index.js +89 -0
  192. package/dist/queries/constants.d.ts +2 -0
  193. package/dist/queries/constants.js +2 -0
  194. package/dist/queries/keys.d.ts +9 -0
  195. package/dist/queries/keys.js +9 -0
  196. package/dist/queries/queryClient.d.ts +3 -0
  197. package/dist/queries/queryClient.js +16 -0
  198. package/dist/services/getExplorerLink.d.ts +1 -0
  199. package/dist/services/getExplorerLink.js +10 -0
  200. package/dist/services/handleShareChoices.d.ts +2 -0
  201. package/dist/services/handleShareChoices.js +10 -0
  202. package/dist/services/historicalOrderCharts.d.ts +12 -0
  203. package/dist/services/historicalOrderCharts.js +496 -0
  204. package/dist/services/index.d.ts +2 -0
  205. package/dist/services/index.js +1 -0
  206. package/dist/services/registry.d.ts +25 -0
  207. package/dist/services/registry.js +133 -0
  208. package/dist/services/time.d.ts +6 -0
  209. package/dist/services/time.js +17 -0
  210. package/dist/stores/transactionStore.d.ts +98 -0
  211. package/dist/stores/transactionStore.js +303 -0
  212. package/dist/test/matchers.d.ts +6 -0
  213. package/dist/test/matchers.js +4 -0
  214. package/dist/types/appStores.d.ts +19 -0
  215. package/dist/types/appStores.js +1 -0
  216. package/dist/types/modal.d.ts +20 -0
  217. package/dist/types/modal.js +1 -0
  218. package/dist/types/strategy.d.ts +10 -0
  219. package/dist/types/strategy.js +1 -0
  220. package/dist/types/transaction.d.ts +27 -0
  221. package/dist/types/transaction.js +1 -0
  222. package/dist/utils/breadcrumbs.d.ts +5 -0
  223. package/dist/utils/breadcrumbs.js +9 -0
  224. package/dist/utils/codeMirrorThemes.d.ts +2 -0
  225. package/dist/utils/codeMirrorThemes.js +86 -0
  226. package/dist/utils/hex.d.ts +2 -0
  227. package/dist/utils/hex.js +3 -0
  228. package/dist/utils/lightweightChartsThemes.d.ts +52 -0
  229. package/dist/utils/lightweightChartsThemes.js +21 -0
  230. package/dist/utils/number.d.ts +14 -0
  231. package/dist/utils/number.js +43 -0
  232. package/dist/utils/time.d.ts +12 -0
  233. package/dist/utils/time.js +27 -0
  234. package/dist/utils/vault.d.ts +2 -0
  235. package/dist/utils/vault.js +29 -0
  236. package/package.json +86 -0
@@ -0,0 +1,496 @@
1
+ import { timestampSecondsToUTCTimestamp } from '../utils/time';
2
+ import { sortBy } from 'lodash';
3
+ import { formatUnits } from 'viem';
4
+ export function prepareHistoricalOrderChartData(takeOrderEntities, colorTheme) {
5
+ const transformedData = takeOrderEntities.map((d) => ({
6
+ value: Math.abs(Number(formatUnits(BigInt(d.inputVaultBalanceChange.amount), Number(d.inputVaultBalanceChange.vault.token.decimals ?? 0))) /
7
+ Number(formatUnits(BigInt(d.outputVaultBalanceChange.amount), Number(d.outputVaultBalanceChange.vault.token.decimals ?? 0)))),
8
+ time: timestampSecondsToUTCTimestamp(BigInt(d.timestamp)),
9
+ color: colorTheme == 'dark' ? '#5178FF' : '#4E4AF6',
10
+ outputAmount: +d.outputVaultBalanceChange.amount
11
+ }));
12
+ // if we have multiple object in the array with the same timestamp, we need to merge them
13
+ // we do this by taking the weighted average of the ioratio values for objects that share the same timestamp.
14
+ const uniqueTimestamps = Array.from(new Set(transformedData.map((d) => d.time)));
15
+ const finalData = [];
16
+ uniqueTimestamps.forEach((timestamp) => {
17
+ const objectsWithSameTimestamp = transformedData.filter((d) => d.time === timestamp);
18
+ if (objectsWithSameTimestamp.length > 1) {
19
+ // calculate a weighted average of the ioratio values using the amount of the output token as the weight
20
+ const ioratioSum = objectsWithSameTimestamp.reduce((acc, d) => acc + d.value * d.outputAmount, 0);
21
+ const outputAmountSum = objectsWithSameTimestamp.reduce((acc, d) => acc + d.outputAmount, 0);
22
+ const ioratioAverage = ioratioSum / outputAmountSum;
23
+ finalData.push({
24
+ value: ioratioAverage,
25
+ time: timestamp,
26
+ color: objectsWithSameTimestamp[0].color
27
+ });
28
+ }
29
+ else {
30
+ finalData.push(objectsWithSameTimestamp[0]);
31
+ }
32
+ });
33
+ return sortBy(finalData, (d) => d.time);
34
+ }
35
+ if (import.meta.vitest) {
36
+ const { it, expect } = import.meta.vitest;
37
+ it('transforms and sorts data as expected', () => {
38
+ const takeOrderEntities = [
39
+ {
40
+ id: '1',
41
+ timestamp: '1632000000',
42
+ tradeEvent: {
43
+ sender: 'sender_address',
44
+ transaction: {
45
+ id: 'transaction_id',
46
+ from: 'sender_address',
47
+ timestamp: '1632000000',
48
+ blockNumber: '0'
49
+ }
50
+ },
51
+ outputVaultBalanceChange: {
52
+ amount: '100',
53
+ vault: {
54
+ id: '1',
55
+ vaultId: 'vault-id1',
56
+ token: {
57
+ id: 'output_token',
58
+ address: 'output_token',
59
+ name: 'output_token',
60
+ symbol: 'output_token',
61
+ decimals: '1'
62
+ }
63
+ },
64
+ id: '1',
65
+ __typename: 'Withdraw',
66
+ newVaultBalance: '0',
67
+ oldVaultBalance: '0',
68
+ timestamp: '0',
69
+ transaction: {
70
+ id: 'transaction_id',
71
+ from: 'sender_address',
72
+ timestamp: '1632000000',
73
+ blockNumber: '0'
74
+ },
75
+ orderbook: { id: '1' }
76
+ },
77
+ order: {
78
+ id: 'order_id',
79
+ orderHash: 'orderHash'
80
+ },
81
+ inputVaultBalanceChange: {
82
+ vault: {
83
+ id: '1',
84
+ vaultId: 'vault-id1',
85
+ token: {
86
+ id: 'output_token',
87
+ address: 'output_token',
88
+ name: 'output_token',
89
+ symbol: 'output_token',
90
+ decimals: '1'
91
+ }
92
+ },
93
+ amount: '50',
94
+ id: '1',
95
+ __typename: 'Withdraw',
96
+ newVaultBalance: '0',
97
+ oldVaultBalance: '0',
98
+ timestamp: '0',
99
+ transaction: {
100
+ id: 'transaction_id',
101
+ from: 'sender_address',
102
+ timestamp: '1632000000',
103
+ blockNumber: '0'
104
+ },
105
+ orderbook: { id: '1' }
106
+ },
107
+ orderbook: {
108
+ id: '0x00'
109
+ }
110
+ },
111
+ {
112
+ id: '2',
113
+ timestamp: '1631000000',
114
+ tradeEvent: {
115
+ sender: 'sender_address',
116
+ transaction: {
117
+ id: 'transaction_id',
118
+ from: 'sender_address',
119
+ timestamp: '1631000000',
120
+ blockNumber: '0'
121
+ }
122
+ },
123
+ outputVaultBalanceChange: {
124
+ amount: '100',
125
+ vault: {
126
+ id: '1',
127
+ vaultId: 'vault-id1',
128
+ token: {
129
+ id: 'output_token',
130
+ address: 'output_token',
131
+ name: 'output_token',
132
+ symbol: 'output_token',
133
+ decimals: '1'
134
+ }
135
+ },
136
+ id: '1',
137
+ __typename: 'Withdraw',
138
+ newVaultBalance: '0',
139
+ oldVaultBalance: '0',
140
+ timestamp: '0',
141
+ transaction: {
142
+ id: 'transaction_id',
143
+ from: 'sender_address',
144
+ timestamp: '1632000000',
145
+ blockNumber: '0'
146
+ },
147
+ orderbook: { id: '1' }
148
+ },
149
+ order: {
150
+ id: 'order_id',
151
+ orderHash: 'orderHash'
152
+ },
153
+ inputVaultBalanceChange: {
154
+ vault: {
155
+ id: '1',
156
+ vaultId: 'vault-id1',
157
+ token: {
158
+ id: 'output_token',
159
+ address: 'output_token',
160
+ name: 'output_token',
161
+ symbol: 'output_token',
162
+ decimals: '1'
163
+ }
164
+ },
165
+ amount: '50',
166
+ id: '1',
167
+ __typename: 'Withdraw',
168
+ newVaultBalance: '0',
169
+ oldVaultBalance: '0',
170
+ timestamp: '0',
171
+ transaction: {
172
+ id: 'transaction_id',
173
+ from: 'sender_address',
174
+ timestamp: '1632000000',
175
+ blockNumber: '0'
176
+ },
177
+ orderbook: { id: '1' }
178
+ },
179
+ orderbook: {
180
+ id: '0x00'
181
+ }
182
+ },
183
+ {
184
+ id: '3',
185
+ timestamp: '1630000000',
186
+ tradeEvent: {
187
+ sender: 'sender_address',
188
+ transaction: {
189
+ id: 'transaction_id',
190
+ from: 'sender_address',
191
+ timestamp: '1630000000',
192
+ blockNumber: '0'
193
+ }
194
+ },
195
+ outputVaultBalanceChange: {
196
+ amount: '100',
197
+ vault: {
198
+ id: '1',
199
+ vaultId: 'vault-id1',
200
+ token: {
201
+ id: 'output_token',
202
+ address: 'output_token',
203
+ name: 'output_token',
204
+ symbol: 'output_token',
205
+ decimals: '1'
206
+ }
207
+ },
208
+ id: '1',
209
+ __typename: 'Withdraw',
210
+ newVaultBalance: '0',
211
+ oldVaultBalance: '0',
212
+ timestamp: '0',
213
+ transaction: {
214
+ id: 'transaction_id',
215
+ from: 'sender_address',
216
+ timestamp: '1632000000',
217
+ blockNumber: '0'
218
+ },
219
+ orderbook: { id: '1' }
220
+ },
221
+ order: {
222
+ id: 'order_id',
223
+ orderHash: 'orderHash'
224
+ },
225
+ inputVaultBalanceChange: {
226
+ vault: {
227
+ id: '1',
228
+ vaultId: 'vault-id1',
229
+ token: {
230
+ id: 'output_token',
231
+ address: 'output_token',
232
+ name: 'output_token',
233
+ symbol: 'output_token',
234
+ decimals: '1'
235
+ }
236
+ },
237
+ amount: '50',
238
+ id: '1',
239
+ __typename: 'Withdraw',
240
+ newVaultBalance: '0',
241
+ oldVaultBalance: '0',
242
+ timestamp: '0',
243
+ transaction: {
244
+ id: 'transaction_id',
245
+ from: 'sender_address',
246
+ timestamp: '1632000000',
247
+ blockNumber: '0'
248
+ },
249
+ orderbook: { id: '1' }
250
+ },
251
+ orderbook: {
252
+ id: '0x00'
253
+ }
254
+ }
255
+ ];
256
+ const result = prepareHistoricalOrderChartData(takeOrderEntities, 'dark');
257
+ expect(result.length).toEqual(3);
258
+ expect(result[0].value).toEqual(0.5);
259
+ expect(result[0].time).toEqual(1630000000);
260
+ expect(result[1].value).toEqual(0.5);
261
+ expect(result[1].time).toEqual(1631000000);
262
+ expect(result[2].value).toEqual(0.5);
263
+ expect(result[2].time).toEqual(1632000000);
264
+ // check the color
265
+ expect(result[0].color).toEqual('#5178FF');
266
+ expect(result[1].color).toEqual('#5178FF');
267
+ expect(result[2].color).toEqual('#5178FF');
268
+ });
269
+ it('handles the case where multiple trades have the same timestamp', () => {
270
+ const takeOrderEntities = [
271
+ {
272
+ id: '1',
273
+ timestamp: '1632000000',
274
+ tradeEvent: {
275
+ sender: 'sender_address',
276
+ transaction: {
277
+ id: 'transaction_id',
278
+ from: 'sender_address',
279
+ timestamp: '1632000000',
280
+ blockNumber: '0'
281
+ }
282
+ },
283
+ outputVaultBalanceChange: {
284
+ amount: '100',
285
+ vault: {
286
+ id: '1',
287
+ vaultId: 'vault-id1',
288
+ token: {
289
+ id: 'output_token',
290
+ address: 'output_token',
291
+ name: 'output_token',
292
+ symbol: 'output_token',
293
+ decimals: '1'
294
+ }
295
+ },
296
+ id: '1',
297
+ __typename: 'Withdraw',
298
+ newVaultBalance: '0',
299
+ oldVaultBalance: '0',
300
+ timestamp: '0',
301
+ transaction: {
302
+ id: 'transaction_id',
303
+ from: 'sender_address',
304
+ timestamp: '1632000000',
305
+ blockNumber: '0'
306
+ },
307
+ orderbook: { id: '1' }
308
+ },
309
+ order: {
310
+ id: 'order_id',
311
+ orderHash: 'orderHash'
312
+ },
313
+ inputVaultBalanceChange: {
314
+ vault: {
315
+ id: '1',
316
+ vaultId: 'vault-id1',
317
+ token: {
318
+ id: 'output_token',
319
+ address: 'output_token',
320
+ name: 'output_token',
321
+ symbol: 'output_token',
322
+ decimals: '1'
323
+ }
324
+ },
325
+ amount: '50',
326
+ id: '1',
327
+ __typename: 'Withdraw',
328
+ newVaultBalance: '0',
329
+ oldVaultBalance: '0',
330
+ timestamp: '0',
331
+ transaction: {
332
+ id: 'transaction_id',
333
+ from: 'sender_address',
334
+ timestamp: '1632000000',
335
+ blockNumber: '0'
336
+ },
337
+ orderbook: { id: '1' }
338
+ },
339
+ orderbook: {
340
+ id: '0x00'
341
+ }
342
+ },
343
+ {
344
+ id: '2',
345
+ timestamp: '1632000000',
346
+ tradeEvent: {
347
+ sender: 'sender_address',
348
+ transaction: {
349
+ id: 'transaction_id',
350
+ from: 'sender_address',
351
+ timestamp: '1632000000',
352
+ blockNumber: '0'
353
+ }
354
+ },
355
+ outputVaultBalanceChange: {
356
+ amount: '200',
357
+ vault: {
358
+ id: '1',
359
+ vaultId: 'vault-id1',
360
+ token: {
361
+ id: 'output_token',
362
+ address: 'output_token',
363
+ name: 'output_token',
364
+ symbol: 'output_token',
365
+ decimals: '1'
366
+ }
367
+ },
368
+ id: '1',
369
+ __typename: 'Withdraw',
370
+ newVaultBalance: '0',
371
+ oldVaultBalance: '0',
372
+ timestamp: '0',
373
+ transaction: {
374
+ id: 'transaction_id',
375
+ from: 'sender_address',
376
+ timestamp: '1632000000',
377
+ blockNumber: '0'
378
+ },
379
+ orderbook: { id: '1' }
380
+ },
381
+ order: {
382
+ id: 'order_id',
383
+ orderHash: 'orderHash'
384
+ },
385
+ inputVaultBalanceChange: {
386
+ vault: {
387
+ id: '1',
388
+ vaultId: 'vault-id1',
389
+ token: {
390
+ id: 'output_token',
391
+ address: 'output_token',
392
+ name: 'output_token',
393
+ symbol: 'output_token',
394
+ decimals: '1'
395
+ }
396
+ },
397
+ amount: '50',
398
+ id: '1',
399
+ __typename: 'Withdraw',
400
+ newVaultBalance: '0',
401
+ oldVaultBalance: '0',
402
+ timestamp: '0',
403
+ transaction: {
404
+ id: 'transaction_id',
405
+ from: 'sender_address',
406
+ timestamp: '1632000000',
407
+ blockNumber: '0'
408
+ },
409
+ orderbook: { id: '1' }
410
+ },
411
+ orderbook: {
412
+ id: '0x00'
413
+ }
414
+ },
415
+ {
416
+ id: '3',
417
+ timestamp: '1632000000',
418
+ tradeEvent: {
419
+ sender: 'sender_address',
420
+ transaction: {
421
+ id: 'transaction_id',
422
+ from: 'sender_address',
423
+ timestamp: '1632000000',
424
+ blockNumber: '0'
425
+ }
426
+ },
427
+ outputVaultBalanceChange: {
428
+ amount: '400',
429
+ vault: {
430
+ id: '1',
431
+ vaultId: 'vault-id1',
432
+ token: {
433
+ id: 'output_token',
434
+ address: 'output_token',
435
+ name: 'output_token',
436
+ symbol: 'output_token',
437
+ decimals: '1'
438
+ }
439
+ },
440
+ id: '1',
441
+ __typename: 'Withdraw',
442
+ newVaultBalance: '0',
443
+ oldVaultBalance: '0',
444
+ timestamp: '0',
445
+ transaction: {
446
+ id: 'transaction_id',
447
+ from: 'sender_address',
448
+ timestamp: '1632000000',
449
+ blockNumber: '0'
450
+ },
451
+ orderbook: { id: '1' }
452
+ },
453
+ order: {
454
+ id: 'order_id',
455
+ orderHash: 'orderHash'
456
+ },
457
+ inputVaultBalanceChange: {
458
+ vault: {
459
+ id: '1',
460
+ vaultId: 'vault-id1',
461
+ token: {
462
+ id: 'output_token',
463
+ address: 'output_token',
464
+ name: 'output_token',
465
+ symbol: 'output_token',
466
+ decimals: '1'
467
+ }
468
+ },
469
+ amount: '50',
470
+ id: '1',
471
+ __typename: 'Withdraw',
472
+ newVaultBalance: '0',
473
+ oldVaultBalance: '0',
474
+ timestamp: '0',
475
+ transaction: {
476
+ id: 'transaction_id',
477
+ from: 'sender_address',
478
+ timestamp: '1632000000',
479
+ blockNumber: '0'
480
+ },
481
+ orderbook: { id: '1' }
482
+ },
483
+ orderbook: {
484
+ id: '0x00'
485
+ }
486
+ }
487
+ ];
488
+ const result = prepareHistoricalOrderChartData(takeOrderEntities, 'dark');
489
+ // calculate the weighted average of the ioratio values
490
+ const ioratioSum = 0.5 * 100 + 0.25 * 200 + 0.125 * 400;
491
+ const outputAmountSum = 100 + 200 + 400;
492
+ const ioratioAverage = ioratioSum / outputAmountSum;
493
+ expect(result.length).toEqual(1);
494
+ expect(result[0].value).toEqual(ioratioAverage);
495
+ });
496
+ }
@@ -0,0 +1,2 @@
1
+ export { fetchParseRegistry, fetchRegistryDotrains } from './registry';
2
+ export type { RegistryDotrain, RegistryFile } from './registry';
@@ -0,0 +1 @@
1
+ export { fetchParseRegistry, fetchRegistryDotrains } from './registry';
@@ -0,0 +1,25 @@
1
+ export type RegistryFile = {
2
+ name: string;
3
+ url: string;
4
+ };
5
+ export type RegistryDotrain = {
6
+ name: string;
7
+ dotrain: string;
8
+ };
9
+ /**
10
+ * Fetches and parses a file registry from a given URL.
11
+ * The registry is expected to be a text file where each line contains a file name and URL separated by a space.
12
+ *
13
+ * @param url - The URL of the registry file to fetch
14
+ * @returns A Promise that resolves to an array of objects containing file names and their corresponding URLs
15
+ * @throws Will throw an error if the fetch fails, if the response is not ok, or if the registry format is invalid
16
+ *
17
+ * @example
18
+ * const files = await fetchParseRegistryFile('https://example.com/registry');
19
+ * // Returns: [{ name: 'file1', url: 'https://example.com/file1.rain' }, ...]
20
+ */
21
+ export declare const fetchParseRegistry: (url: string) => Promise<{
22
+ name: string;
23
+ url: string;
24
+ }[]>;
25
+ export declare const fetchRegistryDotrains: (url: string) => Promise<RegistryDotrain[]>;
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Fetches and parses a file registry from a given URL.
3
+ * The registry is expected to be a text file where each line contains a file name and URL separated by a space.
4
+ *
5
+ * @param url - The URL of the registry file to fetch
6
+ * @returns A Promise that resolves to an array of objects containing file names and their corresponding URLs
7
+ * @throws Will throw an error if the fetch fails, if the response is not ok, or if the registry format is invalid
8
+ *
9
+ * @example
10
+ * const files = await fetchParseRegistryFile('https://example.com/registry');
11
+ * // Returns: [{ name: 'file1', url: 'https://example.com/file1.rain' }, ...]
12
+ */
13
+ export const fetchParseRegistry = async (url) => {
14
+ try {
15
+ const response = await fetch(url);
16
+ if (!response.ok) {
17
+ throw new Error('Failed to fetch registry.');
18
+ }
19
+ const filesList = await response.text();
20
+ const files = filesList
21
+ .split('\n')
22
+ .filter((line) => line.trim())
23
+ .map((line) => {
24
+ const [name, url] = line.split(' ');
25
+ return { name, url };
26
+ });
27
+ if (!files) {
28
+ throw new Error('Invalid stategy registry.');
29
+ }
30
+ return files;
31
+ }
32
+ catch (e) {
33
+ throw new Error(e instanceof Error ? e.message : 'Unknown error.');
34
+ }
35
+ };
36
+ export const fetchRegistryDotrains = async (url) => {
37
+ const files = await fetchParseRegistry(url);
38
+ const dotrains = await Promise.all(files.map(async (file) => {
39
+ try {
40
+ const response = await fetch(file.url);
41
+ if (!response.ok) {
42
+ throw new Error(`Failed to fetch dotrain for ${file.name}`);
43
+ }
44
+ const dotrain = await response.text();
45
+ return { name: file.name, dotrain };
46
+ }
47
+ catch (e) {
48
+ throw new Error(e instanceof Error
49
+ ? `Error fetching dotrain for ${file.name}: ${e.message}`
50
+ : `Unknown error fetching dotrain for ${file.name}`);
51
+ }
52
+ }));
53
+ return dotrains;
54
+ };
55
+ if (import.meta.vitest) {
56
+ const { describe, it, expect, vi } = import.meta.vitest;
57
+ describe('getFileRegistry', () => {
58
+ it('should parse registry file content correctly', async () => {
59
+ const mockResponse = `file1.js https://example.com/file1.js
60
+ file2.js https://example.com/file2.js`;
61
+ global.fetch = vi.fn().mockResolvedValue({
62
+ ok: true,
63
+ text: () => Promise.resolve(mockResponse)
64
+ });
65
+ const result = await fetchParseRegistry('https://example.com/registry');
66
+ expect(result).toEqual([
67
+ { name: 'file1.js', url: 'https://example.com/file1.js' },
68
+ { name: 'file2.js', url: 'https://example.com/file2.js' }
69
+ ]);
70
+ });
71
+ it('should handle failed fetch response', async () => {
72
+ global.fetch = vi.fn().mockResolvedValue({
73
+ ok: false
74
+ });
75
+ await expect(fetchParseRegistry('https://example.com/registry')).rejects.toThrow('Failed to fetch registry');
76
+ });
77
+ it('should handle network errors', async () => {
78
+ global.fetch = vi.fn().mockRejectedValue(new Error('Network error'));
79
+ await expect(fetchParseRegistry('https://example.com/registry')).rejects.toThrow('Network error');
80
+ });
81
+ });
82
+ describe('fetchRegistryDotrains', () => {
83
+ it('should fetch and parse dotrains correctly', async () => {
84
+ const mockRegistry = `file1.rain https://example.com/file1.rain
85
+ file2.rain https://example.com/file2.rain`;
86
+ const mockDotrain1 = 'content of file1';
87
+ const mockDotrain2 = 'content of file2';
88
+ global.fetch = vi
89
+ .fn()
90
+ .mockResolvedValueOnce({
91
+ ok: true,
92
+ text: () => Promise.resolve(mockRegistry)
93
+ })
94
+ .mockResolvedValueOnce({
95
+ ok: true,
96
+ text: () => Promise.resolve(mockDotrain1)
97
+ })
98
+ .mockResolvedValueOnce({
99
+ ok: true,
100
+ text: () => Promise.resolve(mockDotrain2)
101
+ });
102
+ const result = await fetchRegistryDotrains('https://example.com/registry');
103
+ expect(result).toEqual([
104
+ { name: 'file1.rain', dotrain: mockDotrain1 },
105
+ { name: 'file2.rain', dotrain: mockDotrain2 }
106
+ ]);
107
+ });
108
+ it('should handle failed dotrain fetch', async () => {
109
+ const mockRegistry = `file1.rain https://example.com/file1.rain`;
110
+ global.fetch = vi
111
+ .fn()
112
+ .mockResolvedValueOnce({
113
+ ok: true,
114
+ text: () => Promise.resolve(mockRegistry)
115
+ })
116
+ .mockResolvedValueOnce({
117
+ ok: false
118
+ });
119
+ await expect(fetchRegistryDotrains('https://example.com/registry')).rejects.toThrow('Failed to fetch dotrain for file1.rain');
120
+ });
121
+ it('should handle network errors during dotrain fetch', async () => {
122
+ const mockRegistry = `file1.rain https://example.com/file1.rain`;
123
+ global.fetch = vi
124
+ .fn()
125
+ .mockResolvedValueOnce({
126
+ ok: true,
127
+ text: () => Promise.resolve(mockRegistry)
128
+ })
129
+ .mockRejectedValueOnce(new Error('Network error'));
130
+ await expect(fetchRegistryDotrains('https://example.com/registry')).rejects.toThrow('Error fetching dotrain for file1.rain: Network error');
131
+ });
132
+ });
133
+ }
@@ -0,0 +1,6 @@
1
+ export declare const TIME_DELTA_24_HOURS: number;
2
+ export declare const TIME_DELTA_48_HOURS: number;
3
+ export declare const TIME_DELTA_7_DAYS: number;
4
+ export declare const TIME_DELTA_30_DAYS: number;
5
+ export declare const TIME_DELTA_1_YEAR: number;
6
+ export declare function dateTimestamp(date: Date): number;
@@ -0,0 +1,17 @@
1
+ export const TIME_DELTA_24_HOURS = 60 * 60 * 24;
2
+ export const TIME_DELTA_48_HOURS = TIME_DELTA_24_HOURS * 2;
3
+ export const TIME_DELTA_7_DAYS = TIME_DELTA_24_HOURS * 7;
4
+ export const TIME_DELTA_30_DAYS = TIME_DELTA_24_HOURS * 30;
5
+ export const TIME_DELTA_1_YEAR = TIME_DELTA_24_HOURS * 365;
6
+ export function dateTimestamp(date) {
7
+ return Math.floor(date.getTime() / 1000);
8
+ }
9
+ if (import.meta.vitest) {
10
+ const { it, expect } = import.meta.vitest;
11
+ it('should get date timestamp in seconds', () => {
12
+ const date = new Date(2022, 1, 16, 17, 32, 11, 168);
13
+ const result = dateTimestamp(date);
14
+ const expected = Math.floor(date.getTime() / 1000);
15
+ expect(result).toEqual(expected);
16
+ });
17
+ }