@0xtorch/core 0.0.1

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 (241) hide show
  1. package/README.md +15 -0
  2. package/dist/import/accounts/index.d.ts +2 -0
  3. package/dist/import/accounts/index.d.ts.map +1 -0
  4. package/dist/import/accounts/types/account.d.ts +6 -0
  5. package/dist/import/accounts/types/account.d.ts.map +1 -0
  6. package/dist/import/accounts/types/index.d.ts +2 -0
  7. package/dist/import/accounts/types/index.d.ts.map +1 -0
  8. package/dist/import/actions/index.d.ts +2 -0
  9. package/dist/import/actions/index.d.ts.map +1 -0
  10. package/dist/import/actions/types/addLiquidity.d.ts +7 -0
  11. package/dist/import/actions/types/addLiquidity.d.ts.map +1 -0
  12. package/dist/import/actions/types/atomicArbitrage.d.ts +5 -0
  13. package/dist/import/actions/types/atomicArbitrage.d.ts.map +1 -0
  14. package/dist/import/actions/types/bridgeFrom.d.ts +6 -0
  15. package/dist/import/actions/types/bridgeFrom.d.ts.map +1 -0
  16. package/dist/import/actions/types/bridgeTo.d.ts +6 -0
  17. package/dist/import/actions/types/bridgeTo.d.ts.map +1 -0
  18. package/dist/import/actions/types/buyNft.d.ts +7 -0
  19. package/dist/import/actions/types/buyNft.d.ts.map +1 -0
  20. package/dist/import/actions/types/common.d.ts +50 -0
  21. package/dist/import/actions/types/common.d.ts.map +1 -0
  22. package/dist/import/actions/types/deposit.d.ts +6 -0
  23. package/dist/import/actions/types/deposit.d.ts.map +1 -0
  24. package/dist/import/actions/types/depositWithBond.d.ts +7 -0
  25. package/dist/import/actions/types/depositWithBond.d.ts.map +1 -0
  26. package/dist/import/actions/types/freeMintNft.d.ts +8 -0
  27. package/dist/import/actions/types/freeMintNft.d.ts.map +1 -0
  28. package/dist/import/actions/types/income.d.ts +5 -0
  29. package/dist/import/actions/types/income.d.ts.map +1 -0
  30. package/dist/import/actions/types/index.d.ts +24 -0
  31. package/dist/import/actions/types/index.d.ts.map +1 -0
  32. package/dist/import/actions/types/move.d.ts +5 -0
  33. package/dist/import/actions/types/move.d.ts.map +1 -0
  34. package/dist/import/actions/types/nftRoyalty.d.ts +7 -0
  35. package/dist/import/actions/types/nftRoyalty.d.ts.map +1 -0
  36. package/dist/import/actions/types/removeLiquidity.d.ts +7 -0
  37. package/dist/import/actions/types/removeLiquidity.d.ts.map +1 -0
  38. package/dist/import/actions/types/sellNft.d.ts +6 -0
  39. package/dist/import/actions/types/sellNft.d.ts.map +1 -0
  40. package/dist/import/actions/types/spam.d.ts +6 -0
  41. package/dist/import/actions/types/spam.d.ts.map +1 -0
  42. package/dist/import/actions/types/swapIncome.d.ts +4 -0
  43. package/dist/import/actions/types/swapIncome.d.ts.map +1 -0
  44. package/dist/import/actions/types/swapNft.d.ts +6 -0
  45. package/dist/import/actions/types/swapNft.d.ts.map +1 -0
  46. package/dist/import/actions/types/swapTransfer.d.ts +4 -0
  47. package/dist/import/actions/types/swapTransfer.d.ts.map +1 -0
  48. package/dist/import/actions/types/trade.d.ts +7 -0
  49. package/dist/import/actions/types/trade.d.ts.map +1 -0
  50. package/dist/import/actions/types/transactionFee.d.ts +7 -0
  51. package/dist/import/actions/types/transactionFee.d.ts.map +1 -0
  52. package/dist/import/actions/types/transfer.d.ts +8 -0
  53. package/dist/import/actions/types/transfer.d.ts.map +1 -0
  54. package/dist/import/actions/types/withdraw.d.ts +7 -0
  55. package/dist/import/actions/types/withdraw.d.ts.map +1 -0
  56. package/dist/import/actions/types/withdrawWithBond.d.ts +7 -0
  57. package/dist/import/actions/types/withdrawWithBond.d.ts.map +1 -0
  58. package/dist/import/apps/index.d.ts +3 -0
  59. package/dist/import/apps/index.d.ts.map +1 -0
  60. package/dist/import/apps/types.d.ts +11 -0
  61. package/dist/import/apps/types.d.ts.map +1 -0
  62. package/dist/import/assets/constants.d.ts +2 -0
  63. package/dist/import/assets/constants.d.ts.map +1 -0
  64. package/dist/import/assets/creates/createCryptoCurrency.d.ts +3 -0
  65. package/dist/import/assets/creates/createCryptoCurrency.d.ts.map +1 -0
  66. package/dist/import/assets/creates/createFiatCurrency.d.ts +3 -0
  67. package/dist/import/assets/creates/createFiatCurrency.d.ts.map +1 -0
  68. package/dist/import/assets/creates/index.d.ts +3 -0
  69. package/dist/import/assets/creates/index.d.ts.map +1 -0
  70. package/dist/import/assets/definitions/astar.d.ts +13 -0
  71. package/dist/import/assets/definitions/astar.d.ts.map +1 -0
  72. package/dist/import/assets/definitions/avalanche.d.ts +13 -0
  73. package/dist/import/assets/definitions/avalanche.d.ts.map +1 -0
  74. package/dist/import/assets/definitions/bnb.d.ts +13 -0
  75. package/dist/import/assets/definitions/bnb.d.ts.map +1 -0
  76. package/dist/import/assets/definitions/coingeckoCryptoCurrencyDataSource.d.ts +18 -0
  77. package/dist/import/assets/definitions/coingeckoCryptoCurrencyDataSource.d.ts.map +1 -0
  78. package/dist/import/assets/definitions/ethereum.d.ts +13 -0
  79. package/dist/import/assets/definitions/ethereum.d.ts.map +1 -0
  80. package/dist/import/assets/definitions/eur.d.ts +8 -0
  81. package/dist/import/assets/definitions/eur.d.ts.map +1 -0
  82. package/dist/import/assets/definitions/fantom.d.ts +13 -0
  83. package/dist/import/assets/definitions/fantom.d.ts.map +1 -0
  84. package/dist/import/assets/definitions/index.d.ts +17 -0
  85. package/dist/import/assets/definitions/index.d.ts.map +1 -0
  86. package/dist/import/assets/definitions/jpy.d.ts +8 -0
  87. package/dist/import/assets/definitions/jpy.d.ts.map +1 -0
  88. package/dist/import/assets/definitions/kava.d.ts +13 -0
  89. package/dist/import/assets/definitions/kava.d.ts.map +1 -0
  90. package/dist/import/assets/definitions/mantle.d.ts +13 -0
  91. package/dist/import/assets/definitions/mantle.d.ts.map +1 -0
  92. package/dist/import/assets/definitions/maticNetwork.d.ts +13 -0
  93. package/dist/import/assets/definitions/maticNetwork.d.ts.map +1 -0
  94. package/dist/import/assets/definitions/metis.d.ts +13 -0
  95. package/dist/import/assets/definitions/metis.d.ts.map +1 -0
  96. package/dist/import/assets/definitions/moonbeam.d.ts +13 -0
  97. package/dist/import/assets/definitions/moonbeam.d.ts.map +1 -0
  98. package/dist/import/assets/definitions/moonriver.d.ts +13 -0
  99. package/dist/import/assets/definitions/moonriver.d.ts.map +1 -0
  100. package/dist/import/assets/definitions/ronin.d.ts +13 -0
  101. package/dist/import/assets/definitions/ronin.d.ts.map +1 -0
  102. package/dist/import/assets/definitions/usd.d.ts +8 -0
  103. package/dist/import/assets/definitions/usd.d.ts.map +1 -0
  104. package/dist/import/assets/externals/coingecko/constants.d.ts +2 -0
  105. package/dist/import/assets/externals/coingecko/constants.d.ts.map +1 -0
  106. package/dist/import/assets/externals/coingecko/getAutoRetry.d.ts +4 -0
  107. package/dist/import/assets/externals/coingecko/getAutoRetry.d.ts.map +1 -0
  108. package/dist/import/assets/externals/coingecko/getCoinMarketChartRange.d.ts +49 -0
  109. package/dist/import/assets/externals/coingecko/getCoinMarketChartRange.d.ts.map +1 -0
  110. package/dist/import/assets/externals/coingecko/getCoinsMarkets.d.ts +58 -0
  111. package/dist/import/assets/externals/coingecko/getCoinsMarkets.d.ts.map +1 -0
  112. package/dist/import/assets/externals/coingecko/index.d.ts +3 -0
  113. package/dist/import/assets/externals/coingecko/index.d.ts.map +1 -0
  114. package/dist/import/assets/externals/index.d.ts +2 -0
  115. package/dist/import/assets/externals/index.d.ts.map +1 -0
  116. package/dist/import/assets/index.d.ts +5 -0
  117. package/dist/import/assets/index.d.ts.map +1 -0
  118. package/dist/import/assets/types/cryptoCurrency.d.ts +17 -0
  119. package/dist/import/assets/types/cryptoCurrency.d.ts.map +1 -0
  120. package/dist/import/assets/types/cryptoCurrencyPrice.d.ts +10 -0
  121. package/dist/import/assets/types/cryptoCurrencyPrice.d.ts.map +1 -0
  122. package/dist/import/assets/types/dataSource.d.ts +18 -0
  123. package/dist/import/assets/types/dataSource.d.ts.map +1 -0
  124. package/dist/import/assets/types/fiatCurrency.d.ts +12 -0
  125. package/dist/import/assets/types/fiatCurrency.d.ts.map +1 -0
  126. package/dist/import/assets/types/index.d.ts +6 -0
  127. package/dist/import/assets/types/index.d.ts.map +1 -0
  128. package/dist/import/assets/types/nft.d.ts +5 -0
  129. package/dist/import/assets/types/nft.d.ts.map +1 -0
  130. package/dist/import/index.d.mts +12 -0
  131. package/dist/import/index.d.mts.map +1 -0
  132. package/dist/import/index.mjs +2 -0
  133. package/dist/import/portfolios/createPortfolio.d.ts +2 -0
  134. package/dist/import/portfolios/createPortfolio.d.ts.map +1 -0
  135. package/dist/import/portfolios/index.d.ts +3 -0
  136. package/dist/import/portfolios/index.d.ts.map +1 -0
  137. package/dist/import/portfolios/type.d.ts +4 -0
  138. package/dist/import/portfolios/type.d.ts.map +1 -0
  139. package/dist/import/types.d.ts +11 -0
  140. package/dist/import/types.d.ts.map +1 -0
  141. package/dist/import/utils/errors.d.ts +48 -0
  142. package/dist/import/utils/errors.d.ts.map +1 -0
  143. package/dist/import/utils/index.d.ts +5 -0
  144. package/dist/import/utils/index.d.ts.map +1 -0
  145. package/dist/import/utils/rest.d.ts +14 -0
  146. package/dist/import/utils/rest.d.ts.map +1 -0
  147. package/dist/import/utils/stringify.d.ts +2 -0
  148. package/dist/import/utils/stringify.d.ts.map +1 -0
  149. package/dist/import/utils/types.d.ts +12 -0
  150. package/dist/import/utils/types.d.ts.map +1 -0
  151. package/dist/require/index.cjs +2 -0
  152. package/dist/require/index.d.cts +2 -0
  153. package/dist/require/index.d.cts.map +1 -0
  154. package/package.json +79 -0
  155. package/src/accounts/index.ts +1 -0
  156. package/src/accounts/types/account.ts +5 -0
  157. package/src/accounts/types/index.ts +1 -0
  158. package/src/actions/index.ts +44 -0
  159. package/src/actions/schemas/constants.ts +16 -0
  160. package/src/actions/schemas/swap.ts +7 -0
  161. package/src/actions/types/addLiquidity.ts +23 -0
  162. package/src/actions/types/atomicArbitrage.ts +30 -0
  163. package/src/actions/types/bridgeFrom.ts +23 -0
  164. package/src/actions/types/bridgeTo.ts +23 -0
  165. package/src/actions/types/buyNft.ts +34 -0
  166. package/src/actions/types/common.ts +142 -0
  167. package/src/actions/types/deposit.ts +23 -0
  168. package/src/actions/types/depositWithBond.ts +23 -0
  169. package/src/actions/types/freeMintNft.ts +20 -0
  170. package/src/actions/types/income.ts +21 -0
  171. package/src/actions/types/index.ts +53 -0
  172. package/src/actions/types/move.ts +21 -0
  173. package/src/actions/types/nftRoyalty.ts +19 -0
  174. package/src/actions/types/removeLiquidity.ts +23 -0
  175. package/src/actions/types/sellNft.ts +22 -0
  176. package/src/actions/types/spam.ts +23 -0
  177. package/src/actions/types/swapIncome.ts +12 -0
  178. package/src/actions/types/swapNft.ts +12 -0
  179. package/src/actions/types/swapTransfer.ts +12 -0
  180. package/src/actions/types/trade.ts +34 -0
  181. package/src/actions/types/transactionFee.ts +19 -0
  182. package/src/actions/types/transfer.ts +36 -0
  183. package/src/actions/types/withdraw.ts +23 -0
  184. package/src/actions/types/withdrawWithBond.ts +23 -0
  185. package/src/apps/index.ts +2 -0
  186. package/src/apps/types.ts +20 -0
  187. package/src/assets/constants.ts +1 -0
  188. package/src/assets/creates/createCryptoCurrency.ts +7 -0
  189. package/src/assets/creates/createFiatCurrency.ts +10 -0
  190. package/src/assets/creates/index.ts +2 -0
  191. package/src/assets/definitions/astar.ts +14 -0
  192. package/src/assets/definitions/avalanche.ts +14 -0
  193. package/src/assets/definitions/bnb.ts +14 -0
  194. package/src/assets/definitions/coingeckoCryptoCurrencyDataSource.test.ts +53 -0
  195. package/src/assets/definitions/coingeckoCryptoCurrencyDataSource.ts +169 -0
  196. package/src/assets/definitions/ethereum.ts +14 -0
  197. package/src/assets/definitions/eur.ts +9 -0
  198. package/src/assets/definitions/fantom.ts +14 -0
  199. package/src/assets/definitions/index.ts +16 -0
  200. package/src/assets/definitions/jpy.ts +9 -0
  201. package/src/assets/definitions/kava.ts +14 -0
  202. package/src/assets/definitions/mantle.ts +14 -0
  203. package/src/assets/definitions/maticNetwork.ts +14 -0
  204. package/src/assets/definitions/metis.ts +14 -0
  205. package/src/assets/definitions/moonbeam.ts +14 -0
  206. package/src/assets/definitions/moonriver.ts +14 -0
  207. package/src/assets/definitions/ronin.ts +14 -0
  208. package/src/assets/definitions/usd.ts +9 -0
  209. package/src/assets/externals/coingecko/constants.ts +1 -0
  210. package/src/assets/externals/coingecko/getAutoRetry.ts +35 -0
  211. package/src/assets/externals/coingecko/getCoinMarketChartRange.test.ts +28 -0
  212. package/src/assets/externals/coingecko/getCoinMarketChartRange.ts +88 -0
  213. package/src/assets/externals/coingecko/getCoinsMarkets.test.ts +11 -0
  214. package/src/assets/externals/coingecko/getCoinsMarkets.ts +106 -0
  215. package/src/assets/externals/coingecko/index.ts +2 -0
  216. package/src/assets/externals/index.ts +1 -0
  217. package/src/assets/index.ts +27 -0
  218. package/src/assets/types/cryptoCurrency.ts +17 -0
  219. package/src/assets/types/cryptoCurrencyPrice.ts +14 -0
  220. package/src/assets/types/dataSource.ts +26 -0
  221. package/src/assets/types/fiatCurrency.ts +21 -0
  222. package/src/assets/types/index.ts +9 -0
  223. package/src/assets/types/nft.ts +5 -0
  224. package/src/index.cts +1 -0
  225. package/src/index.mts +79 -0
  226. package/src/portfolios/createPortfolio.test.ts +7 -0
  227. package/src/portfolios/createPortfolio.ts +3 -0
  228. package/src/portfolios/index.ts +2 -0
  229. package/src/portfolios/type.ts +3 -0
  230. package/src/tests/constants.ts +1 -0
  231. package/src/tests/index.ts +2 -0
  232. package/src/tests/utils.ts +26 -0
  233. package/src/types.ts +11 -0
  234. package/src/utils/errors.ts +130 -0
  235. package/src/utils/index.ts +4 -0
  236. package/src/utils/rest.test.ts +19 -0
  237. package/src/utils/rest.ts +138 -0
  238. package/src/utils/stringify.test.ts +24 -0
  239. package/src/utils/stringify.ts +11 -0
  240. package/src/utils/types.ts +12 -0
  241. package/tsconfig.json +28 -0
@@ -0,0 +1,35 @@
1
+ import type { Config } from '../../../types'
2
+ import type { Schema } from '../../../utils'
3
+ import { rest } from '../../../utils'
4
+ import { HttpRequestError } from '../../../utils/errors'
5
+
6
+ export const getAutoRetry = async <TData>(
7
+ url: string,
8
+ schema: Schema<TData>,
9
+ config?: Config,
10
+ ): Promise<TData> => {
11
+ const timeoutTimestamp =
12
+ Date.now() + (config?.timeout === undefined ? 60_000 : config.timeout)
13
+
14
+ let mut_retryCount = 0
15
+ const loop = true
16
+ while (loop) {
17
+ try {
18
+ return await rest(url, {
19
+ schema,
20
+ timeout: timeoutTimestamp - Date.now(),
21
+ logger: config?.logger,
22
+ })
23
+ } catch (error) {
24
+ if (error instanceof HttpRequestError && error.status === 429) {
25
+ mut_retryCount += 1
26
+ await new Promise<void>((resolve) =>
27
+ setTimeout(resolve, mut_retryCount + 1 * 60_000),
28
+ )
29
+ } else {
30
+ throw error
31
+ }
32
+ }
33
+ }
34
+ throw new Error('Unreachable')
35
+ }
@@ -0,0 +1,28 @@
1
+ import { describe, expect, it } from 'bun:test'
2
+ import { isIntegrationTest } from '../../../tests'
3
+ import { getCoinMarketChartRange } from './getCoinMarketChartRange'
4
+
5
+ describe('getCoinMarketChartRange', () => {
6
+ it.if(isIntegrationTest)('Should return validated object', async () => {
7
+ const to = Math.floor(Date.now() / 1000)
8
+ const days90Seconds = 60 * 60 * 24 * 90
9
+ const from = to - days90Seconds
10
+ const data = await getCoinMarketChartRange({ id: 'bitcoin', from, to })
11
+
12
+ // expected length is 90 days * 24 hours
13
+ const expectedLength = 90 * 24
14
+ expect(data.prices.length).toEqual(expectedLength)
15
+ expect(data.market_caps.length).toEqual(expectedLength)
16
+
17
+ // expected time difference between two prices is 1 hour
18
+ const hourMilliseconds = 1000 * 60 * 60
19
+ const expectedDiffTimeMin = hourMilliseconds * 0.9
20
+ const expectedDiffTimeMax = hourMilliseconds * 1.1
21
+ expect(data.prices[1][0] - data.prices[0][0]).toBeGreaterThan(
22
+ expectedDiffTimeMin,
23
+ )
24
+ expect(data.prices[1][0] - data.prices[0][0]).toBeLessThan(
25
+ expectedDiffTimeMax,
26
+ )
27
+ })
28
+ })
@@ -0,0 +1,88 @@
1
+ import type { ReadonlyDeep } from 'type-fest'
2
+ import { z } from 'zod'
3
+ import type { Config } from '../../../types'
4
+ import { rootUrl } from './constants'
5
+ import { getAutoRetry } from './getAutoRetry'
6
+
7
+ type GetCoinMarketChartRangeParameters = {
8
+ /**
9
+ * coin id
10
+ *
11
+ * @example "bitcoin"
12
+ * */
13
+ readonly id: string
14
+ /** The target currency of market data (usd, eur, jpy, etc.) */
15
+ readonly vs_currency?: string
16
+ /**
17
+ * From date in UNIX Timestamp
18
+ *
19
+ * @example 1392577232
20
+ */
21
+ readonly from: number
22
+ /**
23
+ * To date in UNIX Timestamp
24
+ *
25
+ * @example 1422577232
26
+ */
27
+ readonly to: number
28
+ /**
29
+ * **full** or any value between 0 - 18 to specify decimal place for currency price value
30
+ */
31
+ readonly precision?:
32
+ | 'full'
33
+ | '0'
34
+ | '1'
35
+ | '2'
36
+ | '3'
37
+ | '4'
38
+ | '5'
39
+ | '6'
40
+ | '7'
41
+ | '8'
42
+ | '9'
43
+ | '10'
44
+ | '11'
45
+ | '12'
46
+ | '13'
47
+ | '14'
48
+ | '15'
49
+ | '16'
50
+ | '17'
51
+ | '18'
52
+ }
53
+
54
+ const getCoinMarketChartRangeResponseSchema = z.object({
55
+ /** [UNIXTIME milliseconds, price][] @example [[1703229613690, 43920.82996790591]] */
56
+ prices: z.array(z.tuple([z.number(), z.number()])),
57
+ /** [UNIXTIME milliseconds, market_cap][] @example [[1703229613690, 860219630538.0055]] */
58
+ market_caps: z.array(z.tuple([z.number(), z.number()])),
59
+ /** [UNIXTIME milliseconds, total_volume][] @example [[1703229613690, 21233021243.384785]] */
60
+ total_volumes: z.array(z.tuple([z.number(), z.number()])),
61
+ })
62
+ type GetCoinMarketChartRangeResponse = ReadonlyDeep<
63
+ z.infer<typeof getCoinMarketChartRangeResponseSchema>
64
+ >
65
+
66
+ export const getCoinMarketChartRange = async (
67
+ {
68
+ id,
69
+ vs_currency = 'usd',
70
+ from,
71
+ to,
72
+ precision = 'full',
73
+ }: GetCoinMarketChartRangeParameters,
74
+ config?: Config,
75
+ ): Promise<GetCoinMarketChartRangeResponse> => {
76
+ const url = new URL(`${rootUrl}/coins/${id}/market_chart/range`)
77
+ url.searchParams.set('vs_currency', vs_currency)
78
+ url.searchParams.set('from', from.toString())
79
+ url.searchParams.set('to', to.toString())
80
+ url.searchParams.set('precision', precision)
81
+
82
+ const response = await getAutoRetry(
83
+ url.toString(),
84
+ getCoinMarketChartRangeResponseSchema,
85
+ config,
86
+ )
87
+ return response
88
+ }
@@ -0,0 +1,11 @@
1
+ import { describe, expect, it } from 'bun:test'
2
+ import { isIntegrationTest } from '../../../tests'
3
+ import { getCoinsMarkets } from './getCoinsMarkets'
4
+
5
+ describe('getCoinsMarkets', () => {
6
+ it.if(isIntegrationTest)('Should return validated object', async () => {
7
+ const data = await getCoinsMarkets({ ids: ['bitcoin'] })
8
+ expect(data).toHaveLength(1)
9
+ expect(data[0].id).toEqual('bitcoin')
10
+ })
11
+ })
@@ -0,0 +1,106 @@
1
+ import type { ReadonlyDeep } from 'type-fest'
2
+ import { z } from 'zod'
3
+ import type { Config } from '../../../types'
4
+ import { rootUrl } from './constants'
5
+ import { getAutoRetry } from './getAutoRetry'
6
+
7
+ type GetCoinMarketsParameters = {
8
+ readonly vs_currency?: string
9
+ readonly ids?: readonly string[]
10
+ readonly category?: string
11
+ readonly order?:
12
+ | 'market_cap_asc'
13
+ | 'market_cap_desc'
14
+ | 'volume_asc'
15
+ | 'volume_desc'
16
+ | 'id_asc'
17
+ | 'id_desc'
18
+ readonly per_page?: number
19
+ readonly page?: number
20
+ readonly sparkline?: boolean
21
+ readonly price_change_percentage?: string
22
+ readonly precision?:
23
+ | 'full'
24
+ | '0'
25
+ | '1'
26
+ | '2'
27
+ | '3'
28
+ | '4'
29
+ | '5'
30
+ | '6'
31
+ | '7'
32
+ | '8'
33
+ | '9'
34
+ | '10'
35
+ | '11'
36
+ | '12'
37
+ | '13'
38
+ | '14'
39
+ | '15'
40
+ | '16'
41
+ | '17'
42
+ | '18'
43
+ }
44
+
45
+ const getCoinMarketsResponseSchema = z.array(
46
+ z.object({
47
+ /** @example "bitcoin" */
48
+ id: z.string(),
49
+ /** @example "btc" */
50
+ symbol: z.string(),
51
+ /** @example "Bitcoin" */
52
+ name: z.string(),
53
+ /** @example "https://assets.coingecko.com/coins/images/1/large/bitcoin.png?1696501400" */
54
+ image: z.string(),
55
+ /** @example 43639.197719840064 */
56
+ current_price: z.number(),
57
+ /** @example 854305524160 */
58
+ market_cap: z.number().nullable().optional(),
59
+ /** @example 1 */
60
+ market_cap_rank: z.number().int().nullable().optional(),
61
+ /** @example "2023-12-22T09:35:19.746Z" */
62
+ last_updated: z.string(),
63
+ }),
64
+ )
65
+ type CoinMarketsResponse = ReadonlyDeep<
66
+ z.infer<typeof getCoinMarketsResponseSchema>
67
+ >
68
+
69
+ /**
70
+ * List all supported coins price, market cap, volume, and market related data
71
+ * @link https://www.coingecko.com/api/documentation
72
+ * */
73
+ export const getCoinsMarkets = async (
74
+ {
75
+ vs_currency = 'usd',
76
+ ids,
77
+ category,
78
+ order = 'market_cap_desc',
79
+ per_page = 250,
80
+ page = 1,
81
+ sparkline,
82
+ price_change_percentage,
83
+ precision = 'full',
84
+ }: GetCoinMarketsParameters,
85
+ config?: Config,
86
+ ): Promise<CoinMarketsResponse> => {
87
+ const url = new URL(`${rootUrl}/coins/markets`)
88
+ url.searchParams.append('vs_currency', vs_currency)
89
+ url.searchParams.append('order', order)
90
+ url.searchParams.append('per_page', per_page.toString())
91
+ url.searchParams.append('page', page.toString())
92
+ url.searchParams.append('precision', precision)
93
+ if (ids !== undefined) url.searchParams.append('ids', ids.join(','))
94
+ if (category !== undefined) url.searchParams.append('category', category)
95
+ if (sparkline !== undefined)
96
+ url.searchParams.append('sparkline', sparkline.toString())
97
+ if (price_change_percentage !== undefined)
98
+ url.searchParams.append('price_change_percentage', price_change_percentage)
99
+
100
+ const response = await getAutoRetry(
101
+ url.toString(),
102
+ getCoinMarketsResponseSchema,
103
+ config,
104
+ )
105
+ return response
106
+ }
@@ -0,0 +1,2 @@
1
+ export { getCoinMarketChartRange } from './getCoinMarketChartRange'
2
+ export { getCoinsMarkets } from './getCoinsMarkets'
@@ -0,0 +1 @@
1
+ export { getCoinMarketChartRange, getCoinsMarkets } from './coingecko'
@@ -0,0 +1,27 @@
1
+ export { fiatCurrencyDecimals } from './constants'
2
+ export { createCryptoCurrency, createFiatCurrency } from './creates'
3
+ export {
4
+ astar,
5
+ avalanche,
6
+ bnb,
7
+ coingeckoCryptoCurrencyDataSource,
8
+ ethereum,
9
+ eur,
10
+ fantom,
11
+ jpy,
12
+ kava,
13
+ mantle,
14
+ maticNetwork,
15
+ metis,
16
+ moonbeam,
17
+ moonriver,
18
+ ronin,
19
+ usd,
20
+ } from './definitions'
21
+ export type {
22
+ CryptoCurrency,
23
+ CryptoCurrencyDataSource,
24
+ CryptoCurrencyPrice,
25
+ FiatCurrency,
26
+ Nft,
27
+ } from './types'
@@ -0,0 +1,17 @@
1
+ import type { BigDecimal } from '@0xtorch/big-decimal'
2
+
3
+ export type CryptoCurrency = {
4
+ readonly type: 'CryptoCurrency'
5
+ readonly id: string
6
+ readonly name: string
7
+ readonly symbol: string
8
+ /** icon image's url */
9
+ readonly icon: string | undefined
10
+ readonly market: CryptoCurrencyMarket
11
+ readonly updatedAt: number
12
+ }
13
+
14
+ type CryptoCurrencyMarket = {
15
+ readonly coingeckoId: string | undefined
16
+ readonly marketCapUsd: BigDecimal | undefined
17
+ }
@@ -0,0 +1,14 @@
1
+ import type { BigDecimal } from '@0xtorch/big-decimal'
2
+ import type { CryptoCurrency } from '.'
3
+
4
+ export type CryptoCurrencyPrice<
5
+ TCryptoCurrency extends CryptoCurrency | undefined =
6
+ | CryptoCurrency
7
+ | undefined,
8
+ > = {
9
+ readonly cryptoCurrencyId: string
10
+ readonly crypto: TCryptoCurrency
11
+ readonly fiatCurrencyId: string
12
+ readonly price: BigDecimal
13
+ readonly timestamp: number
14
+ }
@@ -0,0 +1,26 @@
1
+ import type { CryptoCurrency, FiatCurrency } from '.'
2
+ import type { Config } from '../../types'
3
+ import type { CryptoCurrencyPrice } from './cryptoCurrencyPrice'
4
+
5
+ export type GetCurrentPriceParameters = {
6
+ readonly targetCurrencies: readonly CryptoCurrency[]
7
+ readonly vsCurrency: FiatCurrency
8
+ }
9
+
10
+ export type GetHistoricalPricesParameters = {
11
+ readonly targetCurrencies: readonly CryptoCurrency[]
12
+ readonly vsCurrency: FiatCurrency
13
+ readonly from: number
14
+ readonly to: number
15
+ }
16
+
17
+ export type CryptoCurrencyDataSource = {
18
+ readonly getCurrentPrice: (
19
+ parameters: GetCurrentPriceParameters,
20
+ config?: Config,
21
+ ) => Promise<readonly CryptoCurrencyPrice[]>
22
+ readonly getHistoricalPrices: (
23
+ parameters: GetHistoricalPricesParameters,
24
+ config?: Config,
25
+ ) => Promise<readonly CryptoCurrencyPrice[]>
26
+ }
@@ -0,0 +1,21 @@
1
+ export type FiatCurrency<Id extends FiatCurrencyId = FiatCurrencyId> = {
2
+ readonly type: 'FiatCurrency'
3
+ // TODO implement
4
+ readonly id: Id
5
+ readonly symbol: Uppercase<Id>
6
+ readonly name: string
7
+ /** icon image's url */
8
+ readonly icon: string | undefined
9
+ }
10
+
11
+ const fiatCurrencyIds = [
12
+ 'cny',
13
+ 'eur',
14
+ 'idr',
15
+ 'jpy',
16
+ 'krw',
17
+ 'rub',
18
+ 'twd',
19
+ 'usd',
20
+ ] as const
21
+ export type FiatCurrencyId = (typeof fiatCurrencyIds)[number]
@@ -0,0 +1,9 @@
1
+ export type { CryptoCurrency } from './cryptoCurrency'
2
+ export type { CryptoCurrencyPrice } from './cryptoCurrencyPrice'
3
+ export type {
4
+ CryptoCurrencyDataSource,
5
+ GetCurrentPriceParameters,
6
+ GetHistoricalPricesParameters,
7
+ } from './dataSource'
8
+ export type { FiatCurrency, FiatCurrencyId } from './fiatCurrency'
9
+ export type { Nft } from './nft'
@@ -0,0 +1,5 @@
1
+ export type Nft = {
2
+ // TODO implement
3
+ readonly type: 'Nft'
4
+ readonly id: string
5
+ }
package/src/index.cts ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./index.mts')
package/src/index.mts ADDED
@@ -0,0 +1,79 @@
1
+ export type { Account } from './accounts'
2
+ export type {
3
+ AccountAction,
4
+ AccountActionAddLiquidity,
5
+ AccountActionAtomicArbitrage,
6
+ AccountActionBridgeFrom,
7
+ AccountActionBridgeTo,
8
+ AccountActionBuyNft,
9
+ AccountActionDeposit,
10
+ AccountActionDepositWithBond,
11
+ AccountActionFreeMintNft,
12
+ AccountActionIncome,
13
+ AccountActionMove,
14
+ AccountActionNftRoyalty,
15
+ AccountActionRemoveLiquidity,
16
+ AccountActionSellNft,
17
+ AccountActionSpam,
18
+ AccountActionSwapIncome,
19
+ AccountActionSwapNft,
20
+ AccountActionSwapTransfer,
21
+ AccountActionTrade,
22
+ AccountActionTransactionFee,
23
+ AccountActionTransfer,
24
+ AccountActionType,
25
+ AccountActionWithdraw,
26
+ AccountActionWithdrawWithBond,
27
+ ActionType,
28
+ Evidence,
29
+ NormalAction,
30
+ NormalActionAddLiquidity,
31
+ NormalActionAtomicArbitrage,
32
+ NormalActionBridgeFrom,
33
+ NormalActionBridgeTo,
34
+ NormalActionBuyNft,
35
+ NormalActionDeposit,
36
+ NormalActionDepositWithBond,
37
+ NormalActionFreeMintNft,
38
+ NormalActionRemoveLiquidity,
39
+ NormalActionSpam,
40
+ NormalActionTrade,
41
+ NormalActionTransactionFee,
42
+ NormalActionTransfer,
43
+ NormalActionWithdraw,
44
+ NormalActionWithdrawWithBond,
45
+ } from './actions'
46
+ export { appCategories } from './apps'
47
+ export type { App, AppCategory } from './apps'
48
+ export {
49
+ astar,
50
+ avalanche,
51
+ bnb,
52
+ coingeckoCryptoCurrencyDataSource,
53
+ createCryptoCurrency,
54
+ ethereum,
55
+ eur,
56
+ fantom,
57
+ fiatCurrencyDecimals,
58
+ jpy,
59
+ kava,
60
+ mantle,
61
+ maticNetwork,
62
+ metis,
63
+ moonbeam,
64
+ moonriver,
65
+ ronin,
66
+ usd,
67
+ } from './assets'
68
+ export type {
69
+ CryptoCurrency,
70
+ CryptoCurrencyDataSource,
71
+ CryptoCurrencyPrice,
72
+ FiatCurrency,
73
+ Nft,
74
+ } from './assets'
75
+ export { createPortfolio } from './portfolios'
76
+ export type { Portfolio } from './portfolios'
77
+ export type { Config, Logger } from './types'
78
+ export { rest, stringify } from './utils'
79
+ export type { Schema } from './utils'
@@ -0,0 +1,7 @@
1
+ import { describe, it } from 'bun:test'
2
+
3
+ describe('createPortfolio', () => {
4
+ it.todo('should create a portfolio', () => {
5
+ // TODO
6
+ })
7
+ })
@@ -0,0 +1,3 @@
1
+ export const createPortfolio = () => {
2
+ throw new Error('Not implemented')
3
+ }
@@ -0,0 +1,2 @@
1
+ export { createPortfolio } from './createPortfolio'
2
+ export type { Portfolio } from './type'
@@ -0,0 +1,3 @@
1
+ export type Portfolio = {
2
+ readonly id: string
3
+ }
@@ -0,0 +1 @@
1
+ export const isIntegrationTest = process.env.INTEGRATION_TEST === 'true'
@@ -0,0 +1,2 @@
1
+ export { isIntegrationTest } from './constants'
2
+ export { cryptoCurrencyDataSourceTest } from './utils'
@@ -0,0 +1,26 @@
1
+ import { createBigDecimal } from '@0xtorch/big-decimal'
2
+ import type { CryptoCurrencyDataSource } from '../assets'
3
+
4
+ export const cryptoCurrencyDataSourceTest: CryptoCurrencyDataSource = {
5
+ getCurrentPrice: async ({ targetCurrencies, vsCurrency }) => {
6
+ await new Promise((resolve) => setTimeout(resolve))
7
+ const timestamp = Date.now()
8
+ return targetCurrencies.map((currency) => ({
9
+ cryptoCurrencyId: currency.id,
10
+ crypto: currency,
11
+ fiatCurrencyId: vsCurrency.id,
12
+ price: createBigDecimal(100n),
13
+ timestamp,
14
+ }))
15
+ },
16
+ getHistoricalPrices: ({ targetCurrencies, vsCurrency, from, to }) => {
17
+ // TODO implement
18
+ console.debug('getHistoricalPrices', {
19
+ targetCurrencies,
20
+ vsCurrency,
21
+ from,
22
+ to,
23
+ })
24
+ throw new Error('Not implemented')
25
+ },
26
+ }
package/src/types.ts ADDED
@@ -0,0 +1,11 @@
1
+ export type Logger = {
2
+ debug: (...data: unknown[]) => void
3
+ info: (...data: unknown[]) => void
4
+ warn: (...data: unknown[]) => void
5
+ error: (...data: unknown[]) => void
6
+ }
7
+
8
+ export type Config = {
9
+ readonly timeout?: number
10
+ readonly logger?: Logger
11
+ }