@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.
- package/README.md +58 -44
- package/dist/ccip-D21YSsYF.js +184 -0
- package/dist/index-DiU4Bbp1.js +146252 -0
- package/dist/index.es.js +14 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/lib/GardenSwapWidget.d.ts +4 -0
- package/dist/src/lib/common/BottomSheet.d.ts +7 -0
- package/dist/src/lib/common/ChainsToolTip.d.ts +1 -3
- package/dist/src/lib/common/CopyToClipboard.d.ts +7 -0
- package/dist/src/lib/common/GardenBranding.d.ts +1 -0
- package/dist/src/lib/common/Header.d.ts +3 -0
- package/dist/src/lib/common/Modal.d.ts +0 -2
- package/dist/src/lib/common/ModalComponent.d.ts +1 -3
- package/dist/src/lib/common/Sidebar.d.ts +9 -0
- package/dist/src/lib/common/SwapWidgetBase.d.ts +7 -0
- package/dist/src/lib/components/CreateSwap.d.ts +1 -4
- package/dist/src/lib/components/SwapSavingsAndAddresses.d.ts +1 -3
- package/dist/src/lib/components/SwapWidget.d.ts +5 -4
- package/dist/src/lib/components/TestSwapStore.d.ts +1 -0
- package/dist/src/lib/components/assetSelection/AvailableChainsSidebar.d.ts +1 -2
- package/dist/src/lib/components/feesAndRateDetails/FeeAndRateDetails.d.ts +1 -3
- package/dist/src/lib/components/feesAndRateDetails/InputAddress.d.ts +1 -3
- package/dist/src/lib/components/feesAndRateDetails/InputAddressAndFeeRateDetails.d.ts +1 -3
- package/dist/src/lib/components/swapInProgress/SwapInProgress.d.ts +1 -0
- package/dist/src/lib/components/swapInProgress/SwapInProgressSkeleton.d.ts +1 -0
- package/dist/src/lib/components/transactions/TransactionHistory.d.ts +2 -2
- package/dist/src/lib/components/transactions/Transactions.d.ts +1 -4
- package/dist/src/lib/constants/constants.d.ts +25 -0
- package/dist/src/lib/constants/wagmiConfig.d.ts +1404 -0
- package/dist/src/lib/hooks/useAddresses.d.ts +8 -0
- package/dist/src/lib/hooks/useSwap.d.ts +1 -0
- package/dist/src/lib/store/assetStore.d.ts +11 -0
- package/dist/src/lib/store/heightStore.d.ts +10 -0
- package/dist/src/lib/store/orderInProgressStore.d.ts +10 -0
- package/dist/src/lib/store/swapStore.d.ts +12 -2
- package/dist/src/lib/store/transactionHistoryStore.d.ts +2 -2
- package/dist/src/lib/store/widgetConfigStore.d.ts +8 -0
- package/dist/src/lib/types/types.d.ts +20 -2
- package/dist/src/lib/utils/balance/getBalanceMulticall.d.ts +5 -0
- package/dist/src/lib/utils/balance/getNativeTokenFee.d.ts +7 -0
- package/dist/src/lib/utils/balance/getNetworkFees.d.ts +5 -0
- package/dist/src/lib/utils/balance/getTokenBalance.d.ts +8 -0
- package/dist/src/lib/utils/balance/getmaxBtc.d.ts +3 -0
- package/dist/src/lib/utils/balance/rpcUtils.d.ts +17 -0
- package/dist/src/lib/utils/utils.d.ts +1 -0
- package/dist/style.css +1 -1
- package/package.json +31 -25
- package/src/index.ts +2 -0
- package/dist/index.cjs +0 -1
- package/dist/index.js +0 -5
- package/dist/index10.cjs +0 -1
- package/dist/index10.js +0 -33
- package/dist/index11.cjs +0 -1
- package/dist/index11.js +0 -36
- package/dist/index12.cjs +0 -1
- package/dist/index12.js +0 -65
- package/dist/index13.cjs +0 -1
- package/dist/index13.js +0 -33
- package/dist/index14.cjs +0 -1
- package/dist/index14.js +0 -190
- package/dist/index15.cjs +0 -1
- package/dist/index15.js +0 -51
- package/dist/index16.cjs +0 -1
- package/dist/index16.js +0 -313
- package/dist/index17.cjs +0 -1
- package/dist/index17.js +0 -29
- package/dist/index18.cjs +0 -1
- package/dist/index18.js +0 -17
- package/dist/index19.cjs +0 -1
- package/dist/index19.js +0 -229
- package/dist/index20.cjs +0 -1
- package/dist/index20.js +0 -15
- package/dist/index21.cjs +0 -1
- package/dist/index21.js +0 -92
- package/dist/index22.cjs +0 -1
- package/dist/index22.js +0 -143
- package/dist/index23.cjs +0 -1
- package/dist/index23.js +0 -22
- package/dist/index24.cjs +0 -1
- package/dist/index24.js +0 -20
- package/dist/index25.cjs +0 -1
- package/dist/index25.js +0 -108
- package/dist/index26.cjs +0 -1
- package/dist/index26.js +0 -85
- package/dist/index27.cjs +0 -1
- package/dist/index27.js +0 -15
- package/dist/index28.cjs +0 -1
- package/dist/index28.js +0 -54
- package/dist/index29.cjs +0 -1
- package/dist/index29.js +0 -63
- package/dist/index3.cjs +0 -1
- package/dist/index3.js +0 -7
- package/dist/index30.cjs +0 -1
- package/dist/index30.js +0 -44
- package/dist/index31.cjs +0 -1
- package/dist/index31.js +0 -43
- package/dist/index4.cjs +0 -1
- package/dist/index4.js +0 -26
- package/dist/index5.cjs +0 -1
- package/dist/index5.js +0 -250
- package/dist/index6.cjs +0 -1
- package/dist/index6.js +0 -98
- package/dist/index7.cjs +0 -1
- package/dist/index7.js +0 -51
- package/dist/index8.cjs +0 -1
- package/dist/index8.js +0 -51
- package/dist/index9.cjs +0 -1
- package/dist/index9.js +0 -101
- package/dist/src/lib/GardenComponent.d.ts +0 -6
- 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
|
-
|
|
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
|
-
##
|
|
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
|
|
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
|
|
19
|
-
environment: 'mainnet',
|
|
20
|
-
// wallets or htlc configs here
|
|
21
|
-
} as any;
|
|
22
|
-
|
|
34
|
+
const { data: walletClient } = useWalletClient();
|
|
23
35
|
return (
|
|
24
|
-
<
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
68
|
+
That’s it. The widget fetches assets, quotes, validates inputs, and creates orders.
|
|
52
69
|
|
|
53
|
-
|
|
54
|
-
yarn unlink:all
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
## Publishing
|
|
58
|
-
|
|
59
|
-
This package follows the root workspace publish scripts. Use:
|
|
70
|
+
## Props
|
|
60
71
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
+
};
|