anchor-sdk 0.1.41-internal.0 → 0.1.41-internal.2

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.
@@ -1,4 +1,4 @@
1
- import { BadgeCheckRequest, BadgeClaimSignatureRequest, BadgeSingleCheckRequest, BadgesCheckRequest, BatchMintRequestVO, CheckEventRequest, MintResponse, NFTMintRequestVO, PurchaseRequest, QueryAssetsRequest, UserOpHashProcessRequest, WebResultAssetsBadgeResponse, WebResultBadgeAssetsResponse, WebResultBadgeCheckResponse, WebResultBadgeClaimSignatureResponse, WebResultBadgeClaimableListResponse, WebResultBadgeDetailResponse, WebResultBadgeResponse, WebResultBadgeSeriesDetailResponse, WebResultBadgeSeriesResponse, WebResultBadgeVerifiersResponse, WebResultBadgesCheckResponse, WebResultCheckEventResponse, WebResultCheckResponse, WebResultCheckResultResponse, WebResultGrantBadgeRequestVO, WebResultGrantBadgeResponseVO, WebResultListSeasonConfigVO, WebResultNftSeriesDetailResponse, WebResultNftSeriesResponse, WebResultPurchaseResponse, WebResultTransactionHashProcess, WebResultUserOpHashProcess } from "./generated/Api";
1
+ import { BadgeClaimSignatureRequest, BadgeSingleCheckRequest, BatchMintRequestVO, MintResponse, NFTMintRequestVO, UserOpHashProcessRequest, WebResultBadgeAssetsResponse, WebResultBadgeCheckResponse, WebResultBadgeClaimSignatureResponse, WebResultBadgeClaimableListResponse, WebResultBadgeDetailResponse, WebResultBadgeSeriesDetailResponse, WebResultBadgeSeriesResponse, WebResultBadgeVerifiersResponse, WebResultTransactionHashProcess, WebResultUserOpHashProcess } from "./generated/Api";
2
2
  import { Chain } from "viem";
3
3
  /**
4
4
  * Anchor API V2 客户端配置
@@ -99,7 +99,7 @@ export declare class AnchorApiClientV2 {
99
99
  /**
100
100
  * 获取用户徽章资产
101
101
  * @param params 查询参数
102
- * @param params.status 徽章状态过滤器 pending/claimable/claimed
102
+ * @param params.includeClaimable 徽章状态是否包含可领取
103
103
  * @param params.strategy 返回策略 BADGE_ALL/BADGE_MAX/BADGE_REWARD
104
104
  * @param params.series 徽章系列过滤器
105
105
  * @param params.limit 每页项目数
@@ -107,9 +107,9 @@ export declare class AnchorApiClientV2 {
107
107
  * @returns 徽章资产响应
108
108
  */
109
109
  getUserBadgeAssets(params?: {
110
- status?: string;
110
+ includeClaimable?: boolean;
111
111
  strategy?: string;
112
- series?: string;
112
+ series?: string[];
113
113
  limit?: number;
114
114
  nextToken?: string;
115
115
  }): Promise<WebResultBadgeAssetsResponse>;
@@ -143,7 +143,7 @@ export declare class AnchorApiClientV2 {
143
143
  * @param data 徽章检查请求
144
144
  * @returns 徽章检查响应
145
145
  */
146
- checkUserClaimableBadges(data: BadgeCheckRequest): Promise<WebResultBadgeCheckResponse>;
146
+ checkUserClaimableBadges(data: object): Promise<WebResultBadgeCheckResponse>;
147
147
  /**
148
148
  * 获取徽章领取签名
149
149
  * @param data 徽章领取签名请求
@@ -179,54 +179,6 @@ export declare class AnchorApiClientV2 {
179
179
  * @returns 批量铸造响应
180
180
  */
181
181
  batchMint(type: string, data: BatchMintRequestVO): Promise<MintResponse>;
182
- /**
183
- * 根据 ID 获取 NFT 系列
184
- * @param type NFT 类型
185
- * @param series 系列标识符
186
- * @param customerId 客户 ID
187
- * @returns NFT 系列详情响应
188
- */
189
- getNftSeriesById(type: string, series: string, customerId?: string): Promise<WebResultNftSeriesDetailResponse>;
190
- /**
191
- * 获取 NFT 系列
192
- * @param type NFT 类型
193
- * @returns NFT 系列响应
194
- */
195
- nftSeries(type: string): Promise<WebResultNftSeriesResponse>;
196
- /**
197
- * Anchor 检查
198
- * @param type 检查类型
199
- * @returns 检查响应
200
- */
201
- check(type: string): Promise<WebResultCheckResponse>;
202
- /**
203
- * 获取检查结果
204
- * @param type 检查类型
205
- * @returns 检查结果响应
206
- */
207
- getCheckResult(type: string): Promise<WebResultCheckResultResponse>;
208
- /**
209
- * 获取赛季配置列表
210
- * @returns 赛季配置列表响应
211
- */
212
- listSeasonConfig(): Promise<WebResultListSeasonConfigVO>;
213
- /**
214
- * 查询用户可领取或已领取的徽章
215
- * @param customerId 客户 ID
216
- * @param status 徽章状态
217
- * @param strategy 返回策略
218
- * @param series 徽章系列
219
- * @param limit 每页条数
220
- * @param nextToken 分页参数
221
- * @returns 徽章响应
222
- */
223
- badgeAssets(customerId?: string, status?: string, strategy?: string, series?: string, limit?: number, nextToken?: string): Promise<WebResultBadgeResponse>;
224
- /**
225
- * 处理用户操作哈希
226
- * @param data 用户操作哈希处理请求
227
- * @returns 用户操作哈希处理响应
228
- */
229
- userOpHashProcess(data: UserOpHashProcessRequest): Promise<WebResultUserOpHashProcess>;
230
182
  /**
231
183
  * 处理交易哈希(加速交易处理)
232
184
  * @param txHash 交易哈希
@@ -234,43 +186,9 @@ export declare class AnchorApiClientV2 {
234
186
  */
235
187
  transactionHashProcess(txHash: string): Promise<WebResultTransactionHashProcess>;
236
188
  /**
237
- * 授予徽章
238
- * @param data 授予徽章请求
239
- * @returns 授予徽章响应
240
- */
241
- grantBadge(data: WebResultGrantBadgeRequestVO): Promise<WebResultGrantBadgeResponseVO>;
242
- /**
243
- * 购买铸造(带签名)
244
- * @param type 购买类型
245
- * @param data 购买请求数据
246
- * @returns 购买响应
247
- */
248
- purchaseMint(type: string, data: PurchaseRequest): Promise<WebResultPurchaseResponse>;
249
- /**
250
- * 查询资产
251
- * @param type 资产类型
252
- * @param data 查询请求数据
253
- * @returns 资产响应
254
- */
255
- queryAssets(type: string, data: QueryAssetsRequest): Promise<WebResultAssetsBadgeResponse>;
256
- /**
257
- * 根据 ID 获取 NFT 系列详情
258
- * @param type NFT 类型
259
- * @param series 系列标识符
260
- * @param customerId 客户 ID
261
- * @returns NFT 系列详情响应
262
- */
263
- getNftSeriesDetail(type: string, series: string, customerId?: string): Promise<WebResultNftSeriesDetailResponse>;
264
- /**
265
- * 根据事件检查
266
- * @param data 检查事件请求
267
- * @returns 检查事件响应
268
- */
269
- checkByEvent(data: CheckEventRequest): Promise<WebResultCheckEventResponse>;
270
- /**
271
- * 徽章检查
272
- * @param data 徽章检查请求
273
- * @returns 徽章检查响应
189
+ * 处理用户操作哈希
190
+ * @param data 用户操作哈希处理请求
191
+ * @returns 用户操作哈希处理响应
274
192
  */
275
- badgesCheck(data: BadgesCheckRequest): Promise<WebResultBadgesCheckResponse>;
193
+ userOpHashProcess(data: UserOpHashProcessRequest): Promise<WebResultUserOpHashProcess>;
276
194
  }
@@ -165,7 +165,7 @@ class AnchorApiClientV2 {
165
165
  /**
166
166
  * 获取用户徽章资产
167
167
  * @param params 查询参数
168
- * @param params.status 徽章状态过滤器 pending/claimable/claimed
168
+ * @param params.includeClaimable 徽章状态是否包含可领取
169
169
  * @param params.strategy 返回策略 BADGE_ALL/BADGE_MAX/BADGE_REWARD
170
170
  * @param params.series 徽章系列过滤器
171
171
  * @param params.limit 每页项目数
@@ -276,92 +276,7 @@ class AnchorApiClientV2 {
276
276
  return response.data;
277
277
  });
278
278
  }
279
- // ==================== V1 API Methods ====================
280
- /**
281
- * 根据 ID 获取 NFT 系列
282
- * @param type NFT 类型
283
- * @param series 系列标识符
284
- * @param customerId 客户 ID
285
- * @returns NFT 系列详情响应
286
- */
287
- async getNftSeriesById(type, series, customerId) {
288
- return this.handleApiCall(async () => {
289
- const query = customerId ? { customerId } : undefined;
290
- const response = await this.generatedApi.v1.getNftSeriesById(type, series, query, this.getRequestParams());
291
- return response.data;
292
- });
293
- }
294
- /**
295
- * 获取 NFT 系列
296
- * @param type NFT 类型
297
- * @returns NFT 系列响应
298
- */
299
- async nftSeries(type) {
300
- return this.handleApiCall(async () => {
301
- const response = await this.generatedApi.v1.nftSeries(type, this.getRequestParams());
302
- return response.data;
303
- });
304
- }
305
- /**
306
- * Anchor 检查
307
- * @param type 检查类型
308
- * @returns 检查响应
309
- */
310
- async check(type) {
311
- return this.handleApiCall(async () => {
312
- const response = await this.generatedApi.v1.check(type, this.getRequestParams());
313
- return response.data;
314
- });
315
- }
316
- /**
317
- * 获取检查结果
318
- * @param type 检查类型
319
- * @returns 检查结果响应
320
- */
321
- async getCheckResult(type) {
322
- return this.handleApiCall(async () => {
323
- const response = await this.generatedApi.v1.getCheckResult(type, this.getRequestParams());
324
- return response.data;
325
- });
326
- }
327
- /**
328
- * 获取赛季配置列表
329
- * @returns 赛季配置列表响应
330
- */
331
- async listSeasonConfig() {
332
- return this.handleApiCall(async () => {
333
- const response = await this.generatedApi.v1.listSeasonConfig(this.getRequestParams());
334
- return response.data;
335
- });
336
- }
337
- /**
338
- * 查询用户可领取或已领取的徽章
339
- * @param customerId 客户 ID
340
- * @param status 徽章状态
341
- * @param strategy 返回策略
342
- * @param series 徽章系列
343
- * @param limit 每页条数
344
- * @param nextToken 分页参数
345
- * @returns 徽章响应
346
- */
347
- async badgeAssets(customerId, status, strategy, series, limit, nextToken) {
348
- return this.handleApiCall(async () => {
349
- const query = { customerId, status, strategy, series, limit, nextToken };
350
- const response = await this.generatedApi.v1.badgeAssets(query, this.getRequestParams());
351
- return response.data;
352
- });
353
- }
354
- /**
355
- * 处理用户操作哈希
356
- * @param data 用户操作哈希处理请求
357
- * @returns 用户操作哈希处理响应
358
- */
359
- async userOpHashProcess(data) {
360
- return this.handleApiCall(async () => {
361
- const response = await this.generatedApi.v1.userOpHashProcess(data, this.getRequestParams());
362
- return response.data;
363
- });
364
- }
279
+ // ==================== Transaction Methods ====================
365
280
  /**
366
281
  * 处理交易哈希(加速交易处理)
367
282
  * @param txHash 交易哈希
@@ -373,75 +288,14 @@ class AnchorApiClientV2 {
373
288
  return response.data;
374
289
  });
375
290
  }
376
- // ==================== S1 API Methods ====================
377
- /**
378
- * 授予徽章
379
- * @param data 授予徽章请求
380
- * @returns 授予徽章响应
381
- */
382
- async grantBadge(data) {
383
- return this.handleApiCall(async () => {
384
- const response = await this.generatedApi.s1.grantBadge(data, this.getRequestParams());
385
- return response.data;
386
- });
387
- }
388
- /**
389
- * 购买铸造(带签名)
390
- * @param type 购买类型
391
- * @param data 购买请求数据
392
- * @returns 购买响应
393
- */
394
- async purchaseMint(type, data) {
395
- return this.handleApiCall(async () => {
396
- const response = await this.generatedApi.s1.purchaseMint(type, data, this.getRequestParams());
397
- return response.data;
398
- });
399
- }
400
- /**
401
- * 查询资产
402
- * @param type 资产类型
403
- * @param data 查询请求数据
404
- * @returns 资产响应
405
- */
406
- async queryAssets(type, data) {
407
- return this.handleApiCall(async () => {
408
- const response = await this.generatedApi.s1.queryAssets(type, data, this.getRequestParams());
409
- return response.data;
410
- });
411
- }
412
291
  /**
413
- * 根据 ID 获取 NFT 系列详情
414
- * @param type NFT 类型
415
- * @param series 系列标识符
416
- * @param customerId 客户 ID
417
- * @returns NFT 系列详情响应
418
- */
419
- async getNftSeriesDetail(type, series, customerId) {
420
- return this.handleApiCall(async () => {
421
- const query = customerId ? { customerId } : undefined;
422
- const response = await this.generatedApi.s1.getNftSeriesDetail(type, series, query, this.getRequestParams());
423
- return response.data;
424
- });
425
- }
426
- /**
427
- * 根据事件检查
428
- * @param data 检查事件请求
429
- * @returns 检查事件响应
430
- */
431
- async checkByEvent(data) {
432
- return this.handleApiCall(async () => {
433
- const response = await this.generatedApi.s1.checkByEvent(data, this.getRequestParams());
434
- return response.data;
435
- });
436
- }
437
- /**
438
- * 徽章检查
439
- * @param data 徽章检查请求
440
- * @returns 徽章检查响应
292
+ * 处理用户操作哈希
293
+ * @param data 用户操作哈希处理请求
294
+ * @returns 用户操作哈希处理响应
441
295
  */
442
- async badgesCheck(data) {
296
+ async userOpHashProcess(data) {
443
297
  return this.handleApiCall(async () => {
444
- const response = await this.generatedApi.s1.badgesCheck(data, this.getRequestParams());
298
+ const response = await this.generatedApi.v1.userOpHashProcess(data, this.getRequestParams());
445
299
  return response.data;
446
300
  });
447
301
  }
@@ -102,6 +102,14 @@ class AnchorERC1155Client {
102
102
  if (!this.walletClient || !this.account) {
103
103
  throw new Error("Wallet client and account are required to send transactions");
104
104
  }
105
+ // 估算 gas 和费用
106
+ const { maxFeePerGas, maxPriorityFeePerGas } = await this.publicClient.estimateFeesPerGas();
107
+ const gas = await this.publicClient.estimateGas({
108
+ to: contractAddress,
109
+ data: data,
110
+ value: 0n,
111
+ account: this.account,
112
+ });
105
113
  const txHash = await this.walletClient.writeContract({
106
114
  account: this.account,
107
115
  address: contractAddress,
@@ -111,7 +119,10 @@ class AnchorERC1155Client {
111
119
  this.formatMintRequest(signedRequest.request),
112
120
  signedRequest.signature,
113
121
  ],
114
- chain: null,
122
+ chain: this.publicClient.chain,
123
+ maxFeePerGas,
124
+ maxPriorityFeePerGas,
125
+ gas,
115
126
  });
116
127
  const receipt = await this.publicClient.waitForTransactionReceipt({
117
128
  hash: txHash,
@@ -1,4 +1,4 @@
1
- import { Address, Hex, PublicClient, WalletClient, Account, TransactionReceipt, Chain } from "viem";
1
+ import { Account, Address, Chain, Hex, PublicClient, TransactionReceipt, WalletClient } from "viem";
2
2
  import { PaymentOptions } from "./types";
3
3
  /**
4
4
  * AnchorPay 客户端
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.AnchorPayClient = void 0;
7
7
  const viem_1 = require("viem");
8
- const AnchorPay_json_1 = __importDefault(require("./abi/AnchorPay.json"));
9
8
  const constants_1 = require("./constants");
9
+ const AnchorPay_json_1 = __importDefault(require("./abi/AnchorPay.json"));
10
10
  /**
11
11
  * AnchorPay 客户端
12
12
  * 用于与 AnchorPay 合约交互
@@ -34,39 +34,51 @@ class AnchorPayClient {
34
34
  * @param options 交易选项
35
35
  * @returns 交易收据或交易数据
36
36
  */
37
- async sendETH(recipient, amount, data = '0x', options) {
37
+ async sendETH(recipient, amount, data = "0x", options) {
38
38
  // 如果需要发送交易,但没有钱包客户端或账户
39
- if (options?.sendTransaction !== false && (!this.walletClient || !this.account)) {
39
+ if (options?.sendTransaction !== false &&
40
+ (!this.walletClient || !this.account)) {
40
41
  throw new Error("Wallet client and account are required to send transactions");
41
42
  }
42
43
  // 准备交易数据
43
44
  const calldata = (0, viem_1.encodeFunctionData)({
44
45
  abi: AnchorPay_json_1.default,
45
- functionName: 'send',
46
- args: [recipient, constants_1.NATIVE_TOKEN_ADDRESS, amount, data]
46
+ functionName: "send",
47
+ args: [recipient, constants_1.NATIVE_TOKEN_ADDRESS, amount, data],
47
48
  });
48
49
  // 如果不需要发送交易,只返回交易数据(AA 模式)
49
50
  if (options?.sendTransaction === false) {
50
51
  return {
51
52
  to: this.contracts?.anchorPay || "",
52
53
  data: calldata,
53
- value: amount
54
+ value: amount,
54
55
  };
55
56
  }
57
+ // 估算 gas 和费用
58
+ const { maxFeePerGas, maxPriorityFeePerGas } = await this.publicClient.estimateFeesPerGas();
59
+ const gas = await this.publicClient.estimateGas({
60
+ to: this.contracts?.anchorPay || "",
61
+ data: calldata,
62
+ value: amount,
63
+ account: this.account,
64
+ });
56
65
  // 发送交易(EOA 模式)
66
+ if (!this.walletClient || !this.account) {
67
+ throw new Error("Wallet client and account are required to send transactions");
68
+ }
57
69
  const txHash = await this.walletClient.sendTransaction({
58
70
  account: this.account,
59
71
  to: this.contracts?.anchorPay || "",
60
72
  data: calldata,
61
73
  value: amount,
62
- maxFeePerGas: options?.maxFeePerGas,
63
- maxPriorityFeePerGas: options?.maxPriorityFeePerGas,
64
- gas: options?.gas,
65
- chain: null
74
+ maxFeePerGas: options?.maxFeePerGas || maxFeePerGas,
75
+ maxPriorityFeePerGas: options?.maxPriorityFeePerGas || maxPriorityFeePerGas,
76
+ gas: options?.gas || gas,
77
+ chain: this.publicClient.chain,
66
78
  });
67
79
  // 等待交易确认并返回收据
68
80
  const receipt = await this.publicClient.waitForTransactionReceipt({
69
- hash: txHash
81
+ hash: txHash,
70
82
  });
71
83
  return receipt;
72
84
  }
@@ -79,38 +91,57 @@ class AnchorPayClient {
79
91
  * @param options 交易选项
80
92
  * @returns 交易收据或交易数据
81
93
  */
82
- async sendERC20(recipient, tokenAddress, amount, data = '0x', options) {
94
+ async sendERC20(recipient, tokenAddress, amount, data = "0x", options) {
83
95
  // 如果需要发送交易,但没有钱包客户端或账户
84
- if (options?.sendTransaction !== false && (!this.walletClient || !this.account)) {
96
+ if (options?.sendTransaction !== false &&
97
+ (!this.walletClient || !this.account)) {
85
98
  throw new Error("Wallet client and account are required to send transactions");
86
99
  }
87
100
  // 如果需要自动批准,则先批准代币(默认开启自动批准)
88
- if ((options?.autoApprove !== false) && this.walletClient && this.account) {
101
+ if (options?.autoApprove !== false && this.walletClient && this.account) {
89
102
  try {
90
103
  console.log(`Checking ERC20 token approval status: ${tokenAddress}`);
91
104
  // 检查授权
92
- const allowance = await this.publicClient.readContract({
105
+ const allowance = (await this.publicClient.readContract({
93
106
  address: tokenAddress,
94
107
  abi: constants_1.ERC20_ABI,
95
- functionName: 'allowance',
96
- args: [this.account.address, this.contracts?.anchorPay]
97
- });
108
+ functionName: "allowance",
109
+ args: [this.account.address, this.contracts?.anchorPay],
110
+ }));
98
111
  console.log(`Current allowance: ${allowance}, Required amount: ${amount}, AnchorPay contract address: ${this.contracts?.anchorPay}`);
99
112
  if (allowance < amount) {
100
113
  console.log(`Approving ${amount} tokens to AnchorPay contract...`);
101
114
  // 批准代币 - 使用最大可能值进行授权,避免多次授权
102
115
  const maxApproveAmount = 2n ** 256n - 1n;
116
+ // 估算 gas 和费用
117
+ const { maxFeePerGas: approveMaxFeePerGas, maxPriorityFeePerGas: approveMaxPriorityFeePerGas, } = await this.publicClient.estimateFeesPerGas();
118
+ const approveCalldata = (0, viem_1.encodeFunctionData)({
119
+ abi: constants_1.ERC20_ABI,
120
+ functionName: "approve",
121
+ args: [this.contracts?.anchorPay, maxApproveAmount],
122
+ });
123
+ const approveGas = await this.publicClient.estimateGas({
124
+ to: tokenAddress,
125
+ data: approveCalldata,
126
+ value: 0n,
127
+ account: this.account,
128
+ });
103
129
  const approveTxHash = await this.walletClient.writeContract({
104
130
  account: this.account,
105
131
  address: tokenAddress,
106
132
  abi: constants_1.ERC20_ABI,
107
- functionName: 'approve',
133
+ functionName: "approve",
108
134
  args: [this.contracts?.anchorPay, maxApproveAmount],
109
- chain: null
135
+ chain: this.publicClient.chain,
136
+ maxFeePerGas: approveMaxFeePerGas,
137
+ maxPriorityFeePerGas: approveMaxPriorityFeePerGas,
138
+ gas: approveGas,
110
139
  });
111
140
  console.log(`Approval transaction sent, hash: ${approveTxHash}`);
112
141
  // 等待交易确认
113
- await this.publicClient.waitForTransactionReceipt({ hash: approveTxHash });
142
+ await this.publicClient.waitForTransactionReceipt({
143
+ hash: approveTxHash,
144
+ });
114
145
  console.log(`Approval transaction confirmed`);
115
146
  }
116
147
  else {
@@ -125,31 +156,42 @@ class AnchorPayClient {
125
156
  // 准备交易数据
126
157
  const calldata = (0, viem_1.encodeFunctionData)({
127
158
  abi: AnchorPay_json_1.default,
128
- functionName: 'send',
129
- args: [recipient, tokenAddress, amount, data]
159
+ functionName: "send",
160
+ args: [recipient, tokenAddress, amount, data],
130
161
  });
131
162
  // 如果不需要发送交易,只返回交易数据(AA 模式)
132
163
  if (options?.sendTransaction === false) {
133
164
  return {
134
165
  to: this.contracts?.anchorPay || "",
135
166
  data: calldata,
136
- value: 0n
167
+ value: 0n,
137
168
  };
138
169
  }
170
+ // 估算 gas 和费用
171
+ const { maxFeePerGas, maxPriorityFeePerGas } = await this.publicClient.estimateFeesPerGas();
172
+ const gas = await this.publicClient.estimateGas({
173
+ to: this.contracts?.anchorPay || "",
174
+ data: calldata,
175
+ value: 0n,
176
+ account: this.account,
177
+ });
139
178
  // 发送交易(EOA 模式)
179
+ if (!this.walletClient || !this.account) {
180
+ throw new Error("Wallet client and account are required to send transactions");
181
+ }
140
182
  const txHash = await this.walletClient.sendTransaction({
141
183
  account: this.account,
142
184
  to: this.contracts?.anchorPay || "",
143
185
  data: calldata,
144
186
  // value: amount,
145
- maxFeePerGas: options?.maxFeePerGas,
146
- maxPriorityFeePerGas: options?.maxPriorityFeePerGas,
147
- gas: options?.gas,
148
- chain: null
187
+ maxFeePerGas: options?.maxFeePerGas || maxFeePerGas,
188
+ maxPriorityFeePerGas: options?.maxPriorityFeePerGas || maxPriorityFeePerGas,
189
+ gas: options?.gas || gas,
190
+ chain: this.publicClient.chain,
149
191
  });
150
192
  // 等待交易确认并返回收据
151
193
  const receipt = await this.publicClient.waitForTransactionReceipt({
152
- hash: txHash
194
+ hash: txHash,
153
195
  });
154
196
  return receipt;
155
197
  }
@@ -160,12 +202,12 @@ class AnchorPayClient {
160
202
  * @returns 实现者地址
161
203
  */
162
204
  async getInterfaceImplementer(account, interfaceHash) {
163
- return await this.publicClient.readContract({
205
+ return (await this.publicClient.readContract({
164
206
  address: this.contracts?.anchorPay || "",
165
207
  abi: AnchorPay_json_1.default,
166
- functionName: 'getInterfaceImplementer',
167
- args: [account, interfaceHash]
168
- });
208
+ functionName: "getInterfaceImplementer",
209
+ args: [account, interfaceHash],
210
+ }));
169
211
  }
170
212
  /**
171
213
  * 设置接口实现者(仅限管理员)
@@ -178,17 +220,33 @@ class AnchorPayClient {
178
220
  if (!this.walletClient || !this.account) {
179
221
  throw new Error("Wallet client and account are required to send transactions");
180
222
  }
223
+ // 估算 gas 和费用
224
+ const { maxFeePerGas, maxPriorityFeePerGas } = await this.publicClient.estimateFeesPerGas();
225
+ const calldata = (0, viem_1.encodeFunctionData)({
226
+ abi: AnchorPay_json_1.default,
227
+ functionName: "setInterfaceImplementer",
228
+ args: [account, interfaceHash, implementer],
229
+ });
230
+ const gas = await this.publicClient.estimateGas({
231
+ to: this.contracts?.anchorPay || "",
232
+ data: calldata,
233
+ value: 0n,
234
+ account: this.account,
235
+ });
181
236
  const txHash = await this.walletClient.writeContract({
182
237
  account: this.account,
183
238
  address: this.contracts?.anchorPay || "",
184
239
  abi: AnchorPay_json_1.default,
185
- functionName: 'setInterfaceImplementer',
240
+ functionName: "setInterfaceImplementer",
186
241
  args: [account, interfaceHash, implementer],
187
- chain: null
242
+ chain: this.publicClient.chain,
243
+ maxFeePerGas,
244
+ maxPriorityFeePerGas,
245
+ gas,
188
246
  });
189
247
  // 等待交易确认并返回收据
190
248
  const receipt = await this.publicClient.waitForTransactionReceipt({
191
- hash: txHash
249
+ hash: txHash,
192
250
  });
193
251
  return receipt;
194
252
  }
@@ -200,17 +258,17 @@ class AnchorPayClient {
200
258
  * @returns 交易数据对象,包含 to、data 和 value 字段
201
259
  */
202
260
  getERC20ApprovalData(tokenAddress, amount, spender) {
203
- const approveSpender = spender || (this.contracts?.anchorPay || "");
261
+ const approveSpender = spender || this.contracts?.anchorPay || "";
204
262
  // 编码 approve 函数调用
205
263
  const data = (0, viem_1.encodeFunctionData)({
206
264
  abi: constants_1.ERC20_ABI,
207
- functionName: 'approve',
208
- args: [approveSpender, amount]
265
+ functionName: "approve",
266
+ args: [approveSpender, amount],
209
267
  });
210
268
  return {
211
269
  to: tokenAddress,
212
270
  data,
213
- value: 0n // ERC20 批准不需要发送 ETH
271
+ value: 0n, // ERC20 批准不需要发送 ETH
214
272
  };
215
273
  }
216
274
  }