@hinkal/common 0.3.4 → 0.3.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/assets/snarkjsWorkerLauncher-SrStwJvX.js +1 -0
- package/assets/snarkjsWorkerLogic-DtIjisbE.js +132 -0
- package/assets/utxoWorkerLauncher-CIBeBAML.js +1 -0
- package/assets/utxoWorkerLogic-C8R4GSaf.js +199 -0
- package/assets/zkProofWorkerLauncher-DfwteloJ.js +1 -0
- package/assets/zkProofWorkerLogic-CY9y6rOV.js +199 -0
- package/common/src/constants/vite.constants.cjs +1 -1
- package/common/src/constants/vite.constants.mjs +23 -5
- package/common/src/data-structures/Hinkal/hinkalSolanaClaimUtxo.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaClaimUtxo.mjs +50 -97
- package/common/src/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.mjs +90 -128
- package/common/src/data-structures/Hinkal/hinkalSolanaSwap.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaSwap.mjs +56 -110
- package/common/src/data-structures/Hinkal/hinkalSolanaTransact.cjs +1 -0
- package/common/src/data-structures/Hinkal/hinkalSolanaTransact.d.ts +3 -0
- package/common/src/data-structures/Hinkal/hinkalSolanaTransact.mjs +117 -0
- package/common/src/data-structures/Hinkal/hinkalSolanaTransfer.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaTransfer.d.ts +2 -31
- package/common/src/data-structures/Hinkal/hinkalSolanaTransfer.mjs +45 -121
- package/common/src/data-structures/Hinkal/hinkalSolanaWithdraw.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaWithdraw.mjs +41 -83
- package/common/src/data-structures/Hinkal/hinkalTransact.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalTransact.mjs +41 -42
- package/common/src/data-structures/Hinkal/hinkalWithdrawStuckUtxos.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalWithdrawStuckUtxos.mjs +106 -125
- package/common/src/data-structures/IndexedDB/pay-activity-db.cjs +1 -1
- package/common/src/data-structures/IndexedDB/pay-activity-db.mjs +43 -1
- package/common/src/functions/index.cjs +1 -1
- package/common/src/functions/index.mjs +0 -1
- package/common/src/functions/pre-transaction/ensureAmountChanges.cjs +1 -1
- package/common/src/functions/pre-transaction/ensureAmountChanges.mjs +3 -10
- package/common/src/functions/pre-transaction/outputUtxoProcessing.cjs +1 -1
- package/common/src/functions/pre-transaction/outputUtxoProcessing.d.ts +1 -0
- package/common/src/functions/pre-transaction/outputUtxoProcessing.mjs +13 -9
- package/common/src/functions/snarkjs/constructSolanaZkProof.cjs +1 -1
- package/common/src/functions/snarkjs/constructSolanaZkProof.d.ts +1 -1
- package/common/src/functions/snarkjs/constructSolanaZkProof.mjs +35 -35
- package/common/src/functions/snarkjs/constructTxEnclave.cjs +1 -1
- package/common/src/functions/snarkjs/constructTxEnclave.d.ts +2 -0
- package/common/src/functions/snarkjs/constructTxEnclave.mjs +40 -40
- package/common/src/functions/utils/enum.utils.cjs +1 -0
- package/common/src/functions/utils/enum.utils.mjs +12 -0
- package/common/src/functions/utils/index.cjs +1 -1
- package/common/src/functions/utils/index.mjs +0 -1
- package/common/src/types/index.cjs +1 -1
- package/common/src/types/index.d.ts +1 -0
- package/common/src/types/index.mjs +1 -0
- package/common/src/types/pay-activities.types.d.ts +18 -3
- package/common/src/types/solana-transact.types.cjs +1 -0
- package/common/src/types/solana-transact.types.d.ts +35 -0
- package/common/src/types/solana-transact.types.mjs +6 -0
- package/common/src/webworker/logError-Dex6ch32.js +2 -0
- package/common/src/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.cjs +1 -1
- package/common/src/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.mjs +1 -1
- package/common/src/webworker/snarkjsWorkerNode.cjs +1 -1
- package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.cjs +1 -1
- package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.mjs +1 -1
- package/common/src/webworker/utxoWorkerNode.cjs +1 -1
- package/common/src/webworker/viteWorkerURL.constant.cjs +1 -28
- package/common/src/webworker/viteWorkerURL.constant.mjs +13 -27
- package/common/src/webworker/workerProxy-BuJUMCQ4.js +1 -0
- package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.cjs +1 -1
- package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.mjs +1 -1
- package/common/src/webworker/zkProofWorkerNode.cjs +1 -1
- package/package.json +12 -12
- package/common/src/webworker/logError-CxZzSALU.js +0 -2
- package/common/src/webworker/workerProxy-swwPYw6e.js +0 -1
|
@@ -1,94 +1,52 @@
|
|
|
1
1
|
import { networkRegistry as e } from "../../constants/chains.constants.mjs";
|
|
2
2
|
import "../../constants/protocol.constants.mjs";
|
|
3
3
|
import { transactionErrorCodes as t } from "../../error-handling/error-codes.constants.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { getCurrentTimeInSeconds as i } from "../../functions/utils/time.utils.mjs";
|
|
7
|
-
import { ExternalActionId as a } from "../../types/external-action.types.mjs";
|
|
4
|
+
import { ExternalActionId as n } from "../../types/external-action.types.mjs";
|
|
5
|
+
import { SolanaSubmitMode as r } from "../../types/solana-transact.types.mjs";
|
|
8
6
|
import "../../types/index.mjs";
|
|
9
|
-
import { validateAndGetChainId as
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { finalizeSolanaTxEnclaveCallRelay as u, prepareSolanaTxEnclaveCall as d } from "../../functions/snarkjs/constructTxEnclave.mjs";
|
|
14
|
-
import { calculateSolanaNullifierCount as f } from "../../functions/pre-transaction/calculateSolanaNullifierCount.mjs";
|
|
15
|
-
import { ensureAmountChanges as p } from "../../functions/pre-transaction/ensureAmountChanges.mjs";
|
|
16
|
-
import { getFeeStructure as m } from "../../functions/pre-transaction/getFeeStructure.mjs";
|
|
7
|
+
import { validateAndGetChainId as i } from "../../functions/utils/token-check.utils.mjs";
|
|
8
|
+
import { constructAdminData as a } from "../../functions/pre-transaction/constructAdminData.mjs";
|
|
9
|
+
import { calculateSolanaNullifierCount as o } from "../../functions/pre-transaction/calculateSolanaNullifierCount.mjs";
|
|
10
|
+
import { getFeeStructure as s } from "../../functions/pre-transaction/getFeeStructure.mjs";
|
|
17
11
|
import "../../functions/pre-transaction/index.mjs";
|
|
18
|
-
import { solanaTransactCallRelayer as h } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
|
|
19
12
|
import "../../constants/index.mjs";
|
|
20
|
-
import { calculateModifiedFeeStructure as
|
|
21
|
-
import {
|
|
13
|
+
import { calculateModifiedFeeStructure as c } from "../../functions/utils/fees.utils.mjs";
|
|
14
|
+
import { hinkalSolanaTransact as l } from "./hinkalSolanaTransact.mjs";
|
|
22
15
|
//#region libs/shared/common/src/data-structures/Hinkal/hinkalSolanaWithdraw.ts
|
|
23
|
-
var
|
|
24
|
-
let
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
16
|
+
var u = async (u, d, f, p, m, h, g) => {
|
|
17
|
+
let _ = i(d), v = d.map((e) => e.erc20TokenAddress), y = d[0];
|
|
18
|
+
if (!y) throw Error("Solana Withdraw: No Token Found");
|
|
19
|
+
let { originalDeployer: b } = e[_].contractData;
|
|
20
|
+
if (!b) throw Error("missing data");
|
|
21
|
+
let x = m ?? v[0], S = {
|
|
22
|
+
mintTo: v[0],
|
|
23
|
+
recipient: p,
|
|
24
|
+
nullifierCount: await o(u, _, v, f)
|
|
25
|
+
}, C = h ?? await s(_, x, v, n.Transact, [], void 0, S), w = await c(_, y, -f[0], C);
|
|
26
|
+
f[0] -= w.flatFee;
|
|
27
|
+
let [T, E] = await Promise.all([u.getRandomRelay(_, !0), u.getEthereumAddress()]);
|
|
28
|
+
if (!T) throw Error(t.RELAYER_NOT_AVAILABLE);
|
|
29
|
+
if (v.length > 1) throw Error("Solana Withdraw: Only one mint address is supported");
|
|
30
|
+
let D = {
|
|
31
|
+
recipient: p,
|
|
32
|
+
mint: v[0] === "11111111111111111111111111111111" ? void 0 : v[0]
|
|
33
|
+
}, O = a(g, _, v, f, E);
|
|
34
|
+
return l(u, {
|
|
35
|
+
chainId: _,
|
|
36
|
+
mintAddresses: v,
|
|
37
|
+
amountChanges: f,
|
|
38
|
+
relayAddress: T,
|
|
39
|
+
recipient: p,
|
|
40
|
+
signer: T,
|
|
37
41
|
functionName: "transact",
|
|
38
|
-
accounts:
|
|
39
|
-
relayerFee:
|
|
40
|
-
variableRate:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
R8: p,
|
|
46
|
-
S: m
|
|
47
|
-
}, t, { adminData: c });
|
|
48
|
-
}, b = async (i, s, c, u, d, b, x) => {
|
|
49
|
-
let S = o(s), C = s.map((e) => e.erc20TokenAddress), w = s[0];
|
|
50
|
-
if (!w) throw Error("Solana Withdraw: No Token Found");
|
|
51
|
-
let { originalDeployer: T } = e[S].contractData;
|
|
52
|
-
if (!T) throw Error("missing data");
|
|
53
|
-
let { userKeys: E, merkleTreeHinkalByChain: D } = i, O = d ?? C[0], k = {
|
|
54
|
-
mintTo: C[0],
|
|
55
|
-
recipient: u,
|
|
56
|
-
nullifierCount: await f(i, S, C, c)
|
|
57
|
-
}, A = b ?? await m(S, O, C, a.Transact, [], void 0, k), j = await g(S, w, -c[0], A);
|
|
58
|
-
c[0] -= j.flatFee;
|
|
59
|
-
let [M, N] = await Promise.all([i.getRandomRelay(S, !0), i.getEthereumAddress()]);
|
|
60
|
-
if (!M) throw Error(t.RELAYER_NOT_AVAILABLE);
|
|
61
|
-
if (C.length > 1) throw Error("Solana Withdraw: Only one mint address is supported");
|
|
62
|
-
let P = {
|
|
63
|
-
recipient: u,
|
|
64
|
-
mint: C[0] === "11111111111111111111111111111111" ? void 0 : C[0]
|
|
65
|
-
}, F = l(x, S, C, c, N);
|
|
66
|
-
if (i.generateProofRemotely) return y(i, S, C, c, u, M, P, j, F);
|
|
67
|
-
let { inputUtxos: I, outputUtxos: L } = await v(i, S, C, c), R = r.findCorrectRandomization(n(31), i.userKeys.getShieldedPrivateKey()), z = {
|
|
68
|
-
tokenNumber: C.length,
|
|
69
|
-
nullifierAmount: I.length,
|
|
70
|
-
outputAmount: L.length
|
|
71
|
-
};
|
|
72
|
-
p([I], [L], c);
|
|
73
|
-
let { proofAArr: B, proofBArr: V, proofCArr: H, publicInputsArr: U, commitmentValidationData: W, rootHashHinkalIndex: G, encryptedOutputs: K } = await _(D[S], E, [C[0]], [I], [L], R, j.flatFee, j.variableRate, u, M, z, void 0, S);
|
|
74
|
-
return h({
|
|
75
|
-
chainId: S,
|
|
76
|
-
relayAddress: M,
|
|
77
|
-
functionName: "transact",
|
|
78
|
-
args: {
|
|
79
|
-
proofAArr: B,
|
|
80
|
-
proofBArr: V,
|
|
81
|
-
proofCArr: H,
|
|
82
|
-
publicInputsArr: U,
|
|
83
|
-
encryptedOutputs: K,
|
|
84
|
-
relayerFee: j.flatFee.toString(),
|
|
85
|
-
dimensions: z,
|
|
86
|
-
rootHashIndex: G.toString()
|
|
87
|
-
},
|
|
88
|
-
accounts: P,
|
|
89
|
-
commitmentValidationData: W,
|
|
90
|
-
adminData: F
|
|
42
|
+
accounts: D,
|
|
43
|
+
relayerFee: w.flatFee,
|
|
44
|
+
variableRate: w.variableRate,
|
|
45
|
+
submit: {
|
|
46
|
+
mode: r.Relayer,
|
|
47
|
+
adminData: O
|
|
48
|
+
}
|
|
91
49
|
});
|
|
92
50
|
};
|
|
93
51
|
//#endregion
|
|
94
|
-
export {
|
|
52
|
+
export { u as hinkalSolanaWithdraw };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../constants/protocol.constants.cjs`),t=require(`../../types/hinkal.types.cjs`),n=require(
|
|
1
|
+
const e=require(`../../constants/protocol.constants.cjs`),t=require(`../../types/hinkal.types.cjs`),n=require(`../utxo/Utxo.cjs`),r=require(`../../types/transact.types.cjs`),i=require(`../../functions/web3/events/getShieldedBalance.cjs`),a=require(`../../functions/pre-transaction/outputUtxoProcessing.cjs`),o=require(`../../functions/snarkjs/common.snarkjs.cjs`),s=require(`../../functions/snarkjs/constructTxEnclave.cjs`),c=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),l=require(`../../functions/web3/functionCalls/submitProof.cjs`);var u=2,d=6,f=(e,t)=>{let r=Math.max(...t.map(e=>e.length))<=u?u:d;return t.map(t=>{let i=t[0];if(!i)throw Error(`hinkalTransact: inputUtxos must contain at least one note per token`);let a=[...t];for(;a.length<r;)a.push(new n.Utxo({amount:0n,erc20TokenAddress:i.erc20TokenAddress,mintAddress:i.mintAddress,nullifyingKey:e.getShieldedPrivateKey(),spendingPublicKey:e.getSpendingKeyPair().pubSpendingBJJPoint}));return a})},p=async(n,r,o)=>{let{chainId:s,erc20Addresses:l,amountChanges:u,externalAddress:d,externalActionId:p,externalActionMetadata:m,feeStructure:h,relay:g,onChainCreation:_,recipientAddress:v,recipientAmounts:y,useBlockedUtxos:b,inputUtxos:x,forceEmptyUtxos:S,originalSender:C,subAccountPrivateKey:w,emporiumOps:T}=r,E=x?f(o,x):[...await i.addPaddingToUtxos(n,s,l,u,void 0,S,b)],D=a.buildOutputUtxos(o,E,u,v,y),{zkCallData:O,circomData:k,dimData:A,commitmentValidationData:j}=await c.constructZkProof(n.merkleTreeHinkalByChain[s],E,D,o,p??0n,d,T??m??`0x00`,h??t.zeroFeeStructure,g??e.zeroAddress,s,_,void 0,C,w);return{zkCallData:O,circomData:k,dimData:A,commitmentValidationData:j}},m=async(e,t,n)=>{let{chainId:r,erc20Addresses:i,externalAddress:a,amountChanges:o,relay:c,feeStructure:l,externalActionId:u,externalActionMetadata:d,onChainCreation:f,recipientAddress:p,recipientAmounts:m,useBlockedUtxos:h,createBlockedUtxos:g,skipLock:_,selfOutputAmounts:v,forceEmptyUtxos:y,messageSeed:b,inputUtxos:x,originalSender:S}=t,{jobId:C,signedMessageHash:w}=await s.prepareTxEnclaveCall(e,{chainId:r,erc20Addresses:i,externalAddress:a,originalSender:S,amountChanges:o,relay:c,feeStructure:l,externalActionId:u,externalActionMetadata:d,onChainCreation:f,recipientAddress:p,recipientAmounts:m,useBlockedUtxos:h,createBlockedUtxos:g,skipLock:_,selfOutputAmounts:v,forceEmptyUtxos:y,messageSeed:b,inputCommitments:s.collectInputCommitments(x)},n),{R8:T,S:E}=n.signEddsa(BigInt(w));return{jobId:C,eddsaSignature:{R8:T,S:E}}},h=async(e,t,n)=>{let i=await l.submitProof(e,t,n);return t.submit.mode!==r.SubmitMode.ProofOnly&&t.onTxSubmitLocally?.(n.circomData),i},g=async(e,t)=>{if(t.userKeys&&!t.inputUtxos)throw Error(`hinkalTransact: userKeys requires explicit inputUtxos`);let n=t.userKeys??e.userKeys,{chainId:i,submit:a}=t;if(e.generateProofRemotely){let{jobId:c,eddsaSignature:l}=await m(e,t,n);if(a.mode===r.SubmitMode.Relayer)return s.finalizeTxEnclaveCallRelay(c,l,i,{adminData:a.adminData,authorizationData:a.authorizationData,withUniswapWorkAround:a.withUniswapWorkAround});let{zkCallData:u,circomData:d,dimData:f,commitmentValidationData:p,tronProofSignature:g}=await s.finalizeTxEnclaveCall(c,l);return h(e,t,{zkCallData:u,circomData:o.deserializeCircomData(d),dimData:f,commitmentValidationData:p,tronProofSignature:g})}return h(e,t,await p(e,t,n))};exports.hinkalTransact=g;
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import { zeroAddress as e } from "../../constants/protocol.constants.mjs";
|
|
2
2
|
import { zeroFeeStructure as t } from "../../types/hinkal.types.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { finalizeTxEnclaveCall as c, finalizeTxEnclaveCallRelay as l, prepareTxEnclaveCall as u } from "../../functions/snarkjs/constructTxEnclave.mjs";
|
|
3
|
+
import { Utxo as n } from "../utxo/Utxo.mjs";
|
|
4
|
+
import { SubmitMode as r } from "../../types/transact.types.mjs";
|
|
5
|
+
import { addPaddingToUtxos as i } from "../../functions/web3/events/getShieldedBalance.mjs";
|
|
6
|
+
import { buildOutputUtxos as a } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
|
|
7
|
+
import { deserializeCircomData as o } from "../../functions/snarkjs/common.snarkjs.mjs";
|
|
8
|
+
import { collectInputCommitments as s, finalizeTxEnclaveCall as c, finalizeTxEnclaveCallRelay as l, prepareTxEnclaveCall as u } from "../../functions/snarkjs/constructTxEnclave.mjs";
|
|
10
9
|
import { constructZkProof as d } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
|
|
11
10
|
import { submitProof as f } from "../../functions/web3/functionCalls/submitProof.mjs";
|
|
12
11
|
//#region libs/shared/common/src/data-structures/Hinkal/hinkalTransact.ts
|
|
13
12
|
var p = 2, m = 6, h = (e, t) => {
|
|
14
|
-
let
|
|
13
|
+
let r = Math.max(...t.map((e) => e.length)) <= p ? p : m;
|
|
15
14
|
return t.map((t) => {
|
|
16
15
|
let i = t[0];
|
|
17
16
|
if (!i) throw Error("hinkalTransact: inputUtxos must contain at least one note per token");
|
|
18
17
|
let a = [...t];
|
|
19
|
-
for (; a.length <
|
|
18
|
+
for (; a.length < r;) a.push(new n({
|
|
20
19
|
amount: 0n,
|
|
21
20
|
erc20TokenAddress: i.erc20TokenAddress,
|
|
22
21
|
mintAddress: i.mintAddress,
|
|
@@ -25,60 +24,60 @@ var p = 2, m = 6, h = (e, t) => {
|
|
|
25
24
|
}));
|
|
26
25
|
return a;
|
|
27
26
|
});
|
|
28
|
-
}, g = async (
|
|
29
|
-
let { chainId:
|
|
27
|
+
}, g = async (n, r, o) => {
|
|
28
|
+
let { chainId: s, erc20Addresses: c, amountChanges: l, externalAddress: u, externalActionId: f, externalActionMetadata: p, feeStructure: m, relay: g, onChainCreation: _, recipientAddress: v, recipientAmounts: y, useBlockedUtxos: b, inputUtxos: x, forceEmptyUtxos: S, originalSender: C, subAccountPrivateKey: w, emporiumOps: T } = r, E = x ? h(o, x) : [...await i(n, s, c, l, void 0, S, b)], D = a(o, E, l, v, y), { zkCallData: O, circomData: k, dimData: A, commitmentValidationData: j } = await d(n.merkleTreeHinkalByChain[s], E, D, o, f ?? 0n, u, T ?? p ?? "0x00", m ?? t, g ?? e, s, _, void 0, C, w);
|
|
30
29
|
return {
|
|
31
|
-
zkCallData:
|
|
32
|
-
circomData:
|
|
33
|
-
dimData:
|
|
34
|
-
commitmentValidationData:
|
|
30
|
+
zkCallData: O,
|
|
31
|
+
circomData: k,
|
|
32
|
+
dimData: A,
|
|
33
|
+
commitmentValidationData: j
|
|
35
34
|
};
|
|
36
35
|
}, _ = async (e, t, n) => {
|
|
37
|
-
let { chainId: r, erc20Addresses: i, externalAddress: a, amountChanges: o, relay:
|
|
36
|
+
let { chainId: r, erc20Addresses: i, externalAddress: a, amountChanges: o, relay: c, feeStructure: l, externalActionId: d, externalActionMetadata: f, onChainCreation: p, recipientAddress: m, recipientAmounts: h, useBlockedUtxos: g, createBlockedUtxos: _, skipLock: v, selfOutputAmounts: y, forceEmptyUtxos: b, messageSeed: x, inputUtxos: S, originalSender: C } = t, { jobId: w, signedMessageHash: T } = await u(e, {
|
|
38
37
|
chainId: r,
|
|
39
38
|
erc20Addresses: i,
|
|
40
39
|
externalAddress: a,
|
|
41
|
-
originalSender:
|
|
40
|
+
originalSender: C,
|
|
42
41
|
amountChanges: o,
|
|
43
|
-
relay:
|
|
44
|
-
feeStructure:
|
|
45
|
-
externalActionId:
|
|
46
|
-
externalActionMetadata:
|
|
47
|
-
onChainCreation:
|
|
48
|
-
recipientAddress:
|
|
49
|
-
recipientAmounts:
|
|
50
|
-
useBlockedUtxos:
|
|
51
|
-
createBlockedUtxos:
|
|
52
|
-
skipLock:
|
|
53
|
-
selfOutputAmounts:
|
|
54
|
-
forceEmptyUtxos:
|
|
55
|
-
messageSeed:
|
|
56
|
-
inputCommitments:
|
|
57
|
-
}, n), { R8:
|
|
42
|
+
relay: c,
|
|
43
|
+
feeStructure: l,
|
|
44
|
+
externalActionId: d,
|
|
45
|
+
externalActionMetadata: f,
|
|
46
|
+
onChainCreation: p,
|
|
47
|
+
recipientAddress: m,
|
|
48
|
+
recipientAmounts: h,
|
|
49
|
+
useBlockedUtxos: g,
|
|
50
|
+
createBlockedUtxos: _,
|
|
51
|
+
skipLock: v,
|
|
52
|
+
selfOutputAmounts: y,
|
|
53
|
+
forceEmptyUtxos: b,
|
|
54
|
+
messageSeed: x,
|
|
55
|
+
inputCommitments: s(S)
|
|
56
|
+
}, n), { R8: E, S: D } = n.signEddsa(BigInt(T));
|
|
58
57
|
return {
|
|
59
|
-
jobId:
|
|
58
|
+
jobId: w,
|
|
60
59
|
eddsaSignature: {
|
|
61
|
-
R8:
|
|
62
|
-
S:
|
|
60
|
+
R8: E,
|
|
61
|
+
S: D
|
|
63
62
|
}
|
|
64
63
|
};
|
|
65
64
|
}, v = async (e, t, n) => {
|
|
66
|
-
let
|
|
67
|
-
return t.submit.mode !==
|
|
65
|
+
let i = await f(e, t, n);
|
|
66
|
+
return t.submit.mode !== r.ProofOnly && t.onTxSubmitLocally?.(n.circomData), i;
|
|
68
67
|
}, y = async (e, t) => {
|
|
69
68
|
if (t.userKeys && !t.inputUtxos) throw Error("hinkalTransact: userKeys requires explicit inputUtxos");
|
|
70
|
-
let n = t.userKeys ?? e.userKeys, { chainId:
|
|
69
|
+
let n = t.userKeys ?? e.userKeys, { chainId: i, submit: a } = t;
|
|
71
70
|
if (e.generateProofRemotely) {
|
|
72
|
-
let { jobId:
|
|
73
|
-
if (a.mode ===
|
|
71
|
+
let { jobId: s, eddsaSignature: u } = await _(e, t, n);
|
|
72
|
+
if (a.mode === r.Relayer) return l(s, u, i, {
|
|
74
73
|
adminData: a.adminData,
|
|
75
74
|
authorizationData: a.authorizationData,
|
|
76
75
|
withUniswapWorkAround: a.withUniswapWorkAround
|
|
77
76
|
});
|
|
78
|
-
let { zkCallData: d, circomData: f, dimData: p, commitmentValidationData: m, tronProofSignature: h } = await c(
|
|
77
|
+
let { zkCallData: d, circomData: f, dimData: p, commitmentValidationData: m, tronProofSignature: h } = await c(s, u);
|
|
79
78
|
return v(e, t, {
|
|
80
79
|
zkCallData: d,
|
|
81
|
-
circomData:
|
|
80
|
+
circomData: o(f),
|
|
82
81
|
dimData: p,
|
|
83
82
|
commitmentValidationData: m,
|
|
84
83
|
tronProofSignature: h
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const e=require(`../../constants/chains.constants.cjs`);require(`../../constants/protocol.constants.cjs`);const t=require(`../../functions/utils/amounts.utils.cjs`),n=require(`../../error-handling/error-codes.constants.cjs`),r=require(`../../functions/utils/encodeTokenWithId.cjs`),i=require(`../../functions/utils/addresses.cjs`),a=require(`../../functions/utils/tron.utils.cjs`),o=require(`../../functions/web3/events/getInputUtxoAndBalance.cjs`),s=require(`../../types/external-action.types.cjs`),c=require(`../../types/transact.types.cjs`),l=require(`../../types/solana-transact.types.cjs`),u=require(`../../error-handling/logger.cjs`),d=require(`../../functions/utils/token-check.utils.cjs`),f=require(`../../functions/snarkjs/constructTxEnclave.cjs`),p=require(`../../functions/pre-transaction/getFeeStructure.cjs`),m=require(`./hinkalTransact.cjs`),h=require(`../../functions/auto-deposit-back-helpers/update-hinkal.cjs`),g=require(`../../functions/pre-transaction/merge-with-fee-structure.cjs`),_=require(`./hinkalSolanaTransact.cjs`);var v=6,y=async(e,t,r,o)=>{let c=r.erc20TokenAddress,l=await e.getEthereumAddressByChain(t),[d,m]=await Promise.all([p.getFeeStructure(t,c,[c],s.ExternalActionId.Transact),e.getRandomRelay(t,!0)]);if(!m)throw Error(n.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let h=await f.prepareStuckWithdrawEnclaveCall(e,{chainId:t,erc20Address:c,externalAddress:a.addressToHexFormat(o),relay:m,feeStructure:d,hashedEthereumAddress:i.hashEthereumAddress(l)}),g=[];for(let n=0;n<h.length;n+=1)try{let{jobId:r,signedMessageHash:i}=h[n],{R8:a,S:o}=e.userKeys.signEddsa(BigInt(i));g.push(await f.finalizeTxEnclaveCallRelay(r,{R8:a,S:o},t))}catch(e){if(!g.length)throw e;return u.Logger.error(`Stuck withdrawal partially submitted (${g.length}/${h.length})`,e),g}return g},b=async(e,t,n)=>{let r=await Promise.all(Array.from({length:v},async(r,i)=>{let a=i+1,o=await p.getFeeStructure(e,t,[t],s.ExternalActionId.Transact,void 0,void 0,{mintTo:t,recipient:n,nullifierCount:a});return[String(a),o]}));return Object.fromEntries(r)},x=async(e,t,r,a)=>{let o=r.erc20TokenAddress,[s,c,l]=await Promise.all([e.getEthereumAddressByChain(t),e.getRandomRelay(t,!0),b(t,o,a)]);if(!c)throw Error(n.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let u=await f.prepareSolanaStuckWithdrawEnclaveCall(e,{chainId:t,mintAddress:o,recipient:a,relayAddress:c,accounts:{recipient:a,mint:o===`11111111111111111111111111111111`?void 0:o},feeStructures:l,hashedEthereumAddress:i.hashEthereumAddress(s)}),d=[];for(let n=0;n<u.length;n+=1){let{jobId:r,signedMessageHash:i}=u[n],{R8:a,S:o}=e.userKeys.signEddsa(BigInt(i));d.push(await f.finalizeSolanaTxEnclaveCallRelay(r,{R8:a,S:o},t))}return d},S=async(e,t,r,i,o)=>{let l=[r.erc20TokenAddress],u=r.erc20TokenAddress,[d,f]=await Promise.all([p.getFeeStructure(t,u,l,s.ExternalActionId.Transact),e.getRandomRelay(t,!0)]);if(!f)throw Error(n.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let _=a.addressToHexFormat(o),v=i-d.flatFee;if(v<=0n)throw Error(`Insufficient balance to cover fee. Balance: ${i}, Fee: ${d.flatFee}`);let y=[-v];return await g.mergeWithFeeStructure(t,l,y,d),{tx:await m.hinkalTransact(e,{chainId:t,erc20Addresses:l,amountChanges:y,externalAddress:_,feeStructure:d,relay:f,useBlockedUtxos:!0,onTxSubmitLocally:n=>{h.updateHinkal(t,e,n.inputNullifiers?.flat(),n.outCommitments?.flat(),n.encryptedOutputs?.flat())},submit:{mode:c.SubmitMode.Relayer}}),amountToRecipient:v}},C=async(t,r,i,a,o,c)=>{let u=[i.erc20TokenAddress],{originalDeployer:d}=e.networkRegistry[r].contractData;if(!d)throw Error(`missing data`);let f=i.erc20TokenAddress,[m,g]=await Promise.all([p.getFeeStructure(r,f,u,s.ExternalActionId.Transact,void 0,void 0,{mintTo:u[0],recipient:o,nullifierCount:c}),t.getRandomRelay(r,!0)]);if(!g)throw Error(n.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let v=a-m.flatFee;if(v<=0n)throw Error(`Insufficient balance to cover fee. Balance: ${a}, Fee: ${m.flatFee}`);let y=[-v];return y[0]-=m.flatFee,{tx:await _.hinkalSolanaTransact(t,{chainId:r,mintAddresses:u,amountChanges:y,relayAddress:g,recipient:o,signer:g,functionName:`transact`,accounts:{recipient:o,mint:u[0]===`11111111111111111111111111111111`?void 0:u[0]},relayerFee:m.flatFee,variableRate:m.variableRate,useBlockedUtxos:!0,onTxSubmitLocally:({inputNullifiers:e,outCommitments:n,encryptedOutputs:i})=>{h.updateHinkal(r,t,e,n,i)},submit:{mode:l.SolanaSubmitMode.Relayer}}),amountToRecipient:v}},w=async(t,n,r,i,a,o)=>e.isSolanaLike(n)?C(t,n,r,i,a,o):S(t,n,r,i,a),T=async(i,a,s)=>{let c=d.validateAndGetChainId([a]);if(i.generateProofRemotely){let t=e.isSolanaLike(c)?await x(i,c,a,s):await y(i,c,a,s);if(!t.length)throw Error(n.transactionErrorCodes.NO_STUCK_BALANCE_TO_WITHDRAW);return t}let l=[],f=r.normalizeTokenAddress(c,a.erc20TokenAddress);await i.resetMerkleTreesIfNecessary([c]);let p=((await o.getInputUtxoAndBalancePerToken({hinkal:i,sliceIfMore6:!1,useBlockedUtxos:!0,chainId:c}))?.get(f)??[]).filter(e=>e.amount>0n).sort((e,t)=>Number(t.amount-e.amount));if(!p.length)throw Error(n.transactionErrorCodes.NO_STUCK_BALANCE_TO_WITHDRAW);for(let e=0;e<p.length;e+=v){let n=p.slice(e,e+v),r=t.countTotalAmountInUtxos(n);try{let{tx:e}=await w(i,c,a,r,s,n.length);l.push(e)}catch(e){if(!l.length)throw e;return u.Logger.error(`Stuck withdrawal partially submitted (${l.length}/${Math.ceil(p.length/v)})`,e),l}}return l};exports.hinkalWithdrawStuckUtxos=T;
|
|
@@ -2,60 +2,47 @@ import { isSolanaLike as e, networkRegistry as t } from "../../constants/chains.
|
|
|
2
2
|
import "../../constants/protocol.constants.mjs";
|
|
3
3
|
import { countTotalAmountInUtxos as n } from "../../functions/utils/amounts.utils.mjs";
|
|
4
4
|
import { transactionErrorCodes as r } from "../../error-handling/error-codes.constants.mjs";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import { getFeeStructure as S } from "../../functions/pre-transaction/getFeeStructure.mjs";
|
|
21
|
-
import { solanaTransactCallRelayer as C } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
|
|
22
|
-
import { hinkalTransact as w } from "./hinkalTransact.mjs";
|
|
23
|
-
import { constructSolanaZkProof as T } from "../../functions/snarkjs/constructSolanaZkProof.mjs";
|
|
24
|
-
import { updateHinkal as E } from "../../functions/auto-deposit-back-helpers/update-hinkal.mjs";
|
|
25
|
-
import { mergeWithFeeStructure as D } from "../../functions/pre-transaction/merge-with-fee-structure.mjs";
|
|
26
|
-
import { ethers as O } from "ethers";
|
|
5
|
+
import { normalizeTokenAddress as i } from "../../functions/utils/encodeTokenWithId.mjs";
|
|
6
|
+
import { hashEthereumAddress as a } from "../../functions/utils/addresses.mjs";
|
|
7
|
+
import { addressToHexFormat as o } from "../../functions/utils/tron.utils.mjs";
|
|
8
|
+
import { getInputUtxoAndBalancePerToken as s } from "../../functions/web3/events/getInputUtxoAndBalance.mjs";
|
|
9
|
+
import { ExternalActionId as c } from "../../types/external-action.types.mjs";
|
|
10
|
+
import { SubmitMode as l } from "../../types/transact.types.mjs";
|
|
11
|
+
import { SolanaSubmitMode as u } from "../../types/solana-transact.types.mjs";
|
|
12
|
+
import { Logger as d } from "../../error-handling/logger.mjs";
|
|
13
|
+
import { validateAndGetChainId as f } from "../../functions/utils/token-check.utils.mjs";
|
|
14
|
+
import { finalizeSolanaTxEnclaveCallRelay as p, finalizeTxEnclaveCallRelay as m, prepareSolanaStuckWithdrawEnclaveCall as h, prepareStuckWithdrawEnclaveCall as g } from "../../functions/snarkjs/constructTxEnclave.mjs";
|
|
15
|
+
import { getFeeStructure as _ } from "../../functions/pre-transaction/getFeeStructure.mjs";
|
|
16
|
+
import { hinkalTransact as v } from "./hinkalTransact.mjs";
|
|
17
|
+
import { updateHinkal as y } from "../../functions/auto-deposit-back-helpers/update-hinkal.mjs";
|
|
18
|
+
import { mergeWithFeeStructure as b } from "../../functions/pre-transaction/merge-with-fee-structure.mjs";
|
|
19
|
+
import { hinkalSolanaTransact as x } from "./hinkalSolanaTransact.mjs";
|
|
27
20
|
//#region libs/shared/common/src/data-structures/Hinkal/hinkalWithdrawStuckUtxos.ts
|
|
28
|
-
var
|
|
29
|
-
let
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
outputUtxos: s
|
|
33
|
-
};
|
|
34
|
-
}, j = async (e, t, n, i) => {
|
|
35
|
-
let a = n.erc20TokenAddress, o = await e.getEthereumAddressByChain(t), [s, u] = await Promise.all([S(t, a, [a], d.Transact), e.getRandomRelay(t, !0)]);
|
|
36
|
-
if (!u) throw Error(r.RELAYER_NOT_AVAILABLE);
|
|
37
|
-
let f = await x(e, {
|
|
21
|
+
var S = 6, C = async (e, t, n, i) => {
|
|
22
|
+
let s = n.erc20TokenAddress, l = await e.getEthereumAddressByChain(t), [u, f] = await Promise.all([_(t, s, [s], c.Transact), e.getRandomRelay(t, !0)]);
|
|
23
|
+
if (!f) throw Error(r.RELAYER_NOT_AVAILABLE);
|
|
24
|
+
let p = await g(e, {
|
|
38
25
|
chainId: t,
|
|
39
|
-
erc20Address:
|
|
40
|
-
externalAddress:
|
|
41
|
-
relay:
|
|
42
|
-
feeStructure:
|
|
43
|
-
hashedEthereumAddress:
|
|
44
|
-
}),
|
|
45
|
-
for (let n = 0; n <
|
|
46
|
-
let { jobId: r, signedMessageHash: i } =
|
|
47
|
-
|
|
26
|
+
erc20Address: s,
|
|
27
|
+
externalAddress: o(i),
|
|
28
|
+
relay: f,
|
|
29
|
+
feeStructure: u,
|
|
30
|
+
hashedEthereumAddress: a(l)
|
|
31
|
+
}), h = [];
|
|
32
|
+
for (let n = 0; n < p.length; n += 1) try {
|
|
33
|
+
let { jobId: r, signedMessageHash: i } = p[n], { R8: a, S: o } = e.userKeys.signEddsa(BigInt(i));
|
|
34
|
+
h.push(await m(r, {
|
|
48
35
|
R8: a,
|
|
49
36
|
S: o
|
|
50
37
|
}, t));
|
|
51
38
|
} catch (e) {
|
|
52
|
-
if (!
|
|
53
|
-
return
|
|
39
|
+
if (!h.length) throw e;
|
|
40
|
+
return d.error(`Stuck withdrawal partially submitted (${h.length}/${p.length})`, e), h;
|
|
54
41
|
}
|
|
55
|
-
return
|
|
56
|
-
},
|
|
57
|
-
let r = await Promise.all(Array.from({ length:
|
|
58
|
-
let a = i + 1, o = await
|
|
42
|
+
return h;
|
|
43
|
+
}, w = async (e, t, n) => {
|
|
44
|
+
let r = await Promise.all(Array.from({ length: S }, async (r, i) => {
|
|
45
|
+
let a = i + 1, o = await _(e, t, [t], c.Transact, void 0, void 0, {
|
|
59
46
|
mintTo: t,
|
|
60
47
|
recipient: n,
|
|
61
48
|
nullifierCount: a
|
|
@@ -63,123 +50,117 @@ var k = 6, A = async (e, t, n, r) => {
|
|
|
63
50
|
return [String(a), o];
|
|
64
51
|
}));
|
|
65
52
|
return Object.fromEntries(r);
|
|
66
|
-
},
|
|
67
|
-
let
|
|
53
|
+
}, T = async (e, t, n, i) => {
|
|
54
|
+
let o = n.erc20TokenAddress, [s, c, l] = await Promise.all([
|
|
68
55
|
e.getEthereumAddressByChain(t),
|
|
69
56
|
e.getRandomRelay(t, !0),
|
|
70
|
-
|
|
57
|
+
w(t, o, i)
|
|
71
58
|
]);
|
|
72
|
-
if (!
|
|
73
|
-
let u = await
|
|
59
|
+
if (!c) throw Error(r.RELAYER_NOT_AVAILABLE);
|
|
60
|
+
let u = await h(e, {
|
|
74
61
|
chainId: t,
|
|
75
|
-
mintAddress:
|
|
62
|
+
mintAddress: o,
|
|
76
63
|
recipient: i,
|
|
77
|
-
relayAddress:
|
|
64
|
+
relayAddress: c,
|
|
78
65
|
accounts: {
|
|
79
66
|
recipient: i,
|
|
80
|
-
mint:
|
|
67
|
+
mint: o === "11111111111111111111111111111111" ? void 0 : o
|
|
81
68
|
},
|
|
82
69
|
feeStructures: l,
|
|
83
|
-
hashedEthereumAddress:
|
|
70
|
+
hashedEthereumAddress: a(s)
|
|
84
71
|
}), d = [];
|
|
85
72
|
for (let n = 0; n < u.length; n += 1) {
|
|
86
73
|
let { jobId: r, signedMessageHash: i } = u[n], { R8: a, S: o } = e.userKeys.signEddsa(BigInt(i));
|
|
87
|
-
d.push(await
|
|
74
|
+
d.push(await p(r, {
|
|
88
75
|
R8: a,
|
|
89
76
|
S: o
|
|
90
77
|
}, t));
|
|
91
78
|
}
|
|
92
79
|
return d;
|
|
93
|
-
},
|
|
94
|
-
let
|
|
95
|
-
if (!
|
|
96
|
-
let p =
|
|
97
|
-
if (m <= 0n) throw Error(`Insufficient balance to cover fee. Balance: ${i}, Fee: ${
|
|
80
|
+
}, E = async (e, t, n, i, a) => {
|
|
81
|
+
let s = [n.erc20TokenAddress], u = n.erc20TokenAddress, [d, f] = await Promise.all([_(t, u, s, c.Transact), e.getRandomRelay(t, !0)]);
|
|
82
|
+
if (!f) throw Error(r.RELAYER_NOT_AVAILABLE);
|
|
83
|
+
let p = o(a), m = i - d.flatFee;
|
|
84
|
+
if (m <= 0n) throw Error(`Insufficient balance to cover fee. Balance: ${i}, Fee: ${d.flatFee}`);
|
|
98
85
|
let h = [-m];
|
|
99
|
-
return await
|
|
100
|
-
tx: await
|
|
86
|
+
return await b(t, s, h, d), {
|
|
87
|
+
tx: await v(e, {
|
|
101
88
|
chainId: t,
|
|
102
|
-
erc20Addresses:
|
|
89
|
+
erc20Addresses: s,
|
|
103
90
|
amountChanges: h,
|
|
104
91
|
externalAddress: p,
|
|
105
|
-
feeStructure:
|
|
106
|
-
relay:
|
|
92
|
+
feeStructure: d,
|
|
93
|
+
relay: f,
|
|
107
94
|
useBlockedUtxos: !0,
|
|
108
95
|
onTxSubmitLocally: (n) => {
|
|
109
|
-
|
|
96
|
+
y(t, e, n.inputNullifiers?.flat(), n.outCommitments?.flat(), n.encryptedOutputs?.flat());
|
|
110
97
|
},
|
|
111
|
-
submit: { mode:
|
|
98
|
+
submit: { mode: l.Relayer }
|
|
112
99
|
}),
|
|
113
100
|
amountToRecipient: m
|
|
114
101
|
};
|
|
115
|
-
},
|
|
116
|
-
let
|
|
117
|
-
if (!
|
|
118
|
-
let
|
|
119
|
-
mintTo:
|
|
120
|
-
recipient:
|
|
121
|
-
nullifierCount:
|
|
102
|
+
}, D = async (e, n, i, a, o, s) => {
|
|
103
|
+
let l = [i.erc20TokenAddress], { originalDeployer: d } = t[n].contractData;
|
|
104
|
+
if (!d) throw Error("missing data");
|
|
105
|
+
let f = i.erc20TokenAddress, [p, m] = await Promise.all([_(n, f, l, c.Transact, void 0, void 0, {
|
|
106
|
+
mintTo: l[0],
|
|
107
|
+
recipient: o,
|
|
108
|
+
nullifierCount: s
|
|
122
109
|
}), e.getRandomRelay(n, !0)]);
|
|
123
|
-
if (!
|
|
124
|
-
let
|
|
125
|
-
if (
|
|
126
|
-
let
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
accounts: R,
|
|
150
|
-
commitmentValidationData: F
|
|
151
|
-
});
|
|
152
|
-
return E(n, e, x.map((e) => e.getNullifier()), _([w]).flat(), L.map((e) => O.hexlify(new Uint8Array(e)))), {
|
|
153
|
-
tx: z,
|
|
154
|
-
amountToRecipient: y
|
|
110
|
+
if (!m) throw Error(r.RELAYER_NOT_AVAILABLE);
|
|
111
|
+
let h = a - p.flatFee;
|
|
112
|
+
if (h <= 0n) throw Error(`Insufficient balance to cover fee. Balance: ${a}, Fee: ${p.flatFee}`);
|
|
113
|
+
let g = [-h];
|
|
114
|
+
return g[0] -= p.flatFee, {
|
|
115
|
+
tx: await x(e, {
|
|
116
|
+
chainId: n,
|
|
117
|
+
mintAddresses: l,
|
|
118
|
+
amountChanges: g,
|
|
119
|
+
relayAddress: m,
|
|
120
|
+
recipient: o,
|
|
121
|
+
signer: m,
|
|
122
|
+
functionName: "transact",
|
|
123
|
+
accounts: {
|
|
124
|
+
recipient: o,
|
|
125
|
+
mint: l[0] === "11111111111111111111111111111111" ? void 0 : l[0]
|
|
126
|
+
},
|
|
127
|
+
relayerFee: p.flatFee,
|
|
128
|
+
variableRate: p.variableRate,
|
|
129
|
+
useBlockedUtxos: !0,
|
|
130
|
+
onTxSubmitLocally: ({ inputNullifiers: t, outCommitments: r, encryptedOutputs: i }) => {
|
|
131
|
+
y(n, e, t, r, i);
|
|
132
|
+
},
|
|
133
|
+
submit: { mode: u.Relayer }
|
|
134
|
+
}),
|
|
135
|
+
amountToRecipient: h
|
|
155
136
|
};
|
|
156
|
-
},
|
|
157
|
-
let
|
|
137
|
+
}, O = async (t, n, r, i, a, o) => e(n) ? D(t, n, r, i, a, o) : E(t, n, r, i, a), k = async (t, a, o) => {
|
|
138
|
+
let c = f([a]);
|
|
158
139
|
if (t.generateProofRemotely) {
|
|
159
|
-
let n = e(
|
|
140
|
+
let n = e(c) ? await T(t, c, a, o) : await C(t, c, a, o);
|
|
160
141
|
if (!n.length) throw Error(r.NO_STUCK_BALANCE_TO_WITHDRAW);
|
|
161
142
|
return n;
|
|
162
143
|
}
|
|
163
|
-
let
|
|
164
|
-
await t.resetMerkleTreesIfNecessary([
|
|
165
|
-
let
|
|
144
|
+
let l = [], u = i(c, a.erc20TokenAddress);
|
|
145
|
+
await t.resetMerkleTreesIfNecessary([c]);
|
|
146
|
+
let p = ((await s({
|
|
166
147
|
hinkal: t,
|
|
167
148
|
sliceIfMore6: !1,
|
|
168
149
|
useBlockedUtxos: !0,
|
|
169
|
-
chainId:
|
|
170
|
-
}))?.get(
|
|
171
|
-
if (!
|
|
172
|
-
for (let e = 0; e <
|
|
173
|
-
let r =
|
|
150
|
+
chainId: c
|
|
151
|
+
}))?.get(u) ?? []).filter((e) => e.amount > 0n).sort((e, t) => Number(t.amount - e.amount));
|
|
152
|
+
if (!p.length) throw Error(r.NO_STUCK_BALANCE_TO_WITHDRAW);
|
|
153
|
+
for (let e = 0; e < p.length; e += S) {
|
|
154
|
+
let r = p.slice(e, e + S), i = n(r);
|
|
174
155
|
try {
|
|
175
|
-
let { tx: e } = await
|
|
176
|
-
|
|
156
|
+
let { tx: e } = await O(t, c, a, i, o, r.length);
|
|
157
|
+
l.push(e);
|
|
177
158
|
} catch (e) {
|
|
178
|
-
if (!
|
|
179
|
-
return
|
|
159
|
+
if (!l.length) throw e;
|
|
160
|
+
return d.error(`Stuck withdrawal partially submitted (${l.length}/${Math.ceil(p.length / S)})`, e), l;
|
|
180
161
|
}
|
|
181
162
|
}
|
|
182
|
-
return
|
|
163
|
+
return l;
|
|
183
164
|
};
|
|
184
165
|
//#endregion
|
|
185
|
-
export {
|
|
166
|
+
export { k as hinkalWithdrawStuckUtxos };
|