the rust based implementation of the me protocol
The Pool contract represents a critical component of the Me Protocol ecosystem. It operates as an Automated Market Maker (AMM) with a unique approach to liquidity provisioning. The Pool contract serves as a bridge between various reward tokens and the native Me token within the Me Protocol.
The Pool contract is organized into several key components:
-
Implemented Traits as Interfaces: These interfaces are defined within the "controllers" folder and are named "a_pool" inside the "deployables" folder.
-
Contract Storage Structure: The contract employs two primary storage structures:
PoolState
andPoolConfig
. Both structures can be found within the "data" folder, under the "a_pool" file. -
Contract Implementations: The contract implementations are encapsulated in the "PoolImpl" trait, residing in the "providers" folder with the file name "a_pool".
The Pool contract draws inspiration from traditional AMMs but introduces unique functionalities tailored to the Me Protocol ecosystem. It embodies the following traits and functionalities from the OpenBrush framework:
-
Access Control: Ensures that access and authorization to various contract functions are correctly managed.
-
PSP34: Akin to the functionality of the well-known ERC-721 standard, PSP34 mints tokens as a representation of positions held within the pool. Liquidity providers receive these tokens, serving as their position in the pool.
-
start_open_rewards: This function initializes the pool, but it can only be activated once both the reward token and Me token have been deposited. Starting the pool allows for conversations, effectively enabling token swaps within the pool.
-
pause_open_rewards: Pauses the pool, temporarily disabling swapping operations with other pools.
-
resume_open_rewards: Resumes the pool, allowing normal operation to continue.
-
check_open_rewards_state: Checks the current state of the pool, determining whether it is paused or actively participating in conversations.
-
get_liquidity_ratios: Provides the liquidity ratio between the Me token and the reward token within the pool.
-
withdraw_liquidity: Enables liquidity providers to withdraw their assets from the pool.
-
record_liquidity_provided: Records the liquidity provided into the pool, creating positions and issuing PSP34 tokens to liquidity providers.
- initiate_outgoing_conversation: This function serves as the entry point for inter-pool conversations. It facilitates the swapping of tokens between different pools, enhancing the overall liquidity provision in the Me Protocol.
The Pool contract is a fundamental component of the Me Protocol, facilitating the seamless exchange of various reward tokens and the Me token. Its unique approach to AMM operations makes it an essential element within the ecosystem.
For a deeper understanding of the contract's inner workings, please refer to the official documentation or the MY AI, Inc. documentation to explore the mathematical formulas and unique mechanisms that drive this innovative pool contract.
The Treasury contract is a central component of the Me Protocol ecosystem. It functions as a ledger that tracks all tokens owned by business owners. Any tokens sent to or withdrawn from pools by business owners are meticulously accounted for in the treasury.
The Treasury contract is responsible for managing various aspects of token flows within the Me Protocol:
- deposit_reward_and_or_me: This function is called after a pair of reward and Me tokens has been deposited into the treasury. It serves as the record-keeping mechanism for these deposited tokens.
- withdraw_reward_and_or_me: This function is responsible for withdrawing both the reward token and the Me token, providing flexibility for token management.
- pay_for_some_costs: Business owners can use this function to cover specific costs incurred within the protocol.
- top_up_pool_with_reward_and_or_me: This function is used to add more Me tokens and reward tokens to the treasury. It is a vital aspect of liquidity provisioning within the Me Protocol.
- set_reward_notify_limit: This function is employed to configure reward notification limits, ensuring effective communication and monitoring of reward-related activities.
The Treasury contract plays a pivotal role in ensuring the transparent and accountable management of tokens within the Me Protocol. By recording all token movements and providing essential functions for depositing, withdrawing, and maintaining token liquidity, it serves as a foundational element of the Me Protocol ecosystem.
For in-depth insights into the inner workings of the contract and its role within the protocol, refer to the official documentation or MY AI, Inc.'s comprehensive resources.
The Bounty contract serves as the central hub for storing rewards that are meant to be distributed to users after they have successfully completed specific tasks within the Me Protocol ecosystem.
The Bounty contract primarily manages the following functionalities:
-
Depositing Bounty Rewards
- deposit_bounty: This function is used to record and store deposited rewards within the Bounty contract.
-
Withdrawing Bounty Rewards
- withdraw_bounty: Business owners or administrators can withdraw bounty rewards from the contract.
-
Setting Trigger Limits
- set_trigger_limit: This function allows the configuration of a trigger limit that specifies when the bounty rewards will be distributed to users who have successfully fulfilled certain tasks.
-
Retrieving Trigger Limits
- get_trigger_limit: You can use this function to retrieve the currently set trigger limit, providing insights into when users can expect to receive their bounty rewards.
The Bounty contract plays a vital role in the Me Protocol ecosystem by facilitating the transparent distribution of rewards to users. As users complete specific tasks, the Bounty contract records and manages these rewards, ensuring a seamless process for the entire ecosystem.
For more comprehensive information on the Bounty contract and its functionalities, please refer to the official documentation or MY AI, Inc.'s educational materials.
The Payment contract serves as a fundamental component of the Me Protocol, offering a range of features and functions aimed at facilitating transactions between brands and other users. The core functionality of the Payment contract includes:
- Brand Deposits: Enabling brands to deposit and acquire shares in the Payment contract.
- Payment for Services: Allowing brands to use their deposited shares to pay for various services within the Me Protocol.
- Withdrawals: Brands can withdraw their shares from the Payment contract, providing a flexible approach to managing their holdings.
- Admin Withdrawals: Admins have the capability to withdraw payments for services rendered within the Me Protocol.
The Payment contract implements a set of methods to manage these functionalities:
-
Brand Deposit of Me Tokens
- brand_deposit_me: This function facilitates the deposit of Me tokens into the Payment contract, allowing brands to acquire shares.
-
Brand Payment for Services
- brand_service_payment: Brands can use this function to pay for services with their Me token shares.
-
Brand Withdrawal of Me Tokens
- brand_withdraw_me: Brands can withdraw Me tokens from the contract after successful transactions or service payments.
-
Retrieving Brand Me Token Balance
- brand_me_balance: This function provides the current Me token balance of a brand within the Payment contract.
-
Protocol Withdrawal of Me Tokens
- protocol_withdraw_me: Admins or protocol-level users can withdraw Me tokens from the Payment contract.
-
Retrieving Protocol Me Token Balance
- protocol_me_balance: This function returns the current Me token balance at the protocol level.
-
Setting Up Payment Contract
- set_up_payment: Admins can configure the Me token contract for the Payment contract.
-
Retrieving Me Token Address
- get_me_id: This function allows users to retrieve the address of the Me token contract.
The Payment contract is a crucial element of the Me Protocol, serving as the gateway for brands to engage in transactions and payments. Brands can deposit, use, and withdraw their Me token shares, while administrators can manage payments for services. The Payment contract plays a pivotal role in ensuring a smooth and secure payment process within the Me Protocol ecosystem.
For detailed information on the Payment contract and its functions, refer to the official documentation or educational materials provided by MY AI, Inc.
The Oracle contract is a critical component of the Me Protocol, dedicated to a singular function that plays a vital role in ensuring smooth cross-pool interactions. This function is designed to obtain the equivalent value of a reward token from one pool to another. Just like a conventional price oracle, the Oracle contract excels in calculating the corresponding amount of reward between two pools: Pool A and Pool B.
The Oracle contract implements a single function:
- Determine Needed Reward B Given Reward A
- Function Name:
determine_needed_reward_b_given_reward_a
- Parameters:
reward_a
: The AccountId of the source pool (Pool A).reward_b
: The AccountId of the destination pool (Pool B).amount
: The specified amount in Me tokens.
- Return Type: A
u128
value representing the required amount of the target reward token (Reward B). - Error Handling: The function returns a
Result
that includes the calculated amount or an error if the operation encounters any issues.
- Function Name:
The Oracle contract serves as a crucial bridge for Me Protocol users, enabling them to seamlessly determine the equivalent value of reward tokens when moving assets between different pools. The Oracle function, determine_needed_reward_b_given_reward_a
, ensures efficient and accurate conversions, making it an essential tool for users operating within the Me Protocol ecosystem.
For comprehensive information regarding the Oracle contract and its function, please refer to the official documentation or educational resources provided by MY AI, Inc.
The Services contract is a key component of the Me Protocol, designed to manage interactions among brands, customers, and administrators. This contract encapsulates three main roles: Brand, Customer, and Admin, each with its specific functions and responsibilities. The Services contract ensures efficient protocol management, customer operations, and brand reward handling, making it a comprehensive tool within the Me Protocol ecosystem.
The Brand component exposes various functions that allow brands to manage their rewards and liquidity pools. Brands can create new rewards, update reward details, manage liquidity, and perform other related operations.
-
Create New Reward
- Function Name:
create_new_reward
- Parameters:
reward
: AccountIdreward_name
: Optionreward_symbol
: Optionreward_description_link
: Optionreward_type
: u8brand_id
: BRAND_ID_TYPErequestor
: AccountIdpool_id
: AccountId
- Description: Creates a new reward token for the brand.
- Function Name:
-
Update Reward Details
- Function Name:
update_reward_details
- Parameters:
reward
: AccountIdreward_details
: EditableRewardDetailsignore_default
: bool
- Description: Updates details of an existing reward token.
- Function Name:
-
Add Liquidity for Open Rewards
- Function Name:
add_liquidity_for_open_rewards
- Parameters:
reward
: AccountIdreward_amount
: Balanceme_amount
: Balance
- Description: Adds liquidity for open rewards.
- Function Name:
-
Withdraw Rewards from Bounty Pool to Treasury
- Function Name:
withdraw_rewards_from_bounty_pool_to_treasury
- Parameters:
reward
: AccountIdamount
: Balance
- Description: Withdraws specified amount of rewards from the bounty pool to the treasury.
- Function Name:
-
Update Brand Details
- Function Name:
update_brand_details
- Parameters:
brand_details
: EditableBrandDetailsignore_default
: bool
- Description: Updates the details of a brand.
- Function Name:
The Customer component provides functions that allow customers to interact with the rewards, including spending, exchanging, and managing their rewards.
-
Spend Rewards on Issuing Brand
- Function Name:
spend_rewards_on_issuing_brand
- Parameters:
reward
: AccountIdamount
: Balance
- Description: Allows customers to spend rewards on the issuing brand.
- Function Name:
-
Spend Rewards on Other Brand
- Function Name:
spend_rewards_on_other_brand
- Parameters:
reward_at_hand
: AccountIdtargeted_reward
: AccountIdamount_of_reward_at_hand
: Balanceexpected_amount_of_targeted_reward
: Balance
- Description: Enables customers to spend rewards on a different brand.
- Function Name:
-
Exchange Brand Rewards
- Function Name:
exchange_brand_rewards
- Parameters:
reward_at_hand
: AccountIdtargeted_reward
: AccountIdamount_of_reward_at_hand
: Balanceexpected_amount_of_targeted_reward
: Balanceto
: AccountId
- Description: Allows customers to exchange brand rewards with another user.
- Function Name:
The Admin component is responsible for managing the overall protocol configurations and records. Admins can update protocol configurations, manage brands, and handle other administrative tasks.
-
Get Protocol Config
- Function Name:
get_protocol_config
- Return Type: EditableProtocolConfig
- Description: Retrieves the current protocol configuration.
- Function Name:
-
Update Protocol Configurations
- Function Name:
update_protocol_configurations
- Parameters:
config
: EditableProtocolConfig
- Description: Updates the protocol configurations.
- Function Name:
-
Register Brand
- Function Name:
register_brand
- Parameters:
brand_name
: Optionbrand_online_presence
: Optionbrand_account
: AccountIdbrand_id
: BRAND_ID_TYPE
- Description: Registers a new brand in the protocol.
- Function Name:
-
Update Treasury Address
- Function Name:
update_treasury_address
- Parameters:
address
: AccountId
- Description: Updates the treasury address in the protocol.
- Function Name:
The Services contract is a comprehensive and essential component of the Me Protocol, enabling seamless interactions among brands, customers, and administrators. By encapsulating functionalities for managing rewards, liquidity, and protocol configurations, the Services contract ensures a robust and efficient protocol operation.
For more detailed information regarding the Services contract and its functionalities, please refer to the official documentation or educational resources provided by MY AI, Inc.
The governance function is used to pass proposals and create votes within the Me Protocol. This component is essential for managing decision-making processes and ensuring that protocol changes are carried out democratically and transparently.
-
Hash Proposal
- Function Name:
hash_proposal
- Description: Generates a unique hash for a given proposal consisting of a list of transactions and a description hash. This ensures that each proposal is uniquely identifiable.
- Function Name:
-
State
- Function Name:
state
- Description: Retrieves the current state of a proposal, such as whether it is pending, succeeded, or failed. This helps in tracking the proposal's progress.
- Function Name:
-
Proposal Snapshot
- Function Name:
proposal_snapshot
- Description: Returns the timestamp at which votes for a proposal start. This defines the beginning of the voting period for a proposal.
- Function Name:
-
Proposal Deadline
- Function Name:
proposal_deadline
- Description: Returns the timestamp at which votes for a proposal end. This marks the end of the voting period.
- Function Name:
-
Proposal Proposer
- Function Name:
proposal_proposer
- Description: Returns the AccountId of the proposer of a proposal. This identifies who initiated the proposal.
- Function Name:
-
Get Votes with Parameters
- Function Name:
get_votes_with_params
- Description: Returns the number of votes already cast for a proposal by a given account, considering specific parameters. This provides detailed voting information.
- Function Name:
-
Propose
- Function Name:
propose
- Description: Allows a user to make a proposal for a list of transactions to be executed, and returns the ID of the proposal. This is the starting point for any governance decision.
- Function Name:
-
Execute
- Function Name:
execute
- Description: Executes a proposal if it is in the
Succeeded
state, meaning it has passed all necessary votes. It returns the ID of the executed proposal.
- Function Name:
-
Cancel
- Function Name:
cancel
- Description: Cancels a proposal if it is in the
Pending
state and returns the ID of the canceled proposal. This allows the proposer to withdraw a proposal before it is voted on.
- Function Name:
-
Cast Vote
- Function Name:
cast_vote
- Description: Allows a user to cast a vote for a proposal, specifying their support and optionally providing a reason and additional parameters. It returns the number of votes cast by the user.
- Function Name:
-
Cast Vote with Signature
- Function Name:
cast_vote_with_signature
- Description: Allows a user to cast a vote for a proposal using a cryptographic signature for verification. This adds an extra layer of security.
- Function Name:
-
Cast Vote with Signature and Parameters
- Function Name:
cast_vote_with_signature_and_params
- Description: Similar to casting a vote with a signature, but also includes additional parameters. This is useful for more complex voting scenarios.
- Function Name:
The Governance contract is a critical component of the Me Protocol, facilitating the democratic and transparent management of protocol changes. By providing functionalities for proposing, voting on, and executing proposals, the Governance contract ensures that all stakeholders have a voice in the protocol's evolution.
For more detailed information regarding the Governance contract and its functionalities, please refer to the official documentation or educational resources provided by MY AI, Inc.
-
Build a Docker image with the required dependencies using the provided Dockerfile:
docker build -t my-rust-environment .
-
Run the Docker container:
docker run -it my-rust-environment
You now have a container with the necessary dependencies to build and test your contracts.