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()