@hinkal/common 0.2.25 → 0.2.27

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.
@@ -17,23 +17,23 @@ 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, u, o, i, w, c) => {
21
- if (r.length === 0)
20
+ const Q = async (t, r, o, w, a, n, h, A) => {
21
+ if (o.length === 0)
22
22
  throw new Error("userDepositedUtxos must not be empty");
23
- const a = e.erc20TokenAddress, s = await t.getRandomRelay();
24
- if (!s)
23
+ const e = r.erc20TokenAddress, i = await t.getRandomRelay();
24
+ if (!i)
25
25
  throw Error(F.RELAYER_NOT_AVAILABLE);
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
- I.map(async ({ recipientAddress: D, utxo: A }) => {
30
- const R = [-A.amount], l = new B({
26
+ const s = await t.getEthereumAddress(), c = Z().toString(), d = t.generateProofRemotely ? 5 : 1, m = [];
27
+ for (let u = 0; u < o.length; u += d) {
28
+ const I = o.slice(u, u + d), E = await Promise.all(
29
+ I.map(async ({ recipientAddress: D, utxo: f }) => {
30
+ const R = [-f.amount], l = new B({
31
31
  amount: 0n,
32
- erc20TokenAddress: a,
32
+ erc20TokenAddress: e,
33
33
  shieldedPrivateKey: t.userKeys.getShieldedPrivateKey(),
34
- timeStamp: h,
34
+ timeStamp: c,
35
35
  tokenId: 0
36
- }), T = [[A, l]], S = [[l]], v = `swapperM1x${T[0].length}x1`, f = {
36
+ }), T = [[f, l]], S = [[l]], v = `swapperM1x${T[0].length}x1`, C = {
37
37
  externalActionId: 0n,
38
38
  externalAddress: D,
39
39
  externalActionMetadata: "0x00"
@@ -41,18 +41,18 @@ const Q = async (t, e, r, u, o, i, w, c) => {
41
41
  patchAccessTokenMerkleTree: H,
42
42
  kycRequired: P,
43
43
  hasAccessToken: U
44
- } = await Y(t, [a], R), W = await V(
44
+ } = await Y(t, [e], R), W = await V(
45
45
  t.getCurrentChainId(),
46
- n,
46
+ s,
47
47
  t.userKeys,
48
48
  P,
49
49
  U
50
50
  ), K = J(
51
51
  N.WithdrawOnChainUtxos,
52
52
  t.getCurrentChainId(),
53
- [a],
54
- [-A.amount],
55
- n
53
+ [e],
54
+ [-f.amount],
55
+ s
56
56
  ), { zkCallData: M, circomData: _, dimData: b } = await L(
57
57
  "v1x1",
58
58
  t.merkleTreeHinkal,
@@ -61,11 +61,11 @@ const Q = async (t, e, r, u, o, i, w, c) => {
61
61
  S,
62
62
  t.userKeys,
63
63
  v,
64
- f.externalActionId,
65
- f.externalAddress,
66
- f.externalActionMetadata,
64
+ C.externalActionId,
65
+ C.externalAddress,
66
+ C.externalActionMetadata,
67
67
  t.generateProofRemotely,
68
- s ?? k,
68
+ i ?? k,
69
69
  t.getCurrentChainId(),
70
70
  void 0,
71
71
  void 0,
@@ -73,7 +73,7 @@ const Q = async (t, e, r, u, o, i, w, c) => {
73
73
  H,
74
74
  void 0,
75
75
  void 0,
76
- u,
76
+ w,
77
77
  t.getContractWithFetcher(q.HinkalHelperContract),
78
78
  W,
79
79
  void 0,
@@ -89,44 +89,45 @@ const Q = async (t, e, r, u, o, i, w, c) => {
89
89
  );
90
90
  m.push(...E);
91
91
  }
92
- const C = t.getCurrentChainId();
93
- await x(C, {
94
- id: i,
95
- hashedEthereumAddress: o,
92
+ const p = t.getCurrentChainId();
93
+ await x(p, {
94
+ id: n,
95
+ hashedEthereumAddress: a,
96
96
  phase: y.BEFORE_SCHEDULE_WITHDRAW
97
97
  });
98
98
  const g = await O(
99
99
  t.getCurrentChainId(),
100
100
  m,
101
- o,
102
- w,
103
- c
101
+ a,
102
+ h,
103
+ A
104
104
  );
105
- return await x(C, {
106
- id: i,
107
- hashedEthereumAddress: o,
105
+ return await x(p, {
106
+ id: n,
107
+ hashedEthereumAddress: a,
108
108
  phase: y.AFTER_SCHEDULE_WITHDRAW,
109
109
  scheduleId: g
110
110
  }), 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(
111
+ }, gt = async (t, r, o, w, a, n, h, A = !0) => {
112
+ const e = r.erc20TokenAddress, i = t.getCurrentChainId(), s = j(await t.getEthereumAddress()), c = n ?? await $(i, e, [e], z.Transact), { userDepositedUtxos: d, statusId: m, depositTxHash: p } = await G(
113
113
  t,
114
- e,
115
114
  r,
116
- u,
117
- n,
118
- s
115
+ o,
116
+ w,
117
+ c,
118
+ s,
119
+ A
119
120
  );
120
121
  return await Q(
121
122
  t,
122
- e,
123
- h,
124
- n,
125
- s,
123
+ r,
126
124
  d,
127
- o,
128
- w
129
- ), m;
125
+ c,
126
+ s,
127
+ m,
128
+ a,
129
+ h
130
+ ), p;
130
131
  };
131
132
  export {
132
133
  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 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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const B=require("ethers"),j=require("../../constants/protocol.constants.cjs"),G=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),N=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),X=require("../../functions/web3/events/getShieldedBalance.cjs"),J=require("../../functions/web3/functionCalls/transactCallDirect.cjs"),L=require("../../types/external-action.types.cjs");require("../../types/circom-data.types.cjs");const u=require("../../types/ethereum-network.types.cjs"),Q=require("../../types/admin.types.cjs");require("../../types/activities.types.cjs");const y=require("../../types/scheduled-transactions.types.cjs"),V=require("../../functions/pre-transaction/getSignatureDataForTransact.cjs"),Y=require("../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs"),tt=require("../../functions/utils/getUtxosFromReceipt.utils.cjs"),et=require("../../functions/utils/fees.utils.cjs"),st=require("../../functions/pre-transaction/constructAdminData.cjs"),ot=require("../../API/admin-calls.cjs"),f=require("../../API/deposit-and-withdraw-status-calls.cjs"),rt=async(t,p,P,O,S,l,W=!0)=>{const h=p.erc20TokenAddress,x=await t.getEthereumAddress(),a=P.map(e=>e+et.calculateTotalFee(e,S)),n=[h],i=[0n],v=[!0],{patchAccessTokenMerkleTree:E,kycRequired:_,hasAccessToken:F}=await Y.shouldPatchAccessTokenMerkleTree(t,n,i),I=await V.getSignatureDataForTransact(t.getCurrentChainId(),x,t.userKeys,_,F),o=[...await X.addPaddingToUtxos(t,n,i)],C=[];for(let e=0;e<o.length;e+=1){const{outputUtxos:s}=G.outputUtxoProcessing(t.userKeys,o[e],i[e]);C.push(s)}const A=a.reduce((e,s)=>e+s,0n),k=B.ethers.AbiCoder.defaultAbiCoder().encode(["uint256[]"],[a]),g=t.getContractWithSigner(u.ContractType.HinkalWrapper),D=t.getContractWithSigner(u.ContractType.DepositOnChainUtxos),{zkCallData:b,circomData:R,dimData:H}=await N.constructZkProof("v1x1",t.merkleTreeHinkal,t.merkleTreeAccessToken,o,C,t.userKeys,`swapperM1x${o[0].length}x1`,L.ExternalActionId.DepositOnChainUtxos,await D.getAddress(),k,t.generateProofRemotely,j.zeroAddress,t.getCurrentChainId(),v,void 0,void 0,E,void 0,void 0,void 0,t.getContractWithFetcher(u.ContractType.HinkalHelperContract),I,await g.getAddress(),!1),r=t.getCurrentChainId(),T=(await f.updateDepositAndWithdrawStatus(r,{hashedEthereumAddress:l,phase:y.DepositAndWithdrawPhase.BEFORE_DEPOSIT})).id??void 0,m=await J.transactCallDirect(t,A,p,b,R,H,D,g,W),M=await m.wait(),w=m.hash;await f.safeUpdateDepositAndWithdrawStatus(r,{id:T,hashedEthereumAddress:l,phase:y.DepositAndWithdrawPhase.AFTER_DEPOSIT,depositTxHash:w});const K=await tt.getUtxosFromReceipt(M,t,h),q=[],c=[...K];O.forEach((e,s)=>{const U=a[s],d=c.find(z=>z.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 $=c.indexOf(d);c.splice($,1)});const Z=st.constructAdminData(Q.AdminTransactionType.DepositOnChainUtxos,r,n,[A],x);return ot.emitTxPublicData(r,Z),{userDepositedUtxos:q,statusId:T,depositTxHash:w}};exports.hinkalDepositOnChainUtxos=rt;
@@ -1,7 +1,7 @@
1
1
  import { IHinkal } from './IHinkal';
2
2
  import { ERC20Token, RecipientUtxo } from '../../types';
3
3
  import { FeeStructure } from '../../types/hinkal.types';
4
- export declare const hinkalDepositOnChainUtxos: (hinkal: IHinkal, erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], feeStructure: FeeStructure, hashedEthereumAddress: string) => Promise<{
4
+ export declare const hinkalDepositOnChainUtxos: (hinkal: IHinkal, erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], feeStructure: FeeStructure, hashedEthereumAddress: string, preEstimateGas?: boolean) => Promise<{
5
5
  userDepositedUtxos: RecipientUtxo[];
6
6
  statusId?: string | undefined;
7
7
  depositTxHash: string;
@@ -1,43 +1,43 @@
1
- import { ethers as _ } from "ethers";
2
- import { zeroAddress as q } from "../../constants/protocol.constants.mjs";
3
- import { outputUtxoProcessing as B } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
4
- import { constructZkProof as X } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
5
- import { addPaddingToUtxos as j } from "../../functions/web3/events/getShieldedBalance.mjs";
6
- import { transactCallDirect as G } from "../../functions/web3/functionCalls/transactCallDirect.mjs";
7
- import { ExternalActionId as J } from "../../types/external-action.types.mjs";
1
+ import { ethers as q } from "ethers";
2
+ import { zeroAddress as B } from "../../constants/protocol.constants.mjs";
3
+ import { outputUtxoProcessing as X } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
4
+ import { constructZkProof as j } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
5
+ import { addPaddingToUtxos as G } from "../../functions/web3/events/getShieldedBalance.mjs";
6
+ import { transactCallDirect as J } from "../../functions/web3/functionCalls/transactCallDirect.mjs";
7
+ import { ExternalActionId as L } from "../../types/external-action.types.mjs";
8
8
  import "../../types/circom-data.types.mjs";
9
9
  import { ContractType as p } from "../../types/ethereum-network.types.mjs";
10
- import { AdminTransactionType as L } from "../../types/admin.types.mjs";
10
+ import { AdminTransactionType as N } from "../../types/admin.types.mjs";
11
11
  import "../../types/activities.types.mjs";
12
12
  import { DepositAndWithdrawPhase as y } from "../../types/scheduled-transactions.types.mjs";
13
- import { getSignatureDataForTransact as N } from "../../functions/pre-transaction/getSignatureDataForTransact.mjs";
14
- import { shouldPatchAccessTokenMerkleTree as Q } from "../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.mjs";
15
- import { getUtxosFromReceipt as V } from "../../functions/utils/getUtxosFromReceipt.utils.mjs";
16
- import { calculateTotalFee as Y } from "../../functions/utils/fees.utils.mjs";
17
- import { constructAdminData as tt } from "../../functions/pre-transaction/constructAdminData.mjs";
18
- import { emitTxPublicData as ot } from "../../API/admin-calls.mjs";
19
- import { updateDepositAndWithdrawStatus as et, safeUpdateDepositAndWithdrawStatus as rt } from "../../API/deposit-and-withdraw-status-calls.mjs";
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(
13
+ import { getSignatureDataForTransact as Q } from "../../functions/pre-transaction/getSignatureDataForTransact.mjs";
14
+ import { shouldPatchAccessTokenMerkleTree as V } from "../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.mjs";
15
+ import { getUtxosFromReceipt as Y } from "../../functions/utils/getUtxosFromReceipt.utils.mjs";
16
+ import { calculateTotalFee as tt } from "../../functions/utils/fees.utils.mjs";
17
+ import { constructAdminData as ot } from "../../functions/pre-transaction/constructAdminData.mjs";
18
+ import { emitTxPublicData as et } from "../../API/admin-calls.mjs";
19
+ import { updateDepositAndWithdrawStatus as rt, safeUpdateDepositAndWithdrawStatus as st } from "../../API/deposit-and-withdraw-status-calls.mjs";
20
+ const Ot = async (t, m, O, E, P, u, v = !0) => {
21
+ const f = m.erc20TokenAddress, x = await t.getEthereumAddress(), a = O.map((o) => o + tt(o, P)), i = [f], n = [0n], I = [!0], { patchAccessTokenMerkleTree: W, kycRequired: S, hasAccessToken: F } = await V(
22
22
  t,
23
23
  i,
24
24
  n
25
- ), F = await N(
25
+ ), H = await Q(
26
26
  t.getCurrentChainId(),
27
27
  x,
28
28
  t.userKeys,
29
- W,
30
- S
31
- ), r = [...await j(t, i, n)], C = [];
29
+ S,
30
+ F
31
+ ), r = [...await G(t, i, n)], C = [];
32
32
  for (let o = 0; o < r.length; o += 1) {
33
- const { outputUtxos: e } = B(t.userKeys, r[o], n[o]);
33
+ const { outputUtxos: e } = X(t.userKeys, r[o], n[o]);
34
34
  C.push(e);
35
35
  }
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
- } = await X(
36
+ const A = a.reduce((o, e) => o + e, 0n), R = q.AbiCoder.defaultAbiCoder().encode(["uint256[]"], [a]), D = t.getContractWithSigner(p.HinkalWrapper), g = t.getContractWithSigner(p.DepositOnChainUtxos), {
37
+ zkCallData: b,
38
+ circomData: K,
39
+ dimData: M
40
+ } = await j(
41
41
  "v1x1",
42
42
  t.merkleTreeHinkal,
43
43
  t.merkleTreeAccessToken,
@@ -45,63 +45,64 @@ const yt = async (t, m, O, E, P, u) => {
45
45
  C,
46
46
  t.userKeys,
47
47
  `swapperM1x${r[0].length}x1`,
48
- J.DepositOnChainUtxos,
48
+ L.DepositOnChainUtxos,
49
49
  await g.getAddress(),
50
- H,
50
+ R,
51
51
  t.generateProofRemotely,
52
- q,
52
+ B,
53
53
  t.getCurrentChainId(),
54
- v,
54
+ I,
55
55
  void 0,
56
56
  void 0,
57
- I,
57
+ W,
58
58
  void 0,
59
59
  void 0,
60
60
  void 0,
61
61
  t.getContractWithFetcher(p.HinkalHelperContract),
62
- F,
62
+ H,
63
63
  await D.getAddress(),
64
64
  !1
65
- ), s = t.getCurrentChainId(), h = (await et(s, {
65
+ ), s = t.getCurrentChainId(), h = (await rt(s, {
66
66
  hashedEthereumAddress: u,
67
67
  phase: y.BEFORE_DEPOSIT
68
- })).id ?? void 0, w = await G(
68
+ })).id ?? void 0, w = await J(
69
69
  t,
70
70
  A,
71
71
  m,
72
- R,
73
72
  b,
74
73
  K,
74
+ M,
75
75
  g,
76
- D
77
- ), M = await w.wait(), T = w.hash;
78
- await rt(s, {
76
+ D,
77
+ v
78
+ ), $ = await w.wait(), T = w.hash;
79
+ await st(s, {
79
80
  id: h,
80
81
  hashedEthereumAddress: u,
81
82
  phase: y.AFTER_DEPOSIT,
82
83
  depositTxHash: T
83
84
  });
84
- const $ = await V(M, t, f), l = [], c = [...$];
85
+ const k = await Y($, t, f), l = [], c = [...k];
85
86
  E.forEach((o, e) => {
86
- const U = a[e], d = c.find((Z) => Z.amount === U);
87
+ const U = a[e], d = c.find((_) => _.amount === U);
87
88
  if (!d)
88
89
  throw new Error(`Could not find newly created UTXO with amount ${U} for recipient ${o}.`);
89
90
  l.push({
90
91
  recipientAddress: o,
91
92
  utxo: d
92
93
  });
93
- const z = c.indexOf(d);
94
- c.splice(z, 1);
94
+ const Z = c.indexOf(d);
95
+ c.splice(Z, 1);
95
96
  });
96
- const k = tt(
97
- L.DepositOnChainUtxos,
97
+ const z = ot(
98
+ N.DepositOnChainUtxos,
98
99
  s,
99
100
  i,
100
101
  [A],
101
102
  x
102
103
  );
103
- return ot(s, k), { userDepositedUtxos: l, statusId: h, depositTxHash: T };
104
+ return et(s, z), { userDepositedUtxos: l, statusId: h, depositTxHash: T };
104
105
  };
105
106
  export {
106
- yt as hinkalDepositOnChainUtxos
107
+ Ot as hinkalDepositOnChainUtxos
107
108
  };
@@ -1 +1 @@
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
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=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"),U=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,p,o,D,a,h,C,c)=>{if(o.length===0)throw new Error("No recipients to bridge");const n=p.erc20TokenAddress,r=e.getCurrentChainId(),{contractData:g}=ce.networkRegistry[r],{emporiumAddress:i}=g;if(!i)throw Error("No Emporium Address");const E=N.SWAP_ROUTER_ADDRESSES[U.ExternalActionId.Lifi][r];if(!E)throw new Error(`LIFI not configured for chain ${r}`);const R=await e.getRandomRelay();if(!R)throw Error(X.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const T=await e.getEthereumAddress(),f=ne.getCurrentTimeInSeconds().toString(),q=e.generateProofRemotely?5:1,w=[];for(let u=0;u<o.length;u+=q){const v=o.slice(u,u+q),S=await Promise.all(v.map(async({utxo:t,nativeUtxo:s,bridgeAmount:A,quote:d,temporarySubAccount:I})=>{await le.API.addTemporaryWalletNonce(r,a,I.index);const H=d.nativeFee>0n&&!K.caseInsensitiveEqual(n,l.zeroAddress),m=[n],_=[-t.amount],k=[!1],F=new W.Utxo({amount:0n,erc20TokenAddress:n,shieldedPrivateKey:e.userKeys.getShieldedPrivateKey(),timeStamp:f,tokenId:0}),x=[[t,F]],P=[[F]];if(H&&s){const O=new W.Utxo({amount:0n,erc20TokenAddress:l.zeroAddress,shieldedPrivateKey:e.userKeys.getShieldedPrivateKey(),timeStamp:f,tokenId:0});m.push(l.zeroAddress),_.push(-s.amount),k.push(!1),x.push([s,O]),P.push([O])}const M=B.createLifiBridgeOps(e,I.ethAddress,E,n,t.amount,A,d),{patchAccessTokenMerkleTree:j,kycRequired:V,hasAccessToken:Y}=await oe.shouldPatchAccessTokenMerkleTree(e,m,_),Z=await se.getSignatureDataForTransact(r,T,e.userKeys,V,Y),{zkCallData:$,circomData:G,dimData:J,authorizationData:Q}=await ee.constructEmporiumProof("v1x1",e.merkleTreeHinkal,e.merkleTreeAccessToken,m,m.map(()=>0),x,P,e.userKeys,m.length,x[0].length,i,M,e.generateProofRemotely,R??l.zeroAddress,r,k,void 0,I.privateKey,void 0,j,void 0,D,e.getContractWithFetcher(re.ContractType.HinkalHelperContract),Z,void 0,!1);return{zkCallData:$,dimData:J,circomData:G,authorizationData:Q}}));w.push(...S)}await L.safeUpdateDepositAndWithdrawStatus(r,{id:h,hashedEthereumAddress:a,phase:b.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});const y=await te.transactCallRelayerBatch(r,w,a,C,c);return await L.safeUpdateDepositAndWithdrawStatus(r,{id:h,hashedEthereumAddress:a,phase:b.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:y}),y},qe=async(e,p,o,D,a,h,C=!0)=>{const c=p.erc20TokenAddress,n=e.getCurrentChainId(),r=ae.hashEthereumAddress(await e.getEthereumAddress()),g=N.SWAP_ROUTER_ADDRESSES[U.ExternalActionId.Lifi][n];if(!g)throw Error("LIFI router not configured");let i;if(a)i=a;else{const t=o[0],A=B.createLifiBridgeOps(e,t.temporarySubAccount.ethAddress,g,c,t.bridgeAmount,t.bridgeAmount,t.quote).map(d=>de.convertEmporiumOpToCallInfo(d,t.temporarySubAccount.ethAddress,n));i=await ie.getFeeStructure(n,c,[c],U.ExternalActionId.Emporium,A)}const E={feeToken:i.feeToken,flatFee:0n,variableRate:0n},T=o.reduce((t,s)=>t+s.quote.nativeFee,0n)>0n&&!K.caseInsensitiveEqual(c,l.zeroAddress),f=o.map(t=>t.bridgeAmount),q=o.map(t=>t.recipientAddress),{userDepositedUtxos:w,statusId:y,depositTxHash:u}=await z.hinkalDepositOnChainUtxos(e,p,f,q,i,r);let v=[];if(T){const t=ue.getERC20Token(l.zeroAddress,n);if(!t)throw Error("No native token");const s=o.map(d=>d.quote.nativeFee),{userDepositedUtxos:A}=await z.hinkalDepositOnChainUtxos(e,t,s,q,E,r,C);v=A}const S=o.map((t,s)=>({...t,utxo:w[s].utxo,nativeUtxo:T?v[s]?.utxo:void 0}));return await pe(e,p,S,i,r,y,D,h),u};exports.hinkalDepositAndBridge=qe;
@@ -1,4 +1,4 @@
1
1
  import { IHinkal } from './IHinkal';
2
2
  import { BridgeRecipient, ERC20Token } from '../../types';
3
3
  import { FeeStructure } from '../../types/hinkal.types';
4
- export declare const hinkalDepositAndBridge: (hinkal: IHinkal, erc20Token: ERC20Token, recipients: BridgeRecipient[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string) => Promise<string>;
4
+ export declare const hinkalDepositAndBridge: (hinkal: IHinkal, erc20Token: ERC20Token, recipients: BridgeRecipient[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, preEstimateGas?: boolean) => Promise<string>;