@hinkal/common 0.2.23 → 0.2.25

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.
@@ -9,7 +9,7 @@ import "../../types/circom-data.types.mjs";
9
9
  import { ContractType as p } from "../../types/ethereum-network.types.mjs";
10
10
  import { AdminTransactionType as L } from "../../types/admin.types.mjs";
11
11
  import "../../types/activities.types.mjs";
12
- import { DepositAndWithdrawPhase as U } from "../../types/scheduled-transactions.types.mjs";
12
+ import { DepositAndWithdrawPhase as y } from "../../types/scheduled-transactions.types.mjs";
13
13
  import { getSignatureDataForTransact as N } from "../../functions/pre-transaction/getSignatureDataForTransact.mjs";
14
14
  import { shouldPatchAccessTokenMerkleTree as Q } from "../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.mjs";
15
15
  import { getUtxosFromReceipt as V } from "../../functions/utils/getUtxosFromReceipt.utils.mjs";
@@ -17,26 +17,26 @@ import { calculateTotalFee as Y } from "../../functions/utils/fees.utils.mjs";
17
17
  import { constructAdminData as tt } from "../../functions/pre-transaction/constructAdminData.mjs";
18
18
  import { emitTxPublicData as ot } from "../../API/admin-calls.mjs";
19
19
  import { updateDepositAndWithdrawStatus as et, safeUpdateDepositAndWithdrawStatus as rt } from "../../API/deposit-and-withdraw-status-calls.mjs";
20
- const yt = async (t, m, y, O, E, u) => {
21
- const f = m.erc20TokenAddress, x = await t.getEthereumAddress(), a = y.map((o) => o + Y(o, E)), i = [f], n = [0n], P = [!0], { patchAccessTokenMerkleTree: v, kycRequired: I, hasAccessToken: W } = await Q(
20
+ const yt = async (t, m, O, E, P, u) => {
21
+ const f = m.erc20TokenAddress, x = await t.getEthereumAddress(), a = O.map((o) => o + Y(o, P)), i = [f], n = [0n], v = [!0], { patchAccessTokenMerkleTree: I, kycRequired: W, hasAccessToken: S } = await Q(
22
22
  t,
23
23
  i,
24
24
  n
25
- ), S = await N(
25
+ ), F = await N(
26
26
  t.getCurrentChainId(),
27
27
  x,
28
28
  t.userKeys,
29
- I,
30
- W
29
+ W,
30
+ S
31
31
  ), r = [...await j(t, i, n)], C = [];
32
32
  for (let o = 0; o < r.length; o += 1) {
33
33
  const { outputUtxos: e } = B(t.userKeys, r[o], n[o]);
34
34
  C.push(e);
35
35
  }
36
- const A = a.reduce((o, e) => o + e, 0n), F = _.AbiCoder.defaultAbiCoder().encode(["uint256[]"], [a]), D = t.getContractWithSigner(p.HinkalWrapper), g = t.getContractWithSigner(p.DepositOnChainUtxos), {
37
- zkCallData: H,
38
- circomData: R,
39
- dimData: b
36
+ const A = a.reduce((o, e) => o + e, 0n), H = _.AbiCoder.defaultAbiCoder().encode(["uint256[]"], [a]), D = t.getContractWithSigner(p.HinkalWrapper), g = t.getContractWithSigner(p.DepositOnChainUtxos), {
37
+ zkCallData: R,
38
+ circomData: b,
39
+ dimData: K
40
40
  } = await X(
41
41
  "v1x1",
42
42
  t.merkleTreeHinkal,
@@ -47,46 +47,46 @@ const yt = async (t, m, y, O, E, u) => {
47
47
  `swapperM1x${r[0].length}x1`,
48
48
  J.DepositOnChainUtxos,
49
49
  await g.getAddress(),
50
- F,
50
+ H,
51
51
  t.generateProofRemotely,
52
52
  q,
53
53
  t.getCurrentChainId(),
54
- P,
54
+ v,
55
55
  void 0,
56
56
  void 0,
57
- v,
57
+ I,
58
58
  void 0,
59
59
  void 0,
60
60
  void 0,
61
61
  t.getContractWithFetcher(p.HinkalHelperContract),
62
- S,
62
+ F,
63
63
  await D.getAddress(),
64
64
  !1
65
65
  ), s = t.getCurrentChainId(), h = (await et(s, {
66
66
  hashedEthereumAddress: u,
67
- phase: U.BEFORE_DEPOSIT
67
+ phase: y.BEFORE_DEPOSIT
68
68
  })).id ?? void 0, w = await G(
69
69
  t,
70
70
  A,
71
71
  m,
72
- H,
73
72
  R,
74
73
  b,
74
+ K,
75
75
  g,
76
76
  D
77
- ), K = await w.wait(), M = w.hash;
77
+ ), M = await w.wait(), T = w.hash;
78
78
  await rt(s, {
79
79
  id: h,
80
80
  hashedEthereumAddress: u,
81
- phase: U.AFTER_DEPOSIT,
82
- depositTxHash: M
81
+ phase: y.AFTER_DEPOSIT,
82
+ depositTxHash: T
83
83
  });
84
- const $ = await V(K, t, f), T = [], c = [...$];
85
- O.forEach((o, e) => {
86
- const l = a[e], d = c.find((Z) => Z.amount === l);
84
+ const $ = await V(M, t, f), l = [], c = [...$];
85
+ E.forEach((o, e) => {
86
+ const U = a[e], d = c.find((Z) => Z.amount === U);
87
87
  if (!d)
88
- throw new Error(`Could not find newly created UTXO with amount ${l} for recipient ${o}.`);
89
- T.push({
88
+ throw new Error(`Could not find newly created UTXO with amount ${U} for recipient ${o}.`);
89
+ l.push({
90
90
  recipientAddress: o,
91
91
  utxo: d
92
92
  });
@@ -100,7 +100,7 @@ const yt = async (t, m, y, O, E, u) => {
100
100
  [A],
101
101
  x
102
102
  );
103
- return ot(s, k), { userDepositedUtxos: T, statusId: h };
103
+ return ot(s, k), { userDepositedUtxos: l, statusId: h, depositTxHash: T };
104
104
  };
105
105
  export {
106
106
  yt as hinkalDepositOnChainUtxos
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("../../constants/protocol.constants.cjs"),X=require("../../error-handling/error-codes.constants.cjs"),ee=require("../../functions/snarkjs/constructEmporiumProof.cjs"),te=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),I=require("../../types/external-action.types.cjs"),O=require("../utxo/Utxo.cjs");require("../../types/circom-data.types.cjs");const re=require("../../types/ethereum-network.types.cjs");require("../../types/activities.types.cjs");const W=require("../../types/scheduled-transactions.types.cjs"),se=require("../../functions/pre-transaction/getSignatureDataForTransact.cjs"),oe=require("../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs"),ne=require("../../functions/utils/time.utils.cjs"),ie=require("../../functions/pre-transaction/getFeeStructure.cjs"),ae=require("../../functions/utils/addresses.cjs"),ce=require("../../constants/chains.constants.cjs"),L=require("../../constants/addresses.constants.cjs");require("idb-keyval");require("@solana/web3.js");require("../http/HttpClient.cjs");require("../../constants/vite.constants.cjs");require("ethers");const ue=require("../../functions/utils/erc20tokenFunctions.cjs");require("../../functions/utils/convertIntegrationProviderToExternalActionId.cjs");require("../../constants/server.constants.cjs");require("axios");const N=require("../../functions/utils/caseInsensitive.utils.cjs");require("../../API/getServerURL.cjs");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");require("../../constants/save-depths.cjs");require("../../constants/reorg-depths.constants.cjs");require("../../functions/utils/mutexes.utils.cjs");require("@coral-xyz/anchor");require("../crypto-keys/keys.cjs");require("@solana/spl-token");require("../../constants/token-data/index.cjs");require("../../constants/contracts.constants.cjs");require("../../constants/kyc.constants.cjs");require("../../constants/coingecko.constants.cjs");require("../../constants/token.limits.constants.cjs");require("../../constants/presale.constants.cjs");require("../../constants/activity.constants.cjs");require("../../constants/tasks.constants.cjs");require("../../constants/events.constants.cjs");require("../../functions/utils/userAgent.cjs");const de=require("../../functions/utils/convertEmporiumOpToCallInfo.cjs");require("multiformats");const le=require("../../API/API.cjs");require("../../API/tenderly.api.cjs");const b=require("./hinkalDepositOnChainUtxos.cjs"),K=require("../../functions/private-wallet/emporium.helpers.cjs"),z=require("../../API/deposit-and-withdraw-status-calls.cjs"),pe=async(e,A,s,v,i,f,d,l)=>{if(s.length===0)throw new Error("No recipients to bridge");const n=A.erc20TokenAddress,r=e.getCurrentChainId(),{contractData:a}=ce.networkRegistry[r],{emporiumAddress:T}=a;if(!T)throw Error("No Emporium Address");const D=L.SWAP_ROUTER_ADDRESSES[I.ExternalActionId.Lifi][r];if(!D)throw new Error(`LIFI not configured for chain ${r}`);const m=await e.getRandomRelay();if(!m)throw Error(X.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const C=await e.getEthereumAddress(),h=ne.getCurrentTimeInSeconds().toString(),w=e.generateProofRemotely?5:1,y=[];for(let p=0;p<s.length;p+=w){const t=s.slice(p,p+w),o=await Promise.all(t.map(async({utxo:c,nativeUtxo:u,bridgeAmount:B,quote:x,temporarySubAccount:R})=>{await le.API.addTemporaryWalletNonce(r,i,R.index);const H=x.nativeFee>0n&&!N.caseInsensitiveEqual(n,q.zeroAddress),E=[n],U=[-c.amount],_=[!1],k=new O.Utxo({amount:0n,erc20TokenAddress:n,shieldedPrivateKey:e.userKeys.getShieldedPrivateKey(),timeStamp:h,tokenId:0}),S=[[c,k]],F=[[k]];if(H&&u){const P=new O.Utxo({amount:0n,erc20TokenAddress:q.zeroAddress,shieldedPrivateKey:e.userKeys.getShieldedPrivateKey(),timeStamp:h,tokenId:0});E.push(q.zeroAddress),U.push(-u.amount),_.push(!1),S.push([u,P]),F.push([P])}const M=K.createLifiBridgeOps(e,R.ethAddress,D,n,c.amount,B,x),{patchAccessTokenMerkleTree:j,kycRequired:V,hasAccessToken:Y}=await oe.shouldPatchAccessTokenMerkleTree(e,E,U),Z=await se.getSignatureDataForTransact(r,C,e.userKeys,V,Y),{zkCallData:$,circomData:G,dimData:J,authorizationData:Q}=await ee.constructEmporiumProof("v1x1",e.merkleTreeHinkal,e.merkleTreeAccessToken,E,E.map(()=>0),S,F,e.userKeys,E.length,S[0].length,T,M,e.generateProofRemotely,m??q.zeroAddress,r,_,void 0,R.privateKey,void 0,j,void 0,v,e.getContractWithFetcher(re.ContractType.HinkalHelperContract),Z,void 0,!1);return{zkCallData:$,dimData:J,circomData:G,authorizationData:Q}}));y.push(...o)}await z.safeUpdateDepositAndWithdrawStatus(r,{id:f,hashedEthereumAddress:i,phase:W.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});const g=await te.transactCallRelayerBatch(r,y,i,d,l);return await z.safeUpdateDepositAndWithdrawStatus(r,{id:f,hashedEthereumAddress:i,phase:W.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:g}),g},qe=async(e,A,s,v,i,f)=>{const d=A.erc20TokenAddress,l=e.getCurrentChainId(),n=ae.hashEthereumAddress(await e.getEthereumAddress()),r=L.SWAP_ROUTER_ADDRESSES[I.ExternalActionId.Lifi][l];if(!r)throw Error("LIFI router not configured");let a;if(i)a=i;else{const t=s[0],c=K.createLifiBridgeOps(e,t.temporarySubAccount.ethAddress,r,d,t.bridgeAmount,t.bridgeAmount,t.quote).map(u=>de.convertEmporiumOpToCallInfo(u,t.temporarySubAccount.ethAddress,l));a=await ie.getFeeStructure(l,d,[d],I.ExternalActionId.Emporium,c)}const T={feeToken:a.feeToken,flatFee:0n,variableRate:0n},m=s.reduce((t,o)=>t+o.quote.nativeFee,0n)>0n&&!N.caseInsensitiveEqual(d,q.zeroAddress),C=s.map(t=>t.bridgeAmount),h=s.map(t=>t.recipientAddress),{userDepositedUtxos:w,statusId:y}=await b.hinkalDepositOnChainUtxos(e,A,C,h,a,n);let g=[];if(m){const t=ue.getERC20Token(q.zeroAddress,l);if(!t)throw Error("No native token");const o=s.map(u=>u.quote.nativeFee),{userDepositedUtxos:c}=await b.hinkalDepositOnChainUtxos(e,t,o,h,T,n);g=c}const p=s.map((t,o)=>({...t,utxo:w[o].utxo,nativeUtxo:m?g[o]?.utxo:void 0}));return pe(e,A,p,a,n,y,v,f)};exports.hinkalDepositAndBridge=qe;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("../../constants/protocol.constants.cjs"),X=require("../../error-handling/error-codes.constants.cjs"),ee=require("../../functions/snarkjs/constructEmporiumProof.cjs"),te=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),x=require("../../types/external-action.types.cjs"),W=require("../utxo/Utxo.cjs");require("../../types/circom-data.types.cjs");const re=require("../../types/ethereum-network.types.cjs");require("../../types/activities.types.cjs");const b=require("../../types/scheduled-transactions.types.cjs"),se=require("../../functions/pre-transaction/getSignatureDataForTransact.cjs"),oe=require("../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs"),ne=require("../../functions/utils/time.utils.cjs"),ie=require("../../functions/pre-transaction/getFeeStructure.cjs"),ae=require("../../functions/utils/addresses.cjs"),ce=require("../../constants/chains.constants.cjs"),N=require("../../constants/addresses.constants.cjs");require("idb-keyval");require("@solana/web3.js");require("../http/HttpClient.cjs");require("../../constants/vite.constants.cjs");require("ethers");const ue=require("../../functions/utils/erc20tokenFunctions.cjs");require("../../functions/utils/convertIntegrationProviderToExternalActionId.cjs");require("../../constants/server.constants.cjs");require("axios");const K=require("../../functions/utils/caseInsensitive.utils.cjs");require("../../API/getServerURL.cjs");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");require("../../constants/save-depths.cjs");require("../../constants/reorg-depths.constants.cjs");require("../../functions/utils/mutexes.utils.cjs");require("@coral-xyz/anchor");require("../crypto-keys/keys.cjs");require("@solana/spl-token");require("../../constants/token-data/index.cjs");require("../../constants/contracts.constants.cjs");require("../../constants/kyc.constants.cjs");require("../../constants/coingecko.constants.cjs");require("../../constants/token.limits.constants.cjs");require("../../constants/presale.constants.cjs");require("../../constants/activity.constants.cjs");require("../../constants/tasks.constants.cjs");require("../../constants/events.constants.cjs");require("../../functions/utils/userAgent.cjs");const de=require("../../functions/utils/convertEmporiumOpToCallInfo.cjs");require("multiformats");const le=require("../../API/API.cjs");require("../../API/tenderly.api.cjs");const z=require("./hinkalDepositOnChainUtxos.cjs"),B=require("../../functions/private-wallet/emporium.helpers.cjs"),L=require("../../API/deposit-and-withdraw-status-calls.cjs"),pe=async(e,q,o,v,i,E,d,l)=>{if(o.length===0)throw new Error("No recipients to bridge");const n=q.erc20TokenAddress,r=e.getCurrentChainId(),{contractData:a}=ce.networkRegistry[r],{emporiumAddress:T}=a;if(!T)throw Error("No Emporium Address");const D=N.SWAP_ROUTER_ADDRESSES[x.ExternalActionId.Lifi][r];if(!D)throw new Error(`LIFI not configured for chain ${r}`);const A=await e.getRandomRelay();if(!A)throw Error(X.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const C=await e.getEthereumAddress(),m=ne.getCurrentTimeInSeconds().toString(),f=e.generateProofRemotely?5:1,w=[];for(let c=0;c<o.length;c+=f){const R=o.slice(c,c+f),t=await Promise.all(R.map(async({utxo:s,nativeUtxo:u,bridgeAmount:h,quote:U,temporarySubAccount:S})=>{await le.API.addTemporaryWalletNonce(r,i,S.index);const H=U.nativeFee>0n&&!K.caseInsensitiveEqual(n,p.zeroAddress),g=[n],_=[-s.amount],k=[!1],F=new W.Utxo({amount:0n,erc20TokenAddress:n,shieldedPrivateKey:e.userKeys.getShieldedPrivateKey(),timeStamp:m,tokenId:0}),I=[[s,F]],P=[[F]];if(H&&u){const O=new W.Utxo({amount:0n,erc20TokenAddress:p.zeroAddress,shieldedPrivateKey:e.userKeys.getShieldedPrivateKey(),timeStamp:m,tokenId:0});g.push(p.zeroAddress),_.push(-u.amount),k.push(!1),I.push([u,O]),P.push([O])}const M=B.createLifiBridgeOps(e,S.ethAddress,D,n,s.amount,h,U),{patchAccessTokenMerkleTree:j,kycRequired:V,hasAccessToken:Y}=await oe.shouldPatchAccessTokenMerkleTree(e,g,_),Z=await se.getSignatureDataForTransact(r,C,e.userKeys,V,Y),{zkCallData:$,circomData:G,dimData:J,authorizationData:Q}=await ee.constructEmporiumProof("v1x1",e.merkleTreeHinkal,e.merkleTreeAccessToken,g,g.map(()=>0),I,P,e.userKeys,g.length,I[0].length,T,M,e.generateProofRemotely,A??p.zeroAddress,r,k,void 0,S.privateKey,void 0,j,void 0,v,e.getContractWithFetcher(re.ContractType.HinkalHelperContract),Z,void 0,!1);return{zkCallData:$,dimData:J,circomData:G,authorizationData:Q}}));w.push(...t)}await L.safeUpdateDepositAndWithdrawStatus(r,{id:E,hashedEthereumAddress:i,phase:b.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});const y=await te.transactCallRelayerBatch(r,w,i,d,l);return await L.safeUpdateDepositAndWithdrawStatus(r,{id:E,hashedEthereumAddress:i,phase:b.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:y}),y},qe=async(e,q,o,v,i,E)=>{const d=q.erc20TokenAddress,l=e.getCurrentChainId(),n=ae.hashEthereumAddress(await e.getEthereumAddress()),r=N.SWAP_ROUTER_ADDRESSES[x.ExternalActionId.Lifi][l];if(!r)throw Error("LIFI router not configured");let a;if(i)a=i;else{const t=o[0],u=B.createLifiBridgeOps(e,t.temporarySubAccount.ethAddress,r,d,t.bridgeAmount,t.bridgeAmount,t.quote).map(h=>de.convertEmporiumOpToCallInfo(h,t.temporarySubAccount.ethAddress,l));a=await ie.getFeeStructure(l,d,[d],x.ExternalActionId.Emporium,u)}const T={feeToken:a.feeToken,flatFee:0n,variableRate:0n},A=o.reduce((t,s)=>t+s.quote.nativeFee,0n)>0n&&!K.caseInsensitiveEqual(d,p.zeroAddress),C=o.map(t=>t.bridgeAmount),m=o.map(t=>t.recipientAddress),{userDepositedUtxos:f,statusId:w,depositTxHash:y}=await z.hinkalDepositOnChainUtxos(e,q,C,m,a,n);let c=[];if(A){const t=ue.getERC20Token(p.zeroAddress,l);if(!t)throw Error("No native token");const s=o.map(h=>h.quote.nativeFee),{userDepositedUtxos:u}=await z.hinkalDepositOnChainUtxos(e,t,s,m,T,n);c=u}const R=o.map((t,s)=>({...t,utxo:f[s].utxo,nativeUtxo:A?c[s]?.utxo:void 0}));return await pe(e,q,R,a,n,w,v,E),y};exports.hinkalDepositAndBridge=qe;
@@ -1,20 +1,20 @@
1
- import { zeroAddress as f } from "../../constants/protocol.constants.mjs";
1
+ import { zeroAddress as u } from "../../constants/protocol.constants.mjs";
2
2
  import { transactionErrorCodes as X } from "../../error-handling/error-codes.constants.mjs";
3
3
  import { constructEmporiumProof as tt } from "../../functions/snarkjs/constructEmporiumProof.mjs";
4
4
  import { transactCallRelayerBatch as et } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
5
5
  import { ExternalActionId as S } from "../../types/external-action.types.mjs";
6
- import { Utxo as K } from "../utxo/Utxo.mjs";
6
+ import { Utxo as N } from "../utxo/Utxo.mjs";
7
7
  import "../../types/circom-data.types.mjs";
8
8
  import { ContractType as ot } from "../../types/ethereum-network.types.mjs";
9
9
  import "../../types/activities.types.mjs";
10
- import { DepositAndWithdrawPhase as N } from "../../types/scheduled-transactions.types.mjs";
10
+ import { DepositAndWithdrawPhase as W } from "../../types/scheduled-transactions.types.mjs";
11
11
  import { getSignatureDataForTransact as rt } from "../../functions/pre-transaction/getSignatureDataForTransact.mjs";
12
12
  import { shouldPatchAccessTokenMerkleTree as st } from "../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.mjs";
13
13
  import { getCurrentTimeInSeconds as it } from "../../functions/utils/time.utils.mjs";
14
- import { getFeeStructure as nt } from "../../functions/pre-transaction/getFeeStructure.mjs";
15
- import { hashEthereumAddress as at } from "../../functions/utils/addresses.mjs";
14
+ import { getFeeStructure as at } from "../../functions/pre-transaction/getFeeStructure.mjs";
15
+ import { hashEthereumAddress as nt } from "../../functions/utils/addresses.mjs";
16
16
  import { networkRegistry as mt } from "../../constants/chains.constants.mjs";
17
- import { SWAP_ROUTER_ADDRESSES as H } from "../../constants/addresses.constants.mjs";
17
+ import { SWAP_ROUTER_ADDRESSES as O } from "../../constants/addresses.constants.mjs";
18
18
  import "idb-keyval";
19
19
  import "@solana/web3.js";
20
20
  import "../http/HttpClient.mjs";
@@ -24,7 +24,7 @@ import { getERC20Token as pt } from "../../functions/utils/erc20tokenFunctions.m
24
24
  import "../../functions/utils/convertIntegrationProviderToExternalActionId.mjs";
25
25
  import "../../constants/server.constants.mjs";
26
26
  import "axios";
27
- import { caseInsensitiveEqual as O } from "../../functions/utils/caseInsensitive.utils.mjs";
27
+ import { caseInsensitiveEqual as z } from "../../functions/utils/caseInsensitive.utils.mjs";
28
28
  import "../../API/getServerURL.mjs";
29
29
  import "circomlibjs-hinkal-fork";
30
30
  import "libsodium-wrappers";
@@ -50,55 +50,55 @@ import { convertEmporiumOpToCallInfo as ct } from "../../functions/utils/convert
50
50
  import "multiformats";
51
51
  import { API as dt } from "../../API/API.mjs";
52
52
  import "../../API/tenderly.api.mjs";
53
- import { hinkalDepositOnChainUtxos as W } from "./hinkalDepositOnChainUtxos.mjs";
54
- import { createLifiBridgeOps as z } from "../../functions/private-wallet/emporium.helpers.mjs";
53
+ import { hinkalDepositOnChainUtxos as H } from "./hinkalDepositOnChainUtxos.mjs";
54
+ import { createLifiBridgeOps as B } from "../../functions/private-wallet/emporium.helpers.mjs";
55
55
  import { safeUpdateDepositAndWithdrawStatus as _ } from "../../API/deposit-and-withdraw-status-calls.mjs";
56
- const ut = async (t, A, r, R, n, T, c, d) => {
57
- if (r.length === 0)
56
+ const ut = async (t, f, s, R, a, T, c, d) => {
57
+ if (s.length === 0)
58
58
  throw new Error("No recipients to bridge");
59
- const i = A.erc20TokenAddress, o = t.getCurrentChainId(), { contractData: a } = mt[o], { emporiumAddress: w } = a;
59
+ const i = f.erc20TokenAddress, o = t.getCurrentChainId(), { contractData: n } = mt[o], { emporiumAddress: w } = n;
60
60
  if (!w)
61
61
  throw Error("No Emporium Address");
62
- const C = H[S.Lifi][o];
62
+ const C = O[S.Lifi][o];
63
63
  if (!C)
64
64
  throw new Error(`LIFI not configured for chain ${o}`);
65
- const l = await t.getRandomRelay();
66
- if (!l)
65
+ const A = await t.getRandomRelay();
66
+ if (!A)
67
67
  throw Error(X.RELAYER_NOT_AVAILABLE);
68
- const D = await t.getEthereumAddress(), h = it().toString(), v = t.generateProofRemotely ? 5 : 1, y = [];
69
- for (let u = 0; u < r.length; u += v) {
70
- const e = r.slice(u, u + v), s = await Promise.all(
71
- e.map(async ({ utxo: m, nativeUtxo: p, bridgeAmount: B, quote: x, temporarySubAccount: I }) => {
72
- await dt.addTemporaryWalletNonce(o, n, I.index);
73
- const q = x.nativeFee > 0n && !O(i, f), E = [i], U = [-m.amount], k = [!1], P = new K({
68
+ const D = await t.getEthereumAddress(), l = it().toString(), E = t.generateProofRemotely ? 5 : 1, v = [];
69
+ for (let m = 0; m < s.length; m += E) {
70
+ const I = s.slice(m, m + E), e = await Promise.all(
71
+ I.map(async ({ utxo: r, nativeUtxo: p, bridgeAmount: h, quote: U, temporarySubAccount: x }) => {
72
+ await dt.addTemporaryWalletNonce(o, a, x.index);
73
+ const q = U.nativeFee > 0n && !z(i, u), g = [i], k = [-r.amount], P = [!1], L = new N({
74
74
  amount: 0n,
75
75
  erc20TokenAddress: i,
76
76
  shieldedPrivateKey: t.userKeys.getShieldedPrivateKey(),
77
- timeStamp: h,
77
+ timeStamp: l,
78
78
  tokenId: 0
79
- }), F = [[m, P]], L = [[P]];
79
+ }), F = [[r, L]], b = [[L]];
80
80
  if (q && p) {
81
- const b = new K({
81
+ const K = new N({
82
82
  amount: 0n,
83
- erc20TokenAddress: f,
83
+ erc20TokenAddress: u,
84
84
  shieldedPrivateKey: t.userKeys.getShieldedPrivateKey(),
85
- timeStamp: h,
85
+ timeStamp: l,
86
86
  tokenId: 0
87
87
  });
88
- E.push(f), U.push(-p.amount), k.push(!1), F.push([p, b]), L.push([b]);
88
+ g.push(u), k.push(-p.amount), P.push(!1), F.push([p, K]), b.push([K]);
89
89
  }
90
- const M = z(
90
+ const M = B(
91
91
  t,
92
- I.ethAddress,
92
+ x.ethAddress,
93
93
  C,
94
94
  i,
95
- m.amount,
96
- B,
97
- x
95
+ r.amount,
96
+ h,
97
+ U
98
98
  ), { patchAccessTokenMerkleTree: V, kycRequired: Y, hasAccessToken: Z } = await st(
99
99
  t,
100
- E,
101
- U
100
+ g,
101
+ k
102
102
  ), $ = await rt(
103
103
  o,
104
104
  D,
@@ -109,21 +109,21 @@ const ut = async (t, A, r, R, n, T, c, d) => {
109
109
  "v1x1",
110
110
  t.merkleTreeHinkal,
111
111
  t.merkleTreeAccessToken,
112
- E,
113
- E.map(() => 0),
112
+ g,
113
+ g.map(() => 0),
114
114
  F,
115
- L,
115
+ b,
116
116
  t.userKeys,
117
- E.length,
117
+ g.length,
118
118
  F[0].length,
119
119
  w,
120
120
  M,
121
121
  t.generateProofRemotely,
122
- l ?? f,
122
+ A ?? u,
123
123
  o,
124
- k,
124
+ P,
125
125
  void 0,
126
- I.privateKey,
126
+ x.privateKey,
127
127
  void 0,
128
128
  V,
129
129
  void 0,
@@ -136,35 +136,35 @@ const ut = async (t, A, r, R, n, T, c, d) => {
136
136
  return { zkCallData: j, dimData: J, circomData: G, authorizationData: Q };
137
137
  })
138
138
  );
139
- y.push(...s);
139
+ v.push(...e);
140
140
  }
141
141
  await _(o, {
142
142
  id: T,
143
- hashedEthereumAddress: n,
144
- phase: N.BEFORE_SCHEDULE_WITHDRAW
143
+ hashedEthereumAddress: a,
144
+ phase: W.BEFORE_SCHEDULE_WITHDRAW
145
145
  });
146
- const g = await et(
146
+ const y = await et(
147
147
  o,
148
- y,
149
- n,
148
+ v,
149
+ a,
150
150
  c,
151
151
  d
152
152
  );
153
153
  return await _(o, {
154
154
  id: T,
155
- hashedEthereumAddress: n,
156
- phase: N.AFTER_SCHEDULE_WITHDRAW,
157
- scheduleId: g
158
- }), g;
159
- }, Ae = async (t, A, r, R, n, T) => {
160
- const c = A.erc20TokenAddress, d = t.getCurrentChainId(), i = at(await t.getEthereumAddress()), o = H[S.Lifi][d];
155
+ hashedEthereumAddress: a,
156
+ phase: W.AFTER_SCHEDULE_WITHDRAW,
157
+ scheduleId: y
158
+ }), y;
159
+ }, Ae = async (t, f, s, R, a, T) => {
160
+ const c = f.erc20TokenAddress, d = t.getCurrentChainId(), i = nt(await t.getEthereumAddress()), o = O[S.Lifi][d];
161
161
  if (!o)
162
162
  throw Error("LIFI router not configured");
163
- let a;
164
- if (n)
165
- a = n;
163
+ let n;
164
+ if (a)
165
+ n = a;
166
166
  else {
167
- const e = r[0], m = z(
167
+ const e = s[0], p = B(
168
168
  t,
169
169
  e.temporarySubAccount.ethAddress,
170
170
  o,
@@ -173,52 +173,56 @@ const ut = async (t, A, r, R, n, T, c, d) => {
173
173
  e.bridgeAmount,
174
174
  e.quote
175
175
  ).map(
176
- (p) => ct(p, e.temporarySubAccount.ethAddress, d)
176
+ (h) => ct(h, e.temporarySubAccount.ethAddress, d)
177
177
  );
178
- a = await nt(d, c, [c], S.Emporium, m);
178
+ n = await at(d, c, [c], S.Emporium, p);
179
179
  }
180
180
  const w = {
181
- feeToken: a.feeToken,
181
+ feeToken: n.feeToken,
182
182
  flatFee: 0n,
183
183
  variableRate: 0n
184
- }, l = r.reduce((e, s) => e + s.quote.nativeFee, 0n) > 0n && !O(c, f), D = r.map((e) => e.bridgeAmount), h = r.map((e) => e.recipientAddress), { userDepositedUtxos: v, statusId: y } = await W(
184
+ }, A = s.reduce((e, r) => e + r.quote.nativeFee, 0n) > 0n && !z(c, u), D = s.map((e) => e.bridgeAmount), l = s.map((e) => e.recipientAddress), {
185
+ userDepositedUtxos: E,
186
+ statusId: v,
187
+ depositTxHash: y
188
+ } = await H(
185
189
  t,
186
- A,
190
+ f,
187
191
  D,
188
- h,
189
- a,
192
+ l,
193
+ n,
190
194
  i
191
195
  );
192
- let g = [];
193
- if (l) {
194
- const e = pt(f, d);
196
+ let m = [];
197
+ if (A) {
198
+ const e = pt(u, d);
195
199
  if (!e)
196
200
  throw Error("No native token");
197
- const s = r.map((p) => p.quote.nativeFee), { userDepositedUtxos: m } = await W(
201
+ const r = s.map((h) => h.quote.nativeFee), { userDepositedUtxos: p } = await H(
198
202
  t,
199
203
  e,
200
- s,
201
- h,
204
+ r,
205
+ l,
202
206
  w,
203
207
  i
204
208
  );
205
- g = m;
209
+ m = p;
206
210
  }
207
- const u = r.map((e, s) => ({
211
+ const I = s.map((e, r) => ({
208
212
  ...e,
209
- utxo: v[s].utxo,
210
- nativeUtxo: l ? g[s]?.utxo : void 0
213
+ utxo: E[r].utxo,
214
+ nativeUtxo: A ? m[r]?.utxo : void 0
211
215
  }));
212
- return ut(
216
+ return await ut(
213
217
  t,
214
- A,
215
- u,
216
- a,
218
+ f,
219
+ I,
220
+ n,
217
221
  i,
218
- y,
222
+ v,
219
223
  R,
220
224
  T
221
- );
225
+ ), y;
222
226
  };
223
227
  export {
224
228
  Ae as hinkalDepositAndBridge
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("../../functions/web3/etherFunctions.cjs"),z=require("../utxo/Utxo.cjs"),Y=require("../../error-handling/error-codes.constants.cjs");require("idb-keyval");const j=require("../../constants/chains.constants.cjs"),G=require("ethers");require("../crypto-keys/keys.cjs");require("node-forge");require("../../constants/vite.constants.cjs");require("libsodium-wrappers");require("../http/HttpClient.cjs");require("axios");const $=require("../../functions/utils/solanaMint.utils.cjs"),N=require("@solana/web3.js"),J=require("../../functions/utils/addresses.cjs");require("../../constants/server.constants.cjs");require("../../constants/token-data/index.cjs");const _=require("../../constants/protocol.constants.cjs"),Q=require("../../API/API.cjs");require("../../functions/utils/mutexes.utils.cjs");require("../../types/circom-data.types.cjs");const ee=require("../../types/external-action.types.cjs");require("../../types/activities.types.cjs");const B=require("../../types/scheduled-transactions.types.cjs");require("../../functions/web3/events/getApprovedBalance.cjs");require("../../constants/contracts.constants.cjs");require("../../constants/kyc.constants.cjs");require("../../constants/coingecko.constants.cjs");require("../../constants/reorg-depths.constants.cjs");require("../../constants/addresses.constants.cjs");require("../../constants/token.limits.constants.cjs");require("../../constants/presale.constants.cjs");require("../../constants/activity.constants.cjs");require("../../constants/tasks.constants.cjs");require("../../constants/events.constants.cjs");require("../../functions/utils/convertIntegrationProviderToExternalActionId.cjs");require("../../API/getServerURL.cjs");require("circomlibjs-hinkal-fork");require("process");require("buffer");require("../../constants/save-depths.cjs");const te=require("@coral-xyz/anchor"),E=require("../../functions/pre-transaction/solana.cjs");require("@solana/spl-token");require("../../functions/utils/userAgent.cjs");const re=require("../../functions/utils/time.utils.cjs");require("multiformats");require("../../API/tenderly.api.cjs");const oe=require("../../functions/utils/fees.utils.cjs");require("../../functions/web3/getTokenHolder.cjs");const ne=require("../../functions/web3/signAndSendSerializedTransaction.cjs"),Z=require("../../functions/snarkjs/common.snarkjs.cjs"),ae=require("./hinkalCheckSolanaTokenRegistry.cjs"),se=require("../../functions/utils/getUtxosFromReceiptSolana.cjs"),ie=require("../../functions/snarkjs/constructSolanaZkProof.cjs"),ce=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),ue=require("../../functions/pre-transaction/getFeeStructure.cjs"),W=require("../../API/deposit-and-withdraw-status-calls.cjs"),de=async(e,r,d,l,g,h)=>{const p=d.map(t=>t+oe.calculateTotalFee(t,g)),{hinkalIdl:m,hinkalAddress:q,originalDeployer:i}=j.networkRegistry[e.getCurrentChainId()].contractData;if(!m)throw new Error("No IDL configured for Solana program on this network");if(!i)throw new Error("missing original deployer");const w=e.userKeys.getShieldedPrivateKey(),P=z.Utxo.findCorrectRandomization(M.randomBigInt(31),w),S=Z.calcStealthAddressStructure(P,w),o=e.getSolanaProgram(m),b=e.getSolanaPublicKey(),n=new N.PublicKey(i),A=new N.PublicKey(q),{mintPublicKey:c}=$.formatMintAddress(r),D=c.toString(),O=E.getStorageAccountPublicKey(A,n),R=E.getStorageVaultPublicKey(A,n),F=E.getMerkleAccountPublicKey(A,n),v=E.buildAnchorStealthAddressStructure(S),f=e.getCurrentChainId(),x=p.reduce((t,s)=>t+s,0n),I=await ae.hinkalCheckSolanaTokenRegistry(o,new N.PublicKey(n),[r],[x]),K=p.map(t=>`${t}`);let a="";const T=(await W.updateDepositAndWithdrawStatus(f,{hashedEthereumAddress:h,phase:B.DepositAndWithdrawPhase.BEFORE_DEPOSIT})).id??void 0;if(I){const{serializedTransaction:t,blockhash:s,lastValidBlockHeight:y}=await Q.API.generateMultiPaymentDepositLimitless(f,{amounts:K,payer:e.getSolanaPublicKey().toBase58(),ethereumAddress:await e.getEthereumAddress(),mint:r,stealthAddressStructure:v}),{wallet:u}=o.provider;if(!u)throw new Error("missing wallet");a=await ne.signAndSendSerializedTransaction(o.provider,t,s,y)}else{const t=E.getTokenLimitStorageAccountPublicKey(o.programId,n,c),s=D===_.solanaNativeAddress?null:c,y=D===_.solanaNativeAddress?null:void 0;a=await o.methods.multiPaymentDeposit(K.map(L=>new te.BN(L)),v).accounts({mint:s,signer:b,signerAta:y,originalDeployer:n,storageAccount:O,storageVault:R,merkleAccount:F,tokenLimitStorage:t,storageVaultAta:y,accessTokenOwner:null}).rpc();const u=await o.provider.connection.getLatestBlockhash();await o.provider.connection.confirmTransaction({blockhash:u.blockhash,lastValidBlockHeight:u.lastValidBlockHeight,signature:a},"confirmed")}const k=await o.provider.connection.getTransaction(a,{commitment:"confirmed",maxSupportedTransactionVersion:0});if(!k)throw new Error("Transaction missing");await W.safeUpdateDepositAndWithdrawStatus(f,{id:T,hashedEthereumAddress:h,phase:B.DepositAndWithdrawPhase.AFTER_DEPOSIT,depositTxHash:a});const H=se.getUtxosFromReceiptSolana(k,o,e.userKeys),U=[],C=[...H];return l.forEach((t,s)=>{const y=p[s],u=C.find(X=>X.amount===y);if(!u)throw new Error(`Could not find newly created UTXO with amount ${y} for recipient ${t}.`);U.push({recipientAddress:t,utxo:u});const L=C.indexOf(u);C.splice(L,1)}),{userDepositedUtxos:U,signature:a,statusId:T}},le=async(e,r,d,l,g,h,p,m)=>{const q=e.getCurrentChainId();if(d.length===0)throw new Error("userDepositedUtxos must not be empty");const{hinkalIdl:i,originalDeployer:w}=j.networkRegistry[e.getCurrentChainId()].contractData;if(!w||!i)throw new Error("missing data");const P=e.getSolanaProgram(i),S=await e.getRandomRelay(!0);if(!S)throw new Error(Y.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const o=re.getCurrentTimeInSeconds().toString(),b=e.generateProofRemotely?5:1,n=[];for(let c=0;c<d.length;c+=b){const D=d.slice(c,c+b),O=await Promise.all(D.map(async({recipientAddress:R,utxo:F})=>{const{compressedAddress:v}=$.formatMintAddress(_.solanaNativeAddress),f=new z.Utxo({amount:0n,mintAddress:r,erc20TokenAddress:v,shieldedPrivateKey:e.userKeys.getShieldedPrivateKey(),timeStamp:o,tokenId:0}),x=[F,f],I=[f],K=z.Utxo.findCorrectRandomization(M.randomBigInt(31),e.userKeys.getShieldedPrivateKey()),a={tokenNumber:1,nullifierAmount:x.length,outputAmount:I.length},V=Z.calcEncryptedOutputs([I])[0][0],T=Array.from(G.ethers.getBytes(V)),{proofAArr:k,proofBArr:H,proofCArr:U,publicInputsArr:C}=await ie.constructSolanaZkProof(e.generateProofRemotely,w,e.merkleTreeHinkal,e.merkleTreeAccessToken,e.userKeys,P,[r],[x],[I],K,l.flatFee,l.variableRate,R,S,a,[T],e.getCurrentChainId(),void 0,void 0,void 0,void 0,void 0,!1),t=r===_.solanaNativeAddress,s={recipient:R,mint:t?void 0:r};return{relayAddress:S,functionName:"transact",args:{proofAArr:k,proofBArr:H,proofCArr:U,publicInputsArr:C,encryptedOutputs:[T],relayerFee:l.flatFee.toString(),dimensions:a},accounts:s}}));n.push(...O)}await W.safeUpdateDepositAndWithdrawStatus(q,{id:h,hashedEthereumAddress:g,phase:B.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});const A=await ce.solanaTransactCallRelayerBatch(e.getCurrentChainId(),n,g,p,m);return await W.safeUpdateDepositAndWithdrawStatus(q,{id:h,hashedEthereumAddress:g,phase:B.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:A}),A},ge=async(e,r,d,l,g,h,p)=>{const m=J.hashEthereumAddress(await e.getEthereumAddress()),q=e.getCurrentChainId(),i=h??await ue.getFeeStructure(q,r,[r],ee.ExternalActionId.Transact,[],0n),{userDepositedUtxos:w,statusId:P}=await de(e,r,d,l,i,m);return await le(e,r,w,i,m,P,g,p)};exports.hinkalSolanaDepositAndWithdraw=ge;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("../../functions/web3/etherFunctions.cjs"),z=require("../utxo/Utxo.cjs"),Y=require("../../error-handling/error-codes.constants.cjs");require("idb-keyval");const j=require("../../constants/chains.constants.cjs"),G=require("ethers");require("../crypto-keys/keys.cjs");require("node-forge");require("../../constants/vite.constants.cjs");require("libsodium-wrappers");require("../http/HttpClient.cjs");require("axios");const $=require("../../functions/utils/solanaMint.utils.cjs"),N=require("@solana/web3.js"),J=require("../../functions/utils/addresses.cjs");require("../../constants/server.constants.cjs");require("../../constants/token-data/index.cjs");const _=require("../../constants/protocol.constants.cjs"),Q=require("../../API/API.cjs");require("../../functions/utils/mutexes.utils.cjs");require("../../types/circom-data.types.cjs");const ee=require("../../types/external-action.types.cjs");require("../../types/activities.types.cjs");const B=require("../../types/scheduled-transactions.types.cjs");require("../../functions/web3/events/getApprovedBalance.cjs");require("../../constants/contracts.constants.cjs");require("../../constants/kyc.constants.cjs");require("../../constants/coingecko.constants.cjs");require("../../constants/reorg-depths.constants.cjs");require("../../constants/addresses.constants.cjs");require("../../constants/token.limits.constants.cjs");require("../../constants/presale.constants.cjs");require("../../constants/activity.constants.cjs");require("../../constants/tasks.constants.cjs");require("../../constants/events.constants.cjs");require("../../functions/utils/convertIntegrationProviderToExternalActionId.cjs");require("../../API/getServerURL.cjs");require("circomlibjs-hinkal-fork");require("process");require("buffer");require("../../constants/save-depths.cjs");const te=require("@coral-xyz/anchor"),E=require("../../functions/pre-transaction/solana.cjs");require("@solana/spl-token");require("../../functions/utils/userAgent.cjs");const re=require("../../functions/utils/time.utils.cjs");require("multiformats");require("../../API/tenderly.api.cjs");const oe=require("../../functions/utils/fees.utils.cjs");require("../../functions/web3/getTokenHolder.cjs");const ne=require("../../functions/web3/signAndSendSerializedTransaction.cjs"),Z=require("../../functions/snarkjs/common.snarkjs.cjs"),ae=require("./hinkalCheckSolanaTokenRegistry.cjs"),se=require("../../functions/utils/getUtxosFromReceiptSolana.cjs"),ie=require("../../functions/snarkjs/constructSolanaZkProof.cjs"),ce=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),ue=require("../../functions/pre-transaction/getFeeStructure.cjs"),W=require("../../API/deposit-and-withdraw-status-calls.cjs"),de=async(e,r,d,l,g,p)=>{const h=d.map(t=>t+oe.calculateTotalFee(t,g)),{hinkalIdl:m,hinkalAddress:S,originalDeployer:i}=j.networkRegistry[e.getCurrentChainId()].contractData;if(!m)throw new Error("No IDL configured for Solana program on this network");if(!i)throw new Error("missing original deployer");const w=e.userKeys.getShieldedPrivateKey(),P=z.Utxo.findCorrectRandomization(M.randomBigInt(31),w),y=Z.calcStealthAddressStructure(P,w),o=e.getSolanaProgram(m),b=e.getSolanaPublicKey(),n=new N.PublicKey(i),A=new N.PublicKey(S),{mintPublicKey:c}=$.formatMintAddress(r),x=c.toString(),O=E.getStorageAccountPublicKey(A,n),D=E.getStorageVaultPublicKey(A,n),F=E.getMerkleAccountPublicKey(A,n),R=E.buildAnchorStealthAddressStructure(y),f=e.getCurrentChainId(),v=h.reduce((t,s)=>t+s,0n),T=await ae.hinkalCheckSolanaTokenRegistry(o,new N.PublicKey(n),[r],[v]),K=h.map(t=>`${t}`);let a="";const I=(await W.updateDepositAndWithdrawStatus(f,{hashedEthereumAddress:p,phase:B.DepositAndWithdrawPhase.BEFORE_DEPOSIT})).id??void 0;if(T){const{serializedTransaction:t,blockhash:s,lastValidBlockHeight:q}=await Q.API.generateMultiPaymentDepositLimitless(f,{amounts:K,payer:e.getSolanaPublicKey().toBase58(),ethereumAddress:await e.getEthereumAddress(),mint:r,stealthAddressStructure:R}),{wallet:u}=o.provider;if(!u)throw new Error("missing wallet");a=await ne.signAndSendSerializedTransaction(o.provider,t,s,q)}else{const t=E.getTokenLimitStorageAccountPublicKey(o.programId,n,c),s=x===_.solanaNativeAddress?null:c,q=x===_.solanaNativeAddress?null:void 0;a=await o.methods.multiPaymentDeposit(K.map(L=>new te.BN(L)),R).accounts({mint:s,signer:b,signerAta:q,originalDeployer:n,storageAccount:O,storageVault:D,merkleAccount:F,tokenLimitStorage:t,storageVaultAta:q,accessTokenOwner:null}).rpc();const u=await o.provider.connection.getLatestBlockhash();await o.provider.connection.confirmTransaction({blockhash:u.blockhash,lastValidBlockHeight:u.lastValidBlockHeight,signature:a},"confirmed")}const k=await o.provider.connection.getTransaction(a,{commitment:"confirmed",maxSupportedTransactionVersion:0});if(!k)throw new Error("Transaction missing");await W.safeUpdateDepositAndWithdrawStatus(f,{id:I,hashedEthereumAddress:p,phase:B.DepositAndWithdrawPhase.AFTER_DEPOSIT,depositTxHash:a});const H=se.getUtxosFromReceiptSolana(k,o,e.userKeys),U=[],C=[...H];return l.forEach((t,s)=>{const q=h[s],u=C.find(X=>X.amount===q);if(!u)throw new Error(`Could not find newly created UTXO with amount ${q} for recipient ${t}.`);U.push({recipientAddress:t,utxo:u});const L=C.indexOf(u);C.splice(L,1)}),{userDepositedUtxos:U,depositTxHash:a,statusId:I}},le=async(e,r,d,l,g,p,h,m)=>{const S=e.getCurrentChainId();if(d.length===0)throw new Error("userDepositedUtxos must not be empty");const{hinkalIdl:i,originalDeployer:w}=j.networkRegistry[e.getCurrentChainId()].contractData;if(!w||!i)throw new Error("missing data");const P=e.getSolanaProgram(i),y=await e.getRandomRelay(!0);if(!y)throw new Error(Y.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const o=re.getCurrentTimeInSeconds().toString(),b=e.generateProofRemotely?5:1,n=[];for(let c=0;c<d.length;c+=b){const x=d.slice(c,c+b),O=await Promise.all(x.map(async({recipientAddress:D,utxo:F})=>{const{compressedAddress:R}=$.formatMintAddress(_.solanaNativeAddress),f=new z.Utxo({amount:0n,mintAddress:r,erc20TokenAddress:R,shieldedPrivateKey:e.userKeys.getShieldedPrivateKey(),timeStamp:o,tokenId:0}),v=[F,f],T=[f],K=z.Utxo.findCorrectRandomization(M.randomBigInt(31),e.userKeys.getShieldedPrivateKey()),a={tokenNumber:1,nullifierAmount:v.length,outputAmount:T.length},V=Z.calcEncryptedOutputs([T])[0][0],I=Array.from(G.ethers.getBytes(V)),{proofAArr:k,proofBArr:H,proofCArr:U,publicInputsArr:C}=await ie.constructSolanaZkProof(e.generateProofRemotely,w,e.merkleTreeHinkal,e.merkleTreeAccessToken,e.userKeys,P,[r],[v],[T],K,l.flatFee,l.variableRate,D,y,a,[I],e.getCurrentChainId(),void 0,void 0,void 0,void 0,void 0,!1),t=r===_.solanaNativeAddress,s={recipient:D,mint:t?void 0:r};return{relayAddress:y,functionName:"transact",args:{proofAArr:k,proofBArr:H,proofCArr:U,publicInputsArr:C,encryptedOutputs:[I],relayerFee:l.flatFee.toString(),dimensions:a},accounts:s}}));n.push(...O)}await W.safeUpdateDepositAndWithdrawStatus(S,{id:p,hashedEthereumAddress:g,phase:B.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});const A=await ce.solanaTransactCallRelayerBatch(e.getCurrentChainId(),n,g,h,m);return await W.safeUpdateDepositAndWithdrawStatus(S,{id:p,hashedEthereumAddress:g,phase:B.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:A}),A},ge=async(e,r,d,l,g,p,h)=>{const m=J.hashEthereumAddress(await e.getEthereumAddress()),S=e.getCurrentChainId(),i=p??await ue.getFeeStructure(S,r,[r],ee.ExternalActionId.Transact,[],0n),{userDepositedUtxos:w,statusId:P,depositTxHash:y}=await de(e,r,d,l,i,m);return await le(e,r,w,i,m,P,g,h),y};exports.hinkalSolanaDepositAndWithdraw=ge;