@hot-labs/kit 1.3.2 → 1.4.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/build/HotConnector.d.ts +9 -13
- package/build/HotConnector.js +17 -57
- package/build/HotConnector.js.map +1 -1
- package/build/activity.d.ts +1 -1
- package/build/activity.js +8 -8
- package/build/activity.js.map +1 -1
- package/build/core/Intents.d.ts +4 -3
- package/build/core/Intents.js +24 -4
- package/build/core/Intents.js.map +1 -1
- package/build/{OmniConnector.d.ts → core/OmniConnector.d.ts} +4 -4
- package/build/{OmniConnector.js → core/OmniConnector.js} +2 -2
- package/build/core/OmniConnector.js.map +1 -0
- package/build/{OmniWallet.d.ts → core/OmniWallet.d.ts} +19 -13
- package/build/core/OmniWallet.js +97 -0
- package/build/core/OmniWallet.js.map +1 -0
- package/build/core/chains.d.ts +1 -1
- package/build/core/chains.js +5 -5
- package/build/core/chains.js.map +1 -1
- package/build/core/defaultTokens.js +0 -9
- package/build/core/defaultTokens.js.map +1 -1
- package/build/{exchange.d.ts → core/exchange.d.ts} +13 -16
- package/build/{exchange.js → core/exchange.js} +76 -80
- package/build/core/exchange.js.map +1 -0
- package/build/core/index.d.ts +4 -2
- package/build/core/index.js +4 -2
- package/build/core/index.js.map +1 -1
- package/build/core/recipient.d.ts +1 -1
- package/build/core/telemetry.d.ts +3 -0
- package/build/core/telemetry.js.map +1 -1
- package/build/core/token.js +3 -3
- package/build/core/token.js.map +1 -1
- package/build/core/tokens.js +1 -1
- package/build/core/tokens.js.map +1 -1
- package/build/core/utils.d.ts +1 -0
- package/build/core/utils.js +19 -0
- package/build/core/utils.js.map +1 -1
- package/build/cosmos/connector.d.ts +2 -2
- package/build/cosmos/connector.js +2 -2
- package/build/cosmos/connector.js.map +1 -1
- package/build/cosmos/wallet.d.ts +2 -2
- package/build/cosmos/wallet.js +7 -10
- package/build/cosmos/wallet.js.map +1 -1
- package/build/defaults.d.ts +1 -1
- package/build/defaults.js +2 -2
- package/build/defaults.js.map +1 -1
- package/build/evm/connector.d.ts +2 -2
- package/build/evm/connector.js +10 -4
- package/build/evm/connector.js.map +1 -1
- package/build/evm/wallet.d.ts +5 -5
- package/build/evm/wallet.js +25 -24
- package/build/evm/wallet.js.map +1 -1
- package/build/hot-wallet/google.d.ts +2 -2
- package/build/hot-wallet/google.js +4 -4
- package/build/hot-wallet/google.js.map +1 -1
- package/build/index.d.ts +2 -2
- package/build/index.js +2 -2
- package/build/index.js.map +1 -1
- package/build/near/connector.d.ts +2 -2
- package/build/near/connector.js +1 -1
- package/build/near/connector.js.map +1 -1
- package/build/near/index.d.ts +1 -1
- package/build/near/index.js.map +1 -1
- package/build/near/rpc.js +1 -2
- package/build/near/rpc.js.map +1 -1
- package/build/near/standalone.d.ts +2 -0
- package/build/near/standalone.js +42 -0
- package/build/near/standalone.js.map +1 -0
- package/build/near/wallet.d.ts +3 -2
- package/build/near/wallet.js +21 -12
- package/build/near/wallet.js.map +1 -1
- package/build/solana/connector.d.ts +4 -4
- package/build/solana/connector.js +11 -4
- package/build/solana/connector.js.map +1 -1
- package/build/solana/wallet.d.ts +3 -3
- package/build/solana/wallet.js +14 -11
- package/build/solana/wallet.js.map +1 -1
- package/build/stellar/connector.d.ts +2 -2
- package/build/stellar/connector.js +3 -2
- package/build/stellar/connector.js.map +1 -1
- package/build/stellar/wallet.d.ts +3 -3
- package/build/stellar/wallet.js +27 -19
- package/build/stellar/wallet.js.map +1 -1
- package/build/ton/connector.d.ts +2 -2
- package/build/ton/connector.js +2 -2
- package/build/ton/connector.js.map +1 -1
- package/build/ton/wallet.d.ts +3 -3
- package/build/ton/wallet.js +26 -17
- package/build/ton/wallet.js.map +1 -1
- package/build/tron/connector.d.ts +2 -2
- package/build/tron/connector.js +1 -1
- package/build/tron/connector.js.map +1 -1
- package/build/tron/wallet.d.ts +2 -2
- package/build/tron/wallet.js +9 -15
- package/build/tron/wallet.js.map +1 -1
- package/build/ui/bridge/Bridge.d.ts +2 -2
- package/build/ui/bridge/Bridge.js +13 -11
- package/build/ui/bridge/Bridge.js.map +1 -1
- package/build/ui/bridge/SelectRecipient.d.ts +3 -3
- package/build/ui/bridge/SelectRecipient.js +5 -5
- package/build/ui/bridge/SelectRecipient.js.map +1 -1
- package/build/ui/bridge/SelectSender.d.ts +1 -1
- package/build/ui/bridge/SelectSender.js +1 -1
- package/build/ui/bridge/SelectSender.js.map +1 -1
- package/build/ui/bridge/SelectToken.d.ts +1 -1
- package/build/ui/bridge/SelectToken.js +2 -2
- package/build/ui/bridge/SelectToken.js.map +1 -1
- package/build/ui/bridge/TokenCard.d.ts +1 -1
- package/build/ui/connect/AuthPopup.d.ts +1 -1
- package/build/ui/connect/ConnectWallet.d.ts +1 -1
- package/build/ui/connect/ConnectWallet.js +1 -1
- package/build/ui/connect/ConnectWallet.js.map +1 -1
- package/build/ui/connect/LogoutPopup.d.ts +1 -1
- package/build/ui/connect/WCPopup.js +1 -1
- package/build/ui/connect/WCPopup.js.map +1 -1
- package/build/ui/connect/WalletPicker.d.ts +2 -2
- package/build/ui/profile/DepositQR.d.ts +1 -1
- package/build/ui/profile/Payment.d.ts +1 -1
- package/build/ui/profile/Payment.js +8 -8
- package/build/ui/profile/Payment.js.map +1 -1
- package/build/ui/profile/Profile.js.map +1 -1
- package/build/ui/router.d.ts +3 -3
- package/examples-node/.env +2 -0
- package/examples-node/package.json +17 -0
- package/examples-node/transfer.ts +38 -0
- package/examples-node/withdraw.ts +52 -0
- package/examples-node/yarn.lock +2691 -0
- package/package.json +1 -1
- package/src/HotConnector.ts +16 -60
- package/src/activity.ts +9 -9
- package/src/core/Intents.ts +25 -7
- package/src/{OmniConnector.ts → core/OmniConnector.ts} +4 -6
- package/src/core/OmniWallet.ts +125 -0
- package/src/core/chains.ts +5 -5
- package/src/core/defaultTokens.ts +0 -9
- package/src/{exchange.ts → core/exchange.ts} +79 -85
- package/src/core/index.ts +6 -2
- package/src/core/recipient.ts +1 -1
- package/src/core/telemetry.ts +4 -0
- package/src/core/token.ts +3 -3
- package/src/core/tokens.ts +1 -1
- package/src/core/utils.ts +16 -0
- package/src/cosmos/connector.ts +3 -3
- package/src/cosmos/wallet.ts +8 -11
- package/src/defaults.ts +2 -2
- package/src/evm/connector.ts +12 -6
- package/src/evm/wallet.ts +25 -26
- package/src/hot-wallet/google.ts +5 -5
- package/src/index.ts +2 -2
- package/src/near/connector.ts +2 -2
- package/src/near/index.ts +2 -1
- package/src/near/rpc.ts +1 -2
- package/src/near/standalone.ts +52 -0
- package/src/near/wallet.ts +21 -15
- package/src/solana/connector.ts +15 -6
- package/src/solana/wallet.ts +12 -12
- package/src/stellar/connector.ts +5 -4
- package/src/stellar/wallet.ts +28 -22
- package/src/ton/connector.ts +4 -3
- package/src/ton/wallet.ts +24 -18
- package/src/tron/connector.ts +2 -2
- package/src/tron/wallet.ts +9 -19
- package/src/ui/bridge/Bridge.tsx +16 -14
- package/src/ui/bridge/SelectRecipient.tsx +8 -8
- package/src/ui/bridge/SelectSender.tsx +2 -2
- package/src/ui/bridge/SelectToken.tsx +3 -3
- package/src/ui/bridge/TokenCard.tsx +1 -1
- package/src/ui/connect/AuthPopup.tsx +1 -1
- package/src/ui/connect/ConnectWallet.tsx +2 -2
- package/src/ui/connect/LogoutPopup.tsx +1 -1
- package/src/ui/connect/WCPopup.tsx +1 -1
- package/src/ui/connect/WalletPicker.tsx +2 -2
- package/src/ui/profile/DepositQR.tsx +1 -1
- package/src/ui/profile/Payment.tsx +12 -13
- package/src/ui/profile/Profile.tsx +1 -2
- package/src/ui/router.tsx +3 -3
- package/build/OmniConnector.js.map +0 -1
- package/build/OmniWallet.js +0 -58
- package/build/OmniWallet.js.map +0 -1
- package/build/exchange.js.map +0 -1
- package/build/ui/utils.d.ts +0 -1
- package/build/ui/utils.js +0 -20
- package/build/ui/utils.js.map +0 -1
- package/src/OmniWallet.ts +0 -82
- package/src/ui/utils.ts +0 -14
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import { GetExecutionStatusResponse, OneClickService, ApiError,
|
|
1
|
+
import { GetExecutionStatusResponse, OneClickService, ApiError, QuoteRequest, QuoteResponse, OpenAPI } from "@defuse-protocol/one-click-sdk-typescript";
|
|
2
2
|
import { utils } from "@hot-labs/omni-sdk";
|
|
3
3
|
import { hex } from "@scure/base";
|
|
4
4
|
|
|
5
|
-
import { Network, OmniToken, WalletType } from "./
|
|
6
|
-
import { ReviewFee } from "./
|
|
7
|
-
import { Recipient } from "./core/recipient";
|
|
8
|
-
import { tokens } from "./core/tokens";
|
|
9
|
-
import { Token } from "./core/token";
|
|
10
|
-
|
|
11
|
-
import StellarWallet from "./stellar/wallet";
|
|
12
|
-
import { HotConnector } from "./HotConnector";
|
|
5
|
+
import { Network, OmniToken, WalletType } from "./chains";
|
|
6
|
+
import { createHotBridge, ReviewFee } from "./bridge";
|
|
13
7
|
import { OmniWallet } from "./OmniWallet";
|
|
14
|
-
import {
|
|
8
|
+
import { Recipient } from "./recipient";
|
|
9
|
+
import { ILogger } from "./telemetry";
|
|
10
|
+
import { formatter } from "./utils";
|
|
11
|
+
import { Intents } from "./Intents";
|
|
12
|
+
import { tokens } from "./tokens";
|
|
13
|
+
import { Token } from "./token";
|
|
14
|
+
|
|
15
|
+
import StellarWallet from "../stellar/wallet";
|
|
16
|
+
import NearWallet from "../near/wallet";
|
|
15
17
|
|
|
16
18
|
export class UnsupportedDexError extends Error {
|
|
17
19
|
constructor(message: string) {
|
|
@@ -34,15 +36,17 @@ export type BridgeReview = {
|
|
|
34
36
|
status: "pending" | "success" | "failed";
|
|
35
37
|
statusMessage: string | null;
|
|
36
38
|
sender: OmniWallet | "qr";
|
|
37
|
-
recipient: Recipient;
|
|
39
|
+
recipient: OmniWallet | Recipient;
|
|
40
|
+
logger?: ILogger;
|
|
38
41
|
from: Token;
|
|
39
42
|
to: Token;
|
|
40
43
|
};
|
|
41
44
|
|
|
42
|
-
interface BridgeRequest {
|
|
45
|
+
export interface BridgeRequest {
|
|
43
46
|
refund: OmniWallet;
|
|
44
47
|
sender: OmniWallet | "qr";
|
|
45
48
|
type?: "exactIn" | "exactOut";
|
|
49
|
+
logger?: ILogger;
|
|
46
50
|
recipient: Recipient;
|
|
47
51
|
slippage: number;
|
|
48
52
|
amount: bigint;
|
|
@@ -53,13 +57,10 @@ interface BridgeRequest {
|
|
|
53
57
|
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
54
58
|
|
|
55
59
|
export class Exchange {
|
|
56
|
-
|
|
57
|
-
// OpenAPI.BASE = api.getOneClickApiUrl();
|
|
58
|
-
// OpenAPI.HEADERS = { "api-key": api.apiKey };
|
|
59
|
-
}
|
|
60
|
+
readonly bridge = createHotBridge();
|
|
60
61
|
|
|
61
62
|
async getToken(chain: number, address: string): Promise<string | null> {
|
|
62
|
-
if (chain === Network.
|
|
63
|
+
if (chain === Network.Omni) return address;
|
|
63
64
|
const tokensList = await tokens.getTokens();
|
|
64
65
|
const token = tokensList.find((t) => {
|
|
65
66
|
if (t.chain !== chain) return false;
|
|
@@ -72,15 +73,15 @@ export class Exchange {
|
|
|
72
73
|
return token?.omniAddress || null;
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
async deposit(args: { sender: OmniWallet; token: Token; amount: bigint; recipient: Recipient;
|
|
76
|
-
let { sender, token, amount, recipient,
|
|
77
|
-
|
|
76
|
+
async deposit(args: { sender: OmniWallet; token: Token; amount: bigint; recipient: Recipient; logger?: ILogger }) {
|
|
77
|
+
let { sender, token, amount, recipient, logger } = args;
|
|
78
|
+
logger?.log("Sending deposit transaction");
|
|
78
79
|
|
|
79
|
-
const balance = await
|
|
80
|
+
const balance = await sender.fetchBalance(token.chain, token.address);
|
|
80
81
|
amount = formatter.bigIntMin(amount, balance);
|
|
81
82
|
|
|
82
|
-
if (token.type === WalletType.COSMOS &&
|
|
83
|
-
const cosmosBridge = await this.
|
|
83
|
+
if (token.type === WalletType.COSMOS && sender.type === WalletType.COSMOS) {
|
|
84
|
+
const cosmosBridge = await this.bridge.cosmos();
|
|
84
85
|
const hash = await cosmosBridge.deposit({
|
|
85
86
|
sendTransaction: async (tx) => sender.sendTransaction(tx),
|
|
86
87
|
senderPublicKey: hex.decode(sender.publicKey!),
|
|
@@ -91,17 +92,17 @@ export class Exchange {
|
|
|
91
92
|
amount: amount,
|
|
92
93
|
});
|
|
93
94
|
|
|
94
|
-
|
|
95
|
-
const deposit = await this.
|
|
96
|
-
|
|
97
|
-
await this.
|
|
98
|
-
|
|
95
|
+
logger?.log("Waiting for deposit");
|
|
96
|
+
const deposit = await this.bridge.waitPendingDeposit(token.chain, hash, recipient.omniAddress);
|
|
97
|
+
logger?.log("Finishing deposit");
|
|
98
|
+
await this.bridge.finishDeposit(deposit);
|
|
99
|
+
logger?.log("Deposit finished");
|
|
99
100
|
return;
|
|
100
101
|
}
|
|
101
102
|
|
|
102
|
-
if (token.type === WalletType.EVM &&
|
|
103
|
-
const hash = await this.
|
|
104
|
-
sendTransaction: async (tx) => sender.sendTransaction(
|
|
103
|
+
if (token.type === WalletType.EVM && sender.type === WalletType.EVM) {
|
|
104
|
+
const hash = await this.bridge.evm.deposit({
|
|
105
|
+
sendTransaction: async (tx) => sender.sendTransaction(tx),
|
|
105
106
|
intentAccount: recipient.omniAddress,
|
|
106
107
|
sender: sender.address,
|
|
107
108
|
token: token.address,
|
|
@@ -110,16 +111,16 @@ export class Exchange {
|
|
|
110
111
|
});
|
|
111
112
|
|
|
112
113
|
if (!hash) throw new Error("Failed to deposit");
|
|
113
|
-
|
|
114
|
-
const deposit = await this.
|
|
115
|
-
|
|
116
|
-
await this.
|
|
117
|
-
|
|
114
|
+
logger?.log("Waiting for deposit");
|
|
115
|
+
const deposit = await this.bridge.waitPendingDeposit(token.chain, hash, recipient.omniAddress);
|
|
116
|
+
logger?.log("Finishing deposit");
|
|
117
|
+
await this.bridge.finishDeposit(deposit);
|
|
118
|
+
logger?.log("Deposit finished");
|
|
118
119
|
return;
|
|
119
120
|
}
|
|
120
121
|
|
|
121
|
-
if (token.type === WalletType.NEAR &&
|
|
122
|
-
return await this.
|
|
122
|
+
if (token.type === WalletType.NEAR && sender.type === WalletType.NEAR) {
|
|
123
|
+
return await this.bridge.near.deposit({
|
|
123
124
|
sendTransaction: async (tx: any) => sender.sendTransaction(tx),
|
|
124
125
|
intentAccount: recipient.omniAddress,
|
|
125
126
|
sender: sender.address,
|
|
@@ -131,17 +132,16 @@ export class Exchange {
|
|
|
131
132
|
throw new Error("Unsupported token");
|
|
132
133
|
}
|
|
133
134
|
|
|
134
|
-
async withdraw(args: { sender: OmniWallet; token: Token; amount: bigint; recipient:
|
|
135
|
-
const { sender, token, amount, recipient } = args;
|
|
135
|
+
async withdraw(args: { sender: OmniWallet; token: Token; amount: bigint; recipient: OmniWallet | Recipient; logger?: ILogger }) {
|
|
136
|
+
const { sender, token, amount, recipient, logger } = args;
|
|
136
137
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
await receipientWallet.registerToken(token.originalAddress);
|
|
138
|
+
if (recipient.type === WalletType.NEAR && token.type === WalletType.NEAR && recipient instanceof NearWallet) {
|
|
139
|
+
logger?.log("Registering NEAR token");
|
|
140
|
+
await recipient.registerToken(token.originalAddress);
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
|
|
144
|
-
await this.
|
|
143
|
+
logger?.log("Withdrawing token");
|
|
144
|
+
await this.bridge.withdrawToken({
|
|
145
145
|
signIntents: async (intents) => sender.signIntents(intents),
|
|
146
146
|
intentAccount: sender.omniAddress,
|
|
147
147
|
receiver: recipient.address,
|
|
@@ -155,8 +155,8 @@ export class Exchange {
|
|
|
155
155
|
|
|
156
156
|
async withdrawFee(request: BridgeRequest) {
|
|
157
157
|
if (request.sender === "qr") throw new Error("Sender is QR");
|
|
158
|
-
if (request.to.chain === Network.Near || request.to.chain === Network.
|
|
159
|
-
const gaslessFee = await this.
|
|
158
|
+
if (request.to.chain === Network.Near || request.to.chain === Network.Omni) return 0n;
|
|
159
|
+
const gaslessFee = await this.bridge.getGaslessWithdrawFee({
|
|
160
160
|
receiver: request.recipient.address,
|
|
161
161
|
token: request.to.address,
|
|
162
162
|
chain: request.to.chain,
|
|
@@ -166,7 +166,7 @@ export class Exchange {
|
|
|
166
166
|
if (request.to.address === "native") return 0n;
|
|
167
167
|
|
|
168
168
|
// if withdraw token is not native, we need to swap a bit of it to native to cover the withdraw fee
|
|
169
|
-
const swap = await this.
|
|
169
|
+
const swap = await this.bridge.buildSwapExectOutIntent({
|
|
170
170
|
intentFrom: utils.toOmniIntent(request.to.chain, request.to.address),
|
|
171
171
|
intentTo: utils.toOmniIntent(request.to.chain, "native"),
|
|
172
172
|
amountOut: gaslessFee.gasPrice,
|
|
@@ -178,16 +178,16 @@ export class Exchange {
|
|
|
178
178
|
|
|
179
179
|
isDirectDeposit(from: Token, to: Token) {
|
|
180
180
|
const directChains = [Network.Near, Network.Juno, Network.Gonka, Network.ADI];
|
|
181
|
-
return directChains.includes(from.chain) && to.chain === Network.
|
|
181
|
+
return directChains.includes(from.chain) && to.chain === Network.Omni && from.omniAddress === to.omniAddress;
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
isDirectWithdraw(from: Token, to: Token) {
|
|
185
185
|
const directChains = [Network.Near, Network.Juno, Network.Gonka, Network.ADI];
|
|
186
|
-
return directChains.includes(to.chain) && from.chain === Network.
|
|
186
|
+
return directChains.includes(to.chain) && from.chain === Network.Omni && from.omniAddress === to.omniAddress;
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
async reviewSwap(request: BridgeRequest): Promise<BridgeReview> {
|
|
190
|
-
const { sender, refund, from, to, amount, recipient, slippage, type } = request;
|
|
190
|
+
const { sender, refund, from, to, amount, recipient, slippage, type, logger } = request;
|
|
191
191
|
const intentFrom = await this.getToken(from.chain, from.address);
|
|
192
192
|
const intentTo = await this.getToken(to.chain, to.address);
|
|
193
193
|
|
|
@@ -199,7 +199,7 @@ export class Exchange {
|
|
|
199
199
|
const noFee = from.symbol === to.symbol || (from.symbol.toLowerCase().includes("usd") && to.symbol.toLowerCase().includes("usd"));
|
|
200
200
|
|
|
201
201
|
if (sender !== "qr" && this.isDirectDeposit(from, to)) {
|
|
202
|
-
const fee = await this.
|
|
202
|
+
const fee = await this.bridge.getDepositFee({
|
|
203
203
|
intentAccount: sender.omniAddress,
|
|
204
204
|
sender: sender.address,
|
|
205
205
|
token: from.address,
|
|
@@ -218,6 +218,7 @@ export class Exchange {
|
|
|
218
218
|
statusMessage: null,
|
|
219
219
|
status: "pending",
|
|
220
220
|
qoute: "deposit",
|
|
221
|
+
logger,
|
|
221
222
|
fee,
|
|
222
223
|
};
|
|
223
224
|
}
|
|
@@ -237,6 +238,7 @@ export class Exchange {
|
|
|
237
238
|
statusMessage: null,
|
|
238
239
|
status: "pending",
|
|
239
240
|
qoute: "withdraw",
|
|
241
|
+
logger,
|
|
240
242
|
};
|
|
241
243
|
}
|
|
242
244
|
|
|
@@ -249,8 +251,7 @@ export class Exchange {
|
|
|
249
251
|
|
|
250
252
|
if (recipient.type === WalletType.STELLAR) {
|
|
251
253
|
const isTokenActivated = await StellarWallet.isTokenActivated(recipient.address, request.to.address);
|
|
252
|
-
|
|
253
|
-
if (!isTokenActivated && !recipientWallet) throw "Token not activated for recipient";
|
|
254
|
+
if (!isTokenActivated && !(recipient instanceof StellarWallet)) throw "Token not activated for recipient";
|
|
254
255
|
}
|
|
255
256
|
|
|
256
257
|
let qoute: QuoteResponse | null = null;
|
|
@@ -260,11 +261,11 @@ export class Exchange {
|
|
|
260
261
|
destinationAsset: intentTo,
|
|
261
262
|
quoteWaitingTimeMs: 3000,
|
|
262
263
|
slippageTolerance: Math.round(slippage * 10_000),
|
|
263
|
-
swapType: type === "
|
|
264
|
-
depositType: from.chain === Network.
|
|
264
|
+
swapType: type === "exactOut" ? QuoteRequest.swapType.EXACT_OUTPUT : QuoteRequest.swapType.EXACT_INPUT,
|
|
265
|
+
depositType: from.chain === Network.Omni ? QuoteRequest.depositType.INTENTS : QuoteRequest.depositType.ORIGIN_CHAIN,
|
|
265
266
|
depositMode: from.chain === Network.Stellar ? QuoteRequest.depositMode.MEMO : QuoteRequest.depositMode.SIMPLE,
|
|
266
|
-
recipientType: to.chain === Network.
|
|
267
|
-
recipient: to.chain === Network.
|
|
267
|
+
recipientType: to.chain === Network.Omni ? QuoteRequest.recipientType.INTENTS : QuoteRequest.recipientType.DESTINATION_CHAIN,
|
|
268
|
+
recipient: to.chain === Network.Omni ? recipient.omniAddress : recipient.address,
|
|
268
269
|
appFees: noFee ? [] : [{ recipient: "intents.tg", fee: 25 }],
|
|
269
270
|
amount: request.amount.toString(),
|
|
270
271
|
referral: "intents.tg",
|
|
@@ -288,7 +289,7 @@ export class Exchange {
|
|
|
288
289
|
}
|
|
289
290
|
|
|
290
291
|
let fee: ReviewFee | null = null;
|
|
291
|
-
if (request.from.chain !== Network.
|
|
292
|
+
if (request.from.chain !== Network.Omni && sender !== "qr") {
|
|
292
293
|
const amount = BigInt(qoute.quote.amountIn);
|
|
293
294
|
const depositAddress = qoute.quote.depositAddress!;
|
|
294
295
|
fee = await sender.transferFee(request.from, depositAddress, amount).catch(() => null);
|
|
@@ -306,47 +307,41 @@ export class Exchange {
|
|
|
306
307
|
status: "pending",
|
|
307
308
|
sender: sender,
|
|
308
309
|
fee: fee,
|
|
310
|
+
logger,
|
|
309
311
|
};
|
|
310
312
|
}
|
|
311
313
|
|
|
312
|
-
async makeSwap(review: BridgeReview
|
|
313
|
-
const { sender, recipient } = review;
|
|
314
|
+
async makeSwap(review: BridgeReview): Promise<{ review: BridgeReview; processing?: () => Promise<BridgeReview> }> {
|
|
315
|
+
const { sender, recipient, logger } = review;
|
|
314
316
|
|
|
315
317
|
if (review.qoute === "withdraw") {
|
|
316
318
|
if (sender === "qr") throw new Error("Sender is QR");
|
|
317
|
-
await this.withdraw({ sender, token: review.to, amount: review.amountIn, recipient }
|
|
318
|
-
|
|
319
|
-
if (
|
|
320
|
-
this.wibe3.fetchToken(review.from, sender);
|
|
319
|
+
await this.withdraw({ sender, token: review.to, amount: review.amountIn, recipient, logger });
|
|
320
|
+
if (recipient instanceof OmniWallet) recipient.fetchBalance(review.to.chain, review.to.address);
|
|
321
|
+
if (sender instanceof OmniWallet) sender.fetchBalance(review.from.chain, review.from.address);
|
|
321
322
|
return { review };
|
|
322
323
|
}
|
|
323
324
|
|
|
324
325
|
if (review.qoute === "deposit") {
|
|
325
326
|
if (sender === "qr") throw new Error("Sender is QR");
|
|
326
|
-
await this.deposit({ sender, token: review.from, amount: review.amountIn, recipient,
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
const recipientWallet = this.wibe3.wallets.find((w) => w.address === recipient.address);
|
|
330
|
-
if (recipientWallet) this.wibe3.fetchToken(review.to, recipientWallet);
|
|
327
|
+
await this.deposit({ sender, token: review.from, amount: review.amountIn, recipient, logger });
|
|
328
|
+
if (recipient instanceof OmniWallet) recipient.fetchBalance(review.to.chain, review.to.address);
|
|
329
|
+
if (sender instanceof OmniWallet) sender.fetchBalance(review.from.chain, review.from.address);
|
|
331
330
|
return { review };
|
|
332
331
|
}
|
|
333
332
|
|
|
334
333
|
if (sender !== "qr") {
|
|
335
334
|
if (recipient.type === WalletType.STELLAR) {
|
|
336
335
|
const isTokenActivated = await StellarWallet.isTokenActivated(recipient.address, review.to.address);
|
|
337
|
-
|
|
338
|
-
if (!isTokenActivated &&
|
|
339
|
-
if (!isTokenActivated && recipientWallet instanceof StellarWallet) {
|
|
340
|
-
await recipientWallet.changeTrustline(review.to.address);
|
|
341
|
-
}
|
|
336
|
+
if (!isTokenActivated && !(recipient instanceof StellarWallet)) throw "Token not activated for recipient";
|
|
337
|
+
if (!isTokenActivated && recipient instanceof StellarWallet) await recipient.changeTrustline(review.to.address);
|
|
342
338
|
}
|
|
343
339
|
|
|
344
340
|
const depositAddress = review.qoute.depositAddress!;
|
|
345
341
|
let hash = "";
|
|
346
342
|
|
|
347
|
-
if (review.from.chain === Network.
|
|
348
|
-
hash = await
|
|
349
|
-
.intentsBuilder(sender)
|
|
343
|
+
if (review.from.chain === Network.Omni) {
|
|
344
|
+
hash = await Intents.builder(sender)
|
|
350
345
|
.transfer({ amount: review.amountIn, token: review.from.address as OmniToken, recipient: depositAddress })
|
|
351
346
|
.execute();
|
|
352
347
|
} else {
|
|
@@ -359,21 +354,20 @@ export class Exchange {
|
|
|
359
354
|
});
|
|
360
355
|
}
|
|
361
356
|
|
|
362
|
-
|
|
357
|
+
if (sender instanceof OmniWallet) sender.fetchBalance(review.from.chain, review.from.address);
|
|
363
358
|
OneClickService.submitDepositTx({ txHash: hash, depositAddress }).catch(() => {});
|
|
364
359
|
}
|
|
365
360
|
|
|
366
361
|
return {
|
|
367
362
|
review,
|
|
368
363
|
processing: async () => {
|
|
369
|
-
|
|
370
|
-
if (!recipientWallet) return await this.processing(review);
|
|
364
|
+
if (!(recipient instanceof OmniWallet)) return await this.processing(review);
|
|
371
365
|
|
|
372
|
-
const beforeBalance = await
|
|
366
|
+
const beforeBalance = await recipient.fetchBalance(review.to.chain, review.to.address).catch(() => null);
|
|
373
367
|
if (!beforeBalance) return await this.processing(review);
|
|
374
368
|
|
|
375
369
|
return await Promise.race([
|
|
376
|
-
this.waitBalance(review.to,
|
|
370
|
+
this.waitBalance(review.to, recipient, beforeBalance, review),
|
|
377
371
|
this.processing(review), //
|
|
378
372
|
]);
|
|
379
373
|
},
|
|
@@ -381,7 +375,7 @@ export class Exchange {
|
|
|
381
375
|
}
|
|
382
376
|
|
|
383
377
|
async waitBalance(to: Token, wallet: OmniWallet, beforeBalance: bigint, review: BridgeReview): Promise<BridgeReview> {
|
|
384
|
-
const afterBalance = await
|
|
378
|
+
const afterBalance = await wallet.fetchBalance(to.chain, to.address).catch(() => beforeBalance);
|
|
385
379
|
if (afterBalance > beforeBalance) {
|
|
386
380
|
return {
|
|
387
381
|
...review,
|
package/src/core/index.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
export { OmniToken, WalletType, Network, chains } from "./chains";
|
|
2
|
-
export { createHotBridge, HotBridge, ReviewFee } from "./bridge";
|
|
3
1
|
export { rpc as nearRpc, TGAS } from "../near/rpc";
|
|
2
|
+
|
|
3
|
+
export { OmniToken, WalletType, Network } from "./chains";
|
|
4
|
+
|
|
5
|
+
export { chains } from "./chains";
|
|
6
|
+
export { createHotBridge, HotBridge, ReviewFee } from "./bridge";
|
|
7
|
+
export { Exchange } from "./exchange";
|
|
4
8
|
export { EventEmitter } from "./events";
|
|
5
9
|
export { Recipient } from "./recipient";
|
|
6
10
|
export { formatter } from "./utils";
|
package/src/core/recipient.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Address } from "@ton/core";
|
|
2
2
|
import { hex, base32, base58 } from "@scure/base";
|
|
3
3
|
|
|
4
|
-
import { type OmniWallet } from "
|
|
4
|
+
import { type OmniWallet } from "./OmniWallet";
|
|
5
5
|
import { tonApi } from "../ton/utils";
|
|
6
6
|
import { WalletType } from "./chains";
|
|
7
7
|
|
package/src/core/telemetry.ts
CHANGED
|
@@ -2,6 +2,10 @@ import { api } from "./api";
|
|
|
2
2
|
import { HotConnector } from "../HotConnector";
|
|
3
3
|
import { formatter } from "./utils";
|
|
4
4
|
|
|
5
|
+
export interface ILogger {
|
|
6
|
+
log: (message: string) => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
5
9
|
export class Telemetry {
|
|
6
10
|
events: { event: string; value_str?: string; value_float?: number; ts: number }[] = [];
|
|
7
11
|
constructor(readonly wibe3: HotConnector) {
|
package/src/core/token.ts
CHANGED
|
@@ -73,7 +73,7 @@ export class Token {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
get isMainOmni() {
|
|
76
|
-
if (this.chain !== Network.
|
|
76
|
+
if (this.chain !== Network.Omni) return false;
|
|
77
77
|
return Object.values(OmniToken).some((token) => this.address === token);
|
|
78
78
|
}
|
|
79
79
|
|
|
@@ -90,7 +90,7 @@ export class Token {
|
|
|
90
90
|
if (this.chain === Network.Juno) return 0.01;
|
|
91
91
|
|
|
92
92
|
if (this.address !== "native") return 0;
|
|
93
|
-
if (this.chain === Network.
|
|
93
|
+
if (this.chain === Network.Omni) return 0;
|
|
94
94
|
if (this.chain === Network.Ton) return 0.01;
|
|
95
95
|
if (this.chain === Network.Stellar) return 0;
|
|
96
96
|
if (this.chain === Network.Solana) return 0.001;
|
|
@@ -102,7 +102,7 @@ export class Token {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
get icon() {
|
|
105
|
-
if (this.chain === Network.
|
|
105
|
+
if (this.chain === Network.Omni) return `https://storage.herewallet.app/ft/${this.originalChain}:${this.originalAddress.toLowerCase()}.png`;
|
|
106
106
|
return `https://storage.herewallet.app/ft/${this.id.toLowerCase()}.png`;
|
|
107
107
|
}
|
|
108
108
|
|
package/src/core/tokens.ts
CHANGED
|
@@ -13,7 +13,7 @@ class TokensStorage {
|
|
|
13
13
|
makeObservable(this, { list: observable });
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
get(id: OmniToken | string, chain = Network.
|
|
16
|
+
get(id: OmniToken | string, chain = Network.Omni): Token {
|
|
17
17
|
return this.list.find((t) => t.chain === chain && t.address === id)!;
|
|
18
18
|
}
|
|
19
19
|
|
package/src/core/utils.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { NetworkError, TimeoutNetworkError } from "./api";
|
|
2
|
+
|
|
1
3
|
type Value = number | bigint | string;
|
|
2
4
|
export const formatter = {
|
|
3
5
|
toReadableNumber(decimals: number | bigint, number: bigint | string = "0"): string {
|
|
@@ -107,6 +109,7 @@ export const formatter = {
|
|
|
107
109
|
if (n < 1_000_000_000_000) return [formatter.round(n / 1_000_000, 2), "M"];
|
|
108
110
|
return [formatter.round(n / 1_000_000_000, 2), "B"];
|
|
109
111
|
},
|
|
112
|
+
|
|
110
113
|
formatNumber(num: string) {
|
|
111
114
|
let useDelimeter = false;
|
|
112
115
|
let right = "";
|
|
@@ -176,4 +179,17 @@ export const formatter = {
|
|
|
176
179
|
return acc;
|
|
177
180
|
}, []);
|
|
178
181
|
},
|
|
182
|
+
|
|
183
|
+
serializeError(error: any): string {
|
|
184
|
+
try {
|
|
185
|
+
if (error instanceof Error) return error.message;
|
|
186
|
+
if (error instanceof NetworkError) return error.toString();
|
|
187
|
+
if (error instanceof TimeoutNetworkError) return error.toString();
|
|
188
|
+
if (typeof error === "object" && Object.keys(error).length > 0) return JSON.stringify(error);
|
|
189
|
+
if (typeof error === "string" || typeof error === "number") return error.toString();
|
|
190
|
+
return "";
|
|
191
|
+
} catch (error) {
|
|
192
|
+
return "Unknown error";
|
|
193
|
+
}
|
|
194
|
+
},
|
|
179
195
|
};
|
package/src/cosmos/connector.ts
CHANGED
|
@@ -6,9 +6,9 @@ import { runInAction } from "mobx";
|
|
|
6
6
|
|
|
7
7
|
import { api } from "../core/api";
|
|
8
8
|
import { chains, WalletType } from "../core/chains";
|
|
9
|
-
import { ConnectorType, OmniConnector, OmniConnectorOption, WC_ICON } from "../OmniConnector";
|
|
9
|
+
import { ConnectorType, OmniConnector, OmniConnectorOption, WC_ICON } from "../core/OmniConnector";
|
|
10
10
|
import { HotConnector } from "../HotConnector";
|
|
11
|
-
import { OmniWallet } from "../OmniWallet";
|
|
11
|
+
import { OmniWallet } from "../core/OmniWallet";
|
|
12
12
|
|
|
13
13
|
import { signAndSendTx } from "./helpers";
|
|
14
14
|
import CosmosWallet from "./wallet";
|
|
@@ -80,7 +80,7 @@ export default class CosmosConnector extends OmniConnector<CosmosWallet> {
|
|
|
80
80
|
});
|
|
81
81
|
|
|
82
82
|
this.initWalletConnect()
|
|
83
|
-
.then(async (
|
|
83
|
+
.then(async () => {
|
|
84
84
|
this.options.unshift({
|
|
85
85
|
download: "https://www.walletconnect.com/get",
|
|
86
86
|
name: "WalletConnect",
|
package/src/cosmos/wallet.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StargateClient } from "@cosmjs/stargate";
|
|
2
|
-
import { OmniWallet } from "../OmniWallet";
|
|
2
|
+
import { OmniWallet } from "../core/OmniWallet";
|
|
3
3
|
import { chains, WalletType } from "../core/chains";
|
|
4
4
|
import { ReviewFee } from "../core/bridge";
|
|
5
5
|
import { Commitment } from "../core";
|
|
@@ -48,21 +48,18 @@ export default class CosmosWallet extends OmniWallet {
|
|
|
48
48
|
throw new Error("Method not implemented.");
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
async fetchBalances(chain: number, whitelist: string[]): Promise<Record<string, bigint>> {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
const balance = await this.fetchBalance(chain, token);
|
|
55
|
-
return [token, balance];
|
|
56
|
-
})
|
|
57
|
-
);
|
|
58
|
-
return Object.fromEntries(balances);
|
|
51
|
+
async fetchBalances(chain: number, whitelist: string[] = []): Promise<Record<string, bigint>> {
|
|
52
|
+
const tasks = whitelist.map(async (token) => [token, await this.fetchBalance(chain, token)]);
|
|
53
|
+
return Object.fromEntries(await Promise.all(tasks));
|
|
59
54
|
}
|
|
60
55
|
|
|
61
56
|
async fetchBalance(chain: number, token: string): Promise<bigint> {
|
|
62
57
|
const config = chains.get(chain);
|
|
63
|
-
if (!config)
|
|
58
|
+
if (!config || config.type !== WalletType.COSMOS) return super.fetchBalance(chain, token);
|
|
59
|
+
|
|
64
60
|
const client = await StargateClient.connect(config.rpc);
|
|
65
61
|
const balance = await client.getBalance(this.address, token);
|
|
66
|
-
|
|
62
|
+
|
|
63
|
+
return this.setBalance(`${chain}:${token}`, BigInt(balance.amount || 0));
|
|
67
64
|
}
|
|
68
65
|
}
|
package/src/defaults.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import near from "./near";
|
|
2
1
|
import stellar from "./stellar";
|
|
3
|
-
import ton from "./ton";
|
|
4
2
|
import solana from "./solana";
|
|
3
|
+
import near from "./near";
|
|
5
4
|
import evm from "./evm";
|
|
5
|
+
import ton from "./ton";
|
|
6
6
|
|
|
7
7
|
export const defaultConnectors = [near(), evm(), solana(), ton(), stellar()];
|
package/src/evm/connector.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { runInAction } from "mobx";
|
|
2
2
|
|
|
3
3
|
import HOT from "../hot-wallet/iframe";
|
|
4
|
-
import {
|
|
5
|
-
import { ConnectorType, OmniConnector, WC_ICON } from "../OmniConnector";
|
|
6
|
-
import { HotConnector } from "../HotConnector";
|
|
4
|
+
import type { HotConnector } from "../HotConnector";
|
|
7
5
|
|
|
6
|
+
import { Network, WalletType } from "../core/chains";
|
|
7
|
+
import { ConnectorType, OmniConnector, WC_ICON } from "../core/OmniConnector";
|
|
8
8
|
import EvmWallet, { EvmProvider } from "./wallet";
|
|
9
9
|
|
|
10
10
|
class EvmConnector extends OmniConnector<EvmWallet, { provider: EvmProvider }> {
|
|
@@ -44,13 +44,19 @@ class EvmConnector extends OmniConnector<EvmWallet, { provider: EvmProvider }> {
|
|
|
44
44
|
window.dispatchEvent(new Event("eip6963:requestProvider"));
|
|
45
45
|
|
|
46
46
|
this.initWalletConnect()
|
|
47
|
-
.then((
|
|
48
|
-
this.options.unshift({
|
|
47
|
+
.then(() => {
|
|
48
|
+
this.options.unshift({
|
|
49
|
+
id: "walletconnect",
|
|
50
|
+
name: "WalletConnect",
|
|
51
|
+
provider: {} as any,
|
|
52
|
+
type: "external",
|
|
53
|
+
icon: WC_ICON,
|
|
54
|
+
});
|
|
49
55
|
})
|
|
50
56
|
.catch(() => {});
|
|
51
57
|
|
|
52
58
|
this.wc
|
|
53
|
-
?.then(async (
|
|
59
|
+
?.then(async () => {
|
|
54
60
|
const selected = await this.getConnectedWallet();
|
|
55
61
|
if (selected.id !== "walletconnect") return;
|
|
56
62
|
this.setupWalletConnect();
|