@mezo-org/passport 0.4.0-dev.49 → 0.4.0-dev.50

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 (81) hide show
  1. package/dist/src/api/endpoint-error.d.ts +4 -0
  2. package/dist/src/api/endpoint-error.d.ts.map +1 -0
  3. package/dist/src/api/endpoint-error.js +6 -0
  4. package/dist/src/api/endpoint-error.js.map +1 -0
  5. package/dist/src/api/fetch-error copy.d.ts +5 -0
  6. package/dist/src/api/fetch-error copy.d.ts.map +1 -0
  7. package/dist/src/api/fetch-error copy.js +8 -0
  8. package/dist/src/api/fetch-error copy.js.map +1 -0
  9. package/dist/src/hooks/useAssetsConversionRates.d.ts +21 -5
  10. package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -1
  11. package/dist/src/hooks/useAssetsConversionRates.js +77 -16
  12. package/dist/src/hooks/useAssetsConversionRates.js.map +1 -1
  13. package/dist/src/hooks/useBitcoinPriceConversion copy.d.ts +2 -0
  14. package/dist/src/hooks/useBitcoinPriceConversion copy.d.ts.map +1 -0
  15. package/dist/src/hooks/useBitcoinPriceConversion copy.js +43 -0
  16. package/dist/src/hooks/useBitcoinPriceConversion copy.js.map +1 -0
  17. package/dist/src/hooks/useBitcoinPriceConversion.d.ts +103 -0
  18. package/dist/src/hooks/useBitcoinPriceConversion.d.ts.map +1 -0
  19. package/dist/src/hooks/useBitcoinPriceConversion.js +50 -0
  20. package/dist/src/hooks/useBitcoinPriceConversion.js.map +1 -0
  21. package/dist/src/hooks/useBitcoinPriceFeed.d.ts +15 -0
  22. package/dist/src/hooks/useBitcoinPriceFeed.d.ts.map +1 -0
  23. package/dist/src/hooks/useBitcoinPriceFeed.js +67 -0
  24. package/dist/src/hooks/useBitcoinPriceFeed.js.map +1 -0
  25. package/dist/src/hooks/useDropdownData.d.ts.map +1 -1
  26. package/dist/src/hooks/useDropdownData.js +11 -7
  27. package/dist/src/hooks/useDropdownData.js.map +1 -1
  28. package/dist/src/lib/contracts/index.d.ts +1 -1
  29. package/dist/src/lib/contracts/index.d.ts.map +1 -1
  30. package/dist/src/lib/contracts/index.js +1 -0
  31. package/dist/src/lib/contracts/index.js.map +1 -1
  32. package/dist/src/lib/contracts/price-oracle.d.ts +43 -0
  33. package/dist/src/lib/contracts/price-oracle.d.ts.map +1 -0
  34. package/dist/src/lib/contracts/price-oracle.js +52 -0
  35. package/dist/src/lib/contracts/price-oracle.js.map +1 -0
  36. package/dist/src/lib/contracts/priceOracle.d.ts +43 -0
  37. package/dist/src/lib/contracts/priceOracle.d.ts.map +1 -0
  38. package/dist/src/lib/contracts/priceOracle.js +52 -0
  39. package/dist/src/lib/contracts/priceOracle.js.map +1 -0
  40. package/dist/src/utils/cryptoAssets.d.ts +1 -1
  41. package/dist/src/utils/cryptoAssets.d.ts.map +1 -1
  42. package/dist/src/utils/cryptoAssets.js +6 -5
  43. package/dist/src/utils/cryptoAssets.js.map +1 -1
  44. package/package.json +15 -15
  45. package/src/api/auth.ts +3 -1
  46. package/src/api/client.ts +11 -2
  47. package/src/api/portal.ts +4 -1
  48. package/src/hooks/useAssetsConversionRates.ts +82 -22
  49. package/src/hooks/useDropdownData.ts +17 -7
  50. package/src/lib/contracts/index.ts +2 -0
  51. package/src/lib/contracts/priceOracle.ts +53 -0
  52. package/src/utils/cryptoAssets.ts +11 -11
  53. package/dist/cjs/index.js +0 -68
  54. package/dist/cjs/index.js.map +0 -1
  55. package/dist/esm/index.js +0 -68
  56. package/dist/esm/index.js.map +0 -1
  57. package/dist/index.d.ts +0 -31
  58. package/dist/src/components/Dropdown/AccountAddress.d.ts +0 -8
  59. package/dist/src/components/Dropdown/AccountAddress.d.ts.map +0 -1
  60. package/dist/src/components/Dropdown/AccountAddress.js +0 -66
  61. package/dist/src/components/Dropdown/AccountAddress.js.map +0 -1
  62. package/dist/src/components/Dropdown/AccountAssets.d.ts +0 -13
  63. package/dist/src/components/Dropdown/AccountAssets.d.ts.map +0 -1
  64. package/dist/src/components/Dropdown/AccountAssets.js +0 -43
  65. package/dist/src/components/Dropdown/AccountAssets.js.map +0 -1
  66. package/dist/src/components/Dropdown/AccountBalance.d.ts +0 -7
  67. package/dist/src/components/Dropdown/AccountBalance.d.ts.map +0 -1
  68. package/dist/src/components/Dropdown/AccountBalance.js +0 -16
  69. package/dist/src/components/Dropdown/AccountBalance.js.map +0 -1
  70. package/dist/src/components/Dropdown/WelcomeBlock.d.ts +0 -8
  71. package/dist/src/components/Dropdown/WelcomeBlock.d.ts.map +0 -1
  72. package/dist/src/components/Dropdown/WelcomeBlock.js +0 -43
  73. package/dist/src/components/Dropdown/WelcomeBlock.js.map +0 -1
  74. package/dist/src/hooks/useAssetsUSDConversion.d.ts +0 -8
  75. package/dist/src/hooks/useAssetsUSDConversion.d.ts.map +0 -1
  76. package/dist/src/hooks/useAssetsUSDConversion.js +0 -21
  77. package/dist/src/hooks/useAssetsUSDConversion.js.map +0 -1
  78. package/dist/src/lib/contracts/troveManager.d.ts +0 -1401
  79. package/dist/src/lib/contracts/troveManager.d.ts.map +0 -1
  80. package/dist/src/lib/contracts/troveManager.js +0 -1820
  81. package/dist/src/lib/contracts/troveManager.js.map +0 -1
@@ -0,0 +1,43 @@
1
+ import { Address } from "viem";
2
+ declare const _default: {
3
+ address: Address;
4
+ abi: readonly [{
5
+ readonly inputs: readonly [];
6
+ readonly name: "decimals";
7
+ readonly outputs: readonly [{
8
+ readonly internalType: "uint8";
9
+ readonly name: "";
10
+ readonly type: "uint8";
11
+ }];
12
+ readonly stateMutability: "view";
13
+ readonly type: "function";
14
+ }, {
15
+ readonly inputs: readonly [];
16
+ readonly name: "latestRoundData";
17
+ readonly outputs: readonly [{
18
+ readonly internalType: "uint80";
19
+ readonly name: "roundId";
20
+ readonly type: "uint80";
21
+ }, {
22
+ readonly internalType: "int256";
23
+ readonly name: "answer";
24
+ readonly type: "int256";
25
+ }, {
26
+ readonly internalType: "uint256";
27
+ readonly name: "startedAt";
28
+ readonly type: "uint256";
29
+ }, {
30
+ readonly internalType: "uint256";
31
+ readonly name: "updatedAt";
32
+ readonly type: "uint256";
33
+ }, {
34
+ readonly internalType: "uint80";
35
+ readonly name: "answeredInRound";
36
+ readonly type: "uint80";
37
+ }];
38
+ readonly stateMutability: "view";
39
+ readonly type: "function";
40
+ }];
41
+ };
42
+ export default _default;
43
+ //# sourceMappingURL=price-oracle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"price-oracle.d.ts","sourceRoot":"","sources":["../../../../src/lib/contracts/price-oracle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;;aAG6B,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AADlE,wBAkDC"}
@@ -0,0 +1,52 @@
1
+ export default {
2
+ address: "0x7b7c000000000000000000000000000000000015",
3
+ abi: [
4
+ {
5
+ inputs: [],
6
+ name: "decimals",
7
+ outputs: [
8
+ {
9
+ internalType: "uint8",
10
+ name: "",
11
+ type: "uint8",
12
+ },
13
+ ],
14
+ stateMutability: "view",
15
+ type: "function",
16
+ },
17
+ {
18
+ inputs: [],
19
+ name: "latestRoundData",
20
+ outputs: [
21
+ {
22
+ internalType: "uint80",
23
+ name: "roundId",
24
+ type: "uint80",
25
+ },
26
+ {
27
+ internalType: "int256",
28
+ name: "answer",
29
+ type: "int256",
30
+ },
31
+ {
32
+ internalType: "uint256",
33
+ name: "startedAt",
34
+ type: "uint256",
35
+ },
36
+ {
37
+ internalType: "uint256",
38
+ name: "updatedAt",
39
+ type: "uint256",
40
+ },
41
+ {
42
+ internalType: "uint80",
43
+ name: "answeredInRound",
44
+ type: "uint80",
45
+ },
46
+ ],
47
+ stateMutability: "view",
48
+ type: "function",
49
+ },
50
+ ],
51
+ };
52
+ //# sourceMappingURL=price-oracle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"price-oracle.js","sourceRoot":"","sources":["../../../../src/lib/contracts/price-oracle.ts"],"names":[],"mappings":"AAEA,eAAe;IACb,OAAO,EAAE,4CAAuD;IAChE,GAAG,EAAE;QACH;YACE,MAAM,EAAE,EAAE;YACV,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE;gBACP;oBACE,YAAY,EAAE,OAAO;oBACrB,IAAI,EAAE,EAAE;oBACR,IAAI,EAAE,OAAO;iBACd;aACF;YACD,eAAe,EAAE,MAAM;YACvB,IAAI,EAAE,UAAU;SACjB;QACD;YACE,MAAM,EAAE,EAAE;YACV,IAAI,EAAE,iBAAiB;YACvB,OAAO,EAAE;gBACP;oBACE,YAAY,EAAE,QAAQ;oBACtB,IAAI,EAAE,SAAS;oBACf,IAAI,EAAE,QAAQ;iBACf;gBACD;oBACE,YAAY,EAAE,QAAQ;oBACtB,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,QAAQ;iBACf;gBACD;oBACE,YAAY,EAAE,SAAS;oBACvB,IAAI,EAAE,WAAW;oBACjB,IAAI,EAAE,SAAS;iBAChB;gBACD;oBACE,YAAY,EAAE,SAAS;oBACvB,IAAI,EAAE,WAAW;oBACjB,IAAI,EAAE,SAAS;iBAChB;gBACD;oBACE,YAAY,EAAE,QAAQ;oBACtB,IAAI,EAAE,iBAAiB;oBACvB,IAAI,EAAE,QAAQ;iBACf;aACF;YACD,eAAe,EAAE,MAAM;YACvB,IAAI,EAAE,UAAU;SACjB;KACO;CACX,CAAA"}
@@ -0,0 +1,43 @@
1
+ import { Address } from "viem";
2
+ declare const _default: {
3
+ address: Address;
4
+ abi: readonly [{
5
+ readonly inputs: readonly [];
6
+ readonly name: "decimals";
7
+ readonly outputs: readonly [{
8
+ readonly internalType: "uint8";
9
+ readonly name: "";
10
+ readonly type: "uint8";
11
+ }];
12
+ readonly stateMutability: "view";
13
+ readonly type: "function";
14
+ }, {
15
+ readonly inputs: readonly [];
16
+ readonly name: "latestRoundData";
17
+ readonly outputs: readonly [{
18
+ readonly internalType: "uint80";
19
+ readonly name: "roundId";
20
+ readonly type: "uint80";
21
+ }, {
22
+ readonly internalType: "int256";
23
+ readonly name: "answer";
24
+ readonly type: "int256";
25
+ }, {
26
+ readonly internalType: "uint256";
27
+ readonly name: "startedAt";
28
+ readonly type: "uint256";
29
+ }, {
30
+ readonly internalType: "uint256";
31
+ readonly name: "updatedAt";
32
+ readonly type: "uint256";
33
+ }, {
34
+ readonly internalType: "uint80";
35
+ readonly name: "answeredInRound";
36
+ readonly type: "uint80";
37
+ }];
38
+ readonly stateMutability: "view";
39
+ readonly type: "function";
40
+ }];
41
+ };
42
+ export default _default;
43
+ //# sourceMappingURL=priceOracle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"priceOracle.d.ts","sourceRoot":"","sources":["../../../../src/lib/contracts/priceOracle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;;aAG6B,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AADlE,wBAkDC"}
@@ -0,0 +1,52 @@
1
+ export default {
2
+ address: "0x7b7c000000000000000000000000000000000015",
3
+ abi: [
4
+ {
5
+ inputs: [],
6
+ name: "decimals",
7
+ outputs: [
8
+ {
9
+ internalType: "uint8",
10
+ name: "",
11
+ type: "uint8",
12
+ },
13
+ ],
14
+ stateMutability: "view",
15
+ type: "function",
16
+ },
17
+ {
18
+ inputs: [],
19
+ name: "latestRoundData",
20
+ outputs: [
21
+ {
22
+ internalType: "uint80",
23
+ name: "roundId",
24
+ type: "uint80",
25
+ },
26
+ {
27
+ internalType: "int256",
28
+ name: "answer",
29
+ type: "int256",
30
+ },
31
+ {
32
+ internalType: "uint256",
33
+ name: "startedAt",
34
+ type: "uint256",
35
+ },
36
+ {
37
+ internalType: "uint256",
38
+ name: "updatedAt",
39
+ type: "uint256",
40
+ },
41
+ {
42
+ internalType: "uint80",
43
+ name: "answeredInRound",
44
+ type: "uint80",
45
+ },
46
+ ],
47
+ stateMutability: "view",
48
+ type: "function",
49
+ },
50
+ ],
51
+ };
52
+ //# sourceMappingURL=priceOracle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"priceOracle.js","sourceRoot":"","sources":["../../../../src/lib/contracts/priceOracle.ts"],"names":[],"mappings":"AAEA,eAAe;IACb,OAAO,EAAE,4CAAuD;IAChE,GAAG,EAAE;QACH;YACE,MAAM,EAAE,EAAE;YACV,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE;gBACP;oBACE,YAAY,EAAE,OAAO;oBACrB,IAAI,EAAE,EAAE;oBACR,IAAI,EAAE,OAAO;iBACd;aACF;YACD,eAAe,EAAE,MAAM;YACvB,IAAI,EAAE,UAAU;SACjB;QACD;YACE,MAAM,EAAE,EAAE;YACV,IAAI,EAAE,iBAAiB;YACvB,OAAO,EAAE;gBACP;oBACE,YAAY,EAAE,QAAQ;oBACtB,IAAI,EAAE,SAAS;oBACf,IAAI,EAAE,QAAQ;iBACf;gBACD;oBACE,YAAY,EAAE,QAAQ;oBACtB,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,QAAQ;iBACf;gBACD;oBACE,YAAY,EAAE,SAAS;oBACvB,IAAI,EAAE,WAAW;oBACjB,IAAI,EAAE,SAAS;iBAChB;gBACD;oBACE,YAAY,EAAE,SAAS;oBACvB,IAAI,EAAE,WAAW;oBACjB,IAAI,EAAE,SAAS;iBAChB;gBACD;oBACE,YAAY,EAAE,QAAQ;oBACtB,IAAI,EAAE,iBAAiB;oBACvB,IAAI,EAAE,QAAQ;iBACf;aACF;YACD,eAAe,EAAE,MAAM;YACvB,IAAI,EAAE,UAAU;SACjB;KACO;CACX,CAAA"}
@@ -33,7 +33,7 @@ export declare function isUsdLikeCryptoAsset(key: CryptoAssetKey): boolean;
33
33
  * @param usdConversionRate The USD conversion rate
34
34
  * @returns The balance details
35
35
  */
36
- export declare function mapCryptoAssetToDetails(type: CryptoAssetKey, balance: bigint, usdConversionRate: number): {
36
+ export declare function mapCryptoAssetToDetails(type: CryptoAssetKey, balance: bigint, usdConversionRate?: bigint, usdConversionRateDecimals?: number): {
37
37
  type: CryptoAssetKey;
38
38
  rawBalance: bigint;
39
39
  formattedBalance: string;
@@ -1 +1 @@
1
- {"version":3,"file":"cryptoAssets.d.ts","sourceRoot":"","sources":["../../../src/utils/cryptoAssets.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,SAAS,EAGV,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAQjD,MAAM,MAAM,cAAc,GAAG,cAAc,GAAG,KAAK,GAAG,KAAK,CAAA;AAE3D,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAqFD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,cAAc,eAEjD;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,cAAc,WAE3D;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,cAAc,WAEvD;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,cAAc,EACpB,OAAO,EAAE,MAAM,EACf,iBAAiB,EAAE,MAAM;;;;;;EAyB1B;AAED,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAAA"}
1
+ {"version":3,"file":"cryptoAssets.d.ts","sourceRoot":"","sources":["../../../src/utils/cryptoAssets.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,SAAS,EAGV,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAIjD,MAAM,MAAM,cAAc,GAAG,cAAc,GAAG,KAAK,GAAG,KAAK,CAAA;AAE3D,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAqFD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,cAAc,eAEjD;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,cAAc,WAE3D;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,cAAc,WAEvD;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,cAAc,EACpB,OAAO,EAAE,MAAM,EACf,iBAAiB,CAAC,EAAE,MAAM,EAC1B,yBAAyB,CAAC,EAAE,MAAM;;;;;;EA4BnC;AAED,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAAA"}
@@ -1,6 +1,6 @@
1
1
  import { BitcoinCircle, EthCircle, MUsdCircle02, Cryptocurrency04, } from "@mezo-org/mezo-clay";
2
2
  import { formatUsd } from "./currency";
3
- import { fromFixedPointToString, fromFixedPoint, fromFloatToBigInt, } from "./numbers";
3
+ import { fromFixedPointToString, fromFixedPoint } from "./numbers";
4
4
  // TODO: Add actual icons for the assets
5
5
  const CRYPTO_ASSETS = {
6
6
  BTC: {
@@ -113,12 +113,13 @@ export function isUsdLikeCryptoAsset(key) {
113
113
  * @param usdConversionRate The USD conversion rate
114
114
  * @returns The balance details
115
115
  */
116
- export function mapCryptoAssetToDetails(type, balance, usdConversionRate) {
116
+ export function mapCryptoAssetToDetails(type, balance, usdConversionRate, usdConversionRateDecimals) {
117
117
  const { decimals } = getCryptoAsset(type);
118
118
  const formattedBalance = fromFixedPointToString(balance, decimals, isUsdLikeCryptoAsset(type) ? 2 : 4);
119
- const usdBalance = fromFixedPoint(
120
- // Native BigInt constructor doesn't support floating point numbers.
121
- balance * fromFloatToBigInt(usdConversionRate, 0), decimals);
119
+ let usdBalance = fromFixedPoint(balance, decimals);
120
+ if (usdConversionRate && usdConversionRateDecimals) {
121
+ usdBalance = fromFixedPoint((usdConversionRate * balance) / 10n ** BigInt(decimals), usdConversionRateDecimals);
122
+ }
122
123
  const formattedUsdBalance = formatUsd(usdBalance);
123
124
  return {
124
125
  type,
@@ -1 +1 @@
1
- {"version":3,"file":"cryptoAssets.js","sourceRoot":"","sources":["../../../src/utils/cryptoAssets.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,SAAS,EAET,YAAY,EACZ,gBAAgB,GACjB,MAAM,qBAAqB,CAAA;AAG5B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,iBAAiB,GAClB,MAAM,WAAW,CAAA;AAWlB,wCAAwC;AAExC,MAAM,aAAa,GAAwC;IACzD,GAAG,EAAE;QACH,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,KAAK;QACb,IAAI,EAAE,aAAa;QACnB,QAAQ,EAAE,EAAE;KACb;IACD,GAAG,EAAE;QACH,IAAI,EAAE,UAAU;QAChB,MAAM,EAAE,KAAK;QACb,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,EAAE;KACb;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,YAAY;QAClB,QAAQ,EAAE,EAAE;KACb;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,gBAAgB;QACtB,QAAQ,EAAE,EAAE;KACb;IACD,KAAK,EAAE;QACL,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,OAAO;QACf,IAAI,EAAE,aAAa;QACnB,QAAQ,EAAE,CAAC;KACZ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ezo-org/passport",
3
- "version": "0.4.0-dev.49",
3
+ "version": "0.4.0-dev.50",
4
4
  "main": "dist/src/index.js",
5
5
  "license": "GPL-3.0-only",
6
+ "scripts": {
7
+ "build": "tsc",
8
+ "dev": "tsc --watch",
9
+ "format": "npm run lint:js && npm run lint:config",
10
+ "format:fix": "npm run lint:js:fix && npm run lint:config:fix",
11
+ "lint:js": "eslint .",
12
+ "lint:js:fix": "eslint . --fix",
13
+ "lint:config": "prettier -c '**/*.@(json|yaml|toml)'",
14
+ "lint:config:fix": "prettier -w '**/*.@(json|yaml|toml)'",
15
+ "test": "jest --verbose"
16
+ },
6
17
  "files": [
7
18
  "dist/",
8
19
  "src/"
@@ -29,6 +40,7 @@
29
40
  "@mezo-org/mezo-clay": "0.1.0-dev.27",
30
41
  "@mezo-org/mezod-contracts": "^1.0.0",
31
42
  "@mezo-org/musd-contracts": "^1.0.1",
43
+ "@mezo-org/orangekit": "1.0.0-beta.40-dev.10",
32
44
  "@mezo-org/sign-in-with-wallet": "1.0.0-beta.8",
33
45
  "@rainbow-me/rainbowkit": "2.0.2",
34
46
  "@tanstack/react-query": "^5.28.4",
@@ -38,18 +50,6 @@
38
50
  "usehooks-ts": "^3.1.1",
39
51
  "viem": "2.22.8",
40
52
  "wagmi": "2.5.12",
41
- "zustand": "^5.0.3",
42
- "@mezo-org/orangekit": "1.0.0-beta.40-dev.8"
43
- },
44
- "scripts": {
45
- "build": "tsc",
46
- "dev": "tsc --watch",
47
- "format": "npm run lint:js && npm run lint:config",
48
- "format:fix": "npm run lint:js:fix && npm run lint:config:fix",
49
- "lint:js": "eslint .",
50
- "lint:js:fix": "eslint . --fix",
51
- "lint:config": "prettier -c '**/*.@(json|yaml|toml)'",
52
- "lint:config:fix": "prettier -w '**/*.@(json|yaml|toml)'",
53
- "test": "jest --verbose"
53
+ "zustand": "^5.0.3"
54
54
  }
55
- }
55
+ }
package/src/api/auth.ts CHANGED
@@ -82,7 +82,9 @@ export class AuthApiClient extends ApiClient {
82
82
  environment: keyof typeof AUTH_API_ENDPOINTS_BY_ENV = "mainnet",
83
83
  apiUrl?: string,
84
84
  ) {
85
- super(apiUrl ?? AUTH_API_ENDPOINTS_BY_ENV[environment])
85
+ super({
86
+ apiUrl: apiUrl ?? AUTH_API_ENDPOINTS_BY_ENV[environment],
87
+ })
86
88
  }
87
89
 
88
90
  async getSession(code?: string) {
package/src/api/client.ts CHANGED
@@ -5,10 +5,19 @@ type RequestHandlerOptions = Omit<RequestInit, "credentials" | "body"> & {
5
5
  queryParams?: Record<string, string | undefined>
6
6
  }
7
7
 
8
+ const ENDS_WITH_VERSIONING_REGEX = /\/v\d+(?=\/|$)/
9
+ const TRAILING_SLASH_REGEX = /\/$/
10
+
8
11
  export abstract class ApiClient {
9
12
  private apiUrl: string
10
13
 
11
- constructor(apiUrl: string) {
14
+ constructor(opts: { apiUrl: string; removeVersioning?: boolean }) {
15
+ const { apiUrl, removeVersioning = false } = opts
16
+
17
+ if (removeVersioning) {
18
+ this.apiUrl = apiUrl.replace(ENDS_WITH_VERSIONING_REGEX, "")
19
+ return
20
+ }
12
21
  this.apiUrl = apiUrl
13
22
  }
14
23
 
@@ -33,7 +42,7 @@ export abstract class ApiClient {
33
42
  const { method, body, queryParams = {}, ...restOptions } = options
34
43
 
35
44
  // If last character in apiUrl is forward slash we are removing it
36
- const authApiUrlRoute = this.apiUrl.replace(/\/$/, "")
45
+ const authApiUrlRoute = this.apiUrl.replace(TRAILING_SLASH_REGEX, "")
37
46
  const url = new URL(`${authApiUrlRoute}${endpoint}`)
38
47
 
39
48
  // Removes falsy values (e.g. null, undefined etc.) from query params and
package/src/api/portal.ts CHANGED
@@ -26,7 +26,10 @@ export class PortalApiClient extends ApiClient {
26
26
  environment: keyof typeof PORTAL_API_ENDPOINTS_BY_ENV = "mainnet",
27
27
  apiUrl?: string,
28
28
  ) {
29
- super(apiUrl ?? PORTAL_API_ENDPOINTS_BY_ENV[environment])
29
+ super({
30
+ apiUrl: apiUrl ?? PORTAL_API_ENDPOINTS_BY_ENV[environment],
31
+ removeVersioning: true,
32
+ })
30
33
  }
31
34
 
32
35
  async getPortalStatistics() {
@@ -1,32 +1,92 @@
1
- import { UseBaseQueryOptions, useQuery } from "@tanstack/react-query"
2
- import { ONE_MINUTE_MS } from "../utils/time"
1
+ import { useQuery } from "@tanstack/react-query"
2
+ import { useReadContract } from "wagmi"
3
+ import { ONE_SECOND_MS } from "../utils/time"
3
4
  import { QUERY_KEYS } from "./constants"
4
5
  import { usePortalApiClient } from "./usePortalApiClient"
6
+ import { priceOracleContract } from "../lib/contracts"
7
+ import { fromFloatToBigInt } from "../utils/numbers"
5
8
 
6
- type AssetsUsdConversion = {
7
- usd: Record<"btc" | "eth" | "t", number>
9
+ const BTC_TARGET_DIGITS = 18
10
+ const T_TARGET_DIGITS = 10
11
+ // If the oracle has not been updated in at least 60 seconds, it is stale.
12
+ const MAX_PRICE_DELAY = 60 * ONE_SECOND_MS
13
+
14
+ /**
15
+ * Scales the price by the number of digits.
16
+ * @dev Oracles returns prices with variable number of digits. This function
17
+ * scales the price to a fixed number of digits ensuring consistency.
18
+ * @param price - The price to scale.
19
+ * @param priceDigits - The number of digits in the price.
20
+ * @returns The scaled price.
21
+ */
22
+ function scalePriceByDigits(price: bigint, priceDigits: number): bigint {
23
+ if (priceDigits > BTC_TARGET_DIGITS) {
24
+ return price / 10n ** BigInt(priceDigits - BTC_TARGET_DIGITS)
25
+ }
26
+ if (priceDigits < BTC_TARGET_DIGITS) {
27
+ return price * 10n ** BigInt(BTC_TARGET_DIGITS - priceDigits)
28
+ }
29
+ return price
8
30
  }
9
31
 
10
- export default function useAssetsConversionRates(
11
- useQueryOptions: Partial<UseBaseQueryOptions<AssetsUsdConversion>> = {},
12
- ) {
32
+ /**
33
+ * Hook to fetch assets conversion rates.
34
+ * @see https://github.com/mezo-org/musd/blob/f0b2030315f0d8b0fc11a9fc778856fe4673051f/solidity/contracts/PriceFeed.sol
35
+ * @returns {}.data.{}.price - The latest asset price.
36
+ * @returns {}.data.{}.digits - The latest asset price digits.
37
+ * @returns {}.isPending - Whether the request is pending.
38
+ * @returns {}.isError - Whether there was an error fetching the price.
39
+ */
40
+ export function useAssetsConversionRates() {
13
41
  const portalApiClient = usePortalApiClient()
14
42
 
15
- return useQuery({
16
- queryKey: [QUERY_KEYS.ASSETS_USD_CONVERSION],
17
- queryFn: async () => {
18
- const { currentUsdPerBtc, currentUsdPerEth, currentUsdPerTToken } =
19
- await portalApiClient.getPortalStatistics()
20
- return {
21
- usd: {
22
- btc: Number(currentUsdPerBtc),
23
- eth: Number(currentUsdPerEth),
24
- t: Number(currentUsdPerTToken),
25
- },
26
- }
43
+ const btcPrice = useReadContract({
44
+ ...priceOracleContract,
45
+ functionName: "latestRoundData",
46
+ query: {
47
+ refetchInterval: ({ state }) => {
48
+ if (!state.data) return MAX_PRICE_DELAY
49
+
50
+ const [, , , updatedAt] = state.data ?? []
51
+ if (!updatedAt) return MAX_PRICE_DELAY
52
+
53
+ const age = Date.now() - Number(updatedAt) * 1000
54
+
55
+ return age > MAX_PRICE_DELAY
56
+ ? // If the data is stale, we want to refetch as soon as possible, but
57
+ // not faster than once per second, to avoid excessive requests.
58
+ // Math.max ensures the interval is at least 1 second.
59
+ Math.max(ONE_SECOND_MS, MAX_PRICE_DELAY - age)
60
+ : MAX_PRICE_DELAY - age
61
+ },
62
+ select: (data) => {
63
+ const [, answer] = data
64
+ return scalePriceByDigits(answer, BTC_TARGET_DIGITS)
65
+ },
27
66
  },
28
- staleTime: 30 * ONE_MINUTE_MS,
29
- retry: 1,
30
- ...useQueryOptions,
31
67
  })
68
+
69
+ const tPrice = useQuery({
70
+ queryKey: [QUERY_KEYS.ASSETS_USD_CONVERSION],
71
+ queryFn: () => portalApiClient.getPortalStatistics(),
72
+ select: (data) =>
73
+ fromFloatToBigInt(data.currentUsdPerTToken, T_TARGET_DIGITS),
74
+ refetchInterval: MAX_PRICE_DELAY,
75
+ throwOnError: true,
76
+ })
77
+
78
+ return {
79
+ data: {
80
+ t: {
81
+ price: tPrice.data ?? 0n,
82
+ decimals: T_TARGET_DIGITS,
83
+ },
84
+ btc: {
85
+ price: btcPrice.data ?? 0n,
86
+ decimals: BTC_TARGET_DIGITS,
87
+ },
88
+ },
89
+ isPending: tPrice.isPending || btcPrice.isPending,
90
+ isError: tPrice.isError || btcPrice.isError,
91
+ }
32
92
  }
@@ -6,7 +6,7 @@ import {
6
6
  mapCryptoAssetToDetails,
7
7
  } from "../utils/cryptoAssets"
8
8
  import { fromFixedPoint } from "../utils/numbers"
9
- import useAssetsConversionRates from "./useAssetsConversionRates"
9
+ import { useAssetsConversionRates } from "./useAssetsConversionRates"
10
10
  import useWalletAccount from "./useWalletAccount"
11
11
  import { useTokensBalances } from "./useTokensBalances"
12
12
  import { useBorrowData } from "./useBorrowData"
@@ -73,14 +73,24 @@ export default function useDropdownData({
73
73
  ].map((asset) => {
74
74
  const [type, balance] = asset as [CryptoAssetKey, bigint]
75
75
 
76
- let usdConversionRate: number | undefined
77
- if (isBitcoinLikeCryptoAsset(type))
78
- usdConversionRate = assetsConversionRates?.usd.btc
76
+ let conversionRate: bigint | undefined
77
+ let conversionRateDecimals: number | undefined
78
+
79
+ if (isBitcoinLikeCryptoAsset(type)) {
80
+ conversionRate = assetsConversionRates.btc.price
81
+ conversionRateDecimals = assetsConversionRates.btc.decimals
82
+ }
79
83
  if (type === "mT") {
80
- usdConversionRate = assetsConversionRates?.usd.t
84
+ conversionRate = assetsConversionRates.t.price
85
+ conversionRateDecimals = assetsConversionRates.t.decimals
81
86
  }
82
87
 
83
- return mapCryptoAssetToDetails(type, balance, usdConversionRate || 1)
88
+ return mapCryptoAssetToDetails(
89
+ type,
90
+ balance,
91
+ conversionRate,
92
+ conversionRateDecimals,
93
+ )
84
94
  })
85
95
 
86
96
  const btcData = detailedAssets.find(({ type }) => type === "BTC")!
@@ -117,7 +127,7 @@ export default function useDropdownData({
117
127
  const matsBalance = passportAccount?.mats.totalMats || 0
118
128
 
119
129
  const usdCollateral = fromFixedPoint(
120
- (debt?.collateral ?? 0n) * BigInt(assetsConversionRates?.usd.btc ?? 0),
130
+ (debt?.collateral ?? 0n) * assetsConversionRates.btc.price,
121
131
  18,
122
132
  )
123
133
 
@@ -86,3 +86,5 @@ export const mainnetBorrowContracts = {
86
86
  export const testnetBorrowContracts = {
87
87
  TroveManager: troveManagerTestnet,
88
88
  } as unknown as ContractsMap<MezoBorrowContract>
89
+
90
+ 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
+ }
@@ -8,11 +8,7 @@ import {
8
8
  import { FC } from "react"
9
9
  import { MezoChainToken } from "../lib/contracts"
10
10
  import { formatUsd } from "./currency"
11
- import {
12
- fromFixedPointToString,
13
- fromFixedPoint,
14
- fromFloatToBigInt,
15
- } from "./numbers"
11
+ import { fromFixedPointToString, fromFixedPoint } from "./numbers"
16
12
 
17
13
  export type CryptoAssetKey = MezoChainToken | "BTC" | "ETH"
18
14
 
@@ -143,7 +139,8 @@ export function isUsdLikeCryptoAsset(key: CryptoAssetKey) {
143
139
  export function mapCryptoAssetToDetails(
144
140
  type: CryptoAssetKey,
145
141
  balance: bigint,
146
- usdConversionRate: number,
142
+ usdConversionRate?: bigint,
143
+ usdConversionRateDecimals?: number,
147
144
  ) {
148
145
  const { decimals } = getCryptoAsset(type)
149
146
 
@@ -153,11 +150,14 @@ export function mapCryptoAssetToDetails(
153
150
  isUsdLikeCryptoAsset(type) ? 2 : 4,
154
151
  )
155
152
 
156
- const usdBalance = fromFixedPoint(
157
- // Native BigInt constructor doesn't support floating point numbers.
158
- balance * fromFloatToBigInt(usdConversionRate, 0),
159
- decimals,
160
- )
153
+ let usdBalance = fromFixedPoint(balance, decimals)
154
+
155
+ if (usdConversionRate && usdConversionRateDecimals) {
156
+ usdBalance = fromFixedPoint(
157
+ (usdConversionRate * balance) / 10n ** BigInt(decimals),
158
+ usdConversionRateDecimals,
159
+ )
160
+ }
161
161
 
162
162
  const formattedUsdBalance = formatUsd(usdBalance)
163
163