Skip to content

Commit

Permalink
Fix bsv 20 lock neg supply.
Browse files Browse the repository at this point in the history
  • Loading branch information
msinkec committed Dec 7, 2023
1 parent d34aee3 commit 7da828f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/contracts/bsv20Mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 7da828f

Please sign in to comment.