h_test_1 0.0.4 → 0.0.5
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/hinkalSwap.cjs +1 -1
- package/data-structures/Hinkal/hinkalSwap.mjs +84 -61
- package/data-structures/crypto-keys/encryptDecryptUtxo.mjs +1 -0
- package/functions/web3/events/getInputUtxoAndBalance.cjs +1 -1
- package/functions/web3/events/getInputUtxoAndBalance.mjs +48 -48
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("../../error-handling/error-codes.constants.cjs"),L=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),M=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),H=require("../../functions/web3/events/getShieldedBalance.cjs"),K=require("../../functions/web3/functionCalls/estimateGasRelayer.cjs"),N=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),W=require("../../functions/pre-transaction/getFeeStructure.cjs"),B=require("../../functions/pre-transaction/merge-with-fee-structure.cjs"),b=require("../../types/external-action.types.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("../../error-handling/error-codes.constants.cjs"),L=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),M=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),H=require("../../functions/web3/events/getShieldedBalance.cjs"),K=require("../../functions/web3/functionCalls/estimateGasRelayer.cjs"),N=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),W=require("../../functions/pre-transaction/getFeeStructure.cjs"),B=require("../../functions/pre-transaction/merge-with-fee-structure.cjs"),b=require("../../types/external-action.types.cjs"),G=require("../../types/hinkal.types.cjs"),O=require("../../functions/pre-transaction/outputApprovalDataProcessing.cjs"),V=require("../../types/ethereum-network.types.cjs"),Z=require("../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs"),$=require("../../functions/pre-transaction/getSignatureDataForTransact.cjs"),j=require("../../functions/pre-transaction/getExternalSwapAddress.cjs"),z=require("../../functions/utils/time.utils.cjs"),Y=require("../../constants/protocol.constants.cjs");require("../../types/circom-data.types.cjs");require("../../types/activities.types.cjs");require("../../constants/server.constants.cjs");require("../../constants/chains.constants.cjs");require("../../constants/vite.constants.cjs");require("../http/HttpClient.cjs");require("axios");require("ethers");require("../../constants/token-data/index.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("@solana/web3.js");require("../crypto-keys/keys.cjs");const J=require("../../functions/pre-transaction/constructAdminData.cjs");require("@solana/spl-token");const Q=async(e,c,t,i,A,C,k,x,l=!1,y=!1)=>{console.log("hinkalSwap 1");const o=c.map(r=>r.erc20TokenAddress);console.log("hinkalSwap 2");const u=await e.getEthereumAddress();console.log("hinkalSwap 3");const g=k??await W.getFeeStructure(e.getCurrentChainId(),C,o,b.ExternalActionId.Transact,void 0,Y.HINKAL_SWAP_VARIABLE_RATE);B.mergeWithFeeStructure(e.getCurrentChainId(),o,t,g),console.log("hinkalSwap 4");const T=j.getExternalSwapAddress(e,i),s={externalActionId:i,externalAddress:T,externalActionMetadata:A};console.log("hinkalSwap 5");const a=[...await H.addPaddingToUtxos(e,o,t)],m=`swapperM${t.length.toString()}x${a[0].length}x1`;console.log("hinkalSwap 6");const f=[!1,!0,!1].slice(0,t.length),p=[];console.log("hinkalSwap 7");const n=G.defaultHinkalLogicArgs(t.length,e.userKeys);console.log("hinkalSwap 8");const v=z.getCurrentTimeInSeconds().toString();for(let r=0;r<o.length;r+=1){console.log("hinkalSwap 9",{i:r});const{outputUtxos:U}=L.outputUtxoProcessing(e.userKeys,a[r],t[r],v,void 0,!1);console.log("hinkalSwap 10",{i:r}),p.push(U);const{useApprovalUtxoData:h}=O.outputApprovalDataProcessing(e,a[r],t[r]);console.log("hinkalSwap 11",{i:r}),h&&(n.useApprovalUtxoData[r]=h,n.doPreTxApproval=!0),console.log("hinkalSwap 12",{i:r})}console.log("hinkalSwap 13");const d=await e.getRandomRelay(!l);if(!d)throw Error(F.transactionErrorCodes.RELAYER_NOT_AVAILABLE);console.log("hinkalSwap 14");const{patchAccessTokenMerkleTree:D,kycRequired:P,hasAccessToken:R}=await Z.shouldPatchAccessTokenMerkleTree(e,o,t);console.log("hinkalSwap 15");const E=await $.getSignatureDataForTransact(e.getCurrentChainId(),u,e.userKeys,P,R);console.log("hinkalSwap 16");const{zkCallData:q,circomData:S,dimData:w}=await M.constructZkProof("v1x1",e.merkleTreeHinkal,e.merkleTreeAccessToken,a,p,e.userKeys,m,s.externalActionId,s.externalAddress,s.externalActionMetadata,e.generateProofRemotely,d,e.getCurrentChainId(),f,void 0,void 0,D,n,void 0,g,e.getContractWithFetcher(V.ContractType.HinkalHelperContract),E);if(console.log("hinkalSwap 17"),l)return await K.estimateGasRelayer(e,q,w,S);console.log("hinkalSwap 18");const I=J.constructAdminData(x,e.getCurrentChainId(),o,t,u,c);console.log("hinkalSwap 19");const _=await N.transactCallRelayer(e.getCurrentChainId(),q,w,S,y,void 0,void 0,I);return console.log("hinkalSwap 20"),_};exports.hinkalSwap=Q;
|
|
@@ -37,92 +37,115 @@ import "@solana/web3.js";
|
|
|
37
37
|
import "../crypto-keys/keys.mjs";
|
|
38
38
|
import { constructAdminData as J } from "../../functions/pre-transaction/constructAdminData.mjs";
|
|
39
39
|
import "@solana/spl-token";
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
const No = async (o, s, r, p, h, A, C, x, c = !1, T = !1) => {
|
|
41
|
+
console.log("hinkalSwap 1");
|
|
42
|
+
const e = s.map((t) => t.erc20TokenAddress);
|
|
43
|
+
console.log("hinkalSwap 2");
|
|
44
|
+
const l = await o.getEthereumAddress();
|
|
45
|
+
console.log("hinkalSwap 3");
|
|
46
|
+
const m = C ?? await B(
|
|
47
|
+
o.getCurrentChainId(),
|
|
48
|
+
A,
|
|
49
|
+
e,
|
|
45
50
|
$.Transact,
|
|
46
51
|
void 0,
|
|
47
52
|
G
|
|
48
53
|
);
|
|
49
|
-
V(
|
|
50
|
-
const
|
|
54
|
+
V(o.getCurrentChainId(), e, r, m), console.log("hinkalSwap 4");
|
|
55
|
+
const k = b(o, p), i = {
|
|
51
56
|
externalActionId: p,
|
|
52
|
-
externalAddress:
|
|
53
|
-
externalActionMetadata:
|
|
54
|
-
}
|
|
55
|
-
|
|
57
|
+
externalAddress: k,
|
|
58
|
+
externalActionMetadata: h
|
|
59
|
+
};
|
|
60
|
+
console.log("hinkalSwap 5");
|
|
61
|
+
const a = [...await F(o, e, r)], y = `swapperM${r.length.toString()}x${a[0].length}x1`;
|
|
62
|
+
console.log("hinkalSwap 6");
|
|
63
|
+
const v = [!1, !0, !1].slice(0, r.length), g = [];
|
|
64
|
+
console.log("hinkalSwap 7");
|
|
65
|
+
const n = q(r.length, o.userKeys);
|
|
66
|
+
console.log("hinkalSwap 8");
|
|
67
|
+
const D = j().toString();
|
|
68
|
+
for (let t = 0; t < e.length; t += 1) {
|
|
69
|
+
console.log("hinkalSwap 9", { i: t });
|
|
56
70
|
const { outputUtxos: H } = M(
|
|
57
|
-
|
|
58
|
-
a[
|
|
59
|
-
|
|
60
|
-
|
|
71
|
+
o.userKeys,
|
|
72
|
+
a[t],
|
|
73
|
+
r[t],
|
|
74
|
+
D,
|
|
61
75
|
void 0,
|
|
62
76
|
!1
|
|
63
77
|
);
|
|
64
|
-
|
|
65
|
-
const { useApprovalUtxoData:
|
|
66
|
-
|
|
78
|
+
console.log("hinkalSwap 10", { i: t }), g.push(H);
|
|
79
|
+
const { useApprovalUtxoData: S } = z(o, a[t], r[t]);
|
|
80
|
+
console.log("hinkalSwap 11", { i: t }), S && (n.useApprovalUtxoData[t] = S, n.doPreTxApproval = !0), console.log("hinkalSwap 12", { i: t });
|
|
67
81
|
}
|
|
68
|
-
|
|
69
|
-
|
|
82
|
+
console.log("hinkalSwap 13");
|
|
83
|
+
const d = await o.getRandomRelay(!c);
|
|
84
|
+
if (!d)
|
|
70
85
|
throw Error(K.RELAYER_NOT_AVAILABLE);
|
|
71
|
-
|
|
72
|
-
|
|
86
|
+
console.log("hinkalSwap 14");
|
|
87
|
+
const { patchAccessTokenMerkleTree: E, kycRequired: I, hasAccessToken: R } = await Y(
|
|
73
88
|
o,
|
|
74
|
-
e
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
89
|
+
e,
|
|
90
|
+
r
|
|
91
|
+
);
|
|
92
|
+
console.log("hinkalSwap 15");
|
|
93
|
+
const P = await Z(
|
|
94
|
+
o.getCurrentChainId(),
|
|
95
|
+
l,
|
|
96
|
+
o.userKeys,
|
|
97
|
+
I,
|
|
98
|
+
R
|
|
99
|
+
);
|
|
100
|
+
console.log("hinkalSwap 16");
|
|
101
|
+
const { zkCallData: u, circomData: w, dimData: f } = await _(
|
|
82
102
|
"v1x1",
|
|
83
|
-
|
|
84
|
-
|
|
103
|
+
o.merkleTreeHinkal,
|
|
104
|
+
o.merkleTreeAccessToken,
|
|
85
105
|
a,
|
|
86
|
-
u,
|
|
87
|
-
t.userKeys,
|
|
88
|
-
D,
|
|
89
|
-
s.externalActionId,
|
|
90
|
-
s.externalAddress,
|
|
91
|
-
s.externalActionMetadata,
|
|
92
|
-
t.generateProofRemotely,
|
|
93
106
|
g,
|
|
94
|
-
|
|
95
|
-
|
|
107
|
+
o.userKeys,
|
|
108
|
+
y,
|
|
109
|
+
i.externalActionId,
|
|
110
|
+
i.externalAddress,
|
|
111
|
+
i.externalActionMetadata,
|
|
112
|
+
o.generateProofRemotely,
|
|
113
|
+
d,
|
|
114
|
+
o.getCurrentChainId(),
|
|
115
|
+
v,
|
|
96
116
|
void 0,
|
|
97
117
|
void 0,
|
|
98
|
-
|
|
99
|
-
|
|
118
|
+
E,
|
|
119
|
+
n,
|
|
100
120
|
void 0,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
121
|
+
m,
|
|
122
|
+
o.getContractWithFetcher(O.HinkalHelperContract),
|
|
123
|
+
P
|
|
104
124
|
);
|
|
105
|
-
if (c)
|
|
106
|
-
return await N(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
o,
|
|
125
|
+
if (console.log("hinkalSwap 17"), c)
|
|
126
|
+
return await N(o, u, f, w);
|
|
127
|
+
console.log("hinkalSwap 18");
|
|
128
|
+
const L = J(
|
|
129
|
+
x,
|
|
130
|
+
o.getCurrentChainId(),
|
|
111
131
|
e,
|
|
112
|
-
|
|
113
|
-
|
|
132
|
+
r,
|
|
133
|
+
l,
|
|
134
|
+
s
|
|
114
135
|
);
|
|
115
|
-
|
|
116
|
-
|
|
136
|
+
console.log("hinkalSwap 19");
|
|
137
|
+
const U = await W(
|
|
138
|
+
o.getCurrentChainId(),
|
|
139
|
+
u,
|
|
117
140
|
f,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
v,
|
|
141
|
+
w,
|
|
142
|
+
T,
|
|
121
143
|
void 0,
|
|
122
144
|
void 0,
|
|
123
|
-
|
|
145
|
+
L
|
|
124
146
|
);
|
|
147
|
+
return console.log("hinkalSwap 20"), U;
|
|
125
148
|
};
|
|
126
149
|
export {
|
|
127
|
-
|
|
150
|
+
No as hinkalSwap
|
|
128
151
|
};
|
|
@@ -7,6 +7,7 @@ const K = (e) => {
|
|
|
7
7
|
const r = [
|
|
8
8
|
Buffer.from(o.toBeHex(e.amount)),
|
|
9
9
|
Buffer.from(e.erc20TokenAddress),
|
|
10
|
+
// if it is zeroAddress toBeHex will return 0x00
|
|
10
11
|
Buffer.from(o.toBeHex(e.randomization)),
|
|
11
12
|
Buffer.from(e.getStealthAddress()),
|
|
12
13
|
Buffer.from(o.toBeHex(BigInt(e.timeStamp))),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("../../../data-structures/utxo/Utxo.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("../../../data-structures/utxo/Utxo.cjs"),k=require("../../utils/upToDateState.cjs"),O=require("../../utils/cacheFunctions.cjs"),K=require("../../utils/caseInsensitive.utils.cjs"),P=require("../../utils/encodeTokenWithId.cjs"),M=require("./getInputUtxosEnclave.cjs"),F=require("../../../error-handling/logger.cjs"),H=require("../../utils/solanaMint.utils.cjs"),_=require("../../../constants/chains.constants.cjs"),j=require("../../utils/addresses.cjs"),G=require("../../../API/scheduled-transactions-calls.cjs"),b=async(t,o,e,n,c,r,u,a,s)=>{s+=1;const l=r.slice(s),{lastOutput:w,additionalEncryptedOutputs:f}=await t.utxoUtils.batchProcess(l,a,o,e),i=[...u,...f];return await k.checkChainOrAddressNotUpdated(t,e,n),O.setHinkalCache({lastOutput:w,encryptedOutputs:i},t,e,c),await t.utxoUtils.buildBatchProcess(i,o,e)},q=async(t,o,e,n)=>{const{utxos:c,encryptedOutputs:r,lastOutput:u}=await M.getInputUtxosEnclave(t,e,o);return O.setHinkalCache({encryptedOutputs:r,lastOutput:u},t,e,n),c},S=async(t,o,e,n,c,r,u,a,s)=>{try{return await q(t,o,e,c)}catch{return b(t,o,e,n,c,r,u,a,s)}},D=t=>{if(Array.isArray(t))return t;if(t!==void 0)return[t]},J=async(t,o,e)=>await t.utxoUtils.batchFilterUtxosWithNullifier(o,e),W=(t,o,e,n,c,r,u)=>{for(t.sort((a,s)=>a.amount<=s.amount?1:-1),console.log("sorted utxos");t.length<o||t.length>o&&t.length<6;)if(console.log("before pushing"),console.log("aaa",c,u,n,r),t.push(new R.Utxo({amount:0n,erc20TokenAddress:c,mintAddress:u,shieldedPrivateKey:n,tokenId:r,enableLogs:!0})),console.log("after pushing"),e)for(;t.length>6;)t.splice(t.length-1);console.log("completed sorting utxos")},C=async({hinkal:t,chainId:o=void 0,passedShieldedPublicKey:e=void 0,ethAddress:n=void 0,resetCacheBefore:c=!1,allowRemoteDecryption:r=!1,useBlockedUtxos:u=!1})=>{if(!t.getCurrentChainId||!t.getSelectedNetwork())return F.Logger.log("returning empty balance"),{inputUtxos:[]};const a=n??await t.getEthereumAddress(),s=o??t.getCurrentChainId(),l=e??t.userKeys.getShieldedPublicKey(),{encryptedOutputs:w,nullifiers:f,userKeys:i}=t,g=Array.from(w);console.log("getInputUtxoAndBalance 1"),c&&O.resetCache(t,s,l);let{encryptedOutputs:h,lastOutput:x}=O.getHinkalCache(t,s,l);console.log("getInputUtxoAndBalance 2"),await k.checkChainOrAddressNotUpdated(t,s,a),console.log("getInputUtxoAndBalance 3");const p=x!=="",d=g.findIndex(m=>m.value===x);console.log("getInputUtxoAndBalance 4");const y=d>-1,T=!p&&d===-1;console.log("getInputUtxoAndBalance 5");const I=t.areMerkleTreeUpdatesDisabled();console.log("getInputUtxoAndBalance 6");const v=!I&&(y||!r&&T),B=!I&&r&&T,U=!v&&!B;let A=[];v?A=await b(t,i,s,a,l,g,h,x,d):B?A=await S(t,i,s,a,l,g,h,x,d):U&&(A=await t.utxoUtils.buildBatchProcess(h,i,s)),console.log("getInputUtxoAndBalance 7"),await k.checkChainOrAddressNotUpdated(t,s,a);const E=await J(t,A,f);console.log("getInputUtxoAndBalance 8");const L=u?E:E.filter(m=>!m.isBlocked);return console.log("getInputUtxoAndBalance 9"),console.trace(),{inputUtxos:L}},N=async({hinkal:t,chainId:o=void 0,passedShieldedPublicKey:e=void 0,ethAddress:n=void 0,resetCacheBefore:c=!1,allowRemoteDecryption:r=!1})=>{const u=o??t.getCurrentChainId(),a=n??await t.getEthereumAddress(),s=j.hashEthereumAddress(a),{inputUtxos:l}=await C({hinkal:t,chainId:u,passedShieldedPublicKey:e,ethAddress:a,resetCacheBefore:c,allowRemoteDecryption:r,useBlockedUtxos:!0});if(!l.length)return{inputUtxos:[]};const w=l.map(g=>g.getNullifier()),{indexes:f}=await G.getScheduledTransactionsNullifierIndexes(u,{hashedEthereumAddress:s,nullifiers:w});return{inputUtxos:f.map(g=>l[g]).filter(g=>!!g)}},z=async({hinkal:t,tokenWithId:o,minInput:e=2,sliceIfMore6:n=!0,chainId:c=void 0,passedShieldedPrivateKey:r=void 0,passedShieldedPublicKey:u=void 0,ethAddress:a=void 0,resetCacheBefore:s=!1,ensuredTokensWithId:l,useBlockedUtxos:w=!1})=>{const f=r??t.userKeys.getShieldedPrivateKey(),i=c??t.getCurrentChainId();console.log("getInputUtxoAndBalancePerToken 1");const{inputUtxos:g}=w?await N({hinkal:t,chainId:c,ethAddress:a,passedShieldedPrivateKey:r,resetCacheBefore:s}):await C({hinkal:t,tokenWithId:o,minInput:e,sliceIfMore6:n,chainId:c,passedShieldedPrivateKey:r,passedShieldedPublicKey:u,ethAddress:a,resetCacheBefore:s});console.log("getInputUtxoAndBalancePerToken 2");const h=D(o),x=new Map;console.log("getInputUtxoAndBalancePerToken 3"),g.forEach(p=>{const d=p.getTokenAddress(i);if(h&&!h.some(I=>K.caseInsensitiveEqual(I.erc20TokenAddress,d)&&I.tokenId===p.tokenId))return;const y=P.encodeTokenWithId(i,{erc20TokenAddress:d,tokenId:p.tokenId}),T=x.get(y)??[];x.set(y,[...T,p])}),console.log("getInputUtxoAndBalancePerToken 4"),l?.forEach(p=>{const d=P.encodeTokenWithId(i,{erc20TokenAddress:p.erc20TokenAddress,tokenId:p.tokenId});x.set(d,x.get(d)??[])}),console.log("getInputUtxoAndBalancePerToken 5");for(const[p,d]of x){const y=p.split("-")[0],T=Number(p.split("-")[1]),I=_.isSolanaLike(i),v=I?y:void 0,B=I?H.formatMintAddress(y).compressedAddress.toLowerCase():y.toLowerCase(),U=A=>A===null?"null":typeof A!="object"?typeof A:A.constructor.name;console.log("types",JSON.stringify({value:U(d),minInput:U(e),sliceIfMore6:U(n),shieldedPrivateKey:U(f),modifiedErc20TokenAddress:U(B),tokenId:U(T),mintAddress:U(v)})),console.log("started padding"),W(d,e,n,f,B,T,v),console.log("done padding")}return console.log("getInputUtxoAndBalancePerToken 6"),x};exports.attemptGetInputUtxosRemotely=S;exports.getInputUtxoAndBalance=C;exports.getInputUtxoAndBalanceOfStuckUtxos=N;exports.getInputUtxoAndBalancePerToken=z;exports.getInputUtxosRemotely=q;
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import { Utxo as S } from "../../../data-structures/utxo/Utxo.mjs";
|
|
2
|
-
import { checkChainOrAddressNotUpdated as
|
|
3
|
-
import { setHinkalCache as
|
|
2
|
+
import { checkChainOrAddressNotUpdated as h } from "../../utils/upToDateState.mjs";
|
|
3
|
+
import { setHinkalCache as C, resetCache as L, getHinkalCache as K } from "../../utils/cacheFunctions.mjs";
|
|
4
4
|
import { caseInsensitiveEqual as R } from "../../utils/caseInsensitive.utils.mjs";
|
|
5
|
-
import { encodeTokenWithId as
|
|
5
|
+
import { encodeTokenWithId as P } from "../../utils/encodeTokenWithId.mjs";
|
|
6
6
|
import { getInputUtxosEnclave as F } from "./getInputUtxosEnclave.mjs";
|
|
7
7
|
import { Logger as H } from "../../../error-handling/logger.mjs";
|
|
8
8
|
import { formatMintAddress as M } from "../../utils/solanaMint.utils.mjs";
|
|
9
9
|
import { isSolanaLike as j } from "../../../constants/chains.constants.mjs";
|
|
10
10
|
import { hashEthereumAddress as q } from "../../utils/addresses.mjs";
|
|
11
11
|
import { getScheduledTransactionsNullifierIndexes as G } from "../../../API/scheduled-transactions-calls.mjs";
|
|
12
|
-
const
|
|
12
|
+
const b = async (t, o, e, n, r, c, l, a, s) => {
|
|
13
13
|
s += 1;
|
|
14
|
-
const u = c.slice(s), { lastOutput:
|
|
14
|
+
const u = c.slice(s), { lastOutput: I, additionalEncryptedOutputs: A } = await t.utxoUtils.batchProcess(
|
|
15
15
|
u,
|
|
16
16
|
a,
|
|
17
17
|
o,
|
|
18
18
|
e
|
|
19
|
-
), i = [...l, ...
|
|
20
|
-
return await
|
|
19
|
+
), i = [...l, ...A];
|
|
20
|
+
return await h(t, e, n), C(
|
|
21
21
|
{
|
|
22
|
-
lastOutput:
|
|
22
|
+
lastOutput: I,
|
|
23
23
|
encryptedOutputs: i
|
|
24
24
|
},
|
|
25
25
|
t,
|
|
@@ -32,7 +32,7 @@ const k = async (t, o, e, n, r, c, l, a, s) => {
|
|
|
32
32
|
encryptedOutputs: c,
|
|
33
33
|
lastOutput: l
|
|
34
34
|
} = await F(t, e, o);
|
|
35
|
-
return
|
|
35
|
+
return C(
|
|
36
36
|
{
|
|
37
37
|
encryptedOutputs: c,
|
|
38
38
|
lastOutput: l
|
|
@@ -45,7 +45,7 @@ const k = async (t, o, e, n, r, c, l, a, s) => {
|
|
|
45
45
|
try {
|
|
46
46
|
return await J(t, o, e, r);
|
|
47
47
|
} catch {
|
|
48
|
-
return
|
|
48
|
+
return b(
|
|
49
49
|
t,
|
|
50
50
|
o,
|
|
51
51
|
e,
|
|
@@ -70,7 +70,7 @@ const k = async (t, o, e, n, r, c, l, a, s) => {
|
|
|
70
70
|
for (; t.length > 6; )
|
|
71
71
|
t.splice(t.length - 1);
|
|
72
72
|
console.log("completed sorting utxos");
|
|
73
|
-
},
|
|
73
|
+
}, k = async ({
|
|
74
74
|
hinkal: t,
|
|
75
75
|
chainId: o = void 0,
|
|
76
76
|
passedShieldedPublicKey: e = void 0,
|
|
@@ -81,23 +81,23 @@ const k = async (t, o, e, n, r, c, l, a, s) => {
|
|
|
81
81
|
}) => {
|
|
82
82
|
if (!t.getCurrentChainId || !t.getSelectedNetwork())
|
|
83
83
|
return H.log("returning empty balance"), { inputUtxos: [] };
|
|
84
|
-
const a = n ?? await t.getEthereumAddress(), s = o ?? t.getCurrentChainId(), u = e ?? t.userKeys.getShieldedPublicKey(), { encryptedOutputs:
|
|
85
|
-
console.log("getInputUtxoAndBalance 1"
|
|
84
|
+
const a = n ?? await t.getEthereumAddress(), s = o ?? t.getCurrentChainId(), u = e ?? t.userKeys.getShieldedPublicKey(), { encryptedOutputs: I, nullifiers: A, userKeys: i } = t, p = Array.from(I);
|
|
85
|
+
console.log("getInputUtxoAndBalance 1"), r && L(t, s, u);
|
|
86
86
|
let { encryptedOutputs: v, lastOutput: f } = K(
|
|
87
87
|
t,
|
|
88
88
|
s,
|
|
89
89
|
u
|
|
90
90
|
);
|
|
91
|
-
console.log("getInputUtxoAndBalance 2"), await
|
|
92
|
-
const g = f !== "", d = p.findIndex((
|
|
91
|
+
console.log("getInputUtxoAndBalance 2"), await h(t, s, a), console.log("getInputUtxoAndBalance 3");
|
|
92
|
+
const g = f !== "", d = p.findIndex((O) => O.value === f);
|
|
93
93
|
console.log("getInputUtxoAndBalance 4");
|
|
94
|
-
const
|
|
94
|
+
const m = d > -1, w = !g && d === -1;
|
|
95
95
|
console.log("getInputUtxoAndBalance 5");
|
|
96
|
-
const
|
|
96
|
+
const y = t.areMerkleTreeUpdatesDisabled();
|
|
97
97
|
console.log("getInputUtxoAndBalance 6");
|
|
98
|
-
const B = !
|
|
99
|
-
let
|
|
100
|
-
B ?
|
|
98
|
+
const B = !y && (m || !c && w), T = !y && c && w, x = !B && !T;
|
|
99
|
+
let U = [];
|
|
100
|
+
B ? U = await b(
|
|
101
101
|
t,
|
|
102
102
|
i,
|
|
103
103
|
s,
|
|
@@ -107,7 +107,7 @@ const k = async (t, o, e, n, r, c, l, a, s) => {
|
|
|
107
107
|
v,
|
|
108
108
|
f,
|
|
109
109
|
d
|
|
110
|
-
) : T ?
|
|
110
|
+
) : T ? U = await z(
|
|
111
111
|
t,
|
|
112
112
|
i,
|
|
113
113
|
s,
|
|
@@ -117,11 +117,11 @@ const k = async (t, o, e, n, r, c, l, a, s) => {
|
|
|
117
117
|
v,
|
|
118
118
|
f,
|
|
119
119
|
d
|
|
120
|
-
) :
|
|
121
|
-
const
|
|
122
|
-
console.log("getInputUtxoAndBalance 8"
|
|
123
|
-
const
|
|
124
|
-
return console.log("getInputUtxoAndBalance 9"
|
|
120
|
+
) : x && (U = await t.utxoUtils.buildBatchProcess(v, i, s)), console.log("getInputUtxoAndBalance 7"), await h(t, s, a);
|
|
121
|
+
const E = await Q(t, U, A);
|
|
122
|
+
console.log("getInputUtxoAndBalance 8");
|
|
123
|
+
const N = l ? E : E.filter((O) => !O.isBlocked);
|
|
124
|
+
return console.log("getInputUtxoAndBalance 9"), console.trace(), { inputUtxos: N };
|
|
125
125
|
}, X = async ({
|
|
126
126
|
hinkal: t,
|
|
127
127
|
chainId: o = void 0,
|
|
@@ -130,7 +130,7 @@ const k = async (t, o, e, n, r, c, l, a, s) => {
|
|
|
130
130
|
resetCacheBefore: r = !1,
|
|
131
131
|
allowRemoteDecryption: c = !1
|
|
132
132
|
}) => {
|
|
133
|
-
const l = o ?? t.getCurrentChainId(), a = n ?? await t.getEthereumAddress(), s = q(a), { inputUtxos: u } = await
|
|
133
|
+
const l = o ?? t.getCurrentChainId(), a = n ?? await t.getEthereumAddress(), s = q(a), { inputUtxos: u } = await k({
|
|
134
134
|
hinkal: t,
|
|
135
135
|
chainId: l,
|
|
136
136
|
passedShieldedPublicKey: e,
|
|
@@ -141,11 +141,11 @@ const k = async (t, o, e, n, r, c, l, a, s) => {
|
|
|
141
141
|
});
|
|
142
142
|
if (!u.length)
|
|
143
143
|
return { inputUtxos: [] };
|
|
144
|
-
const
|
|
144
|
+
const I = u.map((p) => p.getNullifier()), { indexes: A } = await G(l, {
|
|
145
145
|
hashedEthereumAddress: s,
|
|
146
|
-
nullifiers:
|
|
146
|
+
nullifiers: I
|
|
147
147
|
});
|
|
148
|
-
return { inputUtxos:
|
|
148
|
+
return { inputUtxos: A.map((p) => u[p]).filter((p) => !!p) };
|
|
149
149
|
}, ct = async ({
|
|
150
150
|
hinkal: t,
|
|
151
151
|
tokenWithId: o,
|
|
@@ -157,17 +157,17 @@ const k = async (t, o, e, n, r, c, l, a, s) => {
|
|
|
157
157
|
ethAddress: a = void 0,
|
|
158
158
|
resetCacheBefore: s = !1,
|
|
159
159
|
ensuredTokensWithId: u,
|
|
160
|
-
useBlockedUtxos:
|
|
160
|
+
useBlockedUtxos: I = !1
|
|
161
161
|
}) => {
|
|
162
|
-
const
|
|
162
|
+
const A = c ?? t.userKeys.getShieldedPrivateKey(), i = r ?? t.getCurrentChainId();
|
|
163
163
|
console.log("getInputUtxoAndBalancePerToken 1");
|
|
164
|
-
const { inputUtxos: p } =
|
|
164
|
+
const { inputUtxos: p } = I ? await X({
|
|
165
165
|
hinkal: t,
|
|
166
166
|
chainId: r,
|
|
167
167
|
ethAddress: a,
|
|
168
168
|
passedShieldedPrivateKey: c,
|
|
169
169
|
resetCacheBefore: s
|
|
170
|
-
}) : await
|
|
170
|
+
}) : await k({
|
|
171
171
|
hinkal: t,
|
|
172
172
|
tokenWithId: o,
|
|
173
173
|
minInput: e,
|
|
@@ -183,38 +183,38 @@ const k = async (t, o, e, n, r, c, l, a, s) => {
|
|
|
183
183
|
console.log("getInputUtxoAndBalancePerToken 3"), p.forEach((g) => {
|
|
184
184
|
const d = g.getTokenAddress(i);
|
|
185
185
|
if (v && !v.some(
|
|
186
|
-
(
|
|
186
|
+
(y) => R(y.erc20TokenAddress, d) && y.tokenId === g.tokenId
|
|
187
187
|
))
|
|
188
188
|
return;
|
|
189
|
-
const
|
|
190
|
-
f.set(
|
|
189
|
+
const m = P(i, { erc20TokenAddress: d, tokenId: g.tokenId }), w = f.get(m) ?? [];
|
|
190
|
+
f.set(m, [...w, g]);
|
|
191
191
|
}), console.log("getInputUtxoAndBalancePerToken 4"), u?.forEach((g) => {
|
|
192
|
-
const d =
|
|
192
|
+
const d = P(i, {
|
|
193
193
|
erc20TokenAddress: g.erc20TokenAddress,
|
|
194
194
|
tokenId: g.tokenId
|
|
195
195
|
});
|
|
196
196
|
f.set(d, f.get(d) ?? []);
|
|
197
197
|
}), console.log("getInputUtxoAndBalancePerToken 5");
|
|
198
198
|
for (const [g, d] of f) {
|
|
199
|
-
const
|
|
199
|
+
const m = g.split("-")[0], w = Number(g.split("-")[1]), y = j(i), B = y ? m : void 0, T = y ? M(m).compressedAddress.toLowerCase() : m.toLowerCase(), x = (U) => U === null ? "null" : typeof U != "object" ? typeof U : U.constructor.name;
|
|
200
200
|
console.log(
|
|
201
201
|
"types",
|
|
202
202
|
JSON.stringify({
|
|
203
|
-
value:
|
|
204
|
-
minInput:
|
|
205
|
-
sliceIfMore6:
|
|
206
|
-
shieldedPrivateKey:
|
|
207
|
-
modifiedErc20TokenAddress:
|
|
208
|
-
tokenId:
|
|
209
|
-
mintAddress:
|
|
203
|
+
value: x(d),
|
|
204
|
+
minInput: x(e),
|
|
205
|
+
sliceIfMore6: x(n),
|
|
206
|
+
shieldedPrivateKey: x(A),
|
|
207
|
+
modifiedErc20TokenAddress: x(T),
|
|
208
|
+
tokenId: x(w),
|
|
209
|
+
mintAddress: x(B)
|
|
210
210
|
})
|
|
211
|
-
), console.log("started padding"), V(d, e, n,
|
|
211
|
+
), console.log("started padding"), V(d, e, n, A, T, w, B), console.log("done padding");
|
|
212
212
|
}
|
|
213
213
|
return console.log("getInputUtxoAndBalancePerToken 6"), f;
|
|
214
214
|
};
|
|
215
215
|
export {
|
|
216
216
|
z as attemptGetInputUtxosRemotely,
|
|
217
|
-
|
|
217
|
+
k as getInputUtxoAndBalance,
|
|
218
218
|
X as getInputUtxoAndBalanceOfStuckUtxos,
|
|
219
219
|
ct as getInputUtxoAndBalancePerToken,
|
|
220
220
|
J as getInputUtxosRemotely
|