@hinkal/common 0.2.23 → 0.2.25
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 +267 -63
- 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
|
@@ -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;
|