๐ Ethereum contract architecture
Last updated
Last updated
https://github.com/fluidity-money/fluidity-app/tree/production/contracts/ethereum
Ethereum support is built as a trio of contracts:
Token - the token for the wrapped asset being traded/transferred, supporting swapping in, swapping out, ERC20 features
WorkerConfig - configuration for each token
LiquidityProvider - abstract wrapper that holds custody of ctokens/atokens
Token takes the user's unwrapped tokens and moves it into the contract
Token sends the unwrapped tokens to the LiquidityProvider
LiquidityProvider provides it to the underlying liquidity provider (Compound or AAVE)
Underlying liquidity provider (Compound/AAVE) mints cToken/aToken with the amount given
LiquidityProvider receives cToken/aToken adjusted to the "exchange rate" of the cToken/aToken (unwrapped token/exchange rate)
Token sends the user an amount equal to the initial unwrapped token of the Fluid Asset form using the mint function
Token burns the minted amount owed to the user wrapping out of the contract
Underlying LiquidityProvider "redeems" the amount of token that the user wishes to unwrap - the underlying redemption process (Compound/AAVE) calculates the amount owed using the amount of the cToken/aToken - on Compound this is cToken * exchange rate
The LiquidityProvider sends the Token the amount redeemed
The Token sends the user their unwrapped asset after redemption
Worker sends to the Token a batch of winners and the span of blocks that was won
Token aggregates the amounts that should be paid out to each winner
Token aggregates the remaining pool amount
Token rewards each user with the internal reward function rewardPool
LiquidityProvider calculates the balance of the underlying assets based on the exchange rate of the cTokens/aTokens held in the Compound/AAVE pool
Token calculates the difference between the amount deposited by users with the amount reported by the LiquidityProvider for the prize pool amount
Token calls the reward from pool function (rewardFromPool
) - which simply calls the mint function and emits a log