@hot-labs/kit 1.0.33
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/.eslintrc.cjs +11 -0
- package/.github/workflows/deploy-example.yml +55 -0
- package/.github/workflows/release.yml +74 -0
- package/.prettierrc +4 -0
- package/.prototools +2 -0
- package/.vscode/settings.json +3 -0
- package/CHANGELOG.md +1 -0
- package/README.md +67 -0
- package/build/GoogleConnector.d.ts +20 -0
- package/build/GoogleConnector.js +76 -0
- package/build/GoogleConnector.js.map +1 -0
- package/build/HotConnector.d.ts +91 -0
- package/build/HotConnector.js +285 -0
- package/build/HotConnector.js.map +1 -0
- package/build/OmniConnector.d.ts +95 -0
- package/build/OmniConnector.js +123 -0
- package/build/OmniConnector.js.map +1 -0
- package/build/OmniWallet.d.ts +57 -0
- package/build/OmniWallet.js +56 -0
- package/build/OmniWallet.js.map +1 -0
- package/build/cosmos/connector.d.ts +53 -0
- package/build/cosmos/connector.js +207 -0
- package/build/cosmos/connector.js.map +1 -0
- package/build/cosmos/wallet.d.ts +28 -0
- package/build/cosmos/wallet.js +59 -0
- package/build/cosmos/wallet.js.map +1 -0
- package/build/events.d.ts +42 -0
- package/build/events.js +64 -0
- package/build/events.js.map +1 -0
- package/build/evm/abi.d.ts +17 -0
- package/build/evm/abi.js +38 -0
- package/build/evm/abi.js.map +1 -0
- package/build/evm/connector.d.ts +35 -0
- package/build/evm/connector.js +124 -0
- package/build/evm/connector.js.map +1 -0
- package/build/evm/wallet.d.ts +47 -0
- package/build/evm/wallet.js +136 -0
- package/build/evm/wallet.js.map +1 -0
- package/build/exchange.d.ts +63 -0
- package/build/exchange.js +384 -0
- package/build/exchange.js.map +1 -0
- package/build/hot-wallet/evm.d.ts +1 -0
- package/build/hot-wallet/evm.js +33 -0
- package/build/hot-wallet/evm.js.map +1 -0
- package/build/hot-wallet/hot.d.ts +3 -0
- package/build/hot-wallet/hot.js +40 -0
- package/build/hot-wallet/hot.js.map +1 -0
- package/build/hot-wallet/index.d.ts +4 -0
- package/build/hot-wallet/index.js +5 -0
- package/build/hot-wallet/index.js.map +1 -0
- package/build/hot-wallet/solana/account.d.ts +11 -0
- package/build/hot-wallet/solana/account.js +42 -0
- package/build/hot-wallet/solana/account.js.map +1 -0
- package/build/hot-wallet/solana/index.d.ts +1 -0
- package/build/hot-wallet/solana/index.js +85 -0
- package/build/hot-wallet/solana/index.js.map +1 -0
- package/build/hot-wallet/solana/register.d.ts +2 -0
- package/build/hot-wallet/solana/register.js +41 -0
- package/build/hot-wallet/solana/register.js.map +1 -0
- package/build/hot-wallet/solana/solana-wallet.d.ts +34 -0
- package/build/hot-wallet/solana/solana-wallet.js +223 -0
- package/build/hot-wallet/solana/solana-wallet.js.map +1 -0
- package/build/hot-wallet/solana/utils.d.ts +32 -0
- package/build/hot-wallet/solana/utils.js +36 -0
- package/build/hot-wallet/solana/utils.js.map +1 -0
- package/build/hot-wallet/stellar.d.ts +38 -0
- package/build/hot-wallet/stellar.js +32 -0
- package/build/hot-wallet/stellar.js.map +1 -0
- package/build/hot-wallet/ton.d.ts +1 -0
- package/build/hot-wallet/ton.js +49 -0
- package/build/hot-wallet/ton.js.map +1 -0
- package/build/hot-wallet/wallet.d.ts +1 -0
- package/build/hot-wallet/wallet.js +40 -0
- package/build/hot-wallet/wallet.js.map +1 -0
- package/build/index.d.ts +24 -0
- package/build/index.js +25 -0
- package/build/index.js.map +1 -0
- package/build/near/connector.d.ts +28 -0
- package/build/near/connector.js +56 -0
- package/build/near/connector.js.map +1 -0
- package/build/near/wallet.d.ts +62 -0
- package/build/near/wallet.js +233 -0
- package/build/near/wallet.js.map +1 -0
- package/build/omni/Intents.d.ts +93 -0
- package/build/omni/Intents.js +395 -0
- package/build/omni/Intents.js.map +1 -0
- package/build/omni/bridge.d.ts +3 -0
- package/build/omni/bridge.js +34 -0
- package/build/omni/bridge.js.map +1 -0
- package/build/omni/config.d.ts +99 -0
- package/build/omni/config.js +126 -0
- package/build/omni/config.js.map +1 -0
- package/build/omni/defaultTokens.d.ts +17 -0
- package/build/omni/defaultTokens.js +1079 -0
- package/build/omni/defaultTokens.js.map +1 -0
- package/build/omni/index.d.ts +8 -0
- package/build/omni/index.js +9 -0
- package/build/omni/index.js.map +1 -0
- package/build/omni/nearRpc.d.ts +24 -0
- package/build/omni/nearRpc.js +167 -0
- package/build/omni/nearRpc.js.map +1 -0
- package/build/omni/recipient.d.ts +10 -0
- package/build/omni/recipient.js +40 -0
- package/build/omni/recipient.js.map +1 -0
- package/build/omni/token.d.ts +36 -0
- package/build/omni/token.js +136 -0
- package/build/omni/token.js.map +1 -0
- package/build/omni/tokens.d.ts +14 -0
- package/build/omni/tokens.js +57 -0
- package/build/omni/tokens.js.map +1 -0
- package/build/omni/types.d.ts +41 -0
- package/build/omni/types.js +2 -0
- package/build/omni/types.js.map +1 -0
- package/build/omni/utils.d.ts +24 -0
- package/build/omni/utils.js +150 -0
- package/build/omni/utils.js.map +1 -0
- package/build/settings.d.ts +5 -0
- package/build/settings.js +6 -0
- package/build/settings.js.map +1 -0
- package/build/solana/connector.d.ts +31 -0
- package/build/solana/connector.js +138 -0
- package/build/solana/connector.js.map +1 -0
- package/build/solana/protocol.d.ts +25 -0
- package/build/solana/protocol.js +56 -0
- package/build/solana/protocol.js.map +1 -0
- package/build/solana/wallet.d.ts +47 -0
- package/build/solana/wallet.js +188 -0
- package/build/solana/wallet.js.map +1 -0
- package/build/solana/wallets.d.ts +102 -0
- package/build/solana/wallets.js +150 -0
- package/build/solana/wallets.js.map +1 -0
- package/build/stellar/connector.d.ts +25 -0
- package/build/stellar/connector.js +56 -0
- package/build/stellar/connector.js.map +1 -0
- package/build/stellar/wallet.d.ts +70 -0
- package/build/stellar/wallet.js +225 -0
- package/build/stellar/wallet.js.map +1 -0
- package/build/storage.d.ts +10 -0
- package/build/storage.js +12 -0
- package/build/storage.js.map +1 -0
- package/build/ton/connector.d.ts +25 -0
- package/build/ton/connector.js +119 -0
- package/build/ton/connector.js.map +1 -0
- package/build/ton/utils.d.ts +45 -0
- package/build/ton/utils.js +64 -0
- package/build/ton/utils.js.map +1 -0
- package/build/ton/wallet.d.ts +70 -0
- package/build/ton/wallet.js +154 -0
- package/build/ton/wallet.js.map +1 -0
- package/build/ui/Popup.d.ts +10 -0
- package/build/ui/Popup.js +38 -0
- package/build/ui/Popup.js.map +1 -0
- package/build/ui/connect/AuthPopup.d.ts +2 -0
- package/build/ui/connect/AuthPopup.js +48 -0
- package/build/ui/connect/AuthPopup.js.map +1 -0
- package/build/ui/connect/ConnectWallet.d.ts +9 -0
- package/build/ui/connect/ConnectWallet.js +22 -0
- package/build/ui/connect/ConnectWallet.js.map +1 -0
- package/build/ui/connect/LogoutPopup.d.ts +10 -0
- package/build/ui/connect/LogoutPopup.js +8 -0
- package/build/ui/connect/LogoutPopup.js.map +1 -0
- package/build/ui/connect/WCPopup.d.ts +13 -0
- package/build/ui/connect/WCPopup.js +81 -0
- package/build/ui/connect/WCPopup.js.map +1 -0
- package/build/ui/connect/WCRequest.d.ts +9 -0
- package/build/ui/connect/WCRequest.js +13 -0
- package/build/ui/connect/WCRequest.js.map +1 -0
- package/build/ui/connect/WalletPicker.d.ts +11 -0
- package/build/ui/connect/WalletPicker.js +48 -0
- package/build/ui/connect/WalletPicker.js.map +1 -0
- package/build/ui/icons/arrow-right.d.ts +1 -0
- package/build/ui/icons/arrow-right.js +5 -0
- package/build/ui/icons/arrow-right.js.map +1 -0
- package/build/ui/icons/exchange.d.ts +6 -0
- package/build/ui/icons/exchange.js +6 -0
- package/build/ui/icons/exchange.js.map +1 -0
- package/build/ui/icons/logout.d.ts +1 -0
- package/build/ui/icons/logout.js +3 -0
- package/build/ui/icons/logout.js.map +1 -0
- package/build/ui/icons/pending.d.ts +1 -0
- package/build/ui/icons/pending.js +5 -0
- package/build/ui/icons/pending.js.map +1 -0
- package/build/ui/icons/qr.d.ts +1 -0
- package/build/ui/icons/qr.js +5 -0
- package/build/ui/icons/qr.js.map +1 -0
- package/build/ui/icons/search.d.ts +1 -0
- package/build/ui/icons/search.js +5 -0
- package/build/ui/icons/search.js.map +1 -0
- package/build/ui/icons/switch.d.ts +1 -0
- package/build/ui/icons/switch.js +5 -0
- package/build/ui/icons/switch.js.map +1 -0
- package/build/ui/icons/wallet.d.ts +1 -0
- package/build/ui/icons/wallet.js +5 -0
- package/build/ui/icons/wallet.js.map +1 -0
- package/build/ui/payment/Bridge.d.ts +27 -0
- package/build/ui/payment/Bridge.js +340 -0
- package/build/ui/payment/Bridge.js.map +1 -0
- package/build/ui/payment/DepositQR.d.ts +9 -0
- package/build/ui/payment/DepositQR.js +56 -0
- package/build/ui/payment/DepositQR.js.map +1 -0
- package/build/ui/payment/Payment.d.ts +16 -0
- package/build/ui/payment/Payment.js +50 -0
- package/build/ui/payment/Payment.js.map +1 -0
- package/build/ui/payment/Profile.d.ts +7 -0
- package/build/ui/payment/Profile.js +88 -0
- package/build/ui/payment/Profile.js.map +1 -0
- package/build/ui/payment/SelectRecipient.d.ts +14 -0
- package/build/ui/payment/SelectRecipient.js +68 -0
- package/build/ui/payment/SelectRecipient.js.map +1 -0
- package/build/ui/payment/SelectSender.d.ts +13 -0
- package/build/ui/payment/SelectSender.js +23 -0
- package/build/ui/payment/SelectSender.js.map +1 -0
- package/build/ui/payment/SelectToken.d.ts +13 -0
- package/build/ui/payment/SelectToken.js +92 -0
- package/build/ui/payment/SelectToken.js.map +1 -0
- package/build/ui/payment/TokenCard.d.ts +23 -0
- package/build/ui/payment/TokenCard.js +50 -0
- package/build/ui/payment/TokenCard.js.map +1 -0
- package/build/ui/router.d.ts +37 -0
- package/build/ui/router.js +56 -0
- package/build/ui/router.js.map +1 -0
- package/build/ui/styles.d.ts +11 -0
- package/build/ui/styles.js +273 -0
- package/build/ui/styles.js.map +1 -0
- package/package.json +60 -0
- package/skill.md +989 -0
- package/src/GoogleConnector.ts +102 -0
- package/src/HotConnector.ts +344 -0
- package/src/OmniConnector.ts +161 -0
- package/src/OmniWallet.ts +94 -0
- package/src/cosmos/connector.ts +242 -0
- package/src/cosmos/wallet.ts +77 -0
- package/src/events.ts +66 -0
- package/src/evm/abi.ts +39 -0
- package/src/evm/connector.ts +139 -0
- package/src/evm/wallet.ts +156 -0
- package/src/exchange.ts +426 -0
- package/src/hot-wallet/evm.ts +38 -0
- package/src/hot-wallet/hot.ts +39 -0
- package/src/hot-wallet/index.ts +4 -0
- package/src/hot-wallet/solana/account.ts +52 -0
- package/src/hot-wallet/solana/index.ts +98 -0
- package/src/hot-wallet/solana/register.ts +48 -0
- package/src/hot-wallet/solana/solana-wallet.ts +280 -0
- package/src/hot-wallet/solana/utils.ts +56 -0
- package/src/hot-wallet/stellar.ts +39 -0
- package/src/hot-wallet/ton.ts +56 -0
- package/src/hot-wallet/wallet.ts +44 -0
- package/src/index.ts +30 -0
- package/src/near/connector.ts +71 -0
- package/src/near/wallet.ts +255 -0
- package/src/omni/Intents.ts +454 -0
- package/src/omni/bridge.ts +38 -0
- package/src/omni/config.ts +130 -0
- package/src/omni/defaultTokens.ts +1078 -0
- package/src/omni/index.ts +8 -0
- package/src/omni/nearRpc.ts +187 -0
- package/src/omni/recipient.ts +41 -0
- package/src/omni/token.ts +125 -0
- package/src/omni/tokens.ts +68 -0
- package/src/omni/types.ts +46 -0
- package/src/omni/utils.ts +163 -0
- package/src/settings.ts +5 -0
- package/src/solana/connector.ts +151 -0
- package/src/solana/protocol.ts +66 -0
- package/src/solana/wallet.ts +230 -0
- package/src/solana/wallets.ts +243 -0
- package/src/stellar/connector.ts +69 -0
- package/src/stellar/wallet.ts +267 -0
- package/src/storage.ts +19 -0
- package/src/ton/connector.ts +138 -0
- package/src/ton/utils.ts +73 -0
- package/src/ton/wallet.ts +178 -0
- package/src/ui/Popup.tsx +62 -0
- package/src/ui/connect/AuthPopup.tsx +78 -0
- package/src/ui/connect/ConnectWallet.tsx +63 -0
- package/src/ui/connect/LogoutPopup.tsx +20 -0
- package/src/ui/connect/WCPopup.tsx +122 -0
- package/src/ui/connect/WCRequest.tsx +28 -0
- package/src/ui/connect/WalletPicker.tsx +92 -0
- package/src/ui/icons/arrow-right.tsx +8 -0
- package/src/ui/icons/exchange.tsx +17 -0
- package/src/ui/icons/logout.tsx +18 -0
- package/src/ui/icons/pending.tsx +18 -0
- package/src/ui/icons/qr.tsx +12 -0
- package/src/ui/icons/search.tsx +18 -0
- package/src/ui/icons/switch.tsx +10 -0
- package/src/ui/icons/wallet.tsx +18 -0
- package/src/ui/payment/Bridge.tsx +582 -0
- package/src/ui/payment/DepositQR.tsx +88 -0
- package/src/ui/payment/Payment.tsx +78 -0
- package/src/ui/payment/Profile.tsx +140 -0
- package/src/ui/payment/SelectRecipient.tsx +111 -0
- package/src/ui/payment/SelectSender.tsx +60 -0
- package/src/ui/payment/SelectToken.tsx +134 -0
- package/src/ui/payment/TokenCard.tsx +83 -0
- package/src/ui/router.tsx +92 -0
- package/src/ui/styles.ts +284 -0
- package/tsconfig.json +22 -0
- package/vite.config.ts +17 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import type { Keplr } from "@keplr-wallet/provider-extension";
|
|
2
|
+
import { TxRaw } from "@keplr-wallet/proto-types/cosmos/tx/v1beta1/tx";
|
|
3
|
+
import { StargateClient } from "@cosmjs/stargate";
|
|
4
|
+
import { hex } from "@scure/base";
|
|
5
|
+
|
|
6
|
+
import { WalletType } from "../omni/config";
|
|
7
|
+
import { HotConnector } from "../HotConnector";
|
|
8
|
+
import { ConnectorType, OmniConnector, OmniConnectorOptions, WC_ICON } from "../OmniConnector";
|
|
9
|
+
import CosmosWallet from "./wallet";
|
|
10
|
+
import { OmniWallet } from "../OmniWallet";
|
|
11
|
+
|
|
12
|
+
export interface CosmosConnectorOptions extends OmniConnectorOptions {
|
|
13
|
+
cosmosChains?: Record<string, { chain: string; rpc: string; denom: string; prefix: string }>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare global {
|
|
17
|
+
interface Window {
|
|
18
|
+
keplr?: Keplr;
|
|
19
|
+
leap?: Keplr;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const wallets = {
|
|
24
|
+
keplr: {
|
|
25
|
+
name: "Keplr",
|
|
26
|
+
icon: "https://cdn.prod.website-files.com/667dc891bc7b863b5397495b/68a4ca95f93a9ab64dc67ab4_keplr-symbol.svg",
|
|
27
|
+
download: "https://www.keplr.app/get",
|
|
28
|
+
deeplink: "keplrwallet://wcV2?",
|
|
29
|
+
type: "extension",
|
|
30
|
+
id: "keplr",
|
|
31
|
+
},
|
|
32
|
+
leap: {
|
|
33
|
+
name: "Leap",
|
|
34
|
+
icon: "https://framerusercontent.com/images/AbGYvbwnLekBbsdf5g7PI5PpSg.png?scale-down-to=512",
|
|
35
|
+
download: "https://www.leapwallet.io/download",
|
|
36
|
+
deeplink: "leapcosmos://wcV2?",
|
|
37
|
+
type: "extension",
|
|
38
|
+
id: "leap",
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default class CosmosConnector extends OmniConnector<CosmosWallet> {
|
|
43
|
+
cosmosChains: Record<string, { chain: string; rpc: string; denom: string; prefix: string }>;
|
|
44
|
+
|
|
45
|
+
type = ConnectorType.WALLET;
|
|
46
|
+
walletTypes = [WalletType.COSMOS];
|
|
47
|
+
icon = "https://legacy.cosmos.network/presskit/cosmos-brandmark-dynamic-dark.svg";
|
|
48
|
+
name = "Cosmos Wallet";
|
|
49
|
+
isSupported = true;
|
|
50
|
+
id = "cosmos";
|
|
51
|
+
|
|
52
|
+
constructor(wibe3: HotConnector, options?: CosmosConnectorOptions) {
|
|
53
|
+
super(wibe3, options);
|
|
54
|
+
|
|
55
|
+
this.options = [
|
|
56
|
+
{
|
|
57
|
+
name: "keplr" in window ? "Keplr" : "Keplr Mobile",
|
|
58
|
+
download: "https://www.keplr.app/get",
|
|
59
|
+
icon: "https://cdn.prod.website-files.com/667dc891bc7b863b5397495b/68a4ca95f93a9ab64dc67ab4_keplr-symbol.svg",
|
|
60
|
+
type: "keplr" in window ? "extension" : "external",
|
|
61
|
+
id: "keplr",
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: "leap" in window ? "Leap" : "Leap Mobile",
|
|
65
|
+
download: "https://www.leapwallet.io/download",
|
|
66
|
+
icon: "https://framerusercontent.com/images/AbGYvbwnLekBbsdf5g7PI5PpSg.png?scale-down-to=512",
|
|
67
|
+
type: "leap" in window ? "extension" : "external",
|
|
68
|
+
id: "leap",
|
|
69
|
+
},
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
this.cosmosChains = {
|
|
73
|
+
"juno-1": { chain: "juno-1", rpc: "https://juno-rpc.publicnode.com", denom: "ujuno", prefix: "juno" },
|
|
74
|
+
"gonka-mainnet": { chain: "gonka-mainnet", rpc: "https://dev.herewallet.app/api/v1/evm/rpc/4444119", denom: "ngonka", prefix: "gonka" },
|
|
75
|
+
"cosmoshub-4": { chain: "cosmoshub-4", rpc: "https://rpc.cosmoshub.certus.one", denom: "uatom", prefix: "cosmos" },
|
|
76
|
+
...options?.cosmosChains,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
this.getStorage().then(({ type, address, publicKey }) => {
|
|
80
|
+
if (!address || !publicKey) return;
|
|
81
|
+
if (type === "keplr" && window.keplr) this.setKeplrWallet(window.keplr, address, publicKey);
|
|
82
|
+
if (type === "leap" && window.leap) this.setKeplrWallet(window.leap, address, publicKey);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
this.initWalletConnect().then(async (wc) => {
|
|
86
|
+
this.options.unshift({
|
|
87
|
+
download: "https://www.walletconnect.com/get",
|
|
88
|
+
name: "WalletConnect",
|
|
89
|
+
id: "walletconnect",
|
|
90
|
+
type: "external",
|
|
91
|
+
icon: WC_ICON,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const selected = await this.getStorage();
|
|
95
|
+
if (selected.type !== "walletconnect") return;
|
|
96
|
+
this.setupWalletConnect(selected.id as "keplr" | "leap");
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
getConfig(chain: string) {
|
|
101
|
+
return this.cosmosChains[chain];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async setupWalletConnect(id?: "keplr" | "leap"): Promise<CosmosWallet> {
|
|
105
|
+
const wc = await this.wc;
|
|
106
|
+
if (!wc) throw new Error("WalletConnect not found");
|
|
107
|
+
|
|
108
|
+
const properties = JSON.parse(wc.session?.sessionProperties?.keys || "{}");
|
|
109
|
+
const account = properties?.find((t: any) => t.chainId === "gonka-mainnet");
|
|
110
|
+
if (!account) throw new Error("Account not found");
|
|
111
|
+
|
|
112
|
+
const publicKey = Buffer.from(account.pubKey, "base64").toString("hex");
|
|
113
|
+
const address = account.bech32Address;
|
|
114
|
+
|
|
115
|
+
this.setStorage({ type: "walletconnect", id });
|
|
116
|
+
const wallet = new CosmosWallet(this, {
|
|
117
|
+
address: address,
|
|
118
|
+
publicKeyHex: publicKey,
|
|
119
|
+
disconnect: () => this.disconnectWalletConnect(),
|
|
120
|
+
sendTransaction: async (signDoc: any) => {
|
|
121
|
+
const { signed, signature } = await this.requestWalletConnect<{ signed: TxRaw; signature: { signature: string } }>({
|
|
122
|
+
chain: `cosmos:${signDoc.chainId}`,
|
|
123
|
+
deeplink: id ? wallets[id].deeplink : undefined,
|
|
124
|
+
icon: id ? wallets[id].icon : undefined,
|
|
125
|
+
name: id ? wallets[id].name : undefined,
|
|
126
|
+
request: {
|
|
127
|
+
method: "cosmos_signDirect",
|
|
128
|
+
params: {
|
|
129
|
+
signerAddress: address,
|
|
130
|
+
signDoc: {
|
|
131
|
+
chainId: signDoc.chainId,
|
|
132
|
+
accountNumber: signDoc.accountNumber?.toString(),
|
|
133
|
+
bodyBytes: signDoc.bodyBytes ? Buffer.from(signDoc.bodyBytes).toString("base64") : null,
|
|
134
|
+
authInfoBytes: signDoc.authInfoBytes ? Buffer.from(signDoc.authInfoBytes).toString("base64") : null,
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const client = await StargateClient.connect(this.getConfig(signDoc.chainId)?.rpc || "");
|
|
141
|
+
const protobufTx = TxRaw.encode({
|
|
142
|
+
bodyBytes: signed.bodyBytes,
|
|
143
|
+
authInfoBytes: signed.authInfoBytes,
|
|
144
|
+
signatures: [Buffer.from(signature.signature, "base64")],
|
|
145
|
+
}).finish();
|
|
146
|
+
|
|
147
|
+
const result = await client.broadcastTx(protobufTx);
|
|
148
|
+
if (result.code !== 0) throw "Transaction failed";
|
|
149
|
+
return result.transactionHash;
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
return this.setWallet(wallet);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async setKeplrWallet(keplr: Keplr, address: string, publicKey: string) {
|
|
157
|
+
return this.setWallet(
|
|
158
|
+
new CosmosWallet(this, {
|
|
159
|
+
address: address,
|
|
160
|
+
publicKeyHex: publicKey,
|
|
161
|
+
disconnect: () => keplr.disable(),
|
|
162
|
+
sendTransaction: async (signDoc: any, opts = { preferNoSetFee: true }) => {
|
|
163
|
+
await keplr.enable(Object.keys(this.cosmosChains));
|
|
164
|
+
const account = await keplr.getKey(signDoc.chainId);
|
|
165
|
+
const protoSignResponse = await keplr.signDirect(signDoc.chainId, account.bech32Address, signDoc, opts);
|
|
166
|
+
const client = await StargateClient.connect(this.getConfig(signDoc.chainId)?.rpc || "");
|
|
167
|
+
|
|
168
|
+
// Build a TxRaw and serialize it for broadcasting
|
|
169
|
+
const protobufTx = TxRaw.encode({
|
|
170
|
+
bodyBytes: protoSignResponse.signed.bodyBytes,
|
|
171
|
+
authInfoBytes: protoSignResponse.signed.authInfoBytes,
|
|
172
|
+
signatures: [Buffer.from(protoSignResponse.signature.signature, "base64")],
|
|
173
|
+
}).finish();
|
|
174
|
+
|
|
175
|
+
const result = await client.broadcastTx(protobufTx);
|
|
176
|
+
if (result.code !== 0) throw "Transaction failed";
|
|
177
|
+
return result.transactionHash;
|
|
178
|
+
},
|
|
179
|
+
})
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async connectKeplr(type: "keplr" | "leap", extension?: Keplr): Promise<OmniWallet | { qrcode: string; deeplink?: string; task: Promise<OmniWallet> }> {
|
|
184
|
+
if (!extension) {
|
|
185
|
+
return await this.connectWalletConnect({
|
|
186
|
+
onConnect: () => this.setupWalletConnect(type),
|
|
187
|
+
deeplink: wallets[type].deeplink,
|
|
188
|
+
namespaces: {
|
|
189
|
+
cosmos: {
|
|
190
|
+
methods: ["cosmos_getAccounts", "cosmos_signDirect"],
|
|
191
|
+
events: ["chainChanged", "accountsChanged"],
|
|
192
|
+
chains: Object.keys(this.cosmosChains).map((chain) => `cosmos:${chain}`),
|
|
193
|
+
rpcMap: {},
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
await extension.experimentalSuggestChain({
|
|
200
|
+
bech32Config: { bech32PrefixAccAddr: "gonka", bech32PrefixAccPub: "gonka", bech32PrefixValAddr: "gonka", bech32PrefixValPub: "gonka", bech32PrefixConsAddr: "gonka", bech32PrefixConsPub: "gonka" },
|
|
201
|
+
feeCurrencies: [{ coinDenom: "GNK", coinMinimalDenom: "ngonka", coinDecimals: 9, coinGeckoId: "gonka", gasPriceStep: { low: 0, average: 0, high: 0 } }],
|
|
202
|
+
stakeCurrency: { coinDenom: "GNK", coinMinimalDenom: "ngonka", coinDecimals: 9, coinGeckoId: "gonka" },
|
|
203
|
+
currencies: [{ coinDenom: "GNK", coinMinimalDenom: "ngonka", coinDecimals: 9, coinGeckoId: "gonka" }],
|
|
204
|
+
rpc: "https://gonka04.6block.com:8443/chain-rpc",
|
|
205
|
+
rest: "https://gonka04.6block.com:8443/chain-api",
|
|
206
|
+
bip44: { coinType: 1200 },
|
|
207
|
+
chainId: "gonka-mainnet",
|
|
208
|
+
chainName: "Gonka",
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
await extension.enable(Object.keys(this.cosmosChains));
|
|
212
|
+
const account = await extension.getKey("gonka-mainnet");
|
|
213
|
+
await this.setStorage({ type, address: account.bech32Address, publicKey: hex.encode(account.pubKey) });
|
|
214
|
+
return await this.setKeplrWallet(extension, account.bech32Address, hex.encode(account.pubKey));
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async connect(id: string) {
|
|
218
|
+
if (id === "walletconnect") {
|
|
219
|
+
return await this.connectWalletConnect({
|
|
220
|
+
onConnect: () => this.setupWalletConnect(),
|
|
221
|
+
namespaces: {
|
|
222
|
+
cosmos: {
|
|
223
|
+
methods: ["cosmos_getAccounts", "cosmos_signDirect"],
|
|
224
|
+
events: ["chainChanged", "accountsChanged"],
|
|
225
|
+
chains: Object.keys(this.cosmosChains).map((chain) => `cosmos:${chain}`),
|
|
226
|
+
rpcMap: {},
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (id === "keplr") {
|
|
233
|
+
return await this.connectKeplr("keplr", window.keplr);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (id === "leap") {
|
|
237
|
+
return await this.connectKeplr("leap", window.leap);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
throw new Error("Wallet not found");
|
|
241
|
+
}
|
|
242
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { StargateClient } from "@cosmjs/stargate";
|
|
2
|
+
|
|
3
|
+
import { OmniWallet, SignedAuth } from "../OmniWallet";
|
|
4
|
+
import { chainsMap, WalletType } from "../omni/config";
|
|
5
|
+
import { ReviewFee } from "../omni/bridge";
|
|
6
|
+
import CosmosConnector from "./connector";
|
|
7
|
+
|
|
8
|
+
interface ProtocolWallet {
|
|
9
|
+
disconnect?: () => Promise<void>;
|
|
10
|
+
sendTransaction?: (signDoc: any) => Promise<string>;
|
|
11
|
+
address: string;
|
|
12
|
+
publicKeyHex: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default class CosmosWallet extends OmniWallet {
|
|
16
|
+
readonly type = WalletType.COSMOS;
|
|
17
|
+
|
|
18
|
+
constructor(readonly connector: CosmosConnector, readonly wallet: ProtocolWallet) {
|
|
19
|
+
super(connector);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get address() {
|
|
23
|
+
return this.wallet.address;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get publicKey() {
|
|
27
|
+
return this.wallet.publicKeyHex;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get omniAddress() {
|
|
31
|
+
return "";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async disconnect() {
|
|
35
|
+
super.disconnect();
|
|
36
|
+
this.wallet.disconnect?.();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
sendTransaction(signDoc: any): Promise<string> {
|
|
40
|
+
if (!this.wallet.sendTransaction) throw "Not impl";
|
|
41
|
+
return this.wallet.sendTransaction(signDoc);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
transferFee(): Promise<ReviewFee> {
|
|
45
|
+
throw new Error("Method not implemented.");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
transfer(): Promise<string> {
|
|
49
|
+
throw "Not impl";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
signIntentsWithAuth(): Promise<SignedAuth> {
|
|
53
|
+
throw new Error("Method not implemented.");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
signIntents(): Promise<Record<string, any>> {
|
|
57
|
+
throw new Error("Method not implemented.");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async fetchBalances(chain: number, whitelist: string[]): Promise<Record<string, bigint>> {
|
|
61
|
+
const balances = await Promise.all(
|
|
62
|
+
whitelist.map(async (token) => {
|
|
63
|
+
const balance = await this.fetchBalance(chain, token);
|
|
64
|
+
return [token, balance];
|
|
65
|
+
})
|
|
66
|
+
);
|
|
67
|
+
return Object.fromEntries(balances);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async fetchBalance(chain: number, token: string): Promise<bigint> {
|
|
71
|
+
const config = this.connector.getConfig(chainsMap[chain].id);
|
|
72
|
+
if (!config) throw new Error("Config not found");
|
|
73
|
+
const client = await StargateClient.connect(config.rpc);
|
|
74
|
+
const balance = await client.getBalance(this.address, token);
|
|
75
|
+
return BigInt(balance.amount || 0);
|
|
76
|
+
}
|
|
77
|
+
}
|
package/src/events.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic event emitter class for handling typed events and their callbacks
|
|
3
|
+
* @template T Record type containing event names as keys and their payload types as values
|
|
4
|
+
*/
|
|
5
|
+
export class EventEmitter<T extends Record<string, any>> {
|
|
6
|
+
/** Internal storage for event callbacks */
|
|
7
|
+
private events: Partial<Record<keyof T, Array<(payload: any) => void>>> = {};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Subscribe to an event
|
|
11
|
+
* @template K Event name type
|
|
12
|
+
* @param event Name of the event to subscribe to
|
|
13
|
+
* @param callback Function to be called when event is emitted
|
|
14
|
+
*/
|
|
15
|
+
on<K extends keyof T>(event: K, callback: (payload: T[K]) => void): void {
|
|
16
|
+
if (!this.events[event]) this.events[event] = [];
|
|
17
|
+
this.events[event]!.push(callback);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Emit an event with payload
|
|
22
|
+
* @template K Event name type
|
|
23
|
+
* @param event Name of the event to emit
|
|
24
|
+
* @param payload Data to pass to event handlers
|
|
25
|
+
*/
|
|
26
|
+
emit<K extends keyof T>(event: K, payload: T[K]): void {
|
|
27
|
+
this.events[event]?.forEach((cb) => cb(payload));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Unsubscribe from an event
|
|
32
|
+
* @template K Event name type
|
|
33
|
+
* @param event Name of the event to unsubscribe from
|
|
34
|
+
* @param callback Function to remove from event handlers
|
|
35
|
+
*/
|
|
36
|
+
off<K extends keyof T>(event: K, callback: (payload: T[K]) => void): void {
|
|
37
|
+
this.events[event] = this.events[event]?.filter((cb) => cb !== callback);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Subscribe to an event for a single emission
|
|
42
|
+
* @template K Event name type
|
|
43
|
+
* @param event Name of the event to subscribe to
|
|
44
|
+
* @param callback Function to be called when event is emitted
|
|
45
|
+
*/
|
|
46
|
+
once<K extends keyof T>(event: K, callback: (payload: T[K]) => void): void {
|
|
47
|
+
const onceWrapper = (payload: T[K]) => {
|
|
48
|
+
callback(payload);
|
|
49
|
+
this.off(event, onceWrapper);
|
|
50
|
+
};
|
|
51
|
+
this.on(event, onceWrapper);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Remove all event listeners
|
|
56
|
+
* @template K Event name type
|
|
57
|
+
* @param event Optional event name to remove listeners for. If not provided, removes all listeners for all events
|
|
58
|
+
*/
|
|
59
|
+
removeAllListeners<K extends keyof T>(event?: K): void {
|
|
60
|
+
if (event) {
|
|
61
|
+
delete this.events[event];
|
|
62
|
+
} else {
|
|
63
|
+
this.events = {};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
package/src/evm/abi.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export const erc20abi = [
|
|
2
|
+
"function name() public view returns (string)",
|
|
3
|
+
"function symbol() public view returns (string)",
|
|
4
|
+
"function decimals() public view returns (uint8)",
|
|
5
|
+
"function totalSupply() public view returns (uint256)",
|
|
6
|
+
"function balanceOf(address _owner) public view returns (uint256 balance)",
|
|
7
|
+
"function transfer(address _to, uint256 _value) public returns (bool success)",
|
|
8
|
+
"function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)",
|
|
9
|
+
"function approve(address _spender, uint256 _value) public returns (bool success)",
|
|
10
|
+
"function allowance(address _owner, address _spender) public view returns (uint256 remaining)",
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
export const bridgeAbi = [
|
|
14
|
+
"function multi_deposit(bytes memory receiver, address contract_id, uint256[] memory tokenIds)",
|
|
15
|
+
"function deposit(bytes memory receiver, address contract_id, uint256 tokenId)",
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
export const nftAbi = [
|
|
19
|
+
{
|
|
20
|
+
inputs: [
|
|
21
|
+
{ internalType: "address", name: "operator", type: "address" },
|
|
22
|
+
{ internalType: "bool", name: "approved", type: "bool" },
|
|
23
|
+
],
|
|
24
|
+
name: "setApprovalForAll",
|
|
25
|
+
stateMutability: "nonpayable",
|
|
26
|
+
type: "function",
|
|
27
|
+
outputs: [],
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
inputs: [
|
|
31
|
+
{ internalType: "address", name: "account", type: "address" },
|
|
32
|
+
{ internalType: "address", name: "operator", type: "address" },
|
|
33
|
+
],
|
|
34
|
+
name: "isApprovedForAll",
|
|
35
|
+
outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
|
36
|
+
stateMutability: "view",
|
|
37
|
+
type: "function",
|
|
38
|
+
},
|
|
39
|
+
];
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import MetaMaskSDK from "@metamask/sdk";
|
|
2
|
+
import { runInAction } from "mobx";
|
|
3
|
+
|
|
4
|
+
import { ConnectorType, OmniConnector, OmniConnectorOptions, WC_ICON } from "../OmniConnector";
|
|
5
|
+
import { WalletType } from "../omni/config";
|
|
6
|
+
import { isInjected } from "../hot-wallet/hot";
|
|
7
|
+
import { HotConnector } from "../HotConnector";
|
|
8
|
+
import EvmWallet, { EvmProvider } from "./wallet";
|
|
9
|
+
|
|
10
|
+
const chains = [1, 10, 56, 137, 8453, 42161, 421613, 80001];
|
|
11
|
+
|
|
12
|
+
export interface EvmConnectorOptions extends OmniConnectorOptions {
|
|
13
|
+
chains?: number[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
class EvmConnector extends OmniConnector<EvmWallet, { provider: EvmProvider }> {
|
|
17
|
+
icon = "https://storage.herewallet.app/upload/06b43b164683c2cbfe9a9c0699f0953fd56f1f802035e7701ea10501d9e091c6.png";
|
|
18
|
+
walletTypes = [WalletType.EVM, WalletType.OMNI];
|
|
19
|
+
type = ConnectorType.WALLET;
|
|
20
|
+
name = "EVM Wallet";
|
|
21
|
+
chains = chains;
|
|
22
|
+
id = "evm";
|
|
23
|
+
|
|
24
|
+
MMSDK = new MetaMaskSDK({
|
|
25
|
+
dappMetadata: {
|
|
26
|
+
name: "Wibe3",
|
|
27
|
+
url: window.location.href,
|
|
28
|
+
// iconUrl: "https://mydapp.com/icon.png" // Optional
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
constructor(wibe3: HotConnector, readonly settings: EvmConnectorOptions = {}) {
|
|
33
|
+
super(wibe3, settings);
|
|
34
|
+
|
|
35
|
+
if (settings.chains) this.chains.push(...settings.chains);
|
|
36
|
+
|
|
37
|
+
window.addEventListener<any>("eip6963:announceProvider", async (provider) => {
|
|
38
|
+
if (this.options.find((t) => t.name === provider.detail.info.name || t.id === provider.detail.info.uuid)) return;
|
|
39
|
+
|
|
40
|
+
runInAction(() => {
|
|
41
|
+
const info = provider.detail.info;
|
|
42
|
+
const wallet = {
|
|
43
|
+
download: `https://${info.rdns.split(".").reverse().join(".")}`,
|
|
44
|
+
provider: provider.detail.provider,
|
|
45
|
+
type: "extension" as const,
|
|
46
|
+
name: info.name,
|
|
47
|
+
icon: info.icon,
|
|
48
|
+
id: info.rdns,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
if (info.rdns === "org.hot-labs") this.options.unshift(wallet);
|
|
52
|
+
else this.options.push(wallet);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const connected = await this.getConnectedWallet();
|
|
56
|
+
if (connected.type === "wallet" && connected.id === provider.detail.info.rdns) {
|
|
57
|
+
this.connectWallet(provider.detail.info.rdns, provider.detail.provider);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
window.dispatchEvent(new Event("eip6963:requestProvider"));
|
|
62
|
+
|
|
63
|
+
this.initWalletConnect().then((wc) => {
|
|
64
|
+
this.options.unshift({ id: "walletconnect", name: "WalletConnect", icon: WC_ICON, provider: {} as any, type: "external" });
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
this.wc?.then(async (wc) => {
|
|
68
|
+
const selected = await this.getConnectedWallet();
|
|
69
|
+
if (selected.id !== "walletconnect") return;
|
|
70
|
+
this.setupWalletConnect();
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async setupWalletConnect(): Promise<EvmWallet> {
|
|
75
|
+
const wc = await this.wc;
|
|
76
|
+
if (!wc) throw new Error("WalletConnect not found");
|
|
77
|
+
|
|
78
|
+
const address = wc.session?.namespaces.eip155.accounts[0]?.split(":")[2];
|
|
79
|
+
if (!address) throw new Error("Account not found");
|
|
80
|
+
|
|
81
|
+
this.setStorage({ type: "walletconnect" });
|
|
82
|
+
return this.setWallet(
|
|
83
|
+
new EvmWallet(this, address, {
|
|
84
|
+
request: async (request: any) => this.requestWalletConnect<any>({ request }),
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async connectWallet(id: string, provider: EvmProvider) {
|
|
90
|
+
try {
|
|
91
|
+
if (this.wallets.length > 0) this.removeWallet();
|
|
92
|
+
|
|
93
|
+
const [address] = await provider.request({ method: "eth_requestAccounts" });
|
|
94
|
+
if (!address) throw "No address found";
|
|
95
|
+
this.setStorage({ type: "wallet", id });
|
|
96
|
+
|
|
97
|
+
const handler = async (data: string[]) => {
|
|
98
|
+
provider.off?.("accountsChanged", handler as any);
|
|
99
|
+
if (data.length > 0) this.connectWallet(id, provider);
|
|
100
|
+
else this.disconnect();
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
provider.on?.("accountsChanged", handler);
|
|
104
|
+
return this.setWallet(new EvmWallet(this, address, provider));
|
|
105
|
+
} catch (e) {
|
|
106
|
+
this.disconnect();
|
|
107
|
+
throw e;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async getConnectedWallet() {
|
|
112
|
+
if (isInjected()) return { type: "wallet", id: "org.hot-labs" };
|
|
113
|
+
return await this.getStorage();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async connect(id: string) {
|
|
117
|
+
if (id === "walletconnect") {
|
|
118
|
+
return await this.connectWalletConnect({
|
|
119
|
+
onConnect: () => this.setupWalletConnect(),
|
|
120
|
+
namespaces: {
|
|
121
|
+
eip155: {
|
|
122
|
+
methods: ["eth_sendTransaction", "eth_signTransaction", "eth_sign", "personal_sign", "eth_signTypedData"],
|
|
123
|
+
chains: chains.map((chain) => `eip155:${chain}`),
|
|
124
|
+
events: ["chainChanged", "accountsChanged"],
|
|
125
|
+
rpcMap: {},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
this.disconnectWalletConnect();
|
|
132
|
+
const wallet = this.options.find((t) => t.id === id);
|
|
133
|
+
if (!wallet) throw new Error("Wallet not found");
|
|
134
|
+
|
|
135
|
+
return await this.connectWallet(id, wallet.provider);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export default EvmConnector;
|