@mezo-org/passport 0.4.0-dev.7 → 0.4.0-dev.70

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 (255) hide show
  1. package/README.md +18 -22
  2. package/dist/src/api/auth.d.ts +7 -3
  3. package/dist/src/api/auth.d.ts.map +1 -1
  4. package/dist/src/api/auth.js +3 -1
  5. package/dist/src/api/auth.js.map +1 -1
  6. package/dist/src/api/client.d.ts +4 -1
  7. package/dist/src/api/client.d.ts.map +1 -1
  8. package/dist/src/api/client.js +9 -2
  9. package/dist/src/api/client.js.map +1 -1
  10. package/dist/src/api/portal.d.ts +3 -9
  11. package/dist/src/api/portal.d.ts.map +1 -1
  12. package/dist/src/api/portal.js +8 -5
  13. package/dist/src/api/portal.js.map +1 -1
  14. package/dist/src/components/Dropdown/ConnectedTrigger.d.ts +2 -1
  15. package/dist/src/components/Dropdown/ConnectedTrigger.d.ts.map +1 -1
  16. package/dist/src/components/Dropdown/ConnectedTrigger.js +29 -20
  17. package/dist/src/components/Dropdown/ConnectedTrigger.js.map +1 -1
  18. package/dist/src/components/Dropdown/Content.d.ts +19 -5
  19. package/dist/src/components/Dropdown/Content.d.ts.map +1 -1
  20. package/dist/src/components/Dropdown/Content.js +19 -61
  21. package/dist/src/components/Dropdown/Content.js.map +1 -1
  22. package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts.map +1 -1
  23. package/dist/src/components/Dropdown/DisconnectedTrigger.js +2 -2
  24. package/dist/src/components/Dropdown/DisconnectedTrigger.js.map +1 -1
  25. package/dist/src/components/Dropdown/Dropdown.d.ts +13 -6
  26. package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -1
  27. package/dist/src/components/Dropdown/Dropdown.js +32 -9
  28. package/dist/src/components/Dropdown/Dropdown.js.map +1 -1
  29. package/dist/src/components/Dropdown/ListingItem.d.ts +13 -0
  30. package/dist/src/components/Dropdown/ListingItem.d.ts.map +1 -0
  31. package/dist/src/components/Dropdown/ListingItem.js +34 -0
  32. package/dist/src/components/Dropdown/ListingItem.js.map +1 -0
  33. package/dist/src/components/Dropdown/NestedViewLayout.d.ts +7 -0
  34. package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -0
  35. package/dist/src/components/Dropdown/NestedViewLayout.js +34 -0
  36. package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -0
  37. package/dist/src/components/Dropdown/Receive/Receive.d.ts +7 -0
  38. package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -0
  39. package/dist/src/components/Dropdown/Receive/Receive.js +53 -0
  40. package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -0
  41. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +7 -0
  42. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -0
  43. package/dist/src/components/Dropdown/Root/AccountAddressActions.js +48 -0
  44. package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -0
  45. package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts +11 -0
  46. package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts.map +1 -0
  47. package/dist/src/components/Dropdown/Root/AccountAssetItem.js +9 -0
  48. package/dist/src/components/Dropdown/Root/AccountAssetItem.js.map +1 -0
  49. package/dist/src/components/Dropdown/{AccountBalance.d.ts → Root/AccountBalance.d.ts} +2 -1
  50. package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -0
  51. package/dist/src/components/Dropdown/Root/AccountBalance.js +15 -0
  52. package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -0
  53. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts +9 -0
  54. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts.map +1 -0
  55. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js +48 -0
  56. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -0
  57. package/dist/src/components/Dropdown/Root/Root.d.ts +23 -0
  58. package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -0
  59. package/dist/src/components/Dropdown/Root/Root.js +57 -0
  60. package/dist/src/components/Dropdown/Root/Root.js.map +1 -0
  61. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +8 -0
  62. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -0
  63. package/dist/src/components/Dropdown/{AccountAddress.js → Root/WalletAddress.js} +21 -15
  64. package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -0
  65. package/dist/src/components/Dropdown/{WelcomeBlock.d.ts → Root/WelcomeBlock.d.ts} +1 -1
  66. package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -0
  67. package/dist/src/components/Dropdown/{WelcomeBlock.js → Root/WelcomeBlock.js} +5 -5
  68. package/dist/src/components/Dropdown/Root/WelcomeBlock.js.map +1 -0
  69. package/dist/src/components/Dropdown/TestnetTopBanner.d.ts +3 -0
  70. package/dist/src/components/Dropdown/TestnetTopBanner.d.ts.map +1 -0
  71. package/dist/src/components/Dropdown/TestnetTopBanner.js +14 -0
  72. package/dist/src/components/Dropdown/TestnetTopBanner.js.map +1 -0
  73. package/dist/src/config.d.ts +18 -5
  74. package/dist/src/config.d.ts.map +1 -1
  75. package/dist/src/config.js +45 -14
  76. package/dist/src/config.js.map +1 -1
  77. package/dist/src/constants.d.ts +11 -3
  78. package/dist/src/constants.d.ts.map +1 -1
  79. package/dist/src/constants.js +12 -4
  80. package/dist/src/constants.js.map +1 -1
  81. package/dist/src/hooks/index.d.ts +4 -0
  82. package/dist/src/hooks/index.d.ts.map +1 -1
  83. package/dist/src/hooks/index.js +4 -0
  84. package/dist/src/hooks/index.js.map +1 -1
  85. package/dist/src/hooks/useAssetsConversionRates.d.ts +23 -0
  86. package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -0
  87. package/dist/src/hooks/useAssetsConversionRates.js +90 -0
  88. package/dist/src/hooks/useAssetsConversionRates.js.map +1 -0
  89. package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -1
  90. package/dist/src/hooks/useAuthenticateWithWallet.js +9 -9
  91. package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
  92. package/dist/src/hooks/useBorrowData.d.ts +82 -0
  93. package/dist/src/hooks/useBorrowData.d.ts.map +1 -0
  94. package/dist/src/hooks/useBorrowData.js +159 -0
  95. package/dist/src/hooks/useBorrowData.js.map +1 -0
  96. package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
  97. package/dist/src/hooks/useCreateAccount.js +22 -1
  98. package/dist/src/hooks/useCreateAccount.js.map +1 -1
  99. package/dist/src/hooks/useDropdownData.d.ts +37 -34
  100. package/dist/src/hooks/useDropdownData.d.ts.map +1 -1
  101. package/dist/src/hooks/useDropdownData.js +85 -61
  102. package/dist/src/hooks/useDropdownData.js.map +1 -1
  103. package/dist/src/hooks/useLinkAccount.d.ts +19 -13
  104. package/dist/src/hooks/useLinkAccount.d.ts.map +1 -1
  105. package/dist/src/hooks/useLinkAccount.js +20 -1
  106. package/dist/src/hooks/useLinkAccount.js.map +1 -1
  107. package/dist/src/hooks/useRefreshPassport.d.ts +19 -0
  108. package/dist/src/hooks/useRefreshPassport.d.ts.map +1 -0
  109. package/dist/src/hooks/useRefreshPassport.js +44 -0
  110. package/dist/src/hooks/useRefreshPassport.js.map +1 -0
  111. package/dist/src/hooks/useTokensBalances.d.ts +74 -0
  112. package/dist/src/hooks/useTokensBalances.d.ts.map +1 -0
  113. package/dist/src/hooks/useTokensBalances.js +140 -0
  114. package/dist/src/hooks/useTokensBalances.js.map +1 -0
  115. package/dist/src/hooks/useValidateMezoId.d.ts +8 -0
  116. package/dist/src/hooks/useValidateMezoId.d.ts.map +1 -0
  117. package/dist/src/hooks/useValidateMezoId.js +24 -0
  118. package/dist/src/hooks/useValidateMezoId.js.map +1 -0
  119. package/dist/src/hooks/useWalletAccount.d.ts +2 -1
  120. package/dist/src/hooks/useWalletAccount.d.ts.map +1 -1
  121. package/dist/src/hooks/useWalletAccount.js +19 -15
  122. package/dist/src/hooks/useWalletAccount.js.map +1 -1
  123. package/dist/src/hooks/useWatchTransferEvents.d.ts +5 -0
  124. package/dist/src/hooks/useWatchTransferEvents.d.ts.map +1 -0
  125. package/dist/src/hooks/useWatchTransferEvents.js +63 -0
  126. package/dist/src/hooks/useWatchTransferEvents.js.map +1 -0
  127. package/dist/src/index.d.ts +1 -1
  128. package/dist/src/index.d.ts.map +1 -1
  129. package/dist/src/index.js +1 -1
  130. package/dist/src/index.js.map +1 -1
  131. package/dist/src/lib/contracts/index.d.ts +13 -0
  132. package/dist/src/lib/contracts/index.d.ts.map +1 -0
  133. package/dist/src/lib/contracts/index.js +62 -0
  134. package/dist/src/lib/contracts/index.js.map +1 -0
  135. package/dist/src/lib/contracts/priceOracle.d.ts +43 -0
  136. package/dist/src/lib/contracts/priceOracle.d.ts.map +1 -0
  137. package/dist/src/lib/contracts/priceOracle.js +52 -0
  138. package/dist/src/lib/contracts/priceOracle.js.map +1 -0
  139. package/dist/src/provider.js +1 -1
  140. package/dist/src/provider.js.map +1 -1
  141. package/dist/src/stores/dropdownStore.d.ts +12 -0
  142. package/dist/src/stores/dropdownStore.d.ts.map +1 -0
  143. package/dist/src/stores/dropdownStore.js +13 -0
  144. package/dist/src/stores/dropdownStore.js.map +1 -0
  145. package/dist/src/utils/address.d.ts +1 -1
  146. package/dist/src/utils/address.d.ts.map +1 -1
  147. package/dist/src/utils/address.js +2 -0
  148. package/dist/src/utils/address.js.map +1 -1
  149. package/dist/src/utils/address.test.js +8 -5
  150. package/dist/src/utils/address.test.js.map +1 -1
  151. package/dist/src/utils/cryptoAssets.d.ts +17 -1
  152. package/dist/src/utils/cryptoAssets.d.ts.map +1 -1
  153. package/dist/src/utils/cryptoAssets.js +87 -31
  154. package/dist/src/utils/cryptoAssets.js.map +1 -1
  155. package/dist/src/utils/cryptoAssets.test.js +51 -33
  156. package/dist/src/utils/cryptoAssets.test.js.map +1 -1
  157. package/dist/src/utils/currency.d.ts +8 -0
  158. package/dist/src/utils/currency.d.ts.map +1 -1
  159. package/dist/src/utils/currency.js +11 -0
  160. package/dist/src/utils/currency.js.map +1 -1
  161. package/dist/src/utils/currency.test.js +1 -0
  162. package/dist/src/utils/currency.test.js.map +1 -1
  163. package/dist/src/utils/mezoId.d.ts +3 -0
  164. package/dist/src/utils/mezoId.d.ts.map +1 -0
  165. package/dist/src/utils/mezoId.js +41 -0
  166. package/dist/src/utils/mezoId.js.map +1 -0
  167. package/dist/src/utils/numbers.d.ts +39 -17
  168. package/dist/src/utils/numbers.d.ts.map +1 -1
  169. package/dist/src/utils/numbers.js +91 -33
  170. package/dist/src/utils/numbers.js.map +1 -1
  171. package/dist/src/utils/numbers.test.js +144 -22
  172. package/dist/src/utils/numbers.test.js.map +1 -1
  173. package/dist/src/utils/siww.d.ts +1 -0
  174. package/dist/src/utils/siww.d.ts.map +1 -1
  175. package/dist/src/utils/siww.js +50 -12
  176. package/dist/src/utils/siww.js.map +1 -1
  177. package/dist/src/utils/wagmi.d.ts +3 -0
  178. package/dist/src/utils/wagmi.d.ts.map +1 -0
  179. package/dist/src/utils/wagmi.js +7 -0
  180. package/dist/src/utils/wagmi.js.map +1 -0
  181. package/dist/src/wallet/index.d.ts +1 -1
  182. package/dist/src/wallet/index.d.ts.map +1 -1
  183. package/dist/src/wallet/index.js +1 -1
  184. package/dist/src/wallet/index.js.map +1 -1
  185. package/package.json +10 -8
  186. package/src/api/auth.ts +8 -4
  187. package/src/api/client.ts +11 -2
  188. package/src/api/portal.ts +11 -14
  189. package/src/components/Dropdown/ConnectedTrigger.tsx +52 -32
  190. package/src/components/Dropdown/Content.tsx +67 -117
  191. package/src/components/Dropdown/DisconnectedTrigger.tsx +2 -1
  192. package/src/components/Dropdown/Dropdown.tsx +75 -15
  193. package/src/components/Dropdown/ListingItem.tsx +80 -0
  194. package/src/components/Dropdown/NestedViewLayout.tsx +75 -0
  195. package/src/components/Dropdown/README.md +10 -18
  196. package/src/components/Dropdown/Receive/Receive.tsx +119 -0
  197. package/src/components/Dropdown/Root/AccountAddressActions.tsx +101 -0
  198. package/src/components/Dropdown/Root/AccountAssetItem.tsx +26 -0
  199. package/src/components/Dropdown/Root/AccountBalance.tsx +30 -0
  200. package/src/components/Dropdown/Root/AccountOtherAssets.tsx +68 -0
  201. package/src/components/Dropdown/Root/Root.tsx +147 -0
  202. package/src/components/Dropdown/Root/WalletAddress.tsx +128 -0
  203. package/src/components/Dropdown/{WelcomeBlock.tsx → Root/WelcomeBlock.tsx} +5 -6
  204. package/src/components/Dropdown/TestnetTopBanner.tsx +32 -0
  205. package/src/config.ts +73 -20
  206. package/src/constants.ts +12 -4
  207. package/src/hooks/index.ts +7 -0
  208. package/src/hooks/useAssetsConversionRates.ts +97 -0
  209. package/src/hooks/useAuthenticateWithWallet.ts +18 -12
  210. package/src/hooks/useBorrowData.ts +187 -0
  211. package/src/hooks/useCreateAccount.ts +28 -2
  212. package/src/hooks/useDropdownData.ts +119 -97
  213. package/src/hooks/useLinkAccount.ts +36 -4
  214. package/src/hooks/useRefreshPassport.ts +56 -0
  215. package/src/hooks/useTokensBalances.ts +187 -0
  216. package/src/hooks/useValidateMezoId.ts +31 -0
  217. package/src/hooks/useWalletAccount.ts +29 -19
  218. package/src/hooks/useWatchTransferEvents.ts +74 -0
  219. package/src/index.ts +11 -1
  220. package/src/lib/contracts/index.ts +92 -0
  221. package/src/lib/contracts/priceOracle.ts +53 -0
  222. package/src/provider.ts +1 -1
  223. package/src/stores/dropdownStore.ts +20 -0
  224. package/src/utils/address.test.ts +10 -6
  225. package/src/utils/address.ts +5 -3
  226. package/src/utils/cryptoAssets.test.ts +57 -37
  227. package/src/utils/cryptoAssets.ts +113 -35
  228. package/src/utils/currency.test.ts +2 -0
  229. package/src/utils/currency.ts +21 -0
  230. package/src/utils/mezoId.ts +50 -0
  231. package/src/utils/numbers.test.ts +181 -23
  232. package/src/utils/numbers.ts +121 -34
  233. package/src/utils/siww.ts +71 -16
  234. package/src/utils/wagmi.ts +12 -0
  235. package/src/wallet/index.ts +3 -2
  236. package/dist/src/components/Dropdown/AccountAddress.d.ts +0 -8
  237. package/dist/src/components/Dropdown/AccountAddress.d.ts.map +0 -1
  238. package/dist/src/components/Dropdown/AccountAddress.js.map +0 -1
  239. package/dist/src/components/Dropdown/AccountAssets.d.ts +0 -14
  240. package/dist/src/components/Dropdown/AccountAssets.d.ts.map +0 -1
  241. package/dist/src/components/Dropdown/AccountAssets.js +0 -44
  242. package/dist/src/components/Dropdown/AccountAssets.js.map +0 -1
  243. package/dist/src/components/Dropdown/AccountBalance.d.ts.map +0 -1
  244. package/dist/src/components/Dropdown/AccountBalance.js +0 -18
  245. package/dist/src/components/Dropdown/AccountBalance.js.map +0 -1
  246. package/dist/src/components/Dropdown/WelcomeBlock.d.ts.map +0 -1
  247. package/dist/src/components/Dropdown/WelcomeBlock.js.map +0 -1
  248. package/dist/src/hooks/useAssetsUSDConversion.d.ts +0 -8
  249. package/dist/src/hooks/useAssetsUSDConversion.d.ts.map +0 -1
  250. package/dist/src/hooks/useAssetsUSDConversion.js +0 -21
  251. package/dist/src/hooks/useAssetsUSDConversion.js.map +0 -1
  252. package/src/components/Dropdown/AccountAddress.tsx +0 -111
  253. package/src/components/Dropdown/AccountAssets.tsx +0 -110
  254. package/src/components/Dropdown/AccountBalance.tsx +0 -38
  255. package/src/hooks/useAssetsUSDConversion.ts +0 -31
@@ -0,0 +1,74 @@
1
+ import { useMemo } from "react"
2
+ import { useAccount, useWatchContractEvent } from "wagmi"
3
+ import {
4
+ mainnetTokenContracts,
5
+ MezoChainToken,
6
+ testnetTokenContracts,
7
+ } from "../lib/contracts"
8
+ import { usePassportContext } from "./usePassportContext"
9
+ import { CHAIN_ID } from "../constants"
10
+ import { useRefreshPassport } from "./useRefreshPassport"
11
+ import { simpleWssMezoConfig } from "../config"
12
+
13
+ function useWatchTransferEvents(token: MezoChainToken) {
14
+ const { address: userAddress } = useAccount()
15
+ const { environment = "mainnet" } = usePassportContext()
16
+ const { refreshTokensBalances, refreshBorrowData } = useRefreshPassport()
17
+
18
+ const contract = useMemo(() => {
19
+ const contracts =
20
+ environment === "mainnet" ? mainnetTokenContracts : testnetTokenContracts
21
+
22
+ return contracts[token]
23
+ }, [environment, token])
24
+
25
+ useWatchContractEvent({
26
+ address: contract.address,
27
+ abi: contract.abi,
28
+ eventName: "Transfer",
29
+ args: {
30
+ from: userAddress,
31
+ },
32
+ chainId: CHAIN_ID[environment],
33
+ enabled: !!userAddress,
34
+ config: simpleWssMezoConfig,
35
+ onLogs() {
36
+ console.log(`[${token}] Transfer from: ${userAddress}`)
37
+ refreshTokensBalances()
38
+ refreshBorrowData()
39
+ },
40
+ })
41
+
42
+ useWatchContractEvent({
43
+ address: contract.address,
44
+ abi: contract.abi,
45
+ eventName: "Transfer",
46
+ args: {
47
+ to: userAddress,
48
+ },
49
+ chainId: CHAIN_ID[environment],
50
+ enabled: !!userAddress,
51
+ config: simpleWssMezoConfig,
52
+ onLogs() {
53
+ console.log(`[${token}] Transfer to: ${userAddress}`)
54
+ refreshTokensBalances()
55
+ refreshBorrowData()
56
+ },
57
+ })
58
+ }
59
+
60
+ function useWatchTransferEventsForAllTokens() {
61
+ useWatchTransferEvents("mcbBTC")
62
+ useWatchTransferEvents("mDAI")
63
+ useWatchTransferEvents("mFBTC")
64
+ useWatchTransferEvents("mSolvBTC")
65
+ useWatchTransferEvents("mswBTC")
66
+ useWatchTransferEvents("mT")
67
+ useWatchTransferEvents("mUSDC")
68
+ useWatchTransferEvents("mUSDe")
69
+ useWatchTransferEvents("mUSDT")
70
+ useWatchTransferEvents("mxSolvBTC")
71
+ useWatchTransferEvents("MUSD")
72
+ }
73
+
74
+ export { useWatchTransferEvents, useWatchTransferEventsForAllTokens }
package/src/index.ts CHANGED
@@ -1,5 +1,15 @@
1
1
  export * from "./components"
2
- export * from "./config"
2
+ export {
3
+ defaultConfig,
4
+ unisatWalletMezoMainnet,
5
+ unisatWalletMezoTestnet,
6
+ okxWalletMezoMainnet,
7
+ okxWalletMezoTestnet,
8
+ xverseWalletMezoMainnet,
9
+ xverseWalletMezoTestnet,
10
+ getDefaultWallets,
11
+ getConfig,
12
+ } from "./config"
3
13
  export * from "./constants"
4
14
  export * from "./hooks"
5
15
  export * from "./provider"
@@ -0,0 +1,92 @@
1
+ import cbbtcMainnet from "@mezo-org/mezod-contracts/deployments/mainnet/mcbBTC.json"
2
+ import daiMainnet from "@mezo-org/mezod-contracts/deployments/mainnet/mDAI.json"
3
+ import fbtcMainnet from "@mezo-org/mezod-contracts/deployments/mainnet/mFBTC.json"
4
+ import solvbtcMainnet from "@mezo-org/mezod-contracts/deployments/mainnet/mSolvBTC.json"
5
+ import swbtcMainnet from "@mezo-org/mezod-contracts/deployments/mainnet/mswBTC.json"
6
+ import tMainnet from "@mezo-org/mezod-contracts/deployments/mainnet/mT.json"
7
+ import usdcMainnet from "@mezo-org/mezod-contracts/deployments/mainnet/mUSDC.json"
8
+ import usdeMainnet from "@mezo-org/mezod-contracts/deployments/mainnet/mUSDe.json"
9
+ import usdtMainnet from "@mezo-org/mezod-contracts/deployments/mainnet/mUSDT.json"
10
+ import xsolvbtcMainnet from "@mezo-org/mezod-contracts/deployments/mainnet/mxSolvBTC.json"
11
+ import musdMainnet from "@mezo-org/musd-contracts/deployments/mainnet/MUSD.json"
12
+ import troveManagerMainnet from "@mezo-org/musd-contracts/deployments/mainnet/TroveManager.json"
13
+ import borrowerOperationsMainnet from "@mezo-org/musd-contracts/deployments/mainnet/BorrowerOperations.json"
14
+
15
+ import cbbtcTestnet from "@mezo-org/mezod-contracts/deployments/testnet/mcbBTC.json"
16
+ import daiTestnet from "@mezo-org/mezod-contracts/deployments/testnet/mDAI.json"
17
+ import fbtcTestnet from "@mezo-org/mezod-contracts/deployments/testnet/mFBTC.json"
18
+ import solvbtcTestnet from "@mezo-org/mezod-contracts/deployments/testnet/mSolvBTC.json"
19
+ import swbtcTestnet from "@mezo-org/mezod-contracts/deployments/testnet/mswBTC.json"
20
+ import tTestnet from "@mezo-org/mezod-contracts/deployments/testnet/mT.json"
21
+ import usdcTestnet from "@mezo-org/mezod-contracts/deployments/testnet/mUSDC.json"
22
+ import usdeTestnet from "@mezo-org/mezod-contracts/deployments/testnet/mUSDe.json"
23
+ import usdtTestnet from "@mezo-org/mezod-contracts/deployments/testnet/mUSDT.json"
24
+ import xsolvbtcTestnet from "@mezo-org/mezod-contracts/deployments/testnet/mxSolvBTC.json"
25
+ import musdTestnet from "@mezo-org/musd-contracts/deployments/matsnet/MUSD.json"
26
+ import troveManagerTestnet from "@mezo-org/musd-contracts/deployments/matsnet/TroveManager.json"
27
+ import borrowerOperationsTestnet from "@mezo-org/musd-contracts/deployments/matsnet/BorrowerOperations.json"
28
+
29
+ import { Abi, Address } from "viem"
30
+
31
+ export type MezoChainToken =
32
+ | "mcbBTC"
33
+ | "mDAI"
34
+ | "mFBTC"
35
+ | "mSolvBTC"
36
+ | "mswBTC"
37
+ | "mT"
38
+ | "mUSDC"
39
+ | "mUSDe"
40
+ | "mUSDT"
41
+ | "mxSolvBTC"
42
+ | "MUSD"
43
+
44
+ export type MezoBorrowContract = "TroveManager" | "BorrowerOperations"
45
+
46
+ type ContractsMap<K extends string> = Record<
47
+ K,
48
+ {
49
+ address: Address
50
+ abi: Abi
51
+ }
52
+ >
53
+
54
+ export const testnetTokenContracts = {
55
+ mcbBTC: cbbtcTestnet,
56
+ mDAI: daiTestnet,
57
+ mFBTC: fbtcTestnet,
58
+ mSolvBTC: solvbtcTestnet,
59
+ mswBTC: swbtcTestnet,
60
+ mT: tTestnet,
61
+ mUSDC: usdcTestnet,
62
+ mUSDe: usdeTestnet,
63
+ mUSDT: usdtTestnet,
64
+ mxSolvBTC: xsolvbtcTestnet,
65
+ MUSD: musdTestnet,
66
+ } as unknown as ContractsMap<MezoChainToken>
67
+
68
+ export const mainnetTokenContracts = {
69
+ mcbBTC: cbbtcMainnet,
70
+ mDAI: daiMainnet,
71
+ mFBTC: fbtcMainnet,
72
+ mSolvBTC: solvbtcMainnet,
73
+ mswBTC: swbtcMainnet,
74
+ mT: tMainnet,
75
+ mUSDC: usdcMainnet,
76
+ mUSDe: usdeMainnet,
77
+ mUSDT: usdtMainnet,
78
+ mxSolvBTC: xsolvbtcMainnet,
79
+ MUSD: musdMainnet,
80
+ } as unknown as ContractsMap<MezoChainToken>
81
+
82
+ export const mainnetBorrowContracts = {
83
+ TroveManager: troveManagerMainnet,
84
+ BorrowerOperations: borrowerOperationsMainnet,
85
+ } as unknown as ContractsMap<MezoBorrowContract>
86
+
87
+ export const testnetBorrowContracts = {
88
+ TroveManager: troveManagerTestnet,
89
+ BorrowerOperations: borrowerOperationsTestnet,
90
+ } as unknown as ContractsMap<MezoBorrowContract>
91
+
92
+ export { default as priceOracleContract } from "./priceOracle"
@@ -0,0 +1,53 @@
1
+ import { Address } from "viem"
2
+
3
+ export default {
4
+ address: "0x7b7c000000000000000000000000000000000015" as Address,
5
+ abi: [
6
+ {
7
+ inputs: [],
8
+ name: "decimals",
9
+ outputs: [
10
+ {
11
+ internalType: "uint8",
12
+ name: "",
13
+ type: "uint8",
14
+ },
15
+ ],
16
+ stateMutability: "view",
17
+ type: "function",
18
+ },
19
+ {
20
+ inputs: [],
21
+ name: "latestRoundData",
22
+ outputs: [
23
+ {
24
+ internalType: "uint80",
25
+ name: "roundId",
26
+ type: "uint80",
27
+ },
28
+ {
29
+ internalType: "int256",
30
+ name: "answer",
31
+ type: "int256",
32
+ },
33
+ {
34
+ internalType: "uint256",
35
+ name: "startedAt",
36
+ type: "uint256",
37
+ },
38
+ {
39
+ internalType: "uint256",
40
+ name: "updatedAt",
41
+ type: "uint256",
42
+ },
43
+ {
44
+ internalType: "uint80",
45
+ name: "answeredInRound",
46
+ type: "uint80",
47
+ },
48
+ ],
49
+ stateMutability: "view",
50
+ type: "function",
51
+ },
52
+ ] as const,
53
+ }
package/src/provider.ts CHANGED
@@ -29,7 +29,7 @@ export function PassportProvider({
29
29
  portalApiUrl,
30
30
  children,
31
31
  }: PassportProviderProps) {
32
- if (environment !== "mainnet" && environment !== "testnet") {
32
+ if (environment && !["mainnet", "testnet"].includes(environment)) {
33
33
  throw new Error("Wrong environment passed to PassportProvider.")
34
34
  }
35
35
 
@@ -0,0 +1,20 @@
1
+ import { create } from "zustand"
2
+
3
+ export enum DropdownView {
4
+ ROOT = "ROOT",
5
+ RECEIVE = "RECEIVE",
6
+ }
7
+
8
+ interface DropdownStore {
9
+ view: DropdownView
10
+ setView: (view: DropdownView) => void
11
+ isNestedView: () => boolean
12
+ }
13
+
14
+ const useDropdownStore = create<DropdownStore>((set, get) => ({
15
+ view: DropdownView.ROOT,
16
+ setView: (view: DropdownView) => set({ view }),
17
+ isNestedView: () => get().view !== DropdownView.ROOT,
18
+ }))
19
+
20
+ export default useDropdownStore
@@ -10,12 +10,6 @@ describe("trimAddress", () => {
10
10
  const expected = "0x123...bcdef"
11
11
  expect(trimAddress(input)).toBe(expected)
12
12
  })
13
-
14
- it("returns lowercase result", () => {
15
- const input = "0xABCDEF1234567890"
16
- const expected = "0xabc...67890"
17
- expect(trimAddress(input)).toBe(expected)
18
- })
19
13
  })
20
14
 
21
15
  describe("getAddressExplorerUrl", () => {
@@ -41,4 +35,14 @@ describe("getAddressExplorerUrl", () => {
41
35
  const url = getAddressExplorerUrl(evmAddress, "evm", true)
42
36
  expect(url).toBe(`https://sepolia.etherscan.io/address/${evmAddress}`)
43
37
  })
38
+
39
+ it("returns correct mainnet Mezo explorer URL", () => {
40
+ const url = getAddressExplorerUrl(evmAddress, "mezo", false)
41
+ expect(url).toBe(`https://explorer.mezo.org/address/${evmAddress}`)
42
+ })
43
+
44
+ it("returns correct testnet Mezo explorer URL", () => {
45
+ const url = getAddressExplorerUrl(evmAddress, "mezo", true)
46
+ expect(url).toBe(`https://explorer.test.mezo.org/address/${evmAddress}`)
47
+ })
44
48
  })
@@ -11,14 +11,16 @@ export function trimAddress(address: string): string {
11
11
  return trimmedAddress
12
12
  }
13
13
 
14
- const MAINNET_EXPLORER_URLS: Record<"bitcoin" | "evm", string> = {
14
+ const MAINNET_EXPLORER_URLS: Record<"bitcoin" | "evm" | "mezo", string> = {
15
15
  bitcoin: "https://mempool.space",
16
16
  evm: "https://etherscan.io",
17
+ mezo: "https://explorer.mezo.org",
17
18
  }
18
19
 
19
- const TESTNET_EXPLORER_URLS: Record<"bitcoin" | "evm", string> = {
20
+ const TESTNET_EXPLORER_URLS: Record<"bitcoin" | "evm" | "mezo", string> = {
20
21
  bitcoin: "https://mempool.space/testnet",
21
22
  evm: "https://sepolia.etherscan.io",
23
+ mezo: "https://explorer.test.mezo.org",
22
24
  }
23
25
 
24
26
  /**
@@ -30,7 +32,7 @@ const TESTNET_EXPLORER_URLS: Record<"bitcoin" | "evm", string> = {
30
32
  */
31
33
  export function getAddressExplorerUrl(
32
34
  address: string,
33
- chainType: "bitcoin" | "evm",
35
+ chainType: "bitcoin" | "evm" | "mezo",
34
36
  isTestnet: boolean,
35
37
  ) {
36
38
  const EXPLORER_URLS = isTestnet
@@ -1,59 +1,79 @@
1
+ import { BitcoinCircle, EthCircle, MUsdCircle02 } from "@mezo-org/mezo-clay"
1
2
  import {
2
- BitcoinCircle,
3
- EthCircle,
4
- MUsdCircle,
5
- TBtcCircle,
6
- } from "@mezo-org/mezo-clay"
7
- import { getCryptoAsset } from "./cryptoAssets"
3
+ CryptoAssetKey,
4
+ getCryptoAsset,
5
+ isBitcoinLikeCryptoAsset,
6
+ isUsdLikeCryptoAsset,
7
+ } from "./cryptoAssets"
8
+
9
+ // FIXME: Test fails if run in full suite (pnpm test) but works when run in isolation (pnpm test cryptoAssets)
8
10
 
9
11
  describe("getCryptoAsset", () => {
10
- it("returns the correct asset for 'btc'", () => {
11
- const asset = getCryptoAsset("btc")
12
+ it("returns the correct asset for 'BTC (mBTC)'", () => {
13
+ const asset = getCryptoAsset("BTC")
12
14
  expect(asset.name).toBe("Bitcoin")
13
15
  expect(asset.symbol).toBe("BTC")
14
- expect(asset.decimals).toBe(8)
16
+ expect(asset.decimals).toBe(18)
15
17
  expect(asset.icon).toBe(BitcoinCircle)
16
18
  })
17
19
 
18
- it("returns the correct asset for 'eth'", () => {
19
- const asset = getCryptoAsset("eth")
20
+ it("returns the correct asset for 'ETH'", () => {
21
+ const asset = getCryptoAsset("ETH")
20
22
  expect(asset.name).toBe("Ethereum")
21
23
  expect(asset.symbol).toBe("ETH")
22
24
  expect(asset.decimals).toBe(18)
23
25
  expect(asset.icon).toBe(EthCircle)
24
26
  })
25
27
 
26
- it("returns the correct asset for 'tbtc'", () => {
27
- const asset = getCryptoAsset("tbtc")
28
- expect(asset.name).toBe("Threshold Bitcoin")
29
- expect(asset.symbol).toBe("tBTC")
28
+ it("returns the correct asset for 'MUSD'", () => {
29
+ const asset = getCryptoAsset("MUSD")
30
+ expect(asset.name).toBe("MUSD")
31
+ expect(asset.symbol).toBe("MUSD")
30
32
  expect(asset.decimals).toBe(18)
31
- expect(asset.icon).toBe(TBtcCircle)
33
+ expect(asset.icon).toBe(MUsdCircle02)
32
34
  })
35
+ })
33
36
 
34
- it("returns the correct asset for 'wbtc'", () => {
35
- const asset = getCryptoAsset("wbtc")
36
- expect(asset.name).toBe("Wrapped Bitcoin")
37
- expect(asset.symbol).toBe("wBTC")
38
- expect(asset.decimals).toBe(8)
39
- // FIXME: Test should expect the exact icon component
40
- expect(asset.icon).toEqual(expect.any(Function))
41
- })
37
+ describe("isBitcoinLikeCryptoAsset", () => {
38
+ const cases = [
39
+ { input: "mcbBTC", expected: true },
40
+ { input: "mDAI", expected: false },
41
+ { input: "mFBTC", expected: true },
42
+ { input: "mSolvBTC", expected: true },
43
+ { input: "mswBTC", expected: true },
44
+ { input: "mT", expected: false },
45
+ { input: "mUSDC", expected: false },
46
+ { input: "mUSDe", expected: false },
47
+ { input: "mUSDT", expected: false },
48
+ { input: "mxSolvBTC", expected: true },
49
+ { input: "MUSD", expected: false },
50
+ ]
42
51
 
43
- it("returns the correct asset for 'mbtc'", () => {
44
- const asset = getCryptoAsset("mbtc")
45
- expect(asset.name).toBe("Matsnet Bitcoin")
46
- expect(asset.symbol).toBe("BTC")
47
- expect(asset.decimals).toBe(18)
48
- // FIXME: Test should expect the exact icon component
49
- expect(asset.icon).toEqual(expect.any(Function))
52
+ cases.forEach(({ input, expected }) => {
53
+ it(`returns ${expected} for ${input}`, () => {
54
+ expect(isBitcoinLikeCryptoAsset(input as CryptoAssetKey)).toBe(expected)
55
+ })
50
56
  })
57
+ })
51
58
 
52
- it("returns the correct asset for 'musd'", () => {
53
- const asset = getCryptoAsset("musd")
54
- expect(asset.name).toBe("Mezo USD")
55
- expect(asset.symbol).toBe("mUSD")
56
- expect(asset.decimals).toBe(18)
57
- expect(asset.icon).toBe(MUsdCircle)
59
+ describe("isUsdLikeCryptoAsset", () => {
60
+ const cases = [
61
+ { input: "mcbBTC", expected: false },
62
+ { input: "mDAI", expected: true },
63
+ { input: "mFBTC", expected: false },
64
+ { input: "mSolvBTC", expected: false },
65
+ { input: "mswBTC", expected: false },
66
+ { input: "mT", expected: false },
67
+ { input: "mUSDC", expected: true },
68
+ { input: "mUSDe", expected: true },
69
+ { input: "mUSDT", expected: true },
70
+ { input: "mxSolvBTC", expected: false },
71
+ { input: "MUSD", expected: true },
72
+ ]
73
+
74
+ cases.forEach(({ input, expected }) => {
75
+ it(`returns ${expected} for ${input}`, () => {
76
+ expect(isUsdLikeCryptoAsset(input as CryptoAssetKey)).toBe(expected)
77
+ })
58
78
  })
59
79
  })
@@ -2,12 +2,15 @@ import {
2
2
  BitcoinCircle,
3
3
  EthCircle,
4
4
  IconProps,
5
- MUsdCircle,
6
- TBtcCircle,
5
+ MUsdCircle02,
6
+ Cryptocurrency04,
7
7
  } from "@mezo-org/mezo-clay"
8
- import { createElement, FC } from "react"
8
+ import { FC } from "react"
9
+ import { MezoChainToken } from "../lib/contracts"
10
+ import { convertToUsd, formatUsd } from "./currency"
11
+ import { fromFixedPointToString } from "./numbers"
9
12
 
10
- export type CryptoAssetKey = "btc" | "eth" | "tbtc" | "wbtc" | "mbtc" | "musd"
13
+ export type CryptoAssetKey = MezoChainToken | "BTC" | "ETH"
11
14
 
12
15
  export type CryptoAsset = {
13
16
  name: string
@@ -16,51 +19,85 @@ export type CryptoAsset = {
16
19
  decimals: number
17
20
  }
18
21
 
22
+ // TODO: Add actual icons for the assets
23
+
19
24
  const CRYPTO_ASSETS: Record<CryptoAssetKey, CryptoAsset> = {
20
- btc: {
25
+ BTC: {
21
26
  name: "Bitcoin",
22
27
  symbol: "BTC",
23
28
  icon: BitcoinCircle,
24
- decimals: 8,
29
+ decimals: 18,
25
30
  },
26
- eth: {
31
+ ETH: {
27
32
  name: "Ethereum",
28
33
  symbol: "ETH",
29
34
  icon: EthCircle,
30
35
  decimals: 18,
31
36
  },
32
- tbtc: {
33
- name: "Threshold Bitcoin",
34
- symbol: "tBTC",
35
- icon: TBtcCircle,
37
+ MUSD: {
38
+ name: "MUSD",
39
+ symbol: "MUSD",
40
+ icon: MUsdCircle02,
41
+ decimals: 18,
42
+ },
43
+ mDAI: {
44
+ name: "mDAI",
45
+ symbol: "mDAI",
46
+ icon: Cryptocurrency04,
36
47
  decimals: 18,
37
48
  },
38
- wbtc: {
39
- name: "Wrapped Bitcoin",
40
- symbol: "wBTC",
41
- icon: (props) =>
42
- createElement(BitcoinCircle, {
43
- ...props,
44
- symbolColor: "#FF8A00",
45
- color: "#000000",
46
- }),
49
+ mFBTC: {
50
+ name: "mFBTC",
51
+ symbol: "mFBTC",
52
+ icon: BitcoinCircle,
47
53
  decimals: 8,
48
54
  },
49
- mbtc: {
50
- name: "Matsnet Bitcoin",
51
- symbol: "BTC",
52
- icon: (props) =>
53
- createElement(BitcoinCircle, {
54
- ...props,
55
- symbolColor: "#000000",
56
- color: "#FFC907",
57
- }),
55
+ mcbBTC: {
56
+ name: "mcbBTC",
57
+ symbol: "mcbBTC",
58
+ icon: BitcoinCircle,
59
+ decimals: 8,
60
+ },
61
+ mSolvBTC: {
62
+ name: "mSolvBTC",
63
+ symbol: "mSolvBTC",
64
+ icon: BitcoinCircle,
58
65
  decimals: 18,
59
66
  },
60
- musd: {
61
- name: "Mezo USD",
62
- symbol: "MUSD",
63
- icon: MUsdCircle,
67
+ mswBTC: {
68
+ name: "mswBTC",
69
+ symbol: "mswBTC",
70
+ icon: BitcoinCircle,
71
+ decimals: 8,
72
+ },
73
+ mT: {
74
+ name: "mT",
75
+ symbol: "mT",
76
+ icon: Cryptocurrency04,
77
+ decimals: 18,
78
+ },
79
+ mUSDC: {
80
+ name: "mUSDC",
81
+ symbol: "mUSDC",
82
+ icon: Cryptocurrency04,
83
+ decimals: 6,
84
+ },
85
+ mUSDe: {
86
+ name: "mUSDe",
87
+ symbol: "mUSDe",
88
+ icon: Cryptocurrency04,
89
+ decimals: 18,
90
+ },
91
+ mUSDT: {
92
+ name: "mUSDT",
93
+ symbol: "mUSDT",
94
+ icon: Cryptocurrency04,
95
+ decimals: 6,
96
+ },
97
+ mxSolvBTC: {
98
+ name: "mxSolvBTC",
99
+ symbol: "mxSolvBTC",
100
+ icon: BitcoinCircle,
64
101
  decimals: 18,
65
102
  },
66
103
  }
@@ -80,7 +117,7 @@ export function getCryptoAsset(key: CryptoAssetKey) {
80
117
  * @returns True if crypto asset is Bitcoin-like
81
118
  */
82
119
  export function isBitcoinLikeCryptoAsset(key: CryptoAssetKey) {
83
- return ["btc", "tbtc", "wbtc", "mbtc"].includes(key)
120
+ return /(btc)/i.test(key)
84
121
  }
85
122
 
86
123
  /**
@@ -89,5 +126,46 @@ export function isBitcoinLikeCryptoAsset(key: CryptoAssetKey) {
89
126
  * @returns True if crypto asset is USD-like
90
127
  */
91
128
  export function isUsdLikeCryptoAsset(key: CryptoAssetKey) {
92
- return ["musd"].includes(key)
129
+ return /(usd|dai)/i.test(key)
130
+ }
131
+
132
+ /**
133
+ * Formats crypto asset to balance details (balance in USD and decimals)
134
+ * @param type The type of crypto asset
135
+ * @param balance The balance of crypto asset
136
+ * @param usdConversionRate The USD conversion rate
137
+ * @returns The balance details
138
+ */
139
+ export function mapCryptoAssetToDetails(
140
+ type: CryptoAssetKey,
141
+ balance: bigint,
142
+ usdConversionRate: bigint,
143
+ usdConversionRateDecimals: number,
144
+ ) {
145
+ const { decimals } = getCryptoAsset(type)
146
+
147
+ const formattedBalance = fromFixedPointToString(
148
+ balance,
149
+ decimals,
150
+ isUsdLikeCryptoAsset(type) ? 2 : 4,
151
+ )
152
+
153
+ const usdBalance = convertToUsd(
154
+ balance,
155
+ decimals,
156
+ usdConversionRate,
157
+ usdConversionRateDecimals,
158
+ )
159
+
160
+ const formattedUsdBalance = formatUsd(usdBalance)
161
+
162
+ return {
163
+ type,
164
+ rawBalance: balance,
165
+ formattedBalance,
166
+ usdBalance,
167
+ formattedUsdBalance,
168
+ }
93
169
  }
170
+
171
+ export type DetailedCryptoAsset = ReturnType<typeof mapCryptoAssetToDetails>
@@ -36,3 +36,5 @@ describe("formatUsd", () => {
36
36
  expect(result).toBe("$0.00")
37
37
  })
38
38
  })
39
+
40
+ // TODO: Add tests for convertToUsd function
@@ -1,3 +1,5 @@
1
+ import { fromFixedPoint } from "./numbers"
2
+
1
3
  const DEFAULT_FORMAT_OPTIONS: Intl.NumberFormatOptions = {
2
4
  style: "currency",
3
5
  minimumFractionDigits: 2,
@@ -30,3 +32,22 @@ export function formatCurrency(
30
32
  export function formatUsd(value: number): string {
31
33
  return formatCurrency(value, { currency: "USD" })
32
34
  }
35
+
36
+ /**
37
+ * Converts an asset amount to USD based on a conversion rate and decimals
38
+ * @param assetAmount - The amount of the asset in its smallest unit (e.g., satoshis for BTC)
39
+ * @param conversionRate - The conversion rate from the asset to USD in fixed-point format
40
+ * @param decimals - The number of decimals for the asset
41
+ * @returns - The value in USD as a number
42
+ */
43
+ export function convertToUsd(
44
+ assetAmount: bigint,
45
+ assetDecimals: number,
46
+ conversionRate: bigint,
47
+ conversionRateDecimals: number,
48
+ ): number {
49
+ return fromFixedPoint(
50
+ (assetAmount * conversionRate) / 10n ** BigInt(conversionRateDecimals),
51
+ assetDecimals,
52
+ )
53
+ }