@aastar/enduser 0.16.16 → 0.16.18

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.
@@ -30,6 +30,18 @@ export declare class CommunityClient extends BaseClient {
30
30
  * 3. Linking the Token to the Community in Registry
31
31
  */
32
32
  createCommunityToken(params: CreateCommunityParams, options?: TransactionOptions): Promise<Hash>;
33
+ /**
34
+ * Get Community Details (Decodes Role Metadata)
35
+ * @param communityAddress - The address of the community manager (defaults to self)
36
+ */
37
+ getCommunityInfo(communityAddress?: Address): Promise<{
38
+ name: string;
39
+ ensName: string;
40
+ website: string;
41
+ description: string;
42
+ logoURI: string;
43
+ stakeAmount: bigint;
44
+ }>;
33
45
  /**
34
46
  * Register self as a Community Manager.
35
47
  * This method handles all necessary steps:
@@ -45,6 +45,48 @@ export class CommunityClient extends BaseClient {
45
45
  throw error;
46
46
  }
47
47
  }
48
+ /**
49
+ * Get Community Details (Decodes Role Metadata)
50
+ * @param communityAddress - The address of the community manager (defaults to self)
51
+ */
52
+ async getCommunityInfo(communityAddress) {
53
+ try {
54
+ const target = communityAddress || this.getAddress();
55
+ const registryAddr = this.requireRegistry();
56
+ const registry = registryActions(registryAddr);
57
+ const publicClient = this.getStartPublicClient();
58
+ // 1. Get Role ID
59
+ const API_ROLE_COMMUNITY = await registry(publicClient).ROLE_COMMUNITY();
60
+ // 2. Fetch Metadata (Hex)
61
+ const metadataHex = await registry(publicClient).roleMetadata({
62
+ roleId: API_ROLE_COMMUNITY,
63
+ user: target
64
+ });
65
+ if (!metadataHex || metadataHex === '0x') {
66
+ throw new Error('No metadata found for this community');
67
+ }
68
+ // 3. Decode
69
+ // struct CommunityRoleData { string name; string ensName; string website; string description; string logoURI; uint256 stakeAmount; }
70
+ let dataToDecode = metadataHex;
71
+ // Check for common 'bytes' or 'tuple' wrapper offset (0x20)
72
+ if (metadataHex.startsWith('0x0000000000000000000000000000000000000000000000000000000000000020')) {
73
+ dataToDecode = `0x${metadataHex.slice(66)}`;
74
+ }
75
+ const { decodeAbiParameters, parseAbiParameters } = await import('viem');
76
+ const [name, ensName, website, description, logoURI, stakeAmount] = decodeAbiParameters(parseAbiParameters('string, string, string, string, string, uint256'), dataToDecode);
77
+ return {
78
+ name,
79
+ ensName,
80
+ website,
81
+ description,
82
+ logoURI,
83
+ stakeAmount
84
+ };
85
+ }
86
+ catch (error) {
87
+ throw error;
88
+ }
89
+ }
48
90
  /**
49
91
  * Register self as a Community Manager.
50
92
  * This method handles all necessary steps:
@@ -19,6 +19,25 @@ export declare class UserClient extends BaseClient {
19
19
  gTokenAddress?: Address;
20
20
  bundlerClient?: any;
21
21
  constructor(config: UserClientConfig);
22
+ /**
23
+ * Deploy a new Smart Account (Supports multiple factory types)
24
+ * Static helper to facilitate onboarding before instantiating the UserClient.
25
+ *
26
+ * @param client - WalletClient to sign the deployment transaction
27
+ * @param params - Deployment parameters
28
+ * @returns Object containing the deployed account address and transaction hash
29
+ */
30
+ static deployAccount(client: any, params: {
31
+ owner: Address;
32
+ salt?: bigint;
33
+ factoryAddress?: Address;
34
+ publicClient?: any;
35
+ accountType?: 'simple' | 'kernel' | 'safe' | string;
36
+ customAbi?: any;
37
+ }): Promise<{
38
+ accountAddress: Address;
39
+ hash: Hash;
40
+ }>;
22
41
  /**
23
42
  * Get the nonce of the account from EntryPoint (more reliable for 4337)
24
43
  */
@@ -20,6 +20,45 @@ export class UserClient extends BaseClient {
20
20
  this.registryAddress = config.registryAddress;
21
21
  this.gTokenAddress = config.gTokenAddress;
22
22
  }
23
+ /**
24
+ * Deploy a new Smart Account (Supports multiple factory types)
25
+ * Static helper to facilitate onboarding before instantiating the UserClient.
26
+ *
27
+ * @param client - WalletClient to sign the deployment transaction
28
+ * @param params - Deployment parameters
29
+ * @returns Object containing the deployed account address and transaction hash
30
+ */
31
+ static async deployAccount(client, params) {
32
+ const { accountFactoryActions, SimpleAccountFactoryABI } = await import('@aastar/core');
33
+ // 1. Determine Factory ABI (Ensure it's the raw ABI array)
34
+ let abi = params.customAbi || (SimpleAccountFactoryABI?.abi || SimpleAccountFactoryABI);
35
+ // In the future, we can add more built-in ABIs here based on accountType
36
+ // if (params.accountType === 'kernel') abi = KernelFactoryABI;
37
+ const factoryAddr = params.factoryAddress || '0x9406Cc6185a346906296840746125a0E44976454'; // Default v0.7 Factory
38
+ const salt = params.salt || 0n;
39
+ // Use publicClient for reading if provided, otherwise fallback to client (which might be a Full Client)
40
+ const readClient = params.publicClient || client;
41
+ // Use the generic actions with the selected ABI
42
+ const factoryRead = accountFactoryActions(factoryAddr, abi)(readClient);
43
+ const factoryWrite = accountFactoryActions(factoryAddr, abi)(client);
44
+ // 1. Predict Address
45
+ const accountAddress = await factoryRead.getAddress({
46
+ owner: params.owner,
47
+ salt
48
+ });
49
+ // 2. Deploy
50
+ try {
51
+ const hash = await factoryWrite.createAccount({
52
+ owner: params.owner,
53
+ salt,
54
+ account: client.account
55
+ });
56
+ return { accountAddress, hash };
57
+ }
58
+ catch (error) {
59
+ throw error;
60
+ }
61
+ }
23
62
  // ========================================
24
63
  // 1. 账户基本操作 (基于 L1 simpleAccountActions)
25
64
  // ========================================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aastar/enduser",
3
- "version": "0.16.16",
3
+ "version": "0.16.18",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -20,7 +20,7 @@
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
22
  "viem": "2.43.3",
23
- "@aastar/core": "0.16.16"
23
+ "@aastar/core": "0.16.18"
24
24
  },
25
25
  "devDependencies": {
26
26
  "typescript": "5.7.2",