@hot-labs/kit 1.2.0-alpha.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -9
- package/build/HotConnector.d.ts +8 -7
- package/build/HotConnector.js +21 -24
- package/build/HotConnector.js.map +1 -1
- package/build/OmniConnector.d.ts +5 -0
- package/build/OmniConnector.js +5 -5
- package/build/OmniConnector.js.map +1 -1
- package/build/OmniWallet.d.ts +10 -17
- package/build/OmniWallet.js +14 -19
- package/build/OmniWallet.js.map +1 -1
- package/build/core/Intents.d.ts +53 -43
- package/build/core/Intents.js +207 -133
- package/build/core/Intents.js.map +1 -1
- package/build/core/api.d.ts +30 -2
- package/build/core/api.js +43 -10
- package/build/core/api.js.map +1 -1
- package/build/core/bridge.js +1 -1
- package/build/core/bridge.js.map +1 -1
- package/build/core/index.d.ts +1 -1
- package/build/core/index.js +1 -1
- package/build/core/index.js.map +1 -1
- package/build/core/telemetry.d.ts +13 -0
- package/build/core/telemetry.js +27 -0
- package/build/core/telemetry.js.map +1 -0
- package/build/core/token.d.ts +1 -0
- package/build/core/token.js +3 -0
- package/build/core/token.js.map +1 -1
- package/build/core/tokens.js +0 -8
- package/build/core/tokens.js.map +1 -1
- package/build/core/types.d.ts +17 -0
- package/build/core/utils.d.ts +1 -0
- package/build/core/utils.js +21 -1
- package/build/core/utils.js.map +1 -1
- package/build/cosmos/connector.d.ts +2 -2
- package/build/cosmos/connector.js +17 -21
- package/build/cosmos/connector.js.map +1 -1
- package/build/cosmos/wallet.d.ts +2 -4
- package/build/cosmos/wallet.js +3 -8
- package/build/cosmos/wallet.js.map +1 -1
- package/build/evm/connector.d.ts +1 -0
- package/build/evm/connector.js +4 -0
- package/build/evm/connector.js.map +1 -1
- package/build/evm/wallet.d.ts +2 -1
- package/build/evm/wallet.js +7 -5
- package/build/evm/wallet.js.map +1 -1
- package/build/exchange.d.ts +4 -1
- package/build/exchange.js +24 -30
- package/build/exchange.js.map +1 -1
- package/build/hot-wallet/google.js +10 -5
- package/build/hot-wallet/google.js.map +1 -1
- package/build/hot-wallet/proxy.js +2 -2
- package/build/hot-wallet/proxy.js.map +1 -1
- package/build/index.d.ts +2 -1
- package/build/index.js +2 -1
- package/build/index.js.map +1 -1
- package/build/near/connector.js +2 -2
- package/build/near/connector.js.map +1 -1
- package/build/{core/nearRpc.d.ts → near/rpc.d.ts} +0 -1
- package/build/{core/nearRpc.js → near/rpc.js} +8 -22
- package/build/near/rpc.js.map +1 -0
- package/build/near/wallet.d.ts +4 -4
- package/build/near/wallet.js +36 -30
- package/build/near/wallet.js.map +1 -1
- package/build/solana/{protocol.d.ts → WalletStandard.d.ts} +1 -1
- package/build/solana/{protocol.js → WalletStandard.js} +1 -1
- package/build/solana/WalletStandard.js.map +1 -0
- package/build/solana/connector.d.ts +1 -1
- package/build/solana/connector.js +9 -8
- package/build/solana/connector.js.map +1 -1
- package/build/solana/injected/solana-wallet.js.map +1 -1
- package/build/solana/wallet.d.ts +5 -7
- package/build/solana/wallet.js +8 -17
- package/build/solana/wallet.js.map +1 -1
- package/build/solana/{wallets.js → walletStandartList.js} +1 -1
- package/build/solana/walletStandartList.js.map +1 -0
- package/build/stellar/connector.d.ts +0 -2
- package/build/stellar/connector.js +1 -4
- package/build/stellar/connector.js.map +1 -1
- package/build/stellar/wallet.d.ts +10 -8
- package/build/stellar/wallet.js +12 -16
- package/build/stellar/wallet.js.map +1 -1
- package/build/ton/connector.d.ts +0 -1
- package/build/ton/connector.js +1 -4
- package/build/ton/connector.js.map +1 -1
- package/build/ton/wallet.d.ts +2 -3
- package/build/ton/wallet.js +3 -4
- package/build/ton/wallet.js.map +1 -1
- package/build/tron/connector.d.ts +51 -0
- package/build/tron/connector.js +65 -0
- package/build/tron/connector.js.map +1 -0
- package/build/tron/index.d.ts +6 -0
- package/build/tron/index.js +5 -0
- package/build/tron/index.js.map +1 -0
- package/build/tron/wallet.d.ts +52 -0
- package/build/tron/wallet.js +122 -0
- package/build/tron/wallet.js.map +1 -0
- package/build/ui/Popup.d.ts +2 -2
- package/build/ui/Popup.js +5 -1
- package/build/ui/Popup.js.map +1 -1
- package/build/ui/bridge/Bridge.js +389 -0
- package/build/ui/bridge/Bridge.js.map +1 -0
- package/build/ui/{payment → bridge}/SelectRecipient.js +3 -3
- package/build/ui/bridge/SelectRecipient.js.map +1 -0
- package/build/ui/{payment → bridge}/SelectSender.js +2 -2
- package/build/ui/bridge/SelectSender.js.map +1 -0
- package/build/ui/{payment → bridge}/SelectToken.js +4 -3
- package/build/ui/bridge/SelectToken.js.map +1 -0
- package/build/ui/{payment → bridge}/TokenCard.d.ts +7 -9
- package/build/ui/bridge/TokenCard.js +65 -0
- package/build/ui/bridge/TokenCard.js.map +1 -0
- package/build/ui/connect/AuthPopup.js +1 -1
- package/build/ui/connect/AuthPopup.js.map +1 -1
- package/build/ui/connect/ConnectWallet.d.ts +7 -2
- package/build/ui/connect/ConnectWallet.js +7 -7
- package/build/ui/connect/ConnectWallet.js.map +1 -1
- package/build/ui/connect/PrimaryWallet.d.ts +6 -0
- package/build/ui/connect/PrimaryWallet.js +18 -0
- package/build/ui/connect/PrimaryWallet.js.map +1 -0
- package/build/ui/connect/WCRequest.js +1 -1
- package/build/ui/connect/WCRequest.js.map +1 -1
- package/build/ui/connect/WalletPicker.js +1 -1
- package/build/ui/connect/WalletPicker.js.map +1 -1
- package/build/ui/icons/arrow-right.d.ts +3 -1
- package/build/ui/icons/arrow-right.js +3 -3
- package/build/ui/icons/arrow-right.js.map +1 -1
- package/build/ui/icons/close.js +1 -1
- package/build/ui/icons/close.js.map +1 -1
- package/build/ui/icons/exchange.d.ts +3 -4
- package/build/ui/icons/exchange.js +2 -2
- package/build/ui/icons/exchange.js.map +1 -1
- package/build/ui/icons/logout.js +1 -1
- package/build/ui/icons/logout.js.map +1 -1
- package/build/ui/icons/pending.js +1 -1
- package/build/ui/icons/pending.js.map +1 -1
- package/build/ui/icons/plus.d.ts +2 -0
- package/build/ui/icons/plus.js +6 -0
- package/build/ui/icons/plus.js.map +1 -0
- package/build/ui/icons/qr.js +1 -1
- package/build/ui/icons/qr.js.map +1 -1
- package/build/ui/icons/refresh.d.ts +2 -0
- package/build/ui/icons/refresh.js +6 -0
- package/build/ui/icons/refresh.js.map +1 -0
- package/build/ui/icons/search.js +1 -1
- package/build/ui/icons/search.js.map +1 -1
- package/build/ui/icons/switch.js +1 -1
- package/build/ui/icons/switch.js.map +1 -1
- package/build/ui/icons/wallet.js +1 -1
- package/build/ui/icons/wallet.js.map +1 -1
- package/build/ui/{payment → profile}/DepositQR.js.map +1 -1
- package/build/ui/profile/Payment.d.ts +23 -0
- package/build/ui/profile/Payment.js +150 -0
- package/build/ui/profile/Payment.js.map +1 -0
- package/build/ui/profile/Profile.d.ts +7 -0
- package/build/ui/profile/Profile.js +135 -0
- package/build/ui/profile/Profile.js.map +1 -0
- package/build/ui/router.d.ts +19 -5
- package/build/ui/router.js +21 -9
- package/build/ui/router.js.map +1 -1
- package/build/ui/styles.js +4 -11
- package/build/ui/styles.js.map +1 -1
- package/build/ui/uikit/Stepper.d.ts +13 -0
- package/build/ui/uikit/Stepper.js +22 -0
- package/build/ui/uikit/Stepper.js.map +1 -0
- package/build/ui/uikit/Toast.d.ts +4 -0
- package/build/ui/uikit/Toast.js +33 -0
- package/build/ui/uikit/Toast.js.map +1 -0
- package/build/ui/uikit/button.d.ts +2 -0
- package/build/ui/uikit/button.js +52 -0
- package/build/ui/uikit/button.js.map +1 -0
- package/build/ui/uikit/image.d.ts +6 -0
- package/build/ui/uikit/image.js +38 -0
- package/build/ui/uikit/image.js.map +1 -0
- package/build/ui/uikit/loader.d.ts +2 -0
- package/build/ui/uikit/loader.js +50 -0
- package/build/ui/uikit/loader.js.map +1 -0
- package/build/ui/uikit/tabs.d.ts +12 -0
- package/build/ui/uikit/tabs.js +35 -0
- package/build/ui/uikit/tabs.js.map +1 -0
- package/build/ui/uikit/text.d.ts +6 -0
- package/build/ui/uikit/text.js +59 -0
- package/build/ui/uikit/text.js.map +1 -0
- package/build/ui/utils.d.ts +1 -0
- package/build/ui/utils.js +20 -0
- package/build/ui/utils.js.map +1 -0
- package/package.json +8 -4
- package/src/HotConnector.ts +24 -31
- package/src/OmniConnector.ts +10 -9
- package/src/OmniWallet.ts +24 -25
- package/src/core/Intents.ts +222 -151
- package/src/core/api.ts +56 -10
- package/src/core/bridge.ts +3 -2
- package/src/core/index.ts +1 -1
- package/src/core/telemetry.ts +28 -0
- package/src/core/token.ts +4 -0
- package/src/core/tokens.ts +0 -9
- package/src/core/types.ts +21 -0
- package/src/core/utils.ts +17 -1
- package/src/cosmos/connector.ts +22 -26
- package/src/cosmos/wallet.ts +3 -8
- package/src/evm/connector.ts +5 -0
- package/src/evm/wallet.ts +9 -6
- package/src/exchange.ts +24 -30
- package/src/hot-wallet/google.ts +12 -5
- package/src/hot-wallet/proxy.ts +2 -2
- package/src/index.ts +3 -1
- package/src/near/connector.ts +2 -2
- package/src/{core/nearRpc.ts → near/rpc.ts} +9 -23
- package/src/near/wallet.ts +39 -31
- package/src/solana/{protocol.ts → WalletStandard.ts} +2 -4
- package/src/solana/connector.ts +9 -8
- package/src/solana/injected/solana-wallet.ts +6 -6
- package/src/solana/wallet.ts +11 -20
- package/src/stellar/connector.ts +1 -6
- package/src/stellar/wallet.ts +17 -17
- package/src/ton/connector.ts +1 -5
- package/src/ton/wallet.ts +3 -3
- package/src/tron/connector.ts +89 -0
- package/src/tron/index.ts +7 -0
- package/src/tron/wallet.ts +146 -0
- package/src/ui/Popup.tsx +12 -4
- package/src/ui/{payment → bridge}/Bridge.tsx +266 -212
- package/src/ui/{payment → bridge}/SelectRecipient.tsx +5 -4
- package/src/ui/{payment → bridge}/SelectSender.tsx +5 -5
- package/src/ui/{payment → bridge}/SelectToken.tsx +6 -4
- package/src/ui/bridge/TokenCard.tsx +99 -0
- package/src/ui/connect/AuthPopup.tsx +1 -1
- package/src/ui/connect/ConnectWallet.tsx +16 -10
- package/src/ui/connect/PrimaryWallet.tsx +65 -0
- package/src/ui/connect/WCRequest.tsx +1 -1
- package/src/ui/connect/WalletPicker.tsx +1 -1
- package/src/ui/icons/arrow-right.tsx +3 -4
- package/src/ui/icons/close.tsx +1 -1
- package/src/ui/icons/exchange.tsx +4 -11
- package/src/ui/icons/logout.tsx +4 -13
- package/src/ui/icons/pending.tsx +2 -4
- package/src/ui/icons/plus.tsx +12 -0
- package/src/ui/icons/qr.tsx +1 -2
- package/src/ui/icons/refresh.tsx +20 -0
- package/src/ui/icons/search.tsx +4 -4
- package/src/ui/icons/switch.tsx +4 -4
- package/src/ui/icons/wallet.tsx +2 -4
- package/src/ui/profile/Payment.tsx +309 -0
- package/src/ui/{payment → profile}/Profile.tsx +110 -70
- package/src/ui/router.tsx +57 -17
- package/src/ui/styles.ts +4 -11
- package/src/ui/uikit/Stepper.tsx +50 -0
- package/src/ui/uikit/Toast.tsx +45 -0
- package/src/ui/uikit/button.tsx +53 -0
- package/src/ui/uikit/image.tsx +45 -0
- package/src/ui/uikit/loader.tsx +52 -0
- package/src/ui/uikit/tabs.tsx +56 -0
- package/src/ui/uikit/text.tsx +64 -0
- package/src/ui/utils.ts +14 -0
- package/build/core/nearRpc.js.map +0 -1
- package/build/solana/protocol.js.map +0 -1
- package/build/solana/wallets.js.map +0 -1
- package/build/ui/payment/Bridge.js +0 -358
- package/build/ui/payment/Bridge.js.map +0 -1
- package/build/ui/payment/Payment.d.ts +0 -16
- package/build/ui/payment/Payment.js +0 -50
- package/build/ui/payment/Payment.js.map +0 -1
- package/build/ui/payment/Profile.d.ts +0 -8
- package/build/ui/payment/Profile.js +0 -110
- package/build/ui/payment/Profile.js.map +0 -1
- package/build/ui/payment/SelectRecipient.js.map +0 -1
- package/build/ui/payment/SelectSender.js.map +0 -1
- package/build/ui/payment/SelectToken.js.map +0 -1
- package/build/ui/payment/TokenCard.js +0 -63
- package/build/ui/payment/TokenCard.js.map +0 -1
- package/src/ui/payment/Payment.tsx +0 -79
- package/src/ui/payment/TokenCard.tsx +0 -98
- package/build/solana/{wallets.d.ts → walletStandartList.d.ts} +0 -0
- package/build/ui/{payment → bridge}/Bridge.d.ts +3 -3
- package/build/ui/{payment → bridge}/SelectRecipient.d.ts +0 -0
- package/build/ui/{payment → bridge}/SelectSender.d.ts +2 -2
- package/build/ui/{payment → bridge}/SelectToken.d.ts +1 -1
- /package/build/ui/{payment → profile}/DepositQR.d.ts +0 -0
- /package/build/ui/{payment → profile}/DepositQR.js +0 -0
- /package/src/solana/{wallets.ts → walletStandartList.ts} +0 -0
- /package/src/ui/{payment → profile}/DepositQR.tsx +0 -0
|
@@ -1,42 +1,27 @@
|
|
|
1
1
|
import { JsonRpcProvider } from "@near-js/providers";
|
|
2
2
|
import { getErrorTypeFromErrorMessage, parseRpcError } from "@near-js/utils";
|
|
3
3
|
import { TypedError, FinalExecutionOutcome } from "@near-js/types";
|
|
4
|
+
import { base64 } from "@scure/base";
|
|
5
|
+
|
|
6
|
+
import { api, NetworkError, TimeoutNetworkError } from "../core/api";
|
|
7
|
+
import { Network } from "../core";
|
|
4
8
|
|
|
5
9
|
let _nextId = 123;
|
|
6
10
|
|
|
7
11
|
export const TGAS = 1_000_000_000_000n;
|
|
8
12
|
|
|
9
|
-
class NetworkError extends Error {
|
|
10
|
-
constructor(status: number, title: string, message: string) {
|
|
11
|
-
super(`${status} ${title}: ${message}`);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
class TimeoutNetworkError extends NetworkError {
|
|
16
|
-
constructor(title: string) {
|
|
17
|
-
super(0, title, "Timeout error");
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
13
|
const wait = (timeout: number) => {
|
|
22
14
|
return new Promise<void>((resolve) => setTimeout(resolve, timeout));
|
|
23
15
|
};
|
|
24
16
|
|
|
25
|
-
const
|
|
26
|
-
export const rpcProviders = [
|
|
27
|
-
c1 ? "https://c1.rpc.fastnear.com" : "https://c2.rpc.fastnear.com",
|
|
28
|
-
c1 ? "https://c2.rpc.fastnear.com" : "https://c1.rpc.fastnear.com",
|
|
29
|
-
"https://relmn.aurora.dev",
|
|
30
|
-
"https://nearrpc.aurora.dev",
|
|
31
|
-
"https://archival-rpc.mainnet.near.org",
|
|
32
|
-
];
|
|
17
|
+
const rpcUrls = [api.getRpcUrl(Network.Near), "https://relmn.aurora.dev", "https://archival-rpc.mainnet.near.org", "https://rpc-near.hapi.mobi", "https://nearrpc.aurora.dev"];
|
|
33
18
|
|
|
34
19
|
export class NearRpc extends JsonRpcProvider {
|
|
35
20
|
public providers: string[];
|
|
36
21
|
public currentProviderIndex = 0;
|
|
37
22
|
public startTimeout;
|
|
38
23
|
|
|
39
|
-
constructor(providers =
|
|
24
|
+
constructor(providers = rpcUrls, private timeout = 30_000, private triesCountForEveryProvider = 3, private incrementTimout = true) {
|
|
40
25
|
super({ url: "" });
|
|
41
26
|
this.currentProviderIndex = 0;
|
|
42
27
|
this.providers = providers;
|
|
@@ -44,7 +29,7 @@ export class NearRpc extends JsonRpcProvider {
|
|
|
44
29
|
}
|
|
45
30
|
|
|
46
31
|
async viewMethod(args: { contractId: string; methodName: string; args: any }) {
|
|
47
|
-
const payload =
|
|
32
|
+
const payload = base64.encode(new TextEncoder().encode(JSON.stringify(args.args)));
|
|
48
33
|
const data: any = await rpc.query({
|
|
49
34
|
args_base64: payload,
|
|
50
35
|
finality: "optimistic",
|
|
@@ -97,7 +82,7 @@ export class NearRpc extends JsonRpcProvider {
|
|
|
97
82
|
|
|
98
83
|
const req = await fetch(url, {
|
|
99
84
|
body: JSON.stringify({ method, params, id: _nextId++, jsonrpc: "2.0" }),
|
|
100
|
-
headers: { "Content-Type": "application/json" },
|
|
85
|
+
headers: { "Content-Type": "application/json", "Api-Key": api.apiKey },
|
|
101
86
|
signal: controller.signal,
|
|
102
87
|
method: "POST",
|
|
103
88
|
}).catch(() => {
|
|
@@ -136,6 +121,7 @@ export class NearRpc extends JsonRpcProvider {
|
|
|
136
121
|
if (isTimeout) {
|
|
137
122
|
throw new TypedError(errorMessage, "TimeoutError");
|
|
138
123
|
}
|
|
124
|
+
|
|
139
125
|
const type = getErrorTypeFromErrorMessage(response.error.data, response.error.name);
|
|
140
126
|
throw new TypedError(errorMessage, type);
|
|
141
127
|
}
|
package/src/near/wallet.ts
CHANGED
|
@@ -1,30 +1,25 @@
|
|
|
1
1
|
import { NearWalletBase, SignMessageParams, SignedMessage, SignAndSendTransactionParams } from "@hot-labs/near-connect";
|
|
2
2
|
import { base64, base58 } from "@scure/base";
|
|
3
3
|
|
|
4
|
-
import { OmniConnector } from "../OmniConnector";
|
|
5
4
|
import { OmniWallet } from "../OmniWallet";
|
|
6
5
|
import { WalletType } from "../core/chains";
|
|
7
6
|
import { ReviewFee } from "../core/bridge";
|
|
8
|
-
import { rpc, TGAS } from "
|
|
7
|
+
import { rpc, TGAS } from "./rpc";
|
|
9
8
|
import { Token } from "../core/token";
|
|
10
9
|
import { Commitment } from "../core";
|
|
11
10
|
|
|
12
11
|
export default class NearWallet extends OmniWallet {
|
|
12
|
+
readonly icon = "https://storage.herewallet.app/upload/73a44e583769f11112b0eff1f2dd2a560c05eed5f6d92f0c03484fa047c31668.png";
|
|
13
13
|
readonly type = WalletType.NEAR;
|
|
14
14
|
|
|
15
|
-
constructor(readonly
|
|
16
|
-
super(
|
|
15
|
+
constructor(readonly address: string, readonly publicKey?: string, readonly wallet?: NearWalletBase) {
|
|
16
|
+
super();
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
get omniAddress() {
|
|
20
20
|
return this.address;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
async disconnect() {
|
|
24
|
-
await this.wallet?.signOut();
|
|
25
|
-
super.disconnect();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
23
|
async fetchBalances(_: number, whitelist: string[]): Promise<Record<string, bigint>> {
|
|
29
24
|
const balances = await Promise.all(
|
|
30
25
|
whitelist.map(async (token) => {
|
|
@@ -167,6 +162,40 @@ export default class NearWallet extends OmniWallet {
|
|
|
167
162
|
return await this.sendTransaction({ receiverId: args.token.address, actions });
|
|
168
163
|
}
|
|
169
164
|
|
|
165
|
+
async isIntentAccountRegistered() {
|
|
166
|
+
const keys = await rpc.viewMethod({
|
|
167
|
+
contractId: "intents.near",
|
|
168
|
+
methodName: "public_keys_of",
|
|
169
|
+
args: { account_id: this.address },
|
|
170
|
+
});
|
|
171
|
+
return keys.includes(this.publicKey);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async registerIntentAccountIfNeeded() {
|
|
175
|
+
let isRegistered = await this.isIntentAccountRegistered();
|
|
176
|
+
if (isRegistered) return;
|
|
177
|
+
|
|
178
|
+
await this.sendTransaction({
|
|
179
|
+
receiverId: "intents.near",
|
|
180
|
+
actions: [
|
|
181
|
+
{
|
|
182
|
+
type: "FunctionCall",
|
|
183
|
+
params: {
|
|
184
|
+
methodName: "add_public_key",
|
|
185
|
+
args: { public_key: this.publicKey },
|
|
186
|
+
gas: String(80n * TGAS),
|
|
187
|
+
deposit: String(1n),
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
}).catch(() => null);
|
|
192
|
+
|
|
193
|
+
isRegistered = await this.isIntentAccountRegistered();
|
|
194
|
+
if (isRegistered) return;
|
|
195
|
+
|
|
196
|
+
throw new Error("Failed to register intent account");
|
|
197
|
+
}
|
|
198
|
+
|
|
170
199
|
async signIntents(intents: Record<string, any>[], options?: { nonce?: Uint8Array; deadline?: number }): Promise<Commitment> {
|
|
171
200
|
if (!this.wallet) throw "not impl";
|
|
172
201
|
|
|
@@ -181,28 +210,7 @@ export default class NearWallet extends OmniWallet {
|
|
|
181
210
|
if (!result) throw new Error("Failed to sign message");
|
|
182
211
|
const { signature, publicKey } = result;
|
|
183
212
|
|
|
184
|
-
|
|
185
|
-
contractId: "intents.near",
|
|
186
|
-
methodName: "public_keys_of",
|
|
187
|
-
args: { account_id: this.address },
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
if (!keys.includes(publicKey)) {
|
|
191
|
-
await this.sendTransaction({
|
|
192
|
-
receiverId: "intents.near",
|
|
193
|
-
actions: [
|
|
194
|
-
{
|
|
195
|
-
type: "FunctionCall",
|
|
196
|
-
params: {
|
|
197
|
-
methodName: "add_public_key",
|
|
198
|
-
args: { public_key: publicKey },
|
|
199
|
-
gas: String(80n * TGAS),
|
|
200
|
-
deposit: String(1n),
|
|
201
|
-
},
|
|
202
|
-
},
|
|
203
|
-
],
|
|
204
|
-
});
|
|
205
|
-
}
|
|
213
|
+
await this.registerIntentAccountIfNeeded();
|
|
206
214
|
|
|
207
215
|
return {
|
|
208
216
|
standard: "nep413",
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { Connection, Transaction, VersionedTransaction } from "@solana/web3.js";
|
|
2
|
-
import { SolanaSignAndSendTransactionMethod, SolanaSignMessageMethod, SolanaSignTransactionMethod } from "@solana/wallet-standard-features";
|
|
3
2
|
import type { Wallet } from "@wallet-standard/base";
|
|
4
|
-
import { base58 } from "@scure/base";
|
|
5
3
|
|
|
6
4
|
export interface ISolanaProtocolWallet {
|
|
7
5
|
address: string;
|
|
@@ -41,7 +39,7 @@ class SolanaProtocolWallet implements ISolanaProtocolWallet {
|
|
|
41
39
|
async sendTransaction(transaction: Transaction | VersionedTransaction, connection: Connection, options?: any): Promise<string> {
|
|
42
40
|
const account = await this.getAccount();
|
|
43
41
|
const features = this.wallet.features as any;
|
|
44
|
-
const signTx = features["solana:signTransaction"]?.signTransaction
|
|
42
|
+
const signTx = features["solana:signTransaction"]?.signTransaction;
|
|
45
43
|
const [signed] = await signTx({ account, chain: account.chains[0], transaction: transaction.serialize() });
|
|
46
44
|
const signedTx = signed.signedTransaction as Transaction | VersionedTransaction | Uint8Array;
|
|
47
45
|
const raw = signedTx instanceof Uint8Array ? signedTx : (signedTx as any).serialize();
|
|
@@ -52,7 +50,7 @@ class SolanaProtocolWallet implements ISolanaProtocolWallet {
|
|
|
52
50
|
async signMessage(message: string) {
|
|
53
51
|
const account = await this.getAccount();
|
|
54
52
|
const features = this.wallet.features as any;
|
|
55
|
-
const signMessageFeature = features["solana:signMessage"]?.signMessage
|
|
53
|
+
const signMessageFeature = features["solana:signMessage"]?.signMessage;
|
|
56
54
|
|
|
57
55
|
if (!signMessageFeature) throw new Error("Wallet does not support solana:signMessage");
|
|
58
56
|
const [result] = await signMessageFeature({ account, message: new TextEncoder().encode(message) });
|
package/src/solana/connector.ts
CHANGED
|
@@ -9,8 +9,8 @@ import { OmniWallet } from "../OmniWallet";
|
|
|
9
9
|
import { WalletType } from "../core/chains";
|
|
10
10
|
import HOT from "../hot-wallet/iframe";
|
|
11
11
|
|
|
12
|
-
import SolanaProtocolWallet from "./
|
|
13
|
-
import { getWallets } from "./
|
|
12
|
+
import SolanaProtocolWallet from "./WalletStandard";
|
|
13
|
+
import { getWallets } from "./walletStandartList";
|
|
14
14
|
import SolanaWallet from "./wallet";
|
|
15
15
|
|
|
16
16
|
const wallets = getWallets();
|
|
@@ -36,7 +36,7 @@ class SolanaConnector extends OmniConnector<SolanaWallet, { wallet: Wallet }> {
|
|
|
36
36
|
const wallet = this.options.find((w) => w.id === id);
|
|
37
37
|
if (!wallet) return;
|
|
38
38
|
const protocolWallet = await SolanaProtocolWallet.connect(wallet.wallet, { silent: true });
|
|
39
|
-
this.setWallet(new SolanaWallet(
|
|
39
|
+
this.setWallet(new SolanaWallet(protocolWallet));
|
|
40
40
|
} catch {
|
|
41
41
|
this.removeStorage();
|
|
42
42
|
}
|
|
@@ -59,7 +59,7 @@ class SolanaConnector extends OmniConnector<SolanaWallet, { wallet: Wallet }> {
|
|
|
59
59
|
const connected = await this.getConnectedWallet();
|
|
60
60
|
if (connected !== wallet.name) return;
|
|
61
61
|
const protocolWallet = await SolanaProtocolWallet.connect(wallet, { silent: true });
|
|
62
|
-
this.setWallet(new SolanaWallet(
|
|
62
|
+
this.setWallet(new SolanaWallet(protocolWallet));
|
|
63
63
|
} catch {
|
|
64
64
|
this.removeStorage();
|
|
65
65
|
}
|
|
@@ -88,7 +88,7 @@ class SolanaConnector extends OmniConnector<SolanaWallet, { wallet: Wallet }> {
|
|
|
88
88
|
|
|
89
89
|
this.setStorage({ type: "walletconnect" });
|
|
90
90
|
return this.setWallet(
|
|
91
|
-
new SolanaWallet(
|
|
91
|
+
new SolanaWallet({
|
|
92
92
|
address: account,
|
|
93
93
|
sendTransaction: async (tx: Transaction | VersionedTransaction, connection: Connection, options?: any) => {
|
|
94
94
|
const transaction = Buffer.from(tx.serialize()).toString("base64");
|
|
@@ -112,8 +112,9 @@ class SolanaConnector extends OmniConnector<SolanaWallet, { wallet: Wallet }> {
|
|
|
112
112
|
);
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
async
|
|
116
|
-
|
|
115
|
+
async disconnect() {
|
|
116
|
+
this.wallets.forEach((w) => w.wallet.disconnect?.());
|
|
117
|
+
super.disconnect();
|
|
117
118
|
}
|
|
118
119
|
|
|
119
120
|
async getConnectedWallet() {
|
|
@@ -142,7 +143,7 @@ class SolanaConnector extends OmniConnector<SolanaWallet, { wallet: Wallet }> {
|
|
|
142
143
|
try {
|
|
143
144
|
this.setStorage({ type: "wallet", id });
|
|
144
145
|
const protocolWallet = await SolanaProtocolWallet.connect(wallet.wallet, { silent: false });
|
|
145
|
-
return this.setWallet(new SolanaWallet(
|
|
146
|
+
return this.setWallet(new SolanaWallet(protocolWallet));
|
|
146
147
|
} catch (e) {
|
|
147
148
|
this.removeStorage();
|
|
148
149
|
throw e;
|
|
@@ -110,7 +110,7 @@ export class GhostWallet implements Wallet {
|
|
|
110
110
|
this._connected();
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
_on: StandardEventsOnMethod = (event, listener) => {
|
|
113
|
+
_on: StandardEventsOnMethod = (event: StandardEventsNames, listener: StandardEventsListeners[StandardEventsNames]) => {
|
|
114
114
|
this._listeners[event]?.push(listener) || (this._listeners[event] = [listener]);
|
|
115
115
|
return (): void => this._off(event, listener);
|
|
116
116
|
};
|
|
@@ -152,7 +152,7 @@ export class GhostWallet implements Wallet {
|
|
|
152
152
|
}
|
|
153
153
|
};
|
|
154
154
|
|
|
155
|
-
_connect: StandardConnectMethod = async ({ silent } = {}) => {
|
|
155
|
+
_connect: StandardConnectMethod = async ({ silent }: { silent?: boolean } = {}) => {
|
|
156
156
|
if (!this._account) await this._ghost.connect(silent ? { onlyIfTrusted: true } : undefined);
|
|
157
157
|
this._connected();
|
|
158
158
|
return { accounts: this.accounts };
|
|
@@ -162,7 +162,7 @@ export class GhostWallet implements Wallet {
|
|
|
162
162
|
await this._ghost.disconnect();
|
|
163
163
|
};
|
|
164
164
|
|
|
165
|
-
_signAndSendTransaction: SolanaSignAndSendTransactionMethod = async (...inputs) => {
|
|
165
|
+
_signAndSendTransaction: SolanaSignAndSendTransactionMethod = async (...inputs: any[]) => {
|
|
166
166
|
if (!this._account) throw new Error("not connected");
|
|
167
167
|
|
|
168
168
|
const outputs: SolanaSignAndSendTransactionOutput[] = [];
|
|
@@ -189,7 +189,7 @@ export class GhostWallet implements Wallet {
|
|
|
189
189
|
return outputs;
|
|
190
190
|
};
|
|
191
191
|
|
|
192
|
-
_signTransaction: SolanaSignTransactionMethod = async (...inputs) => {
|
|
192
|
+
_signTransaction: SolanaSignTransactionMethod = async (...inputs: any[]) => {
|
|
193
193
|
if (!this._account) throw new Error("not connected");
|
|
194
194
|
|
|
195
195
|
const outputs: SolanaSignTransactionOutput[] = [];
|
|
@@ -243,7 +243,7 @@ export class GhostWallet implements Wallet {
|
|
|
243
243
|
return outputs;
|
|
244
244
|
};
|
|
245
245
|
|
|
246
|
-
_signMessage: SolanaSignMessageMethod = async (...inputs) => {
|
|
246
|
+
_signMessage: SolanaSignMessageMethod = async (...inputs: any[]) => {
|
|
247
247
|
if (!this._account) throw new Error("not connected");
|
|
248
248
|
|
|
249
249
|
const outputs: SolanaSignMessageOutput[] = [];
|
|
@@ -264,7 +264,7 @@ export class GhostWallet implements Wallet {
|
|
|
264
264
|
return outputs;
|
|
265
265
|
};
|
|
266
266
|
|
|
267
|
-
_signIn: SolanaSignInMethod = async (...inputs) => {
|
|
267
|
+
_signIn: SolanaSignInMethod = async (...inputs: any[]) => {
|
|
268
268
|
const outputs: SolanaSignInOutput[] = [];
|
|
269
269
|
|
|
270
270
|
if (inputs.length > 1) {
|
package/src/solana/wallet.ts
CHANGED
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
} from "@solana/spl-token";
|
|
15
15
|
|
|
16
16
|
import { Network, WalletType } from "../core/chains";
|
|
17
|
-
import { OmniConnector } from "../OmniConnector";
|
|
18
17
|
import { OmniWallet } from "../OmniWallet";
|
|
19
18
|
|
|
20
19
|
import { Token } from "../core/token";
|
|
@@ -23,13 +22,14 @@ import { ReviewFee } from "../core/bridge";
|
|
|
23
22
|
import { Commitment } from "../core";
|
|
24
23
|
import { api } from "../core/api";
|
|
25
24
|
|
|
26
|
-
import { ISolanaProtocolWallet } from "./
|
|
25
|
+
import { ISolanaProtocolWallet } from "./WalletStandard";
|
|
27
26
|
|
|
28
27
|
class SolanaWallet extends OmniWallet {
|
|
28
|
+
readonly icon = "https://storage.herewallet.app/upload/8700f33153ad813e133e5bf9b791b5ecbeea66edca6b8d17aeccb8048eb29ef7.png";
|
|
29
29
|
readonly type = WalletType.SOLANA;
|
|
30
30
|
|
|
31
|
-
constructor(readonly
|
|
32
|
-
super(
|
|
31
|
+
constructor(readonly wallet: ISolanaProtocolWallet) {
|
|
32
|
+
super();
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
getConnection() {
|
|
@@ -63,12 +63,7 @@ class SolanaWallet extends OmniWallet {
|
|
|
63
63
|
return BigInt(meta.value.amount);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
async
|
|
67
|
-
await this.wallet.disconnect?.();
|
|
68
|
-
super.disconnect();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async buildTranferInstructions(token: Token, amount: bigint, receiver: string, fee?: ReviewFee) {
|
|
66
|
+
async buildTranferInstructions(token: Token, amount: bigint, receiver: string, fee: ReviewFee) {
|
|
72
67
|
const destination = new PublicKey(receiver);
|
|
73
68
|
const owner = new PublicKey(this.address);
|
|
74
69
|
const connection = this.getConnection();
|
|
@@ -81,10 +76,10 @@ class SolanaWallet extends OmniWallet {
|
|
|
81
76
|
reserve,
|
|
82
77
|
additionalFee,
|
|
83
78
|
instructions: [
|
|
84
|
-
|
|
85
|
-
|
|
79
|
+
ComputeBudgetProgram.setComputeUnitPrice({ microLamports: Number(fee.priorityFee) }),
|
|
80
|
+
ComputeBudgetProgram.setComputeUnitLimit({ units: Number(fee.gasLimit) }),
|
|
86
81
|
SystemProgram.transfer({ fromPubkey: owner, toPubkey: destination, lamports: amount }),
|
|
87
|
-
]
|
|
82
|
+
],
|
|
88
83
|
};
|
|
89
84
|
}
|
|
90
85
|
|
|
@@ -95,11 +90,7 @@ class SolanaWallet extends OmniWallet {
|
|
|
95
90
|
const tokenFrom = getAssociatedTokenAddressSync(mint, owner, false, tokenProgramId);
|
|
96
91
|
const tokenTo = getAssociatedTokenAddressSync(mint, destination, false, tokenProgramId);
|
|
97
92
|
|
|
98
|
-
const instructions: TransactionInstruction[] = [];
|
|
99
|
-
if (fee) {
|
|
100
|
-
instructions.push(ComputeBudgetProgram.setComputeUnitPrice({ microLamports: Number(fee.baseFee) }));
|
|
101
|
-
instructions.push(ComputeBudgetProgram.setComputeUnitLimit({ units: Number(fee.gasLimit) }));
|
|
102
|
-
}
|
|
93
|
+
const instructions: TransactionInstruction[] = [ComputeBudgetProgram.setComputeUnitPrice({ microLamports: Number(fee.baseFee) }), ComputeBudgetProgram.setComputeUnitLimit({ units: Number(fee.gasLimit) })];
|
|
103
94
|
|
|
104
95
|
const isRegistered = await getAccount(connection, tokenTo, "confirmed", tokenProgramId).catch(() => null);
|
|
105
96
|
if (isRegistered == null) {
|
|
@@ -156,7 +147,7 @@ class SolanaWallet extends OmniWallet {
|
|
|
156
147
|
}
|
|
157
148
|
|
|
158
149
|
async getPriorityFeeEstimate(params: any): Promise<any> {
|
|
159
|
-
const response = await fetch("
|
|
150
|
+
const response = await fetch(api.baseUrl + "/api/v1/evm/helius/staked", {
|
|
160
151
|
body: JSON.stringify({ jsonrpc: "2.0", id: "helius-sdk", method: "getPriorityFeeEstimate", params: [params] }),
|
|
161
152
|
headers: { "Content-Type": "application/json" },
|
|
162
153
|
method: "POST",
|
|
@@ -169,7 +160,7 @@ class SolanaWallet extends OmniWallet {
|
|
|
169
160
|
return result;
|
|
170
161
|
}
|
|
171
162
|
|
|
172
|
-
async transfer(args: { token: Token; receiver: string; amount: bigint; comment?: string; gasFee
|
|
163
|
+
async transfer(args: { token: Token; receiver: string; amount: bigint; comment?: string; gasFee: ReviewFee }): Promise<string> {
|
|
173
164
|
const { instructions } = await this.buildTranferInstructions(args.token, args.amount, args.receiver, args.gasFee);
|
|
174
165
|
return await this.sendTransaction(instructions);
|
|
175
166
|
}
|
package/src/stellar/connector.ts
CHANGED
|
@@ -4,7 +4,6 @@ import HOT from "../hot-wallet/iframe";
|
|
|
4
4
|
import { WalletType } from "../core/chains";
|
|
5
5
|
import { HotConnector } from "../HotConnector";
|
|
6
6
|
import { ConnectorType, OmniConnector } from "../OmniConnector";
|
|
7
|
-
import { OmniWallet } from "../OmniWallet";
|
|
8
7
|
|
|
9
8
|
import { FreighterModule } from "./freigher";
|
|
10
9
|
import { HotWalletModule } from "./hotWallet";
|
|
@@ -45,10 +44,6 @@ class StellarConnector extends OmniConnector<StellarWallet> {
|
|
|
45
44
|
return Object.values(this.modules).find((module) => module.productId === id) || null;
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
async createWallet(address: string): Promise<OmniWallet> {
|
|
49
|
-
return new StellarWallet(this, { address });
|
|
50
|
-
}
|
|
51
|
-
|
|
52
47
|
async getConnectedWallet() {
|
|
53
48
|
if (HOT.isInjected) {
|
|
54
49
|
const { address } = await this.modules.hotWallet.getAddress();
|
|
@@ -61,7 +56,7 @@ class StellarConnector extends OmniConnector<StellarWallet> {
|
|
|
61
56
|
async selectWallet(address: string, wallet: HotWalletModule | FreighterModule) {
|
|
62
57
|
const signMessage = async (message: string) => wallet.signMessage(message);
|
|
63
58
|
const signTransaction = async (transaction: Transaction) => wallet.signTransaction(transaction.toXDR());
|
|
64
|
-
return this.setWallet(new StellarWallet(
|
|
59
|
+
return this.setWallet(new StellarWallet({ address, rpc: this.wibe3.hotBridge.stellar, signMessage, signTransaction }));
|
|
65
60
|
}
|
|
66
61
|
|
|
67
62
|
async connect(id: string) {
|
package/src/stellar/wallet.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { rpc } from "@stellar/stellar-sdk";
|
|
|
4
4
|
|
|
5
5
|
import { WalletType } from "../core/chains";
|
|
6
6
|
import { OmniWallet } from "../OmniWallet";
|
|
7
|
-
import { OmniConnector } from "../OmniConnector";
|
|
8
7
|
import { ReviewFee } from "../core/bridge";
|
|
9
8
|
import { formatter } from "../core/utils";
|
|
10
9
|
import { Network } from "../core/chains";
|
|
@@ -12,9 +11,13 @@ import { Token } from "../core/token";
|
|
|
12
11
|
import { Commitment } from "../core";
|
|
13
12
|
|
|
14
13
|
interface ProtocolWallet {
|
|
14
|
+
address: string;
|
|
15
15
|
signTransaction?: (transaction: Transaction) => Promise<{ signedTxXdr: string }>;
|
|
16
16
|
signMessage?: (message: string) => Promise<{ signedMessage: string }>;
|
|
17
|
-
|
|
17
|
+
rpc: {
|
|
18
|
+
callSoroban: (callback: (s: any) => Promise<any>) => Promise<any>;
|
|
19
|
+
callHorizon: (callback: (h: any) => Promise<any>) => Promise<any>;
|
|
20
|
+
};
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
export const ACCOUNT_FOR_SIMULATE = "GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7";
|
|
@@ -28,14 +31,11 @@ export enum ASSET_CONTRACT_METHOD {
|
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
class StellarWallet extends OmniWallet {
|
|
34
|
+
readonly icon = "https://storage.herewallet.app/upload/1469894e53ca248ac6adceb2194e6950a13a52d972beb378a20bce7815ba01a4.png";
|
|
31
35
|
readonly type = WalletType.STELLAR;
|
|
32
36
|
|
|
33
|
-
constructor(readonly
|
|
34
|
-
super(
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
get rpc() {
|
|
38
|
-
return this.connector.wibe3.hotBridge.stellar;
|
|
37
|
+
constructor(readonly wallet: ProtocolWallet) {
|
|
38
|
+
super();
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
get address() {
|
|
@@ -86,8 +86,8 @@ class StellarWallet extends OmniWallet {
|
|
|
86
86
|
const asset = await this.getAssetFromContractId(token);
|
|
87
87
|
const sendAmount = formatter.formatAmount(amount, 7);
|
|
88
88
|
|
|
89
|
-
const account = await this.
|
|
90
|
-
const baseFee = await this.
|
|
89
|
+
const account = await this.wallet.rpc.callSoroban((s) => s.getAccount(this.address));
|
|
90
|
+
const baseFee = await this.wallet.rpc.callHorizon((h) => h.fetchBaseFee()).catch(() => +BASE_FEE);
|
|
91
91
|
const builder = new TransactionBuilder(account, {
|
|
92
92
|
memo: memo ? Memo.text(memo) : undefined,
|
|
93
93
|
networkPassphrase: Networks.PUBLIC,
|
|
@@ -106,13 +106,13 @@ class StellarWallet extends OmniWallet {
|
|
|
106
106
|
)
|
|
107
107
|
);
|
|
108
108
|
|
|
109
|
-
const tx = await this.rpc.callSoroban((s) => s.prepareTransaction(builder.build() as any));
|
|
109
|
+
const tx = await this.wallet.rpc.callSoroban((s) => s.prepareTransaction(builder.build() as any));
|
|
110
110
|
const fee = BigInt(Math.floor(baseFee * tx.operations.length));
|
|
111
111
|
return { fee: new ReviewFee({ baseFee: fee, priorityFee: 0n, gasLimit: 1n, chain: Network.Stellar }), tx: tx as unknown as Transaction };
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
let needXlm = 0;
|
|
115
|
-
const receiverAccount = await this.rpc.callHorizon((h) => h.loadAccount(receiver)).catch(() => null);
|
|
115
|
+
const receiverAccount = await this.wallet.rpc.callHorizon((h) => h.loadAccount(receiver)).catch(() => null);
|
|
116
116
|
const claimableBalance = Operation.createClaimableBalance({ amount: amount.toString(), claimants: [new Claimant(receiver)], asset });
|
|
117
117
|
|
|
118
118
|
if (receiverAccount == null) {
|
|
@@ -154,7 +154,7 @@ class StellarWallet extends OmniWallet {
|
|
|
154
154
|
if (!this.wallet.signTransaction) throw "not impl";
|
|
155
155
|
const result = await this.wallet.signTransaction(transaction);
|
|
156
156
|
const txObject = new Transaction(result.signedTxXdr, Networks.PUBLIC);
|
|
157
|
-
const { hash } = await this.rpc.callHorizon((t) => t.submitTransaction(txObject as any));
|
|
157
|
+
const { hash } = await this.wallet.rpc.callHorizon((t) => t.submitTransaction(txObject as any));
|
|
158
158
|
return hash;
|
|
159
159
|
}
|
|
160
160
|
|
|
@@ -197,7 +197,7 @@ class StellarWallet extends OmniWallet {
|
|
|
197
197
|
async changeTrustline(address: string) {
|
|
198
198
|
if (address === "native") return;
|
|
199
199
|
const asset = await this.getAssetFromContractId(address);
|
|
200
|
-
const account = await this.rpc.callHorizon((h) => h.loadAccount(this.address));
|
|
200
|
+
const account = await this.wallet.rpc.callHorizon((h) => h.loadAccount(this.address));
|
|
201
201
|
const trustlineOp = Operation.changeTrust({ asset: asset, source: this.address });
|
|
202
202
|
const trustlineTx = new TransactionBuilder(account, { fee: BASE_FEE, networkPassphrase: Networks.PUBLIC }) //
|
|
203
203
|
.addOperation(trustlineOp)
|
|
@@ -215,7 +215,7 @@ class StellarWallet extends OmniWallet {
|
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
const tx = await this.buildSmartContactTx(ACCOUNT_FOR_SIMULATE, id, ASSET_CONTRACT_METHOD.NAME);
|
|
218
|
-
const result = (await this.rpc.callSoroban((s) => s.simulateTransaction(tx as any))) as unknown as rpc.Api.SimulateTransactionSuccessResponse;
|
|
218
|
+
const result = (await this.wallet.rpc.callSoroban((s) => s.simulateTransaction(tx as any))) as unknown as rpc.Api.SimulateTransactionSuccessResponse;
|
|
219
219
|
|
|
220
220
|
const value = result?.result?.retval?.value();
|
|
221
221
|
if (!value) throw "Asset not found";
|
|
@@ -227,7 +227,7 @@ class StellarWallet extends OmniWallet {
|
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
async buildSmartContactTx(publicKey: string, contactId: string, method: string, ...args: any[]) {
|
|
230
|
-
const account = await this.rpc.callSoroban((s) => s.getAccount(publicKey));
|
|
230
|
+
const account = await this.wallet.rpc.callSoroban((s) => s.getAccount(publicKey));
|
|
231
231
|
const contract = new Contract(contactId);
|
|
232
232
|
const builtTx = new TransactionBuilder(account, { fee: BASE_FEE, networkPassphrase: Networks.PUBLIC });
|
|
233
233
|
|
|
@@ -244,7 +244,7 @@ class StellarWallet extends OmniWallet {
|
|
|
244
244
|
Address.fromString(contract).toScVal()
|
|
245
245
|
);
|
|
246
246
|
|
|
247
|
-
const result = (await this.rpc.callSoroban((s) => s.simulateTransaction(tx as any))) as unknown as rpc.Api.SimulateTransactionSuccessResponse;
|
|
247
|
+
const result = (await this.wallet.rpc.callSoroban((s) => s.simulateTransaction(tx as any))) as unknown as rpc.Api.SimulateTransactionSuccessResponse;
|
|
248
248
|
if (result) return BigInt(this.i128ToInt(result.result?.retval.value() as xdr.Int128Parts));
|
|
249
249
|
return 0n;
|
|
250
250
|
}
|
package/src/ton/connector.ts
CHANGED
|
@@ -69,7 +69,7 @@ class TonConnector extends OmniConnector<TonWallet> {
|
|
|
69
69
|
tonConnect.onStatusChange(async (wallet) => {
|
|
70
70
|
if (!wallet) return this.removeWallet();
|
|
71
71
|
this.setWallet(
|
|
72
|
-
new TonWallet(
|
|
72
|
+
new TonWallet({
|
|
73
73
|
sendTransaction: (params) => tonConnect.sendTransaction(params),
|
|
74
74
|
signData: (params) => tonConnect.signData(params),
|
|
75
75
|
account: wallet.account,
|
|
@@ -108,10 +108,6 @@ class TonConnector extends OmniConnector<TonWallet> {
|
|
|
108
108
|
return tonConnect;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
async createWallet(address: string) {
|
|
112
|
-
return new TonWallet(this, { account: { address } });
|
|
113
|
-
}
|
|
114
|
-
|
|
115
111
|
async connect(id: string) {
|
|
116
112
|
const connector = await this.tonConnect;
|
|
117
113
|
connector.openSingleWalletModal(id);
|
package/src/ton/wallet.ts
CHANGED
|
@@ -6,7 +6,6 @@ import { base58, base64, hex } from "@scure/base";
|
|
|
6
6
|
|
|
7
7
|
import { OmniWallet } from "../OmniWallet";
|
|
8
8
|
import { WalletType } from "../core/chains";
|
|
9
|
-
import { OmniConnector } from "../OmniConnector";
|
|
10
9
|
import { ReviewFee } from "../core/bridge";
|
|
11
10
|
import { Token } from "../core/token";
|
|
12
11
|
|
|
@@ -19,10 +18,11 @@ interface ProtocolWallet {
|
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
class TonWallet extends OmniWallet {
|
|
21
|
+
readonly icon = "https://storage.herewallet.app/upload/3ffa61e237f8e38d390abd60200db8edff3ec2b20aad0cc0a8c7a8ba9c318124.png";
|
|
22
22
|
readonly type = WalletType.TON;
|
|
23
23
|
|
|
24
|
-
constructor(readonly
|
|
25
|
-
super(
|
|
24
|
+
constructor(readonly wallet: ProtocolWallet) {
|
|
25
|
+
super();
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
get address() {
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { WalletType } from "../core/chains";
|
|
2
|
+
import { ConnectorType, OmniConnector } from "../OmniConnector";
|
|
3
|
+
import { HotConnector } from "../HotConnector";
|
|
4
|
+
import TronWallet from "./wallet";
|
|
5
|
+
|
|
6
|
+
declare global {
|
|
7
|
+
interface Window {
|
|
8
|
+
tronLink?: {
|
|
9
|
+
ready?: boolean;
|
|
10
|
+
request?: (args: { method: string; params?: any }) => Promise<any>;
|
|
11
|
+
tronWeb?: {
|
|
12
|
+
defaultAddress?: { base58?: string; hex?: string };
|
|
13
|
+
address?: { toHex?: (address: string) => string };
|
|
14
|
+
contract?: () => { at: (address: string) => Promise<any> };
|
|
15
|
+
trx?: {
|
|
16
|
+
getBalance?: (address: string) => Promise<number | string>;
|
|
17
|
+
sendTransaction?: (to: string, amount: number | string) => Promise<any>;
|
|
18
|
+
signMessageV2?: (message: string) => Promise<string>;
|
|
19
|
+
signMessage?: (message: string) => Promise<string>;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const TRONLINK = {
|
|
27
|
+
id: "tronlink",
|
|
28
|
+
name: "Tron Link",
|
|
29
|
+
type: window?.tronLink ? ("extension" as const) : ("external" as const),
|
|
30
|
+
icon: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png",
|
|
31
|
+
download: "https://www.tronlink.org/",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
class TronConnector extends OmniConnector<TronWallet> {
|
|
35
|
+
type = ConnectorType.WALLET;
|
|
36
|
+
walletTypes = [WalletType.Tron, WalletType.OMNI];
|
|
37
|
+
icon = "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png";
|
|
38
|
+
name = "TRON Wallet";
|
|
39
|
+
options = [TRONLINK];
|
|
40
|
+
id = "tron";
|
|
41
|
+
|
|
42
|
+
constructor(wibe3: HotConnector) {
|
|
43
|
+
super(wibe3);
|
|
44
|
+
|
|
45
|
+
this.syncFromProvider().catch(() => this.removeStorage());
|
|
46
|
+
window.addEventListener("message", () => {
|
|
47
|
+
this.syncFromProvider().catch(() => {});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private async syncFromProvider() {
|
|
52
|
+
const stored = (await this.getStorage().catch(() => ({} as any))) as { type?: string; id?: string; address?: string };
|
|
53
|
+
if (stored.type !== "wallet" || stored.id !== TRONLINK.id) return;
|
|
54
|
+
|
|
55
|
+
const tronWeb = window?.tronLink?.tronWeb;
|
|
56
|
+
const address = tronWeb?.defaultAddress?.base58;
|
|
57
|
+
if (!window?.tronLink?.ready || !address) return;
|
|
58
|
+
|
|
59
|
+
const current = this.wallets[0]?.address;
|
|
60
|
+
if (current === address) return;
|
|
61
|
+
|
|
62
|
+
if (this.wallets.length > 0) this.removeWallet();
|
|
63
|
+
await this.setStorage({ type: "wallet", id: TRONLINK.id, address });
|
|
64
|
+
this.setWallet(new TronWallet(this, address, tronWeb as any));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async connect(id: string = TRONLINK.id) {
|
|
68
|
+
if (id !== TRONLINK.id) throw new Error("Wallet not found");
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
if (this.wallets.length > 0) this.removeWallet();
|
|
72
|
+
|
|
73
|
+
const res = await window?.tronLink?.request?.({ method: "tron_requestAccounts" });
|
|
74
|
+
if (res?.code !== 200) throw new Error("Failed to connect to TronLink");
|
|
75
|
+
if (!window?.tronLink?.tronWeb) throw new Error("TronLink not found");
|
|
76
|
+
|
|
77
|
+
const address = window?.tronLink?.tronWeb?.defaultAddress?.base58;
|
|
78
|
+
if (!address) throw new Error("No account found");
|
|
79
|
+
|
|
80
|
+
await this.setStorage({ type: "wallet", id: TRONLINK.id, address });
|
|
81
|
+
return this.setWallet(new TronWallet(this, address, window.tronLink.tronWeb));
|
|
82
|
+
} catch (e) {
|
|
83
|
+
await this.removeStorage();
|
|
84
|
+
throw e;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export default TronConnector;
|