@hinkal/common 0.2.25 → 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 +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>;
@@ -1,8 +1,8 @@
1
- import { zeroAddress as u } from "../../constants/protocol.constants.mjs";
1
+ import { zeroAddress as d } 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
- import { ExternalActionId as S } from "../../types/external-action.types.mjs";
5
+ import { ExternalActionId as U } from "../../types/external-action.types.mjs";
6
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";
@@ -53,55 +53,55 @@ import "../../API/tenderly.api.mjs";
53
53
  import { hinkalDepositOnChainUtxos as H } from "./hinkalDepositOnChainUtxos.mjs";
54
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, f, s, R, a, T, c, d) => {
56
+ const ut = async (t, u, s, C, n, h, D, m) => {
57
57
  if (s.length === 0)
58
58
  throw new Error("No recipients to bridge");
59
- const i = f.erc20TokenAddress, o = t.getCurrentChainId(), { contractData: n } = mt[o], { emporiumAddress: w } = n;
60
- if (!w)
59
+ const i = u.erc20TokenAddress, o = t.getCurrentChainId(), { contractData: g } = mt[o], { emporiumAddress: a } = g;
60
+ if (!a)
61
61
  throw Error("No Emporium Address");
62
- const C = O[S.Lifi][o];
63
- if (!C)
62
+ const T = O[U.Lifi][o];
63
+ if (!T)
64
64
  throw new Error(`LIFI not configured for chain ${o}`);
65
- const A = await t.getRandomRelay();
66
- if (!A)
65
+ const I = await t.getRandomRelay();
66
+ if (!I)
67
67
  throw Error(X.RELAYER_NOT_AVAILABLE);
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({
68
+ const w = await t.getEthereumAddress(), E = it().toString(), f = t.generateProofRemotely ? 5 : 1, v = [];
69
+ for (let p = 0; p < s.length; p += f) {
70
+ const R = s.slice(p, p + f), x = await Promise.all(
71
+ R.map(async ({ utxo: e, nativeUtxo: r, bridgeAmount: A, quote: c, temporarySubAccount: F }) => {
72
+ await dt.addTemporaryWalletNonce(o, n, F.index);
73
+ const q = c.nativeFee > 0n && !z(i, d), l = [i], k = [-e.amount], P = [!1], L = new N({
74
74
  amount: 0n,
75
75
  erc20TokenAddress: i,
76
76
  shieldedPrivateKey: t.userKeys.getShieldedPrivateKey(),
77
- timeStamp: l,
77
+ timeStamp: E,
78
78
  tokenId: 0
79
- }), F = [[r, L]], b = [[L]];
80
- if (q && p) {
79
+ }), S = [[e, L]], b = [[L]];
80
+ if (q && r) {
81
81
  const K = new N({
82
82
  amount: 0n,
83
- erc20TokenAddress: u,
83
+ erc20TokenAddress: d,
84
84
  shieldedPrivateKey: t.userKeys.getShieldedPrivateKey(),
85
- timeStamp: l,
85
+ timeStamp: E,
86
86
  tokenId: 0
87
87
  });
88
- g.push(u), k.push(-p.amount), P.push(!1), F.push([p, K]), b.push([K]);
88
+ l.push(d), k.push(-r.amount), P.push(!1), S.push([r, K]), b.push([K]);
89
89
  }
90
90
  const M = B(
91
91
  t,
92
- x.ethAddress,
93
- C,
92
+ F.ethAddress,
93
+ T,
94
94
  i,
95
- r.amount,
96
- h,
97
- U
95
+ e.amount,
96
+ A,
97
+ c
98
98
  ), { patchAccessTokenMerkleTree: V, kycRequired: Y, hasAccessToken: Z } = await st(
99
99
  t,
100
- g,
100
+ l,
101
101
  k
102
102
  ), $ = await rt(
103
103
  o,
104
- D,
104
+ w,
105
105
  t.userKeys,
106
106
  Y,
107
107
  Z
@@ -109,25 +109,25 @@ const ut = async (t, f, s, R, a, T, c, d) => {
109
109
  "v1x1",
110
110
  t.merkleTreeHinkal,
111
111
  t.merkleTreeAccessToken,
112
- g,
113
- g.map(() => 0),
114
- F,
112
+ l,
113
+ l.map(() => 0),
114
+ S,
115
115
  b,
116
116
  t.userKeys,
117
- g.length,
118
- F[0].length,
119
- w,
117
+ l.length,
118
+ S[0].length,
119
+ a,
120
120
  M,
121
121
  t.generateProofRemotely,
122
- A ?? u,
122
+ I ?? d,
123
123
  o,
124
124
  P,
125
125
  void 0,
126
- x.privateKey,
126
+ F.privateKey,
127
127
  void 0,
128
128
  V,
129
129
  void 0,
130
- R,
130
+ C,
131
131
  t.getContractWithFetcher(ot.HinkalHelperContract),
132
132
  $,
133
133
  void 0,
@@ -136,93 +136,94 @@ const ut = async (t, f, s, R, a, T, c, d) => {
136
136
  return { zkCallData: j, dimData: J, circomData: G, authorizationData: Q };
137
137
  })
138
138
  );
139
- v.push(...e);
139
+ v.push(...x);
140
140
  }
141
141
  await _(o, {
142
- id: T,
143
- hashedEthereumAddress: a,
142
+ id: h,
143
+ hashedEthereumAddress: n,
144
144
  phase: W.BEFORE_SCHEDULE_WITHDRAW
145
145
  });
146
146
  const y = await et(
147
147
  o,
148
148
  v,
149
- a,
150
- c,
151
- d
149
+ n,
150
+ D,
151
+ m
152
152
  );
153
153
  return await _(o, {
154
- id: T,
155
- hashedEthereumAddress: a,
154
+ id: h,
155
+ hashedEthereumAddress: n,
156
156
  phase: W.AFTER_SCHEDULE_WITHDRAW,
157
157
  scheduleId: y
158
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
- if (!o)
159
+ }, Ae = async (t, u, s, C, n, h, D = !0) => {
160
+ const m = u.erc20TokenAddress, i = t.getCurrentChainId(), o = nt(await t.getEthereumAddress()), g = O[U.Lifi][i];
161
+ if (!g)
162
162
  throw Error("LIFI router not configured");
163
- let n;
164
- if (a)
165
- n = a;
163
+ let a;
164
+ if (n)
165
+ a = n;
166
166
  else {
167
- const e = s[0], p = B(
167
+ const e = s[0], A = B(
168
168
  t,
169
169
  e.temporarySubAccount.ethAddress,
170
- o,
171
- c,
170
+ g,
171
+ m,
172
172
  e.bridgeAmount,
173
173
  e.bridgeAmount,
174
174
  e.quote
175
175
  ).map(
176
- (h) => ct(h, e.temporarySubAccount.ethAddress, d)
176
+ (c) => ct(c, e.temporarySubAccount.ethAddress, i)
177
177
  );
178
- n = await at(d, c, [c], S.Emporium, p);
178
+ a = await at(i, m, [m], U.Emporium, A);
179
179
  }
180
- const w = {
181
- feeToken: n.feeToken,
180
+ const T = {
181
+ feeToken: a.feeToken,
182
182
  flatFee: 0n,
183
183
  variableRate: 0n
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
184
+ }, w = s.reduce((e, r) => e + r.quote.nativeFee, 0n) > 0n && !z(m, d), E = s.map((e) => e.bridgeAmount), f = s.map((e) => e.recipientAddress), {
185
+ userDepositedUtxos: v,
186
+ statusId: y,
187
+ depositTxHash: p
188
188
  } = await H(
189
189
  t,
190
+ u,
191
+ E,
190
192
  f,
191
- D,
192
- l,
193
- n,
194
- i
193
+ a,
194
+ o
195
195
  );
196
- let m = [];
197
- if (A) {
198
- const e = pt(u, d);
196
+ let R = [];
197
+ if (w) {
198
+ const e = pt(d, i);
199
199
  if (!e)
200
200
  throw Error("No native token");
201
- const r = s.map((h) => h.quote.nativeFee), { userDepositedUtxos: p } = await H(
201
+ const r = s.map((c) => c.quote.nativeFee), { userDepositedUtxos: A } = await H(
202
202
  t,
203
203
  e,
204
204
  r,
205
- l,
206
- w,
207
- i
205
+ f,
206
+ T,
207
+ o,
208
+ D
208
209
  );
209
- m = p;
210
+ R = A;
210
211
  }
211
- const I = s.map((e, r) => ({
212
+ const x = s.map((e, r) => ({
212
213
  ...e,
213
- utxo: E[r].utxo,
214
- nativeUtxo: A ? m[r]?.utxo : void 0
214
+ utxo: v[r].utxo,
215
+ nativeUtxo: w ? R[r]?.utxo : void 0
215
216
  }));
216
217
  return await ut(
217
218
  t,
218
- f,
219
- I,
220
- n,
221
- i,
222
- v,
223
- R,
224
- T
225
- ), y;
219
+ u,
220
+ x,
221
+ a,
222
+ o,
223
+ y,
224
+ C,
225
+ h
226
+ ), p;
226
227
  };
227
228
  export {
228
229
  Ae as hinkalDepositAndBridge
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("ethers"),f=require("../../../constants/protocol.constants.cjs"),I=require("../../../types/ethereum-network.types.cjs"),S=require("../../utils/time.utils.cjs"),F=require("./approveTokensToHinkal.cjs"),N=require("./constructBatchCall.cjs"),_=require("./recoverTransactionFromError.cjs"),z=require("../../utils/getContractAddress.cjs"),G=async(r,d,l,s,p,A,q,x)=>{const n=Array.isArray(d)?d:[d],e=Array.isArray(l)?l:[l];if(n.length!==e.length)throw new Error("token and amount length mismatch");const w=r.getContractWithSigner(I.ContractType.HinkalContract),b=await r.getEthereumAddress(),v=q??w,a=x??w,m="transact",C=e.findIndex(({erc20TokenAddress:t})=>t===f.zeroAddress),k=e.some(({erc20TokenAddress:t})=>t!==f.zeroAddress),h=C===-1?0n:n[C],g=r.getProviderAdapter();if(k&&await g.supportsBatchCall?.()&&g.sendBatchCallsTransaction){const t=e.map(B=>B.erc20TokenAddress),i=await N.buildApproveAndTransactCalls(t,n,z.getContractAddress(v),a,s,A,p,h);return await g.sendBatchCallsTransaction(i)}await F.approveTokensToHinkal(r,v,e,n);const T={value:h>0n?BigInt(h).toString():void 0};let o;const y=[s[0],s[1],s[2],A,p,{...T,from:b}],{runner:c}=a;if(!(c instanceof E.ethers.AbstractSigner))throw new Error("expected signer");try{o=Number(await a[m].estimateGas(...y)),console.log({gasCosts:o}),console.log({signerAddress:await c.getAddress(),chainIdHinkal:r.getCurrentChainId(),ethersNetwork:await c.provider.getNetwork()})}catch(t){console.log("hinkalDeposit: gas estimation error",{err:t})}const H=o&&o>=0?Math.ceil(o*12/10):void 0;T.gasLimit=H,await S.waitLittle();let u;try{u=await a[m](...y)}catch(t){if(!t?.transactionHash)throw t;const i=await _.recoverTransactionFromError(c.provider,t.transactionHash);if(!i)throw t;u=i}return u};exports.transactCallDirect=G;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("ethers"),f=require("../../../constants/protocol.constants.cjs"),S=require("../../../types/ethereum-network.types.cjs"),F=require("../../utils/time.utils.cjs"),N=require("./approveTokensToHinkal.cjs"),_=require("./constructBatchCall.cjs"),z=require("./recoverTransactionFromError.cjs"),G=require("../../utils/getContractAddress.cjs"),L=async(r,d,l,s,p,A,q,x,b=!0)=>{const n=Array.isArray(d)?d:[d],e=Array.isArray(l)?l:[l];if(n.length!==e.length)throw new Error("token and amount length mismatch");const w=r.getContractWithSigner(S.ContractType.HinkalContract),k=await r.getEthereumAddress(),v=q??w,a=x??w,m="transact",C=e.findIndex(({erc20TokenAddress:t})=>t===f.zeroAddress),H=e.some(({erc20TokenAddress:t})=>t!==f.zeroAddress),h=C===-1?0n:n[C],u=r.getProviderAdapter();if(H&&await u.supportsBatchCall?.()&&u.sendBatchCallsTransaction){const t=e.map(E=>E.erc20TokenAddress),i=await _.buildApproveAndTransactCalls(t,n,G.getContractAddress(v),a,s,A,p,h);return await u.sendBatchCallsTransaction(i)}await N.approveTokensToHinkal(r,v,e,n);const T={value:h>0n?BigInt(h).toString():void 0};let o;const y=[s[0],s[1],s[2],A,p,{...T,from:k}],{runner:c}=a;if(!(c instanceof I.ethers.AbstractSigner))throw new Error("expected signer");if(b)try{o=Number(await a[m].estimateGas(...y)),console.log({gasCosts:o}),console.log({signerAddress:await c.getAddress(),chainIdHinkal:r.getCurrentChainId(),ethersNetwork:await c.provider.getNetwork()})}catch(t){console.log("hinkalDeposit: gas estimation error",{err:t})}const B=o&&o>=0?Math.ceil(o*12/10):void 0;T.gasLimit=B,await F.waitLittle();let g;try{g=await a[m](...y)}catch(t){if(!t?.transactionHash)throw t;const i=await z.recoverTransactionFromError(c.provider,t.transactionHash);if(!i)throw t;g=i}return g};exports.transactCallDirect=L;
@@ -3,4 +3,4 @@ import { IHinkal } from '../../../data-structures/Hinkal/IHinkal';
3
3
  import { CircomDataBaseType, DimDataType } from '../../../types/circom-data.types';
4
4
  import { ERC20Token } from '../../../types/token.types';
5
5
  import { NewZkCallDataType } from '../../../types/snark.types';
6
- export declare const transactCallDirect: (hinkal: IHinkal, amount: bigint | bigint[], tokenToApprove: ERC20Token | ERC20Token[], newZkCallData: NewZkCallDataType, circomData: CircomDataBaseType, dimData: DimDataType, contractApproval?: ethers.Contract, contractTransaction?: ethers.Contract) => Promise<any>;
6
+ export declare const transactCallDirect: (hinkal: IHinkal, amount: bigint | bigint[], tokenToApprove: ERC20Token | ERC20Token[], newZkCallData: NewZkCallDataType, circomData: CircomDataBaseType, dimData: DimDataType, contractApproval?: ethers.Contract, contractTransaction?: ethers.Contract, preEstimateGas?: boolean) => Promise<any>;
@@ -1,21 +1,21 @@
1
- import { ethers as k } from "ethers";
1
+ import { ethers as F } from "ethers";
2
2
  import { zeroAddress as T } from "../../../constants/protocol.constants.mjs";
3
- import { ContractType as F } from "../../../types/ethereum-network.types.mjs";
4
- import { waitLittle as N } from "../../utils/time.utils.mjs";
5
- import { approveTokensToHinkal as S } from "./approveTokensToHinkal.mjs";
6
- import { buildApproveAndTransactCalls as G } from "./constructBatchCall.mjs";
7
- import { recoverTransactionFromError as L } from "./recoverTransactionFromError.mjs";
8
- import { getContractAddress as z } from "../../utils/getContractAddress.mjs";
9
- const R = async (r, d, m, s, g, A, y, H) => {
3
+ import { ContractType as N } from "../../../types/ethereum-network.types.mjs";
4
+ import { waitLittle as S } from "../../utils/time.utils.mjs";
5
+ import { approveTokensToHinkal as G } from "./approveTokensToHinkal.mjs";
6
+ import { buildApproveAndTransactCalls as L } from "./constructBatchCall.mjs";
7
+ import { recoverTransactionFromError as z } from "./recoverTransactionFromError.mjs";
8
+ import { getContractAddress as M } from "../../utils/getContractAddress.mjs";
9
+ const U = async (r, d, m, s, g, A, y, H, I = !0) => {
10
10
  const n = Array.isArray(d) ? d : [d], o = Array.isArray(m) ? m : [m];
11
11
  if (n.length !== o.length)
12
12
  throw new Error("token and amount length mismatch");
13
- const w = r.getContractWithSigner(F.HinkalContract), I = await r.getEthereumAddress(), f = y ?? w, a = H ?? w, v = "transact", C = o.findIndex(({ erc20TokenAddress: t }) => t === T), b = o.some(({ erc20TokenAddress: t }) => t !== T), l = C === -1 ? 0n : n[C], p = r.getProviderAdapter();
14
- if (b && await p.supportsBatchCall?.() && p.sendBatchCallsTransaction) {
15
- const t = o.map((E) => E.erc20TokenAddress), c = await G(
13
+ const f = r.getContractWithSigner(N.HinkalContract), b = await r.getEthereumAddress(), w = y ?? f, a = H ?? f, v = "transact", u = o.findIndex(({ erc20TokenAddress: t }) => t === T), B = o.some(({ erc20TokenAddress: t }) => t !== T), l = u === -1 ? 0n : n[u], p = r.getProviderAdapter();
14
+ if (B && await p.supportsBatchCall?.() && p.sendBatchCallsTransaction) {
15
+ const t = o.map((k) => k.erc20TokenAddress), c = await L(
16
16
  t,
17
17
  n,
18
- z(f),
18
+ M(w),
19
19
  a,
20
20
  s,
21
21
  A,
@@ -24,8 +24,8 @@ const R = async (r, d, m, s, g, A, y, H) => {
24
24
  );
25
25
  return await p.sendBatchCallsTransaction(c);
26
26
  }
27
- await S(r, f, o, n);
28
- const u = {
27
+ await G(r, w, o, n);
28
+ const C = {
29
29
  value: l > 0n ? BigInt(l).toString() : void 0
30
30
  };
31
31
  let e;
@@ -35,28 +35,29 @@ const R = async (r, d, m, s, g, A, y, H) => {
35
35
  s[2],
36
36
  A,
37
37
  g,
38
- { ...u, from: I }
38
+ { ...C, from: b }
39
39
  ], { runner: i } = a;
40
- if (!(i instanceof k.AbstractSigner))
40
+ if (!(i instanceof F.AbstractSigner))
41
41
  throw new Error("expected signer");
42
- try {
43
- e = Number(await a[v].estimateGas(...x)), console.log({ gasCosts: e }), console.log({
44
- signerAddress: await i.getAddress(),
45
- chainIdHinkal: r.getCurrentChainId(),
46
- ethersNetwork: await i.provider.getNetwork()
47
- });
48
- } catch (t) {
49
- console.log("hinkalDeposit: gas estimation error", { err: t });
50
- }
51
- const B = e && e >= 0 ? Math.ceil(e * 12 / 10) : void 0;
52
- u.gasLimit = B, await N();
42
+ if (I)
43
+ try {
44
+ e = Number(await a[v].estimateGas(...x)), console.log({ gasCosts: e }), console.log({
45
+ signerAddress: await i.getAddress(),
46
+ chainIdHinkal: r.getCurrentChainId(),
47
+ ethersNetwork: await i.provider.getNetwork()
48
+ });
49
+ } catch (t) {
50
+ console.log("hinkalDeposit: gas estimation error", { err: t });
51
+ }
52
+ const E = e && e >= 0 ? Math.ceil(e * 12 / 10) : void 0;
53
+ C.gasLimit = E, await S();
53
54
  let h;
54
55
  try {
55
56
  h = await a[v](...x);
56
57
  } catch (t) {
57
58
  if (!t?.transactionHash)
58
59
  throw t;
59
- const c = await L(i.provider, t.transactionHash);
60
+ const c = await z(i.provider, t.transactionHash);
60
61
  if (!c)
61
62
  throw t;
62
63
  h = c;
@@ -64,5 +65,5 @@ const R = async (r, d, m, s, g, A, y, H) => {
64
65
  return h;
65
66
  };
66
67
  export {
67
- R as transactCallDirect
68
+ U as transactCallDirect
68
69
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hinkal/common",
3
- "version": "0.2.25",
3
+ "version": "0.2.26",
4
4
  "homepage": "hinkal.io",
5
5
  "author": {
6
6
  "name": "Hinkal Protocol"