@claritydao/midnight-agora-sdk 0.1.0

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.
Files changed (60) hide show
  1. package/.prettierrc +1 -0
  2. package/LICENSE +0 -0
  3. package/README.md +1134 -0
  4. package/dist/browser-providers.d.ts +21 -0
  5. package/dist/browser-providers.d.ts.map +1 -0
  6. package/dist/browser-providers.js +147 -0
  7. package/dist/browser-providers.js.map +1 -0
  8. package/dist/common-types.d.ts +29 -0
  9. package/dist/common-types.d.ts.map +1 -0
  10. package/dist/common-types.js +2 -0
  11. package/dist/common-types.js.map +1 -0
  12. package/dist/errors.d.ts +67 -0
  13. package/dist/errors.d.ts.map +1 -0
  14. package/dist/errors.js +108 -0
  15. package/dist/errors.js.map +1 -0
  16. package/dist/governor-api.d.ts +348 -0
  17. package/dist/governor-api.d.ts.map +1 -0
  18. package/dist/governor-api.js +716 -0
  19. package/dist/governor-api.js.map +1 -0
  20. package/dist/index.d.ts +11 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +14 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/manager.d.ts +87 -0
  25. package/dist/manager.d.ts.map +1 -0
  26. package/dist/manager.js +93 -0
  27. package/dist/manager.js.map +1 -0
  28. package/dist/types.d.ts +307 -0
  29. package/dist/types.d.ts.map +1 -0
  30. package/dist/types.js +77 -0
  31. package/dist/types.js.map +1 -0
  32. package/dist/utils/index.d.ts +34 -0
  33. package/dist/utils/index.d.ts.map +1 -0
  34. package/dist/utils/index.js +57 -0
  35. package/dist/utils/index.js.map +1 -0
  36. package/dist/validators.d.ts +52 -0
  37. package/dist/validators.d.ts.map +1 -0
  38. package/dist/validators.js +160 -0
  39. package/dist/validators.js.map +1 -0
  40. package/eslint.config.mjs +48 -0
  41. package/package.json +39 -0
  42. package/src/browser-providers.ts +274 -0
  43. package/src/common-types.ts +51 -0
  44. package/src/errors.ts +124 -0
  45. package/src/governor-api.ts +948 -0
  46. package/src/index.ts +51 -0
  47. package/src/manager.ts +203 -0
  48. package/src/types.ts +403 -0
  49. package/src/utils/index.ts +60 -0
  50. package/src/validators.ts +245 -0
  51. package/test/README.md +409 -0
  52. package/test/errors.test.ts +179 -0
  53. package/test/integration/governor-api.test.ts +370 -0
  54. package/test/mocks/providers.ts +130 -0
  55. package/test/types.test.ts +112 -0
  56. package/test/utils.test.ts +111 -0
  57. package/test/validators.test.ts +368 -0
  58. package/test/wasm-init.test.ts +132 -0
  59. package/tsconfig.json +18 -0
  60. package/vitest.config.ts +9 -0
@@ -0,0 +1,21 @@
1
+ import { type GovernorProviders } from "./common-types";
2
+ import { type Logger } from "pino";
3
+ import { type InitialAPI } from "@midnight-ntwrk/dapp-connector-api";
4
+ /**
5
+ * Initializes and returns the providers required for Governor contract interactions in a browser environment.
6
+ *
7
+ * @param logger The logger instance for logging.
8
+ * @param networkId The network ID to connect to (e.g., 'testnet', 'mainnet').
9
+ * @returns A promise that resolves to configured GovernorProviders.
10
+ *
11
+ * @remarks
12
+ * This function connects to the Midnight Lace wallet extension and retrieves network configuration
13
+ * from the wallet. The network ID is specified by the caller.
14
+ */
15
+ export declare const initializeProviders: (logger: Logger, networkId?: string) => Promise<GovernorProviders>;
16
+ declare global {
17
+ interface Window {
18
+ midnight?: Record<string, InitialAPI>;
19
+ }
20
+ }
21
+ //# sourceMappingURL=browser-providers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-providers.d.ts","sourceRoot":"","sources":["../src/browser-providers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAyB,MAAM,gBAAgB,CAAC;AAe/E,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EACL,KAAK,UAAU,EAGhB,MAAM,oCAAoC,CAAC;AAgC5C;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,GAC9B,QAAQ,MAAM,EACd,YAAW,MAAkB,KAC5B,OAAO,CAAC,iBAAiB,CAoC3B,CAAC;AAuKF,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;KACvC;CACF"}
@@ -0,0 +1,147 @@
1
+ import { concatMap, filter, firstValueFrom, interval, map, of, take, tap, throwError, timeout, catchError } from "rxjs";
2
+ import { pipe as fnPipe } from "fp-ts/function";
3
+ import { levelPrivateStateProvider } from "@midnight-ntwrk/midnight-js-level-private-state-provider";
4
+ import { FetchZkConfigProvider } from "@midnight-ntwrk/midnight-js-fetch-zk-config-provider";
5
+ import { httpClientProofProvider } from "@midnight-ntwrk/midnight-js-http-client-proof-provider";
6
+ import { indexerPublicDataProvider } from "@midnight-ntwrk/midnight-js-indexer-public-data-provider";
7
+ import semver from "semver";
8
+ import { getNetworkId, setNetworkId } from "@midnight-ntwrk/midnight-js-network-id";
9
+ // Helper functions for hex encoding/decoding
10
+ const toHexString = (bytes) => Array.from(bytes)
11
+ .map((b) => b.toString(16).padStart(2, "0"))
12
+ .join("");
13
+ const _fromHexString = (hex) => new Uint8Array(hex.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
14
+ /**
15
+ * Initializes and returns the providers required for Governor contract interactions in a browser environment.
16
+ *
17
+ * @param logger The logger instance for logging.
18
+ * @param networkId The network ID to connect to (e.g., 'testnet', 'mainnet').
19
+ * @returns A promise that resolves to configured GovernorProviders.
20
+ *
21
+ * @remarks
22
+ * This function connects to the Midnight Lace wallet extension and retrieves network configuration
23
+ * from the wallet. The network ID is specified by the caller.
24
+ */
25
+ export const initializeProviders = async (logger, networkId = "testnet") => {
26
+ const { wallet, config } = await connectToWallet(logger, networkId);
27
+ const zkConfigPath = window.location.origin;
28
+ logger.info(`Connecting to wallet with network ID: ${getNetworkId()}`);
29
+ // Get wallet addresses
30
+ const addresses = await wallet.getShieldedAddresses();
31
+ return {
32
+ privateStateProvider: levelPrivateStateProvider({
33
+ privateStateStoreName: "governor-private-state"
34
+ }),
35
+ zkConfigProvider: new FetchZkConfigProvider(zkConfigPath, fetch.bind(window)),
36
+ proofProvider: config.proverServerUri
37
+ ? httpClientProofProvider(config.proverServerUri)
38
+ : httpClientProofProvider(""), // Fallback - proving may be done by wallet
39
+ publicDataProvider: indexerPublicDataProvider(config.indexerUri, config.indexerWsUri),
40
+ walletProvider: createWalletProvider(wallet, addresses),
41
+ midnightProvider: {
42
+ async submitTx(tx) {
43
+ // Convert transaction to hex string for the connector API
44
+ const serialized = tx.serialize();
45
+ const hexString = toHexString(serialized);
46
+ await wallet.submitTransaction(hexString);
47
+ // Return the transaction hash as the ID
48
+ return tx.transactionHash();
49
+ }
50
+ }
51
+ };
52
+ };
53
+ /**
54
+ * Creates a WalletProvider from the connected wallet API.
55
+ */
56
+ const createWalletProvider = (wallet, addresses) => {
57
+ // Note: The bech32m addresses need to be converted to the expected key types
58
+ // This conversion may need adjustment based on the actual key format expected
59
+ const coinPublicKey = addresses.shieldedCoinPublicKey;
60
+ const encryptionPublicKey = addresses.shieldedEncryptionPublicKey;
61
+ return {
62
+ getCoinPublicKey() {
63
+ return coinPublicKey;
64
+ },
65
+ getEncryptionPublicKey() {
66
+ return encryptionPublicKey;
67
+ },
68
+ async balanceTx(tx, _newCoins, _ttl) {
69
+ // Use the wallet's balancing capability
70
+ // Convert Uint8Array to hex string for the connector API
71
+ const serialized = tx.serialize();
72
+ const hexString = toHexString(serialized);
73
+ const _result = await wallet.balanceUnsealedTransaction(hexString);
74
+ // The wallet returns a balanced transaction as a hex string
75
+ // We need to convert it back and return as NothingToProve
76
+ // Note: The actual deserialization may need the Transaction.deserialize with proper markers
77
+ // For now, we return the original transaction as the wallet handles proving internally
78
+ return {
79
+ type: "NothingToProve",
80
+ transaction: tx // The wallet should have balanced this
81
+ };
82
+ }
83
+ };
84
+ };
85
+ /**
86
+ * Connects to the Midnight Lace wallet extension.
87
+ *
88
+ * @param logger The logger instance for logging.
89
+ * @param networkId The network ID to connect to.
90
+ * @returns A promise that resolves to the wallet API and configuration.
91
+ */
92
+ const connectToWallet = (logger, networkId) => {
93
+ const COMPATIBLE_CONNECTOR_API_VERSION = "4.x";
94
+ return firstValueFrom(fnPipe(interval(100), map(() => {
95
+ // Find wallet in window.midnight
96
+ const midnight = window.midnight;
97
+ if (!midnight)
98
+ return undefined;
99
+ // The new API uses rdns keys instead of named keys like mnLace
100
+ // Look for any available wallet
101
+ const walletKeys = Object.keys(midnight).filter((key) => key !== "addEventListener");
102
+ if (walletKeys.length === 0)
103
+ return undefined;
104
+ return midnight[walletKeys[0]];
105
+ }), tap((connectorAPI) => {
106
+ logger.info(connectorAPI, "Check for wallet connector API");
107
+ }), filter((connectorAPI) => !!connectorAPI), concatMap((connectorAPI) => semver.satisfies(connectorAPI.apiVersion, COMPATIBLE_CONNECTOR_API_VERSION)
108
+ ? of(connectorAPI)
109
+ : throwError(() => {
110
+ logger.error({
111
+ expected: COMPATIBLE_CONNECTOR_API_VERSION,
112
+ actual: connectorAPI.apiVersion
113
+ }, "Incompatible version of wallet connector API");
114
+ return new Error(`Incompatible version of Midnight Lace wallet found. Require '${COMPATIBLE_CONNECTOR_API_VERSION}', got '${connectorAPI.apiVersion}'.`);
115
+ })), tap((connectorAPI) => {
116
+ logger.info(connectorAPI, "Compatible wallet connector API found. Connecting.");
117
+ }), take(1), timeout({
118
+ first: 1_000,
119
+ with: () => throwError(() => {
120
+ logger.error("Could not find wallet connector API");
121
+ return new Error("Could not find Midnight Lace wallet. Extension installed?");
122
+ })
123
+ }), concatMap(async (connectorAPI) => {
124
+ // Connect to the wallet with the specified network ID
125
+ const connectedAPI = await connectorAPI.connect(networkId);
126
+ // Set the network ID globally
127
+ setNetworkId(networkId);
128
+ logger.info("Connected to wallet");
129
+ return { walletConnectorAPI: connectedAPI, connectorAPI };
130
+ }), timeout({
131
+ first: 30_000, // Increased timeout for user approval
132
+ with: () => throwError(() => {
133
+ logger.error("Wallet connector API has failed to respond");
134
+ return new Error("Midnight Lace wallet has failed to respond. Extension enabled?");
135
+ })
136
+ }), catchError((error, apis) => error
137
+ ? throwError(() => {
138
+ logger.error("Unable to connect to wallet");
139
+ return new Error("Application is not authorized or connection failed");
140
+ })
141
+ : apis), concatMap(async ({ walletConnectorAPI }) => {
142
+ const config = await walletConnectorAPI.getConfiguration();
143
+ logger.info("Connected to wallet connector API and retrieved service configuration");
144
+ return { wallet: walletConnectorAPI, config };
145
+ })));
146
+ };
147
+ //# sourceMappingURL=browser-providers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-providers.js","sourceRoot":"","sources":["../src/browser-providers.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,MAAM,EACN,cAAc,EACd,QAAQ,EACR,GAAG,EACH,EAAE,EACF,IAAI,EACJ,GAAG,EACH,UAAU,EACV,OAAO,EACP,UAAU,EACX,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAOhD,OAAO,EAAE,yBAAyB,EAAE,MAAM,0DAA0D,CAAC;AACrG,OAAO,EAAE,qBAAqB,EAAE,MAAM,sDAAsD,CAAC;AAC7F,OAAO,EAAE,uBAAuB,EAAE,MAAM,wDAAwD,CAAC;AACjG,OAAO,EAAE,yBAAyB,EAAE,MAAM,0DAA0D,CAAC;AAarG,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EACL,YAAY,EACZ,YAAY,EACb,MAAM,wCAAwC,CAAC;AAEhD,6CAA6C;AAC7C,MAAM,WAAW,GAAG,CAAC,KAAiB,EAAU,EAAE,CAChD,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;KACd,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;KAC3C,IAAI,CAAC,EAAE,CAAC,CAAC;AAEd,MAAM,cAAc,GAAG,C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ChD,CAAC,CAAC,CACH,CACF,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type { ImpureCircuitId, MidnightProviders, Contract } from "@midnight-ntwrk/midnight-js-types";
2
+ import type { DeployedContract, FoundContract } from "@midnight-ntwrk/midnight-js-contracts";
3
+ export type GovernorContract = Contract;
4
+ export type GovernorCircuits = ImpureCircuitId<GovernorContract>;
5
+ export declare const GovernorPrivateStateId = "governorPrivateState";
6
+ export type GovernorPrivateState = {
7
+ secretKey: Uint8Array | null;
8
+ currentTime: bigint;
9
+ userStake: {
10
+ amount: bigint;
11
+ delegatedTo: Uint8Array;
12
+ stakedAt: bigint;
13
+ };
14
+ votingHistory: any[];
15
+ proposalHistory: any[];
16
+ governanceConfig: {
17
+ votingPeriod: bigint;
18
+ quorumThreshold: bigint;
19
+ proposalThreshold: bigint;
20
+ proposalLifetime: bigint;
21
+ executionDelay: bigint;
22
+ gracePeriod: bigint;
23
+ minStakeAmount: bigint;
24
+ stakingPeriod: bigint;
25
+ };
26
+ };
27
+ export type GovernorProviders = MidnightProviders<GovernorCircuits, typeof GovernorPrivateStateId, GovernorPrivateState>;
28
+ export type DeployedGovernorContract = DeployedContract<GovernorContract> | FoundContract<GovernorContract>;
29
+ //# sourceMappingURL=common-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common-types.d.ts","sourceRoot":"","sources":["../src/common-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EACjB,QAAQ,EACT,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EACd,MAAM,uCAAuC,CAAC;AAI/C,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAExC,MAAM,MAAM,gBAAgB,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAAC;AAEjE,eAAO,MAAM,sBAAsB,yBAAyB,CAAC;AAI7D,MAAM,MAAM,oBAAoB,GAAG;IACjC,SAAS,EAAE,UAAU,GAAG,IAAI,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE;QACT,MAAM,EAAE,MAAM,CAAC;QACf,WAAW,EAAE,UAAU,CAAC;QACxB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,aAAa,EAAE,GAAG,EAAE,CAAC;IACrB,eAAe,EAAE,GAAG,EAAE,CAAC;IACvB,gBAAgB,EAAE;QAChB,YAAY,EAAE,MAAM,CAAC;QACrB,eAAe,EAAE,MAAM,CAAC;QACxB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,gBAAgB,EAAE,MAAM,CAAC;QACzB,cAAc,EAAE,MAAM,CAAC;QACvB,WAAW,EAAE,MAAM,CAAC;QACpB,cAAc,EAAE,MAAM,CAAC;QACvB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,CAC/C,gBAAgB,EAChB,OAAO,sBAAsB,EAC7B,oBAAoB,CACrB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAChC,gBAAgB,CAAC,gBAAgB,CAAC,GAClC,aAAa,CAAC,gBAAgB,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export const GovernorPrivateStateId = "governorPrivateState";
2
+ //# sourceMappingURL=common-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common-types.js","sourceRoot":"","sources":["../src/common-types.ts"],"names":[],"mappings":"AAgBA,MAAM,CAAC,MAAM,sBAAsB,GAAG,sBAAsB,CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Custom error classes for the Agora DAO Governor SDK.
3
+ *
4
+ * @module errors
5
+ */
6
+ /**
7
+ * Base error class for all SDK errors.
8
+ */
9
+ export declare class GovernorSDKError extends Error {
10
+ constructor(message: string);
11
+ }
12
+ /**
13
+ * Thrown when wallet is not connected.
14
+ */
15
+ export declare class WalletNotConnectedError extends GovernorSDKError {
16
+ constructor();
17
+ }
18
+ /**
19
+ * Thrown when user has insufficient stake for an operation.
20
+ */
21
+ export declare class InsufficientStakeError extends GovernorSDKError {
22
+ constructor(required: bigint, actual: bigint);
23
+ }
24
+ /**
25
+ * Thrown when a parameter is invalid.
26
+ */
27
+ export declare class InvalidParameterError extends GovernorSDKError {
28
+ constructor(parameterName: string, reason: string);
29
+ }
30
+ /**
31
+ * Thrown when a contract is not found at the specified address.
32
+ */
33
+ export declare class ContractNotFoundError extends GovernorSDKError {
34
+ constructor(address: string);
35
+ }
36
+ /**
37
+ * Thrown when a proposal is not found.
38
+ */
39
+ export declare class ProposalNotFoundError extends GovernorSDKError {
40
+ constructor(proposalId: bigint);
41
+ }
42
+ /**
43
+ * Thrown when a transaction fails.
44
+ */
45
+ export declare class TransactionError extends GovernorSDKError {
46
+ readonly txHash?: string | undefined;
47
+ constructor(message: string, txHash?: string | undefined);
48
+ }
49
+ /**
50
+ * Thrown when contract deployment fails.
51
+ */
52
+ export declare class DeploymentError extends GovernorSDKError {
53
+ constructor(message: string);
54
+ }
55
+ /**
56
+ * Thrown when configuration is invalid.
57
+ */
58
+ export declare class InvalidConfigurationError extends GovernorSDKError {
59
+ constructor(message: string);
60
+ }
61
+ /**
62
+ * Thrown when network ID is not set.
63
+ */
64
+ export declare class NetworkNotConfiguredError extends GovernorSDKError {
65
+ constructor();
66
+ }
67
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;gBAC7B,OAAO,EAAE,MAAM;CAK5B;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,gBAAgB;;CAQ5D;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,gBAAgB;gBAC9C,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAK7C;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,gBAAgB;gBAC7C,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAKlD;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,gBAAgB;gBAC7C,OAAO,EAAE,MAAM;CAK5B;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,gBAAgB;gBAC7C,UAAU,EAAE,MAAM;CAK/B;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,gBAAgB;aAGlC,MAAM,CAAC,EAAE,MAAM;gBAD/B,OAAO,EAAE,MAAM,EACC,MAAM,CAAC,EAAE,MAAM,YAAA;CAQlC;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,gBAAgB;gBACvC,OAAO,EAAE,MAAM;CAK5B;AAED;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,gBAAgB;gBACjD,OAAO,EAAE,MAAM;CAK5B;AAED;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,gBAAgB;;CAQ9D"}
package/dist/errors.js ADDED
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Custom error classes for the Agora DAO Governor SDK.
3
+ *
4
+ * @module errors
5
+ */
6
+ /**
7
+ * Base error class for all SDK errors.
8
+ */
9
+ export class GovernorSDKError extends Error {
10
+ constructor(message) {
11
+ super(message);
12
+ this.name = "GovernorSDKError";
13
+ Object.setPrototypeOf(this, GovernorSDKError.prototype);
14
+ }
15
+ }
16
+ /**
17
+ * Thrown when wallet is not connected.
18
+ */
19
+ export class WalletNotConnectedError extends GovernorSDKError {
20
+ constructor() {
21
+ super("Wallet not connected. Please ensure Lace wallet is installed and connected.");
22
+ this.name = "WalletNotConnectedError";
23
+ Object.setPrototypeOf(this, WalletNotConnectedError.prototype);
24
+ }
25
+ }
26
+ /**
27
+ * Thrown when user has insufficient stake for an operation.
28
+ */
29
+ export class InsufficientStakeError extends GovernorSDKError {
30
+ constructor(required, actual) {
31
+ super(`Insufficient stake. Required: ${required}, Actual: ${actual}`);
32
+ this.name = "InsufficientStakeError";
33
+ Object.setPrototypeOf(this, InsufficientStakeError.prototype);
34
+ }
35
+ }
36
+ /**
37
+ * Thrown when a parameter is invalid.
38
+ */
39
+ export class InvalidParameterError extends GovernorSDKError {
40
+ constructor(parameterName, reason) {
41
+ super(`Invalid parameter '${parameterName}': ${reason}`);
42
+ this.name = "InvalidParameterError";
43
+ Object.setPrototypeOf(this, InvalidParameterError.prototype);
44
+ }
45
+ }
46
+ /**
47
+ * Thrown when a contract is not found at the specified address.
48
+ */
49
+ export class ContractNotFoundError extends GovernorSDKError {
50
+ constructor(address) {
51
+ super(`Contract not found at address: ${address}`);
52
+ this.name = "ContractNotFoundError";
53
+ Object.setPrototypeOf(this, ContractNotFoundError.prototype);
54
+ }
55
+ }
56
+ /**
57
+ * Thrown when a proposal is not found.
58
+ */
59
+ export class ProposalNotFoundError extends GovernorSDKError {
60
+ constructor(proposalId) {
61
+ super(`Proposal not found with ID: ${proposalId}`);
62
+ this.name = "ProposalNotFoundError";
63
+ Object.setPrototypeOf(this, ProposalNotFoundError.prototype);
64
+ }
65
+ }
66
+ /**
67
+ * Thrown when a transaction fails.
68
+ */
69
+ export class TransactionError extends GovernorSDKError {
70
+ txHash;
71
+ constructor(message, txHash) {
72
+ super(`Transaction failed: ${message}${txHash ? ` (txHash: ${txHash})` : ""}`);
73
+ this.txHash = txHash;
74
+ this.name = "TransactionError";
75
+ Object.setPrototypeOf(this, TransactionError.prototype);
76
+ }
77
+ }
78
+ /**
79
+ * Thrown when contract deployment fails.
80
+ */
81
+ export class DeploymentError extends GovernorSDKError {
82
+ constructor(message) {
83
+ super(`Contract deployment failed: ${message}`);
84
+ this.name = "DeploymentError";
85
+ Object.setPrototypeOf(this, DeploymentError.prototype);
86
+ }
87
+ }
88
+ /**
89
+ * Thrown when configuration is invalid.
90
+ */
91
+ export class InvalidConfigurationError extends GovernorSDKError {
92
+ constructor(message) {
93
+ super(`Invalid configuration: ${message}`);
94
+ this.name = "InvalidConfigurationError";
95
+ Object.setPrototypeOf(this, InvalidConfigurationError.prototype);
96
+ }
97
+ }
98
+ /**
99
+ * Thrown when network ID is not set.
100
+ */
101
+ export class NetworkNotConfiguredError extends GovernorSDKError {
102
+ constructor() {
103
+ super("Network ID not configured. Set window.midnight.mnLace.networkId before initializing providers.");
104
+ this.name = "NetworkNotConfiguredError";
105
+ Object.setPrototypeOf(this, NetworkNotConfiguredError.prototype);
106
+ }
107
+ }
108
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAC1D,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,gBAAgB;IAC3D;QACE,KAAK,CACH,6EAA6E,CAC9E,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;QACtC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,uBAAuB,CAAC,SAAS,CAAC,CAAC;IACjE,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,gBAAgB;IAC1D,YAAY,QAAgB,EAAE,MAAc;QAC1C,KAAK,CAAC,iCAAiC,QAAQ,aAAa,MAAM,EAAE,CAAC,CAAC;QACtE,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;QACrC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAChE,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,gBAAgB;IACzD,YAAY,aAAqB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