@aastar/operator 0.16.14 → 0.16.16

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.
@@ -0,0 +1,42 @@
1
+ import { type Address, type Hash } from 'viem';
2
+ import { type TransactionOptions } from '@aastar/core';
3
+ import { PaymasterOperatorClient, type OperatorClientConfig } from './PaymasterOperatorClient.js';
4
+ export interface OperatorStatus {
5
+ isConfigured: boolean;
6
+ isActive: boolean;
7
+ balance: bigint;
8
+ }
9
+ /**
10
+ * OperatorLifecycle - L3 Pattern
11
+ *
12
+ * Responsibilities:
13
+ * 1. Managing the complete lifecycle of a Paymaster Operator
14
+ * 2. Unifying setup (onboard), operation (config), and exit (withdraw)
15
+ */
16
+ export declare class OperatorLifecycle extends PaymasterOperatorClient {
17
+ constructor(config: OperatorClientConfig);
18
+ /**
19
+ * Check if the account is ready to become an operator
20
+ * (e.g., has GToken, has ROLE_COMMUNITY, etc.)
21
+ */
22
+ checkReadiness(): Promise<OperatorStatus>;
23
+ /**
24
+ * One-click Setup: Register + Deposit + Deploy Node
25
+ * Wraps existing registerAsSuperPaymasterOperator or deployAndRegisterPaymasterV4
26
+ */
27
+ setupNode(params: {
28
+ type: 'V4' | 'SUPER';
29
+ stakeAmount?: bigint;
30
+ depositAmount?: bigint;
31
+ }, options?: TransactionOptions): Promise<Hash[]>;
32
+ getOperatorStats(): Promise<any>;
33
+ /**
34
+ * Start the exit process: Unstake from Registry/SuperPaymaster and Unlock funds
35
+ */
36
+ initiateExit(options?: TransactionOptions): Promise<Hash>;
37
+ /**
38
+ * Finalize exit: Withdraw all funds (Collateral + Rewards)
39
+ */
40
+ withdrawAllFunds(to?: Address, options?: TransactionOptions): Promise<Hash[]>;
41
+ private getTokenBalance;
42
+ }
@@ -0,0 +1,118 @@
1
+ import { parseEther } from 'viem';
2
+ import { PaymasterOperatorClient } from './PaymasterOperatorClient.js';
3
+ import { tokenActions, registryActions } from '@aastar/core'; // L2/L1 Actions
4
+ /**
5
+ * OperatorLifecycle - L3 Pattern
6
+ *
7
+ * Responsibilities:
8
+ * 1. Managing the complete lifecycle of a Paymaster Operator
9
+ * 2. Unifying setup (onboard), operation (config), and exit (withdraw)
10
+ */
11
+ export class OperatorLifecycle extends PaymasterOperatorClient {
12
+ constructor(config) {
13
+ super(config);
14
+ }
15
+ // ===========================================
16
+ // 1. Setup Phase (Onboarding)
17
+ // ===========================================
18
+ /**
19
+ * Check if the account is ready to become an operator
20
+ * (e.g., has GToken, has ROLE_COMMUNITY, etc.)
21
+ */
22
+ async checkReadiness() {
23
+ const isOp = await this.isOperator(this.getAddress());
24
+ // For SuperPaymaster, balance is 'aPNTsBalance' (Collateral)
25
+ const details = await this.getOperatorDetails();
26
+ const balance = details.aPNTsBalance || 0n;
27
+ return {
28
+ isConfigured: isOp,
29
+ isActive: isOp, // Simplification
30
+ balance
31
+ };
32
+ }
33
+ /**
34
+ * One-click Setup: Register + Deposit + Deploy Node
35
+ * Wraps existing registerAsSuperPaymasterOperator or deployAndRegisterPaymasterV4
36
+ */
37
+ async setupNode(params, options) {
38
+ const hashes = [];
39
+ if (params.type === 'SUPER') {
40
+ const h = await this.registerAsSuperPaymasterOperator({
41
+ stakeAmount: params.stakeAmount,
42
+ depositAmount: params.depositAmount
43
+ }, options);
44
+ hashes.push(h);
45
+ // Fetch Token Address and Configure
46
+ const factory = await import('@aastar/core').then(m => m.xPNTsFactoryActions(this.xpntsFactory)(this.getStartPublicClient()));
47
+ const token = await factory.getTokenAddress({ community: this.getAddress() });
48
+ if (token && token !== '0x0000000000000000000000000000000000000000') {
49
+ const hConfig = await this.configureOperator(token, this.getAddress(), // Default treasury to self
50
+ parseEther('1'), // Default 1:1 rate
51
+ options);
52
+ hashes.push(hConfig);
53
+ }
54
+ }
55
+ else {
56
+ const result = await this.deployAndRegisterPaymasterV4({
57
+ stakeAmount: params.stakeAmount
58
+ }, options);
59
+ hashes.push(result.deployHash);
60
+ hashes.push(result.registerHash);
61
+ }
62
+ return hashes;
63
+ }
64
+ // ===========================================
65
+ // 2. Operational Phase (Config & Funds)
66
+ // ===========================================
67
+ // Inherits: addGasToken, configureOperator, depositCollateral from PaymasterOperatorClient
68
+ async getOperatorStats() {
69
+ return await this.getOperatorDetails();
70
+ }
71
+ // ===========================================
72
+ // 3. Exit Phase (Withdraw & Leave)
73
+ // ===========================================
74
+ /**
75
+ * Start the exit process: Unstake from Registry/SuperPaymaster and Unlock funds
76
+ */
77
+ async initiateExit(options) {
78
+ // 1. Unlock Stake from SuperPaymaster (if applicable)
79
+ return await super.initiateExit(options);
80
+ }
81
+ /**
82
+ * Finalize exit: Withdraw all funds (Collateral + Rewards)
83
+ */
84
+ async withdrawAllFunds(to, options) {
85
+ const recipient = to || this.getAddress();
86
+ const hashes = [];
87
+ // 1. Withdraw Collateral from SuperPaymaster (if any)
88
+ // Note: We need to know the balance to withdraw exact amount.
89
+ // For current L3 pattern, we assume the user tracks it or we fetch it.
90
+ const stats = await this.checkReadiness();
91
+ if (stats.balance > 0n) {
92
+ const hCol = await this.withdrawCollateral(recipient, stats.balance, options);
93
+ hashes.push(hCol);
94
+ }
95
+ // 2. Exit Role in Registry (Unstake GToken)
96
+ // This will fail if lock duration > 0 and not yet cooldown.
97
+ // Or it will initiate cooldown.
98
+ const client = this.getStartPublicClient();
99
+ const registry = registryActions(this.registryAddress); // Use local registry address
100
+ const registryWriter = registryActions(this.registryAddress)(this.client);
101
+ // Check if we have the role
102
+ // For Super Operator
103
+ const ROLE_PAYMASTER_SUPER = await registry(client).ROLE_PAYMASTER_SUPER();
104
+ const hasRole = await registry(client).hasRole({ user: this.getAddress(), roleId: ROLE_PAYMASTER_SUPER });
105
+ if (hasRole) {
106
+ const hExit = await registryWriter.exitRole({ roleId: ROLE_PAYMASTER_SUPER, account: options?.account });
107
+ hashes.push(hExit);
108
+ }
109
+ return hashes;
110
+ }
111
+ // Helper: Get GToken Balance
112
+ async getTokenBalance() {
113
+ if (!this.tokenAddress)
114
+ return 0n;
115
+ const token = tokenActions()(this.getStartPublicClient());
116
+ return await token.balanceOf({ token: this.tokenAddress, account: this.getAddress() });
117
+ }
118
+ }
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './PaymasterOperatorClient.js';
2
2
  export * from './ProtocolClient.js';
3
+ export * from './OperatorLifecycle.js';
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './PaymasterOperatorClient.js';
2
2
  export * from './ProtocolClient.js';
3
+ export * from './OperatorLifecycle.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aastar/operator",
3
- "version": "0.16.14",
3
+ "version": "0.16.16",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -19,7 +19,7 @@
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
21
  "viem": "2.43.3",
22
- "@aastar/core": "0.16.14"
22
+ "@aastar/core": "0.16.16"
23
23
  },
24
24
  "devDependencies": {
25
25
  "typescript": "5.7.2"