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

build: apply gno's new static analysis #223

Merged
merged 1 commit into from
May 16, 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
2 changes: 0 additions & 2 deletions _deploy/p/demo/gnoswap/pool/sqrt_price_math.gno
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ func sqrtPriceMathGetAmount0DeltaHelper(
panic("pool_sqrt price math #3")
}

value := u256.MulDiv(numerator1, numerator2, sqrtRatioBX96)

if roundUp {
value1 := u256.MulDivRoundingUp(numerator1, numerator2, sqrtRatioBX96)
return u256.DivRoundingUp(value1, sqrtRatioAX96)
Expand Down
2 changes: 0 additions & 2 deletions _deploy/r/demo/gnoswap/common/sqrt_price_math.gno
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ func sqrtPriceMathGetAmount0DeltaHelper(
panic("common_sqrt price math #3")
}

value := u256.MulDiv(numerator1, numerator2, sqrtRatioBX96)

if roundUp {
value1 := u256.MulDivRoundingUp(numerator1, numerator2, sqrtRatioBX96)
return u256.DivRoundingUp(value1, sqrtRatioAX96)
Expand Down
2 changes: 1 addition & 1 deletion _deploy/r/demo/gnoswap/consts/consts.gno
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (
)

// CONTRACT PATH & ADDRESS
const (
var (
POOL_PATH string = "gno.land/r/demo/pool"
POOL_ADDR std.Address = std.DerivePkgAddr(POOL_PATH)

Expand Down
16 changes: 8 additions & 8 deletions gov/api.gno
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ func UpdateVotingPower(address string, newPower uint64) {
votes := votersMap[address]

for proposalID, vote := range votes {
proposal := &proposalsMap[proposalID]
proposal := proposalsMap[proposalID]

proposal.updateVotingPower(vote.VoteOption, vote.Power, newPower)
proposalsMap[proposal.ProposalID] = *proposal
proposalsMap[proposal.ProposalID] = proposal
}

}
Expand All @@ -20,10 +20,10 @@ func MakeVote(proposalID uint64, option VoteOption) {
caller := std.GetOrigCaller()
amount := balanceOf(caller)

proposal := &proposalsMap[proposalID]
proposal := proposalsMap[proposalID]
proposal.vote(caller, option, amount)

proposalsMap[proposal.ProposalID] = *proposal
proposalsMap[proposal.ProposalID] = proposal
}

func MakeDeposit(proposalID uint64, amount uint64) {
Expand All @@ -32,19 +32,19 @@ func MakeDeposit(proposalID uint64, amount uint64) {
// commented out, replace `gov` with the address of the gov contract
// gns.Transfer(users.AddressOrName(caller), gov, amount)

proposal := &proposalsMap[proposalID]
proposal := proposalsMap[proposalID]
proposal.deposit(caller, amount)

proposalsMap[proposal.ProposalID] = *proposal
proposalsMap[proposal.ProposalID] = proposal
}

func GetActiveProposals() []Proposal {
// TODO
return nil
}

func GetProposalById(proposalID uint64) *Proposal {
return &proposalsMap[proposalID]
func GetProposalById(proposalID uint64) Proposal {
return proposalsMap[proposalID]
}

func SubmitProposalText(
Expand Down
2 changes: 1 addition & 1 deletion gov/const.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package gov

import "std"

const (
var (
GNS_TOKEN_ADDRESS = std.DerivePkgAddr("gno.land/r/demo/gns")
)
2 changes: 1 addition & 1 deletion gov/realm_variables.gno
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func getNextProposalID() uint64 {
}

func updateVote(proposalID uint64, address string, option VoteOption, power uint64) {
proposal := &proposalsMap[proposalID]
proposal := proposalsMap[proposalID]
proposalVotes := proposalVotesMap[proposalID]
oldVote := proposalVotes[address]

Expand Down
3 changes: 3 additions & 0 deletions gov/tally.gno
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ func (p *Proposal) processVotingPeriod(currentTime uint64) {
// (especially on community pool spend with untrusted tokens)
p.ProposalStatus = ProposalStatusPassed
err := p.ProposalData.execute()
if err != nil {
panic(err)
}
// TODO: handle error
return
}
Expand Down
2 changes: 1 addition & 1 deletion pool/_RPC_api.gno
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func ApiGetPools() string {

// RESPONSE (ARRAY) NODE
responses := json.ArrayNode("", []*json.Node{})
for i, pool := range rpcPools {
for _, pool := range rpcPools {
_poolNode := json.ObjectNode("", map[string]*json.Node{
"poolPath": json.StringNode("poolPath", pool.PoolPath),
"token0Path": json.StringNode("token0Path", pool.Token0Path),
Expand Down
7 changes: 4 additions & 3 deletions pool/_RPC_dry.gno
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ func DrySwap(

// update global fee tracker
if state.liquidity.Gt(u256.Zero()) {
value1 := new(u256.Uint).Mul(step.feeAmount, u256.MustFromDecimal(consts.Q128))
value2 := new(u256.Uint).Div(value1, state.liquidity)

// OBS if `DrySwap()` update its state, next ACTUAL `Swap()` gets affect

// value1 := new(u256.Uint).Mul(step.feeAmount, u256.MustFromDecimal(consts.Q128))
// value2 := new(u256.Uint).Div(value1, state.liquidity)

// state.feeGrowthGlobalX128 = new(u256.Uint).Add(state.feeGrowthGlobalX128, value2)
}

Expand Down
2 changes: 1 addition & 1 deletion position/_RPC_api.gno
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func ApiGetPositions() string {

// RESPONSE (ARRAY) NODE
responses := json.ArrayNode("", []*json.Node{})
for i, position := range r.Response {
for _, position := range r.Response {
_positionNode := json.ObjectNode("", map[string]*json.Node{
"lpTokenId": json.NumberNode("lpTokenId", float64(position.LpTokenId)),
"burned": json.BoolNode("burned", position.Burned),
Expand Down
2 changes: 1 addition & 1 deletion position/position.gno
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func IncreaseLiquidity(
}

// INCREASE
tokneId, liquidity, amount0, amount1, poolPath := increaseLiquidity(increaseLiquidityParams)
_, liquidity, amount0, amount1, poolPath := increaseLiquidity(increaseLiquidityParams) // tokenId, liquidity, amount0, amount1, poolPath

// unwrap left
if isToken0Wugnot || isToken1Wugnot {
Expand Down
1 change: 0 additions & 1 deletion position/wrap_unwrap.gno
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func unwrap(wugnotAmount uint64) {
if wugnotAmount == 0 {
return
}
userOldWugnot := wugnot.BalanceOf(a2u(std.GetOrigCaller()))

// SEND WUGNOT: USER -> POSITION
wugnot.TransferFrom(a2u(std.GetOrigCaller()), a2u(consts.POSITION_ADDR), wugnotAmount)
Expand Down
2 changes: 1 addition & 1 deletion router/comptue_routes.gno
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func computeRoutes(
continue
}

curPool := pools[i]
curPool := pool

var previousTokenOut string
if _previousTokenOut == "" { // first iteration
Expand Down
2 changes: 1 addition & 1 deletion router/router.gno
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func handleMultiSwap(swapType string, route string, numHops int, amountSpecified
}
return multiSwap(swapParams, 0, numHops, route) // iterate here

case ExactOut:
case "EXACT_OUT":
input, output, fee := getDataForMultiPath(route, numHops-1) // last data
swapParams := SwapParams{
tokenIn: input,
Expand Down
3 changes: 1 addition & 2 deletions router/swap_multi.gno
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func multiSwapNegative(params SwapParams, numPools int, swapPath string) (*u256.

// CALCULATE BACKWARD INFO
for {
amountIn, amountOut := singleSwapDry(
amountIn, _ := singleSwapDry(
SingleSwapParams{
tokenIn: params.tokenIn,
tokenOut: params.tokenOut,
Expand Down Expand Up @@ -175,7 +175,6 @@ func multiSwapDry(params SwapParams, currentPoolIndex, numPool int, swapPath str
func multiSwapNegativeDry(params SwapParams, currentPoolIndex int, swapPath string) (*u256.Uint, *u256.Uint) { // firstAmountIn, lastAmountOut
firstAmountIn := u256.Zero()
payer := consts.ROUTER_ADDR
numPools := currentPoolIndex

for {
amountIn, amountOut := _swapDry(
Expand Down
1 change: 0 additions & 1 deletion router/wrap_unwrap.gno
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func unwrap(wugnotAmount uint64) {
if wugnotAmount == 0 {
return
}
userOldWugnot := wugnot.BalanceOf(a2u(std.GetOrigCaller()))

// SEND WUGNOT: USER -> ROUTER
wugnot.TransferFrom(a2u(std.GetOrigCaller()), a2u(consts.ROUTER_ADDR), wugnotAmount)
Expand Down
2 changes: 1 addition & 1 deletion staker/_RPC_api_incentive.gno
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func ApiGetRewardTokens() string {

// RESPONSE (ARRAY) NODE
responses := json.ArrayNode("", []*json.Node{})
for i, rewardToken := range rewardTokens {
for _, rewardToken := range rewardTokens {
_rewardTokenNode := json.ObjectNode("", map[string]*json.Node{
"poolPath": json.StringNode("poolPath", rewardToken.PoolPath),
"tokens": json.ArrayNode("tokens", makeRewardTokensArray(rewardToken.RewardsTokenList)),
Expand Down
4 changes: 2 additions & 2 deletions staker/_RPC_api_stake.gno
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func ApiGetRewards() string {

// RESPONSE (ARRAY) NODE
responses := json.ArrayNode("", []*json.Node{})
for i, reward := range r.Response {
for _, reward := range r.Response {
_rewardNode := json.ObjectNode("", map[string]*json.Node{
"lpTokenId": json.NumberNode("lpTokenId", float64(reward.LpTokenId)),
"address": json.StringNode("address", reward.Address),
Expand Down Expand Up @@ -158,7 +158,7 @@ func ApiGetStakes() string {

// RESPONSE (ARRAY) NODE
responses := json.ArrayNode("", []*json.Node{})
for i, stake := range r.Response {
for _, stake := range r.Response {
_stakeNode := json.ObjectNode("", map[string]*json.Node{
"tokenId": json.NumberNode("tokenId", float64(stake.TokenId)),
"owner": json.StringNode("owner", stake.Owner.String()),
Expand Down
4 changes: 2 additions & 2 deletions staker/reward_math.gno
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ type userClaimedReward map[std.Address]map[uint64]map[string]*u256.Uint // addre
var userClaimedRewards = make(userClaimedReward)

func userClaimedRewardAmount(address std.Address, tokenId uint64, rewardTokenPath string, rewardAmount *u256.Uint, claimeRequest bool) *u256.Uint {
userClaimed, ok := userClaimedRewards[address] // if user(address) ever claimed reward
_, ok := userClaimedRewards[address] // if user(address) ever claimed reward
if !ok {
userClaimedRewards[address] = make(map[uint64]map[string]*u256.Uint)
}

claimedPosition, ok := userClaimedRewards[address][tokenId] // if user(address) ever claimed reward from tokenId
_, ok = userClaimedRewards[address][tokenId] // if user(address) ever claimed reward from tokenId
if !ok {
userClaimedRewards[address][tokenId] = make(map[string]*u256.Uint)
}
Expand Down
10 changes: 9 additions & 1 deletion staker/staker.gno
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,15 @@ func CreateExternalIncentive(
for _, v := range poolIncentives[targetPoolPath] {
if v == incentiveId {
transferFromByRegisterCall(rewardToken, std.GetOrigCaller(), GetOrigPkgAddr(), rewardAmount.Uint64())
incentives[v].rewardAmount = new(u256.Uint).Add(incentives[v].rewardAmount, rewardAmount)

incentive, ok := incentives[v]
if !ok {
return
}

incentive.rewardAmount = new(u256.Uint).Add(incentive.rewardAmount, rewardAmount)
incentives[v] = incentive

return
}
}
Expand Down
14 changes: 7 additions & 7 deletions staker/staker_parameters.gno
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,31 @@ func SubmitProposalParameterStakingReward(
) uint64 {

if newStakingReward1 == 0 {
return false
return 0
}

if newStakingReward2 == 0 {
return false
return 0
}

if newStakingReward3 == 0 {
return false
return 0
}

if newStakingReward4 == 0 {
return false
return 0
}

if newStakingReward1 < newStakingReward2 {
return false
return 0
}

if newStakingReward2 < newStakingReward3 {
return false
return 0
}

if newStakingReward3 < newStakingReward4 {
return false
return 0
}

changes := []gov.ParameterChange{
Expand Down
2 changes: 0 additions & 2 deletions staker/utils.gno
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ func poolKeyDivide(poolKey string) string {
pToken0, pToken1, fee := res[0], res[1], res[2]

if pToken0 < pToken1 {
zz := ufmt.Sprintf("%s:%s:%s", pToken0, pToken1, fee)
return ufmt.Sprintf("%s:%s:%s", pToken0, pToken1, fee)
}

zz := ufmt.Sprintf("%s:%s:%s", pToken1, pToken0, fee)
return ufmt.Sprintf("%s:%s:%s", pToken1, pToken0, fee)
}

Expand Down