There are 4 main logical components that contribute to Alpaca Leverage Farming platform.
Frontend - Alpaca Interface
Liquidator - Bots that watch positions margin and liquidate if the position's debt raitio hit the threshold
Reinvestor - Bots that harvest the yield and compound back to the position
Implied by the name, this is the contract that keep the tokens deposited from the users that want to lend out their valuable assets. Vault also allow borrower to request fund from the vault in return of dynamic interest with respect to utilization of the deposited funds at that point in time.
Act as a position manager that responsible for handling how users fund will be used. This includes opening a yield farming position at a specific DEX, close the position, adjust the position. Each worker will have a specific tokens and a specific DEX to work on. Different set of underly ERC20 token / DEX will require separate workers.
Strategy is a DEX-specific logic component that will handle one scenario at the time. With dynamically specifying a set of token address, it can perform the same operation for any ERC20 tokens.
Act as a platform incentive component where it receives ERC20 tokens and will generate Alpaca token for each pool of token. Each pool will have different reward emission allocation.
While Alpaca Finance integrated to number of DEXs and each one will have slightly different minute detail of implementation, most of the DEXs are based on UniSwap V2. In this version of document, we will cover only PancakeSwap specific implementation of Worker and Strategy contract.