btc-wallet 0.2.5 → 0.2.6
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/dist/components/btcWalletSelectorContext.d.ts +4 -1
- package/dist/config.d.ts +14 -0
- package/dist/evmSigner/index.d.ts +2737 -817
- package/dist/index.d.ts +1 -0
- package/dist/index.js +276 -60
- package/dist/index.js.map +4 -4
- package/dist/utils/bridgeSupplyUtils.d.ts +1 -0
- package/dist/utils/request.d.ts +11 -0
- package/esm/index.js +276 -60
- package/esm/index.js.map +4 -4
- package/package.json +9 -7
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -90,6 +90,7 @@ __export(src_exports, {
|
|
90
90
|
UnisatConnector: () => UnisatConnector,
|
91
91
|
WizzConnector: () => WizzConnector,
|
92
92
|
XverseConnector: () => XverseConnector,
|
93
|
+
executeBurrowSupply: () => executeBurrowSupply,
|
93
94
|
getVersion: () => getVersion,
|
94
95
|
setupBTCWallet: () => setupBTCWallet,
|
95
96
|
useAccountContract: () => useAccountContract,
|
@@ -134,6 +135,7 @@ var InjectedConnector = class extends BaseConnector {
|
|
134
135
|
requestAccounts() {
|
135
136
|
return __async(this, null, function* () {
|
136
137
|
const accounts = yield this.getProviderOrThrow().requestAccounts();
|
138
|
+
console.log("\u{1F680} ~ InjectedConnector ~ requestAccounts ~ accounts:", accounts);
|
137
139
|
return accounts;
|
138
140
|
});
|
139
141
|
}
|
@@ -534,7 +536,7 @@ var useAccounts = () => {
|
|
534
536
|
// src/hooks/useBTCProvider.ts
|
535
537
|
var import_react = require("react");
|
536
538
|
var useBTCProvider = () => {
|
537
|
-
const { connector, provider, accounts, getPublicKey, signMessage, getNetwork, switchNetwork, sendBitcoin } = useConnectProvider();
|
539
|
+
const { connector, provider, accounts, getPublicKey, signMessage, getNetwork, switchNetwork, sendBitcoin: sendBitcoin2 } = useConnectProvider();
|
538
540
|
const sendInscription = (0, import_react.useCallback)(
|
539
541
|
(address, inscriptionId, options) => __async(void 0, null, function* () {
|
540
542
|
if (!connector) {
|
@@ -545,7 +547,7 @@ var useBTCProvider = () => {
|
|
545
547
|
}),
|
546
548
|
[connector]
|
547
549
|
);
|
548
|
-
return { provider, accounts, getPublicKey, signMessage, getNetwork, switchNetwork, sendBitcoin, sendInscription, connector };
|
550
|
+
return { provider, accounts, getPublicKey, signMessage, getNetwork, switchNetwork, sendBitcoin: sendBitcoin2, sendInscription, connector };
|
549
551
|
};
|
550
552
|
|
551
553
|
// src/hooks/useConnectModal.ts
|
@@ -699,6 +701,7 @@ var WalletClientProvider = class {
|
|
699
701
|
}
|
700
702
|
}
|
701
703
|
if (method === "personal_sign" /* personalSign */) {
|
704
|
+
console.log("personal_sign ---- ", arg);
|
702
705
|
return new Promise((resolve, reject) => {
|
703
706
|
eventUtils_default.emit("personalSign" /* personalSign */, arg);
|
704
707
|
eventUtils_default.once("personalSignResult" /* personalSignResult */, ({ result, error }) => {
|
@@ -1004,6 +1007,7 @@ var ConnectModal = ({ open, onClose }) => {
|
|
1004
1007
|
yield connect(connector.metadata.id);
|
1005
1008
|
closeConnectModal();
|
1006
1009
|
} catch (error) {
|
1010
|
+
console.error("onConnect error", error);
|
1007
1011
|
if (error.code === 4001) {
|
1008
1012
|
setRetryVisible(true);
|
1009
1013
|
}
|
@@ -1546,10 +1550,13 @@ var SignModal = ({ open, onClose, onOpen }) => {
|
|
1546
1550
|
}), [userOpBundle, smartAccount, accountContract]);
|
1547
1551
|
(0, import_react8.useEffect)(() => {
|
1548
1552
|
if (userOpBundle && open) {
|
1553
|
+
console.log("deserializeUserOp start");
|
1549
1554
|
setDeserializeLoading(true);
|
1550
1555
|
deserializeUserOp().then((result) => {
|
1556
|
+
console.log("\u{1F680} ~ deserializeUserOp ~ result:", result);
|
1551
1557
|
setDeserializeResult(result);
|
1552
1558
|
}).catch((error) => {
|
1559
|
+
console.log("\u{1F680} ~ deserializeUserOp ~ error:", error);
|
1553
1560
|
eventUtils_default.emit("sendUserOpResult" /* sendUserOpResult */, {
|
1554
1561
|
error
|
1555
1562
|
});
|
@@ -1560,6 +1567,7 @@ var SignModal = ({ open, onClose, onOpen }) => {
|
|
1560
1567
|
(0, import_react8.useEffect)(() => {
|
1561
1568
|
if (open && publicClient && evmAccount && userOpBundle) {
|
1562
1569
|
publicClient.getBalance({ address: evmAccount }).then((result) => setNativeBalance(result)).catch((error) => {
|
1570
|
+
console.log("\u{1F680} ~ getBalance ~ error:", error);
|
1563
1571
|
eventUtils_default.emit("sendUserOpResult" /* sendUserOpResult */, {
|
1564
1572
|
error
|
1565
1573
|
});
|
@@ -1724,6 +1732,7 @@ var AASignerProvider = class {
|
|
1724
1732
|
this.getPublicClient = () => {
|
1725
1733
|
var _a, _b;
|
1726
1734
|
const rpcUrl = ((_a = this == null ? void 0 : this.rpcUrls) == null ? void 0 : _a[this.chainId]) || ((_b = import_chains3.chains.getEVMChainInfoById(this.chainId || 1)) == null ? void 0 : _b.rpcUrl);
|
1735
|
+
console.log("rpcUrl", rpcUrl);
|
1727
1736
|
return (0, import_viem4.createPublicClient)({
|
1728
1737
|
transport: (0, import_viem4.http)(rpcUrl)
|
1729
1738
|
});
|
@@ -1758,8 +1767,10 @@ var AASignerProvider = class {
|
|
1758
1767
|
return `0x${this.chainId.toString(16)}`;
|
1759
1768
|
} else if (arg.method === "personal_sign" /* personalSign */) {
|
1760
1769
|
let message = (_a = arg.params) == null ? void 0 : _a[0];
|
1770
|
+
console.log("personal_sign message:", message);
|
1761
1771
|
if (message.length !== 66) {
|
1762
1772
|
const hash = (0, import_viem4.hashMessage)({ raw: message });
|
1773
|
+
console.log("personal_sign hash:", hash);
|
1763
1774
|
message = hash;
|
1764
1775
|
}
|
1765
1776
|
const result = yield this.personalSign(message || "");
|
@@ -1767,15 +1778,19 @@ var AASignerProvider = class {
|
|
1767
1778
|
if (!convertResult) {
|
1768
1779
|
throw new Error("sign error");
|
1769
1780
|
}
|
1781
|
+
console.log(`personal_sign result(${convertResult.length}): `, convertResult);
|
1770
1782
|
return convertResult;
|
1771
1783
|
} else if (arg.method === "eth_signTypedData" || arg.method === "eth_signTypedData_v4") {
|
1772
1784
|
const typedData = (_b = arg.params) == null ? void 0 : _b[1];
|
1785
|
+
console.log("signTypedData typedData", typedData);
|
1773
1786
|
const hash = (0, import_viem4.hashTypedData)(typeof typedData === "string" ? JSON.parse(typedData) : typedData);
|
1787
|
+
console.log("signTypedData hash", hash);
|
1774
1788
|
const result = yield this.personalSign(hash || "");
|
1775
1789
|
const convertResult = convertSignature(result);
|
1776
1790
|
if (!convertResult) {
|
1777
1791
|
throw new Error("sign error");
|
1778
1792
|
}
|
1793
|
+
console.log(`eth_signTypedData result(${convertResult.length}): `, convertResult);
|
1779
1794
|
return convertResult;
|
1780
1795
|
} else if (arg.method === "wallet_switchEthereumChain") {
|
1781
1796
|
if (arg.params && arg.params instanceof Array && arg.params[0] && arg.params[0].chainId) {
|
@@ -1855,12 +1870,12 @@ var ConnectProvider = ({
|
|
1855
1870
|
version: ((_c = options.aaOptions.accountContracts[((_b = Object.keys(options.aaOptions.accountContracts)) == null ? void 0 : _b[0]) || "BTC"]) == null ? void 0 : _c[0].version) || "1.0.0"
|
1856
1871
|
});
|
1857
1872
|
const setAccountContract = (0, import_react10.useCallback)(
|
1858
|
-
(
|
1859
|
-
if (!checkBTCVersion(options.aaOptions.accountContracts,
|
1873
|
+
(config) => {
|
1874
|
+
if (!checkBTCVersion(options.aaOptions.accountContracts, config.name, config.version)) {
|
1860
1875
|
throw new Error("Invalid Account Contract");
|
1861
1876
|
}
|
1862
|
-
localStorage.setItem(SAContractKey, JSON.stringify(
|
1863
|
-
_setAccountContract(
|
1877
|
+
localStorage.setItem(SAContractKey, JSON.stringify(config));
|
1878
|
+
_setAccountContract(config);
|
1864
1879
|
},
|
1865
1880
|
[options.aaOptions.accountContracts, _setAccountContract]
|
1866
1881
|
);
|
@@ -1899,7 +1914,7 @@ var ConnectProvider = ({
|
|
1899
1914
|
}),
|
1900
1915
|
[connector]
|
1901
1916
|
);
|
1902
|
-
const
|
1917
|
+
const sendBitcoin2 = (0, import_react10.useCallback)(
|
1903
1918
|
(toAddress, satoshis, options2) => __async(void 0, null, function* () {
|
1904
1919
|
if (!connector) {
|
1905
1920
|
throw new Error("Wallet not connected!");
|
@@ -1947,6 +1962,7 @@ var ConnectProvider = ({
|
|
1947
1962
|
setEVMAccount(res);
|
1948
1963
|
}).catch((e) => {
|
1949
1964
|
setEVMAccount(void 0);
|
1965
|
+
console.error("smartAccount getAddress error", e);
|
1950
1966
|
});
|
1951
1967
|
} else {
|
1952
1968
|
setEVMAccount(void 0);
|
@@ -1968,6 +1984,7 @@ var ConnectProvider = ({
|
|
1968
1984
|
const requestAccount = (0, import_react10.useCallback)(
|
1969
1985
|
(connector2) => __async(void 0, null, function* () {
|
1970
1986
|
let accounts2 = yield connector2.getAccounts();
|
1987
|
+
console.log("requestAccount start, autoConnect", accounts2, autoConnect);
|
1971
1988
|
if (accounts2.length === 0 && autoConnect) {
|
1972
1989
|
accounts2 = yield connector2.requestAccounts();
|
1973
1990
|
}
|
@@ -1977,7 +1994,9 @@ var ConnectProvider = ({
|
|
1977
1994
|
);
|
1978
1995
|
const requestDirectAccount = (0, import_react10.useCallback)(
|
1979
1996
|
(connector2) => __async(void 0, null, function* () {
|
1997
|
+
console.log(111);
|
1980
1998
|
let accounts2 = yield connector2.getAccounts();
|
1999
|
+
console.log("requestAccount start, autoConnect", accounts2, autoConnect);
|
1981
2000
|
if (accounts2.length === 0) {
|
1982
2001
|
accounts2 = yield connector2.requestAccounts();
|
1983
2002
|
}
|
@@ -1989,6 +2008,7 @@ var ConnectProvider = ({
|
|
1989
2008
|
(0, import_react10.useEffect)(() => {
|
1990
2009
|
if (connector) {
|
1991
2010
|
requestAccount(connector).catch((e) => {
|
2011
|
+
console.log("get account error", e);
|
1992
2012
|
setAccounts([]);
|
1993
2013
|
});
|
1994
2014
|
} else {
|
@@ -2019,9 +2039,9 @@ var ConnectProvider = ({
|
|
2019
2039
|
setConnectorId(void 0);
|
2020
2040
|
}, [connector]);
|
2021
2041
|
(0, import_react10.useEffect)(() => {
|
2022
|
-
const
|
2023
|
-
if (
|
2024
|
-
_setAccountContract(
|
2042
|
+
const config = JSON.parse(localStorage.getItem(SAContractKey) || "{}");
|
2043
|
+
if (config.name && config.version && checkBTCVersion(options.aaOptions.accountContracts, config.name, config.version)) {
|
2044
|
+
_setAccountContract(config);
|
2025
2045
|
}
|
2026
2046
|
}, [options.aaOptions.accountContracts, _setAccountContract]);
|
2027
2047
|
(0, import_react10.useEffect)(() => {
|
@@ -2044,6 +2064,7 @@ var ConnectProvider = ({
|
|
2044
2064
|
})
|
2045
2065
|
})
|
2046
2066
|
);
|
2067
|
+
console.log("walletEntryPlugin init");
|
2047
2068
|
}
|
2048
2069
|
}, [options, evmSupportChainIds, accountContract]);
|
2049
2070
|
(0, import_react10.useEffect)(() => {
|
@@ -2052,6 +2073,7 @@ var ConnectProvider = ({
|
|
2052
2073
|
import_wallet.walletEntryPlugin.setWalletCore({
|
2053
2074
|
ethereum: smartAccount.provider
|
2054
2075
|
});
|
2076
|
+
console.log("walletEntryPlugin setWalletCore");
|
2055
2077
|
}
|
2056
2078
|
}, [smartAccount, options]);
|
2057
2079
|
(0, import_react10.useEffect)(() => {
|
@@ -2059,8 +2081,10 @@ var ConnectProvider = ({
|
|
2059
2081
|
if (((_a2 = options.walletOptions) == null ? void 0 : _a2.visible) !== false) {
|
2060
2082
|
if (evmAccount) {
|
2061
2083
|
import_wallet.walletEntryPlugin.walletEntryCreate();
|
2084
|
+
console.log("walletEntryPlugin walletEntryCreate");
|
2062
2085
|
} else {
|
2063
2086
|
import_wallet.walletEntryPlugin.walletEntryDestroy();
|
2087
|
+
console.log("walletEntryPlugin walletEntryDestroy");
|
2064
2088
|
}
|
2065
2089
|
}
|
2066
2090
|
}, [evmAccount, smartAccount, options]);
|
@@ -2112,7 +2136,7 @@ var ConnectProvider = ({
|
|
2112
2136
|
smartAccount,
|
2113
2137
|
getNetwork,
|
2114
2138
|
switchNetwork,
|
2115
|
-
sendBitcoin,
|
2139
|
+
sendBitcoin: sendBitcoin2,
|
2116
2140
|
accountContract,
|
2117
2141
|
setAccountContract,
|
2118
2142
|
getSmartAccountInfo
|
@@ -2198,7 +2222,10 @@ function InitContextHook() {
|
|
2198
2222
|
// src/components/btcWalletSelectorContext.tsx
|
2199
2223
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
2200
2224
|
var WalletSelectorContext = import_react12.default.createContext(null);
|
2201
|
-
function BtcWalletSelectorContextProvider({
|
2225
|
+
function BtcWalletSelectorContextProvider({
|
2226
|
+
children,
|
2227
|
+
autoConnect = false
|
2228
|
+
}) {
|
2202
2229
|
const [isProcessing, setIsProcessing] = (0, import_react12.useState)(false);
|
2203
2230
|
const walletSelectorContextValue = (0, import_react12.useMemo)(() => {
|
2204
2231
|
const simpleFn = {};
|
@@ -2242,9 +2269,16 @@ function BtcWalletSelectorContextProvider({ children, autoConnect = false }) {
|
|
2242
2269
|
connectors: [new UnisatConnector()],
|
2243
2270
|
children: [
|
2244
2271
|
children,
|
2245
|
-
isProcessing && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
2246
|
-
|
2247
|
-
|
2272
|
+
isProcessing && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
2273
|
+
ComfirmBox,
|
2274
|
+
{
|
2275
|
+
hash: "",
|
2276
|
+
status: 0,
|
2277
|
+
onClose: () => {
|
2278
|
+
setIsProcessing(false);
|
2279
|
+
}
|
2280
|
+
}
|
2281
|
+
),
|
2248
2282
|
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(InitContextHook, {})
|
2249
2283
|
]
|
2250
2284
|
}
|
@@ -2252,7 +2286,7 @@ function BtcWalletSelectorContextProvider({ children, autoConnect = false }) {
|
|
2252
2286
|
}
|
2253
2287
|
function useBtcWalletSelector() {
|
2254
2288
|
const { openConnectModal, openConnectModalAsync, disconnect, requestDirectAccount } = useConnectModal();
|
2255
|
-
const { accounts, sendBitcoin, getPublicKey, provider, signMessage, connector } = useBTCProvider();
|
2289
|
+
const { accounts, sendBitcoin: sendBitcoin2, getPublicKey, provider, signMessage, connector } = useBTCProvider();
|
2256
2290
|
const publicKey = (0, import_react12.useRef)(null);
|
2257
2291
|
const signMessageFn = (0, import_react12.useRef)(null);
|
2258
2292
|
const connectorRef = (0, import_react12.useRef)(null);
|
@@ -2344,7 +2378,8 @@ function useBtcWalletSelector() {
|
|
2344
2378
|
}
|
2345
2379
|
const { total } = yield providerRef.current.getBalance();
|
2346
2380
|
return total;
|
2347
|
-
})
|
2381
|
+
}),
|
2382
|
+
sendBitcoin: sendBitcoin2
|
2348
2383
|
};
|
2349
2384
|
}
|
2350
2385
|
function sleep(time) {
|
@@ -2369,6 +2404,7 @@ var walletUrlConfig = {
|
|
2369
2404
|
mainnet: "https://wallet.satoshibridge.top"
|
2370
2405
|
};
|
2371
2406
|
function setupWalletButton(network, wallet, originalWallet) {
|
2407
|
+
console.log("setupWalletButton");
|
2372
2408
|
if (document.getElementById("satoshi-wallet-button")) {
|
2373
2409
|
return;
|
2374
2410
|
}
|
@@ -2456,20 +2492,24 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2456
2492
|
const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
|
2457
2493
|
const originalAccountId = originalWallet.account;
|
2458
2494
|
const originalPublicKey = yield originalWallet.getPublicKey();
|
2495
|
+
console.log({ accountId, originalAccountId, originalPublicKey });
|
2459
2496
|
const iframeSrc = new URL(iframe.src);
|
2460
2497
|
iframeSrc.searchParams.set("origin", window.location.origin);
|
2461
2498
|
accountId && iframeSrc.searchParams.set("accountId", accountId);
|
2462
2499
|
originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
|
2463
2500
|
originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
|
2464
2501
|
iframe.src = iframeSrc.toString();
|
2502
|
+
console.log("iframe src", iframe.src);
|
2465
2503
|
window.addEventListener("message", (event) => __async(this, null, function* () {
|
2466
2504
|
var _a2, _b;
|
2467
2505
|
if (event.origin !== iframeSrc.origin)
|
2468
2506
|
return;
|
2469
2507
|
const { action, requestId, data } = event.data;
|
2470
2508
|
if (action === "signAndSendTransaction") {
|
2509
|
+
console.log("signAndSendTransaction message", event.data);
|
2471
2510
|
try {
|
2472
2511
|
const result = yield wallet.signAndSendTransaction(data);
|
2512
|
+
console.log("signAndSendTransaction result", result);
|
2473
2513
|
(_a2 = event.source) == null ? void 0 : _a2.postMessage(
|
2474
2514
|
{
|
2475
2515
|
requestId,
|
@@ -2479,6 +2519,7 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2479
2519
|
{ targetOrigin: event.origin }
|
2480
2520
|
);
|
2481
2521
|
} catch (error) {
|
2522
|
+
console.error("signAndSendTransaction error", error);
|
2482
2523
|
(_b = event.source) == null ? void 0 : _b.postMessage(
|
2483
2524
|
{
|
2484
2525
|
requestId,
|
@@ -2499,25 +2540,117 @@ function removeWalletButton() {
|
|
2499
2540
|
iframe == null ? void 0 : iframe.remove();
|
2500
2541
|
}
|
2501
2542
|
|
2502
|
-
// src/
|
2503
|
-
var
|
2504
|
-
var config = {
|
2543
|
+
// src/config.ts
|
2544
|
+
var walletConfig = {
|
2505
2545
|
dev: {
|
2506
|
-
base_url: "https://api.dev.satoshibridge.top
|
2546
|
+
base_url: "https://api.dev.satoshibridge.top",
|
2507
2547
|
token: "nbtc1-nsp.testnet",
|
2508
|
-
contractId: "dev1-nsp.testnet"
|
2548
|
+
contractId: "dev1-nsp.testnet",
|
2549
|
+
walletUrl: "https://wallet-dev.satoshibridge.top"
|
2509
2550
|
},
|
2510
2551
|
testnet: {
|
2511
|
-
base_url: "https://api.testnet.satoshibridge.top
|
2552
|
+
base_url: "https://api.testnet.satoshibridge.top",
|
2512
2553
|
token: "nbtc2-nsp.testnet",
|
2513
|
-
contractId: "dev2-nsp.testnet"
|
2554
|
+
contractId: "dev2-nsp.testnet",
|
2555
|
+
walletUrl: "https://wallet-test.satoshibridge.top"
|
2514
2556
|
},
|
2515
2557
|
mainnet: {
|
2516
|
-
base_url: "https://api.mainnet.satoshibridge.top
|
2558
|
+
base_url: "https://api.mainnet.satoshibridge.top",
|
2517
2559
|
token: "",
|
2518
|
-
contractId: ""
|
2560
|
+
contractId: "",
|
2561
|
+
walletUrl: "https://wallet.satoshibridge.top"
|
2519
2562
|
}
|
2520
2563
|
};
|
2564
|
+
var nearRpcUrls = {
|
2565
|
+
mainnet: [
|
2566
|
+
"https://near.lava.build",
|
2567
|
+
"https://rpc.mainnet.near.org",
|
2568
|
+
"https://free.rpc.fastnear.com",
|
2569
|
+
"https://near.drpc.org"
|
2570
|
+
],
|
2571
|
+
testnet: [
|
2572
|
+
"https://near-testnet.lava.build",
|
2573
|
+
"https://rpc.testnet.near.org",
|
2574
|
+
"https://near-testnet.drpc.org"
|
2575
|
+
]
|
2576
|
+
};
|
2577
|
+
var btcRpcUrls = {
|
2578
|
+
mainnet: "https://blockstream.info/api",
|
2579
|
+
testnet: "https://blockstream.info/testnet/api"
|
2580
|
+
};
|
2581
|
+
|
2582
|
+
// src/utils/request.ts
|
2583
|
+
var cache = /* @__PURE__ */ new Map();
|
2584
|
+
var defaultCacheTimeout = 3e3;
|
2585
|
+
function request(url, options) {
|
2586
|
+
return __async(this, null, function* () {
|
2587
|
+
var _a;
|
2588
|
+
const defaultHeaders = {
|
2589
|
+
"Content-Type": "application/json"
|
2590
|
+
};
|
2591
|
+
const cacheTimeout = (options == null ? void 0 : options.cacheTimeout) || defaultCacheTimeout;
|
2592
|
+
const headers = __spreadValues(__spreadValues({}, defaultHeaders), options == null ? void 0 : options.headers);
|
2593
|
+
let body = options == null ? void 0 : options.body;
|
2594
|
+
if (headers["Content-Type"] === "application/json" && body && typeof body !== "string") {
|
2595
|
+
body = JSON.stringify(body);
|
2596
|
+
}
|
2597
|
+
const method = (options == null ? void 0 : options.method) || "GET";
|
2598
|
+
const cacheKey = method.toUpperCase() === "GET" ? url : null;
|
2599
|
+
if (cacheKey) {
|
2600
|
+
const cached = cache.get(cacheKey);
|
2601
|
+
const isCacheValid = cached && Date.now() - cached.timestamp < cacheTimeout;
|
2602
|
+
if (isCacheValid) {
|
2603
|
+
return Promise.resolve(cached.data);
|
2604
|
+
}
|
2605
|
+
}
|
2606
|
+
const newOptions = __spreadProps(__spreadValues({}, options), {
|
2607
|
+
headers,
|
2608
|
+
body,
|
2609
|
+
method
|
2610
|
+
});
|
2611
|
+
const retryCount = (_a = options == null ? void 0 : options.retryCount) != null ? _a : 1;
|
2612
|
+
const controller = new AbortController();
|
2613
|
+
const timeout = (options == null ? void 0 : options.timeout) || 2e4;
|
2614
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
2615
|
+
try {
|
2616
|
+
const res = yield fetch(url, __spreadProps(__spreadValues({}, newOptions), { signal: controller.signal })).finally(
|
2617
|
+
() => clearTimeout(timeoutId)
|
2618
|
+
);
|
2619
|
+
if (!res.ok)
|
2620
|
+
throw new Error(res.statusText);
|
2621
|
+
const data = yield res.json();
|
2622
|
+
if (cacheKey) {
|
2623
|
+
cache.set(cacheKey, { timestamp: Date.now(), data });
|
2624
|
+
setTimeout(() => {
|
2625
|
+
cache.delete(cacheKey);
|
2626
|
+
}, cacheTimeout);
|
2627
|
+
}
|
2628
|
+
if ((options == null ? void 0 : options.shouldStopPolling) && options.shouldStopPolling(data)) {
|
2629
|
+
return data;
|
2630
|
+
}
|
2631
|
+
return data;
|
2632
|
+
} catch (err) {
|
2633
|
+
console.error(err);
|
2634
|
+
if (retryCount > 0) {
|
2635
|
+
console.log(`Retrying... attempts left: ${retryCount}`);
|
2636
|
+
return request(url, __spreadProps(__spreadValues({}, options), { retryCount: retryCount - 1 }));
|
2637
|
+
} else if ((options == null ? void 0 : options.pollingInterval) && (options == null ? void 0 : options.maxPollingAttempts)) {
|
2638
|
+
if (options.maxPollingAttempts > 0) {
|
2639
|
+
console.log(`Polling... attempts left: ${options.maxPollingAttempts}`);
|
2640
|
+
yield new Promise((resolve) => setTimeout(resolve, options.pollingInterval));
|
2641
|
+
return request(url, __spreadProps(__spreadValues({}, options), {
|
2642
|
+
maxPollingAttempts: options.maxPollingAttempts - 1,
|
2643
|
+
retryCount
|
2644
|
+
}));
|
2645
|
+
}
|
2646
|
+
}
|
2647
|
+
return Promise.reject(err);
|
2648
|
+
}
|
2649
|
+
});
|
2650
|
+
}
|
2651
|
+
|
2652
|
+
// src/utils/setupBTCWallet.ts
|
2653
|
+
var { transfer, functionCall } = import_transactions.actionCreators;
|
2521
2654
|
var state = {
|
2522
2655
|
saveAccount(account) {
|
2523
2656
|
window.localStorage.setItem("btc-wallet-account", account);
|
@@ -2575,12 +2708,13 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2575
2708
|
signAndSendTransaction,
|
2576
2709
|
signAndSendTransactions
|
2577
2710
|
};
|
2578
|
-
const currentConfig = "isDev" in metadata && metadata.isDev ?
|
2711
|
+
const currentConfig = "isDev" in metadata && metadata.isDev ? walletConfig.dev : walletConfig[options.network.networkId];
|
2579
2712
|
const walletNetwork = "isDev" in metadata && metadata.isDev ? "dev" : options.network.networkId;
|
2580
2713
|
initWalletButton(walletNetwork, wallet);
|
2581
2714
|
if (!inter) {
|
2582
2715
|
inter = setInterval(() => __async(void 0, null, function* () {
|
2583
2716
|
const btcContext = window.btcContext;
|
2717
|
+
console.log("inter btcContext:", btcContext);
|
2584
2718
|
if (btcContext) {
|
2585
2719
|
clearInterval(inter);
|
2586
2720
|
const context = btcContext.getContext();
|
@@ -2602,10 +2736,12 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2602
2736
|
});
|
2603
2737
|
}));
|
2604
2738
|
context.on("btcLogOut", (e) => __async(void 0, null, function* () {
|
2739
|
+
console.log(3333);
|
2605
2740
|
emitter.emit("accountsChanged", {
|
2606
2741
|
accounts: []
|
2607
2742
|
});
|
2608
2743
|
}));
|
2744
|
+
console.log("metadata.autoConnect:", metadata);
|
2609
2745
|
if ("autoConnect" in metadata && metadata.autoConnect && localStorage.getItem("near-wallet-selector:selectedWalletId") === '"btc-wallet"') {
|
2610
2746
|
yield btcContext.autoConnect();
|
2611
2747
|
}
|
@@ -2754,6 +2890,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2754
2890
|
txBytes,
|
2755
2891
|
(byte) => ("0" + (byte & 255).toString(16)).slice(-2)
|
2756
2892
|
).join("");
|
2893
|
+
console.log("txHex:", txHex);
|
2757
2894
|
const hash = import_bs58.default.encode(new Uint8Array(import_js_sha256.sha256.array(txBytes)));
|
2758
2895
|
return { txBytes, txHex, hash };
|
2759
2896
|
});
|
@@ -2788,8 +2925,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2788
2925
|
btcPubKey: state.getBtcPublicKey(),
|
2789
2926
|
data: toHex(strIntention)
|
2790
2927
|
});
|
2928
|
+
console.log("result:", result);
|
2791
2929
|
if (result.result_code === 0) {
|
2792
2930
|
const hash = newTransactions.map((t) => t.hash);
|
2931
|
+
console.log("txHash:", hash);
|
2793
2932
|
const result2 = yield pollTransactionStatuses(options.network.networkId, hash);
|
2794
2933
|
return result2;
|
2795
2934
|
} else {
|
@@ -2802,6 +2941,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2802
2941
|
const checkAndSetupWalletButton = () => {
|
2803
2942
|
const accountId = state.getAccount();
|
2804
2943
|
const btcContext = window.btcContext;
|
2944
|
+
console.log("checkAndSetupWalletButton:", accountId, btcContext.account);
|
2805
2945
|
if (accountId && btcContext.account) {
|
2806
2946
|
setupWalletButton(network, wallet2, btcContext);
|
2807
2947
|
} else {
|
@@ -2818,29 +2958,16 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2818
2958
|
return wallet;
|
2819
2959
|
});
|
2820
2960
|
function getNonceFromApi(url, accountId) {
|
2821
|
-
return
|
2822
|
-
method: "GET",
|
2823
|
-
headers: {
|
2824
|
-
"Content-Type": "application/json"
|
2825
|
-
}
|
2826
|
-
}).then((res) => res.json());
|
2961
|
+
return request(`${url}/v1/nonce?csna=${accountId}`);
|
2827
2962
|
}
|
2828
2963
|
function getNearNonceFromApi(url, accountId) {
|
2829
|
-
return
|
2830
|
-
method: "GET",
|
2831
|
-
headers: {
|
2832
|
-
"Content-Type": "application/json"
|
2833
|
-
}
|
2834
|
-
}).then((res) => res.json());
|
2964
|
+
return request(`${url}/v1/nonceNear?csna=${accountId}`);
|
2835
2965
|
}
|
2836
2966
|
function uploadBTCTx(url, data) {
|
2837
|
-
return
|
2967
|
+
return request(`${url}/v1/receiveTransaction`, {
|
2838
2968
|
method: "POST",
|
2839
|
-
|
2840
|
-
|
2841
|
-
},
|
2842
|
-
body: JSON.stringify(data)
|
2843
|
-
}).then((res) => res.json());
|
2969
|
+
body: data
|
2970
|
+
});
|
2844
2971
|
}
|
2845
2972
|
function setupBTCWallet({
|
2846
2973
|
iconUrl = "https://assets.deltatrade.ai/assets/chain/btc.svg",
|
@@ -2877,23 +3004,10 @@ function toHex(originalString) {
|
|
2877
3004
|
hexString = hexString.replace(/(^0+)/g, "");
|
2878
3005
|
return hexString;
|
2879
3006
|
}
|
2880
|
-
var rcpUrls = {
|
2881
|
-
mainnet: [
|
2882
|
-
"https://near.lava.build",
|
2883
|
-
"https://rpc.mainnet.near.org",
|
2884
|
-
"https://free.rpc.fastnear.com",
|
2885
|
-
"https://near.drpc.org"
|
2886
|
-
],
|
2887
|
-
testnet: [
|
2888
|
-
"https://near-testnet.lava.build",
|
2889
|
-
"https://rpc.testnet.near.org",
|
2890
|
-
"https://near-testnet.drpc.org"
|
2891
|
-
]
|
2892
|
-
};
|
2893
3007
|
function pollTransactionStatuses(network, hashes) {
|
2894
3008
|
return __async(this, null, function* () {
|
2895
3009
|
const provider = new import_near_api_js.providers.FailoverRpcProvider(
|
2896
|
-
Object.values(
|
3010
|
+
Object.values(nearRpcUrls[network]).map(
|
2897
3011
|
(url) => new import_near_api_js.providers.JsonRpcProvider({ url })
|
2898
3012
|
)
|
2899
3013
|
);
|
@@ -2905,14 +3019,17 @@ function pollTransactionStatuses(network, hashes) {
|
|
2905
3019
|
try {
|
2906
3020
|
const result = yield provider.txStatus(hash, "unused", "FINAL");
|
2907
3021
|
if (result && result.status) {
|
3022
|
+
console.log(`Transaction ${hash} result:`, result);
|
2908
3023
|
return result;
|
2909
3024
|
}
|
2910
3025
|
} catch (error) {
|
3026
|
+
console.error(`Failed to fetch transaction status for ${hash}: ${error.message}`);
|
2911
3027
|
}
|
2912
3028
|
if (attempt === maxAttempts) {
|
2913
3029
|
throw new Error(`Transaction not found after max attempts: ${hash}`);
|
2914
3030
|
}
|
2915
3031
|
yield delay(1e4);
|
3032
|
+
console.log(`RPC request failed for ${hash}, retrying ${maxAttempts - attempt} more times`);
|
2916
3033
|
}
|
2917
3034
|
});
|
2918
3035
|
const results = yield Promise.all(hashes.map((hash) => pollStatus(hash)));
|
@@ -2920,9 +3037,108 @@ function pollTransactionStatuses(network, hashes) {
|
|
2920
3037
|
});
|
2921
3038
|
}
|
2922
3039
|
|
3040
|
+
// src/utils/bridgeSupplyUtils.ts
|
3041
|
+
var import_near_api_js2 = require("near-api-js");
|
3042
|
+
var import_big = __toESM(require("big.js"), 1);
|
3043
|
+
function nearViewMethod(contractId, methodName, args, network) {
|
3044
|
+
return __async(this, null, function* () {
|
3045
|
+
const nearProvider = new import_near_api_js2.providers.FailoverRpcProvider(
|
3046
|
+
nearRpcUrls[network].map(
|
3047
|
+
(url) => new import_near_api_js2.providers.JsonRpcProvider({ url })
|
3048
|
+
)
|
3049
|
+
);
|
3050
|
+
const res = yield nearProvider.query({
|
3051
|
+
request_type: "call_function",
|
3052
|
+
account_id: contractId,
|
3053
|
+
method_name: methodName,
|
3054
|
+
args_base64: Buffer.from(JSON.stringify(args)).toString("base64"),
|
3055
|
+
finality: "optimistic"
|
3056
|
+
});
|
3057
|
+
return JSON.parse(Buffer.from(res.result).toString());
|
3058
|
+
});
|
3059
|
+
}
|
3060
|
+
function getDepositAddress(btcPublicKey, contractId, network) {
|
3061
|
+
return __async(this, null, function* () {
|
3062
|
+
const res = yield nearViewMethod(
|
3063
|
+
contractId,
|
3064
|
+
"get_user_dapp_deposit_address",
|
3065
|
+
{
|
3066
|
+
deposit_type: {
|
3067
|
+
BtcPublicKey: { btc_public_key: btcPublicKey, dapp_operation: "Burrowland->Supply" }
|
3068
|
+
}
|
3069
|
+
},
|
3070
|
+
network
|
3071
|
+
);
|
3072
|
+
return res;
|
3073
|
+
});
|
3074
|
+
}
|
3075
|
+
function getGasPrice(btcRpcUrl) {
|
3076
|
+
return __async(this, null, function* () {
|
3077
|
+
const defaultFeeRate = 100;
|
3078
|
+
try {
|
3079
|
+
const res = yield request(`${btcRpcUrl}/fee-estimates`);
|
3080
|
+
const feeRate = res[6];
|
3081
|
+
return feeRate || defaultFeeRate;
|
3082
|
+
} catch (error) {
|
3083
|
+
return defaultFeeRate;
|
3084
|
+
}
|
3085
|
+
});
|
3086
|
+
}
|
3087
|
+
function sendBitcoin(btcProvider, address, amount, feeRate) {
|
3088
|
+
return __async(this, null, function* () {
|
3089
|
+
const satoshis = new import_big.default(amount).mul(__pow(10, 8)).toNumber();
|
3090
|
+
const txHash = yield btcProvider.sendBitcoin(address, satoshis, { feeRate });
|
3091
|
+
return txHash;
|
3092
|
+
});
|
3093
|
+
}
|
3094
|
+
function receiveDepositMsg(_0, _1) {
|
3095
|
+
return __async(this, arguments, function* (baseUrl, {
|
3096
|
+
btcPublicKey,
|
3097
|
+
txHash,
|
3098
|
+
depositType = 1
|
3099
|
+
}) {
|
3100
|
+
const res = yield request(`${baseUrl}/v1/receiveDepositMsg`, {
|
3101
|
+
method: "POST",
|
3102
|
+
body: { btcPublicKey, txHash, depositType }
|
3103
|
+
});
|
3104
|
+
return res;
|
3105
|
+
});
|
3106
|
+
}
|
3107
|
+
function checkTransactionStatus(baseUrl, txHash) {
|
3108
|
+
return __async(this, null, function* () {
|
3109
|
+
const res = yield request(`${baseUrl}/v1/bridgeFromTx?fromTxHash=${txHash}`);
|
3110
|
+
return res;
|
3111
|
+
});
|
3112
|
+
}
|
3113
|
+
function executeBurrowSupply(amount, environment) {
|
3114
|
+
return __async(this, null, function* () {
|
3115
|
+
try {
|
3116
|
+
if (typeof window === "undefined" || !window.btcContext) {
|
3117
|
+
throw new Error("BTC Provider is not initialized.");
|
3118
|
+
}
|
3119
|
+
const btcProvider = window.btcContext;
|
3120
|
+
const network = environment === "dev" ? "testnet" : environment;
|
3121
|
+
const config = walletConfig[environment];
|
3122
|
+
const btcRpcUrl = btcRpcUrls[network];
|
3123
|
+
const btcPublicKey = yield btcProvider.getPublicKey();
|
3124
|
+
if (!btcPublicKey) {
|
3125
|
+
throw new Error("BTC Public Key is not available.");
|
3126
|
+
}
|
3127
|
+
const address = yield getDepositAddress(btcPublicKey, config.contractId, network);
|
3128
|
+
const feeRate = yield getGasPrice(btcRpcUrl);
|
3129
|
+
const txHash = yield sendBitcoin(btcProvider, address, amount, feeRate);
|
3130
|
+
yield receiveDepositMsg(config.base_url, { btcPublicKey, txHash });
|
3131
|
+
const status = yield checkTransactionStatus(config.base_url, txHash);
|
3132
|
+
console.log("Transaction Status:", status);
|
3133
|
+
} catch (error) {
|
3134
|
+
console.error("Error executing Bridge+BurrowSupply:", error);
|
3135
|
+
}
|
3136
|
+
});
|
3137
|
+
}
|
3138
|
+
|
2923
3139
|
// src/index.ts
|
2924
3140
|
var getVersion = () => {
|
2925
|
-
return "0.2.
|
3141
|
+
return "0.2.6";
|
2926
3142
|
};
|
2927
3143
|
if (typeof window !== "undefined") {
|
2928
3144
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|