Skip to content

Commit

Permalink
fix amount encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
hundredark committed Nov 28, 2024
1 parent e262a1c commit 1e2337e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/client/utils/amount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export const formatUnits = (amount: string | number, unit: number) => {
};
export const parseUnits = (amount: string | number, unit: number) => {
const m = getMultiplier(unit);
return BigNumber(amount).times(m);
return BigNumber(amount).times(m).integerValue(BigNumber.ROUND_FLOOR);
};
6 changes: 3 additions & 3 deletions src/client/utils/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class Encoder {
this.write(tx);

this.writeUint64(d.index);
this.writeInteger(parseUnits(Number(d.amount).toFixed(8), 8));
this.writeInteger(parseUnits(d.amount, 8));
}
const m = i.mint;
if (typeof m === 'undefined') {
Expand All @@ -151,15 +151,15 @@ export class Encoder {
this.write(Buffer.from(m.group));

this.writeUint64(m.batch);
this.writeInteger(parseUnits(Number(m.amount).toFixed(8), 8));
this.writeInteger(parseUnits(m.amount, 8));
}
}

encodeOutput(output: Output) {
const o = output;
if (!o.type) o.type = 0;
this.write(Buffer.from([0x00, o.type]));
this.writeInteger(parseUnits(Number(o.amount).toFixed(8), 8));
this.writeInteger(parseUnits(o.amount, 8));

this.writeInt(o.keys.length);
o.keys.forEach(k => this.write(Buffer.from(k, 'hex')));
Expand Down

0 comments on commit 1e2337e

Please sign in to comment.