@prohetamine/redstone 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/dist/PhArrowCircleDown-BR-zH4LC.js +14 -0
  2. package/dist/PhArrowCircleDown-Sb38khBy.mjs +73 -0
  3. package/dist/PhArrowClockwise-BE5j9P0Z.mjs +73 -0
  4. package/dist/PhArrowClockwise-BRaehQGe.js +14 -0
  5. package/dist/PhArrowDown-B_WmmmY9.js +14 -0
  6. package/dist/PhArrowDown-CFEyR2dR.mjs +73 -0
  7. package/dist/PhArrowLeft-CYfU7NZj.mjs +73 -0
  8. package/dist/PhArrowLeft-CkEd70hm.js +14 -0
  9. package/dist/PhArrowRight-C07Qkx86.js +14 -0
  10. package/dist/PhArrowRight-EermNu0V.mjs +73 -0
  11. package/dist/PhArrowSquareOut-BjTBfzOP.js +14 -0
  12. package/dist/PhArrowSquareOut-DZwTtw54.mjs +73 -0
  13. package/dist/PhArrowUp-DB4CCSss.js +14 -0
  14. package/dist/PhArrowUp-xTpLFQkg.mjs +73 -0
  15. package/dist/PhArrowUpRight-CQbvn6NO.mjs +73 -0
  16. package/dist/PhArrowUpRight-GpCIMsAh.js +14 -0
  17. package/dist/PhArrowsClockwise-BgcIUg-Z.js +14 -0
  18. package/dist/PhArrowsClockwise-DnUYZTVx.mjs +73 -0
  19. package/dist/PhArrowsDownUp-C8KXUqtu.js +14 -0
  20. package/dist/PhArrowsDownUp-DgoprEe2.mjs +73 -0
  21. package/dist/PhArrowsLeftRight-CahChzCj.js +14 -0
  22. package/dist/PhArrowsLeftRight-FD4AZiLh.mjs +73 -0
  23. package/dist/PhBank-DIqIL4x_.js +14 -0
  24. package/dist/PhBank-DbQOQ9zJ.mjs +73 -0
  25. package/dist/PhBrowser-BCBXK2IM.mjs +73 -0
  26. package/dist/PhBrowser-laCKtn7T.js +14 -0
  27. package/dist/PhCaretDown-CnjP-QjZ.mjs +73 -0
  28. package/dist/PhCaretDown-DDe42xDU.js +14 -0
  29. package/dist/PhCaretLeft-Cskc5OY9.js +14 -0
  30. package/dist/PhCaretLeft-DkuXxjf_.mjs +73 -0
  31. package/dist/PhCaretRight-CBWpghxt.mjs +73 -0
  32. package/dist/PhCaretRight-DNgI5w_B.js +14 -0
  33. package/dist/PhCaretUp-CQ-OztBV.mjs +73 -0
  34. package/dist/PhCaretUp-CUZ4g_Me.js +14 -0
  35. package/dist/PhCheck-BVV_Dwfo.js +14 -0
  36. package/dist/PhCheck-t515emYS.mjs +73 -0
  37. package/dist/PhCircleHalf-BuQTmrKW.mjs +73 -0
  38. package/dist/PhCircleHalf-DDC7rige.js +14 -0
  39. package/dist/PhClock-BqynEKWl.js +14 -0
  40. package/dist/PhClock-D6XkTmM_.mjs +73 -0
  41. package/dist/PhCompass-2QeeX5Ad.mjs +73 -0
  42. package/dist/PhCompass-BsuJwXAE.js +14 -0
  43. package/dist/PhCopy-CO34-_xD.mjs +73 -0
  44. package/dist/PhCopy-MVqtRS6X.js +14 -0
  45. package/dist/PhCreditCard-Dq4kdjCw.js +14 -0
  46. package/dist/PhCreditCard-bfnqYflD.mjs +73 -0
  47. package/dist/PhCurrencyDollar-6k8UWxal.js +14 -0
  48. package/dist/PhCurrencyDollar-BekVYPtC.mjs +73 -0
  49. package/dist/PhDesktop-BkNzf3rT.mjs +73 -0
  50. package/dist/PhDesktop-CfsXQ0vC.js +14 -0
  51. package/dist/PhDeviceMobile-BT3Mg_b0.mjs +73 -0
  52. package/dist/PhDeviceMobile-BnrrDrwf.js +14 -0
  53. package/dist/PhDotsThree-6LRvhAcL.js +14 -0
  54. package/dist/PhDotsThree-kpf2OKxJ.mjs +73 -0
  55. package/dist/PhEnvelope-CHsfC2e0.js +14 -0
  56. package/dist/PhEnvelope-UFKpKtwf.mjs +73 -0
  57. package/dist/PhFunnelSimple-CdAqSIhK.mjs +73 -0
  58. package/dist/PhFunnelSimple-JAk7X9Wo.js +14 -0
  59. package/dist/PhGlobe-B3RYXl8h.mjs +73 -0
  60. package/dist/PhGlobe-Tfs4MfpG.js +14 -0
  61. package/dist/PhIdentificationCard-Dqmd6eY1.js +14 -0
  62. package/dist/PhIdentificationCard-rSq59Czm.mjs +73 -0
  63. package/dist/PhImage-aEryzfCi.js +14 -0
  64. package/dist/PhImage-ynsEnFd_.mjs +73 -0
  65. package/dist/PhInfo-B7lsWl6m.mjs +73 -0
  66. package/dist/PhInfo-D6oUrWpA.js +14 -0
  67. package/dist/PhLightbulb-FQDaMMqu.mjs +73 -0
  68. package/dist/PhLightbulb-qbEduhPa.js +14 -0
  69. package/dist/PhMagnifyingGlass-COdRH2k5.js +14 -0
  70. package/dist/PhMagnifyingGlass-_NXk13-0.mjs +73 -0
  71. package/dist/PhPaperPlaneRight-BYi7SorW.mjs +73 -0
  72. package/dist/PhPaperPlaneRight-DrpVAQOZ.js +14 -0
  73. package/dist/PhPlus-25KQTPHG.mjs +73 -0
  74. package/dist/PhPlus-BhUXef08.js +14 -0
  75. package/dist/PhPower-BKl7gzsB.mjs +73 -0
  76. package/dist/PhPower-BNJf1AGQ.js +14 -0
  77. package/dist/PhPuzzlePiece-BkZeF8CX.js +14 -0
  78. package/dist/PhPuzzlePiece-BqUI4GRs.mjs +73 -0
  79. package/dist/PhQrCode-C-tqZKPP.mjs +73 -0
  80. package/dist/PhQrCode-C0v0iXQN.js +14 -0
  81. package/dist/PhQuestion-BBAiRWgt.js +14 -0
  82. package/dist/PhQuestion-CtYvffyD.mjs +73 -0
  83. package/dist/PhQuestionMark-BNbtL2yx.mjs +73 -0
  84. package/dist/PhQuestionMark-BvGUBZ1h.js +14 -0
  85. package/dist/PhSealCheck-B0TEqWpq.mjs +73 -0
  86. package/dist/PhSealCheck-BwNkuF7G.js +14 -0
  87. package/dist/PhSignOut-C1rMSNaS.js +14 -0
  88. package/dist/PhSignOut-HX2_BVsD.mjs +73 -0
  89. package/dist/PhSpinner-CoDYLYOX.mjs +73 -0
  90. package/dist/PhSpinner-nmsGWDQl.js +14 -0
  91. package/dist/PhTrash-CALlKx3e.js +14 -0
  92. package/dist/PhTrash-DeQHS8ZP.mjs +73 -0
  93. package/dist/PhUser-CA0e5OPI.js +14 -0
  94. package/dist/PhUser-Cy5EY3vX.mjs +73 -0
  95. package/dist/PhVault-DdXjVOO9.mjs +73 -0
  96. package/dist/PhVault-DqxV75cz.js +14 -0
  97. package/dist/PhWallet-CeQrfGYc.mjs +73 -0
  98. package/dist/PhWallet-CyCuEs2U.js +14 -0
  99. package/dist/PhWarning-BKaHv_wT.mjs +73 -0
  100. package/dist/PhWarning-C7oj86bY.js +14 -0
  101. package/dist/PhWarningCircle-8MWw-QgE.mjs +73 -0
  102. package/dist/PhWarningCircle-CrNPXGj4.js +14 -0
  103. package/dist/PhX-9lsrXjyl.js +14 -0
  104. package/dist/PhX-DgXr_Fb0.mjs +73 -0
  105. package/dist/ReownAuthentication-Bfv31LzI.mjs +274 -0
  106. package/dist/ReownAuthentication-d8aYgGOq.js +5 -0
  107. package/dist/SwapController-4lzoYsYr.js +1 -0
  108. package/dist/SwapController-DjzUWRyQ.mjs +462 -0
  109. package/dist/ccip-CvwbEhki.js +1 -0
  110. package/dist/ccip-TuO68NeE.mjs +150 -0
  111. package/dist/data-capture-BwdjH2vc.mjs +489 -0
  112. package/dist/data-capture-xVUNZJ2T.js +242 -0
  113. package/dist/email-BCZObJCY.js +90 -0
  114. package/dist/email-m-wo60fN.mjs +338 -0
  115. package/dist/embedded-wallet-CGSri-4g.js +410 -0
  116. package/dist/embedded-wallet-DdZmv5qP.mjs +808 -0
  117. package/dist/features-BJ8kNaE8.js +1 -0
  118. package/dist/features-CJ34oImB.mjs +6 -0
  119. package/dist/index-4lfXeo30.js +132 -0
  120. package/dist/index-B6Mg114Z.mjs +69182 -0
  121. package/dist/index-BX7gAgT3.mjs +35 -0
  122. package/dist/index-BYQqNbCe.js +1 -0
  123. package/dist/index-BmdHwtJo.js +1 -0
  124. package/dist/index-BvUx3ULC.js +78 -0
  125. package/dist/index-CD-QGO70.mjs +196 -0
  126. package/dist/index-CJtXfdoM.mjs +29621 -0
  127. package/dist/index-CMzdgE-y.mjs +215 -0
  128. package/dist/index-CjZQCcwG.js +7203 -0
  129. package/dist/index-D7VuOaCI.js +19 -0
  130. package/dist/index-DV7SQwgn.mjs +2688 -0
  131. package/dist/index-DVf4BnNh.mjs +352 -0
  132. package/dist/index-DhN9vL4k.js +138 -0
  133. package/dist/index-DvllakY0.mjs +274 -0
  134. package/dist/index-Ho06VKh2.mjs +151 -0
  135. package/dist/index-a8mS2Eh1.js +1062 -0
  136. package/dist/index-aamBi9Tu.js +1 -0
  137. package/dist/index.cjs.js +1 -0
  138. package/dist/index.es.js +14 -0
  139. package/dist/onramp-DLlhSPQg.js +422 -0
  140. package/dist/onramp-k-EAEepC.mjs +842 -0
  141. package/dist/parseSignature-D1tZHglo.js +16 -0
  142. package/dist/parseSignature-DM0lwcDr.mjs +8883 -0
  143. package/dist/pay-with-exchange---G2M1Ag.js +280 -0
  144. package/dist/pay-with-exchange-CFIcUXUe.mjs +512 -0
  145. package/dist/property-Bd8U3_QP.mjs +618 -0
  146. package/dist/property-DissjCbZ.js +27 -0
  147. package/dist/receive-B9LCljO6.mjs +228 -0
  148. package/dist/receive-E8H6GDOX.js +131 -0
  149. package/dist/send-B-AooLph.js +554 -0
  150. package/dist/send-DZd_xhsd.mjs +1155 -0
  151. package/dist/socials-ChWFLEFe.mjs +611 -0
  152. package/dist/socials-YSUYSh8o.js +250 -0
  153. package/dist/swaps-DpR9W9Ld.js +1050 -0
  154. package/dist/swaps-Du7-Ui_V.mjs +1752 -0
  155. package/dist/transactions-DhsK5-QJ.mjs +35 -0
  156. package/dist/transactions-VPsz2OLe.js +16 -0
  157. package/dist/w3m-modal-DhomfjKU.js +891 -0
  158. package/dist/w3m-modal-KuYD-zqQ.mjs +1759 -0
  159. package/package.json +51 -0
  160. package/readme.md +1 -0
@@ -0,0 +1,462 @@
1
+ import { c1 as T, c2 as W, c3 as A, c4 as w, c5 as D, c6 as P, c7 as B, c8 as M, c9 as F, ca as m, cb as v, cc as L, cd as N, ce as x, cf as z, cg as _, ch as R, ci as H, cj as V, ck as $, cl as q } from "./index-B6Mg114Z.mjs";
2
+ const I = {
3
+ getGasPriceInEther(n, t) {
4
+ const o = t * n;
5
+ return Number(o) / 1e18;
6
+ },
7
+ getGasPriceInUSD(n, t, o) {
8
+ const s = I.getGasPriceInEther(t, o);
9
+ return T.bigNumber(n).times(s).toNumber();
10
+ },
11
+ getPriceImpact({ sourceTokenAmount: n, sourceTokenPriceInUSD: t, toTokenPriceInUSD: o, toTokenAmount: s }) {
12
+ const c = T.bigNumber(n).times(t), r = T.bigNumber(s).times(o);
13
+ return c.minus(r).div(c).times(100).toNumber();
14
+ },
15
+ getMaxSlippage(n, t) {
16
+ const o = T.bigNumber(n).div(100);
17
+ return T.multiply(t, o).toNumber();
18
+ },
19
+ getProviderFee(n, t = 85e-4) {
20
+ return T.bigNumber(n).times(t).toString();
21
+ },
22
+ isInsufficientNetworkTokenForGas(n, t) {
23
+ const o = t || "0";
24
+ return T.bigNumber(n).eq(0) ? !0 : T.bigNumber(T.bigNumber(o)).gt(n);
25
+ },
26
+ isInsufficientSourceTokenForSwap(n, t, o) {
27
+ var r, d;
28
+ const s = (d = (r = o == null ? void 0 : o.find((l) => l.address === t)) == null ? void 0 : r.quantity) == null ? void 0 : d.numeric;
29
+ return T.bigNumber(s || "0").lt(n);
30
+ }
31
+ }, O = 15e4, Q = 6, k = {
32
+ // Loading states
33
+ initializing: !1,
34
+ initialized: !1,
35
+ loadingPrices: !1,
36
+ loadingQuote: !1,
37
+ loadingApprovalTransaction: !1,
38
+ loadingBuildTransaction: !1,
39
+ loadingTransaction: !1,
40
+ // Control states
41
+ switchingTokens: !1,
42
+ // Error states
43
+ fetchError: !1,
44
+ // Approval & Swap transaction states
45
+ approvalTransaction: void 0,
46
+ swapTransaction: void 0,
47
+ transactionError: void 0,
48
+ // Input values
49
+ sourceToken: void 0,
50
+ sourceTokenAmount: "",
51
+ sourceTokenPriceInUSD: 0,
52
+ toToken: void 0,
53
+ toTokenAmount: "",
54
+ toTokenPriceInUSD: 0,
55
+ networkPrice: "0",
56
+ networkBalanceInUSD: "0",
57
+ networkTokenSymbol: "",
58
+ inputError: void 0,
59
+ // Request values
60
+ slippage: _.CONVERT_SLIPPAGE_TOLERANCE,
61
+ // Tokens
62
+ tokens: void 0,
63
+ popularTokens: void 0,
64
+ suggestedTokens: void 0,
65
+ foundTokens: void 0,
66
+ myTokensWithBalance: void 0,
67
+ tokensPriceMap: {},
68
+ // Calculations
69
+ gasFee: "0",
70
+ gasPriceInUSD: 0,
71
+ priceImpact: void 0,
72
+ maxSlippage: void 0,
73
+ providerFee: void 0
74
+ }, e = q({ ...k }), E = {
75
+ state: e,
76
+ subscribe(n) {
77
+ return $(e, () => n(e));
78
+ },
79
+ subscribeKey(n, t) {
80
+ return V(e, n, t);
81
+ },
82
+ getParams() {
83
+ var i, u, p, f, S, h, y, b, C;
84
+ const n = m.state.activeChain, t = ((i = m.getAccountData(n)) == null ? void 0 : i.caipAddress) ?? m.state.activeCaipAddress, o = L.getPlainAddress(t), s = R(), c = H.getConnectorId(m.state.activeChain);
85
+ if (!o)
86
+ throw new Error("No address found to swap the tokens from.");
87
+ const r = !((u = e.toToken) != null && u.address) || !((p = e.toToken) != null && p.decimals), d = !((f = e.sourceToken) != null && f.address) || !((S = e.sourceToken) != null && S.decimals) || !T.bigNumber(e.sourceTokenAmount).gt(0), l = !e.sourceTokenAmount;
88
+ return {
89
+ networkAddress: s,
90
+ fromAddress: o,
91
+ fromCaipAddress: t,
92
+ sourceTokenAddress: (h = e.sourceToken) == null ? void 0 : h.address,
93
+ toTokenAddress: (y = e.toToken) == null ? void 0 : y.address,
94
+ toTokenAmount: e.toTokenAmount,
95
+ toTokenDecimals: (b = e.toToken) == null ? void 0 : b.decimals,
96
+ sourceTokenAmount: e.sourceTokenAmount,
97
+ sourceTokenDecimals: (C = e.sourceToken) == null ? void 0 : C.decimals,
98
+ invalidToToken: r,
99
+ invalidSourceToken: d,
100
+ invalidSourceTokenAmount: l,
101
+ availableToSwap: t && !r && !d && !l,
102
+ isAuthConnector: c === P.CONNECTOR_ID.AUTH
103
+ };
104
+ },
105
+ async setSourceToken(n) {
106
+ if (!n) {
107
+ e.sourceToken = n, e.sourceTokenAmount = "", e.sourceTokenPriceInUSD = 0;
108
+ return;
109
+ }
110
+ e.sourceToken = n, await a.setTokenPrice(n.address, "sourceToken");
111
+ },
112
+ setSourceTokenAmount(n) {
113
+ e.sourceTokenAmount = n;
114
+ },
115
+ async setToToken(n) {
116
+ if (!n) {
117
+ e.toToken = n, e.toTokenAmount = "", e.toTokenPriceInUSD = 0;
118
+ return;
119
+ }
120
+ e.toToken = n, await a.setTokenPrice(n.address, "toToken");
121
+ },
122
+ setToTokenAmount(n) {
123
+ e.toTokenAmount = n ? T.toFixed(n, Q) : "";
124
+ },
125
+ async setTokenPrice(n, t) {
126
+ let o = e.tokensPriceMap[n] || 0;
127
+ o || (e.loadingPrices = !0, o = await a.getAddressPrice(n)), t === "sourceToken" ? e.sourceTokenPriceInUSD = o : t === "toToken" && (e.toTokenPriceInUSD = o), e.loadingPrices && (e.loadingPrices = !1), a.getParams().availableToSwap && !e.switchingTokens && a.swapTokens();
128
+ },
129
+ async switchTokens() {
130
+ if (!(e.initializing || !e.initialized || e.switchingTokens)) {
131
+ e.switchingTokens = !0;
132
+ try {
133
+ const n = e.toToken ? { ...e.toToken } : void 0, t = e.sourceToken ? { ...e.sourceToken } : void 0, o = n && e.toTokenAmount === "" ? "1" : e.toTokenAmount;
134
+ a.setSourceTokenAmount(o), a.setToTokenAmount(""), await a.setSourceToken(n), await a.setToToken(t), e.switchingTokens = !1, a.swapTokens();
135
+ } catch (n) {
136
+ throw e.switchingTokens = !1, n;
137
+ }
138
+ }
139
+ },
140
+ resetState() {
141
+ e.myTokensWithBalance = k.myTokensWithBalance, e.tokensPriceMap = k.tokensPriceMap, e.initialized = k.initialized, e.initializing = k.initializing, e.switchingTokens = k.switchingTokens, e.sourceToken = k.sourceToken, e.sourceTokenAmount = k.sourceTokenAmount, e.sourceTokenPriceInUSD = k.sourceTokenPriceInUSD, e.toToken = k.toToken, e.toTokenAmount = k.toTokenAmount, e.toTokenPriceInUSD = k.toTokenPriceInUSD, e.networkPrice = k.networkPrice, e.networkTokenSymbol = k.networkTokenSymbol, e.networkBalanceInUSD = k.networkBalanceInUSD, e.inputError = k.inputError;
142
+ },
143
+ resetValues() {
144
+ var o;
145
+ const { networkAddress: n } = a.getParams(), t = (o = e.tokens) == null ? void 0 : o.find((s) => s.address === n);
146
+ a.setSourceToken(t), a.setToToken(void 0);
147
+ },
148
+ getApprovalLoadingState() {
149
+ return e.loadingApprovalTransaction;
150
+ },
151
+ clearError() {
152
+ e.transactionError = void 0;
153
+ },
154
+ async initializeState() {
155
+ if (!e.initializing) {
156
+ if (e.initializing = !0, !e.initialized)
157
+ try {
158
+ await a.fetchTokens(), e.initialized = !0;
159
+ } catch {
160
+ e.initialized = !1, w.showError("Failed to initialize swap"), A.goBack();
161
+ }
162
+ e.initializing = !1;
163
+ }
164
+ },
165
+ async fetchTokens() {
166
+ var o;
167
+ const { networkAddress: n } = a.getParams();
168
+ await a.getNetworkTokenPrice(), await a.getMyTokensWithBalance();
169
+ const t = (o = e.myTokensWithBalance) == null ? void 0 : o.find((s) => s.address === n);
170
+ t && (e.networkTokenSymbol = t.symbol, a.setSourceToken(t), a.setSourceTokenAmount("0"));
171
+ },
172
+ async getTokenList() {
173
+ var t, o;
174
+ const n = (t = m.state.activeCaipNetwork) == null ? void 0 : t.caipNetworkId;
175
+ if (!(e.caipNetworkId === n && e.tokens))
176
+ try {
177
+ e.tokensLoading = !0;
178
+ const s = await N.getTokenList(n);
179
+ e.tokens = s, e.caipNetworkId = n, e.popularTokens = s.sort((i, u) => i.symbol < u.symbol ? -1 : i.symbol > u.symbol ? 1 : 0);
180
+ const r = (n && ((o = _.SUGGESTED_TOKENS_BY_CHAIN) == null ? void 0 : o[n]) || []).map((i) => s.find((u) => u.symbol === i)).filter((i) => !!i), l = (_.SWAP_SUGGESTED_TOKENS || []).map((i) => s.find((u) => u.symbol === i)).filter((i) => !!i).filter((i) => !r.some((u) => u.address === i.address));
181
+ e.suggestedTokens = [...r, ...l];
182
+ } catch {
183
+ e.tokens = [], e.popularTokens = [], e.suggestedTokens = [];
184
+ } finally {
185
+ e.tokensLoading = !1;
186
+ }
187
+ },
188
+ async getAddressPrice(n) {
189
+ var i, u;
190
+ const t = e.tokensPriceMap[n];
191
+ if (t)
192
+ return t;
193
+ const o = await v.fetchTokenPrice({
194
+ addresses: [n]
195
+ }), s = (o == null ? void 0 : o.fungibles) || [], c = [...e.tokens || [], ...e.myTokensWithBalance || []], r = (i = c == null ? void 0 : c.find((p) => p.address === n)) == null ? void 0 : i.symbol, d = ((u = s.find((p) => p.symbol.toLowerCase() === (r == null ? void 0 : r.toLowerCase()))) == null ? void 0 : u.price) || 0, l = parseFloat(d.toString());
196
+ return e.tokensPriceMap[n] = l, l;
197
+ },
198
+ async getNetworkTokenPrice() {
199
+ var c;
200
+ const { networkAddress: n } = a.getParams(), o = (c = (await v.fetchTokenPrice({
201
+ addresses: [n]
202
+ }).catch(() => (w.showError("Failed to fetch network token price"), { fungibles: [] }))).fungibles) == null ? void 0 : c[0], s = (o == null ? void 0 : o.price.toString()) || "0";
203
+ e.tokensPriceMap[n] = parseFloat(s), e.networkTokenSymbol = (o == null ? void 0 : o.symbol) || "", e.networkPrice = s;
204
+ },
205
+ async getMyTokensWithBalance(n) {
206
+ var s;
207
+ const t = await z.getMyTokensWithBalance({
208
+ forceUpdate: n,
209
+ caipNetwork: m.state.activeCaipNetwork,
210
+ address: (s = m.getAccountData()) == null ? void 0 : s.address
211
+ }), o = N.mapBalancesToSwapTokens(t);
212
+ o && (await a.getInitialGasPrice(), a.setBalances(o));
213
+ },
214
+ setBalances(n) {
215
+ const { networkAddress: t } = a.getParams(), o = m.state.activeCaipNetwork;
216
+ if (!o)
217
+ return;
218
+ const s = n.find((c) => c.address === t);
219
+ n.forEach((c) => {
220
+ e.tokensPriceMap[c.address] = c.price || 0;
221
+ }), e.myTokensWithBalance = n.filter((c) => c.address.startsWith(o.caipNetworkId)), e.networkBalanceInUSD = s ? T.multiply(s.quantity.numeric, s.price).toString() : "0";
222
+ },
223
+ async getInitialGasPrice() {
224
+ var t, o;
225
+ const n = await N.fetchGasPrice();
226
+ if (!n)
227
+ return { gasPrice: null, gasPriceInUSD: null };
228
+ switch ((o = (t = m.state) == null ? void 0 : t.activeCaipNetwork) == null ? void 0 : o.chainNamespace) {
229
+ case P.CHAIN.SOLANA:
230
+ return e.gasFee = n.standard ?? "0", e.gasPriceInUSD = T.multiply(n.standard, e.networkPrice).div(1e9).toNumber(), {
231
+ gasPrice: BigInt(e.gasFee),
232
+ gasPriceInUSD: Number(e.gasPriceInUSD)
233
+ };
234
+ case P.CHAIN.EVM:
235
+ default:
236
+ const s = n.standard ?? "0", c = BigInt(s), r = BigInt(O), d = I.getGasPriceInUSD(e.networkPrice, r, c);
237
+ return e.gasFee = s, e.gasPriceInUSD = d, { gasPrice: c, gasPriceInUSD: d };
238
+ }
239
+ },
240
+ // -- Swap -------------------------------------- //
241
+ async swapTokens() {
242
+ var r, d, l;
243
+ const n = (r = m.getAccountData()) == null ? void 0 : r.address, t = e.sourceToken, o = e.toToken, s = T.bigNumber(e.sourceTokenAmount).gt(0);
244
+ if (s || a.setToTokenAmount(""), !o || !t || e.loadingPrices || !s || !n)
245
+ return;
246
+ e.loadingQuote = !0;
247
+ const c = T.bigNumber(e.sourceTokenAmount).times(10 ** t.decimals).round(0).toFixed(0);
248
+ try {
249
+ const i = await v.fetchSwapQuote({
250
+ userAddress: n,
251
+ from: t.address,
252
+ to: o.address,
253
+ gasPrice: e.gasFee,
254
+ amount: c.toString()
255
+ });
256
+ e.loadingQuote = !1;
257
+ const u = (l = (d = i == null ? void 0 : i.quotes) == null ? void 0 : d[0]) == null ? void 0 : l.toAmount;
258
+ if (!u) {
259
+ x.open({
260
+ displayMessage: "Incorrect amount",
261
+ debugMessage: "Please enter a valid amount"
262
+ }, "error");
263
+ return;
264
+ }
265
+ const p = T.bigNumber(u).div(10 ** o.decimals).toString();
266
+ a.setToTokenAmount(p), a.hasInsufficientToken(e.sourceTokenAmount, t.address) ? e.inputError = "Insufficient balance" : (e.inputError = void 0, a.setTransactionDetails());
267
+ } catch (i) {
268
+ const u = await N.handleSwapError(i);
269
+ e.loadingQuote = !1, e.inputError = u || "Insufficient balance";
270
+ }
271
+ },
272
+ // -- Create Transactions -------------------------------------- //
273
+ async getTransaction() {
274
+ const { fromCaipAddress: n, availableToSwap: t } = a.getParams(), o = e.sourceToken, s = e.toToken;
275
+ if (!(!n || !t || !o || !s || e.loadingQuote))
276
+ try {
277
+ e.loadingBuildTransaction = !0;
278
+ const c = await N.fetchSwapAllowance({
279
+ userAddress: n,
280
+ tokenAddress: o.address,
281
+ sourceTokenAmount: e.sourceTokenAmount,
282
+ sourceTokenDecimals: o.decimals
283
+ });
284
+ let r;
285
+ return c ? r = await a.createSwapTransaction() : r = await a.createAllowanceTransaction(), e.loadingBuildTransaction = !1, e.fetchError = !1, r;
286
+ } catch {
287
+ A.goBack(), w.showError("Failed to check allowance"), e.loadingBuildTransaction = !1, e.approvalTransaction = void 0, e.swapTransaction = void 0, e.fetchError = !0;
288
+ return;
289
+ }
290
+ },
291
+ async createAllowanceTransaction() {
292
+ const { fromCaipAddress: n, sourceTokenAddress: t, toTokenAddress: o } = a.getParams();
293
+ if (!(!n || !o)) {
294
+ if (!t)
295
+ throw new Error("createAllowanceTransaction - No source token address found.");
296
+ try {
297
+ const s = await v.generateApproveCalldata({
298
+ from: t,
299
+ to: o,
300
+ userAddress: n
301
+ }), c = L.getPlainAddress(s.tx.from);
302
+ if (!c)
303
+ throw new Error("SwapController:createAllowanceTransaction - address is required");
304
+ const r = {
305
+ data: s.tx.data,
306
+ to: c,
307
+ gasPrice: BigInt(s.tx.eip155.gasPrice),
308
+ value: BigInt(s.tx.value),
309
+ toAmount: e.toTokenAmount
310
+ };
311
+ return e.swapTransaction = void 0, e.approvalTransaction = {
312
+ data: r.data,
313
+ to: r.to,
314
+ gasPrice: r.gasPrice,
315
+ value: r.value,
316
+ toAmount: r.toAmount
317
+ }, {
318
+ data: r.data,
319
+ to: r.to,
320
+ gasPrice: r.gasPrice,
321
+ value: r.value,
322
+ toAmount: r.toAmount
323
+ };
324
+ } catch {
325
+ A.goBack(), w.showError("Failed to create approval transaction"), e.approvalTransaction = void 0, e.swapTransaction = void 0, e.fetchError = !0;
326
+ return;
327
+ }
328
+ }
329
+ },
330
+ async createSwapTransaction() {
331
+ var d;
332
+ const { networkAddress: n, fromCaipAddress: t, sourceTokenAmount: o } = a.getParams(), s = e.sourceToken, c = e.toToken;
333
+ if (!t || !o || !s || !c)
334
+ return;
335
+ const r = (d = D.parseUnits(o, s.decimals)) == null ? void 0 : d.toString();
336
+ try {
337
+ const l = await v.generateSwapCalldata({
338
+ userAddress: t,
339
+ from: s.address,
340
+ to: c.address,
341
+ amount: r,
342
+ disableEstimate: !0
343
+ }), i = s.address === n, u = BigInt(l.tx.eip155.gas), p = BigInt(l.tx.eip155.gasPrice), f = L.getPlainAddress(l.tx.to);
344
+ if (!f)
345
+ throw new Error("SwapController:createSwapTransaction - address is required");
346
+ const S = {
347
+ data: l.tx.data,
348
+ to: f,
349
+ gas: u,
350
+ gasPrice: p,
351
+ value: BigInt(i ? r ?? "0" : "0"),
352
+ toAmount: e.toTokenAmount
353
+ };
354
+ return e.gasPriceInUSD = I.getGasPriceInUSD(e.networkPrice, u, p), e.approvalTransaction = void 0, e.swapTransaction = S, S;
355
+ } catch {
356
+ A.goBack(), w.showError("Failed to create transaction"), e.approvalTransaction = void 0, e.swapTransaction = void 0, e.fetchError = !0;
357
+ return;
358
+ }
359
+ },
360
+ onEmbeddedWalletApprovalSuccess() {
361
+ w.showLoading("Approve limit increase in your wallet"), A.replace("SwapPreview");
362
+ },
363
+ // -- Send Transactions --------------------------------- //
364
+ async sendTransactionForApproval(n) {
365
+ var c, r, d;
366
+ const { fromAddress: t, isAuthConnector: o } = a.getParams();
367
+ e.loadingApprovalTransaction = !0, o ? A.pushTransactionStack({
368
+ onSuccess: a.onEmbeddedWalletApprovalSuccess
369
+ }) : w.showLoading("Approve limit increase in your wallet");
370
+ try {
371
+ await D.sendTransaction({
372
+ address: t,
373
+ to: n.to,
374
+ data: n.data,
375
+ value: n.value,
376
+ chainNamespace: P.CHAIN.EVM
377
+ }), await a.swapTokens(), await a.getTransaction(), e.approvalTransaction = void 0, e.loadingApprovalTransaction = !1;
378
+ } catch (l) {
379
+ const i = l;
380
+ e.transactionError = i == null ? void 0 : i.displayMessage, e.loadingApprovalTransaction = !1, w.showError((i == null ? void 0 : i.displayMessage) || "Transaction error"), B.sendEvent({
381
+ type: "track",
382
+ event: "SWAP_APPROVAL_ERROR",
383
+ properties: {
384
+ message: (i == null ? void 0 : i.displayMessage) || (i == null ? void 0 : i.message) || "Unknown",
385
+ network: ((c = m.state.activeCaipNetwork) == null ? void 0 : c.caipNetworkId) || "",
386
+ swapFromToken: ((r = a.state.sourceToken) == null ? void 0 : r.symbol) || "",
387
+ swapToToken: ((d = a.state.toToken) == null ? void 0 : d.symbol) || "",
388
+ swapFromAmount: a.state.sourceTokenAmount || "",
389
+ swapToAmount: a.state.toTokenAmount || "",
390
+ isSmartAccount: M(P.CHAIN.EVM) === F.ACCOUNT_TYPES.SMART_ACCOUNT
391
+ }
392
+ });
393
+ }
394
+ },
395
+ async sendTransactionForSwap(n) {
396
+ var d, l, i, u, p, f, S, h, y, b, C, G;
397
+ if (!n)
398
+ return;
399
+ const { fromAddress: t, toTokenAmount: o, isAuthConnector: s } = a.getParams();
400
+ e.loadingTransaction = !0;
401
+ const c = `Swapping ${(d = e.sourceToken) == null ? void 0 : d.symbol} to ${T.formatNumberToLocalString(o, 3)} ${(l = e.toToken) == null ? void 0 : l.symbol}`, r = `Swapped ${(i = e.sourceToken) == null ? void 0 : i.symbol} to ${T.formatNumberToLocalString(o, 3)} ${(u = e.toToken) == null ? void 0 : u.symbol}`;
402
+ s ? A.pushTransactionStack({
403
+ onSuccess() {
404
+ A.replace("Account"), w.showLoading(c), E.resetState();
405
+ }
406
+ }) : w.showLoading("Confirm transaction in your wallet");
407
+ try {
408
+ const U = [(p = e.sourceToken) == null ? void 0 : p.address, (f = e.toToken) == null ? void 0 : f.address].join(","), g = await D.sendTransaction({
409
+ address: t,
410
+ to: n.to,
411
+ data: n.data,
412
+ value: n.value,
413
+ chainNamespace: P.CHAIN.EVM
414
+ });
415
+ return e.loadingTransaction = !1, w.showSuccess(r), B.sendEvent({
416
+ type: "track",
417
+ event: "SWAP_SUCCESS",
418
+ properties: {
419
+ network: ((S = m.state.activeCaipNetwork) == null ? void 0 : S.caipNetworkId) || "",
420
+ swapFromToken: ((h = a.state.sourceToken) == null ? void 0 : h.symbol) || "",
421
+ swapToToken: ((y = a.state.toToken) == null ? void 0 : y.symbol) || "",
422
+ swapFromAmount: a.state.sourceTokenAmount || "",
423
+ swapToAmount: a.state.toTokenAmount || "",
424
+ isSmartAccount: M(P.CHAIN.EVM) === F.ACCOUNT_TYPES.SMART_ACCOUNT
425
+ }
426
+ }), E.resetState(), s || A.replace("Account"), E.getMyTokensWithBalance(U), g;
427
+ } catch (U) {
428
+ const g = U;
429
+ e.transactionError = g == null ? void 0 : g.displayMessage, e.loadingTransaction = !1, w.showError((g == null ? void 0 : g.displayMessage) || "Transaction error"), B.sendEvent({
430
+ type: "track",
431
+ event: "SWAP_ERROR",
432
+ properties: {
433
+ message: (g == null ? void 0 : g.displayMessage) || (g == null ? void 0 : g.message) || "Unknown",
434
+ network: ((b = m.state.activeCaipNetwork) == null ? void 0 : b.caipNetworkId) || "",
435
+ swapFromToken: ((C = a.state.sourceToken) == null ? void 0 : C.symbol) || "",
436
+ swapToToken: ((G = a.state.toToken) == null ? void 0 : G.symbol) || "",
437
+ swapFromAmount: a.state.sourceTokenAmount || "",
438
+ swapToAmount: a.state.toTokenAmount || "",
439
+ isSmartAccount: M(P.CHAIN.EVM) === F.ACCOUNT_TYPES.SMART_ACCOUNT
440
+ }
441
+ });
442
+ return;
443
+ }
444
+ },
445
+ // -- Checks -------------------------------------------- //
446
+ hasInsufficientToken(n, t) {
447
+ return I.isInsufficientSourceTokenForSwap(n, t, e.myTokensWithBalance);
448
+ },
449
+ // -- Calculations -------------------------------------- //
450
+ setTransactionDetails() {
451
+ const { toTokenAddress: n, toTokenDecimals: t } = a.getParams();
452
+ !n || !t || (e.gasPriceInUSD = I.getGasPriceInUSD(e.networkPrice, BigInt(e.gasFee), BigInt(O)), e.priceImpact = I.getPriceImpact({
453
+ sourceTokenAmount: e.sourceTokenAmount,
454
+ sourceTokenPriceInUSD: e.sourceTokenPriceInUSD,
455
+ toTokenPriceInUSD: e.toTokenPriceInUSD,
456
+ toTokenAmount: e.toTokenAmount
457
+ }), e.maxSlippage = I.getMaxSlippage(e.slippage, e.toTokenAmount), e.providerFee = I.getProviderFee(e.sourceTokenAmount));
458
+ }
459
+ }, a = W(E);
460
+ export {
461
+ a as S
462
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./parseSignature-D1tZHglo.js"),s=require("./index-CjZQCcwG.js");class k extends s.BaseError{constructor({callbackSelector:o,cause:t,data:c,extraData:u,sender:d,urls:a}){var n;super(t.shortMessage||"An error occurred while fetching for an offchain result.",{cause:t,metaMessages:[...t.metaMessages||[],(n=t.metaMessages)!=null&&n.length?"":[],"Offchain Gateway Call:",a&&[" Gateway URL(s):",...a.map(f=>` ${s.getUrl(f)}`)],` Sender: ${d}`,` Data: ${c}`,` Callback selector: ${o}`,` Extra data: ${u}`].flat(),name:"OffchainLookupError"})}}class b extends s.BaseError{constructor({result:o,url:t}){super("Offchain gateway response is malformed. Response data must be a hex value.",{metaMessages:[`Gateway URL: ${s.getUrl(t)}`,`Response: ${s.stringify(o)}`],name:"OffchainLookupResponseMalformedError"})}}class L extends s.BaseError{constructor({sender:o,to:t}){super("Reverted sender address does not match target contract address (`to`).",{metaMessages:[`Contract address: ${t}`,`OffchainLookup sender address: ${o}`],name:"OffchainLookupSenderMismatchError"})}}const E="0x556f1830",m={name:"OffchainLookup",type:"error",inputs:[{name:"sender",type:"address"},{name:"urls",type:"string[]"},{name:"callData",type:"bytes"},{name:"callbackFunction",type:"bytes4"},{name:"extraData",type:"bytes"}]};async function O(i,{blockNumber:o,blockTag:t,data:c,to:u}){const{args:d}=l.decodeErrorResult({data:c,abi:[m]}),[a,n,f,p,r]=d,{ccipRead:e}=i,y=e&&typeof(e==null?void 0:e.request)=="function"?e.request:g;try{if(!l.isAddressEqual(u,a))throw new L({sender:a,to:u});const h=n.includes(l.localBatchGatewayUrl)?await l.localBatchGatewayRequest({data:f,ccipRequest:y}):await y({data:f,sender:a,urls:n}),{data:w}=await l.call(i,{blockNumber:o,blockTag:t,data:s.concat([p,s.encodeAbiParameters([{type:"bytes"},{type:"bytes"}],[h,r])]),to:u});return w}catch(h){throw new k({callbackSelector:p,cause:h,data:c,extraData:r,sender:a,urls:n})}}async function g({data:i,sender:o,urls:t}){var u;let c=new Error("An unknown error occurred.");for(let d=0;d<t.length;d++){const a=t[d],n=a.includes("{data}")?"GET":"POST",f=n==="POST"?{data:i,sender:o}:void 0,p=n==="POST"?{"Content-Type":"application/json"}:{};try{const r=await fetch(a.replace("{sender}",o.toLowerCase()).replace("{data}",i),{body:JSON.stringify(f),headers:p,method:n});let e;if((u=r.headers.get("Content-Type"))!=null&&u.startsWith("application/json")?e=(await r.json()).data:e=await r.text(),!r.ok){c=new s.HttpRequestError({body:f,details:e!=null&&e.error?s.stringify(e.error):r.statusText,headers:r.headers,status:r.status,url:a});continue}if(!s.isHex(e)){c=new b({result:e,url:a});continue}return e}catch(r){c=new s.HttpRequestError({body:f,details:r.message,url:a})}}throw c}exports.ccipRequest=g;exports.offchainLookup=O;exports.offchainLookupAbiItem=m;exports.offchainLookupSignature=E;
@@ -0,0 +1,150 @@
1
+ import { a6 as b, ay as k, aX as L, aY as O, aZ as E } from "./parseSignature-DM0lwcDr.mjs";
2
+ import { Z as p, cr as y, bI as w, a_ as x, b2 as R, a7 as m, br as M } from "./index-B6Mg114Z.mjs";
3
+ class S extends p {
4
+ constructor({ callbackSelector: r, cause: a, data: n, extraData: i, sender: f, urls: t }) {
5
+ var o;
6
+ super(a.shortMessage || "An error occurred while fetching for an offchain result.", {
7
+ cause: a,
8
+ metaMessages: [
9
+ ...a.metaMessages || [],
10
+ (o = a.metaMessages) != null && o.length ? "" : [],
11
+ "Offchain Gateway Call:",
12
+ t && [
13
+ " Gateway URL(s):",
14
+ ...t.map((d) => ` ${y(d)}`)
15
+ ],
16
+ ` Sender: ${f}`,
17
+ ` Data: ${n}`,
18
+ ` Callback selector: ${r}`,
19
+ ` Extra data: ${i}`
20
+ ].flat(),
21
+ name: "OffchainLookupError"
22
+ });
23
+ }
24
+ }
25
+ class $ extends p {
26
+ constructor({ result: r, url: a }) {
27
+ super("Offchain gateway response is malformed. Response data must be a hex value.", {
28
+ metaMessages: [
29
+ `Gateway URL: ${y(a)}`,
30
+ `Response: ${w(r)}`
31
+ ],
32
+ name: "OffchainLookupResponseMalformedError"
33
+ });
34
+ }
35
+ }
36
+ class q extends p {
37
+ constructor({ sender: r, to: a }) {
38
+ super("Reverted sender address does not match target contract address (`to`).", {
39
+ metaMessages: [
40
+ `Contract address: ${a}`,
41
+ `OffchainLookup sender address: ${r}`
42
+ ],
43
+ name: "OffchainLookupSenderMismatchError"
44
+ });
45
+ }
46
+ }
47
+ const D = "0x556f1830", T = {
48
+ name: "OffchainLookup",
49
+ type: "error",
50
+ inputs: [
51
+ {
52
+ name: "sender",
53
+ type: "address"
54
+ },
55
+ {
56
+ name: "urls",
57
+ type: "string[]"
58
+ },
59
+ {
60
+ name: "callData",
61
+ type: "bytes"
62
+ },
63
+ {
64
+ name: "callbackFunction",
65
+ type: "bytes4"
66
+ },
67
+ {
68
+ name: "extraData",
69
+ type: "bytes"
70
+ }
71
+ ]
72
+ };
73
+ async function P(c, { blockNumber: r, blockTag: a, data: n, to: i }) {
74
+ const { args: f } = b({
75
+ data: n,
76
+ abi: [T]
77
+ }), [t, o, d, l, s] = f, { ccipRead: e } = c, h = e && typeof (e == null ? void 0 : e.request) == "function" ? e.request : C;
78
+ try {
79
+ if (!k(i, t))
80
+ throw new q({ sender: t, to: i });
81
+ const u = o.includes(L) ? await O({
82
+ data: d,
83
+ ccipRequest: h
84
+ }) : await h({ data: d, sender: t, urls: o }), { data: g } = await E(c, {
85
+ blockNumber: r,
86
+ blockTag: a,
87
+ data: x([
88
+ l,
89
+ R([{ type: "bytes" }, { type: "bytes" }], [u, s])
90
+ ]),
91
+ to: i
92
+ });
93
+ return g;
94
+ } catch (u) {
95
+ throw new S({
96
+ callbackSelector: l,
97
+ cause: u,
98
+ data: n,
99
+ extraData: s,
100
+ sender: t,
101
+ urls: o
102
+ });
103
+ }
104
+ }
105
+ async function C({ data: c, sender: r, urls: a }) {
106
+ var i;
107
+ let n = new Error("An unknown error occurred.");
108
+ for (let f = 0; f < a.length; f++) {
109
+ const t = a[f], o = t.includes("{data}") ? "GET" : "POST", d = o === "POST" ? { data: c, sender: r } : void 0, l = o === "POST" ? { "Content-Type": "application/json" } : {};
110
+ try {
111
+ const s = await fetch(t.replace("{sender}", r.toLowerCase()).replace("{data}", c), {
112
+ body: JSON.stringify(d),
113
+ headers: l,
114
+ method: o
115
+ });
116
+ let e;
117
+ if ((i = s.headers.get("Content-Type")) != null && i.startsWith("application/json") ? e = (await s.json()).data : e = await s.text(), !s.ok) {
118
+ n = new m({
119
+ body: d,
120
+ details: e != null && e.error ? w(e.error) : s.statusText,
121
+ headers: s.headers,
122
+ status: s.status,
123
+ url: t
124
+ });
125
+ continue;
126
+ }
127
+ if (!M(e)) {
128
+ n = new $({
129
+ result: e,
130
+ url: t
131
+ });
132
+ continue;
133
+ }
134
+ return e;
135
+ } catch (s) {
136
+ n = new m({
137
+ body: d,
138
+ details: s.message,
139
+ url: t
140
+ });
141
+ }
142
+ }
143
+ throw n;
144
+ }
145
+ export {
146
+ C as ccipRequest,
147
+ P as offchainLookup,
148
+ T as offchainLookupAbiItem,
149
+ D as offchainLookupSignature
150
+ };