@hinkal/common 0.2.25 → 0.2.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -14
- 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 +83 -79
- 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/snarkjs/getZKFiles.cjs +1 -1
- package/functions/snarkjs/getZKFiles.mjs +8 -11
- package/functions/web3/functionCalls/transactCallDirect.cjs +1 -1
- package/functions/web3/functionCalls/transactCallDirect.d.ts +1 -1
- package/functions/web3/functionCalls/transactCallDirect.mjs +52 -50
- package/package.json +1 -1
|
@@ -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,
|
|
21
|
-
if (
|
|
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
|
|
24
|
-
if (!
|
|
23
|
+
const e = r.erc20TokenAddress, i = await t.getRandomRelay();
|
|
24
|
+
if (!i)
|
|
25
25
|
throw Error(F.RELAYER_NOT_AVAILABLE);
|
|
26
|
-
const
|
|
27
|
-
for (let
|
|
28
|
-
const I =
|
|
29
|
-
I.map(async ({ recipientAddress: D, utxo:
|
|
30
|
-
const R = [-
|
|
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:
|
|
32
|
+
erc20TokenAddress: e,
|
|
33
33
|
shieldedPrivateKey: t.userKeys.getShieldedPrivateKey(),
|
|
34
|
-
timeStamp:
|
|
34
|
+
timeStamp: c,
|
|
35
35
|
tokenId: 0
|
|
36
|
-
}), T = [[
|
|
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, [
|
|
44
|
+
} = await Y(t, [e], R), W = await V(
|
|
45
45
|
t.getCurrentChainId(),
|
|
46
|
-
|
|
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
|
-
[
|
|
54
|
-
[-
|
|
55
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
C.externalActionId,
|
|
65
|
+
C.externalAddress,
|
|
66
|
+
C.externalActionMetadata,
|
|
67
67
|
t.generateProofRemotely,
|
|
68
|
-
|
|
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
|
-
|
|
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
|
|
93
|
-
await x(
|
|
94
|
-
id:
|
|
95
|
-
hashedEthereumAddress:
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
a,
|
|
102
|
+
h,
|
|
103
|
+
A
|
|
104
104
|
);
|
|
105
|
-
return await x(
|
|
106
|
-
id:
|
|
107
|
-
hashedEthereumAddress:
|
|
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,
|
|
112
|
-
const
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
115
|
+
o,
|
|
116
|
+
w,
|
|
117
|
+
c,
|
|
118
|
+
s,
|
|
119
|
+
A
|
|
119
120
|
);
|
|
120
121
|
return await Q(
|
|
121
122
|
t,
|
|
122
|
-
|
|
123
|
-
h,
|
|
124
|
-
n,
|
|
125
|
-
s,
|
|
123
|
+
r,
|
|
126
124
|
d,
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
|
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>;
|