@hinkal/common 0.2.36 → 0.2.37

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.
Files changed (70) hide show
  1. package/API/enclaveUtxoCalls.cjs +1 -1
  2. package/API/enclaveUtxoCalls.mjs +6 -7
  3. package/constants/events.constants.cjs +1 -1
  4. package/constants/events.constants.mjs +3 -1
  5. package/constants/server.constants.cjs +1 -1
  6. package/constants/server.constants.d.ts +1 -1
  7. package/constants/server.constants.mjs +1 -1
  8. package/data-structures/ApprovalDBs/EventsPublicApprovalsDB.cjs +1 -1
  9. package/data-structures/ApprovalDBs/EventsPublicApprovalsDB.mjs +13 -13
  10. package/data-structures/Hinkal/Hinkal.cjs +1 -1
  11. package/data-structures/Hinkal/Hinkal.d.ts +5 -0
  12. package/data-structures/Hinkal/Hinkal.mjs +114 -104
  13. package/data-structures/Hinkal/IHinkal.d.ts +5 -0
  14. package/data-structures/Hinkal/hinkalDepositAndBridge.cjs +1 -1
  15. package/data-structures/Hinkal/hinkalDepositAndBridge.d.ts +2 -2
  16. package/data-structures/Hinkal/hinkalDepositAndBridge.mjs +8 -5
  17. package/data-structures/Hinkal/hinkalDepositAndWithdraw.cjs +1 -1
  18. package/data-structures/Hinkal/hinkalDepositAndWithdraw.d.ts +2 -2
  19. package/data-structures/Hinkal/hinkalDepositAndWithdraw.mjs +4 -1
  20. package/data-structures/Hinkal/hinkalNearDepositAndBridge.cjs +1 -1
  21. package/data-structures/Hinkal/hinkalNearDepositAndBridge.mjs +1 -1
  22. package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.cjs +1 -1
  23. package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.d.ts +2 -2
  24. package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.mjs +4 -1
  25. package/data-structures/Hinkal/resetMerkleTrees.cjs +1 -1
  26. package/data-structures/Hinkal/resetMerkleTrees.mjs +12 -12
  27. package/data-structures/TokenDBs/AlchemyPublicTokensDB.cjs +1 -1
  28. package/data-structures/TokenDBs/AlchemyPublicTokensDB.mjs +3 -2
  29. package/data-structures/TokenDBs/EventsPublicTokensDB.cjs +1 -1
  30. package/data-structures/TokenDBs/EventsPublicTokensDB.d.ts +0 -1
  31. package/data-structures/TokenDBs/EventsPublicTokensDB.mjs +27 -36
  32. package/data-structures/TokenDBs/PublicTokensDB.cjs +1 -1
  33. package/data-structures/TokenDBs/PublicTokensDB.mjs +22 -20
  34. package/data-structures/TokenDBs/TronPublicTokensDB.cjs +1 -0
  35. package/data-structures/TokenDBs/TronPublicTokensDB.d.ts +9 -0
  36. package/data-structures/TokenDBs/TronPublicTokensDB.mjs +47 -0
  37. package/data-structures/TokenDBs/index.cjs +1 -1
  38. package/data-structures/TokenDBs/index.d.ts +1 -0
  39. package/data-structures/TokenDBs/index.mjs +1 -0
  40. package/data-structures/index.cjs +1 -1
  41. package/data-structures/index.mjs +1 -0
  42. package/functions/index.cjs +1 -1
  43. package/functions/index.mjs +1 -0
  44. package/functions/pre-transaction/sendV0Transaction.cjs +2 -2
  45. package/functions/pre-transaction/sendV0Transaction.mjs +69 -57
  46. package/functions/snarkjs/common.snarkjs.cjs +1 -1
  47. package/functions/snarkjs/common.snarkjs.mjs +2 -2
  48. package/functions/snarkjs/constant.cjs +1 -1
  49. package/functions/snarkjs/constant.mjs +1 -1
  50. package/functions/utils/enclaveHandshakeService.cjs +1 -0
  51. package/functions/utils/enclaveHandshakeService.d.ts +10 -0
  52. package/functions/utils/enclaveHandshakeService.mjs +22 -0
  53. package/functions/utils/encryptInputForEnclave.cjs +1 -1
  54. package/functions/utils/encryptInputForEnclave.mjs +23 -25
  55. package/functions/utils/index.cjs +1 -1
  56. package/functions/utils/index.d.ts +1 -0
  57. package/functions/utils/index.mjs +1 -0
  58. package/functions/utils/tron.utils.cjs +1 -1
  59. package/functions/utils/tron.utils.d.ts +1 -0
  60. package/functions/utils/tron.utils.mjs +1 -1
  61. package/index.cjs +1 -1
  62. package/index.mjs +183 -181
  63. package/package.json +1 -1
  64. package/types/cache.types.cjs +1 -1
  65. package/types/cache.types.d.ts +1 -0
  66. package/types/cache.types.mjs +1 -1
  67. package/types/scheduled-transactions.types.d.ts +4 -0
  68. package/webworker/package.json +1 -1
  69. package/webworker/viteWorkerURL.constant.cjs +3 -3
  70. package/webworker/viteWorkerURL.constant.mjs +3 -3
@@ -3,63 +3,64 @@ import { CustomJSONStringify as t } from "../../functions/utils/serialize.utils.
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
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";
6
+ import { EventType as ee, LoginMessageMode as h } from "../../types/hinkal.types.mjs";
7
+ import { getScheduledTransactionById as g } from "../../API/scheduled-transactions-calls.mjs";
7
8
  import { API as _ } from "../../API/API.mjs";
8
- import { supportedPassportLinks as ee } from "../../constants/kyc.constants.mjs";
9
- import { transactionErrorCodes as te } from "../../error-handling/error-codes.constants.mjs";
10
- import { getErc20TokensForChain as ne } from "../../functions/utils/erc20tokenFunctions.mjs";
9
+ import { supportedPassportLinks as te } from "../../constants/kyc.constants.mjs";
10
+ import { transactionErrorCodes as ne } from "../../error-handling/error-codes.constants.mjs";
11
+ import { getErc20TokensForChain as re } from "../../functions/utils/erc20tokenFunctions.mjs";
11
12
  import "../../API/index.mjs";
12
- import { poseidonFunction as re } from "../../crypto/poseidon.mjs";
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";
13
+ import { poseidonFunction as v } from "../../crypto/poseidon.mjs";
14
+ import { UserKeys as y } from "../crypto-keys/keys.mjs";
15
+ import { validateAndGetChainId as b } from "../../functions/utils/token-check.utils.mjs";
16
+ import { privateTokensDB as x } from "../TokenDBs/PrivateTokensDB.mjs";
17
+ import { getShieldedBalance as S } from "../../functions/web3/events/getShieldedBalance.mjs";
18
+ import { getMerkleAccountPublicKey as C } from "../../functions/pre-transaction/solana.mjs";
19
+ import { getContractWithFetcherByChainId as w } from "../../functions/web3/getContractMetadata.mjs";
20
+ import { reloadPage as T } from "../../functions/utils/reloadPage.mjs";
21
+ import { createCacheDevice as E } from "../../functions/utils/cacheDevice.utils.mjs";
22
+ import { SolanaProviderAdapter as D } from "../../providers/SolanaProviderAdapter.mjs";
23
+ import { storeAndGetSignatureFromEnclave as O } from "../../functions/utils/enclave-signature-storage.mjs";
24
+ import { generateHashFromSeedPhrases as k } from "../../functions/utils/mnemonics.mjs";
25
+ import { fetchSolanaMerkleTreeRootHash as A } from "../../functions/web3/fetchSolanaMerkleTreeRootHash.mjs";
26
+ import { createTransaferEmporiumOpsBatch as j } from "../../functions/private-wallet/emporium.helpers.mjs";
27
+ import { hinkalDeposit as M, hinkalDepositForOther as N } from "./hinkalDeposit.mjs";
28
+ import { checkTokenLimitsUSD as P } from "../../functions/kyc/checkTokenLimitsUSD.mjs";
29
+ import { hinkalDepositAndWithdraw as F } from "./hinkalDepositAndWithdraw.mjs";
30
+ import { hinkalSolanaDeposit as I, hinkalSolanaDepositForOther as L, hinkalSolanaProoflessDepositWithPublicFee as R } from "./hinkalSolanaDeposit.mjs";
31
+ import { hinkalSwap as z } from "./hinkalSwap.mjs";
32
+ import { hinkalWithdraw as B } from "./hinkalWithdraw.mjs";
33
+ import { MerkleTree as V } from "../merkle-tree/MerkleTree.mjs";
33
34
  import "../merkle-tree/index.mjs";
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";
35
+ import { resetMerkleTrees as ie } from "./resetMerkleTrees.mjs";
36
+ import { MultiThreadedUtxoUtils as H } from "../MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.mjs";
37
+ import { hinkalPrivateWallet as U } from "./hinkalPrivateWallet.mjs";
38
+ import { getRecipientInfo as W } from "./hinkalGetRecipientInfo.mjs";
39
+ import { hinkalSignSubAccount as G } from "./hinkalSignSubAccount.mjs";
40
+ import { hinkalActionReceive as K } from "./hinkalActionReceive.mjs";
40
41
  import "../TokenDBs/index.mjs";
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";
42
+ import { hinkalProoflessDeposit as q, hinkalProoflessDepositWithPublicFee as J } from "./hinkalProoflessDeposit.mjs";
43
+ import { hinkalProxySwap as Y } from "./hinkalProxySwap.mjs";
44
+ import { hinkalMultiSendPrivateRecipients as ae } from "./hinkalMultiSend.mjs";
45
+ import { hinkalTransfer as oe } from "./hinkalTransfer.mjs";
46
+ import { hinkalProxyToPrivate as se } from "./hinkalProxyToPrivate.mjs";
46
47
  import { TronProviderAdapter as X } from "../../providers/TronProviderAdapter.mjs";
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";
48
+ import { hinkalSolanaDepositAndWithdraw as ce } from "./hinkalSolanaDepositAndWithdraw.mjs";
49
+ import { hinkalSolanaWithdraw as le } from "./hinkalSolanaWithdraw.mjs";
50
+ import { hinkalSolanaTransfer as ue } from "./hinkalSolanaTransfer.mjs";
51
+ import { hinkalSolanaSwap as de } from "./hinkalSolanaSwap.mjs";
52
+ import { hinkalSolanaProxySend as fe } from "./hinkalSolanaProxySend.mjs";
53
+ import { hinkalSolanaProxySwap as pe } from "./hinkalSolanaProxySwap.mjs";
53
54
  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";
55
+ import { hinkalDepositAndBridge as me } from "./hinkalDepositAndBridge.mjs";
56
+ import { hinkalNearDepositAndBridge as Q } from "./hinkalNearDepositAndBridge.mjs";
57
+ import { hinkalClaimUtxo as he } from "./hinkalClaimUtxo.mjs";
58
+ import { hinkalSolanaProoflessDeposit as ge } from "./hinkalSolanaProoflessDeposit.mjs";
59
+ import { hinkalSolanaClaimUtxo as _e } from "./hinkalSolanaClaimUtxo.mjs";
60
+ import { hinkalWithdrawStuckUtxos as ve } from "./hinkalWithdrawStuckUtxos.mjs";
61
+ import { PublicKey as $, Transaction as ye } from "@solana/web3.js";
61
62
  //#region libs/shared/common/src/data-structures/Hinkal/Hinkal.ts
62
- var ye = class {
63
+ var be = class {
63
64
  ethereumProviderAdapter;
64
65
  solanaProviderAdapter;
65
66
  tronProviderAdapter;
@@ -77,9 +78,9 @@ var ye = class {
77
78
  generateProofRemotely;
78
79
  disableMerkleTreeUpdates;
79
80
  constructor(e) {
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
+ this.userKeys = new y(void 0), e?.tronChainOverride && f(e.tronChainOverride), r.forEach((e) => {
82
+ this.merkleTreeHinkalByChain[e] = V.create(v, 0n), this.nullifiersByChain[e] = /* @__PURE__ */ new Set(), this.encryptedOutputsByChain[e] = [];
83
+ }), this.generateProofRemotely = e?.generateProofRemotely ?? !0, this.utxoUtils = new H(), this.cacheDevice = E(e), this.disableMerkleTreeUpdates = e?.disableMerkleTreeUpdates ?? !1;
83
84
  }
84
85
  enforceRateLimit(e, n, r = 1e3) {
85
86
  let i = Date.now(), a = t(n), o = this.lastCallState.get(e);
@@ -98,23 +99,23 @@ var ye = class {
98
99
  }
99
100
  async initProviderAdapter(e, t) {
100
101
  let n = a.ethMainnet;
101
- t instanceof E ? n = o : t instanceof X && (n = s), await this.updateProviderAdapter(n, t), t.initConnector(e);
102
+ t instanceof D ? n = o : t instanceof X && (n = s), await this.updateProviderAdapter(n, t), t.initConnector(e);
102
103
  let r = await t.connectAndPatchProvider(e);
103
104
  await t.init(r), await this.setListeners();
104
105
  }
105
- getSigningMessage(e = g.PROTOCOL) {
106
+ getSigningMessage(e = h.PROTOCOL) {
106
107
  switch (e) {
107
- case g.PRIVATE_TRANSFER: return this.privateTransferSigningMessage;
108
- case g.PROTOCOL:
108
+ case h.PRIVATE_TRANSFER: return this.privateTransferSigningMessage;
109
+ case h.PROTOCOL:
109
110
  default: return this.signingMessage;
110
111
  }
111
112
  }
112
- async signHinkalMessage(e = g.PROTOCOL) {
113
+ async signHinkalMessage(e = h.PROTOCOL) {
113
114
  let t = this.getSigningMessage(e);
114
115
  return this.getProviderAdapter().signMessage(t);
115
116
  }
116
117
  async signSolanaLedgerMessage() {
117
- let e = new ve({
118
+ let e = new ye({
118
119
  blockhash: p,
119
120
  lastValidBlockHeight: m,
120
121
  feePayer: this.getSolanaPublicKey()
@@ -125,23 +126,23 @@ var ye = class {
125
126
  txMessageForSolanaLedger: t.transactionMessageB64
126
127
  };
127
128
  }
128
- async initUserKeys(e = g.PROTOCOL) {
129
- this.userKeys = new v(await this.signHinkalMessage(e));
129
+ async initUserKeys(e = h.PROTOCOL) {
130
+ this.userKeys = new y(await this.signHinkalMessage(e));
130
131
  }
131
132
  initUserKeysWithSignature(e) {
132
- this.userKeys = new v(e);
133
+ this.userKeys = new y(e);
133
134
  }
134
135
  async initUserKeysFromSeedPhrases(e) {
135
- let t = O(e);
136
- this.userKeys = new v(t);
136
+ let t = k(e);
137
+ this.userKeys = new y(t);
137
138
  }
138
139
  async storeAndGetInitialSignature(e, t = !1, n) {
139
140
  let r = await this.getEthereumAddress();
140
141
  if (!r) throw Error("Connected address not found");
141
- return await D(r, e, t, n);
142
+ return await O(r, e, t, n);
142
143
  }
143
144
  async resetMerkle(e) {
144
- this.disableMerkleTreeUpdates || (e?.every((e) => this.isSelectedNetworkSupported(e)) ?? !0) && await V(this, e);
145
+ this.disableMerkleTreeUpdates || (e?.every((e) => this.isSelectedNetworkSupported(e)) ?? !0) && await ie(this, e);
145
146
  }
146
147
  getTronWeb() {
147
148
  let e = this.tronProviderAdapter;
@@ -161,7 +162,7 @@ var ye = class {
161
162
  return this.getProviderAdapter(e).getContract(e, t, n);
162
163
  }
163
164
  getContractWithFetcherByChainId(e, t, n = void 0) {
164
- return C(e, t, n);
165
+ return w(e, t, n);
165
166
  }
166
167
  async signMessage(e) {
167
168
  return await this.getProviderAdapter().signMessage(e);
@@ -170,7 +171,7 @@ var ye = class {
170
171
  return await this.getProviderAdapter().signTypedData(e, t, n);
171
172
  }
172
173
  async signWithSubAccount(e, t, n, r) {
173
- return W(e, t, n, r);
174
+ return G(e, t, n, r);
174
175
  }
175
176
  getContractWithSigner(e, t, n = "") {
176
177
  return this.getProviderAdapter(e).getContractWithSigner(e, t, n);
@@ -186,7 +187,7 @@ var ye = class {
186
187
  if (!(e.chainId === n || r)) try {
187
188
  await t.switchNetwork(e);
188
189
  } catch {
189
- throw Error(te.FAILED_TO_SWITCH_NETWORKS);
190
+ throw Error(ne.FAILED_TO_SWITCH_NETWORKS);
190
191
  }
191
192
  }
192
193
  isPermitterAvailable(e) {
@@ -231,20 +232,20 @@ var ye = class {
231
232
  }
232
233
  async onAccountChanged() {
233
234
  await this.ethereumProviderAdapter?.onAccountChanged(), await this.solanaProviderAdapter?.onAccountChanged(), await this.tronProviderAdapter?.onAccountChanged();
234
- let e = h.AccountChanged;
235
+ let e = ee.AccountChanged;
235
236
  typeof document < "u" ? document?.dispatchEvent(new Event(e)) : process?.emit("message", e, void 0);
236
237
  }
237
238
  async onChainChanged(e) {
238
- e ? await this.getProviderAdapter(e).onChainChanged(e) : (await this.disconnectFromConnector(), w());
239
+ e ? await this.getProviderAdapter(e).onChainChanged(e) : (await this.disconnectFromConnector(), T());
239
240
  }
240
241
  async monitorConnectedAddress(e) {
241
242
  await _.monitor(await this.getEthereumAddressByChain(e));
242
243
  }
243
244
  async getBalances(e, t, n, r, i = !1, a, o = !1) {
244
- return x(this, e, t, n, r, i, this.generateProofRemotely, a, o);
245
+ return S(this, e, t, n, r, i, this.generateProofRemotely, a, o);
245
246
  }
246
247
  async getTotalBalance(e, t, r, i = !1, a, o = !1) {
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 = [];
248
+ 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 x.getPrivateTokens(e, s) : re(e), d = [];
248
249
  return u.forEach((e) => {
249
250
  let t = e.erc20TokenAddress.toLowerCase(), n = l.get(t), r = {
250
251
  token: e,
@@ -259,20 +260,20 @@ var ye = class {
259
260
  return (await this.getTotalBalance(e, t, n, !1, !1, !0)).filter((e) => e.balance > 0n);
260
261
  }
261
262
  getSupportedPassportLinks() {
262
- return ee;
263
+ return te;
263
264
  }
264
265
  checkAccessToken(e, t) {
265
266
  return Promise.resolve(!0);
266
267
  }
267
268
  checkExternalTokenLimitsUSD(e, t, n) {
268
- return N(e, t, n);
269
+ return P(e, t, n);
269
270
  }
270
271
  async getHinkalTreeRootHash(t) {
271
272
  if (l(t)) {
272
273
  let { hinkalIdl: e, hinkalAddress: n, originalDeployer: r } = d[t].contractData;
273
274
  if (!e || !n || !r) throw Error(`Missing Solana configuration for chain ${t}`);
274
- let i = new $(r), a = S(new $(n), i);
275
- return k(this.getSolanaProgram(e), a);
275
+ let i = new $(r), a = C(new $(n), i);
276
+ return A(this.getSolanaProgram(e), a);
276
277
  }
277
278
  return this.getContractWithFetcherByChainId(t, e.HinkalContract).getRootHash();
278
279
  }
@@ -311,36 +312,45 @@ var ye = class {
311
312
  });
312
313
  }
313
314
  getRecipientInfo() {
314
- return U(this);
315
+ return W(this);
315
316
  }
316
317
  async deposit(e, t, n = !0, r = !1) {
317
- return j(this, e, t, n, r);
318
+ return M(this, e, t, n, r);
318
319
  }
319
320
  async depositSolana(e, t, n = !1) {
320
- return F(this, e, t, n);
321
+ return I(this, e, t, n);
321
322
  }
322
323
  async depositForOther(e, t, n, r = !0, i = !1, a) {
323
324
  return this.enforceRateLimit(this.depositForOther.name, [
324
325
  e,
325
326
  t,
326
327
  n
327
- ]), M(this, e, t, n, r, i, a);
328
+ ]), N(this, e, t, n, r, i, a);
328
329
  }
329
330
  async depositSolanaForOther(e, t, n, r = !1, i) {
330
331
  return this.enforceRateLimit(this.depositSolanaForOther.name, [
331
332
  e,
332
333
  t,
333
334
  n
334
- ]), I(this, e, t, n, r, i);
335
+ ]), L(this, e, t, n, r, i);
335
336
  }
336
337
  async depositAndWithdraw(e, t, n, r, i, a, o, s, c = !0) {
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);
338
+ return (await this.depositAndWithdrawExtended(e, t, n, r, i, a, o, s, c)).depositTxHash;
339
+ }
340
+ async depositAndWithdrawExtended(e, t, n, r, i, a, o, s, c = !0) {
341
+ return l(b([e])) ? ce(this, e, t, n, r, i, a, o, s) : F(this, e, t, n, r, i, a, o, s, c);
338
342
  }
339
343
  async claimUtxo(e, t, n, r) {
340
- return l(y([e])) ? ge(this, e, t, n, r) : Q(this, e, t, n, r);
344
+ return l(b([e])) ? _e(this, e, t, n, r) : he(this, e, t, n, r);
341
345
  }
342
346
  async depositAndBridge(e, t, n, r, i, a, o, s = !0) {
343
- return pe(this, e, t, n, r, i, a, o, s);
347
+ return (await this.depositAndBridgeExtended(e, t, n, r, i, a, o, s)).depositTxHash;
348
+ }
349
+ async depositAndBridgeExtended(e, t, n, r, i, a, o, s = !0) {
350
+ return me(this, e, t, n, r, i, a, o, s);
351
+ }
352
+ async checkSendTransactionStatus(e) {
353
+ return g(e);
344
354
  }
345
355
  async nearDepositAndBridge(e, t, n, r, i, a, o, s, c) {
346
356
  return this.enforceRateLimit(this.nearDepositAndBridge.name, [
@@ -348,14 +358,14 @@ var ye = class {
348
358
  t,
349
359
  n,
350
360
  r
351
- ]), me(this, e, t, n, r, i, a, o, s, c);
361
+ ]), Q(this, e, t, n, r, i, a, o, s, c);
352
362
  }
353
363
  async prooflessDeposit(e, t, n, r, i = !1) {
354
- return l(y(e)) ? he(this, e, t, n, r, i) : K(this, e, t, n, r, i);
364
+ return l(b(e)) ? ge(this, e, t, n, r, i) : q(this, e, t, n, r, i);
355
365
  }
356
366
  async prooflessDepositWithPublicFee(e, t, n, r, i) {
357
- let a = y([e]);
358
- return l(a) ? L(this, e, t, n, r, i) : q(this, a, e, t, n, r, i);
367
+ let a = b([e]);
368
+ return l(a) ? R(this, e, t, n, r, i) : J(this, a, e, t, n, r, i);
359
369
  }
360
370
  getSolanaProgram(e) {
361
371
  if (!this.solanaProviderAdapter) throw Error("No provider adapter initialized");
@@ -372,24 +382,24 @@ var ye = class {
372
382
  e,
373
383
  t,
374
384
  n
375
- ]), l(y(e)) ? le(this, e, t, n, r, i, a) : ae(this, e, t, n, r, i, a);
385
+ ]), l(b(e)) ? ue(this, e, t, n, r, i, a) : oe(this, e, t, n, r, i, a);
376
386
  }
377
387
  async withdraw(e, t, n, r, i, a, o) {
378
- return l(y(e)) ? ce(this, e, t, n, i, a, o) : z(this, e, t, n, r, i, a, o);
388
+ return l(b(e)) ? le(this, e, t, n, i, a, o) : B(this, e, t, n, r, i, a, o);
379
389
  }
380
390
  async withdrawStuckUtxos(e, t) {
381
- return _e(this, e, t);
391
+ return ve(this, e, t);
382
392
  }
383
393
  async swap(e, t, n, r, i, a, o) {
384
- return l(y(e)) ? this.swapSolana(e, t, r, i, a, o) : R(this, e, t, n, r, i, a, o);
394
+ return l(b(e)) ? this.swapSolana(e, t, r, i, a, o) : z(this, e, t, n, r, i, a, o);
385
395
  }
386
396
  async swapSolana(e, t, n, r, i, a) {
387
397
  let o = JSON.parse(n), s = BigInt(o.swapperAccountSalt), { instructionLists: c, addressLookupTableAccount: l } = o.data;
388
- return ue(this, e, t, s, c, l, r, i, a);
398
+ return de(this, e, t, s, c, l, r, i, a);
389
399
  }
390
400
  async actionReceive(e, t, n, r, i, a) {
391
401
  if (!i) throw Error("subAccount is required");
392
- return l(y(e)) ? Z(this, e[0], t[0], i, void 0, a) : G(this, e, t, n, r, i, a);
402
+ return l(b(e)) ? Z(this, e[0], t[0], i, void 0, a) : K(this, e, t, n, r, i, a);
393
403
  }
394
404
  async actionPrivateWallet(e, t, n, r, i, a, o, s, c, l, u = !1, d, f, p) {
395
405
  return this.enforceRateLimit(this.actionPrivateWallet.name, [
@@ -403,23 +413,23 @@ var ye = class {
403
413
  s,
404
414
  c,
405
415
  p
406
- ]), H(this, e, t, n, r, i, a, o, s, c, l, u, d, f, p);
416
+ ]), U(this, e, t, n, r, i, a, o, s, c, l, u, d, f, p);
407
417
  }
408
418
  async proxySwap(e, t, n, r, i, a, o, s, c = !1, u, d) {
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);
419
+ return l(b(e)) ? pe(this, e, t, r, a, n, o, s, d) : Y(this, e, t, n, r, i, a, o, s, c, u, d);
410
420
  }
411
421
  async proxyToPrivate(e, t, n, r, i, a, o) {
412
- return l(y(e)) ? (this.enforceRateLimit(this.proxyToPrivate.name, [
422
+ return l(b(e)) ? (this.enforceRateLimit(this.proxyToPrivate.name, [
413
423
  e[0],
414
424
  t[0],
415
425
  n,
416
426
  r
417
- ]), Z(this, e[0], t[0], n, r, o)) : oe(this, e, t, r, i, a, n, o);
427
+ ]), Z(this, e[0], t[0], n, r, o)) : se(this, e, t, r, i, a, n, o);
418
428
  }
419
429
  async proxySend(e, t, n, r, i, a, o) {
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) => ({
430
+ let s = b(e);
431
+ if (l(s)) return fe(this, e[0], t[0], n, r, o);
432
+ let c = j(this, s, e.map((e) => e.erc20TokenAddress), t, r), u = e.map((e, n) => ({
423
433
  token: e,
424
434
  amount: -1n * t[n]
425
435
  }));
@@ -430,7 +440,7 @@ var ye = class {
430
440
  e,
431
441
  t,
432
442
  n
433
- ]), Y(this, e, t, n);
443
+ ]), ae(this, e, t, n);
434
444
  }
435
445
  areMerkleTreeUpdatesDisabled() {
436
446
  return this.disableMerkleTreeUpdates;
@@ -440,4 +450,4 @@ var ye = class {
440
450
  }
441
451
  };
442
452
  //#endregion
443
- export { ye as Hinkal };
453
+ export { be as Hinkal };
@@ -19,6 +19,8 @@ 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
21
  import { NearBridgeParams, NearBridgeResult } from '../../types/near-intents.types';
22
+ import { DepositAndSendExtendedResult } from '../../types/scheduled-transactions.types';
23
+ import { ScheduledTransactionByIdResponse } from '../../API/scheduled-transactions-calls';
22
24
  import { Utxo } from '../utxo/Utxo';
23
25
  export interface IHinkal<ConnectorType = unknown> {
24
26
  userKeys: UserKeys;
@@ -53,7 +55,10 @@ export interface IHinkal<ConnectorType = unknown> {
53
55
  depositForOther(erc20Tokens: ERC20Token[], amountChanges: bigint[], recepinetInfo: string, preEstimateGas?: boolean, returnTxData?: boolean, action?: AdminTransactionType): Promise<ethers.TransactionResponse | ethers.TransactionRequest | string | TronWebTypes.Transaction<TronWebTypes.TriggerSmartContract>>;
54
56
  claimUtxo(erc20Token: ERC20Token, utxo: Utxo, feeStructureOverride?: FeeStructure, claimableSignature?: string): Promise<string>;
55
57
  depositAndWithdraw(erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, preEstimateGas?: boolean): Promise<string>;
58
+ depositAndWithdrawExtended(erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, preEstimateGas?: boolean): Promise<DepositAndSendExtendedResult>;
56
59
  depositAndBridge(erc20Token: ERC20Token, recipientBridges: BridgeRecipient[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, preEstimateGas?: boolean): Promise<string>;
60
+ depositAndBridgeExtended(erc20Token: ERC20Token, recipientBridges: BridgeRecipient[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, preEstimateGas?: boolean): Promise<DepositAndSendExtendedResult>;
61
+ checkSendTransactionStatus(scheduleId: string): Promise<ScheduledTransactionByIdResponse>;
57
62
  nearDepositAndBridge(erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], params: NearBridgeParams, txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, action?: AdminTransactionType, dashboardAccountId?: string): Promise<NearBridgeResult>;
58
63
  prooflessDeposit(erc20Tokens: ERC20Token[], amountChanges: bigint[], stealthAddressStructures?: StealthAddressStructure[], action?: AdminTransactionType, returnTxData?: boolean): Promise<string | ethers.TransactionRequest | TronWebTypes.Transaction<TronWebTypes.TriggerSmartContract>>;
59
64
  prooflessDepositWithPublicFee(erc20Token: ERC20Token, amounts: bigint[], stealthAddressStructures: StealthAddressStructure[], feeAmount: bigint, action?: AdminTransactionType): Promise<string>;
@@ -1 +1 @@
1
- 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/caseInsensitive.utils.cjs`),a=require(`../../functions/utils/addresses.cjs`),o=require(`../../API/API.cjs`),s=require(`../../constants/addresses.constants.cjs`),c=require(`../../error-handling/error-codes.constants.cjs`),l=require(`../../functions/utils/erc20tokenFunctions.cjs`),u=require(`../../functions/utils/time.utils.cjs`),d=require(`../utxo/Utxo.cjs`),f=require(`../../functions/utils/token-check.utils.cjs`),p=require(`../../functions/pre-transaction/constructAdminData.cjs`),m=require(`../../functions/pre-transaction/getFeeStructure.cjs`),h=require(`../../functions/pre-transaction/waitForDepositedUtxosInMerkleTree.cjs`),g=require(`../../functions/utils/convertEmporiumOpToCallInfo.cjs`),_=require(`../../functions/utils/fees.utils.cjs`);require(`../../functions/utils/index.cjs`);const v=require(`../../functions/private-wallet/emporium.helpers.cjs`),y=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),b=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`),x=require(`../../API/deposit-and-withdraw-status-calls.cjs`),S=require(`./hinkalDepositOnChainUtxos.cjs`);require(`../../functions/index.cjs`);var C=async(a,l,f,m,h,g,S,C,w,T,E)=>{if(m.length===0)throw Error(`No recipients to bridge`);let D=f.erc20TokenAddress,{contractData:O}=t.networkRegistry[l],{emporiumAddress:k}=O;if(!k)throw Error(`No Emporium Address`);let A=s.SWAP_ROUTER_ADDRESSES[e.ExternalActionId.Lifi][l];if(!A)throw Error(`LIFI not configured for chain ${l}`);let j=await a.getRandomRelay(l);if(!j)throw Error(c.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let M=await a.getEthereumAddressByChain(l),N=u.getCurrentTimeInSeconds().toString(),P=a.generateProofRemotely?5:1,F=[];for(let t=0;t<m.length;t+=P){let r=m.slice(t,t+P),s=await Promise.all(r.map(async({utxo:t,nativeUtxo:r,bridgeAmount:s,quote:c,temporarySubAccount:u,recipientAddress:m})=>{await o.API.addTemporaryWalletNonce(l,g,u.index);let b=c.nativeFee>0n&&!i.caseInsensitiveEqual(D,n.zeroAddress),x=[D],S=[-t.amount],C=[!1],w=new d.Utxo({amount:0n,erc20TokenAddress:D,nullifyingKey:a.userKeys.getShieldedPrivateKey(),timeStamp:N,...t.isNewStyle?{spendingPublicKey:a.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,isNewStyle:!0}:{isNewStyle:!1}}),E=[[t,w]],O=[[w]];if(b&&r){let e=new d.Utxo({amount:0n,erc20TokenAddress:n.zeroAddress,nullifyingKey:a.userKeys.getShieldedPrivateKey(),timeStamp:N,...r.isNewStyle?{spendingPublicKey:a.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,isNewStyle:!0}:{isNewStyle:!1}});x.push(n.zeroAddress),S.push(-r.amount),C.push(!1),E.push([r,e]),O.push([e])}let P=v.createLifiBridgeOps(a,l,u.ethAddress,A,D,t.amount,s,c),F=await _.calculateModifiedFeeStructure(l,f,s,h),I=p.constructAdminData(T,l,x,[-t.amount],M),[{zkCallData:L,circomData:R,dimData:z,commitmentValidationData:B},V]=await Promise.all([y.constructZkProof(a.merkleTreeHinkalByChain[l],E,O,a.userKeys,e.ExternalActionId.Emporium,k,P,a.generateProofRemotely,F,j??n.zeroAddress,l,C,void 0,void 0,u.privateKey),v.getAuthorizationDataIfNeeded(l,u.privateKey)]);return{zkCallData:L,dimData:z,circomData:R,commitmentValidationData:B,authorizationData:V,recipientAddress:m,adminData:I}}));F.push(...s)}await x.safeUpdateDepositAndWithdrawStatus({id:S,chainId:l,hashedEthereumAddress:g,phase:r.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});let I=await b.transactCallRelayerBatch(l,F,g,C,w,E);return await x.safeUpdateDepositAndWithdrawStatus({id:S,chainId:l,hashedEthereumAddress:g,phase:r.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:I}),I},w=async(t,r,o,c,u,d,p,_,y=!0)=>{let b=r.erc20TokenAddress,x=f.validateAndGetChainId([r]),w=_?a.hashString(_):void 0,T=a.hashEthereumAddress(await t.getEthereumAddressByChain(x)),E=s.SWAP_ROUTER_ADDRESSES[e.ExternalActionId.Lifi][x];if(!E)throw Error(`LIFI router not configured`);let D;if(u)D=u;else{let r=o[0],i=v.createLifiBridgeOps(t,x,r.temporarySubAccount.ethAddress,E,b,r.bridgeAmount,r.bridgeAmount,r.quote).map(e=>g.convertEmporiumOpToCallInfo(e,r.temporarySubAccount.ethAddress,x));D=await m.getFeeStructure(x,b,[b],e.ExternalActionId.Emporium,i,n.PAY_SEND_VARIABLE_RATE)}let O={feeToken:D.feeToken,flatFee:0n,variableRate:0n},k=o.reduce((e,t)=>e+t.quote.nativeFee,0n)>0n&&!i.caseInsensitiveEqual(b,n.zeroAddress),A=o.map(e=>e.bridgeAmount),j=o.map(e=>e.recipientAddress),{userDepositedUtxos:M,statusId:N,depositTxHash:P}=await S.hinkalDepositOnChainUtxos(t,x,r,A,j,D,T,y),F=[];if(k){let e=l.getERC20Token(n.zeroAddress,x);if(!e)throw Error(`No native token`);let{userDepositedUtxos:r}=await S.hinkalDepositOnChainUtxos(t,x,e,o.map(e=>e.quote.nativeFee),j,O,T,y);F=r}return await h.waitForDepositedUtxosInMerkleTree(t,x,[...M,...F]),await C(t,x,r,o.map((e,t)=>({...e,utxo:M[t].utxo,nativeUtxo:k?F[t]?.utxo:void 0})),D,T,N,c,d,p,w),P};exports.hinkalDepositAndBridge=w;
1
+ 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/caseInsensitive.utils.cjs`),a=require(`../../functions/utils/addresses.cjs`),o=require(`../../API/API.cjs`),s=require(`../../constants/addresses.constants.cjs`),c=require(`../../error-handling/error-codes.constants.cjs`),l=require(`../../functions/utils/erc20tokenFunctions.cjs`),u=require(`../../functions/utils/time.utils.cjs`),d=require(`../utxo/Utxo.cjs`),f=require(`../../functions/utils/token-check.utils.cjs`),p=require(`../../functions/pre-transaction/constructAdminData.cjs`),m=require(`../../functions/pre-transaction/getFeeStructure.cjs`),h=require(`../../functions/pre-transaction/waitForDepositedUtxosInMerkleTree.cjs`),g=require(`../../functions/utils/convertEmporiumOpToCallInfo.cjs`),_=require(`../../functions/utils/fees.utils.cjs`);require(`../../functions/utils/index.cjs`);const v=require(`../../functions/private-wallet/emporium.helpers.cjs`),y=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),b=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`),x=require(`../../API/deposit-and-withdraw-status-calls.cjs`),S=require(`./hinkalDepositOnChainUtxos.cjs`);require(`../../functions/index.cjs`);var C=async(a,l,f,m,h,g,S,C,w,T,E)=>{if(m.length===0)throw Error(`No recipients to bridge`);let D=f.erc20TokenAddress,{contractData:O}=t.networkRegistry[l],{emporiumAddress:k}=O;if(!k)throw Error(`No Emporium Address`);let A=s.SWAP_ROUTER_ADDRESSES[e.ExternalActionId.Lifi][l];if(!A)throw Error(`LIFI not configured for chain ${l}`);let j=await a.getRandomRelay(l);if(!j)throw Error(c.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let M=await a.getEthereumAddressByChain(l),N=u.getCurrentTimeInSeconds().toString(),P=a.generateProofRemotely?5:1,F=[];for(let t=0;t<m.length;t+=P){let r=m.slice(t,t+P),s=await Promise.all(r.map(async({utxo:t,nativeUtxo:r,bridgeAmount:s,quote:c,temporarySubAccount:u,recipientAddress:m})=>{await o.API.addTemporaryWalletNonce(l,g,u.index);let b=c.nativeFee>0n&&!i.caseInsensitiveEqual(D,n.zeroAddress),x=[D],S=[-t.amount],C=[!1],w=new d.Utxo({amount:0n,erc20TokenAddress:D,nullifyingKey:a.userKeys.getShieldedPrivateKey(),timeStamp:N,...t.isNewStyle?{spendingPublicKey:a.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,isNewStyle:!0}:{isNewStyle:!1}}),E=[[t,w]],O=[[w]];if(b&&r){let e=new d.Utxo({amount:0n,erc20TokenAddress:n.zeroAddress,nullifyingKey:a.userKeys.getShieldedPrivateKey(),timeStamp:N,...r.isNewStyle?{spendingPublicKey:a.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,isNewStyle:!0}:{isNewStyle:!1}});x.push(n.zeroAddress),S.push(-r.amount),C.push(!1),E.push([r,e]),O.push([e])}let P=v.createLifiBridgeOps(a,l,u.ethAddress,A,D,t.amount,s,c),F=await _.calculateModifiedFeeStructure(l,f,s,h),I=p.constructAdminData(T,l,x,[-t.amount],M),[{zkCallData:L,circomData:R,dimData:z,commitmentValidationData:B},V]=await Promise.all([y.constructZkProof(a.merkleTreeHinkalByChain[l],E,O,a.userKeys,e.ExternalActionId.Emporium,k,P,a.generateProofRemotely,F,j??n.zeroAddress,l,C,void 0,void 0,u.privateKey),v.getAuthorizationDataIfNeeded(l,u.privateKey)]);return{zkCallData:L,dimData:z,circomData:R,commitmentValidationData:B,authorizationData:V,recipientAddress:m,adminData:I}}));F.push(...s)}await x.safeUpdateDepositAndWithdrawStatus({id:S,chainId:l,hashedEthereumAddress:g,phase:r.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});let I=await b.transactCallRelayerBatch(l,F,g,C,w,E);return await x.safeUpdateDepositAndWithdrawStatus({id:S,chainId:l,hashedEthereumAddress:g,phase:r.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:I}),I},w=async(t,r,o,c,u,d,p,_,y=!0)=>{let b=r.erc20TokenAddress,x=f.validateAndGetChainId([r]),w=_?a.hashString(_):void 0,T=a.hashEthereumAddress(await t.getEthereumAddressByChain(x)),E=s.SWAP_ROUTER_ADDRESSES[e.ExternalActionId.Lifi][x];if(!E)throw Error(`LIFI router not configured`);let D;if(u)D=u;else{let r=o[0],i=v.createLifiBridgeOps(t,x,r.temporarySubAccount.ethAddress,E,b,r.bridgeAmount,r.bridgeAmount,r.quote).map(e=>g.convertEmporiumOpToCallInfo(e,r.temporarySubAccount.ethAddress,x));D=await m.getFeeStructure(x,b,[b],e.ExternalActionId.Emporium,i,n.PAY_SEND_VARIABLE_RATE)}let O={feeToken:D.feeToken,flatFee:0n,variableRate:0n},k=o.reduce((e,t)=>e+t.quote.nativeFee,0n)>0n&&!i.caseInsensitiveEqual(b,n.zeroAddress),A=o.map(e=>e.bridgeAmount),j=o.map(e=>e.recipientAddress),{userDepositedUtxos:M,statusId:N,depositTxHash:P}=await S.hinkalDepositOnChainUtxos(t,x,r,A,j,D,T,y),F=[];if(k){let e=l.getERC20Token(n.zeroAddress,x);if(!e)throw Error(`No native token`);let{userDepositedUtxos:r}=await S.hinkalDepositOnChainUtxos(t,x,e,o.map(e=>e.quote.nativeFee),j,O,T,y);F=r}return await h.waitForDepositedUtxosInMerkleTree(t,x,[...M,...F]),{depositTxHash:P,scheduleId:await C(t,x,r,o.map((e,t)=>({...e,utxo:M[t].utxo,nativeUtxo:k?F[t]?.utxo:void 0})),D,T,N,c,d,p,w)}};exports.hinkalDepositAndBridge=w;
@@ -1,4 +1,4 @@
1
1
  import { IHinkal } from './IHinkal';
2
- import { AdminTransactionType, BridgeRecipient, ERC20Token } from '../../types';
2
+ import { AdminTransactionType, BridgeRecipient, DepositAndSendExtendedResult, ERC20Token } from '../../types';
3
3
  import { FeeStructure } from '../../types/hinkal.types';
4
- export declare const hinkalDepositAndBridge: (hinkal: IHinkal, erc20Token: ERC20Token, recipients: BridgeRecipient[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, preEstimateGas?: boolean) => Promise<string>;
4
+ export declare const hinkalDepositAndBridge: (hinkal: IHinkal, erc20Token: ERC20Token, recipients: BridgeRecipient[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, preEstimateGas?: boolean) => Promise<DepositAndSendExtendedResult>;
@@ -107,11 +107,14 @@ var E = async (n, o, s, d, m, g, _, v, T, E, D) => {
107
107
  let { userDepositedUtxos: n } = await T(t, C, e, c.map((e) => e.quote.nativeFee), N, A, D, x);
108
108
  L = n;
109
109
  }
110
- return await _(t, C, [...P, ...L]), await E(t, C, i, c.map((e, t) => ({
111
- ...e,
112
- utxo: P[t].utxo,
113
- nativeUtxo: j ? L[t]?.utxo : void 0
114
- })), k, D, F, u, p, h, w), I;
110
+ return await _(t, C, [...P, ...L]), {
111
+ depositTxHash: I,
112
+ scheduleId: await E(t, C, i, c.map((e, t) => ({
113
+ ...e,
114
+ utxo: P[t].utxo,
115
+ nativeUtxo: j ? L[t]?.utxo : void 0
116
+ })), k, D, F, u, p, h, w)
117
+ };
115
118
  };
116
119
  //#endregion
117
120
  export { D as hinkalDepositAndBridge };
@@ -1 +1 @@
1
- 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/caseInsensitive.utils.cjs`),a=require(`../../functions/utils/addresses.cjs`),o=require(`../../error-handling/error-codes.constants.cjs`),s=require(`../../functions/utils/time.utils.cjs`),c=require(`../utxo/Utxo.cjs`),l=require(`../../functions/utils/tron.utils.cjs`),u=require(`../../functions/utils/token-check.utils.cjs`),d=require(`../../functions/pre-transaction/constructAdminData.cjs`),f=require(`../../functions/pre-transaction/getFeeStructure.cjs`),p=require(`../../functions/pre-transaction/waitForDepositedUtxosInMerkleTree.cjs`),m=require(`../../functions/utils/fees.utils.cjs`),h=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),g=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`),_=require(`../../API/deposit-and-withdraw-status-calls.cjs`),v=require(`./hinkalDepositOnChainUtxos.cjs`);require(`../../functions/index.cjs`);var y=async(e,a,u,f,p,v,y,b,x,S,C,w)=>{let T=t.isTronLike(a);if(f.length===0)throw Error(`userDepositedUtxos must not be empty`);let E=u.erc20TokenAddress,[D,O]=await Promise.all([e.getRandomRelay(a),e.getEthereumAddressByChain(a)]);if(!D)throw Error(o.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let k=s.getCurrentTimeInSeconds().toString(),A=e.generateProofRemotely&&!T?5:1,j=[],M=l.addressToHexFormat(O);for(let t=0;t<f.length;t+=A){let r=f.slice(t,t+A),o=await Promise.all(r.map(async({recipientAddress:r,utxo:o},s)=>{let f=t+s,g=l.addressToHexFormat(r),_=new c.Utxo({amount:0n,erc20TokenAddress:E,nullifyingKey:e.userKeys.getShieldedPrivateKey(),timeStamp:k,...o.isNewStyle?{spendingPublicKey:e.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,isNewStyle:!0}:{isNewStyle:!1}}),y=[[i.caseInsensitiveEqual(o.erc20TokenAddress,E)?o:c.Utxo.createFrom(o,{erc20TokenAddress:E}),_]],b=[[_]],x={externalActionId:0n,externalAddress:g,externalActionMetadata:`0x00`},S=d.constructAdminData(C,a,[E],[-o.amount],M),w=await m.calculateModifiedFeeStructure(a,u,p[f],v),{zkCallData:O,circomData:A,dimData:j,commitmentValidationData:N}=await h.constructZkProof(e.merkleTreeHinkalByChain[a],y,b,e.userKeys,x.externalActionId,x.externalAddress,x.externalActionMetadata,e.generateProofRemotely,w,D??n.zeroAddress,a);return{zkCallData:O,dimData:j,circomData:A,commitmentValidationData:N,adminData:S,recipientAddress:r,tronProofSignature:await l.reorderZkCallData(T,O,j,A)}}));j.push(...o)}await _.safeUpdateDepositAndWithdrawStatus({id:b,chainId:a,hashedEthereumAddress:y,phase:r.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});let N=await g.transactCallRelayerBatch(a,j,y,x,S,w);return await _.safeUpdateDepositAndWithdrawStatus({id:b,chainId:a,hashedEthereumAddress:y,phase:r.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:N}),N},b=async(t,n,r,i,o,s,c,d,m,h=!0)=>{let g=u.validateAndGetChainId([n]),_=m?a.hashString(m):void 0,b=n.erc20TokenAddress,x=a.hashEthereumAddress(l.addressToHexFormat(await t.getEthereumAddressByChain(g))),S=s??await f.getFeeStructure(g,b,[b],e.ExternalActionId.Transact,[],10n),{userDepositedUtxos:C,statusId:w,depositTxHash:T}=await v.hinkalDepositOnChainUtxos(t,g,n,r,i,S,x,h);return await p.waitForDepositedUtxosInMerkleTree(t,g,C),await y(t,g,n,C,r,S,x,w,o,c,d,_),T};exports.hinkalDepositAndWithdraw=b,exports.hinkalWithdrawBatch=y;
1
+ 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/caseInsensitive.utils.cjs`),a=require(`../../functions/utils/addresses.cjs`),o=require(`../../error-handling/error-codes.constants.cjs`),s=require(`../../functions/utils/time.utils.cjs`),c=require(`../utxo/Utxo.cjs`),l=require(`../../functions/utils/tron.utils.cjs`),u=require(`../../functions/utils/token-check.utils.cjs`),d=require(`../../functions/pre-transaction/constructAdminData.cjs`),f=require(`../../functions/pre-transaction/getFeeStructure.cjs`),p=require(`../../functions/pre-transaction/waitForDepositedUtxosInMerkleTree.cjs`),m=require(`../../functions/utils/fees.utils.cjs`),h=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),g=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`),_=require(`../../API/deposit-and-withdraw-status-calls.cjs`),v=require(`./hinkalDepositOnChainUtxos.cjs`);require(`../../functions/index.cjs`);var y=async(e,a,u,f,p,v,y,b,x,S,C,w)=>{let T=t.isTronLike(a);if(f.length===0)throw Error(`userDepositedUtxos must not be empty`);let E=u.erc20TokenAddress,[D,O]=await Promise.all([e.getRandomRelay(a),e.getEthereumAddressByChain(a)]);if(!D)throw Error(o.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let k=s.getCurrentTimeInSeconds().toString(),A=e.generateProofRemotely&&!T?5:1,j=[],M=l.addressToHexFormat(O);for(let t=0;t<f.length;t+=A){let r=f.slice(t,t+A),o=await Promise.all(r.map(async({recipientAddress:r,utxo:o},s)=>{let f=t+s,g=l.addressToHexFormat(r),_=new c.Utxo({amount:0n,erc20TokenAddress:E,nullifyingKey:e.userKeys.getShieldedPrivateKey(),timeStamp:k,...o.isNewStyle?{spendingPublicKey:e.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,isNewStyle:!0}:{isNewStyle:!1}}),y=[[i.caseInsensitiveEqual(o.erc20TokenAddress,E)?o:c.Utxo.createFrom(o,{erc20TokenAddress:E}),_]],b=[[_]],x={externalActionId:0n,externalAddress:g,externalActionMetadata:`0x00`},S=d.constructAdminData(C,a,[E],[-o.amount],M),w=await m.calculateModifiedFeeStructure(a,u,p[f],v),{zkCallData:O,circomData:A,dimData:j,commitmentValidationData:N}=await h.constructZkProof(e.merkleTreeHinkalByChain[a],y,b,e.userKeys,x.externalActionId,x.externalAddress,x.externalActionMetadata,e.generateProofRemotely,w,D??n.zeroAddress,a);return{zkCallData:O,dimData:j,circomData:A,commitmentValidationData:N,adminData:S,recipientAddress:r,tronProofSignature:await l.reorderZkCallData(T,O,j,A)}}));j.push(...o)}await _.safeUpdateDepositAndWithdrawStatus({id:b,chainId:a,hashedEthereumAddress:y,phase:r.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});let N=await g.transactCallRelayerBatch(a,j,y,x,S,w);return await _.safeUpdateDepositAndWithdrawStatus({id:b,chainId:a,hashedEthereumAddress:y,phase:r.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:N}),N},b=async(t,n,r,i,o,s,c,d,m,h=!0)=>{let g=u.validateAndGetChainId([n]),_=m?a.hashString(m):void 0,b=n.erc20TokenAddress,x=a.hashEthereumAddress(l.addressToHexFormat(await t.getEthereumAddressByChain(g))),S=s??await f.getFeeStructure(g,b,[b],e.ExternalActionId.Transact,[],10n),{userDepositedUtxos:C,statusId:w,depositTxHash:T}=await v.hinkalDepositOnChainUtxos(t,g,n,r,i,S,x,h);return await p.waitForDepositedUtxosInMerkleTree(t,g,C),{depositTxHash:T,scheduleId:await y(t,g,n,C,r,S,x,w,o,c,d,_)}};exports.hinkalDepositAndWithdraw=b,exports.hinkalWithdrawBatch=y;
@@ -1,6 +1,6 @@
1
1
  import { IHinkal } from './IHinkal';
2
- import { AdminTransactionType, ERC20Token, RecipientUtxo } from '../../types';
2
+ import { AdminTransactionType, DepositAndSendExtendedResult, ERC20Token, RecipientUtxo } from '../../types';
3
3
  import { FeeStructure } from '../../types/hinkal.types';
4
4
  export declare const hinkalWithdrawBatch: (hinkal: IHinkal, chainId: number, erc20Token: ERC20Token, userDepositedUtxos: RecipientUtxo[], recipientAmounts: bigint[], feeStructure: FeeStructure, hashedEthereumAddress: string, statusId: string | undefined, txCompletionTime?: number, ref?: string, action?: AdminTransactionType, hashedDashboardAccountId?: string) => Promise<string>;
5
5
  export declare const hinkalDepositAndWithdraw: (hinkal: IHinkal, erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, // Should be passed fee for only one withdraw transaction, multiplication happening in this function
6
- ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, preEstimateGas?: boolean) => Promise<string>;
6
+ ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, preEstimateGas?: boolean) => Promise<DepositAndSendExtendedResult>;
@@ -70,7 +70,10 @@ var x = async (e, a, o, f, m, h, b, x, S, C, w, T) => {
70
70
  }), P;
71
71
  }, S = async (t, n, r, i, s, c, l, d, p, g = !0) => {
72
72
  let _ = f([n]), v = p ? o(p) : void 0, y = n.erc20TokenAddress, S = a(u(await t.getEthereumAddressByChain(_))), C = c ?? await m(_, y, [y], e.Transact, [], 10n), { userDepositedUtxos: w, statusId: T, depositTxHash: E } = await b(t, _, n, r, i, C, S, g);
73
- return await h(t, _, w), await x(t, _, n, w, r, C, S, T, s, l, d, v), E;
73
+ return await h(t, _, w), {
74
+ depositTxHash: E,
75
+ scheduleId: await x(t, _, n, w, r, C, S, T, s, l, d, v)
76
+ };
74
77
  };
75
78
  //#endregion
76
79
  export { S as hinkalDepositAndWithdraw, x as hinkalWithdrawBatch };
@@ -1 +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;
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 e.isSolanaLike(v)?{depositTxHash:T}=await s.hinkalSolanaDepositAndWithdraw(c,l,C,w,p,S,h,g,_,x.map(e=>e.destinationRecipient)):{depositTxHash:T}=await o.hinkalDepositAndWithdraw(c,l,C,w,p,S,h,g,_),{depositTxHash:T,legs:x}};exports.hinkalNearDepositAndBridge=c;
@@ -34,7 +34,7 @@ var c = async (c, l, u, d, f, p, m, h, g, _) => {
34
34
  quote: i
35
35
  };
36
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, _), {
37
+ return e(v) ? {depositTxHash: T} = await s(c, l, C, w, p, S, h, g, _, x.map((e) => e.destinationRecipient)) : {depositTxHash: T} = await o(c, l, C, w, p, S, h, g, _), {
38
38
  depositTxHash: T,
39
39
  legs: x
40
40
  };
@@ -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,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;
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),{depositTxHash:x,scheduleId:await k(t,p,n,b,y,h,r,S,o,c,l,v,f)}};exports.buildMultiPaymentDepositBuilder=D,exports.buildMultiPaymentDepositSetup=E,exports.hinkalSolanaDepositAndWithdraw=A,exports.hinkalSolanaWithdrawBatch=k;
@@ -1,7 +1,7 @@
1
1
  import { FeeStructure } from '../../types/hinkal.types';
2
2
  import { IHinkal } from './IHinkal';
3
3
  import { PublicKey } from '@solana/web3.js';
4
- import { AdminTransactionType, RecipientUtxo } from '../../types';
4
+ import { AdminTransactionType, DepositAndSendExtendedResult, RecipientUtxo } from '../../types';
5
5
  import { ERC20Token } from '../../types/token.types';
6
6
  export declare const buildMultiPaymentDepositSetup: (hinkal: IHinkal, chainId: number, token: ERC20Token, amounts: bigint[]) => {
7
7
  program: import('@coral-xyz/anchor').Program<import('@coral-xyz/anchor').Idl>;
@@ -21,4 +21,4 @@ export declare const buildMultiPaymentDepositBuilder: (setup: MultiPaymentDeposi
21
21
  }, import('@coral-xyz/anchor/dist/cjs/idl').IdlInstructionAccountItem>;
22
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, displayRecipients?: string[]) => Promise<string>;
24
+ ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, displayRecipients?: string[]) => Promise<DepositAndSendExtendedResult>;