@hinkal/common 0.2.34 → 0.2.35
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/API/callNearIntentsAPI.cjs +1 -0
- package/API/callNearIntentsAPI.d.ts +3 -0
- package/API/callNearIntentsAPI.mjs +8 -0
- package/API/enclaveSignatureCalls.cjs +1 -1
- package/API/enclaveSignatureCalls.d.ts +1 -1
- package/API/enclaveSignatureCalls.mjs +1 -1
- package/API/index.cjs +1 -1
- package/API/index.d.ts +1 -0
- package/API/index.mjs +1 -0
- package/constants/bridging.constants.cjs +1 -1
- package/constants/bridging.constants.d.ts +14 -0
- package/constants/bridging.constants.mjs +24 -5
- package/constants/chains.constants.cjs +1 -1
- package/constants/chains.constants.d.ts +1 -0
- package/constants/chains.constants.mjs +13 -13
- package/constants/index.cjs +1 -1
- package/constants/index.mjs +1 -0
- package/constants/protocol.constants.cjs +1 -1
- package/constants/protocol.constants.d.ts +2 -0
- package/constants/protocol.constants.mjs +2 -2
- package/constants/server.constants.cjs +1 -1
- package/constants/server.constants.d.ts +2 -0
- package/constants/server.constants.mjs +2 -0
- package/constants/token-data/index.cjs +1 -1
- package/constants/token-data/index.d.ts +1 -0
- package/constants/token-data/index.mjs +1 -0
- package/constants/token-data/popularNonRebasingTokens.cjs +1 -0
- package/constants/token-data/popularNonRebasingTokens.d.ts +2 -0
- package/constants/token-data/popularNonRebasingTokens.mjs +11 -0
- package/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.d.ts +7 -1
- package/data-structures/Hinkal/Hinkal.mjs +123 -101
- package/data-structures/Hinkal/IHinkal.d.ts +7 -1
- package/data-structures/Hinkal/hinkalNearDepositAndBridge.cjs +1 -0
- package/data-structures/Hinkal/hinkalNearDepositAndBridge.d.ts +6 -0
- package/data-structures/Hinkal/hinkalNearDepositAndBridge.mjs +43 -0
- package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.d.ts +2 -2
- package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.mjs +31 -30
- package/data-structures/Hinkal/index.cjs +1 -1
- package/data-structures/Hinkal/index.d.ts +1 -0
- package/data-structures/Hinkal/index.mjs +1 -0
- package/data-structures/crypto-keys/keys.cjs +1 -1
- package/data-structures/crypto-keys/keys.d.ts +18 -0
- package/data-structures/crypto-keys/keys.mjs +10 -0
- package/data-structures/index.cjs +1 -1
- package/data-structures/index.mjs +1 -0
- package/error-handling/error-codes.constants.cjs +1 -1
- package/error-handling/error-codes.constants.d.ts +2 -0
- package/error-handling/error-codes.constants.mjs +2 -0
- package/functions/index.cjs +1 -1
- package/functions/index.mjs +1 -0
- package/functions/pre-transaction/sendV0Transaction.cjs +2 -1
- package/functions/pre-transaction/sendV0Transaction.mjs +2 -2
- package/functions/utils/enclave-signature-storage.cjs +1 -1
- package/functions/utils/enclave-signature-storage.d.ts +1 -1
- package/functions/utils/enclave-signature-storage.mjs +1 -1
- package/functions/utils/index.cjs +1 -1
- package/functions/utils/index.d.ts +1 -0
- package/functions/utils/index.mjs +1 -0
- package/functions/utils/nearIntents.utils.cjs +1 -0
- package/functions/utils/nearIntents.utils.d.ts +11 -0
- package/functions/utils/nearIntents.utils.mjs +36 -0
- package/functions/utils/time.utils.cjs +1 -1
- package/functions/utils/time.utils.d.ts +1 -0
- package/functions/utils/time.utils.mjs +2 -2
- package/index.cjs +1 -1
- package/index.mjs +320 -316
- package/package.json +1 -1
- package/types/index.d.ts +1 -0
- package/types/near-intents.types.d.ts +60 -0
- package/types/solana.types.d.ts +1 -0
- package/webworker/{logError-DZiJbbaT.js → logError-DoUkEIFE.js} +13 -13
- package/webworker/package.json +1 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.mjs +1 -1
- package/webworker/utxoWorkerNode.cjs +1 -1
- package/webworker/viteWorkerURL.constant.cjs +3 -3
- package/webworker/viteWorkerURL.constant.mjs +3 -3
- package/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.cjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.mjs +1 -1
- package/webworker/zkProofWorkerNode.cjs +1 -1
|
@@ -19,6 +19,7 @@ import { ClientCommitmentsSnapshotService, ClientNullifierSnapshotService, Clien
|
|
|
19
19
|
import { Idl, Program } from '@coral-xyz/anchor';
|
|
20
20
|
import { PublicKey } from '@solana/web3.js';
|
|
21
21
|
import { BridgeRecipient } from '../../types/bridging-tx.types';
|
|
22
|
+
import { NearBridgeParams, NearBridgeResult } from '../../types/near-intents.types';
|
|
22
23
|
import { Utxo } from '../utxo/Utxo';
|
|
23
24
|
export declare class Hinkal<ConnectorType> implements IHinkal {
|
|
24
25
|
private ethereumProviderAdapter?;
|
|
@@ -43,10 +44,14 @@ export declare class Hinkal<ConnectorType> implements IHinkal {
|
|
|
43
44
|
initProviderAdapter(connector: ConnectorType, providerAdapter: IProviderAdapter<ConnectorType>): Promise<void>;
|
|
44
45
|
getSigningMessage(mode?: LoginMessageMode): string;
|
|
45
46
|
signHinkalMessage(mode?: LoginMessageMode): Promise<string>;
|
|
47
|
+
signSolanaLedgerMessage(): Promise<{
|
|
48
|
+
signature: string;
|
|
49
|
+
txMessageForSolanaLedger: string;
|
|
50
|
+
}>;
|
|
46
51
|
initUserKeys(mode?: LoginMessageMode): Promise<void>;
|
|
47
52
|
initUserKeysWithSignature(signature: string): void;
|
|
48
53
|
initUserKeysFromSeedPhrases(seedPhrases: string[]): Promise<void>;
|
|
49
|
-
storeAndGetInitialSignature(authSignature: string, isSolanaLedger
|
|
54
|
+
storeAndGetInitialSignature(authSignature: string, isSolanaLedger?: boolean, txMessageForSolanaLedger?: string): Promise<string>;
|
|
50
55
|
resetMerkle(chains?: number[]): Promise<void>;
|
|
51
56
|
getTronWeb(): import('tronweb').TronWeb;
|
|
52
57
|
getSupportedChains(): number[];
|
|
@@ -90,6 +95,7 @@ export declare class Hinkal<ConnectorType> implements IHinkal {
|
|
|
90
95
|
depositAndWithdraw(erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, preEstimateGas?: boolean): Promise<string>;
|
|
91
96
|
claimUtxo(erc20Token: ERC20Token, utxo: Utxo, feeStructureOverride?: FeeStructure, claimableSignature?: string): Promise<string>;
|
|
92
97
|
depositAndBridge(erc20Token: ERC20Token, recipientBridges: BridgeRecipient[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, preEstimateGas?: boolean): Promise<string>;
|
|
98
|
+
nearDepositAndBridge(erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], params: NearBridgeParams, txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, action?: AdminTransactionType, dashboardAccountId?: string): Promise<NearBridgeResult>;
|
|
93
99
|
prooflessDeposit(erc20Tokens: ERC20Token[], amountChanges: bigint[], stealthAddressStructures?: StealthAddressStructure[], action?: AdminTransactionType, returnTxData?: boolean): Promise<string | ethers.TransactionRequest | TronWebTypes.Transaction<TronWebTypes.TriggerSmartContract>>;
|
|
94
100
|
prooflessDepositWithPublicFee(erc20Token: ERC20Token, amounts: bigint[], stealthAddressStructures: StealthAddressStructure[], feeAmount: bigint, action?: AdminTransactionType): Promise<string>;
|
|
95
101
|
getSolanaProgram(idl: Idl): Program;
|
|
@@ -2,62 +2,64 @@ import { ContractType as e } from "../../types/ethereum-network.types.mjs";
|
|
|
2
2
|
import { CustomJSONStringify as t } from "../../functions/utils/serialize.utils.mjs";
|
|
3
3
|
import { isExtension as n } from "../../constants/vite.constants.mjs";
|
|
4
4
|
import { HINKAL_SUPPORTED_CHAINS as r, WALLET_SUPPORTED_CHAINS as i, chainIds as a, currentSolanaChainId as o, currentTronChainId as s, isSameOnchainNetwork as c, isSolanaLike as l, isTronLike as u, networkRegistry as d, setHinkalTronChainId as f } from "../../constants/chains.constants.mjs";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { DETERMINISTIC_SOLANA_LEDGER_BLOCKHASH as p, DETERMINISTIC_SOLANA_LEDGER_LAST_VALID_BLOCK_HEIGHT as m } from "../../constants/protocol.constants.mjs";
|
|
6
|
+
import { EventType as h, LoginMessageMode as g } from "../../types/hinkal.types.mjs";
|
|
7
|
+
import { API as _ } from "../../API/API.mjs";
|
|
7
8
|
import { supportedPassportLinks as ee } from "../../constants/kyc.constants.mjs";
|
|
8
9
|
import { transactionErrorCodes as te } from "../../error-handling/error-codes.constants.mjs";
|
|
9
10
|
import { getErc20TokensForChain as ne } from "../../functions/utils/erc20tokenFunctions.mjs";
|
|
10
11
|
import "../../API/index.mjs";
|
|
11
12
|
import { poseidonFunction as re } from "../../crypto/poseidon.mjs";
|
|
12
|
-
import { UserKeys as
|
|
13
|
-
import { validateAndGetChainId as
|
|
14
|
-
import { privateTokensDB as
|
|
15
|
-
import { getShieldedBalance as
|
|
16
|
-
import { getMerkleAccountPublicKey as
|
|
17
|
-
import { getContractWithFetcherByChainId as
|
|
18
|
-
import { reloadPage as
|
|
19
|
-
import { createCacheDevice as
|
|
20
|
-
import { SolanaProviderAdapter as
|
|
21
|
-
import { storeAndGetSignatureFromEnclave as
|
|
22
|
-
import { generateHashFromSeedPhrases as
|
|
23
|
-
import { fetchSolanaMerkleTreeRootHash as
|
|
24
|
-
import { createTransaferEmporiumOpsBatch as
|
|
25
|
-
import { hinkalDeposit as
|
|
26
|
-
import { checkTokenLimitsUSD as
|
|
27
|
-
import { hinkalDepositAndWithdraw as
|
|
28
|
-
import { hinkalSolanaDeposit as
|
|
29
|
-
import { hinkalSwap as
|
|
30
|
-
import { hinkalWithdraw as
|
|
31
|
-
import { MerkleTree as
|
|
13
|
+
import { UserKeys as v } from "../crypto-keys/keys.mjs";
|
|
14
|
+
import { validateAndGetChainId as y } from "../../functions/utils/token-check.utils.mjs";
|
|
15
|
+
import { privateTokensDB as b } from "../TokenDBs/PrivateTokensDB.mjs";
|
|
16
|
+
import { getShieldedBalance as x } from "../../functions/web3/events/getShieldedBalance.mjs";
|
|
17
|
+
import { getMerkleAccountPublicKey as S } from "../../functions/pre-transaction/solana.mjs";
|
|
18
|
+
import { getContractWithFetcherByChainId as C } from "../../functions/web3/getContractMetadata.mjs";
|
|
19
|
+
import { reloadPage as w } from "../../functions/utils/reloadPage.mjs";
|
|
20
|
+
import { createCacheDevice as T } from "../../functions/utils/cacheDevice.utils.mjs";
|
|
21
|
+
import { SolanaProviderAdapter as E } from "../../providers/SolanaProviderAdapter.mjs";
|
|
22
|
+
import { storeAndGetSignatureFromEnclave as D } from "../../functions/utils/enclave-signature-storage.mjs";
|
|
23
|
+
import { generateHashFromSeedPhrases as O } from "../../functions/utils/mnemonics.mjs";
|
|
24
|
+
import { fetchSolanaMerkleTreeRootHash as k } from "../../functions/web3/fetchSolanaMerkleTreeRootHash.mjs";
|
|
25
|
+
import { createTransaferEmporiumOpsBatch as A } from "../../functions/private-wallet/emporium.helpers.mjs";
|
|
26
|
+
import { hinkalDeposit as j, hinkalDepositForOther as M } from "./hinkalDeposit.mjs";
|
|
27
|
+
import { checkTokenLimitsUSD as N } from "../../functions/kyc/checkTokenLimitsUSD.mjs";
|
|
28
|
+
import { hinkalDepositAndWithdraw as P } from "./hinkalDepositAndWithdraw.mjs";
|
|
29
|
+
import { hinkalSolanaDeposit as F, hinkalSolanaDepositForOther as I, hinkalSolanaProoflessDepositWithPublicFee as L } from "./hinkalSolanaDeposit.mjs";
|
|
30
|
+
import { hinkalSwap as R } from "./hinkalSwap.mjs";
|
|
31
|
+
import { hinkalWithdraw as z } from "./hinkalWithdraw.mjs";
|
|
32
|
+
import { MerkleTree as B } from "../merkle-tree/MerkleTree.mjs";
|
|
32
33
|
import "../merkle-tree/index.mjs";
|
|
33
|
-
import { resetMerkleTrees as
|
|
34
|
-
import { MultiThreadedUtxoUtils as
|
|
35
|
-
import { hinkalPrivateWallet as
|
|
36
|
-
import { getRecipientInfo as
|
|
37
|
-
import { hinkalSignSubAccount as
|
|
38
|
-
import { hinkalActionReceive as
|
|
34
|
+
import { resetMerkleTrees as V } from "./resetMerkleTrees.mjs";
|
|
35
|
+
import { MultiThreadedUtxoUtils as ie } from "../MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.mjs";
|
|
36
|
+
import { hinkalPrivateWallet as H } from "./hinkalPrivateWallet.mjs";
|
|
37
|
+
import { getRecipientInfo as U } from "./hinkalGetRecipientInfo.mjs";
|
|
38
|
+
import { hinkalSignSubAccount as W } from "./hinkalSignSubAccount.mjs";
|
|
39
|
+
import { hinkalActionReceive as G } from "./hinkalActionReceive.mjs";
|
|
39
40
|
import "../TokenDBs/index.mjs";
|
|
40
|
-
import { hinkalProoflessDeposit as
|
|
41
|
-
import { hinkalProxySwap as
|
|
42
|
-
import { hinkalMultiSendPrivateRecipients as
|
|
43
|
-
import { hinkalTransfer as
|
|
44
|
-
import { hinkalProxyToPrivate as
|
|
41
|
+
import { hinkalProoflessDeposit as K, hinkalProoflessDepositWithPublicFee as q } from "./hinkalProoflessDeposit.mjs";
|
|
42
|
+
import { hinkalProxySwap as J } from "./hinkalProxySwap.mjs";
|
|
43
|
+
import { hinkalMultiSendPrivateRecipients as Y } from "./hinkalMultiSend.mjs";
|
|
44
|
+
import { hinkalTransfer as ae } from "./hinkalTransfer.mjs";
|
|
45
|
+
import { hinkalProxyToPrivate as oe } from "./hinkalProxyToPrivate.mjs";
|
|
45
46
|
import { TronProviderAdapter as X } from "../../providers/TronProviderAdapter.mjs";
|
|
46
|
-
import { hinkalSolanaDepositAndWithdraw as
|
|
47
|
-
import { hinkalSolanaWithdraw as
|
|
48
|
-
import { hinkalSolanaTransfer as
|
|
49
|
-
import { hinkalSolanaSwap as
|
|
50
|
-
import { hinkalSolanaProxySend as
|
|
51
|
-
import { hinkalSolanaProxySwap as
|
|
52
|
-
import { hinkalSolanaProxyShield as
|
|
53
|
-
import { hinkalDepositAndBridge as
|
|
54
|
-
import {
|
|
55
|
-
import {
|
|
56
|
-
import {
|
|
57
|
-
import {
|
|
58
|
-
import {
|
|
47
|
+
import { hinkalSolanaDepositAndWithdraw as se } from "./hinkalSolanaDepositAndWithdraw.mjs";
|
|
48
|
+
import { hinkalSolanaWithdraw as ce } from "./hinkalSolanaWithdraw.mjs";
|
|
49
|
+
import { hinkalSolanaTransfer as le } from "./hinkalSolanaTransfer.mjs";
|
|
50
|
+
import { hinkalSolanaSwap as ue } from "./hinkalSolanaSwap.mjs";
|
|
51
|
+
import { hinkalSolanaProxySend as de } from "./hinkalSolanaProxySend.mjs";
|
|
52
|
+
import { hinkalSolanaProxySwap as fe } from "./hinkalSolanaProxySwap.mjs";
|
|
53
|
+
import { hinkalSolanaProxyShield as Z } from "./hinkalSolanaProxyShield.mjs";
|
|
54
|
+
import { hinkalDepositAndBridge as pe } from "./hinkalDepositAndBridge.mjs";
|
|
55
|
+
import { hinkalNearDepositAndBridge as me } from "./hinkalNearDepositAndBridge.mjs";
|
|
56
|
+
import { hinkalClaimUtxo as Q } from "./hinkalClaimUtxo.mjs";
|
|
57
|
+
import { hinkalSolanaProoflessDeposit as he } from "./hinkalSolanaProoflessDeposit.mjs";
|
|
58
|
+
import { hinkalSolanaClaimUtxo as ge } from "./hinkalSolanaClaimUtxo.mjs";
|
|
59
|
+
import { hinkalWithdrawStuckUtxos as _e } from "./hinkalWithdrawStuckUtxos.mjs";
|
|
60
|
+
import { PublicKey as $, Transaction as ve } from "@solana/web3.js";
|
|
59
61
|
//#region libs/shared/common/src/data-structures/Hinkal/Hinkal.ts
|
|
60
|
-
var
|
|
62
|
+
var ye = class {
|
|
61
63
|
ethereumProviderAdapter;
|
|
62
64
|
solanaProviderAdapter;
|
|
63
65
|
tronProviderAdapter;
|
|
@@ -75,9 +77,9 @@ var he = class {
|
|
|
75
77
|
generateProofRemotely;
|
|
76
78
|
disableMerkleTreeUpdates;
|
|
77
79
|
constructor(e) {
|
|
78
|
-
this.userKeys = new
|
|
79
|
-
this.merkleTreeHinkalByChain[e] =
|
|
80
|
-
}), this.generateProofRemotely = e?.generateProofRemotely ?? !0, this.utxoUtils = new
|
|
80
|
+
this.userKeys = new v(void 0), e?.tronChainOverride && f(e.tronChainOverride), r.forEach((e) => {
|
|
81
|
+
this.merkleTreeHinkalByChain[e] = B.create(re, 0n), this.nullifiersByChain[e] = /* @__PURE__ */ new Set(), this.encryptedOutputsByChain[e] = [];
|
|
82
|
+
}), this.generateProofRemotely = e?.generateProofRemotely ?? !0, this.utxoUtils = new ie(), this.cacheDevice = T(e), this.disableMerkleTreeUpdates = e?.disableMerkleTreeUpdates ?? !1;
|
|
81
83
|
}
|
|
82
84
|
enforceRateLimit(e, n, r = 1e3) {
|
|
83
85
|
let i = Date.now(), a = t(n), o = this.lastCallState.get(e);
|
|
@@ -96,38 +98,50 @@ var he = class {
|
|
|
96
98
|
}
|
|
97
99
|
async initProviderAdapter(e, t) {
|
|
98
100
|
let n = a.ethMainnet;
|
|
99
|
-
t instanceof
|
|
101
|
+
t instanceof E ? n = o : t instanceof X && (n = s), await this.updateProviderAdapter(n, t), t.initConnector(e);
|
|
100
102
|
let r = await t.connectAndPatchProvider(e);
|
|
101
103
|
await t.init(r), await this.setListeners();
|
|
102
104
|
}
|
|
103
|
-
getSigningMessage(e =
|
|
105
|
+
getSigningMessage(e = g.PROTOCOL) {
|
|
104
106
|
switch (e) {
|
|
105
|
-
case
|
|
106
|
-
case
|
|
107
|
+
case g.PRIVATE_TRANSFER: return this.privateTransferSigningMessage;
|
|
108
|
+
case g.PROTOCOL:
|
|
107
109
|
default: return this.signingMessage;
|
|
108
110
|
}
|
|
109
111
|
}
|
|
110
|
-
async signHinkalMessage(e =
|
|
112
|
+
async signHinkalMessage(e = g.PROTOCOL) {
|
|
111
113
|
let t = this.getSigningMessage(e);
|
|
112
114
|
return this.getProviderAdapter().signMessage(t);
|
|
113
115
|
}
|
|
114
|
-
async
|
|
115
|
-
|
|
116
|
+
async signSolanaLedgerMessage() {
|
|
117
|
+
let e = new ve({
|
|
118
|
+
blockhash: p,
|
|
119
|
+
lastValidBlockHeight: m,
|
|
120
|
+
feePayer: this.getSolanaPublicKey()
|
|
121
|
+
}), t = await this.getProviderAdapter().signTransactionWithoutBroadcast?.(e);
|
|
122
|
+
if (!t) throw Error("Failed to sign transaction without broadcast");
|
|
123
|
+
return {
|
|
124
|
+
signature: t.signature,
|
|
125
|
+
txMessageForSolanaLedger: t.transactionMessageB64
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
async initUserKeys(e = g.PROTOCOL) {
|
|
129
|
+
this.userKeys = new v(await this.signHinkalMessage(e));
|
|
116
130
|
}
|
|
117
131
|
initUserKeysWithSignature(e) {
|
|
118
|
-
this.userKeys = new
|
|
132
|
+
this.userKeys = new v(e);
|
|
119
133
|
}
|
|
120
134
|
async initUserKeysFromSeedPhrases(e) {
|
|
121
|
-
let t =
|
|
122
|
-
this.userKeys = new
|
|
135
|
+
let t = O(e);
|
|
136
|
+
this.userKeys = new v(t);
|
|
123
137
|
}
|
|
124
|
-
async storeAndGetInitialSignature(e, t, n) {
|
|
138
|
+
async storeAndGetInitialSignature(e, t = !1, n) {
|
|
125
139
|
let r = await this.getEthereumAddress();
|
|
126
140
|
if (!r) throw Error("Connected address not found");
|
|
127
|
-
return await
|
|
141
|
+
return await D(r, e, t, n);
|
|
128
142
|
}
|
|
129
143
|
async resetMerkle(e) {
|
|
130
|
-
this.disableMerkleTreeUpdates || (e?.every((e) => this.isSelectedNetworkSupported(e)) ?? !0) && await
|
|
144
|
+
this.disableMerkleTreeUpdates || (e?.every((e) => this.isSelectedNetworkSupported(e)) ?? !0) && await V(this, e);
|
|
131
145
|
}
|
|
132
146
|
getTronWeb() {
|
|
133
147
|
let e = this.tronProviderAdapter;
|
|
@@ -147,7 +161,7 @@ var he = class {
|
|
|
147
161
|
return this.getProviderAdapter(e).getContract(e, t, n);
|
|
148
162
|
}
|
|
149
163
|
getContractWithFetcherByChainId(e, t, n = void 0) {
|
|
150
|
-
return
|
|
164
|
+
return C(e, t, n);
|
|
151
165
|
}
|
|
152
166
|
async signMessage(e) {
|
|
153
167
|
return await this.getProviderAdapter().signMessage(e);
|
|
@@ -156,7 +170,7 @@ var he = class {
|
|
|
156
170
|
return await this.getProviderAdapter().signTypedData(e, t, n);
|
|
157
171
|
}
|
|
158
172
|
async signWithSubAccount(e, t, n, r) {
|
|
159
|
-
return
|
|
173
|
+
return W(e, t, n, r);
|
|
160
174
|
}
|
|
161
175
|
getContractWithSigner(e, t, n = "") {
|
|
162
176
|
return this.getProviderAdapter(e).getContractWithSigner(e, t, n);
|
|
@@ -217,20 +231,20 @@ var he = class {
|
|
|
217
231
|
}
|
|
218
232
|
async onAccountChanged() {
|
|
219
233
|
await this.ethereumProviderAdapter?.onAccountChanged(), await this.solanaProviderAdapter?.onAccountChanged(), await this.tronProviderAdapter?.onAccountChanged();
|
|
220
|
-
let e =
|
|
234
|
+
let e = h.AccountChanged;
|
|
221
235
|
typeof document < "u" ? document?.dispatchEvent(new Event(e)) : process?.emit("message", e, void 0);
|
|
222
236
|
}
|
|
223
237
|
async onChainChanged(e) {
|
|
224
|
-
e ? await this.getProviderAdapter(e).onChainChanged(e) : (await this.disconnectFromConnector(),
|
|
238
|
+
e ? await this.getProviderAdapter(e).onChainChanged(e) : (await this.disconnectFromConnector(), w());
|
|
225
239
|
}
|
|
226
240
|
async monitorConnectedAddress(e) {
|
|
227
|
-
await
|
|
241
|
+
await _.monitor(await this.getEthereumAddressByChain(e));
|
|
228
242
|
}
|
|
229
243
|
async getBalances(e, t, n, r, i = !1, a, o = !1) {
|
|
230
|
-
return
|
|
244
|
+
return x(this, e, t, n, r, i, this.generateProofRemotely, a, o);
|
|
231
245
|
}
|
|
232
246
|
async getTotalBalance(e, t, r, i = !1, a, o = !1) {
|
|
233
|
-
let s = r ?? await this.getEthereumAddressByChain(e), c = t ?? this.userKeys, l = await this.getBalances(e, c.getShieldedPrivateKey(), c.getShieldedPublicKey(), s, i, a, o), u = n ? await
|
|
247
|
+
let s = r ?? await this.getEthereumAddressByChain(e), c = t ?? this.userKeys, l = await this.getBalances(e, c.getShieldedPrivateKey(), c.getShieldedPublicKey(), s, i, a, o), u = n ? await b.getPrivateTokens(e, s) : ne(e), d = [];
|
|
234
248
|
return u.forEach((e) => {
|
|
235
249
|
let t = e.erc20TokenAddress.toLowerCase(), n = l.get(t), r = {
|
|
236
250
|
token: e,
|
|
@@ -251,14 +265,14 @@ var he = class {
|
|
|
251
265
|
return Promise.resolve(!0);
|
|
252
266
|
}
|
|
253
267
|
checkExternalTokenLimitsUSD(e, t, n) {
|
|
254
|
-
return
|
|
268
|
+
return N(e, t, n);
|
|
255
269
|
}
|
|
256
270
|
async getHinkalTreeRootHash(t) {
|
|
257
271
|
if (l(t)) {
|
|
258
272
|
let { hinkalIdl: e, hinkalAddress: n, originalDeployer: r } = d[t].contractData;
|
|
259
273
|
if (!e || !n || !r) throw Error(`Missing Solana configuration for chain ${t}`);
|
|
260
|
-
let i = new $(r), a =
|
|
261
|
-
return
|
|
274
|
+
let i = new $(r), a = S(new $(n), i);
|
|
275
|
+
return k(this.getSolanaProgram(e), a);
|
|
262
276
|
}
|
|
263
277
|
return this.getContractWithFetcherByChainId(t, e.HinkalContract).getRootHash();
|
|
264
278
|
}
|
|
@@ -281,7 +295,7 @@ var he = class {
|
|
|
281
295
|
return this.getProviderAdapter(e).getAddress();
|
|
282
296
|
}
|
|
283
297
|
async getRandomRelay(e, t = !1) {
|
|
284
|
-
return (await
|
|
298
|
+
return (await _.getIdleRelay(e, t)).relay;
|
|
285
299
|
}
|
|
286
300
|
getGasPrice(e) {
|
|
287
301
|
let t = this.getProviderAdapter(e);
|
|
@@ -289,7 +303,7 @@ var he = class {
|
|
|
289
303
|
return t.getGasPrice(e);
|
|
290
304
|
}
|
|
291
305
|
getAPI() {
|
|
292
|
-
return
|
|
306
|
+
return _;
|
|
293
307
|
}
|
|
294
308
|
snapshotsClearInterval() {
|
|
295
309
|
this.getSupportedChains().forEach((e) => {
|
|
@@ -297,43 +311,51 @@ var he = class {
|
|
|
297
311
|
});
|
|
298
312
|
}
|
|
299
313
|
getRecipientInfo() {
|
|
300
|
-
return
|
|
314
|
+
return U(this);
|
|
301
315
|
}
|
|
302
316
|
async deposit(e, t, n = !0, r = !1) {
|
|
303
|
-
return
|
|
317
|
+
return j(this, e, t, n, r);
|
|
304
318
|
}
|
|
305
319
|
async depositSolana(e, t, n = !1) {
|
|
306
|
-
return
|
|
320
|
+
return F(this, e, t, n);
|
|
307
321
|
}
|
|
308
322
|
async depositForOther(e, t, n, r = !0, i = !1, a) {
|
|
309
323
|
return this.enforceRateLimit(this.depositForOther.name, [
|
|
310
324
|
e,
|
|
311
325
|
t,
|
|
312
326
|
n
|
|
313
|
-
]),
|
|
327
|
+
]), M(this, e, t, n, r, i, a);
|
|
314
328
|
}
|
|
315
329
|
async depositSolanaForOther(e, t, n, r = !1, i) {
|
|
316
330
|
return this.enforceRateLimit(this.depositSolanaForOther.name, [
|
|
317
331
|
e,
|
|
318
332
|
t,
|
|
319
333
|
n
|
|
320
|
-
]),
|
|
334
|
+
]), I(this, e, t, n, r, i);
|
|
321
335
|
}
|
|
322
336
|
async depositAndWithdraw(e, t, n, r, i, a, o, s, c = !0) {
|
|
323
|
-
return l(
|
|
337
|
+
return l(y([e])) ? se(this, e, t, n, r, i, a, o, s) : P(this, e, t, n, r, i, a, o, s, c);
|
|
324
338
|
}
|
|
325
339
|
async claimUtxo(e, t, n, r) {
|
|
326
|
-
return l(
|
|
340
|
+
return l(y([e])) ? ge(this, e, t, n, r) : Q(this, e, t, n, r);
|
|
327
341
|
}
|
|
328
342
|
async depositAndBridge(e, t, n, r, i, a, o, s = !0) {
|
|
329
|
-
return
|
|
343
|
+
return pe(this, e, t, n, r, i, a, o, s);
|
|
344
|
+
}
|
|
345
|
+
async nearDepositAndBridge(e, t, n, r, i, a, o, s, c) {
|
|
346
|
+
return this.enforceRateLimit(this.nearDepositAndBridge.name, [
|
|
347
|
+
e,
|
|
348
|
+
t,
|
|
349
|
+
n,
|
|
350
|
+
r
|
|
351
|
+
]), me(this, e, t, n, r, i, a, o, s, c);
|
|
330
352
|
}
|
|
331
353
|
async prooflessDeposit(e, t, n, r, i = !1) {
|
|
332
|
-
return l(
|
|
354
|
+
return l(y(e)) ? he(this, e, t, n, r, i) : K(this, e, t, n, r, i);
|
|
333
355
|
}
|
|
334
356
|
async prooflessDepositWithPublicFee(e, t, n, r, i) {
|
|
335
|
-
let a =
|
|
336
|
-
return l(a) ?
|
|
357
|
+
let a = y([e]);
|
|
358
|
+
return l(a) ? L(this, e, t, n, r, i) : q(this, a, e, t, n, r, i);
|
|
337
359
|
}
|
|
338
360
|
getSolanaProgram(e) {
|
|
339
361
|
if (!this.solanaProviderAdapter) throw Error("No provider adapter initialized");
|
|
@@ -350,24 +372,24 @@ var he = class {
|
|
|
350
372
|
e,
|
|
351
373
|
t,
|
|
352
374
|
n
|
|
353
|
-
]), l(
|
|
375
|
+
]), l(y(e)) ? le(this, e, t, n, r, i, a) : ae(this, e, t, n, r, i, a);
|
|
354
376
|
}
|
|
355
377
|
async withdraw(e, t, n, r, i, a, o) {
|
|
356
|
-
return l(
|
|
378
|
+
return l(y(e)) ? ce(this, e, t, n, i, a, o) : z(this, e, t, n, r, i, a, o);
|
|
357
379
|
}
|
|
358
380
|
async withdrawStuckUtxos(e, t) {
|
|
359
|
-
return
|
|
381
|
+
return _e(this, e, t);
|
|
360
382
|
}
|
|
361
383
|
async swap(e, t, n, r, i, a, o) {
|
|
362
|
-
return l(
|
|
384
|
+
return l(y(e)) ? this.swapSolana(e, t, r, i, a, o) : R(this, e, t, n, r, i, a, o);
|
|
363
385
|
}
|
|
364
386
|
async swapSolana(e, t, n, r, i, a) {
|
|
365
387
|
let o = JSON.parse(n), s = BigInt(o.swapperAccountSalt), { instructionLists: c, addressLookupTableAccount: l } = o.data;
|
|
366
|
-
return
|
|
388
|
+
return ue(this, e, t, s, c, l, r, i, a);
|
|
367
389
|
}
|
|
368
390
|
async actionReceive(e, t, n, r, i, a) {
|
|
369
391
|
if (!i) throw Error("subAccount is required");
|
|
370
|
-
return l(
|
|
392
|
+
return l(y(e)) ? Z(this, e[0], t[0], i, void 0, a) : G(this, e, t, n, r, i, a);
|
|
371
393
|
}
|
|
372
394
|
async actionPrivateWallet(e, t, n, r, i, a, o, s, c, l, u = !1, d, f, p) {
|
|
373
395
|
return this.enforceRateLimit(this.actionPrivateWallet.name, [
|
|
@@ -381,23 +403,23 @@ var he = class {
|
|
|
381
403
|
s,
|
|
382
404
|
c,
|
|
383
405
|
p
|
|
384
|
-
]),
|
|
406
|
+
]), H(this, e, t, n, r, i, a, o, s, c, l, u, d, f, p);
|
|
385
407
|
}
|
|
386
408
|
async proxySwap(e, t, n, r, i, a, o, s, c = !1, u, d) {
|
|
387
|
-
return l(
|
|
409
|
+
return l(y(e)) ? fe(this, e, t, r, a, n, o, s, d) : J(this, e, t, n, r, i, a, o, s, c, u, d);
|
|
388
410
|
}
|
|
389
411
|
async proxyToPrivate(e, t, n, r, i, a, o) {
|
|
390
|
-
return l(
|
|
412
|
+
return l(y(e)) ? (this.enforceRateLimit(this.proxyToPrivate.name, [
|
|
391
413
|
e[0],
|
|
392
414
|
t[0],
|
|
393
415
|
n,
|
|
394
416
|
r
|
|
395
|
-
]),
|
|
417
|
+
]), Z(this, e[0], t[0], n, r, o)) : oe(this, e, t, r, i, a, n, o);
|
|
396
418
|
}
|
|
397
419
|
async proxySend(e, t, n, r, i, a, o) {
|
|
398
|
-
let s =
|
|
399
|
-
if (l(s)) return
|
|
400
|
-
let c =
|
|
420
|
+
let s = y(e);
|
|
421
|
+
if (l(s)) return de(this, e[0], t[0], n, r, o);
|
|
422
|
+
let c = A(this, s, e.map((e) => e.erc20TokenAddress), t, r), u = e.map((e, n) => ({
|
|
401
423
|
token: e,
|
|
402
424
|
amount: -1n * t[n]
|
|
403
425
|
}));
|
|
@@ -408,7 +430,7 @@ var he = class {
|
|
|
408
430
|
e,
|
|
409
431
|
t,
|
|
410
432
|
n
|
|
411
|
-
]),
|
|
433
|
+
]), Y(this, e, t, n);
|
|
412
434
|
}
|
|
413
435
|
areMerkleTreeUpdatesDisabled() {
|
|
414
436
|
return this.disableMerkleTreeUpdates;
|
|
@@ -418,4 +440,4 @@ var he = class {
|
|
|
418
440
|
}
|
|
419
441
|
};
|
|
420
442
|
//#endregion
|
|
421
|
-
export {
|
|
443
|
+
export { ye as Hinkal };
|
|
@@ -18,6 +18,7 @@ import { AdminTransactionType } from '../../types/admin.types';
|
|
|
18
18
|
import { Idl, Program } from '@coral-xyz/anchor';
|
|
19
19
|
import { PublicKey } from '@solana/web3.js';
|
|
20
20
|
import { BridgeRecipient } from '../../types/bridging-tx.types';
|
|
21
|
+
import { NearBridgeParams, NearBridgeResult } from '../../types/near-intents.types';
|
|
21
22
|
import { Utxo } from '../utxo/Utxo';
|
|
22
23
|
export interface IHinkal<ConnectorType = unknown> {
|
|
23
24
|
userKeys: UserKeys;
|
|
@@ -53,6 +54,7 @@ export interface IHinkal<ConnectorType = unknown> {
|
|
|
53
54
|
claimUtxo(erc20Token: ERC20Token, utxo: Utxo, feeStructureOverride?: FeeStructure, claimableSignature?: string): Promise<string>;
|
|
54
55
|
depositAndWithdraw(erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, preEstimateGas?: boolean): Promise<string>;
|
|
55
56
|
depositAndBridge(erc20Token: ERC20Token, recipientBridges: BridgeRecipient[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, preEstimateGas?: boolean): Promise<string>;
|
|
57
|
+
nearDepositAndBridge(erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], params: NearBridgeParams, txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, action?: AdminTransactionType, dashboardAccountId?: string): Promise<NearBridgeResult>;
|
|
56
58
|
prooflessDeposit(erc20Tokens: ERC20Token[], amountChanges: bigint[], stealthAddressStructures?: StealthAddressStructure[], action?: AdminTransactionType, returnTxData?: boolean): Promise<string | ethers.TransactionRequest | TronWebTypes.Transaction<TronWebTypes.TriggerSmartContract>>;
|
|
57
59
|
prooflessDepositWithPublicFee(erc20Token: ERC20Token, amounts: bigint[], stealthAddressStructures: StealthAddressStructure[], feeAmount: bigint, action?: AdminTransactionType): Promise<string>;
|
|
58
60
|
getSolanaProgram(idl: Idl): Program;
|
|
@@ -67,10 +69,14 @@ export interface IHinkal<ConnectorType = unknown> {
|
|
|
67
69
|
getTronWeb(): TronWeb;
|
|
68
70
|
getSigningMessage(mode?: LoginMessageMode): string;
|
|
69
71
|
signHinkalMessage(mode?: LoginMessageMode): Promise<string>;
|
|
72
|
+
signSolanaLedgerMessage(): Promise<{
|
|
73
|
+
signature: string;
|
|
74
|
+
txMessageForSolanaLedger: string;
|
|
75
|
+
}>;
|
|
70
76
|
initUserKeys(mode?: LoginMessageMode): Promise<void>;
|
|
71
77
|
initUserKeysWithSignature(signature: string): void;
|
|
72
78
|
initUserKeysFromSeedPhrases(seedPhrases: string[]): Promise<void>;
|
|
73
|
-
storeAndGetInitialSignature(authSignature: string, isSolanaLedger
|
|
79
|
+
storeAndGetInitialSignature(authSignature: string, isSolanaLedger?: boolean, txMessageForSolanaLedger?: string): Promise<string>;
|
|
74
80
|
initProviderAdapter(connector: ConnectorType, providerAdapter: IProviderAdapter<ConnectorType>): Promise<void>;
|
|
75
81
|
disconnectFromConnector(): Promise<void>;
|
|
76
82
|
resetProviderAdapters(): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../API/callNearIntentsAPI.cjs`),n=require(`../../constants/bridging.constants.cjs`),r=require(`../../functions/utils/time.utils.cjs`),i=require(`../../functions/utils/token-check.utils.cjs`),a=require(`../../functions/utils/nearIntents.utils.cjs`),o=require(`./hinkalDepositAndWithdraw.cjs`),s=require(`./hinkalSolanaDepositAndWithdraw.cjs`);var c=async(c,l,u,d,f,p,m,h,g,_)=>{if(u.length!==d.length)throw Error(`recipientAmounts and recipientAddresses length mismatch`);if(u.length===0)throw Error(`No recipients to bridge`);let v=i.validateAndGetChainId([l]),y=r.secondsToMs(p),b=new Date(y+n.NEAR_BRIDGE_QUOTE_DEADLINE_BUFFER_MS).toISOString(),x=await Promise.all(d.map(async(e,n)=>{let r=u[n],{quote:i}=await t.getNearIntentsQuote({dry:!1,swapType:`EXACT_INPUT`,slippageTolerance:f.slippageBps??100,originAsset:f.originAsset,depositType:`ORIGIN_CHAIN`,destinationAsset:f.destinationAsset,amount:r.toString(),recipient:e,recipientType:`DESTINATION_CHAIN`,refundTo:c.userKeys.getNearIntentsAccountId(),refundType:`INTENTS`,deadline:b});if(!i.depositAddress)throw Error(`NEAR Intents quote returned no deposit address for recipient ${e}`);if(i.deadline&&new Date(i.deadline).getTime()<y)throw Error(`Bridge quote expires before the scheduled execution time. Choose a sooner time.`);return{destinationRecipient:e,amount:r,depositAddress:i.depositAddress,quote:i}})),S=m??await a.buildNearBridgeFeeStructure(v,l,x[0].depositAddress),C=x.map(e=>e.amount),w=x.map(e=>e.depositAddress),T;return T=e.isSolanaLike(v)?await s.hinkalSolanaDepositAndWithdraw(c,l,C,w,p,S,h,g,_,x.map(e=>e.destinationRecipient)):await o.hinkalDepositAndWithdraw(c,l,C,w,p,S,h,g,_),{depositTxHash:T,legs:x}};exports.hinkalNearDepositAndBridge=c;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AdminTransactionType } from '../../types';
|
|
2
|
+
import { FeeStructure } from '../../types/hinkal.types';
|
|
3
|
+
import { NearBridgeParams, NearBridgeResult } from '../../types/near-intents.types';
|
|
4
|
+
import { ERC20Token } from '../../types/token.types';
|
|
5
|
+
import { IHinkal } from './IHinkal';
|
|
6
|
+
export declare const hinkalNearDepositAndBridge: (hinkal: IHinkal, token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], params: NearBridgeParams, txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, action?: AdminTransactionType, dashboardAccountId?: string) => Promise<NearBridgeResult>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { isSolanaLike as e } from "../../constants/chains.constants.mjs";
|
|
2
|
+
import { getNearIntentsQuote as t } from "../../API/callNearIntentsAPI.mjs";
|
|
3
|
+
import { NEAR_BRIDGE_QUOTE_DEADLINE_BUFFER_MS as n } from "../../constants/bridging.constants.mjs";
|
|
4
|
+
import { secondsToMs as r } from "../../functions/utils/time.utils.mjs";
|
|
5
|
+
import { validateAndGetChainId as i } from "../../functions/utils/token-check.utils.mjs";
|
|
6
|
+
import { buildNearBridgeFeeStructure as a } from "../../functions/utils/nearIntents.utils.mjs";
|
|
7
|
+
import { hinkalDepositAndWithdraw as o } from "./hinkalDepositAndWithdraw.mjs";
|
|
8
|
+
import { hinkalSolanaDepositAndWithdraw as s } from "./hinkalSolanaDepositAndWithdraw.mjs";
|
|
9
|
+
//#region libs/shared/common/src/data-structures/Hinkal/hinkalNearDepositAndBridge.ts
|
|
10
|
+
var c = async (c, l, u, d, f, p, m, h, g, _) => {
|
|
11
|
+
if (u.length !== d.length) throw Error("recipientAmounts and recipientAddresses length mismatch");
|
|
12
|
+
if (u.length === 0) throw Error("No recipients to bridge");
|
|
13
|
+
let v = i([l]), y = r(p), b = new Date(y + n).toISOString(), x = await Promise.all(d.map(async (e, n) => {
|
|
14
|
+
let r = u[n], { quote: i } = await t({
|
|
15
|
+
dry: !1,
|
|
16
|
+
swapType: "EXACT_INPUT",
|
|
17
|
+
slippageTolerance: f.slippageBps ?? 100,
|
|
18
|
+
originAsset: f.originAsset,
|
|
19
|
+
depositType: "ORIGIN_CHAIN",
|
|
20
|
+
destinationAsset: f.destinationAsset,
|
|
21
|
+
amount: r.toString(),
|
|
22
|
+
recipient: e,
|
|
23
|
+
recipientType: "DESTINATION_CHAIN",
|
|
24
|
+
refundTo: c.userKeys.getNearIntentsAccountId(),
|
|
25
|
+
refundType: "INTENTS",
|
|
26
|
+
deadline: b
|
|
27
|
+
});
|
|
28
|
+
if (!i.depositAddress) throw Error(`NEAR Intents quote returned no deposit address for recipient ${e}`);
|
|
29
|
+
if (i.deadline && new Date(i.deadline).getTime() < y) throw Error("Bridge quote expires before the scheduled execution time. Choose a sooner time.");
|
|
30
|
+
return {
|
|
31
|
+
destinationRecipient: e,
|
|
32
|
+
amount: r,
|
|
33
|
+
depositAddress: i.depositAddress,
|
|
34
|
+
quote: i
|
|
35
|
+
};
|
|
36
|
+
})), S = m ?? await a(v, l, x[0].depositAddress), C = x.map((e) => e.amount), w = x.map((e) => e.depositAddress), T;
|
|
37
|
+
return T = e(v) ? await s(c, l, C, w, p, S, h, g, _, x.map((e) => e.destinationRecipient)) : await o(c, l, C, w, p, S, h, g, _), {
|
|
38
|
+
depositTxHash: T,
|
|
39
|
+
legs: x
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
//#endregion
|
|
43
|
+
export { c as hinkalNearDepositAndBridge };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../types/external-action.types.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../constants/protocol.constants.cjs`),r=require(`../../types/scheduled-transactions.types.cjs`);require(`../../types/index.cjs`);const i=require(`../../functions/utils/addresses.cjs`),a=require(`../../error-handling/error-codes.constants.cjs`),o=require(`../../functions/web3/etherFunctions.cjs`),s=require(`../crypto-keys/keys.cjs`),c=require(`../../functions/utils/time.utils.cjs`),l=require(`../utxo/Utxo.cjs`),u=require(`../../functions/utils/solanaMint.utils.cjs`),d=require(`../../functions/utils/token-check.utils.cjs`),f=require(`../../functions/snarkjs/common.snarkjs.cjs`),p=require(`../../functions/pre-transaction/solana.cjs`),m=require(`../../functions/pre-transaction/constructAdminData.cjs`),h=require(`../../functions/pre-transaction/sendV0Transaction.cjs`),g=require(`../../functions/pre-transaction/getFeeStructure.cjs`),_=require(`../../functions/pre-transaction/waitForDepositedUtxosInMerkleTree.cjs`);require(`../../functions/pre-transaction/index.cjs`);const v=require(`../../functions/utils/getUtxosFromReceiptSolana.cjs`),y=require(`../../functions/utils/fees.utils.cjs`);require(`../../functions/web3/index.cjs`);const b=require(`../../functions/snarkjs/constructSolanaZkProof.cjs`),x=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`),S=require(`../../API/deposit-and-withdraw-status-calls.cjs`);require(`../../functions/index.cjs`);let C=require(`ethers`),w=require(`@solana/web3.js`),T=require(`@coral-xyz/anchor`);var E=(e,r,i,a)=>{let{hinkalIdl:c,hinkalAddress:l,originalDeployer:d}=t.networkRegistry[r].contractData;if(!c)throw Error(`No IDL configured for Solana program on this network`);if(!d)throw Error(`missing original deployer`);let m=e.userKeys.getShieldedPrivateKey(),h=e.getSolanaProgram(c),g=e.getSolanaPublicKey(),_=new w.PublicKey(d),v=new w.PublicKey(l),{mintPublicKey:y}=u.formatMintAddress(i.erc20TokenAddress),b=y.toString(),x=p.getStorageAccountPublicKey(v,_),S=p.getStorageVaultPublicKey(v,_),C=p.getMerkleAccountPublicKey(v,_),T=a.map(()=>p.buildAnchorStealthAddressStructure(f.calcStealthAddressStructure(s.UserKeys.findCorrectRandomization(o.randomBigInt(31),m),m,e.userKeys.getSpendingKeyPair().pubSpendingBJJPoint))),E=b===n.solanaNativeAddress;return{program:h,publicKey:g,originalDeployer:_,mint:E?null:y,atasValue:E?null:void 0,storageAccount:x,storageVault:S,merkleAccount:C,amounts:a,anchorStealthStructures:T}},D=e=>e.program.methods.multiPaymentDeposit(e.amounts.map(e=>new T.BN(e.toString())),e.anchorStealthStructures,!0).accounts({mint:e.mint,signer:e.publicKey,signerAta:e.atasValue,originalDeployer:e.originalDeployer,storageAccount:e.storageAccount,storageVault:e.storageVault,merkleAccount:e.merkleAccount,storageVaultAta:e.atasValue}),O=async(e,t,n,i,a,o,s)=>{let c=i.map(e=>e+y.calculateTotalFee(e,o)),l=E(e,t,n,c),d=(await S.updateDepositAndWithdrawStatus({chainId:t,hashedEthereumAddress:s,phase:r.DepositAndWithdrawPhase.BEFORE_DEPOSIT})).id??void 0,f=await D(l).rpc(),p=await l.program.provider.connection.getLatestBlockhash();await l.program.provider.connection.confirmTransaction({blockhash:p.blockhash,lastValidBlockHeight:p.lastValidBlockHeight,signature:f},`finalized`);let m=await h.fetchSolanaTransaction(l.program.provider.connection,f,`finalized`);if(!m)throw Error(`Transaction missing`);await S.safeUpdateDepositAndWithdrawStatus({id:d,chainId:t,hashedEthereumAddress:s,phase:r.DepositAndWithdrawPhase.AFTER_DEPOSIT,depositTxHash:f});let{compressedAddress:g}=u.formatMintAddress(n.erc20TokenAddress),_=v.getOnChainUtxosFromReceiptSolana(m,l.program,e.userKeys,g),b=[],x=[..._];return a.forEach((e,t)=>{let n=c[t],r=x.find(e=>e.amount===n);if(!r)throw Error(`Could not find newly created UTXO with amount ${n} for recipient ${e}.`);b.push({recipientAddress:e,utxo:r}),x.splice(x.indexOf(r),1)}),{userDepositedUtxos:b,depositTxHash:f,statusId:d}},k=async(e,i,d,p,h,g,_,v,w,T,E,D)=>{let
|
|
1
|
+
require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../types/external-action.types.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../constants/protocol.constants.cjs`),r=require(`../../types/scheduled-transactions.types.cjs`);require(`../../types/index.cjs`);const i=require(`../../functions/utils/addresses.cjs`),a=require(`../../error-handling/error-codes.constants.cjs`),o=require(`../../functions/web3/etherFunctions.cjs`),s=require(`../crypto-keys/keys.cjs`),c=require(`../../functions/utils/time.utils.cjs`),l=require(`../utxo/Utxo.cjs`),u=require(`../../functions/utils/solanaMint.utils.cjs`),d=require(`../../functions/utils/token-check.utils.cjs`),f=require(`../../functions/snarkjs/common.snarkjs.cjs`),p=require(`../../functions/pre-transaction/solana.cjs`),m=require(`../../functions/pre-transaction/constructAdminData.cjs`),h=require(`../../functions/pre-transaction/sendV0Transaction.cjs`),g=require(`../../functions/pre-transaction/getFeeStructure.cjs`),_=require(`../../functions/pre-transaction/waitForDepositedUtxosInMerkleTree.cjs`);require(`../../functions/pre-transaction/index.cjs`);const v=require(`../../functions/utils/getUtxosFromReceiptSolana.cjs`),y=require(`../../functions/utils/fees.utils.cjs`);require(`../../functions/web3/index.cjs`);const b=require(`../../functions/snarkjs/constructSolanaZkProof.cjs`),x=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`),S=require(`../../API/deposit-and-withdraw-status-calls.cjs`);require(`../../functions/index.cjs`);let C=require(`ethers`),w=require(`@solana/web3.js`),T=require(`@coral-xyz/anchor`);var E=(e,r,i,a)=>{let{hinkalIdl:c,hinkalAddress:l,originalDeployer:d}=t.networkRegistry[r].contractData;if(!c)throw Error(`No IDL configured for Solana program on this network`);if(!d)throw Error(`missing original deployer`);let m=e.userKeys.getShieldedPrivateKey(),h=e.getSolanaProgram(c),g=e.getSolanaPublicKey(),_=new w.PublicKey(d),v=new w.PublicKey(l),{mintPublicKey:y}=u.formatMintAddress(i.erc20TokenAddress),b=y.toString(),x=p.getStorageAccountPublicKey(v,_),S=p.getStorageVaultPublicKey(v,_),C=p.getMerkleAccountPublicKey(v,_),T=a.map(()=>p.buildAnchorStealthAddressStructure(f.calcStealthAddressStructure(s.UserKeys.findCorrectRandomization(o.randomBigInt(31),m),m,e.userKeys.getSpendingKeyPair().pubSpendingBJJPoint))),E=b===n.solanaNativeAddress;return{program:h,publicKey:g,originalDeployer:_,mint:E?null:y,atasValue:E?null:void 0,storageAccount:x,storageVault:S,merkleAccount:C,amounts:a,anchorStealthStructures:T}},D=e=>e.program.methods.multiPaymentDeposit(e.amounts.map(e=>new T.BN(e.toString())),e.anchorStealthStructures,!0).accounts({mint:e.mint,signer:e.publicKey,signerAta:e.atasValue,originalDeployer:e.originalDeployer,storageAccount:e.storageAccount,storageVault:e.storageVault,merkleAccount:e.merkleAccount,storageVaultAta:e.atasValue}),O=async(e,t,n,i,a,o,s)=>{let c=i.map(e=>e+y.calculateTotalFee(e,o)),l=E(e,t,n,c),d=(await S.updateDepositAndWithdrawStatus({chainId:t,hashedEthereumAddress:s,phase:r.DepositAndWithdrawPhase.BEFORE_DEPOSIT})).id??void 0,f=await D(l).rpc(),p=await l.program.provider.connection.getLatestBlockhash();await l.program.provider.connection.confirmTransaction({blockhash:p.blockhash,lastValidBlockHeight:p.lastValidBlockHeight,signature:f},`finalized`);let m=await h.fetchSolanaTransaction(l.program.provider.connection,f,`finalized`);if(!m)throw Error(`Transaction missing`);await S.safeUpdateDepositAndWithdrawStatus({id:d,chainId:t,hashedEthereumAddress:s,phase:r.DepositAndWithdrawPhase.AFTER_DEPOSIT,depositTxHash:f});let{compressedAddress:g}=u.formatMintAddress(n.erc20TokenAddress),_=v.getOnChainUtxosFromReceiptSolana(m,l.program,e.userKeys,g),b=[],x=[..._];return a.forEach((e,t)=>{let n=c[t],r=x.find(e=>e.amount===n);if(!r)throw Error(`Could not find newly created UTXO with amount ${n} for recipient ${e}.`);b.push({recipientAddress:e,utxo:r}),x.splice(x.indexOf(r),1)}),{userDepositedUtxos:b,depositTxHash:f,statusId:d}},k=async(e,i,d,p,h,g,_,v,w,T,E,D,O)=>{let k=d.erc20TokenAddress;if(p.length===0)throw Error(`userDepositedUtxos must not be empty`);let{originalDeployer:A}=t.networkRegistry[i].contractData;if(!A)throw Error(`missing data`);let j=await e.getRandomRelay(i,!0);if(!j)throw Error(a.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let M=c.getCurrentTimeInSeconds().toString(),N=e.generateProofRemotely?5:1,P=[];for(let t=0;t<p.length;t+=N){let r=p.slice(t,t+N),a=await Promise.all(r.map(async({recipientAddress:t,utxo:r},a)=>{let{compressedAddress:c}=u.formatMintAddress(n.solanaNativeAddress),p=new l.Utxo({amount:0n,mintAddress:k,erc20TokenAddress:c,nullifyingKey:e.userKeys.getShieldedPrivateKey(),timeStamp:M,...r.isNewStyle?{spendingPublicKey:e.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,isNewStyle:!0}:{isNewStyle:!1}}),g=[r,p],v=[p],x=s.UserKeys.findCorrectRandomization(o.randomBigInt(31),e.userKeys.getShieldedPrivateKey()),S={tokenNumber:1,nullifierAmount:g.length,outputAmount:v.length},w=f.calcEncryptedOutputs([v])[0][0],T=Array.from(C.ethers.getBytes(w)),D=await y.calculateModifiedFeeStructure(i,d,_[a],h),A=m.constructAdminData(E,i,[k],[_[a]],await e.getEthereumAddress()),{proofAArr:N,proofBArr:P,proofCArr:F,publicInputsArr:I,commitmentValidationData:L}=await b.constructSolanaZkProof(e.generateProofRemotely,e.merkleTreeHinkalByChain[i],e.userKeys,[k],[g],[v],x,D.flatFee,D.variableRate,t,j,S,[T],i),R={recipient:t,mint:k===`11111111111111111111111111111111`?void 0:k};return{relayAddress:j,functionName:`transact`,chainId:i,recipientAmount:_[a].toString(),args:{proofAArr:N,proofBArr:P,proofCArr:F,publicInputsArr:I,encryptedOutputs:[T],relayerFee:D.flatFee.toString(),dimensions:S},accounts:R,adminData:A,commitmentValidationData:L,displayRecipient:O?.[a]}}));P.push(...a)}await S.safeUpdateDepositAndWithdrawStatus({id:v,chainId:i,hashedEthereumAddress:g,phase:r.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});let F=await x.solanaTransactCallRelayerBatch(i,P,g,w,T,D);return await S.safeUpdateDepositAndWithdrawStatus({id:v,chainId:i,hashedEthereumAddress:g,phase:r.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:F}),F},A=async(t,n,r,a,o,s,c,l,u,f)=>{let p=d.validateAndGetChainId([n]),m=n.erc20TokenAddress,h=i.hashEthereumAddress(await t.getEthereumAddressByChain(p)),v=u?i.hashString(u):void 0,y=s??await g.getFeeStructure(p,m,[m],e.ExternalActionId.Transact,[],5n),{userDepositedUtxos:b,depositTxHash:x,statusId:S}=await O(t,p,n,r,a,y,h);return await _.waitForDepositedUtxosInMerkleTree(t,p,b),await k(t,p,n,b,y,h,r,S,o,c,l,v,f),x};exports.buildMultiPaymentDepositBuilder=D,exports.buildMultiPaymentDepositSetup=E,exports.hinkalSolanaDepositAndWithdraw=A,exports.hinkalSolanaWithdrawBatch=k;
|
|
@@ -19,6 +19,6 @@ export type MultiPaymentDepositSetup = ReturnType<typeof buildMultiPaymentDeposi
|
|
|
19
19
|
export declare const buildMultiPaymentDepositBuilder: (setup: MultiPaymentDepositSetup) => import('@coral-xyz/anchor/dist/cjs/program/namespace/methods').MethodsBuilder<import('@coral-xyz/anchor').Idl, import('@coral-xyz/anchor/dist/cjs/idl').IdlInstruction & {
|
|
20
20
|
name: string;
|
|
21
21
|
}, import('@coral-xyz/anchor/dist/cjs/idl').IdlInstructionAccountItem>;
|
|
22
|
-
export declare const hinkalSolanaWithdrawBatch: (hinkal: IHinkal, chainId: number, token: ERC20Token, userDepositedUtxos: RecipientUtxo[], feeStructure: FeeStructure, hashedEthereumAddress: string, recipientAmounts: bigint[], statusId: string | undefined, txCompletionTime?: number, ref?: string, action?: AdminTransactionType, hashedDashboardAccountId?: string) => Promise<string>;
|
|
22
|
+
export declare const hinkalSolanaWithdrawBatch: (hinkal: IHinkal, chainId: number, token: ERC20Token, userDepositedUtxos: RecipientUtxo[], feeStructure: FeeStructure, hashedEthereumAddress: string, recipientAmounts: bigint[], statusId: string | undefined, txCompletionTime?: number, ref?: string, action?: AdminTransactionType, hashedDashboardAccountId?: string, displayRecipients?: string[]) => Promise<string>;
|
|
23
23
|
export declare const hinkalSolanaDepositAndWithdraw: (hinkal: IHinkal, token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, // Should be passed fee for only one withdraw transaction, multiplication happening in this function
|
|
24
|
-
ref?: string, action?: AdminTransactionType, dashboardAccountId?: string) => Promise<string>;
|
|
24
|
+
ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, displayRecipients?: string[]) => Promise<string>;
|