@hinkal/common 0.2.24 → 0.2.26

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,62 +1,62 @@
1
- import { zeroAddress as D } from "../../constants/protocol.constants.mjs";
2
- import { outputUtxoProcessing as R } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
3
- import { constructZkProof as C } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
4
- import { addPaddingToUtxos as H } from "../../functions/web3/events/getShieldedBalance.mjs";
5
- import { transactCallDirect as P } from "../../functions/web3/functionCalls/transactCallDirect.mjs";
6
- import { Utxo as w } from "../utxo/Utxo.mjs";
7
- import { transactionErrorCodes as z } from "../../error-handling/error-codes.constants.mjs";
1
+ import { zeroAddress as C } from "../../constants/protocol.constants.mjs";
2
+ import { outputUtxoProcessing as H } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
3
+ import { constructZkProof as P } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
4
+ import { addPaddingToUtxos as z } from "../../functions/web3/events/getShieldedBalance.mjs";
5
+ import { transactCallDirect as I } from "../../functions/web3/functionCalls/transactCallDirect.mjs";
6
+ import { Utxo as D } from "../utxo/Utxo.mjs";
7
+ import { transactionErrorCodes as F } from "../../error-handling/error-codes.constants.mjs";
8
8
  import "../../types/circom-data.types.mjs";
9
- import { ContractType as I } from "../../types/ethereum-network.types.mjs";
10
- import { AdminTransactionType as K } from "../../types/admin.types.mjs";
9
+ import { ContractType as K } from "../../types/ethereum-network.types.mjs";
10
+ import { AdminTransactionType as M } from "../../types/admin.types.mjs";
11
11
  import "../../types/activities.types.mjs";
12
- import { getSignatureDataForTransact as F } from "../../functions/pre-transaction/getSignatureDataForTransact.mjs";
13
- import { isValidPrivateAddress as N } from "../../functions/utils/addresses.mjs";
14
- import { shouldPatchAccessTokenMerkleTree as O } from "../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.mjs";
15
- import { getCurrentTimeInSeconds as $ } from "../../functions/utils/time.utils.mjs";
16
- import { emitTxPublicData as M } from "../../API/admin-calls.mjs";
17
- import { constructAdminData as E } from "../../functions/pre-transaction/constructAdminData.mjs";
18
- const S = async (t, s, e) => {
19
- const { patchAccessTokenMerkleTree: o, kycRequired: r, hasAccessToken: p } = await O(
12
+ import { getSignatureDataForTransact as N } from "../../functions/pre-transaction/getSignatureDataForTransact.mjs";
13
+ import { isValidPrivateAddress as O } from "../../functions/utils/addresses.mjs";
14
+ import { shouldPatchAccessTokenMerkleTree as $ } from "../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.mjs";
15
+ import { getCurrentTimeInSeconds as b } from "../../functions/utils/time.utils.mjs";
16
+ import { emitTxPublicData as E } from "../../API/admin-calls.mjs";
17
+ import { constructAdminData as S } from "../../functions/pre-transaction/constructAdminData.mjs";
18
+ const U = async (t, s, e) => {
19
+ const { patchAccessTokenMerkleTree: n, kycRequired: o, hasAccessToken: r } = await $(
20
20
  t,
21
21
  s,
22
22
  e
23
- ), c = void 0, A = await t.getEthereumAddress(), i = await F(
23
+ ), c = void 0, p = await t.getEthereumAddress(), A = await N(
24
24
  t.getCurrentChainId(),
25
- A,
25
+ p,
26
26
  t.userKeys,
27
- r,
28
- p
29
- ), n = {
27
+ o,
28
+ r
29
+ ), i = {
30
30
  externalActionId: 0n,
31
31
  externalAddress: await t.getEthereumAddress(),
32
32
  externalActionMetadata: "0x00"
33
33
  };
34
34
  return {
35
- signatureData: i,
36
- externalActionData: n,
35
+ signatureData: A,
36
+ externalActionData: i,
37
37
  contractTransaction: c,
38
38
  contractToApprove: c,
39
- patchAccessTokenMerkleTree: o
39
+ patchAccessTokenMerkleTree: n
40
40
  };
41
- }, et = async (t, s, e) => {
42
- const o = s.map((a) => a.erc20TokenAddress), { externalActionData: r, contractTransaction: p, contractToApprove: c, patchAccessTokenMerkleTree: A, signatureData: i } = await S(t, o, e), n = [...await H(t, o, e)], u = `swapperM${e.length.toString()}x${n[0].length}x1`, d = [], x = $().toString();
41
+ }, rt = async (t, s, e, n = !0) => {
42
+ const o = s.map((a) => a.erc20TokenAddress), { externalActionData: r, contractTransaction: c, contractToApprove: p, patchAccessTokenMerkleTree: A, signatureData: i } = await U(t, o, e), u = [...await z(t, o, e)], x = `swapperM${e.length.toString()}x${u[0].length}x1`, d = [], T = b().toString();
43
43
  for (let a = 0; a < o.length; a += 1) {
44
- const { outputUtxos: f } = R(t.userKeys, n[a], e[a], x);
45
- d.push(f);
44
+ const { outputUtxos: w } = H(t.userKeys, u[a], e[a], T);
45
+ d.push(w);
46
46
  }
47
- const { zkCallData: T, circomData: g, dimData: y } = await C(
47
+ const { zkCallData: g, circomData: y, dimData: l } = await P(
48
48
  "v1x1",
49
49
  t.merkleTreeHinkal,
50
50
  t.merkleTreeAccessToken,
51
- n,
51
+ u,
52
52
  d,
53
53
  t.userKeys,
54
- u,
54
+ x,
55
55
  r.externalActionId,
56
56
  r.externalAddress,
57
57
  r.externalActionMetadata,
58
58
  t.generateProofRemotely,
59
- D,
59
+ C,
60
60
  t.getCurrentChainId(),
61
61
  void 0,
62
62
  void 0,
@@ -65,82 +65,84 @@ const S = async (t, s, e) => {
65
65
  void 0,
66
66
  void 0,
67
67
  void 0,
68
- t.getContractWithFetcher(I.HinkalHelperContract),
68
+ t.getContractWithFetcher(K.HinkalHelperContract),
69
69
  i
70
- ), l = await P(
70
+ ), v = await I(
71
71
  t,
72
72
  e,
73
73
  // for volotile tokens: amountChanges != amountOfTokenToApprove
74
74
  s,
75
- T,
76
75
  g,
77
76
  y,
77
+ l,
78
+ p,
78
79
  c,
79
- p
80
- ), v = E(
81
- K.Onboarding,
80
+ n
81
+ ), f = S(
82
+ M.Onboarding,
82
83
  t.getCurrentChainId(),
83
84
  o,
84
85
  e,
85
86
  await t.getEthereumAddress()
86
87
  );
87
- return M(t.getCurrentChainId(), v), l;
88
- }, rt = async (t, s, e, o) => {
89
- const r = s.map((m) => m.erc20TokenAddress), [p, c, A] = o.split(",");
90
- if (!N(o))
91
- throw Error(z.RECIPIENT_FORMAT_INCORRECT);
88
+ return E(t.getCurrentChainId(), f), v;
89
+ }, ot = async (t, s, e, n, o = !0) => {
90
+ const r = s.map((m) => m.erc20TokenAddress), [c, p, A] = n.split(",");
91
+ if (!O(n))
92
+ throw Error(F.RECIPIENT_FORMAT_INCORRECT);
92
93
  const i = r.map((m) => [
93
- new w({ amount: 0n, erc20TokenAddress: m, shieldedPrivateKey: t.userKeys.getShieldedPrivateKey() }),
94
- new w({ amount: 0n, erc20TokenAddress: m, shieldedPrivateKey: t.userKeys.getShieldedPrivateKey() })
95
- ]), n = `swapperM${e.length.toString()}x${i[0].length}x1`, u = r.map((m, U) => [
96
- new w({
97
- amount: e[U],
94
+ new D({ amount: 0n, erc20TokenAddress: m, shieldedPrivateKey: t.userKeys.getShieldedPrivateKey() }),
95
+ new D({ amount: 0n, erc20TokenAddress: m, shieldedPrivateKey: t.userKeys.getShieldedPrivateKey() })
96
+ ]), u = `swapperM${e.length.toString()}x${i[0].length}x1`, x = r.map((m, R) => [
97
+ new D({
98
+ amount: e[R],
98
99
  erc20TokenAddress: m,
99
- randomization: BigInt(p),
100
- stealthAddress: c,
100
+ randomization: BigInt(c),
101
+ stealthAddress: p,
101
102
  encryptionKey: A
102
103
  })
103
- ]), { externalActionData: d, contractTransaction: x, contractToApprove: T, patchAccessTokenMerkleTree: g } = await S(t, r, e), { zkCallData: y, circomData: l, dimData: v } = await C(
104
+ ]), { externalActionData: d, contractTransaction: T, contractToApprove: g, patchAccessTokenMerkleTree: y } = await U(t, r, e), { zkCallData: l, circomData: v, dimData: f } = await P(
104
105
  "v1x1",
105
106
  t.merkleTreeHinkal,
106
107
  t.merkleTreeAccessToken,
107
108
  i,
108
- u,
109
+ x,
109
110
  t.userKeys,
110
- n,
111
+ u,
111
112
  d.externalActionId,
112
113
  d.externalAddress,
113
114
  d.externalActionMetadata,
114
115
  t.generateProofRemotely,
115
- D,
116
+ C,
116
117
  t.getCurrentChainId(),
117
118
  void 0,
118
119
  void 0,
119
120
  void 0,
120
- g,
121
+ y,
121
122
  void 0,
122
123
  void 0,
123
124
  void 0,
124
- t.getContractWithFetcher(I.HinkalHelperContract)
125
- ), a = await P(
125
+ t.getContractWithFetcher(K.HinkalHelperContract)
126
+ ), a = await I(
126
127
  t,
127
128
  e,
128
129
  s,
129
- y,
130
130
  l,
131
131
  v,
132
+ f,
133
+ g,
132
134
  T,
133
- x
134
- ), f = E(
135
- K.PaymentLink,
135
+ o
136
+ ), w = S(
137
+ M.PaymentLink,
136
138
  t.getCurrentChainId(),
137
139
  r,
138
140
  e,
139
141
  await t.getEthereumAddress()
140
142
  );
141
- return M(t.getCurrentChainId(), f), a;
143
+ return E(t.getCurrentChainId(), w), a;
142
144
  };
143
145
  export {
144
- et as hinkalDeposit,
145
- rt as hinkalDepositForOther
146
+ rt as hinkalDeposit,
147
+ ot as hinkalDepositForOther
146
148
  };
@@ -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,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;
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,r,a,A,s,o,l,p)=>{if(a.length===0)throw new Error("userDepositedUtxos must not be empty");const t=r.erc20TokenAddress,c=await e.getRandomRelay();if(!c)throw Error(F.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const n=await e.getEthereumAddress(),i=G.getCurrentTimeInSeconds().toString(),d=e.generateProofRemotely?5:1,u=[];for(let w=0;w<a.length;w+=d){const x=a.slice(w,w+d),S=await Promise.all(x.map(async({recipientAddress:I,utxo:m})=>{const E=[-m.amount],T=new z.Utxo({amount:0n,erc20TokenAddress:t,shieldedPrivateKey:e.userKeys.getShieldedPrivateKey(),timeStamp:i,tokenId:0}),y=[[m,T]],R=[[T]],P=`swapperM1x${y[0].length}x1`,C={externalActionId:0n,externalAddress:I,externalActionMetadata:"0x00"},{patchAccessTokenMerkleTree:_,kycRequired:f,hasAccessToken:U}=await j.shouldPatchAccessTokenMerkleTree(e,[t],E),W=await Z.getSignatureDataForTransact(e.getCurrentChainId(),n,e.userKeys,f,U),k=J.constructAdminData(N.AdminTransactionType.WithdrawOnChainUtxos,e.getCurrentChainId(),[t],[-m.amount],n),{zkCallData:v,circomData:H,dimData:M}=await O.constructZkProof("v1x1",e.merkleTreeHinkal,e.merkleTreeAccessToken,y,R,e.userKeys,P,C.externalActionId,C.externalAddress,C.externalActionMetadata,e.generateProofRemotely,c??b.zeroAddress,e.getCurrentChainId(),void 0,void 0,void 0,_,void 0,void 0,A,e.getContractWithFetcher(B.ContractType.HinkalHelperContract),W,void 0,!1);return{zkCallData:v,dimData:M,circomData:H,adminData:k}}));u.push(...S)}const h=e.getCurrentChainId();await q.safeUpdateDepositAndWithdrawStatus(h,{id:o,hashedEthereumAddress:s,phase:D.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});const g=await K.transactCallRelayerBatch(e.getCurrentChainId(),u,s,l,p);return await q.safeUpdateDepositAndWithdrawStatus(h,{id:o,hashedEthereumAddress:s,phase:D.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:g}),g},X=async(e,r,a,A,s,o,l,p=!0)=>{const t=r.erc20TokenAddress,c=e.getCurrentChainId(),n=Y.hashEthereumAddress(await e.getEthereumAddress()),i=o??await V.getFeeStructure(c,t,[t],L.ExternalActionId.Transact),{userDepositedUtxos:d,statusId:u,depositTxHash:h}=await $.hinkalDepositOnChainUtxos(e,r,a,A,i,n,p);return await Q(e,r,d,i,n,u,s,l),h};exports.hinkalDepositAndWithdraw=X;
@@ -1,4 +1,4 @@
1
1
  import { IHinkal } from './IHinkal';
2
2
  import { ERC20Token } from '../../types';
3
3
  import { FeeStructure } from '../../types/hinkal.types';
4
- export declare const hinkalDepositAndWithdraw: (hinkal: IHinkal, erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string) => Promise<string>;
4
+ export declare const hinkalDepositAndWithdraw: (hinkal: IHinkal, erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, preEstimateGas?: boolean) => Promise<string>;
@@ -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>;