Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: HasReserves should return true for single-sided pools #639

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 13 additions & 28 deletions pkg/entity/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,60 +58,45 @@ type Pool struct {
BlockNumber uint64 `json:"blockNumber,omitempty"`
}

func (p Pool) IsZero() bool { return len(p.Address) == 0 && len(p.Tokens) == 0 }
func (p *Pool) IsZero() bool { return len(p.Address) == 0 && len(p.Tokens) == 0 }

func (p Pool) GetTotalSupply() float64 {
func (p *Pool) GetTotalSupply() float64 {
totalSupplyBF, _ := new(big.Float).SetString(p.TotalSupply)
totalSupply, _ := new(big.Float).Quo(totalSupplyBF, bignumber.TenPowDecimals(18)).Float64()

totalSupply, _ := totalSupplyBF.Quo(totalSupplyBF, bignumber.TenPowDecimals(18)).Float64()
return totalSupply
}

// GetLpToken returns the LpToken of the pool
// If there is a LpToken in the StaticExtra, we use it. If not, we get the pool's address
func (p Pool) GetLpToken() string {

func (p *Pool) GetLpToken() string {
var staticExtra = struct {
LpToken string `json:"lpToken"`
}{}

_ = json.Unmarshal([]byte(p.StaticExtra), &staticExtra)

if len(staticExtra.LpToken) > 0 {
return strings.ToLower(staticExtra.LpToken)
}

return p.Address
}

// HasReserves check if a pool has correct reserves or not
// if there is no reserve in pool, or reserve is empty string, or reserve = "0", this function returns false
// if pool has equals or more than 2 tokens have reserve, this function returns true
func (p Pool) HasReserves() bool {
if (len(p.Reserves)) == 0 {
return false
}

zeroReserveCount := 0
// HasReserves check if a pool has some reserves or not.
// Returns false if there is no reserve in pool, or all reserves are empty string or "0". True otherwise.
func (p *Pool) HasReserves() bool {
for _, reserve := range p.Reserves {
if len(reserve) == 0 || reserve == "0" {
zeroReserveCount += 1
if p.HasReserve(reserve) {
return true
}
}

return len(p.Reserves)-zeroReserveCount >= 2
return false
}

func (p Pool) HasReserve(reserve string) bool {
if len(reserve) == 0 || reserve == "0" {
return false
}

return true
func (p *Pool) HasReserve(reserve string) bool {
return len(reserve) > 0 && reserve != "0"
}

// HasAmplifiedTvl check if the pool has amplifiedTvl or not
func (p Pool) HasAmplifiedTvl() bool {
func (p *Pool) HasAmplifiedTvl() bool {
return p.AmplifiedTvl > 0
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/entity/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func TestPool_HasReserves(t *testing.T) {
expectedResult: false,
},
{
name: "it should return false when at least one reserve is empty string",
name: "it should return true when at least one reserve is not empty",
pool: Pool{
Address: "address1",
ReserveUsd: 100,
Expand Down Expand Up @@ -202,10 +202,10 @@ func TestPool_HasReserves(t *testing.T) {
StaticExtra: "staticExtra1",
TotalSupply: "totalSupply1",
},
expectedResult: false,
expectedResult: true,
},
{
name: "it should return false when at least one reserve is 0",
name: "it should return true when at least one reserve is not 0",
pool: Pool{
Address: "address1",
ReserveUsd: 100,
Expand Down Expand Up @@ -237,7 +237,7 @@ func TestPool_HasReserves(t *testing.T) {
StaticExtra: "staticExtra1",
TotalSupply: "totalSupply1",
},
expectedResult: false,
expectedResult: true,
},
}

Expand Down
Loading