@aastar/dapp 0.16.7

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 (108) hide show
  1. package/LICENSE +21 -0
  2. package/dist/core/src/abis/BLSAggregator.json +686 -0
  3. package/dist/core/src/abis/BLSValidator.json +42 -0
  4. package/dist/core/src/abis/DVTValidator.json +368 -0
  5. package/dist/core/src/abis/EntryPoint.json +1382 -0
  6. package/dist/core/src/abis/GToken.json +513 -0
  7. package/dist/core/src/abis/GTokenStaking.json +949 -0
  8. package/dist/core/src/abis/MySBT.json +1518 -0
  9. package/dist/core/src/abis/Paymaster.json +1143 -0
  10. package/dist/core/src/abis/PaymasterFactory.json +640 -0
  11. package/dist/core/src/abis/Registry.json +1942 -0
  12. package/dist/core/src/abis/ReputationSystem.json +699 -0
  13. package/dist/core/src/abis/SimpleAccount.json +560 -0
  14. package/dist/core/src/abis/SimpleAccountFactory.json +111 -0
  15. package/dist/core/src/abis/SuperPaymaster.json +1781 -0
  16. package/dist/core/src/abis/index.d.ts +1126 -0
  17. package/dist/core/src/abis/index.js +91 -0
  18. package/dist/core/src/abis/xPNTsFactory.json +718 -0
  19. package/dist/core/src/abis/xPNTsToken.json +1280 -0
  20. package/dist/core/src/actions/StateValidator.d.ts +68 -0
  21. package/dist/core/src/actions/StateValidator.js +187 -0
  22. package/dist/core/src/actions/account.d.ts +55 -0
  23. package/dist/core/src/actions/account.js +133 -0
  24. package/dist/core/src/actions/aggregator.d.ts +17 -0
  25. package/dist/core/src/actions/aggregator.js +31 -0
  26. package/dist/core/src/actions/dvt.d.ts +30 -0
  27. package/dist/core/src/actions/dvt.js +41 -0
  28. package/dist/core/src/actions/entryPoint.d.ts +90 -0
  29. package/dist/core/src/actions/entryPoint.js +211 -0
  30. package/dist/core/src/actions/factory.d.ts +215 -0
  31. package/dist/core/src/actions/factory.js +442 -0
  32. package/dist/core/src/actions/faucet.d.ts +48 -0
  33. package/dist/core/src/actions/faucet.js +337 -0
  34. package/dist/core/src/actions/gtokenExtended.d.ts +39 -0
  35. package/dist/core/src/actions/gtokenExtended.js +115 -0
  36. package/dist/core/src/actions/index.d.ts +15 -0
  37. package/dist/core/src/actions/index.js +17 -0
  38. package/dist/core/src/actions/paymasterV4.d.ts +170 -0
  39. package/dist/core/src/actions/paymasterV4.js +334 -0
  40. package/dist/core/src/actions/registry.d.ts +246 -0
  41. package/dist/core/src/actions/registry.js +667 -0
  42. package/dist/core/src/actions/reputation.d.ts +129 -0
  43. package/dist/core/src/actions/reputation.js +281 -0
  44. package/dist/core/src/actions/sbt.d.ts +191 -0
  45. package/dist/core/src/actions/sbt.js +533 -0
  46. package/dist/core/src/actions/staking.d.ts +132 -0
  47. package/dist/core/src/actions/staking.js +330 -0
  48. package/dist/core/src/actions/superPaymaster.d.ts +237 -0
  49. package/dist/core/src/actions/superPaymaster.js +644 -0
  50. package/dist/core/src/actions/tokens.d.ts +229 -0
  51. package/dist/core/src/actions/tokens.js +415 -0
  52. package/dist/core/src/branding.d.ts +30 -0
  53. package/dist/core/src/branding.js +30 -0
  54. package/dist/core/src/clients/BaseClient.d.ts +25 -0
  55. package/dist/core/src/clients/BaseClient.js +66 -0
  56. package/dist/core/src/clients/types.d.ts +60 -0
  57. package/dist/core/src/clients/types.js +1 -0
  58. package/dist/core/src/clients.d.ts +5 -0
  59. package/dist/core/src/clients.js +11 -0
  60. package/dist/core/src/communities.d.ts +52 -0
  61. package/dist/core/src/communities.js +73 -0
  62. package/dist/core/src/config/ContractConfigManager.d.ts +20 -0
  63. package/dist/core/src/config/ContractConfigManager.js +48 -0
  64. package/dist/core/src/constants.d.ts +88 -0
  65. package/dist/core/src/constants.js +125 -0
  66. package/dist/core/src/contract-addresses.d.ts +110 -0
  67. package/dist/core/src/contract-addresses.js +99 -0
  68. package/dist/core/src/contracts.d.ts +424 -0
  69. package/dist/core/src/contracts.js +343 -0
  70. package/dist/core/src/crypto/blsSigner.d.ts +64 -0
  71. package/dist/core/src/crypto/blsSigner.js +98 -0
  72. package/dist/core/src/crypto/index.d.ts +1 -0
  73. package/dist/core/src/crypto/index.js +1 -0
  74. package/dist/core/src/index.d.ts +21 -0
  75. package/dist/core/src/index.js +21 -0
  76. package/dist/core/src/networks.d.ts +127 -0
  77. package/dist/core/src/networks.js +118 -0
  78. package/dist/core/src/requirementChecker.d.ts +38 -0
  79. package/dist/core/src/requirementChecker.js +139 -0
  80. package/dist/core/src/roles.d.ts +204 -0
  81. package/dist/core/src/roles.js +211 -0
  82. package/dist/core/src/utils/validation.d.ts +24 -0
  83. package/dist/core/src/utils/validation.js +56 -0
  84. package/dist/dapp/src/index.d.ts +3 -0
  85. package/dist/dapp/src/index.js +3 -0
  86. package/dist/dapp/src/ui/components/EvaluationPanel.d.ts +11 -0
  87. package/dist/dapp/src/ui/components/EvaluationPanel.js +37 -0
  88. package/dist/dapp/src/ui/hooks/useCreditScore.d.ts +13 -0
  89. package/dist/dapp/src/ui/hooks/useCreditScore.js +32 -0
  90. package/dist/dapp/src/ui/hooks/useSuperPaymaster.d.ts +8 -0
  91. package/dist/dapp/src/ui/hooks/useSuperPaymaster.js +23 -0
  92. package/dist/dapp/src/ui/index.d.ts +4 -0
  93. package/dist/dapp/src/ui/index.js +17 -0
  94. package/dist/paymaster/src/SuperPaymaster/index.d.ts +44 -0
  95. package/dist/paymaster/src/SuperPaymaster/index.js +133 -0
  96. package/dist/paymaster/src/V4/PaymasterClient.d.ts +79 -0
  97. package/dist/paymaster/src/V4/PaymasterClient.js +315 -0
  98. package/dist/paymaster/src/V4/PaymasterOperator.d.ts +41 -0
  99. package/dist/paymaster/src/V4/PaymasterOperator.js +241 -0
  100. package/dist/paymaster/src/V4/PaymasterUtils.d.ts +55 -0
  101. package/dist/paymaster/src/V4/PaymasterUtils.js +124 -0
  102. package/dist/paymaster/src/V4/SuperPaymasterClient.d.ts +21 -0
  103. package/dist/paymaster/src/V4/SuperPaymasterClient.js +73 -0
  104. package/dist/paymaster/src/V4/index.d.ts +4 -0
  105. package/dist/paymaster/src/V4/index.js +4 -0
  106. package/dist/paymaster/src/index.d.ts +2 -0
  107. package/dist/paymaster/src/index.js +4 -0
  108. package/package.json +31 -0
@@ -0,0 +1,211 @@
1
+ /**
2
+ * Role constants and utilities for AAstar SDK
3
+ * @remarks
4
+ * All role hashes and configurations match exactly with Registry.sol v3.0.0
5
+ *
6
+ * **Source**: /contracts/src/core/Registry.sol
7
+ */
8
+ import { keccak256, toHex } from 'viem';
9
+ // ========== Role Hash Constants (from Registry.sol lines 32-38) ==========
10
+ /**
11
+ * Default Admin Role (OpenZeppelin AccessControl)
12
+ * @remarks
13
+ * - **Description**: Highest privilege, can grant/revoke all roles
14
+ * - **Permission**: Protocol governance only
15
+ * - **Source**: OpenZeppelin AccessControl DEFAULT_ADMIN_ROLE
16
+ */
17
+ export const DEFAULT_ADMIN_ROLE = '0x0000000000000000000000000000000000000000000000000000000000000000';
18
+ /**
19
+ * Community Role
20
+ * @remarks
21
+ * - **Description**: Community administrator, can issue xPNTs, configure SBT rules
22
+ * - **Permission**: Community-level governance
23
+ * - **Requirement**: minStake: 30 GT, entryBurn: 3 GT (line 99)
24
+ * - **Exit Fee**: 5% (500 basis points), min 1 GT
25
+ * - **Lock Duration**: 30 days
26
+ * - **Source**: Registry.sol line 32: ROLE_COMMUNITY = keccak256("COMMUNITY")
27
+ */
28
+ export const ROLE_COMMUNITY = keccak256(toHex('COMMUNITY'));
29
+ /**
30
+ * End User Role
31
+ * @remarks
32
+ * - **Description**: Community member, can participate and use gasless transactions
33
+ * - **Permission**: Basic user level
34
+ * - **Requirement**: minStake: 0.3 GT, entryBurn: 0.05 GT (line 100)
35
+ * - **Additional Requirement**: Must hold MySBT from community
36
+ * - **Exit Fee**: 10% (1000 basis points), min 0.05 GT
37
+ * - **Lock Duration**: 7 days
38
+ * - **Source**: Registry.sol line 33: ROLE_ENDUSER = keccak256("ENDUSER")
39
+ */
40
+ export const ROLE_ENDUSER = keccak256(toHex('ENDUSER'));
41
+ /**
42
+ * Paymaster AOA Role (Account Ownership Authentication)
43
+ * @remarks
44
+ * - **Description**: Basic Paymaster node operator with account-based auth
45
+ * - **Permission**: Infrastructure operator
46
+ * - **Requirement**: minStake: 30 GT, entryBurn: 3 GT (line 92)
47
+ * - **Exit Fee**: 10% (1000 basis points), min 1 GT
48
+ * - **Lock Duration**: 30 days
49
+ * - **Source**: Registry.sol line 34: ROLE_PAYMASTER_AOA = keccak256("PAYMASTER_AOA")
50
+ */
51
+ export const ROLE_PAYMASTER_AOA = keccak256(toHex('PAYMASTER_AOA'));
52
+ /**
53
+ * Paymaster Super Role
54
+ * @remarks
55
+ * - **Description**: Advanced Paymaster operator, can use SuperPaymaster with aPNTs collateral
56
+ * - **Permission**: Infrastructure operator (higher tier)
57
+ * - **Requirement**: minStake: 50 GT, entryBurn: 5 GT (line 93)
58
+ * - **Additional Requirement**: aPNTs collateral in SuperPaymaster contract
59
+ * - **Exit Fee**: 10% (1000 basis points), min 2 GT
60
+ * - **Lock Duration**: 30 days
61
+ * - **Source**: Registry.sol line 35: ROLE_PAYMASTER_SUPER = keccak256("PAYMASTER_SUPER")
62
+ */
63
+ export const ROLE_PAYMASTER_SUPER = keccak256(toHex('PAYMASTER_SUPER'));
64
+ /**
65
+ * DVT Role (Distributed Validator Technology)
66
+ * @remarks
67
+ * - **Description**: DVT node operator for consensus validation
68
+ * - **Permission**: Infrastructure operator
69
+ * - **Requirement**: minStake: 30 GT, entryBurn: 3 GT (line 94)
70
+ * - **Exit Fee**: 10% (1000 basis points), min 1 GT
71
+ * - **Lock Duration**: 30 days
72
+ * - **Source**: Registry.sol line 36: ROLE_DVT = keccak256("DVT")
73
+ */
74
+ export const ROLE_DVT = keccak256(toHex('DVT'));
75
+ /**
76
+ * ANODE Role (Anonymous Node)
77
+ * @remarks
78
+ * - **Description**: Anonymous infrastructure node operator
79
+ * - **Permission**: Infrastructure operator
80
+ * - **Requirement**: minStake: 20 GT, entryBurn: 2 GT (line 95)
81
+ * - **Exit Fee**: 10% (1000 basis points), min 1 GT
82
+ * - **Lock Duration**: 30 days
83
+ * - **Source**: Registry.sol line 37: ROLE_ANODE = keccak256("ANODE")
84
+ */
85
+ export const ROLE_ANODE = keccak256(toHex('ANODE'));
86
+ /**
87
+ * KMS Role (Key Management Service)
88
+ * @remarks
89
+ * - **Description**: KMS operator for secure key storage and management
90
+ * - **Permission**: Infrastructure operator (highest stake)
91
+ * - **Requirement**: minStake: 100 GT, entryBurn: 10 GT (line 98)
92
+ * - **Exit Fee**: 10% (1000 basis points), min 5 GT
93
+ * - **Lock Duration**: 30 days
94
+ * - **Source**: Registry.sol line 38: ROLE_KMS = keccak256("KMS")
95
+ */
96
+ export const ROLE_KMS = keccak256(toHex('KMS'));
97
+ // ========== Role Name Mapping ==========
98
+ export const ROLE_NAMES = {
99
+ [DEFAULT_ADMIN_ROLE]: 'Default Admin',
100
+ [ROLE_COMMUNITY]: 'Community Admin',
101
+ [ROLE_ENDUSER]: 'End User',
102
+ [ROLE_PAYMASTER_AOA]: 'Paymaster (AOA)',
103
+ [ROLE_PAYMASTER_SUPER]: 'Paymaster (Super)',
104
+ [ROLE_DVT]: 'DVT Operator',
105
+ [ROLE_ANODE]: 'Anonymous Node',
106
+ [ROLE_KMS]: 'KMS Operator'
107
+ };
108
+ /**
109
+ * Get human-readable role name
110
+ */
111
+ export function getRoleName(roleHash) {
112
+ return ROLE_NAMES[roleHash] || 'Unknown Role';
113
+ }
114
+ /**
115
+ * Role permission levels (for UI sorting/filtering)
116
+ */
117
+ export var RolePermissionLevel;
118
+ (function (RolePermissionLevel) {
119
+ RolePermissionLevel[RolePermissionLevel["PROTOCOL"] = 100] = "PROTOCOL";
120
+ RolePermissionLevel[RolePermissionLevel["KMS"] = 80] = "KMS";
121
+ RolePermissionLevel[RolePermissionLevel["OPERATOR"] = 50] = "OPERATOR";
122
+ RolePermissionLevel[RolePermissionLevel["COMMUNITY"] = 30] = "COMMUNITY";
123
+ RolePermissionLevel[RolePermissionLevel["USER"] = 10] = "USER"; // End Users
124
+ })(RolePermissionLevel || (RolePermissionLevel = {}));
125
+ export const ROLE_PERMISSION_LEVELS = {
126
+ [DEFAULT_ADMIN_ROLE]: RolePermissionLevel.PROTOCOL,
127
+ [ROLE_KMS]: RolePermissionLevel.KMS,
128
+ [ROLE_PAYMASTER_SUPER]: RolePermissionLevel.OPERATOR,
129
+ [ROLE_PAYMASTER_AOA]: RolePermissionLevel.OPERATOR,
130
+ [ROLE_DVT]: RolePermissionLevel.OPERATOR,
131
+ [ROLE_ANODE]: RolePermissionLevel.OPERATOR,
132
+ [ROLE_COMMUNITY]: RolePermissionLevel.COMMUNITY,
133
+ [ROLE_ENDUSER]: RolePermissionLevel.USER
134
+ };
135
+ /**
136
+ * Exact stake requirements from Registry.sol constructor (lines 92-100)
137
+ * @remarks
138
+ * **Warning**: These are initial values, always query contract for current configuration
139
+ */
140
+ export const INITIAL_ROLE_STAKES = {
141
+ [ROLE_PAYMASTER_AOA]: {
142
+ minStake: '30 GT',
143
+ entryBurn: '3 GT',
144
+ exitFeePercent: '10%',
145
+ minExitFee: '1 GT',
146
+ lockDuration: '30 days',
147
+ line: 92
148
+ },
149
+ [ROLE_PAYMASTER_SUPER]: {
150
+ minStake: '50 GT',
151
+ entryBurn: '5 GT',
152
+ exitFeePercent: '10%',
153
+ minExitFee: '2 GT',
154
+ lockDuration: '30 days',
155
+ additionalRequirement: 'aPNTs collateral in SuperPaymaster',
156
+ line: 93
157
+ },
158
+ [ROLE_DVT]: {
159
+ minStake: '30 GT',
160
+ entryBurn: '3 GT',
161
+ exitFeePercent: '10%',
162
+ minExitFee: '1 GT',
163
+ lockDuration: '30 days',
164
+ line: 94
165
+ },
166
+ [ROLE_ANODE]: {
167
+ minStake: '20 GT',
168
+ entryBurn: '2 GT',
169
+ exitFeePercent: '10%',
170
+ minExitFee: '1 GT',
171
+ lockDuration: '30 days',
172
+ line: 95
173
+ },
174
+ [ROLE_KMS]: {
175
+ minStake: '100 GT',
176
+ entryBurn: '10 GT',
177
+ exitFeePercent: '10%',
178
+ minExitFee: '5 GT',
179
+ lockDuration: '30 days',
180
+ line: 98
181
+ },
182
+ [ROLE_COMMUNITY]: {
183
+ minStake: '30 GT',
184
+ entryBurn: '3 GT',
185
+ exitFeePercent: '5%',
186
+ minExitFee: '1 GT',
187
+ lockDuration: '30 days',
188
+ line: 99
189
+ },
190
+ [ROLE_ENDUSER]: {
191
+ minStake: '0.3 GT',
192
+ entryBurn: '0.05 GT',
193
+ exitFeePercent: '10%',
194
+ minExitFee: '0.05 GT',
195
+ lockDuration: '7 days',
196
+ additionalRequirement: 'Must hold MySBT from community',
197
+ line: 100
198
+ }
199
+ };
200
+ /**
201
+ * All defined roles array (for iteration)
202
+ */
203
+ export const ALL_ROLES = [
204
+ ROLE_COMMUNITY,
205
+ ROLE_ENDUSER,
206
+ ROLE_PAYMASTER_AOA,
207
+ ROLE_PAYMASTER_SUPER,
208
+ ROLE_DVT,
209
+ ROLE_ANODE,
210
+ ROLE_KMS
211
+ ];
@@ -0,0 +1,24 @@
1
+ export declare class AAStarValidationError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ /**
5
+ * Validates an Ethereum address.
6
+ * Throws AAStarValidationError if invalid.
7
+ */
8
+ export declare function validateAddress(address: string, fieldName?: string): `0x${string}`;
9
+ /**
10
+ * Validates a BigInt amount.
11
+ * @param amount The value to check
12
+ * @param fieldName Name for error messages
13
+ * @param min Minimum value (default 0n)
14
+ * @param max Maximum value (optional)
15
+ */
16
+ export declare function validateAmount(amount: bigint, fieldName?: string, min?: bigint, max?: bigint): bigint;
17
+ /**
18
+ * Validates a UINT128 value (Common in Paymaster Data).
19
+ */
20
+ export declare function validateUint128(value: bigint, fieldName?: string): bigint;
21
+ /**
22
+ * Validates a Hex string.
23
+ */
24
+ export declare function validateHex(value: string, fieldName?: string): `0x${string}`;
@@ -0,0 +1,56 @@
1
+ import { isAddress, getAddress } from 'viem';
2
+ export class AAStarValidationError extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = 'AAStarValidationError';
6
+ }
7
+ }
8
+ /**
9
+ * Validates an Ethereum address.
10
+ * Throws AAStarValidationError if invalid.
11
+ */
12
+ export function validateAddress(address, fieldName = 'Address') {
13
+ if (!address) {
14
+ throw new AAStarValidationError(`${fieldName} is required.`);
15
+ }
16
+ if (!isAddress(address)) {
17
+ throw new AAStarValidationError(`${fieldName} must be a valid Ethereum address. Got: ${address}`);
18
+ }
19
+ return getAddress(address); // Returns checksummed address
20
+ }
21
+ /**
22
+ * Validates a BigInt amount.
23
+ * @param amount The value to check
24
+ * @param fieldName Name for error messages
25
+ * @param min Minimum value (default 0n)
26
+ * @param max Maximum value (optional)
27
+ */
28
+ export function validateAmount(amount, fieldName = 'Amount', min = 0n, max) {
29
+ if (amount < min) {
30
+ throw new AAStarValidationError(`${fieldName} must be >= ${min}. Got: ${amount}`);
31
+ }
32
+ if (max !== undefined && amount > max) {
33
+ throw new AAStarValidationError(`${fieldName} must be <= ${max}. Got: ${amount}`);
34
+ }
35
+ return amount;
36
+ }
37
+ /**
38
+ * Validates a UINT128 value (Common in Paymaster Data).
39
+ */
40
+ export function validateUint128(value, fieldName = 'Value') {
41
+ const MAX_UINT128 = (1n << 128n) - 1n;
42
+ return validateAmount(value, fieldName, 0n, MAX_UINT128);
43
+ }
44
+ /**
45
+ * Validates a Hex string.
46
+ */
47
+ export function validateHex(value, fieldName = 'Hex') {
48
+ if (!value.startsWith('0x')) {
49
+ throw new AAStarValidationError(`${fieldName} must start with 0x. Got: ${value}`);
50
+ }
51
+ const hexRegex = /^0x[0-9a-fA-F]*$/;
52
+ if (!hexRegex.test(value)) {
53
+ throw new AAStarValidationError(`${fieldName} must be a valid hex string.`);
54
+ }
55
+ return value;
56
+ }
@@ -0,0 +1,3 @@
1
+ export * from './ui/index.js';
2
+ export * from './ui/hooks/useCreditScore.js';
3
+ export * from './ui/hooks/useSuperPaymaster.js';
@@ -0,0 +1,3 @@
1
+ export * from './ui/index.js';
2
+ export * from './ui/hooks/useCreditScore.js';
3
+ export * from './ui/hooks/useSuperPaymaster.js';
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { type PaymasterConfig } from '@aastar/paymaster';
3
+ import { type Chain, type Address } from 'viem';
4
+ type EvaluationPanelProps = {
5
+ paymasterConfig: PaymasterConfig;
6
+ userAddress: Address;
7
+ chain: Chain;
8
+ registryAddress: Address;
9
+ };
10
+ export declare const EvaluationPanel: React.FC<EvaluationPanelProps>;
11
+ export {};
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import { useCreditScore } from '../hooks/useCreditScore';
3
+ export const EvaluationPanel = ({ paymasterConfig, userAddress, chain, registryAddress }) => {
4
+ const { creditLimit, loading } = useCreditScore({
5
+ chain,
6
+ userAddress,
7
+ registryAddress
8
+ });
9
+ return (React.createElement("div", { style: { padding: '10px', border: '1px solid #ccc', borderRadius: '4px', maxWidth: '300px' } },
10
+ React.createElement("h3", null, "SuperPaymaster Debug"),
11
+ React.createElement("div", { style: { fontSize: '12px' } },
12
+ React.createElement("p", null,
13
+ React.createElement("strong", null, "Status:"),
14
+ " ",
15
+ loading ? 'Loading...' : 'Ready'),
16
+ React.createElement("p", null,
17
+ React.createElement("strong", null, "User:"),
18
+ " ",
19
+ userAddress.slice(0, 6),
20
+ "...",
21
+ userAddress.slice(-4)),
22
+ React.createElement("p", null,
23
+ React.createElement("strong", null, "Credit Limit:"),
24
+ " ",
25
+ creditLimit ? creditLimit.toString() : '0'),
26
+ React.createElement("hr", null),
27
+ React.createElement("p", null,
28
+ React.createElement("strong", null, "Paymaster:"),
29
+ " ",
30
+ paymasterConfig.paymasterAddress.slice(0, 6),
31
+ "..."),
32
+ React.createElement("p", null,
33
+ React.createElement("strong", null, "Operator:"),
34
+ " ",
35
+ paymasterConfig.operator.slice(0, 6),
36
+ "..."))));
37
+ };
@@ -0,0 +1,13 @@
1
+ import { type Address, type Chain, type Transport } from 'viem';
2
+ type UseCreditScoreConfig = {
3
+ chain: Chain;
4
+ rpcUrl?: string;
5
+ registryAddress: Address;
6
+ userAddress: Address;
7
+ transport?: Transport;
8
+ };
9
+ export declare function useCreditScore({ chain, rpcUrl, registryAddress, userAddress }: UseCreditScoreConfig): {
10
+ creditLimit: bigint | null;
11
+ loading: boolean;
12
+ };
13
+ export {};
@@ -0,0 +1,32 @@
1
+ import { useState, useEffect } from 'react';
2
+ import { createAAStarPublicClient, RegistryABI } from '@aastar/core';
3
+ export function useCreditScore({ chain, rpcUrl, registryAddress, userAddress }) {
4
+ const [creditLimit, setCreditLimit] = useState(null);
5
+ const [loading, setLoading] = useState(false);
6
+ useEffect(() => {
7
+ if (!registryAddress || !userAddress || !rpcUrl)
8
+ return;
9
+ const fetchCredit = async () => {
10
+ setLoading(true);
11
+ try {
12
+ const client = createAAStarPublicClient(rpcUrl, chain);
13
+ const limit = await client.readContract({
14
+ address: registryAddress,
15
+ abi: RegistryABI,
16
+ functionName: 'getCreditLimit',
17
+ args: [userAddress]
18
+ });
19
+ setCreditLimit(limit);
20
+ }
21
+ catch (e) {
22
+ console.error("Failed to fetch credit limit:", e);
23
+ setCreditLimit(0n);
24
+ }
25
+ finally {
26
+ setLoading(false);
27
+ }
28
+ };
29
+ fetchCredit();
30
+ }, [chain, rpcUrl, registryAddress, userAddress]);
31
+ return { creditLimit, loading };
32
+ }
@@ -0,0 +1,8 @@
1
+ import { type PaymasterConfig } from '@aastar/paymaster';
2
+ type UseSuperPaymasterResult = {
3
+ generatePaymasterAndData: (userOp: any) => Promise<string>;
4
+ isLoading: boolean;
5
+ error: Error | null;
6
+ };
7
+ export declare function useSuperPaymaster(config: PaymasterConfig): UseSuperPaymasterResult;
8
+ export {};
@@ -0,0 +1,23 @@
1
+ import { useState, useCallback } from 'react';
2
+ import { getSuperPaymasterMiddleware } from '@aastar/paymaster';
3
+ export function useSuperPaymaster(config) {
4
+ const [isLoading, setIsLoading] = useState(false);
5
+ const [error, setError] = useState(null);
6
+ const generatePaymasterAndData = useCallback(async (userOp) => {
7
+ setIsLoading(true);
8
+ setError(null);
9
+ try {
10
+ const middleware = getSuperPaymasterMiddleware(config);
11
+ const result = await middleware.sponsorUserOperation({ userOperation: userOp });
12
+ return result.paymasterAndData;
13
+ }
14
+ catch (err) {
15
+ setError(err);
16
+ throw err;
17
+ }
18
+ finally {
19
+ setIsLoading(false);
20
+ }
21
+ }, [config.paymasterAddress, config.operator, config.verificationGasLimit, config.postOpGasLimit]);
22
+ return { generatePaymasterAndData, isLoading, error };
23
+ }
@@ -0,0 +1,4 @@
1
+ import { type Address, type WalletClient, type Hex } from 'viem';
2
+ export declare class DVTClient {
3
+ static registerValidator(wallet: WalletClient, dvtAddr: Address, blsPublicKey: Hex): Promise<`0x${string}`>;
4
+ }
@@ -0,0 +1,17 @@
1
+ import { parseAbi } from 'viem';
2
+ const DVT_ABI = parseAbi([
3
+ 'function registerValidator(bytes)',
4
+ 'function createProposal(address, uint8, string)',
5
+ 'function signProposal(uint256, bytes)'
6
+ ]);
7
+ export class DVTClient {
8
+ static async registerValidator(wallet, dvtAddr, blsPublicKey) {
9
+ return wallet.writeContract({
10
+ address: dvtAddr,
11
+ abi: DVT_ABI,
12
+ functionName: 'registerValidator',
13
+ args: [blsPublicKey],
14
+ chain: wallet.chain
15
+ });
16
+ }
17
+ }
@@ -0,0 +1,44 @@
1
+ import { type Address } from 'viem';
2
+ export type PaymasterConfig = {
3
+ paymasterAddress: Address;
4
+ operator: Address;
5
+ maxRate?: bigint;
6
+ verificationGasLimit?: bigint;
7
+ postOpGasLimit?: bigint;
8
+ };
9
+ /**
10
+ * Constructs the middleware for SuperPaymaster.
11
+ * Returns the `paymasterAndData` hex string.
12
+ */
13
+ export declare function getSuperPaymasterMiddleware(config: PaymasterConfig): {
14
+ sponsorUserOperation: (args: {
15
+ userOperation: any;
16
+ }) => Promise<{
17
+ paymasterAndData: `0x${string}`;
18
+ verificationGasLimit: bigint;
19
+ preVerificationGas: any;
20
+ }>;
21
+ };
22
+ /**
23
+ * Enhanced eligibility check for SuperPaymaster V3.
24
+ * Validates that user has sufficient credit with the given operator.
25
+ */
26
+ export declare function checkEligibility(client: any, paymaster: Address, user: Address, operator: Address): Promise<{
27
+ eligible: boolean;
28
+ credit?: bigint;
29
+ token?: Address;
30
+ }>;
31
+ /**
32
+ * Admin Client for SuperPaymaster V3
33
+ */
34
+ export declare class SuperPaymasterAdminClient {
35
+ private client;
36
+ private paymasterAddress;
37
+ constructor(client: any, paymasterAddress: Address);
38
+ getOperator(operator: Address): Promise<any>;
39
+ static configureOperator(wallet: any, paymaster: Address, token: Address, treasury: Address, exchangeRate: bigint): Promise<any>;
40
+ static setOperatorPaused(wallet: any, paymaster: Address, operator: Address, paused: boolean): Promise<any>;
41
+ static updateReputation(wallet: any, paymaster: Address, operator: Address, score: bigint): Promise<any>;
42
+ static setAPNTsToken(wallet: any, paymaster: Address, token: Address): Promise<any>;
43
+ static setXPNTsFactory(wallet: any, paymaster: Address, factory: Address): Promise<any>;
44
+ }
@@ -0,0 +1,133 @@
1
+ import { concat, pad, toHex } from 'viem';
2
+ import { SuperPaymasterABI as SUPERPAYMASTER_ABI } from '@aastar/core';
3
+ const DEFAULT_VERIFICATION_GAS = 160000n;
4
+ const DEFAULT_POSTOP_GAS = 10000n;
5
+ /**
6
+ * Constructs the middleware for SuperPaymaster.
7
+ * Returns the `paymasterAndData` hex string.
8
+ */
9
+ export function getSuperPaymasterMiddleware(config) {
10
+ return {
11
+ sponsorUserOperation: async (args) => {
12
+ const verGas = config.verificationGasLimit ?? DEFAULT_VERIFICATION_GAS;
13
+ const postGas = config.postOpGasLimit ?? DEFAULT_POSTOP_GAS;
14
+ const maxRate = config.maxRate ?? 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn;
15
+ // V3.2.1 Layout: [Paymaster(20)] [VerGas(16)] [PostOpGas(16)] [Operator(20)] [MaxRate(32)]
16
+ // Offset 72 starts MaxRate.
17
+ const paymasterAndData = concat([
18
+ config.paymasterAddress,
19
+ pad(toHex(verGas), { size: 16 }),
20
+ pad(toHex(postGas), { size: 16 }),
21
+ config.operator,
22
+ pad(toHex(maxRate), { size: 32 })
23
+ ]);
24
+ return {
25
+ paymasterAndData,
26
+ verificationGasLimit: verGas,
27
+ preVerificationGas: args.userOperation.preVerificationGas,
28
+ };
29
+ }
30
+ };
31
+ }
32
+ /**
33
+ * Enhanced eligibility check for SuperPaymaster V3.
34
+ * Validates that user has sufficient credit with the given operator.
35
+ */
36
+ export async function checkEligibility(client, paymaster, user, operator) {
37
+ try {
38
+ // 1. Fetch operator's configured token
39
+ const operatorData = await client.readContract({
40
+ address: paymaster,
41
+ abi: SUPERPAYMASTER_ABI,
42
+ functionName: 'operators',
43
+ args: [operator]
44
+ });
45
+ // operatorData structure: [token, treasury, isConfigured, isPaused, exchangeRate, ...]
46
+ const token = operatorData[0];
47
+ const isConfigured = operatorData[2];
48
+ const isPaused = operatorData[3];
49
+ if (!isConfigured || isPaused) {
50
+ return { eligible: false };
51
+ }
52
+ // 2. Check available credit
53
+ const credit = await client.readContract({
54
+ address: paymaster,
55
+ abi: SUPERPAYMASTER_ABI,
56
+ functionName: 'getAvailableCredit',
57
+ args: [user, token]
58
+ });
59
+ return {
60
+ eligible: credit > 0n,
61
+ credit: credit,
62
+ token
63
+ };
64
+ }
65
+ catch (e) {
66
+ console.warn('Eligibility check failed:', e);
67
+ return { eligible: false };
68
+ }
69
+ }
70
+ /**
71
+ * Admin Client for SuperPaymaster V3
72
+ */
73
+ export class SuperPaymasterAdminClient {
74
+ client;
75
+ paymasterAddress;
76
+ constructor(client, paymasterAddress) {
77
+ this.client = client;
78
+ this.paymasterAddress = paymasterAddress;
79
+ }
80
+ async getOperator(operator) {
81
+ return this.client.readContract({
82
+ address: this.paymasterAddress,
83
+ abi: SUPERPAYMASTER_ABI,
84
+ functionName: 'operators',
85
+ args: [operator]
86
+ });
87
+ }
88
+ static async configureOperator(wallet, paymaster, token, treasury, exchangeRate) {
89
+ return wallet.writeContract({
90
+ address: paymaster,
91
+ abi: SUPERPAYMASTER_ABI,
92
+ functionName: 'configureOperator',
93
+ args: [token, treasury, exchangeRate],
94
+ chain: wallet.chain
95
+ });
96
+ }
97
+ static async setOperatorPaused(wallet, paymaster, operator, paused) {
98
+ return wallet.writeContract({
99
+ address: paymaster,
100
+ abi: SUPERPAYMASTER_ABI,
101
+ functionName: 'setOperatorPaused',
102
+ args: [operator, paused],
103
+ chain: wallet.chain
104
+ });
105
+ }
106
+ static async updateReputation(wallet, paymaster, operator, score) {
107
+ return wallet.writeContract({
108
+ address: paymaster,
109
+ abi: SUPERPAYMASTER_ABI,
110
+ functionName: 'updateReputation',
111
+ args: [operator, score],
112
+ chain: wallet.chain
113
+ });
114
+ }
115
+ static async setAPNTsToken(wallet, paymaster, token) {
116
+ return wallet.writeContract({
117
+ address: paymaster,
118
+ abi: SUPERPAYMASTER_ABI,
119
+ functionName: 'setAPNTsToken',
120
+ args: [token],
121
+ chain: wallet.chain
122
+ });
123
+ }
124
+ static async setXPNTsFactory(wallet, paymaster, factory) {
125
+ return wallet.writeContract({
126
+ address: paymaster,
127
+ abi: SUPERPAYMASTER_ABI,
128
+ functionName: 'setXPNTsFactory',
129
+ args: [factory],
130
+ chain: wallet.chain
131
+ });
132
+ }
133
+ }