Skip to content

Commit

Permalink
GSW-1845 feat: skip minting gns block, if emission is ended
Browse files Browse the repository at this point in the history
  • Loading branch information
r3v4s committed Dec 20, 2024
1 parent 0bfd2cd commit 3588325
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
21 changes: 9 additions & 12 deletions _deploy/r/gnoswap/gns/gns.gno
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ func MintGns(address pusers.AddressOrName) uint64 {
lastMintedHeight := GetLastMintedHeight()
currentHeight := std.GetHeight()

// skip minting process if gns for current block is already minted
if skipIfSameHeight(lastMintedHeight, currentHeight) {
// skip minting process if following conditions are met
// - if gns for current block is already minted
// - if emission has ended
if skipIfSameHeight(lastMintedHeight, currentHeight) || skipIfEmissionEnded(currentHeight) {
return 0
}

Expand Down Expand Up @@ -146,10 +148,6 @@ func calculateAmountToMint(fromHeight, toHeight int64) uint64 {
fromYear := GetHalvingYearByHeight(fromHeight)
toYear := GetHalvingYearByHeight(toHeight)

if isEmissionEnded(fromYear) || isEmissionEnded(toYear) {
return 0
}

totalAmountToMint := uint64(0)

for i := fromYear; i <= toYear; i++ {
Expand Down Expand Up @@ -199,14 +197,13 @@ func skipIfSameHeight(lastMintedHeight, currentHeight int64) bool {
return lastMintedHeight == currentHeight
}

// isEmissionEnded returns true if the emission is ended.
// It returns false if the emission is not ended.
func isEmissionEnded(year int64) bool {
if 1 <= year && year <= 12 {
return false
// skipIfEmissionEnded returns true if the emission has ended.
func skipIfEmissionEnded(height int64) bool {
if isEmissionEnded(height) {
return true
}

return true
return false
}

// Getter
Expand Down
10 changes: 10 additions & 0 deletions _deploy/r/gnoswap/gns/gns_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ func TestSkipIfSameHeight(t *testing.T) {
})
}

func TestSkipIfEmissionEnded(t *testing.T) {
t.Run("should skip if emission has ended", func(t *testing.T) {
uassert.True(t, skipIfEmissionEnded(GetEndHeight()+1))
})

t.Run("should not skip if emission has not ended", func(t *testing.T) {
uassert.False(t, skipIfEmissionEnded(std.GetHeight()))
})
}

func TestGetterSetter(t *testing.T) {
t.Run("last minted height", func(t *testing.T) {
value := int64(1234)
Expand Down

0 comments on commit 3588325

Please sign in to comment.