diff --git a/_deploy/r/gnoswap/common/halt.gno b/_deploy/r/gnoswap/common/halt.gno index 2ea37b47..f701a6ad 100644 --- a/_deploy/r/gnoswap/common/halt.gno +++ b/_deploy/r/gnoswap/common/halt.gno @@ -2,6 +2,7 @@ package common import ( "std" + "strconv" "gno.land/p/demo/ufmt" "gno.land/r/gnoswap/v1/consts" @@ -89,11 +90,11 @@ func SetHalt(halt bool) { func setHalt(halt bool) { halted = halt - prevAddr, prevRealm := getPrevAsString() + prevAddr, prevPkgPath := getPrevAsString() std.Emit( "setHalt", "prevAddr", prevAddr, - "prevRealm", prevRealm, - "halt", ufmt.Sprintf("%t", halt), + "prevRealm", prevPkgPath, + "halt", strconv.FormatBool(halt), ) } diff --git a/_deploy/r/gnoswap/common/limit_caller.gno b/_deploy/r/gnoswap/common/limit_caller.gno index c12d3611..66c3588a 100644 --- a/_deploy/r/gnoswap/common/limit_caller.gno +++ b/_deploy/r/gnoswap/common/limit_caller.gno @@ -2,6 +2,7 @@ package common import ( "std" + "strconv" "gno.land/p/demo/ufmt" ) @@ -47,6 +48,6 @@ func SetLimitCaller(v bool) { "SetLimitCaller", "prevAddr", prevAddr, "prevRealm", prevPkgPath, - "limitCaller", ufmt.Sprintf("%t", v), + "limitCaller", strconv.FormatBool(v), ) } diff --git a/_deploy/r/gnoswap/gnft/gnft.gno b/_deploy/r/gnoswap/gnft/gnft.gno index 7fed629a..598c8754 100644 --- a/_deploy/r/gnoswap/gnft/gnft.gno +++ b/_deploy/r/gnoswap/gnft/gnft.gno @@ -361,8 +361,8 @@ func setTokenURI(tid grc721.TokenID, tURI grc721.TokenURI) error { "SetTokenURI", "prevAddr", prevAddr, "prevRealm", prevPkgPath, - "lpTokenId", "tid", - "tokenURI", "tURI", + "lpTokenId", string(tid), + "tokenURI", string(tURI), ) return nil diff --git a/_deploy/r/gnoswap/gns/halving.gno b/_deploy/r/gnoswap/gns/halving.gno index 7a55d03b..aad105f4 100644 --- a/_deploy/r/gnoswap/gns/halving.gno +++ b/_deploy/r/gnoswap/gns/halving.gno @@ -5,8 +5,6 @@ import ( "strconv" "time" - "gno.land/p/demo/ufmt" - "gno.land/r/gnoswap/v1/common" "gno.land/r/gnoswap/v1/consts" @@ -125,14 +123,28 @@ func SetAvgBlockTimeInMsByAdmin(ms int64) { panic(err) } + prevAvgBlockTimeMs := avgBlockTimeMs setAvgBlockTimeInMs(ms) - prevAddr, prevRealm := getPrev() + prevAddr, prevPkgPath := getPrev() std.Emit( "SetAvgBlockTimeInMsByAdmin", "prevAddr", prevAddr, - "prevRealm", prevRealm, - "ms", ufmt.Sprintf("%d", ms), + "prevRealm", prevPkgPath, + "newAvgBlockTimeMs", strconv.FormatInt(ms, 10), + "prevAvgBlockTimeMs", strconv.FormatInt(prevAvgBlockTimeMs, 10), + "endBlock1Year", strconv.FormatInt(halvingYearEndBlock[0], 10), + "endBlock2Year", strconv.FormatInt(halvingYearEndBlock[1], 10), + "endBlock3Year", strconv.FormatInt(halvingYearEndBlock[2], 10), + "endBlock4Year", strconv.FormatInt(halvingYearEndBlock[3], 10), + "endBlock5Year", strconv.FormatInt(halvingYearEndBlock[4], 10), + "endBlock6Year", strconv.FormatInt(halvingYearEndBlock[5], 10), + "endBlock7Year", strconv.FormatInt(halvingYearEndBlock[6], 10), + "endBlock8Year", strconv.FormatInt(halvingYearEndBlock[7], 10), + "endBlock9Year", strconv.FormatInt(halvingYearEndBlock[8], 10), + "endBlock10Year", strconv.FormatInt(halvingYearEndBlock[9], 10), + "endBlock11Year", strconv.FormatInt(halvingYearEndBlock[10], 10), + "endBlock12Year", strconv.FormatInt(halvingYearEndBlock[11], 10), ) } @@ -144,14 +156,28 @@ func SetAvgBlockTimeInMs(ms int64) { panic(err) } + prevAvgBlockTimeMs := avgBlockTimeMs setAvgBlockTimeInMs(ms) - prevAddr, prevRealm := getPrev() + prevAddr, prevPkgPath := getPrev() std.Emit( "SetAvgBlockTimeInMs", "prevAddr", prevAddr, - "prevRealm", prevRealm, - "ms", ufmt.Sprintf("%d", ms), + "prevRealm", prevPkgPath, + "newAvgBlockTimeMs", strconv.FormatInt(ms, 10), + "prevAvgBlockTimeMs", strconv.FormatInt(prevAvgBlockTimeMs, 10), + "endBlock1Year", strconv.FormatInt(halvingYearEndBlock[0], 10), + "endBlock2Year", strconv.FormatInt(halvingYearEndBlock[1], 10), + "endBlock3Year", strconv.FormatInt(halvingYearEndBlock[2], 10), + "endBlock4Year", strconv.FormatInt(halvingYearEndBlock[3], 10), + "endBlock5Year", strconv.FormatInt(halvingYearEndBlock[4], 10), + "endBlock6Year", strconv.FormatInt(halvingYearEndBlock[5], 10), + "endBlock7Year", strconv.FormatInt(halvingYearEndBlock[6], 10), + "endBlock8Year", strconv.FormatInt(halvingYearEndBlock[7], 10), + "endBlock9Year", strconv.FormatInt(halvingYearEndBlock[8], 10), + "endBlock10Year", strconv.FormatInt(halvingYearEndBlock[9], 10), + "endBlock11Year", strconv.FormatInt(halvingYearEndBlock[10], 10), + "endBlock12Year", strconv.FormatInt(halvingYearEndBlock[11], 10), ) } diff --git a/community_pool/community_pool.gno b/community_pool/community_pool.gno index 182a6dad..35bf4f3a 100644 --- a/community_pool/community_pool.gno +++ b/community_pool/community_pool.gno @@ -2,8 +2,7 @@ package community_pool import ( "std" - - "gno.land/p/demo/ufmt" + "strconv" "gno.land/r/gnoswap/v1/common" ) @@ -30,14 +29,15 @@ func transferToken(tokenPath string, to std.Address, amount uint64) { teller := common.GetTokenTeller(tokenPath) checkErr(teller.Transfer(to, amount)) - prevAddr, prevRealm := getPrevAsString() + prevAddr, prevPkgPath := getPrevAsString() + std.Emit( "TransferToken", "prevAddr", prevAddr, - "prevRealm", prevRealm, + "prevRealm", prevPkgPath, "tokenPath", tokenPath, "to", to.String(), - "amount", ufmt.Sprintf("%d", amount), + "amount", strconv.FormatUint(amount, 10), ) } diff --git a/emission/distribution.gno b/emission/distribution.gno index d2cc02c2..1911b497 100644 --- a/emission/distribution.gno +++ b/emission/distribution.gno @@ -121,13 +121,13 @@ func changeDistributionPcts( "ChangeDistributionPct", "prevAddr", prevAddr, "prevRealm", prevPkgPath, - "target01", strconv.Itoa(target01), + "target01", targetToStr(target01), "pct01", strconv.FormatUint(pct01, 10), - "target02", strconv.Itoa(target02), + "target02", targetToStr(target02), "pct02", strconv.FormatUint(pct02, 10), - "target03", strconv.Itoa(target03), + "target03", targetToStr(target03), "pct03", strconv.FormatUint(pct03, 10), - "target04", strconv.Itoa(target04), + "target04", targetToStr(target04), "pct04", strconv.FormatUint(pct04, 10), ) } @@ -260,3 +260,18 @@ func ClearDistributedToGovStaker() { func setDistributionBpsPct(target int, pct uint64) { distributionBpsPct.Set(strconv.Itoa(target), pct) } + +func targetToStr(target int) string { + switch target { + case LIQUIDITY_STAKER: + return "LIQUIDITY_STAKER" + case DEVOPS: + return "DEVOPS" + case COMMUNITY_POOL: + return "COMMUNITY_POOL" + case GOV_STAKER: + return "GOV_STAKER" + default: + return "UNKNOWN" + } +} diff --git a/emission/emission.gno b/emission/emission.gno index b2492489..66a857eb 100644 --- a/emission/emission.gno +++ b/emission/emission.gno @@ -2,11 +2,9 @@ package emission import ( "std" + "strconv" "time" - "gno.land/p/demo/ufmt" - - "gno.land/r/gnoswap/v1/common" "gno.land/r/gnoswap/v1/consts" "gno.land/r/gnoswap/v1/gns" ) @@ -32,15 +30,18 @@ func MintAndDistributeGns() uint64 { // Mint new tokens and add any leftover amounts from previous distribution mintedEmissionRewardAmount := gns.MintGns(a2u(consts.EMISSION_ADDR)) + + distributableAmount := mintedEmissionRewardAmount + prevLeftAmount := GetLeftGNSAmount() if hasLeftGNSAmount() { - mintedEmissionRewardAmount += GetLeftGNSAmount() + distributableAmount += prevLeftAmount setLeftGNSAmount(0) } // Distribute tokens and track any undistributed amount - distributedGNSAmount := distributeToTarget(mintedEmissionRewardAmount) - if mintedEmissionRewardAmount != distributedGNSAmount { - setLeftGNSAmount(mintedEmissionRewardAmount - distributedGNSAmount) + distributedGNSAmount := distributeToTarget(distributableAmount) + if distributableAmount != distributedGNSAmount { + setLeftGNSAmount(distributableAmount - distributedGNSAmount) } // Emit event with distribution details @@ -49,11 +50,14 @@ func MintAndDistributeGns() uint64 { "MintAndDistributeGns", "prevAddr", prevAddr, "prevRealm", prevPkgPath, - "internal_lastHeight", ufmt.Sprintf("%d", lastExecutedHeight), - "internal_height", ufmt.Sprintf("%d", currentHeight), - "internal_time", ufmt.Sprintf("%d", time.Now().Unix()), - "internal_amount", ufmt.Sprintf("%d", mintedEmissionRewardAmount), - "internal_totalSupply", ufmt.Sprintf("%d", gns.TotalSupply()), + "lastHeight", strconv.FormatInt(lastExecutedHeight, 10), + "currentHeight", strconv.FormatInt(currentHeight, 10), + "currentTimestamp", strconv.FormatInt(time.Now().Unix(), 10), + "mintedAmount", strconv.FormatUint(mintedEmissionRewardAmount, 10), + "prevLeftAmount", strconv.FormatUint(prevLeftAmount, 10), + "distributedAmount", strconv.FormatUint(distributedGNSAmount, 10), + "currentLeftAmount", strconv.FormatUint(GetLeftGNSAmount(), 10), + "gnsTotalSupply", strconv.FormatUint(gns.TotalSupply(), 10), ) setLastExecutedHeight(currentHeight) diff --git a/pool/pool.gno b/pool/pool.gno index 67308c22..3a9ad78d 100644 --- a/pool/pool.gno +++ b/pool/pool.gno @@ -2,6 +2,7 @@ package pool import ( "std" + "strconv" "gno.land/p/demo/ufmt" @@ -267,11 +268,11 @@ func setFeeProtocolInternal(feeProtocol0, feeProtocol1 uint8, eventName string) eventName, "prevAddr", prevAddr, "prevRealm", prevPkgPath, - "feeProtocol0Old", ufmt.Sprintf("%d", feeProtocol0Old), - "feeProtocol1Old", ufmt.Sprintf("%d", feeProtocol1Old), - "feeProtocol0", ufmt.Sprintf("%d", feeProtocol0), - "feeProtocol1", ufmt.Sprintf("%d", feeProtocol1), - "internal_newFee", ufmt.Sprintf("%d", newFee), + "prevFeeProtocol0", strconv.FormatUint(uint64(feeProtocol0Old), 10), + "prevFeeProtocol1", strconv.FormatUint(uint64(feeProtocol1Old), 10), + "feeProtocol0", strconv.FormatUint(uint64(feeProtocol0), 10), + "feeProtocol1", strconv.FormatUint(uint64(feeProtocol1), 10), + "newFee", strconv.FormatUint(uint64(newFee), 10), ) } @@ -383,10 +384,10 @@ func CollectProtocolByAdmin( "prevRealm", prevPkgPath, "token0Path", token0Path, "token1Path", token1Path, - "fee", ufmt.Sprintf("%d", fee), + "fee", strconv.FormatUint(uint64(fee), 10), "recipient", recipient.String(), - "internal_amount0", amount0, - "internal_amount1", amount1, + "collectedAmount0", amount0, + "collectedAmount1", amount1, ) return amount0, amount1 @@ -421,10 +422,10 @@ func CollectProtocol( "prevRealm", prevPkgPath, "token0Path", token0Path, "token1Path", token1Path, - "fee", ufmt.Sprintf("%d", fee), + "fee", strconv.FormatUint(uint64(fee), 10), "recipient", recipient.String(), - "internal_amount0", amount0, - "internal_amount1", amount1, + "collectedAmount0", amount0, + "collectedAmount1", amount1, ) return amount0, amount1 diff --git a/pool/pool_manager.gno b/pool/pool_manager.gno index 8edcb1af..ae1b0c48 100644 --- a/pool/pool_manager.gno +++ b/pool/pool_manager.gno @@ -194,24 +194,28 @@ func CreatePool( "PoolCreationFee", "prevAddr", prevAddr, "prevRealm", prevRealm, - "internal_poolPath", poolPath, - "internal_tokenPath", consts.GNS_PATH, - "internal_amount", ufmt.Sprintf("%d", poolCreationFee), + "poolPath", poolPath, + "feeTokenPath", consts.GNS_PATH, + "feeAmount", strconv.FormatUint(poolCreationFee, 10), ) } pool = newPool(poolInfo) pools.Set(poolPath, pool) + currentTick := common.TickMathGetTickAtSqrtRatio(sqrtPriceX96) + std.Emit( "CreatePool", "prevAddr", prevAddr, "prevRealm", prevRealm, "token0Path", token0Path, "token1Path", token1Path, - "fee", ufmt.Sprintf("%d", fee), + "fee", strconv.FormatUint(uint64(fee), 10), "sqrtPriceX96", sqrtPriceX96, - "internal_poolPath", poolPath, + "poolPath", poolPath, + "tick", strconv.FormatInt(int64(currentTick), 10), + "tickSpacing", strconv.FormatInt(int64(poolInfo.TickSpacing()), 10), ) } diff --git a/pool/protocol_fee_pool_creation.gno b/pool/protocol_fee_pool_creation.gno index c6e4e06a..a5d93b5f 100644 --- a/pool/protocol_fee_pool_creation.gno +++ b/pool/protocol_fee_pool_creation.gno @@ -2,8 +2,8 @@ package pool import ( "std" + "strconv" - "gno.land/p/demo/ufmt" "gno.land/r/gnoswap/v1/common" ) @@ -23,13 +23,12 @@ func GetPoolCreationFee() uint64 { // Only governance contract can execute this function via proposal // ref: https://docs.gnoswap.io/contracts/pool/protocol_fee_pool_creation.gno#setpoolcreationfee func SetPoolCreationFee(fee uint64) { - // TODO: - // 1. IsHalted name chnage to assertIsHalted - common.IsHalted() - caller := std.PrevRealm().Addr() + assertOnlyNotHalted() + caller := getPrevAddr() if err := common.GovernanceOnly(caller); err != nil { panic(err.Error()) } + prevPoolCreationFee := poolCreationFee setPoolCreationFee(fee) prevAddr, prevPkgPath := getPrevAsString() @@ -37,21 +36,21 @@ func SetPoolCreationFee(fee uint64) { "SetPoolCreationFee", "prevAddr", prevAddr, "prevRealm", prevPkgPath, - "fee", ufmt.Sprintf("%d", fee), + "prevFee", strconv.FormatUint(prevPoolCreationFee, 10), + "newFee", strconv.FormatUint(fee, 10), ) } // SetPoolCreationFeeByAdmin sets the poolCreationFee by Admin. // Only admin can execute this function. func SetPoolCreationFeeByAdmin(fee uint64) { - // TODO: - // 1. IsHalted name chnage to assertIsHalted - common.IsHalted() + assertOnlyNotHalted() - caller := std.PrevRealm().Addr() + caller := getPrevAddr() if err := common.AdminOnly(caller); err != nil { panic(err.Error()) } + prevPoolCreationFee := poolCreationFee setPoolCreationFee(fee) prevAddr, prevPkgPath := getPrevAsString() @@ -59,7 +58,8 @@ func SetPoolCreationFeeByAdmin(fee uint64) { "SetPoolCreationFeeByAdmin", "prevAddr", prevAddr, "prevRealm", prevPkgPath, - "fee", ufmt.Sprintf("%d", fee), + "prevFee", strconv.FormatUint(prevPoolCreationFee, 10), + "newFee", strconv.FormatUint(fee, 10), ) } diff --git a/pool/protocol_fee_withdrawal.gno b/pool/protocol_fee_withdrawal.gno index d7d208b9..ea9a119c 100644 --- a/pool/protocol_fee_withdrawal.gno +++ b/pool/protocol_fee_withdrawal.gno @@ -2,6 +2,7 @@ package pool import ( "std" + "strconv" "gno.land/p/demo/ufmt" u256 "gno.land/p/gnoswap/uint256" @@ -39,18 +40,18 @@ const ( func HandleWithdrawalFee( tokenId uint64, token0Path string, - _amount0 string, // uint256 + amount0 string, // uint256 token1Path string, - _amount1 string, // uint256 + amount1 string, // uint256 poolPath string, positionCaller std.Address, ) (string, string) { // uint256 x2 - common.IsHalted() + assertOnlyNotHalted() common.MustRegistered(token0Path) common.MustRegistered(token1Path) // only position contract can call this function - caller := std.PrevRealm().Addr() + caller := getPrevAddr() if err := common.PositionOnly(caller); err != nil { panic(addDetailToError( errNoPermission, @@ -60,11 +61,11 @@ func HandleWithdrawalFee( fee := GetWithdrawalFee() if fee == ZeroBps { - return _amount0, _amount1 + return amount0, amount1 } - feeAmount0, afterAmount0 := calculateAmountWithFee(u256.MustFromDecimal(_amount0), u256.NewUint(fee)) - feeAmount1, afterAmount1 := calculateAmountWithFee(u256.MustFromDecimal(_amount1), u256.NewUint(fee)) + feeAmount0, afterAmount0 := calculateAmountWithFee(u256.MustFromDecimal(amount0), u256.NewUint(fee)) + feeAmount1, afterAmount1 := calculateAmountWithFee(u256.MustFromDecimal(amount1), u256.NewUint(fee)) token0Teller := common.GetTokenTeller(token0Path) checkTransferError(token0Teller.TransferFrom(positionCaller, consts.PROTOCOL_FEE_ADDR, feeAmount0.Uint64())) @@ -77,12 +78,10 @@ func HandleWithdrawalFee( "WithdrawalFee", "prevAddr", prevAddr, "prevRealm", prevPkgPath, - "lpTokenId", ufmt.Sprintf("%d", tokenId), - "token0Path", token0Path, - "token1Path", token1Path, - "internal_fee0Amount", feeAmount0.ToString(), - "internal_fee1Amount", feeAmount1.ToString(), + "lpTokenId", strconv.FormatUint(tokenId, 10), "poolPath", poolPath, + "feeAmount0", feeAmount0.ToString(), + "feeAmount1", feeAmount1.ToString(), ) return afterAmount0.ToString(), afterAmount1.ToString() @@ -98,12 +97,14 @@ func GetWithdrawalFee() uint64 { // Only governance contract can execute this function via proposal // ref: https://docs.gnoswap.io/contracts/pool/protocol_fee_withdrawal.gno#setwithdrawalfee func SetWithdrawalFee(fee uint64) { - common.IsHalted() - caller := std.PrevRealm().Addr() + assertOnlyNotHalted() + caller := getPrevAddr() if err := common.GovernanceOnly(caller); err != nil { panic(err.Error()) } + prevWithdrawalFee := withdrawalFeeBPS + setWithdrawalFee(fee) prevAddr, prevPkgPath := getPrevAsString() @@ -111,7 +112,8 @@ func SetWithdrawalFee(fee uint64) { "SetWithdrawalFee", "prevAddr", prevAddr, "prevRealm", prevPkgPath, - "fee", ufmt.Sprintf("%d", fee), + "prevFee", strconv.FormatUint(prevWithdrawalFee, 10), + "newFee", strconv.FormatUint(fee, 10), ) } @@ -124,6 +126,8 @@ func SetWithdrawalFeeByAdmin(fee uint64) { panic(err.Error()) } + prevWithdrawalFee := withdrawalFeeBPS + setWithdrawalFee(fee) prevAddr, prevPkgPath := getPrevAsString() @@ -131,7 +135,8 @@ func SetWithdrawalFeeByAdmin(fee uint64) { "SetWithdrawalFeeByAdmin", "prevAddr", prevAddr, "prevRealm", prevPkgPath, - "fee", ufmt.Sprintf("%d", fee), + "prevFee", strconv.FormatUint(prevWithdrawalFee, 10), + "newFee", strconv.FormatUint(fee, 10), ) } diff --git a/pool/swap.gno b/pool/swap.gno index 3b8b9c60..6c7b1fbb 100644 --- a/pool/swap.gno +++ b/pool/swap.gno @@ -2,6 +2,7 @@ package pool import ( "std" + "strconv" "gno.land/p/demo/ufmt" "gno.land/r/gnoswap/v1/common" @@ -52,9 +53,9 @@ func Swap( sqrtPriceLimitX96 string, payer std.Address, // router ) (string, string) { - common.IsHalted() + assertOnlyNotHalted() if common.GetLimitCaller() { - caller := std.PrevRealm().Addr() + caller := getPrevAddr() if err := common.RouterOnly(caller); err != nil { panic(addDetailToError( errNoPermission, @@ -114,16 +115,23 @@ func Swap( "prevAddr", prevAddr, "prevRealm", prevPkgPath, "poolPath", GetPoolPath(token0Path, token1Path, fee), - "zeroForOne", ufmt.Sprintf("%t", zeroForOne), - "amountSpecified", amountSpecified, + "zeroForOne", strconv.FormatBool(zeroForOne), + "requestAmount", amountSpecified, "sqrtPriceLimitX96", sqrtPriceLimitX96, "payer", payer.String(), "recipient", recipient.String(), - "internal_amount0", result.Amount0.ToString(), - "internal_amount1", result.Amount1.ToString(), - "internal_protocolFee0", pool.protocolFees.token0.ToString(), - "internal_protocolFee1", pool.protocolFees.token1.ToString(), - "internal_sqrtPriceX96", pool.slot0.sqrtPriceX96.ToString(), + "token0Amount", result.Amount0.ToString(), + "token1Amount", result.Amount1.ToString(), + "protocolFee0", pool.protocolFees.token0.ToString(), + "protocolFee1", pool.protocolFees.token1.ToString(), + "sqrtPriceX96", pool.slot0.sqrtPriceX96.ToString(), + "exactIn", strconv.FormatBool(comp.ExactInput), + "currentTick", strconv.FormatInt(int64(pool.Slot0Tick()), 10), + "liquidity", pool.Liquidity().ToString(), + "feeGrowthGlobal0X128", pool.FeeGrowthGlobal0X128().ToString(), + "feeGrowthGlobal1X128", pool.FeeGrowthGlobal1X128().ToString(), + "balanceToken0", pool.BalanceToken0().ToString(), + "balanceToken1", pool.BalanceToken1().ToString(), ) return result.Amount0.ToString(), result.Amount1.ToString() diff --git a/position/position.gno b/position/position.gno index f1c924eb..01060d31 100644 --- a/position/position.gno +++ b/position/position.gno @@ -237,12 +237,12 @@ func Mint( "Mint", "prevAddr", prevAddr, "prevRealm", prevPkgPath, - "tickLower", ufmt.Sprintf("%d", processedInput.tickLower), - "tickUpper", ufmt.Sprintf("%d", processedInput.tickUpper), + "tickLower", strconv.FormatInt(int64(processedInput.tickLower), 10), + "tickUpper", strconv.FormatInt(int64(processedInput.tickUpper), 10), "poolPath", processedInput.poolPath, "mintTo", mintTo.String(), "caller", caller.String(), - "lpTokenId", ufmt.Sprintf("%d", tokenId), + "lpTokenId", strconv.FormatUint(tokenId, 10), "liquidity", liquidity.ToString(), "amount0", amount0.ToString(), "amount1", amount1.ToString(), @@ -615,6 +615,8 @@ func IncreaseLiquidity( } poolSqrtPriceX96 := pl.PoolGetSlot0SqrtPriceX96(poolPath) + token0Balance := pl.PoolGetBalanceToken0(poolPath) + token1Balance := pl.PoolGetBalanceToken1(poolPath) prevAddr, prevPkgPath := getPrevAsString() @@ -624,11 +626,14 @@ func IncreaseLiquidity( "prevRealm", prevPkgPath, "poolPath", poolPath, "caller", caller.String(), - "lpTokenId", ufmt.Sprintf("%d", tokenId), + "lpTokenId", strconv.FormatUint(tokenId, 10), "liquidity", liquidity.ToString(), "amount0", amount0.ToString(), "amount1", amount1.ToString(), "sqrtPriceX96", poolSqrtPriceX96, + "positionLiquidity", position.liquidity.ToString(), + "token0Balance", token0Balance.ToString(), + "token1Balance", token1Balance.ToString(), ) return tokenId, liquidity.ToString(), amount0.ToString(), amount1.ToString(), poolPath @@ -776,6 +781,8 @@ func DecreaseLiquidity( tokenId, liquidity, fee0, fee1, amount0, amount1, poolPath := decreaseLiquidity(decreaseLiquidityParams) poolSqrtPriceX96 := pl.PoolGetSlot0SqrtPriceX96(poolPath) + token0Balance := pl.PoolGetBalanceToken0(poolPath) + token1Balance := pl.PoolGetBalanceToken1(poolPath) prevAddr, prevPkgPath := getPrevAsString() @@ -783,16 +790,18 @@ func DecreaseLiquidity( "DecreaseLiquidity", "prevAddr", prevAddr, "prevRealm", prevPkgPath, - "lpTokenId", ufmt.Sprintf("%d", tokenId), - "removeLiquidity", liquidityStr, - "internal_poolPath", poolPath, - "internal_liquidity", liquidity.ToString(), - "internal_fee0", fee0.ToString(), - "internal_fee1", fee1.ToString(), - "internal_amount0", amount0.ToString(), - "internal_amount1", amount1.ToString(), - "internal_unwrapResult", ufmt.Sprintf("%t", unwrapResult), - "internal_sqrtPriceX96", poolSqrtPriceX96, + "lpTokenId", strconv.FormatUint(tokenId, 10), + "poolPath", poolPath, + "decreasedLiquidity", liquidity.ToString(), + "feeAmount0", fee0.ToString(), + "feeAmount1", fee1.ToString(), + "amount0", amount0.ToString(), + "amount1", amount1.ToString(), + "unwrapResult", strconv.FormatBool(unwrapResult), + "sqrtPriceX96", poolSqrtPriceX96, + "positionLiquidity", PositionGetPositionLiquidityStr(tokenId), + "token0Balance", token0Balance.ToString(), + "token1Balance", token1Balance.ToString(), ) return tokenId, liquidity.ToString(), fee0.ToString(), fee1.ToString(), amount0.ToString(), amount1.ToString(), poolPath @@ -981,11 +990,11 @@ func CollectFee(tokenId uint64, unwrapResult bool) (uint64, string, string, stri "CollectSwapFee", "prevAddr", prevAddr, "prevRealm", prevPkgPath, - "lpTokenId", ufmt.Sprintf("%d", tokenId), - "fee0", withoutFee0, - "fee1", withoutFee1, + "lpTokenId", strconv.FormatUint(tokenId, 10), + "feeAmount0", withoutFee0, + "feeAmount1", withoutFee1, "poolPath", position.poolKey, - "unwrapResult", ufmt.Sprintf("%t", unwrapResult), + "unwrapResult", strconv.FormatBool(unwrapResult), ) return tokenId, withoutFee0, withoutFee1, position.poolKey, amount0, amount1 @@ -1095,22 +1104,27 @@ func Reposition( mustUpdatePosition(tokenId, position) poolSqrtPriceX96 := pl.PoolGetSlot0SqrtPriceX96(position.poolKey) + token0Balance := pl.PoolGetBalanceToken0(poolPath) + token1Balance := pl.PoolGetBalanceToken1(poolPath) prevAddr, prevPkgPath := getPrevAsString() std.Emit( "Reposition", "prevAddr", prevAddr, "prevRealm", prevPkgPath, - "lpTokenId", ufmt.Sprintf("%d", tokenId), - "tickLower", ufmt.Sprintf("%d", tickLower), - "tickUpper", ufmt.Sprintf("%d", tickUpper), + "lpTokenId", strconv.FormatUint(tokenId, 10), + "tickLower", strconv.FormatInt(int64(tickLower), 10), + "tickUpper", strconv.FormatInt(int64(tickUpper), 10), "liquidity", liquidity.ToString(), "amount0", amount0.ToString(), "amount1", amount1.ToString(), - "oldTickLower", ufmt.Sprintf("%d", oldTickLower), - "oldTickUpper", ufmt.Sprintf("%d", oldTickUpper), + "prevTickLower", strconv.FormatInt(int64(oldTickLower), 10), + "prevTickUpper", strconv.FormatInt(int64(oldTickUpper), 10), "poolPath", position.poolKey, "sqrtPriceX96", poolSqrtPriceX96, + "positionLiquidity", PositionGetPositionLiquidityStr(tokenId), + "token0Balance", token0Balance.ToString(), + "token1Balance", token1Balance.ToString(), ) return tokenId, liquidity.ToString(), tickLower, tickUpper, amount0.ToString(), amount1.ToString() diff --git a/protocol_fee/protocol_fee.gno b/protocol_fee/protocol_fee.gno index 7ee21f4b..3b8d2bf3 100644 --- a/protocol_fee/protocol_fee.gno +++ b/protocol_fee/protocol_fee.gno @@ -2,6 +2,7 @@ package protocol_fee import ( "std" + "strconv" "gno.land/p/demo/avl" "gno.land/p/demo/ufmt" @@ -91,14 +92,16 @@ func setDevOpsPct(pct uint64) { )) } + prevDevOpsPct := devOpsPct devOpsPct = pct - prevAddr, prevRealm := getPrev() + prevAddr, prevPkgPath := getPrev() std.Emit( "SetDevOpsPct", "prevAddr", prevAddr, - "prevRealm", prevRealm, - "pct", ufmt.Sprintf("%d", pct), + "prevRealm", prevPkgPath, + "newPct", strconv.FormatUint(pct, 10), + "prevPct", strconv.FormatUint(prevDevOpsPct, 10), ) } diff --git a/router/exact_in.gno b/router/exact_in.gno index 41ba01fc..f28c98c1 100644 --- a/router/exact_in.gno +++ b/router/exact_in.gno @@ -26,7 +26,7 @@ func NewExactInSwapOperation(pp ExactInParams) *ExactInSwapOperation { func ExactInSwapRoute( inputToken string, outputToken string, - finalAmountIn string, + amountIn string, RouteArr string, quoteArr string, amountOutMin string, @@ -44,7 +44,7 @@ func ExactInSwapRoute( pp := NewExactInParams( baseParams, - finalAmountIn, + amountIn, amountOutMin, ) @@ -58,7 +58,7 @@ func ExactInSwapRoute( )) } - finalAmountIn, finalAmountOut := finalizeSwap( + inputAmount, outputAmount := finalizeSwap( pp.InputToken, pp.OutputToken, result.AmountIn, @@ -78,15 +78,14 @@ func ExactInSwapRoute( "prevRealm", prevPkgPath, "input", pp.InputToken, "output", pp.OutputToken, - "amountIn", result.AmountIn.ToString(), + "exactAmount", amountIn, "route", pp.RouteArr, "quote", pp.QuoteArr, - "internal_amountIn", result.AmountIn.ToString(), - "internal_amountOut", result.AmountOut.ToString(), - "internal_amountOutWithoutFee", result.AmountOut.ToString(), + "resultInputAmount", inputAmount, + "resultOutputAmount", outputAmount, ) - return finalAmountIn, finalAmountOut + return inputAmount, outputAmount } func (op *ExactInSwapOperation) Validate() error { diff --git a/router/exact_out.gno b/router/exact_out.gno index d33bb4c5..61ef6157 100644 --- a/router/exact_out.gno +++ b/router/exact_out.gno @@ -50,7 +50,7 @@ func ExactOutSwapRoute( panic(addDetailToError(errInvalidInput, err.Error())) } - finalAmountIn, finalAmountOut := finalizeSwap( + inputAmount, outputAmount := finalizeSwap( pp.InputToken, pp.OutputToken, result.AmountIn, @@ -70,15 +70,14 @@ func ExactOutSwapRoute( "prevRealm", prevPkgPath, "input", pp.InputToken, "output", pp.OutputToken, - "amountOut", pp.AmountOut, + "exactAmount", amountOut, "route", pp.RouteArr, "quote", pp.QuoteArr, - "internal_amountIn", result.AmountIn.ToString(), - "internal_amountOut", result.AmountOut.ToString(), - "internal_amountOutWithoutFee", result.AmountOut.ToString(), + "resultInputAmount", inputAmount, + "resultOutputAmount", outputAmount, ) - return finalAmountIn, finalAmountOut + return inputAmount, outputAmount } func (op *ExactOutSwapOperation) Validate() error { diff --git a/router/protocol_fee_swap.gno b/router/protocol_fee_swap.gno index 36262029..2aa5848e 100644 --- a/router/protocol_fee_swap.gno +++ b/router/protocol_fee_swap.gno @@ -2,6 +2,7 @@ package router import ( "std" + "strconv" "gno.land/r/gnoswap/v1/common" "gno.land/r/gnoswap/v1/consts" @@ -28,22 +29,24 @@ func GetSwapFee() uint64 { // SetSwapFeeByAdmin modifies the swap fee // Only admin can execute this function func SetSwapFeeByAdmin(fee uint64) { - caller := std.PrevRealm().Addr() + caller := getPrevAddr() if err := common.AdminOnly(caller); err != nil { panic(err) } + prevSwapFee := swapFee if err := setSwapFee(fee); err != nil { panic(err) } - prevAddr, prevRealm := getPrev() + prevAddr, prevPkgPath := getPrev() std.Emit( "SetSwapFeeByAdmin", "prevAddr", prevAddr, - "prevRealm", prevRealm, - "fee", ufmt.Sprintf("%d", fee), + "prevRealm", prevPkgPath, + "newFee", strconv.FormatUint(fee, 10), + "prevFee", strconv.FormatUint(prevSwapFee, 10), ) } @@ -51,22 +54,24 @@ func SetSwapFeeByAdmin(fee uint64) { // Only governance contract can execute this function via proposal // ref: https://docs.gnoswap.io/contracts/router/protocol_fee_swap.gno#setswapfee func SetSwapFee(fee uint64) { - caller := std.PrevRealm().Addr() + caller := getPrevAddr() if err := common.GovernanceOnly(caller); err != nil { panic(err) } + prevSwapFee := swapFee if err := setSwapFee(fee); err != nil { panic(err) } - prevAddr, prevRealm := getPrev() + prevAddr, prevPkgPath := getPrev() std.Emit( "SetSwapFee", "prevAddr", prevAddr, - "prevRealm", prevRealm, - "fee", ufmt.Sprintf("%d", fee), + "prevRealm", prevPkgPath, + "newFee", strconv.FormatUint(fee, 10), + "prevFee", strconv.FormatUint(prevSwapFee, 10), ) } @@ -100,14 +105,14 @@ func handleSwapFee( outputTeller := common.GetTokenTeller(outputToken) outputTeller.TransferFrom(std.PrevRealm().Addr(), consts.PROTOCOL_FEE_ADDR, feeAmountUint64) - prevAddr, prevRealm := getPrev() + prevAddr, prevPkgPath := getPrev() std.Emit( "SwapRouteFee", "prevAddr", prevAddr, - "prevRealm", prevRealm, - "internal_tokenPath", outputToken, - "internal_amount", ufmt.Sprintf("%d", feeAmountUint64), + "prevRealm", prevPkgPath, + "tokenPath", outputToken, + "amount", strconv.FormatUint(feeAmountUint64, 10), ) toUserAfterProtocol := new(u256.Uint).Sub(amount, feeAmount)