@kapa123456789/sdk 0.0.81 → 0.0.82
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/common/src/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/common/src/data-structures/Hinkal/Hinkal.mjs +41 -4
- package/common/src/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalDeposit.mjs +73 -46
- package/common/src/data-structures/Hinkal/hinkalTransfer.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalTransfer.mjs +37 -16
- package/common/src/data-structures/Hinkal/hinkalWithdraw.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalWithdraw.mjs +47 -18
- package/common/src/functions/pre-transaction/getFeeStructure.cjs +1 -1
- package/common/src/functions/pre-transaction/getFeeStructure.mjs +21 -10
- package/common/src/functions/snarkjs/constructGeneralZkProof.cjs +1 -1
- package/common/src/functions/snarkjs/constructGeneralZkProof.mjs +89 -71
- package/common/src/functions/snarkjs/generateMainAndCommitmentZkProof.cjs +1 -1
- package/common/src/functions/snarkjs/generateMainAndCommitmentZkProof.mjs +17 -8
- package/common/src/functions/snarkjs/generateZkProof.cjs +1 -1
- package/common/src/functions/snarkjs/generateZkProof.mjs +26 -8
- package/common/src/functions/web3/functionCalls/transactCallDirect.cjs +1 -1
- package/common/src/functions/web3/functionCalls/transactCallDirect.mjs +61 -43
- package/common/src/functions/web3/functionCalls/transactCallDirectTron.cjs +1 -1
- package/common/src/functions/web3/functionCalls/transactCallDirectTron.mjs +73 -65
- package/common/src/functions/web3/functionCalls/transactCallRelayer.cjs +1 -1
- package/common/src/functions/web3/functionCalls/transactCallRelayer.mjs +22 -14
- package/common/src/webworker/package.json +1 -1
- package/package.json +1 -1
- package/services/Hinkal.cjs +1 -1
- package/services/Hinkal.mjs +42 -3
|
@@ -1,82 +1,100 @@
|
|
|
1
|
-
import { chainIds as e, getOnchainChainId as
|
|
2
|
-
import { defaultSignatureData as
|
|
3
|
-
import { poseidonFunction as
|
|
4
|
-
import { randomBigInt as
|
|
5
|
-
import { UserKeys as
|
|
6
|
-
import { getCurrentTimeInSeconds as
|
|
7
|
-
import { ExternalActionId as
|
|
8
|
-
import { Logger as
|
|
9
|
-
import { takeOffHighestBit as
|
|
10
|
-
import { buildOutCommitments as
|
|
11
|
-
import { computeSignedMessageHashEvm as
|
|
12
|
-
import { generateCircomData as
|
|
1
|
+
import { chainIds as e, getOnchainChainId as ee } from "../../constants/chains.constants.mjs";
|
|
2
|
+
import { defaultSignatureData as te, zeroAddress as t } from "../../constants/protocol.constants.mjs";
|
|
3
|
+
import { poseidonFunction as ne } from "../../crypto/poseidon.mjs";
|
|
4
|
+
import { randomBigInt as n } from "../web3/etherFunctions.mjs";
|
|
5
|
+
import { UserKeys as r } from "../../data-structures/crypto-keys/keys.mjs";
|
|
6
|
+
import { getCurrentTimeInSeconds as i } from "../utils/time.utils.mjs";
|
|
7
|
+
import { ExternalActionId as a } from "../../types/external-action.types.mjs";
|
|
8
|
+
import { Logger as o } from "../../error-handling/logger.mjs";
|
|
9
|
+
import { takeOffHighestBit as re } from "../utils/bit.operations.mjs";
|
|
10
|
+
import { buildOutCommitments as ie, calcAmountChanges as s, calcEncryptedOutputs as ae, calcPublicSignalCount as oe, calcStealthAddressStructure as se, createCallDataHash as ce, getSlippageValues as le, getUtxoCircuitH0Coords as c, getUtxoCircuitInRandomization as ue, getZkProofVerifierName as de } from "./common.snarkjs.mjs";
|
|
11
|
+
import { computeSignedMessageHashEvm as fe } from "./signedMessageHash.mjs";
|
|
12
|
+
import { generateCircomData as l } from "./generateCircomData.mjs";
|
|
13
13
|
import { AccountActions as u } from "../../data-structures/AccountActions/AccountActions.mjs";
|
|
14
14
|
import { generateMainAndCommitmentZkProof as d } from "./generateMainAndCommitmentZkProof.mjs";
|
|
15
15
|
import { getDataFromWorkers as f } from "./getMerkleTreeSiblingsAndRootHashes.mjs";
|
|
16
16
|
import { encodeEmporiumMetadata as p } from "../private-wallet/emporium.helpers.mjs";
|
|
17
17
|
//#region libs/shared/common/src/functions/snarkjs/constructGeneralZkProof.ts
|
|
18
|
-
var m = async (m, h, g, _, v, y, b, pe, x, S =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
inNullifiers
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
18
|
+
var m = async (m, h, g, _, v, y, b, pe, x, S = t, C = e.localhost, w = h.map(() => !1), T = void 0, E, D) => {
|
|
19
|
+
console.log("[constructZkProof] start", {
|
|
20
|
+
chainId: C,
|
|
21
|
+
externalActionId: String(v)
|
|
22
|
+
});
|
|
23
|
+
try {
|
|
24
|
+
let e = de(h, g);
|
|
25
|
+
console.log("[constructZkProof] calcAmountChanges + encryptedOutputs");
|
|
26
|
+
let O = s(h, g), k = h.map((e) => e[0].erc20TokenAddress), A = ae(g), j = te, M = _.getShieldedPrivateKey(), { pubSpendingBJJPoint: N } = _.getSpendingKeyPair(), P = se(r.findCorrectRandomization(n(31), M), M, _.getSpendingKeyPair().pubSpendingBJJPoint), F = h.map((e) => e.map((e) => e.getConstructableParams()));
|
|
27
|
+
console.log("[constructZkProof] getDataFromWorkers");
|
|
28
|
+
let { inCommitmentSiblings: I, inCommitmentSiblingSides: L, rootHashHinkal: R, inNullifiers: z } = await f(C, m, F), B = ie(g), V = n(31), H = ne(V), U = BigInt(g.length > 0 ? g[0][0].timeStamp : i()), W = {
|
|
29
|
+
rootHashHinkal: R,
|
|
30
|
+
spendingPublicKey: N,
|
|
31
|
+
nullifyingPrivateKey: M,
|
|
32
|
+
erc20TokenAddresses: k,
|
|
33
|
+
amountChanges: O,
|
|
34
|
+
inAmounts: h.map((e) => e.map((e) => e.amount.toString())),
|
|
35
|
+
inRandomizations: h.map((e) => e.map((e) => ue(e))),
|
|
36
|
+
inH0Ax: h.map((e) => e.map((e) => c(e)[0].toString())),
|
|
37
|
+
inH0Ay: h.map((e) => e.map((e) => c(e)[1].toString())),
|
|
38
|
+
isNewStyle: h.map((e) => e.map((e) => !!e.isNewStyle)),
|
|
39
|
+
inTimeStamps: h.map((e) => e.map((e) => e.timeStamp)),
|
|
40
|
+
inNullifiers: z,
|
|
41
|
+
inCommitmentSiblings: I,
|
|
42
|
+
inCommitmentSiblingSides: L,
|
|
43
|
+
outAmounts: g.map((e) => e.map((e) => e.amount.toString())),
|
|
44
|
+
outTimeStamp: U,
|
|
45
|
+
outPublicKeys: g.map((e) => e.map((e) => e.getStealthAddress())),
|
|
46
|
+
outCommitments: B,
|
|
47
|
+
calldataHash: 0n,
|
|
48
|
+
messageSeed: V,
|
|
49
|
+
H0Ax: re(P.extraRandomization),
|
|
50
|
+
H0Ay: P.H0
|
|
51
|
+
}, G = oe(e, W.erc20TokenAddresses, W.amountChanges, W.inNullifiers, W.outCommitments), K = s(h, g, !0), q = le(K);
|
|
52
|
+
o.log({ publicSignalCount: G });
|
|
53
|
+
let J = Array.isArray(b) ? b : [b], me = ee(C), he = D ? u.getSignerAddressFromPrivateKey(me, D) : void 0;
|
|
54
|
+
console.log("[constructZkProof] encodeEmporiumMetadata");
|
|
55
|
+
let Y = v === a.Emporium ? await p(C, y ?? t, D, J, H, he) : await p(C, t, void 0, v === 0n ? [] : J, H, t);
|
|
56
|
+
W.calldataHash = ce(G, S, y, v, Y, A, T, q, w, x, j, E);
|
|
57
|
+
let X = fe({
|
|
58
|
+
rootHashHinkal: R,
|
|
59
|
+
erc20TokenAddresses: k,
|
|
60
|
+
amountChanges: O,
|
|
61
|
+
outTimeStamp: U,
|
|
62
|
+
inNullifiers: z,
|
|
63
|
+
outCommitments: B,
|
|
64
|
+
calldataHash: W.calldataHash,
|
|
65
|
+
message: H,
|
|
66
|
+
outH1Ay: P.H1,
|
|
67
|
+
H0Ax: W.H0Ax,
|
|
68
|
+
H0Ay: P.H0
|
|
69
|
+
}), { R8: Z, S: ge } = _.signEddsa(X);
|
|
70
|
+
W.eddsaSignature = [
|
|
71
|
+
Z[0],
|
|
72
|
+
Z[1],
|
|
73
|
+
ge
|
|
74
|
+
], W.signedMessageHash = X;
|
|
75
|
+
let Q = e.startsWith("mainEVMCircuitMin0"), $ = {
|
|
76
|
+
outTimeStamp: U,
|
|
77
|
+
calldataHash: W.calldataHash,
|
|
78
|
+
messageSeed: V
|
|
79
|
+
};
|
|
80
|
+
console.log("[constructZkProof] generateMainAndCommitmentZkProof");
|
|
81
|
+
let { zkCallData: _e, commitmentValidationData: ve } = await d(C, _, k, h, e, Q ? $ : W, pe);
|
|
82
|
+
console.log("[constructZkProof] generateCircomData");
|
|
83
|
+
let ye = l(B, z, R, K, k, g, A, G, v, y, Y, S, W.calldataHash, P, w, T, Q ? Number(U) : void 0, q, x, j, E), be = {
|
|
73
84
|
tokenNumber: h.length,
|
|
74
85
|
nullifierAmount: h.length > 0 ? h[0].length : 0,
|
|
75
86
|
outputAmount: g.length > 0 ? g[0].length : 0
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
87
|
+
};
|
|
88
|
+
return console.log("[constructZkProof] success"), {
|
|
89
|
+
zkCallData: _e,
|
|
90
|
+
circomData: ye,
|
|
91
|
+
dimData: be,
|
|
92
|
+
encryptedOutputs: A,
|
|
93
|
+
commitmentValidationData: ve
|
|
94
|
+
};
|
|
95
|
+
} catch (e) {
|
|
96
|
+
throw console.log("[constructZkProof] error", e), e;
|
|
97
|
+
}
|
|
80
98
|
};
|
|
81
99
|
//#endregion
|
|
82
100
|
export { m as constructZkProof };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../pre-transaction/buildCommitmentValidationData.cjs`);require(`../pre-transaction/index.cjs`);const t=require(`./generateZkProof.cjs`);var n=async(n,r,i,a,o,s,c)=>{let l=await e.buildCommitmentValidationData(n,r,i,a),u=[o],d=[s];l&&(u.push(l.verifierName),d.push(l.commitmentInput));let f=await t.generateZkProof(n,u,d,c),{zkCallData:p,publicSignals:m}=f[0];return{zkCallData:p,publicSignals:m,commitmentValidationData:e.
|
|
1
|
+
const e=require(`../pre-transaction/buildCommitmentValidationData.cjs`);require(`../pre-transaction/index.cjs`);const t=require(`./generateZkProof.cjs`);var n=async(n,r,i,a,o,s,c)=>{console.log(`[generateMainAndCommitmentZkProof] start`,{chainId:n,mainVerifierName:o});try{console.log(`[generateMainAndCommitmentZkProof] buildCommitmentValidationData`);let l=await e.buildCommitmentValidationData(n,r,i,a),u=[o],d=[s];l&&(u.push(l.verifierName),d.push(l.commitmentInput)),console.log(`[generateMainAndCommitmentZkProof] generateZkProof`);let f=await t.generateZkProof(n,u,d,c),{zkCallData:p,publicSignals:m}=f[0],h=e.buildCommitmentValidationDataFromProof(l,f[1]);return console.log(`[generateMainAndCommitmentZkProof] success`),{zkCallData:p,publicSignals:m,commitmentValidationData:h}}catch(e){throw console.log(`[generateMainAndCommitmentZkProof] error`,e),e}};exports.generateMainAndCommitmentZkProof=n;
|
|
@@ -3,14 +3,23 @@ import "../pre-transaction/index.mjs";
|
|
|
3
3
|
import { generateZkProof as n } from "./generateZkProof.mjs";
|
|
4
4
|
//#region libs/shared/common/src/functions/snarkjs/generateMainAndCommitmentZkProof.ts
|
|
5
5
|
var r = async (r, i, a, o, s, c, l) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
console.log("[generateMainAndCommitmentZkProof] start", {
|
|
7
|
+
chainId: r,
|
|
8
|
+
mainVerifierName: s
|
|
9
|
+
});
|
|
10
|
+
try {
|
|
11
|
+
console.log("[generateMainAndCommitmentZkProof] buildCommitmentValidationData");
|
|
12
|
+
let u = await e(r, i, a, o), d = [s], f = [c];
|
|
13
|
+
u && (d.push(u.verifierName), f.push(u.commitmentInput)), console.log("[generateMainAndCommitmentZkProof] generateZkProof");
|
|
14
|
+
let p = await n(r, d, f, l), { zkCallData: m, publicSignals: h } = p[0], g = t(u, p[1]);
|
|
15
|
+
return console.log("[generateMainAndCommitmentZkProof] success"), {
|
|
16
|
+
zkCallData: m,
|
|
17
|
+
publicSignals: h,
|
|
18
|
+
commitmentValidationData: g
|
|
19
|
+
};
|
|
20
|
+
} catch (e) {
|
|
21
|
+
throw console.log("[generateMainAndCommitmentZkProof] error", e), e;
|
|
22
|
+
}
|
|
14
23
|
};
|
|
15
24
|
//#endregion
|
|
16
25
|
export { r as generateMainAndCommitmentZkProof };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../utils/customEnclaveFunctionsRegister.cjs`),t=require(`../../error-handling/logger.cjs`),n=require(`./getZKFiles.cjs`),r=require(`./generateZkProofEnclave.cjs`),i=require(`./generateZkProofSelf.cjs`);var a=async(a,o,s,c)=>{if(c)try{let t=e.getCustomProofGenerator();
|
|
1
|
+
const e=require(`../utils/customEnclaveFunctionsRegister.cjs`),t=require(`../../error-handling/logger.cjs`),n=require(`./getZKFiles.cjs`),r=require(`./generateZkProofEnclave.cjs`),i=require(`./generateZkProofSelf.cjs`);var a=async(a,o,s,c)=>{console.log(`[generateZkProof] start`,{chainId:a,verifierNames:o,remotely:c});try{if(c)try{let t=e.getCustomProofGenerator();if(t){console.log(`[generateZkProof] custom proof generator`);let e=await t(s,o.map(e=>n.getWASMFile(e,a)),o.map(e=>n.getZKeyFile(e,a)));return console.log(`[generateZkProof] success (custom)`),e.map(({zkCallData:e,publicSignals:t})=>({zkCallData:e,publicSignals:t}))}console.log(`[generateZkProof] generateZkProofEnclave`);let i=await r.generateZkProofEnclave(a,o,s);return console.log(`[generateZkProof] success (enclave)`),i}catch(e){t.Logger.error(`enclave proof error`,e),console.log(`[generateZkProof] enclave failed, falling back to self`)}console.log(`[generateZkProof] generateZkProofSelf`);let l=await Promise.all(o.map((e,t)=>i.generateZkProofSelf(a,e,s[t])));return console.log(`[generateZkProof] success (self)`),l}catch(e){throw console.log(`[generateZkProof] error`,e),e}};exports.generateZkProof=a;
|
|
@@ -5,16 +5,34 @@ import { generateZkProofEnclave as i } from "./generateZkProofEnclave.mjs";
|
|
|
5
5
|
import { generateZkProofSelf as a } from "./generateZkProofSelf.mjs";
|
|
6
6
|
//#region libs/shared/common/src/functions/snarkjs/generateZkProof.ts
|
|
7
7
|
var o = async (o, s, c, l) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
console.log("[generateZkProof] start", {
|
|
9
|
+
chainId: o,
|
|
10
|
+
verifierNames: s,
|
|
11
|
+
remotely: l
|
|
12
|
+
});
|
|
13
|
+
try {
|
|
14
|
+
if (l) try {
|
|
15
|
+
let t = e();
|
|
16
|
+
if (t) {
|
|
17
|
+
console.log("[generateZkProof] custom proof generator");
|
|
18
|
+
let e = await t(c, s.map((e) => n(e, o)), s.map((e) => r(e, o)));
|
|
19
|
+
return console.log("[generateZkProof] success (custom)"), e.map(({ zkCallData: e, publicSignals: t }) => ({
|
|
20
|
+
zkCallData: e,
|
|
21
|
+
publicSignals: t
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
console.log("[generateZkProof] generateZkProofEnclave");
|
|
25
|
+
let a = await i(o, s, c);
|
|
26
|
+
return console.log("[generateZkProof] success (enclave)"), a;
|
|
27
|
+
} catch (e) {
|
|
28
|
+
t.error("enclave proof error", e), console.log("[generateZkProof] enclave failed, falling back to self");
|
|
29
|
+
}
|
|
30
|
+
console.log("[generateZkProof] generateZkProofSelf");
|
|
31
|
+
let u = await Promise.all(s.map((e, t) => a(o, e, c[t])));
|
|
32
|
+
return console.log("[generateZkProof] success (self)"), u;
|
|
14
33
|
} catch (e) {
|
|
15
|
-
|
|
34
|
+
throw console.log("[generateZkProof] error", e), e;
|
|
16
35
|
}
|
|
17
|
-
return Promise.all(s.map((e, t) => a(o, e, c[t])));
|
|
18
36
|
};
|
|
19
37
|
//#endregion
|
|
20
38
|
export { o as generateZkProof };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/protocol.constants.cjs`),t=require(`../../../types/ethereum-network.types.cjs`),n=require(`../../utils/time.utils.cjs`),r=require(`../../utils/getContractAddress.cjs`),i=require(`./recoverTransactionFromError.cjs`),a=require(`./approveTokensToHinkal.cjs`),o=require(`./constructBatchCall.cjs`),s=require(`./waitForErc20Approvals.cjs`);let c=require(`ethers`);var l=async(l,u,d,f,p,m,h,g,_,v=!0,y=!1)=>{let b=Array.isArray(d)?d:[d],x=Array.isArray(f)?f:[f];if(b.length!==x.length)throw Error(`token and amount length mismatch`);let S=l.getContractWithSigner(u,t.ContractType.HinkalContract),C=await l.getEthereumAddressByChain(u),w=g??S,T=_??S,E=`transact`,D=x.findIndex(({erc20TokenAddress:t})=>t===e.zeroAddress),O=x.some(({erc20TokenAddress:t})=>t!==e.zeroAddress),k=D===-1?0n:b[D]
|
|
1
|
+
require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/protocol.constants.cjs`),t=require(`../../../types/ethereum-network.types.cjs`),n=require(`../../utils/time.utils.cjs`),r=require(`../../utils/getContractAddress.cjs`),i=require(`./recoverTransactionFromError.cjs`),a=require(`./approveTokensToHinkal.cjs`),o=require(`./constructBatchCall.cjs`),s=require(`./waitForErc20Approvals.cjs`);let c=require(`ethers`);var l=async(l,u,d,f,p,m,h,g,_,v=!0,y=!1)=>{console.log(`[transactCallDirect] start`,{chainId:u,preEstimateGas:v,returnTxData:y});try{let b=Array.isArray(d)?d:[d],x=Array.isArray(f)?f:[f];if(b.length!==x.length)throw Error(`token and amount length mismatch`);console.log(`[transactCallDirect] getContractWithSigner`);let S=l.getContractWithSigner(u,t.ContractType.HinkalContract),C=await l.getEthereumAddressByChain(u),w=g??S,T=_??S,E=`transact`,D=x.findIndex(({erc20TokenAddress:t})=>t===e.zeroAddress),O=x.some(({erc20TokenAddress:t})=>t!==e.zeroAddress),k=D===-1?0n:b[D];console.log(`[transactCallDirect] supportsBatchCall`);let A=l.getProviderAdapter(u),j=await A.supportsBatchCall?.(u);if(!y&&O&&j&&A.sendBatchCallsTransaction){console.log(`[transactCallDirect] sendBatchCallsTransaction`);let e=o.buildApproveAndTransactCalls(x.map(e=>e.erc20TokenAddress),b,r.getContractAddress(w),T,p,h,m,k),t=await A.sendBatchCallsTransaction(u,e);return console.log(`[transactCallDirect] success (batch)`,{tx:t}),t}if(!y&&(console.log(`[transactCallDirect] approveTokensToHinkal`),await a.approveTokensToHinkal(l,u,w,x,b),O)){console.log(`[transactCallDirect] waitForErc20Approvals`);let e=x.map(({erc20TokenAddress:e},t)=>({tokenAddress:e,requiredAmount:b[t]}));await s.waitForErc20Approvals(l,u,C,r.getContractAddress(w),e)}let M={value:k>0n?BigInt(k).toString():void 0,gasLimit:void 0},N,P=[p[0],p[1],p[2],h,m,{...M,from:C}],{runner:F}=T;if(!(F instanceof c.ethers.AbstractSigner))throw Error(`expected signer`);if(v){console.log(`[transactCallDirect] estimateGas`);try{N=Number(await T[E].estimateGas(...P))}catch(e){console.log(`[transactCallDirect] gas estimation error`,{err:e})}}let I=N&&N>=0?Math.ceil(N*12/10):void 0;I&&(P[5].gasLimit=I),await n.waitLittle();let L;try{console.log(`[transactCallDirect] send transaction`,{returnTxData:y}),L=y?await T[E].populateTransaction(...P):await T[E](...P)}catch(e){if(!e?.transactionHash)throw e;console.log(`[transactCallDirect] recoverTransactionFromError`,{hash:e.transactionHash});let t=await i.recoverTransactionFromError(F.provider,e.transactionHash);if(!t)throw e;L=t}return console.log(`[transactCallDirect] success`,{tx:L}),L}catch(e){throw console.log(`[transactCallDirect] error`,e),e}};exports.transactCallDirect=l;
|
|
@@ -9,52 +9,70 @@ import { waitForErc20Approvals as s } from "./waitForErc20Approvals.mjs";
|
|
|
9
9
|
import { ethers as c } from "ethers";
|
|
10
10
|
//#region libs/shared/common/src/functions/web3/functionCalls/transactCallDirect.ts
|
|
11
11
|
var l = async (l, u, d, f, p, m, h, g, _, v = !0, y = !1) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return await A.sendBatchCallsTransaction(u, e);
|
|
18
|
-
}
|
|
19
|
-
if (!y && (await a(l, u, w, x, b), O)) {
|
|
20
|
-
let e = x.map(({ erc20TokenAddress: e }, t) => ({
|
|
21
|
-
tokenAddress: e,
|
|
22
|
-
requiredAmount: b[t]
|
|
23
|
-
}));
|
|
24
|
-
await s(l, u, C, r(w), e);
|
|
25
|
-
}
|
|
26
|
-
let M = {
|
|
27
|
-
value: k > 0n ? BigInt(k).toString() : void 0,
|
|
28
|
-
gasLimit: void 0
|
|
29
|
-
}, N, P = [
|
|
30
|
-
p[0],
|
|
31
|
-
p[1],
|
|
32
|
-
p[2],
|
|
33
|
-
h,
|
|
34
|
-
m,
|
|
35
|
-
{
|
|
36
|
-
...M,
|
|
37
|
-
from: C
|
|
38
|
-
}
|
|
39
|
-
], { runner: F } = T;
|
|
40
|
-
if (!(F instanceof c.AbstractSigner)) throw Error("expected signer");
|
|
41
|
-
if (v) try {
|
|
42
|
-
N = Number(await T[E].estimateGas(...P));
|
|
43
|
-
} catch (e) {
|
|
44
|
-
console.log("hinkalDeposit: gas estimation error", { err: e });
|
|
45
|
-
}
|
|
46
|
-
let I = N && N >= 0 ? Math.ceil(N * 12 / 10) : void 0;
|
|
47
|
-
I && (P[5].gasLimit = I), await n();
|
|
48
|
-
let L;
|
|
12
|
+
console.log("[transactCallDirect] start", {
|
|
13
|
+
chainId: u,
|
|
14
|
+
preEstimateGas: v,
|
|
15
|
+
returnTxData: y
|
|
16
|
+
});
|
|
49
17
|
try {
|
|
50
|
-
|
|
18
|
+
let b = Array.isArray(d) ? d : [d], x = Array.isArray(f) ? f : [f];
|
|
19
|
+
if (b.length !== x.length) throw Error("token and amount length mismatch");
|
|
20
|
+
console.log("[transactCallDirect] getContractWithSigner");
|
|
21
|
+
let S = l.getContractWithSigner(u, t.HinkalContract), C = await l.getEthereumAddressByChain(u), w = g ?? S, T = _ ?? S, E = "transact", D = x.findIndex(({ erc20TokenAddress: t }) => t === e), O = x.some(({ erc20TokenAddress: t }) => t !== e), k = D === -1 ? 0n : b[D];
|
|
22
|
+
console.log("[transactCallDirect] supportsBatchCall");
|
|
23
|
+
let A = l.getProviderAdapter(u), j = await A.supportsBatchCall?.(u);
|
|
24
|
+
if (!y && O && j && A.sendBatchCallsTransaction) {
|
|
25
|
+
console.log("[transactCallDirect] sendBatchCallsTransaction");
|
|
26
|
+
let e = o(x.map((e) => e.erc20TokenAddress), b, r(w), T, p, h, m, k), t = await A.sendBatchCallsTransaction(u, e);
|
|
27
|
+
return console.log("[transactCallDirect] success (batch)", { tx: t }), t;
|
|
28
|
+
}
|
|
29
|
+
if (!y && (console.log("[transactCallDirect] approveTokensToHinkal"), await a(l, u, w, x, b), O)) {
|
|
30
|
+
console.log("[transactCallDirect] waitForErc20Approvals");
|
|
31
|
+
let e = x.map(({ erc20TokenAddress: e }, t) => ({
|
|
32
|
+
tokenAddress: e,
|
|
33
|
+
requiredAmount: b[t]
|
|
34
|
+
}));
|
|
35
|
+
await s(l, u, C, r(w), e);
|
|
36
|
+
}
|
|
37
|
+
let M = {
|
|
38
|
+
value: k > 0n ? BigInt(k).toString() : void 0,
|
|
39
|
+
gasLimit: void 0
|
|
40
|
+
}, N, P = [
|
|
41
|
+
p[0],
|
|
42
|
+
p[1],
|
|
43
|
+
p[2],
|
|
44
|
+
h,
|
|
45
|
+
m,
|
|
46
|
+
{
|
|
47
|
+
...M,
|
|
48
|
+
from: C
|
|
49
|
+
}
|
|
50
|
+
], { runner: F } = T;
|
|
51
|
+
if (!(F instanceof c.AbstractSigner)) throw Error("expected signer");
|
|
52
|
+
if (v) {
|
|
53
|
+
console.log("[transactCallDirect] estimateGas");
|
|
54
|
+
try {
|
|
55
|
+
N = Number(await T[E].estimateGas(...P));
|
|
56
|
+
} catch (e) {
|
|
57
|
+
console.log("[transactCallDirect] gas estimation error", { err: e });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
let I = N && N >= 0 ? Math.ceil(N * 12 / 10) : void 0;
|
|
61
|
+
I && (P[5].gasLimit = I), await n();
|
|
62
|
+
let L;
|
|
63
|
+
try {
|
|
64
|
+
console.log("[transactCallDirect] send transaction", { returnTxData: y }), L = y ? await T[E].populateTransaction(...P) : await T[E](...P);
|
|
65
|
+
} catch (e) {
|
|
66
|
+
if (!e?.transactionHash) throw e;
|
|
67
|
+
console.log("[transactCallDirect] recoverTransactionFromError", { hash: e.transactionHash });
|
|
68
|
+
let t = await i(F.provider, e.transactionHash);
|
|
69
|
+
if (!t) throw e;
|
|
70
|
+
L = t;
|
|
71
|
+
}
|
|
72
|
+
return console.log("[transactCallDirect] success", { tx: L }), L;
|
|
51
73
|
} catch (e) {
|
|
52
|
-
|
|
53
|
-
let t = await i(F.provider, e.transactionHash);
|
|
54
|
-
if (!t) throw e;
|
|
55
|
-
L = t;
|
|
74
|
+
throw console.log("[transactCallDirect] error", e), e;
|
|
56
75
|
}
|
|
57
|
-
return L;
|
|
58
76
|
};
|
|
59
77
|
//#endregion
|
|
60
78
|
export { l as transactCallDirect };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../../constants/protocol.constants.cjs`),n=require(`../../utils/caseInsensitive.utils.cjs`),r=require(`../../../error-handling/error-codes.constants.cjs`),i=require(`../../../externalABIs/index.cjs`),a=require(`../../../error-handling/logger.cjs`),o=require(`../../utils/tron.utils.cjs`),s=require(`../../utils/tronSimulation.utils.cjs`),c=require(`./waitForErc20Approvals.cjs`);var l=async(l,u,d,f,p,m,h,g,_,v=!0)=>{let y=Array.isArray(d)?d:[d],b=Array.isArray(f)?f:[f];if(y.length!==b.length)throw Error(`token and amount length mismatch`);let x=l.getTronWeb(),S=await l.getEthereumAddressByChain(u),{hinkalAddress:C,hinkalABI:w}=e.networkRegistry[u].contractData,T=x.contract(w,o.evmHexToTronBase58Address(C)),E=g??T,D=_??T;if(!E.address)throw Error(`contractForApproval address not set`);if(!D.address)throw Error(`contractForTransaction address not set`);let O=b.findIndex(({erc20TokenAddress:e})=>n.caseInsensitiveEqual(e,t.zeroAddress)),k=O===-1?0n:y[O],A=k>0n?k:0n;if(b.some(({erc20TokenAddress:e},r)=>!n.caseInsensitiveEqual(e,t.zeroAddress)&&y[r]>0n)){let e=E.address;if(!e)throw Error(`token approval spender not set`);let r=[];for(let a=0;a<b.length;a+=1){let s=b[a],c=y[a];if(c>0n&&!n.caseInsensitiveEqual(s.erc20TokenAddress,t.zeroAddress)){let n=o.evmHexToTronBase58Address(s.erc20TokenAddress),a=await x.contract(i.ERC20ABI,n).allowance(S,e).call({from:S});if(BigInt(String(a))<c){let{transaction:i}=await x.transactionBuilder.triggerSmartContract(n,`approve(address,uint256)`,{feeLimit:t.TRON_DEFAULT_FEE_LIMIT_SUN},[{type:`address`,value:e},{type:`uint256`,value:c.toString()}],S),a=await x.trx.sign(i),o=await x.trx.sendRawTransaction(a);if(!o.result){let e=o.code??`UNKNOWN`,t=o.message?Buffer.from(o.message,`hex`).toString():`no message`;throw Error(`Tron token approval failed: ${e} - ${t}`)}r.push({tokenAddress:n,requiredAmount:c})}}}r.length>0&&await c.waitForTronErc20Approvals(x,S,e,r)}let{a:j,b:M,c:N}=o.parseZkCalldata(p),P=await o.reorderZkCallData(!0,p,h,m,!1);if(!P)throw Error(`Tron proof signature not found`);let F=[P.v,P.r,P.s],I=[h.tokenNumber,h.nullifierAmount,h.outputAmount],L=o.circomDataToArray(m);if(v){await s.simulateTronTransaction(u,D.address,`transact`,D.abi,[F,j,M,N,I,L],S,A);let e=BigInt(await x.trx.getBalance(S)),n=BigInt(t.TRON_DEFAULT_FEE_LIMIT_SUN);try{let e=o.createTronCallData(D.abi,`transact`,[F,j,M,N,I,L]);n=await o.estimateTronFeeSunWithPadding(x,u,D.address,S,e,A)}catch(e){a.Logger.error(`Error estimating Tron transact fee`,e)}if(e<A+n)throw Error(r.insufficientResourcesErrorCodes.INSUFFICIENT_TRON_BALANCE_FOR_FEE)}let R=await D.transact(F,j,M,N,I,L).send({feeLimit:t.TRON_DEFAULT_FEE_LIMIT_SUN,callValue:Number(A)}),z=typeof R==`string`?R:R?.txid??R?.transaction?.txID??R?.transaction?.txid;if(!z)throw Error(`Tron transact failed (missing txid)`);return z};exports.transactCallDirectTron=l;
|
|
1
|
+
const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../../constants/protocol.constants.cjs`),n=require(`../../utils/caseInsensitive.utils.cjs`),r=require(`../../../error-handling/error-codes.constants.cjs`),i=require(`../../../externalABIs/index.cjs`),a=require(`../../../error-handling/logger.cjs`),o=require(`../../utils/tron.utils.cjs`),s=require(`../../utils/tronSimulation.utils.cjs`),c=require(`./waitForErc20Approvals.cjs`);var l=async(l,u,d,f,p,m,h,g,_,v=!0)=>{console.log(`[transactCallDirectTron] start`,{chainId:u});try{let y=Array.isArray(d)?d:[d],b=Array.isArray(f)?f:[f];if(y.length!==b.length)throw Error(`token and amount length mismatch`);let x=l.getTronWeb(),S=await l.getEthereumAddressByChain(u),{hinkalAddress:C,hinkalABI:w}=e.networkRegistry[u].contractData,T=x.contract(w,o.evmHexToTronBase58Address(C)),E=g??T,D=_??T;if(!E.address)throw Error(`contractForApproval address not set`);if(!D.address)throw Error(`contractForTransaction address not set`);let O=b.findIndex(({erc20TokenAddress:e})=>n.caseInsensitiveEqual(e,t.zeroAddress)),k=O===-1?0n:y[O],A=k>0n?k:0n;if(b.some(({erc20TokenAddress:e},r)=>!n.caseInsensitiveEqual(e,t.zeroAddress)&&y[r]>0n)){console.log(`[transactCallDirectTron] token approvals`);let e=E.address;if(!e)throw Error(`token approval spender not set`);let r=[];for(let a=0;a<b.length;a+=1){let s=b[a],c=y[a];if(c>0n&&!n.caseInsensitiveEqual(s.erc20TokenAddress,t.zeroAddress)){let n=o.evmHexToTronBase58Address(s.erc20TokenAddress),a=await x.contract(i.ERC20ABI,n).allowance(S,e).call({from:S});if(BigInt(String(a))<c){let{transaction:i}=await x.transactionBuilder.triggerSmartContract(n,`approve(address,uint256)`,{feeLimit:t.TRON_DEFAULT_FEE_LIMIT_SUN},[{type:`address`,value:e},{type:`uint256`,value:c.toString()}],S),a=await x.trx.sign(i),o=await x.trx.sendRawTransaction(a);if(!o.result){let e=o.code??`UNKNOWN`,t=o.message?Buffer.from(o.message,`hex`).toString():`no message`;throw Error(`Tron token approval failed: ${e} - ${t}`)}r.push({tokenAddress:n,requiredAmount:c})}}}r.length>0&&await c.waitForTronErc20Approvals(x,S,e,r)}console.log(`[transactCallDirectTron] reorderZkCallData`);let{a:j,b:M,c:N}=o.parseZkCalldata(p),P=await o.reorderZkCallData(!0,p,h,m,!1);if(!P)throw Error(`Tron proof signature not found`);let F=[P.v,P.r,P.s],I=[h.tokenNumber,h.nullifierAmount,h.outputAmount],L=o.circomDataToArray(m);if(v){console.log(`[transactCallDirectTron] simulateTronTransaction`),await s.simulateTronTransaction(u,D.address,`transact`,D.abi,[F,j,M,N,I,L],S,A);let e=BigInt(await x.trx.getBalance(S)),n=BigInt(t.TRON_DEFAULT_FEE_LIMIT_SUN);try{let e=o.createTronCallData(D.abi,`transact`,[F,j,M,N,I,L]);n=await o.estimateTronFeeSunWithPadding(x,u,D.address,S,e,A)}catch(e){a.Logger.error(`Error estimating Tron transact fee`,e)}if(e<A+n)throw Error(r.insufficientResourcesErrorCodes.INSUFFICIENT_TRON_BALANCE_FOR_FEE)}console.log(`[transactCallDirectTron] contract.transact.send`);let R=await D.transact(F,j,M,N,I,L).send({feeLimit:t.TRON_DEFAULT_FEE_LIMIT_SUN,callValue:Number(A)}),z=typeof R==`string`?R:R?.txid??R?.transaction?.txID??R?.transaction?.txid;if(!z)throw Error(`Tron transact failed (missing txid)`);return console.log(`[transactCallDirectTron] success`,{txid:z}),z}catch(e){throw console.log(`[transactCallDirectTron] error`,e),e}};exports.transactCallDirectTron=l;
|
|
@@ -9,83 +9,91 @@ import { simulateTronTransaction as p } from "../../utils/tronSimulation.utils.m
|
|
|
9
9
|
import { waitForTronErc20Approvals as m } from "./waitForErc20Approvals.mjs";
|
|
10
10
|
//#region libs/shared/common/src/functions/web3/functionCalls/transactCallDirectTron.ts
|
|
11
11
|
var h = async (h, g, _, v, y, b, x, S, C, w = !0) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
let e =
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
12
|
+
console.log("[transactCallDirectTron] start", { chainId: g });
|
|
13
|
+
try {
|
|
14
|
+
let T = Array.isArray(_) ? _ : [_], E = Array.isArray(v) ? v : [v];
|
|
15
|
+
if (T.length !== E.length) throw Error("token and amount length mismatch");
|
|
16
|
+
let D = h.getTronWeb(), O = await h.getEthereumAddressByChain(g), { hinkalAddress: k, hinkalABI: A } = e[g].contractData, j = D.contract(A, u(k)), M = S ?? j, N = C ?? j;
|
|
17
|
+
if (!M.address) throw Error("contractForApproval address not set");
|
|
18
|
+
if (!N.address) throw Error("contractForTransaction address not set");
|
|
19
|
+
let P = E.findIndex(({ erc20TokenAddress: e }) => r(e, n)), F = P === -1 ? 0n : T[P], I = F > 0n ? F : 0n;
|
|
20
|
+
if (E.some(({ erc20TokenAddress: e }, t) => !r(e, n) && T[t] > 0n)) {
|
|
21
|
+
console.log("[transactCallDirectTron] token approvals");
|
|
22
|
+
let e = M.address;
|
|
23
|
+
if (!e) throw Error("token approval spender not set");
|
|
24
|
+
let i = [];
|
|
25
|
+
for (let o = 0; o < E.length; o += 1) {
|
|
26
|
+
let s = E[o], c = T[o];
|
|
27
|
+
if (c > 0n && !r(s.erc20TokenAddress, n)) {
|
|
28
|
+
let n = u(s.erc20TokenAddress), r = await D.contract(a, n).allowance(O, e).call({ from: O });
|
|
29
|
+
if (BigInt(String(r)) < c) {
|
|
30
|
+
let { transaction: r } = await D.transactionBuilder.triggerSmartContract(n, "approve(address,uint256)", { feeLimit: t }, [{
|
|
31
|
+
type: "address",
|
|
32
|
+
value: e
|
|
33
|
+
}, {
|
|
34
|
+
type: "uint256",
|
|
35
|
+
value: c.toString()
|
|
36
|
+
}], O), a = await D.trx.sign(r), o = await D.trx.sendRawTransaction(a);
|
|
37
|
+
if (!o.result) {
|
|
38
|
+
let e = o.code ?? "UNKNOWN", t = o.message ? Buffer.from(o.message, "hex").toString() : "no message";
|
|
39
|
+
throw Error(`Tron token approval failed: ${e} - ${t}`);
|
|
40
|
+
}
|
|
41
|
+
i.push({
|
|
42
|
+
tokenAddress: n,
|
|
43
|
+
requiredAmount: c
|
|
44
|
+
});
|
|
37
45
|
}
|
|
38
|
-
i.push({
|
|
39
|
-
tokenAddress: n,
|
|
40
|
-
requiredAmount: c
|
|
41
|
-
});
|
|
42
46
|
}
|
|
43
47
|
}
|
|
48
|
+
i.length > 0 && await m(D, O, e, i);
|
|
44
49
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
await p(g, N.address, "transact", N.abi, [
|
|
60
|
-
V,
|
|
61
|
-
L,
|
|
62
|
-
R,
|
|
63
|
-
z,
|
|
64
|
-
H,
|
|
65
|
-
U
|
|
66
|
-
], O, I);
|
|
67
|
-
let e = BigInt(await D.trx.getBalance(O)), n = BigInt(t);
|
|
68
|
-
try {
|
|
69
|
-
let e = c(N.abi, "transact", [
|
|
50
|
+
console.log("[transactCallDirectTron] reorderZkCallData");
|
|
51
|
+
let { a: L, b: R, c: z } = d(y), B = await f(!0, y, x, b, !1);
|
|
52
|
+
if (!B) throw Error("Tron proof signature not found");
|
|
53
|
+
let V = [
|
|
54
|
+
B.v,
|
|
55
|
+
B.r,
|
|
56
|
+
B.s
|
|
57
|
+
], H = [
|
|
58
|
+
x.tokenNumber,
|
|
59
|
+
x.nullifierAmount,
|
|
60
|
+
x.outputAmount
|
|
61
|
+
], U = s(b);
|
|
62
|
+
if (w) {
|
|
63
|
+
console.log("[transactCallDirectTron] simulateTronTransaction"), await p(g, N.address, "transact", N.abi, [
|
|
70
64
|
V,
|
|
71
65
|
L,
|
|
72
66
|
R,
|
|
73
67
|
z,
|
|
74
68
|
H,
|
|
75
69
|
U
|
|
76
|
-
]);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
70
|
+
], O, I);
|
|
71
|
+
let e = BigInt(await D.trx.getBalance(O)), n = BigInt(t);
|
|
72
|
+
try {
|
|
73
|
+
let e = c(N.abi, "transact", [
|
|
74
|
+
V,
|
|
75
|
+
L,
|
|
76
|
+
R,
|
|
77
|
+
z,
|
|
78
|
+
H,
|
|
79
|
+
U
|
|
80
|
+
]);
|
|
81
|
+
n = await l(D, g, N.address, O, e, I);
|
|
82
|
+
} catch (e) {
|
|
83
|
+
o.error("Error estimating Tron transact fee", e);
|
|
84
|
+
}
|
|
85
|
+
if (e < I + n) throw Error(i.INSUFFICIENT_TRON_BALANCE_FOR_FEE);
|
|
80
86
|
}
|
|
81
|
-
|
|
87
|
+
console.log("[transactCallDirectTron] contract.transact.send");
|
|
88
|
+
let W = await N.transact(V, L, R, z, H, U).send({
|
|
89
|
+
feeLimit: t,
|
|
90
|
+
callValue: Number(I)
|
|
91
|
+
}), G = typeof W == "string" ? W : W?.txid ?? W?.transaction?.txID ?? W?.transaction?.txid;
|
|
92
|
+
if (!G) throw Error("Tron transact failed (missing txid)");
|
|
93
|
+
return console.log("[transactCallDirectTron] success", { txid: G }), G;
|
|
94
|
+
} catch (e) {
|
|
95
|
+
throw console.log("[transactCallDirectTron] error", e), e;
|
|
82
96
|
}
|
|
83
|
-
let W = await N.transact(V, L, R, z, H, U).send({
|
|
84
|
-
feeLimit: t,
|
|
85
|
-
callValue: Number(I)
|
|
86
|
-
}), G = typeof W == "string" ? W : W?.txid ?? W?.transaction?.txID ?? W?.transaction?.txid;
|
|
87
|
-
if (!G) throw Error("Tron transact failed (missing txid)");
|
|
88
|
-
return G;
|
|
89
97
|
};
|
|
90
98
|
//#endregion
|
|
91
99
|
export { h as transactCallDirectTron };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../../error-handling/customErrors/ErrorWithTx.cjs`),t=require(`../../../constants/server.constants.cjs`),n=require(`../../../API/getServerURL.cjs`),r=require(`../../../data-structures/http/HttpClient.cjs`),i=require(`../../../API/callRelayer.cjs`),a=require(`../../snarkjs/common.snarkjs.cjs`);require(`../../../error-handling/index.cjs`),require(`../../snarkjs/index.cjs`);var o=t=>{if(t.status===`success`)return t.message;throw t.message&&t.error?new e.ErrorWithRelayerTransaction(t.error,t.message):Error(t.error)},s=async(e,t,n,r,s,c,l,u,d)=>{let f=a.serializeCircomData(r);
|
|
1
|
+
const e=require(`../../../error-handling/customErrors/ErrorWithTx.cjs`),t=require(`../../../constants/server.constants.cjs`),n=require(`../../../API/getServerURL.cjs`),r=require(`../../../data-structures/http/HttpClient.cjs`),i=require(`../../../API/callRelayer.cjs`),a=require(`../../snarkjs/common.snarkjs.cjs`);require(`../../../error-handling/index.cjs`),require(`../../snarkjs/index.cjs`);var o=t=>{if(t.status===`success`)return t.message;throw t.message&&t.error?new e.ErrorWithRelayerTransaction(t.error,t.message):Error(t.error)},s=async(e,t,n,r,s,c,l,u,d)=>{console.log(`[transactCallRelayer] start`,{chainId:e});try{console.log(`[transactCallRelayer] serializeCircomData`);let f=a.serializeCircomData(r);console.log(`[transactCallRelayer] callRelayerTransactAPI`);let p=o(await i.callRelayerTransactAPI({chainId:e,a:t[0],b:t[1],c:t[2],dimData:n,circomData:f,withUniswapWorkAround:c,authorizationData:l,adminData:u,tronProofSignature:d,commitmentValidationData:s}));return console.log(`[transactCallRelayer] success`,{txHash:p}),p}catch(e){throw console.log(`[transactCallRelayer] error`,e),e}},c=async e=>o(await r.httpClient.post(`${n.RELAYER_URL}${t.RELAYER_CONFIG.SOLANA_TRANSACT}`,e)),l=e=>{if(e.status===`success`)return e.message.scheduleId;throw Error(e.error||`Batch transaction failed`)},u=async(e,t,n,r,o,s)=>{let c=t.map(e=>a.serializeCircomData(e.circomData));return l(await i.callRelayerTransactBatchAPI({chainId:e,transactions:t.map((t,n)=>({chainId:e,a:t.zkCallData[0],b:t.zkCallData[1],c:t.zkCallData[2],dimData:t.dimData,circomData:c[n],commitmentValidationData:t.commitmentValidationData,withUniswapWorkAround:t.withUniswapWorkAround,authorizationData:t.authorizationData,adminData:t.adminData,recipientAddress:t.recipientAddress,tronProofSignature:t.tronProofSignature})),txCompletionTime:r,hashedEthereumAddress:n,ref:o,hashedDashboardAccountId:s}))},d=async(e,t,n,r,a,o)=>l(await i.callRelayerSolanaTransactBatchAPI({chainId:e,transactions:t,hashedEthereumAddress:n,txCompletionTime:r,ref:a,hashedDashboardAccountId:o}));exports.solanaTransactCallRelayer=c,exports.solanaTransactCallRelayerBatch=d,exports.transactCallRelayer=s,exports.transactCallRelayerBatch=u;
|
|
@@ -11,20 +11,28 @@ var c = (t) => {
|
|
|
11
11
|
if (t.status === "success") return t.message;
|
|
12
12
|
throw t.message && t.error ? new e(t.error, t.message) : Error(t.error);
|
|
13
13
|
}, l = async (e, t, n, r, i, o, l, u, d) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
c
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
console.log("[transactCallRelayer] start", { chainId: e });
|
|
15
|
+
try {
|
|
16
|
+
console.log("[transactCallRelayer] serializeCircomData");
|
|
17
|
+
let f = s(r);
|
|
18
|
+
console.log("[transactCallRelayer] callRelayerTransactAPI");
|
|
19
|
+
let p = c(await a({
|
|
20
|
+
chainId: e,
|
|
21
|
+
a: t[0],
|
|
22
|
+
b: t[1],
|
|
23
|
+
c: t[2],
|
|
24
|
+
dimData: n,
|
|
25
|
+
circomData: f,
|
|
26
|
+
withUniswapWorkAround: o,
|
|
27
|
+
authorizationData: l,
|
|
28
|
+
adminData: u,
|
|
29
|
+
tronProofSignature: d,
|
|
30
|
+
commitmentValidationData: i
|
|
31
|
+
}));
|
|
32
|
+
return console.log("[transactCallRelayer] success", { txHash: p }), p;
|
|
33
|
+
} catch (e) {
|
|
34
|
+
throw console.log("[transactCallRelayer] error", e), e;
|
|
35
|
+
}
|
|
28
36
|
}, u = async (e) => c(await r.post(`${n}${t.SOLANA_TRANSACT}`, e)), d = (e) => {
|
|
29
37
|
if (e.status === "success") return e.message.scheduleId;
|
|
30
38
|
throw Error(e.error || "Batch transaction failed");
|