@hinkal/common 0.1.67 → 0.2.1

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 CHANGED
@@ -18,64 +18,6 @@ Or, yarn:
18
18
  yarn add @hinkal/common
19
19
  ```
20
20
 
21
- If you want to use `wagmi` version 2+ you should instal it using npm alias `wagmi2`1
22
-
23
-
24
- ## Vite-based React App
25
- #### Step 1: Create a Vite App
26
- If you don't have a Vite app set up, create one using the following command:
27
-
28
- ```bash
29
- npm create vite@latest my-vite-app --template react
30
- cd my-vite-app
31
- ```
32
-
33
- ## Next.js-based App
34
- #### Step 1: Create a Next.js App
35
- If you don't have a Next.js app set up, create one using the following command:
36
-
37
- ```bash
38
- npx create-next-app@latest my-next-app
39
- cd my-next-app
40
- ```
41
-
42
- #### Step 2: Install Required Packages
43
- For correct operation in Next.js, you should install copy-webpack-plugin:
44
-
45
- ```bash
46
- npm install copy-webpack-plugin node-polyfill-webpack-plugin
47
- ```
48
-
49
- #### Step 3: Configure Next.js
50
- Create or update the next.config.js file in the root of your Next.js project and add the following configuration:
51
-
52
- ```javascript
53
- // next.config.js
54
- const CopyPlugin = require("copy-webpack-plugin");
55
-
56
- module.exports = {
57
- webpack: (config) => {
58
- config.plugins.push(
59
- new NodePolyfillPlugin({
60
- additionalAliases: ['fs'],
61
- excludeAliases: ['constants']
62
- }),
63
- // TODO: research better solution
64
- new ReplaceInFileWebpackPlugin([{
65
- dir: 'node_modules/fastfile/src',
66
- files: ['fastfile.js'],
67
- rules: [{
68
- search: 'import { O_TRUNC, O_CREAT, O_RDWR, O_EXCL, O_RDONLY } from "constants";',
69
- replace: 'import t from "constants"; const { O_TRUNC, O_CREAT, O_RDWR, O_EXCL, O_RDONLY } = t;'
70
- }],
71
- }]),
72
- );
73
- return config;
74
- },
75
- };
76
- ```
77
- The CopyPlugin in the Next.js configuration is required to ensure that the necessary worker scripts are correctly loaded into your application. By copying the worker-related assets to the appropriate directory, you enable seamless access to these resources. This setup is crucial for the proper functioning of your library, which relies on Web Workers.
78
-
79
21
  ### Usage
80
22
 
81
23
  1. Import hinkal from @hinkal/common package and initiate a Hinkal instance:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hinkal/common",
3
- "version": "0.1.67",
3
+ "version": "0.2.1",
4
4
  "homepage": "hinkal.pro",
5
5
  "author": {
6
6
  "name": "Hinkal Protocol"
@@ -20,25 +20,17 @@
20
20
  "import": "./providers/EthersProviderAdapter.mjs",
21
21
  "require": "./providers/EthersProviderAdapter.cjs"
22
22
  },
23
- "./providers/Wagmiv1ProviderAdapter": {
24
- "import": "./providers/Wagmiv1ProviderAdapter.mjs",
25
- "require": "./providers/Wagmiv1ProviderAdapter.cjs"
26
- },
27
- "./providers/Wagmiv2ProviderAdapter": {
28
- "import": "./providers/Wagmiv2ProviderAdapter.mjs",
29
- "require": "./providers/Wagmiv2ProviderAdapter.cjs"
23
+ "./providers/WagmiProviderAdapter": {
24
+ "import": "./providers/WagmiProviderAdapter.mjs",
25
+ "require": "./providers/WagmiProviderAdapter.cjs"
30
26
  },
31
27
  "./providers/prepareEthersHinkal": {
32
28
  "import": "./providers/prepareEthersHinkal.mjs",
33
29
  "require": "./providers/prepareEthersHinkal.cjs"
34
30
  },
35
- "./providers/prepareWagmiv2Hinkal": {
36
- "import": "./providers/prepareWagmiv2Hinkal.mjs",
37
- "require": "./providers/prepareWagmiv2Hinkal.cjs"
38
- },
39
- "./providers/prepareWagmiv1Hinkal": {
40
- "import": "./providers/prepareWagmiv1Hinkal.mjs",
41
- "require": "./providers/prepareWagmiv1Hinkal.cjs"
31
+ "./providers/prepareWagmiHinkal": {
32
+ "import": "./providers/prepareWagmiHinkal.mjs",
33
+ "require": "./providers/prepareWagmiHinkal.cjs"
42
34
  }
43
35
  },
44
36
  "scripts": {
@@ -68,16 +60,12 @@
68
60
  "uuid": "^9.0.1"
69
61
  },
70
62
  "peerDependencies": {
71
- "wagmi": "^1.4.8",
72
- "wagmi2": "npm:wagmi@^2.12.24",
63
+ "wagmi": "2.12.24",
73
64
  "ethers": "5.x"
74
65
  },
75
66
  "peerDependenciesMeta": {
76
67
  "wagmi": {
77
68
  "optional": true
78
- },
79
- "wagmi2": {
80
- "optional": true
81
69
  }
82
70
  }
83
71
  }
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("../constants/chains.constants.cjs"),h=require("../constants/contracts.constants.cjs"),c=require("../error-handling/error-codes.constants.cjs"),s=require("ethers"),d=require("wagmi"),g=require("../node_modules/@wagmi/core/dist/esm/actions/disconnect.cjs"),w=require("../node_modules/@wagmi/core/dist/esm/actions/connect.cjs"),u=require("../node_modules/@wagmi/core/dist/esm/actions/signMessage.cjs"),f=require("../node_modules/@wagmi/core/dist/esm/actions/switchChain.cjs"),l=require("../node_modules/@wagmi/core/dist/esm/actions/getAccount.cjs"),v=require("../node_modules/@wagmi/core/dist/esm/actions/watchAccount.cjs"),C=require("../node_modules/@wagmi/core/dist/esm/actions/watchChainId.cjs");class a{connector;chainId;originalProvider;fetchProvider;signer;chainEventListener;config;unsubscribeFns=[];initConnector(r){this.connector=r}requireConnector(){if(!this.connector)throw Error("No Connector In Provider Adapter")}initConfig(r){this.config=r}async init(r){this.requireConnector(),r&&(this.chainId=r),this.originalProvider=await this.connector.getProvider(),this.fetchProvider=this.createFetchProvider()??this.originalProvider,this.fetchProvider===this.originalProvider&&console.warn("fetchProvider not available");const t=await this.connector.getProvider(),e=await this.connector.getAccounts();this.signer=await this.walletClientToSigner({transport:t,account:e[0]},this.chainId)}async disconnectFromConnector(){if(!this.config)throw new Error("No Config In Provider Adapter");this.release(),await g.disconnect(this.config)}async connectToConnector(r){if(!this.config)throw new Error("No Config In Provider Adapter");try{return(await w.connect(this.config,{connector:r})).chainId}catch(t){if(t instanceof d.ConnectorAlreadyConnectedError)return r.getChainId();throw console.log(t),new Error(c.transactionErrorCodes.CONNECTION_FAILED)}}async waitForTransaction(r,t){if((await this.fetchProvider?.waitForTransaction(r,t))?.status)return!0;throw Error(c.transactionErrorCodes.TRANSACTION_NOT_CONFIRMED)}async signMessage(r){if(!this.config)throw new Error("No Config In Provider Adapter");const t=await u.signMessage(this.config,{message:r});if(!t)throw new Error(c.transactionErrorCodes.SIGNING_FAILED);if(t.includes("error"))throw new Error(c.transactionErrorCodes.SIGNATURE_UNSUPPORTED_PERSONAL_SIGN);return t}async signTypedData(r,t,e){return this.signer._signTypedData(r,t,e)}getSelectedNetwork=()=>{if(!this.chainId)throw new Error("Illegal state: no chaindId");return i.networkRegistry[this.chainId]};async switchNetwork(r){if(!this.config)throw new Error("No Config In Provider Adapter");return f.switchChain(this.config,{chainId:r.chainId})}createFetchProvider(){try{const t=i.networkRegistry[this.chainId]?.fetchRpcUrl;return t?t.includes("wss")?new s.providers.WebSocketProvider(t):new s.providers.StaticJsonRpcProvider(t):void 0}catch(r){console.log("create Fetch Provider error",r);return}}async getAddress(){if(!this.config)throw new Error("No Config In Provider Adapter");const{address:r}=l.getAccount(this.config);if(!r)throw new Error("IllegalState");return s.utils.getAddress(r)}setChainEventListener(r){if(!this.config)throw new Error("No Config In Provider Adapter");this.chainEventListener=r,this.chainEventListener&&(this.unsubscribeFns.push(v.watchAccount(this.config,{onChange:({address:t},{address:e})=>{if(!this.chainEventListener){console.warn("chainEventListener is not set");return}console.log("Account changed"),t!==e&&(console.log("Account changed"),this.chainEventListener.onAccountChanged())}})),this.unsubscribeFns.push(C.watchChainId(this.config,{onChange:t=>{if(!this.chainEventListener){console.warn("chainEventListener is not set");return}console.log("Chain ID changed!",t),this.chainEventListener.onChainChanged(t)}})))}onAccountChanged(){return this.init()}onChainChanged(r){return this.init(r)}release(){this.removeListeners()}removeListeners(){this.unsubscribeFns.forEach(r=>r()),this.unsubscribeFns=[]}getContractMetadata(r,t){const e=t??this.chainId;if(!e)throw new Error("No chainId provided in context");const n=i.networkRegistry[e];if(!n)throw new Error(c.transactionErrorCodes.UNSUPPORTED_NETWORK);const o=h.contractMetadataMapping[r];if(!o)throw new Error(`Unsupported contractType: ${r}`);return o(n.contractData)}getContract(r,t=void 0,e){const n=this.getContractMetadata(r,e);if(!n.abi)throw new Error(`No ABI configured for contractType: ${r}`);if(n.address&&t)throw new Error(`Overriding address is not supported for contractType: ${r}`);const o=n.address??t;if(!o)throw new Error(`No contractAddress configured for contractType: ${r}`);return new s.ethers.Contract(o,n.abi)}getContractWithSigner(r,t=void 0){if(!this.signer)throw new Error("IllegalState: no signer");return this.getContract(r,t).connect(this.signer)}getContractWithFetcher(r,t=void 0){if(!this.fetchProvider)throw new Error("fetchProvider not initialized");return this.getContract(r,t).connect(this.fetchProvider)}getContractWithFetcherForEthereum(r,t=void 0){const e=this.chainId===i.chainIds.localhost&&i.localhostNetwork===i.chainIds.ethMainnet?i.chainIds.localhost:i.chainIds.ethMainnet;return this.getContract(r,t).connect(new s.ethers.providers.StaticJsonRpcProvider(i.networkRegistry[e].fetchRpcUrl))}async sendTransaction(r){if(!this.signer)throw new Error("IllegalState: no signer");return await this.signer.sendTransaction(r)}async patchExternalProvider(r){const t=await r.getProvider();let e;if(t instanceof s.ethers.providers.Web3Provider?e=t.provider:e=t,"isWalletConnect"in e){const n=await r.getChainId();e.http=e.setHttpProvider?.(n)}}async connectAndPatchProvider(r){const t=await this.connectToConnector(r);return await this.patchExternalProvider(r),t}isPermitterAvailable(){return!!this.getSelectedNetwork()?.contractData?.permitterAddress}async getGasPrice(){const r=await this.fetchProvider?.getGasPrice();if(!r)throw Error("Could not fetch gas price in getGasPrice");return r.toBigInt()}async walletClientToSigner(r,t){const{account:e,transport:n}=r,o={chainId:t,name:""};return new s.providers.Web3Provider(n,o).getSigner(e)}}const p=new a,E=()=>new a;exports.WagmiProviderAdapter=a;exports.default=E;exports.wagmiProviderAdapter=p;
@@ -1,8 +1,8 @@
1
1
  import { ChainEventListener, IProviderAdapter } from '../data-structures/provider-adapter/IProviderAdapter';
2
2
  import { ContractMetadata, ContractType, EthereumNetwork } from '../types/ethereum-network.types';
3
3
  import { ethers } from 'ethers';
4
- import { type Connector } from 'wagmi2';
5
- export declare class Wagmiv2ProviderAdapter implements IProviderAdapter<Connector> {
4
+ import { type Connector } from 'wagmi';
5
+ export declare class WagmiProviderAdapter implements IProviderAdapter<Connector> {
6
6
  private connector;
7
7
  chainId: number | undefined;
8
8
  private originalProvider;
@@ -21,7 +21,7 @@ export declare class Wagmiv2ProviderAdapter implements IProviderAdapter<Connecto
21
21
  signMessage(message: string): Promise<string>;
22
22
  signTypedData(domain: ethers.TypedDataDomain, types: Record<string, ethers.TypedDataField[]>, value: Record<string, unknown>): Promise<string>;
23
23
  getSelectedNetwork: () => EthereumNetwork | undefined;
24
- switchNetwork(network: EthereumNetwork): Promise<any>;
24
+ switchNetwork(network: EthereumNetwork): Promise<import("viem").Chain>;
25
25
  private createFetchProvider;
26
26
  getAddress(): Promise<string>;
27
27
  setChainEventListener(chainEventListener: ChainEventListener): void;
@@ -41,6 +41,6 @@ export declare class Wagmiv2ProviderAdapter implements IProviderAdapter<Connecto
41
41
  getGasPrice(): Promise<bigint>;
42
42
  walletClientToSigner(walletClient: any, chainId: number): Promise<ethers.providers.JsonRpcSigner>;
43
43
  }
44
- export declare const wagmiv2ProviderAdapter: Wagmiv2ProviderAdapter;
44
+ export declare const wagmiProviderAdapter: WagmiProviderAdapter;
45
45
  declare const _default: <T = unknown>() => IProviderAdapter<T>;
46
46
  export default _default;
@@ -1,9 +1,15 @@
1
1
  import { networkRegistry as s, chainIds as c, localhostNetwork as g } from "../constants/chains.constants.mjs";
2
- import { contractMetadataMapping as w } from "../constants/contracts.constants.mjs";
2
+ import { contractMetadataMapping as f } from "../constants/contracts.constants.mjs";
3
3
  import { transactionErrorCodes as o } from "../error-handling/error-codes.constants.mjs";
4
- import { providers as a, utils as f, ethers as h } from "ethers";
5
- import { ConnectorAlreadyConnectedError as l } from "wagmi2";
6
- import { disconnect as v, connect as u, signMessage as p, switchChain as C, getAccount as P, watchAccount as E, watchChainId as I } from "wagmi2/actions";
4
+ import { providers as a, utils as w, ethers as h } from "ethers";
5
+ import { ConnectorAlreadyConnectedError as l } from "wagmi";
6
+ import { disconnect as v } from "../node_modules/@wagmi/core/dist/esm/actions/disconnect.mjs";
7
+ import { connect as u } from "../node_modules/@wagmi/core/dist/esm/actions/connect.mjs";
8
+ import { signMessage as p } from "../node_modules/@wagmi/core/dist/esm/actions/signMessage.mjs";
9
+ import { switchChain as C } from "../node_modules/@wagmi/core/dist/esm/actions/switchChain.mjs";
10
+ import { getAccount as P } from "../node_modules/@wagmi/core/dist/esm/actions/getAccount.mjs";
11
+ import { watchAccount as E } from "../node_modules/@wagmi/core/dist/esm/actions/watchAccount.mjs";
12
+ import { watchChainId as I } from "../node_modules/@wagmi/core/dist/esm/actions/watchChainId.mjs";
7
13
  class d {
8
14
  connector;
9
15
  chainId;
@@ -87,7 +93,7 @@ class d {
87
93
  const { address: t } = P(this.config);
88
94
  if (!t)
89
95
  throw new Error("IllegalState");
90
- return f.getAddress(t);
96
+ return w.getAddress(t);
91
97
  }
92
98
  setChainEventListener(t) {
93
99
  if (!this.config)
@@ -133,7 +139,7 @@ class d {
133
139
  const n = s[e];
134
140
  if (!n)
135
141
  throw new Error(o.UNSUPPORTED_NETWORK);
136
- const i = w[t];
142
+ const i = f[t];
137
143
  if (!i)
138
144
  throw new Error(`Unsupported contractType: ${t}`);
139
145
  return i(n.contractData);
@@ -199,9 +205,9 @@ class d {
199
205
  return new a.Web3Provider(n, i).getSigner(e);
200
206
  }
201
207
  }
202
- const L = new d(), k = () => new d();
208
+ const W = new d(), _ = () => new d();
203
209
  export {
204
- d as Wagmiv2ProviderAdapter,
205
- k as default,
206
- L as wagmiv2ProviderAdapter
210
+ d as WagmiProviderAdapter,
211
+ _ as default,
212
+ W as wagmiProviderAdapter
207
213
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("ethers");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");const u=require("../data-structures/Hinkal/Hinkal.cjs");require("../constants/chains.constants.cjs");require("../types/circom-data.types.cjs");require("../types/transactions.types.cjs");require("../types/curve.types.cjs");require("../data-structures/custom-token-registry/CustomTokenRegistry.cjs");require("../constants/vite.constants.cjs");require("axios");require("../constants/coingecko.constants.cjs");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 t=require("../crypto/preProcessing.cjs");require("../functions/utils/external-action.utils.cjs");require("../functions/web3/events/getShieldedBalance.cjs");require("../data-structures/volatile-helper/VolatileHelper.cjs");require("idb-keyval");const r=require("./Wagmiv2ProviderAdapter.cjs"),q=async(i,a)=>{await t.preProcessing();const e=new u.Hinkal;return r.wagmiv2ProviderAdapter.initConfig(a),await e.initProviderAdapter(i,r.wagmiv2ProviderAdapter),await e.initUserKeys(),await e.resetMerkle(),e};exports.prepareWagmiv2EthersHinkal=q;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("ethers");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");const u=require("../data-structures/Hinkal/Hinkal.cjs");require("../constants/chains.constants.cjs");require("../types/circom-data.types.cjs");require("../types/transactions.types.cjs");require("../types/curve.types.cjs");require("../data-structures/custom-token-registry/CustomTokenRegistry.cjs");require("../constants/vite.constants.cjs");require("axios");require("../constants/coingecko.constants.cjs");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 t=require("../crypto/preProcessing.cjs");require("../functions/utils/external-action.utils.cjs");require("../functions/web3/events/getShieldedBalance.cjs");require("../data-structures/volatile-helper/VolatileHelper.cjs");require("idb-keyval");const r=require("./WagmiProviderAdapter.cjs"),q=async(i,a)=>{await t.preProcessing();const e=new u.Hinkal;return r.wagmiProviderAdapter.initConfig(a),await e.initProviderAdapter(i,r.wagmiProviderAdapter),await e.initUserKeys(),await e.resetMerkle(),e};exports.prepareWagmiHinkal=q;
@@ -0,0 +1,3 @@
1
+ import { Hinkal } from '../data-structures';
2
+ import { type Config, type Connector } from 'wagmi';
3
+ export declare const prepareWagmiHinkal: (connector: Connector, config: Config) => Promise<Hinkal<unknown>>;
@@ -20,12 +20,12 @@ import "../functions/utils/external-action.utils.mjs";
20
20
  import "../functions/web3/events/getShieldedBalance.mjs";
21
21
  import "../data-structures/volatile-helper/VolatileHelper.mjs";
22
22
  import "idb-keyval";
23
- import { wagmiv2ProviderAdapter as i } from "./Wagmiv2ProviderAdapter.mjs";
24
- const U = async (t, o) => {
23
+ import { wagmiProviderAdapter as r } from "./WagmiProviderAdapter.mjs";
24
+ const W = async (t, o) => {
25
25
  await m();
26
- const r = new p();
27
- return i.initConfig(o), await r.initProviderAdapter(t, i), await r.initUserKeys(), await r.resetMerkle(), r;
26
+ const i = new p();
27
+ return r.initConfig(o), await i.initProviderAdapter(t, r), await i.initUserKeys(), await i.resetMerkle(), i;
28
28
  };
29
29
  export {
30
- U as prepareWagmiv2EthersHinkal
30
+ W as prepareWagmiHinkal
31
31
  };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("../constants/chains.constants.cjs"),d=require("../constants/contracts.constants.cjs"),a=require("../error-handling/error-codes.constants.cjs"),c=require("ethers"),o=require("../node_modules/@wagmi/core/dist/chunk-TSH6VVF4.cjs");class h{connector;chainId;originalProvider;fetchProvider;signer;chainEventListener;unsubscribeFns=[];initConnector(t){this.connector=t}requireConnector(){if(!this.connector)throw Error("No Connector In Provider Adapter")}async init(t){this.requireConnector(),t&&(this.chainId=t),this.originalProvider=await this.connector.getProvider(),this.fetchProvider=this.createFetchProvider()??this.originalProvider,this.fetchProvider===this.originalProvider&&console.warn("fetchProvider not available");const r=await this.connector.getWalletClient();this.signer=await this.walletClientToSigner(r,this.chainId)}async disconnectFromConnector(){this.release(),await o.disconnect()}async connectToConnector(t){const{isConnected:r}=o.getAccount();r&&await this.disconnectFromConnector();try{return(await o.connect({connector:t})).chain.id}catch{throw new Error(a.transactionErrorCodes.CONNECTION_FAILED)}}async waitForTransaction(t,r){if((await this.fetchProvider?.waitForTransaction(t,r))?.status)return!0;throw Error(a.transactionErrorCodes.TRANSACTION_NOT_CONFIRMED)}async signMessage(t){const r=await o.signMessage({message:t});if(!r)throw new Error(a.transactionErrorCodes.SIGNING_FAILED);if(r.includes("error"))throw new Error(a.transactionErrorCodes.SIGNATURE_UNSUPPORTED_PERSONAL_SIGN);return r}async signTypedData(t,r,e){return this.signer._signTypedData(t,r,e)}getSelectedNetwork=()=>{if(!this.chainId)throw new Error("Illegal state: no chaindId");return i.networkRegistry[this.chainId]};async switchNetwork(t){return o.switchNetwork({chainId:t.chainId})}createFetchProvider(){try{const r=i.networkRegistry[this.chainId]?.fetchRpcUrl;return r?r.includes("wss")?new c.providers.WebSocketProvider(r):new c.providers.StaticJsonRpcProvider(r):void 0}catch(t){console.log("create Fetch Provider error",t);return}}async getAddress(){const{address:t}=o.getAccount();if(!t)throw new Error("IllegalState");return c.utils.getAddress(t)}setChainEventListener(t){this.chainEventListener=t,this.chainEventListener&&(this.unsubscribeFns.push(o.watchAccount(r=>{if(!this.chainEventListener){console.warn("chainEventListener is not set");return}this.chainEventListener.onAccountChanged()})),this.unsubscribeFns.push(o.watchNetwork(r=>{if(!this.chainEventListener){console.warn("chainEventListener is not set");return}this.chainEventListener.onChainChanged(r.chain?.id)})))}onAccountChanged(){return this.init()}onChainChanged(t){return this.init(t)}release(){this.removeListeners()}removeListeners(){this.unsubscribeFns.forEach(t=>t()),this.unsubscribeFns=[]}getContractMetadata(t,r){const e=r??this.chainId;if(!e)throw new Error("No chainId provided in context");const n=i.networkRegistry[e];if(!n)throw new Error(a.transactionErrorCodes.UNSUPPORTED_NETWORK);const s=d.contractMetadataMapping[t];if(!s)throw new Error(`Unsupported contractType: ${t}`);return s(n.contractData)}getContract(t,r=void 0,e){const n=this.getContractMetadata(t,e);if(!n.abi)throw new Error(`No ABI configured for contractType: ${t}`);if(n.address&&r)throw new Error(`Overriding address is not supported for contractType: ${t}`);const s=n.address??r;if(!s)throw new Error(`No contractAddress configured for contractType: ${t}`);return new c.ethers.Contract(s,n.abi)}getContractWithSigner(t,r=void 0){if(!this.signer)throw new Error("IllegalState: no signer");return this.getContract(t,r).connect(this.signer)}getContractWithFetcher(t,r=void 0){if(!this.fetchProvider)throw new Error("fetchProvider not initialized");return this.getContract(t,r).connect(this.fetchProvider)}getContractWithFetcherForEthereum(t,r=void 0){const e=this.chainId===i.chainIds.localhost&&i.localhostNetwork===i.chainIds.ethMainnet?i.chainIds.localhost:i.chainIds.ethMainnet;return this.getContract(t,r).connect(new c.ethers.providers.StaticJsonRpcProvider(i.networkRegistry[e].fetchRpcUrl))}async sendTransaction(t){if(!this.signer)throw new Error("IllegalState: no signer");return await this.signer.sendTransaction(t)}async patchExternalProvider(t){const r=await t.getProvider();let e;if(r instanceof c.ethers.providers.Web3Provider?e=r.provider:e=r,"isWalletConnect"in e){const n=await t.getChainId();e.http=e.setHttpProvider?.(n)}}async connectAndPatchProvider(t){const r=await this.connectToConnector(t);return await this.patchExternalProvider(t),r}isPermitterAvailable(){return!!this.getSelectedNetwork()?.contractData?.permitterAddress}async getGasPrice(){const t=await this.fetchProvider?.getGasPrice();if(!t)throw Error("Could not fetch gas price in getGasPrice");return t.toBigInt()}async walletClientToSigner(t,r){const{account:e,transport:n}=t,s={chainId:r,name:""};return new c.providers.Web3Provider(n,s).getSigner(e.address)}}const w=new h,g=()=>new h;exports.Wagmiv1ProviderAdapter=h;exports.default=g;exports.wagmiv1ProvierAdapter=w;
@@ -1,44 +0,0 @@
1
- import { ChainEventListener, IProviderAdapter } from '../data-structures/provider-adapter/IProviderAdapter';
2
- import { ContractMetadata, ContractType, EthereumNetwork } from '../types/ethereum-network.types';
3
- import { ethers } from 'ethers';
4
- import { type Connector, type WalletClient } from 'wagmi';
5
- export declare class Wagmiv1ProviderAdapter implements IProviderAdapter<Connector> {
6
- private connector;
7
- chainId: number | undefined;
8
- private originalProvider;
9
- private fetchProvider;
10
- private signer;
11
- private chainEventListener?;
12
- private unsubscribeFns;
13
- initConnector(connector: Connector): void;
14
- requireConnector(): void;
15
- init(chainId?: number): Promise<void>;
16
- disconnectFromConnector(): Promise<void>;
17
- connectToConnector(connector: Connector): Promise<number>;
18
- waitForTransaction(transactionHash: string, confirmations: number): Promise<boolean>;
19
- signMessage(message: string): Promise<string>;
20
- signTypedData(domain: ethers.TypedDataDomain, types: Record<string, ethers.TypedDataField[]>, value: Record<string, unknown>): Promise<string>;
21
- getSelectedNetwork: () => EthereumNetwork | undefined;
22
- switchNetwork(network: EthereumNetwork): Promise<import("@wagmi/core").SwitchNetworkResult>;
23
- private createFetchProvider;
24
- getAddress(): Promise<string>;
25
- setChainEventListener(chainEventListener: ChainEventListener): void;
26
- onAccountChanged(): Promise<unknown>;
27
- onChainChanged(chainId?: number): Promise<unknown>;
28
- release(): void;
29
- private removeListeners;
30
- getContractMetadata(contractType: ContractType, chainId?: number): ContractMetadata;
31
- getContract(contractType: ContractType, contractAddress?: undefined, chainId?: number): ethers.Contract;
32
- getContractWithSigner(contract: ContractType, contractAddress?: undefined): ethers.Contract;
33
- getContractWithFetcher(contract: ContractType, contractAddress?: undefined): ethers.Contract;
34
- getContractWithFetcherForEthereum(contract: ContractType, contractAddress?: undefined): ethers.Contract;
35
- sendTransaction(tx: ethers.providers.TransactionRequest): Promise<ethers.providers.TransactionResponse>;
36
- patchExternalProvider(connector: Connector): Promise<void>;
37
- connectAndPatchProvider(connector: Connector): Promise<number>;
38
- isPermitterAvailable(): boolean;
39
- getGasPrice(): Promise<bigint>;
40
- walletClientToSigner(walletClient: WalletClient, chainId: number): Promise<ethers.providers.JsonRpcSigner>;
41
- }
42
- export declare const wagmiv1ProvierAdapter: Wagmiv1ProviderAdapter;
43
- declare const _default: <T = unknown>() => IProviderAdapter<T>;
44
- export default _default;
@@ -1,186 +0,0 @@
1
- import { networkRegistry as s, chainIds as c, localhostNetwork as l } from "../constants/chains.constants.mjs";
2
- import { contractMetadataMapping as g } from "../constants/contracts.constants.mjs";
3
- import { transactionErrorCodes as o } from "../error-handling/error-codes.constants.mjs";
4
- import { providers as a, utils as v, ethers as h } from "ethers";
5
- import { disconnect as u, getAccount as d, connect as f, signMessage as p, switchNetwork as P, watchAccount as C, watchNetwork as E } from "../node_modules/@wagmi/core/dist/chunk-TSH6VVF4.mjs";
6
- class w {
7
- connector;
8
- chainId;
9
- originalProvider;
10
- fetchProvider;
11
- signer;
12
- chainEventListener;
13
- unsubscribeFns = [];
14
- initConnector(t) {
15
- this.connector = t;
16
- }
17
- requireConnector() {
18
- if (!this.connector)
19
- throw Error("No Connector In Provider Adapter");
20
- }
21
- async init(t) {
22
- this.requireConnector(), t && (this.chainId = t), this.originalProvider = await this.connector.getProvider(), this.fetchProvider = this.createFetchProvider() ?? this.originalProvider, this.fetchProvider === this.originalProvider && console.warn("fetchProvider not available");
23
- const r = await this.connector.getWalletClient();
24
- this.signer = await this.walletClientToSigner(r, this.chainId);
25
- }
26
- async disconnectFromConnector() {
27
- this.release(), await u();
28
- }
29
- async connectToConnector(t) {
30
- const { isConnected: r } = d();
31
- r && await this.disconnectFromConnector();
32
- try {
33
- return (await f({ connector: t })).chain.id;
34
- } catch {
35
- throw new Error(o.CONNECTION_FAILED);
36
- }
37
- }
38
- async waitForTransaction(t, r) {
39
- if ((await this.fetchProvider?.waitForTransaction(t, r))?.status)
40
- return !0;
41
- throw Error(o.TRANSACTION_NOT_CONFIRMED);
42
- }
43
- async signMessage(t) {
44
- const r = await p({ message: t });
45
- if (!r)
46
- throw new Error(o.SIGNING_FAILED);
47
- if (r.includes("error"))
48
- throw new Error(o.SIGNATURE_UNSUPPORTED_PERSONAL_SIGN);
49
- return r;
50
- }
51
- async signTypedData(t, r, e) {
52
- return this.signer._signTypedData(t, r, e);
53
- }
54
- getSelectedNetwork = () => {
55
- if (!this.chainId)
56
- throw new Error("Illegal state: no chaindId");
57
- return s[this.chainId];
58
- };
59
- async switchNetwork(t) {
60
- return P({ chainId: t.chainId });
61
- }
62
- createFetchProvider() {
63
- try {
64
- const r = s[this.chainId]?.fetchRpcUrl;
65
- return r ? r.includes("wss") ? new a.WebSocketProvider(r) : new a.StaticJsonRpcProvider(r) : void 0;
66
- } catch (t) {
67
- console.log("create Fetch Provider error", t);
68
- return;
69
- }
70
- }
71
- async getAddress() {
72
- const { address: t } = d();
73
- if (!t)
74
- throw new Error("IllegalState");
75
- return v.getAddress(t);
76
- }
77
- setChainEventListener(t) {
78
- this.chainEventListener = t, this.chainEventListener && (this.unsubscribeFns.push(
79
- C((r) => {
80
- if (!this.chainEventListener) {
81
- console.warn("chainEventListener is not set");
82
- return;
83
- }
84
- this.chainEventListener.onAccountChanged();
85
- })
86
- ), this.unsubscribeFns.push(
87
- E((r) => {
88
- if (!this.chainEventListener) {
89
- console.warn("chainEventListener is not set");
90
- return;
91
- }
92
- this.chainEventListener.onChainChanged(r.chain?.id);
93
- })
94
- ));
95
- }
96
- onAccountChanged() {
97
- return this.init();
98
- }
99
- onChainChanged(t) {
100
- return this.init(t);
101
- }
102
- release() {
103
- this.removeListeners();
104
- }
105
- removeListeners() {
106
- this.unsubscribeFns.forEach((t) => t()), this.unsubscribeFns = [];
107
- }
108
- getContractMetadata(t, r) {
109
- const e = r ?? this.chainId;
110
- if (!e)
111
- throw new Error("No chainId provided in context");
112
- const n = s[e];
113
- if (!n)
114
- throw new Error(o.UNSUPPORTED_NETWORK);
115
- const i = g[t];
116
- if (!i)
117
- throw new Error(`Unsupported contractType: ${t}`);
118
- return i(n.contractData);
119
- }
120
- getContract(t, r = void 0, e) {
121
- const n = this.getContractMetadata(t, e);
122
- if (!n.abi)
123
- throw new Error(`No ABI configured for contractType: ${t}`);
124
- if (n.address && r)
125
- throw new Error(`Overriding address is not supported for contractType: ${t}`);
126
- const i = n.address ?? r;
127
- if (!i)
128
- throw new Error(`No contractAddress configured for contractType: ${t}`);
129
- return new h.Contract(i, n.abi);
130
- }
131
- getContractWithSigner(t, r = void 0) {
132
- if (!this.signer)
133
- throw new Error("IllegalState: no signer");
134
- return this.getContract(t, r).connect(this.signer);
135
- }
136
- getContractWithFetcher(t, r = void 0) {
137
- if (!this.fetchProvider)
138
- throw new Error("fetchProvider not initialized");
139
- return this.getContract(t, r).connect(this.fetchProvider);
140
- }
141
- getContractWithFetcherForEthereum(t, r = void 0) {
142
- const e = this.chainId === c.localhost && l === c.ethMainnet ? c.localhost : c.ethMainnet;
143
- return this.getContract(t, r).connect(
144
- new h.providers.StaticJsonRpcProvider(s[e].fetchRpcUrl)
145
- );
146
- }
147
- async sendTransaction(t) {
148
- if (!this.signer)
149
- throw new Error("IllegalState: no signer");
150
- return await this.signer.sendTransaction(t);
151
- }
152
- async patchExternalProvider(t) {
153
- const r = await t.getProvider();
154
- let e;
155
- if (r instanceof h.providers.Web3Provider ? e = r.provider : e = r, "isWalletConnect" in e) {
156
- const n = await t.getChainId();
157
- e.http = e.setHttpProvider?.(n);
158
- }
159
- }
160
- async connectAndPatchProvider(t) {
161
- const r = await this.connectToConnector(t);
162
- return await this.patchExternalProvider(t), r;
163
- }
164
- isPermitterAvailable() {
165
- return !!this.getSelectedNetwork()?.contractData?.permitterAddress;
166
- }
167
- async getGasPrice() {
168
- const t = await this.fetchProvider?.getGasPrice();
169
- if (!t)
170
- throw Error("Could not fetch gas price in getGasPrice");
171
- return t.toBigInt();
172
- }
173
- async walletClientToSigner(t, r) {
174
- const { account: e, transport: n } = t, i = {
175
- chainId: r,
176
- name: ""
177
- };
178
- return new a.Web3Provider(n, i).getSigner(e.address);
179
- }
180
- }
181
- const T = new w(), b = () => new w();
182
- export {
183
- w as Wagmiv1ProviderAdapter,
184
- b as default,
185
- T as wagmiv1ProvierAdapter
186
- };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("../constants/chains.constants.cjs"),d=require("../constants/contracts.constants.cjs"),a=require("../error-handling/error-codes.constants.cjs"),s=require("ethers"),g=require("wagmi2"),c=require("wagmi2/actions");class h{connector;chainId;originalProvider;fetchProvider;signer;chainEventListener;config;unsubscribeFns=[];initConnector(r){this.connector=r}requireConnector(){if(!this.connector)throw Error("No Connector In Provider Adapter")}initConfig(r){this.config=r}async init(r){this.requireConnector(),r&&(this.chainId=r),this.originalProvider=await this.connector.getProvider(),this.fetchProvider=this.createFetchProvider()??this.originalProvider,this.fetchProvider===this.originalProvider&&console.warn("fetchProvider not available");const t=await this.connector.getProvider(),e=await this.connector.getAccounts();this.signer=await this.walletClientToSigner({transport:t,account:e[0]},this.chainId)}async disconnectFromConnector(){if(!this.config)throw new Error("No Config In Provider Adapter");this.release(),await c.disconnect(this.config)}async connectToConnector(r){if(!this.config)throw new Error("No Config In Provider Adapter");try{return(await c.connect(this.config,{connector:r})).chainId}catch(t){if(t instanceof g.ConnectorAlreadyConnectedError)return r.getChainId();throw console.log(t),new Error(a.transactionErrorCodes.CONNECTION_FAILED)}}async waitForTransaction(r,t){if((await this.fetchProvider?.waitForTransaction(r,t))?.status)return!0;throw Error(a.transactionErrorCodes.TRANSACTION_NOT_CONFIRMED)}async signMessage(r){if(!this.config)throw new Error("No Config In Provider Adapter");const t=await c.signMessage(this.config,{message:r});if(!t)throw new Error(a.transactionErrorCodes.SIGNING_FAILED);if(t.includes("error"))throw new Error(a.transactionErrorCodes.SIGNATURE_UNSUPPORTED_PERSONAL_SIGN);return t}async signTypedData(r,t,e){return this.signer._signTypedData(r,t,e)}getSelectedNetwork=()=>{if(!this.chainId)throw new Error("Illegal state: no chaindId");return i.networkRegistry[this.chainId]};async switchNetwork(r){if(!this.config)throw new Error("No Config In Provider Adapter");return c.switchChain(this.config,{chainId:r.chainId})}createFetchProvider(){try{const t=i.networkRegistry[this.chainId]?.fetchRpcUrl;return t?t.includes("wss")?new s.providers.WebSocketProvider(t):new s.providers.StaticJsonRpcProvider(t):void 0}catch(r){console.log("create Fetch Provider error",r);return}}async getAddress(){if(!this.config)throw new Error("No Config In Provider Adapter");const{address:r}=c.getAccount(this.config);if(!r)throw new Error("IllegalState");return s.utils.getAddress(r)}setChainEventListener(r){if(!this.config)throw new Error("No Config In Provider Adapter");this.chainEventListener=r,this.chainEventListener&&(this.unsubscribeFns.push(c.watchAccount(this.config,{onChange:({address:t},{address:e})=>{if(!this.chainEventListener){console.warn("chainEventListener is not set");return}console.log("Account changed"),t!==e&&(console.log("Account changed"),this.chainEventListener.onAccountChanged())}})),this.unsubscribeFns.push(c.watchChainId(this.config,{onChange:t=>{if(!this.chainEventListener){console.warn("chainEventListener is not set");return}console.log("Chain ID changed!",t),this.chainEventListener.onChainChanged(t)}})))}onAccountChanged(){return this.init()}onChainChanged(r){return this.init(r)}release(){this.removeListeners()}removeListeners(){this.unsubscribeFns.forEach(r=>r()),this.unsubscribeFns=[]}getContractMetadata(r,t){const e=t??this.chainId;if(!e)throw new Error("No chainId provided in context");const n=i.networkRegistry[e];if(!n)throw new Error(a.transactionErrorCodes.UNSUPPORTED_NETWORK);const o=d.contractMetadataMapping[r];if(!o)throw new Error(`Unsupported contractType: ${r}`);return o(n.contractData)}getContract(r,t=void 0,e){const n=this.getContractMetadata(r,e);if(!n.abi)throw new Error(`No ABI configured for contractType: ${r}`);if(n.address&&t)throw new Error(`Overriding address is not supported for contractType: ${r}`);const o=n.address??t;if(!o)throw new Error(`No contractAddress configured for contractType: ${r}`);return new s.ethers.Contract(o,n.abi)}getContractWithSigner(r,t=void 0){if(!this.signer)throw new Error("IllegalState: no signer");return this.getContract(r,t).connect(this.signer)}getContractWithFetcher(r,t=void 0){if(!this.fetchProvider)throw new Error("fetchProvider not initialized");return this.getContract(r,t).connect(this.fetchProvider)}getContractWithFetcherForEthereum(r,t=void 0){const e=this.chainId===i.chainIds.localhost&&i.localhostNetwork===i.chainIds.ethMainnet?i.chainIds.localhost:i.chainIds.ethMainnet;return this.getContract(r,t).connect(new s.ethers.providers.StaticJsonRpcProvider(i.networkRegistry[e].fetchRpcUrl))}async sendTransaction(r){if(!this.signer)throw new Error("IllegalState: no signer");return await this.signer.sendTransaction(r)}async patchExternalProvider(r){const t=await r.getProvider();let e;if(t instanceof s.ethers.providers.Web3Provider?e=t.provider:e=t,"isWalletConnect"in e){const n=await r.getChainId();e.http=e.setHttpProvider?.(n)}}async connectAndPatchProvider(r){const t=await this.connectToConnector(r);return await this.patchExternalProvider(r),t}isPermitterAvailable(){return!!this.getSelectedNetwork()?.contractData?.permitterAddress}async getGasPrice(){const r=await this.fetchProvider?.getGasPrice();if(!r)throw Error("Could not fetch gas price in getGasPrice");return r.toBigInt()}async walletClientToSigner(r,t){const{account:e,transport:n}=r,o={chainId:t,name:""};return new s.providers.Web3Provider(n,o).getSigner(e)}}const w=new h,v=()=>new h;exports.Wagmiv2ProviderAdapter=h;exports.default=v;exports.wagmiv2ProviderAdapter=w;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("ethers");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");const u=require("../data-structures/Hinkal/Hinkal.cjs");require("../constants/chains.constants.cjs");require("../types/circom-data.types.cjs");require("../types/transactions.types.cjs");require("../types/curve.types.cjs");require("../data-structures/custom-token-registry/CustomTokenRegistry.cjs");require("../constants/vite.constants.cjs");require("axios");require("../constants/coingecko.constants.cjs");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 a=require("../crypto/preProcessing.cjs");require("../functions/utils/external-action.utils.cjs");require("../functions/web3/events/getShieldedBalance.cjs");require("../data-structures/volatile-helper/VolatileHelper.cjs");require("idb-keyval");const t=require("./Wagmiv1ProviderAdapter.cjs"),q=async(r,i)=>{await a.preProcessing();const e=new u.Hinkal(i);return await e.initProviderAdapter(r,t.wagmiv1ProvierAdapter),await e.initUserKeys(),await e.resetMerkle(),e};exports.prepareWagmiv1EthersHinkal=q;
@@ -1,4 +0,0 @@
1
- import { Hinkal } from '../data-structures';
2
- import { type Connector } from 'wagmi';
3
- import { type HinkalConfig } from '../types/hinkal.types';
4
- export declare const prepareWagmiv1EthersHinkal: (connector: Connector, hinkalConfig?: HinkalConfig) => Promise<Hinkal<Connector>>;
@@ -1,31 +0,0 @@
1
- import "ethers";
2
- import "circomlibjs-hinkal-fork";
3
- import "libsodium-wrappers";
4
- import { Hinkal as o } from "../data-structures/Hinkal/Hinkal.mjs";
5
- import "../constants/chains.constants.mjs";
6
- import "../types/circom-data.types.mjs";
7
- import "../types/transactions.types.mjs";
8
- import "../types/curve.types.mjs";
9
- import "../data-structures/custom-token-registry/CustomTokenRegistry.mjs";
10
- import "../constants/vite.constants.mjs";
11
- import "axios";
12
- import "../constants/coingecko.constants.mjs";
13
- import "../constants/contracts.constants.mjs";
14
- import "../constants/kyc.constants.mjs";
15
- import "../constants/axelar.constants.mjs";
16
- import "../constants/rewards.constants.mjs";
17
- import "../constants/reorg-depths.constants.mjs";
18
- import { preProcessing as p } from "../crypto/preProcessing.mjs";
19
- import "../functions/utils/external-action.utils.mjs";
20
- import "../functions/web3/events/getShieldedBalance.mjs";
21
- import "../data-structures/volatile-helper/VolatileHelper.mjs";
22
- import "idb-keyval";
23
- import { wagmiv1ProvierAdapter as m } from "./Wagmiv1ProviderAdapter.mjs";
24
- const W = async (i, t) => {
25
- await p();
26
- const r = new o(t);
27
- return await r.initProviderAdapter(i, m), await r.initUserKeys(), await r.resetMerkle(), r;
28
- };
29
- export {
30
- W as prepareWagmiv1EthersHinkal
31
- };
@@ -1,2 +0,0 @@
1
- import { Hinkal } from '../data-structures';
2
- export declare const prepareWagmiv2EthersHinkal: (connector: Connector, config: Config) => Promise<Hinkal<unknown>>;