@hinkal/common 0.2.22 → 0.2.24
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/proxyAccountsCalls.cjs +1 -1
- package/API/proxyAccountsCalls.mjs +13 -13
- package/README.md +63 -267
- package/constants/activity.constants.cjs +1 -1
- package/constants/activity.constants.mjs +0 -1
- package/constants/addresses.constants.cjs +1 -1
- package/constants/addresses.constants.mjs +9 -10
- package/constants/contracts.constants.cjs +1 -1
- package/constants/contracts.constants.d.ts +3 -3
- package/constants/contracts.constants.mjs +29 -29
- package/constants/server.constants.cjs +1 -1
- package/constants/server.constants.mjs +28 -29
- package/constants/tasks.constants.cjs +1 -1
- package/constants/tasks.constants.mjs +4 -5
- package/crypto/poseidon.cjs +1 -1
- package/crypto/poseidon.mjs +10 -10
- package/data-structures/ApprovalDBs/EventsPublicApprovalsDB.cjs +1 -1
- package/data-structures/ApprovalDBs/EventsPublicApprovalsDB.mjs +24 -24
- package/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.mjs +4 -5
- package/data-structures/Hinkal/IHinkal.d.ts +2 -2
- package/data-structures/Hinkal/hinkalApprove.cjs +1 -1
- package/data-structures/Hinkal/hinkalApprove.mjs +40 -40
- package/data-structures/Hinkal/hinkalCheckTokenRegistry.cjs +1 -1
- package/data-structures/Hinkal/hinkalCheckTokenRegistry.mjs +7 -8
- package/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
- package/data-structures/Hinkal/hinkalDeposit.mjs +4 -5
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.mjs +27 -28
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.d.ts +1 -0
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.mjs +35 -36
- package/data-structures/Hinkal/hinkalDepostAndBridge.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepostAndBridge.mjs +86 -83
- package/data-structures/Hinkal/hinkalInsideTransact.cjs +1 -1
- package/data-structures/Hinkal/hinkalInsideTransact.mjs +14 -13
- package/data-structures/Hinkal/hinkalPrivateWallet.cjs +1 -1
- package/data-structures/Hinkal/hinkalPrivateWallet.mjs +2 -3
- package/data-structures/Hinkal/hinkalProoflessDeposit.cjs +1 -1
- package/data-structures/Hinkal/hinkalProoflessDeposit.mjs +27 -26
- package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.mjs +72 -73
- package/data-structures/Hinkal/hinkalSolanaSwap.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaSwap.mjs +16 -17
- package/data-structures/Hinkal/hinkalSolanaTransfer.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaTransfer.mjs +24 -25
- package/data-structures/Hinkal/hinkalSolanaWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaWithdraw.mjs +15 -16
- package/data-structures/Hinkal/hinkalSwap.cjs +1 -1
- package/data-structures/Hinkal/hinkalSwap.mjs +2 -3
- package/data-structures/Hinkal/hinkalTransfer.cjs +1 -1
- package/data-structures/Hinkal/hinkalTransfer.mjs +2 -3
- package/data-structures/Hinkal/hinkalWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalWithdraw.mjs +9 -10
- package/data-structures/Hinkal/hinkalWithdrawStuckUtxos.cjs +1 -1
- package/data-structures/Hinkal/hinkalWithdrawStuckUtxos.mjs +8 -9
- package/data-structures/Hinkal/resetMerkleTrees.cjs +1 -1
- package/data-structures/Hinkal/resetMerkleTrees.mjs +10 -10
- package/data-structures/IndexedDB/activity-db.cjs +1 -1
- package/data-structures/IndexedDB/activity-db.mjs +39 -41
- package/data-structures/IndexedDB/balances-db.cjs +1 -1
- package/data-structures/IndexedDB/balances-db.mjs +8 -9
- package/data-structures/IndexedDB/contact-db.cjs +1 -1
- package/data-structures/IndexedDB/contact-db.mjs +21 -23
- package/data-structures/IndexedDB/signatures-db.cjs +1 -1
- package/data-structures/IndexedDB/signatures-db.mjs +2 -3
- package/data-structures/TokenDBs/EventsPublicTokensDB.cjs +1 -1
- package/data-structures/TokenDBs/EventsPublicTokensDB.mjs +34 -36
- package/data-structures/crypto-keys/decodeUTXO.cjs +1 -1
- package/data-structures/crypto-keys/decodeUTXO.mjs +45 -45
- package/data-structures/crypto-keys/encryptDecryptUtxo.cjs +1 -1
- package/data-structures/crypto-keys/encryptDecryptUtxo.mjs +28 -27
- package/data-structures/crypto-keys/keys.cjs +1 -1
- package/data-structures/crypto-keys/keys.d.ts +2 -3
- package/data-structures/crypto-keys/keys.mjs +56 -57
- package/data-structures/event-service/evm/AbstractEventService.cjs +1 -1
- package/data-structures/event-service/evm/AbstractEventService.mjs +14 -14
- package/data-structures/event-service/evm/AbstractNullifierSnapshotService.cjs +1 -1
- package/data-structures/event-service/evm/AbstractNullifierSnapshotService.d.ts +2 -3
- package/data-structures/event-service/evm/AbstractNullifierSnapshotService.mjs +5 -4
- package/data-structures/event-service/evm/AbstractSnapshotService.cjs +1 -1
- package/data-structures/event-service/evm/AbstractSnapshotService.mjs +6 -3
- package/data-structures/event-service/evm/BlockchainEventEmitter.cjs +1 -1
- package/data-structures/event-service/evm/BlockchainEventEmitter.d.ts +1 -1
- package/data-structures/event-service/evm/BlockchainEventEmitter.mjs +22 -18
- package/data-structures/event-service/solana/AbstractSolanaNullifierSnapshotService.cjs +1 -1
- package/data-structures/event-service/solana/AbstractSolanaNullifierSnapshotService.mjs +2 -2
- package/data-structures/presale/PresaleContractWrapper.cjs +1 -1
- package/data-structures/presale/PresaleContractWrapper.d.ts +3 -3
- package/data-structures/presale/PresaleContractWrapper.mjs +10 -10
- package/data-structures/provider-adapter/IProviderAdapter.d.ts +7 -7
- package/data-structures/snapshot/evm-snapshots/ClientAccessTokenSnapshotService.cjs +1 -1
- package/data-structures/snapshot/evm-snapshots/ClientAccessTokenSnapshotService.mjs +16 -14
- package/data-structures/snapshot/evm-snapshots/ClientApprovalsSnapshotService.cjs +1 -1
- package/data-structures/snapshot/evm-snapshots/ClientApprovalsSnapshotService.mjs +7 -5
- package/error-handling/get-error.message.cjs +1 -1
- package/error-handling/get-error.message.mjs +2 -3
- package/functions/kyc/zkMeHelper.cjs +1 -1
- package/functions/kyc/zkMeHelper.mjs +3 -3
- package/functions/pre-transaction/getFlatFees.cjs +1 -1
- package/functions/pre-transaction/getFlatFees.mjs +2 -3
- package/functions/pre-transaction/getSolanaCalldataHash.cjs +1 -1
- package/functions/pre-transaction/getSolanaCalldataHash.mjs +21 -21
- package/functions/pre-transaction/getVolatileTransferAmount.cjs +1 -1
- package/functions/pre-transaction/getVolatileTransferAmount.mjs +2 -3
- package/functions/pre-transaction/interaction-to-action.cjs +1 -1
- package/functions/pre-transaction/interaction-to-action.mjs +2 -3
- package/functions/private-wallet/emporium.helpers.cjs +1 -1
- package/functions/private-wallet/emporium.helpers.d.ts +6 -7
- package/functions/private-wallet/emporium.helpers.mjs +104 -105
- package/functions/private-wallet/emporium.swap.helpers.cjs +1 -1
- package/functions/private-wallet/emporium.swap.helpers.mjs +44 -43
- package/functions/private-wallet/opProducer.cjs +1 -1
- package/functions/private-wallet/opProducer.mjs +1 -1
- package/functions/snarkjs/common.snarkjs.cjs +1 -1
- package/functions/snarkjs/common.snarkjs.mjs +21 -18
- package/functions/snarkjs/constructSolanaZkProof.cjs +1 -1
- package/functions/snarkjs/constructSolanaZkProof.mjs +11 -12
- package/functions/utils/addresses.cjs +1 -1
- package/functions/utils/addresses.mjs +6 -6
- package/functions/utils/cacheFunctions.cjs +1 -1
- package/functions/utils/cacheFunctions.d.ts +1 -1
- package/functions/utils/cacheFunctions.mjs +55 -54
- package/functions/utils/convertEmporiumOpToCallInfo.cjs +1 -1
- package/functions/utils/convertEmporiumOpToCallInfo.mjs +5 -5
- package/functions/utils/create-provider.cjs +1 -1
- package/functions/utils/create-provider.d.ts +2 -2
- package/functions/utils/create-provider.mjs +5 -5
- package/functions/utils/encryptInputForEnclave.cjs +1 -1
- package/functions/utils/encryptInputForEnclave.mjs +9 -9
- package/functions/utils/ethers-formatter.utils.d.ts +1 -1
- package/functions/utils/external-action.utils.cjs +1 -1
- package/functions/utils/external-action.utils.mjs +2 -2
- package/functions/utils/getContractAddress.cjs +1 -0
- package/functions/utils/getContractAddress.d.ts +2 -0
- package/functions/utils/getContractAddress.mjs +9 -0
- package/functions/utils/getDataFromTransaction.cjs +1 -1
- package/functions/utils/getDataFromTransaction.d.ts +0 -11
- package/functions/utils/getDataFromTransaction.mjs +26 -50
- package/functions/utils/getRecipientInfoFromUserKeys.cjs +1 -1
- package/functions/utils/getRecipientInfoFromUserKeys.mjs +1 -1
- package/functions/utils/getSignerFromContract.cjs +1 -0
- package/functions/utils/getSignerFromContract.d.ts +3 -0
- package/functions/utils/getSignerFromContract.mjs +16 -0
- package/functions/utils/getUtxosFromReceipt.utils.cjs +1 -1
- package/functions/utils/getUtxosFromReceipt.utils.d.ts +1 -1
- package/functions/utils/getUtxosFromReceipt.utils.mjs +15 -16
- package/functions/utils/inLogicMetadata.cjs +1 -1
- package/functions/utils/inLogicMetadata.mjs +2 -2
- package/functions/utils/nftTokenFunctions.cjs +1 -1
- package/functions/utils/nftTokenFunctions.mjs +2 -3
- package/functions/utils/publicBalance.utils.cjs +1 -1
- package/functions/utils/publicBalance.utils.d.ts +1 -1
- package/functions/utils/publicBalance.utils.mjs +42 -42
- package/functions/utils/rpc-int-encode.cjs +1 -1
- package/functions/utils/rpc-int-encode.d.ts +1 -2
- package/functions/utils/rpc-int-encode.mjs +3 -6
- package/functions/utils/solanaMint.utils.cjs +1 -1
- package/functions/utils/solanaMint.utils.mjs +6 -6
- package/functions/web3/EIP-712.cjs +1 -1
- package/functions/web3/EIP-712.d.ts +4 -4
- package/functions/web3/EIP-712.mjs +1 -1
- package/functions/web3/etherFunctions.cjs +1 -1
- package/functions/web3/etherFunctions.mjs +32 -29
- package/functions/web3/events/balanceChangedCustomHandler.cjs +1 -1
- package/functions/web3/events/balanceChangedCustomHandler.mjs +4 -5
- package/functions/web3/events/balanceChangedHandler.cjs +1 -1
- package/functions/web3/events/balanceChangedHandler.mjs +2 -3
- package/functions/web3/events/getApprovedBalance.cjs +1 -1
- package/functions/web3/events/getApprovedBalance.mjs +1 -1
- package/functions/web3/events/getInputUtxosEnclave.cjs +1 -1
- package/functions/web3/events/getInputUtxosEnclave.mjs +20 -20
- package/functions/web3/events/getTransactionLogEvents.cjs +1 -1
- package/functions/web3/events/getTransactionLogEvents.d.ts +3 -3
- package/functions/web3/events/getTransactionLogEvents.mjs +6 -5
- package/functions/web3/events/index.d.ts +0 -1
- package/functions/web3/fetchSolanaMerkleTreeRootHash.cjs +1 -1
- package/functions/web3/fetchSolanaMerkleTreeRootHash.d.ts +1 -2
- package/functions/web3/fetchSolanaMerkleTreeRootHash.mjs +4 -5
- package/functions/web3/functionCalls/accessTokenCalls.cjs +1 -1
- package/functions/web3/functionCalls/accessTokenCalls.mjs +10 -11
- package/functions/web3/functionCalls/approveToken.cjs +1 -1
- package/functions/web3/functionCalls/approveToken.mjs +61 -58
- package/functions/web3/functionCalls/constructBatchCall.cjs +1 -1
- package/functions/web3/functionCalls/constructBatchCall.d.ts +2 -2
- package/functions/web3/functionCalls/constructBatchCall.mjs +10 -9
- package/functions/web3/functionCalls/estimateGasRelayer.cjs +1 -1
- package/functions/web3/functionCalls/estimateGasRelayer.mjs +1 -1
- package/functions/web3/functionCalls/inHinkalApprovalCalls.cjs +1 -1
- package/functions/web3/functionCalls/inHinkalApprovalCalls.mjs +18 -21
- package/functions/web3/functionCalls/recoverTransactionFromError.d.ts +1 -1
- package/functions/web3/functionCalls/transactCallDirect.cjs +1 -1
- package/functions/web3/functionCalls/transactCallDirect.mjs +38 -34
- package/functions/web3/functionCalls/transactCallRelayer.cjs +1 -1
- package/functions/web3/functionCalls/transactCallRelayer.mjs +8 -10
- package/functions/web3/getContractMetadata.cjs +1 -1
- package/functions/web3/getContractMetadata.d.ts +1 -1
- package/functions/web3/getContractMetadata.mjs +25 -25
- package/functions/web3/getPublicAddressBalance.cjs +1 -1
- package/functions/web3/getPublicAddressBalance.mjs +7 -6
- package/functions/web3/getTokenHolder.cjs +1 -1
- package/functions/web3/getTokenHolder.mjs +16 -15
- package/functions/web3/odosAPI.cjs +1 -1
- package/functions/web3/odosAPI.mjs +6 -7
- package/functions/web3/oneInchAPI.cjs +1 -1
- package/functions/web3/oneInchAPI.mjs +2 -3
- package/functions/web3/runContractFunction.cjs +1 -1
- package/functions/web3/runContractFunction.d.ts +6 -5
- package/functions/web3/runContractFunction.mjs +41 -45
- package/functions/web3/uniswapAPI.cjs +1 -1
- package/functions/web3/uniswapAPI.d.ts +2 -2
- package/functions/web3/uniswapAPI.mjs +23 -24
- package/index.cjs +1 -1
- package/index.mjs +336 -340
- package/package.json +3 -4
- package/providers/CustomEthersProvider.d.ts +1 -1
- package/providers/EthersProviderAdapter.cjs +1 -1
- package/providers/EthersProviderAdapter.d.ts +7 -7
- package/providers/EthersProviderAdapter.mjs +46 -44
- package/providers/SolanaProviderAdapter.d.ts +1 -1
- package/providers/WagmiProviderAdapter.cjs +1 -1
- package/providers/WagmiProviderAdapter.d.ts +5 -5
- package/providers/WagmiProviderAdapter.mjs +37 -33
- package/providers/prepareEthersHinkal.cjs +1 -1
- package/providers/prepareEthersHinkal.d.ts +2 -2
- package/providers/prepareEthersHinkal.mjs +3 -5
- package/providers/prepareWagmiHinkal.cjs +1 -1
- package/providers/prepareWagmiHinkal.mjs +3 -5
- package/types/activities.types.d.ts +2 -3
- package/types/big-intable.types.d.ts +3 -2
- package/types/ethereum-network.types.d.ts +10 -10
- package/types/transactions.types.cjs +1 -1
- package/types/transactions.types.d.ts +2 -3
- package/types/transactions.types.mjs +6 -7
- package/webworker/utxoWorker/utxoWorkerLauncher.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.mjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLogic.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLogic.mjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.cjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.mjs +1 -1
- package/functions/web3/events/web3RetrieveEvents.cjs +0 -1
- package/functions/web3/events/web3RetrieveEvents.d.ts +0 -14
- package/functions/web3/events/web3RetrieveEvents.mjs +0 -9
|
@@ -1,40 +1,41 @@
|
|
|
1
|
-
import { calcStealthAddressStructure as
|
|
1
|
+
import { calcStealthAddressStructure as h } from "../../functions/snarkjs/common.snarkjs.mjs";
|
|
2
2
|
import { randomBigInt as g } from "../../functions/web3/etherFunctions.mjs";
|
|
3
|
-
import { ContractType as
|
|
3
|
+
import { ContractType as d } from "../../types/ethereum-network.types.mjs";
|
|
4
4
|
import { Utxo as A } from "../utxo/Utxo.mjs";
|
|
5
|
-
import { zeroAddress as
|
|
6
|
-
import { caseInsensitiveEqual as
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import { zeroAddress as p } from "../../constants/protocol.constants.mjs";
|
|
6
|
+
import { caseInsensitiveEqual as m } from "../../functions/utils/caseInsensitive.utils.mjs";
|
|
7
|
+
import { getContractAddress as C } from "../../functions/utils/getContractAddress.mjs";
|
|
8
|
+
const k = (r, e) => {
|
|
9
|
+
const o = [];
|
|
10
|
+
let n = 0;
|
|
10
11
|
for (let a = 0; a < r.length; a += 1) {
|
|
11
12
|
let s = !1;
|
|
12
|
-
for (let t = 0; t <
|
|
13
|
-
if (
|
|
14
|
-
|
|
13
|
+
for (let t = 0; t < n; t += 1)
|
|
14
|
+
if (m(o[t].token.erc20TokenAddress, r[a].erc20TokenAddress)) {
|
|
15
|
+
o[t].balance += e[a], s = !0;
|
|
15
16
|
break;
|
|
16
17
|
}
|
|
17
|
-
s || (n
|
|
18
|
+
s || (o[n] = {
|
|
18
19
|
token: r[a],
|
|
19
20
|
balance: e[a]
|
|
20
|
-
},
|
|
21
|
+
}, n += 1);
|
|
21
22
|
}
|
|
22
|
-
return
|
|
23
|
-
},
|
|
24
|
-
const
|
|
25
|
-
for (let t = 0; t <
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
).approve(s,
|
|
30
|
-
},
|
|
31
|
-
const a = r.getContractWithSigner(
|
|
23
|
+
return o;
|
|
24
|
+
}, w = async (r, e, o) => {
|
|
25
|
+
const n = k(e, o), a = r.getContractWithSigner(d.HinkalContract), s = C(a);
|
|
26
|
+
for (let t = 0; t < n.length; t += 1)
|
|
27
|
+
m(n[t].token.erc20TokenAddress, p) || await (await r.getContractWithSigner(
|
|
28
|
+
d.ERC20Contract,
|
|
29
|
+
n[t].token.erc20TokenAddress
|
|
30
|
+
).approve(s, n[t].balance)).wait();
|
|
31
|
+
}, W = async (r, e, o, n) => {
|
|
32
|
+
const a = r.getContractWithSigner(d.HinkalContract), s = r.userKeys.getShieldedPrivateKey(), t = A.findCorrectRandomization(g(31), s), i = n ?? Array(e.length).fill(h(t, s));
|
|
32
33
|
if (i.length !== e.length)
|
|
33
34
|
throw new Error("Stealth address structures length must be equal to erc20 tokens length");
|
|
34
|
-
await
|
|
35
|
-
const
|
|
35
|
+
await w(r, e, o);
|
|
36
|
+
const l = e.findIndex((c) => c.erc20TokenAddress === p), u = o[l] ?? 0n, f = await a.prooflessDeposit(
|
|
36
37
|
e.map(({ erc20TokenAddress: c }) => c),
|
|
37
|
-
|
|
38
|
+
o,
|
|
38
39
|
e.map(() => 0n),
|
|
39
40
|
i,
|
|
40
41
|
{ value: u }
|
|
@@ -42,5 +43,5 @@ const C = (r, e) => {
|
|
|
42
43
|
return await f.wait(), f;
|
|
43
44
|
};
|
|
44
45
|
export {
|
|
45
|
-
|
|
46
|
+
W as hinkalProoflessDeposit
|
|
46
47
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("../../functions/web3/etherFunctions.cjs"),z=require("../utxo/Utxo.cjs"),Y=require("../../error-handling/error-codes.constants.cjs")
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("../../functions/web3/etherFunctions.cjs"),z=require("../utxo/Utxo.cjs"),Y=require("../../error-handling/error-codes.constants.cjs");require("idb-keyval");const j=require("../../constants/chains.constants.cjs"),G=require("ethers");require("../crypto-keys/keys.cjs");require("node-forge");require("../../constants/vite.constants.cjs");require("libsodium-wrappers");require("../http/HttpClient.cjs");require("axios");const $=require("../../functions/utils/solanaMint.utils.cjs"),N=require("@solana/web3.js"),J=require("../../functions/utils/addresses.cjs");require("../../constants/server.constants.cjs");require("../../constants/token-data/index.cjs");const _=require("../../constants/protocol.constants.cjs"),Q=require("../../API/API.cjs");require("../../functions/utils/mutexes.utils.cjs");require("../../types/circom-data.types.cjs");const ee=require("../../types/external-action.types.cjs");require("../../types/activities.types.cjs");const B=require("../../types/scheduled-transactions.types.cjs");require("../../functions/web3/events/getApprovedBalance.cjs");require("../../constants/contracts.constants.cjs");require("../../constants/kyc.constants.cjs");require("../../constants/coingecko.constants.cjs");require("../../constants/reorg-depths.constants.cjs");require("../../constants/addresses.constants.cjs");require("../../constants/token.limits.constants.cjs");require("../../constants/presale.constants.cjs");require("../../constants/activity.constants.cjs");require("../../constants/tasks.constants.cjs");require("../../constants/events.constants.cjs");require("../../functions/utils/convertIntegrationProviderToExternalActionId.cjs");require("../../API/getServerURL.cjs");require("circomlibjs-hinkal-fork");require("process");require("buffer");require("../../constants/save-depths.cjs");const te=require("@coral-xyz/anchor"),E=require("../../functions/pre-transaction/solana.cjs");require("@solana/spl-token");require("../../functions/utils/userAgent.cjs");const re=require("../../functions/utils/time.utils.cjs");require("multiformats");require("../../API/tenderly.api.cjs");const oe=require("../../functions/utils/fees.utils.cjs");require("../../functions/web3/getTokenHolder.cjs");const ne=require("../../functions/web3/signAndSendSerializedTransaction.cjs"),Z=require("../../functions/snarkjs/common.snarkjs.cjs"),ae=require("./hinkalCheckSolanaTokenRegistry.cjs"),se=require("../../functions/utils/getUtxosFromReceiptSolana.cjs"),ie=require("../../functions/snarkjs/constructSolanaZkProof.cjs"),ce=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),ue=require("../../functions/pre-transaction/getFeeStructure.cjs"),W=require("../../API/deposit-and-withdraw-status-calls.cjs"),de=async(e,r,d,l,g,p)=>{const h=d.map(t=>t+oe.calculateTotalFee(t,g)),{hinkalIdl:m,hinkalAddress:S,originalDeployer:i}=j.networkRegistry[e.getCurrentChainId()].contractData;if(!m)throw new Error("No IDL configured for Solana program on this network");if(!i)throw new Error("missing original deployer");const w=e.userKeys.getShieldedPrivateKey(),P=z.Utxo.findCorrectRandomization(M.randomBigInt(31),w),y=Z.calcStealthAddressStructure(P,w),o=e.getSolanaProgram(m),b=e.getSolanaPublicKey(),n=new N.PublicKey(i),A=new N.PublicKey(S),{mintPublicKey:c}=$.formatMintAddress(r),x=c.toString(),O=E.getStorageAccountPublicKey(A,n),D=E.getStorageVaultPublicKey(A,n),F=E.getMerkleAccountPublicKey(A,n),R=E.buildAnchorStealthAddressStructure(y),f=e.getCurrentChainId(),v=h.reduce((t,s)=>t+s,0n),T=await ae.hinkalCheckSolanaTokenRegistry(o,new N.PublicKey(n),[r],[v]),K=h.map(t=>`${t}`);let a="";const I=(await W.updateDepositAndWithdrawStatus(f,{hashedEthereumAddress:p,phase:B.DepositAndWithdrawPhase.BEFORE_DEPOSIT})).id??void 0;if(T){const{serializedTransaction:t,blockhash:s,lastValidBlockHeight:q}=await Q.API.generateMultiPaymentDepositLimitless(f,{amounts:K,payer:e.getSolanaPublicKey().toBase58(),ethereumAddress:await e.getEthereumAddress(),mint:r,stealthAddressStructure:R}),{wallet:u}=o.provider;if(!u)throw new Error("missing wallet");a=await ne.signAndSendSerializedTransaction(o.provider,t,s,q)}else{const t=E.getTokenLimitStorageAccountPublicKey(o.programId,n,c),s=x===_.solanaNativeAddress?null:c,q=x===_.solanaNativeAddress?null:void 0;a=await o.methods.multiPaymentDeposit(K.map(L=>new te.BN(L)),R).accounts({mint:s,signer:b,signerAta:q,originalDeployer:n,storageAccount:O,storageVault:D,merkleAccount:F,tokenLimitStorage:t,storageVaultAta:q,accessTokenOwner:null}).rpc();const u=await o.provider.connection.getLatestBlockhash();await o.provider.connection.confirmTransaction({blockhash:u.blockhash,lastValidBlockHeight:u.lastValidBlockHeight,signature:a},"confirmed")}const k=await o.provider.connection.getTransaction(a,{commitment:"confirmed",maxSupportedTransactionVersion:0});if(!k)throw new Error("Transaction missing");await W.safeUpdateDepositAndWithdrawStatus(f,{id:I,hashedEthereumAddress:p,phase:B.DepositAndWithdrawPhase.AFTER_DEPOSIT,depositTxHash:a});const H=se.getUtxosFromReceiptSolana(k,o,e.userKeys),U=[],C=[...H];return l.forEach((t,s)=>{const q=h[s],u=C.find(X=>X.amount===q);if(!u)throw new Error(`Could not find newly created UTXO with amount ${q} for recipient ${t}.`);U.push({recipientAddress:t,utxo:u});const L=C.indexOf(u);C.splice(L,1)}),{userDepositedUtxos:U,depositTxHash:a,statusId:I}},le=async(e,r,d,l,g,p,h,m)=>{const S=e.getCurrentChainId();if(d.length===0)throw new Error("userDepositedUtxos must not be empty");const{hinkalIdl:i,originalDeployer:w}=j.networkRegistry[e.getCurrentChainId()].contractData;if(!w||!i)throw new Error("missing data");const P=e.getSolanaProgram(i),y=await e.getRandomRelay(!0);if(!y)throw new Error(Y.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const o=re.getCurrentTimeInSeconds().toString(),b=e.generateProofRemotely?5:1,n=[];for(let c=0;c<d.length;c+=b){const x=d.slice(c,c+b),O=await Promise.all(x.map(async({recipientAddress:D,utxo:F})=>{const{compressedAddress:R}=$.formatMintAddress(_.solanaNativeAddress),f=new z.Utxo({amount:0n,mintAddress:r,erc20TokenAddress:R,shieldedPrivateKey:e.userKeys.getShieldedPrivateKey(),timeStamp:o,tokenId:0}),v=[F,f],T=[f],K=z.Utxo.findCorrectRandomization(M.randomBigInt(31),e.userKeys.getShieldedPrivateKey()),a={tokenNumber:1,nullifierAmount:v.length,outputAmount:T.length},V=Z.calcEncryptedOutputs([T])[0][0],I=Array.from(G.ethers.getBytes(V)),{proofAArr:k,proofBArr:H,proofCArr:U,publicInputsArr:C}=await ie.constructSolanaZkProof(e.generateProofRemotely,w,e.merkleTreeHinkal,e.merkleTreeAccessToken,e.userKeys,P,[r],[v],[T],K,l.flatFee,l.variableRate,D,y,a,[I],e.getCurrentChainId(),void 0,void 0,void 0,void 0,void 0,!1),t=r===_.solanaNativeAddress,s={recipient:D,mint:t?void 0:r};return{relayAddress:y,functionName:"transact",args:{proofAArr:k,proofBArr:H,proofCArr:U,publicInputsArr:C,encryptedOutputs:[I],relayerFee:l.flatFee.toString(),dimensions:a},accounts:s}}));n.push(...O)}await W.safeUpdateDepositAndWithdrawStatus(S,{id:p,hashedEthereumAddress:g,phase:B.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});const A=await ce.solanaTransactCallRelayerBatch(e.getCurrentChainId(),n,g,h,m);return await W.safeUpdateDepositAndWithdrawStatus(S,{id:p,hashedEthereumAddress:g,phase:B.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:A}),A},ge=async(e,r,d,l,g,p,h)=>{const m=J.hashEthereumAddress(await e.getEthereumAddress()),S=e.getCurrentChainId(),i=p??await ue.getFeeStructure(S,r,[r],ee.ExternalActionId.Transact,[],0n),{userDepositedUtxos:w,statusId:P,depositTxHash:y}=await de(e,r,d,l,i,m);return await le(e,r,w,i,m,P,g,h),y};exports.hinkalSolanaDepositAndWithdraw=ge;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { randomBigInt as M } from "../../functions/web3/etherFunctions.mjs";
|
|
2
2
|
import { Utxo as z } from "../utxo/Utxo.mjs";
|
|
3
3
|
import { transactionErrorCodes as Y } from "../../error-handling/error-codes.constants.mjs";
|
|
4
|
-
import { ethers as Z } from "ethers";
|
|
5
4
|
import "idb-keyval";
|
|
6
5
|
import { networkRegistry as $ } from "../../constants/chains.constants.mjs";
|
|
6
|
+
import { ethers as Z } from "ethers";
|
|
7
7
|
import "../crypto-keys/keys.mjs";
|
|
8
8
|
import "node-forge";
|
|
9
9
|
import "../../constants/vite.constants.mjs";
|
|
@@ -20,7 +20,6 @@ import { API as G } from "../../API/API.mjs";
|
|
|
20
20
|
import "../../functions/utils/mutexes.utils.mjs";
|
|
21
21
|
import "../../types/circom-data.types.mjs";
|
|
22
22
|
import { ExternalActionId as J } from "../../types/external-action.types.mjs";
|
|
23
|
-
import "../../types/transactions.types.mjs";
|
|
24
23
|
import "../../types/activities.types.mjs";
|
|
25
24
|
import { DepositAndWithdrawPhase as k } from "../../types/scheduled-transactions.types.mjs";
|
|
26
25
|
import "../../functions/web3/events/getApprovedBalance.mjs";
|
|
@@ -41,10 +40,10 @@ import "process";
|
|
|
41
40
|
import "buffer";
|
|
42
41
|
import "../../constants/save-depths.mjs";
|
|
43
42
|
import { BN as Q } from "@coral-xyz/anchor";
|
|
44
|
-
import { getStorageAccountPublicKey as tt, getStorageVaultPublicKey as ot, getMerkleAccountPublicKey as rt, buildAnchorStealthAddressStructure as et, getTokenLimitStorageAccountPublicKey as
|
|
43
|
+
import { getStorageAccountPublicKey as tt, getStorageVaultPublicKey as ot, getMerkleAccountPublicKey as rt, buildAnchorStealthAddressStructure as et, getTokenLimitStorageAccountPublicKey as at } from "../../functions/pre-transaction/solana.mjs";
|
|
45
44
|
import "@solana/spl-token";
|
|
46
45
|
import "../../functions/utils/userAgent.mjs";
|
|
47
|
-
import { getCurrentTimeInSeconds as
|
|
46
|
+
import { getCurrentTimeInSeconds as it } from "../../functions/utils/time.utils.mjs";
|
|
48
47
|
import "multiformats";
|
|
49
48
|
import "../../API/tenderly.api.mjs";
|
|
50
49
|
import { calculateTotalFee as nt } from "../../functions/utils/fees.utils.mjs";
|
|
@@ -52,66 +51,66 @@ import "../../functions/web3/getTokenHolder.mjs";
|
|
|
52
51
|
import { signAndSendSerializedTransaction as st } from "../../functions/web3/signAndSendSerializedTransaction.mjs";
|
|
53
52
|
import { calcStealthAddressStructure as ct, calcEncryptedOutputs as mt } from "../../functions/snarkjs/common.snarkjs.mjs";
|
|
54
53
|
import { hinkalCheckSolanaTokenRegistry as pt } from "./hinkalCheckSolanaTokenRegistry.mjs";
|
|
55
|
-
import { getUtxosFromReceiptSolana as
|
|
56
|
-
import { constructSolanaZkProof as
|
|
54
|
+
import { getUtxosFromReceiptSolana as dt } from "../../functions/utils/getUtxosFromReceiptSolana.mjs";
|
|
55
|
+
import { constructSolanaZkProof as lt } from "../../functions/snarkjs/constructSolanaZkProof.mjs";
|
|
57
56
|
import { solanaTransactCallRelayerBatch as ut } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
|
|
58
57
|
import { getFeeStructure as gt } from "../../functions/pre-transaction/getFeeStructure.mjs";
|
|
59
58
|
import { updateDepositAndWithdrawStatus as ht, safeUpdateDepositAndWithdrawStatus as N } from "../../API/deposit-and-withdraw-status-calls.mjs";
|
|
60
|
-
const ft = async (t, r, p,
|
|
61
|
-
const g = p.map((o) => o + nt(o,
|
|
59
|
+
const ft = async (t, r, p, d, l, u) => {
|
|
60
|
+
const g = p.map((o) => o + nt(o, l)), {
|
|
62
61
|
hinkalIdl: h,
|
|
63
|
-
hinkalAddress:
|
|
62
|
+
hinkalAddress: S,
|
|
64
63
|
originalDeployer: s
|
|
65
64
|
} = $[t.getCurrentChainId()].contractData;
|
|
66
65
|
if (!h)
|
|
67
66
|
throw new Error("No IDL configured for Solana program on this network");
|
|
68
67
|
if (!s)
|
|
69
68
|
throw new Error("missing original deployer");
|
|
70
|
-
const f = t.userKeys.getShieldedPrivateKey(), E = z.findCorrectRandomization(M(31), f),
|
|
69
|
+
const f = t.userKeys.getShieldedPrivateKey(), E = z.findCorrectRandomization(M(31), f), w = ct(E, f), e = t.getSolanaProgram(h), v = t.getSolanaPublicKey(), a = new W(s), A = new W(S), { mintPublicKey: c } = q(r), x = c.toString(), H = tt(A, a), R = ot(A, a), F = rt(A, a), b = et(w), T = t.getCurrentChainId(), D = g.reduce((o, n) => o + n, 0n), I = await pt(
|
|
71
70
|
e,
|
|
72
|
-
new W(
|
|
71
|
+
new W(a),
|
|
73
72
|
[r],
|
|
74
73
|
[D]
|
|
75
74
|
), K = g.map((o) => `${o}`);
|
|
76
|
-
let
|
|
77
|
-
const P = (await ht(
|
|
75
|
+
let i = "";
|
|
76
|
+
const P = (await ht(T, {
|
|
78
77
|
hashedEthereumAddress: u,
|
|
79
78
|
phase: k.BEFORE_DEPOSIT
|
|
80
79
|
})).id ?? void 0;
|
|
81
|
-
if (
|
|
82
|
-
const { serializedTransaction: o, blockhash: n, lastValidBlockHeight:
|
|
83
|
-
|
|
80
|
+
if (I) {
|
|
81
|
+
const { serializedTransaction: o, blockhash: n, lastValidBlockHeight: y } = await G.generateMultiPaymentDepositLimitless(
|
|
82
|
+
T,
|
|
84
83
|
{
|
|
85
84
|
amounts: K,
|
|
86
85
|
payer: t.getSolanaPublicKey().toBase58(),
|
|
87
86
|
ethereumAddress: await t.getEthereumAddress(),
|
|
88
87
|
mint: r,
|
|
89
|
-
stealthAddressStructure:
|
|
88
|
+
stealthAddressStructure: b
|
|
90
89
|
}
|
|
91
90
|
), { wallet: m } = e.provider;
|
|
92
91
|
if (!m)
|
|
93
92
|
throw new Error("missing wallet");
|
|
94
|
-
|
|
93
|
+
i = await st(
|
|
95
94
|
e.provider,
|
|
96
95
|
o,
|
|
97
96
|
n,
|
|
98
|
-
|
|
97
|
+
y
|
|
99
98
|
);
|
|
100
99
|
} else {
|
|
101
|
-
const o =
|
|
102
|
-
|
|
100
|
+
const o = at(e.programId, a, c), n = x === U ? null : c, y = x === U ? null : void 0;
|
|
101
|
+
i = await e.methods.multiPaymentDeposit(
|
|
103
102
|
K.map((V) => new Q(V)),
|
|
104
|
-
|
|
103
|
+
b
|
|
105
104
|
).accounts({
|
|
106
105
|
mint: n,
|
|
107
106
|
signer: v,
|
|
108
|
-
signerAta:
|
|
109
|
-
originalDeployer:
|
|
110
|
-
storageAccount:
|
|
111
|
-
storageVault:
|
|
112
|
-
merkleAccount:
|
|
107
|
+
signerAta: y,
|
|
108
|
+
originalDeployer: a,
|
|
109
|
+
storageAccount: H,
|
|
110
|
+
storageVault: R,
|
|
111
|
+
merkleAccount: F,
|
|
113
112
|
tokenLimitStorage: o,
|
|
114
|
-
storageVaultAta:
|
|
113
|
+
storageVaultAta: y,
|
|
115
114
|
accessTokenOwner: null
|
|
116
115
|
}).rpc();
|
|
117
116
|
const m = await e.provider.connection.getLatestBlockhash();
|
|
@@ -119,64 +118,64 @@ const ft = async (t, r, p, l, d, u) => {
|
|
|
119
118
|
{
|
|
120
119
|
blockhash: m.blockhash,
|
|
121
120
|
lastValidBlockHeight: m.lastValidBlockHeight,
|
|
122
|
-
signature:
|
|
121
|
+
signature: i
|
|
123
122
|
},
|
|
124
123
|
"confirmed"
|
|
125
124
|
);
|
|
126
125
|
}
|
|
127
|
-
const B = await e.provider.connection.getTransaction(
|
|
126
|
+
const B = await e.provider.connection.getTransaction(i, {
|
|
128
127
|
commitment: "confirmed",
|
|
129
128
|
maxSupportedTransactionVersion: 0
|
|
130
129
|
});
|
|
131
130
|
if (!B)
|
|
132
131
|
throw new Error("Transaction missing");
|
|
133
|
-
await N(
|
|
132
|
+
await N(T, {
|
|
134
133
|
id: P,
|
|
135
134
|
hashedEthereumAddress: u,
|
|
136
135
|
phase: k.AFTER_DEPOSIT,
|
|
137
|
-
depositTxHash:
|
|
136
|
+
depositTxHash: i
|
|
138
137
|
});
|
|
139
|
-
const L =
|
|
140
|
-
return
|
|
141
|
-
const
|
|
138
|
+
const L = dt(B, e, t.userKeys), O = [], C = [...L];
|
|
139
|
+
return d.forEach((o, n) => {
|
|
140
|
+
const y = g[n], m = C.find((X) => X.amount === y);
|
|
142
141
|
if (!m)
|
|
143
|
-
throw new Error(`Could not find newly created UTXO with amount ${
|
|
142
|
+
throw new Error(`Could not find newly created UTXO with amount ${y} for recipient ${o}.`);
|
|
144
143
|
O.push({
|
|
145
144
|
recipientAddress: o,
|
|
146
145
|
utxo: m
|
|
147
146
|
});
|
|
148
147
|
const V = C.indexOf(m);
|
|
149
148
|
C.splice(V, 1);
|
|
150
|
-
}), { userDepositedUtxos: O,
|
|
151
|
-
}, wt = async (t, r, p,
|
|
152
|
-
const
|
|
149
|
+
}), { userDepositedUtxos: O, depositTxHash: i, statusId: P };
|
|
150
|
+
}, wt = async (t, r, p, d, l, u, g, h) => {
|
|
151
|
+
const S = t.getCurrentChainId();
|
|
153
152
|
if (p.length === 0)
|
|
154
153
|
throw new Error("userDepositedUtxos must not be empty");
|
|
155
154
|
const { hinkalIdl: s, originalDeployer: f } = $[t.getCurrentChainId()].contractData;
|
|
156
155
|
if (!f || !s)
|
|
157
156
|
throw new Error("missing data");
|
|
158
|
-
const E = t.getSolanaProgram(s),
|
|
159
|
-
if (!
|
|
157
|
+
const E = t.getSolanaProgram(s), w = await t.getRandomRelay(!0);
|
|
158
|
+
if (!w)
|
|
160
159
|
throw new Error(Y.RELAYER_NOT_AVAILABLE);
|
|
161
|
-
const e =
|
|
160
|
+
const e = it().toString(), v = t.generateProofRemotely ? 5 : 1, a = [];
|
|
162
161
|
for (let c = 0; c < p.length; c += v) {
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
const { compressedAddress:
|
|
162
|
+
const x = p.slice(c, c + v), H = await Promise.all(
|
|
163
|
+
x.map(async ({ recipientAddress: R, utxo: F }) => {
|
|
164
|
+
const { compressedAddress: b } = q(U), T = new z({
|
|
166
165
|
amount: 0n,
|
|
167
166
|
mintAddress: r,
|
|
168
|
-
erc20TokenAddress:
|
|
167
|
+
erc20TokenAddress: b,
|
|
169
168
|
shieldedPrivateKey: t.userKeys.getShieldedPrivateKey(),
|
|
170
169
|
timeStamp: e,
|
|
171
170
|
tokenId: 0
|
|
172
|
-
}), D = [
|
|
171
|
+
}), D = [F, T], I = [T], K = z.findCorrectRandomization(
|
|
173
172
|
M(31),
|
|
174
173
|
t.userKeys.getShieldedPrivateKey()
|
|
175
|
-
),
|
|
174
|
+
), i = {
|
|
176
175
|
tokenNumber: 1,
|
|
177
176
|
nullifierAmount: D.length,
|
|
178
|
-
outputAmount:
|
|
179
|
-
}, _ = mt([
|
|
177
|
+
outputAmount: I.length
|
|
178
|
+
}, _ = mt([I])[0][0], P = Array.from(Z.getBytes(_)), { proofAArr: B, proofBArr: L, proofCArr: O, publicInputsArr: C } = await lt(
|
|
180
179
|
t.generateProofRemotely,
|
|
181
180
|
f,
|
|
182
181
|
t.merkleTreeHinkal,
|
|
@@ -185,13 +184,13 @@ const ft = async (t, r, p, l, d, u) => {
|
|
|
185
184
|
E,
|
|
186
185
|
[r],
|
|
187
186
|
[D],
|
|
188
|
-
[
|
|
187
|
+
[I],
|
|
189
188
|
K,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
189
|
+
d.flatFee,
|
|
190
|
+
d.variableRate,
|
|
191
|
+
R,
|
|
192
|
+
w,
|
|
193
|
+
i,
|
|
195
194
|
[P],
|
|
196
195
|
t.getCurrentChainId(),
|
|
197
196
|
void 0,
|
|
@@ -201,11 +200,11 @@ const ft = async (t, r, p, l, d, u) => {
|
|
|
201
200
|
void 0,
|
|
202
201
|
!1
|
|
203
202
|
), n = {
|
|
204
|
-
recipient:
|
|
203
|
+
recipient: R,
|
|
205
204
|
mint: r === U ? void 0 : r
|
|
206
205
|
};
|
|
207
206
|
return {
|
|
208
|
-
relayAddress:
|
|
207
|
+
relayAddress: w,
|
|
209
208
|
functionName: "transact",
|
|
210
209
|
args: {
|
|
211
210
|
proofAArr: B,
|
|
@@ -213,39 +212,39 @@ const ft = async (t, r, p, l, d, u) => {
|
|
|
213
212
|
proofCArr: O,
|
|
214
213
|
publicInputsArr: C,
|
|
215
214
|
encryptedOutputs: [P],
|
|
216
|
-
relayerFee:
|
|
217
|
-
dimensions:
|
|
215
|
+
relayerFee: d.flatFee.toString(),
|
|
216
|
+
dimensions: i
|
|
218
217
|
},
|
|
219
218
|
accounts: n
|
|
220
219
|
};
|
|
221
220
|
})
|
|
222
221
|
);
|
|
223
|
-
|
|
222
|
+
a.push(...H);
|
|
224
223
|
}
|
|
225
|
-
await N(
|
|
224
|
+
await N(S, {
|
|
226
225
|
id: u,
|
|
227
|
-
hashedEthereumAddress:
|
|
226
|
+
hashedEthereumAddress: l,
|
|
228
227
|
phase: k.BEFORE_SCHEDULE_WITHDRAW
|
|
229
228
|
});
|
|
230
229
|
const A = await ut(
|
|
231
230
|
t.getCurrentChainId(),
|
|
232
|
-
|
|
233
|
-
|
|
231
|
+
a,
|
|
232
|
+
l,
|
|
234
233
|
g,
|
|
235
234
|
h
|
|
236
235
|
);
|
|
237
|
-
return await N(
|
|
236
|
+
return await N(S, {
|
|
238
237
|
id: u,
|
|
239
|
-
hashedEthereumAddress:
|
|
238
|
+
hashedEthereumAddress: l,
|
|
240
239
|
phase: k.AFTER_SCHEDULE_WITHDRAW,
|
|
241
240
|
scheduleId: A
|
|
242
241
|
}), A;
|
|
243
|
-
},
|
|
244
|
-
const h = j(await t.getEthereumAddress()),
|
|
242
|
+
}, Io = async (t, r, p, d, l, u, g) => {
|
|
243
|
+
const h = j(await t.getEthereumAddress()), S = t.getCurrentChainId(), s = u ?? await gt(S, r, [r], J.Transact, [], 0n), { userDepositedUtxos: f, statusId: E, depositTxHash: w } = await ft(
|
|
245
244
|
t,
|
|
246
245
|
r,
|
|
247
246
|
p,
|
|
248
|
-
|
|
247
|
+
d,
|
|
249
248
|
s,
|
|
250
249
|
h
|
|
251
250
|
);
|
|
@@ -256,10 +255,10 @@ const ft = async (t, r, p, l, d, u) => {
|
|
|
256
255
|
s,
|
|
257
256
|
h,
|
|
258
257
|
E,
|
|
259
|
-
|
|
258
|
+
l,
|
|
260
259
|
g
|
|
261
|
-
);
|
|
260
|
+
), w;
|
|
262
261
|
};
|
|
263
262
|
export {
|
|
264
|
-
|
|
263
|
+
Io as hinkalSolanaDepositAndWithdraw
|
|
265
264
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../../types/circom-data.types.cjs");const ne=require("../../types/external-action.types.cjs"),y=require("../../constants/protocol.constants.cjs");require("../../types/
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../../types/circom-data.types.cjs");const ne=require("../../types/external-action.types.cjs"),y=require("../../constants/protocol.constants.cjs");require("../../types/activities.types.cjs");const se=require("../../types/cache.types.cjs"),ce=require("../../functions/web3/events/getShieldedBalance.cjs"),ae=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),ie=require("../../functions/utils/time.utils.cjs"),ue=require("../../functions/pre-transaction/getFeeStructure.cjs"),le=require("../../functions/snarkjs/common.snarkjs.cjs"),de=require("../../constants/chains.constants.cjs"),c=require("@solana/web3.js"),m=require("../../functions/pre-transaction/solana.cjs"),pe=require("../../functions/snarkjs/constructSolanaZkProof.cjs"),ge=require("../utxo/Utxo.cjs"),S=require("../../functions/web3/etherFunctions.cjs"),Ae=require("../../functions/pre-transaction/convert-okx-instructions.cjs"),ye=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),me=require("../../error-handling/error-codes.constants.cjs"),Se=require("../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs"),we=require("ethers"),Pe=async(t,o,r,w,K,x,E,R,v=!1)=>{if(v)throw new Error("onlyGasEstimate is not supported for Solana swap");const a=t.getCurrentChainId(),P=new c.PublicKey(y.solanaNativeAddress),{hinkalAddress:F,originalDeployer:i,hinkalIdl:f}=de.networkRegistry[a].contractData;if(!i||!f)throw new Error("No IDL configured for Solana program on this network");const u=new c.PublicKey(i),l=new c.PublicKey(F),n=o.map(e=>e.erc20TokenAddress),{userKeys:b,merkleTreeAccessToken:_,merkleTreeHinkal:N}=t,O=t.getSolanaProgram(f),s=R??await ue.getFeeStructure(a,E,n,ne.ExternalActionId.Transact),{patchAccessTokenMerkleTree:U,kycRequired:D,hasAccessToken:B}=await Se.shouldPatchAccessTokenMerkleTree(t,n,r);r[1]-=s.flatFee;const C=s.variableRate.toString(),L=Number(t.cacheDevice.get(se.StorageKeys.SLIPPAGE_PERCENTAGE)??0),d=o[1],M=S.getAmountInToken(d,r[1]),V=Number(M)*L/100;r[1]-=S.getAmountInWei(d,V.toFixed(d.decimals));const p=[...await ce.addPaddingToUtxos(t,n,r,6)],j=ie.getCurrentTimeInSeconds().toString(),G=t.userKeys.getShieldedPrivateKey(),g=[];for(let e=0;e<n.length;e+=1){const{outputUtxos:oe}=ae.outputUtxoProcessing(t.userKeys,p[e],r[e],j,void 0,!1);g.push([oe[0]])}const W=ge.Utxo.findCorrectRandomization(S.randomBigInt(31),G),T={tokenNumber:2,nullifierAmount:p[0].length,outputAmount:1},z=[!1,!0].slice(0,r.length),A=await t.getRandomRelay(!0);if(!A)throw Error(me.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const k=le.calcEncryptedOutputs(g).map(e=>[...we.ethers.getBytes(e[0])]),q=m.getSwapperAccountPublicKeyFromSalt(l,u,w),{remainingAccounts:I,hinkalInstructions:h}=Ae.convertOKXToHinkalInstructions(K,q),{proofAArr:H,proofBArr:Z,proofCArr:X,publicInputsArr:Y}=await pe.constructSolanaZkProof(t.generateProofRemotely,i,N,_,b,O,n,p,g,W,s.flatFee,s.variableRate,P.toString(),A,T,k,a,U,z,w,h,I),J=m.getStorageAccountPublicKey(l,u),Q=m.getStorageVaultPublicKey(l,u),$=o[0].erc20TokenAddress!==y.solanaNativeAddress?new c.PublicKey(o[0].erc20TokenAddress):null,ee=o[1].erc20TokenAddress!==y.solanaNativeAddress?new c.PublicKey(o[1].erc20TokenAddress):null,te={recipient:P.toString(),storageAccount:J.toString(),storageVault:Q.toString(),swapperAccount:q.toString(),mintFrom:$?.toString()??null,mintTo:ee?.toString()??null,remainingAccounts:I.map(e=>({pubkey:e.pubkey.toString(),isSigner:e.isSigner,isWritable:e.isWritable})),addressLookupTableAccount:x},re={encryptedOutputs:k,proofAArr:H,proofBArr:Z,proofCArr:X,publicInputsArr:Y,relayerFee:s.flatFee.toString(),variableRate:C,dimensions:T,hinkalInstructions:h.map(e=>({accountIndexes:[...e.accountIndexes],data:[...e.data],programIndex:e.programIndex}))};return ye.solanaTransactCallRelayer(a,{relayAddress:A,functionName:"swap",args:re,accounts:te,solanaAccessTokenData:!B&&D?{ethereumAddress:await t.getEthereumAddress(),accessKey:b.getAccessKey()}:void 0})};exports.hinkalSolanaSwap=Pe;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import "../../types/circom-data.types.mjs";
|
|
2
|
-
import { ExternalActionId as
|
|
2
|
+
import { ExternalActionId as ot } from "../../types/external-action.types.mjs";
|
|
3
3
|
import { solanaNativeAddress as A } from "../../constants/protocol.constants.mjs";
|
|
4
|
-
import "../../types/transactions.types.mjs";
|
|
5
4
|
import "../../types/activities.types.mjs";
|
|
6
|
-
import { StorageKeys as
|
|
5
|
+
import { StorageKeys as rt } from "../../types/cache.types.mjs";
|
|
7
6
|
import { addPaddingToUtxos as nt } from "../../functions/web3/events/getShieldedBalance.mjs";
|
|
8
7
|
import { outputUtxoProcessing as st } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
|
|
9
8
|
import { getCurrentTimeInSeconds as at } from "../../functions/utils/time.utils.mjs";
|
|
@@ -20,26 +19,26 @@ import { solanaTransactCallRelayer as wt } from "../../functions/web3/functionCa
|
|
|
20
19
|
import { transactionErrorCodes as Tt } from "../../error-handling/error-codes.constants.mjs";
|
|
21
20
|
import { shouldPatchAccessTokenMerkleTree as It } from "../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.mjs";
|
|
22
21
|
import { ethers as Pt } from "ethers";
|
|
23
|
-
const
|
|
22
|
+
const Mt = async (e, r, o, f, E, x, K, R, h = !1) => {
|
|
24
23
|
if (h)
|
|
25
24
|
throw new Error("onlyGasEstimate is not supported for Solana swap");
|
|
26
25
|
const i = e.getCurrentChainId(), y = new a(A), { hinkalAddress: v, originalDeployer: c, hinkalIdl: S } = mt[i].contractData;
|
|
27
26
|
if (!c || !S)
|
|
28
27
|
throw new Error("No IDL configured for Solana program on this network");
|
|
29
|
-
const m = new a(c), u = new a(v), n =
|
|
28
|
+
const m = new a(c), u = new a(v), n = r.map((t) => t.erc20TokenAddress), { userKeys: w, merkleTreeAccessToken: F, merkleTreeHinkal: N } = e, D = e.getSolanaProgram(S), s = R ?? await it(i, K, n, ot.Transact), { patchAccessTokenMerkleTree: O, kycRequired: U, hasAccessToken: B } = await It(
|
|
30
29
|
e,
|
|
31
30
|
n,
|
|
32
|
-
|
|
31
|
+
o
|
|
33
32
|
);
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
const l = [...await nt(e, n,
|
|
33
|
+
o[1] -= s.flatFee;
|
|
34
|
+
const L = s.variableRate.toString(), C = Number(e.cacheDevice.get(rt.SLIPPAGE_PERCENTAGE) ?? 0), p = r[1], V = At(p, o[1]), G = Number(V) * C / 100;
|
|
35
|
+
o[1] -= ft(p, G.toFixed(p.decimals));
|
|
36
|
+
const l = [...await nt(e, n, o, 6)], W = at().toString(), _ = e.userKeys.getShieldedPrivateKey(), d = [];
|
|
38
37
|
for (let t = 0; t < n.length; t += 1) {
|
|
39
38
|
const { outputUtxos: et } = st(
|
|
40
39
|
e.userKeys,
|
|
41
40
|
l[t],
|
|
42
|
-
|
|
41
|
+
o[t],
|
|
43
42
|
W,
|
|
44
43
|
void 0,
|
|
45
44
|
!1
|
|
@@ -50,10 +49,10 @@ const qt = async (e, o, r, f, E, x, K, R, h = !1) => {
|
|
|
50
49
|
tokenNumber: 2,
|
|
51
50
|
nullifierAmount: l[0].length,
|
|
52
51
|
outputAmount: 1
|
|
53
|
-
}, H = [!1, !0].slice(0,
|
|
52
|
+
}, H = [!1, !0].slice(0, o.length), g = await e.getRandomRelay(!0);
|
|
54
53
|
if (!g)
|
|
55
54
|
throw Error(Tt.RELAYER_NOT_AVAILABLE);
|
|
56
|
-
const I = ct(d).map((t) => [...Pt.
|
|
55
|
+
const I = ct(d).map((t) => [...Pt.getBytes(t[0])]), P = ut(u, m, f), { remainingAccounts: b, hinkalInstructions: k } = St(E, P), { proofAArr: M, proofBArr: q, proofCArr: X, publicInputsArr: Y } = await dt(
|
|
57
56
|
e.generateProofRemotely,
|
|
58
57
|
c,
|
|
59
58
|
N,
|
|
@@ -76,7 +75,7 @@ const qt = async (e, o, r, f, E, x, K, R, h = !1) => {
|
|
|
76
75
|
f,
|
|
77
76
|
k,
|
|
78
77
|
b
|
|
79
|
-
), Z = pt(u, m), j = lt(u, m), J =
|
|
78
|
+
), Z = pt(u, m), j = lt(u, m), J = r[0].erc20TokenAddress !== A ? new a(r[0].erc20TokenAddress) : null, Q = r[1].erc20TokenAddress !== A ? new a(r[1].erc20TokenAddress) : null, $ = {
|
|
80
79
|
recipient: y.toString(),
|
|
81
80
|
storageAccount: Z.toString(),
|
|
82
81
|
storageVault: j.toString(),
|
|
@@ -96,7 +95,7 @@ const qt = async (e, o, r, f, E, x, K, R, h = !1) => {
|
|
|
96
95
|
proofCArr: X,
|
|
97
96
|
publicInputsArr: Y,
|
|
98
97
|
relayerFee: s.flatFee.toString(),
|
|
99
|
-
variableRate:
|
|
98
|
+
variableRate: L,
|
|
100
99
|
dimensions: T,
|
|
101
100
|
hinkalInstructions: k.map((t) => ({
|
|
102
101
|
accountIndexes: [...t.accountIndexes],
|
|
@@ -109,12 +108,12 @@ const qt = async (e, o, r, f, E, x, K, R, h = !1) => {
|
|
|
109
108
|
functionName: "swap",
|
|
110
109
|
args: tt,
|
|
111
110
|
accounts: $,
|
|
112
|
-
solanaAccessTokenData: !
|
|
111
|
+
solanaAccessTokenData: !B && U ? {
|
|
113
112
|
ethereumAddress: await e.getEthereumAddress(),
|
|
114
113
|
accessKey: w.getAccessKey()
|
|
115
114
|
} : void 0
|
|
116
115
|
});
|
|
117
116
|
};
|
|
118
117
|
export {
|
|
119
|
-
|
|
118
|
+
Mt as hinkalSolanaSwap
|
|
120
119
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../../types/circom-data.types.cjs");const z=require("../../types/external-action.types.cjs"),c=require("../../constants/protocol.constants.cjs");require("../../types/
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../../types/circom-data.types.cjs");const z=require("../../types/external-action.types.cjs"),c=require("../../constants/protocol.constants.cjs");require("../../types/activities.types.cjs");const D=require("../../functions/web3/events/getShieldedBalance.cjs"),M=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),j=require("../../functions/utils/time.utils.cjs"),u=require("../../error-handling/error-codes.constants.cjs"),H=require("../../functions/pre-transaction/getFeeStructure.cjs"),Z=require("../../functions/snarkjs/common.snarkjs.cjs"),Y=require("../../functions/snarkjs/constructSolanaZkProof.cjs"),I=require("../utxo/Utxo.cjs"),G=require("../../functions/web3/etherFunctions.cjs"),J=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),Q=require("../../functions/utils/addresses.cjs"),W=require("../../constants/chains.constants.cjs"),X=require("ethers"),$=async(e,R,r,d,S,q,l=!1)=>{if(l)throw new Error("onlyGasEstimate is not supported for Solana transfer");if(!Q.isValidPrivateAddress(d))throw Error(u.transactionErrorCodes.RECIPIENT_FORMAT_INCORRECT);const n=e.getCurrentChainId(),{originalDeployer:p,hinkalIdl:A}=W.networkRegistry[n].contractData;if(!p||!A)throw new Error("missing data");const{userKeys:_,merkleTreeAccessToken:w,merkleTreeHinkal:x}=e,t=R.map(i=>i.erc20TokenAddress);if(t.length>1)throw new Error("Solana Transfer: Only one mint address is supported");const N=q??await H.getFeeStructure(n,S,t,z.ExternalActionId.Transact),a=-r[0]*(10000n-c.HINKAL_PRIVATE_SEND_VARIABLE_RATE)/10000n;if(r[0]-=N.flatFee,a<=0n)throw Error(u.transactionErrorCodes.RECIPIENT_AMOUNT_INVALID);const m=-r[0]-a,o=(await D.addPaddingToUtxos(e,t,r,6))[0],y=j.getCurrentTimeInSeconds().toString(),{outputUtxos:P}=M.outputUtxoProcessing(e.userKeys,o,r[0],y,void 0,!1),f=P[0],[C,O,U]=d.split(","),g=new I.Utxo({amount:a,erc20TokenAddress:o[0].erc20TokenAddress,mintAddress:o[0].mintAddress,timeStamp:y,randomization:BigInt(C),stealthAddress:O,encryptionKey:U}),s=await e.getRandomRelay(!l);if(!s)throw Error(u.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const h=I.Utxo.findCorrectRandomization(G.randomBigInt(31),e.userKeys.getShieldedPrivateKey()),E={tokenNumber:t.length,nullifierAmount:o.length,outputAmount:2},k=e.getSolanaProgram(A),T=Z.calcEncryptedOutputs([[f,g]])[0].map(i=>Array.from(X.ethers.getBytes(i))),{proofAArr:v,proofBArr:B,proofCArr:F,publicInputsArr:K}=await Y.constructSolanaZkProof(e.generateProofRemotely,p,x,w,_,k,[t[0]],[o],[[f,g]],h,m,0n,c.solanaNativeAddress,s,E,T,n),L=t[0]===c.solanaNativeAddress,V={recipient:s,mint:L?void 0:t[0]},b={proofAArr:v,proofBArr:B,proofCArr:F,publicInputsArr:K,encryptedOutputs:T,relayerFee:m.toString(),dimensions:E};return J.solanaTransactCallRelayer(n,{relayAddress:s,functionName:"transfer",args:b,accounts:V})};exports.hinkalSolanaTransfer=$;
|