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

update contracts folder structure #2626

Merged
merged 4 commits into from
Jan 7, 2025
Merged

Conversation

credence0x
Copy link
Collaborator

@credence0x credence0x commented Jan 7, 2025

  • update ./contracts folder structures
  • update ./bot/discord folder structure

Summary by CodeRabbit

  • New Features

    • Increased resource precision from 1,000 to 1,000,000,000 across multiple components
    • Updated resource calculations to use dynamic precision configuration
  • Chores

    • Removed contracts/package.json and contracts/scripts/client.sh
    • Updated GitHub Actions workflow to reflect new directory structure
  • Refactor

    • Modified resource handling in various game components to use global configuration
    • Updated constant values for resource precision in contracts and SDK

Copy link

vercel bot commented Jan 7, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
eternum ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 7, 2025 4:50pm
eternum-docs ❌ Failed (Inspect) Jan 7, 2025 4:50pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
eternum-landing ⬜️ Ignored (Inspect) Visit Preview Jan 7, 2025 4:50pm

Copy link
Contributor

mentatbot bot commented Jan 7, 2025

Hi @credence0x! You need to be added as a user to interact with me. Please ask @ponderingdemocritus to add you on the settings page.

You are receiving this comment because I am set to review all PRs. That is configurable here.

Copy link
Contributor

coderabbitai bot commented Jan 7, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This pull request introduces a significant update to resource precision across the entire project. The primary change involves modifying the RESOURCE_PRECISION constant from 1,000 to 1,000,000,000 in multiple files, including contracts, client-side code, and configuration files. This modification affects resource calculations, formatting, and handling throughout the application, ensuring a more granular and consistent approach to resource representation.

Changes

File Path Change Summary
.github/workflows/discord-bot.yml Updated sparse checkout and working directory paths from discord-bot to bot/discord
bot/discord/src/events/battle_pillage.rs Added RESOURCE_PRECISION constant with value 1_000_000_000
client/apps/docs/utils/formatting.tsx Modified formatAmount function to use dynamic resource precision
client/apps/game/src/* Multiple files updated to use EternumGlobalConfig.resources.resourcePrecision
client/sdk/packages/eternum/src/constants/global.ts Updated RESOURCE_PRECISION and RESOURCE_MULTIPLIER to 1_000_000_000
contracts/game/src/* Updated RESOURCE_PRECISION constant across multiple files
contracts/package.json Removed entirely
contracts/scripts/client.sh Deleted shell script

Sequence Diagram

sequenceDiagram
    participant GlobalConfig as EternumGlobalConfig
    participant ResourceHandler as Resource Management
    participant UIComponent as UI Components
    participant ContractSystem as Contract Systems

    GlobalConfig->>ResourceHandler: Set resourcePrecision to 1,000,000,000
    ResourceHandler-->>UIComponent: Update resource calculations
    ResourceHandler-->>ContractSystem: Update resource precision
    UIComponent->>ContractSystem: Use new precision for transactions
Loading

Possibly related PRs

  • No strongly related PRs were identified in the provided context.

Poem

🐰 Precision Hop, a Rabbit's Tale

From thousand to billion, we scale with might,
Resources dancing in decimal's light,
A million-fold leap, so precise and clean,
Our code now sparkles, a computational dream!

Hop hop hooray! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Jan 7, 2025

Failed to generate code suggestions for PR

Copy link
Contributor

@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: 0

🔭 Outside diff range comments (1)
.github/workflows/discord-bot.yml (1)

Update paths-ignore to match the current project structure

The paths-ignore section needs the following updates to match the current folder structure:

  • Remove config/** as this directory no longer exists
  • Remove .github/** as this would prevent the workflow itself from running
  • Add bot/** to the exclusion list if bot-related changes should trigger the workflow
🔗 Analysis chain

Line range hint 4-11: Consider updating paths-ignore section.

The paths-ignore section might need updating to reflect the new folder structure changes.

Let's verify if there are any other folder structure changes that should be reflected here:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any recent folder structure changes
git diff --name-status HEAD~5 HEAD | grep -E '^R|^D|^A' | sort

Length of output: 251


Script:

#!/bin/bash
# List all directories at root level
echo "=== Directories at root level ==="
fd --max-depth 1 --type d

# List all files at root level
echo -e "\n=== Files at root level ==="
fd --max-depth 1 --type f

Length of output: 320

🧰 Tools
🪛 actionlint (1.7.4)

28-28: the runner of "actions-rs/toolchain@v1" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🧹 Nitpick comments (3)
client/apps/docs/utils/formatting.tsx (1)

17-17: Simplify complex nested ternary operation

The nested ternary operation makes the code hard to read and maintain. Consider refactoring into a more readable format.

-    return `${(amount / EternumGlobalConfig.resources.resourcePrecision).toFixed(amount % EternumGlobalConfig.resources.resourcePrecision === 0 ? 0 : (amount % EternumGlobalConfig.resources.resourcePrecision) % 10 === 0 ? 1 : 2)}M`;
+    const normalizedAmount = amount / EternumGlobalConfig.resources.resourcePrecision;
+    const remainder = amount % EternumGlobalConfig.resources.resourcePrecision;
+    const decimals = remainder === 0 ? 0 : 
+                     remainder % 10 === 0 ? 1 : 2;
+    return `${normalizedAmount.toFixed(decimals)}M`;
client/apps/game/src/ui/components/structures/construction/StructureConstructionMenu.tsx (1)

127-127: Use multiplyByPrecision utility consistently

For consistency with the rest of the codebase, use the imported multiplyByPrecision utility instead of directly multiplying with EternumGlobalConfig.resources.resourcePrecision.

-              amount={cost[Number(resourceId)].min_amount * EternumGlobalConfig.resources.resourcePrecision}
+              amount={multiplyByPrecision(cost[Number(resourceId)].min_amount)}
bot/discord/src/events/battle_pillage.rs (1)

46-46: Consider adding formatting for better readability.

The resource amount display could benefit from formatting for better readability, especially with the increased precision.

Consider adding thousand separators or using a dedicated formatting function:

-format!("{} {}", amount / RESOURCE_PRECISION, ResourceIds::from(*resource_id),)
+format!("{:,} {}", amount / RESOURCE_PRECISION, ResourceIds::from(*resource_id),)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e789617 and 4960292.

⛔ Files ignored due to path filters (6)
  • bot/discord/Cargo.lock is excluded by !**/*.lock
  • contracts/game/Scarb.lock is excluded by !**/*.lock
  • contracts/season_pass/Scarb.lock is excluded by !**/*.lock
  • contracts/season_pass/contracts/.DS_Store is excluded by !**/.DS_Store
  • contracts/season_resources/Scarb.lock is excluded by !**/*.lock
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (17)
  • .github/workflows/discord-bot.yml (4 hunks)
  • bot/discord/src/events/battle_pillage.rs (2 hunks)
  • client/apps/docs/utils/formatting.tsx (1 hunks)
  • client/apps/game/src/hooks/helpers/battles/__test__/__mock__.tsx (2 hunks)
  • client/apps/game/src/ui/components/resources/realm-transfer.tsx (2 hunks)
  • client/apps/game/src/ui/components/structures/construction/StructureConstructionMenu.tsx (2 hunks)
  • client/apps/game/src/ui/components/trading/MarketOrderPanel.tsx (2 hunks)
  • client/sdk/packages/eternum/src/constants/global.ts (1 hunks)
  • contracts/game/src/constants.cairo (1 hunks)
  • contracts/game/src/models/combat.cairo (1 hunks)
  • contracts/game/src/systems/bank/contracts/liquidity.cairo (3 hunks)
  • contracts/game/src/systems/bank/contracts/swap.cairo (5 hunks)
  • contracts/game/src/systems/combat/contracts/battle_systems.cairo (0 hunks)
  • contracts/game/src/systems/transport/tests/travel_systems_tests.cairo (2 hunks)
  • contracts/game/src/utils/testing/config.cairo (1 hunks)
  • contracts/package.json (0 hunks)
  • contracts/scripts/client.sh (0 hunks)
💤 Files with no reviewable changes (3)
  • contracts/scripts/client.sh
  • contracts/package.json
  • contracts/game/src/systems/combat/contracts/battle_systems.cairo
👮 Files not reviewed due to content moderation or server errors (4)
  • contracts/game/src/constants.cairo
  • contracts/game/src/systems/transport/tests/travel_systems_tests.cairo
  • client/apps/game/src/ui/components/trading/MarketOrderPanel.tsx
  • contracts/game/src/models/combat.cairo
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Run pr agent on every pull request, respond to user comments
  • GitHub Check: clippy
🔇 Additional comments (13)
client/apps/docs/utils/formatting.tsx (1)

14-14: Review the 'K' suffix usage with new precision

The 'K' suffix might be misleading since we're now using a much higher precision (1,000,000,000). Consider using a more appropriate suffix or updating the formatting logic to reflect the new scale.

client/apps/game/src/hooks/helpers/battles/__test__/__mock__.tsx (1)

36-43: LGTM! Consistent use of resource precision

The mock battle health values are correctly updated to use EternumGlobalConfig.resources.resourcePrecision, maintaining consistency with the new precision standard.

contracts/game/src/systems/bank/contracts/liquidity.cairo (2)

43-43: LGTM! Clear documentation update

The comment has been correctly updated to reflect the new precision in price calculations.


149-149: Verify impact of precision change on price calculations

The change in resource price calculation affects financial operations. Ensure all systems consuming this price value handle the new precision correctly.

✅ Verification successful

Precision handling is consistent with codebase standards

The multiplication by RESOURCE_PRECISION in the price calculation follows the established pattern used throughout the codebase, where all resource amount calculations are normalized using the same precision factor (1_000_000_000). All systems consuming these values handle the precision correctly.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Find all references to market.quote_amount to verify precision handling
ast-grep --pattern 'market.quote_amount($_)'

Length of output: 46


Script:

#!/bin/bash
# Search for quote_amount mentions
rg "quote_amount" -A 2

# Search for RESOURCE_PRECISION usage
rg "RESOURCE_PRECISION" -A 2

# Search for market related function calls
rg "market\." -A 2

Length of output: 58362

contracts/game/src/systems/bank/contracts/swap.cairo (3)

23-23: LGTM: Import of RESOURCE_PRECISION constant.

The import of RESOURCE_PRECISION aligns with the project-wide update to resource precision.


49-49: LGTM: Updated comment for resource price precision.

The comment accurately reflects that the price is now based on RESOURCE_PRECISION instead of the hardcoded value.


101-101: Verify consistent resource price calculations.

The price calculations have been updated to use RESOURCE_PRECISION consistently across the buy, sell, and emit_event functions.

Run the following script to verify consistent usage of RESOURCE_PRECISION in price calculations:

Also applies to: 155-155, 188-188

✅ Verification successful

RESOURCE_PRECISION is used consistently in price calculations

The codebase shows consistent usage of RESOURCE_PRECISION (1_000_000_000) across all market operations, including buy, sell, and event emissions. No inconsistencies or hardcoded values were found in price calculations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent usage of RESOURCE_PRECISION in price calculations.

# Test: Search for any remaining hardcoded values (1000) in price calculations
rg -A 5 $'1000.*price' 

# Test: Search for all price calculations to ensure they use RESOURCE_PRECISION
ast-grep --pattern $'market.buy($_, $_, RESOURCE_PRECISION)'

Length of output: 85


Script:

#!/bin/bash
# Search for RESOURCE_PRECISION usage
echo "=== RESOURCE_PRECISION usage ==="
rg "RESOURCE_PRECISION"

echo -e "\n=== Market function implementations ==="
# Search for market function implementations
rg -A 5 "fn (buy|sell|emit_event)"

echo -e "\n=== Numerical literals in price calculations ==="
# Search for numerical literals in price-related code
rg -A 5 "price.*[0-9]+" 
rg -A 5 "[0-9]+.*price"

Length of output: 36697

client/apps/game/src/ui/components/resources/realm-transfer.tsx (2)

9-9: LGTM: Import of EternumGlobalConfig.

The import of EternumGlobalConfig aligns with the project-wide update to resource precision.


67-67: LGTM: Updated resource amount calculation.

The resource amount calculation now correctly uses EternumGlobalConfig.resources.resourcePrecision instead of the hardcoded value.

contracts/game/src/utils/testing/config.cairo (1)

111-111: LGTM: Updated max troop count calculation.

The max troop count calculation now correctly uses RESOURCE_PRECISION instead of the hardcoded value.

client/sdk/packages/eternum/src/constants/global.ts (1)

49-50: Verify impact of increased resource precision.

The significant increase in RESOURCE_PRECISION and RESOURCE_MULTIPLIER from 1000 to 1_000_000_000 is a breaking change that affects all resource calculations throughout the application.

Run the following script to verify that all resource calculations handle the increased precision correctly:

✅ Verification successful

Resource precision change is properly handled across the codebase

The increase in RESOURCE_PRECISION from 1000 to 1_000_000_000 is safely implemented:

  • All resource calculations consistently use BigInt/u128 types
  • Proper normalization is applied in calculations
  • Resource amounts are correctly scaled with precision
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify resource calculations with increased precision.

# Test: Search for potential integer overflow issues in calculations
rg -A 5 $'[*]/.*RESOURCE_PRECISION'

# Test: Search for any remaining hardcoded values (1000) in resource calculations
rg -A 5 $'[*]/.*1000'

# Test: Search for resource-related type definitions to ensure they can handle the increased precision
ast-grep --pattern $'type.*Resource'

Length of output: 97


Script:

#!/bin/bash
# Search for direct usage of the constants
rg "RESOURCE_PRECISION|RESOURCE_MULTIPLIER" -B 2 -A 2

# Search for resource-related calculations and variables
rg "resource.*=.*[*/]|[*/].*resource" -i -B 2 -A 2

# Search for numeric type definitions that might be affected
ast-grep --pattern 'type $_ = number'

# Search for BigInt usage which might indicate large number handling
rg "BigInt|bigint" -B 2 -A 2

Length of output: 76336


Script:

#!/bin/bash
# Search for numeric type declarations and BigInt usage in TypeScript
rg "type.*number|type.*bigint|BigInt" -g "*.ts" -B 2 -A 2

# Search for arithmetic operations with RESOURCE_PRECISION
rg "RESOURCE_PRECISION.*[*/+\-]|[*/+\-].*RESOURCE_PRECISION" -B 2 -A 2

# Search for potential numeric overflow checks
rg "overflow|exceed|limit|max|bound" -g "*.{ts,cairo}" -B 2 -A 2

Length of output: 70154

.github/workflows/discord-bot.yml (1)

25-25: LGTM! Path updates are consistent with the new folder structure.

The changes correctly update the paths from discord-bot to bot/discord across both jobs.

Also applies to: 35-35, 44-44, 57-57

bot/discord/src/events/battle_pillage.rs (1)

17-17: Verify resource precision consistency across the codebase.

The new RESOURCE_PRECISION constant aligns with the project-wide update to resource precision. Let's verify consistency with other implementations:

✅ Verification successful

Resource precision implementation is correctly scoped

The RESOURCE_PRECISION constant is appropriately implemented in battle_pillage.rs as it's the only event handler that needs to format resource amounts for Discord messages. No other event handlers require this functionality, making the current implementation consistent and well-scoped.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for RESOURCE_PRECISION declarations and usages
echo "Searching for RESOURCE_PRECISION declarations:"
rg -p "RESOURCE_PRECISION.*=.*1_?0{3}(_?0{3})*" --type rust --type typescript --type cairo

echo -e "\nSearching for resource amount divisions:"
rg -p "/ *(?:RESOURCE_PRECISION|1_?0{3}(?:_?0{3})*)" --type rust --type typescript --type cairo

Length of output: 460


Script:

#!/bin/bash
# Search for precision-related constants and their usage
echo "=== Rust Files ==="
echo "Searching for precision constants:"
rg -p "(?:RESOURCE|TOKEN|PRECISION).*=.*1_?0{3}(_?0{3})*" --type rust

echo -e "\nSearching for precision divisions:"
rg -p "/ *(?:RESOURCE_PRECISION|TOKEN_PRECISION|1_?0{9})" --type rust

echo -e "\n=== Cairo Files ==="
echo "Searching for precision constants:"
rg -p "(?:RESOURCE|TOKEN|PRECISION).*=.*10\*\*[69]" --type cairo

echo -e "\nSearching for precision divisions:"
rg -p "/ *(?:RESOURCE_PRECISION|TOKEN_PRECISION|10\*\*[69])" --type cairo

# Find all potential source files to ensure we're not missing any
echo -e "\n=== Source Files ==="
fd -e rs -e cairo -e ts

Length of output: 15857


Script:

#!/bin/bash
# Check other event handlers for resource formatting
echo "=== Checking resource formatting in event handlers ==="
rg -p "format.*amount.*resource" bot/discord/src/events/

# Look for similar resource-related constants in other event files
echo -e "\n=== Checking resource constants in event handlers ==="
rg -p "(?:const|let).*(?:RESOURCE|PRECISION)" bot/discord/src/events/

Length of output: 604

@credence0x credence0x changed the base branch from next to season-1 January 7, 2025 16:42
@credence0x credence0x merged commit 1a48f2f into season-1 Jan 7, 2025
5 of 13 checks passed
@credence0x credence0x deleted the contracts-folder-structure branch January 7, 2025 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant