@hot-labs/kit 1.0.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.cjs +11 -0
- package/.github/workflows/deploy-example.yml +55 -0
- package/.github/workflows/release.yml +74 -0
- package/.prettierrc +4 -0
- package/.prototools +2 -0
- package/.vscode/settings.json +3 -0
- package/CHANGELOG.md +1 -0
- package/README.md +67 -0
- package/build/GoogleConnector.d.ts +20 -0
- package/build/GoogleConnector.js +76 -0
- package/build/GoogleConnector.js.map +1 -0
- package/build/HotConnector.d.ts +91 -0
- package/build/HotConnector.js +285 -0
- package/build/HotConnector.js.map +1 -0
- package/build/OmniConnector.d.ts +95 -0
- package/build/OmniConnector.js +123 -0
- package/build/OmniConnector.js.map +1 -0
- package/build/OmniWallet.d.ts +57 -0
- package/build/OmniWallet.js +56 -0
- package/build/OmniWallet.js.map +1 -0
- package/build/cosmos/connector.d.ts +53 -0
- package/build/cosmos/connector.js +207 -0
- package/build/cosmos/connector.js.map +1 -0
- package/build/cosmos/wallet.d.ts +28 -0
- package/build/cosmos/wallet.js +59 -0
- package/build/cosmos/wallet.js.map +1 -0
- package/build/events.d.ts +42 -0
- package/build/events.js +64 -0
- package/build/events.js.map +1 -0
- package/build/evm/abi.d.ts +17 -0
- package/build/evm/abi.js +38 -0
- package/build/evm/abi.js.map +1 -0
- package/build/evm/connector.d.ts +35 -0
- package/build/evm/connector.js +124 -0
- package/build/evm/connector.js.map +1 -0
- package/build/evm/wallet.d.ts +47 -0
- package/build/evm/wallet.js +136 -0
- package/build/evm/wallet.js.map +1 -0
- package/build/exchange.d.ts +63 -0
- package/build/exchange.js +384 -0
- package/build/exchange.js.map +1 -0
- package/build/hot-wallet/evm.d.ts +1 -0
- package/build/hot-wallet/evm.js +33 -0
- package/build/hot-wallet/evm.js.map +1 -0
- package/build/hot-wallet/hot.d.ts +3 -0
- package/build/hot-wallet/hot.js +40 -0
- package/build/hot-wallet/hot.js.map +1 -0
- package/build/hot-wallet/index.d.ts +4 -0
- package/build/hot-wallet/index.js +5 -0
- package/build/hot-wallet/index.js.map +1 -0
- package/build/hot-wallet/solana/account.d.ts +11 -0
- package/build/hot-wallet/solana/account.js +42 -0
- package/build/hot-wallet/solana/account.js.map +1 -0
- package/build/hot-wallet/solana/index.d.ts +1 -0
- package/build/hot-wallet/solana/index.js +85 -0
- package/build/hot-wallet/solana/index.js.map +1 -0
- package/build/hot-wallet/solana/register.d.ts +2 -0
- package/build/hot-wallet/solana/register.js +41 -0
- package/build/hot-wallet/solana/register.js.map +1 -0
- package/build/hot-wallet/solana/solana-wallet.d.ts +34 -0
- package/build/hot-wallet/solana/solana-wallet.js +223 -0
- package/build/hot-wallet/solana/solana-wallet.js.map +1 -0
- package/build/hot-wallet/solana/utils.d.ts +32 -0
- package/build/hot-wallet/solana/utils.js +36 -0
- package/build/hot-wallet/solana/utils.js.map +1 -0
- package/build/hot-wallet/stellar.d.ts +38 -0
- package/build/hot-wallet/stellar.js +32 -0
- package/build/hot-wallet/stellar.js.map +1 -0
- package/build/hot-wallet/ton.d.ts +1 -0
- package/build/hot-wallet/ton.js +49 -0
- package/build/hot-wallet/ton.js.map +1 -0
- package/build/hot-wallet/wallet.d.ts +1 -0
- package/build/hot-wallet/wallet.js +40 -0
- package/build/hot-wallet/wallet.js.map +1 -0
- package/build/index.d.ts +24 -0
- package/build/index.js +25 -0
- package/build/index.js.map +1 -0
- package/build/near/connector.d.ts +28 -0
- package/build/near/connector.js +56 -0
- package/build/near/connector.js.map +1 -0
- package/build/near/wallet.d.ts +62 -0
- package/build/near/wallet.js +233 -0
- package/build/near/wallet.js.map +1 -0
- package/build/omni/Intents.d.ts +93 -0
- package/build/omni/Intents.js +395 -0
- package/build/omni/Intents.js.map +1 -0
- package/build/omni/bridge.d.ts +3 -0
- package/build/omni/bridge.js +34 -0
- package/build/omni/bridge.js.map +1 -0
- package/build/omni/config.d.ts +99 -0
- package/build/omni/config.js +126 -0
- package/build/omni/config.js.map +1 -0
- package/build/omni/defaultTokens.d.ts +17 -0
- package/build/omni/defaultTokens.js +1079 -0
- package/build/omni/defaultTokens.js.map +1 -0
- package/build/omni/index.d.ts +8 -0
- package/build/omni/index.js +9 -0
- package/build/omni/index.js.map +1 -0
- package/build/omni/nearRpc.d.ts +24 -0
- package/build/omni/nearRpc.js +167 -0
- package/build/omni/nearRpc.js.map +1 -0
- package/build/omni/recipient.d.ts +10 -0
- package/build/omni/recipient.js +40 -0
- package/build/omni/recipient.js.map +1 -0
- package/build/omni/token.d.ts +36 -0
- package/build/omni/token.js +136 -0
- package/build/omni/token.js.map +1 -0
- package/build/omni/tokens.d.ts +14 -0
- package/build/omni/tokens.js +57 -0
- package/build/omni/tokens.js.map +1 -0
- package/build/omni/types.d.ts +41 -0
- package/build/omni/types.js +2 -0
- package/build/omni/types.js.map +1 -0
- package/build/omni/utils.d.ts +24 -0
- package/build/omni/utils.js +150 -0
- package/build/omni/utils.js.map +1 -0
- package/build/settings.d.ts +5 -0
- package/build/settings.js +6 -0
- package/build/settings.js.map +1 -0
- package/build/solana/connector.d.ts +31 -0
- package/build/solana/connector.js +138 -0
- package/build/solana/connector.js.map +1 -0
- package/build/solana/protocol.d.ts +25 -0
- package/build/solana/protocol.js +56 -0
- package/build/solana/protocol.js.map +1 -0
- package/build/solana/wallet.d.ts +47 -0
- package/build/solana/wallet.js +188 -0
- package/build/solana/wallet.js.map +1 -0
- package/build/solana/wallets.d.ts +102 -0
- package/build/solana/wallets.js +150 -0
- package/build/solana/wallets.js.map +1 -0
- package/build/stellar/connector.d.ts +25 -0
- package/build/stellar/connector.js +56 -0
- package/build/stellar/connector.js.map +1 -0
- package/build/stellar/wallet.d.ts +70 -0
- package/build/stellar/wallet.js +225 -0
- package/build/stellar/wallet.js.map +1 -0
- package/build/storage.d.ts +10 -0
- package/build/storage.js +12 -0
- package/build/storage.js.map +1 -0
- package/build/ton/connector.d.ts +25 -0
- package/build/ton/connector.js +119 -0
- package/build/ton/connector.js.map +1 -0
- package/build/ton/utils.d.ts +45 -0
- package/build/ton/utils.js +64 -0
- package/build/ton/utils.js.map +1 -0
- package/build/ton/wallet.d.ts +70 -0
- package/build/ton/wallet.js +154 -0
- package/build/ton/wallet.js.map +1 -0
- package/build/ui/Popup.d.ts +10 -0
- package/build/ui/Popup.js +38 -0
- package/build/ui/Popup.js.map +1 -0
- package/build/ui/connect/AuthPopup.d.ts +2 -0
- package/build/ui/connect/AuthPopup.js +48 -0
- package/build/ui/connect/AuthPopup.js.map +1 -0
- package/build/ui/connect/ConnectWallet.d.ts +9 -0
- package/build/ui/connect/ConnectWallet.js +22 -0
- package/build/ui/connect/ConnectWallet.js.map +1 -0
- package/build/ui/connect/LogoutPopup.d.ts +10 -0
- package/build/ui/connect/LogoutPopup.js +8 -0
- package/build/ui/connect/LogoutPopup.js.map +1 -0
- package/build/ui/connect/WCPopup.d.ts +13 -0
- package/build/ui/connect/WCPopup.js +81 -0
- package/build/ui/connect/WCPopup.js.map +1 -0
- package/build/ui/connect/WCRequest.d.ts +9 -0
- package/build/ui/connect/WCRequest.js +13 -0
- package/build/ui/connect/WCRequest.js.map +1 -0
- package/build/ui/connect/WalletPicker.d.ts +11 -0
- package/build/ui/connect/WalletPicker.js +48 -0
- package/build/ui/connect/WalletPicker.js.map +1 -0
- package/build/ui/icons/arrow-right.d.ts +1 -0
- package/build/ui/icons/arrow-right.js +5 -0
- package/build/ui/icons/arrow-right.js.map +1 -0
- package/build/ui/icons/exchange.d.ts +6 -0
- package/build/ui/icons/exchange.js +6 -0
- package/build/ui/icons/exchange.js.map +1 -0
- package/build/ui/icons/logout.d.ts +1 -0
- package/build/ui/icons/logout.js +3 -0
- package/build/ui/icons/logout.js.map +1 -0
- package/build/ui/icons/pending.d.ts +1 -0
- package/build/ui/icons/pending.js +5 -0
- package/build/ui/icons/pending.js.map +1 -0
- package/build/ui/icons/qr.d.ts +1 -0
- package/build/ui/icons/qr.js +5 -0
- package/build/ui/icons/qr.js.map +1 -0
- package/build/ui/icons/search.d.ts +1 -0
- package/build/ui/icons/search.js +5 -0
- package/build/ui/icons/search.js.map +1 -0
- package/build/ui/icons/switch.d.ts +1 -0
- package/build/ui/icons/switch.js +5 -0
- package/build/ui/icons/switch.js.map +1 -0
- package/build/ui/icons/wallet.d.ts +1 -0
- package/build/ui/icons/wallet.js +5 -0
- package/build/ui/icons/wallet.js.map +1 -0
- package/build/ui/payment/Bridge.d.ts +27 -0
- package/build/ui/payment/Bridge.js +340 -0
- package/build/ui/payment/Bridge.js.map +1 -0
- package/build/ui/payment/DepositQR.d.ts +9 -0
- package/build/ui/payment/DepositQR.js +56 -0
- package/build/ui/payment/DepositQR.js.map +1 -0
- package/build/ui/payment/Payment.d.ts +16 -0
- package/build/ui/payment/Payment.js +50 -0
- package/build/ui/payment/Payment.js.map +1 -0
- package/build/ui/payment/Profile.d.ts +7 -0
- package/build/ui/payment/Profile.js +88 -0
- package/build/ui/payment/Profile.js.map +1 -0
- package/build/ui/payment/SelectRecipient.d.ts +14 -0
- package/build/ui/payment/SelectRecipient.js +68 -0
- package/build/ui/payment/SelectRecipient.js.map +1 -0
- package/build/ui/payment/SelectSender.d.ts +13 -0
- package/build/ui/payment/SelectSender.js +23 -0
- package/build/ui/payment/SelectSender.js.map +1 -0
- package/build/ui/payment/SelectToken.d.ts +13 -0
- package/build/ui/payment/SelectToken.js +92 -0
- package/build/ui/payment/SelectToken.js.map +1 -0
- package/build/ui/payment/TokenCard.d.ts +23 -0
- package/build/ui/payment/TokenCard.js +50 -0
- package/build/ui/payment/TokenCard.js.map +1 -0
- package/build/ui/router.d.ts +37 -0
- package/build/ui/router.js +56 -0
- package/build/ui/router.js.map +1 -0
- package/build/ui/styles.d.ts +11 -0
- package/build/ui/styles.js +273 -0
- package/build/ui/styles.js.map +1 -0
- package/package.json +60 -0
- package/skill.md +989 -0
- package/src/GoogleConnector.ts +102 -0
- package/src/HotConnector.ts +344 -0
- package/src/OmniConnector.ts +161 -0
- package/src/OmniWallet.ts +94 -0
- package/src/cosmos/connector.ts +242 -0
- package/src/cosmos/wallet.ts +77 -0
- package/src/events.ts +66 -0
- package/src/evm/abi.ts +39 -0
- package/src/evm/connector.ts +139 -0
- package/src/evm/wallet.ts +156 -0
- package/src/exchange.ts +426 -0
- package/src/hot-wallet/evm.ts +38 -0
- package/src/hot-wallet/hot.ts +39 -0
- package/src/hot-wallet/index.ts +4 -0
- package/src/hot-wallet/solana/account.ts +52 -0
- package/src/hot-wallet/solana/index.ts +98 -0
- package/src/hot-wallet/solana/register.ts +48 -0
- package/src/hot-wallet/solana/solana-wallet.ts +280 -0
- package/src/hot-wallet/solana/utils.ts +56 -0
- package/src/hot-wallet/stellar.ts +39 -0
- package/src/hot-wallet/ton.ts +56 -0
- package/src/hot-wallet/wallet.ts +44 -0
- package/src/index.ts +30 -0
- package/src/near/connector.ts +71 -0
- package/src/near/wallet.ts +255 -0
- package/src/omni/Intents.ts +454 -0
- package/src/omni/bridge.ts +38 -0
- package/src/omni/config.ts +130 -0
- package/src/omni/defaultTokens.ts +1078 -0
- package/src/omni/index.ts +8 -0
- package/src/omni/nearRpc.ts +187 -0
- package/src/omni/recipient.ts +41 -0
- package/src/omni/token.ts +125 -0
- package/src/omni/tokens.ts +68 -0
- package/src/omni/types.ts +46 -0
- package/src/omni/utils.ts +163 -0
- package/src/settings.ts +5 -0
- package/src/solana/connector.ts +151 -0
- package/src/solana/protocol.ts +66 -0
- package/src/solana/wallet.ts +230 -0
- package/src/solana/wallets.ts +243 -0
- package/src/stellar/connector.ts +69 -0
- package/src/stellar/wallet.ts +267 -0
- package/src/storage.ts +19 -0
- package/src/ton/connector.ts +138 -0
- package/src/ton/utils.ts +73 -0
- package/src/ton/wallet.ts +178 -0
- package/src/ui/Popup.tsx +62 -0
- package/src/ui/connect/AuthPopup.tsx +78 -0
- package/src/ui/connect/ConnectWallet.tsx +63 -0
- package/src/ui/connect/LogoutPopup.tsx +20 -0
- package/src/ui/connect/WCPopup.tsx +122 -0
- package/src/ui/connect/WCRequest.tsx +28 -0
- package/src/ui/connect/WalletPicker.tsx +92 -0
- package/src/ui/icons/arrow-right.tsx +8 -0
- package/src/ui/icons/exchange.tsx +17 -0
- package/src/ui/icons/logout.tsx +18 -0
- package/src/ui/icons/pending.tsx +18 -0
- package/src/ui/icons/qr.tsx +12 -0
- package/src/ui/icons/search.tsx +18 -0
- package/src/ui/icons/switch.tsx +10 -0
- package/src/ui/icons/wallet.tsx +18 -0
- package/src/ui/payment/Bridge.tsx +582 -0
- package/src/ui/payment/DepositQR.tsx +88 -0
- package/src/ui/payment/Payment.tsx +78 -0
- package/src/ui/payment/Profile.tsx +140 -0
- package/src/ui/payment/SelectRecipient.tsx +111 -0
- package/src/ui/payment/SelectSender.tsx +60 -0
- package/src/ui/payment/SelectToken.tsx +134 -0
- package/src/ui/payment/TokenCard.tsx +83 -0
- package/src/ui/router.tsx +92 -0
- package/src/ui/styles.ts +284 -0
- package/tsconfig.json +22 -0
- package/vite.config.ts +17 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { sep43Modules, HotWalletModule, StellarWalletsKit, WalletNetwork, ISupportedWallet } from "@creit.tech/stellar-wallets-kit";
|
|
2
|
+
import { Transaction } from "@stellar/stellar-base";
|
|
3
|
+
|
|
4
|
+
import { WalletType } from "../omni/config";
|
|
5
|
+
import { HotConnector } from "../HotConnector";
|
|
6
|
+
import { ConnectorType, OmniConnector } from "../OmniConnector";
|
|
7
|
+
import { isInjected } from "../hot-wallet/hot";
|
|
8
|
+
import { OmniWallet } from "../OmniWallet";
|
|
9
|
+
import StellarWallet from "./wallet";
|
|
10
|
+
|
|
11
|
+
class StellarConnector extends OmniConnector<StellarWallet, ISupportedWallet> {
|
|
12
|
+
stellarKit: StellarWalletsKit;
|
|
13
|
+
|
|
14
|
+
icon = "https://storage.herewallet.app/upload/1469894e53ca248ac6adceb2194e6950a13a52d972beb378a20bce7815ba01a4.png";
|
|
15
|
+
walletTypes = [WalletType.STELLAR, WalletType.OMNI];
|
|
16
|
+
type = ConnectorType.WALLET;
|
|
17
|
+
name = "Stellar Wallet";
|
|
18
|
+
id = "stellar";
|
|
19
|
+
|
|
20
|
+
constructor(wibe3: HotConnector, stellarKit?: StellarWalletsKit) {
|
|
21
|
+
super(wibe3);
|
|
22
|
+
|
|
23
|
+
this.stellarKit = stellarKit || new StellarWalletsKit({ network: WalletNetwork.PUBLIC, modules: isInjected() ? [new HotWalletModule()] : sep43Modules() });
|
|
24
|
+
this.stellarKit.getSupportedWallets().then((wallets) => {
|
|
25
|
+
const hot = wallets.find((w) => w.id === "hot-wallet");
|
|
26
|
+
this.options = wallets.filter((w) => w.id !== "hot-wallet").map((w) => ({ ...w, name: w.name, icon: w.icon, download: w.url, type: "external" as const, id: w.id }));
|
|
27
|
+
if (hot) this.options.unshift({ ...hot, name: hot.name, icon: hot.icon, download: hot.url, type: "external" as const, id: hot.id });
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
this.getConnectedWallet().then((data) => {
|
|
31
|
+
if (!data || !this.stellarKit) throw "No wallet";
|
|
32
|
+
|
|
33
|
+
this.stellarKit.setWallet(data.id!);
|
|
34
|
+
const signMessage = async (message: string) => this.stellarKit.signMessage(message);
|
|
35
|
+
const signTransaction = async (transaction: Transaction) => this.stellarKit.signTransaction(transaction.toXDR());
|
|
36
|
+
this.setWallet(new StellarWallet(this, { address: data.address!, signMessage, signTransaction }));
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async createWallet(address: string): Promise<OmniWallet> {
|
|
41
|
+
return new StellarWallet(this, { address });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async getConnectedWallet() {
|
|
45
|
+
if (isInjected()) {
|
|
46
|
+
this.stellarKit.setWallet("hot-wallet");
|
|
47
|
+
const { address } = await this.stellarKit.getAddress();
|
|
48
|
+
return { type: "wallet", id: "hot-wallet", address };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return await this.getStorage();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async connect(id: string) {
|
|
55
|
+
this.stellarKit.setWallet(id);
|
|
56
|
+
const { address } = await this.stellarKit.getAddress();
|
|
57
|
+
const signMessage = async (message: string) => this.stellarKit.signMessage(message);
|
|
58
|
+
const signTransaction = async (transaction: Transaction) => this.stellarKit.signTransaction(transaction.toXDR());
|
|
59
|
+
this.setStorage({ type: "wallet", id, address });
|
|
60
|
+
return this.setWallet(new StellarWallet(this, { address, signMessage, signTransaction }));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async disconnect() {
|
|
64
|
+
super.disconnect();
|
|
65
|
+
this.stellarKit.disconnect();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default StellarConnector;
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { base64, base58, hex, base32 } from "@scure/base";
|
|
2
|
+
import { Address, Asset, BASE_FEE, Claimant, Contract, Memo, nativeToScVal, Networks, Operation, TimeoutInfinite, Transaction, TransactionBuilder, xdr } from "@stellar/stellar-base";
|
|
3
|
+
import { rpc } from "@stellar/stellar-sdk";
|
|
4
|
+
|
|
5
|
+
import { WalletType } from "../omni/config";
|
|
6
|
+
import { OmniWallet } from "../OmniWallet";
|
|
7
|
+
import { OmniConnector } from "../OmniConnector";
|
|
8
|
+
import { bridge, ReviewFee } from "../omni/bridge";
|
|
9
|
+
import { formatter } from "../omni/utils";
|
|
10
|
+
import { Network } from "../omni/config";
|
|
11
|
+
import { Token } from "../omni/token";
|
|
12
|
+
|
|
13
|
+
interface ProtocolWallet {
|
|
14
|
+
signTransaction?: (transaction: Transaction) => Promise<{ signedTxXdr: string }>;
|
|
15
|
+
signMessage?: (message: string) => Promise<{ signedMessage: string }>;
|
|
16
|
+
address: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const ACCOUNT_FOR_SIMULATE = "GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7";
|
|
20
|
+
export enum ASSET_CONTRACT_METHOD {
|
|
21
|
+
GET_ALLOWANCE = "allowance",
|
|
22
|
+
APPROVE_ALLOWANCE = "approve",
|
|
23
|
+
GET_BALANCE = "balance",
|
|
24
|
+
TRANSFER = "transfer",
|
|
25
|
+
NAME = "name",
|
|
26
|
+
BURN = "burn",
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
class StellarWallet extends OmniWallet {
|
|
30
|
+
readonly type = WalletType.STELLAR;
|
|
31
|
+
|
|
32
|
+
constructor(readonly connector: OmniConnector, readonly wallet: ProtocolWallet) {
|
|
33
|
+
super(connector);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get address() {
|
|
37
|
+
return this.wallet.address;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get publicKey() {
|
|
41
|
+
const payload = base32.decode(this.address);
|
|
42
|
+
return base58.encode(payload.slice(1, -2));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get omniAddress() {
|
|
46
|
+
const payload = base32.decode(this.address);
|
|
47
|
+
return hex.encode(payload.slice(1, -2));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async fetchBalances(): Promise<Record<string, bigint>> {
|
|
51
|
+
const data = await fetch(`https://horizon.stellar.org/accounts/${this.address}`).then((res) => res.json());
|
|
52
|
+
const balances = data.balances?.map((ft: { asset_type: string; sponsor?: string | null; asset_code: string; asset_issuer: string; balance: string }) => {
|
|
53
|
+
const asset = ft.asset_type === "native" ? Asset.native() : new Asset(ft.asset_code, ft.asset_issuer);
|
|
54
|
+
const contractId = ft.asset_type === "native" ? "native" : asset.contractId(Networks.PUBLIC);
|
|
55
|
+
|
|
56
|
+
if (contractId === "native") {
|
|
57
|
+
const activatingReserve = ft.sponsor != null ? 0 : 1;
|
|
58
|
+
const trustlines = data.balances.filter((t: any) => t.asset_type !== "native" && t.sponsor == null);
|
|
59
|
+
const balance = BigInt(formatter.parseAmount(ft.balance, 7));
|
|
60
|
+
const reserved = BigInt(formatter.parseAmount(activatingReserve + 0.5 * (trustlines.length + (data.num_sponsoring || 0)), 7));
|
|
61
|
+
return [contractId, formatter.bigIntMax(0n, balance - BigInt(reserved))];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return [contractId, BigInt(formatter.parseAmount(ft.balance, 7))];
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return Object.fromEntries(balances);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async fetchBalance(chain: number, token: string): Promise<bigint> {
|
|
71
|
+
if (chain !== Network.Stellar) throw "Invalid chain";
|
|
72
|
+
const balances = await this.fetchBalances();
|
|
73
|
+
return balances[token] || 0n;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async transferFee(token: Token): Promise<ReviewFee> {
|
|
77
|
+
return new ReviewFee({ baseFee: 0n, gasLimit: 0n, chain: token.chain });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async emulateTransfer(token: string, receiver: string, amount: bigint, memo?: string): Promise<{ fee: ReviewFee; tx: Transaction }> {
|
|
81
|
+
const asset = await this.getAssetFromContractId(token);
|
|
82
|
+
const sendAmount = formatter.formatAmount(amount, 7);
|
|
83
|
+
|
|
84
|
+
const account = await bridge.stellar.callSoroban((s) => s.getAccount(this.address));
|
|
85
|
+
const baseFee = await bridge.stellar.callHorizon((h) => h.fetchBaseFee()).catch(() => +BASE_FEE);
|
|
86
|
+
const builder = new TransactionBuilder(account, {
|
|
87
|
+
memo: memo ? Memo.text(memo) : undefined,
|
|
88
|
+
networkPassphrase: Networks.PUBLIC,
|
|
89
|
+
fee: String(baseFee),
|
|
90
|
+
}).setTimeout(TimeoutInfinite);
|
|
91
|
+
|
|
92
|
+
if (receiver.startsWith("C")) {
|
|
93
|
+
const contract = new Contract(asset.contractId(Networks.PUBLIC));
|
|
94
|
+
const amountScVal = nativeToScVal(amount, { type: "i128" });
|
|
95
|
+
builder.addOperation(
|
|
96
|
+
contract.call(
|
|
97
|
+
"transfer", //
|
|
98
|
+
Address.fromString(this.address).toScVal(),
|
|
99
|
+
Address.fromString(receiver).toScVal(),
|
|
100
|
+
amountScVal
|
|
101
|
+
)
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const tx = await bridge.stellar.callSoroban((s) => s.prepareTransaction(builder.build() as any));
|
|
105
|
+
const fee = BigInt(Math.floor(baseFee * tx.operations.length));
|
|
106
|
+
return { fee: new ReviewFee({ baseFee: fee, priorityFee: 0n, gasLimit: 1n, chain: Network.Stellar }), tx: tx as unknown as Transaction };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
let needXlm = 0;
|
|
110
|
+
const receiverAccount = await bridge.stellar.callHorizon((h) => h.loadAccount(receiver)).catch(() => null);
|
|
111
|
+
const claimableBalance = Operation.createClaimableBalance({ amount: amount.toString(), claimants: [new Claimant(receiver)], asset });
|
|
112
|
+
|
|
113
|
+
if (receiverAccount == null) {
|
|
114
|
+
if (token === "native") {
|
|
115
|
+
builder.addOperation(Operation.createAccount({ destination: receiver, startingBalance: Math.max(1, sendAmount).toString() }));
|
|
116
|
+
needXlm = Math.max(1, sendAmount);
|
|
117
|
+
} else {
|
|
118
|
+
builder.addOperation(Operation.createAccount({ destination: receiver, startingBalance: "1" }));
|
|
119
|
+
builder.addOperation(claimableBalance);
|
|
120
|
+
needXlm = 1;
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
const trustline = receiverAccount.balances.find((b: any) => {
|
|
124
|
+
if (b.asset_type === "native") return false;
|
|
125
|
+
return b.asset_code === asset.code && b.asset_issuer === asset.issuer;
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Check if trustline exists for non-native assets
|
|
129
|
+
if (token !== "native" && !trustline) {
|
|
130
|
+
builder.addOperation(claimableBalance);
|
|
131
|
+
} else {
|
|
132
|
+
builder.addOperation(Operation.payment({ destination: receiver, asset, amount: sendAmount.toString() }));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const tx = builder.build();
|
|
137
|
+
const fee = BigInt(Math.floor(baseFee * tx.operations.length));
|
|
138
|
+
const need = fee + BigInt(formatter.parseAmount(needXlm, 7));
|
|
139
|
+
|
|
140
|
+
return { fee: new ReviewFee({ baseFee: need, priorityFee: 0n, gasLimit: 1n, chain: Network.Stellar }), tx };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async transfer(args: { token: Token; receiver: string; amount: bigint; comment?: string; gasFee?: ReviewFee }) {
|
|
144
|
+
const { tx } = await this.emulateTransfer(args.token.address, args.receiver, args.amount, args.comment);
|
|
145
|
+
return this.sendTransaction(tx);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async signIntentsWithAuth(domain: string, intents?: Record<string, any>[]) {
|
|
149
|
+
const seed = hex.encode(window.crypto.getRandomValues(new Uint8Array(32)));
|
|
150
|
+
const msgBuffer = new TextEncoder().encode(`${domain}_${seed}`);
|
|
151
|
+
const nonce = await window.crypto.subtle.digest("SHA-256", new Uint8Array(msgBuffer));
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
signed: await this.signIntents(intents || [], { nonce: new Uint8Array(nonce) }),
|
|
155
|
+
publicKey: `ed25519:${this.publicKey}`,
|
|
156
|
+
chainId: WalletType.STELLAR,
|
|
157
|
+
address: this.address,
|
|
158
|
+
seed,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async sendTransaction(transaction: Transaction) {
|
|
163
|
+
if (!this.wallet.signTransaction) throw "not impl";
|
|
164
|
+
const result = await this.wallet.signTransaction(transaction);
|
|
165
|
+
const txObject = new Transaction(result.signedTxXdr, Networks.PUBLIC);
|
|
166
|
+
const { hash } = await bridge.stellar.callHorizon((t) => t.submitTransaction(txObject as any));
|
|
167
|
+
return hash;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async signMessage(message: string) {
|
|
171
|
+
if (!this.wallet.signMessage) throw "not impl";
|
|
172
|
+
return await this.wallet.signMessage(message);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async signIntents(intents: Record<string, any>[], options?: { deadline?: number; nonce?: Uint8Array }): Promise<Record<string, any>> {
|
|
176
|
+
const nonce = new Uint8Array(options?.nonce || window.crypto.getRandomValues(new Uint8Array(32)));
|
|
177
|
+
|
|
178
|
+
const message = JSON.stringify({
|
|
179
|
+
deadline: options?.deadline ? new Date(options.deadline).toISOString() : "2100-01-01T00:00:00.000Z",
|
|
180
|
+
nonce: base64.encode(nonce),
|
|
181
|
+
verifying_contract: "intents.near",
|
|
182
|
+
signer_id: this.omniAddress,
|
|
183
|
+
intents: intents,
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const signature = await this.signMessage(message);
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
signature: `ed25519:${base58.encode(base64.decode(signature.signedMessage))}`,
|
|
190
|
+
public_key: `ed25519:${this.publicKey}`,
|
|
191
|
+
standard: "sep53",
|
|
192
|
+
payload: message,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
static async isTokenActivated(address: string, token: string) {
|
|
197
|
+
if (address === "native") return true;
|
|
198
|
+
const data = await bridge.stellar.callHorizon((h) => h.loadAccount(address));
|
|
199
|
+
return data.balances.some((ft: any) => {
|
|
200
|
+
if (!ft.asset_issuer) return false;
|
|
201
|
+
const asset = new Asset(ft.asset_code, ft.asset_issuer).contractId(Networks.PUBLIC);
|
|
202
|
+
return asset.toLowerCase() === token.toLowerCase();
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async changeTrustline(address: string) {
|
|
207
|
+
if (address === "native") return;
|
|
208
|
+
const asset = await this.getAssetFromContractId(address);
|
|
209
|
+
const account = await bridge.stellar.callHorizon((h) => h.loadAccount(this.address));
|
|
210
|
+
const trustlineOp = Operation.changeTrust({ asset: asset, source: this.address });
|
|
211
|
+
const trustlineTx = new TransactionBuilder(account, { fee: BASE_FEE, networkPassphrase: Networks.PUBLIC }) //
|
|
212
|
+
.addOperation(trustlineOp)
|
|
213
|
+
.setTimeout(TimeoutInfinite)
|
|
214
|
+
.build();
|
|
215
|
+
|
|
216
|
+
return this.sendTransaction(trustlineTx);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
readonly assetsCache = new Map<string, Asset>();
|
|
220
|
+
async getAssetFromContractId(id: string): Promise<Asset> {
|
|
221
|
+
if (id === "native") return Asset.native();
|
|
222
|
+
if (this.assetsCache.has(id)) {
|
|
223
|
+
return Promise.resolve(this.assetsCache.get(id)!);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const tx = await this.buildSmartContactTx(ACCOUNT_FOR_SIMULATE, id, ASSET_CONTRACT_METHOD.NAME);
|
|
227
|
+
const result = (await bridge.stellar.callSoroban((s) => s.simulateTransaction(tx as any))) as unknown as rpc.Api.SimulateTransactionSuccessResponse;
|
|
228
|
+
|
|
229
|
+
const value = result?.result?.retval?.value();
|
|
230
|
+
if (!value) throw "Asset not found";
|
|
231
|
+
|
|
232
|
+
const [code, issuer] = value.toString().split(":");
|
|
233
|
+
const asset = issuer ? new Asset(code, issuer) : Asset.native();
|
|
234
|
+
this.assetsCache.set(id, asset);
|
|
235
|
+
return asset;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async buildSmartContactTx(publicKey: string, contactId: string, method: string, ...args: any[]) {
|
|
239
|
+
const account = await bridge.stellar.callSoroban((s) => s.getAccount(publicKey));
|
|
240
|
+
const contract = new Contract(contactId);
|
|
241
|
+
const builtTx = new TransactionBuilder(account, { fee: BASE_FEE, networkPassphrase: Networks.PUBLIC });
|
|
242
|
+
|
|
243
|
+
if (args) builtTx.addOperation(contract.call(method, ...args));
|
|
244
|
+
else builtTx.addOperation(contract.call(method));
|
|
245
|
+
return builtTx.setTimeout(TimeoutInfinite).build();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async getTokenBalance(token: Asset | string, contract: string): Promise<bigint> {
|
|
249
|
+
const tx = await this.buildSmartContactTx(
|
|
250
|
+
ACCOUNT_FOR_SIMULATE, //
|
|
251
|
+
typeof token === "string" ? (token === "native" ? new Asset("XLM").contractId(Networks.PUBLIC) : token) : token.contractId(Networks.PUBLIC),
|
|
252
|
+
ASSET_CONTRACT_METHOD.GET_BALANCE,
|
|
253
|
+
Address.fromString(contract).toScVal()
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
const result = (await bridge.stellar.callSoroban((s) => s.simulateTransaction(tx as any))) as unknown as rpc.Api.SimulateTransactionSuccessResponse;
|
|
257
|
+
if (result) return BigInt(this.i128ToInt(result.result?.retval.value() as xdr.Int128Parts));
|
|
258
|
+
return 0n;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
i128ToInt(val: xdr.Int128Parts): string {
|
|
262
|
+
// @ts-expect-error TODO: fix this
|
|
263
|
+
return new BigNumber(val.hi()._value).plus(val.lo()._value).div(1e7).toString();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export default StellarWallet;
|
package/src/storage.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface DataStorage {
|
|
2
|
+
get(key: string): Promise<string | null>;
|
|
3
|
+
set(key: string, value: string): Promise<void>;
|
|
4
|
+
remove(key: string): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export class LocalStorage implements DataStorage {
|
|
8
|
+
async get(key: string) {
|
|
9
|
+
return localStorage.getItem(key);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async set(key: string, value: string) {
|
|
13
|
+
localStorage.setItem(key, value);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async remove(key: string) {
|
|
17
|
+
localStorage.removeItem(key);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { TonConnectUI, TonConnect } from "@tonconnect/ui";
|
|
2
|
+
import { runInAction } from "mobx";
|
|
3
|
+
|
|
4
|
+
import { WalletType } from "../omni/config";
|
|
5
|
+
import { HotConnector } from "../HotConnector";
|
|
6
|
+
import { ConnectorType, OmniConnector } from "../OmniConnector";
|
|
7
|
+
import { isInjected } from "../hot-wallet/hot";
|
|
8
|
+
import TonWallet from "./wallet";
|
|
9
|
+
|
|
10
|
+
export interface TonConnectorOptions {
|
|
11
|
+
tonConnect?: TonConnectUI;
|
|
12
|
+
tonWalletsUrl?: string;
|
|
13
|
+
tonManifestUrl?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const hotWallet = {
|
|
17
|
+
app_name: "hot",
|
|
18
|
+
name: "HOT",
|
|
19
|
+
image: "https://raw.githubusercontent.com/hot-dao/media/main/logo.png",
|
|
20
|
+
about_url: "https://hot-labs.org/",
|
|
21
|
+
universal_url: "https://t.me/herewalletbot?attach=wallet",
|
|
22
|
+
bridge: [
|
|
23
|
+
{
|
|
24
|
+
type: "sse",
|
|
25
|
+
url: "https://sse-bridge.hot-labs.org",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
type: "js",
|
|
29
|
+
key: "hotWallet",
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
platforms: ["ios", "android", "chrome", "firefox", "macos", "windows", "linux"],
|
|
33
|
+
features: [
|
|
34
|
+
{
|
|
35
|
+
name: "SendTransaction",
|
|
36
|
+
maxMessages: 4,
|
|
37
|
+
extraCurrencySupported: false,
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
class TonConnector extends OmniConnector<TonWallet> {
|
|
43
|
+
type = ConnectorType.WALLET;
|
|
44
|
+
walletTypes = [WalletType.TON, WalletType.OMNI];
|
|
45
|
+
icon = "https://storage.herewallet.app/upload/3ffa61e237f8e38d390abd60200db8edff3ec2b20aad0cc0a8c7a8ba9c318124.png";
|
|
46
|
+
name = "TON Wallet";
|
|
47
|
+
id = "ton";
|
|
48
|
+
|
|
49
|
+
private tonConnect = this.initializeConnector();
|
|
50
|
+
constructor(wibe3: HotConnector, readonly args?: TonConnectorOptions) {
|
|
51
|
+
super(wibe3);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async initializeConnector() {
|
|
55
|
+
if (typeof window === "undefined") throw "TonConnector can only be initialized in the browser";
|
|
56
|
+
|
|
57
|
+
const url = await fetch(this.args?.tonWalletsUrl || "https://config.ton.org/wallets-v2.json")
|
|
58
|
+
.then((res) => res.json())
|
|
59
|
+
.then((data) => {
|
|
60
|
+
const list = data.filter((t: any) => t.app_name !== "hot");
|
|
61
|
+
list.unshift(hotWallet);
|
|
62
|
+
const myBlob = new Blob([JSON.stringify(list)], { type: "text/plain" });
|
|
63
|
+
return URL.createObjectURL(myBlob);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const tonConnect =
|
|
67
|
+
this.args?.tonConnect ||
|
|
68
|
+
new TonConnectUI({
|
|
69
|
+
connector: new TonConnect({
|
|
70
|
+
walletsListSource: url,
|
|
71
|
+
manifestUrl: this.args?.tonManifestUrl,
|
|
72
|
+
}),
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
tonConnect.onStatusChange(async (wallet) => {
|
|
76
|
+
if (!wallet) return this.removeWallet();
|
|
77
|
+
this.setWallet(
|
|
78
|
+
new TonWallet(this, {
|
|
79
|
+
sendTransaction: (params) => tonConnect.sendTransaction(params),
|
|
80
|
+
signData: (params) => tonConnect.signData(params),
|
|
81
|
+
account: wallet.account,
|
|
82
|
+
})
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
tonConnect.connector.restoreConnection();
|
|
87
|
+
tonConnect.getWallets().then((wallets) => {
|
|
88
|
+
runInAction(() => {
|
|
89
|
+
this.options = wallets.map((w) => ({
|
|
90
|
+
name: w.name,
|
|
91
|
+
icon: w.imageUrl,
|
|
92
|
+
id: w.appName,
|
|
93
|
+
download: w.aboutUrl,
|
|
94
|
+
type: "external" as const,
|
|
95
|
+
}));
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const tcRoot = document.querySelector("#tc-widget-root");
|
|
100
|
+
if (tcRoot instanceof HTMLElement) {
|
|
101
|
+
tcRoot.style.zIndex = "10000000000";
|
|
102
|
+
tcRoot.style.position = "fixed";
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (isInjected()) {
|
|
106
|
+
tonConnect.getWallets().then((wallets) => {
|
|
107
|
+
const wallet = wallets.find((w) => w.appName === "hot");
|
|
108
|
+
if (wallet) tonConnect.connector.connect(wallet, { tonProof: "wibe3" });
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return tonConnect;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async createWallet(address: string) {
|
|
116
|
+
return new TonWallet(this, { account: { address } });
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async connect(id: string) {
|
|
120
|
+
const connector = await this.tonConnect;
|
|
121
|
+
connector.openSingleWalletModal(id);
|
|
122
|
+
return new Promise<TonWallet>((resolve) => {
|
|
123
|
+
const dispose = this.onConnect(({ wallet }) => {
|
|
124
|
+
if (!wallet) return;
|
|
125
|
+
resolve(wallet);
|
|
126
|
+
dispose();
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async disconnect() {
|
|
132
|
+
super.disconnect();
|
|
133
|
+
const connector = await this.tonConnect;
|
|
134
|
+
connector.disconnect();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export default TonConnector;
|
package/src/ton/utils.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Address, beginCell, Cell, loadStateInit, toNano } from "@ton/core";
|
|
2
|
+
import { Maybe } from "@ton/core/dist/utils/maybe";
|
|
3
|
+
import { JettonBalance, TonApiClient } from "@ton-api/client";
|
|
4
|
+
import { GlobalSettings } from "../settings";
|
|
5
|
+
|
|
6
|
+
export const tonApi = new TonApiClient({ baseUrl: "https://tonapi.io", apiKey: GlobalSettings.tonApi });
|
|
7
|
+
|
|
8
|
+
export const jettonTransferAmount = toNano(0.1);
|
|
9
|
+
export const jettonTransferForwardAmount = BigInt(1);
|
|
10
|
+
|
|
11
|
+
export enum JettonExtension {
|
|
12
|
+
NonTransferable = "non_transferable",
|
|
13
|
+
CustomPayload = "custom_payload",
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const seeIfCompressed = (jetton: JettonBalance) => {
|
|
17
|
+
return !!jetton.extensions && jetton.extensions.includes(JettonExtension.CustomPayload);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type StateInit = ReturnType<typeof toStateInit>;
|
|
21
|
+
export const toStateInit = (stateInit?: string): { code: Maybe<Cell>; data: Maybe<Cell> } | undefined => {
|
|
22
|
+
if (!stateInit) return undefined;
|
|
23
|
+
const { code, data } = loadStateInit(Cell.fromBase64(stateInit).asSlice());
|
|
24
|
+
return { code, data };
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const getJettonCustomPayload = async (walletAddress: Address, token: Address): Promise<{ jettonWallet: Address; customPayload: Cell | null; stateInit?: StateInit }> => {
|
|
28
|
+
const jetton = await tonApi.accounts.getAccountJettonBalance(walletAddress, token, { supported_extensions: ["custom_payload"] });
|
|
29
|
+
const jettonWallet = jetton.walletAddress.address;
|
|
30
|
+
|
|
31
|
+
if (!seeIfCompressed(jetton)) return { jettonWallet, customPayload: null, stateInit: undefined };
|
|
32
|
+
const { customPayload, stateInit } = await tonApi.jettons.getJettonTransferPayload(walletAddress, jetton.jetton.address);
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
customPayload: customPayload ? Cell.fromBase64(Buffer.from(customPayload, "hex").toString("base64")) : null,
|
|
36
|
+
stateInit: stateInit ? toStateInit(Buffer.from(stateInit, "hex").toString("base64")) : undefined,
|
|
37
|
+
jettonWallet,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const jettonTransferBody = (params: { queryId: bigint; jettonAmount: bigint; toAddress: Address; responseAddress: Address; forwardAmount: bigint; forwardPayload: Cell | null; customPayload: Cell | null }) => {
|
|
42
|
+
return beginCell()
|
|
43
|
+
.storeUint(0xf_8a_7e_a5, 32) // request_transfer op
|
|
44
|
+
.storeUint(params.queryId, 64)
|
|
45
|
+
.storeCoins(params.jettonAmount)
|
|
46
|
+
.storeAddress(params.toAddress)
|
|
47
|
+
.storeAddress(params.responseAddress)
|
|
48
|
+
.storeMaybeRef(params.customPayload) // null custom_payload
|
|
49
|
+
.storeCoins(params.forwardAmount)
|
|
50
|
+
.storeMaybeRef(params.forwardPayload) // storeMaybeRef put 1 bit before cell (forward_payload in cell) or 0 for null (forward_payload in slice)
|
|
51
|
+
.endCell();
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const createJettonTransferMsgParams = async ({ jetton, amount, recipient, address, forwardPayload }: { address: Address; recipient: Address; jetton: Address; amount: bigint; forwardPayload: Cell | null }) => {
|
|
55
|
+
const { jettonWallet, customPayload, stateInit } = await getJettonCustomPayload(address, jetton);
|
|
56
|
+
const body = jettonTransferBody({
|
|
57
|
+
queryId: 0n,
|
|
58
|
+
jettonAmount: amount,
|
|
59
|
+
toAddress: recipient,
|
|
60
|
+
responseAddress: address,
|
|
61
|
+
forwardAmount: 1n,
|
|
62
|
+
forwardPayload,
|
|
63
|
+
customPayload,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
to: jettonWallet,
|
|
68
|
+
value: jettonTransferAmount,
|
|
69
|
+
init: stateInit,
|
|
70
|
+
body: body,
|
|
71
|
+
bounce: true,
|
|
72
|
+
};
|
|
73
|
+
};
|