Skip to content

Commit

Permalink
feat: skip minting gns block
Browse files Browse the repository at this point in the history
- if emission is ended
  • Loading branch information
r3v4s committed Dec 16, 2024
1 parent dccd16c commit b93deb8
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 @@ -52,8 +52,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 @@ -142,10 +144,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 @@ -205,14 +203,13 @@ func skipIfSameHeight(lastMintedHeight, currentHeight int64) bool {
return false
}

// 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
}

func GetLastMintedHeight() int64 {
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 b93deb8

Please sign in to comment.