btc-wallet 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1 @@
|
|
1
|
+
export declare function executeBurrowSupply(amount: string, environment: 'dev' | 'testnet' | 'mainnet'): Promise<void>;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
interface RequestOptions<T> extends RequestInit {
|
2
|
+
body?: RequestInit['body'] | any;
|
3
|
+
retryCount?: number;
|
4
|
+
timeout?: number;
|
5
|
+
cacheTimeout?: number;
|
6
|
+
pollingInterval?: number;
|
7
|
+
maxPollingAttempts?: number;
|
8
|
+
shouldStopPolling?: (response: T) => boolean;
|
9
|
+
}
|
10
|
+
export default function request<T>(url: string, options?: RequestOptions<T>): Promise<T>;
|
11
|
+
export {};
|
package/esm/index.js
CHANGED
@@ -85,6 +85,7 @@ var InjectedConnector = class extends BaseConnector {
|
|
85
85
|
requestAccounts() {
|
86
86
|
return __async(this, null, function* () {
|
87
87
|
const accounts = yield this.getProviderOrThrow().requestAccounts();
|
88
|
+
console.log("\u{1F680} ~ InjectedConnector ~ requestAccounts ~ accounts:", accounts);
|
88
89
|
return accounts;
|
89
90
|
});
|
90
91
|
}
|
@@ -485,7 +486,7 @@ var useAccounts = () => {
|
|
485
486
|
// src/hooks/useBTCProvider.ts
|
486
487
|
import { useCallback } from "react";
|
487
488
|
var useBTCProvider = () => {
|
488
|
-
const { connector, provider, accounts, getPublicKey, signMessage, getNetwork, switchNetwork, sendBitcoin } = useConnectProvider();
|
489
|
+
const { connector, provider, accounts, getPublicKey, signMessage, getNetwork, switchNetwork, sendBitcoin: sendBitcoin2 } = useConnectProvider();
|
489
490
|
const sendInscription = useCallback(
|
490
491
|
(address, inscriptionId, options) => __async(void 0, null, function* () {
|
491
492
|
if (!connector) {
|
@@ -496,7 +497,7 @@ var useBTCProvider = () => {
|
|
496
497
|
}),
|
497
498
|
[connector]
|
498
499
|
);
|
499
|
-
return { provider, accounts, getPublicKey, signMessage, getNetwork, switchNetwork, sendBitcoin, sendInscription, connector };
|
500
|
+
return { provider, accounts, getPublicKey, signMessage, getNetwork, switchNetwork, sendBitcoin: sendBitcoin2, sendInscription, connector };
|
500
501
|
};
|
501
502
|
|
502
503
|
// src/hooks/useConnectModal.ts
|
@@ -650,6 +651,7 @@ var WalletClientProvider = class {
|
|
650
651
|
}
|
651
652
|
}
|
652
653
|
if (method === "personal_sign" /* personalSign */) {
|
654
|
+
console.log("personal_sign ---- ", arg);
|
653
655
|
return new Promise((resolve, reject) => {
|
654
656
|
eventUtils_default.emit("personalSign" /* personalSign */, arg);
|
655
657
|
eventUtils_default.once("personalSignResult" /* personalSignResult */, ({ result, error }) => {
|
@@ -955,6 +957,7 @@ var ConnectModal = ({ open, onClose }) => {
|
|
955
957
|
yield connect(connector.metadata.id);
|
956
958
|
closeConnectModal();
|
957
959
|
} catch (error) {
|
960
|
+
console.error("onConnect error", error);
|
958
961
|
if (error.code === 4001) {
|
959
962
|
setRetryVisible(true);
|
960
963
|
}
|
@@ -1497,10 +1500,13 @@ var SignModal = ({ open, onClose, onOpen }) => {
|
|
1497
1500
|
}), [userOpBundle, smartAccount, accountContract]);
|
1498
1501
|
useEffect4(() => {
|
1499
1502
|
if (userOpBundle && open) {
|
1503
|
+
console.log("deserializeUserOp start");
|
1500
1504
|
setDeserializeLoading(true);
|
1501
1505
|
deserializeUserOp().then((result) => {
|
1506
|
+
console.log("\u{1F680} ~ deserializeUserOp ~ result:", result);
|
1502
1507
|
setDeserializeResult(result);
|
1503
1508
|
}).catch((error) => {
|
1509
|
+
console.log("\u{1F680} ~ deserializeUserOp ~ error:", error);
|
1504
1510
|
eventUtils_default.emit("sendUserOpResult" /* sendUserOpResult */, {
|
1505
1511
|
error
|
1506
1512
|
});
|
@@ -1511,6 +1517,7 @@ var SignModal = ({ open, onClose, onOpen }) => {
|
|
1511
1517
|
useEffect4(() => {
|
1512
1518
|
if (open && publicClient && evmAccount && userOpBundle) {
|
1513
1519
|
publicClient.getBalance({ address: evmAccount }).then((result) => setNativeBalance(result)).catch((error) => {
|
1520
|
+
console.log("\u{1F680} ~ getBalance ~ error:", error);
|
1514
1521
|
eventUtils_default.emit("sendUserOpResult" /* sendUserOpResult */, {
|
1515
1522
|
error
|
1516
1523
|
});
|
@@ -1683,6 +1690,7 @@ var AASignerProvider = class {
|
|
1683
1690
|
this.getPublicClient = () => {
|
1684
1691
|
var _a, _b;
|
1685
1692
|
const rpcUrl = ((_a = this == null ? void 0 : this.rpcUrls) == null ? void 0 : _a[this.chainId]) || ((_b = chains3.getEVMChainInfoById(this.chainId || 1)) == null ? void 0 : _b.rpcUrl);
|
1693
|
+
console.log("rpcUrl", rpcUrl);
|
1686
1694
|
return createPublicClient({
|
1687
1695
|
transport: http(rpcUrl)
|
1688
1696
|
});
|
@@ -1717,8 +1725,10 @@ var AASignerProvider = class {
|
|
1717
1725
|
return `0x${this.chainId.toString(16)}`;
|
1718
1726
|
} else if (arg.method === "personal_sign" /* personalSign */) {
|
1719
1727
|
let message = (_a = arg.params) == null ? void 0 : _a[0];
|
1728
|
+
console.log("personal_sign message:", message);
|
1720
1729
|
if (message.length !== 66) {
|
1721
1730
|
const hash = hashMessage({ raw: message });
|
1731
|
+
console.log("personal_sign hash:", hash);
|
1722
1732
|
message = hash;
|
1723
1733
|
}
|
1724
1734
|
const result = yield this.personalSign(message || "");
|
@@ -1726,15 +1736,19 @@ var AASignerProvider = class {
|
|
1726
1736
|
if (!convertResult) {
|
1727
1737
|
throw new Error("sign error");
|
1728
1738
|
}
|
1739
|
+
console.log(`personal_sign result(${convertResult.length}): `, convertResult);
|
1729
1740
|
return convertResult;
|
1730
1741
|
} else if (arg.method === "eth_signTypedData" || arg.method === "eth_signTypedData_v4") {
|
1731
1742
|
const typedData = (_b = arg.params) == null ? void 0 : _b[1];
|
1743
|
+
console.log("signTypedData typedData", typedData);
|
1732
1744
|
const hash = hashTypedData(typeof typedData === "string" ? JSON.parse(typedData) : typedData);
|
1745
|
+
console.log("signTypedData hash", hash);
|
1733
1746
|
const result = yield this.personalSign(hash || "");
|
1734
1747
|
const convertResult = convertSignature(result);
|
1735
1748
|
if (!convertResult) {
|
1736
1749
|
throw new Error("sign error");
|
1737
1750
|
}
|
1751
|
+
console.log(`eth_signTypedData result(${convertResult.length}): `, convertResult);
|
1738
1752
|
return convertResult;
|
1739
1753
|
} else if (arg.method === "wallet_switchEthereumChain") {
|
1740
1754
|
if (arg.params && arg.params instanceof Array && arg.params[0] && arg.params[0].chainId) {
|
@@ -1814,12 +1828,12 @@ var ConnectProvider = ({
|
|
1814
1828
|
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"
|
1815
1829
|
});
|
1816
1830
|
const setAccountContract = useCallback7(
|
1817
|
-
(
|
1818
|
-
if (!checkBTCVersion(options.aaOptions.accountContracts,
|
1831
|
+
(config) => {
|
1832
|
+
if (!checkBTCVersion(options.aaOptions.accountContracts, config.name, config.version)) {
|
1819
1833
|
throw new Error("Invalid Account Contract");
|
1820
1834
|
}
|
1821
|
-
localStorage.setItem(SAContractKey, JSON.stringify(
|
1822
|
-
_setAccountContract(
|
1835
|
+
localStorage.setItem(SAContractKey, JSON.stringify(config));
|
1836
|
+
_setAccountContract(config);
|
1823
1837
|
},
|
1824
1838
|
[options.aaOptions.accountContracts, _setAccountContract]
|
1825
1839
|
);
|
@@ -1858,7 +1872,7 @@ var ConnectProvider = ({
|
|
1858
1872
|
}),
|
1859
1873
|
[connector]
|
1860
1874
|
);
|
1861
|
-
const
|
1875
|
+
const sendBitcoin2 = useCallback7(
|
1862
1876
|
(toAddress, satoshis, options2) => __async(void 0, null, function* () {
|
1863
1877
|
if (!connector) {
|
1864
1878
|
throw new Error("Wallet not connected!");
|
@@ -1906,6 +1920,7 @@ var ConnectProvider = ({
|
|
1906
1920
|
setEVMAccount(res);
|
1907
1921
|
}).catch((e) => {
|
1908
1922
|
setEVMAccount(void 0);
|
1923
|
+
console.error("smartAccount getAddress error", e);
|
1909
1924
|
});
|
1910
1925
|
} else {
|
1911
1926
|
setEVMAccount(void 0);
|
@@ -1927,6 +1942,7 @@ var ConnectProvider = ({
|
|
1927
1942
|
const requestAccount = useCallback7(
|
1928
1943
|
(connector2) => __async(void 0, null, function* () {
|
1929
1944
|
let accounts2 = yield connector2.getAccounts();
|
1945
|
+
console.log("requestAccount start, autoConnect", accounts2, autoConnect);
|
1930
1946
|
if (accounts2.length === 0 && autoConnect) {
|
1931
1947
|
accounts2 = yield connector2.requestAccounts();
|
1932
1948
|
}
|
@@ -1936,7 +1952,9 @@ var ConnectProvider = ({
|
|
1936
1952
|
);
|
1937
1953
|
const requestDirectAccount = useCallback7(
|
1938
1954
|
(connector2) => __async(void 0, null, function* () {
|
1955
|
+
console.log(111);
|
1939
1956
|
let accounts2 = yield connector2.getAccounts();
|
1957
|
+
console.log("requestAccount start, autoConnect", accounts2, autoConnect);
|
1940
1958
|
if (accounts2.length === 0) {
|
1941
1959
|
accounts2 = yield connector2.requestAccounts();
|
1942
1960
|
}
|
@@ -1948,6 +1966,7 @@ var ConnectProvider = ({
|
|
1948
1966
|
useEffect5(() => {
|
1949
1967
|
if (connector) {
|
1950
1968
|
requestAccount(connector).catch((e) => {
|
1969
|
+
console.log("get account error", e);
|
1951
1970
|
setAccounts([]);
|
1952
1971
|
});
|
1953
1972
|
} else {
|
@@ -1978,9 +1997,9 @@ var ConnectProvider = ({
|
|
1978
1997
|
setConnectorId(void 0);
|
1979
1998
|
}, [connector]);
|
1980
1999
|
useEffect5(() => {
|
1981
|
-
const
|
1982
|
-
if (
|
1983
|
-
_setAccountContract(
|
2000
|
+
const config = JSON.parse(localStorage.getItem(SAContractKey) || "{}");
|
2001
|
+
if (config.name && config.version && checkBTCVersion(options.aaOptions.accountContracts, config.name, config.version)) {
|
2002
|
+
_setAccountContract(config);
|
1984
2003
|
}
|
1985
2004
|
}, [options.aaOptions.accountContracts, _setAccountContract]);
|
1986
2005
|
useEffect5(() => {
|
@@ -2003,6 +2022,7 @@ var ConnectProvider = ({
|
|
2003
2022
|
})
|
2004
2023
|
})
|
2005
2024
|
);
|
2025
|
+
console.log("walletEntryPlugin init");
|
2006
2026
|
}
|
2007
2027
|
}, [options, evmSupportChainIds, accountContract]);
|
2008
2028
|
useEffect5(() => {
|
@@ -2011,6 +2031,7 @@ var ConnectProvider = ({
|
|
2011
2031
|
walletEntryPlugin.setWalletCore({
|
2012
2032
|
ethereum: smartAccount.provider
|
2013
2033
|
});
|
2034
|
+
console.log("walletEntryPlugin setWalletCore");
|
2014
2035
|
}
|
2015
2036
|
}, [smartAccount, options]);
|
2016
2037
|
useEffect5(() => {
|
@@ -2018,8 +2039,10 @@ var ConnectProvider = ({
|
|
2018
2039
|
if (((_a2 = options.walletOptions) == null ? void 0 : _a2.visible) !== false) {
|
2019
2040
|
if (evmAccount) {
|
2020
2041
|
walletEntryPlugin.walletEntryCreate();
|
2042
|
+
console.log("walletEntryPlugin walletEntryCreate");
|
2021
2043
|
} else {
|
2022
2044
|
walletEntryPlugin.walletEntryDestroy();
|
2045
|
+
console.log("walletEntryPlugin walletEntryDestroy");
|
2023
2046
|
}
|
2024
2047
|
}
|
2025
2048
|
}, [evmAccount, smartAccount, options]);
|
@@ -2071,7 +2094,7 @@ var ConnectProvider = ({
|
|
2071
2094
|
smartAccount,
|
2072
2095
|
getNetwork,
|
2073
2096
|
switchNetwork,
|
2074
|
-
sendBitcoin,
|
2097
|
+
sendBitcoin: sendBitcoin2,
|
2075
2098
|
accountContract,
|
2076
2099
|
setAccountContract,
|
2077
2100
|
getSmartAccountInfo
|
@@ -2157,7 +2180,10 @@ function InitContextHook() {
|
|
2157
2180
|
// src/components/btcWalletSelectorContext.tsx
|
2158
2181
|
import { jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
|
2159
2182
|
var WalletSelectorContext = React.createContext(null);
|
2160
|
-
function BtcWalletSelectorContextProvider({
|
2183
|
+
function BtcWalletSelectorContextProvider({
|
2184
|
+
children,
|
2185
|
+
autoConnect = false
|
2186
|
+
}) {
|
2161
2187
|
const [isProcessing, setIsProcessing] = useState8(false);
|
2162
2188
|
const walletSelectorContextValue = useMemo6(() => {
|
2163
2189
|
const simpleFn = {};
|
@@ -2201,9 +2227,16 @@ function BtcWalletSelectorContextProvider({ children, autoConnect = false }) {
|
|
2201
2227
|
connectors: [new UnisatConnector()],
|
2202
2228
|
children: [
|
2203
2229
|
children,
|
2204
|
-
isProcessing && /* @__PURE__ */ jsx12(
|
2205
|
-
|
2206
|
-
|
2230
|
+
isProcessing && /* @__PURE__ */ jsx12(
|
2231
|
+
ComfirmBox,
|
2232
|
+
{
|
2233
|
+
hash: "",
|
2234
|
+
status: 0,
|
2235
|
+
onClose: () => {
|
2236
|
+
setIsProcessing(false);
|
2237
|
+
}
|
2238
|
+
}
|
2239
|
+
),
|
2207
2240
|
/* @__PURE__ */ jsx12(InitContextHook, {})
|
2208
2241
|
]
|
2209
2242
|
}
|
@@ -2211,7 +2244,7 @@ function BtcWalletSelectorContextProvider({ children, autoConnect = false }) {
|
|
2211
2244
|
}
|
2212
2245
|
function useBtcWalletSelector() {
|
2213
2246
|
const { openConnectModal, openConnectModalAsync, disconnect, requestDirectAccount } = useConnectModal();
|
2214
|
-
const { accounts, sendBitcoin, getPublicKey, provider, signMessage, connector } = useBTCProvider();
|
2247
|
+
const { accounts, sendBitcoin: sendBitcoin2, getPublicKey, provider, signMessage, connector } = useBTCProvider();
|
2215
2248
|
const publicKey = useRef(null);
|
2216
2249
|
const signMessageFn = useRef(null);
|
2217
2250
|
const connectorRef = useRef(null);
|
@@ -2303,7 +2336,8 @@ function useBtcWalletSelector() {
|
|
2303
2336
|
}
|
2304
2337
|
const { total } = yield providerRef.current.getBalance();
|
2305
2338
|
return total;
|
2306
|
-
})
|
2339
|
+
}),
|
2340
|
+
sendBitcoin: sendBitcoin2
|
2307
2341
|
};
|
2308
2342
|
}
|
2309
2343
|
function sleep(time) {
|
@@ -2328,6 +2362,7 @@ var walletUrlConfig = {
|
|
2328
2362
|
mainnet: "https://wallet.satoshibridge.top"
|
2329
2363
|
};
|
2330
2364
|
function setupWalletButton(network, wallet, originalWallet) {
|
2365
|
+
console.log("setupWalletButton");
|
2331
2366
|
if (document.getElementById("satoshi-wallet-button")) {
|
2332
2367
|
return;
|
2333
2368
|
}
|
@@ -2415,20 +2450,24 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2415
2450
|
const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
|
2416
2451
|
const originalAccountId = originalWallet.account;
|
2417
2452
|
const originalPublicKey = yield originalWallet.getPublicKey();
|
2453
|
+
console.log({ accountId, originalAccountId, originalPublicKey });
|
2418
2454
|
const iframeSrc = new URL(iframe.src);
|
2419
2455
|
iframeSrc.searchParams.set("origin", window.location.origin);
|
2420
2456
|
accountId && iframeSrc.searchParams.set("accountId", accountId);
|
2421
2457
|
originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
|
2422
2458
|
originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
|
2423
2459
|
iframe.src = iframeSrc.toString();
|
2460
|
+
console.log("iframe src", iframe.src);
|
2424
2461
|
window.addEventListener("message", (event) => __async(this, null, function* () {
|
2425
2462
|
var _a2, _b;
|
2426
2463
|
if (event.origin !== iframeSrc.origin)
|
2427
2464
|
return;
|
2428
2465
|
const { action, requestId, data } = event.data;
|
2429
2466
|
if (action === "signAndSendTransaction") {
|
2467
|
+
console.log("signAndSendTransaction message", event.data);
|
2430
2468
|
try {
|
2431
2469
|
const result = yield wallet.signAndSendTransaction(data);
|
2470
|
+
console.log("signAndSendTransaction result", result);
|
2432
2471
|
(_a2 = event.source) == null ? void 0 : _a2.postMessage(
|
2433
2472
|
{
|
2434
2473
|
requestId,
|
@@ -2438,6 +2477,7 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2438
2477
|
{ targetOrigin: event.origin }
|
2439
2478
|
);
|
2440
2479
|
} catch (error) {
|
2480
|
+
console.error("signAndSendTransaction error", error);
|
2441
2481
|
(_b = event.source) == null ? void 0 : _b.postMessage(
|
2442
2482
|
{
|
2443
2483
|
requestId,
|
@@ -2458,25 +2498,117 @@ function removeWalletButton() {
|
|
2458
2498
|
iframe == null ? void 0 : iframe.remove();
|
2459
2499
|
}
|
2460
2500
|
|
2461
|
-
// src/
|
2462
|
-
var
|
2463
|
-
var config = {
|
2501
|
+
// src/config.ts
|
2502
|
+
var walletConfig = {
|
2464
2503
|
dev: {
|
2465
|
-
base_url: "https://api.dev.satoshibridge.top
|
2504
|
+
base_url: "https://api.dev.satoshibridge.top",
|
2466
2505
|
token: "nbtc1-nsp.testnet",
|
2467
|
-
contractId: "dev1-nsp.testnet"
|
2506
|
+
contractId: "dev1-nsp.testnet",
|
2507
|
+
walletUrl: "https://wallet-dev.satoshibridge.top"
|
2468
2508
|
},
|
2469
2509
|
testnet: {
|
2470
|
-
base_url: "https://api.testnet.satoshibridge.top
|
2510
|
+
base_url: "https://api.testnet.satoshibridge.top",
|
2471
2511
|
token: "nbtc2-nsp.testnet",
|
2472
|
-
contractId: "dev2-nsp.testnet"
|
2512
|
+
contractId: "dev2-nsp.testnet",
|
2513
|
+
walletUrl: "https://wallet-test.satoshibridge.top"
|
2473
2514
|
},
|
2474
2515
|
mainnet: {
|
2475
|
-
base_url: "https://api.mainnet.satoshibridge.top
|
2516
|
+
base_url: "https://api.mainnet.satoshibridge.top",
|
2476
2517
|
token: "",
|
2477
|
-
contractId: ""
|
2518
|
+
contractId: "",
|
2519
|
+
walletUrl: "https://wallet.satoshibridge.top"
|
2478
2520
|
}
|
2479
2521
|
};
|
2522
|
+
var nearRpcUrls = {
|
2523
|
+
mainnet: [
|
2524
|
+
"https://near.lava.build",
|
2525
|
+
"https://rpc.mainnet.near.org",
|
2526
|
+
"https://free.rpc.fastnear.com",
|
2527
|
+
"https://near.drpc.org"
|
2528
|
+
],
|
2529
|
+
testnet: [
|
2530
|
+
"https://near-testnet.lava.build",
|
2531
|
+
"https://rpc.testnet.near.org",
|
2532
|
+
"https://near-testnet.drpc.org"
|
2533
|
+
]
|
2534
|
+
};
|
2535
|
+
var btcRpcUrls = {
|
2536
|
+
mainnet: "https://blockstream.info/api",
|
2537
|
+
testnet: "https://blockstream.info/testnet/api"
|
2538
|
+
};
|
2539
|
+
|
2540
|
+
// src/utils/request.ts
|
2541
|
+
var cache = /* @__PURE__ */ new Map();
|
2542
|
+
var defaultCacheTimeout = 3e3;
|
2543
|
+
function request(url, options) {
|
2544
|
+
return __async(this, null, function* () {
|
2545
|
+
var _a;
|
2546
|
+
const defaultHeaders = {
|
2547
|
+
"Content-Type": "application/json"
|
2548
|
+
};
|
2549
|
+
const cacheTimeout = (options == null ? void 0 : options.cacheTimeout) || defaultCacheTimeout;
|
2550
|
+
const headers = __spreadValues(__spreadValues({}, defaultHeaders), options == null ? void 0 : options.headers);
|
2551
|
+
let body = options == null ? void 0 : options.body;
|
2552
|
+
if (headers["Content-Type"] === "application/json" && body && typeof body !== "string") {
|
2553
|
+
body = JSON.stringify(body);
|
2554
|
+
}
|
2555
|
+
const method = (options == null ? void 0 : options.method) || "GET";
|
2556
|
+
const cacheKey = method.toUpperCase() === "GET" ? url : null;
|
2557
|
+
if (cacheKey) {
|
2558
|
+
const cached = cache.get(cacheKey);
|
2559
|
+
const isCacheValid = cached && Date.now() - cached.timestamp < cacheTimeout;
|
2560
|
+
if (isCacheValid) {
|
2561
|
+
return Promise.resolve(cached.data);
|
2562
|
+
}
|
2563
|
+
}
|
2564
|
+
const newOptions = __spreadProps(__spreadValues({}, options), {
|
2565
|
+
headers,
|
2566
|
+
body,
|
2567
|
+
method
|
2568
|
+
});
|
2569
|
+
const retryCount = (_a = options == null ? void 0 : options.retryCount) != null ? _a : 1;
|
2570
|
+
const controller = new AbortController();
|
2571
|
+
const timeout = (options == null ? void 0 : options.timeout) || 2e4;
|
2572
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
2573
|
+
try {
|
2574
|
+
const res = yield fetch(url, __spreadProps(__spreadValues({}, newOptions), { signal: controller.signal })).finally(
|
2575
|
+
() => clearTimeout(timeoutId)
|
2576
|
+
);
|
2577
|
+
if (!res.ok)
|
2578
|
+
throw new Error(res.statusText);
|
2579
|
+
const data = yield res.json();
|
2580
|
+
if (cacheKey) {
|
2581
|
+
cache.set(cacheKey, { timestamp: Date.now(), data });
|
2582
|
+
setTimeout(() => {
|
2583
|
+
cache.delete(cacheKey);
|
2584
|
+
}, cacheTimeout);
|
2585
|
+
}
|
2586
|
+
if ((options == null ? void 0 : options.shouldStopPolling) && options.shouldStopPolling(data)) {
|
2587
|
+
return data;
|
2588
|
+
}
|
2589
|
+
return data;
|
2590
|
+
} catch (err) {
|
2591
|
+
console.error(err);
|
2592
|
+
if (retryCount > 0) {
|
2593
|
+
console.log(`Retrying... attempts left: ${retryCount}`);
|
2594
|
+
return request(url, __spreadProps(__spreadValues({}, options), { retryCount: retryCount - 1 }));
|
2595
|
+
} else if ((options == null ? void 0 : options.pollingInterval) && (options == null ? void 0 : options.maxPollingAttempts)) {
|
2596
|
+
if (options.maxPollingAttempts > 0) {
|
2597
|
+
console.log(`Polling... attempts left: ${options.maxPollingAttempts}`);
|
2598
|
+
yield new Promise((resolve) => setTimeout(resolve, options.pollingInterval));
|
2599
|
+
return request(url, __spreadProps(__spreadValues({}, options), {
|
2600
|
+
maxPollingAttempts: options.maxPollingAttempts - 1,
|
2601
|
+
retryCount
|
2602
|
+
}));
|
2603
|
+
}
|
2604
|
+
}
|
2605
|
+
return Promise.reject(err);
|
2606
|
+
}
|
2607
|
+
});
|
2608
|
+
}
|
2609
|
+
|
2610
|
+
// src/utils/setupBTCWallet.ts
|
2611
|
+
var { transfer, functionCall } = actionCreators;
|
2480
2612
|
var state = {
|
2481
2613
|
saveAccount(account) {
|
2482
2614
|
window.localStorage.setItem("btc-wallet-account", account);
|
@@ -2534,12 +2666,13 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2534
2666
|
signAndSendTransaction,
|
2535
2667
|
signAndSendTransactions
|
2536
2668
|
};
|
2537
|
-
const currentConfig = "isDev" in metadata && metadata.isDev ?
|
2669
|
+
const currentConfig = "isDev" in metadata && metadata.isDev ? walletConfig.dev : walletConfig[options.network.networkId];
|
2538
2670
|
const walletNetwork = "isDev" in metadata && metadata.isDev ? "dev" : options.network.networkId;
|
2539
2671
|
initWalletButton(walletNetwork, wallet);
|
2540
2672
|
if (!inter) {
|
2541
2673
|
inter = setInterval(() => __async(void 0, null, function* () {
|
2542
2674
|
const btcContext = window.btcContext;
|
2675
|
+
console.log("inter btcContext:", btcContext);
|
2543
2676
|
if (btcContext) {
|
2544
2677
|
clearInterval(inter);
|
2545
2678
|
const context = btcContext.getContext();
|
@@ -2561,10 +2694,12 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2561
2694
|
});
|
2562
2695
|
}));
|
2563
2696
|
context.on("btcLogOut", (e) => __async(void 0, null, function* () {
|
2697
|
+
console.log(3333);
|
2564
2698
|
emitter.emit("accountsChanged", {
|
2565
2699
|
accounts: []
|
2566
2700
|
});
|
2567
2701
|
}));
|
2702
|
+
console.log("metadata.autoConnect:", metadata);
|
2568
2703
|
if ("autoConnect" in metadata && metadata.autoConnect && localStorage.getItem("near-wallet-selector:selectedWalletId") === '"btc-wallet"') {
|
2569
2704
|
yield btcContext.autoConnect();
|
2570
2705
|
}
|
@@ -2713,6 +2848,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2713
2848
|
txBytes,
|
2714
2849
|
(byte) => ("0" + (byte & 255).toString(16)).slice(-2)
|
2715
2850
|
).join("");
|
2851
|
+
console.log("txHex:", txHex);
|
2716
2852
|
const hash = bs58.encode(new Uint8Array(sha256.array(txBytes)));
|
2717
2853
|
return { txBytes, txHex, hash };
|
2718
2854
|
});
|
@@ -2747,8 +2883,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2747
2883
|
btcPubKey: state.getBtcPublicKey(),
|
2748
2884
|
data: toHex(strIntention)
|
2749
2885
|
});
|
2886
|
+
console.log("result:", result);
|
2750
2887
|
if (result.result_code === 0) {
|
2751
2888
|
const hash = newTransactions.map((t) => t.hash);
|
2889
|
+
console.log("txHash:", hash);
|
2752
2890
|
const result2 = yield pollTransactionStatuses(options.network.networkId, hash);
|
2753
2891
|
return result2;
|
2754
2892
|
} else {
|
@@ -2761,6 +2899,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2761
2899
|
const checkAndSetupWalletButton = () => {
|
2762
2900
|
const accountId = state.getAccount();
|
2763
2901
|
const btcContext = window.btcContext;
|
2902
|
+
console.log("checkAndSetupWalletButton:", accountId, btcContext.account);
|
2764
2903
|
if (accountId && btcContext.account) {
|
2765
2904
|
setupWalletButton(network, wallet2, btcContext);
|
2766
2905
|
} else {
|
@@ -2777,29 +2916,16 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2777
2916
|
return wallet;
|
2778
2917
|
});
|
2779
2918
|
function getNonceFromApi(url, accountId) {
|
2780
|
-
return
|
2781
|
-
method: "GET",
|
2782
|
-
headers: {
|
2783
|
-
"Content-Type": "application/json"
|
2784
|
-
}
|
2785
|
-
}).then((res) => res.json());
|
2919
|
+
return request(`${url}/v1/nonce?csna=${accountId}`);
|
2786
2920
|
}
|
2787
2921
|
function getNearNonceFromApi(url, accountId) {
|
2788
|
-
return
|
2789
|
-
method: "GET",
|
2790
|
-
headers: {
|
2791
|
-
"Content-Type": "application/json"
|
2792
|
-
}
|
2793
|
-
}).then((res) => res.json());
|
2922
|
+
return request(`${url}/v1/nonceNear?csna=${accountId}`);
|
2794
2923
|
}
|
2795
2924
|
function uploadBTCTx(url, data) {
|
2796
|
-
return
|
2925
|
+
return request(`${url}/v1/receiveTransaction`, {
|
2797
2926
|
method: "POST",
|
2798
|
-
|
2799
|
-
|
2800
|
-
},
|
2801
|
-
body: JSON.stringify(data)
|
2802
|
-
}).then((res) => res.json());
|
2927
|
+
body: data
|
2928
|
+
});
|
2803
2929
|
}
|
2804
2930
|
function setupBTCWallet({
|
2805
2931
|
iconUrl = "https://assets.deltatrade.ai/assets/chain/btc.svg",
|
@@ -2836,23 +2962,10 @@ function toHex(originalString) {
|
|
2836
2962
|
hexString = hexString.replace(/(^0+)/g, "");
|
2837
2963
|
return hexString;
|
2838
2964
|
}
|
2839
|
-
var rcpUrls = {
|
2840
|
-
mainnet: [
|
2841
|
-
"https://near.lava.build",
|
2842
|
-
"https://rpc.mainnet.near.org",
|
2843
|
-
"https://free.rpc.fastnear.com",
|
2844
|
-
"https://near.drpc.org"
|
2845
|
-
],
|
2846
|
-
testnet: [
|
2847
|
-
"https://near-testnet.lava.build",
|
2848
|
-
"https://rpc.testnet.near.org",
|
2849
|
-
"https://near-testnet.drpc.org"
|
2850
|
-
]
|
2851
|
-
};
|
2852
2965
|
function pollTransactionStatuses(network, hashes) {
|
2853
2966
|
return __async(this, null, function* () {
|
2854
2967
|
const provider = new providers.FailoverRpcProvider(
|
2855
|
-
Object.values(
|
2968
|
+
Object.values(nearRpcUrls[network]).map(
|
2856
2969
|
(url) => new providers.JsonRpcProvider({ url })
|
2857
2970
|
)
|
2858
2971
|
);
|
@@ -2864,14 +2977,17 @@ function pollTransactionStatuses(network, hashes) {
|
|
2864
2977
|
try {
|
2865
2978
|
const result = yield provider.txStatus(hash, "unused", "FINAL");
|
2866
2979
|
if (result && result.status) {
|
2980
|
+
console.log(`Transaction ${hash} result:`, result);
|
2867
2981
|
return result;
|
2868
2982
|
}
|
2869
2983
|
} catch (error) {
|
2984
|
+
console.error(`Failed to fetch transaction status for ${hash}: ${error.message}`);
|
2870
2985
|
}
|
2871
2986
|
if (attempt === maxAttempts) {
|
2872
2987
|
throw new Error(`Transaction not found after max attempts: ${hash}`);
|
2873
2988
|
}
|
2874
2989
|
yield delay(1e4);
|
2990
|
+
console.log(`RPC request failed for ${hash}, retrying ${maxAttempts - attempt} more times`);
|
2875
2991
|
}
|
2876
2992
|
});
|
2877
2993
|
const results = yield Promise.all(hashes.map((hash) => pollStatus(hash)));
|
@@ -2879,9 +2995,108 @@ function pollTransactionStatuses(network, hashes) {
|
|
2879
2995
|
});
|
2880
2996
|
}
|
2881
2997
|
|
2998
|
+
// src/utils/bridgeSupplyUtils.ts
|
2999
|
+
import { providers as providers2 } from "near-api-js";
|
3000
|
+
import Big from "big.js";
|
3001
|
+
function nearViewMethod(contractId, methodName, args, network) {
|
3002
|
+
return __async(this, null, function* () {
|
3003
|
+
const nearProvider = new providers2.FailoverRpcProvider(
|
3004
|
+
nearRpcUrls[network].map(
|
3005
|
+
(url) => new providers2.JsonRpcProvider({ url })
|
3006
|
+
)
|
3007
|
+
);
|
3008
|
+
const res = yield nearProvider.query({
|
3009
|
+
request_type: "call_function",
|
3010
|
+
account_id: contractId,
|
3011
|
+
method_name: methodName,
|
3012
|
+
args_base64: Buffer.from(JSON.stringify(args)).toString("base64"),
|
3013
|
+
finality: "optimistic"
|
3014
|
+
});
|
3015
|
+
return JSON.parse(Buffer.from(res.result).toString());
|
3016
|
+
});
|
3017
|
+
}
|
3018
|
+
function getDepositAddress(btcPublicKey, contractId, network) {
|
3019
|
+
return __async(this, null, function* () {
|
3020
|
+
const res = yield nearViewMethod(
|
3021
|
+
contractId,
|
3022
|
+
"get_user_dapp_deposit_address",
|
3023
|
+
{
|
3024
|
+
deposit_type: {
|
3025
|
+
BtcPublicKey: { btc_public_key: btcPublicKey, dapp_operation: "Burrowland->Supply" }
|
3026
|
+
}
|
3027
|
+
},
|
3028
|
+
network
|
3029
|
+
);
|
3030
|
+
return res;
|
3031
|
+
});
|
3032
|
+
}
|
3033
|
+
function getGasPrice(btcRpcUrl) {
|
3034
|
+
return __async(this, null, function* () {
|
3035
|
+
const defaultFeeRate = 100;
|
3036
|
+
try {
|
3037
|
+
const res = yield request(`${btcRpcUrl}/fee-estimates`);
|
3038
|
+
const feeRate = res[6];
|
3039
|
+
return feeRate || defaultFeeRate;
|
3040
|
+
} catch (error) {
|
3041
|
+
return defaultFeeRate;
|
3042
|
+
}
|
3043
|
+
});
|
3044
|
+
}
|
3045
|
+
function sendBitcoin(btcProvider, address, amount, feeRate) {
|
3046
|
+
return __async(this, null, function* () {
|
3047
|
+
const satoshis = new Big(amount).mul(__pow(10, 8)).toNumber();
|
3048
|
+
const txHash = yield btcProvider.sendBitcoin(address, satoshis, { feeRate });
|
3049
|
+
return txHash;
|
3050
|
+
});
|
3051
|
+
}
|
3052
|
+
function receiveDepositMsg(_0, _1) {
|
3053
|
+
return __async(this, arguments, function* (baseUrl, {
|
3054
|
+
btcPublicKey,
|
3055
|
+
txHash,
|
3056
|
+
depositType = 1
|
3057
|
+
}) {
|
3058
|
+
const res = yield request(`${baseUrl}/v1/receiveDepositMsg`, {
|
3059
|
+
method: "POST",
|
3060
|
+
body: { btcPublicKey, txHash, depositType }
|
3061
|
+
});
|
3062
|
+
return res;
|
3063
|
+
});
|
3064
|
+
}
|
3065
|
+
function checkTransactionStatus(baseUrl, txHash) {
|
3066
|
+
return __async(this, null, function* () {
|
3067
|
+
const res = yield request(`${baseUrl}/v1/bridgeFromTx?fromTxHash=${txHash}`);
|
3068
|
+
return res;
|
3069
|
+
});
|
3070
|
+
}
|
3071
|
+
function executeBurrowSupply(amount, environment) {
|
3072
|
+
return __async(this, null, function* () {
|
3073
|
+
try {
|
3074
|
+
if (typeof window === "undefined" || !window.btcContext) {
|
3075
|
+
throw new Error("BTC Provider is not initialized.");
|
3076
|
+
}
|
3077
|
+
const btcProvider = window.btcContext;
|
3078
|
+
const network = environment === "dev" ? "testnet" : environment;
|
3079
|
+
const config = walletConfig[environment];
|
3080
|
+
const btcRpcUrl = btcRpcUrls[network];
|
3081
|
+
const btcPublicKey = yield btcProvider.getPublicKey();
|
3082
|
+
if (!btcPublicKey) {
|
3083
|
+
throw new Error("BTC Public Key is not available.");
|
3084
|
+
}
|
3085
|
+
const address = yield getDepositAddress(btcPublicKey, config.contractId, network);
|
3086
|
+
const feeRate = yield getGasPrice(btcRpcUrl);
|
3087
|
+
const txHash = yield sendBitcoin(btcProvider, address, amount, feeRate);
|
3088
|
+
yield receiveDepositMsg(config.base_url, { btcPublicKey, txHash });
|
3089
|
+
const status = yield checkTransactionStatus(config.base_url, txHash);
|
3090
|
+
console.log("Transaction Status:", status);
|
3091
|
+
} catch (error) {
|
3092
|
+
console.error("Error executing Bridge+BurrowSupply:", error);
|
3093
|
+
}
|
3094
|
+
});
|
3095
|
+
}
|
3096
|
+
|
2882
3097
|
// src/index.ts
|
2883
3098
|
var getVersion = () => {
|
2884
|
-
return "0.2.
|
3099
|
+
return "0.2.6";
|
2885
3100
|
};
|
2886
3101
|
if (typeof window !== "undefined") {
|
2887
3102
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|
@@ -2899,6 +3114,7 @@ export {
|
|
2899
3114
|
UnisatConnector,
|
2900
3115
|
WizzConnector,
|
2901
3116
|
XverseConnector,
|
3117
|
+
executeBurrowSupply,
|
2902
3118
|
getVersion,
|
2903
3119
|
setupBTCWallet,
|
2904
3120
|
useAccountContract,
|