@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.
- package/README.md +4 -1
- package/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.d.ts +4 -4
- package/data-structures/Hinkal/Hinkal.mjs +17 -8
- package/data-structures/Hinkal/IHinkal.d.ts +4 -4
- package/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
- package/data-structures/Hinkal/hinkalDeposit.d.ts +2 -2
- package/data-structures/Hinkal/hinkalDeposit.mjs +67 -65
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.d.ts +1 -1
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.mjs +46 -45
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.d.ts +1 -1
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.mjs +48 -47
- package/data-structures/Hinkal/hinkalDepostAndBridge.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepostAndBridge.d.ts +1 -1
- package/data-structures/Hinkal/hinkalDepostAndBridge.mjs +86 -85
- package/functions/web3/functionCalls/transactCallDirect.cjs +1 -1
- package/functions/web3/functionCalls/transactCallDirect.d.ts +1 -1
- package/functions/web3/functionCalls/transactCallDirect.mjs +30 -29
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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
|
|
2
|
-
import { zeroAddress as
|
|
3
|
-
import { outputUtxoProcessing as
|
|
4
|
-
import { constructZkProof as
|
|
5
|
-
import { addPaddingToUtxos as
|
|
6
|
-
import { transactCallDirect as
|
|
7
|
-
import { ExternalActionId as
|
|
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
|
|
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
|
|
14
|
-
import { shouldPatchAccessTokenMerkleTree as
|
|
15
|
-
import { getUtxosFromReceipt as
|
|
16
|
-
import { calculateTotalFee as
|
|
17
|
-
import { constructAdminData as
|
|
18
|
-
import { emitTxPublicData as
|
|
19
|
-
import { updateDepositAndWithdrawStatus as
|
|
20
|
-
const
|
|
21
|
-
const f = m.erc20TokenAddress, x = await t.getEthereumAddress(), a = O.map((o) => o +
|
|
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
|
-
),
|
|
25
|
+
), H = await Q(
|
|
26
26
|
t.getCurrentChainId(),
|
|
27
27
|
x,
|
|
28
28
|
t.userKeys,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
), r = [...await
|
|
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 } =
|
|
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),
|
|
37
|
-
zkCallData:
|
|
38
|
-
circomData:
|
|
39
|
-
dimData:
|
|
40
|
-
} = await
|
|
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
|
-
|
|
48
|
+
L.DepositOnChainUtxos,
|
|
49
49
|
await g.getAddress(),
|
|
50
|
-
|
|
50
|
+
R,
|
|
51
51
|
t.generateProofRemotely,
|
|
52
|
-
|
|
52
|
+
B,
|
|
53
53
|
t.getCurrentChainId(),
|
|
54
|
-
|
|
54
|
+
I,
|
|
55
55
|
void 0,
|
|
56
56
|
void 0,
|
|
57
|
-
|
|
57
|
+
W,
|
|
58
58
|
void 0,
|
|
59
59
|
void 0,
|
|
60
60
|
void 0,
|
|
61
61
|
t.getContractWithFetcher(p.HinkalHelperContract),
|
|
62
|
-
|
|
62
|
+
H,
|
|
63
63
|
await D.getAddress(),
|
|
64
64
|
!1
|
|
65
|
-
), s = t.getCurrentChainId(), h = (await
|
|
65
|
+
), s = t.getCurrentChainId(), h = (await rt(s, {
|
|
66
66
|
hashedEthereumAddress: u,
|
|
67
67
|
phase: y.BEFORE_DEPOSIT
|
|
68
|
-
})).id ?? void 0, w = await
|
|
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
|
-
|
|
78
|
-
await
|
|
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
|
|
85
|
+
const k = await Y($, t, f), l = [], c = [...k];
|
|
85
86
|
E.forEach((o, e) => {
|
|
86
|
-
const U = a[e], d = c.find((
|
|
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
|
|
94
|
-
c.splice(
|
|
94
|
+
const Z = c.indexOf(d);
|
|
95
|
+
c.splice(Z, 1);
|
|
95
96
|
});
|
|
96
|
-
const
|
|
97
|
-
|
|
97
|
+
const z = ot(
|
|
98
|
+
N.DepositOnChainUtxos,
|
|
98
99
|
s,
|
|
99
100
|
i,
|
|
100
101
|
[A],
|
|
101
102
|
x
|
|
102
103
|
);
|
|
103
|
-
return
|
|
104
|
+
return et(s, z), { userDepositedUtxos: l, statusId: h, depositTxHash: T };
|
|
104
105
|
};
|
|
105
106
|
export {
|
|
106
|
-
|
|
107
|
+
Ot as hinkalDepositOnChainUtxos
|
|
107
108
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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
|
|
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
|
|
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,
|
|
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 =
|
|
60
|
-
if (!
|
|
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
|
|
63
|
-
if (!
|
|
62
|
+
const T = O[U.Lifi][o];
|
|
63
|
+
if (!T)
|
|
64
64
|
throw new Error(`LIFI not configured for chain ${o}`);
|
|
65
|
-
const
|
|
66
|
-
if (!
|
|
65
|
+
const I = await t.getRandomRelay();
|
|
66
|
+
if (!I)
|
|
67
67
|
throw Error(X.RELAYER_NOT_AVAILABLE);
|
|
68
|
-
const
|
|
69
|
-
for (let
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
await dt.addTemporaryWalletNonce(o,
|
|
73
|
-
const q =
|
|
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:
|
|
77
|
+
timeStamp: E,
|
|
78
78
|
tokenId: 0
|
|
79
|
-
}),
|
|
80
|
-
if (q &&
|
|
79
|
+
}), S = [[e, L]], b = [[L]];
|
|
80
|
+
if (q && r) {
|
|
81
81
|
const K = new N({
|
|
82
82
|
amount: 0n,
|
|
83
|
-
erc20TokenAddress:
|
|
83
|
+
erc20TokenAddress: d,
|
|
84
84
|
shieldedPrivateKey: t.userKeys.getShieldedPrivateKey(),
|
|
85
|
-
timeStamp:
|
|
85
|
+
timeStamp: E,
|
|
86
86
|
tokenId: 0
|
|
87
87
|
});
|
|
88
|
-
|
|
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
|
-
|
|
93
|
-
|
|
92
|
+
F.ethAddress,
|
|
93
|
+
T,
|
|
94
94
|
i,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
e.amount,
|
|
96
|
+
A,
|
|
97
|
+
c
|
|
98
98
|
), { patchAccessTokenMerkleTree: V, kycRequired: Y, hasAccessToken: Z } = await st(
|
|
99
99
|
t,
|
|
100
|
-
|
|
100
|
+
l,
|
|
101
101
|
k
|
|
102
102
|
), $ = await rt(
|
|
103
103
|
o,
|
|
104
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
l,
|
|
113
|
+
l.map(() => 0),
|
|
114
|
+
S,
|
|
115
115
|
b,
|
|
116
116
|
t.userKeys,
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
l.length,
|
|
118
|
+
S[0].length,
|
|
119
|
+
a,
|
|
120
120
|
M,
|
|
121
121
|
t.generateProofRemotely,
|
|
122
|
-
|
|
122
|
+
I ?? d,
|
|
123
123
|
o,
|
|
124
124
|
P,
|
|
125
125
|
void 0,
|
|
126
|
-
|
|
126
|
+
F.privateKey,
|
|
127
127
|
void 0,
|
|
128
128
|
V,
|
|
129
129
|
void 0,
|
|
130
|
-
|
|
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(...
|
|
139
|
+
v.push(...x);
|
|
140
140
|
}
|
|
141
141
|
await _(o, {
|
|
142
|
-
id:
|
|
143
|
-
hashedEthereumAddress:
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
n,
|
|
150
|
+
D,
|
|
151
|
+
m
|
|
152
152
|
);
|
|
153
153
|
return await _(o, {
|
|
154
|
-
id:
|
|
155
|
-
hashedEthereumAddress:
|
|
154
|
+
id: h,
|
|
155
|
+
hashedEthereumAddress: n,
|
|
156
156
|
phase: W.AFTER_SCHEDULE_WITHDRAW,
|
|
157
157
|
scheduleId: y
|
|
158
158
|
}), y;
|
|
159
|
-
}, Ae = async (t,
|
|
160
|
-
const
|
|
161
|
-
if (!
|
|
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
|
|
164
|
-
if (
|
|
165
|
-
|
|
163
|
+
let a;
|
|
164
|
+
if (n)
|
|
165
|
+
a = n;
|
|
166
166
|
else {
|
|
167
|
-
const e = s[0],
|
|
167
|
+
const e = s[0], A = B(
|
|
168
168
|
t,
|
|
169
169
|
e.temporarySubAccount.ethAddress,
|
|
170
|
-
|
|
171
|
-
|
|
170
|
+
g,
|
|
171
|
+
m,
|
|
172
172
|
e.bridgeAmount,
|
|
173
173
|
e.bridgeAmount,
|
|
174
174
|
e.quote
|
|
175
175
|
).map(
|
|
176
|
-
(
|
|
176
|
+
(c) => ct(c, e.temporarySubAccount.ethAddress, i)
|
|
177
177
|
);
|
|
178
|
-
|
|
178
|
+
a = await at(i, m, [m], U.Emporium, A);
|
|
179
179
|
}
|
|
180
|
-
const
|
|
181
|
-
feeToken:
|
|
180
|
+
const T = {
|
|
181
|
+
feeToken: a.feeToken,
|
|
182
182
|
flatFee: 0n,
|
|
183
183
|
variableRate: 0n
|
|
184
|
-
},
|
|
185
|
-
userDepositedUtxos:
|
|
186
|
-
statusId:
|
|
187
|
-
depositTxHash:
|
|
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
|
-
|
|
192
|
-
|
|
193
|
-
n,
|
|
194
|
-
i
|
|
193
|
+
a,
|
|
194
|
+
o
|
|
195
195
|
);
|
|
196
|
-
let
|
|
197
|
-
if (
|
|
198
|
-
const e = pt(
|
|
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((
|
|
201
|
+
const r = s.map((c) => c.quote.nativeFee), { userDepositedUtxos: A } = await H(
|
|
202
202
|
t,
|
|
203
203
|
e,
|
|
204
204
|
r,
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
205
|
+
f,
|
|
206
|
+
T,
|
|
207
|
+
o,
|
|
208
|
+
D
|
|
208
209
|
);
|
|
209
|
-
|
|
210
|
+
R = A;
|
|
210
211
|
}
|
|
211
|
-
const
|
|
212
|
+
const x = s.map((e, r) => ({
|
|
212
213
|
...e,
|
|
213
|
-
utxo:
|
|
214
|
-
nativeUtxo:
|
|
214
|
+
utxo: v[r].utxo,
|
|
215
|
+
nativeUtxo: w ? R[r]?.utxo : void 0
|
|
215
216
|
}));
|
|
216
217
|
return await ut(
|
|
217
218
|
t,
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
),
|
|
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
|
|
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
|
|
1
|
+
import { ethers as F } from "ethers";
|
|
2
2
|
import { zeroAddress as T } from "../../../constants/protocol.constants.mjs";
|
|
3
|
-
import { ContractType as
|
|
4
|
-
import { waitLittle as
|
|
5
|
-
import { approveTokensToHinkal as
|
|
6
|
-
import { buildApproveAndTransactCalls as
|
|
7
|
-
import { recoverTransactionFromError as
|
|
8
|
-
import { getContractAddress as
|
|
9
|
-
const
|
|
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
|
|
14
|
-
if (
|
|
15
|
-
const t = o.map((
|
|
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
|
-
|
|
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
|
|
28
|
-
const
|
|
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
|
-
{ ...
|
|
38
|
+
{ ...C, from: b }
|
|
39
39
|
], { runner: i } = a;
|
|
40
|
-
if (!(i instanceof
|
|
40
|
+
if (!(i instanceof F.AbstractSigner))
|
|
41
41
|
throw new Error("expected signer");
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
|
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
|
-
|
|
68
|
+
U as transactCallDirect
|
|
68
69
|
};
|