@gearbox-protocol/ui-kit 4.7.0 → 4.8.0-next.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 (34) hide show
  1. package/README.md +5 -0
  2. package/dist/cjs/index.cjs +1 -1
  3. package/dist/cjs/user-agreements/agreement-cache.cjs +1 -0
  4. package/dist/cjs/user-agreements/agreement-error.cjs +1 -0
  5. package/dist/cjs/user-agreements/agreement-service.cjs +1 -0
  6. package/dist/cjs/user-agreements/index.cjs +1 -0
  7. package/dist/cjs/user-agreements/legal-messages.cjs +18 -0
  8. package/dist/cjs/user-agreements/types.cjs +1 -0
  9. package/dist/cjs/user-agreements/use-agreement.cjs +1 -0
  10. package/dist/cjs/user-agreements/use-blocked-region.cjs +1 -0
  11. package/dist/cjs/utils/index.cjs +1 -1
  12. package/dist/cjs/utils/wallet.cjs +1 -0
  13. package/dist/esm/index.js +181 -176
  14. package/dist/esm/user-agreements/agreement-cache.js +15 -0
  15. package/dist/esm/user-agreements/agreement-error.js +44 -0
  16. package/dist/esm/user-agreements/agreement-service.js +122 -0
  17. package/dist/esm/user-agreements/index.js +25 -0
  18. package/dist/esm/user-agreements/legal-messages.js +61 -0
  19. package/dist/esm/user-agreements/types.js +1 -0
  20. package/dist/esm/user-agreements/use-agreement.js +130 -0
  21. package/dist/esm/user-agreements/use-blocked-region.js +24 -0
  22. package/dist/esm/utils/index.js +30 -25
  23. package/dist/esm/utils/wallet.js +37 -0
  24. package/dist/types/user-agreements/agreement-cache.d.ts +11 -0
  25. package/dist/types/user-agreements/agreement-error.d.ts +19 -0
  26. package/dist/types/user-agreements/agreement-service.d.ts +25 -0
  27. package/dist/types/user-agreements/index.d.ts +6 -0
  28. package/dist/types/user-agreements/legal-messages.d.ts +49 -0
  29. package/dist/types/user-agreements/types.d.ts +28 -0
  30. package/dist/types/user-agreements/use-agreement.d.ts +76 -0
  31. package/dist/types/user-agreements/use-blocked-region.d.ts +15 -0
  32. package/dist/types/utils/index.d.ts +1 -0
  33. package/dist/types/utils/wallet.d.ts +25 -0
  34. package/package.json +20 -5
@@ -0,0 +1,15 @@
1
+ const n = ["gearbox-agreement"];
2
+ function s(t, e, r) {
3
+ return [e, t.toLowerCase(), ...r].join("@");
4
+ }
5
+ function u(t, e, r) {
6
+ t.getQueryData(n)?.[e]?.status !== "ALLOWED" && t.setQueryData(n, (o) => ({
7
+ ...o,
8
+ [e]: r
9
+ }));
10
+ }
11
+ export {
12
+ n as AGREEMENT_QUERY_KEY,
13
+ s as getAgreementKey,
14
+ u as setAgreementStatus
15
+ };
@@ -0,0 +1,44 @@
1
+ class i extends Error {
2
+ constructor(r, t) {
3
+ super(`Request failed with status ${r}`), this.status = r, this.data = t, this.name = "AgreementHttpError";
4
+ }
5
+ }
6
+ class e extends Error {
7
+ constructor(r, t) {
8
+ super(r), this.code = r, this.originalError = t, this.name = "AgreementError";
9
+ }
10
+ static type = "AgreementError";
11
+ type = e.type;
12
+ static isAgreementError(r) {
13
+ return !!r && typeof r == "object" && "type" in r && r.type === e.type || r instanceof e;
14
+ }
15
+ static getErrorCode(r, t) {
16
+ if (!(r instanceof i)) return "unknownError";
17
+ switch (r.status) {
18
+ case 400:
19
+ return "badRequest";
20
+ case 500:
21
+ return "internalServerError";
22
+ case 404:
23
+ return "notFound";
24
+ case 401: {
25
+ const n = r.data ?? {}, o = Number(n.currentVersion), s = Number(n.signedVersion) || 0;
26
+ return o === t && s !== 0 && s < t ? "notLogged_passed_v2Sig" : "notLogged_passed";
27
+ }
28
+ case 451:
29
+ return "notLogged_notPassed";
30
+ default:
31
+ return "unknownError";
32
+ }
33
+ }
34
+ static fromError(r, t) {
35
+ return e.isAgreementError(r) ? r : new e(
36
+ e.getErrorCode(r, t),
37
+ r
38
+ );
39
+ }
40
+ }
41
+ export {
42
+ e as AgreementError,
43
+ i as AgreementHttpError
44
+ };
@@ -0,0 +1,122 @@
1
+ import { AgreementError as i, AgreementHttpError as o } from "./agreement-error.js";
2
+ import { DEFAULT_LEGAL_MESSAGE as c, hashMessage as g } from "./legal-messages.js";
3
+ const h = "https://auth.gearbox.foundation/agreements", u = "https://app.gearbox.finance/api/check-access", E = {
4
+ notLogged_passed: "NOT_SIGNED",
5
+ notLogged_passed_v2Sig: "NOT_SIGNED",
6
+ notLogged_notPassed: "BLOCKED",
7
+ badRequest: "NOT_SIGNED",
8
+ notFound: "ALLOWED",
9
+ internalServerError: "ALLOWED",
10
+ unknownError: "NOT_SIGNED"
11
+ };
12
+ async function d(n) {
13
+ const e = await n.text();
14
+ if (e)
15
+ try {
16
+ return JSON.parse(e);
17
+ } catch {
18
+ return e;
19
+ }
20
+ }
21
+ async function r(n, e) {
22
+ const t = await fetch(n, e), s = await d(t);
23
+ if (!t.ok) throw new o(t.status, s);
24
+ return s;
25
+ }
26
+ class p {
27
+ config;
28
+ legalMessage;
29
+ constructor(e) {
30
+ this.config = {
31
+ ...e,
32
+ signatureEndpoint: e.signatureEndpoint ?? h,
33
+ accessCheckEndpoint: e.accessCheckEndpoint ?? u
34
+ }, this.legalMessage = e.legalMessage || c;
35
+ }
36
+ async checkAgreement(e) {
37
+ try {
38
+ return { status: await this.checkSignatureOnServer(
39
+ e.account,
40
+ g(this.legalMessage.text),
41
+ e.chainId
42
+ ) };
43
+ } catch (t) {
44
+ throw i.fromError(t, this.legalMessage.version);
45
+ }
46
+ }
47
+ async signAgreement(e) {
48
+ try {
49
+ return await this.signMessage(e);
50
+ } catch (t) {
51
+ throw i.fromError(t, this.legalMessage.version);
52
+ }
53
+ }
54
+ /**
55
+ * Check access (e.g., geo-blocking). Any failure counts as not allowed.
56
+ */
57
+ async checkAccess() {
58
+ if (!this.config.accessCheckEndpoint) return !0;
59
+ try {
60
+ return (await r(this.config.accessCheckEndpoint))?.allowed === !0;
61
+ } catch {
62
+ return !1;
63
+ }
64
+ }
65
+ getLegalMessage() {
66
+ return this.legalMessage.text;
67
+ }
68
+ getLegalMessageVersion() {
69
+ return this.legalMessage.version;
70
+ }
71
+ async checkSignatureOnServer(e, t, s) {
72
+ const a = new URLSearchParams({
73
+ address: e,
74
+ agreementHash: t
75
+ });
76
+ return s !== void 0 && a.set("chainId", String(s)), await r(`${this.config.signatureEndpoint}?${a}`), "ALLOWED";
77
+ }
78
+ async signMessage({
79
+ signer: e,
80
+ account: t,
81
+ chainId: s
82
+ }) {
83
+ const a = await e.signMessage({
84
+ message: this.legalMessage.text,
85
+ account: t
86
+ });
87
+ return await this.submitSignature({
88
+ account: t,
89
+ signature: a,
90
+ chainId: s,
91
+ hash: g(this.legalMessage.text)
92
+ }), { status: "ALLOWED" };
93
+ }
94
+ async submitSignature({
95
+ account: e,
96
+ hash: t,
97
+ signature: s,
98
+ chainId: a
99
+ }) {
100
+ await r(this.config.signatureEndpoint, {
101
+ method: "POST",
102
+ headers: { "content-type": "application/json" },
103
+ body: JSON.stringify({
104
+ address: e,
105
+ signature: s,
106
+ chainId: a,
107
+ agreementHash: t
108
+ })
109
+ });
110
+ }
111
+ static getAgreementStatus(e) {
112
+ return {
113
+ status: E[e],
114
+ hasV2Signature: e === "notLogged_passed_v2Sig"
115
+ };
116
+ }
117
+ }
118
+ export {
119
+ p as AgreementService,
120
+ u as GEARBOX_ACCESS_CHECK_ENDPOINT,
121
+ h as GEARBOX_USER_AGREEMENTS_ENDPOINT
122
+ };
@@ -0,0 +1,25 @@
1
+ import { AgreementError as A } from "./agreement-error.js";
2
+ import { AgreementService as L, GEARBOX_ACCESS_CHECK_ENDPOINT as G, GEARBOX_USER_AGREEMENTS_ENDPOINT as e } from "./agreement-service.js";
3
+ import { COMBINED_LEGAL_MESSAGES as r, CURRENT_COMBINED_LEGAL_MESSAGE_VERSION as M, CURRENT_LEGAL_MESSAGE_VERSION as N, CURRENT_RWA_LEGAL_MESSAGE_VERSION as o, DEFAULT_COMBINED_LEGAL_MESSAGE as O, DEFAULT_LEGAL_MESSAGE as C, DEFAULT_RWA_LEGAL_MESSAGE as I, LEGAL_MESSAGES as T, PERMISSIONLESS_LEGAL_MESSAGE as m, RWA_LEGAL_MESSAGES as t, SAFE_LEGAL_MESSAGE as D, hashMessage as U } from "./legal-messages.js";
4
+ import { useAgreement as f } from "./use-agreement.js";
5
+ import { useBlockedRegion as p } from "./use-blocked-region.js";
6
+ export {
7
+ A as AgreementError,
8
+ L as AgreementService,
9
+ r as COMBINED_LEGAL_MESSAGES,
10
+ M as CURRENT_COMBINED_LEGAL_MESSAGE_VERSION,
11
+ N as CURRENT_LEGAL_MESSAGE_VERSION,
12
+ o as CURRENT_RWA_LEGAL_MESSAGE_VERSION,
13
+ O as DEFAULT_COMBINED_LEGAL_MESSAGE,
14
+ C as DEFAULT_LEGAL_MESSAGE,
15
+ I as DEFAULT_RWA_LEGAL_MESSAGE,
16
+ G as GEARBOX_ACCESS_CHECK_ENDPOINT,
17
+ e as GEARBOX_USER_AGREEMENTS_ENDPOINT,
18
+ T as LEGAL_MESSAGES,
19
+ m as PERMISSIONLESS_LEGAL_MESSAGE,
20
+ t as RWA_LEGAL_MESSAGES,
21
+ D as SAFE_LEGAL_MESSAGE,
22
+ U as hashMessage,
23
+ f as useAgreement,
24
+ p as useBlockedRegion
25
+ };
@@ -0,0 +1,61 @@
1
+ import { sha256 as r, stringToBytes as s } from "viem";
2
+ function g(n) {
3
+ return r(s(n), "hex").slice(2);
4
+ }
5
+ const i = {
6
+ version: 2,
7
+ text: `By accessing or using Gearbox App, I agree to the Terms of Service (https://gearbox.fi/terms) and confirm that I have read and understood the Privacy Notice (https://gearbox.fi/privacy) and Risk Disclosure Statement (https://gearbox.fi/risks).
8
+ I hereby further represent and warrant that:
9
+ - I’m not a resident of or located in the United States of America (including its territories: American Samoa, Guam, Puerto Rico, the Northern Mariana Islands and the U.S. Virgin Islands) or any other Restricted Jurisdiction (as defined in the Terms of Service);
10
+ - I’m not a Prohibited Person (as defined in the Terms of Service) nor acting on behalf of a Prohibited Person;
11
+ - I understand that if I fail to maintain sufficient collateral when using the Gearbox Protocol, my credit account(s) may be liquidated, in which case a penalty may be charged by the protocol;
12
+ - I acknowledge that Gearbox App and related software are experimental, and that the use of experimental software may result in complete loss of my funds.`
13
+ }, o = {
14
+ version: 3,
15
+ text: `By signing this message, I hereby represent, warrant and confirm that:
16
+ - I agree to the Terms of Service (https://gearbox.finance/terms) and acknowledge the Privacy Notice (https://gearbox.finance/privacy).
17
+ - I represent and confirm that I am not a Prohibited Person (as defined in the above Terms of Service) and am not acting on behalf of one.
18
+ - I acknowledge that the Gearbox App, related software, and smart contracts are experimental and may contain errors or vulnerabilities. I understand that their use may result in the complete loss of my funds. I have read the Risk Disclosure Statement (https://gearbox.finance/risks) and I voluntarily assume all risks described in it.
19
+ `
20
+ }, e = {
21
+ 2: i,
22
+ 3: o
23
+ }, c = 3, E = e[c] ?? e[3], d = {
24
+ version: 1,
25
+ text: `By signing this message, I hereby represent, warrant and confirm that:
26
+ - I agree to the Terms of Service (https://gearbox.finance/terms) and RWA Markets Interface Terms & Conditions (https://gearbox.finance/rwa-tc), and acknowledge the Privacy Notice (https://gearbox.finance/privacy)”.
27
+ - I represent and confirm that I am not a Prohibited Person (as defined in the above Terms of Service) and am not acting on behalf of one.
28
+ - I acknowledge that the Gearbox App, RWA Markets Interface, related software, and smart contracts are experimental and may contain errors or vulnerabilities. I understand that their use may result in the complete loss of my funds. I have read the Risk Disclosure Statement (https://gearbox.finance/risks) and I voluntarily assume all risks described in it and the above RWA Markets Interface Terms & Conditions.
29
+ `
30
+ }, t = {
31
+ 1: d
32
+ }, h = 1, S = t[h] ?? t[1], l = {
33
+ version: 1,
34
+ text: `By signing this message, I hereby represent, warrant, and confirm that:
35
+ - I agree to the Terms of Service (https://gearbox.finance/terms) and RWA Markets Interface Terms & Conditions (https://www.gearbox.finance/rwa-tc), and acknowledge the Privacy Notice (https://gearbox.finance/privacy).
36
+ - I represent and confirm that I am not a Prohibited Person (as defined in the above Terms of Service) and am not acting on behalf of one.
37
+ - I acknowledge that the Gearbox App, RWA Markets Interface, related software, and smart contracts are experimental and may contain errors or vulnerabilities. I understand that their use may result in the complete loss of my funds. I have read the Risk Disclosure Statement (https://gearbox.finance/risks) and I voluntarily assume all risks described in it and the documents indicated above.
38
+ `
39
+ }, a = {
40
+ 1: l
41
+ }, m = 1, p = a[m] ?? a[1], I = {
42
+ version: 1,
43
+ text: "By signing this message, I agree to the Terms of Service (https://permissionless.gearbox.foundation/legal/terms-of-service) and acknowledge the Privacy Notice (https://permissionless.gearbox.foundation/legal/privacy-notice). I have read the Risk Disclosure Statement (https://permissionless.gearbox.foundation/legal/risk-disclosure) and I voluntarily assume all risks described in it."
44
+ }, b = {
45
+ version: 1,
46
+ text: "By signing this message, I agree to the Terms of Service (https://safe.gearbox.finance/legal/terms-of-service) and acknowledge the Privacy Notice (https://safe.gearbox.finance/legal/privacy-notice). I have read the Risk Disclosure Statement (https://safe.gearbox.finance/legal/risk-disclosure) and I voluntarily assume all risks described in it."
47
+ };
48
+ export {
49
+ a as COMBINED_LEGAL_MESSAGES,
50
+ m as CURRENT_COMBINED_LEGAL_MESSAGE_VERSION,
51
+ c as CURRENT_LEGAL_MESSAGE_VERSION,
52
+ h as CURRENT_RWA_LEGAL_MESSAGE_VERSION,
53
+ p as DEFAULT_COMBINED_LEGAL_MESSAGE,
54
+ E as DEFAULT_LEGAL_MESSAGE,
55
+ S as DEFAULT_RWA_LEGAL_MESSAGE,
56
+ e as LEGAL_MESSAGES,
57
+ I as PERMISSIONLESS_LEGAL_MESSAGE,
58
+ t as RWA_LEGAL_MESSAGES,
59
+ b as SAFE_LEGAL_MESSAGE,
60
+ g as hashMessage
61
+ };
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,130 @@
1
+ import { useQueryClient as q, useQuery as S, useMutation as O } from "@tanstack/react-query";
2
+ import { useMemo as T } from "react";
3
+ import { useAccount as R, useChainId as Y } from "wagmi";
4
+ import { AGREEMENT_QUERY_KEY as A, getAgreementKey as s, setAgreementStatus as u } from "./agreement-cache.js";
5
+ import { AgreementError as N } from "./agreement-error.js";
6
+ import { AgreementService as y } from "./agreement-service.js";
7
+ const U = [];
8
+ function B(F) {
9
+ const {
10
+ config: I,
11
+ account: K,
12
+ chainId: M,
13
+ autoCheck: k = !0,
14
+ additionalQueryDep: o = U,
15
+ onCheckAgreement: _,
16
+ onCheckAgreementError: v,
17
+ onSignAgreement: C,
18
+ onSignAgreementSuccess: Q,
19
+ onSignAgreementError: w
20
+ } = F, { address: D } = R(), L = Y(), d = q(), r = K ?? D, f = M ?? L, i = T(
21
+ () => new y(I),
22
+ [I]
23
+ ), n = i.getLegalMessageVersion(), h = S({
24
+ queryKey: A,
25
+ staleTime: Number.POSITIVE_INFINITY,
26
+ refetchOnWindowFocus: !1,
27
+ retry: !1,
28
+ enabled: !1,
29
+ initialData: () => ({}),
30
+ queryFn: async () => ({})
31
+ }), g = T(
32
+ () => r ? h.data?.[s(r, n, o)] : void 0,
33
+ [
34
+ h.data,
35
+ r,
36
+ n,
37
+ o
38
+ ]
39
+ ), m = S({
40
+ queryKey: [...A, "check", r, ...o],
41
+ staleTime: Number.POSITIVE_INFINITY,
42
+ refetchOnWindowFocus: !1,
43
+ retry: !1,
44
+ enabled: k && !!r && g?.status === void 0,
45
+ queryFn: async (e) => {
46
+ if (!r) return null;
47
+ const t = s(
48
+ r,
49
+ n,
50
+ o
51
+ );
52
+ try {
53
+ const c = { account: r, chainId: f };
54
+ _?.(c);
55
+ const a = await i.checkAgreement(c);
56
+ return u(e.client, t, a), a;
57
+ } catch (c) {
58
+ const a = N.fromError(c, n);
59
+ v?.({ error: a, account: r, chainId: f });
60
+ const E = y.getAgreementStatus(a.code);
61
+ return u(e.client, t, E), E;
62
+ }
63
+ }
64
+ }), l = O({
65
+ mutationKey: [...A, "sign"],
66
+ onMutate: (e) => {
67
+ C?.({
68
+ account: e.account,
69
+ chainId: e.chainId,
70
+ legalMessageVersion: n
71
+ });
72
+ const t = s(
73
+ e.account,
74
+ n,
75
+ o
76
+ );
77
+ u(d, t, {
78
+ status: "AWAITING_SIGNATURE"
79
+ });
80
+ },
81
+ mutationFn: (e) => i.signAgreement(e),
82
+ onSuccess: (e, t) => {
83
+ const c = s(
84
+ t.account,
85
+ n,
86
+ o
87
+ );
88
+ u(d, c, e), Q?.({
89
+ account: t.account,
90
+ result: e,
91
+ chainId: t.chainId,
92
+ legalMessageVersion: n
93
+ });
94
+ },
95
+ onError: (e, t) => {
96
+ const c = s(
97
+ t.account,
98
+ n,
99
+ o
100
+ ), a = N.fromError(e, n);
101
+ w?.({
102
+ error: a,
103
+ account: t.account,
104
+ chainId: t.chainId
105
+ }), u(
106
+ d,
107
+ c,
108
+ y.getAgreementStatus(a.code)
109
+ );
110
+ }
111
+ }), P = async () => {
112
+ if (r)
113
+ return m.refetch().then((e) => e.data ?? void 0);
114
+ }, V = (e) => l.mutateAsync(e), b = (m.isLoading || m.isFetching) && g?.status === void 0;
115
+ return {
116
+ status: g?.status,
117
+ isLoading: b,
118
+ isSigning: l.isPending,
119
+ error: m.error || l.error || null,
120
+ checkAgreement: P,
121
+ signAgreement: V,
122
+ hasV2Signature: g?.hasV2Signature ?? !1,
123
+ legalMessage: i.getLegalMessage(),
124
+ legalMessageVersion: n,
125
+ allStatuses: h.data || {}
126
+ };
127
+ }
128
+ export {
129
+ B as useAgreement
130
+ };
@@ -0,0 +1,24 @@
1
+ import { useQuery as o } from "@tanstack/react-query";
2
+ import { useMemo as n } from "react";
3
+ import { AgreementService as t } from "./agreement-service.js";
4
+ function d(e) {
5
+ const s = n(
6
+ () => new t(e),
7
+ [e]
8
+ ), r = o({
9
+ queryKey: ["blockedRegion", e.accessCheckEndpoint],
10
+ retry: !1,
11
+ staleTime: Number.POSITIVE_INFINITY,
12
+ refetchOnWindowFocus: !1,
13
+ enabled: !!e.accessCheckEndpoint,
14
+ queryFn: async () => !await s.checkAccess()
15
+ });
16
+ return {
17
+ isBlocked: r.data ?? !1,
18
+ isLoading: r.isLoading || r.isFetching,
19
+ isError: r.isError
20
+ };
21
+ }
22
+ export {
23
+ d as useBlockedRegion
24
+ };
@@ -1,34 +1,39 @@
1
1
  import { cn as o, cn as t } from "./cn.js";
2
- import { APPROXIMATE_SYMBOL as p, formatTimestamp as a, shortenHash as f } from "./format.js";
3
- import { formatLeverage as x, formatLeverageExact as i } from "./format-leverage.js";
4
- import { formatMoney as l, percentageTemplate as c } from "./format-money.js";
2
+ import { APPROXIMATE_SYMBOL as m, formatTimestamp as p, shortenHash as f } from "./format.js";
3
+ import { formatLeverage as i, formatLeverageExact as x } from "./format-leverage.js";
4
+ import { formatMoney as S, percentageTemplate as c } from "./format-money.js";
5
5
  import { formatPnl as T } from "./format-pnl.js";
6
- import { formatOraclePrice as I } from "./format-price.js";
7
- import { slippageTemplate as d } from "./format-slippage.js";
8
- import { leveragePresets as u } from "./leverage-presets.js";
9
- import { bnToLiquidationPriceView as w, parseInputToBN as E } from "./parse-input-to-bn.js";
10
- import { shortenString as N } from "./shorten-string.js";
11
- import { tokenTemplateString as S } from "./templates.js";
12
- import { openInNewWindow as B } from "./window.js";
13
- import { Z_INDEX as _ } from "./z-index.js";
6
+ import { formatOraclePrice as A } from "./format-price.js";
7
+ import { slippageTemplate as P } from "./format-slippage.js";
8
+ import { leveragePresets as I } from "./leverage-presets.js";
9
+ import { bnToLiquidationPriceView as M, parseInputToBN as N } from "./parse-input-to-bn.js";
10
+ import { shortenString as _ } from "./shorten-string.js";
11
+ import { tokenTemplateString as h } from "./templates.js";
12
+ import { DEFAULT_SAFE_DOMAINS as v, isBinanceSDK as w, isSafeAppsSDK as B, isSafeDomain as F } from "./wallet.js";
13
+ import { openInNewWindow as X } from "./window.js";
14
+ import { Z_INDEX as k } from "./z-index.js";
14
15
  export {
15
- p as APPROXIMATE_SYMBOL,
16
- _ as Z_INDEX,
17
- w as bnToLiquidationPriceView,
16
+ m as APPROXIMATE_SYMBOL,
17
+ v as DEFAULT_SAFE_DOMAINS,
18
+ k as Z_INDEX,
19
+ M as bnToLiquidationPriceView,
18
20
  o as cn,
19
21
  t as default,
20
- x as formatLeverage,
21
- i as formatLeverageExact,
22
- l as formatMoney,
23
- I as formatOraclePrice,
22
+ i as formatLeverage,
23
+ x as formatLeverageExact,
24
+ S as formatMoney,
25
+ A as formatOraclePrice,
24
26
  T as formatPnl,
25
- a as formatTimestamp,
26
- u as leveragePresets,
27
- B as openInNewWindow,
28
- E as parseInputToBN,
27
+ p as formatTimestamp,
28
+ w as isBinanceSDK,
29
+ B as isSafeAppsSDK,
30
+ F as isSafeDomain,
31
+ I as leveragePresets,
32
+ X as openInNewWindow,
33
+ N as parseInputToBN,
29
34
  c as percentageTemplate,
30
35
  f as shortenHash,
31
- N as shortenString,
32
- d as slippageTemplate,
33
- S as tokenTemplateString
36
+ _ as shortenString,
37
+ P as slippageTemplate,
38
+ h as tokenTemplateString
34
39
  };
@@ -0,0 +1,37 @@
1
+ const i = [
2
+ /blockscout\.com(\/|$)/,
3
+ /app\.safe\.global(\/|$)/,
4
+ /coinshift\.global(\/|$)/,
5
+ /explorer\.optimism\.io(\/|$)/
6
+ ];
7
+ function a(e) {
8
+ return e.type === "safe" || e.id === "safe" || e.name.toLowerCase().includes("safe");
9
+ }
10
+ function s(e) {
11
+ return e.type === "binance" || e.id.toLowerCase().includes("binance") || e.name.toLowerCase().includes("binance");
12
+ }
13
+ function r() {
14
+ try {
15
+ return window.self !== window.top;
16
+ } catch {
17
+ return !0;
18
+ }
19
+ }
20
+ function o() {
21
+ try {
22
+ return new URL(document.referrer).host;
23
+ } catch {
24
+ return document.referrer;
25
+ }
26
+ }
27
+ function u(e = i) {
28
+ if (typeof window > "u" || !r()) return !1;
29
+ const n = o();
30
+ return e.some((t) => t.test(n));
31
+ }
32
+ export {
33
+ i as DEFAULT_SAFE_DOMAINS,
34
+ s as isBinanceSDK,
35
+ a as isSafeAppsSDK,
36
+ u as isSafeDomain
37
+ };
@@ -0,0 +1,11 @@
1
+ import { QueryClient } from '@tanstack/react-query';
2
+ import { Address } from 'viem';
3
+ import { AgreementResult } from './types';
4
+ export type AgreementRecord = Record<string, AgreementResult>;
5
+ export declare const AGREEMENT_QUERY_KEY: readonly ["gearbox-agreement"];
6
+ export declare function getAgreementKey(account: Address, version: number, additionalQueryDep: string[]): string;
7
+ /**
8
+ * An ALLOWED status is final: later checks or failed signatures never
9
+ * downgrade it
10
+ */
11
+ export declare function setAgreementStatus(client: QueryClient, authKey: string, result: AgreementResult): void;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Non-2xx response from an agreements endpoint
3
+ */
4
+ export declare class AgreementHttpError extends Error {
5
+ status: number;
6
+ data: unknown;
7
+ constructor(status: number, data: unknown);
8
+ }
9
+ export type AgreementErrorCode = "notLogged_passed" | "notLogged_passed_v2Sig" | "notLogged_notPassed" | "badRequest" | "notFound" | "internalServerError" | "unknownError";
10
+ export declare class AgreementError extends Error {
11
+ code: AgreementErrorCode;
12
+ originalError?: unknown | undefined;
13
+ static type: "AgreementError";
14
+ type: "AgreementError";
15
+ constructor(code: AgreementErrorCode, originalError?: unknown | undefined);
16
+ static isAgreementError(e: unknown): e is AgreementError;
17
+ static getErrorCode(e: unknown, legalMessageVersion: number): AgreementErrorCode;
18
+ static fromError(e: unknown, legalMessageVersion: number): AgreementError;
19
+ }
@@ -0,0 +1,25 @@
1
+ import { AgreementErrorCode } from './agreement-error';
2
+ import { AgreementConfig, AgreementResult, CheckAgreementProps, SignAgreementProps } from './types';
3
+ export declare const GEARBOX_USER_AGREEMENTS_ENDPOINT = "https://auth.gearbox.foundation/agreements";
4
+ export declare const GEARBOX_ACCESS_CHECK_ENDPOINT = "https://app.gearbox.finance/api/check-access";
5
+ /**
6
+ * Service for legal agreement signing.
7
+ * Contract wallets (Safe) are verified on-chain by the server.
8
+ */
9
+ export declare class AgreementService {
10
+ private config;
11
+ private legalMessage;
12
+ constructor(config: AgreementConfig);
13
+ checkAgreement(props: CheckAgreementProps): Promise<AgreementResult>;
14
+ signAgreement(props: SignAgreementProps): Promise<AgreementResult>;
15
+ /**
16
+ * Check access (e.g., geo-blocking). Any failure counts as not allowed.
17
+ */
18
+ checkAccess(): Promise<boolean>;
19
+ getLegalMessage(): string;
20
+ getLegalMessageVersion(): number;
21
+ private checkSignatureOnServer;
22
+ private signMessage;
23
+ private submitSignature;
24
+ static getAgreementStatus(t: AgreementErrorCode): AgreementResult;
25
+ }
@@ -0,0 +1,6 @@
1
+ export { AgreementError, type AgreementErrorCode } from './agreement-error';
2
+ export * from './agreement-service';
3
+ export * from './legal-messages';
4
+ export * from './types';
5
+ export * from './use-agreement';
6
+ export * from './use-blocked-region';
@@ -0,0 +1,49 @@
1
+ import { LegalMessage } from './types';
2
+ /**
3
+ * Hash function to compute SHA256 of message text
4
+ */
5
+ export declare function hashMessage(text: string): string;
6
+ /**
7
+ * All legal message versions
8
+ */
9
+ export declare const LEGAL_MESSAGES: Record<number, LegalMessage>;
10
+ /**
11
+ * Current legal message version
12
+ */
13
+ export declare const CURRENT_LEGAL_MESSAGE_VERSION: number;
14
+ /**
15
+ * Default legal message (current version)
16
+ */
17
+ export declare const DEFAULT_LEGAL_MESSAGE: LegalMessage;
18
+ /**
19
+ * All rwa legal message versions
20
+ */
21
+ export declare const RWA_LEGAL_MESSAGES: Record<number, LegalMessage>;
22
+ /**
23
+ * Current rwa legal message version
24
+ */
25
+ export declare const CURRENT_RWA_LEGAL_MESSAGE_VERSION: number;
26
+ /**
27
+ * Default rwa legal message (current version)
28
+ */
29
+ export declare const DEFAULT_RWA_LEGAL_MESSAGE: LegalMessage;
30
+ /**
31
+ * All combined legal message versions
32
+ */
33
+ export declare const COMBINED_LEGAL_MESSAGES: Record<number, LegalMessage>;
34
+ /**
35
+ * Current combined legal message version
36
+ */
37
+ export declare const CURRENT_COMBINED_LEGAL_MESSAGE_VERSION: number;
38
+ /**
39
+ * Default combined legal message (current version)
40
+ */
41
+ export declare const DEFAULT_COMBINED_LEGAL_MESSAGE: LegalMessage;
42
+ /**
43
+ * Legal message for Permissionless Interface
44
+ */
45
+ export declare const PERMISSIONLESS_LEGAL_MESSAGE: LegalMessage;
46
+ /**
47
+ * Legal message for Gearbox Safe
48
+ */
49
+ export declare const SAFE_LEGAL_MESSAGE: LegalMessage;
@@ -0,0 +1,28 @@
1
+ import { Address, WalletClient } from 'viem';
2
+ export type AgreementStatus = "ALLOWED" | "NOT_SIGNED" | "BLOCKED" | "AWAITING_SIGNATURE";
3
+ export interface AgreementResult {
4
+ status: AgreementStatus;
5
+ hasV2Signature?: boolean;
6
+ }
7
+ export interface LegalMessage {
8
+ version: number;
9
+ text: string;
10
+ }
11
+ export interface CheckAgreementProps {
12
+ account: Address;
13
+ /** Hint for the server: chain to check for Safe on-chain approval first */
14
+ chainId?: number;
15
+ }
16
+ export interface SignAgreementProps {
17
+ account: Address;
18
+ signer: WalletClient;
19
+ chainId: number;
20
+ }
21
+ export interface AgreementConfig {
22
+ /** Endpoint for signature verification (default: GEARBOX_USER_AGREEMENTS_ENDPOINT) */
23
+ signatureEndpoint?: string;
24
+ /** Endpoint for geo-access check (default: GEARBOX_ACCESS_CHECK_ENDPOINT) */
25
+ accessCheckEndpoint?: string;
26
+ /** Legal message for signing */
27
+ legalMessage?: LegalMessage;
28
+ }