@kapa123456789/sdk 0.0.82 → 0.0.84
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/constants/chains.constants.cjs +1 -1
- package/common/src/constants/chains.constants.mjs +1 -1
- package/common/src/crypto/babyJub.cjs +1 -1
- package/common/src/crypto/babyJub.mjs +1 -1
- package/common/src/crypto/eddsa.cjs +1 -1
- package/common/src/crypto/eddsa.mjs +1 -1
- package/common/src/crypto/poseidon.cjs +1 -1
- package/common/src/crypto/poseidon.mjs +1 -1
- package/common/src/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/common/src/data-structures/Hinkal/Hinkal.mjs +4 -41
- package/common/src/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalDeposit.mjs +46 -73
- package/common/src/data-structures/Hinkal/hinkalTransfer.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalTransfer.mjs +16 -37
- package/common/src/data-structures/Hinkal/hinkalWithdraw.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalWithdraw.mjs +18 -47
- package/common/src/data-structures/crypto-keys/keys.cjs +1 -1
- package/common/src/data-structures/crypto-keys/keys.mjs +8 -2
- package/common/src/data-structures/token-price-fetcher/TokenChecker.cjs +1 -1
- package/common/src/data-structures/token-price-fetcher/TokenChecker.mjs +5 -5
- package/common/src/functions/pre-transaction/getFeeStructure.cjs +1 -1
- package/common/src/functions/pre-transaction/getFeeStructure.mjs +10 -21
- package/common/src/functions/snarkjs/constructGeneralZkProof.cjs +1 -1
- package/common/src/functions/snarkjs/constructGeneralZkProof.mjs +71 -89
- package/common/src/functions/snarkjs/generateMainAndCommitmentZkProof.cjs +1 -1
- package/common/src/functions/snarkjs/generateMainAndCommitmentZkProof.mjs +8 -17
- package/common/src/functions/snarkjs/generateZkProof.cjs +1 -1
- package/common/src/functions/snarkjs/generateZkProof.mjs +8 -26
- package/common/src/functions/utils/evmNetworkFunctions.cjs +1 -1
- package/common/src/functions/utils/evmNetworkFunctions.d.ts +1 -0
- package/common/src/functions/utils/evmNetworkFunctions.mjs +4 -0
- package/common/src/functions/utils/process.utils.cjs +1 -1
- package/common/src/functions/utils/process.utils.mjs +6 -10
- package/common/src/functions/web3/functionCalls/transactCallDirect.cjs +1 -1
- package/common/src/functions/web3/functionCalls/transactCallDirect.mjs +43 -61
- package/common/src/functions/web3/functionCalls/transactCallDirectTron.cjs +1 -1
- package/common/src/functions/web3/functionCalls/transactCallDirectTron.mjs +65 -73
- package/common/src/functions/web3/functionCalls/transactCallRelayer.cjs +1 -1
- package/common/src/functions/web3/functionCalls/transactCallRelayer.mjs +14 -22
- package/common/src/types/scheduled-transactions.types.d.ts +1 -0
- package/common/src/webworker/logError-F50ubgnd.js +2 -0
- package/common/src/webworker/package.json +1 -1
- 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 +3 -3
- package/common/src/webworker/viteWorkerURL.constant.mjs +3 -3
- package/common/src/webworker/{workerProxy-D22p2w2G.js → workerProxy-BP_AUL0j.js} +1 -1
- 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/functions/integrations/swapApi.cjs +1 -1
- package/functions/integrations/swapApi.mjs +4 -9
- package/package.json +1 -1
- package/services/Hinkal.cjs +1 -1
- package/services/Hinkal.mjs +3 -42
- package/common/src/webworker/logError-o9XP6THu.js +0 -2
|
@@ -46,8 +46,14 @@ var p = new i(), m = new i(), h = new i(), g = class {
|
|
|
46
46
|
};
|
|
47
47
|
signEddsa = (e) => {
|
|
48
48
|
this.requireSignature();
|
|
49
|
-
let t = n(), i = r()
|
|
50
|
-
|
|
49
|
+
let t = n(), i = r();
|
|
50
|
+
console.log("message", e), console.log("this.getSpendingKeyPair().privSpendingKey", this.getSpendingKeyPair().privSpendingKey);
|
|
51
|
+
let a = Buffer.from(o.getBytes(this.getSpendingKeyPair().privSpendingKey));
|
|
52
|
+
console.log("prvBytes", a);
|
|
53
|
+
let s = t.F.e(e);
|
|
54
|
+
console.log("msgF", s);
|
|
55
|
+
let c = i.signPoseidon(a, s);
|
|
56
|
+
return console.log("sig", c), {
|
|
51
57
|
R8: [BigInt(t.F.toString(c.R8[0])), BigInt(t.F.toString(c.R8[1]))],
|
|
52
58
|
S: BigInt(c.S)
|
|
53
59
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`);var n=class{static isBeefyStakeToken=e=>e.name.includes(`-Boost`)&&e.symbol.includes(`-Boost`);static isStakeToken=e=>this.isBeefyStakeToken(e);static isAaveToken=e=>e.aaveToken;static isKinzaToken=e=>e.name.startsWith(`Kinza`);static isPotentiallyVolatile=n=>n.erc20TokenAddress===t.zeroAddress?!1:n.isVolatile||!e.isSolanaLike(n.chainId)&&(n.balanceStorageOffset===void 0||n.allowanceStorageOffset===void 0);static isPotentiallySpamToken(e){let{name:t,symbol:n}=e,r=`${t} ${n}`,i=/(?:https?:\/\/|www\.)/i,a=/\.(?:com|io|app|org|net|co|xyz|link|site|top|in|ru|cn|me|biz|info|online|club|tech|to|cloud)(?=[^\w]|$)/i,o=/\b(?:t\.me|discord\.(?:gg|com)|twitter\.com|x\.com|telegram\.(?:me|org))\b/i,s=/@[^\s]+\.[^\s]+/i,c=/\p{Extended_Pictographic}/u,l=/[\u{1F1E6}-\u{1F1FF}]{2}/u,u=/[#*0-9]\uFE0F?\u20E3/u,d=i.test(r),f=a.test(r),p=o.test(r),m=s.test(r),h=c.test(r)||l.test(r)||u.test(r);return d||f||p||m||h}};exports.TokenChecker=n;
|
|
1
|
+
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`);var n=class{static isBeefyStakeToken=e=>e.name.includes(`-Boost`)&&e.symbol.includes(`-Boost`);static isStakeToken=e=>this.isBeefyStakeToken(e);static isAaveToken=e=>e.aaveToken;static isKinzaToken=e=>e.name.startsWith(`Kinza`);static isPotentiallyVolatile=n=>n.erc20TokenAddress===t.zeroAddress?!1:n.isVolatile||!e.isSolanaLike(n.chainId)&&!e.isTronLike(n.chainId)&&(n.balanceStorageOffset===void 0||n.allowanceStorageOffset===void 0);static isPotentiallySpamToken(e){let{name:t,symbol:n}=e,r=`${t} ${n}`,i=/(?:https?:\/\/|www\.)/i,a=/\.(?:com|io|app|org|net|co|xyz|link|site|top|in|ru|cn|me|biz|info|online|club|tech|to|cloud)(?=[^\w]|$)/i,o=/\b(?:t\.me|discord\.(?:gg|com)|twitter\.com|x\.com|telegram\.(?:me|org))\b/i,s=/@[^\s]+\.[^\s]+/i,c=/\p{Extended_Pictographic}/u,l=/[\u{1F1E6}-\u{1F1FF}]{2}/u,u=/[#*0-9]\uFE0F?\u20E3/u,d=i.test(r),f=a.test(r),p=o.test(r),m=s.test(r),h=c.test(r)||l.test(r)||u.test(r);return d||f||p||m||h}};exports.TokenChecker=n;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { isSolanaLike as e } from "../../constants/chains.constants.mjs";
|
|
2
|
-
import { zeroAddress as
|
|
1
|
+
import { isSolanaLike as e, isTronLike as t } from "../../constants/chains.constants.mjs";
|
|
2
|
+
import { zeroAddress as n } from "../../constants/protocol.constants.mjs";
|
|
3
3
|
//#region libs/shared/common/src/data-structures/token-price-fetcher/TokenChecker.ts
|
|
4
|
-
var
|
|
4
|
+
var r = class {
|
|
5
5
|
static isBeefyStakeToken = (e) => e.name.includes("-Boost") && e.symbol.includes("-Boost");
|
|
6
6
|
static isStakeToken = (e) => this.isBeefyStakeToken(e);
|
|
7
7
|
static isAaveToken = (e) => e.aaveToken;
|
|
8
8
|
static isKinzaToken = (e) => e.name.startsWith("Kinza");
|
|
9
|
-
static isPotentiallyVolatile = (
|
|
9
|
+
static isPotentiallyVolatile = (r) => r.erc20TokenAddress === n ? !1 : r.isVolatile || !e(r.chainId) && !t(r.chainId) && (r.balanceStorageOffset === void 0 || r.allowanceStorageOffset === void 0);
|
|
10
10
|
static isPotentiallySpamToken(e) {
|
|
11
11
|
let { name: t, symbol: n } = e, r = `${t} ${n}`, i = /(?:https?:\/\/|www\.)/i, a = /\.(?:com|io|app|org|net|co|xyz|link|site|top|in|ru|cn|me|biz|info|online|club|tech|to|cloud)(?=[^\w]|$)/i, o = /\b(?:t\.me|discord\.(?:gg|com)|twitter\.com|x\.com|telegram\.(?:me|org))\b/i, s = /@[^\s]+\.[^\s]+/i, c = /\p{Extended_Pictographic}/u, l = /[\u{1F1E6}-\u{1F1FF}]{2}/u, u = /[#*0-9]\uFE0F?\u20E3/u, d = i.test(r), f = a.test(r), p = o.test(r), m = s.test(r), h = c.test(r) || l.test(r) || u.test(r);
|
|
12
12
|
return d || f || p || m || h;
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
//#endregion
|
|
16
|
-
export {
|
|
16
|
+
export { r as TokenChecker };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../constants/fees.constants.cjs`),t=require(`../utils/caseInsensitive.utils.cjs`),n=require(`../../error-handling/logger.cjs`),r=require(`../utils/erc20tokenFunctions.cjs`),i=require(`./process-gas-estimates.cjs`);var a=async(a,o,s,c,l=[],u=0n,d)=>{
|
|
1
|
+
const e=require(`../../constants/fees.constants.cjs`),t=require(`../utils/caseInsensitive.utils.cjs`),n=require(`../../error-handling/logger.cjs`),r=require(`../utils/erc20tokenFunctions.cjs`),i=require(`./process-gas-estimates.cjs`);var a=async(a,o,s,c,l=[],u=0n,d)=>{let f=await r.getErc20TokenFromAPI(a,o??e.defaultFeeToken);if(!f)throw Error(`failed to find feeToken`);let{priceOfTransactionInToken:p}=await i.processGasEstimates(a,f,c,s.some(e=>t.caseInsensitiveEqual(e,o))?s.length+1:s.length,void 0,l,d);if(p===void 0)throw Error(`failed to process gas estimates`);let m={feeToken:f.erc20TokenAddress,flatFee:p,variableRate:u};return n.Logger.log(m),m};exports.getFeeStructure=a;
|
|
@@ -5,27 +5,16 @@ import { getErc20TokenFromAPI as r } from "../utils/erc20tokenFunctions.mjs";
|
|
|
5
5
|
import { processGasEstimates as i } from "./process-gas-estimates.mjs";
|
|
6
6
|
//#region libs/shared/common/src/functions/pre-transaction/getFeeStructure.ts
|
|
7
7
|
var a = async (a, o, s, c, l = [], u = 0n, d) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
let { priceOfTransactionInToken: m } = await i(a, f, c, p, void 0, l, d);
|
|
19
|
-
if (m === void 0) throw Error("failed to process gas estimates");
|
|
20
|
-
let h = {
|
|
21
|
-
feeToken: f.erc20TokenAddress,
|
|
22
|
-
flatFee: m,
|
|
23
|
-
variableRate: u
|
|
24
|
-
};
|
|
25
|
-
return n.log(h), console.log("[getFeeStructure] success", { feeStructure: h }), h;
|
|
26
|
-
} catch (e) {
|
|
27
|
-
throw console.log("[getFeeStructure] error", e), e;
|
|
28
|
-
}
|
|
8
|
+
let f = await r(a, o ?? e);
|
|
9
|
+
if (!f) throw Error("failed to find feeToken");
|
|
10
|
+
let { priceOfTransactionInToken: p } = await i(a, f, c, s.some((e) => t(e, o)) ? s.length + 1 : s.length, void 0, l, d);
|
|
11
|
+
if (p === void 0) throw Error("failed to process gas estimates");
|
|
12
|
+
let m = {
|
|
13
|
+
feeToken: f.erc20TokenAddress,
|
|
14
|
+
flatFee: p,
|
|
15
|
+
variableRate: u
|
|
16
|
+
};
|
|
17
|
+
return n.log(m), m;
|
|
29
18
|
};
|
|
30
19
|
//#endregion
|
|
31
20
|
export { a as getFeeStructure };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../crypto/poseidon.cjs`),r=require(`../web3/etherFunctions.cjs`),i=require(`../../data-structures/crypto-keys/keys.cjs`),a=require(`../utils/time.utils.cjs`),o=require(`../../types/external-action.types.cjs`),s=require(`../../error-handling/logger.cjs`),c=require(`../utils/bit.operations.cjs`),l=require(`./common.snarkjs.cjs`),
|
|
1
|
+
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../crypto/poseidon.cjs`),r=require(`../web3/etherFunctions.cjs`),i=require(`../../data-structures/crypto-keys/keys.cjs`),a=require(`../utils/time.utils.cjs`),o=require(`../../types/external-action.types.cjs`),s=require(`../../error-handling/logger.cjs`),c=require(`../utils/bit.operations.cjs`),l=require(`./common.snarkjs.cjs`),ee=require(`./signedMessageHash.cjs`),u=require(`./generateCircomData.cjs`),te=require(`../../data-structures/AccountActions/AccountActions.cjs`),d=require(`./generateMainAndCommitmentZkProof.cjs`),f=require(`./getMerkleTreeSiblingsAndRootHashes.cjs`),p=require(`../private-wallet/emporium.helpers.cjs`);var m=async(m,h,g,_,v,y,b,x,S,C=t.zeroAddress,w=e.chainIds.localhost,T=h.map(()=>!1),E=void 0,D,O)=>{let k=l.getZkProofVerifierName(h,g),A=l.calcAmountChanges(h,g),j=h.map(e=>e[0].erc20TokenAddress),M=l.calcEncryptedOutputs(g),N=t.defaultSignatureData,P=_.getShieldedPrivateKey(),{pubSpendingBJJPoint:F}=_.getSpendingKeyPair(),I=l.calcStealthAddressStructure(i.UserKeys.findCorrectRandomization(r.randomBigInt(31),P),P,_.getSpendingKeyPair().pubSpendingBJJPoint),{inCommitmentSiblings:ne,inCommitmentSiblingSides:re,rootHashHinkal:L,inNullifiers:R}=await f.getDataFromWorkers(w,m,h.map(e=>e.map(e=>e.getConstructableParams()))),z=l.buildOutCommitments(g),B=r.randomBigInt(31),V=n.poseidonFunction(B),H=BigInt(g.length>0?g[0][0].timeStamp:a.getCurrentTimeInSeconds()),U={rootHashHinkal:L,spendingPublicKey:F,nullifyingPrivateKey:P,erc20TokenAddresses:j,amountChanges:A,inAmounts:h.map(e=>e.map(e=>e.amount.toString())),inRandomizations:h.map(e=>e.map(e=>l.getUtxoCircuitInRandomization(e))),inH0Ax:h.map(e=>e.map(e=>l.getUtxoCircuitH0Coords(e)[0].toString())),inH0Ay:h.map(e=>e.map(e=>l.getUtxoCircuitH0Coords(e)[1].toString())),isNewStyle:h.map(e=>e.map(e=>!!e.isNewStyle)),inTimeStamps:h.map(e=>e.map(e=>e.timeStamp)),inNullifiers:R,inCommitmentSiblings:ne,inCommitmentSiblingSides:re,outAmounts:g.map(e=>e.map(e=>e.amount.toString())),outTimeStamp:H,outPublicKeys:g.map(e=>e.map(e=>e.getStealthAddress())),outCommitments:z,calldataHash:0n,messageSeed:B,H0Ax:c.takeOffHighestBit(I.extraRandomization),H0Ay:I.H0},W=l.calcPublicSignalCount(k,U.erc20TokenAddresses,U.amountChanges,U.inNullifiers,U.outCommitments),G=l.calcAmountChanges(h,g,!0),K=l.getSlippageValues(G);s.Logger.log({publicSignalCount:W});let q=Array.isArray(b)?b:[b],J=e.getOnchainChainId(w),Y=O?te.AccountActions.getSignerAddressFromPrivateKey(J,O):void 0,X=v===o.ExternalActionId.Emporium?await p.encodeEmporiumMetadata(w,y??t.zeroAddress,O,q,V,Y):await p.encodeEmporiumMetadata(w,t.zeroAddress,void 0,v===0n?[]:q,V,t.zeroAddress);U.calldataHash=l.createCallDataHash(W,C,y,v,X,M,E,K,T,S,N,D);let Z=ee.computeSignedMessageHashEvm({rootHashHinkal:L,erc20TokenAddresses:j,amountChanges:A,outTimeStamp:H,inNullifiers:R,outCommitments:z,calldataHash:U.calldataHash,message:V,outH1Ay:I.H1,H0Ax:U.H0Ax,H0Ay:I.H0}),{R8:Q,S:ie}=_.signEddsa(Z);U.eddsaSignature=[Q[0],Q[1],ie],U.signedMessageHash=Z;let $=k.startsWith(`mainEVMCircuitMin0`),ae={outTimeStamp:H,calldataHash:U.calldataHash,messageSeed:B},{zkCallData:oe,commitmentValidationData:se}=await d.generateMainAndCommitmentZkProof(w,_,j,h,k,$?ae:U,x);return{zkCallData:oe,circomData:u.generateCircomData(z,R,L,G,j,g,M,W,v,y,X,C,U.calldataHash,I,T,E,$?Number(H):void 0,K,S,N,D),dimData:{tokenNumber:h.length,nullifierAmount:h.length>0?h[0].length:0,outputAmount:g.length>0?g[0].length:0},encryptedOutputs:M,commitmentValidationData:se}};exports.constructZkProof=m;
|
|
@@ -1,100 +1,82 @@
|
|
|
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 t } from "../../constants/chains.constants.mjs";
|
|
2
|
+
import { defaultSignatureData as ee, zeroAddress as n } from "../../constants/protocol.constants.mjs";
|
|
3
|
+
import { poseidonFunction as te } from "../../crypto/poseidon.mjs";
|
|
4
|
+
import { randomBigInt as r } from "../web3/etherFunctions.mjs";
|
|
5
|
+
import { UserKeys as i } from "../../data-structures/crypto-keys/keys.mjs";
|
|
6
|
+
import { getCurrentTimeInSeconds as a } from "../utils/time.utils.mjs";
|
|
7
|
+
import { ExternalActionId as o } from "../../types/external-action.types.mjs";
|
|
8
|
+
import { Logger as s } from "../../error-handling/logger.mjs";
|
|
9
|
+
import { takeOffHighestBit as ne } from "../utils/bit.operations.mjs";
|
|
10
|
+
import { buildOutCommitments as re, calcAmountChanges as c, calcEncryptedOutputs as ie, calcPublicSignalCount as ae, calcStealthAddressStructure as oe, createCallDataHash as se, getSlippageValues as ce, getUtxoCircuitH0Coords as l, getUtxoCircuitInRandomization as le, getZkProofVerifierName as ue } from "./common.snarkjs.mjs";
|
|
11
|
+
import { computeSignedMessageHashEvm as de } from "./signedMessageHash.mjs";
|
|
12
|
+
import { generateCircomData as fe } 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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
W.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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 = {
|
|
18
|
+
var m = async (m, h, g, _, v, y, b, pe, x, S = n, C = e.localhost, w = h.map(() => !1), T = void 0, E, D) => {
|
|
19
|
+
let O = ue(h, g), k = c(h, g), A = h.map((e) => e[0].erc20TokenAddress), j = ie(g), M = ee, N = _.getShieldedPrivateKey(), { pubSpendingBJJPoint: P } = _.getSpendingKeyPair(), F = oe(i.findCorrectRandomization(r(31), N), N, _.getSpendingKeyPair().pubSpendingBJJPoint), { inCommitmentSiblings: I, inCommitmentSiblingSides: L, rootHashHinkal: R, inNullifiers: z } = await f(C, m, h.map((e) => e.map((e) => e.getConstructableParams()))), B = re(g), V = r(31), H = te(V), U = BigInt(g.length > 0 ? g[0][0].timeStamp : a()), W = {
|
|
20
|
+
rootHashHinkal: R,
|
|
21
|
+
spendingPublicKey: P,
|
|
22
|
+
nullifyingPrivateKey: N,
|
|
23
|
+
erc20TokenAddresses: A,
|
|
24
|
+
amountChanges: k,
|
|
25
|
+
inAmounts: h.map((e) => e.map((e) => e.amount.toString())),
|
|
26
|
+
inRandomizations: h.map((e) => e.map((e) => le(e))),
|
|
27
|
+
inH0Ax: h.map((e) => e.map((e) => l(e)[0].toString())),
|
|
28
|
+
inH0Ay: h.map((e) => e.map((e) => l(e)[1].toString())),
|
|
29
|
+
isNewStyle: h.map((e) => e.map((e) => !!e.isNewStyle)),
|
|
30
|
+
inTimeStamps: h.map((e) => e.map((e) => e.timeStamp)),
|
|
31
|
+
inNullifiers: z,
|
|
32
|
+
inCommitmentSiblings: I,
|
|
33
|
+
inCommitmentSiblingSides: L,
|
|
34
|
+
outAmounts: g.map((e) => e.map((e) => e.amount.toString())),
|
|
35
|
+
outTimeStamp: U,
|
|
36
|
+
outPublicKeys: g.map((e) => e.map((e) => e.getStealthAddress())),
|
|
37
|
+
outCommitments: B,
|
|
38
|
+
calldataHash: 0n,
|
|
39
|
+
messageSeed: V,
|
|
40
|
+
H0Ax: ne(F.extraRandomization),
|
|
41
|
+
H0Ay: F.H0
|
|
42
|
+
}, G = ae(O, W.erc20TokenAddresses, W.amountChanges, W.inNullifiers, W.outCommitments), K = c(h, g, !0), q = ce(K);
|
|
43
|
+
s.log({ publicSignalCount: G });
|
|
44
|
+
let J = Array.isArray(b) ? b : [b], me = t(C), he = D ? u.getSignerAddressFromPrivateKey(me, D) : void 0, Y = v === o.Emporium ? await p(C, y ?? n, D, J, H, he) : await p(C, n, void 0, v === 0n ? [] : J, H, n);
|
|
45
|
+
W.calldataHash = se(G, S, y, v, Y, j, T, q, w, x, M, E);
|
|
46
|
+
let X = de({
|
|
47
|
+
rootHashHinkal: R,
|
|
48
|
+
erc20TokenAddresses: A,
|
|
49
|
+
amountChanges: k,
|
|
50
|
+
outTimeStamp: U,
|
|
51
|
+
inNullifiers: z,
|
|
52
|
+
outCommitments: B,
|
|
53
|
+
calldataHash: W.calldataHash,
|
|
54
|
+
message: H,
|
|
55
|
+
outH1Ay: F.H1,
|
|
56
|
+
H0Ax: W.H0Ax,
|
|
57
|
+
H0Ay: F.H0
|
|
58
|
+
}), { R8: Z, S: ge } = _.signEddsa(X);
|
|
59
|
+
W.eddsaSignature = [
|
|
60
|
+
Z[0],
|
|
61
|
+
Z[1],
|
|
62
|
+
ge
|
|
63
|
+
], W.signedMessageHash = X;
|
|
64
|
+
let Q = O.startsWith("mainEVMCircuitMin0"), $ = {
|
|
65
|
+
outTimeStamp: U,
|
|
66
|
+
calldataHash: W.calldataHash,
|
|
67
|
+
messageSeed: V
|
|
68
|
+
}, { zkCallData: _e, commitmentValidationData: ve } = await d(C, _, A, h, O, Q ? $ : W, pe);
|
|
69
|
+
return {
|
|
70
|
+
zkCallData: _e,
|
|
71
|
+
circomData: fe(B, z, R, K, A, g, j, G, v, y, Y, S, W.calldataHash, F, w, T, Q ? Number(U) : void 0, q, x, M, E),
|
|
72
|
+
dimData: {
|
|
84
73
|
tokenNumber: h.length,
|
|
85
74
|
nullifierAmount: h.length > 0 ? h[0].length : 0,
|
|
86
75
|
outputAmount: g.length > 0 ? g[0].length : 0
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
dimData: be,
|
|
92
|
-
encryptedOutputs: A,
|
|
93
|
-
commitmentValidationData: ve
|
|
94
|
-
};
|
|
95
|
-
} catch (e) {
|
|
96
|
-
throw console.log("[constructZkProof] error", e), e;
|
|
97
|
-
}
|
|
76
|
+
},
|
|
77
|
+
encryptedOutputs: j,
|
|
78
|
+
commitmentValidationData: ve
|
|
79
|
+
};
|
|
98
80
|
};
|
|
99
81
|
//#endregion
|
|
100
82
|
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)=>{
|
|
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.buildCommitmentValidationDataFromProof(l,f[1])}};exports.generateMainAndCommitmentZkProof=n;
|
|
@@ -3,23 +3,14 @@ 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
|
-
|
|
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
|
-
}
|
|
6
|
+
let u = await e(r, i, a, o), d = [s], f = [c];
|
|
7
|
+
u && (d.push(u.verifierName), f.push(u.commitmentInput));
|
|
8
|
+
let p = await n(r, d, f, l), { zkCallData: m, publicSignals: h } = p[0];
|
|
9
|
+
return {
|
|
10
|
+
zkCallData: m,
|
|
11
|
+
publicSignals: h,
|
|
12
|
+
commitmentValidationData: t(u, p[1])
|
|
13
|
+
};
|
|
23
14
|
};
|
|
24
15
|
//#endregion
|
|
25
16
|
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)=>{
|
|
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();return t?(await t(s,o.map(e=>n.getWASMFile(e,a)),o.map(e=>n.getZKeyFile(e,a)))).map(({zkCallData:e,publicSignals:t})=>({zkCallData:e,publicSignals:t})):await r.generateZkProofEnclave(a,o,s)}catch(e){t.Logger.error(`enclave proof error`,e)}return Promise.all(o.map((e,t)=>i.generateZkProofSelf(a,e,s[t])))};exports.generateZkProof=a;
|
|
@@ -5,34 +5,16 @@ 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
|
-
|
|
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;
|
|
8
|
+
if (l) try {
|
|
9
|
+
let t = e();
|
|
10
|
+
return t ? (await t(c, s.map((e) => n(e, o)), s.map((e) => r(e, o)))).map(({ zkCallData: e, publicSignals: t }) => ({
|
|
11
|
+
zkCallData: e,
|
|
12
|
+
publicSignals: t
|
|
13
|
+
})) : await i(o, s, c);
|
|
33
14
|
} catch (e) {
|
|
34
|
-
|
|
15
|
+
t.error("enclave proof error", e);
|
|
35
16
|
}
|
|
17
|
+
return Promise.all(s.map((e, t) => a(o, e, c[t])));
|
|
36
18
|
};
|
|
37
19
|
//#endregion
|
|
38
20
|
export { o as generateZkProof };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../constants/index.cjs`);
|
|
1
|
+
const e=require(`../../types/chains.types.cjs`);require(`../../types/index.cjs`),require(`../../constants/index.cjs`),e.EthereumNetworkType.Mainnet,e.EthereumNetworkType.Testnet,e.EthereumNetworkType.Local;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { EthereumNetwork, EthereumNetworkType } from '../../types';
|
|
2
2
|
export declare const getNetworkObject: (chainId: number) => EthereumNetwork;
|
|
3
3
|
export declare const getNetworkType: (network: EthereumNetwork) => EthereumNetworkType;
|
|
4
|
+
export declare const compareNetworksByTypeAndPriority: (network1: EthereumNetwork, network2: EthereumNetwork) => number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=e=>new Promise(t=>{setTimeout(t,e)}),t=async(e,t=1e4)=>
|
|
1
|
+
var e=e=>new Promise(t=>{setTimeout(t,e)}),t=async(e,t=1e4)=>Promise.race([e,new Promise((n,r)=>{let i=setTimeout(()=>{r(Error(`Timeout after ${t}ms`))},t);e.finally(()=>clearTimeout(i))})]),n=async(t,n={})=>{let r=n.intervalMs??5e3,i=n.timeoutMs??6e4,a=Math.floor(i/r)+1;for(let n=0;n<a;n+=1){try{let e=await t();if(e!=null)return e}catch{}n<a-1&&await e(r)}};exports.pollForValue=n,exports.wait=e,exports.withTimeout=t;
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
//#region libs/shared/common/src/functions/utils/process.utils.ts
|
|
2
2
|
var e = (e) => new Promise((t) => {
|
|
3
3
|
setTimeout(t, e);
|
|
4
|
-
}), t = async (e, t = 1e4) => {
|
|
5
|
-
let
|
|
6
|
-
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} finally {
|
|
11
|
-
clearTimeout(n);
|
|
12
|
-
}
|
|
13
|
-
}, n = async (t, n = {}) => {
|
|
4
|
+
}), t = async (e, t = 1e4) => Promise.race([e, new Promise((n, r) => {
|
|
5
|
+
let i = setTimeout(() => {
|
|
6
|
+
r(/* @__PURE__ */ Error(`Timeout after ${t}ms`));
|
|
7
|
+
}, t);
|
|
8
|
+
e.finally(() => clearTimeout(i));
|
|
9
|
+
})]), n = async (t, n = {}) => {
|
|
14
10
|
let r = n.intervalMs ?? 5e3, i = n.timeoutMs ?? 6e4, a = Math.floor(i / r) + 1;
|
|
15
11
|
for (let n = 0; n < a; n += 1) {
|
|
16
12
|
try {
|
|
@@ -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)=>{
|
|
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],A=l.getProviderAdapter(u),j=await A.supportsBatchCall?.(u);if(!y&&O&&j&&A.sendBatchCallsTransaction){let e=o.buildApproveAndTransactCalls(x.map(e=>e.erc20TokenAddress),b,r.getContractAddress(w),T,p,h,m,k);return await A.sendBatchCallsTransaction(u,e)}if(!y&&(await a.approveTokensToHinkal(l,u,w,x,b),O)){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)try{N=Number(await T[E].estimateGas(...P))}catch(e){console.log(`hinkalDeposit: 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{L=y?await T[E].populateTransaction(...P):await T[E](...P)}catch(e){if(!e?.transactionHash)throw e;let t=await i.recoverTransactionFromError(F.provider,e.transactionHash);if(!t)throw e;L=t}return L};exports.transactCallDirect=l;
|
|
@@ -9,70 +9,52 @@ 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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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;
|
|
12
|
+
let b = Array.isArray(d) ? d : [d], x = Array.isArray(f) ? f : [f];
|
|
13
|
+
if (b.length !== x.length) throw Error("token and amount length mismatch");
|
|
14
|
+
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], A = l.getProviderAdapter(u), j = await A.supportsBatchCall?.(u);
|
|
15
|
+
if (!y && O && j && A.sendBatchCallsTransaction) {
|
|
16
|
+
let e = o(x.map((e) => e.erc20TokenAddress), b, r(w), T, p, h, m, k);
|
|
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
|
|
71
38
|
}
|
|
72
|
-
|
|
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;
|
|
49
|
+
try {
|
|
50
|
+
L = y ? await T[E].populateTransaction(...P) : await T[E](...P);
|
|
73
51
|
} catch (e) {
|
|
74
|
-
|
|
52
|
+
if (!e?.transactionHash) throw e;
|
|
53
|
+
let t = await i(F.provider, e.transactionHash);
|
|
54
|
+
if (!t) throw e;
|
|
55
|
+
L = t;
|
|
75
56
|
}
|
|
57
|
+
return L;
|
|
76
58
|
};
|
|
77
59
|
//#endregion
|
|
78
60
|
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)=>{
|
|
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;
|