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

Mdjakovic/mint burn #803

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open

Mdjakovic/mint burn #803

wants to merge 28 commits into from

Conversation

mdjakovic0920
Copy link
Contributor

@mdjakovic0920 mdjakovic0920 commented Feb 7, 2025

Motivation

This PR introduces a new Burn-Mint ADO contract built using CosmWasm and Andromeda ADO standards.

Key Features & Purpose

  • Allows burning CW20 tokens or CW721 NFTs in exchange for minting a new token/NFT.
  • Supports different burn-mint ratios (e.g., burn 5 NFTs to mint 1 CW20, or burn 100 CW20 to mint 1 NFT).
  • Users can create orders, specifying the required assets and the output asset.
  • Once all required tokens are fully deposited, the burning and minting process is executed automatically.
  • Supports automated refunds for users who contribute excess tokens.

This contract maybe ideal for in-game economies, DeFi applications, and token exchanges that require dynamic asset transformations.

Implementation

Order Creation

Users create burn-mint orders, specifying:

  • Required assets (CW20 tokens or NFTs)
  • Output asset to be minted
  • Required amounts

Automated Token Handling

  • Users send CW20 tokens/NFTs directly to the contract.
  • Contract burns tokens/NFTs automatically once requirements are met.
  • If excess tokens are deposited, they are automatically refunded.

Minting New Tokens/NFTs

Once all required deposits are met, the contract:

  • Burns the deposited assets
  • Mints the output token/NFT to the first user who completed the order
  • Refunds other contributors who deposited excess amounts

Query System

The contract includes robust querying functions, allowing users to:

  • Fetch an order by ID
  • Fetch orders by status (Completed, Cancelled, NotCompleted)
  • Fetch orders a user has contributed to
  • Fetch authorized addresses from instantiation

Testing

The unit test cases are added.

Version Changes

Version is set as 0.1.0-b.1

Checklist

  • Versions bumped correctly and documented
  • Changelog entry added or label applied

Copy link
Contributor

coderabbitai bot commented Feb 7, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

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.


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.

use cw_storage_plus::{Item, Map};

pub const NEXT_ORDER_ID: Item<Uint128> = Item::new("next_order_id");
pub const ORDERS: Map<u128, OrderInfo> = Map::new("orders");
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not Uint128?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the method may_load exists for struct Map<'static, Uint128, OrderInfo>, but its trait bounds were not satisfied
the following trait bounds were not satisfied:
Uint128: PrimaryKey<'_>

Comment on lines 267 to 326
let hook_msg = Cw20HookMsg::FillOrder {
order_id: Uint128::one(),
};
let cw20_receive_msg = Cw20ReceiveMsg {
sender: "origin_cw20_sender".to_string(),
amount: Uint128::new(5000),
msg: encode_binary(&hook_msg).unwrap(),
};

receive_cw20(deps.as_mut(), cw20_receive_msg, MOCK_CW20_CONTRACT).unwrap();

let cw20_receive_msg = Cw20ReceiveMsg {
sender: "origin_cw20_sender_2".to_string(),
amount: Uint128::new(6000),
msg: encode_binary(&hook_msg).unwrap(),
};

receive_cw20(deps.as_mut(), cw20_receive_msg, MOCK_CW20_CONTRACT).unwrap();

let created_order: GetOrderInfoResponse =
query_order_info(deps.as_ref(), Uint128::one()).unwrap();

let order_status = created_order.order_status;
assert_eq!(order_status, OrderStatus::NotCompleted);

let cw20_receive_msg = Cw20ReceiveMsg {
sender: "origin_cw20_sender".to_string(),
amount: Uint128::new(7000),
msg: encode_binary(&hook_msg).unwrap(),
};

receive_cw20(deps.as_mut(), cw20_receive_msg, MOCK_CW20_CONTRACT).unwrap();

let cw20_receive_msg = Cw20ReceiveMsg {
sender: "origin_cw20_sender_2".to_string(),
amount: Uint128::new(4000),
msg: encode_binary(&hook_msg).unwrap(),
};

receive_cw20(deps.as_mut(), cw20_receive_msg, MOCK_CW20_CONTRACT).unwrap();

let created_order: GetOrderInfoResponse =
query_order_info(deps.as_ref(), Uint128::one()).unwrap();

let order_status = created_order.order_status;
assert_eq!(order_status, OrderStatus::NotCompleted);

let cw20_receive_msg = Cw20ReceiveMsg {
sender: "origin_cw20_sender".to_string(),
amount: Uint128::new(24000),
msg: encode_binary(&hook_msg).unwrap(),
};

receive_cw20(deps.as_mut(), cw20_receive_msg, MOCK_CW20_CONTRACT_2).unwrap();

let created_order: GetOrderInfoResponse =
query_order_info(deps.as_ref(), Uint128::one()).unwrap();

let order_status = created_order.order_status;
assert_eq!(order_status, OrderStatus::Completed);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason this can't be done in a loop? Seems to make the test unnecessarily long

ORDERS.save(ctx.deps.storage, order_id.clone().u128(), &order)?;

// Refund excess tokens (only applicable for CW20)
if excess_amount.gt(&Uint128::zero()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens here if the user sends the incorrect CW20 tokens? Should this not error? Seems like wasted gas to have an empty tx (just refunding the entire amount sent). We're also missing test cases for this scenario.

Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly for a CW721 token.

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.

3 participants