Skip to content

docs(contract): refine public docs after #1161#1243

Draft
junghoon-vans wants to merge 3 commits intomainfrom
GSW-2554-update-docs
Draft

docs(contract): refine public docs after #1161#1243
junghoon-vans wants to merge 3 commits intomainfrom
GSW-2554-update-docs

Conversation

@junghoon-vans
Copy link
Copy Markdown
Member

@junghoon-vans junghoon-vans commented Apr 9, 2026

Summary

  • import the initial contract documentation refresh from docs: standardize function comments with Parameters/Returns sections #1161 and keep it as the base of this branch
  • align public docs and examples with the current contract implementation across governance, staker, router, and position surfaces
  • add a small follow-up README wording cleanup to keep accurate examples while avoiding unnecessary wording churn

Notes

Summary by CodeRabbit

Release Notes

  • New Features

    • Added utility functions for encoding/decoding integer values in staker and governance modules.
    • Added emission height getter and data cloning utility.
  • Documentation

    • Enhanced API documentation across governance, staking, emission, and protocol fee modules with structured return and parameter descriptions.
    • Clarified router behavior: native GNOT not directly supported; use wrapped token paths.
    • Updated external incentive refund mechanics to explicitly use provided refund address.
    • Revised governance delegation documentation for xGNS voting power management.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 9, 2026

Walkthrough

This pull request primarily updates inline documentation and docstrings across multiple Gnoswap contract modules, adding structured Parameters and Returns sections to exported functions. It includes minor API additions (HalvingData.Clone(), EncodeInt64/DecodeInt64 helpers, GetEmissionCreatedHeight/GetEmissionStartHeight getters), updates to README examples and module descriptions, and clarifications to reflect semantic changes in external incentive refund behavior and router capabilities.

Changes

Cohort / File(s) Summary
Community Pool & Emission Core Documentation
contract/r/gnoswap/community_pool/community_pool.gno, contract/r/gnoswap/emission/distribution.gno, contract/r/gnoswap/emission/emission.gno, contract/r/gnoswap/emission/getter.gno
Updated doc comments with structured Parameters and Returns sections for exported getter functions (GetBalanceOf, GetDistributionBpsPct, GetDistributedToStaker, MintAndDistributeGns, SetOnDistributionPctChangeCallback, etc.). No logic changes.
GNS Token & Halving Documentation
contract/r/gnoswap/gns/emission.gno, contract/r/gnoswap/gns/getter.gno, contract/r/gnoswap/gns/gns.gno, contract/r/gnoswap/gns/halving.gno
Updated InitEmissionState and token function doc comments with explicit parameter descriptions; added new HalvingData.Clone() method for deep-copying halving state; added/renamed emission height getters (GetEmissionCreatedHeight/GetEmissionStartHeight); expanded docstrings for Name, Symbol, TotalSupply, BalanceOf, etc.
Governance Core & Proxy Documentation
contract/r/gnoswap/gov/governance/README.md, contract/r/gnoswap/gov/governance/proxy.gno, contract/r/gnoswap/gov/governance/upgrade.gno, contract/r/gnoswap/gov/governance/v1/README.md, contract/r/gnoswap/gov/governance/v1/getter.gno
Updated README examples for Delegate, ProposeText, ProposeCommunityPoolSpend signatures; clarified proxy function parameter/return documentation; replaced ufmt.Errorf with errors.New in getter error handling; added doc comments to GetImplementationPackagePath.
Gov Staker Module Refactor Documentation
contract/r/gnoswap/gov/staker/README.md, contract/r/gnoswap/gov/staker/proxy.gno, contract/r/gnoswap/gov/staker/tree.gno, contract/r/gnoswap/gov/staker/upgrade.gno, contract/r/gnoswap/gov/staker/v1/README.md
Updated README to reflect module purpose change from LP staking to governance delegation (xGNS-based staking, undelegation lockup, snapshot-based voting); clarified delegation/reward collection function docstrings; added EncodeInt64/DecodeInt64 helper functions to tree utility; added doc comments to upgrade getter.
xGNS & LaunchPad Documentation
contract/r/gnoswap/gov/xgns/xgns.gno, contract/r/gnoswap/launchpad/proxy.gno, contract/r/gnoswap/launchpad/upgrade.gno
Updated TotalSupply, BalanceOf, Render doc comments in xGNS token; expanded CreateProject, CollectProtocolFee, DepositGns, CollectRewardByDepositId docstrings in launchpad proxy; added doc comments to launchpad upgrade getter.
Pool & Position API Documentation
contract/r/gnoswap/pool/upgrade.gno, contract/r/gnoswap/position/README.md, contract/r/gnoswap/position/getter.gno, contract/r/gnoswap/position/upgrade.gno, contract/r/gnoswap/position/v1/README.md
Updated README examples for IncreaseLiquidity and CollectFee return value changes; clarified GetPositionTokenBalances doc comment; added doc comments to GetImplementationPackagePath in upgrade module.
Protocol Fee & Router Documentation
contract/r/gnoswap/protocol_fee/getter.gno, contract/r/gnoswap/protocol_fee/proxy.gno, contract/r/gnoswap/protocol_fee/upgrade.gno, contract/r/gnoswap/router/README.md, contract/r/gnoswap/router/doc.gno, contract/r/gnoswap/router/proxy.gno, contract/r/gnoswap/router/upgrade.gno, contract/r/gnoswap/router/v1/doc.gno
Updated protocol fee getter/proxy doc comments with structured Returns sections; updated router documentation to clarify no native GNOT support (requires wrapped tokens); refactored swap function docstrings (ExactInSwapRoute, ExactOutSwapRoute, etc.) to clarify routing direction and parameter meanings; removed "automatic GNOT wrapping/unwrapping" claims.
Staker Module External Incentive & Tree Utilities
contract/r/gnoswap/staker/README.md, contract/r/gnoswap/staker/getter.gno, contract/r/gnoswap/staker/proxy.gno, contract/r/gnoswap/staker/tree.gno, contract/r/gnoswap/staker/upgrade.gno, contract/r/gnoswap/staker/v1/README.md, contract/r/gnoswap/staker/v1/external_incentive.gno, contract/r/gnoswap/staker/v1/staker.gno
Updated external incentive documentation to clarify refund address semantics (remaining rewards refunded to explicit refundAddress rather than creator); added EncodeInt64/DecodeInt64 helper functions to tree utility; clarified GetDepositGnsAmount and other proxy function docstrings; removed unwrapResult parameter documentation.
Module Documentation Updates
docs/position.md, docs/staker.md
Removed references to native token handling files (native_token.gno, wrap_unwrap.gno); clarified external incentive refund address semantics in Staker module rules.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

The review involves substantial breadth (40+ files), but most changes are homogeneous documentation updates (structured comment additions). However, the presence of a few new functions (HalvingData.Clone(), EncodeInt64/DecodeInt64), semantic clarifications in behavior descriptions (external incentive refunds, router GNOT handling, module purpose shifts), and API renaming (GetEmissionCreatedHeight/GetEmissionStartHeight) warrant moderate attention to verify intent alignment across changes.

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'docs(contract): refine public docs after #1161' is fully related to the main changeset, which consists entirely of documentation refinements across multiple contract modules following up on PR #1161.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch GSW-2554-update-docs

Warning

Review ran into problems

🔥 Problems

Timed out fetching pipeline failures after 30000ms


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 9, 2026

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (4)
contract/r/gnoswap/gov/staker/tree.gno (1)

138-143: ⚠️ Potential issue | 🟠 Major

Replace direct strconv.ParseInt with explicit bounds checking.

Line 139 uses strconv.ParseInt directly, which does not provide explicit int64 range validation. Per Audit N-05, string-to-number conversions should validate boundaries explicitly.

The safe pattern already exists in this file: use DecodeUint(s) to parse as uint64, then validate against int64 max before casting:

Suggested patch
 func DecodeInt64(s string) int64 {
-	num, err := strconv.ParseInt(s, 10, 64)
-	if err != nil {
-		panic(err)
-	}
-	return num
+	num := DecodeUint(s)
+	if num > 9223372036854775807 {
+		panic(ufmt.Sprintf("value overflows int64: %s", s))
+	}
+	return int64(num)
 }
contract/r/gnoswap/router/README.md (3)

251-292: ⚠️ Potential issue | 🟠 Major

Critical documentation inconsistency: Contradictory native GNOT guidance.

This section provides extensive examples of "Native GNOT Swaps with Refunds" (lines 251-292), directly contradicting the updated documentation at lines 148-162 which states the router "does not handle native ugnot directly" and "rejects native-coin handling." The code confirms native coins are rejected via AssertIsNotHandleNativeCoin() calls in both ExactInSwapRoute and ExactOutSwapRoute.

This entire section (251-292) should be removed to maintain documentation consistency with the actual router implementation.

📝 Proposed fix: Remove contradictory section

Remove lines 251-292 entirely, as they describe functionality that does not exist in the current router implementation. The corrected native token guidance at lines 148-181 already provides the accurate documentation.


298-308: ⚠️ Potential issue | 🟠 Major

Remove outdated developer notes referencing non-existent native GNOT features.

The "Common Integration Pitfalls" section references WUGNOT approval requirements, native GNOT send amounts, automatic refunds, and route vs token identifier confusion—all predicated on native GNOT support that the router explicitly rejects. These notes are now obsolete given the router's AssertIsNotHandleNativeCoin() enforcement.

🔧 Suggested revision

Revise or remove pitfalls 1-4 to focus on actual router integration concerns (e.g., route format vs pool format confusion, slippage protection, deadline handling) rather than non-existent native token flows.


310-317: ⚠️ Potential issue | 🟡 Minor

Update frontend checklist to remove native GNOT items.

The checklist includes multiple items for native GNOT handling (WUGNOT approval, native token amounts, automatic refunds) that are no longer applicable since the router rejects native coins.

✅ Suggested checklist revision

Remove or update checklist items referencing:

  • WUGNOT approval before native GNOT swaps
  • Token identifier distinction ("ugnot" vs "gno.land/r/gnoland/wugnot")
  • Native token send amounts
  • Automatic refund handling

Focus the checklist on actual router requirements: route formatting, slippage limits, deadline handling, and error cases.

🧹 Nitpick comments (1)
contract/r/gnoswap/gns/getter.gno (1)

142-148: Clarify the dual height getters to avoid API ambiguity.

Line 146 and Line 253 both return getCreatedHeight(), but GetEmissionCreatedHeight vs GetEmissionStartHeight suggests different semantics. Consider explicitly marking one as an alias/deprecated for clearer external usage.

✏️ Suggested doc/API clarification
-// GetEmissionStartHeight returns the block height when emission schedule was initialized.
+// GetEmissionStartHeight is an alias of GetEmissionCreatedHeight.
+// Deprecated: prefer GetEmissionCreatedHeight for clearer semantics.
 //
 // Returns:
 //   - height: emission start block height
 func GetEmissionStartHeight() int64 {
 	return getEmissionState().getCreatedHeight()
 }

Also applies to: 248-254


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5697094f-28c6-4cb4-ac75-bb5100073d5e

📥 Commits

Reviewing files that changed from the base of the PR and between 3e051b0 and 1fbbcaa.

📒 Files selected for processing (44)
  • contract/r/gnoswap/community_pool/community_pool.gno
  • contract/r/gnoswap/emission/distribution.gno
  • contract/r/gnoswap/emission/emission.gno
  • contract/r/gnoswap/emission/getter.gno
  • contract/r/gnoswap/gns/emission.gno
  • contract/r/gnoswap/gns/getter.gno
  • contract/r/gnoswap/gns/gns.gno
  • contract/r/gnoswap/gns/halving.gno
  • contract/r/gnoswap/gov/governance/README.md
  • contract/r/gnoswap/gov/governance/proxy.gno
  • contract/r/gnoswap/gov/governance/upgrade.gno
  • contract/r/gnoswap/gov/governance/v1/README.md
  • contract/r/gnoswap/gov/governance/v1/getter.gno
  • contract/r/gnoswap/gov/staker/README.md
  • contract/r/gnoswap/gov/staker/proxy.gno
  • contract/r/gnoswap/gov/staker/tree.gno
  • contract/r/gnoswap/gov/staker/upgrade.gno
  • contract/r/gnoswap/gov/staker/v1/README.md
  • contract/r/gnoswap/gov/xgns/xgns.gno
  • contract/r/gnoswap/launchpad/proxy.gno
  • contract/r/gnoswap/launchpad/upgrade.gno
  • contract/r/gnoswap/pool/upgrade.gno
  • contract/r/gnoswap/position/README.md
  • contract/r/gnoswap/position/getter.gno
  • contract/r/gnoswap/position/upgrade.gno
  • contract/r/gnoswap/position/v1/README.md
  • contract/r/gnoswap/protocol_fee/getter.gno
  • contract/r/gnoswap/protocol_fee/proxy.gno
  • contract/r/gnoswap/protocol_fee/upgrade.gno
  • contract/r/gnoswap/router/README.md
  • contract/r/gnoswap/router/doc.gno
  • contract/r/gnoswap/router/proxy.gno
  • contract/r/gnoswap/router/upgrade.gno
  • contract/r/gnoswap/router/v1/doc.gno
  • contract/r/gnoswap/staker/README.md
  • contract/r/gnoswap/staker/getter.gno
  • contract/r/gnoswap/staker/proxy.gno
  • contract/r/gnoswap/staker/tree.gno
  • contract/r/gnoswap/staker/upgrade.gno
  • contract/r/gnoswap/staker/v1/README.md
  • contract/r/gnoswap/staker/v1/external_incentive.gno
  • contract/r/gnoswap/staker/v1/staker.gno
  • docs/position.md
  • docs/staker.md
💤 Files with no reviewable changes (2)
  • docs/position.md
  • contract/r/gnoswap/staker/v1/staker.gno

Comment on lines +15 to +16
// - height: block height when emission starts
// - timestamp: timestamp when emission starts
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Parameter names in docs don’t match the function signature.

Use createdHeight / startTimestamp in the comment to avoid API confusion.

📝 Proposed doc fix
 // Parameters:
-//   - height: block height when emission starts
+//   - createdHeight: block height when emission starts
 //
-//   - timestamp: timestamp when emission starts
+//   - startTimestamp: timestamp when emission starts
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// - height: block height when emission starts
// - timestamp: timestamp when emission starts
// - createdHeight: block height when emission starts
// - startTimestamp: timestamp when emission starts

Comment on lines +59 to 72
// CollectReward collects the rewards from the protocol fee contract based on the holdings of xGNS.
//
// Parameters:
// - cur: Pass `cross` as argument.
func CollectReward(cur realm) {
getImplementation().CollectReward()
}

// CollectRewardFromLaunchPad claims rewards from launchpad projects.
// CollectRewardFromLaunchPad collects the rewards from the protocol fee contract based on the holdings of xGNS in the launchpad contract (only callable by the launchpad contract).
//
// Parameters:
// - to: address to collect rewards for
// - cur: Pass `cross` as argument.
// - to: The address to delegate.
func CollectRewardFromLaunchPad(cur realm, to address) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Reward source description is incomplete for CollectReward*.

Line 59 and Line 67 describe protocol-fee rewards only, but implementation-level behavior includes emission reward distribution as well. The proxy docs should reflect both components.

📝 Suggested wording update
-// CollectReward collects the rewards from the protocol fee contract based on the holdings of xGNS.
+// CollectReward collects claimable rewards for xGNS holders (including emission and protocol-fee rewards).

-// CollectRewardFromLaunchPad collects the rewards from the protocol fee contract based on the holdings of xGNS in the launchpad contract (only callable by the launchpad contract).
+// CollectRewardFromLaunchPad collects claimable launchpad-linked rewards (including emission and protocol-fee rewards) for a target address (only callable by the launchpad contract).
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// CollectReward collects the rewards from the protocol fee contract based on the holdings of xGNS.
//
// Parameters:
// - cur: Pass `cross` as argument.
func CollectReward(cur realm) {
getImplementation().CollectReward()
}
// CollectRewardFromLaunchPad claims rewards from launchpad projects.
// CollectRewardFromLaunchPad collects the rewards from the protocol fee contract based on the holdings of xGNS in the launchpad contract (only callable by the launchpad contract).
//
// Parameters:
// - to: address to collect rewards for
// - cur: Pass `cross` as argument.
// - to: The address to delegate.
func CollectRewardFromLaunchPad(cur realm, to address) {
// CollectReward collects claimable rewards for xGNS holders (including emission and protocol-fee rewards).
//
// Parameters:
// - cur: Pass `cross` as argument.
func CollectReward(cur realm) {
getImplementation().CollectReward()
}
// CollectRewardFromLaunchPad collects claimable launchpad-linked rewards (including emission and protocol-fee rewards) for a target address (only callable by the launchpad contract).
//
// Parameters:
// - cur: Pass `cross` as argument.
// - to: The address to delegate.
func CollectRewardFromLaunchPad(cur realm, to address) {

Comment on lines +43 to 59
// ExactOutSwapRoute runs a exact-out direction swap through the route that offers the most favorable exchange rate.
//
// Parameters:
// - inputToken: path of input token
// - outputToken: path of output token
// - amountOut: exact output amount
// - routeArr: encoded route array
// - quoteArr: encoded quote array
// - amountInMax: maximum input amount
// - deadline: transaction deadline
// - referrer: referrer address for reward tracking
// - cur: Pass `cross` as argument.
// - inputToken: The path of the input token.
// - outputToken: The path of the output token.
// - amountOut: The amount of the output token.
// - routeArr: The route of the swap.
// - quoteArr: The share of each split of the route.
// - amountInMax: Limits the number of tokens while routing the swap. The maximum amount of tokens to pay.
// - deadline: The timestamp for transaction to be expired.
// - referrer: The referrer address for reward tracking.
//
// Returns:
// - string: actual input amount
// - string: actual output amount
// - tokenIn: The amount sent to the pool from the user (the input of the swap).
// - tokenOut: The amount sent to the user from the pool (the output of the swap).
func ExactOutSwapRoute(cur realm, inputToken string, outputToken string, amountOut string, routeArr string, quoteArr string, amountInMax string, deadline int64, referrer string) (string, string) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Exact-out return docs currently miss router-fee netting behavior.

Line 57 and Line 77 imply users receive the full output amount, but exact-out in this module is net of router fee (user receives amount - routerFee). This should be explicit in the proxy docs to prevent integration/accounting mistakes.

📝 Suggested doc correction
 // Returns:
-//   - tokenIn: The amount sent to the pool from the user (the input of the swap).
-//   - tokenOut: The amount sent to the user from the pool (the output of the swap).
+//   - tokenIn: The amount paid by the user.
+//   - tokenOut: The swap output amount; in exact-out flows, user-received amount is net of router fee.

 // Returns:
-//   - amountIn: actual input amount
-//   - amountOut: actual output amount
+//   - amountIn: actual input amount
+//   - amountOut: swap output amount before/with router fee handling (document net user-received semantics explicitly)
Based on learnings: Router exact-out: user receives `amount - routerFee`, not V3-compatible. Account for router fee in exact-out swaps (Audit C-07).

Also applies to: 63-79

@junghoon-vans junghoon-vans self-assigned this Apr 10, 2026
@junghoon-vans junghoon-vans added the documentation Improvements or additions to documentation label Apr 10, 2026
@junghoon-vans junghoon-vans marked this pull request as draft April 13, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant