@aastar/sdk 0.20.7 → 0.20.9
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/dist/BaseClient-CkBhQ1ou.d.cts +88 -0
- package/dist/UserClient-2J6XMTNV.cjs +15 -0
- package/dist/UserClient-2J6XMTNV.cjs.map +1 -0
- package/dist/account.cjs +31 -0
- package/dist/account.cjs.map +1 -0
- package/dist/account.d.cts +48 -0
- package/dist/admin.cjs +15 -0
- package/dist/admin.cjs.map +1 -0
- package/dist/admin.d.cts +62 -0
- package/dist/airaccount.cjs +452 -0
- package/dist/airaccount.cjs.map +1 -0
- package/dist/airaccount.d.cts +4 -0
- package/dist/airaccount.js +3 -1
- package/dist/channel-CkRRbzT8.d.cts +77 -0
- package/dist/channel.cjs +27 -0
- package/dist/channel.cjs.map +1 -0
- package/dist/channel.d.cts +64 -0
- package/dist/chunk-2RCJBWPO.cjs +1168 -0
- package/dist/chunk-2RCJBWPO.cjs.map +1 -0
- package/dist/chunk-FTJD2DWE.cjs +42472 -0
- package/dist/chunk-FTJD2DWE.cjs.map +1 -0
- package/dist/chunk-GRDC6ZRA.cjs +118 -0
- package/dist/chunk-GRDC6ZRA.cjs.map +1 -0
- package/dist/chunk-GX7NROST.cjs +421 -0
- package/dist/chunk-GX7NROST.cjs.map +1 -0
- package/dist/chunk-HSVQIFIK.cjs +128 -0
- package/dist/chunk-HSVQIFIK.cjs.map +1 -0
- package/dist/{chunk-UIFMIVDK.js → chunk-IC3G6YM2.js} +24 -26
- package/dist/chunk-IC3G6YM2.js.map +1 -0
- package/dist/chunk-JTWY2XEG.cjs +115 -0
- package/dist/chunk-JTWY2XEG.cjs.map +1 -0
- package/dist/chunk-MRREGCWN.cjs +585 -0
- package/dist/chunk-MRREGCWN.cjs.map +1 -0
- package/dist/chunk-NT26BDGN.cjs +228 -0
- package/dist/chunk-NT26BDGN.cjs.map +1 -0
- package/dist/chunk-Q7SFCCGT.cjs +11 -0
- package/dist/chunk-Q7SFCCGT.cjs.map +1 -0
- package/dist/chunk-QLF7N6H7.cjs +448 -0
- package/dist/chunk-QLF7N6H7.cjs.map +1 -0
- package/dist/chunk-RNHSA3LO.cjs +108 -0
- package/dist/chunk-RNHSA3LO.cjs.map +1 -0
- package/dist/chunk-S5IKOOUR.cjs +393 -0
- package/dist/chunk-S5IKOOUR.cjs.map +1 -0
- package/dist/chunk-TFLZETWB.cjs +4693 -0
- package/dist/chunk-TFLZETWB.cjs.map +1 -0
- package/dist/chunk-WQREDGUF.cjs +435 -0
- package/dist/chunk-WQREDGUF.cjs.map +1 -0
- package/dist/chunk-XQROKLZI.cjs +4521 -0
- package/dist/chunk-XQROKLZI.cjs.map +1 -0
- package/dist/contract-addresses-TANQ5DLX.cjs +49 -0
- package/dist/contract-addresses-TANQ5DLX.cjs.map +1 -0
- package/dist/core.cjs +894 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +6930 -0
- package/dist/dapp.cjs +289 -0
- package/dist/dapp.cjs.map +1 -0
- package/dist/dapp.d.cts +127 -0
- package/dist/doc-types-471vSmPO.d.cts +16 -0
- package/dist/enduser.cjs +24 -0
- package/dist/enduser.cjs.map +1 -0
- package/dist/enduser.d.cts +261 -0
- package/dist/identity.cjs +23 -0
- package/dist/identity.cjs.map +1 -0
- package/dist/identity.d.cts +81 -0
- package/dist/index-B6SfEQxo.d.cts +47 -0
- package/dist/index.cjs +2814 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +656 -0
- package/dist/kms.cjs +452 -0
- package/dist/kms.cjs.map +1 -0
- package/dist/kms.d.cts +3054 -0
- package/dist/kms.d.ts +13 -13
- package/dist/kms.js +3 -1
- package/dist/lib-FE4GR7TO.cjs +1865 -0
- package/dist/lib-FE4GR7TO.cjs.map +1 -0
- package/dist/operator.cjs +27 -0
- package/dist/operator.cjs.map +1 -0
- package/dist/operator.d.cts +164 -0
- package/dist/paymaster.cjs +63 -0
- package/dist/paymaster.cjs.map +1 -0
- package/dist/paymaster.d.cts +312 -0
- package/dist/src-ENPA7D2S.cjs +63 -0
- package/dist/src-ENPA7D2S.cjs.map +1 -0
- package/dist/src-TQKEO2I4.cjs +894 -0
- package/dist/src-TQKEO2I4.cjs.map +1 -0
- package/dist/tier-router-DeeVg69O.d.cts +370 -0
- package/dist/tokens.cjs +15 -0
- package/dist/tokens.cjs.map +1 -0
- package/dist/tokens.d.cts +64 -0
- package/dist/x402.cjs +103 -0
- package/dist/x402.cjs.map +1 -0
- package/dist/x402.d.cts +373 -0
- package/package.json +32 -32
- package/dist/chunk-UIFMIVDK.js.map +0 -1
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkFTJD2DWE_cjs = require('./chunk-FTJD2DWE.cjs');
|
|
4
|
+
var viem = require('viem');
|
|
5
|
+
|
|
6
|
+
var PaymasterOperatorClient = class extends chunkFTJD2DWE_cjs.BaseClient {
|
|
7
|
+
superPaymasterAddress;
|
|
8
|
+
tokenAddress;
|
|
9
|
+
ethUsdPriceFeed;
|
|
10
|
+
xpntsFactory;
|
|
11
|
+
constructor(config) {
|
|
12
|
+
super(config);
|
|
13
|
+
this.superPaymasterAddress = config.superPaymasterAddress;
|
|
14
|
+
this.tokenAddress = config.tokenAddress;
|
|
15
|
+
this.ethUsdPriceFeed = config.ethUsdPriceFeedAddress || "0x694AA1769357215DE4FAC081bf1f309aDC325306";
|
|
16
|
+
this.xpntsFactory = config.xpntsFactoryAddress || "0x0000000000000000000000000000000000000000";
|
|
17
|
+
}
|
|
18
|
+
// ========================================
|
|
19
|
+
// 0. 注册与入驻 (One-Stop Registration)
|
|
20
|
+
// ========================================
|
|
21
|
+
/**
|
|
22
|
+
* Register as SuperPaymaster Operator (one-stop API).
|
|
23
|
+
* This method handles all necessary steps:
|
|
24
|
+
* 1. Checks prerequisites (must have ROLE_COMMUNITY)
|
|
25
|
+
* 2. Checks and approves GToken to GTokenStaking
|
|
26
|
+
* 3. Registers ROLE_PAYMASTER_SUPER
|
|
27
|
+
* 4. Optionally deposits collateral to SuperPaymaster
|
|
28
|
+
*
|
|
29
|
+
* @param params Registration parameters
|
|
30
|
+
* @param options Transaction options
|
|
31
|
+
* @returns Transaction hash of role registration
|
|
32
|
+
*/
|
|
33
|
+
async registerAsSuperPaymasterOperator(params, options) {
|
|
34
|
+
try {
|
|
35
|
+
const registryAddr = this.requireRegistry();
|
|
36
|
+
const gTokenAddr = this.requireGToken();
|
|
37
|
+
const gTokenStakingAddr = this.requireGTokenStaking();
|
|
38
|
+
const registry = chunkFTJD2DWE_cjs.registryActions(registryAddr);
|
|
39
|
+
const gToken = chunkFTJD2DWE_cjs.tokenActions();
|
|
40
|
+
const publicClient = this.getStartPublicClient();
|
|
41
|
+
const ROLE_COMMUNITY = await registry(publicClient).ROLE_COMMUNITY();
|
|
42
|
+
const hasCommunity = await registry(publicClient).hasRole({
|
|
43
|
+
user: this.getAddress(),
|
|
44
|
+
roleId: ROLE_COMMUNITY
|
|
45
|
+
});
|
|
46
|
+
if (!hasCommunity) {
|
|
47
|
+
throw new Error("Must have ROLE_COMMUNITY before registering as SuperPaymaster operator");
|
|
48
|
+
}
|
|
49
|
+
const ROLE_PAYMASTER_SUPER = await registry(publicClient).ROLE_PAYMASTER_SUPER();
|
|
50
|
+
const hasSuper = await registry(publicClient).hasRole({
|
|
51
|
+
user: this.getAddress(),
|
|
52
|
+
roleId: ROLE_PAYMASTER_SUPER
|
|
53
|
+
});
|
|
54
|
+
if (hasSuper) {
|
|
55
|
+
if (params?.depositAmount) {
|
|
56
|
+
return this.depositCollateral(params.depositAmount, options);
|
|
57
|
+
}
|
|
58
|
+
throw new Error("Already registered as SuperPaymaster operator");
|
|
59
|
+
}
|
|
60
|
+
const stakeAmount = params?.stakeAmount || viem.parseEther("50");
|
|
61
|
+
const allowance = await gToken(publicClient).allowance({
|
|
62
|
+
token: gTokenAddr,
|
|
63
|
+
owner: this.getAddress(),
|
|
64
|
+
spender: gTokenStakingAddr
|
|
65
|
+
});
|
|
66
|
+
if (allowance < stakeAmount) {
|
|
67
|
+
const approveHash = await gToken(this.client).approve({
|
|
68
|
+
token: gTokenAddr,
|
|
69
|
+
spender: gTokenStakingAddr,
|
|
70
|
+
amount: stakeAmount * 2n,
|
|
71
|
+
// Approve 2x for future use
|
|
72
|
+
account: options?.account
|
|
73
|
+
});
|
|
74
|
+
await publicClient.waitForTransactionReceipt({ hash: approveHash });
|
|
75
|
+
}
|
|
76
|
+
const registerHash = await registry(this.client).registerRoleSelf({
|
|
77
|
+
roleId: ROLE_PAYMASTER_SUPER,
|
|
78
|
+
data: "0x",
|
|
79
|
+
// SuperPaymaster role doesn't need special data
|
|
80
|
+
account: options?.account
|
|
81
|
+
});
|
|
82
|
+
await publicClient.waitForTransactionReceipt({ hash: registerHash });
|
|
83
|
+
if (params?.depositAmount) {
|
|
84
|
+
await this.depositCollateral(params.depositAmount, options);
|
|
85
|
+
}
|
|
86
|
+
return registerHash;
|
|
87
|
+
} catch (error) {
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Deploy a new Paymaster V4 and Register as AOA Operator (one-stop API).
|
|
93
|
+
* This method handles:
|
|
94
|
+
* 1. Checks prerequisites (ROLE_COMMUNITY)
|
|
95
|
+
* 2. Predicts new Paymaster address
|
|
96
|
+
* 3. Deploys Paymaster V4 via Factory
|
|
97
|
+
* 4. Registers ROLE_PAYMASTER_AOA with staking
|
|
98
|
+
*
|
|
99
|
+
* @param params Deployment parameters
|
|
100
|
+
* @param options Transaction options
|
|
101
|
+
* @returns Object containing new paymaster address and transaction hashes
|
|
102
|
+
*/
|
|
103
|
+
async deployAndRegisterPaymasterV4(params, options) {
|
|
104
|
+
try {
|
|
105
|
+
const registryAddr = this.requireRegistry();
|
|
106
|
+
const gTokenAddr = this.requireGToken();
|
|
107
|
+
const gTokenStakingAddr = this.requireGTokenStaking();
|
|
108
|
+
const factoryAddr = this.requirePaymasterFactory();
|
|
109
|
+
const registry = chunkFTJD2DWE_cjs.registryActions(registryAddr);
|
|
110
|
+
const gToken = chunkFTJD2DWE_cjs.tokenActions();
|
|
111
|
+
const factory = chunkFTJD2DWE_cjs.paymasterFactoryActions(factoryAddr);
|
|
112
|
+
const publicClient = this.getStartPublicClient();
|
|
113
|
+
const account = options?.account || this.client.account || this.getAddress();
|
|
114
|
+
const accountAddr = typeof account === "string" ? account : account.address;
|
|
115
|
+
const ROLE_COMMUNITY = await registry(publicClient).ROLE_COMMUNITY();
|
|
116
|
+
const hasCommunity = await registry(publicClient).hasRole({
|
|
117
|
+
user: accountAddr,
|
|
118
|
+
roleId: ROLE_COMMUNITY
|
|
119
|
+
});
|
|
120
|
+
if (!hasCommunity) {
|
|
121
|
+
throw new Error("Must have ROLE_COMMUNITY before deploying Paymaster V4");
|
|
122
|
+
}
|
|
123
|
+
const existingPaymaster = await factory(publicClient).getPaymaster({ owner: accountAddr });
|
|
124
|
+
let deployHash = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
125
|
+
let paymasterAddress;
|
|
126
|
+
if (existingPaymaster && existingPaymaster !== "0x0000000000000000000000000000000000000000") {
|
|
127
|
+
console.log(` \u2139\uFE0F Paymaster already deployed at: ${existingPaymaster}`);
|
|
128
|
+
paymasterAddress = existingPaymaster;
|
|
129
|
+
} else {
|
|
130
|
+
console.log(" \u{1F6E0}\uFE0F Deploying Paymaster V4 with args:", {
|
|
131
|
+
entryPoint: this.requireEntryPoint(),
|
|
132
|
+
owner: accountAddr,
|
|
133
|
+
priceFeed: this.ethUsdPriceFeed,
|
|
134
|
+
factory: factoryAddr
|
|
135
|
+
});
|
|
136
|
+
const { encodeFunctionData } = await import('viem');
|
|
137
|
+
const initData = encodeFunctionData({
|
|
138
|
+
abi: chunkFTJD2DWE_cjs.PaymasterABI,
|
|
139
|
+
functionName: "initialize",
|
|
140
|
+
args: [
|
|
141
|
+
this.requireEntryPoint(),
|
|
142
|
+
// EntryPoint v0.7
|
|
143
|
+
accountAddr,
|
|
144
|
+
accountAddr,
|
|
145
|
+
// Treasury defaults to owner
|
|
146
|
+
this.ethUsdPriceFeed,
|
|
147
|
+
200n,
|
|
148
|
+
// serviceFeeRate (2%)
|
|
149
|
+
viem.parseEther("0.1"),
|
|
150
|
+
// maxGasCostCap
|
|
151
|
+
3600n
|
|
152
|
+
// priceStalenessThreshold (1 hour)
|
|
153
|
+
]
|
|
154
|
+
});
|
|
155
|
+
deployHash = await factory(this.client).deployPaymaster({
|
|
156
|
+
version: params?.version,
|
|
157
|
+
initData,
|
|
158
|
+
account
|
|
159
|
+
});
|
|
160
|
+
await publicClient.waitForTransactionReceipt({ hash: deployHash });
|
|
161
|
+
paymasterAddress = await factory(publicClient).getPaymaster({ owner: accountAddr });
|
|
162
|
+
}
|
|
163
|
+
if (!paymasterAddress || paymasterAddress === "0x0000000000000000000000000000000000000000") {
|
|
164
|
+
throw new Error("Failed to retrieve Paymaster address from Factory");
|
|
165
|
+
}
|
|
166
|
+
const ROLE_PAYMASTER_AOA = await registry(publicClient).ROLE_PAYMASTER_AOA();
|
|
167
|
+
const hasAOA = await registry(publicClient).hasRole({
|
|
168
|
+
user: accountAddr,
|
|
169
|
+
roleId: ROLE_PAYMASTER_AOA
|
|
170
|
+
});
|
|
171
|
+
if (hasAOA) {
|
|
172
|
+
return { paymasterAddress, deployHash, registerHash: "0x0000000000000000000000000000000000000000000000000000000000000000" };
|
|
173
|
+
}
|
|
174
|
+
const stakeAmount = params?.stakeAmount || viem.parseEther("30");
|
|
175
|
+
const allowance = await gToken(publicClient).allowance({
|
|
176
|
+
token: gTokenAddr,
|
|
177
|
+
owner: accountAddr,
|
|
178
|
+
spender: gTokenStakingAddr
|
|
179
|
+
});
|
|
180
|
+
if (allowance < stakeAmount) {
|
|
181
|
+
const approveHash = await gToken(this.client).approve({
|
|
182
|
+
token: gTokenAddr,
|
|
183
|
+
spender: gTokenStakingAddr,
|
|
184
|
+
amount: stakeAmount * 2n,
|
|
185
|
+
account
|
|
186
|
+
});
|
|
187
|
+
await publicClient.waitForTransactionReceipt({ hash: approveHash });
|
|
188
|
+
}
|
|
189
|
+
const { encodeAbiParameters, parseAbiParameters } = await import('viem');
|
|
190
|
+
let roleData = "0x";
|
|
191
|
+
if (stakeAmount > 0) {
|
|
192
|
+
roleData = encodeAbiParameters(
|
|
193
|
+
parseAbiParameters("uint256"),
|
|
194
|
+
[stakeAmount]
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
const registerHash = await registry(this.client).registerRoleSelf({
|
|
198
|
+
roleId: ROLE_PAYMASTER_AOA,
|
|
199
|
+
data: roleData,
|
|
200
|
+
account
|
|
201
|
+
});
|
|
202
|
+
await publicClient.waitForTransactionReceipt({ hash: registerHash });
|
|
203
|
+
return {
|
|
204
|
+
paymasterAddress,
|
|
205
|
+
deployHash,
|
|
206
|
+
registerHash
|
|
207
|
+
};
|
|
208
|
+
} catch (error) {
|
|
209
|
+
throw error;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Deposit collateral (aPNTs/GToken) to SuperPaymaster.
|
|
214
|
+
* This is a helper method used by registerAsSuperPaymasterOperator.
|
|
215
|
+
*/
|
|
216
|
+
async depositCollateral(amount, options) {
|
|
217
|
+
try {
|
|
218
|
+
const pm = chunkFTJD2DWE_cjs.superPaymasterActions(this.superPaymasterAddress);
|
|
219
|
+
const publicClient = this.getStartPublicClient();
|
|
220
|
+
const depositToken = await pm(publicClient).APNTS_TOKEN();
|
|
221
|
+
const token = chunkFTJD2DWE_cjs.tokenActions();
|
|
222
|
+
const allowance = await token(publicClient).allowance({
|
|
223
|
+
token: depositToken,
|
|
224
|
+
owner: this.getAddress(),
|
|
225
|
+
spender: this.superPaymasterAddress
|
|
226
|
+
});
|
|
227
|
+
if (allowance < amount) {
|
|
228
|
+
const approveHash = await token(this.client).approve({
|
|
229
|
+
token: depositToken,
|
|
230
|
+
spender: this.superPaymasterAddress,
|
|
231
|
+
amount,
|
|
232
|
+
account: options?.account
|
|
233
|
+
});
|
|
234
|
+
await publicClient.waitForTransactionReceipt({ hash: approveHash });
|
|
235
|
+
}
|
|
236
|
+
return pm(this.client).deposit({
|
|
237
|
+
amount,
|
|
238
|
+
account: options?.account
|
|
239
|
+
});
|
|
240
|
+
} catch (error) {
|
|
241
|
+
throw error;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Configure operator parameters (Token, Treasury).
|
|
246
|
+
* Exchange rate is now read live from xPNTsToken.exchangeRate() at runtime.
|
|
247
|
+
* If parameters are undefined, existing values are preserved.
|
|
248
|
+
*/
|
|
249
|
+
async configureOperator(xPNTsToken, treasury, options) {
|
|
250
|
+
try {
|
|
251
|
+
const sp = chunkFTJD2DWE_cjs.superPaymasterActions(this.superPaymasterAddress);
|
|
252
|
+
const publicClient = this.getStartPublicClient();
|
|
253
|
+
const currentConfig = await sp(publicClient).operators({ operator: this.getAddress() });
|
|
254
|
+
const currentToken = currentConfig.xPNTsToken;
|
|
255
|
+
const currentTreasury = currentConfig.treasury;
|
|
256
|
+
return await sp(this.client).configureOperator({
|
|
257
|
+
xPNTsToken: xPNTsToken || currentToken,
|
|
258
|
+
opTreasury: treasury || currentTreasury,
|
|
259
|
+
account: options?.account
|
|
260
|
+
});
|
|
261
|
+
} catch (error) {
|
|
262
|
+
throw error;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
async withdrawCollateral(to, amount, options) {
|
|
266
|
+
try {
|
|
267
|
+
const sp = chunkFTJD2DWE_cjs.superPaymasterActions(this.superPaymasterAddress);
|
|
268
|
+
return await sp(this.client).withdrawTo({
|
|
269
|
+
to,
|
|
270
|
+
amount,
|
|
271
|
+
account: options?.account
|
|
272
|
+
});
|
|
273
|
+
} catch (error) {
|
|
274
|
+
throw error;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
async isOperator(operator) {
|
|
278
|
+
try {
|
|
279
|
+
const sp = chunkFTJD2DWE_cjs.superPaymasterActions(this.superPaymasterAddress);
|
|
280
|
+
const config = await sp(this.getStartPublicClient()).operators({ operator });
|
|
281
|
+
return config.isConfigured;
|
|
282
|
+
} catch (error) {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
async getOperatorDetails(operator) {
|
|
287
|
+
try {
|
|
288
|
+
const target = operator || this.getAddress();
|
|
289
|
+
const sp = chunkFTJD2DWE_cjs.superPaymasterActions(this.superPaymasterAddress);
|
|
290
|
+
return await sp(this.getStartPublicClient()).operators({ operator: target });
|
|
291
|
+
} catch (error) {
|
|
292
|
+
throw error;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
async initiateExit(options) {
|
|
296
|
+
try {
|
|
297
|
+
const sp = chunkFTJD2DWE_cjs.superPaymasterActions(this.superPaymasterAddress);
|
|
298
|
+
return await sp(this.client).unlockStake({
|
|
299
|
+
account: options?.account
|
|
300
|
+
});
|
|
301
|
+
} catch (error) {
|
|
302
|
+
throw error;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
async withdrawStake(to, options) {
|
|
306
|
+
try {
|
|
307
|
+
const sp = chunkFTJD2DWE_cjs.superPaymasterActions(this.superPaymasterAddress);
|
|
308
|
+
return await sp(this.client).withdrawStake({
|
|
309
|
+
to,
|
|
310
|
+
account: options?.account
|
|
311
|
+
});
|
|
312
|
+
} catch (error) {
|
|
313
|
+
throw error;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
// ========================================
|
|
317
|
+
// 3. 支付代币管理 (基于 PaymasterActions)
|
|
318
|
+
// ========================================
|
|
319
|
+
async addGasToken(token, price, options) {
|
|
320
|
+
try {
|
|
321
|
+
const pm = chunkFTJD2DWE_cjs.paymasterActions(this.superPaymasterAddress);
|
|
322
|
+
return await pm(this.client).setTokenPrice({
|
|
323
|
+
token,
|
|
324
|
+
price,
|
|
325
|
+
account: options?.account
|
|
326
|
+
});
|
|
327
|
+
} catch (error) {
|
|
328
|
+
throw error;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
async getTokenPrice(token) {
|
|
332
|
+
try {
|
|
333
|
+
const pm = chunkFTJD2DWE_cjs.paymasterActions(this.superPaymasterAddress);
|
|
334
|
+
return await pm(this.getStartPublicClient()).tokenPrices({ token });
|
|
335
|
+
} catch (error) {
|
|
336
|
+
throw error;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
async setupPaymasterDeposit(params, options) {
|
|
340
|
+
try {
|
|
341
|
+
const pm = chunkFTJD2DWE_cjs.paymasterActions(params.paymaster);
|
|
342
|
+
return await pm(this.client).depositFor({
|
|
343
|
+
user: params.user,
|
|
344
|
+
token: params.token,
|
|
345
|
+
amount: params.amount,
|
|
346
|
+
account: options?.account
|
|
347
|
+
});
|
|
348
|
+
} catch (error) {
|
|
349
|
+
throw error;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
// ../operator/src/ProtocolClient.ts
|
|
355
|
+
var ProposalState = /* @__PURE__ */ ((ProposalState2) => {
|
|
356
|
+
ProposalState2[ProposalState2["Pending"] = 0] = "Pending";
|
|
357
|
+
ProposalState2[ProposalState2["Active"] = 1] = "Active";
|
|
358
|
+
ProposalState2[ProposalState2["Canceled"] = 2] = "Canceled";
|
|
359
|
+
ProposalState2[ProposalState2["Defeated"] = 3] = "Defeated";
|
|
360
|
+
ProposalState2[ProposalState2["Succeeded"] = 4] = "Succeeded";
|
|
361
|
+
ProposalState2[ProposalState2["Queued"] = 5] = "Queued";
|
|
362
|
+
ProposalState2[ProposalState2["Expired"] = 6] = "Expired";
|
|
363
|
+
ProposalState2[ProposalState2["Executed"] = 7] = "Executed";
|
|
364
|
+
return ProposalState2;
|
|
365
|
+
})(ProposalState || {});
|
|
366
|
+
var ProtocolClient = class extends chunkFTJD2DWE_cjs.BaseClient {
|
|
367
|
+
dvtValidatorAddress;
|
|
368
|
+
blsAggregatorAddress;
|
|
369
|
+
superPaymasterAddress;
|
|
370
|
+
constructor(config) {
|
|
371
|
+
super(config);
|
|
372
|
+
this.dvtValidatorAddress = config.dvtValidatorAddress;
|
|
373
|
+
this.blsAggregatorAddress = config.blsAggregatorAddress;
|
|
374
|
+
this.superPaymasterAddress = config.superPaymasterAddress;
|
|
375
|
+
}
|
|
376
|
+
// ========================================
|
|
377
|
+
// 1. 提案管理 (DVT)
|
|
378
|
+
// ========================================
|
|
379
|
+
/**
|
|
380
|
+
* Create a new proposal
|
|
381
|
+
*/
|
|
382
|
+
async createProposal(target, calldata, description, options) {
|
|
383
|
+
try {
|
|
384
|
+
const dvt = chunkFTJD2DWE_cjs.dvtActions(this.dvtValidatorAddress)(this.client);
|
|
385
|
+
return await dvt.createSlashProposal({
|
|
386
|
+
operator: target,
|
|
387
|
+
level: 1,
|
|
388
|
+
// Default level
|
|
389
|
+
reason: description,
|
|
390
|
+
account: options?.account
|
|
391
|
+
});
|
|
392
|
+
} catch (error) {
|
|
393
|
+
throw error;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
async signProposal(proposalId, signature = "0x", options) {
|
|
397
|
+
try {
|
|
398
|
+
const dvt = chunkFTJD2DWE_cjs.dvtActions(this.dvtValidatorAddress)(this.client);
|
|
399
|
+
return await dvt.signSlashProposal({
|
|
400
|
+
proposalId,
|
|
401
|
+
signature,
|
|
402
|
+
account: options?.account
|
|
403
|
+
});
|
|
404
|
+
} catch (error) {
|
|
405
|
+
throw error;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Execute a proposal with collected signatures
|
|
410
|
+
*/
|
|
411
|
+
async executeWithProof(proposalId, signatures, options) {
|
|
412
|
+
try {
|
|
413
|
+
const proof = "0x";
|
|
414
|
+
const dvt = chunkFTJD2DWE_cjs.dvtActions(this.dvtValidatorAddress)(this.client);
|
|
415
|
+
return await dvt.executeSlashWithProof({
|
|
416
|
+
proposalId,
|
|
417
|
+
repUsers: [],
|
|
418
|
+
// Needs real data in production
|
|
419
|
+
newScores: [],
|
|
420
|
+
epoch: 0n,
|
|
421
|
+
proof,
|
|
422
|
+
account: options?.account
|
|
423
|
+
});
|
|
424
|
+
} catch (error) {
|
|
425
|
+
throw error;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
// ========================================
|
|
429
|
+
// 2. 验证器管理 / BLS
|
|
430
|
+
// ========================================
|
|
431
|
+
async registerBLSKey(publicKey, options) {
|
|
432
|
+
try {
|
|
433
|
+
if (!this.blsAggregatorAddress) {
|
|
434
|
+
throw new Error("BLS Aggregator address required for this client");
|
|
435
|
+
}
|
|
436
|
+
const agg = chunkFTJD2DWE_cjs.aggregatorActions(this.blsAggregatorAddress)(this.client);
|
|
437
|
+
return await agg.registerBLSPublicKey({
|
|
438
|
+
validator: this.getAddress(),
|
|
439
|
+
publicKey,
|
|
440
|
+
account: options?.account
|
|
441
|
+
});
|
|
442
|
+
} catch (error) {
|
|
443
|
+
throw error;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
// ========================================
|
|
447
|
+
// 3. 全局参数管理 (Admin)
|
|
448
|
+
// ========================================
|
|
449
|
+
async setProtocolFee(bps, options) {
|
|
450
|
+
try {
|
|
451
|
+
if (!this.superPaymasterAddress) {
|
|
452
|
+
throw new Error("SuperPaymaster address required for this client");
|
|
453
|
+
}
|
|
454
|
+
const sp = chunkFTJD2DWE_cjs.superPaymasterActions(this.superPaymasterAddress);
|
|
455
|
+
return await sp(this.client).setProtocolFee({
|
|
456
|
+
newFeeBPS: bps,
|
|
457
|
+
account: options?.account
|
|
458
|
+
});
|
|
459
|
+
} catch (error) {
|
|
460
|
+
throw error;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
async setTreasury(treasury, options) {
|
|
464
|
+
try {
|
|
465
|
+
if (!this.superPaymasterAddress) {
|
|
466
|
+
throw new Error("SuperPaymaster address required for this client");
|
|
467
|
+
}
|
|
468
|
+
const sp = chunkFTJD2DWE_cjs.superPaymasterActions(this.superPaymasterAddress);
|
|
469
|
+
return await sp(this.client).setTreasury({
|
|
470
|
+
treasury,
|
|
471
|
+
account: options?.account
|
|
472
|
+
});
|
|
473
|
+
} catch (error) {
|
|
474
|
+
throw error;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
// ../operator/src/OperatorLifecycle.ts
|
|
480
|
+
var OperatorLifecycle = class extends PaymasterOperatorClient {
|
|
481
|
+
constructor(config) {
|
|
482
|
+
super(config);
|
|
483
|
+
}
|
|
484
|
+
// ===========================================
|
|
485
|
+
// 1. Setup Phase (Onboarding)
|
|
486
|
+
// ===========================================
|
|
487
|
+
/**
|
|
488
|
+
* Check if the account is ready to become an operator
|
|
489
|
+
* (e.g., has GToken, has ROLE_COMMUNITY, etc.)
|
|
490
|
+
*/
|
|
491
|
+
async checkReadiness() {
|
|
492
|
+
const isOp = await this.isOperator(this.getAddress());
|
|
493
|
+
const details = await this.getOperatorDetails();
|
|
494
|
+
const balance = details.aPNTsBalance || 0n;
|
|
495
|
+
return {
|
|
496
|
+
isConfigured: isOp,
|
|
497
|
+
isActive: isOp,
|
|
498
|
+
// Simplification
|
|
499
|
+
balance
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* One-click Setup: Register + Deposit + Deploy Node
|
|
504
|
+
* Wraps existing registerAsSuperPaymasterOperator or deployAndRegisterPaymasterV4
|
|
505
|
+
*/
|
|
506
|
+
async setupNode(params, options) {
|
|
507
|
+
const hashes = [];
|
|
508
|
+
if (params.type === "SUPER") {
|
|
509
|
+
const h = await this.registerAsSuperPaymasterOperator({
|
|
510
|
+
stakeAmount: params.stakeAmount,
|
|
511
|
+
depositAmount: params.depositAmount
|
|
512
|
+
}, options);
|
|
513
|
+
hashes.push(h);
|
|
514
|
+
const factory = await import('./src-TQKEO2I4.cjs').then((m) => m.xPNTsFactoryActions(this.xpntsFactory)(this.getStartPublicClient()));
|
|
515
|
+
const token = await factory.getTokenAddress({ community: this.getAddress() });
|
|
516
|
+
if (token && token !== "0x0000000000000000000000000000000000000000") {
|
|
517
|
+
const hConfig = await this.configureOperator(
|
|
518
|
+
token,
|
|
519
|
+
this.getAddress(),
|
|
520
|
+
// Default treasury to self
|
|
521
|
+
options
|
|
522
|
+
);
|
|
523
|
+
hashes.push(hConfig);
|
|
524
|
+
}
|
|
525
|
+
} else {
|
|
526
|
+
const result = await this.deployAndRegisterPaymasterV4({
|
|
527
|
+
stakeAmount: params.stakeAmount
|
|
528
|
+
}, options);
|
|
529
|
+
hashes.push(result.deployHash);
|
|
530
|
+
hashes.push(result.registerHash);
|
|
531
|
+
}
|
|
532
|
+
return hashes;
|
|
533
|
+
}
|
|
534
|
+
// ===========================================
|
|
535
|
+
// 2. Operational Phase (Config & Funds)
|
|
536
|
+
// ===========================================
|
|
537
|
+
// Inherits: addGasToken, configureOperator, depositCollateral from PaymasterOperatorClient
|
|
538
|
+
async getOperatorStats() {
|
|
539
|
+
return await this.getOperatorDetails();
|
|
540
|
+
}
|
|
541
|
+
// ===========================================
|
|
542
|
+
// 3. Exit Phase (Withdraw & Leave)
|
|
543
|
+
// ===========================================
|
|
544
|
+
/**
|
|
545
|
+
* Start the exit process: Unstake from Registry/SuperPaymaster and Unlock funds
|
|
546
|
+
*/
|
|
547
|
+
async initiateExit(options) {
|
|
548
|
+
return await super.initiateExit(options);
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Finalize exit: Withdraw all funds (Collateral + Rewards)
|
|
552
|
+
*/
|
|
553
|
+
async withdrawAllFunds(to, options) {
|
|
554
|
+
const recipient = to || this.getAddress();
|
|
555
|
+
const hashes = [];
|
|
556
|
+
const stats = await this.checkReadiness();
|
|
557
|
+
if (stats.balance > 0n) {
|
|
558
|
+
const hCol = await this.withdrawCollateral(recipient, stats.balance, options);
|
|
559
|
+
hashes.push(hCol);
|
|
560
|
+
}
|
|
561
|
+
const client = this.getStartPublicClient();
|
|
562
|
+
const registry = chunkFTJD2DWE_cjs.registryActions(this.registryAddress);
|
|
563
|
+
const registryWriter = chunkFTJD2DWE_cjs.registryActions(this.registryAddress)(this.client);
|
|
564
|
+
const ROLE_PAYMASTER_SUPER = await registry(client).ROLE_PAYMASTER_SUPER();
|
|
565
|
+
const hasRole = await registry(client).hasRole({ user: this.getAddress(), roleId: ROLE_PAYMASTER_SUPER });
|
|
566
|
+
if (hasRole) {
|
|
567
|
+
const hExit = await registryWriter.exitRole({ roleId: ROLE_PAYMASTER_SUPER, account: options?.account });
|
|
568
|
+
hashes.push(hExit);
|
|
569
|
+
}
|
|
570
|
+
return hashes;
|
|
571
|
+
}
|
|
572
|
+
// Helper: Get GToken Balance
|
|
573
|
+
async getTokenBalance() {
|
|
574
|
+
if (!this.tokenAddress) return 0n;
|
|
575
|
+
const token = chunkFTJD2DWE_cjs.tokenActions()(this.getStartPublicClient());
|
|
576
|
+
return await token.balanceOf({ token: this.tokenAddress, account: this.getAddress() });
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
|
|
580
|
+
exports.OperatorLifecycle = OperatorLifecycle;
|
|
581
|
+
exports.PaymasterOperatorClient = PaymasterOperatorClient;
|
|
582
|
+
exports.ProposalState = ProposalState;
|
|
583
|
+
exports.ProtocolClient = ProtocolClient;
|
|
584
|
+
//# sourceMappingURL=chunk-MRREGCWN.cjs.map
|
|
585
|
+
//# sourceMappingURL=chunk-MRREGCWN.cjs.map
|