@hinkal/common 0.2.33 → 0.2.35
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/API/callNearIntentsAPI.cjs +1 -0
- package/API/callNearIntentsAPI.d.ts +3 -0
- package/API/callNearIntentsAPI.mjs +8 -0
- package/API/enclaveSignatureCalls.cjs +1 -1
- package/API/enclaveSignatureCalls.d.ts +1 -1
- package/API/enclaveSignatureCalls.mjs +1 -1
- package/API/index.cjs +1 -1
- package/API/index.d.ts +1 -0
- package/API/index.mjs +1 -0
- package/constants/bridging.constants.cjs +1 -1
- package/constants/bridging.constants.d.ts +15 -1
- package/constants/bridging.constants.mjs +25 -5
- package/constants/chains.constants.cjs +1 -1
- package/constants/chains.constants.d.ts +12 -1
- package/constants/chains.constants.mjs +94 -26
- package/constants/index.cjs +1 -1
- package/constants/index.mjs +1 -0
- package/constants/protocol.constants.cjs +1 -1
- package/constants/protocol.constants.d.ts +3 -0
- package/constants/protocol.constants.mjs +2 -2
- package/constants/server.constants.cjs +1 -1
- package/constants/server.constants.d.ts +2 -0
- package/constants/server.constants.mjs +2 -0
- package/constants/token-data/ERC20Registry.cjs +1 -1
- package/constants/token-data/ERC20Registry.mjs +49 -14
- package/constants/token-data/avalancheRegistry.json.cjs +1 -0
- package/constants/token-data/avalancheRegistry.json.mjs +44 -0
- package/constants/token-data/bnbMainnetRegistry.json.cjs +1 -0
- package/constants/token-data/bnbMainnetRegistry.json.mjs +44 -0
- package/constants/token-data/cronosRegistry.json.cjs +1 -0
- package/constants/token-data/cronosRegistry.json.mjs +44 -0
- package/constants/token-data/hyperEvmRegistry.json.cjs +1 -0
- package/constants/token-data/hyperEvmRegistry.json.mjs +36 -0
- package/constants/token-data/index.cjs +1 -1
- package/constants/token-data/index.d.ts +58 -1
- package/constants/token-data/index.mjs +10 -2
- package/constants/token-data/inkRegistry.json.cjs +1 -0
- package/constants/token-data/inkRegistry.json.mjs +28 -0
- package/constants/token-data/monadRegistry.json.cjs +1 -0
- package/constants/token-data/monadRegistry.json.mjs +36 -0
- package/constants/token-data/plasmaRegistry.json.cjs +1 -0
- package/constants/token-data/plasmaRegistry.json.mjs +28 -0
- package/constants/token-data/popularNonRebasingTokens.cjs +1 -0
- package/constants/token-data/popularNonRebasingTokens.d.ts +2 -0
- package/constants/token-data/popularNonRebasingTokens.mjs +11 -0
- package/constants/tokens.constants.cjs +1 -1
- package/constants/tokens.constants.mjs +8 -1
- package/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.d.ts +8 -2
- package/data-structures/Hinkal/Hinkal.mjs +123 -101
- package/data-structures/Hinkal/IHinkal.d.ts +8 -2
- package/data-structures/Hinkal/handleAutoDepositBack.cjs +1 -1
- package/data-structures/Hinkal/handleAutoDepositBack.mjs +15 -15
- package/data-structures/Hinkal/hinkalClaimUtxo.cjs +1 -1
- package/data-structures/Hinkal/hinkalClaimUtxo.mjs +33 -35
- package/data-structures/Hinkal/hinkalDepositAndBridge.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepositAndBridge.mjs +43 -49
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.mjs +38 -40
- package/data-structures/Hinkal/hinkalNearDepositAndBridge.cjs +1 -0
- package/data-structures/Hinkal/hinkalNearDepositAndBridge.d.ts +6 -0
- package/data-structures/Hinkal/hinkalNearDepositAndBridge.mjs +43 -0
- package/data-structures/Hinkal/hinkalPrivateWallet.cjs +1 -1
- package/data-structures/Hinkal/hinkalPrivateWallet.mjs +21 -26
- package/data-structures/Hinkal/hinkalSolanaClaimUtxo.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaClaimUtxo.mjs +62 -64
- package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.d.ts +2 -2
- package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.mjs +36 -36
- package/data-structures/Hinkal/hinkalSolanaProxySend.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaProxySend.mjs +7 -7
- package/data-structures/Hinkal/hinkalSolanaProxyShield.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaProxyShield.mjs +9 -9
- package/data-structures/Hinkal/hinkalSolanaProxySwap.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaProxySwap.mjs +8 -8
- package/data-structures/Hinkal/hinkalSolanaSwap.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaSwap.mjs +50 -51
- package/data-structures/Hinkal/hinkalSolanaTransfer.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaTransfer.mjs +45 -46
- package/data-structures/Hinkal/hinkalSolanaWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaWithdraw.mjs +38 -39
- package/data-structures/Hinkal/hinkalSwap.cjs +1 -1
- package/data-structures/Hinkal/hinkalSwap.mjs +18 -19
- package/data-structures/Hinkal/hinkalTransfer.cjs +1 -1
- package/data-structures/Hinkal/hinkalTransfer.mjs +21 -22
- package/data-structures/Hinkal/hinkalWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalWithdraw.mjs +24 -25
- package/data-structures/Hinkal/hinkalWithdrawStuckUtxos.cjs +1 -1
- package/data-structures/Hinkal/hinkalWithdrawStuckUtxos.mjs +39 -41
- package/data-structures/Hinkal/index.cjs +1 -1
- package/data-structures/Hinkal/index.d.ts +1 -0
- package/data-structures/Hinkal/index.mjs +1 -0
- package/data-structures/crypto-keys/keys.cjs +1 -1
- package/data-structures/crypto-keys/keys.d.ts +18 -0
- package/data-structures/crypto-keys/keys.mjs +10 -0
- package/data-structures/index.cjs +1 -1
- package/data-structures/index.mjs +1 -0
- package/error-handling/error-codes.constants.cjs +1 -1
- package/error-handling/error-codes.constants.d.ts +4 -0
- package/error-handling/error-codes.constants.mjs +4 -0
- package/error-handling/get-error.message.cjs +1 -1
- package/error-handling/get-error.message.mjs +2 -1
- package/functions/index.cjs +1 -1
- package/functions/index.mjs +8 -6
- package/functions/pre-transaction/buildCommitmentValidationData.cjs +1 -1
- package/functions/pre-transaction/buildCommitmentValidationData.d.ts +12 -2
- package/functions/pre-transaction/buildCommitmentValidationData.mjs +43 -36
- package/functions/pre-transaction/sendV0Transaction.cjs +2 -1
- package/functions/pre-transaction/sendV0Transaction.d.ts +2 -2
- package/functions/pre-transaction/sendV0Transaction.mjs +65 -60
- package/functions/snarkjs/constructGeneralZkProof.cjs +1 -1
- package/functions/snarkjs/constructGeneralZkProof.d.ts +1 -0
- package/functions/snarkjs/constructGeneralZkProof.mjs +6 -5
- package/functions/snarkjs/constructSolanaZkProof.cjs +1 -1
- package/functions/snarkjs/constructSolanaZkProof.d.ts +1 -0
- package/functions/snarkjs/constructSolanaZkProof.mjs +35 -34
- package/functions/snarkjs/generateMainAndCommitmentZkProof.cjs +1 -0
- package/functions/snarkjs/generateMainAndCommitmentZkProof.d.ts +11 -0
- package/functions/snarkjs/generateMainAndCommitmentZkProof.mjs +16 -0
- package/functions/snarkjs/generateZkProof.cjs +1 -1
- package/functions/snarkjs/generateZkProof.d.ts +3 -3
- package/functions/snarkjs/generateZkProof.mjs +5 -9
- package/functions/snarkjs/generateZkProofEnclave.cjs +1 -1
- package/functions/snarkjs/generateZkProofEnclave.d.ts +2 -2
- package/functions/snarkjs/generateZkProofEnclave.mjs +8 -8
- package/functions/snarkjs/generateZkProofSelf.cjs +1 -1
- package/functions/snarkjs/generateZkProofSelf.mjs +5 -5
- package/functions/snarkjs/index.cjs +1 -1
- package/functions/snarkjs/index.d.ts +1 -0
- package/functions/snarkjs/index.mjs +1 -0
- package/functions/snarkjs/verifyCommitmentValidationData.cjs +1 -1
- package/functions/snarkjs/verifyCommitmentValidationData.mjs +5 -5
- package/functions/utils/customEnclaveFunctionsRegister.d.ts +3 -3
- package/functions/utils/enclave-signature-storage.cjs +1 -1
- package/functions/utils/enclave-signature-storage.d.ts +1 -1
- package/functions/utils/enclave-signature-storage.mjs +1 -1
- package/functions/utils/index.cjs +1 -1
- package/functions/utils/index.d.ts +1 -0
- package/functions/utils/index.mjs +6 -5
- package/functions/utils/nearIntents.utils.cjs +1 -0
- package/functions/utils/nearIntents.utils.d.ts +11 -0
- package/functions/utils/nearIntents.utils.mjs +36 -0
- package/functions/utils/time.utils.cjs +1 -1
- package/functions/utils/time.utils.d.ts +1 -0
- package/functions/utils/time.utils.mjs +2 -2
- package/functions/web3/oneInchAPI.cjs +1 -1
- package/functions/web3/oneInchAPI.mjs +1 -1
- package/index.cjs +1 -1
- package/index.mjs +320 -315
- package/package.json +1 -1
- package/types/index.d.ts +1 -0
- package/types/near-intents.types.d.ts +60 -0
- package/types/solana.types.d.ts +1 -0
- package/webworker/{logError-fCJ4HXQz.js → logError-DoUkEIFE.js} +14 -14
- package/webworker/package.json +1 -1
- package/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.cjs +1 -1
- package/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.mjs +1 -1
- package/webworker/snarkjsWorkerNode.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.mjs +1 -1
- package/webworker/utxoWorkerNode.cjs +1 -1
- package/webworker/viteWorkerURL.constant.cjs +3 -3
- package/webworker/viteWorkerURL.constant.mjs +3 -3
- package/webworker/{workerProxy-BNBqYien.js → workerProxy-DQJE57Ye.js} +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.cjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.mjs +1 -1
- package/webworker/zkProofWorkerNode.cjs +1 -1
|
@@ -11,13 +11,13 @@ import { API as l } from "../../API/API.mjs";
|
|
|
11
11
|
import { gasErrorCodes as u, transactionErrorCodes as d } from "../../error-handling/error-codes.constants.mjs";
|
|
12
12
|
import { getAmountInToken as f } from "../../functions/web3/etherFunctions.mjs";
|
|
13
13
|
import { getERC20Token as p, getERC20TokenBySymbol as m } from "../../functions/utils/erc20tokenFunctions.mjs";
|
|
14
|
-
import { waitLittle as
|
|
15
|
-
import { ErrorWithRelayerTransaction as
|
|
16
|
-
import { Logger as
|
|
17
|
-
import {
|
|
18
|
-
import { getErrorMessageFromTransactionRequest as v } from "../../error-handling/get-error.message.mjs";
|
|
14
|
+
import { waitLittle as ee } from "../../functions/utils/time.utils.mjs";
|
|
15
|
+
import { ErrorWithRelayerTransaction as h } from "../../error-handling/customErrors/ErrorWithTx.mjs";
|
|
16
|
+
import { Logger as g } from "../../error-handling/logger.mjs";
|
|
17
|
+
import { getErrorMessageFromTransactionRequest as _ } from "../../error-handling/get-error.message.mjs";
|
|
19
18
|
import "../../error-handling/index.mjs";
|
|
20
|
-
import { modifyVolatileTokenAmountChanges as
|
|
19
|
+
import { modifyVolatileTokenAmountChanges as v } from "../../functions/pre-transaction/getVolatileTransferAmount.mjs";
|
|
20
|
+
import { createJsonRpcProvider as y } from "../../functions/utils/create-provider.mjs";
|
|
21
21
|
import { getFeeStructure as b } from "../../functions/pre-transaction/getFeeStructure.mjs";
|
|
22
22
|
import { convertEmporiumOpToCallInfo as x } from "../../functions/utils/convertEmporiumOpToCallInfo.mjs";
|
|
23
23
|
import { postToOffscreen as S } from "../../functions/utils/postToOffscreen.mjs";
|
|
@@ -35,16 +35,16 @@ var te = 3 * 1e3, ne = 13 * 1e3, A = async (A, j, M, N, P, F, I, L) => {
|
|
|
35
35
|
if (!M || I.length === 0) return;
|
|
36
36
|
let R;
|
|
37
37
|
try {
|
|
38
|
-
let o =
|
|
39
|
-
await
|
|
40
|
-
let
|
|
41
|
-
if (!
|
|
38
|
+
let o = y(j);
|
|
39
|
+
await ee(j === t.ethMainnet ? ne : te);
|
|
40
|
+
let h = await T(I, P, M, o);
|
|
41
|
+
if (!h.length) {
|
|
42
42
|
S(s.AutoShieldTxStatus, { message: d.AUTO_SHIELD_SKIPPED });
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
|
-
let
|
|
45
|
+
let g = C(j).map((e) => m(e, j)).filter((e) => e !== void 0), { prices: _ } = await l.getTokenPrices(j, g.map((e) => e.erc20TokenAddress)), z = new Map(_.map((e, t) => [g[t].erc20TokenAddress.toLowerCase(), e])), B = h.map(({ token: e }) => e), V = h.map(({ balance: e }) => e), H = B.map(({ erc20TokenAddress: e }) => e), U = w(A, j, H, await v(j, B, V, M)), W = await b(j, P, H, e.Emporium, U.map((e) => x(e, M, j))), { flatFee: G } = W ?? {}, K = p(W.feeToken, j);
|
|
46
46
|
if (!K) return;
|
|
47
|
-
let q = f(K, G), J = (z.get(K.erc20TokenAddress.toLowerCase()) ?? 0) * Number(q), Y = await D(P, J, j, B, U, await E(
|
|
47
|
+
let q = f(K, G), J = (z.get(K.erc20TokenAddress.toLowerCase()) ?? 0) * Number(q), Y = await D(P, J, j, B, U, await E(g, j, A, M, o, z), W, H, M);
|
|
48
48
|
if (!Y) return;
|
|
49
49
|
let { feeToken: X, feeStructure: Z } = Y ?? {};
|
|
50
50
|
if (F && Number(F) < J) {
|
|
@@ -76,7 +76,7 @@ var te = 3 * 1e3, ne = 13 * 1e3, A = async (A, j, M, N, P, F, I, L) => {
|
|
|
76
76
|
});
|
|
77
77
|
} catch (e) {
|
|
78
78
|
let t;
|
|
79
|
-
e instanceof
|
|
79
|
+
e instanceof h && (t = e.txHash);
|
|
80
80
|
let n = {
|
|
81
81
|
error: e,
|
|
82
82
|
id: 0,
|
|
@@ -85,8 +85,8 @@ var te = 3 * 1e3, ne = 13 * 1e3, A = async (A, j, M, N, P, F, I, L) => {
|
|
|
85
85
|
};
|
|
86
86
|
R && await k.updatePendingTransactions(n, R), S(s.AutoShieldTxStatus, {
|
|
87
87
|
status: r.Failed,
|
|
88
|
-
error:
|
|
89
|
-
}),
|
|
88
|
+
error: _(e, o.ReceiveFromShieldedAccount)
|
|
89
|
+
}), g.error("Error in auto deposit back:", e);
|
|
90
90
|
}
|
|
91
91
|
};
|
|
92
92
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../types/external-action.types.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../constants/protocol.constants.cjs`),r=require(`../../functions/utils/caseInsensitive.utils.cjs`),i=require(`../../error-handling/error-codes.constants.cjs`),a=require(`../crypto-keys/keys.cjs`),o=require(`../../functions/utils/time.utils.cjs`),s=require(`../utxo/Utxo.cjs`),c=require(`../../functions/utils/tron.utils.cjs`),l=require(`../../functions/utils/token-check.utils.cjs`),u=require(`../../functions/pre-transaction/outputUtxoProcessing.cjs`),d=require(`../../functions/pre-transaction/getFeeStructure.cjs`),f=require(`../../functions/
|
|
1
|
+
const e=require(`../../types/external-action.types.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../constants/protocol.constants.cjs`),r=require(`../../functions/utils/caseInsensitive.utils.cjs`),i=require(`../../error-handling/error-codes.constants.cjs`),a=require(`../crypto-keys/keys.cjs`),o=require(`../../functions/utils/time.utils.cjs`),s=require(`../utxo/Utxo.cjs`),c=require(`../../functions/utils/tron.utils.cjs`),l=require(`../../functions/utils/token-check.utils.cjs`),u=require(`../../functions/pre-transaction/outputUtxoProcessing.cjs`),d=require(`../../functions/pre-transaction/getFeeStructure.cjs`),f=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),p=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`);var m=async(m,h,g,_,v)=>{let y=l.validateAndGetChainId([h]),b=t.isTronLike(y),x=h.erc20TokenAddress,S=c.addressToHexFormat(await m.getEthereumAddressByChain(y));if(!r.caseInsensitiveEqual(x,g.erc20TokenAddress))throw Error(`Off-chain UTXO token mismatch`);let C=v?new a.UserKeys(v):new a.UserKeys(g.nullifyingKey,g.nullifyingKey);if(!g.nullifyingKey&&!v)throw Error(`Claimable UTXO nullifyingKey is missing`);let w=C.getShieldedPrivateKey();if(g.nullifyingKey&&g.nullifyingKey!==w)throw Error(`Claimable UTXO key mismatch`);let T=m.getRecipientInfo(),E=s.Utxo.createFrom(g,{nullifyingKey:w}),D=new s.Utxo({amount:0n,erc20TokenAddress:E.erc20TokenAddress,mintAddress:E.mintAddress,nullifyingKey:w,...E.isNewStyle?{spendingPublicKey:C.getSpendingKeyPair().pubSpendingBJJPoint,isNewStyle:!0}:{isNewStyle:!1}}),O=_??await d.getFeeStructure(y,x,[x],e.ExternalActionId.Transact);if(!r.caseInsensitiveEqual(O.feeToken,x))throw Error(`Claim fee token mismatch: fee must be paid from claimed UTXO token`);let k=O.variableRate>0n?O.variableRate:n.HINKAL_PRIVATE_SEND_VARIABLE_RATE;if(E.amount<=O.flatFee)throw Error(i.transactionErrorCodes.INSUFFICIENT_FUNDS_TO_TRANSACT);let A=E.amount-O.flatFee,j=A*k/10000n,M=A-j;if(M<=0n)throw Error(i.transactionErrorCodes.RECIPIENT_AMOUNT_INVALID);let N={feeToken:O.feeToken,flatFee:O.flatFee+j,variableRate:0n},P=[-E.amount],F=await m.getRandomRelay(y,!0);if(!F)throw Error(i.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let I={externalActionId:0n,externalAddress:F??S,externalActionMetadata:`0x00`},L=[[E,D]],R=[],z=o.getCurrentTimeInSeconds().toString(),{outputUtxos:B}=u.outputUtxoProcessing(C,L[0],P[0],z,!0,T,M);R.push(B);let{zkCallData:V,circomData:H,dimData:U,commitmentValidationData:W}=await f.constructZkProof(m.merkleTreeHinkalByChain[y],L,R,C,I.externalActionId,I.externalAddress,I.externalActionMetadata,m.generateProofRemotely,N,F,y);return p.transactCallRelayer(y,V,U,H,W,void 0,void 0,void 0,await c.reorderZkCallData(b,V,U,H))};exports.hinkalClaimUtxo=m;
|
|
@@ -10,47 +10,45 @@ import { addressToHexFormat as c, reorderZkCallData as l } from "../../functions
|
|
|
10
10
|
import { validateAndGetChainId as u } from "../../functions/utils/token-check.utils.mjs";
|
|
11
11
|
import { outputUtxoProcessing as d } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
|
|
12
12
|
import { getFeeStructure as f } from "../../functions/pre-transaction/getFeeStructure.mjs";
|
|
13
|
-
import {
|
|
14
|
-
import "../../functions/
|
|
15
|
-
import { constructZkProof as m } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
|
|
16
|
-
import { transactCallRelayer as h } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
|
|
13
|
+
import { constructZkProof as p } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
|
|
14
|
+
import { transactCallRelayer as m } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
|
|
17
15
|
//#region libs/shared/common/src/data-structures/Hinkal/hinkalClaimUtxo.ts
|
|
18
|
-
var
|
|
19
|
-
let
|
|
20
|
-
if (!r(
|
|
21
|
-
let
|
|
22
|
-
if (!
|
|
23
|
-
let
|
|
24
|
-
if (
|
|
25
|
-
let
|
|
16
|
+
var h = async (h, g, _, v, y) => {
|
|
17
|
+
let b = u([g]), x = t(b), S = g.erc20TokenAddress, C = c(await h.getEthereumAddressByChain(b));
|
|
18
|
+
if (!r(S, _.erc20TokenAddress)) throw Error("Off-chain UTXO token mismatch");
|
|
19
|
+
let w = y ? new a(y) : new a(_.nullifyingKey, _.nullifyingKey);
|
|
20
|
+
if (!_.nullifyingKey && !y) throw Error("Claimable UTXO nullifyingKey is missing");
|
|
21
|
+
let T = w.getShieldedPrivateKey();
|
|
22
|
+
if (_.nullifyingKey && _.nullifyingKey !== T) throw Error("Claimable UTXO key mismatch");
|
|
23
|
+
let E = h.getRecipientInfo(), D = s.createFrom(_, { nullifyingKey: T }), O = new s({
|
|
26
24
|
amount: 0n,
|
|
27
|
-
erc20TokenAddress:
|
|
28
|
-
mintAddress:
|
|
29
|
-
nullifyingKey:
|
|
30
|
-
...
|
|
31
|
-
spendingPublicKey:
|
|
25
|
+
erc20TokenAddress: D.erc20TokenAddress,
|
|
26
|
+
mintAddress: D.mintAddress,
|
|
27
|
+
nullifyingKey: T,
|
|
28
|
+
...D.isNewStyle ? {
|
|
29
|
+
spendingPublicKey: w.getSpendingKeyPair().pubSpendingBJJPoint,
|
|
32
30
|
isNewStyle: !0
|
|
33
31
|
} : { isNewStyle: !1 }
|
|
34
|
-
}),
|
|
35
|
-
if (!r(
|
|
36
|
-
let
|
|
37
|
-
if (
|
|
38
|
-
let
|
|
39
|
-
if (
|
|
40
|
-
let
|
|
41
|
-
feeToken:
|
|
42
|
-
flatFee:
|
|
32
|
+
}), k = v ?? await f(b, S, [S], e.Transact);
|
|
33
|
+
if (!r(k.feeToken, S)) throw Error("Claim fee token mismatch: fee must be paid from claimed UTXO token");
|
|
34
|
+
let A = k.variableRate > 0n ? k.variableRate : n;
|
|
35
|
+
if (D.amount <= k.flatFee) throw Error(i.INSUFFICIENT_FUNDS_TO_TRANSACT);
|
|
36
|
+
let j = D.amount - k.flatFee, M = j * A / 10000n, N = j - M;
|
|
37
|
+
if (N <= 0n) throw Error(i.RECIPIENT_AMOUNT_INVALID);
|
|
38
|
+
let P = {
|
|
39
|
+
feeToken: k.feeToken,
|
|
40
|
+
flatFee: k.flatFee + M,
|
|
43
41
|
variableRate: 0n
|
|
44
|
-
},
|
|
45
|
-
if (!
|
|
46
|
-
let
|
|
42
|
+
}, F = [-D.amount], I = await h.getRandomRelay(b, !0);
|
|
43
|
+
if (!I) throw Error(i.RELAYER_NOT_AVAILABLE);
|
|
44
|
+
let L = {
|
|
47
45
|
externalActionId: 0n,
|
|
48
|
-
externalAddress:
|
|
46
|
+
externalAddress: I ?? C,
|
|
49
47
|
externalActionMetadata: "0x00"
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
let
|
|
53
|
-
return
|
|
48
|
+
}, R = [[D, O]], z = [], B = o().toString(), { outputUtxos: V } = d(w, R[0], F[0], B, !0, E, N);
|
|
49
|
+
z.push(V);
|
|
50
|
+
let { zkCallData: H, circomData: U, dimData: W, commitmentValidationData: G } = await p(h.merkleTreeHinkalByChain[b], R, z, w, L.externalActionId, L.externalAddress, L.externalActionMetadata, h.generateProofRemotely, P, I, b);
|
|
51
|
+
return m(b, H, W, U, G, void 0, void 0, void 0, await l(x, H, W, U));
|
|
54
52
|
};
|
|
55
53
|
//#endregion
|
|
56
|
-
export {
|
|
54
|
+
export { h as hinkalClaimUtxo };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../types/external-action.types.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../constants/protocol.constants.cjs`),r=require(`../../types/scheduled-transactions.types.cjs`);require(`../../types/index.cjs`);const i=require(`../../functions/utils/caseInsensitive.utils.cjs`),a=require(`../../functions/utils/addresses.cjs`),o=require(`../../API/API.cjs`),s=require(`../../constants/addresses.constants.cjs`),c=require(`../../error-handling/error-codes.constants.cjs`),l=require(`../../functions/utils/erc20tokenFunctions.cjs`),u=require(`../../functions/utils/time.utils.cjs`),d=require(`../utxo/Utxo.cjs`),f=require(`../../functions/utils/token-check.utils.cjs`),p=require(`../../functions/pre-transaction/constructAdminData.cjs`),m=require(`../../functions/pre-transaction/getFeeStructure.cjs`),h=require(`../../functions/pre-transaction/waitForDepositedUtxosInMerkleTree.cjs`),g=require(`../../functions/
|
|
1
|
+
const e=require(`../../types/external-action.types.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../constants/protocol.constants.cjs`),r=require(`../../types/scheduled-transactions.types.cjs`);require(`../../types/index.cjs`);const i=require(`../../functions/utils/caseInsensitive.utils.cjs`),a=require(`../../functions/utils/addresses.cjs`),o=require(`../../API/API.cjs`),s=require(`../../constants/addresses.constants.cjs`),c=require(`../../error-handling/error-codes.constants.cjs`),l=require(`../../functions/utils/erc20tokenFunctions.cjs`),u=require(`../../functions/utils/time.utils.cjs`),d=require(`../utxo/Utxo.cjs`),f=require(`../../functions/utils/token-check.utils.cjs`),p=require(`../../functions/pre-transaction/constructAdminData.cjs`),m=require(`../../functions/pre-transaction/getFeeStructure.cjs`),h=require(`../../functions/pre-transaction/waitForDepositedUtxosInMerkleTree.cjs`),g=require(`../../functions/utils/convertEmporiumOpToCallInfo.cjs`),_=require(`../../functions/utils/fees.utils.cjs`);require(`../../functions/utils/index.cjs`);const v=require(`../../functions/private-wallet/emporium.helpers.cjs`),y=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),b=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`),x=require(`../../API/deposit-and-withdraw-status-calls.cjs`),S=require(`./hinkalDepositOnChainUtxos.cjs`);require(`../../functions/index.cjs`);var C=async(a,l,f,m,h,g,S,C,w,T,E)=>{if(m.length===0)throw Error(`No recipients to bridge`);let D=f.erc20TokenAddress,{contractData:O}=t.networkRegistry[l],{emporiumAddress:k}=O;if(!k)throw Error(`No Emporium Address`);let A=s.SWAP_ROUTER_ADDRESSES[e.ExternalActionId.Lifi][l];if(!A)throw Error(`LIFI not configured for chain ${l}`);let j=await a.getRandomRelay(l);if(!j)throw Error(c.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let M=await a.getEthereumAddressByChain(l),N=u.getCurrentTimeInSeconds().toString(),P=a.generateProofRemotely?5:1,F=[];for(let t=0;t<m.length;t+=P){let r=m.slice(t,t+P),s=await Promise.all(r.map(async({utxo:t,nativeUtxo:r,bridgeAmount:s,quote:c,temporarySubAccount:u,recipientAddress:m})=>{await o.API.addTemporaryWalletNonce(l,g,u.index);let b=c.nativeFee>0n&&!i.caseInsensitiveEqual(D,n.zeroAddress),x=[D],S=[-t.amount],C=[!1],w=new d.Utxo({amount:0n,erc20TokenAddress:D,nullifyingKey:a.userKeys.getShieldedPrivateKey(),timeStamp:N,...t.isNewStyle?{spendingPublicKey:a.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,isNewStyle:!0}:{isNewStyle:!1}}),E=[[t,w]],O=[[w]];if(b&&r){let e=new d.Utxo({amount:0n,erc20TokenAddress:n.zeroAddress,nullifyingKey:a.userKeys.getShieldedPrivateKey(),timeStamp:N,...r.isNewStyle?{spendingPublicKey:a.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,isNewStyle:!0}:{isNewStyle:!1}});x.push(n.zeroAddress),S.push(-r.amount),C.push(!1),E.push([r,e]),O.push([e])}let P=v.createLifiBridgeOps(a,l,u.ethAddress,A,D,t.amount,s,c),F=await _.calculateModifiedFeeStructure(l,f,s,h),I=p.constructAdminData(T,l,x,[-t.amount],M),[{zkCallData:L,circomData:R,dimData:z,commitmentValidationData:B},V]=await Promise.all([y.constructZkProof(a.merkleTreeHinkalByChain[l],E,O,a.userKeys,e.ExternalActionId.Emporium,k,P,a.generateProofRemotely,F,j??n.zeroAddress,l,C,void 0,void 0,u.privateKey),v.getAuthorizationDataIfNeeded(l,u.privateKey)]);return{zkCallData:L,dimData:z,circomData:R,commitmentValidationData:B,authorizationData:V,recipientAddress:m,adminData:I}}));F.push(...s)}await x.safeUpdateDepositAndWithdrawStatus({id:S,chainId:l,hashedEthereumAddress:g,phase:r.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});let I=await b.transactCallRelayerBatch(l,F,g,C,w,E);return await x.safeUpdateDepositAndWithdrawStatus({id:S,chainId:l,hashedEthereumAddress:g,phase:r.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:I}),I},w=async(t,r,o,c,u,d,p,_,y=!0)=>{let b=r.erc20TokenAddress,x=f.validateAndGetChainId([r]),w=_?a.hashString(_):void 0,T=a.hashEthereumAddress(await t.getEthereumAddressByChain(x)),E=s.SWAP_ROUTER_ADDRESSES[e.ExternalActionId.Lifi][x];if(!E)throw Error(`LIFI router not configured`);let D;if(u)D=u;else{let r=o[0],i=v.createLifiBridgeOps(t,x,r.temporarySubAccount.ethAddress,E,b,r.bridgeAmount,r.bridgeAmount,r.quote).map(e=>g.convertEmporiumOpToCallInfo(e,r.temporarySubAccount.ethAddress,x));D=await m.getFeeStructure(x,b,[b],e.ExternalActionId.Emporium,i,n.PAY_SEND_VARIABLE_RATE)}let O={feeToken:D.feeToken,flatFee:0n,variableRate:0n},k=o.reduce((e,t)=>e+t.quote.nativeFee,0n)>0n&&!i.caseInsensitiveEqual(b,n.zeroAddress),A=o.map(e=>e.bridgeAmount),j=o.map(e=>e.recipientAddress),{userDepositedUtxos:M,statusId:N,depositTxHash:P}=await S.hinkalDepositOnChainUtxos(t,x,r,A,j,D,T,y),F=[];if(k){let e=l.getERC20Token(n.zeroAddress,x);if(!e)throw Error(`No native token`);let{userDepositedUtxos:r}=await S.hinkalDepositOnChainUtxos(t,x,e,o.map(e=>e.quote.nativeFee),j,O,T,y);F=r}return await h.waitForDepositedUtxosInMerkleTree(t,x,[...M,...F]),await C(t,x,r,o.map((e,t)=>({...e,utxo:M[t].utxo,nativeUtxo:k?F[t]?.utxo:void 0})),D,T,N,c,d,p,w),P};exports.hinkalDepositAndBridge=w;
|
|
@@ -15,109 +15,103 @@ import { validateAndGetChainId as m } from "../../functions/utils/token-check.ut
|
|
|
15
15
|
import { constructAdminData as h } from "../../functions/pre-transaction/constructAdminData.mjs";
|
|
16
16
|
import { getFeeStructure as g } from "../../functions/pre-transaction/getFeeStructure.mjs";
|
|
17
17
|
import { waitForDepositedUtxosInMerkleTree as _ } from "../../functions/pre-transaction/waitForDepositedUtxosInMerkleTree.mjs";
|
|
18
|
-
import {
|
|
19
|
-
import "../../functions/
|
|
20
|
-
import { convertEmporiumOpToCallInfo as y } from "../../functions/utils/convertEmporiumOpToCallInfo.mjs";
|
|
21
|
-
import { calculateModifiedFeeStructure as b } from "../../functions/utils/fees.utils.mjs";
|
|
18
|
+
import { convertEmporiumOpToCallInfo as v } from "../../functions/utils/convertEmporiumOpToCallInfo.mjs";
|
|
19
|
+
import { calculateModifiedFeeStructure as y } from "../../functions/utils/fees.utils.mjs";
|
|
22
20
|
import "../../functions/utils/index.mjs";
|
|
23
|
-
import { createLifiBridgeOps as
|
|
24
|
-
import { constructZkProof as
|
|
25
|
-
import { transactCallRelayerBatch as
|
|
26
|
-
import { safeUpdateDepositAndWithdrawStatus as
|
|
27
|
-
import { hinkalDepositOnChainUtxos as
|
|
21
|
+
import { createLifiBridgeOps as b, getAuthorizationDataIfNeeded as x } from "../../functions/private-wallet/emporium.helpers.mjs";
|
|
22
|
+
import { constructZkProof as S } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
|
|
23
|
+
import { transactCallRelayerBatch as C } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
|
|
24
|
+
import { safeUpdateDepositAndWithdrawStatus as w } from "../../API/deposit-and-withdraw-status-calls.mjs";
|
|
25
|
+
import { hinkalDepositOnChainUtxos as T } from "./hinkalDepositOnChainUtxos.mjs";
|
|
28
26
|
import "../../functions/index.mjs";
|
|
29
27
|
//#region libs/shared/common/src/data-structures/Hinkal/hinkalDepositAndBridge.ts
|
|
30
|
-
var
|
|
28
|
+
var E = async (n, o, s, d, m, g, _, v, T, E, D) => {
|
|
31
29
|
if (d.length === 0) throw Error("No recipients to bridge");
|
|
32
|
-
let
|
|
33
|
-
if (!
|
|
34
|
-
let
|
|
35
|
-
if (!
|
|
36
|
-
let
|
|
37
|
-
if (!
|
|
38
|
-
let
|
|
39
|
-
for (let t = 0; t < d.length; t +=
|
|
40
|
-
let i = d.slice(t, t +
|
|
30
|
+
let O = s.erc20TokenAddress, { contractData: k } = t[o], { emporiumAddress: A } = k;
|
|
31
|
+
if (!A) throw Error("No Emporium Address");
|
|
32
|
+
let j = l[e.Lifi][o];
|
|
33
|
+
if (!j) throw Error(`LIFI not configured for chain ${o}`);
|
|
34
|
+
let M = await n.getRandomRelay(o);
|
|
35
|
+
if (!M) throw Error(u.RELAYER_NOT_AVAILABLE);
|
|
36
|
+
let N = await n.getEthereumAddressByChain(o), P = f().toString(), F = n.generateProofRemotely ? 5 : 1, I = [];
|
|
37
|
+
for (let t = 0; t < d.length; t += F) {
|
|
38
|
+
let i = d.slice(t, t + F), l = await Promise.all(i.map(async ({ utxo: t, nativeUtxo: i, bridgeAmount: l, quote: u, temporarySubAccount: d, recipientAddress: f }) => {
|
|
41
39
|
await c.addTemporaryWalletNonce(o, g, d.index);
|
|
42
|
-
let _ = u.nativeFee > 0n && !a(
|
|
40
|
+
let _ = u.nativeFee > 0n && !a(O, r), v = [O], C = [-t.amount], w = [!1], T = new p({
|
|
43
41
|
amount: 0n,
|
|
44
|
-
erc20TokenAddress:
|
|
42
|
+
erc20TokenAddress: O,
|
|
45
43
|
nullifyingKey: n.userKeys.getShieldedPrivateKey(),
|
|
46
|
-
timeStamp:
|
|
44
|
+
timeStamp: P,
|
|
47
45
|
...t.isNewStyle ? {
|
|
48
46
|
spendingPublicKey: n.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,
|
|
49
47
|
isNewStyle: !0
|
|
50
48
|
} : { isNewStyle: !1 }
|
|
51
|
-
}),
|
|
49
|
+
}), D = [[t, T]], k = [[T]];
|
|
52
50
|
if (_ && i) {
|
|
53
51
|
let e = new p({
|
|
54
52
|
amount: 0n,
|
|
55
53
|
erc20TokenAddress: r,
|
|
56
54
|
nullifyingKey: n.userKeys.getShieldedPrivateKey(),
|
|
57
|
-
timeStamp:
|
|
55
|
+
timeStamp: P,
|
|
58
56
|
...i.isNewStyle ? {
|
|
59
57
|
spendingPublicKey: n.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,
|
|
60
58
|
isNewStyle: !0
|
|
61
59
|
} : { isNewStyle: !1 }
|
|
62
60
|
});
|
|
63
|
-
|
|
61
|
+
v.push(r), C.push(-i.amount), w.push(!1), D.push([i, e]), k.push([e]);
|
|
64
62
|
}
|
|
65
|
-
let
|
|
66
|
-
C(n.merkleTreeHinkalByChain[o], O, A, n.userKeys, e.Emporium, j, I, n.generateProofRemotely, L, N ?? r, o, T, void 0, void 0, d.privateKey),
|
|
67
|
-
S(o, d.privateKey),
|
|
68
|
-
v(o, n.userKeys, y, O)
|
|
69
|
-
]);
|
|
63
|
+
let F = b(n, o, d.ethAddress, j, O, t.amount, l, u), I = await y(o, s, l, m), L = h(E, o, v, [-t.amount], N), [{ zkCallData: R, circomData: z, dimData: B, commitmentValidationData: V }, H] = await Promise.all([S(n.merkleTreeHinkalByChain[o], D, k, n.userKeys, e.Emporium, A, F, n.generateProofRemotely, I, M ?? r, o, w, void 0, void 0, d.privateKey), x(o, d.privateKey)]);
|
|
70
64
|
return {
|
|
71
|
-
zkCallData:
|
|
72
|
-
dimData:
|
|
73
|
-
circomData:
|
|
74
|
-
commitmentValidationData:
|
|
65
|
+
zkCallData: R,
|
|
66
|
+
dimData: B,
|
|
67
|
+
circomData: z,
|
|
68
|
+
commitmentValidationData: V,
|
|
75
69
|
authorizationData: H,
|
|
76
70
|
recipientAddress: f,
|
|
77
|
-
adminData:
|
|
71
|
+
adminData: L
|
|
78
72
|
};
|
|
79
73
|
}));
|
|
80
|
-
|
|
74
|
+
I.push(...l);
|
|
81
75
|
}
|
|
82
|
-
await
|
|
76
|
+
await w({
|
|
83
77
|
id: _,
|
|
84
78
|
chainId: o,
|
|
85
79
|
hashedEthereumAddress: g,
|
|
86
80
|
phase: i.BEFORE_SCHEDULE_WITHDRAW
|
|
87
81
|
});
|
|
88
|
-
let
|
|
89
|
-
return await
|
|
82
|
+
let L = await C(o, I, g, v, T, D);
|
|
83
|
+
return await w({
|
|
90
84
|
id: _,
|
|
91
85
|
chainId: o,
|
|
92
86
|
hashedEthereumAddress: g,
|
|
93
87
|
phase: i.AFTER_SCHEDULE_WITHDRAW,
|
|
94
|
-
scheduleId:
|
|
95
|
-
}),
|
|
96
|
-
},
|
|
97
|
-
let S = i.erc20TokenAddress, C = m([i]), w =
|
|
88
|
+
scheduleId: L
|
|
89
|
+
}), L;
|
|
90
|
+
}, D = async (t, i, c, u, f, p, h, y, x = !0) => {
|
|
91
|
+
let S = i.erc20TokenAddress, C = m([i]), w = y ? s(y) : void 0, D = o(await t.getEthereumAddressByChain(C)), O = l[e.Lifi][C];
|
|
98
92
|
if (!O) throw Error("LIFI router not configured");
|
|
99
93
|
let k;
|
|
100
94
|
if (f) k = f;
|
|
101
95
|
else {
|
|
102
|
-
let r = c[0], i =
|
|
96
|
+
let r = c[0], i = b(t, C, r.temporarySubAccount.ethAddress, O, S, r.bridgeAmount, r.bridgeAmount, r.quote).map((e) => v(e, r.temporarySubAccount.ethAddress, C));
|
|
103
97
|
k = await g(C, S, [S], e.Emporium, i, n);
|
|
104
98
|
}
|
|
105
99
|
let A = {
|
|
106
100
|
feeToken: k.feeToken,
|
|
107
101
|
flatFee: 0n,
|
|
108
102
|
variableRate: 0n
|
|
109
|
-
}, j = c.reduce((e, t) => e + t.quote.nativeFee, 0n) > 0n && !a(S, r), M = c.map((e) => e.bridgeAmount), N = c.map((e) => e.recipientAddress), { userDepositedUtxos: P, statusId: F, depositTxHash: I } = await
|
|
103
|
+
}, j = c.reduce((e, t) => e + t.quote.nativeFee, 0n) > 0n && !a(S, r), M = c.map((e) => e.bridgeAmount), N = c.map((e) => e.recipientAddress), { userDepositedUtxos: P, statusId: F, depositTxHash: I } = await T(t, C, i, M, N, k, D, x), L = [];
|
|
110
104
|
if (j) {
|
|
111
105
|
let e = d(r, C);
|
|
112
106
|
if (!e) throw Error("No native token");
|
|
113
|
-
let { userDepositedUtxos: n } = await
|
|
107
|
+
let { userDepositedUtxos: n } = await T(t, C, e, c.map((e) => e.quote.nativeFee), N, A, D, x);
|
|
114
108
|
L = n;
|
|
115
109
|
}
|
|
116
|
-
return await _(t, C, [...P, ...L]), await
|
|
110
|
+
return await _(t, C, [...P, ...L]), await E(t, C, i, c.map((e, t) => ({
|
|
117
111
|
...e,
|
|
118
112
|
utxo: P[t].utxo,
|
|
119
113
|
nativeUtxo: j ? L[t]?.utxo : void 0
|
|
120
|
-
})), k,
|
|
114
|
+
})), k, D, F, u, p, h, w), I;
|
|
121
115
|
};
|
|
122
116
|
//#endregion
|
|
123
|
-
export {
|
|
117
|
+
export { D as hinkalDepositAndBridge };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../types/external-action.types.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../constants/protocol.constants.cjs`),r=require(`../../types/scheduled-transactions.types.cjs`);require(`../../types/index.cjs`);const i=require(`../../functions/utils/caseInsensitive.utils.cjs`),a=require(`../../functions/utils/addresses.cjs`),o=require(`../../error-handling/error-codes.constants.cjs`),s=require(`../../functions/utils/time.utils.cjs`),c=require(`../utxo/Utxo.cjs`),l=require(`../../functions/utils/tron.utils.cjs`),u=require(`../../functions/utils/token-check.utils.cjs`),d=require(`../../functions/pre-transaction/constructAdminData.cjs`),f=require(`../../functions/pre-transaction/getFeeStructure.cjs`),p=require(`../../functions/pre-transaction/waitForDepositedUtxosInMerkleTree.cjs`),m=require(`../../functions/
|
|
1
|
+
const e=require(`../../types/external-action.types.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../constants/protocol.constants.cjs`),r=require(`../../types/scheduled-transactions.types.cjs`);require(`../../types/index.cjs`);const i=require(`../../functions/utils/caseInsensitive.utils.cjs`),a=require(`../../functions/utils/addresses.cjs`),o=require(`../../error-handling/error-codes.constants.cjs`),s=require(`../../functions/utils/time.utils.cjs`),c=require(`../utxo/Utxo.cjs`),l=require(`../../functions/utils/tron.utils.cjs`),u=require(`../../functions/utils/token-check.utils.cjs`),d=require(`../../functions/pre-transaction/constructAdminData.cjs`),f=require(`../../functions/pre-transaction/getFeeStructure.cjs`),p=require(`../../functions/pre-transaction/waitForDepositedUtxosInMerkleTree.cjs`),m=require(`../../functions/utils/fees.utils.cjs`),h=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),g=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`),_=require(`../../API/deposit-and-withdraw-status-calls.cjs`),v=require(`./hinkalDepositOnChainUtxos.cjs`);require(`../../functions/index.cjs`);var y=async(e,a,u,f,p,v,y,b,x,S,C,w)=>{let T=t.isTronLike(a);if(f.length===0)throw Error(`userDepositedUtxos must not be empty`);let E=u.erc20TokenAddress,[D,O]=await Promise.all([e.getRandomRelay(a),e.getEthereumAddressByChain(a)]);if(!D)throw Error(o.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let k=s.getCurrentTimeInSeconds().toString(),A=e.generateProofRemotely&&!T?5:1,j=[],M=l.addressToHexFormat(O);for(let t=0;t<f.length;t+=A){let r=f.slice(t,t+A),o=await Promise.all(r.map(async({recipientAddress:r,utxo:o},s)=>{let f=t+s,g=l.addressToHexFormat(r),_=new c.Utxo({amount:0n,erc20TokenAddress:E,nullifyingKey:e.userKeys.getShieldedPrivateKey(),timeStamp:k,...o.isNewStyle?{spendingPublicKey:e.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,isNewStyle:!0}:{isNewStyle:!1}}),y=[[i.caseInsensitiveEqual(o.erc20TokenAddress,E)?o:c.Utxo.createFrom(o,{erc20TokenAddress:E}),_]],b=[[_]],x={externalActionId:0n,externalAddress:g,externalActionMetadata:`0x00`},S=d.constructAdminData(C,a,[E],[-o.amount],M),w=await m.calculateModifiedFeeStructure(a,u,p[f],v),{zkCallData:O,circomData:A,dimData:j,commitmentValidationData:N}=await h.constructZkProof(e.merkleTreeHinkalByChain[a],y,b,e.userKeys,x.externalActionId,x.externalAddress,x.externalActionMetadata,e.generateProofRemotely,w,D??n.zeroAddress,a);return{zkCallData:O,dimData:j,circomData:A,commitmentValidationData:N,adminData:S,recipientAddress:r,tronProofSignature:await l.reorderZkCallData(T,O,j,A)}}));j.push(...o)}await _.safeUpdateDepositAndWithdrawStatus({id:b,chainId:a,hashedEthereumAddress:y,phase:r.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});let N=await g.transactCallRelayerBatch(a,j,y,x,S,w);return await _.safeUpdateDepositAndWithdrawStatus({id:b,chainId:a,hashedEthereumAddress:y,phase:r.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:N}),N},b=async(t,n,r,i,o,s,c,d,m,h=!0)=>{let g=u.validateAndGetChainId([n]),_=m?a.hashString(m):void 0,b=n.erc20TokenAddress,x=a.hashEthereumAddress(l.addressToHexFormat(await t.getEthereumAddressByChain(g))),S=s??await f.getFeeStructure(g,b,[b],e.ExternalActionId.Transact,[],10n),{userDepositedUtxos:C,statusId:w,depositTxHash:T}=await v.hinkalDepositOnChainUtxos(t,g,n,r,i,S,x,h);return await p.waitForDepositedUtxosInMerkleTree(t,g,C),await y(t,g,n,C,r,S,x,w,o,c,d,_),T};exports.hinkalDepositAndWithdraw=b,exports.hinkalWithdrawBatch=y;
|
|
@@ -13,66 +13,64 @@ import { validateAndGetChainId as f } from "../../functions/utils/token-check.ut
|
|
|
13
13
|
import { constructAdminData as p } from "../../functions/pre-transaction/constructAdminData.mjs";
|
|
14
14
|
import { getFeeStructure as m } from "../../functions/pre-transaction/getFeeStructure.mjs";
|
|
15
15
|
import { waitForDepositedUtxosInMerkleTree as h } from "../../functions/pre-transaction/waitForDepositedUtxosInMerkleTree.mjs";
|
|
16
|
-
import {
|
|
17
|
-
import "../../functions/
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import { safeUpdateDepositAndWithdrawStatus as b } from "../../API/deposit-and-withdraw-status-calls.mjs";
|
|
22
|
-
import { hinkalDepositOnChainUtxos as x } from "./hinkalDepositOnChainUtxos.mjs";
|
|
16
|
+
import { calculateModifiedFeeStructure as g } from "../../functions/utils/fees.utils.mjs";
|
|
17
|
+
import { constructZkProof as _ } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
|
|
18
|
+
import { transactCallRelayerBatch as v } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
|
|
19
|
+
import { safeUpdateDepositAndWithdrawStatus as y } from "../../API/deposit-and-withdraw-status-calls.mjs";
|
|
20
|
+
import { hinkalDepositOnChainUtxos as b } from "./hinkalDepositOnChainUtxos.mjs";
|
|
23
21
|
import "../../functions/index.mjs";
|
|
24
22
|
//#region libs/shared/common/src/data-structures/Hinkal/hinkalDepositAndWithdraw.ts
|
|
25
|
-
var
|
|
26
|
-
let
|
|
23
|
+
var x = async (e, a, o, f, m, h, b, x, S, C, w, T) => {
|
|
24
|
+
let E = t(a);
|
|
27
25
|
if (f.length === 0) throw Error("userDepositedUtxos must not be empty");
|
|
28
|
-
let
|
|
29
|
-
if (!
|
|
30
|
-
let
|
|
31
|
-
for (let t = 0; t < f.length; t +=
|
|
32
|
-
let r = f.slice(t, t +
|
|
33
|
-
let f = t + c,
|
|
26
|
+
let D = o.erc20TokenAddress, [O, k] = await Promise.all([e.getRandomRelay(a), e.getEthereumAddressByChain(a)]);
|
|
27
|
+
if (!O) throw Error(s.RELAYER_NOT_AVAILABLE);
|
|
28
|
+
let A = c().toString(), j = e.generateProofRemotely && !E ? 5 : 1, M = [], N = u(k);
|
|
29
|
+
for (let t = 0; t < f.length; t += j) {
|
|
30
|
+
let r = f.slice(t, t + j), s = await Promise.all(r.map(async ({ recipientAddress: r, utxo: s }, c) => {
|
|
31
|
+
let f = t + c, v = u(r), y = new l({
|
|
34
32
|
amount: 0n,
|
|
35
|
-
erc20TokenAddress:
|
|
33
|
+
erc20TokenAddress: D,
|
|
36
34
|
nullifyingKey: e.userKeys.getShieldedPrivateKey(),
|
|
37
|
-
timeStamp:
|
|
35
|
+
timeStamp: A,
|
|
38
36
|
...s.isNewStyle ? {
|
|
39
37
|
spendingPublicKey: e.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,
|
|
40
38
|
isNewStyle: !0
|
|
41
39
|
} : { isNewStyle: !1 }
|
|
42
|
-
}),
|
|
40
|
+
}), b = [[i(s.erc20TokenAddress, D) ? s : l.createFrom(s, { erc20TokenAddress: D }), y]], x = [[y]], S = {
|
|
43
41
|
externalActionId: 0n,
|
|
44
|
-
externalAddress:
|
|
42
|
+
externalAddress: v,
|
|
45
43
|
externalActionMetadata: "0x00"
|
|
46
|
-
},
|
|
44
|
+
}, C = p(w, a, [D], [-s.amount], N), T = await g(a, o, m[f], h), { zkCallData: k, circomData: j, dimData: M, commitmentValidationData: P } = await _(e.merkleTreeHinkalByChain[a], b, x, e.userKeys, S.externalActionId, S.externalAddress, S.externalActionMetadata, e.generateProofRemotely, T, O ?? n, a);
|
|
47
45
|
return {
|
|
48
|
-
zkCallData:
|
|
49
|
-
dimData:
|
|
50
|
-
circomData:
|
|
51
|
-
commitmentValidationData:
|
|
52
|
-
adminData:
|
|
46
|
+
zkCallData: k,
|
|
47
|
+
dimData: M,
|
|
48
|
+
circomData: j,
|
|
49
|
+
commitmentValidationData: P,
|
|
50
|
+
adminData: C,
|
|
53
51
|
recipientAddress: r,
|
|
54
|
-
tronProofSignature: await d(
|
|
52
|
+
tronProofSignature: await d(E, k, M, j)
|
|
55
53
|
};
|
|
56
54
|
}));
|
|
57
|
-
|
|
55
|
+
M.push(...s);
|
|
58
56
|
}
|
|
59
|
-
await
|
|
60
|
-
id:
|
|
57
|
+
await y({
|
|
58
|
+
id: x,
|
|
61
59
|
chainId: a,
|
|
62
|
-
hashedEthereumAddress:
|
|
60
|
+
hashedEthereumAddress: b,
|
|
63
61
|
phase: r.BEFORE_SCHEDULE_WITHDRAW
|
|
64
62
|
});
|
|
65
|
-
let
|
|
66
|
-
return await
|
|
67
|
-
id:
|
|
63
|
+
let P = await v(a, M, b, S, C, T);
|
|
64
|
+
return await y({
|
|
65
|
+
id: x,
|
|
68
66
|
chainId: a,
|
|
69
|
-
hashedEthereumAddress:
|
|
67
|
+
hashedEthereumAddress: b,
|
|
70
68
|
phase: r.AFTER_SCHEDULE_WITHDRAW,
|
|
71
|
-
scheduleId:
|
|
72
|
-
}),
|
|
73
|
-
},
|
|
74
|
-
let _ = f([n]), v = p ? o(p) : void 0, y = n.erc20TokenAddress,
|
|
75
|
-
return await h(t, _, w), await
|
|
69
|
+
scheduleId: P
|
|
70
|
+
}), P;
|
|
71
|
+
}, S = async (t, n, r, i, s, c, l, d, p, g = !0) => {
|
|
72
|
+
let _ = f([n]), v = p ? o(p) : void 0, y = n.erc20TokenAddress, S = a(u(await t.getEthereumAddressByChain(_))), C = c ?? await m(_, y, [y], e.Transact, [], 10n), { userDepositedUtxos: w, statusId: T, depositTxHash: E } = await b(t, _, n, r, i, C, S, g);
|
|
73
|
+
return await h(t, _, w), await x(t, _, n, w, r, C, S, T, s, l, d, v), E;
|
|
76
74
|
};
|
|
77
75
|
//#endregion
|
|
78
|
-
export {
|
|
76
|
+
export { S as hinkalDepositAndWithdraw, x as hinkalWithdrawBatch };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../API/callNearIntentsAPI.cjs`),n=require(`../../constants/bridging.constants.cjs`),r=require(`../../functions/utils/time.utils.cjs`),i=require(`../../functions/utils/token-check.utils.cjs`),a=require(`../../functions/utils/nearIntents.utils.cjs`),o=require(`./hinkalDepositAndWithdraw.cjs`),s=require(`./hinkalSolanaDepositAndWithdraw.cjs`);var c=async(c,l,u,d,f,p,m,h,g,_)=>{if(u.length!==d.length)throw Error(`recipientAmounts and recipientAddresses length mismatch`);if(u.length===0)throw Error(`No recipients to bridge`);let v=i.validateAndGetChainId([l]),y=r.secondsToMs(p),b=new Date(y+n.NEAR_BRIDGE_QUOTE_DEADLINE_BUFFER_MS).toISOString(),x=await Promise.all(d.map(async(e,n)=>{let r=u[n],{quote:i}=await t.getNearIntentsQuote({dry:!1,swapType:`EXACT_INPUT`,slippageTolerance:f.slippageBps??100,originAsset:f.originAsset,depositType:`ORIGIN_CHAIN`,destinationAsset:f.destinationAsset,amount:r.toString(),recipient:e,recipientType:`DESTINATION_CHAIN`,refundTo:c.userKeys.getNearIntentsAccountId(),refundType:`INTENTS`,deadline:b});if(!i.depositAddress)throw Error(`NEAR Intents quote returned no deposit address for recipient ${e}`);if(i.deadline&&new Date(i.deadline).getTime()<y)throw Error(`Bridge quote expires before the scheduled execution time. Choose a sooner time.`);return{destinationRecipient:e,amount:r,depositAddress:i.depositAddress,quote:i}})),S=m??await a.buildNearBridgeFeeStructure(v,l,x[0].depositAddress),C=x.map(e=>e.amount),w=x.map(e=>e.depositAddress),T;return T=e.isSolanaLike(v)?await s.hinkalSolanaDepositAndWithdraw(c,l,C,w,p,S,h,g,_,x.map(e=>e.destinationRecipient)):await o.hinkalDepositAndWithdraw(c,l,C,w,p,S,h,g,_),{depositTxHash:T,legs:x}};exports.hinkalNearDepositAndBridge=c;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AdminTransactionType } from '../../types';
|
|
2
|
+
import { FeeStructure } from '../../types/hinkal.types';
|
|
3
|
+
import { NearBridgeParams, NearBridgeResult } from '../../types/near-intents.types';
|
|
4
|
+
import { ERC20Token } from '../../types/token.types';
|
|
5
|
+
import { IHinkal } from './IHinkal';
|
|
6
|
+
export declare const hinkalNearDepositAndBridge: (hinkal: IHinkal, token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], params: NearBridgeParams, txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, action?: AdminTransactionType, dashboardAccountId?: string) => Promise<NearBridgeResult>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { isSolanaLike as e } from "../../constants/chains.constants.mjs";
|
|
2
|
+
import { getNearIntentsQuote as t } from "../../API/callNearIntentsAPI.mjs";
|
|
3
|
+
import { NEAR_BRIDGE_QUOTE_DEADLINE_BUFFER_MS as n } from "../../constants/bridging.constants.mjs";
|
|
4
|
+
import { secondsToMs as r } from "../../functions/utils/time.utils.mjs";
|
|
5
|
+
import { validateAndGetChainId as i } from "../../functions/utils/token-check.utils.mjs";
|
|
6
|
+
import { buildNearBridgeFeeStructure as a } from "../../functions/utils/nearIntents.utils.mjs";
|
|
7
|
+
import { hinkalDepositAndWithdraw as o } from "./hinkalDepositAndWithdraw.mjs";
|
|
8
|
+
import { hinkalSolanaDepositAndWithdraw as s } from "./hinkalSolanaDepositAndWithdraw.mjs";
|
|
9
|
+
//#region libs/shared/common/src/data-structures/Hinkal/hinkalNearDepositAndBridge.ts
|
|
10
|
+
var c = async (c, l, u, d, f, p, m, h, g, _) => {
|
|
11
|
+
if (u.length !== d.length) throw Error("recipientAmounts and recipientAddresses length mismatch");
|
|
12
|
+
if (u.length === 0) throw Error("No recipients to bridge");
|
|
13
|
+
let v = i([l]), y = r(p), b = new Date(y + n).toISOString(), x = await Promise.all(d.map(async (e, n) => {
|
|
14
|
+
let r = u[n], { quote: i } = await t({
|
|
15
|
+
dry: !1,
|
|
16
|
+
swapType: "EXACT_INPUT",
|
|
17
|
+
slippageTolerance: f.slippageBps ?? 100,
|
|
18
|
+
originAsset: f.originAsset,
|
|
19
|
+
depositType: "ORIGIN_CHAIN",
|
|
20
|
+
destinationAsset: f.destinationAsset,
|
|
21
|
+
amount: r.toString(),
|
|
22
|
+
recipient: e,
|
|
23
|
+
recipientType: "DESTINATION_CHAIN",
|
|
24
|
+
refundTo: c.userKeys.getNearIntentsAccountId(),
|
|
25
|
+
refundType: "INTENTS",
|
|
26
|
+
deadline: b
|
|
27
|
+
});
|
|
28
|
+
if (!i.depositAddress) throw Error(`NEAR Intents quote returned no deposit address for recipient ${e}`);
|
|
29
|
+
if (i.deadline && new Date(i.deadline).getTime() < y) throw Error("Bridge quote expires before the scheduled execution time. Choose a sooner time.");
|
|
30
|
+
return {
|
|
31
|
+
destinationRecipient: e,
|
|
32
|
+
amount: r,
|
|
33
|
+
depositAddress: i.depositAddress,
|
|
34
|
+
quote: i
|
|
35
|
+
};
|
|
36
|
+
})), S = m ?? await a(v, l, x[0].depositAddress), C = x.map((e) => e.amount), w = x.map((e) => e.depositAddress), T;
|
|
37
|
+
return T = e(v) ? await s(c, l, C, w, p, S, h, g, _, x.map((e) => e.destinationRecipient)) : await o(c, l, C, w, p, S, h, g, _), {
|
|
38
|
+
depositTxHash: T,
|
|
39
|
+
legs: x
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
//#endregion
|
|
43
|
+
export { c as hinkalNearDepositAndBridge };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../types/external-action.types.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../types/admin.types.cjs`),r=require(`../../functions/utils/caseInsensitive.utils.cjs`),i=require(`../../functions/utils/addresses.cjs`),a=require(`../../error-handling/error-codes.constants.cjs`),o=require(`../../functions/utils/time.utils.cjs`),s=require(`../../functions/web3/events/getShieldedBalance.cjs`),c=require(`../../functions/pre-transaction/outputUtxoProcessing.cjs`);require(`../../error-handling/index.cjs`);const l=require(`../../functions/pre-transaction/constructAdminData.cjs`),u=require(`../AccountActions/AccountActions.cjs`),d=require(`../../functions/pre-transaction/recipientUtxoProcessing.cjs`),f=require(`../../functions/pre-transaction/getFeeStructure.cjs`)
|
|
1
|
+
const e=require(`../../types/external-action.types.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../types/admin.types.cjs`),r=require(`../../functions/utils/caseInsensitive.utils.cjs`),i=require(`../../functions/utils/addresses.cjs`),a=require(`../../error-handling/error-codes.constants.cjs`),o=require(`../../functions/utils/time.utils.cjs`),s=require(`../../functions/web3/events/getShieldedBalance.cjs`),c=require(`../../functions/pre-transaction/outputUtxoProcessing.cjs`);require(`../../error-handling/index.cjs`);const l=require(`../../functions/pre-transaction/constructAdminData.cjs`),u=require(`../AccountActions/AccountActions.cjs`),d=require(`../../functions/pre-transaction/recipientUtxoProcessing.cjs`),f=require(`../../functions/pre-transaction/getFeeStructure.cjs`);require(`../../functions/pre-transaction/index.cjs`);const p=require(`../../functions/utils/involves-permit2-op.cjs`),m=require(`../../functions/utils/convertEmporiumOpToCallInfo.cjs`),h=require(`../../functions/private-wallet/emporium.helpers.cjs`),g=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),_=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`),v=require(`../../functions/pre-transaction/merge-with-fee-structure.cjs`),y=require(`../../functions/pre-transaction/merge-with-fee-structure-emporium.cjs`),b=require(`./handleAutoDepositBack.cjs`);var x=async(e,t,n,r,i)=>{let a=[...await s.addPaddingToUtxos(e,t,n,r)],l=[],u=o.getCurrentTimeInSeconds().toString();for(let t=0;t<n.length;t+=1){let{outputUtxos:n}=c.outputUtxoProcessing(e.userKeys,a[t],r[t],u);l.push(n)}return i&&d.recipientUtxoProcessing(i,l,r,u),{inputUtxosArray:a,outputUtxosArray:l}},S=async(o,s,c,d,S,C,w,T,E,D,O,k=!1,A,j,M)=>{if(M&&!i.isValidPrivateAddress(M.recipientInfo))throw Error(a.transactionErrorCodes.RECIPIENT_FORMAT_INCORRECT);if(w.length>0&&!T)throw Error(`Subaccount is required for private wallet transactions`);let N=c.map(e=>e.erc20TokenAddress),P=await o.getEthereumAddressByChain(s),F=T?u.AccountActions.getAddressFromSubAccount(s,T):void 0,{contractData:I}=t.networkRegistry[s],{emporiumAddress:L}=I;if(!L)throw Error(`No Emporium Address Provided`);let R=D??await f.getFeeStructure(s,E,N,e.ExternalActionId.Emporium,C.map(e=>m.convertEmporiumOpToCallInfo(e,F??``,s)));for(F?await y.mergeWithFeeStructureEmporium(o,s,F,C,N,d,R,w.find(e=>r.caseInsensitiveEqual(e.token.erc20TokenAddress,R.feeToken))?.amount??0n):v.mergeWithFeeStructure(s,N,d,R);S.length<N.length;)S.push(!1);let[{inputUtxosArray:z,outputUtxosArray:B},V]=await Promise.all([x(o,s,N,d,M),O??await o.getRandomRelay(s,!0)]);if(!V)throw Error(a.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let H=T?u.AccountActions.getPrivateKeyFromSubAccount(s,T):void 0,[{zkCallData:U,circomData:W,dimData:G,commitmentValidationData:K},q]=await Promise.all([g.constructZkProof(o.merkleTreeHinkalByChain[s],z,B,o.userKeys,e.ExternalActionId.Emporium,L,C,o.generateProofRemotely,R,V,s,S,void 0,void 0,H),h.getAuthorizationDataIfNeeded(s,H)]),J=await _.transactCallRelayer(s,U,G,W,K,p.uniswapWorkaround(C),q,l.constructAdminData(j,s,w.map(e=>e.token.erc20TokenAddress),w.map(e=>e.amount),P,j===n.AdminTransactionType.PublicSwap?w.map(({token:e})=>e):void 0));return k&&T&&b.handleAutoDepositBack(o,s,F,T,R.feeToken,A,w,W),J};exports.hinkalPrivateWallet=S;
|