Developer Docs

Polygon integration

Welcome to the Safi Protocol developer documentation. This guide provides an overview of the Safi Protocol's DeFi lending pool implementation built on the Polygon network. The documentation covers key components of the lending pool, smart contract architecture, development setup, and deployment steps.

Table of Contents

  • Introduction

  • Smart Contract Architecture

  • Development Environment Setup

  • Contract Deployment

  • Testing and Auditing

  • Integration with Frontend

Introduction

The Safi Protocol is a decentralized lending platform designed to finance renewable energy assets, such as solar power systems. Built on the Polygon network, the protocol leverages the network's fast and low-cost transactions to provide an efficient and scalable DeFi lending pool solution for financing renewable energy projects.

Smart Contract Architecture

The Safi Protocol's smart contract architecture consists of the following key components:

  1. LendingPool: The primary smart contract that manages the lending pool, including depositing, withdrawing, and managing interest rates.

  2. LendingPoolConfigurator: A smart contract that handles the configuration of the lending pool, such as setting up asset types, interest rate models, and collateral requirements.

  3. LendingPoolDataProvider: This smart contract provides an interface for querying data about the lending pool, such as user balances, borrow rates, and liquidity available.

  4. InterestRateModel: A smart contract that defines the interest rate model for the lending pool, determining how interest rates change based on factors such as utilization rate and market conditions.

  5. SafiToken: An ERC20-compatible token used for governance, incentives, and staking within the Safi Protocol ecosystem.

Development Environment Setup

To set up the Safi Protocol development environment, follow these steps:

  1. Install Node.js (v14 or newer) and npm (v7 or newer) on your machine.

  2. Clone the Safi Protocol repository:

    bashCopy codegit clone https://github.com/safiprotocol/defi.git
  3. Navigate to the project directory and install the required dependencies:

    bashCopy codecd safi-protocol
    npm install
  4. Install and set up the Polygon Truffle Box to configure the development environment for the Polygon network.

  5. Install the Ganache CLI to set up a local Ethereum test network for development and testing:

    Copy codenpm install -g ganache-cli

Contract Deployment

To deploy the Safi Protocol smart contracts on the Polygon network, follow these steps:

  1. Set up the Polygon testnet or mainnet configuration in the truffle-config.js file.

  2. Compile the smart contracts:

    pythonCopy codetruffle compile
  3. Deploy the smart contracts on the desired Polygon network:

    cssCopy codetruffle migrate --network polygon_testnet
  4. Verify the contract deployment and obtain the contract addresses for further interaction and integration.

Testing and Auditing

Before deploying the Safi Protocol smart contracts to the mainnet, it's crucial to test and audit the code thoroughly:

  1. Write comprehensive unit tests for the smart contracts using the Truffle testing framework.

  2. Run the tests using the following command:

    bashCopy codetruffle test
  3. Perform a thorough code audit, either internally or by engaging a third-party auditing firm, to ensure the smart contracts are secure and free of vulnerabilities.

Integration with Frontend

Once the Safi Protocol smart contracts have been deployed and tested, you can integrate them with the frontend application:

  1. Install a web3 library, such as web3.js or ethers.js, to interact with the smart contracts from your frontend application.

    Copy codenpm install web3
  2. Use the contract addresses obtained during the deployment step to instantiate the web3 contract instances for each smart contract.

  3. Implement frontend functions that interact with the smart contracts, such as depositing and withdrawing funds, borrowing and repaying loans, and querying data from the lending pool.

  4. Ensure proper error handling and user feedback mechanisms are in place to provide a smooth user experience.

  5. Test the frontend application thoroughly to ensure proper integration with the smart contracts.

Additional Resources

For more information and to access additional resources related to the Safi Protocol, Polygon network, and DeFi lending pools, consult the following resources:

By following this guide, you can successfully develop, deploy, and integrate the Safi Protocol DeFi lending pool built on the Polygon network

Last updated