Submissions
This module implements the SwapDex protocol, which provides a decentralized exchange (DEX) with support for liquidity pools, limit orders, market orders, loyalty rewards, and staking functionalities. It is built on the Sui blockchain and integrates with DeepBook for pool and order management. ## Key Features 1. **Token Minting:** Mint WBTC, WETH, and SWAPDEX tokens. 2. **Pool Creation:** Create and manage liquidity pools for token trading. 3. **Order Management:** Place limit and market orders for base and quote assets. 4. **Rewards System:** Earn loyalty points and DEX token rewards for trades. 5. **Staking:** Stake SWAPDEX tokens to earn points and enhance loyalty rewards. 6. **NFT Rewards:** Redeem loyalty points for exclusive NFTs. ### **Reward and Loyalty Mechanism** - **Earning Points**: Users earn 1 point for every trade if their loyalty account has a non-zero stake. - **DEX Token Rewards**: Users are rewarded with 1 SWAPDEX token for trades. - **Redeeming Points**: Users can redeem 10 points to mint an NFT as a reward. --- ## Constants - **`FLOAT_SCALING`**: Scaling factor for fractional values (`1_000_000_000`). - **`ENeeds10Points`**: Error code indicating insufficient points for NFT rewards (`0`). --- ## Core Data Structures ### `SWAPDEX` - Represents the SWAPDEX token. - Has the `drop` capability. ### `SwapEvent` - Emitted during successful swaps. - **Fields**: - `message`: A vector of bytes containing event details. ### `RewardEvent` - Emitted when a user is rewarded with DEX tokens. - **Fields**: - `message`: A vector of bytes containing event details. ### `LoyaltyAccount` - Tracks user loyalty points and staked tokens. - **Fields**: - `id`: Unique identifier. - `stake`: Staked balance in SWAPDEX tokens. - `points`: Accumulated loyalty points. ### `NFT` - Represents a non-fungible token rewarded to loyal users. - **Fields**: - `id`: Unique identifier. --- ## Functions ### Initialization #### `init(witness: SWAPDEX, ctx: &mut TxContext)` Initializes the SWAPDEX token by creating a treasury cap and metadata. --- ### Token Minting #### `mint_weth(cap: &mut TreasuryCap<WETH>, amount: u64, ctx: &mut TxContext)` Mints WETH tokens and transfers them to the caller. #### `mint_wbtc(cap: &mut TreasuryCap<WBTC>, amount: u64, ctx: &mut TxContext)` Mints WBTC tokens and transfers them to the caller. --- ### Pool Management #### `new_pool<WBTC, WETH>(payment: &mut Coin<SUI>, ctx: &mut TxContext)` Creates a new liquidity pool for WBTC and WETH. #### `new_custodian_account(ctx: &mut TxContext)` Creates a new custodian account for managing assets. #### `make_base_deposit<WBTC, WETH>(pool, coin, account_cap)` Deposits a base asset into a liquidity pool. #### `make_quote_deposit<WBTC, WETH>(pool, coin, account_cap)` Deposits a quote asset into a liquidity pool. #### `withdraw_base<BaseAsset, QuoteAsset>(pool, quantity, account_cap, ctx)` Withdraws base assets from a pool. #### `withdraw_quote<WBTC, WETH>(pool, quantity, account_cap, ctx)` Withdraws quote assets from a pool. --- ### Order Management #### `place_ask_order<WBTC, WETH>(...)` Places a limit order to sell a base asset for a quote asset. #### `place_bid_order<WBTC, WETH>(...)` Places a limit order to buy a base asset with a quote asset. #### `place_base_market_order<WBTC, WETH>(...)` Executes a market order to trade a base asset. #### `place_quote_market_order<WBTC, WETH>(...)` Executes a market order to trade a quote asset. #### `swap_exact_base_for_quote<WBTC, WETH>(...)` Swaps a specific amount of base asset for a quote asset. #### `swap_exact_quote_for_base<WBTC, WETH>(...)` Swaps a specific amount of quote asset for a base asset. --- ### Loyalty System #### `create_account(ctx: &mut TxContext) -> LoyaltyAccount` Creates a new loyalty account. #### `loyalty_account_stake(account: &LoyaltyAccount) -> u64` Returns the staked balance in a loyalty account. #### `loyalty_account_points(account: &LoyaltyAccount) -> u64` Returns the loyalty points of an account. #### `get_reward(account: &mut LoyaltyAccount, ctx: &mut TxContext) -> NFT` Redeems 10 loyalty points for an NFT. #### `stake(account: &mut LoyaltyAccount, stake: Coin<SWAPDEX>)` Stakes SWAPDEX tokens into a loyalty account. #### `unstake(account: &mut LoyaltyAccount, ctx: &mut TxContext) -> Coin<SWAPDEX>` Unstakes SWAPDEX tokens from a loyalty account. --- ### Reward System #### `reward_user_with_dex(cap: &mut TreasuryCap<SWAPDEX>, ctx: &mut TxContext)` Grants a reward of 1 SWAPDEX token to the user. --- ### Event Emission #### `SwapEvent` Emitted after a successful swap operation. #### `RewardEvent` Emitted when a user receives DEX token rewards. This module is a robust example of integrating a loyalty program with a DEX while leveraging the Sui blockchain's capabilities for high-performance token swaps and decentralized finance operations. It balances functionality, usability, and rewards to encourage user participation.
Dacade е отворена платформа и е създадена в сътрудничество с множество приносители. Отидете на хранилището , за да започнете да допринасяте.