lampamazaza-new-intents-sdk 0.47.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 (179) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1083 -0
  3. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  4. package/dist/index.cjs +124 -0
  5. package/dist/index.d.cts +22 -0
  6. package/dist/index.d.ts +22 -0
  7. package/dist/index.js +19 -0
  8. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-constants.cjs +10 -0
  9. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-constants.js +7 -0
  10. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-utils.cjs +44 -0
  11. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-utils.js +42 -0
  12. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.cjs +111 -0
  13. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.js +110 -0
  14. package/dist/src/bridges/direct-bridge/direct-bridge-constants.cjs +8 -0
  15. package/dist/src/bridges/direct-bridge/direct-bridge-constants.js +6 -0
  16. package/dist/src/bridges/direct-bridge/direct-bridge-utils.cjs +47 -0
  17. package/dist/src/bridges/direct-bridge/direct-bridge-utils.js +44 -0
  18. package/dist/src/bridges/direct-bridge/direct-bridge.cjs +155 -0
  19. package/dist/src/bridges/direct-bridge/direct-bridge.js +154 -0
  20. package/dist/src/bridges/direct-bridge/error.cjs +16 -0
  21. package/dist/src/bridges/direct-bridge/error.d.cts +12 -0
  22. package/dist/src/bridges/direct-bridge/error.d.ts +12 -0
  23. package/dist/src/bridges/direct-bridge/error.js +15 -0
  24. package/dist/src/bridges/hot-bridge/error.cjs +23 -0
  25. package/dist/src/bridges/hot-bridge/error.d.cts +19 -0
  26. package/dist/src/bridges/hot-bridge/error.d.ts +19 -0
  27. package/dist/src/bridges/hot-bridge/error.js +21 -0
  28. package/dist/src/bridges/hot-bridge/hot-bridge-chains.cjs +21 -0
  29. package/dist/src/bridges/hot-bridge/hot-bridge-chains.d.cts +6 -0
  30. package/dist/src/bridges/hot-bridge/hot-bridge-chains.d.ts +6 -0
  31. package/dist/src/bridges/hot-bridge/hot-bridge-chains.js +20 -0
  32. package/dist/src/bridges/hot-bridge/hot-bridge-constants.cjs +11 -0
  33. package/dist/src/bridges/hot-bridge/hot-bridge-constants.js +9 -0
  34. package/dist/src/bridges/hot-bridge/hot-bridge-utils.cjs +66 -0
  35. package/dist/src/bridges/hot-bridge/hot-bridge-utils.js +61 -0
  36. package/dist/src/bridges/hot-bridge/hot-bridge.cjs +241 -0
  37. package/dist/src/bridges/hot-bridge/hot-bridge.js +239 -0
  38. package/dist/src/bridges/intents-bridge/intents-bridge.cjs +59 -0
  39. package/dist/src/bridges/intents-bridge/intents-bridge.js +59 -0
  40. package/dist/src/bridges/omni-bridge/error.cjs +54 -0
  41. package/dist/src/bridges/omni-bridge/error.d.cts +41 -0
  42. package/dist/src/bridges/omni-bridge/error.d.ts +41 -0
  43. package/dist/src/bridges/omni-bridge/error.js +49 -0
  44. package/dist/src/bridges/omni-bridge/omni-bridge-constants.cjs +12 -0
  45. package/dist/src/bridges/omni-bridge/omni-bridge-constants.js +8 -0
  46. package/dist/src/bridges/omni-bridge/omni-bridge-utils.cjs +153 -0
  47. package/dist/src/bridges/omni-bridge/omni-bridge-utils.js +143 -0
  48. package/dist/src/bridges/omni-bridge/omni-bridge.cjs +316 -0
  49. package/dist/src/bridges/omni-bridge/omni-bridge.js +314 -0
  50. package/dist/src/bridges/poa-bridge/poa-bridge-utils.cjs +76 -0
  51. package/dist/src/bridges/poa-bridge/poa-bridge-utils.js +73 -0
  52. package/dist/src/bridges/poa-bridge/poa-bridge.cjs +175 -0
  53. package/dist/src/bridges/poa-bridge/poa-bridge.js +173 -0
  54. package/dist/src/bridges/poa-bridge/poa-constants.cjs +6 -0
  55. package/dist/src/bridges/poa-bridge/poa-constants.js +5 -0
  56. package/dist/src/classes/errors.cjs +87 -0
  57. package/dist/src/classes/errors.d.cts +48 -0
  58. package/dist/src/classes/errors.d.ts +48 -0
  59. package/dist/src/classes/errors.js +81 -0
  60. package/dist/src/constants/bridge-name-enum.cjs +11 -0
  61. package/dist/src/constants/bridge-name-enum.d.cts +11 -0
  62. package/dist/src/constants/bridge-name-enum.d.ts +11 -0
  63. package/dist/src/constants/bridge-name-enum.js +10 -0
  64. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.cjs +17 -0
  65. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.cts +12 -0
  66. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.ts +12 -0
  67. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.js +16 -0
  68. package/dist/src/constants/public-rpc-urls.cjs +25 -0
  69. package/dist/src/constants/public-rpc-urls.js +24 -0
  70. package/dist/src/constants/route-enum.cjs +13 -0
  71. package/dist/src/constants/route-enum.d.cts +13 -0
  72. package/dist/src/constants/route-enum.d.ts +13 -0
  73. package/dist/src/constants/route-enum.js +12 -0
  74. package/dist/src/constants/withdrawal-timing.cjs +68 -0
  75. package/dist/src/constants/withdrawal-timing.js +68 -0
  76. package/dist/src/core/withdrawal-watcher.cjs +86 -0
  77. package/dist/src/core/withdrawal-watcher.d.cts +18 -0
  78. package/dist/src/core/withdrawal-watcher.d.ts +19 -0
  79. package/dist/src/core/withdrawal-watcher.js +82 -0
  80. package/dist/src/intents/expirable-nonce.cjs +90 -0
  81. package/dist/src/intents/expirable-nonce.d.cts +44 -0
  82. package/dist/src/intents/expirable-nonce.d.ts +45 -0
  83. package/dist/src/intents/expirable-nonce.js +82 -0
  84. package/dist/src/intents/intent-executer-impl/intent-executer.cjs +85 -0
  85. package/dist/src/intents/intent-executer-impl/intent-executer.d.cts +20 -0
  86. package/dist/src/intents/intent-executer-impl/intent-executer.d.ts +24 -0
  87. package/dist/src/intents/intent-executer-impl/intent-executer.js +85 -0
  88. package/dist/src/intents/intent-hash.cjs +48 -0
  89. package/dist/src/intents/intent-hash.d.cts +8 -0
  90. package/dist/src/intents/intent-hash.d.ts +8 -0
  91. package/dist/src/intents/intent-hash.js +47 -0
  92. package/dist/src/intents/intent-hashes/erc191.cjs +38 -0
  93. package/dist/src/intents/intent-hashes/erc191.js +37 -0
  94. package/dist/src/intents/intent-hashes/nep413.cjs +23 -0
  95. package/dist/src/intents/intent-hashes/nep413.js +22 -0
  96. package/dist/src/intents/intent-hashes/raw-ed25519.cjs +26 -0
  97. package/dist/src/intents/intent-hashes/raw-ed25519.js +25 -0
  98. package/dist/src/intents/intent-hashes/sep53.cjs +36 -0
  99. package/dist/src/intents/intent-hashes/sep53.js +35 -0
  100. package/dist/src/intents/intent-hashes/tip191.cjs +39 -0
  101. package/dist/src/intents/intent-hashes/tip191.js +38 -0
  102. package/dist/src/intents/intent-hashes/ton-connect.cjs +105 -0
  103. package/dist/src/intents/intent-hashes/ton-connect.js +104 -0
  104. package/dist/src/intents/intent-hashes/webauthn.cjs +26 -0
  105. package/dist/src/intents/intent-hashes/webauthn.js +25 -0
  106. package/dist/src/intents/intent-payload-builder.cjs +208 -0
  107. package/dist/src/intents/intent-payload-builder.d.cts +161 -0
  108. package/dist/src/intents/intent-payload-builder.d.ts +161 -0
  109. package/dist/src/intents/intent-payload-builder.js +207 -0
  110. package/dist/src/intents/intent-payload-factory.cjs +23 -0
  111. package/dist/src/intents/intent-payload-factory.js +21 -0
  112. package/dist/src/intents/intent-relayer-impl/intent-relayer-public.cjs +43 -0
  113. package/dist/src/intents/intent-relayer-impl/intent-relayer-public.js +42 -0
  114. package/dist/src/intents/intent-signer-impl/factories.cjs +19 -0
  115. package/dist/src/intents/intent-signer-impl/factories.d.cts +11 -0
  116. package/dist/src/intents/intent-signer-impl/factories.d.ts +11 -0
  117. package/dist/src/intents/intent-signer-impl/factories.js +17 -0
  118. package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.cjs +22 -0
  119. package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.d.cts +15 -0
  120. package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.d.ts +16 -0
  121. package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.js +21 -0
  122. package/dist/src/intents/intent-signer-impl/intent-signer-nep413.cjs +37 -0
  123. package/dist/src/intents/intent-signer-impl/intent-signer-nep413.d.cts +14 -0
  124. package/dist/src/intents/intent-signer-impl/intent-signer-nep413.d.ts +14 -0
  125. package/dist/src/intents/intent-signer-impl/intent-signer-nep413.js +36 -0
  126. package/dist/src/intents/intent-signer-impl/intent-signer-noop.cjs +8 -0
  127. package/dist/src/intents/intent-signer-impl/intent-signer-noop.js +7 -0
  128. package/dist/src/intents/intent-signer-impl/intent-signer-viem.cjs +31 -0
  129. package/dist/src/intents/intent-signer-impl/intent-signer-viem.d.cts +17 -0
  130. package/dist/src/intents/intent-signer-impl/intent-signer-viem.d.ts +17 -0
  131. package/dist/src/intents/intent-signer-impl/intent-signer-viem.js +30 -0
  132. package/dist/src/intents/interfaces/intent-executer.d.ts +2 -0
  133. package/dist/src/intents/interfaces/intent-relayer.d.cts +43 -0
  134. package/dist/src/intents/interfaces/intent-relayer.d.ts +43 -0
  135. package/dist/src/intents/interfaces/intent-signer.d.cts +8 -0
  136. package/dist/src/intents/interfaces/intent-signer.d.ts +8 -0
  137. package/dist/src/intents/interfaces/salt-manager.d.cts +9 -0
  138. package/dist/src/intents/interfaces/salt-manager.d.ts +9 -0
  139. package/dist/src/intents/salt-manager.cjs +74 -0
  140. package/dist/src/intents/salt-manager.js +72 -0
  141. package/dist/src/intents/shared-types.d.cts +20 -0
  142. package/dist/src/intents/shared-types.d.ts +20 -0
  143. package/dist/src/lib/array.cjs +11 -0
  144. package/dist/src/lib/array.js +10 -0
  145. package/dist/src/lib/caip2.cjs +50 -0
  146. package/dist/src/lib/caip2.d.cts +38 -0
  147. package/dist/src/lib/caip2.d.ts +38 -0
  148. package/dist/src/lib/caip2.js +48 -0
  149. package/dist/src/lib/configure-rpc-config.cjs +20 -0
  150. package/dist/src/lib/configure-rpc-config.js +18 -0
  151. package/dist/src/lib/estimate-fee.cjs +96 -0
  152. package/dist/src/lib/estimate-fee.js +94 -0
  153. package/dist/src/lib/hex.cjs +11 -0
  154. package/dist/src/lib/hex.js +10 -0
  155. package/dist/src/lib/nep413.cjs +42 -0
  156. package/dist/src/lib/nep413.d.cts +14 -0
  157. package/dist/src/lib/nep413.d.ts +14 -0
  158. package/dist/src/lib/nep413.js +41 -0
  159. package/dist/src/lib/object.cjs +10 -0
  160. package/dist/src/lib/object.js +9 -0
  161. package/dist/src/lib/parse-defuse-asset-id.cjs +15 -0
  162. package/dist/src/lib/parse-defuse-asset-id.js +14 -0
  163. package/dist/src/lib/route-config-factory.cjs +43 -0
  164. package/dist/src/lib/route-config-factory.d.cts +13 -0
  165. package/dist/src/lib/route-config-factory.d.ts +13 -0
  166. package/dist/src/lib/route-config-factory.js +37 -0
  167. package/dist/src/lib/tokensUsdPricesHttpClient/apis.cjs +17 -0
  168. package/dist/src/lib/tokensUsdPricesHttpClient/apis.js +16 -0
  169. package/dist/src/lib/validateAddress.cjs +271 -0
  170. package/dist/src/lib/validateAddress.d.cts +14 -0
  171. package/dist/src/lib/validateAddress.d.ts +14 -0
  172. package/dist/src/lib/validateAddress.js +270 -0
  173. package/dist/src/sdk.cjs +435 -0
  174. package/dist/src/sdk.d.cts +231 -0
  175. package/dist/src/sdk.d.ts +231 -0
  176. package/dist/src/sdk.js +433 -0
  177. package/dist/src/shared-types.d.cts +378 -0
  178. package/dist/src/shared-types.d.ts +378 -0
  179. package/package.json +62 -0
@@ -0,0 +1,96 @@
1
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
+ const require_apis = require('./tokensUsdPricesHttpClient/apis.cjs');
3
+ let lampamazaza_internal_utils = require("lampamazaza-internal-utils");
4
+
5
+ //#region src/lib/estimate-fee.ts
6
+ /**
7
+ * Helper to extract a specific fee from FeeEstimation's underlyingFees.
8
+ * Throws if the route's fee object doesn't exist (invariant: bridges must populate their fees during estimation).
9
+ * Returns the fee value which may be undefined for optional fees within the route object.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const relayerFee = getUnderlyingFee(feeEstimation, RouteEnum.HotBridge, 'relayerFee');
14
+ * const storageDepositFee = getUnderlyingFee(feeEstimation, RouteEnum.OmniBridge, 'storageDepositFee');
15
+ * ```
16
+ * @throws {Error} If the route's fee object is not found in underlyingFees
17
+ */
18
+ function getUnderlyingFee(feeEstimation, route, feeKey) {
19
+ const routeFees = feeEstimation.underlyingFees?.[route];
20
+ if (routeFees === void 0) throw new Error(`Missing underlying fees for route "${String(route)}". Fee estimation must populate underlyingFees before creating withdrawal intents.`);
21
+ return routeFees[feeKey];
22
+ }
23
+ /**
24
+ * ExactIn fallback with 1.2x multiplier
25
+ */
26
+ async function getFeeQuote({ feeAmount, feeAssetId, tokenAssetId, quoteOptions, envConfig, logger, solverRelayApiKey }) {
27
+ try {
28
+ return await lampamazaza_internal_utils.solverRelay.getQuote({
29
+ quoteParams: {
30
+ defuse_asset_identifier_in: tokenAssetId,
31
+ defuse_asset_identifier_out: feeAssetId,
32
+ exact_amount_out: feeAmount.toString(),
33
+ wait_ms: quoteOptions?.waitMs,
34
+ min_wait_ms: quoteOptions?.minWaitMs,
35
+ max_wait_ms: quoteOptions?.maxWaitMs,
36
+ trusted_metadata: quoteOptions?.trustedMetadata
37
+ },
38
+ config: {
39
+ baseURL: envConfig.solverRelayBaseURL,
40
+ logBalanceSufficient: false,
41
+ logger,
42
+ solverRelayApiKey
43
+ }
44
+ });
45
+ } catch (err) {
46
+ if (!(err instanceof lampamazaza_internal_utils.QuoteError)) throw err;
47
+ logger?.info("Can't get exact out quote, trying to get exact in quote with x1.2");
48
+ const prices = await require_apis.tokens({ envConfig });
49
+ const feeAssetPrice = prices.items.find((t) => t.defuse_asset_id === feeAssetId);
50
+ const tokenAssetPrice = prices.items.find((t) => t.defuse_asset_id === tokenAssetId);
51
+ if (feeAssetPrice == null || tokenAssetPrice == null) throw err;
52
+ const USD_SCALE = 1e6;
53
+ const feePriceScaled = BigInt(Math.round(feeAssetPrice.price * USD_SCALE));
54
+ const tokenPriceScaled = BigInt(Math.round(tokenAssetPrice.price * USD_SCALE));
55
+ const feeDecimals = BigInt(feeAssetPrice.decimals);
56
+ const tokenDecimals = BigInt(tokenAssetPrice.decimals);
57
+ const num = feeAmount * feePriceScaled * 12n * 10n ** tokenDecimals;
58
+ const den = tokenPriceScaled * 10n ** feeDecimals * 10n;
59
+ let exactAmountIn = num / den;
60
+ if (num % den !== 0n) exactAmountIn += 1n;
61
+ if (exactAmountIn === 0n) exactAmountIn = 1n;
62
+ const quote = await lampamazaza_internal_utils.solverRelay.getQuote({
63
+ quoteParams: {
64
+ defuse_asset_identifier_in: tokenAssetId,
65
+ defuse_asset_identifier_out: feeAssetId,
66
+ exact_amount_in: exactAmountIn.toString(),
67
+ wait_ms: quoteOptions?.waitMs,
68
+ min_wait_ms: quoteOptions?.minWaitMs,
69
+ max_wait_ms: quoteOptions?.maxWaitMs,
70
+ trusted_metadata: quoteOptions?.trustedMetadata
71
+ },
72
+ config: {
73
+ baseURL: envConfig.solverRelayBaseURL,
74
+ logBalanceSufficient: false,
75
+ logger,
76
+ solverRelayApiKey
77
+ }
78
+ });
79
+ const RATIO_SCALE = 1000n;
80
+ const actualRatio = BigInt(quote.amount_out) * RATIO_SCALE / feeAmount;
81
+ const actualRatioNumber = Number(actualRatio) / Number(RATIO_SCALE);
82
+ if (actualRatio > 1500n) {
83
+ logger?.warn(`Quote amount_out ratio is too high: ${actualRatioNumber.toFixed(2)}x`);
84
+ throw err;
85
+ }
86
+ if (BigInt(quote.amount_out) < feeAmount) {
87
+ logger?.warn(`Quote amount_out (${quote.amount_out}) is less than feeAmount (${feeAmount}), exact_amount_in: ${exactAmountIn}, fee asset price: ${feeAssetPrice.price} USD, token asset price: ${tokenAssetPrice.price} USD`);
88
+ throw err;
89
+ }
90
+ return quote;
91
+ }
92
+ }
93
+
94
+ //#endregion
95
+ exports.getFeeQuote = getFeeQuote;
96
+ exports.getUnderlyingFee = getUnderlyingFee;
@@ -0,0 +1,94 @@
1
+ import { tokens } from "./tokensUsdPricesHttpClient/apis.js";
2
+ import { QuoteError, solverRelay } from "lampamazaza-internal-utils";
3
+
4
+ //#region src/lib/estimate-fee.ts
5
+ /**
6
+ * Helper to extract a specific fee from FeeEstimation's underlyingFees.
7
+ * Throws if the route's fee object doesn't exist (invariant: bridges must populate their fees during estimation).
8
+ * Returns the fee value which may be undefined for optional fees within the route object.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const relayerFee = getUnderlyingFee(feeEstimation, RouteEnum.HotBridge, 'relayerFee');
13
+ * const storageDepositFee = getUnderlyingFee(feeEstimation, RouteEnum.OmniBridge, 'storageDepositFee');
14
+ * ```
15
+ * @throws {Error} If the route's fee object is not found in underlyingFees
16
+ */
17
+ function getUnderlyingFee(feeEstimation, route, feeKey) {
18
+ const routeFees = feeEstimation.underlyingFees?.[route];
19
+ if (routeFees === void 0) throw new Error(`Missing underlying fees for route "${String(route)}". Fee estimation must populate underlyingFees before creating withdrawal intents.`);
20
+ return routeFees[feeKey];
21
+ }
22
+ /**
23
+ * ExactIn fallback with 1.2x multiplier
24
+ */
25
+ async function getFeeQuote({ feeAmount, feeAssetId, tokenAssetId, quoteOptions, envConfig, logger, solverRelayApiKey }) {
26
+ try {
27
+ return await solverRelay.getQuote({
28
+ quoteParams: {
29
+ defuse_asset_identifier_in: tokenAssetId,
30
+ defuse_asset_identifier_out: feeAssetId,
31
+ exact_amount_out: feeAmount.toString(),
32
+ wait_ms: quoteOptions?.waitMs,
33
+ min_wait_ms: quoteOptions?.minWaitMs,
34
+ max_wait_ms: quoteOptions?.maxWaitMs,
35
+ trusted_metadata: quoteOptions?.trustedMetadata
36
+ },
37
+ config: {
38
+ baseURL: envConfig.solverRelayBaseURL,
39
+ logBalanceSufficient: false,
40
+ logger,
41
+ solverRelayApiKey
42
+ }
43
+ });
44
+ } catch (err) {
45
+ if (!(err instanceof QuoteError)) throw err;
46
+ logger?.info("Can't get exact out quote, trying to get exact in quote with x1.2");
47
+ const prices = await tokens({ envConfig });
48
+ const feeAssetPrice = prices.items.find((t) => t.defuse_asset_id === feeAssetId);
49
+ const tokenAssetPrice = prices.items.find((t) => t.defuse_asset_id === tokenAssetId);
50
+ if (feeAssetPrice == null || tokenAssetPrice == null) throw err;
51
+ const USD_SCALE = 1e6;
52
+ const feePriceScaled = BigInt(Math.round(feeAssetPrice.price * USD_SCALE));
53
+ const tokenPriceScaled = BigInt(Math.round(tokenAssetPrice.price * USD_SCALE));
54
+ const feeDecimals = BigInt(feeAssetPrice.decimals);
55
+ const tokenDecimals = BigInt(tokenAssetPrice.decimals);
56
+ const num = feeAmount * feePriceScaled * 12n * 10n ** tokenDecimals;
57
+ const den = tokenPriceScaled * 10n ** feeDecimals * 10n;
58
+ let exactAmountIn = num / den;
59
+ if (num % den !== 0n) exactAmountIn += 1n;
60
+ if (exactAmountIn === 0n) exactAmountIn = 1n;
61
+ const quote = await solverRelay.getQuote({
62
+ quoteParams: {
63
+ defuse_asset_identifier_in: tokenAssetId,
64
+ defuse_asset_identifier_out: feeAssetId,
65
+ exact_amount_in: exactAmountIn.toString(),
66
+ wait_ms: quoteOptions?.waitMs,
67
+ min_wait_ms: quoteOptions?.minWaitMs,
68
+ max_wait_ms: quoteOptions?.maxWaitMs,
69
+ trusted_metadata: quoteOptions?.trustedMetadata
70
+ },
71
+ config: {
72
+ baseURL: envConfig.solverRelayBaseURL,
73
+ logBalanceSufficient: false,
74
+ logger,
75
+ solverRelayApiKey
76
+ }
77
+ });
78
+ const RATIO_SCALE = 1000n;
79
+ const actualRatio = BigInt(quote.amount_out) * RATIO_SCALE / feeAmount;
80
+ const actualRatioNumber = Number(actualRatio) / Number(RATIO_SCALE);
81
+ if (actualRatio > 1500n) {
82
+ logger?.warn(`Quote amount_out ratio is too high: ${actualRatioNumber.toFixed(2)}x`);
83
+ throw err;
84
+ }
85
+ if (BigInt(quote.amount_out) < feeAmount) {
86
+ logger?.warn(`Quote amount_out (${quote.amount_out}) is less than feeAmount (${feeAmount}), exact_amount_in: ${exactAmountIn}, fee asset price: ${feeAssetPrice.price} USD, token asset price: ${tokenAssetPrice.price} USD`);
87
+ throw err;
88
+ }
89
+ return quote;
90
+ }
91
+ }
92
+
93
+ //#endregion
94
+ export { getFeeQuote, getUnderlyingFee };
@@ -0,0 +1,11 @@
1
+
2
+ //#region src/lib/hex.ts
3
+ /**
4
+ * @description verifies value is a non 0x-prefixed hex string
5
+ */
6
+ function isHex(value) {
7
+ return value.length % 2 === 0 && /^[0-9A-Fa-f]+$/.test(value);
8
+ }
9
+
10
+ //#endregion
11
+ exports.default = isHex;
@@ -0,0 +1,10 @@
1
+ //#region src/lib/hex.ts
2
+ /**
3
+ * @description verifies value is a non 0x-prefixed hex string
4
+ */
5
+ function isHex(value) {
6
+ return value.length % 2 === 0 && /^[0-9A-Fa-f]+$/.test(value);
7
+ }
8
+
9
+ //#endregion
10
+ export { isHex as default };
@@ -0,0 +1,42 @@
1
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
+ let borsher = require("borsher");
3
+
4
+ //#region src/lib/nep413.ts
5
+ const nep413PayloadSchema = borsher.BorshSchema.Struct({
6
+ message: borsher.BorshSchema.String,
7
+ nonce: borsher.BorshSchema.Array(borsher.BorshSchema.u8, 32),
8
+ recipient: borsher.BorshSchema.String,
9
+ callback_url: borsher.BorshSchema.Option(borsher.BorshSchema.String)
10
+ });
11
+ /**
12
+ * Client-side utility to serialize and hash NEP-413 messages for EdDSA signature verification.
13
+ * Follows the NEP-413 specification for message serialization and hashing:
14
+ * @see https://github.com/near/NEPs/blob/master/neps/nep-0413.md#specification
15
+ *
16
+ * The resulting hash should be used with EdDSA signing to create a valid NEP-413 signature.
17
+ * Note: This is a browser-only implementation.
18
+ *
19
+ * @param message - Message content to be signed
20
+ * @param recipient - Recipient account ID
21
+ * @param nonce - 32-byte nonce as a Uint8Array
22
+ * @param callback_url - Optional callback URL to be used for the intent
23
+ * @returns Promise resolving to Buffer containing message hash for signing
24
+ */
25
+ async function hashNEP413Message({ message, recipient, nonce, callback_url }) {
26
+ const payloadSerialized = (0, borsher.borshSerialize)(nep413PayloadSchema, {
27
+ message,
28
+ nonce: Array.from(nonce),
29
+ recipient,
30
+ callback_url
31
+ });
32
+ const baseInt = 2 ** 31 + 413;
33
+ const baseIntSerialized = (0, borsher.borshSerialize)(borsher.BorshSchema.u32, baseInt);
34
+ const combinedData = new Uint8Array(baseIntSerialized.length + payloadSerialized.length);
35
+ combinedData.set(baseIntSerialized);
36
+ combinedData.set(payloadSerialized, baseIntSerialized.length);
37
+ const hashBuffer = await crypto.subtle.digest("SHA-256", combinedData);
38
+ return new Uint8Array(hashBuffer);
39
+ }
40
+
41
+ //#endregion
42
+ exports.hashNEP413Message = hashNEP413Message;
@@ -0,0 +1,14 @@
1
+ import { BorshSchema } from "borsher";
2
+
3
+ //#region src/lib/nep413.d.ts
4
+ declare const nep413PayloadSchema: BorshSchema<{
5
+ message: string;
6
+ nonce: number[];
7
+ recipient: string;
8
+ callback_url: string | null;
9
+ }>;
10
+ type NEP413Payload = typeof nep413PayloadSchema extends BorshSchema<infer T> ? Omit<T, "callback_url"> & {
11
+ callback_url?: string | null | undefined;
12
+ } : never;
13
+ //#endregion
14
+ export { NEP413Payload };
@@ -0,0 +1,14 @@
1
+ import { BorshSchema } from "borsher";
2
+
3
+ //#region src/lib/nep413.d.ts
4
+ declare const nep413PayloadSchema: BorshSchema<{
5
+ message: string;
6
+ nonce: number[];
7
+ recipient: string;
8
+ callback_url: string | null;
9
+ }>;
10
+ type NEP413Payload = typeof nep413PayloadSchema extends BorshSchema<infer T> ? Omit<T, "callback_url"> & {
11
+ callback_url?: string | null | undefined;
12
+ } : never;
13
+ //#endregion
14
+ export { NEP413Payload };
@@ -0,0 +1,41 @@
1
+ import { BorshSchema, borshSerialize } from "borsher";
2
+
3
+ //#region src/lib/nep413.ts
4
+ const nep413PayloadSchema = BorshSchema.Struct({
5
+ message: BorshSchema.String,
6
+ nonce: BorshSchema.Array(BorshSchema.u8, 32),
7
+ recipient: BorshSchema.String,
8
+ callback_url: BorshSchema.Option(BorshSchema.String)
9
+ });
10
+ /**
11
+ * Client-side utility to serialize and hash NEP-413 messages for EdDSA signature verification.
12
+ * Follows the NEP-413 specification for message serialization and hashing:
13
+ * @see https://github.com/near/NEPs/blob/master/neps/nep-0413.md#specification
14
+ *
15
+ * The resulting hash should be used with EdDSA signing to create a valid NEP-413 signature.
16
+ * Note: This is a browser-only implementation.
17
+ *
18
+ * @param message - Message content to be signed
19
+ * @param recipient - Recipient account ID
20
+ * @param nonce - 32-byte nonce as a Uint8Array
21
+ * @param callback_url - Optional callback URL to be used for the intent
22
+ * @returns Promise resolving to Buffer containing message hash for signing
23
+ */
24
+ async function hashNEP413Message({ message, recipient, nonce, callback_url }) {
25
+ const payloadSerialized = borshSerialize(nep413PayloadSchema, {
26
+ message,
27
+ nonce: Array.from(nonce),
28
+ recipient,
29
+ callback_url
30
+ });
31
+ const baseInt = 2 ** 31 + 413;
32
+ const baseIntSerialized = borshSerialize(BorshSchema.u32, baseInt);
33
+ const combinedData = new Uint8Array(baseIntSerialized.length + payloadSerialized.length);
34
+ combinedData.set(baseIntSerialized);
35
+ combinedData.set(payloadSerialized, baseIntSerialized.length);
36
+ const hashBuffer = await crypto.subtle.digest("SHA-256", combinedData);
37
+ return new Uint8Array(hashBuffer);
38
+ }
39
+
40
+ //#endregion
41
+ export { hashNEP413Message };
@@ -0,0 +1,10 @@
1
+
2
+ //#region src/lib/object.ts
3
+ function pick(obj, keys) {
4
+ const result = {};
5
+ for (const key of keys) if (key in obj) result[key] = obj[key];
6
+ return result;
7
+ }
8
+
9
+ //#endregion
10
+ exports.pick = pick;
@@ -0,0 +1,9 @@
1
+ //#region src/lib/object.ts
2
+ function pick(obj, keys) {
3
+ const result = {};
4
+ for (const key of keys) if (key in obj) result[key] = obj[key];
5
+ return result;
6
+ }
7
+
8
+ //#endregion
9
+ export { pick };
@@ -0,0 +1,15 @@
1
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
+ const require_errors = require('../classes/errors.cjs');
3
+ let lampamazaza_internal_utils = require("lampamazaza-internal-utils");
4
+
5
+ //#region src/lib/parse-defuse-asset-id.ts
6
+ function parseDefuseAssetId(assetId) {
7
+ try {
8
+ return lampamazaza_internal_utils.utils.parseDefuseAssetId(assetId);
9
+ } catch {
10
+ throw new require_errors.UnsupportedAssetIdError(assetId, "Invalid asset id format.");
11
+ }
12
+ }
13
+
14
+ //#endregion
15
+ exports.parseDefuseAssetId = parseDefuseAssetId;
@@ -0,0 +1,14 @@
1
+ import { UnsupportedAssetIdError } from "../classes/errors.js";
2
+ import { utils } from "lampamazaza-internal-utils";
3
+
4
+ //#region src/lib/parse-defuse-asset-id.ts
5
+ function parseDefuseAssetId(assetId) {
6
+ try {
7
+ return utils.parseDefuseAssetId(assetId);
8
+ } catch {
9
+ throw new UnsupportedAssetIdError(assetId, "Invalid asset id format.");
10
+ }
11
+ }
12
+
13
+ //#endregion
14
+ export { parseDefuseAssetId };
@@ -0,0 +1,43 @@
1
+ const require_route_enum = require('../constants/route-enum.cjs');
2
+
3
+ //#region src/lib/route-config-factory.ts
4
+ function createInternalTransferRoute() {
5
+ return { route: require_route_enum.RouteEnum.InternalTransfer };
6
+ }
7
+ function createNearWithdrawalRoute(msg) {
8
+ return {
9
+ route: require_route_enum.RouteEnum.NearWithdrawal,
10
+ msg
11
+ };
12
+ }
13
+ function createOmniBridgeRoute(chain) {
14
+ const routeConfig = { route: require_route_enum.RouteEnum.OmniBridge };
15
+ if (chain) routeConfig.chain = chain;
16
+ return routeConfig;
17
+ }
18
+ function createVirtualChainRoute(auroraEngineContractId, proxyTokenContractId) {
19
+ return {
20
+ route: require_route_enum.RouteEnum.VirtualChain,
21
+ auroraEngineContractId,
22
+ proxyTokenContractId
23
+ };
24
+ }
25
+ function createPoaBridgeRoute() {
26
+ return { route: require_route_enum.RouteEnum.PoaBridge };
27
+ }
28
+ function createHotBridgeRoute(chain) {
29
+ return {
30
+ route: require_route_enum.RouteEnum.HotBridge,
31
+ chain
32
+ };
33
+ }
34
+ function createDefaultRoute() {}
35
+
36
+ //#endregion
37
+ exports.createDefaultRoute = createDefaultRoute;
38
+ exports.createHotBridgeRoute = createHotBridgeRoute;
39
+ exports.createInternalTransferRoute = createInternalTransferRoute;
40
+ exports.createNearWithdrawalRoute = createNearWithdrawalRoute;
41
+ exports.createOmniBridgeRoute = createOmniBridgeRoute;
42
+ exports.createPoaBridgeRoute = createPoaBridgeRoute;
43
+ exports.createVirtualChainRoute = createVirtualChainRoute;
@@ -0,0 +1,13 @@
1
+ import { Chain } from "./caip2.cjs";
2
+ import { HotBridgeRouteConfig, InternalTransferRouteConfig, NearWithdrawalRouteConfig, OmniBridgeRouteConfig, PoaBridgeRouteConfig, VirtualChainRouteConfig } from "../shared-types.cjs";
3
+
4
+ //#region src/lib/route-config-factory.d.ts
5
+ declare function createInternalTransferRoute(): InternalTransferRouteConfig;
6
+ declare function createNearWithdrawalRoute(msg?: string): NearWithdrawalRouteConfig;
7
+ declare function createOmniBridgeRoute(chain?: Chain): OmniBridgeRouteConfig;
8
+ declare function createVirtualChainRoute(auroraEngineContractId: string, proxyTokenContractId: string | null): VirtualChainRouteConfig;
9
+ declare function createPoaBridgeRoute(): PoaBridgeRouteConfig;
10
+ declare function createHotBridgeRoute(chain: Chain): HotBridgeRouteConfig;
11
+ declare function createDefaultRoute(): undefined;
12
+ //#endregion
13
+ export { createDefaultRoute, createHotBridgeRoute, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
@@ -0,0 +1,13 @@
1
+ import { Chain } from "./caip2.js";
2
+ import { HotBridgeRouteConfig, InternalTransferRouteConfig, NearWithdrawalRouteConfig, OmniBridgeRouteConfig, PoaBridgeRouteConfig, VirtualChainRouteConfig } from "../shared-types.js";
3
+
4
+ //#region src/lib/route-config-factory.d.ts
5
+ declare function createInternalTransferRoute(): InternalTransferRouteConfig;
6
+ declare function createNearWithdrawalRoute(msg?: string): NearWithdrawalRouteConfig;
7
+ declare function createOmniBridgeRoute(chain?: Chain): OmniBridgeRouteConfig;
8
+ declare function createVirtualChainRoute(auroraEngineContractId: string, proxyTokenContractId: string | null): VirtualChainRouteConfig;
9
+ declare function createPoaBridgeRoute(): PoaBridgeRouteConfig;
10
+ declare function createHotBridgeRoute(chain: Chain): HotBridgeRouteConfig;
11
+ declare function createDefaultRoute(): undefined;
12
+ //#endregion
13
+ export { createDefaultRoute, createHotBridgeRoute, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
@@ -0,0 +1,37 @@
1
+ import { RouteEnum } from "../constants/route-enum.js";
2
+
3
+ //#region src/lib/route-config-factory.ts
4
+ function createInternalTransferRoute() {
5
+ return { route: RouteEnum.InternalTransfer };
6
+ }
7
+ function createNearWithdrawalRoute(msg) {
8
+ return {
9
+ route: RouteEnum.NearWithdrawal,
10
+ msg
11
+ };
12
+ }
13
+ function createOmniBridgeRoute(chain) {
14
+ const routeConfig = { route: RouteEnum.OmniBridge };
15
+ if (chain) routeConfig.chain = chain;
16
+ return routeConfig;
17
+ }
18
+ function createVirtualChainRoute(auroraEngineContractId, proxyTokenContractId) {
19
+ return {
20
+ route: RouteEnum.VirtualChain,
21
+ auroraEngineContractId,
22
+ proxyTokenContractId
23
+ };
24
+ }
25
+ function createPoaBridgeRoute() {
26
+ return { route: RouteEnum.PoaBridge };
27
+ }
28
+ function createHotBridgeRoute(chain) {
29
+ return {
30
+ route: RouteEnum.HotBridge,
31
+ chain
32
+ };
33
+ }
34
+ function createDefaultRoute() {}
35
+
36
+ //#endregion
37
+ export { createDefaultRoute, createHotBridgeRoute, createInternalTransferRoute, createNearWithdrawalRoute, createOmniBridgeRoute, createPoaBridgeRoute, createVirtualChainRoute };
@@ -0,0 +1,17 @@
1
+ const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
2
+ let lampamazaza_internal_utils = require("lampamazaza-internal-utils");
3
+
4
+ //#region src/lib/tokensUsdPricesHttpClient/apis.ts
5
+ async function tokens(config) {
6
+ return (await (0, lampamazaza_internal_utils.request)({
7
+ url: new URL("tokens", config.envConfig.managerConsoleBaseURL),
8
+ ...config,
9
+ fetchOptions: {
10
+ ...config.fetchOptions,
11
+ method: "GET"
12
+ }
13
+ })).json();
14
+ }
15
+
16
+ //#endregion
17
+ exports.tokens = tokens;
@@ -0,0 +1,16 @@
1
+ import { request } from "lampamazaza-internal-utils";
2
+
3
+ //#region src/lib/tokensUsdPricesHttpClient/apis.ts
4
+ async function tokens(config) {
5
+ return (await request({
6
+ url: new URL("tokens", config.envConfig.managerConsoleBaseURL),
7
+ ...config,
8
+ fetchOptions: {
9
+ ...config.fetchOptions,
10
+ method: "GET"
11
+ }
12
+ })).json();
13
+ }
14
+
15
+ //#endregion
16
+ export { tokens };