npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@alpaca-finance/alpaca-money-market

v0.0.3

Published

Alpaca Finance 2.0 consists of layers of protocol build on top of the fundamental base layer call Money Market. Money Market is the set of contracts that allow lenders to deposit the tokens into the platform in exchange for interest. This enables borrower

Downloads

11

Readme

Alpaca Finance 2.0

Alpaca Finance 2.0 consists of layers of protocol build on top of the fundamental base layer call Money Market. Money Market is the set of contracts that allow lenders to deposit the tokens into the platform in exchange for interest. This enables borrowers to utilize this for various financial strategies e.g. hedging, carry trading, etc. Other Alpaca Finance's protocol that need accesses to capital such as Leverage Yield Farming will also be able to tap into the same pool of capital. This increases the utilization of lending assets such that the lenders benefit from providing different uses of loan.

Contract Architecture

Money Market

The core contracts are implemented using Diamond Pattern EIP-2535. The protocol facets consist of

  • AdminFacet - Configure the protocol
  • LendFacet - Start/Stop Lending
  • CollateralFacet - Collateral used for over collateralized borrowing
  • BorrowFacet - Over collateralized borrowing
  • NonCollatFacet - Protocol to Protocol borrowing
  • LiquidationFacet - Risk control once the over collateralized borrowing positions became underwater
  • ViewFacet - All the view functions

Glossaries

Subaccounts

Each address will have a maximum number of subaccounts. This subaccount will be used for overcollateralized borrowing. Each subaccount will be a cross-margin portfilio that enable flexibility to users creating complex strategies

Collaterals

Collaterals are token that eligible to allow users to borrow other tokens given that the value of collaterals is greater than the value of token borrowed

Borrowing Power

Under a subaccount, each collateral will have a collateral factor. For example, depositing 1 BTC@$60,000 with a collateral factor of 0.9 will yield 0.9 * 60,000 = 54,000 Borrowing Power. This is used to calculate how much user can borrow against this collateral

Each borrowing token will also have a borrowing factor. For example, borrowing 1000 USDC@$1 with a borrowing factor of 0.8 will use 1000 / 0.8 = 1,250 Borrowing Power.

Follow the above example, this subaccount will have a remaining borrowing power of 54,000 - 1,250 = 52,750

Repurchasing

Once the remaining borrowing power reach 0, the subaccount is available for repurchasing. Repurchase happened when a repurchaser repay the debt for the subaccount in exchange for collateral under that subaccount at discount price

Liquidation

If the used borrowing power / total borrowing power is greater than x%, the subaccount is available for liquidation. Liquidation process is done through market selling an collateral at a pre-configured DEX to repay the outstanding debt

Contracts Call

Opening the market

  • To create a market for lending and borrowing AdminFacet.openMarket() This will deploy an interest bearing token, in short ibToken, that represent the share in the lending pool and debtToken that represent the share in over collateralized lending pool

Lending

  • To start lending LendFacet.deposit() Supply the token to mint the ibToken
  • To withdraw LendFacet.withdraw() Burn the ibToken to get the deposited token back with interest

Overcollateralized Borrowing

  • To add collateral to the subaccount CollateralFacet.addCollateral() - Add a token as a collateral
  • To borrow a token BorrowFacet.borrow() - Borrowing a token

Liquidation

  • To repurchase LiquidationFacet.repurchase() - Repurchase an underwater subaccount
  • To liquidate LiquidationFacet.liquidationCall() - Liquidate an underwater subaccount

Setting up the project

  • Install dependencies yarn
  • to install forge, cast and anvil curl -L https://foundry.paradigm.xyz | bash
  • To compile contracts forge build

Testing

forge test

Deployment

To impersonate as deployer

  • set IMPERSONATE_AS in .env
  • yarn exec:bsc_mainnet:proxy-admin:deploy --unlocked --sender 0xC44f82b07Ab3E691F826951a6E335E1bC1bB0B51

Prerequisite

  • Foundry installed
  • Setup deployment config file in ./configs/[filename].json
  • Setup .env with DEPLOYER_PRIVATE_KEY, RPC_URL
  • Load .env with command source .env

Money market

To simulate the deployment script

forge script solidity/scripts/deployments/01_DeployMoneyMarket.s.sol

To simulate with the real network

`forge script solidity/scripts/deployments/01_DeployMoneyMarket.s.sol --rpc-url $RPC_URL`

To execute the real transactions

`forge script solidity/scripts/deployments/01_DeployMoneyMarket.s.sol --rpc-url $RPC_URL --broadcast`

To make it work on Tenderly, add flag --slow for it wait for tx to be confirmed before submit next tx

Utility scripts

Prerequisite

  • Foundry installed
  • Setup deployment config file in ./configs/[filename].json
  • Setup .env with DEPLOYER_PRIVATE_KEY, RPC_URL, and DEPLOYMENT_CONFIG_FILENAME
  • Load .env with command source .env
  • have deployed contract addresses set in config file
  • for each script, you can set config values in script file in the inputs section

Dry run locally

forge script solidity/scripts/utilities/ScriptName.s.sol --sig "runLocal()"

To simulate with the real network

forge script solidity/scripts/utilities/ScriptName.s.sol --rpc-url $RPC_URL

To execute the real transactions

forge script solidity/scripts/utilities/ScriptName.s.sol --broadcast --rpc-url $RPC_URL

Licensing

The primary license for Alpaca Protocol 2.0 is the BUSL LICENSE, see BUSL LICENSE.