From 7da828fde5915b78f7fb8f022de7a786e59c6506 Mon Sep 17 00:00:00 2001 From: msinkec Date: Thu, 7 Dec 2023 11:47:30 +0100 Subject: [PATCH] Fix bsv 20 lock neg supply. --- src/contracts/bsv20Mint.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/contracts/bsv20Mint.ts b/src/contracts/bsv20Mint.ts index 22e96db9..c7719b0c 100644 --- a/src/contracts/bsv20Mint.ts +++ b/src/contracts/bsv20Mint.ts @@ -55,18 +55,21 @@ export class BSV20Mint extends BSV20V2 { // Check mint amount doesn't exceed maximum. assert(amount <= this.maxMintAmount, 'mint amount exceeds maximum') - // Update supply. - this.supply -= amount - - // If there are still tokens left, then - // build state output inscribed with leftover tokens. let outputs = toByteString('') + let transferAmt = amount + if (this.supply > 0n) { + // If there are still tokens left, then update supply and + // build state output inscribed with leftover tokens. + this.supply -= transferAmt outputs += this.buildStateOutputFT(this.supply) + } else { + // If not, then transfer all the remaining supply. + transferAmt = this.supply } // Build FT P2PKH output to dest paying specified amount of tokens. - outputs += BSV20V2.buildTransferOutput(dest, this.id, amount) + outputs += BSV20V2.buildTransferOutput(dest, this.id, transferAmt) // Build change output. outputs += this.buildChangeOutput()