Pool Contract
Overview
The Pool
contract is designed for allowing users to take the other side of retail flow. The depositors in the pool share the trader's losses and payout trader's profits. Each asset that serves as collateral has an isolated pool. In the future, we will enable cross collateral as part of a more efficient system. Currently available pools are WEMIX and WEMIX$.
Contracts and Variables
- Owner: Address of the owner.
- Router: Address of the router.
- Trading: Address for trading operations.
- Withdraw Fee: Set to 0.3%. This is set up to discourage flash deposits and withdrawals along with the min deposit time.
- Currency: Address of the currency token.
- Rewards: Address of the rewards contract.
- Utilization Multiplier: Set to 100 in basis points.
- Max Cap: Maximum cap set to 1,000,000 ETH.
- Balances: Mapping of account balances.
- Total Supply: Total supply of staked amount.
- Last Deposited: Tracking last deposit timestamps.
- Min Deposit Time: Minimum deposit time set to 1 hour.
- Open Interest: Tracks open interest in the pool.
- UNIT: Standard unit set to (10^{18}).
Events
- Deposit: Triggers on deposit with user, currency, amount, and LP share.
- Withdraw: Triggers on withdrawal with user, currency, amount, and LP share.
Constructor
- Takes the pool's currency address and initializes the contract.
Governance Methods
- setOwner: Sets a new owner.
- setRouter: Sets the router and updates trading and rewards.
- setParams: Sets various parameters like minimum deposit time, utilization multiplier, max cap, and withdraw fee.
- updateOpenInterest: Updates the open interest amount.
Core Methods
- deposit: Allows depositing of the pool's currency into the pool.
- withdraw: Facilitates the withdrawal of the pool's currency from the pool.
- creditUserProfit: Credits profit to a retail trader's account.
Utility Methods
- _transferIn: Internal method for handling incoming transfers.
- _transferOut: Internal method for handling outgoing transfers.
- _getCurrentBalance: Returns the current balance of the pool.
- getUtilization: Calculates and returns the utilization of the pool.
- getCurrencyBalance: Returns the balance of a given currency for an account.
- getBalance: Returns the LP balance of an account.
Modifiers
- onlyOwner: Ensures that only the owner can call certain functions.
- onlyTrading: Restricts access to certain functions to the trading contract.
Fallback and Receive Functions
- Facilitates receiving ETH directly to the contract.