@hinkal/common 0.1.61 → 0.1.63
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/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.d.ts +7 -5
- package/data-structures/Hinkal/Hinkal.mjs +22 -17
- package/data-structures/Hinkal/IHinkal.d.ts +5 -3
- package/data-structures/cacheDevices/BaseCacheDevice.cjs +1 -0
- package/data-structures/cacheDevices/BaseCacheDevice.d.ts +8 -0
- package/data-structures/cacheDevices/BaseCacheDevice.mjs +12 -0
- package/data-structures/cacheDevices/FileCacheDevice.cjs +1 -0
- package/data-structures/cacheDevices/FileCacheDevice.d.ts +8 -0
- package/data-structures/cacheDevices/FileCacheDevice.mjs +35 -0
- package/data-structures/cacheDevices/LocalStorageCacheDevice.cjs +1 -0
- package/data-structures/cacheDevices/LocalStorageCacheDevice.d.ts +7 -0
- package/data-structures/cacheDevices/LocalStorageCacheDevice.mjs +16 -0
- package/data-structures/cacheDevices/index.d.ts +2 -0
- package/data-structures/index.d.ts +1 -0
- package/functions/utils/cacheDevice.utils.cjs +1 -0
- package/functions/utils/cacheDevice.utils.d.ts +2 -0
- package/functions/utils/cacheDevice.utils.mjs +20 -0
- package/functions/utils/cacheFunctions.cjs +1 -1
- package/functions/utils/cacheFunctions.d.ts +3 -3
- package/functions/utils/cacheFunctions.mjs +29 -32
- package/functions/utils/index.d.ts +1 -0
- package/index.cjs +1 -1
- package/index.mjs +372 -366
- package/package.json +2 -2
- package/providers/prepareEthersHinkal.cjs +1 -1
- package/providers/prepareEthersHinkal.d.ts +3 -2
- package/providers/prepareEthersHinkal.mjs +6 -6
- package/providers/prepareWagmiv1Hinkal.cjs +1 -1
- package/providers/prepareWagmiv1Hinkal.d.ts +2 -1
- package/providers/prepareWagmiv1Hinkal.mjs +8 -8
- package/types/ICacheDevice.d.ts +4 -0
- package/types/hinkal.types.d.ts +10 -0
- package/types/hinkalTvl.types.d.ts +4 -0
- package/types/index.d.ts +2 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../../types/hinkal.types.cjs"),h=require("../../types/ethereum-network.types.cjs"),a=require("../../functions/web3/functionCalls/accessTokenCalls.cjs"),A=require("../../functions/web3/events/getShieldedBalance.cjs"),o=require("../crypto-keys/keys.cjs"),y=require("./hinkalActionBeefy.cjs"),C=require("./hinkalActionConvex.cjs"),P=require("./hinkalActionCurve.cjs"),w=require("./hinkalActionPendle.cjs"),d=require("./hinkalDeposit.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../../types/hinkal.types.cjs"),h=require("../../types/ethereum-network.types.cjs"),a=require("../../functions/web3/functionCalls/accessTokenCalls.cjs"),A=require("../../functions/web3/events/getShieldedBalance.cjs"),o=require("../crypto-keys/keys.cjs"),y=require("./hinkalActionBeefy.cjs"),C=require("./hinkalActionConvex.cjs"),P=require("./hinkalActionCurve.cjs"),w=require("./hinkalActionPendle.cjs"),d=require("./hinkalDeposit.cjs"),T=require("./hinkalSwap.cjs"),m=require("./hinkalWithdraw.cjs"),q=require("./resetMerkleTrees.cjs"),l=require("../merkle-tree/MerkleTree.cjs"),u=require("../../crypto/poseidon.cjs");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");const S=require("../../constants/chains.constants.cjs"),g=require("../../error-handling/error-codes.constants.cjs"),f=require("../../API/callMonitor.cjs"),E=require("./hinkalActionLidoEth.cjs");require("../../constants/vite.constants.cjs");require("axios");require("../../constants/coingecko.constants.cjs");const F=require("../../API/getAxelarGasEstimate.cjs"),p=require("../../API/API.cjs");require("ethers");require("../../types/curve.types.cjs");require("../../constants/contracts.constants.cjs");const H=require("../../constants/kyc.constants.cjs");require("../../constants/axelar.constants.cjs");require("../../constants/rewards.constants.cjs");require("../../constants/reorg-depths.constants.cjs");const I=require("../transactions-manager/TransactionsManager.cjs");require("../../functions/utils/external-action.utils.cjs");require("../../types/circom-data.types.cjs");require("../../types/transactions.types.cjs");const M=require("../../functions/utils/reloadPage.cjs"),R=require("./hinkalActionVolatile.cjs"),k=require("./hinkalActionPendleLP.cjs"),L=require("../../API/getConnextReceiveFee.cjs"),W=require("./hinkalActionStake.cjs"),x=require("../MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.cjs"),K=require("./hinkalPrivateWallet.cjs"),N=require("../../functions/utils/cacheFunctions.cjs"),U=require("../../functions/utils/cacheDevice.utils.cjs");class B{providerAdapter;userKeys;signingMessage="Login to Hinkal Protocol";merkleTreeHinkal;merkleTreeAccessToken;nullifiers;encryptedOutputs;commitmentsSnapshotService;nullifierSnapshotService;accessTokenSnapshotService;transactionsManager;utxoUtils;cacheDevice;constructor(e){this.userKeys=new o.UserKeys(void 0),this.merkleTreeHinkal=l.MerkleTree.create(u.poseidonFunction,25n,0n),this.merkleTreeAccessToken=l.MerkleTree.create(u.poseidonFunction,25n,0n),this.nullifiers=new Set,this.encryptedOutputs=[],this.transactionsManager=new I.TransactionsManager,this.utxoUtils=new x.MultiThreadedUtxoUtils,this.cacheDevice=U.createCacheDevice(e?.cacheFilePath)}async initProviderAdapter(e,t){await this.updateProviderAdapter(t),this.providerAdapter?.initConnector(e);const r=await this.connectAndPatchProvider(e);await t.init(r),await this.setListeners()}async initUserKeys(){this.userKeys=new o.UserKeys(await this.getProviderAdapter().signMessage(this.signingMessage))}async initUserKeysWithPassword(e){this.userKeys=new o.UserKeys(e)}async resetMerkle(){this.isSelectedNetworkSupported()&&await q.resetMerkleTrees(this)}getProviderAdapter(){if(!this.providerAdapter)throw new Error("ProviderAdapter is not initialized");return this.providerAdapter}async waitForTransaction(e,t=1){return!!await this.providerAdapter?.waitForTransaction(e,t)}getContractMetadata(e,t){return this.getProviderAdapter().getContractMetadata(e,t)}getContract(e,t=void 0,r){return this.getProviderAdapter().getContract(e,t,r)}async signMessage(e){return await this.getProviderAdapter().signMessage(e)}async signTypedData(e,t,r){return await this.getProviderAdapter().signTypedData(e,t,r)}getContractWithSigner(e,t=""){return this.getProviderAdapter().getContractWithSigner(e,t)}getContractWithFetcher(e,t=""){return this.getProviderAdapter().getContractWithFetcher(e,t)}getContractWithFetcherForEthereum(e,t){return this.getProviderAdapter().getContractWithFetcherForEthereum(e,t)}isSelectedNetworkSupported(){return!!S.networkRegistry[this.getCurrentChainId()]}async switchNetwork(e){try{await this.getProviderAdapter().switchNetwork(e)}catch{throw new Error(g.transactionErrorCodes.FAILED_TO_SWITCH_NETWORKS)}}getCurrentChainId(){const{chainId:e}=this.getProviderAdapter();if(!e)throw new Error("Illegal State: no chainId");return e}getSelectedNetwork(){return this.providerAdapter?.getSelectedNetwork()}isPermitterAvailable(){return this.getProviderAdapter().isPermitterAvailable()}async connectAndPatchProvider(e){return await this.getProviderAdapter().connectAndPatchProvider(e)}async disconnectFromConnector(){await this.getProviderAdapter().disconnectFromConnector()}async updateProviderAdapter(e){try{this.providerAdapter&&this.providerAdapter.release(),this.providerAdapter=e}catch(t){throw console.error(t),Error("updateProviderAdapter failed, please try again.")}}async setListeners(){this.providerAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}})}async onAccountChanged(){await this.getProviderAdapter().onAccountChanged();const e=c.EventType.AccountChanged;typeof document<"u"?document?.dispatchEvent(new Event(e)):process?.emit("message",e,void 0)}async onChainChanged(e){if(e){await this.getProviderAdapter().onChainChanged(e);const t=c.EventType.NetworkChange;typeof document<"u"?document.dispatchEvent(new Event(t)):process?.emit("message",t,void 0)}else await this.disconnectFromConnector(),M.reloadPage()}async monitorConnectedAddress(){f.monitor(await this.getEthereumAddress(),this.getCurrentChainId())}async getBalances(){return A.getShieldedBalance(this)}getSupportedPassportLinks(){return H.supportedPassportLinks}checkAccessToken(){return a.checkHinkalAccessToken(this)}async getAxelarEstimate(e,t,r,n){return F.getAxelarGasEstimate(e,t,r,n,this.userKeys.getAccessKey())}async getConnextReceiveFee(e,t){return L.getConnextReceiveFee(this.getCurrentChainId(),e,t)}async mintHinkalAccessToken(e){return a.mintAccessToken(this,e)}async mintHinkalAccessTokenCrossChain(e,t){return a.mintTokenCrossChain(this,e,t)}async getHinkalTreeRootHash(){return this.getContractWithFetcher(h.ContractType.HinkalContract).getRootHash()}async getAccessTokenTreeRootHash(){return this.getContractWithFetcher(h.ContractType.CrossChainAccessTokenContract).getRootHash()}async resetMerkleTreesIfNecessary(){if(!this.isSelectedNetworkSupported())throw new Error(g.transactionErrorCodes.UNSUPPORTED_NETWORK);const[e,t]=await Promise.all([this.getHinkalTreeRootHash(),this.getAccessTokenTreeRootHash()]);(e.toBigInt()!==this.merkleTreeHinkal.getRootHash()||t.toBigInt()!==this.merkleTreeAccessToken.getRootHash())&&await this.resetMerkle()}async getEventsFromHinkal(){await Promise.all([this.accessTokenSnapshotService?.retrieveEventsFromLatestBlock(),this.commitmentsSnapshotService?.retrieveEventsFromLatestBlock(),this.nullifierSnapshotService?.retrieveEventsFromLatestBlock()])}getEthereumAddress(){return this.getProviderAdapter().getAddress()}async getRandomRelay(){return(await p.API.getIdleRelay(this.getCurrentChainId())).relay}getGasPrice(){if(!this.providerAdapter?.chainId)throw new Error("Illegal State of providerAdapter in Hinkal: no chainId");return this.providerAdapter.getGasPrice()}getAPI(){return p.API}resetCache(){N.resetCache(this)}snapshotsClearInterval(){this.commitmentsSnapshotService?.intervalClear(),this.accessTokenSnapshotService?.intervalClear(),this.nullifierSnapshotService?.intervalClear()}async deposit(e,t){return d.hinkalDeposit(this,e,t)}async depositForOther(e,t,r){return d.hinkalDepositForOther(this,e,t,r)}async withdraw(e,t,r,n,i=!1){return m.hinkalWithdraw(this,e,t,r,n,i)}async swap(e,t,r,n,i=!1,s=!1){return T.hinkalSwap(this,e,t,r,n,i,s)}async actionCurve(e,t,r,n,i,s=!1){return P.hinkalActionCurve(this,e,t,r,n,i,s)}async actionConvex(e,t,r,n,i=!1){return C.hinkalActionConvex(this,e,t,r,n,i)}async actionBeefy(e,t,r,n,i,s,v=!1){return y.hinkalActionBeefy(this,e,t,r,n,i,s,v)}async actionLido(e,t,r,n,i,s=!1){return E.hinkalActionLido(this,e,t,r,n,i,s)}async actionPendle(e,t,r,n,i=!1){return w.hinkalActionPendle(this,e,t,r,n,i)}async actionPendleLP(e,t,r,n,i=!1){return k.hinkalActionPendleLP(this,e,t,r,n,i)}async actionVolatile(e,t,r,n=!1){return R.hinkalActionVolatile(this,e,t,r,n)}async actionStake(e,t,r,n){return W.hinkalActionStake(this,e,t,r,n)}async actionPrivateWallet(e,t,r,n=[],i,s=!1){return K.hinkalPrivateWallet(this,e,t,r,n,i,s)}async getPendleLPClaimableParams(e,t){return k.hinkalGetPendleLPClaimableParams(this,e,t)}}exports.Hinkal=B;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ContractTransaction, ethers } from 'ethers';
|
|
2
2
|
import { AxelarMigrationInfo } from '../../types/axelar.types';
|
|
3
|
-
import { BeefyAction, ConvexAction, CurveAction, LidoAction, LidoVariant, VolatileHelperData } from '../../types/hinkal.types';
|
|
3
|
+
import { BeefyAction, ConvexAction, CurveAction, HinkalConfig, LidoAction, LidoVariant, VolatileHelperData } from '../../types/hinkal.types';
|
|
4
4
|
import { ContractMetadata, ContractType, EthereumNetwork } from '../../types/ethereum-network.types';
|
|
5
5
|
import { EncryptedOutputWithSign } from '../../types/commitments.types';
|
|
6
6
|
import { ExternalActionId } from '../../types/external-action.types';
|
|
7
7
|
import { HinkalStakeMode } from '../../types/hinkal.stake.types';
|
|
8
|
-
import { IMultiThreadedUtxoUtils } from '../../types/IMultiThreadedUtxoUtils';
|
|
8
|
+
import { type IMultiThreadedUtxoUtils } from '../../types/IMultiThreadedUtxoUtils';
|
|
9
9
|
import { PendleLPMetadata, PendleMetadata } from '../../types/pendle.types';
|
|
10
10
|
import { RelayerTransaction } from '../../types/relayer.types';
|
|
11
11
|
import { SignatureData } from '../../types/crypto.types';
|
|
@@ -15,10 +15,11 @@ import { ClientAccessTokenSnapshotService } from '../snapshot/ClientAccessTokenS
|
|
|
15
15
|
import { ClientCommitmentsSnapshotService } from '../snapshot/ClientCommitmentsSnapshotService';
|
|
16
16
|
import { ClientNullifierSnapshotService } from '../snapshot/ClientNullifierSnapshotService';
|
|
17
17
|
import { IProviderAdapter } from '../provider-adapter/IProviderAdapter';
|
|
18
|
-
import { IHinkal } from './IHinkal';
|
|
18
|
+
import { type IHinkal } from './IHinkal';
|
|
19
19
|
import { MerkleTree } from '../merkle-tree';
|
|
20
20
|
import { IAPI } from '../../API';
|
|
21
21
|
import { TransactionsManager } from '../transactions-manager';
|
|
22
|
+
import { type ICacheDevice } from '../../types/ICacheDevice';
|
|
22
23
|
export declare class Hinkal<ConnectorType> implements IHinkal {
|
|
23
24
|
private providerAdapter?;
|
|
24
25
|
userKeys: UserKeys;
|
|
@@ -32,8 +33,8 @@ export declare class Hinkal<ConnectorType> implements IHinkal {
|
|
|
32
33
|
accessTokenSnapshotService?: ClientAccessTokenSnapshotService;
|
|
33
34
|
transactionsManager: TransactionsManager;
|
|
34
35
|
utxoUtils: IMultiThreadedUtxoUtils;
|
|
35
|
-
|
|
36
|
-
constructor();
|
|
36
|
+
cacheDevice: ICacheDevice;
|
|
37
|
+
constructor(hinkalConfig?: HinkalConfig);
|
|
37
38
|
initProviderAdapter(connector: ConnectorType, providerAdapter: IProviderAdapter<ConnectorType>): Promise<void>;
|
|
38
39
|
initUserKeys(): Promise<void>;
|
|
39
40
|
initUserKeysWithPassword(password: string): Promise<void>;
|
|
@@ -74,6 +75,7 @@ export declare class Hinkal<ConnectorType> implements IHinkal {
|
|
|
74
75
|
getRandomRelay(): Promise<string | undefined>;
|
|
75
76
|
getGasPrice(): Promise<bigint>;
|
|
76
77
|
getAPI(): IAPI;
|
|
78
|
+
resetCache(): void;
|
|
77
79
|
snapshotsClearInterval(): void;
|
|
78
80
|
deposit(erc20Addresses: string[], amountChanges: bigint[]): Promise<ethers.ContractTransaction>;
|
|
79
81
|
depositForOther(erc20Addresses: string[], amountChanges: bigint[], recipientInfo: string): Promise<ethers.ContractTransaction>;
|
|
@@ -17,23 +17,23 @@ import "circomlibjs-hinkal-fork";
|
|
|
17
17
|
import "libsodium-wrappers";
|
|
18
18
|
import "process";
|
|
19
19
|
import "buffer";
|
|
20
|
-
import { networkRegistry as
|
|
20
|
+
import { networkRegistry as F } from "../../constants/chains.constants.mjs";
|
|
21
21
|
import { transactionErrorCodes as p } from "../../error-handling/error-codes.constants.mjs";
|
|
22
|
-
import { monitor as
|
|
22
|
+
import { monitor as H } from "../../API/callMonitor.mjs";
|
|
23
23
|
import { hinkalActionLido as I } from "./hinkalActionLidoEth.mjs";
|
|
24
24
|
import "../../constants/vite.constants.mjs";
|
|
25
25
|
import "axios";
|
|
26
26
|
import "../../constants/coingecko.constants.mjs";
|
|
27
|
-
import { getAxelarGasEstimate as
|
|
27
|
+
import { getAxelarGasEstimate as R } from "../../API/getAxelarGasEstimate.mjs";
|
|
28
28
|
import { API as l } from "../../API/API.mjs";
|
|
29
29
|
import "ethers";
|
|
30
30
|
import "../../types/curve.types.mjs";
|
|
31
31
|
import "../../constants/contracts.constants.mjs";
|
|
32
|
-
import { supportedPassportLinks as
|
|
32
|
+
import { supportedPassportLinks as L } from "../../constants/kyc.constants.mjs";
|
|
33
33
|
import "../../constants/axelar.constants.mjs";
|
|
34
34
|
import "../../constants/rewards.constants.mjs";
|
|
35
35
|
import "../../constants/reorg-depths.constants.mjs";
|
|
36
|
-
import { TransactionsManager as
|
|
36
|
+
import { TransactionsManager as M } from "../transactions-manager/TransactionsManager.mjs";
|
|
37
37
|
import "../../functions/utils/external-action.utils.mjs";
|
|
38
38
|
import "../../types/circom-data.types.mjs";
|
|
39
39
|
import "../../types/transactions.types.mjs";
|
|
@@ -42,9 +42,11 @@ import { hinkalActionVolatile as N } from "./hinkalActionVolatile.mjs";
|
|
|
42
42
|
import { hinkalActionPendleLP as K, hinkalGetPendleLPClaimableParams as x } from "./hinkalActionPendleLP.mjs";
|
|
43
43
|
import { getConnextReceiveFee as O } from "../../API/getConnextReceiveFee.mjs";
|
|
44
44
|
import { hinkalActionStake as B } from "./hinkalActionStake.mjs";
|
|
45
|
-
import { MultiThreadedUtxoUtils as
|
|
46
|
-
import { hinkalPrivateWallet as
|
|
47
|
-
|
|
45
|
+
import { MultiThreadedUtxoUtils as D } from "../MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.mjs";
|
|
46
|
+
import { hinkalPrivateWallet as U } from "./hinkalPrivateWallet.mjs";
|
|
47
|
+
import { resetCache as b } from "../../functions/utils/cacheFunctions.mjs";
|
|
48
|
+
import { createCacheDevice as G } from "../../functions/utils/cacheDevice.utils.mjs";
|
|
49
|
+
class Be {
|
|
48
50
|
providerAdapter;
|
|
49
51
|
userKeys;
|
|
50
52
|
signingMessage = "Login to Hinkal Protocol";
|
|
@@ -57,9 +59,9 @@ class Ne {
|
|
|
57
59
|
accessTokenSnapshotService;
|
|
58
60
|
transactionsManager;
|
|
59
61
|
utxoUtils;
|
|
60
|
-
|
|
61
|
-
constructor() {
|
|
62
|
-
this.userKeys = new s(void 0), this.merkleTreeHinkal = h.create(d, 25n, 0n), this.merkleTreeAccessToken = h.create(d, 25n, 0n), this.nullifiers = /* @__PURE__ */ new Set(), this.encryptedOutputs = [], this.transactionsManager = new
|
|
62
|
+
cacheDevice;
|
|
63
|
+
constructor(e) {
|
|
64
|
+
this.userKeys = new s(void 0), this.merkleTreeHinkal = h.create(d, 25n, 0n), this.merkleTreeAccessToken = h.create(d, 25n, 0n), this.nullifiers = /* @__PURE__ */ new Set(), this.encryptedOutputs = [], this.transactionsManager = new M(), this.utxoUtils = new D(), this.cacheDevice = G(e?.cacheFilePath);
|
|
63
65
|
}
|
|
64
66
|
async initProviderAdapter(e, t) {
|
|
65
67
|
await this.updateProviderAdapter(t), this.providerAdapter?.initConnector(e);
|
|
@@ -105,7 +107,7 @@ class Ne {
|
|
|
105
107
|
return this.getProviderAdapter().getContractWithFetcherForEthereum(e, t);
|
|
106
108
|
}
|
|
107
109
|
isSelectedNetworkSupported() {
|
|
108
|
-
return !!
|
|
110
|
+
return !!F[this.getCurrentChainId()];
|
|
109
111
|
}
|
|
110
112
|
async switchNetwork(e) {
|
|
111
113
|
try {
|
|
@@ -163,19 +165,19 @@ class Ne {
|
|
|
163
165
|
await this.disconnectFromConnector(), W();
|
|
164
166
|
}
|
|
165
167
|
async monitorConnectedAddress() {
|
|
166
|
-
|
|
168
|
+
H(await this.getEthereumAddress(), this.getCurrentChainId());
|
|
167
169
|
}
|
|
168
170
|
async getBalances() {
|
|
169
171
|
return k(this);
|
|
170
172
|
}
|
|
171
173
|
getSupportedPassportLinks() {
|
|
172
|
-
return
|
|
174
|
+
return L;
|
|
173
175
|
}
|
|
174
176
|
checkAccessToken() {
|
|
175
177
|
return g(this);
|
|
176
178
|
}
|
|
177
179
|
async getAxelarEstimate(e, t, r, i) {
|
|
178
|
-
return
|
|
180
|
+
return R(
|
|
179
181
|
e,
|
|
180
182
|
t,
|
|
181
183
|
r,
|
|
@@ -228,6 +230,9 @@ class Ne {
|
|
|
228
230
|
getAPI() {
|
|
229
231
|
return l;
|
|
230
232
|
}
|
|
233
|
+
resetCache() {
|
|
234
|
+
b(this);
|
|
235
|
+
}
|
|
231
236
|
snapshotsClearInterval() {
|
|
232
237
|
this.commitmentsSnapshotService?.intervalClear(), this.accessTokenSnapshotService?.intervalClear(), this.nullifierSnapshotService?.intervalClear();
|
|
233
238
|
}
|
|
@@ -295,12 +300,12 @@ class Ne {
|
|
|
295
300
|
return B(this, e, t, r, i);
|
|
296
301
|
}
|
|
297
302
|
async actionPrivateWallet(e, t, r, i = [], n, a = !1) {
|
|
298
|
-
return
|
|
303
|
+
return U(this, e, t, r, i, n, a);
|
|
299
304
|
}
|
|
300
305
|
async getPendleLPClaimableParams(e, t) {
|
|
301
306
|
return x(this, e, t);
|
|
302
307
|
}
|
|
303
308
|
}
|
|
304
309
|
export {
|
|
305
|
-
|
|
310
|
+
Be as Hinkal
|
|
306
311
|
};
|
|
@@ -4,7 +4,7 @@ import { ContractMetadata, ContractType, EthereumNetwork } from '../../types/eth
|
|
|
4
4
|
import { EncryptedOutputWithSign } from '../../types/commitments.types';
|
|
5
5
|
import { ExternalActionId } from '../../types/external-action.types';
|
|
6
6
|
import { HinkalStakeMode } from '../../types/hinkal.stake.types';
|
|
7
|
-
import { IMultiThreadedUtxoUtils } from '../../types/IMultiThreadedUtxoUtils';
|
|
7
|
+
import { type IMultiThreadedUtxoUtils } from '../../types/IMultiThreadedUtxoUtils';
|
|
8
8
|
import { PendleLPMetadata, PendleMetadata } from '../../types/pendle.types';
|
|
9
9
|
import { RelayerTransaction } from '../../types/relayer.types';
|
|
10
10
|
import { SignatureData } from '../../types/crypto.types';
|
|
@@ -19,8 +19,8 @@ import { MerkleTree } from '../merkle-tree';
|
|
|
19
19
|
import { TransactionsManager } from '../transactions-manager/TransactionsManager';
|
|
20
20
|
import { IAPI } from '../../API/API';
|
|
21
21
|
import { AxelarGasResponse } from '../../API/getAxelarGasEstimate';
|
|
22
|
+
import { type ICacheDevice } from '../../types/ICacheDevice';
|
|
22
23
|
export interface IHinkal<ConnectorType = unknown> {
|
|
23
|
-
utxoUtils: IMultiThreadedUtxoUtils;
|
|
24
24
|
userKeys: UserKeys;
|
|
25
25
|
readonly signingMessage: string;
|
|
26
26
|
merkleTreeHinkal: MerkleTree<bigint>;
|
|
@@ -31,7 +31,8 @@ export interface IHinkal<ConnectorType = unknown> {
|
|
|
31
31
|
nullifierSnapshotService?: ClientNullifierSnapshotService;
|
|
32
32
|
accessTokenSnapshotService?: ClientAccessTokenSnapshotService;
|
|
33
33
|
transactionsManager: TransactionsManager;
|
|
34
|
-
|
|
34
|
+
utxoUtils: IMultiThreadedUtxoUtils;
|
|
35
|
+
cacheDevice: ICacheDevice;
|
|
35
36
|
getBalances(): Promise<TokenBalance[]>;
|
|
36
37
|
getSupportedPassportLinks(): string[];
|
|
37
38
|
checkAccessToken(): Promise<boolean>;
|
|
@@ -45,6 +46,7 @@ export interface IHinkal<ConnectorType = unknown> {
|
|
|
45
46
|
getRandomRelay(): Promise<string | undefined>;
|
|
46
47
|
getGasPrice(): Promise<bigint>;
|
|
47
48
|
getAPI(): IAPI;
|
|
49
|
+
resetCache(): void;
|
|
48
50
|
snapshotsClearInterval(): void;
|
|
49
51
|
deposit(erc20Addresses: string[], amountChanges: bigint[]): Promise<ethers.ContractTransaction>;
|
|
50
52
|
depositForOther(erc20Addresses: string[], amountChanges: bigint[], recepinetInfo: string): Promise<ethers.ContractTransaction>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class a{inMemoryCache=new Map;getInMemory(e){return this.inMemoryCache.get(e)??void 0}setInMemory(e,t){this.inMemoryCache.set(e,t)}}exports.BaseCacheDevice=a;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ICacheDevice } from '../../types/ICacheDevice';
|
|
2
|
+
export declare abstract class BaseCacheDevice implements ICacheDevice {
|
|
3
|
+
protected inMemoryCache: Map<string, string>;
|
|
4
|
+
protected getInMemory(key: string): string | undefined;
|
|
5
|
+
protected setInMemory(key: string, value: string): void;
|
|
6
|
+
abstract get(key: string): string | undefined;
|
|
7
|
+
abstract set(key: string, value: string): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./BaseCacheDevice.cjs");class o extends c.BaseCacheDevice{filePath;constructor(e){super(),this.filePath=e,this.readFileFromDevice()}readFileFromDevice(){if(this.filePath)try{const e=require("fs");if(e.existsSync(this.filePath)){const t=JSON.parse(e.readFileSync(this.filePath).toString());Object.entries(t).forEach(([r,s])=>{this.setInMemory(r,s)})}}catch(e){console.log("FileCacheDevice Constructor Error",{err:e})}}get(e){return this.getInMemory(e)}set(e,t){if(this.setInMemory(e,t),this.filePath)try{require("fs").writeFileSync(this.filePath,JSON.stringify(Object.fromEntries(this.inMemoryCache)))}catch(i){console.log("FileCacheDevice set function",{err:i})}}}exports.FileCacheDevice=o;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseCacheDevice } from './BaseCacheDevice';
|
|
2
|
+
export declare class FileCacheDevice extends BaseCacheDevice {
|
|
3
|
+
private filePath;
|
|
4
|
+
constructor(filePath: string);
|
|
5
|
+
private readFileFromDevice;
|
|
6
|
+
get(key: string): string | undefined;
|
|
7
|
+
set(key: string, value: string): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { BaseCacheDevice as c } from "./BaseCacheDevice.mjs";
|
|
2
|
+
class h extends c {
|
|
3
|
+
filePath;
|
|
4
|
+
constructor(e) {
|
|
5
|
+
super(), this.filePath = e, this.readFileFromDevice();
|
|
6
|
+
}
|
|
7
|
+
readFileFromDevice() {
|
|
8
|
+
if (this.filePath)
|
|
9
|
+
try {
|
|
10
|
+
const e = require("fs");
|
|
11
|
+
if (e.existsSync(this.filePath)) {
|
|
12
|
+
const t = JSON.parse(e.readFileSync(this.filePath).toString());
|
|
13
|
+
Object.entries(t).forEach(([r, s]) => {
|
|
14
|
+
this.setInMemory(r, s);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
} catch (e) {
|
|
18
|
+
console.log("FileCacheDevice Constructor Error", { err: e });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
get(e) {
|
|
22
|
+
return this.getInMemory(e);
|
|
23
|
+
}
|
|
24
|
+
set(e, t) {
|
|
25
|
+
if (this.setInMemory(e, t), this.filePath)
|
|
26
|
+
try {
|
|
27
|
+
require("fs").writeFileSync(this.filePath, JSON.stringify(Object.fromEntries(this.inMemoryCache)));
|
|
28
|
+
} catch (i) {
|
|
29
|
+
console.log("FileCacheDevice set function", { err: i });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
h as FileCacheDevice
|
|
35
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./BaseCacheDevice.cjs");class o extends a.BaseCacheDevice{localDataStorage;constructor(){super(),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;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseCacheDevice as a } from "./BaseCacheDevice.mjs";
|
|
2
|
+
class l extends a {
|
|
3
|
+
localDataStorage;
|
|
4
|
+
constructor() {
|
|
5
|
+
super(), typeof localStorage < "u" && (this.localDataStorage = localStorage);
|
|
6
|
+
}
|
|
7
|
+
get(t) {
|
|
8
|
+
return this.localDataStorage ? this.localDataStorage.getItem(t) ?? void 0 : this.getInMemory(t);
|
|
9
|
+
}
|
|
10
|
+
set(t, e) {
|
|
11
|
+
this.localDataStorage ? this.localDataStorage.setItem(t, e) : this.setInMemory(t, e);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
l as LocalStorageCacheDevice
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../../constants/chains.constants.cjs");const c=require("../../constants/vite.constants.cjs");require("../../constants/contracts.constants.cjs");require("../../constants/kyc.constants.cjs");require("../../constants/coingecko.constants.cjs");require("../../constants/axelar.constants.cjs");require("../../constants/rewards.constants.cjs");require("../../constants/reorg-depths.constants.cjs");const i=require("../../data-structures/cacheDevices/FileCacheDevice.cjs"),t=require("../../data-structures/cacheDevices/LocalStorageCacheDevice.cjs"),a=e=>{if(c.isNode){const r=require("path").resolve(process.cwd(),"hinkalCache.json");return new i.FileCacheDevice(e??r)}else return new t.LocalStorageCacheDevice};exports.createCacheDevice=a;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import "../../constants/chains.constants.mjs";
|
|
2
|
+
import { isNode as o } from "../../constants/vite.constants.mjs";
|
|
3
|
+
import "../../constants/contracts.constants.mjs";
|
|
4
|
+
import "../../constants/kyc.constants.mjs";
|
|
5
|
+
import "../../constants/coingecko.constants.mjs";
|
|
6
|
+
import "../../constants/axelar.constants.mjs";
|
|
7
|
+
import "../../constants/rewards.constants.mjs";
|
|
8
|
+
import "../../constants/reorg-depths.constants.mjs";
|
|
9
|
+
import { FileCacheDevice as t } from "../../data-structures/cacheDevices/FileCacheDevice.mjs";
|
|
10
|
+
import { LocalStorageCacheDevice as i } from "../../data-structures/cacheDevices/LocalStorageCacheDevice.mjs";
|
|
11
|
+
const u = (e) => {
|
|
12
|
+
if (o) {
|
|
13
|
+
const r = require("path").resolve(process.cwd(), "hinkalCache.json");
|
|
14
|
+
return new t(e ?? r);
|
|
15
|
+
} else
|
|
16
|
+
return new i();
|
|
17
|
+
};
|
|
18
|
+
export {
|
|
19
|
+
u as createCacheDevice
|
|
20
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../../types/ethereum-network.types.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../../types/ethereum-network.types.cjs"),g=require("./getDataFromTransaction.cjs"),y=require("idb-keyval"),C={encryptedOutputs:[],lastOutput:""},d=(e,t)=>{const s=e.substring(0,25),r=t.substring(0,25);return{shortPublicKey:s,shortHinkalAddress:r}},x=e=>{const t=e.getCurrentChainId(),s=e.getContract(u.ContractType.HinkalContract).address,r=e.userKeys.getShieldedPublicKey();if(!t||!r||!s)throw Error("GetHinkalCache: incorrect arguments");const{shortPublicKey:c,shortHinkalAddress:a}=d(r,s);return JSON.parse(e.cacheDevice.get(`hinkalCache-${t}-${c}-${a}`)??JSON.stringify(C))},H=(e,t)=>{const s=t.getCurrentChainId(),r=t.getContract(u.ContractType.HinkalContract).address,c=t.userKeys.getShieldedPublicKey();if(!s||!c||!r)throw Error("SetHinkalCache: incorrect arguments");const{shortPublicKey:a,shortHinkalAddress:n}=d(c,r);t.cacheDevice.set(`hinkalCache-${s}-${a}-${n}`,JSON.stringify(e))},S=e=>{H(C,e)},T=(e,t,s)=>`txsCache-${e}-${t}-${s}`,k=async(e,t,s,r,c)=>{if(!t||!s||!r)throw Error("saveTxsCache: incorrect arguments");const{shortPublicKey:a,shortHinkalAddress:n}=d(s,r),h=g.serializeDecodedTxs(e),o=T(t,a,n),l=JSON.stringify({serializedTxs:h,lastHash:c});try{await y.set(o,l)}catch{localStorage.setItem(o,l)}},b={serializedTxs:[],lastHash:""},m=async(e,t,s)=>{if(!e||!t||!s)throw Error("loadTxsCache: incorrect arguments");const{shortPublicKey:r,shortHinkalAddress:c}=d(t,s),a=T(e,r,c);let n;try{const i=await y.get(a);if(!i)throw new Error("Empty indexedDB cache");n=i}catch{n=localStorage.getItem(a)}const{serializedTxs:h,lastHash:o}=JSON.parse(n??JSON.stringify(b));return{decodedTxs:h.map(i=>g.deserializeDecodedTxs(i)),lastHash:o===""?void 0:o}};exports.getHinkalCache=x;exports.loadTxsCache=m;exports.resetCache=S;exports.saveTxsCache=k;exports.setHinkalCache=H;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IHinkal } from '../../data-structures';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { type IHinkal } from '../../data-structures/Hinkal/IHinkal';
|
|
2
|
+
import { type DecodedTx } from '../../types/transactions.types';
|
|
3
|
+
import { type EncryptedOutputWithSign } from '../../types/commitments.types';
|
|
4
4
|
interface HinkalCacheInterface {
|
|
5
5
|
encryptedOutputs: EncryptedOutputWithSign[];
|
|
6
6
|
lastOutput: string;
|
|
@@ -1,60 +1,57 @@
|
|
|
1
|
-
import { ContractType as
|
|
2
|
-
import { serializeDecodedTxs as C, deserializeDecodedTxs as
|
|
3
|
-
import { set as
|
|
4
|
-
const
|
|
1
|
+
import { ContractType as g } from "../../types/ethereum-network.types.mjs";
|
|
2
|
+
import { serializeDecodedTxs as C, deserializeDecodedTxs as m } from "./getDataFromTransaction.mjs";
|
|
3
|
+
import { set as x, get as H } from "idb-keyval";
|
|
4
|
+
const u = {
|
|
5
5
|
encryptedOutputs: [],
|
|
6
6
|
lastOutput: ""
|
|
7
7
|
}, d = (t, e) => {
|
|
8
8
|
const s = t.substring(0, 25), r = e.substring(0, 25);
|
|
9
9
|
return { shortPublicKey: s, shortHinkalAddress: r };
|
|
10
|
-
},
|
|
11
|
-
const e = t.getCurrentChainId(), s = t.getContract(
|
|
10
|
+
}, K = (t) => {
|
|
11
|
+
const e = t.getCurrentChainId(), s = t.getContract(g.HinkalContract).address, r = t.userKeys.getShieldedPublicKey();
|
|
12
12
|
if (!e || !r || !s)
|
|
13
13
|
throw Error("GetHinkalCache: incorrect arguments");
|
|
14
|
-
const { shortPublicKey: c, shortHinkalAddress:
|
|
14
|
+
const { shortPublicKey: c, shortHinkalAddress: n } = d(r, s);
|
|
15
15
|
return JSON.parse(
|
|
16
|
-
|
|
16
|
+
t.cacheDevice.get(`hinkalCache-${e}-${c}-${n}`) ?? JSON.stringify(u)
|
|
17
17
|
);
|
|
18
18
|
}, p = (t, e) => {
|
|
19
|
-
const s = e.getCurrentChainId(), r = e.getContract(
|
|
19
|
+
const s = e.getCurrentChainId(), r = e.getContract(g.HinkalContract).address, c = e.userKeys.getShieldedPublicKey();
|
|
20
20
|
if (!s || !c || !r)
|
|
21
21
|
throw Error("SetHinkalCache: incorrect arguments");
|
|
22
|
-
const { shortPublicKey:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}, K = (t) => {
|
|
28
|
-
p(g, t);
|
|
29
|
-
}, u = (t, e, s) => `txsCache-${t}-${e}-${s}`, O = async (t, e, s, r, c) => {
|
|
22
|
+
const { shortPublicKey: n, shortHinkalAddress: o } = d(c, r);
|
|
23
|
+
e.cacheDevice.set(`hinkalCache-${s}-${n}-${o}`, JSON.stringify(t));
|
|
24
|
+
}, b = (t) => {
|
|
25
|
+
p(u, t);
|
|
26
|
+
}, y = (t, e, s) => `txsCache-${t}-${e}-${s}`, $ = async (t, e, s, r, c) => {
|
|
30
27
|
if (!e || !s || !r)
|
|
31
28
|
throw Error("saveTxsCache: incorrect arguments");
|
|
32
|
-
const { shortPublicKey:
|
|
29
|
+
const { shortPublicKey: n, shortHinkalAddress: o } = d(s, r), h = C(t), a = y(e, n, o), l = JSON.stringify({ serializedTxs: h, lastHash: c });
|
|
33
30
|
try {
|
|
34
|
-
await
|
|
31
|
+
await x(a, l);
|
|
35
32
|
} catch {
|
|
36
|
-
localStorage.setItem(a,
|
|
33
|
+
localStorage.setItem(a, l);
|
|
37
34
|
}
|
|
38
|
-
},
|
|
35
|
+
}, S = { serializedTxs: [], lastHash: "" }, w = async (t, e, s) => {
|
|
39
36
|
if (!t || !e || !s)
|
|
40
37
|
throw Error("loadTxsCache: incorrect arguments");
|
|
41
|
-
const { shortPublicKey: r, shortHinkalAddress: c } = d(e, s),
|
|
42
|
-
let
|
|
38
|
+
const { shortPublicKey: r, shortHinkalAddress: c } = d(e, s), n = y(t, r, c);
|
|
39
|
+
let o;
|
|
43
40
|
try {
|
|
44
|
-
const i = await
|
|
41
|
+
const i = await H(n);
|
|
45
42
|
if (!i)
|
|
46
43
|
throw new Error("Empty indexedDB cache");
|
|
47
|
-
|
|
44
|
+
o = i;
|
|
48
45
|
} catch {
|
|
49
|
-
|
|
46
|
+
o = localStorage.getItem(n);
|
|
50
47
|
}
|
|
51
|
-
const { serializedTxs:
|
|
52
|
-
return { decodedTxs:
|
|
48
|
+
const { serializedTxs: h, lastHash: a } = JSON.parse(o ?? JSON.stringify(S));
|
|
49
|
+
return { decodedTxs: h.map((i) => m(i)), lastHash: a === "" ? void 0 : a };
|
|
53
50
|
};
|
|
54
51
|
export {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
K as getHinkalCache,
|
|
53
|
+
w as loadTxsCache,
|
|
54
|
+
b as resetCache,
|
|
55
|
+
$ as saveTxsCache,
|
|
59
56
|
p as setHinkalCache
|
|
60
57
|
};
|