@aastar/sdk 0.16.8 → 0.16.12
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 +21 -0
- package/dist/clients/admin.d.ts +11 -0
- package/dist/clients/admin.js +20 -0
- package/dist/{sdk/src/clients → clients}/community.d.ts +4 -12
- package/dist/clients/community.js +300 -0
- package/dist/{sdk/src/clients → clients}/endUser.d.ts +5 -23
- package/dist/clients/endUser.js +298 -0
- package/dist/{sdk/src/clients → clients}/operator.d.ts +8 -38
- package/dist/{sdk/src/clients → clients}/operator.js +76 -114
- package/dist/errors/decoder.d.ts +6 -0
- package/dist/errors/decoder.js +44 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +21 -0
- package/dist/{sdk/src/utils → utils}/keys.d.ts +0 -12
- package/dist/{sdk/src/utils → utils}/keys.js +0 -7
- package/dist/{sdk/src/utils → utils}/roleData.js +28 -15
- package/dist/{sdk/src/utils → utils}/testScenarios.js +1 -1
- package/dist/{sdk/src/utils → utils}/userOp.js +3 -8
- package/package.json +11 -25
- package/dist/account/src/accounts/simple.d.ts +0 -18
- package/dist/account/src/accounts/simple.js +0 -49
- package/dist/account/src/eoa.d.ts +0 -10
- package/dist/account/src/eoa.js +0 -21
- package/dist/account/src/index.d.ts +0 -19
- package/dist/account/src/index.js +0 -49
- package/dist/core/src/abis/index.d.ts +0 -1126
- package/dist/core/src/abis/index.js +0 -91
- package/dist/core/src/actions/StateValidator.d.ts +0 -68
- package/dist/core/src/actions/StateValidator.js +0 -187
- package/dist/core/src/actions/account.d.ts +0 -55
- package/dist/core/src/actions/account.js +0 -133
- package/dist/core/src/actions/aggregator.d.ts +0 -17
- package/dist/core/src/actions/aggregator.js +0 -31
- package/dist/core/src/actions/dvt.d.ts +0 -30
- package/dist/core/src/actions/dvt.js +0 -41
- package/dist/core/src/actions/entryPoint.d.ts +0 -90
- package/dist/core/src/actions/entryPoint.js +0 -211
- package/dist/core/src/actions/factory.d.ts +0 -215
- package/dist/core/src/actions/factory.js +0 -442
- package/dist/core/src/actions/faucet.d.ts +0 -48
- package/dist/core/src/actions/faucet.js +0 -337
- package/dist/core/src/actions/gtokenExtended.d.ts +0 -39
- package/dist/core/src/actions/gtokenExtended.js +0 -115
- package/dist/core/src/actions/index.d.ts +0 -15
- package/dist/core/src/actions/index.js +0 -17
- package/dist/core/src/actions/paymasterV4.d.ts +0 -170
- package/dist/core/src/actions/paymasterV4.js +0 -334
- package/dist/core/src/actions/registry.d.ts +0 -246
- package/dist/core/src/actions/registry.js +0 -667
- package/dist/core/src/actions/reputation.d.ts +0 -129
- package/dist/core/src/actions/reputation.js +0 -281
- package/dist/core/src/actions/sbt.d.ts +0 -191
- package/dist/core/src/actions/sbt.js +0 -533
- package/dist/core/src/actions/staking.d.ts +0 -132
- package/dist/core/src/actions/staking.js +0 -330
- package/dist/core/src/actions/superPaymaster.d.ts +0 -237
- package/dist/core/src/actions/superPaymaster.js +0 -644
- package/dist/core/src/actions/tokens.d.ts +0 -229
- package/dist/core/src/actions/tokens.js +0 -415
- package/dist/core/src/branding.d.ts +0 -30
- package/dist/core/src/branding.js +0 -30
- package/dist/core/src/clients/BaseClient.d.ts +0 -25
- package/dist/core/src/clients/BaseClient.js +0 -66
- package/dist/core/src/clients/types.d.ts +0 -60
- package/dist/core/src/clients/types.js +0 -1
- package/dist/core/src/clients.d.ts +0 -5
- package/dist/core/src/clients.js +0 -11
- package/dist/core/src/communities.d.ts +0 -52
- package/dist/core/src/communities.js +0 -73
- package/dist/core/src/config/ContractConfigManager.d.ts +0 -20
- package/dist/core/src/config/ContractConfigManager.js +0 -48
- package/dist/core/src/constants.d.ts +0 -88
- package/dist/core/src/constants.js +0 -125
- package/dist/core/src/contract-addresses.d.ts +0 -110
- package/dist/core/src/contract-addresses.js +0 -99
- package/dist/core/src/contracts.d.ts +0 -424
- package/dist/core/src/contracts.js +0 -343
- package/dist/core/src/crypto/blsSigner.d.ts +0 -64
- package/dist/core/src/crypto/blsSigner.js +0 -98
- package/dist/core/src/crypto/index.d.ts +0 -1
- package/dist/core/src/crypto/index.js +0 -1
- package/dist/core/src/index.d.ts +0 -21
- package/dist/core/src/index.js +0 -21
- package/dist/core/src/networks.d.ts +0 -127
- package/dist/core/src/networks.js +0 -118
- package/dist/core/src/requirementChecker.d.ts +0 -38
- package/dist/core/src/requirementChecker.js +0 -139
- package/dist/core/src/roles.d.ts +0 -204
- package/dist/core/src/roles.js +0 -211
- package/dist/core/src/utils/validation.d.ts +0 -24
- package/dist/core/src/utils/validation.js +0 -56
- package/dist/dapp/src/index.d.ts +0 -3
- package/dist/dapp/src/index.js +0 -3
- package/dist/dapp/src/ui/hooks/useCreditScore.d.ts +0 -13
- package/dist/dapp/src/ui/hooks/useCreditScore.js +0 -32
- package/dist/dapp/src/ui/hooks/useSuperPaymaster.d.ts +0 -8
- package/dist/dapp/src/ui/hooks/useSuperPaymaster.js +0 -23
- package/dist/dapp/src/ui/index.d.ts +0 -4
- package/dist/dapp/src/ui/index.js +0 -17
- package/dist/identity/src/index.d.ts +0 -46
- package/dist/identity/src/index.js +0 -94
- package/dist/identity/src/mysbt.d.ts +0 -13
- package/dist/identity/src/mysbt.js +0 -37
- package/dist/paymaster/src/SuperPaymaster/index.d.ts +0 -44
- package/dist/paymaster/src/SuperPaymaster/index.js +0 -133
- package/dist/paymaster/src/V4/PaymasterClient.d.ts +0 -79
- package/dist/paymaster/src/V4/PaymasterClient.js +0 -315
- package/dist/paymaster/src/V4/PaymasterOperator.d.ts +0 -41
- package/dist/paymaster/src/V4/PaymasterOperator.js +0 -241
- package/dist/paymaster/src/V4/PaymasterUtils.d.ts +0 -55
- package/dist/paymaster/src/V4/PaymasterUtils.js +0 -124
- package/dist/paymaster/src/V4/SuperPaymasterClient.d.ts +0 -21
- package/dist/paymaster/src/V4/SuperPaymasterClient.js +0 -73
- package/dist/paymaster/src/V4/index.d.ts +0 -4
- package/dist/paymaster/src/V4/index.js +0 -4
- package/dist/paymaster/src/index.d.ts +0 -2
- package/dist/paymaster/src/index.js +0 -4
- package/dist/sdk/src/clients/admin.d.ts +0 -57
- package/dist/sdk/src/clients/admin.js +0 -105
- package/dist/sdk/src/clients/community.js +0 -244
- package/dist/sdk/src/clients/endUser.js +0 -388
- package/dist/sdk/src/errors/decoder.d.ts +0 -1
- package/dist/sdk/src/errors/decoder.js +0 -83
- package/dist/sdk/src/index.d.ts +0 -16
- package/dist/sdk/src/index.js +0 -20
- package/dist/tokens/src/index.d.ts +0 -56
- package/dist/tokens/src/index.js +0 -230
- package/examples/config.json +0 -1
- package/examples/regression_test.d.ts +0 -2
- package/examples/regression_test.d.ts.map +0 -1
- package/examples/regression_test.js +0 -89
- package/examples/regression_test.js.map +0 -1
- package/examples/regression_test.ts +0 -106
- package/scripts/v2_regression/00_validate_env.ts +0 -101
- package/scripts/v2_regression/01_setup_and_fund.ts +0 -132
- package/scripts/v2_regression/02_operator_onboarding.ts +0 -174
- package/scripts/v2_regression/03_community_registry.ts +0 -139
- package/scripts/v2_regression/04_enduser_flow.ts +0 -141
- package/scripts/v2_regression/05_admin_audit.ts +0 -157
- package/scripts/validate_env.ts +0 -112
- /package/dist/{sdk/src/clients → clients}/ExperimentClient.d.ts +0 -0
- /package/dist/{sdk/src/clients → clients}/ExperimentClient.js +0 -0
- /package/dist/{sdk/src/clients → clients}/ExperimentClient.test.d.ts +0 -0
- /package/dist/{sdk/src/clients → clients}/ExperimentClient.test.js +0 -0
- /package/dist/{sdk/src/clients → clients}/admin.test.d.ts +0 -0
- /package/dist/{sdk/src/clients → clients}/admin.test.js +0 -0
- /package/dist/{sdk/src/clients → clients}/clients.test.d.ts +0 -0
- /package/dist/{sdk/src/clients → clients}/clients.test.js +0 -0
- /package/dist/{sdk/src/clients → clients}/community.test.d.ts +0 -0
- /package/dist/{sdk/src/clients → clients}/community.test.js +0 -0
- /package/dist/{sdk/src/clients → clients}/endUser.test.d.ts +0 -0
- /package/dist/{sdk/src/clients → clients}/endUser.test.js +0 -0
- /package/dist/{sdk/src/clients → clients}/operator.test.d.ts +0 -0
- /package/dist/{sdk/src/clients → clients}/operator.test.js +0 -0
- /package/dist/{sdk/src/errors → errors}/AAStarError.d.ts +0 -0
- /package/dist/{sdk/src/errors → errors}/AAStarError.js +0 -0
- /package/dist/{sdk/src/errors → errors}/AAStarError.test.d.ts +0 -0
- /package/dist/{sdk/src/errors → errors}/AAStarError.test.js +0 -0
- /package/dist/{sdk/src/errors → errors}/decoder.test.d.ts +0 -0
- /package/dist/{sdk/src/errors → errors}/decoder.test.js +0 -0
- /package/dist/{sdk/src/node → node}/index.d.ts +0 -0
- /package/dist/{sdk/src/node → node}/index.js +0 -0
- /package/dist/{sdk/src/types → types}/result.d.ts +0 -0
- /package/dist/{sdk/src/types → types}/result.js +0 -0
- /package/dist/{sdk/src/utils → utils}/errorHandler.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/errorHandler.js +0 -0
- /package/dist/{sdk/src/utils → utils}/errorHandler.test.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/errorHandler.test.js +0 -0
- /package/dist/{sdk/src/utils → utils}/eventDecoder.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/eventDecoder.js +0 -0
- /package/dist/{sdk/src/utils → utils}/eventDecoder.test.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/eventDecoder.test.js +0 -0
- /package/dist/{sdk/src/utils → utils}/funding.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/funding.js +0 -0
- /package/dist/{sdk/src/utils → utils}/funding.test.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/funding.test.js +0 -0
- /package/dist/{sdk/src/utils → utils}/keys.test.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/keys.test.js +0 -0
- /package/dist/{sdk/src/utils → utils}/roleData.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/roleData.test.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/roleData.test.js +0 -0
- /package/dist/{sdk/src/utils → utils}/testScenarios.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/testScenarios.test.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/testScenarios.test.js +0 -0
- /package/dist/{sdk/src/utils → utils}/userOp.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/userOp.test.d.ts +0 -0
- /package/dist/{sdk/src/utils → utils}/userOp.test.js +0 -0
package/README.md
CHANGED
|
@@ -138,6 +138,27 @@ AAstar SDK 基于 **viem** 构建,确保轻量级和类型安全的交互。
|
|
|
138
138
|
|
|
139
139
|
---
|
|
140
140
|
|
|
141
|
+
## 📊 Gas Analytics & Reporting | Gas 分析与报表
|
|
142
|
+
The SDK includes a powerful **Gas Analytics Module** for analyzing Paymaster efficiency, tracking costs, and generating industry comparison reports.
|
|
143
|
+
SDK 包含一个强大的 **Gas 分析模块**,用于分析 Paymaster 效率、追踪成本并生成行业对比报告。
|
|
144
|
+
|
|
145
|
+
### Quick Start | 快速开始
|
|
146
|
+
Generate a real-time analysis of recent Sepolia transactions:
|
|
147
|
+
生成最近 Sepolia 交易的实时分析:
|
|
148
|
+
```bash
|
|
149
|
+
npx tsx packages/analytics/src/gas-analyzer-v4.ts
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Key Features | 核心功能
|
|
153
|
+
- **Double-Layer Analysis (双层分析)**: Intrinsic EVM Efficiency vs. Economic USD Costs
|
|
154
|
+
- **Industry Benchmarking (行业对标)**: Compare AAStar vs. Optimism, Alchemy, Pimlico
|
|
155
|
+
- **Profit Tracking (利润追踪)**: Transparent breakdown of Protocol Revenue & Profit
|
|
156
|
+
- **L2 Simulation (L2 模拟)**: Estimate savings for migrating UserOps to Optimism
|
|
157
|
+
|
|
158
|
+
👉 **[View Full Analytics Documentation | 查看完整分析文档](./packages/analytics/README.md)**
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
141
162
|
## 🤝 Contributing | 贡献
|
|
142
163
|
|
|
143
164
|
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Client, type Transport, type Chain, type Account, type PublicActions, type WalletActions, type Address } from 'viem';
|
|
2
|
+
import { type RegistryActions, type SuperPaymasterActions, type PaymasterActions, type StakingActions, type SBTActions, type DVTActions, type XPNTsFactoryActions, type AggregatorActions } from '@aastar/core';
|
|
3
|
+
export type AdminClient = Client<Transport, Chain, Account | undefined> & PublicActions<Transport, Chain, Account | undefined> & WalletActions<Chain, Account | undefined> & RegistryActions & SuperPaymasterActions & PaymasterActions & StakingActions & SBTActions & DVTActions & XPNTsFactoryActions & AggregatorActions;
|
|
4
|
+
export declare function createAdminClient({ chain, transport, account, addresses }: {
|
|
5
|
+
chain: Chain;
|
|
6
|
+
transport: Transport;
|
|
7
|
+
account?: Account;
|
|
8
|
+
addresses?: {
|
|
9
|
+
[key: string]: Address;
|
|
10
|
+
};
|
|
11
|
+
}): AdminClient;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createClient, publicActions, walletActions } from 'viem';
|
|
2
|
+
import { registryActions, superPaymasterActions, paymasterActions, stakingActions, sbtActions, dvtActions, xPNTsFactoryActions, aggregatorActions, CORE_ADDRESSES, TOKEN_ADDRESSES } from '@aastar/core';
|
|
3
|
+
const ADDRESS_PLACEHOLDER = '0x0000000000000000000000000000000000000000';
|
|
4
|
+
export function createAdminClient({ chain, transport, account, addresses }) {
|
|
5
|
+
const baseClient = createClient({ chain, transport, account })
|
|
6
|
+
.extend(publicActions)
|
|
7
|
+
.extend(walletActions);
|
|
8
|
+
const usedAddresses = { ...CORE_ADDRESSES, ...TOKEN_ADDRESSES, ...addresses };
|
|
9
|
+
const actions = {
|
|
10
|
+
...registryActions(usedAddresses.registry)(baseClient),
|
|
11
|
+
...superPaymasterActions(usedAddresses.superPaymaster)(baseClient),
|
|
12
|
+
...paymasterActions(usedAddresses.paymasterV4)(baseClient),
|
|
13
|
+
...stakingActions(usedAddresses.gTokenStaking)(baseClient),
|
|
14
|
+
...sbtActions(usedAddresses.mySBT)(baseClient),
|
|
15
|
+
...dvtActions(ADDRESS_PLACEHOLDER)(baseClient),
|
|
16
|
+
...xPNTsFactoryActions(usedAddresses.xPNTsFactory || '0x')(baseClient),
|
|
17
|
+
...aggregatorActions(ADDRESS_PLACEHOLDER)(baseClient),
|
|
18
|
+
};
|
|
19
|
+
return Object.assign(baseClient, actions);
|
|
20
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { type Client, type Transport, type Chain, type Account, type
|
|
2
|
-
import { type RegistryActions, type SBTActions
|
|
3
|
-
|
|
4
|
-
export type CommunityClient = Client<Transport, Chain, Account | undefined> & PublicActions<Transport, Chain, Account | undefined> & WalletActions<Chain, Account | undefined> & RegistryActions & SBTActions & ReputationActions & {
|
|
1
|
+
import { type Client, type Transport, type Chain, type Account, type Hex, type PublicActions, type WalletActions, type Address } from 'viem';
|
|
2
|
+
import { type RegistryActions, type SBTActions } from '@aastar/core';
|
|
3
|
+
export type CommunityClient = Client<Transport, Chain, Account | undefined> & PublicActions<Transport, Chain, Account | undefined> & WalletActions<Chain, Account | undefined> & RegistryActions & SBTActions & {
|
|
5
4
|
/**
|
|
6
5
|
* Query community registration status and token information
|
|
7
6
|
* Returns null if not registered, otherwise returns community details
|
|
@@ -26,16 +25,9 @@ export type CommunityClient = Client<Transport, Chain, Account | undefined> & Pu
|
|
|
26
25
|
description?: string;
|
|
27
26
|
logoURI?: string;
|
|
28
27
|
website?: string;
|
|
29
|
-
governance?: {
|
|
30
|
-
minStake?: bigint;
|
|
31
|
-
initialReputationRule?: boolean;
|
|
32
|
-
};
|
|
33
28
|
}) => Promise<{
|
|
34
29
|
tokenAddress: Address;
|
|
35
|
-
|
|
36
|
-
hash: Hash;
|
|
37
|
-
events: DecodedEvent[];
|
|
38
|
-
}[];
|
|
30
|
+
txs: Hex[];
|
|
39
31
|
}>;
|
|
40
32
|
};
|
|
41
33
|
export declare function createCommunityClient({ chain, transport, account, addresses }: {
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { createClient, publicActions, walletActions, erc20Abi } from 'viem';
|
|
2
|
+
import { registryActions, RegistryABI, sbtActions, CORE_ADDRESSES, TEST_TOKEN_ADDRESSES } from '@aastar/core';
|
|
3
|
+
import { RoleDataFactory, RoleIds } from '../utils/roleData.js';
|
|
4
|
+
export function createCommunityClient({ chain, transport, account, addresses }) {
|
|
5
|
+
const client = createClient({
|
|
6
|
+
chain,
|
|
7
|
+
transport,
|
|
8
|
+
account
|
|
9
|
+
})
|
|
10
|
+
.extend(publicActions)
|
|
11
|
+
.extend(walletActions);
|
|
12
|
+
const usedAddresses = { ...CORE_ADDRESSES, ...TEST_TOKEN_ADDRESSES, ...addresses };
|
|
13
|
+
const registryActionsObj = registryActions(usedAddresses.registry)(client);
|
|
14
|
+
const sbtActionsObj = sbtActions(usedAddresses.mySBT)(client);
|
|
15
|
+
const launch = async (args) => {
|
|
16
|
+
try {
|
|
17
|
+
console.log(`🚀 Launching community: ${args.name}`);
|
|
18
|
+
if (!account) {
|
|
19
|
+
throw new Error('Account is required for launch()');
|
|
20
|
+
}
|
|
21
|
+
// Generate unique community name with timestamp
|
|
22
|
+
const uniqueName = `${args.name}_${Date.now()}`;
|
|
23
|
+
console.log(` 📝 Unique name: ${uniqueName}`);
|
|
24
|
+
// Generate roleData using RoleDataFactory
|
|
25
|
+
const roleData = RoleDataFactory.community({
|
|
26
|
+
name: uniqueName,
|
|
27
|
+
ensName: '',
|
|
28
|
+
website: args.website || '',
|
|
29
|
+
description: args.description || '',
|
|
30
|
+
logoURI: args.logoURI || '',
|
|
31
|
+
stakeAmount: 0n
|
|
32
|
+
});
|
|
33
|
+
console.log(` ✅ RoleData generated:`, roleData);
|
|
34
|
+
console.log(` 📊 RoleData type:`, typeof roleData);
|
|
35
|
+
console.log(` 📏 RoleData length:`, roleData?.length);
|
|
36
|
+
// 1. Check if already has role
|
|
37
|
+
const hasRole = await client.readContract({
|
|
38
|
+
address: usedAddresses.registry,
|
|
39
|
+
abi: RegistryABI,
|
|
40
|
+
functionName: 'hasRole',
|
|
41
|
+
args: [RoleIds.COMMUNITY, account.address]
|
|
42
|
+
});
|
|
43
|
+
let registerTx;
|
|
44
|
+
if (hasRole) {
|
|
45
|
+
console.log(` ℹ️ Account already has COMMUNITY role. Skipping registration.`);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// 2. Check GToken Allowance and Balance
|
|
49
|
+
if (usedAddresses.gToken && usedAddresses.gTokenStaking) {
|
|
50
|
+
console.log(` 💰 Checking GToken allowance...`);
|
|
51
|
+
const balance = await client.readContract({
|
|
52
|
+
address: usedAddresses.gToken,
|
|
53
|
+
abi: erc20Abi,
|
|
54
|
+
functionName: 'balanceOf',
|
|
55
|
+
args: [account.address]
|
|
56
|
+
});
|
|
57
|
+
if (balance < 50000000000000000000n) { // 50 GT assumption, should ideally check minStake
|
|
58
|
+
console.warn(` ⚠️ Warning: Low GToken balance (${balance}). Registration may fail if minStake > balance.`);
|
|
59
|
+
}
|
|
60
|
+
const allowance = await client.readContract({
|
|
61
|
+
address: usedAddresses.gToken,
|
|
62
|
+
abi: erc20Abi,
|
|
63
|
+
functionName: 'allowance',
|
|
64
|
+
args: [account.address, usedAddresses.gTokenStaking]
|
|
65
|
+
});
|
|
66
|
+
if (allowance < 50000000000000000000n) {
|
|
67
|
+
console.log(` 🔓 Approving GToken for Staking...`);
|
|
68
|
+
const approveTx = await client.writeContract({
|
|
69
|
+
address: usedAddresses.gToken,
|
|
70
|
+
abi: erc20Abi,
|
|
71
|
+
functionName: 'approve',
|
|
72
|
+
args: [usedAddresses.gTokenStaking, 115792089237316195423570985008687907853269984665640564039457584007913129639935n], // MaxUint256
|
|
73
|
+
account: account
|
|
74
|
+
});
|
|
75
|
+
console.log(` ✅ Approved: ${approveTx}`);
|
|
76
|
+
await client.waitForTransactionReceipt({ hash: approveTx });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Register community role
|
|
80
|
+
console.log(` 📤 Registering community role...`);
|
|
81
|
+
try {
|
|
82
|
+
registerTx = await registryActionsObj.registerRole({
|
|
83
|
+
roleId: RoleIds.COMMUNITY,
|
|
84
|
+
user: account.address,
|
|
85
|
+
data: roleData,
|
|
86
|
+
account: account
|
|
87
|
+
});
|
|
88
|
+
console.log(` ✅ Community registered: ${registerTx}`);
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
// Check for RoleAlreadyGranted (just in case hasRole returned false but race condition or cache)
|
|
92
|
+
const isRoleError = e.message?.includes('RoleAlreadyGranted') ||
|
|
93
|
+
e.cause?.data?.errorName === 'RoleAlreadyGranted' ||
|
|
94
|
+
e.name === 'RoleAlreadyGranted' ||
|
|
95
|
+
e.name === 'RoleAlreadyGranted';
|
|
96
|
+
if (isRoleError) {
|
|
97
|
+
console.log(` ℹ️ Role already granted (caught in tx). Skipping.`);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
throw e;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Deploy xPNTs token if factory is available
|
|
105
|
+
let tokenAddress = '0x0000000000000000000000000000000000000000';
|
|
106
|
+
const txs = [];
|
|
107
|
+
if (registerTx)
|
|
108
|
+
txs.push(registerTx);
|
|
109
|
+
if (usedAddresses.xPNTsFactory) {
|
|
110
|
+
if (!client.account) {
|
|
111
|
+
throw new Error("Client account is required for token deployment");
|
|
112
|
+
}
|
|
113
|
+
// ABI from xPNTsFactory.sol
|
|
114
|
+
const factoryAbi = [
|
|
115
|
+
{
|
|
116
|
+
type: 'function',
|
|
117
|
+
name: 'deployxPNTsToken',
|
|
118
|
+
inputs: [
|
|
119
|
+
{ name: 'name', type: 'string' },
|
|
120
|
+
{ name: 'symbol', type: 'string' },
|
|
121
|
+
{ name: 'communityName', type: 'string' },
|
|
122
|
+
{ name: 'communityENS', type: 'string' },
|
|
123
|
+
{ name: 'exchangeRate', type: 'uint256' },
|
|
124
|
+
{ name: 'paymasterAOA', type: 'address' }
|
|
125
|
+
],
|
|
126
|
+
outputs: [{ name: 'token', type: 'address' }],
|
|
127
|
+
stateMutability: 'nonpayable'
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
type: 'function',
|
|
131
|
+
name: 'getTokenAddress',
|
|
132
|
+
inputs: [{ name: 'community', type: 'address' }],
|
|
133
|
+
outputs: [{ name: 'token', type: 'address' }],
|
|
134
|
+
stateMutability: 'view'
|
|
135
|
+
}
|
|
136
|
+
];
|
|
137
|
+
// 1. Check if token already exists
|
|
138
|
+
try {
|
|
139
|
+
const existingToken = await client.readContract({
|
|
140
|
+
address: usedAddresses.xPNTsFactory,
|
|
141
|
+
abi: factoryAbi,
|
|
142
|
+
functionName: 'getTokenAddress',
|
|
143
|
+
args: [account.address]
|
|
144
|
+
});
|
|
145
|
+
if (existingToken && existingToken !== '0x0000000000000000000000000000000000000000') {
|
|
146
|
+
console.log(` ℹ️ Found existing token at ${existingToken}`);
|
|
147
|
+
tokenAddress = existingToken;
|
|
148
|
+
// Return early or continue? Logic expects result.
|
|
149
|
+
// If we found it, we don't need to deploy.
|
|
150
|
+
return { tokenAddress, txs };
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch (e) {
|
|
154
|
+
console.warn(` ⚠️ Failed to check for existing token:`, e);
|
|
155
|
+
}
|
|
156
|
+
console.log(` 🏭 Deploying Token via Factory: ${usedAddresses.xPNTsFactory}`);
|
|
157
|
+
try {
|
|
158
|
+
// deployxPNTsToken(name, symbol, communityName, communityENS, exchangeRate, paymasterAOA)
|
|
159
|
+
const { request } = await client.simulateContract({
|
|
160
|
+
address: usedAddresses.xPNTsFactory,
|
|
161
|
+
abi: factoryAbi,
|
|
162
|
+
functionName: 'deployxPNTsToken',
|
|
163
|
+
args: [
|
|
164
|
+
args.tokenName,
|
|
165
|
+
args.tokenSymbol,
|
|
166
|
+
args.name, // communityName
|
|
167
|
+
args.website || '', // communityENS (mapping website to ENS param for now)
|
|
168
|
+
1000000000000000000n, // exchangeRate 1e18 (1:1)
|
|
169
|
+
'0x0000000000000000000000000000000000000000' // paymasterAOA (optional)
|
|
170
|
+
],
|
|
171
|
+
account: client.account
|
|
172
|
+
});
|
|
173
|
+
const deployTx = await client.writeContract(request);
|
|
174
|
+
console.log(` 📤 Deploy Token Tx: ${deployTx}`);
|
|
175
|
+
txs.push(deployTx);
|
|
176
|
+
const receipt = await client.waitForTransactionReceipt({ hash: deployTx });
|
|
177
|
+
// After deployment, fetch the address again
|
|
178
|
+
const newTokenAddress = await client.readContract({
|
|
179
|
+
address: usedAddresses.xPNTsFactory,
|
|
180
|
+
abi: factoryAbi,
|
|
181
|
+
functionName: 'getTokenAddress',
|
|
182
|
+
args: [account.address]
|
|
183
|
+
});
|
|
184
|
+
if (newTokenAddress) {
|
|
185
|
+
tokenAddress = newTokenAddress;
|
|
186
|
+
console.log(` 🪙 Token Deployed: ${tokenAddress}`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
catch (deployError) {
|
|
190
|
+
console.warn(' ⚠️ Failed to deploy token, but community registered:', deployError);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return { tokenAddress, txs };
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
console.error('❌ Error in launch():', error);
|
|
197
|
+
// 检查是否是 RoleAlreadyGranted 错误
|
|
198
|
+
const errorMessage = error.message || '';
|
|
199
|
+
const errorData = error.data?.errorName || '';
|
|
200
|
+
const errorString = JSON.stringify(error);
|
|
201
|
+
if (errorMessage.includes('RoleAlreadyGranted') ||
|
|
202
|
+
errorData === 'RoleAlreadyGranted' ||
|
|
203
|
+
errorString.includes('RoleAlreadyGranted')) {
|
|
204
|
+
throw new Error(`Account ${account?.address || 'unknown'} already has COMMUNITY role. Please use a different account or exit the role first.`);
|
|
205
|
+
}
|
|
206
|
+
// 检查其他常见错误
|
|
207
|
+
if (errorMessage.includes('InsufficientStake')) {
|
|
208
|
+
throw new Error('Insufficient stake. Please ensure you have enough GToken staked.');
|
|
209
|
+
}
|
|
210
|
+
if (errorMessage.includes('RoleNotConfigured')) {
|
|
211
|
+
throw new Error('COMMUNITY role is not configured in the Registry contract.');
|
|
212
|
+
}
|
|
213
|
+
// 重新抛出原始错误
|
|
214
|
+
throw error;
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
// State query method - check before operations
|
|
218
|
+
const getCommunityInfo = async (accountAddress) => {
|
|
219
|
+
try {
|
|
220
|
+
// 1. Check if account has COMMUNITY role
|
|
221
|
+
const hasRole = await client.readContract({
|
|
222
|
+
address: usedAddresses.registry,
|
|
223
|
+
abi: RegistryABI,
|
|
224
|
+
functionName: 'hasRole',
|
|
225
|
+
args: [RoleIds.COMMUNITY, accountAddress]
|
|
226
|
+
});
|
|
227
|
+
if (!hasRole) {
|
|
228
|
+
return {
|
|
229
|
+
hasRole: false,
|
|
230
|
+
tokenAddress: null,
|
|
231
|
+
communityData: null
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
// 2. Get token address from factory
|
|
235
|
+
const factoryAbi = [
|
|
236
|
+
{
|
|
237
|
+
inputs: [{ name: 'community', type: 'address' }],
|
|
238
|
+
name: 'getTokenAddress',
|
|
239
|
+
outputs: [{ name: '', type: 'address' }],
|
|
240
|
+
stateMutability: 'view',
|
|
241
|
+
type: 'function'
|
|
242
|
+
}
|
|
243
|
+
];
|
|
244
|
+
const tokenAddress = await client.readContract({
|
|
245
|
+
address: usedAddresses.xPNTsFactory,
|
|
246
|
+
abi: factoryAbi,
|
|
247
|
+
functionName: 'getTokenAddress',
|
|
248
|
+
args: [accountAddress]
|
|
249
|
+
});
|
|
250
|
+
// 3. Get community metadata from Registry
|
|
251
|
+
const metadata = await client.readContract({
|
|
252
|
+
address: usedAddresses.registry,
|
|
253
|
+
abi: RegistryABI,
|
|
254
|
+
functionName: 'roleMetadata',
|
|
255
|
+
args: [RoleIds.COMMUNITY, accountAddress]
|
|
256
|
+
});
|
|
257
|
+
let communityData = {
|
|
258
|
+
name: 'Community',
|
|
259
|
+
ensName: '',
|
|
260
|
+
website: '',
|
|
261
|
+
description: '',
|
|
262
|
+
logoURI: ''
|
|
263
|
+
};
|
|
264
|
+
if (metadata && metadata !== '0x') {
|
|
265
|
+
try {
|
|
266
|
+
// RoleMetadata is encoded as CommunityRoleData struct:
|
|
267
|
+
// (string name, string ensName, string website, string description, string logoURI, uint256 stakeAmount)
|
|
268
|
+
const decoded = RoleDataFactory.decodeCommunity(metadata);
|
|
269
|
+
communityData = {
|
|
270
|
+
name: decoded.name || 'Community',
|
|
271
|
+
ensName: decoded.ensName || '',
|
|
272
|
+
website: decoded.website || '',
|
|
273
|
+
description: decoded.description || '',
|
|
274
|
+
logoURI: decoded.logoURI || ''
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
catch (e) {
|
|
278
|
+
console.warn(' ⚠️ Failed to decode community metadata:', e);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return {
|
|
282
|
+
hasRole: true,
|
|
283
|
+
tokenAddress: (tokenAddress && tokenAddress !== '0x0000000000000000000000000000000000000000') ? tokenAddress : null,
|
|
284
|
+
communityData: (metadata && metadata !== '0x') ? communityData : null
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
console.error('Error fetching community info:', error);
|
|
289
|
+
return {
|
|
290
|
+
hasRole: false,
|
|
291
|
+
tokenAddress: null,
|
|
292
|
+
communityData: null
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
return Object.assign(client, registryActionsObj, sbtActionsObj, {
|
|
297
|
+
launch,
|
|
298
|
+
getCommunityInfo
|
|
299
|
+
});
|
|
300
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type Client, type Transport, type Chain, type Account, type PublicActions, type WalletActions, type Address, type Hex, type Hash } from 'viem';
|
|
2
|
-
import { type RegistryActions, type SBTActions, type SuperPaymasterActions, type
|
|
3
|
-
|
|
4
|
-
export type EndUserClient = Client<Transport, Chain, Account | undefined> & PublicActions<Transport, Chain, Account | undefined> & WalletActions<Chain, Account | undefined> & RegistryActions & SBTActions & SuperPaymasterActions & PaymasterV4Actions & {
|
|
2
|
+
import { type RegistryActions, type SBTActions, type SuperPaymasterActions, type PaymasterActions } from '@aastar/core';
|
|
3
|
+
export type EndUserClient = Client<Transport, Chain, Account | undefined> & PublicActions<Transport, Chain, Account | undefined> & WalletActions<Chain, Account | undefined> & RegistryActions & SBTActions & SuperPaymasterActions & PaymasterActions & {
|
|
5
4
|
/**
|
|
6
5
|
* High-level API: Onboard user to community with automatic funding
|
|
7
6
|
*/
|
|
@@ -10,8 +9,7 @@ export type EndUserClient = Client<Transport, Chain, Account | undefined> & Publ
|
|
|
10
9
|
roleId: Hex;
|
|
11
10
|
roleData: Hex;
|
|
12
11
|
}) => Promise<{
|
|
13
|
-
|
|
14
|
-
events: DecodedEvent[];
|
|
12
|
+
tx: Hash;
|
|
15
13
|
sbtId: bigint;
|
|
16
14
|
}>;
|
|
17
15
|
/**
|
|
@@ -24,8 +22,7 @@ export type EndUserClient = Client<Transport, Chain, Account | undefined> & Publ
|
|
|
24
22
|
roleId: Hex;
|
|
25
23
|
roleData?: Hex;
|
|
26
24
|
}) => Promise<{
|
|
27
|
-
|
|
28
|
-
events: DecodedEvent[];
|
|
25
|
+
tx: Hash;
|
|
29
26
|
sbtId: bigint;
|
|
30
27
|
initialCredit: bigint;
|
|
31
28
|
}>;
|
|
@@ -37,22 +34,7 @@ export type EndUserClient = Client<Transport, Chain, Account | undefined> & Publ
|
|
|
37
34
|
data: Hex;
|
|
38
35
|
value?: bigint;
|
|
39
36
|
operator: Address;
|
|
40
|
-
}) => Promise<
|
|
41
|
-
hash: Hash;
|
|
42
|
-
events: DecodedEvent[];
|
|
43
|
-
}>;
|
|
44
|
-
/**
|
|
45
|
-
* Executes a batch of gasless transactions via SuperPaymaster.
|
|
46
|
-
*/
|
|
47
|
-
executeGaslessBatch: (args: {
|
|
48
|
-
targets: Address[];
|
|
49
|
-
datas: Hex[];
|
|
50
|
-
values?: bigint[];
|
|
51
|
-
operator: Address;
|
|
52
|
-
}) => Promise<{
|
|
53
|
-
hash: Hash;
|
|
54
|
-
events: DecodedEvent[];
|
|
55
|
-
}>;
|
|
37
|
+
}) => Promise<Hash>;
|
|
56
38
|
/**
|
|
57
39
|
* Check if the user meets the requirements to join a community (stake, sbt, etc.)
|
|
58
40
|
*/
|