@gardenfi/swap 0.0.1-beta.3 → 0.0.1-beta.5

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 (110) hide show
  1. package/README.md +58 -44
  2. package/dist/ccip-D21YSsYF.js +184 -0
  3. package/dist/index-DiU4Bbp1.js +146252 -0
  4. package/dist/index.es.js +14 -0
  5. package/dist/src/index.d.ts +1 -1
  6. package/dist/src/lib/GardenSwapWidget.d.ts +4 -0
  7. package/dist/src/lib/common/BottomSheet.d.ts +7 -0
  8. package/dist/src/lib/common/ChainsToolTip.d.ts +1 -3
  9. package/dist/src/lib/common/CopyToClipboard.d.ts +7 -0
  10. package/dist/src/lib/common/GardenBranding.d.ts +1 -0
  11. package/dist/src/lib/common/Header.d.ts +3 -0
  12. package/dist/src/lib/common/Modal.d.ts +0 -2
  13. package/dist/src/lib/common/ModalComponent.d.ts +1 -3
  14. package/dist/src/lib/common/Sidebar.d.ts +9 -0
  15. package/dist/src/lib/common/SwapWidgetBase.d.ts +7 -0
  16. package/dist/src/lib/components/CreateSwap.d.ts +1 -4
  17. package/dist/src/lib/components/SwapSavingsAndAddresses.d.ts +1 -3
  18. package/dist/src/lib/components/SwapWidget.d.ts +5 -4
  19. package/dist/src/lib/components/TestSwapStore.d.ts +1 -0
  20. package/dist/src/lib/components/assetSelection/AvailableChainsSidebar.d.ts +1 -2
  21. package/dist/src/lib/components/feesAndRateDetails/FeeAndRateDetails.d.ts +1 -3
  22. package/dist/src/lib/components/feesAndRateDetails/InputAddress.d.ts +1 -3
  23. package/dist/src/lib/components/feesAndRateDetails/InputAddressAndFeeRateDetails.d.ts +1 -3
  24. package/dist/src/lib/components/swapInProgress/SwapInProgress.d.ts +1 -0
  25. package/dist/src/lib/components/swapInProgress/SwapInProgressSkeleton.d.ts +1 -0
  26. package/dist/src/lib/components/transactions/TransactionHistory.d.ts +2 -2
  27. package/dist/src/lib/components/transactions/Transactions.d.ts +1 -4
  28. package/dist/src/lib/constants/constants.d.ts +25 -0
  29. package/dist/src/lib/constants/wagmiConfig.d.ts +1404 -0
  30. package/dist/src/lib/hooks/useAddresses.d.ts +8 -0
  31. package/dist/src/lib/hooks/useSwap.d.ts +1 -0
  32. package/dist/src/lib/store/assetStore.d.ts +11 -0
  33. package/dist/src/lib/store/heightStore.d.ts +10 -0
  34. package/dist/src/lib/store/orderInProgressStore.d.ts +10 -0
  35. package/dist/src/lib/store/swapStore.d.ts +12 -2
  36. package/dist/src/lib/store/transactionHistoryStore.d.ts +2 -2
  37. package/dist/src/lib/store/widgetConfigStore.d.ts +8 -0
  38. package/dist/src/lib/types/types.d.ts +20 -2
  39. package/dist/src/lib/utils/balance/getBalanceMulticall.d.ts +5 -0
  40. package/dist/src/lib/utils/balance/getNativeTokenFee.d.ts +7 -0
  41. package/dist/src/lib/utils/balance/getNetworkFees.d.ts +5 -0
  42. package/dist/src/lib/utils/balance/getTokenBalance.d.ts +8 -0
  43. package/dist/src/lib/utils/balance/getmaxBtc.d.ts +3 -0
  44. package/dist/src/lib/utils/balance/rpcUtils.d.ts +17 -0
  45. package/dist/src/lib/utils/utils.d.ts +1 -0
  46. package/dist/style.css +1 -1
  47. package/package.json +31 -25
  48. package/src/index.ts +2 -0
  49. package/dist/index.cjs +0 -1
  50. package/dist/index.js +0 -5
  51. package/dist/index10.cjs +0 -1
  52. package/dist/index10.js +0 -33
  53. package/dist/index11.cjs +0 -1
  54. package/dist/index11.js +0 -36
  55. package/dist/index12.cjs +0 -1
  56. package/dist/index12.js +0 -65
  57. package/dist/index13.cjs +0 -1
  58. package/dist/index13.js +0 -33
  59. package/dist/index14.cjs +0 -1
  60. package/dist/index14.js +0 -190
  61. package/dist/index15.cjs +0 -1
  62. package/dist/index15.js +0 -51
  63. package/dist/index16.cjs +0 -1
  64. package/dist/index16.js +0 -313
  65. package/dist/index17.cjs +0 -1
  66. package/dist/index17.js +0 -29
  67. package/dist/index18.cjs +0 -1
  68. package/dist/index18.js +0 -17
  69. package/dist/index19.cjs +0 -1
  70. package/dist/index19.js +0 -229
  71. package/dist/index20.cjs +0 -1
  72. package/dist/index20.js +0 -15
  73. package/dist/index21.cjs +0 -1
  74. package/dist/index21.js +0 -92
  75. package/dist/index22.cjs +0 -1
  76. package/dist/index22.js +0 -143
  77. package/dist/index23.cjs +0 -1
  78. package/dist/index23.js +0 -22
  79. package/dist/index24.cjs +0 -1
  80. package/dist/index24.js +0 -20
  81. package/dist/index25.cjs +0 -1
  82. package/dist/index25.js +0 -108
  83. package/dist/index26.cjs +0 -1
  84. package/dist/index26.js +0 -85
  85. package/dist/index27.cjs +0 -1
  86. package/dist/index27.js +0 -15
  87. package/dist/index28.cjs +0 -1
  88. package/dist/index28.js +0 -54
  89. package/dist/index29.cjs +0 -1
  90. package/dist/index29.js +0 -63
  91. package/dist/index3.cjs +0 -1
  92. package/dist/index3.js +0 -7
  93. package/dist/index30.cjs +0 -1
  94. package/dist/index30.js +0 -44
  95. package/dist/index31.cjs +0 -1
  96. package/dist/index31.js +0 -43
  97. package/dist/index4.cjs +0 -1
  98. package/dist/index4.js +0 -26
  99. package/dist/index5.cjs +0 -1
  100. package/dist/index5.js +0 -250
  101. package/dist/index6.cjs +0 -1
  102. package/dist/index6.js +0 -98
  103. package/dist/index7.cjs +0 -1
  104. package/dist/index7.js +0 -51
  105. package/dist/index8.cjs +0 -1
  106. package/dist/index8.js +0 -51
  107. package/dist/index9.cjs +0 -1
  108. package/dist/index9.js +0 -101
  109. package/dist/src/lib/GardenComponent.d.ts +0 -6
  110. package/dist/src/lib/common/Navbar.d.ts +0 -10
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # @gardenfi/swap
2
2
 
3
- A lightweight, ready-to-use `<Garden />` component that wires up `GardenProvider` and exposes `useGarden` for consuming apps. Designed to drop into any React app and get all Garden features via the provider and hooks.
3
+ [**Demo**](https://jwcgcg0804ocowwoogs4o8cc.staging.btcfi.wtf/)
4
+
5
+ A drop-in cross-chain Swap Widget for React apps. It bundles `GardenProvider` and renders a full swap UI with quotes, order creation, and in-flight order handling.
4
6
 
5
7
  ## Install
6
8
 
@@ -8,58 +10,70 @@ A lightweight, ready-to-use `<Garden />` component that wires up `GardenProvider
8
10
  yarn add @gardenfi/swap
9
11
  ```
10
12
 
11
- ## Usage
13
+ ## Quick start
14
+
15
+ 1. Import the widget and its styles
16
+
17
+ ```tsx
18
+ import '@gardenfi/garden-book/style.css';
19
+ import '@gardenfi/swap/style.css';
20
+ import { GardenSwapWidget } from '@gardenfi/swap';
21
+ ```
22
+
23
+ 2. Render it with a minimal config
12
24
 
13
25
  ```tsx
14
26
  import React from 'react';
15
- import { Garden, useGarden } from '@gardenfi/swap';
27
+ import '@gardenfi/swap/style.css';
28
+ import '@gardenfi/garden-book/style.css';
29
+ import { GardenSwapWidget } from '@gardenfi/swap';
30
+ import { Network } from '@gardenfi/utils';
31
+ import { useWalletClient } from 'wagmi';
16
32
 
17
33
  export default function App() {
18
- const config = {
19
- environment: 'mainnet',
20
- // wallets or htlc configs here
21
- } as any;
22
-
34
+ const { data: walletClient } = useWalletClient();
23
35
  return (
24
- <Garden config={config}>
25
- <MySwapUI />
26
- </Garden>
36
+ <GardenSwapWidget
37
+ config={{
38
+ // Environment controls which Garden endpoints to use Network.MAINNET or Network.TESTNET
39
+ environment: Network.MAINNET,
40
+
41
+ // Required persistent store (used to track pending orders)
42
+ // Provide a Web Storage-like interface (localStorage works in browsers)
43
+ store: window.localStorage,
44
+
45
+ // Optional: enable/disable redeem/persistence service (defaults true)
46
+ setRedeemServiceEnabled: true,
47
+
48
+ // Optional: UI style overrides
49
+ styles: {
50
+ buttonColor: '#4F46E5',
51
+ },
52
+
53
+ // One of the following connection approaches is required:
54
+ // 1) Wallet-driven (preferred)
55
+ // wallets: { evm: <EvmWallet>, solana: <SolanaWallet>, ... }
56
+
57
+ // 2) HTLC actors pre-provisioned (advanced)
58
+ // htlc: { evm: {...}, solana: {...}, bitcoin: {...}, sui: {...}, starknet: {...} }
59
+ wallets: {
60
+ evm: walletClient,
61
+ },
62
+ }}
63
+ />
27
64
  );
28
65
  }
29
-
30
- function MySwapUI() {
31
- const { getQuote, swapAndInitiate, pendingOrders } = useGarden();
32
- // ...
33
- return null;
34
- }
35
- ```
36
-
37
- ## Scripts
38
-
39
- - `yarn build`
40
- - `yarn dev` (watch build)
41
- - `yarn link`
42
-
43
- ## Local linking
44
-
45
- From repo root:
46
-
47
- ```bash
48
- yarn link:all
49
66
  ```
50
67
 
51
- To unlink:
68
+ That’s it. The widget fetches assets, quotes, validates inputs, and creates orders.
52
69
 
53
- ```bash
54
- yarn unlink:all
55
- ```
56
-
57
- ## Publishing
58
-
59
- This package follows the root workspace publish scripts. Use:
70
+ ## Props
60
71
 
61
- ```bash
62
- yarn publish:affected
63
- # or for beta
64
- yarn publish:affected:beta
65
- ```
72
+ - `config` (required): Merges provider config with widget options
73
+ - `environment` (required): `Network.MAINNET | Network.TESTNET | { api?: { baseurl: string }, environment?: Network.MAINNET }`
74
+ - `store` (required): Persistent key–value store used by the provider (e.g., `window.localStorage`)
75
+ - `setRedeemServiceEnabled` (optional): `boolean` to enable in-flight order persistence and redeem service (default: `true`)
76
+ - `styles` (optional): `{ buttonColor?: string }` basic UI overrides
77
+ - Wallet or HTLC connectivity (one is required):
78
+ - `wallets` (preferred): Provide connected wallets. The provider will initialize `Garden` via `Garden.fromWallets(...)`.
79
+ - `htlc`: Provide HTLC actor configuration for chains you want to support. The provider will initialize `Garden` directly.
@@ -0,0 +1,184 @@
1
+ import { B as p, g as m, s as w, d as k, i as b, l as L, a as O, c as R, b as E, e as x, H as y, f as M, __tla as __tla_0 } from "./index-DiU4Bbp1.js";
2
+ let C, D, T, A;
3
+ let __tla = Promise.all([
4
+ (() => {
5
+ try {
6
+ return __tla_0;
7
+ } catch {
8
+ }
9
+ })()
10
+ ]).then(async () => {
11
+ class S extends p {
12
+ constructor({ callbackSelector: s, cause: e, data: o, extraData: n, sender: c, urls: t }) {
13
+ var _a;
14
+ super(e.shortMessage || "An error occurred while fetching for an offchain result.", {
15
+ cause: e,
16
+ metaMessages: [
17
+ ...e.metaMessages || [],
18
+ ((_a = e.metaMessages) == null ? void 0 : _a.length) ? "" : [],
19
+ "Offchain Gateway Call:",
20
+ t && [
21
+ " Gateway URL(s):",
22
+ ...t.map((i) => ` ${m(i)}`)
23
+ ],
24
+ ` Sender: ${c}`,
25
+ ` Data: ${o}`,
26
+ ` Callback selector: ${s}`,
27
+ ` Extra data: ${n}`
28
+ ].flat(),
29
+ name: "OffchainLookupError"
30
+ });
31
+ }
32
+ }
33
+ class $ extends p {
34
+ constructor({ result: s, url: e }) {
35
+ super("Offchain gateway response is malformed. Response data must be a hex value.", {
36
+ metaMessages: [
37
+ `Gateway URL: ${m(e)}`,
38
+ `Response: ${w(s)}`
39
+ ],
40
+ name: "OffchainLookupResponseMalformedError"
41
+ });
42
+ }
43
+ }
44
+ class q extends p {
45
+ constructor({ sender: s, to: e }) {
46
+ super("Reverted sender address does not match target contract address (`to`).", {
47
+ metaMessages: [
48
+ `Contract address: ${e}`,
49
+ `OffchainLookup sender address: ${s}`
50
+ ],
51
+ name: "OffchainLookupSenderMismatchError"
52
+ });
53
+ }
54
+ }
55
+ A = "0x556f1830";
56
+ T = {
57
+ name: "OffchainLookup",
58
+ type: "error",
59
+ inputs: [
60
+ {
61
+ name: "sender",
62
+ type: "address"
63
+ },
64
+ {
65
+ name: "urls",
66
+ type: "string[]"
67
+ },
68
+ {
69
+ name: "callData",
70
+ type: "bytes"
71
+ },
72
+ {
73
+ name: "callbackFunction",
74
+ type: "bytes4"
75
+ },
76
+ {
77
+ name: "extraData",
78
+ type: "bytes"
79
+ }
80
+ ]
81
+ };
82
+ D = async function(d, { blockNumber: s, blockTag: e, data: o, to: n }) {
83
+ const { args: c } = k({
84
+ data: o,
85
+ abi: [
86
+ T
87
+ ]
88
+ }), [t, i, l, a, r] = c, { ccipRead: f } = d, h = f && typeof (f == null ? void 0 : f.request) == "function" ? f.request : C;
89
+ try {
90
+ if (!b(n, t)) throw new q({
91
+ sender: t,
92
+ to: n
93
+ });
94
+ const u = i.includes(L) ? await O({
95
+ data: l,
96
+ ccipRequest: h
97
+ }) : await h({
98
+ data: l,
99
+ sender: t,
100
+ urls: i
101
+ }), { data: g } = await R(d, {
102
+ blockNumber: s,
103
+ blockTag: e,
104
+ data: E([
105
+ a,
106
+ x([
107
+ {
108
+ type: "bytes"
109
+ },
110
+ {
111
+ type: "bytes"
112
+ }
113
+ ], [
114
+ u,
115
+ r
116
+ ])
117
+ ]),
118
+ to: n
119
+ });
120
+ return g;
121
+ } catch (u) {
122
+ throw new S({
123
+ callbackSelector: a,
124
+ cause: u,
125
+ data: o,
126
+ extraData: r,
127
+ sender: t,
128
+ urls: i
129
+ });
130
+ }
131
+ };
132
+ C = async function({ data: d, sender: s, urls: e }) {
133
+ var _a;
134
+ let o = new Error("An unknown error occurred.");
135
+ for (let n = 0; n < e.length; n++) {
136
+ const c = e[n], t = c.includes("{data}") ? "GET" : "POST", i = t === "POST" ? {
137
+ data: d,
138
+ sender: s
139
+ } : void 0, l = t === "POST" ? {
140
+ "Content-Type": "application/json"
141
+ } : {};
142
+ try {
143
+ const a = await fetch(c.replace("{sender}", s.toLowerCase()).replace("{data}", d), {
144
+ body: JSON.stringify(i),
145
+ headers: l,
146
+ method: t
147
+ });
148
+ let r;
149
+ if (((_a = a.headers.get("Content-Type")) == null ? void 0 : _a.startsWith("application/json")) ? r = (await a.json()).data : r = await a.text(), !a.ok) {
150
+ o = new y({
151
+ body: i,
152
+ details: (r == null ? void 0 : r.error) ? w(r.error) : a.statusText,
153
+ headers: a.headers,
154
+ status: a.status,
155
+ url: c
156
+ });
157
+ continue;
158
+ }
159
+ if (!M(r)) {
160
+ o = new $({
161
+ result: r,
162
+ url: c
163
+ });
164
+ continue;
165
+ }
166
+ return r;
167
+ } catch (a) {
168
+ o = new y({
169
+ body: i,
170
+ details: a.message,
171
+ url: c
172
+ });
173
+ }
174
+ }
175
+ throw o;
176
+ };
177
+ });
178
+ export {
179
+ __tla,
180
+ C as ccipRequest,
181
+ D as offchainLookup,
182
+ T as offchainLookupAbiItem,
183
+ A as offchainLookupSignature
184
+ };