Skip to content

Commit 3d6206b

Browse files
authored
Merge pull request #9 from PolyhedraZK/fix/withdraw-amount-in-relayer-request
fix(ops): send net recipient amount as burn_amount in withdraw request
2 parents 0a98299 + e4be8fa commit 3d6206b

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/ops/ops.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ export class Ops implements OpsApi {
500500
array_hash_index: arrayHashIndex,
501501
relayer: typedPlan.relayer,
502502
recipient: input.recipient,
503-
withdraw_amount: burnAmount,
503+
withdraw_amount: BigInt(typedPlan.requestedAmount),
504504
relayer_fee: relayerFee,
505505
gas_drop_value: gasDropValue,
506506
extra_data: extraData,

tests/opsPrepare.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,10 @@ describe('Ops.prepareTransfer / Ops.prepareWithdraw', () => {
378378

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

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

0 commit comments

Comments
 (0)