@hinkal/common 0.2.23 → 0.2.24

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("../../constants/protocol.constants.cjs"),F=require("../../error-handling/error-codes.constants.cjs"),O=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),K=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),L=require("../../types/external-action.types.cjs"),z=require("../utxo/Utxo.cjs");require("../../types/circom-data.types.cjs");const B=require("../../types/ethereum-network.types.cjs"),N=require("../../types/admin.types.cjs");require("../../types/activities.types.cjs");const D=require("../../types/scheduled-transactions.types.cjs"),Z=require("../../functions/pre-transaction/getSignatureDataForTransact.cjs"),j=require("../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs"),G=require("../../functions/utils/time.utils.cjs"),V=require("../../functions/pre-transaction/getFeeStructure.cjs"),Y=require("../../functions/utils/addresses.cjs"),$=require("./hinkalDepositOnChainUtxos.cjs"),J=require("../../functions/pre-transaction/constructAdminData.cjs"),q=require("../../API/deposit-and-withdraw-status-calls.cjs"),Q=async(e,t,r,h,s,c,A,i)=>{if(r.length===0)throw new Error("userDepositedUtxos must not be empty");const a=t.erc20TokenAddress,n=await e.getRandomRelay();if(!n)throw Error(F.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const o=await e.getEthereumAddress(),w=G.getCurrentTimeInSeconds().toString(),d=e.generateProofRemotely?5:1,p=[];for(let u=0;u<r.length;u+=d){const x=r.slice(u,u+d),S=await Promise.all(x.map(async({recipientAddress:I,utxo:l})=>{const E=[-l.amount],y=new z.Utxo({amount:0n,erc20TokenAddress:a,shieldedPrivateKey:e.userKeys.getShieldedPrivateKey(),timeStamp:w,tokenId:0}),T=[[l,y]],R=[[y]],P=`swapperM1x${T[0].length}x1`,m={externalActionId:0n,externalAddress:I,externalActionMetadata:"0x00"},{patchAccessTokenMerkleTree:_,kycRequired:f,hasAccessToken:U}=await j.shouldPatchAccessTokenMerkleTree(e,[a],E),W=await Z.getSignatureDataForTransact(e.getCurrentChainId(),o,e.userKeys,f,U),k=J.constructAdminData(N.AdminTransactionType.WithdrawOnChainUtxos,e.getCurrentChainId(),[a],[-l.amount],o),{zkCallData:v,circomData:H,dimData:M}=await O.constructZkProof("v1x1",e.merkleTreeHinkal,e.merkleTreeAccessToken,T,R,e.userKeys,P,m.externalActionId,m.externalAddress,m.externalActionMetadata,e.generateProofRemotely,n??b.zeroAddress,e.getCurrentChainId(),void 0,void 0,void 0,_,void 0,void 0,h,e.getContractWithFetcher(B.ContractType.HinkalHelperContract),W,void 0,!1);return{zkCallData:v,dimData:M,circomData:H,adminData:k}}));p.push(...S)}const C=e.getCurrentChainId();await q.safeUpdateDepositAndWithdrawStatus(C,{id:c,hashedEthereumAddress:s,phase:D.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});const g=await K.transactCallRelayerBatch(e.getCurrentChainId(),p,s,A,i);return await q.safeUpdateDepositAndWithdrawStatus(C,{id:c,hashedEthereumAddress:s,phase:D.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:g}),g},X=async(e,t,r,h,s,c,A)=>{const i=t.erc20TokenAddress,a=e.getCurrentChainId(),n=Y.hashEthereumAddress(await e.getEthereumAddress()),o=c??await V.getFeeStructure(a,i,[i],L.ExternalActionId.Transact),{userDepositedUtxos:w,statusId:d}=await $.hinkalDepositOnChainUtxos(e,t,r,h,o,n);return Q(e,t,w,o,n,d,s,A)};exports.hinkalDepositAndWithdraw=X;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("../../constants/protocol.constants.cjs"),F=require("../../error-handling/error-codes.constants.cjs"),O=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),K=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),L=require("../../types/external-action.types.cjs"),z=require("../utxo/Utxo.cjs");require("../../types/circom-data.types.cjs");const B=require("../../types/ethereum-network.types.cjs"),N=require("../../types/admin.types.cjs");require("../../types/activities.types.cjs");const D=require("../../types/scheduled-transactions.types.cjs"),Z=require("../../functions/pre-transaction/getSignatureDataForTransact.cjs"),j=require("../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs"),G=require("../../functions/utils/time.utils.cjs"),V=require("../../functions/pre-transaction/getFeeStructure.cjs"),Y=require("../../functions/utils/addresses.cjs"),$=require("./hinkalDepositOnChainUtxos.cjs"),J=require("../../functions/pre-transaction/constructAdminData.cjs"),q=require("../../API/deposit-and-withdraw-status-calls.cjs"),Q=async(e,t,r,w,a,c,A,i)=>{if(r.length===0)throw new Error("userDepositedUtxos must not be empty");const s=t.erc20TokenAddress,n=await e.getRandomRelay();if(!n)throw Error(F.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const o=await e.getEthereumAddress(),l=G.getCurrentTimeInSeconds().toString(),d=e.generateProofRemotely?5:1,u=[];for(let h=0;h<r.length;h+=d){const x=r.slice(h,h+d),S=await Promise.all(x.map(async({recipientAddress:I,utxo:p})=>{const E=[-p.amount],T=new z.Utxo({amount:0n,erc20TokenAddress:s,shieldedPrivateKey:e.userKeys.getShieldedPrivateKey(),timeStamp:l,tokenId:0}),y=[[p,T]],R=[[T]],P=`swapperM1x${y[0].length}x1`,m={externalActionId:0n,externalAddress:I,externalActionMetadata:"0x00"},{patchAccessTokenMerkleTree:_,kycRequired:f,hasAccessToken:U}=await j.shouldPatchAccessTokenMerkleTree(e,[s],E),W=await Z.getSignatureDataForTransact(e.getCurrentChainId(),o,e.userKeys,f,U),k=J.constructAdminData(N.AdminTransactionType.WithdrawOnChainUtxos,e.getCurrentChainId(),[s],[-p.amount],o),{zkCallData:v,circomData:H,dimData:M}=await O.constructZkProof("v1x1",e.merkleTreeHinkal,e.merkleTreeAccessToken,y,R,e.userKeys,P,m.externalActionId,m.externalAddress,m.externalActionMetadata,e.generateProofRemotely,n??b.zeroAddress,e.getCurrentChainId(),void 0,void 0,void 0,_,void 0,void 0,w,e.getContractWithFetcher(B.ContractType.HinkalHelperContract),W,void 0,!1);return{zkCallData:v,dimData:M,circomData:H,adminData:k}}));u.push(...S)}const C=e.getCurrentChainId();await q.safeUpdateDepositAndWithdrawStatus(C,{id:c,hashedEthereumAddress:a,phase:D.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});const g=await K.transactCallRelayerBatch(e.getCurrentChainId(),u,a,A,i);return await q.safeUpdateDepositAndWithdrawStatus(C,{id:c,hashedEthereumAddress:a,phase:D.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:g}),g},X=async(e,t,r,w,a,c,A)=>{const i=t.erc20TokenAddress,s=e.getCurrentChainId(),n=Y.hashEthereumAddress(await e.getEthereumAddress()),o=c??await V.getFeeStructure(s,i,[i],L.ExternalActionId.Transact),{userDepositedUtxos:l,statusId:d,depositTxHash:u}=await $.hinkalDepositOnChainUtxos(e,t,r,w,o,n);return await Q(e,t,l,o,n,d,a,A),u};exports.hinkalDepositAndWithdraw=X;
@@ -17,36 +17,36 @@ import { hashEthereumAddress as j } from "../../functions/utils/addresses.mjs";
17
17
  import { hinkalDepositOnChainUtxos as G } from "./hinkalDepositOnChainUtxos.mjs";
18
18
  import { constructAdminData as J } from "../../functions/pre-transaction/constructAdminData.mjs";
19
19
  import { safeUpdateDepositAndWithdrawStatus as x } from "../../API/deposit-and-withdraw-status-calls.mjs";
20
- const Q = async (t, e, r, p, o, i, u, c) => {
20
+ const Q = async (t, e, r, u, o, i, w, c) => {
21
21
  if (r.length === 0)
22
22
  throw new Error("userDepositedUtxos must not be empty");
23
23
  const a = e.erc20TokenAddress, s = await t.getRandomRelay();
24
24
  if (!s)
25
25
  throw Error(F.RELAYER_NOT_AVAILABLE);
26
- const n = await t.getEthereumAddress(), w = Z().toString(), d = t.generateProofRemotely ? 5 : 1, f = [];
27
- for (let m = 0; m < r.length; m += d) {
28
- const I = r.slice(m, m + d), E = await Promise.all(
26
+ const n = await t.getEthereumAddress(), h = Z().toString(), d = t.generateProofRemotely ? 5 : 1, m = [];
27
+ for (let p = 0; p < r.length; p += d) {
28
+ const I = r.slice(p, p + d), E = await Promise.all(
29
29
  I.map(async ({ recipientAddress: D, utxo: A }) => {
30
30
  const R = [-A.amount], l = new B({
31
31
  amount: 0n,
32
32
  erc20TokenAddress: a,
33
33
  shieldedPrivateKey: t.userKeys.getShieldedPrivateKey(),
34
- timeStamp: w,
34
+ timeStamp: h,
35
35
  tokenId: 0
36
- }), T = [[A, l]], S = [[l]], v = `swapperM1x${T[0].length}x1`, h = {
36
+ }), T = [[A, l]], S = [[l]], v = `swapperM1x${T[0].length}x1`, f = {
37
37
  externalActionId: 0n,
38
38
  externalAddress: D,
39
39
  externalActionMetadata: "0x00"
40
40
  }, {
41
- patchAccessTokenMerkleTree: P,
42
- kycRequired: U,
43
- hasAccessToken: H
41
+ patchAccessTokenMerkleTree: H,
42
+ kycRequired: P,
43
+ hasAccessToken: U
44
44
  } = await Y(t, [a], R), W = await V(
45
45
  t.getCurrentChainId(),
46
46
  n,
47
47
  t.userKeys,
48
- U,
49
- H
48
+ P,
49
+ U
50
50
  ), K = J(
51
51
  N.WithdrawOnChainUtxos,
52
52
  t.getCurrentChainId(),
@@ -61,19 +61,19 @@ const Q = async (t, e, r, p, o, i, u, c) => {
61
61
  S,
62
62
  t.userKeys,
63
63
  v,
64
- h.externalActionId,
65
- h.externalAddress,
66
- h.externalActionMetadata,
64
+ f.externalActionId,
65
+ f.externalAddress,
66
+ f.externalActionMetadata,
67
67
  t.generateProofRemotely,
68
68
  s ?? k,
69
69
  t.getCurrentChainId(),
70
70
  void 0,
71
71
  void 0,
72
72
  void 0,
73
- P,
73
+ H,
74
74
  void 0,
75
75
  void 0,
76
- p,
76
+ u,
77
77
  t.getContractWithFetcher(q.HinkalHelperContract),
78
78
  W,
79
79
  void 0,
@@ -87,7 +87,7 @@ const Q = async (t, e, r, p, o, i, u, c) => {
87
87
  };
88
88
  })
89
89
  );
90
- f.push(...E);
90
+ m.push(...E);
91
91
  }
92
92
  const C = t.getCurrentChainId();
93
93
  await x(C, {
@@ -97,9 +97,9 @@ const Q = async (t, e, r, p, o, i, u, c) => {
97
97
  });
98
98
  const g = await O(
99
99
  t.getCurrentChainId(),
100
- f,
100
+ m,
101
101
  o,
102
- u,
102
+ w,
103
103
  c
104
104
  );
105
105
  return await x(C, {
@@ -108,25 +108,25 @@ const Q = async (t, e, r, p, o, i, u, c) => {
108
108
  phase: y.AFTER_SCHEDULE_WITHDRAW,
109
109
  scheduleId: g
110
110
  }), g;
111
- }, gt = async (t, e, r, p, o, i, u) => {
112
- const c = e.erc20TokenAddress, a = t.getCurrentChainId(), s = j(await t.getEthereumAddress()), n = i ?? await $(a, c, [c], z.Transact), { userDepositedUtxos: w, statusId: d } = await G(
111
+ }, gt = async (t, e, r, u, o, i, w) => {
112
+ const c = e.erc20TokenAddress, a = t.getCurrentChainId(), s = j(await t.getEthereumAddress()), n = i ?? await $(a, c, [c], z.Transact), { userDepositedUtxos: h, statusId: d, depositTxHash: m } = await G(
113
113
  t,
114
114
  e,
115
115
  r,
116
- p,
116
+ u,
117
117
  n,
118
118
  s
119
119
  );
120
- return Q(
120
+ return await Q(
121
121
  t,
122
122
  e,
123
- w,
123
+ h,
124
124
  n,
125
125
  s,
126
126
  d,
127
127
  o,
128
- u
129
- );
128
+ w
129
+ ), m;
130
130
  };
131
131
  export {
132
132
  gt as hinkalDepositAndWithdraw
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=require("ethers"),B=require("../../constants/protocol.constants.cjs"),j=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),G=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),N=require("../../functions/web3/events/getShieldedBalance.cjs"),X=require("../../functions/web3/functionCalls/transactCallDirect.cjs"),J=require("../../types/external-action.types.cjs");require("../../types/circom-data.types.cjs");const u=require("../../types/ethereum-network.types.cjs"),L=require("../../types/admin.types.cjs");require("../../types/activities.types.cjs");const U=require("../../types/scheduled-transactions.types.cjs"),Q=require("../../functions/pre-transaction/getSignatureDataForTransact.cjs"),V=require("../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs"),Y=require("../../functions/utils/getUtxosFromReceipt.utils.cjs"),tt=require("../../functions/utils/fees.utils.cjs"),et=require("../../functions/pre-transaction/constructAdminData.cjs"),st=require("../../API/admin-calls.cjs"),y=require("../../API/deposit-and-withdraw-status-calls.cjs"),ot=async(t,p,f,P,O,l)=>{const h=p.erc20TokenAddress,x=await t.getEthereumAddress(),a=f.map(e=>e+tt.calculateTotalFee(e,O)),n=[h],i=[0n],S=[!0],{patchAccessTokenMerkleTree:W,kycRequired:v,hasAccessToken:E}=await V.shouldPatchAccessTokenMerkleTree(t,n,i),_=await Q.getSignatureDataForTransact(t.getCurrentChainId(),x,t.userKeys,v,E),o=[...await N.addPaddingToUtxos(t,n,i)],C=[];for(let e=0;e<o.length;e+=1){const{outputUtxos:s}=j.outputUtxoProcessing(t.userKeys,o[e],i[e]);C.push(s)}const A=a.reduce((e,s)=>e+s,0n),F=z.ethers.AbiCoder.defaultAbiCoder().encode(["uint256[]"],[a]),g=t.getContractWithSigner(u.ContractType.HinkalWrapper),D=t.getContractWithSigner(u.ContractType.DepositOnChainUtxos),{zkCallData:I,circomData:k,dimData:b}=await G.constructZkProof("v1x1",t.merkleTreeHinkal,t.merkleTreeAccessToken,o,C,t.userKeys,`swapperM1x${o[0].length}x1`,J.ExternalActionId.DepositOnChainUtxos,await D.getAddress(),F,t.generateProofRemotely,B.zeroAddress,t.getCurrentChainId(),S,void 0,void 0,W,void 0,void 0,void 0,t.getContractWithFetcher(u.ContractType.HinkalHelperContract),_,await g.getAddress(),!1),r=t.getCurrentChainId(),T=(await y.updateDepositAndWithdrawStatus(r,{hashedEthereumAddress:l,phase:U.DepositAndWithdrawPhase.BEFORE_DEPOSIT})).id??void 0,m=await X.transactCallDirect(t,A,p,I,k,b,D,g),R=await m.wait(),H=m.hash;await y.safeUpdateDepositAndWithdrawStatus(r,{id:T,hashedEthereumAddress:l,phase:U.DepositAndWithdrawPhase.AFTER_DEPOSIT,depositTxHash:H});const M=await Y.getUtxosFromReceipt(R,t,h),w=[],c=[...M];P.forEach((e,s)=>{const q=a[s],d=c.find($=>$.amount===q);if(!d)throw new Error(`Could not find newly created UTXO with amount ${q} for recipient ${e}.`);w.push({recipientAddress:e,utxo:d});const Z=c.indexOf(d);c.splice(Z,1)});const K=et.constructAdminData(L.AdminTransactionType.DepositOnChainUtxos,r,n,[A],x);return st.emitTxPublicData(r,K),{userDepositedUtxos:w,statusId:T}};exports.hinkalDepositOnChainUtxos=ot;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=require("ethers"),B=require("../../constants/protocol.constants.cjs"),j=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),G=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),N=require("../../functions/web3/events/getShieldedBalance.cjs"),X=require("../../functions/web3/functionCalls/transactCallDirect.cjs"),J=require("../../types/external-action.types.cjs");require("../../types/circom-data.types.cjs");const u=require("../../types/ethereum-network.types.cjs"),L=require("../../types/admin.types.cjs");require("../../types/activities.types.cjs");const y=require("../../types/scheduled-transactions.types.cjs"),Q=require("../../functions/pre-transaction/getSignatureDataForTransact.cjs"),V=require("../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs"),Y=require("../../functions/utils/getUtxosFromReceipt.utils.cjs"),tt=require("../../functions/utils/fees.utils.cjs"),et=require("../../functions/pre-transaction/constructAdminData.cjs"),st=require("../../API/admin-calls.cjs"),f=require("../../API/deposit-and-withdraw-status-calls.cjs"),ot=async(t,p,P,O,S,l)=>{const h=p.erc20TokenAddress,x=await t.getEthereumAddress(),a=P.map(e=>e+tt.calculateTotalFee(e,S)),n=[h],i=[0n],W=[!0],{patchAccessTokenMerkleTree:v,kycRequired:E,hasAccessToken:_}=await V.shouldPatchAccessTokenMerkleTree(t,n,i),F=await Q.getSignatureDataForTransact(t.getCurrentChainId(),x,t.userKeys,E,_),o=[...await N.addPaddingToUtxos(t,n,i)],C=[];for(let e=0;e<o.length;e+=1){const{outputUtxos:s}=j.outputUtxoProcessing(t.userKeys,o[e],i[e]);C.push(s)}const A=a.reduce((e,s)=>e+s,0n),I=z.ethers.AbiCoder.defaultAbiCoder().encode(["uint256[]"],[a]),g=t.getContractWithSigner(u.ContractType.HinkalWrapper),D=t.getContractWithSigner(u.ContractType.DepositOnChainUtxos),{zkCallData:k,circomData:b,dimData:R}=await G.constructZkProof("v1x1",t.merkleTreeHinkal,t.merkleTreeAccessToken,o,C,t.userKeys,`swapperM1x${o[0].length}x1`,J.ExternalActionId.DepositOnChainUtxos,await D.getAddress(),I,t.generateProofRemotely,B.zeroAddress,t.getCurrentChainId(),W,void 0,void 0,v,void 0,void 0,void 0,t.getContractWithFetcher(u.ContractType.HinkalHelperContract),F,await g.getAddress(),!1),r=t.getCurrentChainId(),T=(await f.updateDepositAndWithdrawStatus(r,{hashedEthereumAddress:l,phase:y.DepositAndWithdrawPhase.BEFORE_DEPOSIT})).id??void 0,m=await X.transactCallDirect(t,A,p,k,b,R,D,g),H=await m.wait(),w=m.hash;await f.safeUpdateDepositAndWithdrawStatus(r,{id:T,hashedEthereumAddress:l,phase:y.DepositAndWithdrawPhase.AFTER_DEPOSIT,depositTxHash:w});const M=await Y.getUtxosFromReceipt(H,t,h),q=[],c=[...M];O.forEach((e,s)=>{const U=a[s],d=c.find($=>$.amount===U);if(!d)throw new Error(`Could not find newly created UTXO with amount ${U} for recipient ${e}.`);q.push({recipientAddress:e,utxo:d});const Z=c.indexOf(d);c.splice(Z,1)});const K=et.constructAdminData(L.AdminTransactionType.DepositOnChainUtxos,r,n,[A],x);return st.emitTxPublicData(r,K),{userDepositedUtxos:q,statusId:T,depositTxHash:w}};exports.hinkalDepositOnChainUtxos=ot;
@@ -4,4 +4,5 @@ import { FeeStructure } from '../../types/hinkal.types';
4
4
  export declare const hinkalDepositOnChainUtxos: (hinkal: IHinkal, erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], feeStructure: FeeStructure, hashedEthereumAddress: string) => Promise<{
5
5
  userDepositedUtxos: RecipientUtxo[];
6
6
  statusId?: string | undefined;
7
+ depositTxHash: string;
7
8
  }>;
@@ -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;
@@ -59,33 +59,33 @@ import { updateDepositAndWithdrawStatus as ht, safeUpdateDepositAndWithdrawStatu
59
59
  const ft = async (t, r, p, d, l, u) => {
60
60
  const g = p.map((o) => o + nt(o, l)), {
61
61
  hinkalIdl: h,
62
- hinkalAddress: y,
62
+ hinkalAddress: S,
63
63
  originalDeployer: s
64
64
  } = $[t.getCurrentChainId()].contractData;
65
65
  if (!h)
66
66
  throw new Error("No IDL configured for Solana program on this network");
67
67
  if (!s)
68
68
  throw new Error("missing original deployer");
69
- const f = t.userKeys.getShieldedPrivateKey(), E = z.findCorrectRandomization(M(31), f), S = ct(E, f), e = t.getSolanaProgram(h), v = t.getSolanaPublicKey(), a = new W(s), A = new W(y), { mintPublicKey: c } = q(r), R = c.toString(), F = tt(A, a), b = ot(A, a), H = rt(A, a), x = et(S), I = t.getCurrentChainId(), D = g.reduce((o, n) => o + n, 0n), T = await pt(
69
+ const f = t.userKeys.getShieldedPrivateKey(), E = z.findCorrectRandomization(M(31), f), w = ct(E, f), e = t.getSolanaProgram(h), v = t.getSolanaPublicKey(), a = new W(s), A = new W(S), { mintPublicKey: c } = q(r), x = c.toString(), H = tt(A, a), R = ot(A, a), F = rt(A, a), b = et(w), T = t.getCurrentChainId(), D = g.reduce((o, n) => o + n, 0n), I = await pt(
70
70
  e,
71
71
  new W(a),
72
72
  [r],
73
73
  [D]
74
74
  ), K = g.map((o) => `${o}`);
75
75
  let i = "";
76
- const P = (await ht(I, {
76
+ const P = (await ht(T, {
77
77
  hashedEthereumAddress: u,
78
78
  phase: k.BEFORE_DEPOSIT
79
79
  })).id ?? void 0;
80
- if (T) {
81
- const { serializedTransaction: o, blockhash: n, lastValidBlockHeight: w } = await G.generateMultiPaymentDepositLimitless(
82
- I,
80
+ if (I) {
81
+ const { serializedTransaction: o, blockhash: n, lastValidBlockHeight: y } = await G.generateMultiPaymentDepositLimitless(
82
+ T,
83
83
  {
84
84
  amounts: K,
85
85
  payer: t.getSolanaPublicKey().toBase58(),
86
86
  ethereumAddress: await t.getEthereumAddress(),
87
87
  mint: r,
88
- stealthAddressStructure: x
88
+ stealthAddressStructure: b
89
89
  }
90
90
  ), { wallet: m } = e.provider;
91
91
  if (!m)
@@ -94,23 +94,23 @@ const ft = async (t, r, p, d, l, u) => {
94
94
  e.provider,
95
95
  o,
96
96
  n,
97
- w
97
+ y
98
98
  );
99
99
  } else {
100
- const o = at(e.programId, a, c), n = R === U ? null : c, w = R === U ? null : void 0;
100
+ const o = at(e.programId, a, c), n = x === U ? null : c, y = x === U ? null : void 0;
101
101
  i = await e.methods.multiPaymentDeposit(
102
102
  K.map((V) => new Q(V)),
103
- x
103
+ b
104
104
  ).accounts({
105
105
  mint: n,
106
106
  signer: v,
107
- signerAta: w,
107
+ signerAta: y,
108
108
  originalDeployer: a,
109
- storageAccount: F,
110
- storageVault: b,
111
- merkleAccount: H,
109
+ storageAccount: H,
110
+ storageVault: R,
111
+ merkleAccount: F,
112
112
  tokenLimitStorage: o,
113
- storageVaultAta: w,
113
+ storageVaultAta: y,
114
114
  accessTokenOwner: null
115
115
  }).rpc();
116
116
  const m = await e.provider.connection.getLatestBlockhash();
@@ -129,7 +129,7 @@ const ft = async (t, r, p, d, l, u) => {
129
129
  });
130
130
  if (!B)
131
131
  throw new Error("Transaction missing");
132
- await N(I, {
132
+ await N(T, {
133
133
  id: P,
134
134
  hashedEthereumAddress: u,
135
135
  phase: k.AFTER_DEPOSIT,
@@ -137,45 +137,45 @@ const ft = async (t, r, p, d, l, u) => {
137
137
  });
138
138
  const L = dt(B, e, t.userKeys), O = [], C = [...L];
139
139
  return d.forEach((o, n) => {
140
- const w = g[n], m = C.find((X) => X.amount === w);
140
+ const y = g[n], m = C.find((X) => X.amount === y);
141
141
  if (!m)
142
- throw new Error(`Could not find newly created UTXO with amount ${w} for recipient ${o}.`);
142
+ throw new Error(`Could not find newly created UTXO with amount ${y} for recipient ${o}.`);
143
143
  O.push({
144
144
  recipientAddress: o,
145
145
  utxo: m
146
146
  });
147
147
  const V = C.indexOf(m);
148
148
  C.splice(V, 1);
149
- }), { userDepositedUtxos: O, signature: i, statusId: P };
149
+ }), { userDepositedUtxos: O, depositTxHash: i, statusId: P };
150
150
  }, wt = async (t, r, p, d, l, u, g, h) => {
151
- const y = t.getCurrentChainId();
151
+ const S = t.getCurrentChainId();
152
152
  if (p.length === 0)
153
153
  throw new Error("userDepositedUtxos must not be empty");
154
154
  const { hinkalIdl: s, originalDeployer: f } = $[t.getCurrentChainId()].contractData;
155
155
  if (!f || !s)
156
156
  throw new Error("missing data");
157
- const E = t.getSolanaProgram(s), S = await t.getRandomRelay(!0);
158
- if (!S)
157
+ const E = t.getSolanaProgram(s), w = await t.getRandomRelay(!0);
158
+ if (!w)
159
159
  throw new Error(Y.RELAYER_NOT_AVAILABLE);
160
160
  const e = it().toString(), v = t.generateProofRemotely ? 5 : 1, a = [];
161
161
  for (let c = 0; c < p.length; c += v) {
162
- const R = p.slice(c, c + v), F = await Promise.all(
163
- R.map(async ({ recipientAddress: b, utxo: H }) => {
164
- const { compressedAddress: x } = q(U), I = new z({
162
+ const x = p.slice(c, c + v), H = await Promise.all(
163
+ x.map(async ({ recipientAddress: R, utxo: F }) => {
164
+ const { compressedAddress: b } = q(U), T = new z({
165
165
  amount: 0n,
166
166
  mintAddress: r,
167
- erc20TokenAddress: x,
167
+ erc20TokenAddress: b,
168
168
  shieldedPrivateKey: t.userKeys.getShieldedPrivateKey(),
169
169
  timeStamp: e,
170
170
  tokenId: 0
171
- }), D = [H, I], T = [I], K = z.findCorrectRandomization(
171
+ }), D = [F, T], I = [T], K = z.findCorrectRandomization(
172
172
  M(31),
173
173
  t.userKeys.getShieldedPrivateKey()
174
174
  ), i = {
175
175
  tokenNumber: 1,
176
176
  nullifierAmount: D.length,
177
- outputAmount: T.length
178
- }, _ = mt([T])[0][0], P = Array.from(Z.getBytes(_)), { proofAArr: B, proofBArr: L, proofCArr: O, publicInputsArr: C } = await lt(
177
+ outputAmount: I.length
178
+ }, _ = mt([I])[0][0], P = Array.from(Z.getBytes(_)), { proofAArr: B, proofBArr: L, proofCArr: O, publicInputsArr: C } = await lt(
179
179
  t.generateProofRemotely,
180
180
  f,
181
181
  t.merkleTreeHinkal,
@@ -184,12 +184,12 @@ const ft = async (t, r, p, d, l, u) => {
184
184
  E,
185
185
  [r],
186
186
  [D],
187
- [T],
187
+ [I],
188
188
  K,
189
189
  d.flatFee,
190
190
  d.variableRate,
191
- b,
192
- S,
191
+ R,
192
+ w,
193
193
  i,
194
194
  [P],
195
195
  t.getCurrentChainId(),
@@ -200,11 +200,11 @@ const ft = async (t, r, p, d, l, u) => {
200
200
  void 0,
201
201
  !1
202
202
  ), n = {
203
- recipient: b,
203
+ recipient: R,
204
204
  mint: r === U ? void 0 : r
205
205
  };
206
206
  return {
207
- relayAddress: S,
207
+ relayAddress: w,
208
208
  functionName: "transact",
209
209
  args: {
210
210
  proofAArr: B,
@@ -219,9 +219,9 @@ const ft = async (t, r, p, d, l, u) => {
219
219
  };
220
220
  })
221
221
  );
222
- a.push(...F);
222
+ a.push(...H);
223
223
  }
224
- await N(y, {
224
+ await N(S, {
225
225
  id: u,
226
226
  hashedEthereumAddress: l,
227
227
  phase: k.BEFORE_SCHEDULE_WITHDRAW
@@ -233,14 +233,14 @@ const ft = async (t, r, p, d, l, u) => {
233
233
  g,
234
234
  h
235
235
  );
236
- return await N(y, {
236
+ return await N(S, {
237
237
  id: u,
238
238
  hashedEthereumAddress: l,
239
239
  phase: k.AFTER_SCHEDULE_WITHDRAW,
240
240
  scheduleId: A
241
241
  }), A;
242
- }, To = async (t, r, p, d, l, u, g) => {
243
- const h = j(await t.getEthereumAddress()), y = t.getCurrentChainId(), s = u ?? await gt(y, r, [r], J.Transact, [], 0n), { userDepositedUtxos: f, statusId: E } = await ft(
242
+ }, Io = async (t, r, p, d, l, u, g) => {
243
+ const h = j(await t.getEthereumAddress()), S = t.getCurrentChainId(), s = u ?? await gt(S, r, [r], J.Transact, [], 0n), { userDepositedUtxos: f, statusId: E, depositTxHash: w } = await ft(
244
244
  t,
245
245
  r,
246
246
  p,
@@ -257,8 +257,8 @@ const ft = async (t, r, p, d, l, u) => {
257
257
  E,
258
258
  l,
259
259
  g
260
- );
260
+ ), w;
261
261
  };
262
262
  export {
263
- To as hinkalSolanaDepositAndWithdraw
263
+ Io as hinkalSolanaDepositAndWithdraw
264
264
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hinkal/common",
3
- "version": "0.2.23",
3
+ "version": "0.2.24",
4
4
  "homepage": "hinkal.io",
5
5
  "author": {
6
6
  "name": "Hinkal Protocol"