Skip to content

Commit

Permalink
refactor(staker): add in-range staked liquidity tracker (#438)
Browse files Browse the repository at this point in the history
* refactor, test: calculateCollectReward
* helper test
* change getTokenPairBalanceFromPosition params
* update doc
* change emit param name
* remove function prefix from panic
* pool tier reward cache, pool reward cache, halving, warmup
* chore: remove `Pool` prefix from pool's receiver getter (#423)
* GSW-1838 test: swap_math unitest
* test: define test helper function
* test: remove unnecessary initialization
* refactor: Use Clone data in function calls to protect original data
* GSW-1838 test: sqrt_price_math unitest (#425)
* refactor: sqrt_price_math
- added testcase
* refactor: add test code and comments
* refactor: Overflow check for type conversion to int256 in delta amount calculation
* refactor: dry swap (#421)
* remove duplicate functions
* GSW-1838 refactor: Using the new constructor to protect raw data in sqrtRatio calculations
* GSW-1838 refactor: need to lock pool.slot0 to prevent re-entry
* refactor: Using clone data to protect original data
* refactor: remove unused import
* fix: sqrtRatio calculation default value issue
* refactor: swap and swap math
* refactor: computeSwapStep
- edge case test (amount : zero and over liquidity)
- EXACT IN / EXACT OUT Case
* refactor: Separate pool transfer-related test code
* refactor: Rename a receiver function param and liquidity math bug fix
- Fix absolute value before checking if delta value is negative to fix handling error issue if negative.
- Rename the param in the receiver function from pool to p.
* refactor: Changed large numbers to const for readability & removed some comments
* refactor: Remove unnecessary function usage
* refactor: Fix error messages to make their meaning clear
* GSW-1839 refactor: integrated helper and test code (#432)
* GSW-1839 Refactor/position contract utils (#433)
* GSW-1839 refactor: integrated helper and test code
- integrated helper with nft helper
- add test helper code
- add test code for helper
- change file filename
* GSW-1839 refactor: utils
- add assert functions
- refactor original util functions
* Update position/utils_test.gno
* test: Update to use the correct test values
* GSW-1968 feat: check emission is caller or not (#435)
* feat: add check logic for caller is emission or not
* fix: remove deprecated require from gno.mod
* Refactor/pool total (#442)
* refactor: pool mint
* refactor: name change transferFromAndVerify to safeTransferFrom
* refactor: support checkTick when position modify
* refactor: tick and position update
* refactor: pool mint
* refactor: collect and burn
* refactor: collectProtocol
* refactor: setFeeProtocol
* refactor: createPool
* refactor: Modify code based on code review comments
* fix u256 error
* rm: reward_internal_emission, reward_manager
* rm: staker_type
* rm: unnecessary test (staker_test)
* rm: reward_recipient_store
* rm: function prefix from panic messages
* rm: tier_ratio, warm_up
* rm: external_incentive_calculator
* chore: change file name _GET_no_receiver -> getter
* test: GetPoolStakedLiquidityUpdates
* test, fix: api_calculation
* modify external reward to be indexed by incentive id
* test: more helpers
* chore: exclude unittests
* add per warmup retrieval
* add warmup test
* feat: getPrintInfo()
* fix: gnoVM panics
* fix: internal 01 test
* fix: divide by zero
* refactor: use grc20reg

---------

Co-authored-by: Lee ByeongJun <[email protected]>
Co-authored-by: Blake <[email protected]>
Co-authored-by: n3wbie <[email protected]>
Co-authored-by: 0xTopaz <[email protected]>
  • Loading branch information
5 people authored Jan 15, 2025
1 parent d973fab commit b1ce569
Show file tree
Hide file tree
Showing 156 changed files with 19,522 additions and 12,704 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1 @@
module gno.land/r/g1er355fkjksqpdtwmhf5penwa82p0rhqxkkyhk5/v2/register_gnodev

require (
gno.land/p/demo/users v0.0.0-latest
gno.land/r/demo/foo20 v0.0.0-latest
gno.land/r/demo/wugnot v0.0.0-latest
gno.land/r/gnoswap/v1/community_pool v0.0.0-latest
gno.land/r/gnoswap/v1/gns v0.0.0-latest
gno.land/r/gnoswap/v1/gov/staker v0.0.0-latest
gno.land/r/gnoswap/v1/launchpad v0.0.0-latest
gno.land/r/gnoswap/v1/pool v0.0.0-latest
gno.land/r/gnoswap/v1/protocol_fee v0.0.0-latest
gno.land/r/gnoswap/v1/router v0.0.0-latest
gno.land/r/gnoswap/v1/staker v0.0.0-latest
gno.land/r/onbloc/bar v0.0.0-latest
gno.land/r/onbloc/baz v0.0.0-latest
gno.land/r/onbloc/foo v0.0.0-latest
gno.land/r/onbloc/obl v0.0.0-latest
gno.land/r/onbloc/qux v0.0.0-latest
gno.land/r/onbloc/usdc v0.0.0-latest
)
module gno.land/r/g1er355fkjksqpdtwmhf5penwa82p0rhqxkkyhk5/v2/register_gnodev
11 changes: 1 addition & 10 deletions __local/grc20_tokens/onbloc/bar/gno.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
module gno.land/r/onbloc/bar

require (
gno.land/p/demo/grc/grc20 v0.0.0-latest
gno.land/p/demo/ownable v0.0.0-latest
gno.land/p/demo/ufmt v0.0.0-latest
gno.land/p/demo/users v0.0.0-latest
gno.land/r/demo/users v0.0.0-latest
gno.land/r/demo/grc20reg v0.0.0-latest
)
module gno.land/r/onbloc/bar
11 changes: 1 addition & 10 deletions __local/grc20_tokens/onbloc/baz/gno.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
module gno.land/r/onbloc/baz

require (
gno.land/p/demo/grc/grc20 v0.0.0-latest
gno.land/p/demo/ownable v0.0.0-latest
gno.land/p/demo/ufmt v0.0.0-latest
gno.land/p/demo/users v0.0.0-latest
gno.land/r/demo/users v0.0.0-latest
gno.land/r/demo/grc20reg v0.0.0-latest
)
module gno.land/r/onbloc/baz
11 changes: 1 addition & 10 deletions __local/grc20_tokens/onbloc/foo/gno.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
module gno.land/r/onbloc/foo

require (
gno.land/p/demo/grc/grc20 v0.0.0-latest
gno.land/p/demo/ownable v0.0.0-latest
gno.land/p/demo/ufmt v0.0.0-latest
gno.land/p/demo/users v0.0.0-latest
gno.land/r/demo/users v0.0.0-latest
gno.land/r/demo/grc20reg v0.0.0-latest
)
module gno.land/r/onbloc/foo
11 changes: 1 addition & 10 deletions __local/grc20_tokens/onbloc/obl/gno.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
module gno.land/r/onbloc/obl

require (
gno.land/p/demo/grc/grc20 v0.0.0-latest
gno.land/p/demo/ownable v0.0.0-latest
gno.land/p/demo/ufmt v0.0.0-latest
gno.land/p/demo/users v0.0.0-latest
gno.land/r/demo/users v0.0.0-latest
gno.land/r/demo/grc20reg v0.0.0-latest
)
module gno.land/r/onbloc/obl
11 changes: 1 addition & 10 deletions __local/grc20_tokens/onbloc/qux/gno.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
module gno.land/r/onbloc/qux

require (
gno.land/p/demo/grc/grc20 v0.0.0-latest
gno.land/p/demo/ownable v0.0.0-latest
gno.land/p/demo/ufmt v0.0.0-latest
gno.land/p/demo/users v0.0.0-latest
gno.land/r/demo/users v0.0.0-latest
gno.land/r/demo/grc20reg v0.0.0-latest
)
module gno.land/r/onbloc/qux
11 changes: 1 addition & 10 deletions __local/grc20_tokens/onbloc/usdc/gno.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
module gno.land/r/onbloc/usdc

require (
gno.land/p/demo/grc/grc20 v0.0.0-latest
gno.land/p/demo/ownable v0.0.0-latest
gno.land/p/demo/ufmt v0.0.0-latest
gno.land/p/demo/users v0.0.0-latest
gno.land/r/demo/users v0.0.0-latest
gno.land/r/demo/grc20reg v0.0.0-latest
)
module gno.land/r/onbloc/usdc
6 changes: 3 additions & 3 deletions _deploy/r/gnoswap/common/address_and_username.gno
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// AddrToUser converts a type from address to AddressOrName.
// It panics if the address is invalid.
func AddrToUser(addr std.Address) pusers.AddressOrName {
assertValidAddr(addr)
AssertValidAddr(addr)
return pusers.AddressOrName(addr)
}

Expand All @@ -20,9 +20,9 @@ func UserToAddr(user pusers.AddressOrName) std.Address {
return users.Resolve(user)
}

// assertValidAddr checks if the given address is valid.
// AssertValidAddr checks if the given address is valid.
// It panics with a detailed error message if the address is invalid.
func assertValidAddr(addr std.Address) {
func AssertValidAddr(addr std.Address) {
if !addr.IsValid() {
panic(newErrorWithDetail(errInvalidAddr, addr.String()))
}
Expand Down
4 changes: 2 additions & 2 deletions _deploy/r/gnoswap/common/address_and_username_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ func TestAssertValidAddr(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
if tt.shouldPanic {
uassert.PanicsWithMessage(t, tt.panicMsg, func() {
assertValidAddr(tt.addr)
AssertValidAddr(tt.addr)
})
} else {
uassert.NotPanics(t, func() {
assertValidAddr(tt.addr)
AssertValidAddr(tt.addr)
})
}
})
Expand Down
43 changes: 43 additions & 0 deletions _deploy/r/gnoswap/common/strings.gno
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package common

import (
"strconv"
"strings"

"gno.land/p/demo/ufmt"
Expand All @@ -14,3 +15,45 @@ func Split(input string, sep string, length int) ([]string, error) {

return result, nil
}

// EncodeUint converts an uint64 number into a zero-padded 20-character string.
//
// Parameters:
// - num (uint64): The number to encode.
//
// Returns:
// - string: A zero-padded string representation of the number.
//
// Example:
// Input: 12345
// Output: "00000000000000012345"
func EncodeUint(num uint64) string {
// Convert the value to a decimal string.
s := strconv.FormatUint(num, 10)

// Zero-pad to a total length of 20 characters.
zerosNeeded := 20 - len(s)
return strings.Repeat("0", zerosNeeded) + s
}

// DecodeUint converts a zero-padded string back into a uint64 number.
//
// Parameters:
// - s (string): The zero-padded string.
//
// Returns:
// - uint64: The decoded number.
//
// Panics:
// - If the string cannot be parsed into a uint64.
//
// Example:
// Input: "00000000000000012345"
// Output: 12345
func DecodeUint(s string) uint64 {
num, err := strconv.ParseUint(s, 10, 64)
if err != nil {
panic(err)
}
return num
}
18 changes: 18 additions & 0 deletions _deploy/r/gnoswap/gnft/gnft.gno
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,24 @@ func OwnerOf(tid grc721.TokenID) (std.Address, error) {
return ownerAddr, nil
}

// MustOwnerOf returns the current owner's address of a specific token ID
// Parameters:
// - tid: The token ID to check ownership of
//
// Returns:
// - std.Address: The address of the token owner
//
// Panics:
// - If the token ID is invalid
func MustOwnerOf(tid grc721.TokenID) std.Address {
ownerAddr, err := OwnerOf(tid)
if err != nil {
panic(err.Error())
}

return ownerAddr
}

// SetTokenURI sets the metadata URI using a randomly generated SVG image
// Parameters:
// - tid (grc721.TokenID): The token ID for which the URI will be updated.
Expand Down
2 changes: 1 addition & 1 deletion _deploy/r/gnoswap/gns/_helper_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ func resetHalvingRelatedObject(t *testing.T) {
startHeight = std.GetHeight()
startTimestamp = time.Now().Unix()

initializeHalvingData()
emissionState = GetEmissionState()
setEndTimestamp(startTimestamp + consts.TIMESTAMP_YEAR*HALVING_END_YEAR)
}
2 changes: 1 addition & 1 deletion _deploy/r/gnoswap/gns/errors.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

var (
errNoPermission = errors.New("[GNOSWAP-GNS-001] caller has no permission")
errInvalidYear = errors.New("[GNOSWAP-GNS-001] invalid year")
errTooManyEmission = errors.New("[GNOSWAP-GNS-002] too many emission reward")
)

Expand Down
Loading

0 comments on commit b1ce569

Please sign in to comment.