@hinkal/common 0.2.23 → 0.2.24
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/data-structures/Hinkal/hinkalDepositAndWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.mjs +26 -26
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.d.ts +1 -0
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.mjs +25 -25
- package/data-structures/Hinkal/hinkalDepostAndBridge.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepostAndBridge.mjs +84 -80
- package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.mjs +41 -41
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("../../constants/protocol.constants.cjs"),F=require("../../error-handling/error-codes.constants.cjs"),O=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),K=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),L=require("../../types/external-action.types.cjs"),z=require("../utxo/Utxo.cjs");require("../../types/circom-data.types.cjs");const B=require("../../types/ethereum-network.types.cjs"),N=require("../../types/admin.types.cjs");require("../../types/activities.types.cjs");const D=require("../../types/scheduled-transactions.types.cjs"),Z=require("../../functions/pre-transaction/getSignatureDataForTransact.cjs"),j=require("../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs"),G=require("../../functions/utils/time.utils.cjs"),V=require("../../functions/pre-transaction/getFeeStructure.cjs"),Y=require("../../functions/utils/addresses.cjs"),$=require("./hinkalDepositOnChainUtxos.cjs"),J=require("../../functions/pre-transaction/constructAdminData.cjs"),q=require("../../API/deposit-and-withdraw-status-calls.cjs"),Q=async(e,t,r,
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("../../constants/protocol.constants.cjs"),F=require("../../error-handling/error-codes.constants.cjs"),O=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),K=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),L=require("../../types/external-action.types.cjs"),z=require("../utxo/Utxo.cjs");require("../../types/circom-data.types.cjs");const B=require("../../types/ethereum-network.types.cjs"),N=require("../../types/admin.types.cjs");require("../../types/activities.types.cjs");const D=require("../../types/scheduled-transactions.types.cjs"),Z=require("../../functions/pre-transaction/getSignatureDataForTransact.cjs"),j=require("../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs"),G=require("../../functions/utils/time.utils.cjs"),V=require("../../functions/pre-transaction/getFeeStructure.cjs"),Y=require("../../functions/utils/addresses.cjs"),$=require("./hinkalDepositOnChainUtxos.cjs"),J=require("../../functions/pre-transaction/constructAdminData.cjs"),q=require("../../API/deposit-and-withdraw-status-calls.cjs"),Q=async(e,t,r,w,a,c,A,i)=>{if(r.length===0)throw new Error("userDepositedUtxos must not be empty");const s=t.erc20TokenAddress,n=await e.getRandomRelay();if(!n)throw Error(F.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const o=await e.getEthereumAddress(),l=G.getCurrentTimeInSeconds().toString(),d=e.generateProofRemotely?5:1,u=[];for(let h=0;h<r.length;h+=d){const x=r.slice(h,h+d),S=await Promise.all(x.map(async({recipientAddress:I,utxo:p})=>{const E=[-p.amount],T=new z.Utxo({amount:0n,erc20TokenAddress:s,shieldedPrivateKey:e.userKeys.getShieldedPrivateKey(),timeStamp:l,tokenId:0}),y=[[p,T]],R=[[T]],P=`swapperM1x${y[0].length}x1`,m={externalActionId:0n,externalAddress:I,externalActionMetadata:"0x00"},{patchAccessTokenMerkleTree:_,kycRequired:f,hasAccessToken:U}=await j.shouldPatchAccessTokenMerkleTree(e,[s],E),W=await Z.getSignatureDataForTransact(e.getCurrentChainId(),o,e.userKeys,f,U),k=J.constructAdminData(N.AdminTransactionType.WithdrawOnChainUtxos,e.getCurrentChainId(),[s],[-p.amount],o),{zkCallData:v,circomData:H,dimData:M}=await O.constructZkProof("v1x1",e.merkleTreeHinkal,e.merkleTreeAccessToken,y,R,e.userKeys,P,m.externalActionId,m.externalAddress,m.externalActionMetadata,e.generateProofRemotely,n??b.zeroAddress,e.getCurrentChainId(),void 0,void 0,void 0,_,void 0,void 0,w,e.getContractWithFetcher(B.ContractType.HinkalHelperContract),W,void 0,!1);return{zkCallData:v,dimData:M,circomData:H,adminData:k}}));u.push(...S)}const C=e.getCurrentChainId();await q.safeUpdateDepositAndWithdrawStatus(C,{id:c,hashedEthereumAddress:a,phase:D.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});const g=await K.transactCallRelayerBatch(e.getCurrentChainId(),u,a,A,i);return await q.safeUpdateDepositAndWithdrawStatus(C,{id:c,hashedEthereumAddress:a,phase:D.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:g}),g},X=async(e,t,r,w,a,c,A)=>{const i=t.erc20TokenAddress,s=e.getCurrentChainId(),n=Y.hashEthereumAddress(await e.getEthereumAddress()),o=c??await V.getFeeStructure(s,i,[i],L.ExternalActionId.Transact),{userDepositedUtxos:l,statusId:d,depositTxHash:u}=await $.hinkalDepositOnChainUtxos(e,t,r,w,o,n);return await Q(e,t,l,o,n,d,a,A),u};exports.hinkalDepositAndWithdraw=X;
|
|
@@ -17,36 +17,36 @@ import { hashEthereumAddress as j } from "../../functions/utils/addresses.mjs";
|
|
|
17
17
|
import { hinkalDepositOnChainUtxos as G } from "./hinkalDepositOnChainUtxos.mjs";
|
|
18
18
|
import { constructAdminData as J } from "../../functions/pre-transaction/constructAdminData.mjs";
|
|
19
19
|
import { safeUpdateDepositAndWithdrawStatus as x } from "../../API/deposit-and-withdraw-status-calls.mjs";
|
|
20
|
-
const Q = async (t, e, r,
|
|
20
|
+
const Q = async (t, e, r, u, o, i, w, c) => {
|
|
21
21
|
if (r.length === 0)
|
|
22
22
|
throw new Error("userDepositedUtxos must not be empty");
|
|
23
23
|
const a = e.erc20TokenAddress, s = await t.getRandomRelay();
|
|
24
24
|
if (!s)
|
|
25
25
|
throw Error(F.RELAYER_NOT_AVAILABLE);
|
|
26
|
-
const n = await t.getEthereumAddress(),
|
|
27
|
-
for (let
|
|
28
|
-
const I = r.slice(
|
|
26
|
+
const n = await t.getEthereumAddress(), h = Z().toString(), d = t.generateProofRemotely ? 5 : 1, m = [];
|
|
27
|
+
for (let p = 0; p < r.length; p += d) {
|
|
28
|
+
const I = r.slice(p, p + d), E = await Promise.all(
|
|
29
29
|
I.map(async ({ recipientAddress: D, utxo: A }) => {
|
|
30
30
|
const R = [-A.amount], l = new B({
|
|
31
31
|
amount: 0n,
|
|
32
32
|
erc20TokenAddress: a,
|
|
33
33
|
shieldedPrivateKey: t.userKeys.getShieldedPrivateKey(),
|
|
34
|
-
timeStamp:
|
|
34
|
+
timeStamp: h,
|
|
35
35
|
tokenId: 0
|
|
36
|
-
}), T = [[A, l]], S = [[l]], v = `swapperM1x${T[0].length}x1`,
|
|
36
|
+
}), T = [[A, l]], S = [[l]], v = `swapperM1x${T[0].length}x1`, f = {
|
|
37
37
|
externalActionId: 0n,
|
|
38
38
|
externalAddress: D,
|
|
39
39
|
externalActionMetadata: "0x00"
|
|
40
40
|
}, {
|
|
41
|
-
patchAccessTokenMerkleTree:
|
|
42
|
-
kycRequired:
|
|
43
|
-
hasAccessToken:
|
|
41
|
+
patchAccessTokenMerkleTree: H,
|
|
42
|
+
kycRequired: P,
|
|
43
|
+
hasAccessToken: U
|
|
44
44
|
} = await Y(t, [a], R), W = await V(
|
|
45
45
|
t.getCurrentChainId(),
|
|
46
46
|
n,
|
|
47
47
|
t.userKeys,
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
P,
|
|
49
|
+
U
|
|
50
50
|
), K = J(
|
|
51
51
|
N.WithdrawOnChainUtxos,
|
|
52
52
|
t.getCurrentChainId(),
|
|
@@ -61,19 +61,19 @@ const Q = async (t, e, r, p, o, i, u, c) => {
|
|
|
61
61
|
S,
|
|
62
62
|
t.userKeys,
|
|
63
63
|
v,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
f.externalActionId,
|
|
65
|
+
f.externalAddress,
|
|
66
|
+
f.externalActionMetadata,
|
|
67
67
|
t.generateProofRemotely,
|
|
68
68
|
s ?? k,
|
|
69
69
|
t.getCurrentChainId(),
|
|
70
70
|
void 0,
|
|
71
71
|
void 0,
|
|
72
72
|
void 0,
|
|
73
|
-
|
|
73
|
+
H,
|
|
74
74
|
void 0,
|
|
75
75
|
void 0,
|
|
76
|
-
|
|
76
|
+
u,
|
|
77
77
|
t.getContractWithFetcher(q.HinkalHelperContract),
|
|
78
78
|
W,
|
|
79
79
|
void 0,
|
|
@@ -87,7 +87,7 @@ const Q = async (t, e, r, p, o, i, u, c) => {
|
|
|
87
87
|
};
|
|
88
88
|
})
|
|
89
89
|
);
|
|
90
|
-
|
|
90
|
+
m.push(...E);
|
|
91
91
|
}
|
|
92
92
|
const C = t.getCurrentChainId();
|
|
93
93
|
await x(C, {
|
|
@@ -97,9 +97,9 @@ const Q = async (t, e, r, p, o, i, u, c) => {
|
|
|
97
97
|
});
|
|
98
98
|
const g = await O(
|
|
99
99
|
t.getCurrentChainId(),
|
|
100
|
-
|
|
100
|
+
m,
|
|
101
101
|
o,
|
|
102
|
-
|
|
102
|
+
w,
|
|
103
103
|
c
|
|
104
104
|
);
|
|
105
105
|
return await x(C, {
|
|
@@ -108,25 +108,25 @@ const Q = async (t, e, r, p, o, i, u, c) => {
|
|
|
108
108
|
phase: y.AFTER_SCHEDULE_WITHDRAW,
|
|
109
109
|
scheduleId: g
|
|
110
110
|
}), g;
|
|
111
|
-
}, gt = async (t, e, r,
|
|
112
|
-
const c = e.erc20TokenAddress, a = t.getCurrentChainId(), s = j(await t.getEthereumAddress()), n = i ?? await $(a, c, [c], z.Transact), { userDepositedUtxos:
|
|
111
|
+
}, gt = async (t, e, r, u, o, i, w) => {
|
|
112
|
+
const c = e.erc20TokenAddress, a = t.getCurrentChainId(), s = j(await t.getEthereumAddress()), n = i ?? await $(a, c, [c], z.Transact), { userDepositedUtxos: h, statusId: d, depositTxHash: m } = await G(
|
|
113
113
|
t,
|
|
114
114
|
e,
|
|
115
115
|
r,
|
|
116
|
-
|
|
116
|
+
u,
|
|
117
117
|
n,
|
|
118
118
|
s
|
|
119
119
|
);
|
|
120
|
-
return Q(
|
|
120
|
+
return await Q(
|
|
121
121
|
t,
|
|
122
122
|
e,
|
|
123
|
-
|
|
123
|
+
h,
|
|
124
124
|
n,
|
|
125
125
|
s,
|
|
126
126
|
d,
|
|
127
127
|
o,
|
|
128
|
-
|
|
129
|
-
);
|
|
128
|
+
w
|
|
129
|
+
), m;
|
|
130
130
|
};
|
|
131
131
|
export {
|
|
132
132
|
gt as hinkalDepositAndWithdraw
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=require("ethers"),B=require("../../constants/protocol.constants.cjs"),j=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),G=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),N=require("../../functions/web3/events/getShieldedBalance.cjs"),X=require("../../functions/web3/functionCalls/transactCallDirect.cjs"),J=require("../../types/external-action.types.cjs");require("../../types/circom-data.types.cjs");const u=require("../../types/ethereum-network.types.cjs"),L=require("../../types/admin.types.cjs");require("../../types/activities.types.cjs");const
|
|
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;
|
|
@@ -4,4 +4,5 @@ import { FeeStructure } from '../../types/hinkal.types';
|
|
|
4
4
|
export declare const hinkalDepositOnChainUtxos: (hinkal: IHinkal, erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], feeStructure: FeeStructure, hashedEthereumAddress: string) => Promise<{
|
|
5
5
|
userDepositedUtxos: RecipientUtxo[];
|
|
6
6
|
statusId?: string | undefined;
|
|
7
|
+
depositTxHash: string;
|
|
7
8
|
}>;
|
|
@@ -9,7 +9,7 @@ import "../../types/circom-data.types.mjs";
|
|
|
9
9
|
import { ContractType as p } from "../../types/ethereum-network.types.mjs";
|
|
10
10
|
import { AdminTransactionType as L } from "../../types/admin.types.mjs";
|
|
11
11
|
import "../../types/activities.types.mjs";
|
|
12
|
-
import { DepositAndWithdrawPhase as
|
|
12
|
+
import { DepositAndWithdrawPhase as y } from "../../types/scheduled-transactions.types.mjs";
|
|
13
13
|
import { getSignatureDataForTransact as N } from "../../functions/pre-transaction/getSignatureDataForTransact.mjs";
|
|
14
14
|
import { shouldPatchAccessTokenMerkleTree as Q } from "../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.mjs";
|
|
15
15
|
import { getUtxosFromReceipt as V } from "../../functions/utils/getUtxosFromReceipt.utils.mjs";
|
|
@@ -17,26 +17,26 @@ import { calculateTotalFee as Y } from "../../functions/utils/fees.utils.mjs";
|
|
|
17
17
|
import { constructAdminData as tt } from "../../functions/pre-transaction/constructAdminData.mjs";
|
|
18
18
|
import { emitTxPublicData as ot } from "../../API/admin-calls.mjs";
|
|
19
19
|
import { updateDepositAndWithdrawStatus as et, safeUpdateDepositAndWithdrawStatus as rt } from "../../API/deposit-and-withdraw-status-calls.mjs";
|
|
20
|
-
const yt = async (t, m,
|
|
21
|
-
const f = m.erc20TokenAddress, x = await t.getEthereumAddress(), a =
|
|
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(
|
|
22
22
|
t,
|
|
23
23
|
i,
|
|
24
24
|
n
|
|
25
|
-
),
|
|
25
|
+
), F = await N(
|
|
26
26
|
t.getCurrentChainId(),
|
|
27
27
|
x,
|
|
28
28
|
t.userKeys,
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
W,
|
|
30
|
+
S
|
|
31
31
|
), r = [...await j(t, i, n)], C = [];
|
|
32
32
|
for (let o = 0; o < r.length; o += 1) {
|
|
33
33
|
const { outputUtxos: e } = B(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:
|
|
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
40
|
} = await X(
|
|
41
41
|
"v1x1",
|
|
42
42
|
t.merkleTreeHinkal,
|
|
@@ -47,46 +47,46 @@ const yt = async (t, m, y, O, E, u) => {
|
|
|
47
47
|
`swapperM1x${r[0].length}x1`,
|
|
48
48
|
J.DepositOnChainUtxos,
|
|
49
49
|
await g.getAddress(),
|
|
50
|
-
|
|
50
|
+
H,
|
|
51
51
|
t.generateProofRemotely,
|
|
52
52
|
q,
|
|
53
53
|
t.getCurrentChainId(),
|
|
54
|
-
|
|
54
|
+
v,
|
|
55
55
|
void 0,
|
|
56
56
|
void 0,
|
|
57
|
-
|
|
57
|
+
I,
|
|
58
58
|
void 0,
|
|
59
59
|
void 0,
|
|
60
60
|
void 0,
|
|
61
61
|
t.getContractWithFetcher(p.HinkalHelperContract),
|
|
62
|
-
|
|
62
|
+
F,
|
|
63
63
|
await D.getAddress(),
|
|
64
64
|
!1
|
|
65
65
|
), s = t.getCurrentChainId(), h = (await et(s, {
|
|
66
66
|
hashedEthereumAddress: u,
|
|
67
|
-
phase:
|
|
67
|
+
phase: y.BEFORE_DEPOSIT
|
|
68
68
|
})).id ?? void 0, w = await G(
|
|
69
69
|
t,
|
|
70
70
|
A,
|
|
71
71
|
m,
|
|
72
|
-
H,
|
|
73
72
|
R,
|
|
74
73
|
b,
|
|
74
|
+
K,
|
|
75
75
|
g,
|
|
76
76
|
D
|
|
77
|
-
),
|
|
77
|
+
), M = await w.wait(), T = w.hash;
|
|
78
78
|
await rt(s, {
|
|
79
79
|
id: h,
|
|
80
80
|
hashedEthereumAddress: u,
|
|
81
|
-
phase:
|
|
82
|
-
depositTxHash:
|
|
81
|
+
phase: y.AFTER_DEPOSIT,
|
|
82
|
+
depositTxHash: T
|
|
83
83
|
});
|
|
84
|
-
const $ = await V(
|
|
85
|
-
|
|
86
|
-
const
|
|
84
|
+
const $ = await V(M, t, f), l = [], c = [...$];
|
|
85
|
+
E.forEach((o, e) => {
|
|
86
|
+
const U = a[e], d = c.find((Z) => Z.amount === U);
|
|
87
87
|
if (!d)
|
|
88
|
-
throw new Error(`Could not find newly created UTXO with amount ${
|
|
89
|
-
|
|
88
|
+
throw new Error(`Could not find newly created UTXO with amount ${U} for recipient ${o}.`);
|
|
89
|
+
l.push({
|
|
90
90
|
recipientAddress: o,
|
|
91
91
|
utxo: d
|
|
92
92
|
});
|
|
@@ -100,7 +100,7 @@ const yt = async (t, m, y, O, E, u) => {
|
|
|
100
100
|
[A],
|
|
101
101
|
x
|
|
102
102
|
);
|
|
103
|
-
return ot(s, k), { userDepositedUtxos:
|
|
103
|
+
return ot(s, k), { userDepositedUtxos: l, statusId: h, depositTxHash: T };
|
|
104
104
|
};
|
|
105
105
|
export {
|
|
106
106
|
yt as hinkalDepositOnChainUtxos
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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,20 +1,20 @@
|
|
|
1
|
-
import { zeroAddress as
|
|
1
|
+
import { zeroAddress as u } 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
5
|
import { ExternalActionId as S } from "../../types/external-action.types.mjs";
|
|
6
|
-
import { Utxo as
|
|
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";
|
|
9
9
|
import "../../types/activities.types.mjs";
|
|
10
|
-
import { DepositAndWithdrawPhase as
|
|
10
|
+
import { DepositAndWithdrawPhase as W } from "../../types/scheduled-transactions.types.mjs";
|
|
11
11
|
import { getSignatureDataForTransact as rt } from "../../functions/pre-transaction/getSignatureDataForTransact.mjs";
|
|
12
12
|
import { shouldPatchAccessTokenMerkleTree as st } from "../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.mjs";
|
|
13
13
|
import { getCurrentTimeInSeconds as it } from "../../functions/utils/time.utils.mjs";
|
|
14
|
-
import { getFeeStructure as
|
|
15
|
-
import { hashEthereumAddress as
|
|
14
|
+
import { getFeeStructure as at } from "../../functions/pre-transaction/getFeeStructure.mjs";
|
|
15
|
+
import { hashEthereumAddress as nt } from "../../functions/utils/addresses.mjs";
|
|
16
16
|
import { networkRegistry as mt } from "../../constants/chains.constants.mjs";
|
|
17
|
-
import { SWAP_ROUTER_ADDRESSES as
|
|
17
|
+
import { SWAP_ROUTER_ADDRESSES as O } from "../../constants/addresses.constants.mjs";
|
|
18
18
|
import "idb-keyval";
|
|
19
19
|
import "@solana/web3.js";
|
|
20
20
|
import "../http/HttpClient.mjs";
|
|
@@ -24,7 +24,7 @@ import { getERC20Token as pt } from "../../functions/utils/erc20tokenFunctions.m
|
|
|
24
24
|
import "../../functions/utils/convertIntegrationProviderToExternalActionId.mjs";
|
|
25
25
|
import "../../constants/server.constants.mjs";
|
|
26
26
|
import "axios";
|
|
27
|
-
import { caseInsensitiveEqual as
|
|
27
|
+
import { caseInsensitiveEqual as z } from "../../functions/utils/caseInsensitive.utils.mjs";
|
|
28
28
|
import "../../API/getServerURL.mjs";
|
|
29
29
|
import "circomlibjs-hinkal-fork";
|
|
30
30
|
import "libsodium-wrappers";
|
|
@@ -50,55 +50,55 @@ import { convertEmporiumOpToCallInfo as ct } from "../../functions/utils/convert
|
|
|
50
50
|
import "multiformats";
|
|
51
51
|
import { API as dt } from "../../API/API.mjs";
|
|
52
52
|
import "../../API/tenderly.api.mjs";
|
|
53
|
-
import { hinkalDepositOnChainUtxos as
|
|
54
|
-
import { createLifiBridgeOps as
|
|
53
|
+
import { hinkalDepositOnChainUtxos as H } from "./hinkalDepositOnChainUtxos.mjs";
|
|
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,
|
|
57
|
-
if (
|
|
56
|
+
const ut = async (t, f, s, R, a, T, c, d) => {
|
|
57
|
+
if (s.length === 0)
|
|
58
58
|
throw new Error("No recipients to bridge");
|
|
59
|
-
const i =
|
|
59
|
+
const i = f.erc20TokenAddress, o = t.getCurrentChainId(), { contractData: n } = mt[o], { emporiumAddress: w } = n;
|
|
60
60
|
if (!w)
|
|
61
61
|
throw Error("No Emporium Address");
|
|
62
|
-
const C =
|
|
62
|
+
const C = O[S.Lifi][o];
|
|
63
63
|
if (!C)
|
|
64
64
|
throw new Error(`LIFI not configured for chain ${o}`);
|
|
65
|
-
const
|
|
66
|
-
if (!
|
|
65
|
+
const A = await t.getRandomRelay();
|
|
66
|
+
if (!A)
|
|
67
67
|
throw Error(X.RELAYER_NOT_AVAILABLE);
|
|
68
|
-
const D = await t.getEthereumAddress(),
|
|
69
|
-
for (let
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
await dt.addTemporaryWalletNonce(o,
|
|
73
|
-
const q =
|
|
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({
|
|
74
74
|
amount: 0n,
|
|
75
75
|
erc20TokenAddress: i,
|
|
76
76
|
shieldedPrivateKey: t.userKeys.getShieldedPrivateKey(),
|
|
77
|
-
timeStamp:
|
|
77
|
+
timeStamp: l,
|
|
78
78
|
tokenId: 0
|
|
79
|
-
}), F = [[
|
|
79
|
+
}), F = [[r, L]], b = [[L]];
|
|
80
80
|
if (q && p) {
|
|
81
|
-
const
|
|
81
|
+
const K = new N({
|
|
82
82
|
amount: 0n,
|
|
83
|
-
erc20TokenAddress:
|
|
83
|
+
erc20TokenAddress: u,
|
|
84
84
|
shieldedPrivateKey: t.userKeys.getShieldedPrivateKey(),
|
|
85
|
-
timeStamp:
|
|
85
|
+
timeStamp: l,
|
|
86
86
|
tokenId: 0
|
|
87
87
|
});
|
|
88
|
-
|
|
88
|
+
g.push(u), k.push(-p.amount), P.push(!1), F.push([p, K]), b.push([K]);
|
|
89
89
|
}
|
|
90
|
-
const M =
|
|
90
|
+
const M = B(
|
|
91
91
|
t,
|
|
92
|
-
|
|
92
|
+
x.ethAddress,
|
|
93
93
|
C,
|
|
94
94
|
i,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
r.amount,
|
|
96
|
+
h,
|
|
97
|
+
U
|
|
98
98
|
), { patchAccessTokenMerkleTree: V, kycRequired: Y, hasAccessToken: Z } = await st(
|
|
99
99
|
t,
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
g,
|
|
101
|
+
k
|
|
102
102
|
), $ = await rt(
|
|
103
103
|
o,
|
|
104
104
|
D,
|
|
@@ -109,21 +109,21 @@ const ut = async (t, A, r, R, n, T, c, d) => {
|
|
|
109
109
|
"v1x1",
|
|
110
110
|
t.merkleTreeHinkal,
|
|
111
111
|
t.merkleTreeAccessToken,
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
g,
|
|
113
|
+
g.map(() => 0),
|
|
114
114
|
F,
|
|
115
|
-
|
|
115
|
+
b,
|
|
116
116
|
t.userKeys,
|
|
117
|
-
|
|
117
|
+
g.length,
|
|
118
118
|
F[0].length,
|
|
119
119
|
w,
|
|
120
120
|
M,
|
|
121
121
|
t.generateProofRemotely,
|
|
122
|
-
|
|
122
|
+
A ?? u,
|
|
123
123
|
o,
|
|
124
|
-
|
|
124
|
+
P,
|
|
125
125
|
void 0,
|
|
126
|
-
|
|
126
|
+
x.privateKey,
|
|
127
127
|
void 0,
|
|
128
128
|
V,
|
|
129
129
|
void 0,
|
|
@@ -136,35 +136,35 @@ const ut = async (t, A, r, R, n, T, c, d) => {
|
|
|
136
136
|
return { zkCallData: j, dimData: J, circomData: G, authorizationData: Q };
|
|
137
137
|
})
|
|
138
138
|
);
|
|
139
|
-
|
|
139
|
+
v.push(...e);
|
|
140
140
|
}
|
|
141
141
|
await _(o, {
|
|
142
142
|
id: T,
|
|
143
|
-
hashedEthereumAddress:
|
|
144
|
-
phase:
|
|
143
|
+
hashedEthereumAddress: a,
|
|
144
|
+
phase: W.BEFORE_SCHEDULE_WITHDRAW
|
|
145
145
|
});
|
|
146
|
-
const
|
|
146
|
+
const y = await et(
|
|
147
147
|
o,
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
v,
|
|
149
|
+
a,
|
|
150
150
|
c,
|
|
151
151
|
d
|
|
152
152
|
);
|
|
153
153
|
return await _(o, {
|
|
154
154
|
id: T,
|
|
155
|
-
hashedEthereumAddress:
|
|
156
|
-
phase:
|
|
157
|
-
scheduleId:
|
|
158
|
-
}),
|
|
159
|
-
}, Ae = async (t,
|
|
160
|
-
const c =
|
|
155
|
+
hashedEthereumAddress: a,
|
|
156
|
+
phase: W.AFTER_SCHEDULE_WITHDRAW,
|
|
157
|
+
scheduleId: y
|
|
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
161
|
if (!o)
|
|
162
162
|
throw Error("LIFI router not configured");
|
|
163
|
-
let
|
|
164
|
-
if (
|
|
165
|
-
|
|
163
|
+
let n;
|
|
164
|
+
if (a)
|
|
165
|
+
n = a;
|
|
166
166
|
else {
|
|
167
|
-
const e =
|
|
167
|
+
const e = s[0], p = B(
|
|
168
168
|
t,
|
|
169
169
|
e.temporarySubAccount.ethAddress,
|
|
170
170
|
o,
|
|
@@ -173,52 +173,56 @@ const ut = async (t, A, r, R, n, T, c, d) => {
|
|
|
173
173
|
e.bridgeAmount,
|
|
174
174
|
e.quote
|
|
175
175
|
).map(
|
|
176
|
-
(
|
|
176
|
+
(h) => ct(h, e.temporarySubAccount.ethAddress, d)
|
|
177
177
|
);
|
|
178
|
-
|
|
178
|
+
n = await at(d, c, [c], S.Emporium, p);
|
|
179
179
|
}
|
|
180
180
|
const w = {
|
|
181
|
-
feeToken:
|
|
181
|
+
feeToken: n.feeToken,
|
|
182
182
|
flatFee: 0n,
|
|
183
183
|
variableRate: 0n
|
|
184
|
-
},
|
|
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
|
|
188
|
+
} = await H(
|
|
185
189
|
t,
|
|
186
|
-
|
|
190
|
+
f,
|
|
187
191
|
D,
|
|
188
|
-
|
|
189
|
-
|
|
192
|
+
l,
|
|
193
|
+
n,
|
|
190
194
|
i
|
|
191
195
|
);
|
|
192
|
-
let
|
|
193
|
-
if (
|
|
194
|
-
const e = pt(
|
|
196
|
+
let m = [];
|
|
197
|
+
if (A) {
|
|
198
|
+
const e = pt(u, d);
|
|
195
199
|
if (!e)
|
|
196
200
|
throw Error("No native token");
|
|
197
|
-
const
|
|
201
|
+
const r = s.map((h) => h.quote.nativeFee), { userDepositedUtxos: p } = await H(
|
|
198
202
|
t,
|
|
199
203
|
e,
|
|
200
|
-
|
|
201
|
-
|
|
204
|
+
r,
|
|
205
|
+
l,
|
|
202
206
|
w,
|
|
203
207
|
i
|
|
204
208
|
);
|
|
205
|
-
|
|
209
|
+
m = p;
|
|
206
210
|
}
|
|
207
|
-
const
|
|
211
|
+
const I = s.map((e, r) => ({
|
|
208
212
|
...e,
|
|
209
|
-
utxo:
|
|
210
|
-
nativeUtxo:
|
|
213
|
+
utxo: E[r].utxo,
|
|
214
|
+
nativeUtxo: A ? m[r]?.utxo : void 0
|
|
211
215
|
}));
|
|
212
|
-
return ut(
|
|
216
|
+
return await ut(
|
|
213
217
|
t,
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
218
|
+
f,
|
|
219
|
+
I,
|
|
220
|
+
n,
|
|
217
221
|
i,
|
|
218
|
-
|
|
222
|
+
v,
|
|
219
223
|
R,
|
|
220
224
|
T
|
|
221
|
-
);
|
|
225
|
+
), y;
|
|
222
226
|
};
|
|
223
227
|
export {
|
|
224
228
|
Ae as hinkalDepositAndBridge
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("../../functions/web3/etherFunctions.cjs"),z=require("../utxo/Utxo.cjs"),Y=require("../../error-handling/error-codes.constants.cjs");require("idb-keyval");const j=require("../../constants/chains.constants.cjs"),G=require("ethers");require("../crypto-keys/keys.cjs");require("node-forge");require("../../constants/vite.constants.cjs");require("libsodium-wrappers");require("../http/HttpClient.cjs");require("axios");const $=require("../../functions/utils/solanaMint.utils.cjs"),N=require("@solana/web3.js"),J=require("../../functions/utils/addresses.cjs");require("../../constants/server.constants.cjs");require("../../constants/token-data/index.cjs");const _=require("../../constants/protocol.constants.cjs"),Q=require("../../API/API.cjs");require("../../functions/utils/mutexes.utils.cjs");require("../../types/circom-data.types.cjs");const ee=require("../../types/external-action.types.cjs");require("../../types/activities.types.cjs");const B=require("../../types/scheduled-transactions.types.cjs");require("../../functions/web3/events/getApprovedBalance.cjs");require("../../constants/contracts.constants.cjs");require("../../constants/kyc.constants.cjs");require("../../constants/coingecko.constants.cjs");require("../../constants/reorg-depths.constants.cjs");require("../../constants/addresses.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/convertIntegrationProviderToExternalActionId.cjs");require("../../API/getServerURL.cjs");require("circomlibjs-hinkal-fork");require("process");require("buffer");require("../../constants/save-depths.cjs");const te=require("@coral-xyz/anchor"),E=require("../../functions/pre-transaction/solana.cjs");require("@solana/spl-token");require("../../functions/utils/userAgent.cjs");const re=require("../../functions/utils/time.utils.cjs");require("multiformats");require("../../API/tenderly.api.cjs");const oe=require("../../functions/utils/fees.utils.cjs");require("../../functions/web3/getTokenHolder.cjs");const ne=require("../../functions/web3/signAndSendSerializedTransaction.cjs"),Z=require("../../functions/snarkjs/common.snarkjs.cjs"),ae=require("./hinkalCheckSolanaTokenRegistry.cjs"),se=require("../../functions/utils/getUtxosFromReceiptSolana.cjs"),ie=require("../../functions/snarkjs/constructSolanaZkProof.cjs"),ce=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),ue=require("../../functions/pre-transaction/getFeeStructure.cjs"),W=require("../../API/deposit-and-withdraw-status-calls.cjs"),de=async(e,r,d,l,g,
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("../../functions/web3/etherFunctions.cjs"),z=require("../utxo/Utxo.cjs"),Y=require("../../error-handling/error-codes.constants.cjs");require("idb-keyval");const j=require("../../constants/chains.constants.cjs"),G=require("ethers");require("../crypto-keys/keys.cjs");require("node-forge");require("../../constants/vite.constants.cjs");require("libsodium-wrappers");require("../http/HttpClient.cjs");require("axios");const $=require("../../functions/utils/solanaMint.utils.cjs"),N=require("@solana/web3.js"),J=require("../../functions/utils/addresses.cjs");require("../../constants/server.constants.cjs");require("../../constants/token-data/index.cjs");const _=require("../../constants/protocol.constants.cjs"),Q=require("../../API/API.cjs");require("../../functions/utils/mutexes.utils.cjs");require("../../types/circom-data.types.cjs");const ee=require("../../types/external-action.types.cjs");require("../../types/activities.types.cjs");const B=require("../../types/scheduled-transactions.types.cjs");require("../../functions/web3/events/getApprovedBalance.cjs");require("../../constants/contracts.constants.cjs");require("../../constants/kyc.constants.cjs");require("../../constants/coingecko.constants.cjs");require("../../constants/reorg-depths.constants.cjs");require("../../constants/addresses.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/convertIntegrationProviderToExternalActionId.cjs");require("../../API/getServerURL.cjs");require("circomlibjs-hinkal-fork");require("process");require("buffer");require("../../constants/save-depths.cjs");const te=require("@coral-xyz/anchor"),E=require("../../functions/pre-transaction/solana.cjs");require("@solana/spl-token");require("../../functions/utils/userAgent.cjs");const re=require("../../functions/utils/time.utils.cjs");require("multiformats");require("../../API/tenderly.api.cjs");const oe=require("../../functions/utils/fees.utils.cjs");require("../../functions/web3/getTokenHolder.cjs");const ne=require("../../functions/web3/signAndSendSerializedTransaction.cjs"),Z=require("../../functions/snarkjs/common.snarkjs.cjs"),ae=require("./hinkalCheckSolanaTokenRegistry.cjs"),se=require("../../functions/utils/getUtxosFromReceiptSolana.cjs"),ie=require("../../functions/snarkjs/constructSolanaZkProof.cjs"),ce=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),ue=require("../../functions/pre-transaction/getFeeStructure.cjs"),W=require("../../API/deposit-and-withdraw-status-calls.cjs"),de=async(e,r,d,l,g,p)=>{const h=d.map(t=>t+oe.calculateTotalFee(t,g)),{hinkalIdl:m,hinkalAddress:S,originalDeployer:i}=j.networkRegistry[e.getCurrentChainId()].contractData;if(!m)throw new Error("No IDL configured for Solana program on this network");if(!i)throw new Error("missing original deployer");const w=e.userKeys.getShieldedPrivateKey(),P=z.Utxo.findCorrectRandomization(M.randomBigInt(31),w),y=Z.calcStealthAddressStructure(P,w),o=e.getSolanaProgram(m),b=e.getSolanaPublicKey(),n=new N.PublicKey(i),A=new N.PublicKey(S),{mintPublicKey:c}=$.formatMintAddress(r),x=c.toString(),O=E.getStorageAccountPublicKey(A,n),D=E.getStorageVaultPublicKey(A,n),F=E.getMerkleAccountPublicKey(A,n),R=E.buildAnchorStealthAddressStructure(y),f=e.getCurrentChainId(),v=h.reduce((t,s)=>t+s,0n),T=await ae.hinkalCheckSolanaTokenRegistry(o,new N.PublicKey(n),[r],[v]),K=h.map(t=>`${t}`);let a="";const I=(await W.updateDepositAndWithdrawStatus(f,{hashedEthereumAddress:p,phase:B.DepositAndWithdrawPhase.BEFORE_DEPOSIT})).id??void 0;if(T){const{serializedTransaction:t,blockhash:s,lastValidBlockHeight:q}=await Q.API.generateMultiPaymentDepositLimitless(f,{amounts:K,payer:e.getSolanaPublicKey().toBase58(),ethereumAddress:await e.getEthereumAddress(),mint:r,stealthAddressStructure:R}),{wallet:u}=o.provider;if(!u)throw new Error("missing wallet");a=await ne.signAndSendSerializedTransaction(o.provider,t,s,q)}else{const t=E.getTokenLimitStorageAccountPublicKey(o.programId,n,c),s=x===_.solanaNativeAddress?null:c,q=x===_.solanaNativeAddress?null:void 0;a=await o.methods.multiPaymentDeposit(K.map(L=>new te.BN(L)),R).accounts({mint:s,signer:b,signerAta:q,originalDeployer:n,storageAccount:O,storageVault:D,merkleAccount:F,tokenLimitStorage:t,storageVaultAta:q,accessTokenOwner:null}).rpc();const u=await o.provider.connection.getLatestBlockhash();await o.provider.connection.confirmTransaction({blockhash:u.blockhash,lastValidBlockHeight:u.lastValidBlockHeight,signature:a},"confirmed")}const k=await o.provider.connection.getTransaction(a,{commitment:"confirmed",maxSupportedTransactionVersion:0});if(!k)throw new Error("Transaction missing");await W.safeUpdateDepositAndWithdrawStatus(f,{id:I,hashedEthereumAddress:p,phase:B.DepositAndWithdrawPhase.AFTER_DEPOSIT,depositTxHash:a});const H=se.getUtxosFromReceiptSolana(k,o,e.userKeys),U=[],C=[...H];return l.forEach((t,s)=>{const q=h[s],u=C.find(X=>X.amount===q);if(!u)throw new Error(`Could not find newly created UTXO with amount ${q} for recipient ${t}.`);U.push({recipientAddress:t,utxo:u});const L=C.indexOf(u);C.splice(L,1)}),{userDepositedUtxos:U,depositTxHash:a,statusId:I}},le=async(e,r,d,l,g,p,h,m)=>{const S=e.getCurrentChainId();if(d.length===0)throw new Error("userDepositedUtxos must not be empty");const{hinkalIdl:i,originalDeployer:w}=j.networkRegistry[e.getCurrentChainId()].contractData;if(!w||!i)throw new Error("missing data");const P=e.getSolanaProgram(i),y=await e.getRandomRelay(!0);if(!y)throw new Error(Y.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const o=re.getCurrentTimeInSeconds().toString(),b=e.generateProofRemotely?5:1,n=[];for(let c=0;c<d.length;c+=b){const x=d.slice(c,c+b),O=await Promise.all(x.map(async({recipientAddress:D,utxo:F})=>{const{compressedAddress:R}=$.formatMintAddress(_.solanaNativeAddress),f=new z.Utxo({amount:0n,mintAddress:r,erc20TokenAddress:R,shieldedPrivateKey:e.userKeys.getShieldedPrivateKey(),timeStamp:o,tokenId:0}),v=[F,f],T=[f],K=z.Utxo.findCorrectRandomization(M.randomBigInt(31),e.userKeys.getShieldedPrivateKey()),a={tokenNumber:1,nullifierAmount:v.length,outputAmount:T.length},V=Z.calcEncryptedOutputs([T])[0][0],I=Array.from(G.ethers.getBytes(V)),{proofAArr:k,proofBArr:H,proofCArr:U,publicInputsArr:C}=await ie.constructSolanaZkProof(e.generateProofRemotely,w,e.merkleTreeHinkal,e.merkleTreeAccessToken,e.userKeys,P,[r],[v],[T],K,l.flatFee,l.variableRate,D,y,a,[I],e.getCurrentChainId(),void 0,void 0,void 0,void 0,void 0,!1),t=r===_.solanaNativeAddress,s={recipient:D,mint:t?void 0:r};return{relayAddress:y,functionName:"transact",args:{proofAArr:k,proofBArr:H,proofCArr:U,publicInputsArr:C,encryptedOutputs:[I],relayerFee:l.flatFee.toString(),dimensions:a},accounts:s}}));n.push(...O)}await W.safeUpdateDepositAndWithdrawStatus(S,{id:p,hashedEthereumAddress:g,phase:B.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});const A=await ce.solanaTransactCallRelayerBatch(e.getCurrentChainId(),n,g,h,m);return await W.safeUpdateDepositAndWithdrawStatus(S,{id:p,hashedEthereumAddress:g,phase:B.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:A}),A},ge=async(e,r,d,l,g,p,h)=>{const m=J.hashEthereumAddress(await e.getEthereumAddress()),S=e.getCurrentChainId(),i=p??await ue.getFeeStructure(S,r,[r],ee.ExternalActionId.Transact,[],0n),{userDepositedUtxos:w,statusId:P,depositTxHash:y}=await de(e,r,d,l,i,m);return await le(e,r,w,i,m,P,g,h),y};exports.hinkalSolanaDepositAndWithdraw=ge;
|
|
@@ -59,33 +59,33 @@ import { updateDepositAndWithdrawStatus as ht, safeUpdateDepositAndWithdrawStatu
|
|
|
59
59
|
const ft = async (t, r, p, d, l, u) => {
|
|
60
60
|
const g = p.map((o) => o + nt(o, l)), {
|
|
61
61
|
hinkalIdl: h,
|
|
62
|
-
hinkalAddress:
|
|
62
|
+
hinkalAddress: S,
|
|
63
63
|
originalDeployer: s
|
|
64
64
|
} = $[t.getCurrentChainId()].contractData;
|
|
65
65
|
if (!h)
|
|
66
66
|
throw new Error("No IDL configured for Solana program on this network");
|
|
67
67
|
if (!s)
|
|
68
68
|
throw new Error("missing original deployer");
|
|
69
|
-
const f = t.userKeys.getShieldedPrivateKey(), E = z.findCorrectRandomization(M(31), f),
|
|
69
|
+
const f = t.userKeys.getShieldedPrivateKey(), E = z.findCorrectRandomization(M(31), f), w = ct(E, f), e = t.getSolanaProgram(h), v = t.getSolanaPublicKey(), a = new W(s), A = new W(S), { mintPublicKey: c } = q(r), x = c.toString(), H = tt(A, a), R = ot(A, a), F = rt(A, a), b = et(w), T = t.getCurrentChainId(), D = g.reduce((o, n) => o + n, 0n), I = await pt(
|
|
70
70
|
e,
|
|
71
71
|
new W(a),
|
|
72
72
|
[r],
|
|
73
73
|
[D]
|
|
74
74
|
), K = g.map((o) => `${o}`);
|
|
75
75
|
let i = "";
|
|
76
|
-
const P = (await ht(
|
|
76
|
+
const P = (await ht(T, {
|
|
77
77
|
hashedEthereumAddress: u,
|
|
78
78
|
phase: k.BEFORE_DEPOSIT
|
|
79
79
|
})).id ?? void 0;
|
|
80
|
-
if (
|
|
81
|
-
const { serializedTransaction: o, blockhash: n, lastValidBlockHeight:
|
|
82
|
-
|
|
80
|
+
if (I) {
|
|
81
|
+
const { serializedTransaction: o, blockhash: n, lastValidBlockHeight: y } = await G.generateMultiPaymentDepositLimitless(
|
|
82
|
+
T,
|
|
83
83
|
{
|
|
84
84
|
amounts: K,
|
|
85
85
|
payer: t.getSolanaPublicKey().toBase58(),
|
|
86
86
|
ethereumAddress: await t.getEthereumAddress(),
|
|
87
87
|
mint: r,
|
|
88
|
-
stealthAddressStructure:
|
|
88
|
+
stealthAddressStructure: b
|
|
89
89
|
}
|
|
90
90
|
), { wallet: m } = e.provider;
|
|
91
91
|
if (!m)
|
|
@@ -94,23 +94,23 @@ const ft = async (t, r, p, d, l, u) => {
|
|
|
94
94
|
e.provider,
|
|
95
95
|
o,
|
|
96
96
|
n,
|
|
97
|
-
|
|
97
|
+
y
|
|
98
98
|
);
|
|
99
99
|
} else {
|
|
100
|
-
const o = at(e.programId, a, c), n =
|
|
100
|
+
const o = at(e.programId, a, c), n = x === U ? null : c, y = x === U ? null : void 0;
|
|
101
101
|
i = await e.methods.multiPaymentDeposit(
|
|
102
102
|
K.map((V) => new Q(V)),
|
|
103
|
-
|
|
103
|
+
b
|
|
104
104
|
).accounts({
|
|
105
105
|
mint: n,
|
|
106
106
|
signer: v,
|
|
107
|
-
signerAta:
|
|
107
|
+
signerAta: y,
|
|
108
108
|
originalDeployer: a,
|
|
109
|
-
storageAccount:
|
|
110
|
-
storageVault:
|
|
111
|
-
merkleAccount:
|
|
109
|
+
storageAccount: H,
|
|
110
|
+
storageVault: R,
|
|
111
|
+
merkleAccount: F,
|
|
112
112
|
tokenLimitStorage: o,
|
|
113
|
-
storageVaultAta:
|
|
113
|
+
storageVaultAta: y,
|
|
114
114
|
accessTokenOwner: null
|
|
115
115
|
}).rpc();
|
|
116
116
|
const m = await e.provider.connection.getLatestBlockhash();
|
|
@@ -129,7 +129,7 @@ const ft = async (t, r, p, d, l, u) => {
|
|
|
129
129
|
});
|
|
130
130
|
if (!B)
|
|
131
131
|
throw new Error("Transaction missing");
|
|
132
|
-
await N(
|
|
132
|
+
await N(T, {
|
|
133
133
|
id: P,
|
|
134
134
|
hashedEthereumAddress: u,
|
|
135
135
|
phase: k.AFTER_DEPOSIT,
|
|
@@ -137,45 +137,45 @@ const ft = async (t, r, p, d, l, u) => {
|
|
|
137
137
|
});
|
|
138
138
|
const L = dt(B, e, t.userKeys), O = [], C = [...L];
|
|
139
139
|
return d.forEach((o, n) => {
|
|
140
|
-
const
|
|
140
|
+
const y = g[n], m = C.find((X) => X.amount === y);
|
|
141
141
|
if (!m)
|
|
142
|
-
throw new Error(`Could not find newly created UTXO with amount ${
|
|
142
|
+
throw new Error(`Could not find newly created UTXO with amount ${y} for recipient ${o}.`);
|
|
143
143
|
O.push({
|
|
144
144
|
recipientAddress: o,
|
|
145
145
|
utxo: m
|
|
146
146
|
});
|
|
147
147
|
const V = C.indexOf(m);
|
|
148
148
|
C.splice(V, 1);
|
|
149
|
-
}), { userDepositedUtxos: O,
|
|
149
|
+
}), { userDepositedUtxos: O, depositTxHash: i, statusId: P };
|
|
150
150
|
}, wt = async (t, r, p, d, l, u, g, h) => {
|
|
151
|
-
const
|
|
151
|
+
const S = t.getCurrentChainId();
|
|
152
152
|
if (p.length === 0)
|
|
153
153
|
throw new Error("userDepositedUtxos must not be empty");
|
|
154
154
|
const { hinkalIdl: s, originalDeployer: f } = $[t.getCurrentChainId()].contractData;
|
|
155
155
|
if (!f || !s)
|
|
156
156
|
throw new Error("missing data");
|
|
157
|
-
const E = t.getSolanaProgram(s),
|
|
158
|
-
if (!
|
|
157
|
+
const E = t.getSolanaProgram(s), w = await t.getRandomRelay(!0);
|
|
158
|
+
if (!w)
|
|
159
159
|
throw new Error(Y.RELAYER_NOT_AVAILABLE);
|
|
160
160
|
const e = it().toString(), v = t.generateProofRemotely ? 5 : 1, a = [];
|
|
161
161
|
for (let c = 0; c < p.length; c += v) {
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
const { compressedAddress:
|
|
162
|
+
const x = p.slice(c, c + v), H = await Promise.all(
|
|
163
|
+
x.map(async ({ recipientAddress: R, utxo: F }) => {
|
|
164
|
+
const { compressedAddress: b } = q(U), T = new z({
|
|
165
165
|
amount: 0n,
|
|
166
166
|
mintAddress: r,
|
|
167
|
-
erc20TokenAddress:
|
|
167
|
+
erc20TokenAddress: b,
|
|
168
168
|
shieldedPrivateKey: t.userKeys.getShieldedPrivateKey(),
|
|
169
169
|
timeStamp: e,
|
|
170
170
|
tokenId: 0
|
|
171
|
-
}), D = [
|
|
171
|
+
}), D = [F, T], I = [T], K = z.findCorrectRandomization(
|
|
172
172
|
M(31),
|
|
173
173
|
t.userKeys.getShieldedPrivateKey()
|
|
174
174
|
), i = {
|
|
175
175
|
tokenNumber: 1,
|
|
176
176
|
nullifierAmount: D.length,
|
|
177
|
-
outputAmount:
|
|
178
|
-
}, _ = mt([
|
|
177
|
+
outputAmount: I.length
|
|
178
|
+
}, _ = mt([I])[0][0], P = Array.from(Z.getBytes(_)), { proofAArr: B, proofBArr: L, proofCArr: O, publicInputsArr: C } = await lt(
|
|
179
179
|
t.generateProofRemotely,
|
|
180
180
|
f,
|
|
181
181
|
t.merkleTreeHinkal,
|
|
@@ -184,12 +184,12 @@ const ft = async (t, r, p, d, l, u) => {
|
|
|
184
184
|
E,
|
|
185
185
|
[r],
|
|
186
186
|
[D],
|
|
187
|
-
[
|
|
187
|
+
[I],
|
|
188
188
|
K,
|
|
189
189
|
d.flatFee,
|
|
190
190
|
d.variableRate,
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
R,
|
|
192
|
+
w,
|
|
193
193
|
i,
|
|
194
194
|
[P],
|
|
195
195
|
t.getCurrentChainId(),
|
|
@@ -200,11 +200,11 @@ const ft = async (t, r, p, d, l, u) => {
|
|
|
200
200
|
void 0,
|
|
201
201
|
!1
|
|
202
202
|
), n = {
|
|
203
|
-
recipient:
|
|
203
|
+
recipient: R,
|
|
204
204
|
mint: r === U ? void 0 : r
|
|
205
205
|
};
|
|
206
206
|
return {
|
|
207
|
-
relayAddress:
|
|
207
|
+
relayAddress: w,
|
|
208
208
|
functionName: "transact",
|
|
209
209
|
args: {
|
|
210
210
|
proofAArr: B,
|
|
@@ -219,9 +219,9 @@ const ft = async (t, r, p, d, l, u) => {
|
|
|
219
219
|
};
|
|
220
220
|
})
|
|
221
221
|
);
|
|
222
|
-
a.push(...
|
|
222
|
+
a.push(...H);
|
|
223
223
|
}
|
|
224
|
-
await N(
|
|
224
|
+
await N(S, {
|
|
225
225
|
id: u,
|
|
226
226
|
hashedEthereumAddress: l,
|
|
227
227
|
phase: k.BEFORE_SCHEDULE_WITHDRAW
|
|
@@ -233,14 +233,14 @@ const ft = async (t, r, p, d, l, u) => {
|
|
|
233
233
|
g,
|
|
234
234
|
h
|
|
235
235
|
);
|
|
236
|
-
return await N(
|
|
236
|
+
return await N(S, {
|
|
237
237
|
id: u,
|
|
238
238
|
hashedEthereumAddress: l,
|
|
239
239
|
phase: k.AFTER_SCHEDULE_WITHDRAW,
|
|
240
240
|
scheduleId: A
|
|
241
241
|
}), A;
|
|
242
|
-
},
|
|
243
|
-
const h = j(await t.getEthereumAddress()),
|
|
242
|
+
}, Io = async (t, r, p, d, l, u, g) => {
|
|
243
|
+
const h = j(await t.getEthereumAddress()), S = t.getCurrentChainId(), s = u ?? await gt(S, r, [r], J.Transact, [], 0n), { userDepositedUtxos: f, statusId: E, depositTxHash: w } = await ft(
|
|
244
244
|
t,
|
|
245
245
|
r,
|
|
246
246
|
p,
|
|
@@ -257,8 +257,8 @@ const ft = async (t, r, p, d, l, u) => {
|
|
|
257
257
|
E,
|
|
258
258
|
l,
|
|
259
259
|
g
|
|
260
|
-
);
|
|
260
|
+
), w;
|
|
261
261
|
};
|
|
262
262
|
export {
|
|
263
|
-
|
|
263
|
+
Io as hinkalSolanaDepositAndWithdraw
|
|
264
264
|
};
|