Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ops/ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ export class Ops implements OpsApi {
array_hash_index: arrayHashIndex,
relayer: typedPlan.relayer,
recipient: input.recipient,
withdraw_amount: burnAmount,
withdraw_amount: BigInt(typedPlan.requestedAmount),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

这个修复是正确的,符合 PR 描述中的根因分析。

有一个小建议:根据 src/types.tsWithdrawPlan 的类型定义,typedPlan.requestedAmount 的类型已经是 bigint,所以这里的 BigInt() 包装是多余的,可以移除以使代码更简洁。

Suggested change
withdraw_amount: BigInt(typedPlan.requestedAmount),
withdraw_amount: typedPlan.requestedAmount,

relayer_fee: relayerFee,
gas_drop_value: gasDropValue,
extra_data: extraData,
Expand Down
7 changes: 5 additions & 2 deletions tests/opsPrepare.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,10 @@ describe('Ops.prepareTransfer / Ops.prepareWithdraw', () => {

expect(planner.plan).toHaveBeenCalled();
expect(merkle.getProofByCids).toHaveBeenCalledWith({ chainId, cids: [10], totalElements: 5n });
expect(zkp.proveWithdraw).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({ recipient, withdraw_amount: burnAmount }));
// withdraw_amount in the proof context must be the net recipient amount (requestedAmount),
// NOT burnAmount. The contract computes amountWithFee = inp.amount + protocolFee + relayerFee,
// which equals burnAmount only when inp.amount = requestedAmount (net).
expect(zkp.proveWithdraw).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({ recipient, withdraw_amount: plan.requestedAmount }));

expect(res.meta.arrayHashIndex).toBe(4);
expect(res.meta.merkleRootIndex).toBe(1);
Expand All @@ -388,7 +391,7 @@ describe('Ops.prepareTransfer / Ops.prepareWithdraw', () => {
expect(res.witness.asset_policy.viewer_pk).toMatchObject({ EncryptionKey: { Key: { X: 1n, Y: 2n } } });
expect(res.witness.asset_policy.freezer_pk).toMatchObject({ Point: { X: 3n, Y: 4n } });
expect(res.request.path).toBe('/api/v1/burn');
expect((res.request.body as any).burn_amount).toBe(burnAmount.toString());
expect((res.request.body as any).burn_amount).toBe(plan.requestedAmount.toString());
expect((res.request.body as any).gas_drop_value).toBe(gasDropValue.toString());
expect((res.request.body as any).relayer_fee).toBe(relayerFee.toString());
});
Expand Down