@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
package/src/index.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export { Network, OmniToken, WalletType } from "./omni/config";
|
|
2
|
+
export { formatter } from "./omni/utils";
|
|
3
|
+
export { EventEmitter } from "./events";
|
|
4
|
+
|
|
5
|
+
export { OmniWallet } from "./OmniWallet";
|
|
6
|
+
export { OmniConnector } from "./OmniConnector";
|
|
7
|
+
export { Intents } from "./omni/Intents";
|
|
8
|
+
export { Token } from "./omni/token";
|
|
9
|
+
export { TGAS } from "./omni/nearRpc";
|
|
10
|
+
|
|
11
|
+
export { default as EvmConnector } from "./evm/connector";
|
|
12
|
+
export { default as SolanaConnector } from "./solana/connector";
|
|
13
|
+
export { default as StellarConnector } from "./stellar/connector";
|
|
14
|
+
export { default as TonConnector } from "./ton/connector";
|
|
15
|
+
export { default as NearConnector } from "./near/connector";
|
|
16
|
+
export { default as CosmosConnector } from "./cosmos/connector";
|
|
17
|
+
|
|
18
|
+
export { default as EvmWallet } from "./evm/wallet";
|
|
19
|
+
export { default as SolanaWallet } from "./solana/wallet";
|
|
20
|
+
export { default as StellarWallet } from "./stellar/wallet";
|
|
21
|
+
export { default as TonWallet } from "./ton/wallet";
|
|
22
|
+
export { default as NearWallet } from "./near/wallet";
|
|
23
|
+
export { default as CosmosWallet } from "./cosmos/wallet";
|
|
24
|
+
|
|
25
|
+
export { near, evm, solana, stellar, ton, google } from "./HotConnector";
|
|
26
|
+
export { HotConnector } from "./HotConnector";
|
|
27
|
+
|
|
28
|
+
import "./hot-wallet";
|
|
29
|
+
|
|
30
|
+
export { Bridge as BridgeWidget } from "./ui/payment/Bridge";
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { NearConnector } from "@hot-labs/near-connect";
|
|
2
|
+
import { runInAction } from "mobx";
|
|
3
|
+
|
|
4
|
+
import { WalletType } from "../omni/config";
|
|
5
|
+
import { ConnectorType, OmniConnector } from "../OmniConnector";
|
|
6
|
+
import { HotConnector } from "../HotConnector";
|
|
7
|
+
import NearWallet from "./wallet";
|
|
8
|
+
|
|
9
|
+
export interface NearConnectorOptions {
|
|
10
|
+
connector?: NearConnector;
|
|
11
|
+
projectId?: string;
|
|
12
|
+
metadata?: {
|
|
13
|
+
name: string;
|
|
14
|
+
description: string;
|
|
15
|
+
url: string;
|
|
16
|
+
icons: string[];
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class Connector extends OmniConnector<NearWallet> {
|
|
21
|
+
connector: NearConnector;
|
|
22
|
+
type = ConnectorType.WALLET;
|
|
23
|
+
walletTypes = [WalletType.NEAR, WalletType.OMNI];
|
|
24
|
+
icon = "https://storage.herewallet.app/upload/73a44e583769f11112b0eff1f2dd2a560c05eed5f6d92f0c03484fa047c31668.png";
|
|
25
|
+
name = "NEAR Wallet";
|
|
26
|
+
id = "near";
|
|
27
|
+
|
|
28
|
+
constructor(readonly wibe3: HotConnector, options?: NearConnectorOptions) {
|
|
29
|
+
super(wibe3);
|
|
30
|
+
|
|
31
|
+
this.connector =
|
|
32
|
+
options?.connector ||
|
|
33
|
+
new NearConnector({
|
|
34
|
+
network: "mainnet",
|
|
35
|
+
walletConnect: options?.projectId ? { projectId: options.projectId, metadata: options.metadata } : undefined,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
this.connector.on("wallet:signOut", () => this.removeWallet());
|
|
39
|
+
this.connector.getConnectedWallet().then(async ({ wallet }) => {
|
|
40
|
+
const [account] = await wallet.getAccounts();
|
|
41
|
+
if (account) this.setWallet(new NearWallet(this, account.accountId, account.publicKey, wallet));
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
this.connector.whenManifestLoaded.then(() => {
|
|
45
|
+
runInAction(() => {
|
|
46
|
+
this.options = this.connector.wallets.map((w) => ({
|
|
47
|
+
download: w.manifest.website,
|
|
48
|
+
name: w.manifest.name,
|
|
49
|
+
icon: w.manifest.icon,
|
|
50
|
+
id: w.manifest.id,
|
|
51
|
+
type: "external" as const,
|
|
52
|
+
}));
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async connect(id: string) {
|
|
58
|
+
const wallet = await this.connector.connect(id);
|
|
59
|
+
if (!wallet) throw new Error("Wallet not found");
|
|
60
|
+
const [account] = await wallet.getAccounts();
|
|
61
|
+
if (!account) throw new Error("No account found");
|
|
62
|
+
return this.setWallet(new NearWallet(this, account.accountId, account.publicKey, wallet));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async disconnect() {
|
|
66
|
+
super.disconnect();
|
|
67
|
+
this.connector.disconnect();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export default Connector;
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { NearWalletBase, SignMessageParams, SignedMessage, SignAndSendTransactionParams } from "@hot-labs/near-connect";
|
|
2
|
+
import { base64, base58, hex } from "@scure/base";
|
|
3
|
+
import { Action } from "@near-js/transactions";
|
|
4
|
+
|
|
5
|
+
import { OmniConnector } from "../OmniConnector";
|
|
6
|
+
import { OmniWallet } from "../OmniWallet";
|
|
7
|
+
import { WalletType } from "../omni/config";
|
|
8
|
+
import { ReviewFee } from "../omni/bridge";
|
|
9
|
+
import { rpc, TGAS } from "../omni/nearRpc";
|
|
10
|
+
import { Token } from "../omni/token";
|
|
11
|
+
|
|
12
|
+
export default class NearWallet extends OmniWallet {
|
|
13
|
+
readonly type = WalletType.NEAR;
|
|
14
|
+
|
|
15
|
+
constructor(readonly connector: OmniConnector, readonly address: string, readonly publicKey?: string, readonly wallet?: NearWalletBase) {
|
|
16
|
+
super(connector);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
get omniAddress() {
|
|
20
|
+
return this.address;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async disconnect() {
|
|
24
|
+
await this.wallet?.signOut();
|
|
25
|
+
super.disconnect();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async fetchBalances(_: number, whitelist: string[]): Promise<Record<string, bigint>> {
|
|
29
|
+
const balances = await Promise.all(
|
|
30
|
+
whitelist.map(async (token) => {
|
|
31
|
+
const balance = await this.fetchBalance(1010, token);
|
|
32
|
+
return [token, balance];
|
|
33
|
+
})
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return Object.fromEntries(balances);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async sendTransaction(params: SignAndSendTransactionParams): Promise<string> {
|
|
40
|
+
if (!this.wallet) throw "not impl";
|
|
41
|
+
const actions = (params.actions as any).map((action: Action) => {
|
|
42
|
+
if ((action as any)["type"]) return action;
|
|
43
|
+
if (action.functionCall) {
|
|
44
|
+
return {
|
|
45
|
+
type: "FunctionCall",
|
|
46
|
+
params: {
|
|
47
|
+
methodName: action.functionCall.methodName,
|
|
48
|
+
args: JSON.parse(Buffer.from(action.functionCall.args).toString("utf8")),
|
|
49
|
+
gas: String(action.functionCall.gas),
|
|
50
|
+
deposit: String(action.functionCall.deposit),
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (action.transfer) {
|
|
56
|
+
return {
|
|
57
|
+
type: "Transfer",
|
|
58
|
+
params: { deposit: String(action.transfer.deposit) },
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const result = await this.wallet.signAndSendTransaction({ receiverId: params.receiverId, actions });
|
|
64
|
+
return result.transaction.hash;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async signMessage(params: SignMessageParams): Promise<SignedMessage> {
|
|
68
|
+
if (!this.wallet) throw "not impl";
|
|
69
|
+
return this.wallet.signMessage(params);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public async getWrapNearDepositAction(amount: bigint, address: string) {
|
|
73
|
+
const storage = await rpc.viewMethod({
|
|
74
|
+
contractId: "wrap.near",
|
|
75
|
+
methodName: "storage_balance_of",
|
|
76
|
+
args: { account_id: address },
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const depositAction = {
|
|
80
|
+
type: "FunctionCall",
|
|
81
|
+
params: {
|
|
82
|
+
methodName: "near_deposit",
|
|
83
|
+
deposit: String(amount),
|
|
84
|
+
gas: String(50n * TGAS),
|
|
85
|
+
args: {},
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
if (storage != null) return [depositAction];
|
|
90
|
+
return [
|
|
91
|
+
{
|
|
92
|
+
type: "FunctionCall",
|
|
93
|
+
params: {
|
|
94
|
+
gas: 30n * TGAS,
|
|
95
|
+
methodName: "storage_deposit",
|
|
96
|
+
deposit: `12500000000000000000000`,
|
|
97
|
+
args: { account_id: address, registration_only: true },
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
depositAction,
|
|
101
|
+
];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async needRegisterToken(token: string, address: string): Promise<boolean> {
|
|
105
|
+
const storage = await rpc.viewMethod({ contractId: token, methodName: "storage_balance_of", args: { account_id: address } }).catch(() => null);
|
|
106
|
+
return storage == null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async registerToken(token: string) {
|
|
110
|
+
const isNeedRegister = await this.needRegisterToken(token, this.address);
|
|
111
|
+
if (!isNeedRegister) return;
|
|
112
|
+
|
|
113
|
+
await this.sendTransaction({
|
|
114
|
+
receiverId: token,
|
|
115
|
+
actions: [
|
|
116
|
+
{
|
|
117
|
+
type: "FunctionCall",
|
|
118
|
+
params: {
|
|
119
|
+
methodName: "storage_deposit",
|
|
120
|
+
args: { account_id: this.address, registration_only: true },
|
|
121
|
+
deposit: String(1n),
|
|
122
|
+
gas: String(30n * TGAS),
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async transferFee() {
|
|
130
|
+
return new ReviewFee({ baseFee: 0n, gasLimit: 300n * TGAS, chain: 1010 });
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async fetchBalance(chain: number, address: string) {
|
|
134
|
+
if (chain !== 1010) throw "Invalid chain";
|
|
135
|
+
|
|
136
|
+
if (address === "native") {
|
|
137
|
+
const protocolConfig = await rpc.experimental_protocolConfig({ finality: "near-final" });
|
|
138
|
+
const state = await rpc.viewAccount(this.address, { finality: "near-final" });
|
|
139
|
+
const costPerByte = BigInt(protocolConfig.runtime_config.storage_amount_per_byte);
|
|
140
|
+
const usedOnStorage = BigInt(state.storage_usage) * costPerByte;
|
|
141
|
+
const locked = BigInt(state.locked);
|
|
142
|
+
const total = BigInt(state.amount) + locked;
|
|
143
|
+
const available = total - (locked > usedOnStorage ? locked : usedOnStorage);
|
|
144
|
+
return available < 0n ? 0n : available;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const balance = await rpc.viewMethod({
|
|
148
|
+
args: { account_id: this.address },
|
|
149
|
+
contractId: address,
|
|
150
|
+
methodName: "ft_balance_of",
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
return BigInt(balance);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async transfer(args: { token: Token; receiver: string; amount: bigint; comment?: string; gasFee?: ReviewFee }) {
|
|
157
|
+
if (args.token.address === "native") {
|
|
158
|
+
return await this.sendTransaction({
|
|
159
|
+
actions: [{ type: "Transfer", params: { deposit: String(args.amount) } }],
|
|
160
|
+
receiverId: args.receiver,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const actions: any[] = [
|
|
165
|
+
{
|
|
166
|
+
type: "FunctionCall",
|
|
167
|
+
params: {
|
|
168
|
+
methodName: "ft_transfer",
|
|
169
|
+
args: { receiver_id: args.receiver, amount: String(args.amount) },
|
|
170
|
+
gas: String(30n * TGAS),
|
|
171
|
+
deposit: String(1n),
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
];
|
|
175
|
+
|
|
176
|
+
const needRegister = await this.needRegisterToken(args.token.address, args.receiver);
|
|
177
|
+
if (needRegister)
|
|
178
|
+
actions.unshift({
|
|
179
|
+
type: "FunctionCall",
|
|
180
|
+
params: {
|
|
181
|
+
gas: String(30n * TGAS),
|
|
182
|
+
methodName: "storage_deposit",
|
|
183
|
+
deposit: `12500000000000000000000`,
|
|
184
|
+
args: { account_id: args.receiver, registration_only: true },
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
return await this.sendTransaction({ receiverId: args.token.address, actions });
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async signIntentsWithAuth(domain: string, intents?: Record<string, any>[]) {
|
|
192
|
+
if (!this.wallet) throw "not impl";
|
|
193
|
+
const accounts = await this.wallet.getAccounts();
|
|
194
|
+
if (accounts.length === 0) throw new Error("No account found");
|
|
195
|
+
const { accountId, publicKey } = accounts[0];
|
|
196
|
+
|
|
197
|
+
const seed = hex.encode(window.crypto.getRandomValues(new Uint8Array(32)));
|
|
198
|
+
const msgBuffer = new TextEncoder().encode(`${domain}_${seed}`);
|
|
199
|
+
const nonce = await window.crypto.subtle.digest("SHA-256", new Uint8Array(msgBuffer));
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
signed: await this.signIntents(intents || [], { nonce: new Uint8Array(nonce) }),
|
|
203
|
+
chainId: WalletType.NEAR,
|
|
204
|
+
publicKey: publicKey,
|
|
205
|
+
address: accountId,
|
|
206
|
+
domain,
|
|
207
|
+
seed,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async signIntents(intents: Record<string, any>[], options?: { nonce?: Uint8Array; deadline?: number }): Promise<Record<string, any>> {
|
|
212
|
+
if (!this.wallet) throw "not impl";
|
|
213
|
+
|
|
214
|
+
const nonce = new Uint8Array(options?.nonce || window.crypto.getRandomValues(new Uint8Array(32)));
|
|
215
|
+
const message = JSON.stringify({
|
|
216
|
+
deadline: options?.deadline ? new Date(options.deadline).toISOString() : "2100-01-01T00:00:00.000Z",
|
|
217
|
+
signer_id: this.omniAddress,
|
|
218
|
+
intents: intents,
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
const result = await this.wallet.signMessage({ message, recipient: "intents.near", nonce });
|
|
222
|
+
if (!result) throw new Error("Failed to sign message");
|
|
223
|
+
const { signature, publicKey } = result;
|
|
224
|
+
|
|
225
|
+
const keys = await rpc.viewMethod({
|
|
226
|
+
contractId: "intents.near",
|
|
227
|
+
methodName: "public_keys_of",
|
|
228
|
+
args: { account_id: this.address },
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
if (!keys.includes(publicKey)) {
|
|
232
|
+
await this.sendTransaction({
|
|
233
|
+
receiverId: "intents.near",
|
|
234
|
+
actions: [
|
|
235
|
+
{
|
|
236
|
+
type: "FunctionCall",
|
|
237
|
+
params: {
|
|
238
|
+
methodName: "add_public_key",
|
|
239
|
+
args: { public_key: publicKey },
|
|
240
|
+
gas: String(80n * TGAS),
|
|
241
|
+
deposit: String(1n),
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
],
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return {
|
|
249
|
+
standard: "nep413",
|
|
250
|
+
payload: { nonce: base64.encode(nonce), recipient: "intents.near", message },
|
|
251
|
+
signature: signature.includes("ed25519:") ? signature : `ed25519:${base58.encode(base64.decode(signature))}`,
|
|
252
|
+
public_key: publicKey,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
}
|