porter-finance / v1-core

⛰️ Smart contracts powering the Porter protocol.
https://porter.finance
GNU Affero General Public License v3.0
4 stars 3 forks source link
bonds defi protocol solidity

Porter Smart Contracts Porter Smart Contracts

app testnet landing docs discord blog twitter

Security

Please report any security issues to security@porter.finance

V1

Smart Contracts powering the Porter protocol.

Contracts

mainnet rinkeby
BondFactory 0x9f20521ef789fd2020e708390b1e6c701d8218ba 0x0ae42cF40Fb46A926e2dcCE92b2Fe785d2D1E0A0
Bond Implementation 0x79537dcba69fea2b8dc8292b3726195fe947e332 0xebc0d87f2fb27c967a3cb0e36f279579b0116261

What does it do? How does it work?

The Porter V1 protocol allows a borrower to create a Bond. Each minted bond share has some amount of collateral backing and will be redeemable 1 share for 1 stablecoin at maturity. To incentivize lenders, the bond shares will be sold at a discount either OTC or through an auction.

For more information on this process, the documentation site gives an overview of what the protocol does and some of the concepts like zero coupon bonds and the difference between "Simple" and "Convert" Bond types. For how the protocol works, check out the spec:

Development

For local development there are environment variables necessary to enable some hardhat plugins. To interact with the frontend, you will also need to update your wallet with a new network pointing to hardhat's network.

Network Name: Hardhat
RPC URL: http://localhost:8545
Chain ID: 31337
Currency: ETH

Then, run the local node with npx hardhat node. If forking a blockchain, avoid deploying dependencies with the --no-deploy flag: npx hardhat node --no-deploy.

Deployment

Using hardhat-deploy all of the scripts in the ./deploy folder are run. This will run the whole integration flow as well which includes deploying of the factory, tokens, creating bonds, doing bond actions, and starting auctions. If that is not desired, add a tags flag with what you want to deploy.

npx hardhat deploy --tags main-deployment # deploy bond factory
npx hardhat deploy --tags test-deployment # and deploy tokens
npx hardhat deploy --tags permissions # and grant roles & permissions
npx hardhat deploy --tags e2e # and run e2e test
npx hardhat deploy --tags bonds # and deploy test bonds
npx hardhat deploy --tags auctions # and start bond auctions
npx hardhat deploy --tags actions # and do bond actions

Additionally, all of the above commands can be run with --network rinkeby to deploy to the Rinkeby test network.

Note: The deploy script will run with the npx hardhat node as well as the npx hardhat test tasks.

Verification

The deployment script will automatically verify the BondFactory, Implementation contract, and TestERC20 token. To verify a contract not deployed within that script, use the hardhat-etherscan task.

npx hardhat verify <address>

Testing

Running the hardhat test suite

npx hardhat test

Fork testing requires first running the mainnet-fork

npx hardhat node

and making the target for testing the local node

npx hardhat test --network localhost

Running the fuzzing test suite with Echidna

Other useful commands

npx hardhat help
npx hardhat compile # create contract artifacts
npx hardhat clean # removes artifacts and maybe other things
npx hardhat coverage # runs the contract coverage report
npx hardhat integration # runs the integration task
npx hardhat settle-auction --auctionId <auctionId> # settles an auction
npx eslint '**/*.{js,ts}' --fix
npx prettier '**/*.{json,sol,md,ts}' --write
npx solhint 'contracts/**/*.sol' --fix