@hinkal/common 0.2.3 → 0.2.5
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/API.cjs +1 -1
- package/API/API.d.ts +2 -2
- package/API/API.mjs +22 -22
- package/API/duneAPI.cjs +1 -1
- package/API/duneAPI.mjs +3 -2
- package/API/userVerifyTransactions.cjs +1 -1
- package/API/userVerifyTransactions.d.ts +6 -7
- package/API/userVerifyTransactions.mjs +13 -14
- package/constants/chains.constants.cjs +1 -1
- package/constants/chains.constants.mjs +2 -2
- package/constants/contracts.constants.cjs +1 -1
- package/constants/contracts.constants.mjs +138 -134
- package/constants/deploy-data/deploy-data-arbMainnet.json.cjs +1 -1
- package/constants/deploy-data/deploy-data-arbMainnet.json.mjs +846 -11
- package/constants/deploy-data/deploy-data-avalanche.json.cjs +1 -1
- package/constants/deploy-data/deploy-data-avalanche.json.mjs +848 -13
- package/constants/deploy-data/deploy-data-base.json.cjs +1 -1
- package/constants/deploy-data/deploy-data-base.json.mjs +852 -17
- package/constants/deploy-data/deploy-data-bnbMainnet.json.cjs +1 -1
- package/constants/deploy-data/deploy-data-bnbMainnet.json.mjs +855 -20
- package/constants/deploy-data/deploy-data-ethMainnet.json.cjs +1 -1
- package/constants/deploy-data/deploy-data-ethMainnet.json.mjs +850 -15
- package/constants/deploy-data/deploy-data-localhost.json.cjs +1 -1
- package/constants/deploy-data/deploy-data-localhost.json.mjs +935 -100
- package/constants/deploy-data/deploy-data-optimism.json.cjs +1 -1
- package/constants/deploy-data/deploy-data-optimism.json.mjs +858 -19
- package/constants/deploy-data/deploy-data-polygon.json.cjs +1 -1
- package/constants/deploy-data/deploy-data-polygon.json.mjs +844 -9
- package/constants/kyc.constants.cjs +1 -1
- package/constants/kyc.constants.mjs +30 -18
- package/constants/server.constants.cjs +1 -1
- package/constants/server.constants.d.ts +3 -2
- package/constants/server.constants.mjs +7 -6
- package/constants/token-data/ERC20Registry.cjs +1 -1
- package/constants/token-data/ERC20Registry.mjs +48 -48
- package/constants/token-data/arbMainnetRegistry.json.cjs +1 -1
- package/constants/token-data/arbMainnetRegistry.json.mjs +4 -1
- package/constants/token-data/arbMainnetRegistryFixed.json.cjs +1 -1
- package/constants/token-data/arbMainnetRegistryFixed.json.mjs +4 -1
- package/constants/token-data/avalancheRegistry.json.cjs +1 -1
- package/constants/token-data/avalancheRegistry.json.mjs +4 -1
- package/constants/token-data/avalancheRegistryFixed.json.cjs +1 -1
- package/constants/token-data/avalancheRegistryFixed.json.mjs +4 -1
- package/constants/token-data/baseRegistry.json.cjs +1 -1
- package/constants/token-data/baseRegistry.json.mjs +4 -1
- package/constants/token-data/baseRegistryFixed.json.cjs +1 -1
- package/constants/token-data/baseRegistryFixed.json.mjs +4 -1
- package/constants/token-data/bnbMainnetRegistry.json.cjs +1 -1
- package/constants/token-data/bnbMainnetRegistry.json.mjs +12 -9
- package/constants/token-data/bnbMainnetRegistryFixed.json.cjs +1 -1
- package/constants/token-data/bnbMainnetRegistryFixed.json.mjs +12 -9
- package/constants/token-data/ethMainnetRegistry.json.cjs +1 -1
- package/constants/token-data/ethMainnetRegistry.json.mjs +15 -12
- package/constants/token-data/ethMainnetRegistryFixed.json.cjs +1 -1
- package/constants/token-data/ethMainnetRegistryFixed.json.mjs +15 -12
- package/constants/token-data/index.cjs +1 -0
- package/constants/token-data/index.d.ts +972 -15
- package/constants/token-data/index.mjs +34 -0
- package/constants/token-data/localhostRegistry.json.cjs +1 -1
- package/constants/token-data/localhostRegistry.json.mjs +15 -12
- package/constants/token-data/optimismRegistry.json.cjs +1 -1
- package/constants/token-data/optimismRegistry.json.mjs +4 -1
- package/constants/token-data/optimismRegistryFixed.json.cjs +1 -1
- package/constants/token-data/optimismRegistryFixed.json.mjs +4 -1
- package/constants/token-data/polygonRegistry.json.cjs +1 -1
- package/constants/token-data/polygonRegistry.json.mjs +4 -1
- package/constants/token-data/polygonRegistryFixed.json.cjs +1 -1
- package/constants/token-data/polygonRegistryFixed.json.mjs +4 -1
- package/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.d.ts +2 -0
- package/data-structures/Hinkal/Hinkal.mjs +38 -32
- package/data-structures/Hinkal/IHinkal.d.ts +2 -0
- package/data-structures/Hinkal/hinkalActionBeefy.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionBeefy.mjs +21 -20
- package/data-structures/Hinkal/hinkalActionConvex.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionConvex.mjs +13 -12
- package/data-structures/Hinkal/hinkalActionCurve.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionCurve.mjs +15 -14
- package/data-structures/Hinkal/hinkalActionLidoEth.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionLidoEth.mjs +17 -16
- package/data-structures/Hinkal/hinkalActionPendle.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionPendle.d.ts +1 -1
- package/data-structures/Hinkal/hinkalActionPendle.mjs +24 -23
- package/data-structures/Hinkal/hinkalActionPendleLP.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionPendleLP.mjs +21 -20
- package/data-structures/Hinkal/hinkalActionStake.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionStake.d.ts +1 -1
- package/data-structures/Hinkal/hinkalActionStake.mjs +6 -5
- package/data-structures/Hinkal/hinkalActionVolatile.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionVolatile.d.ts +1 -1
- package/data-structures/Hinkal/hinkalActionVolatile.mjs +9 -8
- package/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
- package/data-structures/Hinkal/hinkalDeposit.d.ts +2 -2
- package/data-structures/Hinkal/hinkalDeposit.mjs +93 -54
- package/data-structures/Hinkal/hinkalGetZkMeProvider.cjs +1 -1
- package/data-structures/Hinkal/hinkalGetZkMeProvider.mjs +3 -2
- package/data-structures/Hinkal/hinkalPrivateWallet.cjs +1 -1
- package/data-structures/Hinkal/hinkalPrivateWallet.mjs +5 -4
- package/data-structures/Hinkal/hinkalSwap.cjs +1 -1
- package/data-structures/Hinkal/hinkalSwap.mjs +23 -22
- package/data-structures/Hinkal/hinkalWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalWithdraw.d.ts +1 -1
- package/data-structures/Hinkal/hinkalWithdraw.mjs +13 -12
- package/data-structures/cacheDevices/LocalStorageCacheDevice.cjs +1 -1
- package/data-structures/cacheDevices/LocalStorageCacheDevice.d.ts +1 -1
- package/data-structures/cacheDevices/LocalStorageCacheDevice.mjs +2 -2
- package/data-structures/custom-token-registry/CustomTokenRegistry.cjs +1 -1
- package/data-structures/custom-token-registry/CustomTokenRegistry.mjs +14 -18
- package/data-structures/merkle-tree/MerkleTree.cjs +1 -1
- package/data-structures/merkle-tree/MerkleTree.d.ts +2 -0
- package/data-structures/merkle-tree/MerkleTree.mjs +38 -25
- package/data-structures/merkle-tree/getPatchedAccessTokenMerkleTree.cjs +1 -0
- package/data-structures/merkle-tree/getPatchedAccessTokenMerkleTree.d.ts +3 -0
- package/data-structures/merkle-tree/getPatchedAccessTokenMerkleTree.mjs +9 -0
- package/data-structures/merkle-tree/index.d.ts +1 -0
- package/data-structures/transactions-manager/TransactionsManager.cjs +1 -1
- package/data-structures/transactions-manager/TransactionsManager.d.ts +6 -5
- package/data-structures/transactions-manager/TransactionsManager.mjs +118 -111
- package/error-handling/error-codes.constants.cjs +1 -1
- package/error-handling/error-codes.constants.d.ts +4 -0
- package/error-handling/error-codes.constants.mjs +6 -2
- package/externalABIs/BabPassport.json.cjs +1 -1
- package/externalABIs/BabPassport.json.mjs +8 -3
- package/externalABIs/BeefyRouterAbi.json.cjs +1 -1
- package/externalABIs/BeefyRouterAbi.json.mjs +5 -2
- package/externalABIs/BeefyStrategyAbi.json.cjs +1 -1
- package/externalABIs/BeefyStrategyAbi.json.mjs +5 -2
- package/externalABIs/BeefyVaultAbi.json.cjs +1 -1
- package/externalABIs/BeefyVaultAbi.json.mjs +5 -2
- package/externalABIs/BeefyZapAbi.json.cjs +1 -1
- package/externalABIs/BeefyZapAbi.json.mjs +5 -2
- package/externalABIs/BeefyZapOneInchAbi.json.cjs +1 -1
- package/externalABIs/BeefyZapOneInchAbi.json.mjs +5 -2
- package/externalABIs/ConvexBoosterAbi.json.cjs +1 -1
- package/externalABIs/ConvexBoosterAbi.json.mjs +5 -2
- package/externalABIs/ConvexBoosterAbiMainnet.json.cjs +1 -1
- package/externalABIs/ConvexBoosterAbiMainnet.json.mjs +5 -2
- package/externalABIs/ConvexRewardPoolAbi.json.cjs +1 -1
- package/externalABIs/ConvexRewardPoolAbi.json.mjs +5 -2
- package/externalABIs/CurveReadingWrapperAbi.json.cjs +1 -1
- package/externalABIs/CurveReadingWrapperAbi.json.mjs +5 -2
- package/externalABIs/CurveWrappedMainPool.json.cjs +1 -1
- package/externalABIs/CurveWrappedMainPool.json.mjs +5 -2
- package/externalABIs/CurveZap.json.cjs +1 -1
- package/externalABIs/CurveZap.json.mjs +5 -2
- package/externalABIs/CvxCrvUtilities.json.cjs +1 -1
- package/externalABIs/CvxCrvUtilities.json.mjs +5 -2
- package/externalABIs/ERC20.json.cjs +1 -1
- package/externalABIs/ERC20.json.mjs +20 -3
- package/externalABIs/GalxePassport.json.cjs +1 -1
- package/externalABIs/GalxePassport.json.mjs +8 -3
- package/externalABIs/IQuoterV2.json.cjs +1 -1
- package/externalABIs/IQuoterV2.json.mjs +20 -3
- package/externalABIs/ISwapRouter.json.cjs +1 -1
- package/externalABIs/ISwapRouter.json.mjs +5 -2
- package/externalABIs/IUniswapV3Factory.json.cjs +1 -1
- package/externalABIs/IUniswapV3Factory.json.mjs +20 -3
- package/externalABIs/IUniswapV3Pool.json.cjs +1 -1
- package/externalABIs/IUniswapV3Pool.json.mjs +20 -3
- package/externalABIs/PendleRouterAbi.json.cjs +1 -1
- package/externalABIs/PendleRouterAbi.json.mjs +5 -2
- package/externalABIs/UniswapV2PoolAbi.json.cjs +1 -1
- package/externalABIs/UniswapV2PoolAbi.json.mjs +16 -3
- package/externalABIs/index.cjs +1 -0
- package/externalABIs/index.d.ts +307 -11
- package/externalABIs/index.mjs +23 -0
- package/externalABIs/transactionsProver.json.cjs +1 -1
- package/externalABIs/transactionsProver.json.mjs +20 -3
- package/functions/kyc/zkMeHelper.cjs +1 -1
- package/functions/kyc/zkMeHelper.d.ts +0 -1
- package/functions/kyc/zkMeHelper.mjs +8 -11
- package/functions/pre-transaction/process-gas-estimates.cjs +1 -1
- package/functions/pre-transaction/process-gas-estimates.mjs +3 -2
- package/functions/private-wallet/emporium.helpers.cjs +1 -1
- package/functions/private-wallet/emporium.helpers.d.ts +8 -3
- package/functions/private-wallet/emporium.helpers.mjs +23 -11
- package/functions/private-wallet/index.d.ts +1 -0
- package/functions/private-wallet/opProducer.cjs +1 -1
- package/functions/private-wallet/opProducer.mjs +9 -10
- package/functions/private-wallet/smartContractWalletCalculator.cjs +1 -0
- package/functions/private-wallet/smartContractWalletCalculator.d.ts +1 -0
- package/functions/private-wallet/smartContractWalletCalculator.mjs +20 -0
- package/functions/protocols/convex.protocols.cjs +1 -1
- package/functions/protocols/convex.protocols.mjs +3 -2
- package/functions/protocols/pendle.helpers.cjs +1 -1
- package/functions/protocols/pendle.helpers.mjs +1 -1
- package/functions/snarkjs/constant.cjs +1 -1
- package/functions/snarkjs/constant.d.ts +1 -0
- package/functions/snarkjs/constant.mjs +6 -5
- package/functions/snarkjs/constructEmporiumProof.cjs +1 -1
- package/functions/snarkjs/constructEmporiumProof.d.ts +1 -1
- package/functions/snarkjs/constructEmporiumProof.mjs +31 -31
- package/functions/snarkjs/constructGeneralZkProof.cjs +1 -1
- package/functions/snarkjs/constructGeneralZkProof.d.ts +1 -1
- package/functions/snarkjs/constructGeneralZkProof.mjs +76 -75
- package/functions/snarkjs/generateZkProof.cjs +1 -1
- package/functions/snarkjs/generateZkProof.d.ts +1 -1
- package/functions/snarkjs/generateZkProof.mjs +4 -15
- package/functions/snarkjs/generateZkProofEnclave.cjs +1 -0
- package/functions/snarkjs/generateZkProofEnclave.d.ts +5 -0
- package/functions/snarkjs/generateZkProofEnclave.mjs +33 -0
- package/functions/snarkjs/generateZkProofSelf.cjs +1 -0
- package/functions/snarkjs/generateZkProofSelf.d.ts +5 -0
- package/functions/snarkjs/generateZkProofSelf.mjs +17 -0
- package/functions/utils/axelar.utils.cjs +1 -1
- package/functions/utils/axelar.utils.mjs +3 -2
- package/functions/utils/cacheDevice.utils.cjs +1 -1
- package/functions/utils/cacheDevice.utils.mjs +2 -1
- package/functions/utils/erc20tokenFunctions.cjs +1 -1
- package/functions/utils/erc20tokenFunctions.mjs +8 -7
- package/functions/utils/evmNetworkFunctions.cjs +1 -1
- package/functions/utils/evmNetworkFunctions.mjs +4 -3
- package/functions/utils/string.utils.cjs +1 -1
- package/functions/utils/string.utils.d.ts +1 -0
- package/functions/utils/string.utils.mjs +16 -6
- package/functions/utils/userAgent.cjs +1 -1
- package/functions/utils/userAgent.mjs +8 -8
- package/functions/web3/functionCalls/accessTokenCalls.cjs +1 -1
- package/functions/web3/functionCalls/accessTokenCalls.mjs +8 -8
- package/functions/web3/functionCalls/transactCallDirect.cjs +1 -1
- package/functions/web3/functionCalls/transactCallDirect.d.ts +1 -1
- package/functions/web3/functionCalls/transactCallDirect.mjs +43 -29
- package/functions/web3/functionCalls/transactCallRelayer.cjs +1 -1
- package/functions/web3/functionCalls/transactCallRelayer.mjs +10 -8
- package/functions/web3/getContractMetadata.cjs +1 -0
- package/functions/web3/getContractMetadata.d.ts +5 -0
- package/functions/web3/getContractMetadata.mjs +30 -0
- package/functions/web3/odosAPI.cjs +1 -1
- package/functions/web3/odosAPI.d.ts +1 -2
- package/functions/web3/odosAPI.mjs +19 -18
- package/functions/web3/oneInchAPI.cjs +1 -1
- package/functions/web3/oneInchAPI.d.ts +1 -2
- package/functions/web3/oneInchAPI.mjs +17 -15
- package/functions/web3/uniswapAPI.cjs +1 -1
- package/functions/web3/uniswapAPI.d.ts +4 -4
- package/functions/web3/uniswapAPI.mjs +54 -43
- package/index.cjs +1 -1
- package/index.mjs +620 -638
- package/package.json +3 -2
- package/providers/EthersProviderAdapter.cjs +1 -1
- package/providers/EthersProviderAdapter.d.ts +1 -0
- package/providers/EthersProviderAdapter.mjs +26 -37
- package/providers/WagmiProviderAdapter.cjs +1 -1
- package/providers/WagmiProviderAdapter.d.ts +1 -0
- package/providers/WagmiProviderAdapter.mjs +45 -56
- package/providers/prepareEthersHinkal.cjs +1 -1
- package/providers/prepareEthersHinkal.mjs +4 -3
- package/providers/prepareWagmiHinkal.cjs +1 -1
- package/providers/prepareWagmiHinkal.mjs +4 -3
- package/types/ethereum-network.types.cjs +1 -1
- package/types/ethereum-network.types.d.ts +64 -59
- package/types/ethereum-network.types.mjs +1 -1
- package/types/hinkal.types.d.ts +5 -0
- package/types/kyc.types.cjs +1 -1
- package/types/kyc.types.d.ts +1 -1
- package/types/kyc.types.mjs +1 -1
- package/types/remote-proof.types.d.ts +15 -0
- package/types/rewards.types.d.ts +5 -0
- package/types/time.types.cjs +1 -1
- package/types/time.types.mjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.cjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.mjs +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { networkRegistry as
|
|
1
|
+
import { networkRegistry as x } from "../../constants/chains.constants.mjs";
|
|
2
2
|
import { transactionErrorCodes as A } from "../../error-handling/error-codes.constants.mjs";
|
|
3
3
|
import "ethers";
|
|
4
4
|
import "axios";
|
|
@@ -29,13 +29,13 @@ const X = async (t, e, o, u, d = [], l, E = !1) => {
|
|
|
29
29
|
});
|
|
30
30
|
const i = [...await I(t, e, o)], a = [];
|
|
31
31
|
for (let r = 0; r < e.length; r += 1) {
|
|
32
|
-
const { outputUtxos:
|
|
33
|
-
a.push(
|
|
32
|
+
const { outputUtxos: g } = C(t.userKeys, i[r], o[r]);
|
|
33
|
+
a.push(g);
|
|
34
34
|
}
|
|
35
35
|
const s = await t.getRandomRelay();
|
|
36
36
|
if (!s)
|
|
37
37
|
throw Error(A.RELAYER_NOT_AVAILABLE);
|
|
38
|
-
const { contractData:
|
|
38
|
+
const { contractData: y } = x[t.getCurrentChainId()], { emporiumAddress: p } = y;
|
|
39
39
|
if (!p)
|
|
40
40
|
throw Error("No Emporium Address Provided");
|
|
41
41
|
const { zkCallData: n, circomData: c, dimData: f } = await R(
|
|
@@ -48,6 +48,7 @@ const X = async (t, e, o, u, d = [], l, E = !1) => {
|
|
|
48
48
|
i[0].length,
|
|
49
49
|
p,
|
|
50
50
|
d,
|
|
51
|
+
t.generateProofRemotely,
|
|
51
52
|
s,
|
|
52
53
|
t.getCurrentChainId(),
|
|
53
54
|
u,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("../../constants/chains.constants.cjs"),I=require("../../error-handling/error-codes.constants.cjs"),m=require("../../functions/pre-transaction/getFlatFees.cjs"),U=require("../../functions/pre-transaction/processAmountChanges.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("../../constants/chains.constants.cjs"),I=require("../../error-handling/error-codes.constants.cjs"),m=require("../../functions/pre-transaction/getFlatFees.cjs"),U=require("../../functions/pre-transaction/processAmountChanges.cjs"),P=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),b=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),S=require("../../functions/web3/events/getShieldedBalance.cjs"),T=require("../../functions/web3/functionCalls/estimateGasRelayer.cjs"),D=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),c=require("../../types/external-action.types.cjs"),F=(e,s)=>{const{contractData:t}=q.networkRegistry[e.getCurrentChainId()];let r;switch(s){case c.ExternalActionId.Uniswap:r=t?.uniswapExternalActionAddress;break;case c.ExternalActionId.Odos:r=t?.odosExternalActionInstanceAddress;break;case c.ExternalActionId.OneInch:r=t?.oneInchExternalActionInstanceAddress;break;default:r=t?.uniswapExternalActionAddress;break}if(!r)throw new Error("No external Address set during swap");return r},_=async(e,s,t,r,g,p=!1,w=!1)=>{const{flatFees:i,feeUnit:y}=await m.getFlatFees(e.getCurrentChainId(),s,r,t);t=U.processAmountChanges({erc20Addresses:s,amountChanges:t,flatFees:i,feeUnit:y,externalActionId:r});const E=F(e,r),n={externalActionId:r,externalAddress:E,externalActionMetadata:g},o=[...await S.addPaddingToUtxos(e,s,t)],f=`swapperM${t.length.toString()}x${o[0].length}x1`,C=[!1,!0],l=[];for(let a=0;a<s.length;a+=1){const{outputUtxos:R}=P.outputUtxoProcessing(e.userKeys,o[a],t[a]);l.push(R)}const u=await e.getRandomRelay();if(!u)throw Error(I.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const{zkCallData:d,circomData:A,dimData:x}=await b.constructZkProof(e.merkleTreeHinkal,e.merkleTreeAccessToken,o,l,e.userKeys,f,n.externalActionId,n.externalAddress,n.externalActionMetadata,e.generateProofRemotely,u,e.getCurrentChainId(),C,i);return p?await T.estimateGasRelayer(e,d,x,A):await D.transactCallRelayer(e.getCurrentChainId(),d,x,A,w)};exports.hinkalSwap=_;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { networkRegistry as
|
|
1
|
+
import { networkRegistry as C } from "../../constants/chains.constants.mjs";
|
|
2
2
|
import { transactionErrorCodes as I } from "../../error-handling/error-codes.constants.mjs";
|
|
3
3
|
import { getFlatFees as U } from "../../functions/pre-transaction/getFlatFees.mjs";
|
|
4
4
|
import { processAmountChanges as D } from "../../functions/pre-transaction/processAmountChanges.mjs";
|
|
5
5
|
import { outputUtxoProcessing as T } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
|
|
6
6
|
import { constructZkProof as b } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
|
|
7
|
-
import { addPaddingToUtxos as
|
|
8
|
-
import { estimateGasRelayer as
|
|
9
|
-
import { transactCallRelayer as
|
|
7
|
+
import { addPaddingToUtxos as P } from "../../functions/web3/events/getShieldedBalance.mjs";
|
|
8
|
+
import { estimateGasRelayer as F } from "../../functions/web3/functionCalls/estimateGasRelayer.mjs";
|
|
9
|
+
import { transactCallRelayer as L } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
|
|
10
10
|
import { ExternalActionId as i } from "../../types/external-action.types.mjs";
|
|
11
|
-
const
|
|
12
|
-
const { contractData: e } =
|
|
11
|
+
const M = (t, o) => {
|
|
12
|
+
const { contractData: e } = C[t.getCurrentChainId()];
|
|
13
13
|
let r;
|
|
14
|
-
switch (
|
|
14
|
+
switch (o) {
|
|
15
15
|
case i.Uniswap:
|
|
16
16
|
r = e?.uniswapExternalActionAddress;
|
|
17
17
|
break;
|
|
@@ -28,49 +28,50 @@ const N = (t, a) => {
|
|
|
28
28
|
if (!r)
|
|
29
29
|
throw new Error("No external Address set during swap");
|
|
30
30
|
return r;
|
|
31
|
-
},
|
|
31
|
+
}, V = async (t, o, e, r, u, A = !1, x = !1) => {
|
|
32
32
|
const { flatFees: c, feeUnit: w } = await U(
|
|
33
33
|
t.getCurrentChainId(),
|
|
34
|
-
|
|
34
|
+
o,
|
|
35
35
|
r,
|
|
36
36
|
e
|
|
37
37
|
);
|
|
38
|
-
e = D({ erc20Addresses:
|
|
39
|
-
const
|
|
38
|
+
e = D({ erc20Addresses: o, amountChanges: e, flatFees: c, feeUnit: w, externalActionId: r });
|
|
39
|
+
const g = M(t, r), s = {
|
|
40
40
|
externalActionId: r,
|
|
41
|
-
externalAddress:
|
|
41
|
+
externalAddress: g,
|
|
42
42
|
externalActionMetadata: u
|
|
43
|
-
}, n = [...await
|
|
44
|
-
for (let
|
|
45
|
-
const { outputUtxos:
|
|
46
|
-
d.push(
|
|
43
|
+
}, n = [...await P(t, o, e)], E = `swapperM${e.length.toString()}x${n[0].length}x1`, y = [!1, !0], d = [];
|
|
44
|
+
for (let a = 0; a < o.length; a += 1) {
|
|
45
|
+
const { outputUtxos: R } = T(t.userKeys, n[a], e[a]);
|
|
46
|
+
d.push(R);
|
|
47
47
|
}
|
|
48
48
|
const l = await t.getRandomRelay();
|
|
49
49
|
if (!l)
|
|
50
50
|
throw Error(I.RELAYER_NOT_AVAILABLE);
|
|
51
|
-
const { zkCallData:
|
|
51
|
+
const { zkCallData: m, circomData: p, dimData: f } = await b(
|
|
52
52
|
t.merkleTreeHinkal,
|
|
53
53
|
t.merkleTreeAccessToken,
|
|
54
54
|
n,
|
|
55
55
|
d,
|
|
56
56
|
t.userKeys,
|
|
57
|
-
|
|
57
|
+
E,
|
|
58
58
|
s.externalActionId,
|
|
59
59
|
s.externalAddress,
|
|
60
60
|
s.externalActionMetadata,
|
|
61
|
+
t.generateProofRemotely,
|
|
61
62
|
l,
|
|
62
63
|
t.getCurrentChainId(),
|
|
63
64
|
y,
|
|
64
65
|
c
|
|
65
66
|
);
|
|
66
|
-
return A ? await
|
|
67
|
+
return A ? await F(t, m, f, p) : await L(
|
|
67
68
|
t.getCurrentChainId(),
|
|
68
|
-
p,
|
|
69
|
-
f,
|
|
70
69
|
m,
|
|
70
|
+
f,
|
|
71
|
+
p,
|
|
71
72
|
x
|
|
72
73
|
);
|
|
73
74
|
};
|
|
74
75
|
export {
|
|
75
|
-
|
|
76
|
+
V as hinkalSwap
|
|
76
77
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("../../constants/protocol.constants.cjs"),I=require("../../error-handling/error-codes.constants.cjs"),f=require("../../functions/utils/erc20tokenFunctions.cjs"),m=require("../../functions/pre-transaction/getFlatFees.cjs"),F=require("../../functions/pre-transaction/processAmountChanges.cjs"),D=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("../../constants/protocol.constants.cjs"),I=require("../../error-handling/error-codes.constants.cjs"),f=require("../../functions/utils/erc20tokenFunctions.cjs"),m=require("../../functions/pre-transaction/getFlatFees.cjs"),F=require("../../functions/pre-transaction/processAmountChanges.cjs"),D=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),P=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),R=require("../../functions/web3/events/getShieldedBalance.cjs"),U=require("../../functions/web3/functionCalls/estimateGasRelayer.cjs"),_=require("../../functions/web3/functionCalls/transactCallDirect.cjs"),M=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),g=require("../../types/external-action.types.cjs"),N=async(t,o,e,C,n,p=!1)=>{const{flatFees:d,feeUnit:w}=await m.getFlatFees(t.getCurrentChainId(),o,g.ExternalActionId.Transact,e);n||F.processAmountChanges({erc20Addresses:o,amountChanges:e,flatFees:d,feeUnit:w,externalActionId:g.ExternalActionId.Transact});const a=f.getERC20Token(o[0],t.getCurrentChainId());if(!a)throw Error("Deposit Action: No Token Found");const s={externalActionId:0n,externalAddress:C,externalActionMetadata:"0x00"},c=[...await R.addPaddingToUtxos(t,o,e)],q=`swapperM${e.length.toString()}x${c[0].length}x1`,y=[!1],x=[];for(let r=0;r<o.length;r+=1){const{outputUtxos:E}=D.outputUtxoProcessing(t.userKeys,c[r],e[r]);x.push(E)}const A=await t.getRandomRelay();if(!n&&!A)throw Error(I.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const{zkCallData:i,circomData:u,dimData:l}=await P.constructZkProof(t.merkleTreeHinkal,t.merkleTreeAccessToken,c,x,t.userKeys,q,s.externalActionId,s.externalAddress,s.externalActionMetadata,t.generateProofRemotely,n?T.zeroAddress:A,t.getCurrentChainId(),y,d);if(p)return await U.estimateGasRelayer(t,i,l,u);if(n){if(!a)throw Error("Withdraw Action: No Token Found");return await _.transactCallDirect(t,e[0],a,i,u,l)}return await M.transactCallRelayer(t.getCurrentChainId(),i,l,u)};exports.hinkalWithdraw=N;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { IHinkal } from './IHinkal';
|
|
2
|
-
export declare const hinkalWithdraw: (hinkal: IHinkal, erc20Addresses: string[], amountChanges: bigint[], recipientAddress: string, isRelayerOff: boolean, onlyGasEstimate?: boolean) => Promise<
|
|
2
|
+
export declare const hinkalWithdraw: (hinkal: IHinkal, erc20Addresses: string[], amountChanges: bigint[], recipientAddress: string, isRelayerOff: boolean, onlyGasEstimate?: boolean) => Promise<any>;
|
|
@@ -4,13 +4,13 @@ import { getERC20Token as y } from "../../functions/utils/erc20tokenFunctions.mj
|
|
|
4
4
|
import { getFlatFees as D } from "../../functions/pre-transaction/getFlatFees.mjs";
|
|
5
5
|
import { processAmountChanges as U } from "../../functions/pre-transaction/processAmountChanges.mjs";
|
|
6
6
|
import { outputUtxoProcessing as F } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
|
|
7
|
-
import { constructZkProof as
|
|
8
|
-
import { addPaddingToUtxos as
|
|
9
|
-
import { estimateGasRelayer as
|
|
10
|
-
import { transactCallDirect as
|
|
11
|
-
import { transactCallRelayer as
|
|
7
|
+
import { constructZkProof as R } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
|
|
8
|
+
import { addPaddingToUtxos as N } from "../../functions/web3/events/getShieldedBalance.mjs";
|
|
9
|
+
import { estimateGasRelayer as P } from "../../functions/web3/functionCalls/estimateGasRelayer.mjs";
|
|
10
|
+
import { transactCallDirect as L } from "../../functions/web3/functionCalls/transactCallDirect.mjs";
|
|
11
|
+
import { transactCallRelayer as M } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
|
|
12
12
|
import { ExternalActionId as l } from "../../types/external-action.types.mjs";
|
|
13
|
-
const
|
|
13
|
+
const j = async (t, e, r, u, a, A = !1) => {
|
|
14
14
|
const { flatFees: x, feeUnit: w } = await D(
|
|
15
15
|
t.getCurrentChainId(),
|
|
16
16
|
e,
|
|
@@ -31,7 +31,7 @@ const h = async (t, e, r, u, a, A = !1) => {
|
|
|
31
31
|
externalActionId: 0n,
|
|
32
32
|
externalAddress: u,
|
|
33
33
|
externalActionMetadata: "0x00"
|
|
34
|
-
}, c = [...await
|
|
34
|
+
}, c = [...await N(t, e, r)], g = `swapperM${r.length.toString()}x${c[0].length}x1`, C = [!1], d = [];
|
|
35
35
|
for (let o = 0; o < e.length; o += 1) {
|
|
36
36
|
const { outputUtxos: E } = F(t.userKeys, c[o], r[o]);
|
|
37
37
|
d.push(E);
|
|
@@ -39,7 +39,7 @@ const h = async (t, e, r, u, a, A = !1) => {
|
|
|
39
39
|
const f = await t.getRandomRelay();
|
|
40
40
|
if (!a && !f)
|
|
41
41
|
throw Error(I.RELAYER_NOT_AVAILABLE);
|
|
42
|
-
const { zkCallData: s, circomData: m, dimData: p } = await
|
|
42
|
+
const { zkCallData: s, circomData: m, dimData: p } = await R(
|
|
43
43
|
t.merkleTreeHinkal,
|
|
44
44
|
t.merkleTreeAccessToken,
|
|
45
45
|
c,
|
|
@@ -49,20 +49,21 @@ const h = async (t, e, r, u, a, A = !1) => {
|
|
|
49
49
|
i.externalActionId,
|
|
50
50
|
i.externalAddress,
|
|
51
51
|
i.externalActionMetadata,
|
|
52
|
+
t.generateProofRemotely,
|
|
52
53
|
a ? T : f,
|
|
53
54
|
t.getCurrentChainId(),
|
|
54
55
|
C,
|
|
55
56
|
x
|
|
56
57
|
);
|
|
57
58
|
if (A)
|
|
58
|
-
return await
|
|
59
|
+
return await P(t, s, p, m);
|
|
59
60
|
if (a) {
|
|
60
61
|
if (!n)
|
|
61
62
|
throw Error("Withdraw Action: No Token Found");
|
|
62
|
-
return await
|
|
63
|
+
return await L(t, r[0], n, s, m, p);
|
|
63
64
|
}
|
|
64
|
-
return await
|
|
65
|
+
return await M(t.getCurrentChainId(), s, p, m);
|
|
65
66
|
};
|
|
66
67
|
export {
|
|
67
|
-
|
|
68
|
+
j as hinkalWithdraw
|
|
68
69
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./BaseCacheDevice.cjs");class o extends a.BaseCacheDevice{localDataStorage;constructor(){super()
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./BaseCacheDevice.cjs");class o extends a.BaseCacheDevice{localDataStorage;constructor(e){super(),!e&&typeof localStorage<"u"&&(this.localDataStorage=localStorage)}get(e){return this.localDataStorage?this.localDataStorage.getItem(e)??void 0:this.getInMemory(e)}set(e,t){this.localDataStorage?this.localDataStorage.setItem(e,t):this.setInMemory(e,t)}}exports.LocalStorageCacheDevice=o;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseCacheDevice } from './BaseCacheDevice';
|
|
2
2
|
export declare class LocalStorageCacheDevice extends BaseCacheDevice {
|
|
3
3
|
private localDataStorage;
|
|
4
|
-
constructor();
|
|
4
|
+
constructor(disableCaching?: boolean);
|
|
5
5
|
get(key: string): string | undefined;
|
|
6
6
|
set(key: string, value: string): void;
|
|
7
7
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BaseCacheDevice as a } from "./BaseCacheDevice.mjs";
|
|
2
2
|
class l extends a {
|
|
3
3
|
localDataStorage;
|
|
4
|
-
constructor() {
|
|
5
|
-
super(), typeof localStorage < "u" && (this.localDataStorage = localStorage);
|
|
4
|
+
constructor(t) {
|
|
5
|
+
super(), !t && typeof localStorage < "u" && (this.localDataStorage = localStorage);
|
|
6
6
|
}
|
|
7
7
|
get(t) {
|
|
8
8
|
return this.localDataStorage ? this.localDataStorage.getItem(t) ?? void 0 : this.getInMemory(t);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class o{localStorageKey="tokenRegistry";tokenRegistry;constructor(){
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class o{localStorageKey="tokenRegistry";tokenRegistry;constructor(){this.tokenRegistry=[]}persistRegistry(){}getCustomTokens(s){return this.tokenRegistry.filter(t=>t.chainId===s)}tokenExists(s,t){return s.find(e=>e.erc20TokenAddress===t.erc20TokenAddress||e.symbol===t.symbol||e.name===t.name)}addCustomToken(s){const{chainId:t}=s,e=this.getCustomTokens(t);this.tokenExists(e,s)||this.tokenRegistry.push(s),this.persistRegistry()}removeCustomToken(s){const{chainId:t}=s,r=this.getCustomTokens(t).filter(i=>i.erc20TokenAddress!==s.erc20TokenAddress);this.tokenRegistry=r,this.persistRegistry()}}const n=new o;exports.customTokenRegistry=n;
|
|
@@ -1,33 +1,29 @@
|
|
|
1
|
-
class
|
|
1
|
+
class n {
|
|
2
2
|
localStorageKey = "tokenRegistry";
|
|
3
3
|
tokenRegistry;
|
|
4
4
|
constructor() {
|
|
5
|
-
|
|
6
|
-
const t = localStorage.getItem(this.localStorageKey);
|
|
7
|
-
t && (this.tokenRegistry = JSON.parse(t));
|
|
8
|
-
}
|
|
5
|
+
this.tokenRegistry = [];
|
|
9
6
|
}
|
|
10
7
|
persistRegistry() {
|
|
11
|
-
typeof localStorage < "u" && localStorage.setItem(this.localStorageKey, JSON.stringify(this.tokenRegistry));
|
|
12
8
|
}
|
|
13
|
-
getCustomTokens(
|
|
14
|
-
return this.tokenRegistry.filter((
|
|
9
|
+
getCustomTokens(s) {
|
|
10
|
+
return this.tokenRegistry.filter((t) => t.chainId === s);
|
|
15
11
|
}
|
|
16
|
-
tokenExists(
|
|
17
|
-
return
|
|
18
|
-
(e) => e.erc20TokenAddress ===
|
|
12
|
+
tokenExists(s, t) {
|
|
13
|
+
return s.find(
|
|
14
|
+
(e) => e.erc20TokenAddress === t.erc20TokenAddress || e.symbol === t.symbol || e.name === t.name
|
|
19
15
|
);
|
|
20
16
|
}
|
|
21
|
-
addCustomToken(
|
|
22
|
-
const { chainId:
|
|
23
|
-
this.tokenExists(e,
|
|
17
|
+
addCustomToken(s) {
|
|
18
|
+
const { chainId: t } = s, e = this.getCustomTokens(t);
|
|
19
|
+
this.tokenExists(e, s) || this.tokenRegistry.push(s), this.persistRegistry();
|
|
24
20
|
}
|
|
25
|
-
removeCustomToken(
|
|
26
|
-
const { chainId:
|
|
21
|
+
removeCustomToken(s) {
|
|
22
|
+
const { chainId: t } = s, r = this.getCustomTokens(t).filter((i) => i.erc20TokenAddress !== s.erc20TokenAddress);
|
|
27
23
|
this.tokenRegistry = r, this.persistRegistry();
|
|
28
24
|
}
|
|
29
25
|
}
|
|
30
|
-
const
|
|
26
|
+
const c = new n();
|
|
31
27
|
export {
|
|
32
|
-
|
|
28
|
+
c as customTokenRegistry
|
|
33
29
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../../error-handling/logError.cjs"),u=require("./MerkleTreeIncompleteError.cjs");class h{constructor(t,e,
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../../error-handling/logError.cjs"),u=require("./MerkleTreeIncompleteError.cjs");class h{constructor(t,e,n,i,r,s){this.hashFunction=t,this.levels=e,this.defaultNodeValue=n,this.tree=i??new Map,this.count=s??0n,this.index=r??2n**(e-1n)}tree;count;index;static createWithData(t,e,n,i,r,s){return new h(i,r,s,t,e,n)}static create(t,e,n){return new h(t,e,n)}getStartIndex(){return 2n**(this.levels-1n)}logarithm2(t){let e=0n;for(;2n**e<t;)e+=1n;return e}bigIntMax(t,e){return t>e?t:e}forceInsert(t,e){if(e<this.getStartIndex())throw new RangeError;this.tree.set(e,t);const n=this.index-this.getStartIndex(),i=this.logarithm2(n);let r=e;for(let s=1n;s<=i;s+=1n){r/=2n;const l=this.hashFunction(this.tree.get(r*2n)||this.defaultNodeValue,this.tree.get(r*2n+1n)||this.defaultNodeValue);this.tree.set(r,l)}}insert(t,e){let n=!1;return this.tree.has(e)&&(n=!0,o.logError(`Editing commitment index: ${e} `)),n||(this.count+=1n),this.index=this.bigIntMax(this.index,e+1n),this.forceInsert(t,e),!0}remove(t){this.forceInsert(this.defaultNodeValue,t)}completenessCheck(){if(this.count!==this.index-this.getStartIndex())throw new u.MerkleTreeIncompleteError}getRootHash(){this.completenessCheck();for(let t=1n;t<2n**this.levels;t*=2n)if(this.tree.get(t))return this.tree.get(t);return this.defaultNodeValue}getMerkleData(){return this.completenessCheck(),new Map(this.tree)}getSiblingIndex(t){return t===1n?1n:t%2n===1n?t-1n:t+1n}getSiblingHashesForVerification(t){this.completenessCheck();let e;for(let i=this.getStartIndex();i<this.getStartIndex()+this.index;i+=1n)if(this.tree.get(i)===t){e=i;break}if(e===void 0)return new Array(Number(this.levels)).fill(0n);const n=[];for(;e!==0n;)n.push(this.tree.get(this.getSiblingIndex(e))||this.defaultNodeValue),e/=2n;return n}getSiblingSides(t){this.completenessCheck();let e;for(let i=this.getStartIndex();i<this.getStartIndex()+this.index;i+=1n)if(this.tree.get(i)===t){e=i;break}if(e===void 0)return new Array(Number(this.levels)).fill(0n);const n=[];for(;e!==0n;){const i=e%2n===0n?0n:1n;n.push(i),e/=2n}return n}toJSON(){const{tree:t,count:e,index:n}=this;return{tree:Object.fromEntries(t),count:e.toString(),index:n.toString()}}clone(){return h.createWithData(new Map(this.tree),this.index,this.count,this.hashFunction,this.levels,this.defaultNodeValue)}getIndex(){return this.index}}exports.MerkleTree=h;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { logError as l } from "../../error-handling/logError.mjs";
|
|
2
2
|
import { MerkleTreeIncompleteError as a } from "./MerkleTreeIncompleteError.mjs";
|
|
3
3
|
class h {
|
|
4
|
-
constructor(e, t,
|
|
5
|
-
this.hashFunction = e, this.levels = t, this.defaultNodeValue =
|
|
4
|
+
constructor(e, t, i, n, r, s) {
|
|
5
|
+
this.hashFunction = e, this.levels = t, this.defaultNodeValue = i, this.tree = n ?? /* @__PURE__ */ new Map(), this.count = s ?? 0n, this.index = r ?? 2n ** (t - 1n);
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* the map where the items are stored
|
|
@@ -18,16 +18,16 @@ class h {
|
|
|
18
18
|
* meaning that there aren't any missing elements between getStartIndex() and index
|
|
19
19
|
*/
|
|
20
20
|
index;
|
|
21
|
-
static createWithData(e, t,
|
|
22
|
-
return new h(
|
|
21
|
+
static createWithData(e, t, i, n, r, s) {
|
|
22
|
+
return new h(n, r, s, e, t, i);
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* @param hashFunction the hashFunction used to fill the upper layers of the merkle tree
|
|
26
26
|
* @param levels the amount of layers in the merkle tree
|
|
27
27
|
* @param defaultNodeValue the default value of an empty node in the merkle tree
|
|
28
28
|
*/
|
|
29
|
-
static create(e, t,
|
|
30
|
-
return new h(e, t,
|
|
29
|
+
static create(e, t, i) {
|
|
30
|
+
return new h(e, t, i);
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* get starting nodeIndex from which inserts are allowed
|
|
@@ -51,9 +51,9 @@ class h {
|
|
|
51
51
|
if (t < this.getStartIndex())
|
|
52
52
|
throw new RangeError();
|
|
53
53
|
this.tree.set(t, e);
|
|
54
|
-
const
|
|
54
|
+
const i = this.index - this.getStartIndex(), n = this.logarithm2(i);
|
|
55
55
|
let r = t;
|
|
56
|
-
for (let s = 1n; s <=
|
|
56
|
+
for (let s = 1n; s <= n; s += 1n) {
|
|
57
57
|
r /= 2n;
|
|
58
58
|
const o = this.hashFunction(
|
|
59
59
|
this.tree.get(r * 2n) || this.defaultNodeValue,
|
|
@@ -70,8 +70,8 @@ class h {
|
|
|
70
70
|
* @throws will throw RangeError if nodeIndex is less than getStartIndex()
|
|
71
71
|
*/
|
|
72
72
|
insert(e, t) {
|
|
73
|
-
let
|
|
74
|
-
return this.tree.has(t) && (
|
|
73
|
+
let i = !1;
|
|
74
|
+
return this.tree.has(t) && (i = !0, l(`Editing commitment index: ${t} `)), i || (this.count += 1n), this.index = this.bigIntMax(this.index, t + 1n), this.forceInsert(e, t), !0;
|
|
75
75
|
}
|
|
76
76
|
remove(e) {
|
|
77
77
|
this.forceInsert(this.defaultNodeValue, e);
|
|
@@ -105,17 +105,17 @@ class h {
|
|
|
105
105
|
getSiblingHashesForVerification(e) {
|
|
106
106
|
this.completenessCheck();
|
|
107
107
|
let t;
|
|
108
|
-
for (let
|
|
109
|
-
if (this.tree.get(
|
|
110
|
-
t =
|
|
108
|
+
for (let n = this.getStartIndex(); n < this.getStartIndex() + this.index; n += 1n)
|
|
109
|
+
if (this.tree.get(n) === e) {
|
|
110
|
+
t = n;
|
|
111
111
|
break;
|
|
112
112
|
}
|
|
113
113
|
if (t === void 0)
|
|
114
114
|
return new Array(Number(this.levels)).fill(0n);
|
|
115
|
-
const
|
|
115
|
+
const i = [];
|
|
116
116
|
for (; t !== 0n; )
|
|
117
|
-
|
|
118
|
-
return
|
|
117
|
+
i.push(this.tree.get(this.getSiblingIndex(t)) || this.defaultNodeValue), t /= 2n;
|
|
118
|
+
return i;
|
|
119
119
|
}
|
|
120
120
|
/**
|
|
121
121
|
* get item's sibling hashes side
|
|
@@ -125,28 +125,41 @@ class h {
|
|
|
125
125
|
getSiblingSides(e) {
|
|
126
126
|
this.completenessCheck();
|
|
127
127
|
let t;
|
|
128
|
-
for (let
|
|
129
|
-
if (this.tree.get(
|
|
130
|
-
t =
|
|
128
|
+
for (let n = this.getStartIndex(); n < this.getStartIndex() + this.index; n += 1n)
|
|
129
|
+
if (this.tree.get(n) === e) {
|
|
130
|
+
t = n;
|
|
131
131
|
break;
|
|
132
132
|
}
|
|
133
133
|
if (t === void 0)
|
|
134
134
|
return new Array(Number(this.levels)).fill(0n);
|
|
135
|
-
const
|
|
135
|
+
const i = [];
|
|
136
136
|
for (; t !== 0n; ) {
|
|
137
|
-
const
|
|
138
|
-
|
|
137
|
+
const n = t % 2n === 0n ? 0n : 1n;
|
|
138
|
+
i.push(n), t /= 2n;
|
|
139
139
|
}
|
|
140
|
-
return
|
|
140
|
+
return i;
|
|
141
141
|
}
|
|
142
142
|
toJSON() {
|
|
143
|
-
const { tree: e, count: t, index:
|
|
143
|
+
const { tree: e, count: t, index: i } = this;
|
|
144
144
|
return {
|
|
145
145
|
tree: Object.fromEntries(e),
|
|
146
146
|
count: t.toString(),
|
|
147
|
-
index:
|
|
147
|
+
index: i.toString()
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
|
+
clone() {
|
|
151
|
+
return h.createWithData(
|
|
152
|
+
new Map(this.tree),
|
|
153
|
+
this.index,
|
|
154
|
+
this.count,
|
|
155
|
+
this.hashFunction,
|
|
156
|
+
this.levels,
|
|
157
|
+
this.defaultNodeValue
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
getIndex() {
|
|
161
|
+
return this.index;
|
|
162
|
+
}
|
|
150
163
|
}
|
|
151
164
|
export {
|
|
152
165
|
h as MerkleTree
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=(t,c,n)=>{if(n)return t;const e=t.clone(),s=e.getIndex(),r=BigInt(c.getAccessKey());return e.insert(r,s),e};exports.getPatchedAccessTokenMerkleTree=o;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("../../constants/chains.constants.cjs");require("../../constants/vite.constants.cjs");require("axios");require("../../constants/coingecko.constants.cjs");const y=require("../../API/API.cjs");require("ethers");require("../../types/curve.types.cjs");const A=require("../../constants/contracts.constants.cjs");require("../../constants/kyc.constants.cjs");require("../../constants/axelar.constants.cjs");require("../../constants/rewards.constants.cjs");require("../../constants/reorg-depths.constants.cjs");const k=require("../../functions/snarkjs/generateZkProof.cjs");require("../../types/circom-data.types.cjs");const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("../../constants/chains.constants.cjs");require("../../constants/vite.constants.cjs");require("axios");require("../../constants/coingecko.constants.cjs");const y=require("../../API/API.cjs");require("ethers");require("../../types/curve.types.cjs");require("../../constants/token-data/index.cjs");const A=require("../../constants/contracts.constants.cjs");require("../../constants/kyc.constants.cjs");require("../../constants/axelar.constants.cjs");require("../../constants/rewards.constants.cjs");require("../../constants/reorg-depths.constants.cjs");const k=require("../../functions/snarkjs/generateZkProof.cjs");require("../../types/circom-data.types.cjs");const m=require("../../types/transactions.types.cjs"),q=require("./history/getTxDetails.cjs");require("circomlibjs-hinkal-fork");const v=require("../../error-handling/error-codes.constants.cjs"),x=require("../crypto-keys/keys.cjs"),w=require("../crypto-keys/encryptDecryptUtxo.cjs"),g=require("../../functions/utils/getDataFromTransaction.cjs"),p=require("../../functions/utils/cacheFunctions.cjs");class C{circuitSize=50;hinkalContract;init(t){this.hinkalContract=t}requireInit(){if(!this.hinkalContract)throw Error("TransactionsManager not initialized")}filterOwnTransactions=async(t,e,r,a)=>{const{transactMethodId:n,transactWithExternalActionMethodId:s,hinkalInterface:i}=A.getHinkalParameters(T.getNonLocalhostChainId(t)),o=c=>"decodedInput"in c,l=e.filter(c=>c.methodId===n||c.methodId===s).map(c=>o(c)?c:{...c,decodedInput:g.decodeTxInput(i,c.input),status:c.isError==="0"?"SUCCESS":"FAILURE"}),h=r.getShieldedPrivateKey();return l.filter(c=>{try{if(o(c)){if(w.decryptUtxo(Buffer.from(c.decodedInput.encryptedOutputs[0].slice(2),"hex"),r),!a&&c.methodId===n){const{extraRandomization:f,H0:I,H1:S}=c.decodedInput.stealthAddressStructure;return x.UserKeys.checkSignature(f,I,S,h)}return!0}return!1}catch{return!1}})};saveTxsInStorage=(t,e,r,a)=>{const n=r.getShieldedPublicKey();return p.saveTxsCache(t,e,n,this.hinkalContract.address,a)};loadTxsFromStorage=async(t,e)=>{const r=e.getShieldedPublicKey();return await p.loadTxsCache(t,r,this.hinkalContract.address)};getAllTransactions=async(t,e,r,a)=>{if(r){const{transactions:o}=await y.API.userGetTransactions(t,r);return o}const{decodedTxs:n,lastHash:s}=await this.loadTxsFromStorage(t,e),{transactions:i}=await y.API.userGetTransactions(t,r,s,a);return[...i,...n]};getHinkalHistoryBase=async(t,e,r,a=!1,n)=>{this.requireInit();const s=await this.getAllTransactions(t,e,r,n)??[];s.sort((o,d)=>d.timeStamp-o.timeStamp);const i=await this.filterOwnTransactions(t,s,e,a);return!r&&s.length>0&&await this.saveTxsInStorage(i,t,e,s[0].hash),i};getHinkalHistory=async(t,e)=>{const r=await this.getHinkalHistoryBase(t,e,void 0,!0),a=g.decodeTxLogs(t,r);return await Promise.all(a.map(async s=>({...s,status:s.status,details:await q.getTxDetails(t,s.decodedInput,s.utxosArray)})))};sortInBatches=t=>{const e=[];let r=0,a=0;t.forEach(i=>{r===0&&e.push([]),e[a].push(i),r+=1,r===this.circuitSize&&(r=0,a+=1)});const n=e[e.length-1],s=n.length;if(s<this.circuitSize){const i=this.circuitSize-s,o=new Array(i).fill(m.emptyDecodedTx);e[e.length-1]=n.concat(o)}return e};generateTransactionsProof=async(t,e,r)=>{const a=this.sortInBatches(e),n=new Array(a.length).fill([]);for(let s=0;s<a.length;s+=1){const i=a[s].map(u=>u.decodedInput.stealthAddressStructure),o=i.map(u=>u.extraRandomization),d=i.map(u=>u.stealthAddress),l={shieldedPrivateKey:r,extraRandomizations:o,stealthAddresses:d},{zkCallData:h}=await k.generateZkProof(t,"transactionsProver",l,!1);n[s]=h}return{zkCallDataArray:n}};userVerifyTransactions=async(t,e,r,a,n)=>await y.API.userVerifyTransactions(t,e,r,a,n);verifyTransactionsInBatches=async(t,e,r,a)=>{const s=e.getBackendToken(),i=e.getShieldedPrivateKey(),o={trade:0,transactions:0,lockedDeposit:0,verification:!0};if(a.length===0){const d=await this.userVerifyTransactions(t,[],[],s,r);Object.assign(o,d)}for(let d=0;d<a.length;d+=15){const l=a.slice(d,d+15),{zkCallDataArray:h}=await this.generateTransactionsProof(t,l,i),u=l.map(f=>f.hash),c=await this.userVerifyTransactions(t,u,h,s,r);if(o.trade+=c.trade,o.transactions+=c.transactions,o.lockedDeposit+=c.lockedDeposit,o.verification&&=c.verification,!o.verification)throw Error("Verification failed for batch of transactions")}return o};processAndSendTransactionsForVerification=async(t,e,r,a,n)=>{this.requireInit();const s=await this.getHinkalHistoryBase(t,e,void 0,void 0,n),i=a?s.findIndex(f=>f.hash===a):void 0,d=s.slice(0,i).reverse(),{trade:l,transactions:h,lockedDeposit:u,verification:c}=await this.verifyTransactionsInBatches(t,e,r,d);return{trade:l,transactions:h,lockedDeposit:u,verification:c}};multiProcessAndSendTransactionsForVerification=async(t,e,r)=>{const a=T.chainIdsByType[T.EthereumNetworkType.Mainnet];let n=!0;for(let s=0;s<a.length;s+=1)try{const i=a[s],o=r?.[i],d=o?.lastCertifiedHash,l=o?.week,{verification:h}=await this.processAndSendTransactionsForVerification(i,t,e,d,l);if(n=n&&h,!n)break}catch(i){console.error(`current chain ${a[s]} certification error`,{err:i}),n=!1;break}if(!n)throw Error(v.transactionErrorCodes.MULTI_VERIFICATION_FAILED);return!0}}exports.TransactionsManager=C;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Contract } from 'ethers';
|
|
2
|
-
import { DecodedTx, RawTx } from '../../types';
|
|
2
|
+
import { DecodedTx, HashInfoByChain, RawTx } from '../../types';
|
|
3
3
|
import { TransactionField } from './history/history.types';
|
|
4
4
|
import { UserKeys } from '../crypto-keys';
|
|
5
5
|
export declare class TransactionsManager {
|
|
@@ -10,17 +10,18 @@ export declare class TransactionsManager {
|
|
|
10
10
|
private filterOwnTransactions;
|
|
11
11
|
private saveTxsInStorage;
|
|
12
12
|
private loadTxsFromStorage;
|
|
13
|
-
getAllTransactions: (chainId: number, userKeys: UserKeys, week?: number) => Promise<RawTx[]>;
|
|
14
|
-
getHinkalHistoryBase: (chainId: number, userKeys: UserKeys, week?: number, includeOthersDeposits?: boolean) => Promise<DecodedTx[]>;
|
|
13
|
+
getAllTransactions: (chainId: number, userKeys: UserKeys, week?: number, startWeek?: number) => Promise<RawTx[]>;
|
|
14
|
+
getHinkalHistoryBase: (chainId: number, userKeys: UserKeys, week?: number, includeOthersDeposits?: boolean, startWeek?: number) => Promise<DecodedTx[]>;
|
|
15
15
|
getHinkalHistory: (chainId: number, userKeys: UserKeys) => Promise<TransactionField[]>;
|
|
16
16
|
private sortInBatches;
|
|
17
17
|
private generateTransactionsProof;
|
|
18
18
|
private userVerifyTransactions;
|
|
19
|
-
|
|
19
|
+
private verifyTransactionsInBatches;
|
|
20
|
+
processAndSendTransactionsForVerification: (chainId: number, userKeys: UserKeys, ethereumAddress: string, latestCertifiedHash?: string, startWeek?: number) => Promise<{
|
|
20
21
|
trade: number;
|
|
21
22
|
transactions: number;
|
|
22
23
|
lockedDeposit: number;
|
|
23
24
|
verification: boolean;
|
|
24
25
|
}>;
|
|
25
|
-
multiProcessAndSendTransactionsForVerification: (userKeys: UserKeys, ethereumAddress: string) => Promise<boolean>;
|
|
26
|
+
multiProcessAndSendTransactionsForVerification: (userKeys: UserKeys, ethereumAddress: string, lastCertifiedHashes?: HashInfoByChain) => Promise<boolean>;
|
|
26
27
|
}
|