@hinkal/common 0.3.13 → 0.3.14
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/README.md +67 -4
- package/common/src/API/API.cjs +1 -1
- package/common/src/API/API.d.ts +0 -2
- package/common/src/API/API.mjs +92 -94
- package/common/src/API/admin-calls.cjs +1 -1
- package/common/src/API/admin-calls.d.ts +2 -1
- package/common/src/API/admin-calls.mjs +1 -0
- package/common/src/API/evm-token-assets.cjs +1 -1
- package/common/src/API/evm-token-assets.mjs +2 -13
- package/common/src/API/get-token-price-chart-data.cjs +1 -1
- package/common/src/API/get-token-price-chart-data.mjs +2 -2
- package/common/src/API/getTokenPrice.cjs +1 -1
- package/common/src/API/getTokenPrice.mjs +2 -2
- package/common/src/API/index.cjs +1 -1
- package/common/src/API/index.d.ts +1 -0
- package/common/src/API/index.mjs +1 -0
- package/common/src/API/privacy-score-calls.cjs +1 -1
- package/common/src/API/privacy-score-calls.mjs +2 -2
- package/common/src/API/receiveVaultCalls.cjs +1 -1
- package/common/src/API/receiveVaultCalls.d.ts +4 -2
- package/common/src/API/receiveVaultCalls.mjs +8 -4
- package/common/src/constants/chains.constants.cjs +1 -1
- package/common/src/constants/chains.constants.d.ts +2 -0
- package/common/src/constants/chains.constants.mjs +106 -93
- package/common/src/constants/coingecko.constants.cjs +1 -1
- package/common/src/constants/coingecko.constants.d.ts +2 -0
- package/common/src/constants/coingecko.constants.mjs +1 -1
- package/common/src/constants/deploy-data/deploy-data-arbMainnet.json.cjs +1 -1
- package/common/src/constants/deploy-data/deploy-data-arbMainnet.json.mjs +2 -1
- package/common/src/constants/deploy-data/deploy-data-arcTestnet.json.cjs +1 -1
- package/common/src/constants/deploy-data/deploy-data-arcTestnet.json.mjs +3 -2
- package/common/src/constants/deploy-data/deploy-data-base.json.cjs +1 -1
- package/common/src/constants/deploy-data/deploy-data-base.json.mjs +2 -1
- package/common/src/constants/deploy-data/deploy-data-bnbMainnet.json.cjs +1 -1
- package/common/src/constants/deploy-data/deploy-data-bnbMainnet.json.mjs +2 -1
- package/common/src/constants/deploy-data/deploy-data-ethMainnet.json.cjs +1 -1
- package/common/src/constants/deploy-data/deploy-data-ethMainnet.json.mjs +2 -1
- package/common/src/constants/deploy-data/deploy-data-polygon.json.cjs +1 -1
- package/common/src/constants/deploy-data/deploy-data-polygon.json.mjs +2 -1
- package/common/src/constants/deploy-data/deploy-data-solanaDevnet.json.cjs +1 -0
- package/common/src/constants/deploy-data/deploy-data-solanaDevnet.json.mjs +6 -0
- package/common/src/constants/deploy-data/deploy-data-tempo.json.cjs +1 -1
- package/common/src/constants/deploy-data/deploy-data-tempo.json.mjs +2 -1
- package/common/src/constants/deploy-data/deploy-data-tronMainnet.json.cjs +1 -1
- package/common/src/constants/deploy-data/deploy-data-tronMainnet.json.mjs +1 -1
- package/common/src/constants/deploy-data/deploy-data-tronNile.json.cjs +1 -1
- package/common/src/constants/deploy-data/deploy-data-tronNile.json.mjs +1 -1
- package/common/src/constants/deploy-data/index.cjs +1 -1
- package/common/src/constants/deploy-data/index.d.ts +2 -1
- package/common/src/constants/deploy-data/index.mjs +7 -6
- package/common/src/constants/deploy-data/shared-deploy-data-evm.json.cjs +1 -1
- package/common/src/constants/deploy-data/shared-deploy-data-evm.json.mjs +1 -1
- package/common/src/constants/deploy-data/shared-deploy-data-solana.json.cjs +1 -1
- package/common/src/constants/deploy-data/shared-deploy-data-solana.json.mjs +1 -1
- package/common/src/constants/deploy-data/shared-deploy-data-tron.json.cjs +1 -1
- package/common/src/constants/deploy-data/shared-deploy-data-tron.json.mjs +1 -1
- package/common/src/constants/index.cjs +1 -1
- package/common/src/constants/index.mjs +1 -1
- package/common/src/constants/protocol.constants.cjs +2 -2
- package/common/src/constants/protocol.constants.d.ts +0 -2
- package/common/src/constants/protocol.constants.mjs +2 -2
- package/common/src/constants/save-depths.cjs +1 -1
- package/common/src/constants/save-depths.d.ts +1 -0
- package/common/src/constants/save-depths.mjs +1 -0
- package/common/src/constants/server.constants.cjs +1 -1
- package/common/src/constants/server.constants.d.ts +8 -6
- package/common/src/constants/server.constants.mjs +8 -6
- package/common/src/constants/tokens.constants.cjs +1 -1
- package/common/src/constants/tokens.constants.mjs +1 -1
- package/common/src/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/common/src/data-structures/Hinkal/Hinkal.d.ts +4 -4
- package/common/src/data-structures/Hinkal/Hinkal.mjs +37 -37
- package/common/src/data-structures/Hinkal/IHinkal.d.ts +4 -4
- package/common/src/data-structures/Hinkal/handleAutoDepositBack.cjs +1 -1
- package/common/src/data-structures/Hinkal/handleAutoDepositBack.mjs +5 -5
- package/common/src/data-structures/Hinkal/hinkalBridgePrivateToPrivate.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalBridgePrivateToPrivate.mjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalDepositAndBridge.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalDepositAndBridge.mjs +55 -54
- package/common/src/data-structures/Hinkal/hinkalDepositAndWithdraw.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalDepositAndWithdraw.mjs +60 -57
- package/common/src/data-structures/Hinkal/hinkalPrivateWallet.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalPrivateWallet.d.ts +1 -1
- package/common/src/data-structures/Hinkal/hinkalPrivateWallet.mjs +29 -29
- package/common/src/data-structures/Hinkal/hinkalProoflessDeposit.utils.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalProoflessDeposit.utils.mjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalProxySwap.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalProxySwap.mjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalReceiveVaultAccount.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalReceiveVaultAccount.mjs +7 -15
- package/common/src/data-structures/Hinkal/hinkalReceiveVaultCreate.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalReceiveVaultCreate.d.ts +2 -2
- package/common/src/data-structures/Hinkal/hinkalReceiveVaultCreate.mjs +24 -28
- package/common/src/data-structures/Hinkal/hinkalReceiveVaultRecover.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalReceiveVaultRecover.mjs +47 -40
- package/common/src/data-structures/Hinkal/hinkalReceiveVaultSettle.d.ts +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaDeposit.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaDeposit.mjs +22 -42
- package/common/src/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.mjs +72 -70
- package/common/src/data-structures/Hinkal/hinkalSolanaProxySend.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaProxySend.mjs +9 -9
- package/common/src/data-structures/Hinkal/hinkalSolanaProxyShield.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaProxyShield.mjs +15 -15
- package/common/src/data-structures/Hinkal/hinkalSolanaProxySwap.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaProxySwap.d.ts +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaProxySwap.mjs +47 -45
- package/common/src/data-structures/Hinkal/hinkalSolanaReceiveVault.cjs +1 -0
- package/common/src/data-structures/Hinkal/hinkalSolanaReceiveVault.d.ts +5 -0
- package/common/src/data-structures/Hinkal/hinkalSolanaReceiveVault.mjs +60 -0
- package/common/src/data-structures/Hinkal/hinkalWithdraw.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalWithdraw.mjs +35 -26
- package/common/src/data-structures/Hinkal/index.d.ts +1 -0
- package/common/src/data-structures/Hinkal/resetMerkleTrees.cjs +1 -1
- package/common/src/data-structures/Hinkal/resetMerkleTrees.mjs +13 -13
- package/common/src/error-handling/error-codes.constants.cjs +1 -1
- package/common/src/error-handling/error-codes.constants.d.ts +2 -0
- package/common/src/error-handling/error-codes.constants.mjs +2 -0
- package/common/src/error-handling/get-error.message.cjs +1 -1
- package/common/src/error-handling/get-error.message.mjs +10 -1
- package/common/src/functions/index.cjs +1 -1
- package/common/src/functions/index.mjs +6 -2
- package/common/src/functions/pre-transaction/addressTableLookup.d.ts +1 -0
- package/common/src/functions/pre-transaction/calculateSolanaNullifierCount.cjs +1 -1
- package/common/src/functions/pre-transaction/calculateSolanaNullifierCount.mjs +7 -7
- package/common/src/functions/pre-transaction/constructAdminData.cjs +1 -1
- package/common/src/functions/pre-transaction/constructAdminData.mjs +4 -3
- package/common/src/functions/pre-transaction/sendV0Transaction.cjs +1 -1
- package/common/src/functions/pre-transaction/sendV0Transaction.d.ts +1 -0
- package/common/src/functions/pre-transaction/sendV0Transaction.mjs +22 -2
- package/common/src/functions/private-wallet/emporium.helpers.cjs +1 -1
- package/common/src/functions/private-wallet/emporium.helpers.mjs +15 -15
- package/common/src/functions/snarkjs/fetchOnChainRootHashes.cjs +1 -1
- package/common/src/functions/snarkjs/fetchOnChainRootHashes.mjs +6 -6
- package/common/src/functions/utils/addresses.cjs +1 -1
- package/common/src/functions/utils/addresses.d.ts +4 -0
- package/common/src/functions/utils/addresses.mjs +17 -17
- package/common/src/functions/utils/admin-dimensions.cjs +1 -0
- package/common/src/functions/utils/admin-dimensions.d.ts +4 -0
- package/common/src/functions/utils/admin-dimensions.mjs +206 -0
- package/common/src/functions/utils/create-provider.cjs +1 -1
- package/common/src/functions/utils/create-provider.mjs +5 -1
- package/common/src/functions/utils/fees.utils.cjs +1 -1
- package/common/src/functions/utils/fees.utils.d.ts +2 -0
- package/common/src/functions/utils/fees.utils.mjs +31 -33
- package/common/src/functions/utils/gas-token.utils.cjs +1 -0
- package/common/src/functions/utils/gas-token.utils.d.ts +3 -0
- package/common/src/functions/utils/gas-token.utils.mjs +7 -0
- package/common/src/functions/utils/getUtxosFromReceiptSolana.d.ts +9 -4
- package/common/src/functions/utils/index.cjs +1 -1
- package/common/src/functions/utils/index.d.ts +4 -0
- package/common/src/functions/utils/index.mjs +5 -1
- package/common/src/functions/utils/publicBalance.utils.cjs +1 -1
- package/common/src/functions/utils/publicBalance.utils.mjs +7 -7
- package/common/src/functions/utils/receive-vault-account.utils.cjs +1 -1
- package/common/src/functions/utils/receive-vault-account.utils.d.ts +2 -1
- package/common/src/functions/utils/receive-vault-account.utils.mjs +16 -15
- package/common/src/functions/utils/receive-vault-scan.utils.cjs +1 -1
- package/common/src/functions/utils/receive-vault-scan.utils.mjs +37 -42
- package/common/src/functions/utils/receive-vault-solana.utils.cjs +1 -0
- package/common/src/functions/utils/receive-vault-solana.utils.d.ts +8 -0
- package/common/src/functions/utils/receive-vault-solana.utils.mjs +45 -0
- package/common/src/functions/utils/receive-vault.utils.cjs +2 -2
- package/common/src/functions/utils/receive-vault.utils.d.ts +13 -11
- package/common/src/functions/utils/receive-vault.utils.mjs +97 -82
- package/common/src/functions/utils/token-check.utils.d.ts +1 -0
- package/common/src/functions/utils/wallet-token-discovery.utils.cjs +1 -1
- package/common/src/functions/utils/wallet-token-discovery.utils.d.ts +5 -0
- package/common/src/functions/utils/wallet-token-discovery.utils.mjs +25 -31
- package/common/src/functions/web3/getContractMetadata.cjs +1 -1
- package/common/src/functions/web3/getContractMetadata.mjs +6 -6
- package/common/src/functions/web3/index.cjs +1 -1
- package/common/src/functions/web3/index.mjs +1 -1
- package/common/src/types/admin.types.cjs +1 -1
- package/common/src/types/admin.types.d.ts +64 -9
- package/common/src/types/admin.types.mjs +10 -2
- package/common/src/types/connector.types.d.ts +1 -0
- package/common/src/types/ethereum-network.types.d.ts +1 -0
- package/common/src/types/external-action.types.cjs +1 -1
- package/common/src/types/external-action.types.d.ts +2 -1
- package/common/src/types/external-action.types.mjs +1 -1
- package/common/src/types/receive-vault.types.cjs +1 -1
- package/common/src/types/receive-vault.types.d.ts +15 -20
- package/common/src/types/receive-vault.types.mjs +4 -2
- package/common/src/webworker/{logError-BeXPKuv9.js → logError-C-ej_TX9.js} +1 -1
- package/common/src/webworker/package.json +1 -1
- package/common/src/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.cjs +1 -1
- package/common/src/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.mjs +1 -1
- package/common/src/webworker/snarkjsWorkerNode.cjs +1 -1
- package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.cjs +1 -1
- package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.mjs +1 -1
- package/common/src/webworker/utxoWorkerNode.cjs +1 -1
- package/common/src/webworker/viteWorkerURL.constant.cjs +3 -3
- package/common/src/webworker/viteWorkerURL.constant.mjs +3 -3
- package/common/src/webworker/workerProxy-CE-rYA3W.js +1 -0
- package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.cjs +1 -1
- package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.mjs +1 -1
- package/common/src/webworker/zkProofWorkerNode.cjs +1 -1
- package/index.cjs +1 -1
- package/index.mjs +3 -2
- package/internal/monitorConnectedAddress.cjs +1 -1
- package/internal/monitorConnectedAddress.d.ts +1 -1
- package/internal/monitorConnectedAddress.mjs +1 -3
- package/package.json +1 -1
- package/providers/prepareEthersHinkal.cjs +1 -1
- package/providers/prepareEthersHinkal.mjs +1 -1
- package/providers/prepareSolanaHinkal.cjs +1 -1
- package/providers/prepareSolanaHinkal.mjs +1 -1
- package/providers/prepareTronHinkal.cjs +1 -1
- package/providers/prepareTronHinkal.mjs +1 -1
- package/providers/prepareWagmiHinkal.cjs +1 -1
- package/providers/prepareWagmiHinkal.mjs +1 -1
- package/services/Hinkal.cjs +1 -1
- package/services/Hinkal.d.ts +6 -2
- package/services/Hinkal.mjs +74 -51
- package/types/IHinkal.d.ts +6 -1
- package/types/index.cjs +1 -1
- package/types/index.d.ts +1 -0
- package/types/index.mjs +2 -0
- package/types/receive-vault.types.cjs +1 -0
- package/types/receive-vault.types.d.ts +14 -0
- package/types/receive-vault.types.mjs +2 -0
- package/common/src/API/getOdosPriceForToken.cjs +0 -1
- package/common/src/API/getOdosPriceForToken.d.ts +0 -1
- package/common/src/API/getOdosPriceForToken.mjs +0 -14
- package/common/src/webworker/workerProxy-DF35H7vU.js +0 -1
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { networkRegistry as e } from "../../constants/chains.constants.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { createCustomSolanaConnection as t } from "../../functions/utils/create-provider.mjs";
|
|
3
|
+
import { validateAndGetChainId as n } from "../../functions/utils/token-check.utils.mjs";
|
|
4
|
+
import { constructAdminData as r } from "../../functions/pre-transaction/constructAdminData.mjs";
|
|
5
5
|
import { AccountActions as i } from "../AccountActions/AccountActions.mjs";
|
|
6
6
|
import { sendProxyV0Transaction as a } from "../../functions/pre-transaction/sendV0Transaction.mjs";
|
|
7
7
|
import { emitTxPublicData as o } from "../../API/admin-calls.mjs";
|
|
8
8
|
import { buildSolanaTransferInstructions as s } from "../../functions/pre-transaction/solanaTransfer.utils.mjs";
|
|
9
9
|
import { PublicKey as c } from "@solana/web3.js";
|
|
10
10
|
//#region libs/shared/common/src/data-structures/Hinkal/hinkalSolanaProxySend.ts
|
|
11
|
-
var l = async (
|
|
12
|
-
let u =
|
|
11
|
+
var l = async (r, a, o, l) => {
|
|
12
|
+
let u = n([r]), d = i.getAddressFromSubAccount(u, o);
|
|
13
13
|
if (!d) throw Error("Public account address is not available");
|
|
14
|
-
let { rpcUrl: f } = e[u], p =
|
|
14
|
+
let { rpcUrl: f } = e[u], p = t(f), m = new c(d), { instructions: h, programId: g } = await s(p, m, new c(l), r, a);
|
|
15
15
|
return {
|
|
16
16
|
connection: p,
|
|
17
17
|
chainId: u,
|
|
@@ -20,15 +20,15 @@ var l = async (n, a, o, l) => {
|
|
|
20
20
|
programId: g,
|
|
21
21
|
instructions: h
|
|
22
22
|
};
|
|
23
|
-
}, u = async (e, t,
|
|
24
|
-
let [{ connection: u, chainId: d, senderPublickey: f, instructions: p }, m] = await Promise.all([l(t,
|
|
23
|
+
}, u = async (e, t, n, i, s, c) => {
|
|
24
|
+
let [{ connection: u, chainId: d, senderPublickey: f, instructions: p }, m] = await Promise.all([l(t, n, i, s), e.getEthereumAddress()]), h = await a({
|
|
25
25
|
connection: u,
|
|
26
26
|
chainId: d,
|
|
27
27
|
subAccount: i,
|
|
28
28
|
payerPublicKey: f,
|
|
29
29
|
instructions: p
|
|
30
30
|
});
|
|
31
|
-
return o(
|
|
31
|
+
return o(r(c, d, [t.erc20TokenAddress], [n], m)), h;
|
|
32
32
|
};
|
|
33
33
|
//#endregion
|
|
34
34
|
export { u as hinkalSolanaProxySend };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../constants/chains.constants.cjs`);require(`../../constants/protocol.constants.cjs`);const t=require(`../../error-handling/error-codes.constants.cjs`),n=require(`../../functions/utils/solanaMint.utils.cjs`),r=require(`../../functions/utils/addresses.cjs`),i=require(`../../functions/utils/
|
|
1
|
+
require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../constants/chains.constants.cjs`);require(`../../constants/protocol.constants.cjs`);const t=require(`../../error-handling/error-codes.constants.cjs`),n=require(`../../functions/utils/solanaMint.utils.cjs`),r=require(`../../functions/utils/addresses.cjs`),i=require(`../../functions/utils/create-provider.cjs`),a=require(`../../functions/utils/token-check.utils.cjs`),o=require(`../../functions/pre-transaction/solana.cjs`),s=require(`../../functions/pre-transaction/constructAdminData.cjs`),c=require(`../AccountActions/AccountActions.cjs`),l=require(`../../functions/pre-transaction/sendV0Transaction.cjs`),u=require(`../../functions/utils/fees.utils.cjs`),d=require(`../../functions/utils/solana-program.utils.cjs`),f=require(`../../API/admin-calls.cjs`),p=require(`../../functions/pre-transaction/solanaTransfer.utils.cjs`),m=require(`./hinkalProoflessDeposit.utils.cjs`);let h=require(`@solana/web3.js`),g=require(`@coral-xyz/anchor`);var _=async({program:e,mintPublicKey:t,mintAddressString:n,tokenAmount:r,stealthAddressStructure:i,recipientEncryptionKey:a,senderPublickey:s,originalDeployer:c,storageAccount:l,storageVault:u,merkleAccount:d,rootBuckets:f,createBlockedUtxos:p})=>{let h=new g.BN(r.toString()),_=o.buildAnchorStealthAddressStructure(i),v=n===`11111111111111111111111111111111`?null:t,y=n===`11111111111111111111111111111111`?null:void 0,[b]=m.buildProoflessEncryptedOutputs([i],[a]),x=Buffer.from(b.slice(2),`hex`),{current:S,next:C}=f;return e.methods.prooflessDeposit(h,_,x,p).accounts({mint:v,signer:s,signerAta:y,originalDeployer:c,storageAccount:l,storageVault:u,merkleAccount:d,rootBucketCurrent:S,rootBucketNext:C??e.programId,storageVaultAta:y}).instruction()},v=async({chainId:a,token:s,tokenAmount:c,senderAddress:l,recipientInfo:u,createBlockedUtxos:f=!1})=>{if(!r.isValidPrivateAddress(u))throw Error(t.transactionErrorCodes.RECIPIENT_FORMAT_INCORRECT);let{hinkalIdl:p,hinkalAddress:m,originalDeployer:g}=e.networkRegistry[a].contractData;if(!p)throw Error(`No IDL configured for Solana program on this network`);if(!g)throw Error(`missing original deployer`);let{rpcUrl:v}=e.networkRegistry[a],y=i.createCustomSolanaConnection(v),b=d.createReadOnlySolanaProgram(y,p),x=new h.PublicKey(g),S=new h.PublicKey(m),C=new h.PublicKey(l),{erc20TokenAddress:w}=s,{mintPublicKey:T}=n.formatMintAddress(w),E=T.toString(),D=o.getStorageAccountPublicKey(S,x),O=o.getStorageVaultPublicKey(S,x),k=o.getMerkleAccountPublicKey(S,x),A=r.constructStealthAddressStructure(u),j=r.getEncryptionKeyFromRecipientInfo(u),M=await o.resolveSolanaRootBuckets(b,k,1),N=await _({program:b,mintPublicKey:T,mintAddressString:E,tokenAmount:c,stealthAddressStructure:A,recipientEncryptionKey:j,senderPublickey:C,originalDeployer:x,storageAccount:D,storageVault:O,merkleAccount:k,rootBuckets:M,createBlockedUtxos:f}),P=n.getSolanaTokenProgramId(s.is2022Program);return{connection:y,senderAddress:l,senderPublickey:C,instructions:[N],storageAccount:D,storageVault:O,rootBucketCurrent:M.current,programId:P}},y=async(e,n,r,i,a,o,s=!1,l=0n)=>{let d=c.AccountActions.getAddressFromSubAccount(n,a);if(!d)throw Error(`Public account address is not available`);let f=await v({chainId:n,token:r,tokenAmount:i,senderAddress:d,recipientInfo:o??e.getRecipientInfo(),createBlockedUtxos:s});if(l<=0n)return f;let m=await e.getRandomRelay(n,!1);if(!m)throw Error(t.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let{instructions:g}=await p.buildSolanaTransferInstructions(f.connection,f.senderPublickey,new h.PublicKey(m),r,u.calculateVariableFee(i,l));return{...f,instructions:[...g,...f.instructions]}},b=async(e,t,n,r,i,o=!1,c=0n,u)=>{if(!r)throw Error(`subAccount is required`);let d=a.validateAndGetChainId([t]),[{connection:p,senderPublickey:m,instructions:h},g]=await Promise.all([y(e,d,t,n,r,i,o,c),e.getEthereumAddress()]),_=await l.sendProxyV0Transaction({connection:p,chainId:d,subAccount:r,payerPublicKey:m,instructions:h});return f.emitTxPublicData(s.constructAdminData(u,d,[t.erc20TokenAddress],[n],g)),_};exports.hinkalSolanaProxyShield=b;
|
|
@@ -3,10 +3,10 @@ import "../../constants/protocol.constants.mjs";
|
|
|
3
3
|
import { transactionErrorCodes as t } from "../../error-handling/error-codes.constants.mjs";
|
|
4
4
|
import { formatMintAddress as n, getSolanaTokenProgramId as r } from "../../functions/utils/solanaMint.utils.mjs";
|
|
5
5
|
import { constructStealthAddressStructure as i, getEncryptionKeyFromRecipientInfo as a, isValidPrivateAddress as o } from "../../functions/utils/addresses.mjs";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
6
|
+
import { createCustomSolanaConnection as s } from "../../functions/utils/create-provider.mjs";
|
|
7
|
+
import { validateAndGetChainId as c } from "../../functions/utils/token-check.utils.mjs";
|
|
8
|
+
import { buildAnchorStealthAddressStructure as l, getMerkleAccountPublicKey as u, getStorageAccountPublicKey as d, getStorageVaultPublicKey as f, resolveSolanaRootBuckets as p } from "../../functions/pre-transaction/solana.mjs";
|
|
9
|
+
import { constructAdminData as m } from "../../functions/pre-transaction/constructAdminData.mjs";
|
|
10
10
|
import { AccountActions as h } from "../AccountActions/AccountActions.mjs";
|
|
11
11
|
import { sendProxyV0Transaction as g } from "../../functions/pre-transaction/sendV0Transaction.mjs";
|
|
12
12
|
import { calculateVariableFee as _ } from "../../functions/utils/fees.utils.mjs";
|
|
@@ -17,30 +17,30 @@ import { buildProoflessEncryptedOutputs as x } from "./hinkalProoflessDeposit.ut
|
|
|
17
17
|
import { PublicKey as S } from "@solana/web3.js";
|
|
18
18
|
import { BN as C } from "@coral-xyz/anchor";
|
|
19
19
|
//#region libs/shared/common/src/data-structures/Hinkal/hinkalSolanaProxyShield.ts
|
|
20
|
-
var w = async ({ program: e, mintPublicKey: t, mintAddressString: n, tokenAmount: r, stealthAddressStructure: i, recipientEncryptionKey: a, senderPublickey: o, originalDeployer: s, storageAccount:
|
|
21
|
-
let m = new C(r.toString()), h =
|
|
20
|
+
var w = async ({ program: e, mintPublicKey: t, mintAddressString: n, tokenAmount: r, stealthAddressStructure: i, recipientEncryptionKey: a, senderPublickey: o, originalDeployer: s, storageAccount: c, storageVault: u, merkleAccount: d, rootBuckets: f, createBlockedUtxos: p }) => {
|
|
21
|
+
let m = new C(r.toString()), h = l(i), g = n === "11111111111111111111111111111111" ? null : t, _ = n === "11111111111111111111111111111111" ? null : void 0, [v] = x([i], [a]), y = Buffer.from(v.slice(2), "hex"), { current: b, next: S } = f;
|
|
22
22
|
return e.methods.prooflessDeposit(m, h, y, p).accounts({
|
|
23
23
|
mint: g,
|
|
24
24
|
signer: o,
|
|
25
25
|
signerAta: _,
|
|
26
26
|
originalDeployer: s,
|
|
27
|
-
storageAccount:
|
|
27
|
+
storageAccount: c,
|
|
28
28
|
storageVault: u,
|
|
29
29
|
merkleAccount: d,
|
|
30
30
|
rootBucketCurrent: b,
|
|
31
31
|
rootBucketNext: S ?? e.programId,
|
|
32
32
|
storageVaultAta: _
|
|
33
33
|
}).instruction();
|
|
34
|
-
}, T = async ({ chainId:
|
|
34
|
+
}, T = async ({ chainId: c, token: l, tokenAmount: m, senderAddress: h, recipientInfo: g, createBlockedUtxos: _ = !1 }) => {
|
|
35
35
|
if (!o(g)) throw Error(t.RECIPIENT_FORMAT_INCORRECT);
|
|
36
|
-
let { hinkalIdl: y, hinkalAddress: b, originalDeployer: x } = e[
|
|
36
|
+
let { hinkalIdl: y, hinkalAddress: b, originalDeployer: x } = e[c].contractData;
|
|
37
37
|
if (!y) throw Error("No IDL configured for Solana program on this network");
|
|
38
38
|
if (!x) throw Error("missing original deployer");
|
|
39
|
-
let { rpcUrl: C } = e[
|
|
39
|
+
let { rpcUrl: C } = e[c], T = s(C), E = v(T, y), D = new S(x), O = new S(b), k = new S(h), { erc20TokenAddress: A } = l, { mintPublicKey: j } = n(A), M = j.toString(), N = d(O, D), P = f(O, D), F = u(O, D), I = i(g), L = a(g), R = await p(E, F, 1), z = await w({
|
|
40
40
|
program: E,
|
|
41
41
|
mintPublicKey: j,
|
|
42
42
|
mintAddressString: M,
|
|
43
|
-
tokenAmount:
|
|
43
|
+
tokenAmount: m,
|
|
44
44
|
stealthAddressStructure: I,
|
|
45
45
|
recipientEncryptionKey: L,
|
|
46
46
|
senderPublickey: k,
|
|
@@ -50,7 +50,7 @@ var w = async ({ program: e, mintPublicKey: t, mintAddressString: n, tokenAmount
|
|
|
50
50
|
merkleAccount: F,
|
|
51
51
|
rootBuckets: R,
|
|
52
52
|
createBlockedUtxos: _
|
|
53
|
-
}), B = r(
|
|
53
|
+
}), B = r(l.is2022Program);
|
|
54
54
|
return {
|
|
55
55
|
connection: T,
|
|
56
56
|
senderAddress: h,
|
|
@@ -80,16 +80,16 @@ var w = async ({ program: e, mintPublicKey: t, mintAddressString: n, tokenAmount
|
|
|
80
80
|
...u,
|
|
81
81
|
instructions: [...f, ...u.instructions]
|
|
82
82
|
};
|
|
83
|
-
}, D = async (e, t, n, r, i, a = !1, o = 0n,
|
|
83
|
+
}, D = async (e, t, n, r, i, a = !1, o = 0n, s) => {
|
|
84
84
|
if (!r) throw Error("subAccount is required");
|
|
85
|
-
let l =
|
|
85
|
+
let l = c([t]), [{ connection: u, senderPublickey: d, instructions: f }, p] = await Promise.all([E(e, l, t, n, r, i, a, o), e.getEthereumAddress()]), h = await g({
|
|
86
86
|
connection: u,
|
|
87
87
|
chainId: l,
|
|
88
88
|
subAccount: r,
|
|
89
89
|
payerPublicKey: d,
|
|
90
90
|
instructions: f
|
|
91
91
|
});
|
|
92
|
-
return y(
|
|
92
|
+
return y(m(s, l, [t.erc20TokenAddress], [n], p)), h;
|
|
93
93
|
};
|
|
94
94
|
//#endregion
|
|
95
95
|
export { D as hinkalSolanaProxyShield };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../constants/chains.constants.cjs`);require(`../../constants/protocol.constants.cjs`);const t=require(`../../error-handling/error-codes.constants.cjs`),n=require(`../../types/external-action.types.cjs`),r=require(`../../functions/utils/
|
|
1
|
+
require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../constants/chains.constants.cjs`);require(`../../constants/protocol.constants.cjs`);const t=require(`../../error-handling/error-codes.constants.cjs`),n=require(`../../types/external-action.types.cjs`),r=require(`../../functions/utils/create-provider.cjs`),i=require(`../../functions/utils/token-check.utils.cjs`),a=require(`../../functions/utils/erc20tokenFunctions.cjs`),o=require(`../../functions/pre-transaction/constructAdminData.cjs`),s=require(`../AccountActions/AccountActions.cjs`),c=require(`../../functions/pre-transaction/sendV0Transaction.cjs`),l=require(`../../functions/pre-transaction/getFeeStructure.cjs`),u=require(`../../functions/utils/fees.utils.cjs`),d=require(`../../API/admin-calls.cjs`);require(`../../constants/index.cjs`);const f=require(`../../functions/utils/admin-dimensions.cjs`),p=require(`../../functions/pre-transaction/solanaTransfer.utils.cjs`);require(`../AccountActions/index.cjs`);let m=require(`@solana/web3.js`);var h=async(e,t)=>{let{addressLookupTableAccount:n,instructionLists:r}=JSON.parse(t).data,i=await Promise.all(n.map(async t=>{let n=await e.getAddressLookupTable(new m.PublicKey(t));if(!n.value)throw Error(`Failed to fetch lookup table: ${t}`);return n.value}));if(r.length===0)throw Error(`No instructions found`);return{instructions:r.map(e=>new m.TransactionInstruction({keys:e.accounts.map(e=>({pubkey:new m.PublicKey(e.pubkey),isSigner:e.isSigner,isWritable:e.isWritable})),programId:new m.PublicKey(e.programId),data:Buffer.from(e.data,`base64`)})),lookupTableAccounts:i}},g=async(e,t)=>{let n=m.VersionedTransaction.deserialize(Buffer.from(t,`base64`)),r=await Promise.all(n.message.addressTableLookups.map(async({accountKey:t})=>{let n=await e.getAddressLookupTable(t);if(!n.value)throw Error(`Failed to fetch lookup table: ${t.toBase58()}`);return n.value})),{instructions:i}=m.TransactionMessage.decompile(n.message,{addressLookupTableAccounts:r});return{instructions:i,lookupTableAccounts:r}},_=async(t,i,a,o)=>{let c=s.AccountActions.getAddressFromSubAccount(t,a);if(!c)throw Error(`Public account address is not available`);let{rpcUrl:l}=e.networkRegistry[t],u=r.createCustomSolanaConnection(l),d=new m.PublicKey(c),{instructions:f,lookupTableAccounts:p}=o===n.ExternalActionId.Lifi?await g(u,i):await h(u,i);return{connection:u,walletPublicKey:d,instructions:f,lookupTableAccounts:p}},v=async(e,r,s,h,g,v,y,b,x,S,C,w)=>{let T=i.validateAndGetChainId(r),[{connection:E,walletPublicKey:D,instructions:O,lookupTableAccounts:k},A,j]=await Promise.all([_(T,h,g,v),e.getRandomRelay(T),e.getEthereumAddressByChain(T)]);if(!A)throw Error(t.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let M=O,N=x??await l.getFeeStructure(T,b,r.map(e=>e.erc20TokenAddress),n.ExternalActionId.Emporium,[],35n),P=r[1],F;if(y)F=s[1]*N.variableRate/10000n;else{let e={...N,flatFee:0n},t=C&&w!==void 0?await u.calculateModifiedFeeStructure(T,C,w,e):e;if(F=t.flatFee,F>0n){let e=await a.getErc20TokenFromAPI(T,t.feeToken);if(!e)throw Error(`Failed to find fee token`);P=e}}if(F>0n){let{instructions:e}=await p.buildSolanaTransferInstructions(E,D,new m.PublicKey(A),P,F);M=[...M,...e]}let I=await c.sendProxyV0Transaction({connection:E,chainId:T,subAccount:g,payerPublicKey:D,instructions:M,lookupTableAccounts:k}),L=f.resolveSwapPairTokens(S,r,C);return d.emitTxPublicData(o.constructAdminData(S,T,r.map(e=>e.erc20TokenAddress),s,j,L)),I};exports.hinkalSolanaProxySwap=v;
|
|
@@ -2,5 +2,5 @@ import { AdminTransactionType, ERC20Token, SubAccount } from '../../types';
|
|
|
2
2
|
import { IHinkal } from './IHinkal';
|
|
3
3
|
import { FeeStructure } from '../../types/hinkal.types';
|
|
4
4
|
import { ExternalActionId } from '../../types/external-action.types';
|
|
5
|
-
export declare const hinkalSolanaProxySwap: (hinkal: IHinkal, erc20Tokens: ERC20Token[], amountChanges: bigint[], data: string, subAccount: SubAccount, externalActionId: ExternalActionId, isTheSameChainSwap: boolean,
|
|
5
|
+
export declare const hinkalSolanaProxySwap: (hinkal: IHinkal, erc20Tokens: ERC20Token[], amountChanges: bigint[], data: string, subAccount: SubAccount, externalActionId: ExternalActionId, isTheSameChainSwap: boolean, feeTokenAddress?: string, feeStructureOverride?: FeeStructure, action?: AdminTransactionType, bridgedToken?: ERC20Token, bridgedTokenAmount?: bigint) => Promise<string>;
|
|
6
6
|
export declare const getSolanaProxySwapSerializedTransaction: (chainId: number, data: string, subAccount: SubAccount, externalActionId: ExternalActionId) => Promise<string>;
|
|
@@ -2,91 +2,93 @@ import { networkRegistry as e } from "../../constants/chains.constants.mjs";
|
|
|
2
2
|
import "../../constants/protocol.constants.mjs";
|
|
3
3
|
import { transactionErrorCodes as t } from "../../error-handling/error-codes.constants.mjs";
|
|
4
4
|
import { ExternalActionId as n } from "../../types/external-action.types.mjs";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
5
|
+
import { createCustomSolanaConnection as r } from "../../functions/utils/create-provider.mjs";
|
|
6
|
+
import { validateAndGetChainId as i } from "../../functions/utils/token-check.utils.mjs";
|
|
7
|
+
import { getErc20TokenFromAPI as a } from "../../functions/utils/erc20tokenFunctions.mjs";
|
|
8
|
+
import { constructAdminData as o } from "../../functions/pre-transaction/constructAdminData.mjs";
|
|
9
9
|
import { AccountActions as s } from "../AccountActions/AccountActions.mjs";
|
|
10
10
|
import { sendProxyV0Transaction as c } from "../../functions/pre-transaction/sendV0Transaction.mjs";
|
|
11
11
|
import { getFeeStructure as l } from "../../functions/pre-transaction/getFeeStructure.mjs";
|
|
12
12
|
import { calculateModifiedFeeStructure as u } from "../../functions/utils/fees.utils.mjs";
|
|
13
13
|
import { emitTxPublicData as d } from "../../API/admin-calls.mjs";
|
|
14
14
|
import "../../constants/index.mjs";
|
|
15
|
-
import {
|
|
15
|
+
import { resolveSwapPairTokens as f } from "../../functions/utils/admin-dimensions.mjs";
|
|
16
|
+
import { buildSolanaTransferInstructions as p } from "../../functions/pre-transaction/solanaTransfer.utils.mjs";
|
|
16
17
|
import "../AccountActions/index.mjs";
|
|
17
|
-
import { PublicKey as
|
|
18
|
+
import { PublicKey as m, TransactionInstruction as h, TransactionMessage as g, VersionedTransaction as _ } from "@solana/web3.js";
|
|
18
19
|
//#region libs/shared/common/src/data-structures/Hinkal/hinkalSolanaProxySwap.ts
|
|
19
|
-
var
|
|
20
|
+
var v = async (e, t) => {
|
|
20
21
|
let { addressLookupTableAccount: n, instructionLists: r } = JSON.parse(t).data, i = await Promise.all(n.map(async (t) => {
|
|
21
|
-
let n = await e.getAddressLookupTable(new
|
|
22
|
+
let n = await e.getAddressLookupTable(new m(t));
|
|
22
23
|
if (!n.value) throw Error(`Failed to fetch lookup table: ${t}`);
|
|
23
24
|
return n.value;
|
|
24
25
|
}));
|
|
25
26
|
if (r.length === 0) throw Error("No instructions found");
|
|
26
27
|
return {
|
|
27
|
-
instructions: r.map((e) => new
|
|
28
|
+
instructions: r.map((e) => new h({
|
|
28
29
|
keys: e.accounts.map((e) => ({
|
|
29
|
-
pubkey: new
|
|
30
|
+
pubkey: new m(e.pubkey),
|
|
30
31
|
isSigner: e.isSigner,
|
|
31
32
|
isWritable: e.isWritable
|
|
32
33
|
})),
|
|
33
|
-
programId: new
|
|
34
|
+
programId: new m(e.programId),
|
|
34
35
|
data: Buffer.from(e.data, "base64")
|
|
35
36
|
})),
|
|
36
37
|
lookupTableAccounts: i
|
|
37
38
|
};
|
|
38
|
-
},
|
|
39
|
-
let n =
|
|
39
|
+
}, y = async (e, t) => {
|
|
40
|
+
let n = _.deserialize(Buffer.from(t, "base64")), r = await Promise.all(n.message.addressTableLookups.map(async ({ accountKey: t }) => {
|
|
40
41
|
let n = await e.getAddressLookupTable(t);
|
|
41
42
|
if (!n.value) throw Error(`Failed to fetch lookup table: ${t.toBase58()}`);
|
|
42
43
|
return n.value;
|
|
43
|
-
})), { instructions: i } =
|
|
44
|
+
})), { instructions: i } = g.decompile(n.message, { addressLookupTableAccounts: r });
|
|
44
45
|
return {
|
|
45
46
|
instructions: i,
|
|
46
47
|
lookupTableAccounts: r
|
|
47
48
|
};
|
|
48
|
-
},
|
|
49
|
-
let c = s.getAddressFromSubAccount(t,
|
|
49
|
+
}, b = async (t, i, a, o) => {
|
|
50
|
+
let c = s.getAddressFromSubAccount(t, a);
|
|
50
51
|
if (!c) throw Error("Public account address is not available");
|
|
51
|
-
let { rpcUrl: l } = e[t], u =
|
|
52
|
+
let { rpcUrl: l } = e[t], u = r(l), d = new m(c), { instructions: f, lookupTableAccounts: p } = o === n.Lifi ? await y(u, i) : await v(u, i);
|
|
52
53
|
return {
|
|
53
54
|
connection: u,
|
|
54
55
|
walletPublicKey: d,
|
|
55
56
|
instructions: f,
|
|
56
|
-
lookupTableAccounts:
|
|
57
|
+
lookupTableAccounts: p
|
|
57
58
|
};
|
|
58
|
-
},
|
|
59
|
-
let
|
|
60
|
-
|
|
61
|
-
e.getRandomRelay(
|
|
62
|
-
e.getEthereumAddressByChain(
|
|
59
|
+
}, x = async (e, r, s, h, g, _, v, y, x, S, C, w) => {
|
|
60
|
+
let T = i(r), [{ connection: E, walletPublicKey: D, instructions: O, lookupTableAccounts: k }, A, j] = await Promise.all([
|
|
61
|
+
b(T, h, g, _),
|
|
62
|
+
e.getRandomRelay(T),
|
|
63
|
+
e.getEthereumAddressByChain(T)
|
|
63
64
|
]);
|
|
64
|
-
if (!
|
|
65
|
-
let
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
j = [...D, ...n];
|
|
69
|
-
} else {
|
|
65
|
+
if (!A) throw Error(t.RELAYER_NOT_AVAILABLE);
|
|
66
|
+
let M = O, N = x ?? await l(T, y, r.map((e) => e.erc20TokenAddress), n.Emporium, [], 35n), P = r[1], F;
|
|
67
|
+
if (v) F = s[1] * N.variableRate / 10000n;
|
|
68
|
+
else {
|
|
70
69
|
let e = {
|
|
71
|
-
...
|
|
70
|
+
...N,
|
|
72
71
|
flatFee: 0n
|
|
73
|
-
}, t =
|
|
74
|
-
if (t.flatFee > 0n) {
|
|
75
|
-
let e = await
|
|
72
|
+
}, t = C && w !== void 0 ? await u(T, C, w, e) : e;
|
|
73
|
+
if (F = t.flatFee, F > 0n) {
|
|
74
|
+
let e = await a(T, t.feeToken);
|
|
76
75
|
if (!e) throw Error("Failed to find fee token");
|
|
77
|
-
|
|
78
|
-
j = [...D, ...n];
|
|
76
|
+
P = e;
|
|
79
77
|
}
|
|
80
78
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
79
|
+
if (F > 0n) {
|
|
80
|
+
let { instructions: e } = await p(E, D, new m(A), P, F);
|
|
81
|
+
M = [...M, ...e];
|
|
82
|
+
}
|
|
83
|
+
let I = await c({
|
|
84
|
+
connection: E,
|
|
85
|
+
chainId: T,
|
|
86
|
+
subAccount: g,
|
|
87
|
+
payerPublicKey: D,
|
|
88
|
+
instructions: M,
|
|
89
|
+
lookupTableAccounts: k
|
|
90
|
+
}), L = f(S, r, C);
|
|
91
|
+
return d(o(S, T, r.map((e) => e.erc20TokenAddress), s, j, L)), I;
|
|
90
92
|
};
|
|
91
93
|
//#endregion
|
|
92
|
-
export {
|
|
94
|
+
export { x as hinkalSolanaProxySwap };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`../../../../_virtual/_rolldown/runtime.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../constants/protocol.constants.cjs`),r=require(`../../functions/utils/solanaMint.utils.cjs`),i=require(`../../functions/utils/create-provider.cjs`),a=require(`../../functions/utils/receive-vault-solana.utils.cjs`),o=require(`../../functions/utils/receive-vault.utils.cjs`),s=require(`../../functions/pre-transaction/solana.cjs`),c=require(`../../functions/pre-transaction/sendV0Transaction.cjs`),l=require(`../../functions/utils/solana-program.utils.cjs`);let u=require(`@solana/web3.js`),d=require(`bs58`);d=e.__toESM(d);let f=require(`@solana/spl-token`),p=require(`@coral-xyz/anchor`);var m=e=>({recipient:s.buildAnchorStealthAddressStructure(e.recipient),owner:new u.PublicKey(e.owner),version:Number(e.version)}),h=e=>{let n=o.getReceiveVaultFactoryAddress(e);if(!n)throw Error(`receive vault: no factory on chain ${e}`);let{hinkalIdl:r}=t.networkRegistry[e].contractData;if(!r)throw Error(`No IDL configured for Solana program on this network`);let{rpcUrl:a}=t.networkRegistry[e],s=i.createCustomSolanaConnection(a),c=l.createReadOnlySolanaProgram(s,r);return{factoryAddress:n,originalDeployer:o.getSolanaOriginalDeployer(e),connection:s,program:c,hinkalIdl:r}},g=async(e,t,i,o,s,l,g,_,v)=>{let{factoryAddress:y,originalDeployer:b,hinkalIdl:x,connection:S,program:C}=h(t),w=a.computeSolanaReceiveVaultAddress(i,y,b),T=new u.PublicKey(w),E=new u.PublicKey(s),D=new u.PublicKey(_),O=o===n.solanaNativeAddress,{mintPublicKey:k}=r.formatMintAddress(o),A=O?f.TOKEN_PROGRAM_ID:(await S.getAccountInfo(k))?.owner;if(!A||!A.equals(f.TOKEN_PROGRAM_ID)&&!A.equals(f.TOKEN_2022_PROGRAM_ID))throw Error(`receive vault: unsupported token program`);let j=a.getSolanaReceiveVaultRecoveryDigest(y,b,w,o,s,l),M=a.computeSolanaRecoveryMarkerAddress(y,b,j),N=u.Ed25519Program.createInstructionWithPublicKey({publicKey:new u.PublicKey(i.owner).toBytes(),message:j,signature:d.default.decode(g)}),P=await C.methods.receiveVaultRecover(m(i),E,new p.BN(l.toString()),Array.from(j)).accounts({signer:D,originalDeployer:new u.PublicKey(b),vault:T,vaultAta:O?null:(0,f.getAssociatedTokenAddressSync)(k,T,!0,A),mint:O?null:k,destination:E,destinationAta:O?null:void 0,tokenProgram:A,recoveryMarker:M,instructionsSysvar:u.SYSVAR_INSTRUCTIONS_PUBKEY}).instruction();if(v){let{blockhash:e}=await S.getLatestBlockhash(),t=new u.Transaction;return t.feePayer=D,t.recentBlockhash=e,t.add(N,P),t.serialize({requireAllSignatures:!1}).toString(`base64`)}let{connection:F,wallet:I}=e.getSolanaProgram(x).provider;if(!I)throw Error(`missing solana wallet`);return c.sendInstructions(F,I,D,[N,P])};exports.hinkalSolanaReceiveVaultRecover=g;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { TransactionInstruction } from '@solana/web3.js';
|
|
2
|
+
import { ReceiveVaultParams } from '../../types/receive-vault.types';
|
|
3
|
+
import { IHinkal } from './IHinkal';
|
|
4
|
+
export declare const buildSolanaReceiveVaultSettleInstructions: (chainId: number, params: ReceiveVaultParams, token: string, encryptedOutput: string, outputSignature: string, relayerPublicKey: string, flatFee: bigint, variableRate: bigint) => Promise<TransactionInstruction[]>;
|
|
5
|
+
export declare const hinkalSolanaReceiveVaultRecover: (hinkal: IHinkal, chainId: number, params: ReceiveVaultParams, token: string, to: string, deadline: bigint, signature: string, feePayer: string, returnTxData: boolean) => Promise<string>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { networkRegistry as e } from "../../constants/chains.constants.mjs";
|
|
2
|
+
import { solanaNativeAddress as t } from "../../constants/protocol.constants.mjs";
|
|
3
|
+
import { formatMintAddress as n } from "../../functions/utils/solanaMint.utils.mjs";
|
|
4
|
+
import { createCustomSolanaConnection as r } from "../../functions/utils/create-provider.mjs";
|
|
5
|
+
import { computeSolanaReceiveVaultAddress as i, computeSolanaRecoveryMarkerAddress as a, getSolanaReceiveVaultRecoveryDigest as o } from "../../functions/utils/receive-vault-solana.utils.mjs";
|
|
6
|
+
import { getReceiveVaultFactoryAddress as s, getSolanaOriginalDeployer as c } from "../../functions/utils/receive-vault.utils.mjs";
|
|
7
|
+
import { buildAnchorStealthAddressStructure as l } from "../../functions/pre-transaction/solana.mjs";
|
|
8
|
+
import { sendInstructions as u } from "../../functions/pre-transaction/sendV0Transaction.mjs";
|
|
9
|
+
import { createReadOnlySolanaProgram as d } from "../../functions/utils/solana-program.utils.mjs";
|
|
10
|
+
import { Ed25519Program as f, PublicKey as p, SYSVAR_INSTRUCTIONS_PUBKEY as m, Transaction as h } from "@solana/web3.js";
|
|
11
|
+
import g from "bs58";
|
|
12
|
+
import { TOKEN_2022_PROGRAM_ID as _, TOKEN_PROGRAM_ID as v, getAssociatedTokenAddressSync as y } from "@solana/spl-token";
|
|
13
|
+
import { BN as b } from "@coral-xyz/anchor";
|
|
14
|
+
//#region libs/shared/common/src/data-structures/Hinkal/hinkalSolanaReceiveVault.ts
|
|
15
|
+
var x = (e) => ({
|
|
16
|
+
recipient: l(e.recipient),
|
|
17
|
+
owner: new p(e.owner),
|
|
18
|
+
version: Number(e.version)
|
|
19
|
+
}), S = (t) => {
|
|
20
|
+
let n = s(t);
|
|
21
|
+
if (!n) throw Error(`receive vault: no factory on chain ${t}`);
|
|
22
|
+
let { hinkalIdl: i } = e[t].contractData;
|
|
23
|
+
if (!i) throw Error("No IDL configured for Solana program on this network");
|
|
24
|
+
let { rpcUrl: a } = e[t], o = r(a), l = d(o, i);
|
|
25
|
+
return {
|
|
26
|
+
factoryAddress: n,
|
|
27
|
+
originalDeployer: c(t),
|
|
28
|
+
connection: o,
|
|
29
|
+
program: l,
|
|
30
|
+
hinkalIdl: i
|
|
31
|
+
};
|
|
32
|
+
}, C = async (e, r, s, c, l, d, C, w, T) => {
|
|
33
|
+
let { factoryAddress: E, originalDeployer: D, hinkalIdl: O, connection: k, program: A } = S(r), j = i(s, E, D), M = new p(j), N = new p(l), P = new p(w), F = c === t, { mintPublicKey: I } = n(c), L = F ? v : (await k.getAccountInfo(I))?.owner;
|
|
34
|
+
if (!L || !L.equals(v) && !L.equals(_)) throw Error("receive vault: unsupported token program");
|
|
35
|
+
let R = o(E, D, j, c, l, d), z = a(E, D, R), B = f.createInstructionWithPublicKey({
|
|
36
|
+
publicKey: new p(s.owner).toBytes(),
|
|
37
|
+
message: R,
|
|
38
|
+
signature: g.decode(C)
|
|
39
|
+
}), V = await A.methods.receiveVaultRecover(x(s), N, new b(d.toString()), Array.from(R)).accounts({
|
|
40
|
+
signer: P,
|
|
41
|
+
originalDeployer: new p(D),
|
|
42
|
+
vault: M,
|
|
43
|
+
vaultAta: F ? null : y(I, M, !0, L),
|
|
44
|
+
mint: F ? null : I,
|
|
45
|
+
destination: N,
|
|
46
|
+
destinationAta: F ? null : void 0,
|
|
47
|
+
tokenProgram: L,
|
|
48
|
+
recoveryMarker: z,
|
|
49
|
+
instructionsSysvar: m
|
|
50
|
+
}).instruction();
|
|
51
|
+
if (T) {
|
|
52
|
+
let { blockhash: e } = await k.getLatestBlockhash(), t = new h();
|
|
53
|
+
return t.feePayer = P, t.recentBlockhash = e, t.add(B, V), t.serialize({ requireAllSignatures: !1 }).toString("base64");
|
|
54
|
+
}
|
|
55
|
+
let { connection: H, wallet: U } = e.getSolanaProgram(O).provider;
|
|
56
|
+
if (!U) throw Error("missing solana wallet");
|
|
57
|
+
return u(H, U, P, [B, V]);
|
|
58
|
+
};
|
|
59
|
+
//#endregion
|
|
60
|
+
export { C as hinkalSolanaReceiveVaultRecover };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../error-handling/error-codes.constants.cjs`),t=require(`../../functions/utils/tron.utils.cjs`),n=require(`../../types/external-action.types.cjs`),r=require(`../../types/transact.types.cjs`),i=require(`../../functions/utils/token-check.utils.cjs`),a=require(`../../functions/pre-transaction/getVolatileTransferAmount.cjs`),o=require(`../../functions/pre-transaction/constructAdminData.cjs`),s=require(`../../functions/pre-transaction/getFeeStructure.cjs`);require(`../../functions/pre-transaction/index.cjs`);const
|
|
1
|
+
const e=require(`../../error-handling/error-codes.constants.cjs`),t=require(`../../functions/utils/tron.utils.cjs`),n=require(`../../types/external-action.types.cjs`),r=require(`../../types/transact.types.cjs`),i=require(`../../functions/utils/token-check.utils.cjs`),a=require(`../../functions/pre-transaction/getVolatileTransferAmount.cjs`),o=require(`../../functions/pre-transaction/constructAdminData.cjs`),s=require(`../../functions/pre-transaction/getFeeStructure.cjs`),c=require(`../../functions/utils/fees.utils.cjs`);require(`../../functions/pre-transaction/index.cjs`);const l=require(`./hinkalTransact.cjs`),u=require(`../../functions/pre-transaction/merge-with-fee-structure.cjs`);var d=async(d,f,p,m,h,g,_,v,y)=>{let b=i.validateAndGetChainId(f),x=t.addressToHexFormat(await d.getEthereumAddressByChain(b)),S=f.map(e=>e.erc20TokenAddress),C=await a.modifyVolatileTokenAmountChanges(b,f,p),w=f[0];if(!w)throw Error(`Withdraw Action: No Token Found`);let T;if(!h){T=_??await s.getFeeStructure(b,g,S,n.ExternalActionId.Transact,[],v),_&&v!==void 0&&(T={...T,variableRate:v});let e=[...C];await u.mergeWithFeeStructure(b,S,C,T),T.variableRate>0n&&f.forEach((t,n)=>{if(C[n]>=0n)return;let r=-e[n];C[n]-=c.calculateVariableFeeGrossUp(r,T.variableRate)})}let E=h?void 0:await d.getRandomRelay(b,!0);if(!h&&!E)throw Error(e.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let D=h?{mode:r.SubmitMode.Self,erc20Tokens:[w],approvalAmounts:[C[0]]}:{mode:r.SubmitMode.Relayer,adminData:o.constructAdminData(y,b,S,C,x)};return l.hinkalTransact(d,{chainId:b,erc20Addresses:S,amountChanges:C,externalAddress:t.addressToHexFormat(m),feeStructure:T,relay:E,originalSender:h?x:void 0,submit:D})};exports.hinkalWithdraw=d;
|
|
@@ -6,38 +6,47 @@ import { validateAndGetChainId as i } from "../../functions/utils/token-check.ut
|
|
|
6
6
|
import { modifyVolatileTokenAmountChanges as a } from "../../functions/pre-transaction/getVolatileTransferAmount.mjs";
|
|
7
7
|
import { constructAdminData as o } from "../../functions/pre-transaction/constructAdminData.mjs";
|
|
8
8
|
import { getFeeStructure as s } from "../../functions/pre-transaction/getFeeStructure.mjs";
|
|
9
|
+
import { calculateVariableFeeGrossUp as c } from "../../functions/utils/fees.utils.mjs";
|
|
9
10
|
import "../../functions/pre-transaction/index.mjs";
|
|
10
|
-
import { hinkalTransact as
|
|
11
|
-
import { mergeWithFeeStructure as
|
|
11
|
+
import { hinkalTransact as l } from "./hinkalTransact.mjs";
|
|
12
|
+
import { mergeWithFeeStructure as u } from "../../functions/pre-transaction/merge-with-fee-structure.mjs";
|
|
12
13
|
//#region libs/shared/common/src/data-structures/Hinkal/hinkalWithdraw.ts
|
|
13
|
-
var
|
|
14
|
-
let
|
|
15
|
-
if (!
|
|
16
|
-
let
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
var d = async (d, f, p, m, h, g, _, v, y) => {
|
|
15
|
+
let b = i(f), x = t(await d.getEthereumAddressByChain(b)), S = f.map((e) => e.erc20TokenAddress), C = await a(b, f, p), w = f[0];
|
|
16
|
+
if (!w) throw Error("Withdraw Action: No Token Found");
|
|
17
|
+
let T;
|
|
18
|
+
if (!h) {
|
|
19
|
+
T = _ ?? await s(b, g, S, n.Transact, [], v), _ && v !== void 0 && (T = {
|
|
20
|
+
...T,
|
|
21
|
+
variableRate: v
|
|
22
|
+
});
|
|
23
|
+
let e = [...C];
|
|
24
|
+
await u(b, S, C, T), T.variableRate > 0n && f.forEach((t, n) => {
|
|
25
|
+
if (C[n] >= 0n) return;
|
|
26
|
+
let r = -e[n];
|
|
27
|
+
C[n] -= c(r, T.variableRate);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
let E = h ? void 0 : await d.getRandomRelay(b, !0);
|
|
31
|
+
if (!h && !E) throw Error(e.RELAYER_NOT_AVAILABLE);
|
|
32
|
+
let D = h ? {
|
|
24
33
|
mode: r.Self,
|
|
25
|
-
erc20Tokens: [
|
|
26
|
-
approvalAmounts: [
|
|
34
|
+
erc20Tokens: [w],
|
|
35
|
+
approvalAmounts: [C[0]]
|
|
27
36
|
} : {
|
|
28
37
|
mode: r.Relayer,
|
|
29
|
-
adminData: o(
|
|
38
|
+
adminData: o(y, b, S, C, x)
|
|
30
39
|
};
|
|
31
|
-
return
|
|
32
|
-
chainId:
|
|
33
|
-
erc20Addresses:
|
|
34
|
-
amountChanges:
|
|
35
|
-
externalAddress: t(
|
|
36
|
-
feeStructure:
|
|
37
|
-
relay:
|
|
38
|
-
originalSender:
|
|
39
|
-
submit:
|
|
40
|
+
return l(d, {
|
|
41
|
+
chainId: b,
|
|
42
|
+
erc20Addresses: S,
|
|
43
|
+
amountChanges: C,
|
|
44
|
+
externalAddress: t(m),
|
|
45
|
+
feeStructure: T,
|
|
46
|
+
relay: E,
|
|
47
|
+
originalSender: h ? x : void 0,
|
|
48
|
+
submit: D
|
|
40
49
|
});
|
|
41
50
|
};
|
|
42
51
|
//#endregion
|
|
43
|
-
export {
|
|
52
|
+
export { d as hinkalWithdraw };
|
|
@@ -26,4 +26,5 @@ export * from './hinkalReceiveVaultAccount';
|
|
|
26
26
|
export * from './hinkalReceiveVaultCreate';
|
|
27
27
|
export * from './hinkalReceiveVaultRecover';
|
|
28
28
|
export * from './hinkalReceiveVaultSettle';
|
|
29
|
+
export * from './hinkalSolanaReceiveVault';
|
|
29
30
|
export * from './hinkalSolanaSponsoredShield';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../constants/chains.constants.cjs`),t=require(`../../types/ethereum-network.types.cjs`),n=require(`../../types/balances.types.cjs`),r=require(`../../types/events.types.cjs`);require(`../../types/index.cjs`);const i=require(`../../functions/utils/
|
|
1
|
+
require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../constants/chains.constants.cjs`),t=require(`../../types/ethereum-network.types.cjs`),n=require(`../../types/balances.types.cjs`),r=require(`../../types/events.types.cjs`);require(`../../types/index.cjs`);const i=require(`../../functions/utils/create-provider.cjs`),a=require(`../../functions/utils/map.utils.cjs`),o=require(`../../functions/utils/mutexes.utils.cjs`),s=require(`../../functions/utils/getContractAddress.cjs`),c=require(`../private-balances/BalanceChangedHandler.cjs`),l=require(`../event-service/evm/ClientBlockchainEventEmitter.cjs`),u=require(`../event-service/solana/ClientSolanaBlockchainEventEmitter.cjs`);require(`../event-service/index.cjs`);const d=require(`../snapshot/SnapshotFetcherService.cjs`),f=require(`../snapshot/solana-snapshots/ClientSolanaCommitmentsSnapshotService.cjs`),p=require(`../snapshot/solana-snapshots/ClientSolanaNullifierSnapshotService.cjs`),m=require(`../snapshot/evm-snapshots/ClientCommitmentsSnapshotService.cjs`),h=require(`../snapshot/evm-snapshots/ClientNullifierSnapshotService.cjs`);require(`../snapshot/index.cjs`);let g=require(`@solana/web3.js`),_=require(`async-mutex`);var v=new Map,y=e=>a.getOrCreateMapValue(v,e,()=>new _.Mutex),b=async(a,_)=>{let v=(_??a.getSupportedChains()).map(_=>y(_).runExclusive(async()=>{if(a.generateProofRemotely)return;a.commitmentsSnapshotServiceByChain[_]?.intervalClear(),a.nullifierSnapshotServiceByChain[_]?.intervalClear();let{maxPageSize:v,rpcUrl:y,contractData:b}=e.networkRegistry[_],x;if(e.isSolanaLike(_)){let e=b.hinkalAddress;if(!e)throw Error(`Solana program ID is not set`);x=new u.ClientSolanaBlockchainEventEmitter(_,i.createCustomSolanaConnection(y),new g.PublicKey(e),0,o.getChainBalanceFetchingMutex(_),v);let t=b.hinkalIdl;t&&x.setIdl(t);let n=new d.SnapshotFetcherService(_,e);a.commitmentsSnapshotServiceByChain[_]=new f.ClientSolanaCommitmentsSnapshotService(x,n),a.nullifierSnapshotServiceByChain[_]=new p.ClientSolanaNullifierSnapshotService(x,n)}else{let e=a.getContractWithFetcherByChainId(_,t.ContractType.HinkalContract),n=o.getChainBalanceFetchingMutex(_);x=new l.ClientBlockchainEventEmitter(r.EventCategory.MainContractEvents,_,e,0,n,v);let i=new d.SnapshotFetcherService(_,s.getContractAddress(e));a.commitmentsSnapshotServiceByChain[_]=new m.ClientCommitmentsSnapshotService(x,i),a.nullifierSnapshotServiceByChain[_]=new h.ClientNullifierSnapshotService(x,i)}let S=a.commitmentsSnapshotServiceByChain[_],C=a.nullifierSnapshotServiceByChain[_];if(!S||!C)throw Error(`Missing snapshot service for chain ${_}`);await Promise.all([S.init(),C.init()]),await x.init(),a.merkleTreeHinkalByChain[_]=S.merkleTree,a.nullifiersByChain[_]=C.nullifiers,a.encryptedOutputsByChain[_]=S.encryptedOutputs,x.onEventsProcessed=e=>{e>0&&c.balanceChangedHandler.dispatch({updateType:n.PrivateBalanceUpdateType.FreshWithoutLoader,updateTokensListBefore:!0,chainIdToUpdate:_})}}));await Promise.allSettled(v)};exports.resetMerkleTrees=b;
|
|
@@ -3,9 +3,9 @@ import { ContractType as n } from "../../types/ethereum-network.types.mjs";
|
|
|
3
3
|
import { PrivateBalanceUpdateType as r } from "../../types/balances.types.mjs";
|
|
4
4
|
import { EventCategory as i } from "../../types/events.types.mjs";
|
|
5
5
|
import "../../types/index.mjs";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
6
|
+
import { createCustomSolanaConnection as a } from "../../functions/utils/create-provider.mjs";
|
|
7
|
+
import { getOrCreateMapValue as o } from "../../functions/utils/map.utils.mjs";
|
|
8
|
+
import { getChainBalanceFetchingMutex as s } from "../../functions/utils/mutexes.utils.mjs";
|
|
9
9
|
import { getContractAddress as c } from "../../functions/utils/getContractAddress.mjs";
|
|
10
10
|
import { balanceChangedHandler as l } from "../private-balances/BalanceChangedHandler.mjs";
|
|
11
11
|
import { ClientBlockchainEventEmitter as u } from "../event-service/evm/ClientBlockchainEventEmitter.mjs";
|
|
@@ -20,28 +20,28 @@ import "../snapshot/index.mjs";
|
|
|
20
20
|
import { PublicKey as _ } from "@solana/web3.js";
|
|
21
21
|
import { Mutex as v } from "async-mutex";
|
|
22
22
|
//#region libs/shared/common/src/data-structures/Hinkal/resetMerkleTrees.ts
|
|
23
|
-
var y = /* @__PURE__ */ new Map(), b = (e) =>
|
|
24
|
-
let y = (v ??
|
|
25
|
-
if (
|
|
26
|
-
|
|
23
|
+
var y = /* @__PURE__ */ new Map(), b = (e) => o(y, e, () => new v()), x = async (o, v) => {
|
|
24
|
+
let y = (v ?? o.getSupportedChains()).map((v) => b(v).runExclusive(async () => {
|
|
25
|
+
if (o.generateProofRemotely) return;
|
|
26
|
+
o.commitmentsSnapshotServiceByChain[v]?.intervalClear(), o.nullifierSnapshotServiceByChain[v]?.intervalClear();
|
|
27
27
|
let { maxPageSize: y, rpcUrl: b, contractData: x } = t[v], S;
|
|
28
28
|
if (e(v)) {
|
|
29
29
|
let e = x.hinkalAddress;
|
|
30
30
|
if (!e) throw Error("Solana program ID is not set");
|
|
31
|
-
S = new d(v,
|
|
31
|
+
S = new d(v, a(b), new _(e), 0, s(v), y);
|
|
32
32
|
let t = x.hinkalIdl;
|
|
33
33
|
t && S.setIdl(t);
|
|
34
34
|
let n = new f(v, e);
|
|
35
|
-
|
|
35
|
+
o.commitmentsSnapshotServiceByChain[v] = new p(S, n), o.nullifierSnapshotServiceByChain[v] = new m(S, n);
|
|
36
36
|
} else {
|
|
37
|
-
let e =
|
|
37
|
+
let e = o.getContractWithFetcherByChainId(v, n.HinkalContract), t = s(v);
|
|
38
38
|
S = new u(i.MainContractEvents, v, e, 0, t, y);
|
|
39
39
|
let r = new f(v, c(e));
|
|
40
|
-
|
|
40
|
+
o.commitmentsSnapshotServiceByChain[v] = new h(S, r), o.nullifierSnapshotServiceByChain[v] = new g(S, r);
|
|
41
41
|
}
|
|
42
|
-
let C =
|
|
42
|
+
let C = o.commitmentsSnapshotServiceByChain[v], w = o.nullifierSnapshotServiceByChain[v];
|
|
43
43
|
if (!C || !w) throw Error(`Missing snapshot service for chain ${v}`);
|
|
44
|
-
await Promise.all([C.init(), w.init()]), await S.init(),
|
|
44
|
+
await Promise.all([C.init(), w.init()]), await S.init(), o.merkleTreeHinkalByChain[v] = C.merkleTree, o.nullifiersByChain[v] = w.nullifiers, o.encryptedOutputsByChain[v] = C.encryptedOutputs, S.onEventsProcessed = (e) => {
|
|
45
45
|
e > 0 && l.dispatch({
|
|
46
46
|
updateType: r.FreshWithoutLoader,
|
|
47
47
|
updateTokensListBefore: !0,
|