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

@defactor/defactor-sdk

v4.0.4

Published

Defactor Development Kit

Downloads

909

Readme

Defactor Software Developer Kit (SDK)

The Defactor SDK is a TypeScript-based Node.js library designed to streamline the process of instantiating contracts and enhancing the seamless interaction with Defactor contracts.

Tailored for developers engaged in blockchain or cryptocurrency operations, this SDK offers interfaces for communicating with smart contracts on Ethereum-based networks. By abstracting complexities, developers can concentrate on their application's business logic, free from the intricacies of underlying blockchain technology.

Features

  • Support for cjs, es, and esm modules.
  • Developed using TypeScript for enhanced type safety and clarity.
  • Seamless integration with ERC20CollateralPool and Pools.
  • Well-defined interfaces that accurately model the Defactor contracts for easy interaction and integration.

This library is built on top of [email protected] to provide a simple and easy to use interface to interact with the Defactor contracts.

Installation

# yarn
yarn add @defactor/defactor-sdk

# npm
npm install @defactor/defactor-sdk

Usage

Importing the SDK

import { DefactorSDK } from '@defactor/defactor-sdk'

This library is built to provide a simple and easy to use interface to interact with the Defactor contracts in two different options:

  • SelfProvider: For developers who prefer using their own digital signature provider to interact with Defactor contracts. In this mode, developers must furnish the private key of the account intended for blockchain interaction. In order to effectuate this integration, the developer team must conscientiously consider the security protocols implemented to safeguard their private key from exposure or compromise in any manner.

  • AssistedProvider: Geared towards developers seeking to interact with Defactor contracts without providing their private key. In this mode, the Defactor library exposes contract methods similar to SelfProvider, but instead of signing transactions, it returns the transaction object for developers to sign. Other contract-interaction functions not requiring signature are seamlessly handled by the SDK.

Instantiating the SDK

const provider = new SelfProvider(
    DefactorSDK.ERC20CollateralPool,    // contract constructor
    ERC20_COLLATERAL_POOL_ETH_ADDRESS,  // contract address
    providerUrl,                        // provider url (alchemy, infura, etc)
    ADMIN_PRIVATE_KEY                   // private key
)

// Pools Contract
const provider = new SelfProvider(
    DefactorSDK.Pools,      // contract constructor
    POOLS_ETH_ADDRESS,      // contract address
    providerUrl,            // provider url (alchemy, infura, etc)
    ADMIN_PRIVATE_KEY       // private key
)

Interacting with the SDK

import { ERC20CollateralPool, SelfProvider } from '@defactor/defactor-sdk'

const providerInstance = new SelfProvider.SelfProvider<ERC20CollateralPool>(
  ERC20CollateralPool,
  contractConfig.contractAddress!, // loaded from config file
  contractConfig.providerUrl!, // loaded from config file
  contractConfig.adminPrivateKey! // loaded from config file
)

const liquidationProtocolFee =
  providerInstance.contract.LIQUIDATION_PROTOCOL_FEE

console.log(liquidationProtocolFee)

Methods Available

async USDC_FEES_COLLECTED(): Promise<bigint>                                                                                                // Returns the total USDC fees collected.
async getUsdc(): Promise<string>                                                                                                            // Returns the USDC contract address.
async getTotalPools(): Promise<bigint>                                                                                                      // Returns the total number of pools.
async getPool(poolId: bigint): Promise<Pool>                                                                                                // Returns the pool with the given ID.
async getPools(offset: bigint, limit: bigint): Promise<Array<Pool>>                                                                         // Returns a list of pools within the given range.
async getTotalLending(poolId: bigint, address: string): Promise<bigint>                                                                     // Returns the total amount of lending for a given pool and address.
async getLoan(poolId: bigint, address: string, lendingId: bigint): Promise<Lend>                                                            // Returns a specific loan.
async addPool(pool: PoolInput): Promise<ethers.ContractTransaction | ethers.TransactionResponse>                                            // Adds a new pool.
async lend(poolId: bigint, amount: bigint): Promise<ethers.ContractTransaction | ethers.TransactionResponse>                                // Lends a certain amount to a pool.
async borrow(poolId: bigint, amount: bigint): Promise<ethers.ContractTransaction | ethers.TransactionResponse>                              // Borrows a certain amount from a pool.
async getBorrow(poolId: bigint, borrowerAddress: string, borrowId: bigint): Promise<Borrow>                                                 // Returns a specific borrow.
async calculateCollateralTokenAmount(poolId: bigint, amount: bigint): Promise<bigint>                                                       // Calculates the amount of collateral tokens for a given amount.
async repay(poolId: bigint, borrowerAddress: string, borrowId: bigint): Promise<ethers.ContractTransaction | ethers.TransactionResponse>    // Repays a borrow.
async getLiquidationInfo(pool: Pool): Promise<PoolLiquidationInfo>                                                                          // Returns information about the liquidation of a pool.
async liquidatePool(poolId: bigint): Promise<ethers.ContractTransaction | ethers.TransactionResponse>                                       // Liquidates a pool.

Development

This project is configured with changeset CI/CD, any new change that requires an npm package update should be done through changeset.

yarn changeset

You'll be prompted to select the type of change you're making and a summary of the change. Once you've done that, you can commit the changeset file that was created and the CI/CD will take care of the rest.

Contributing

To contribute, please familiarize yourself with Defactor`s Open Source Contributing Guidelines and then propose your amazing code feature/fix.

If you encounter any big or small bugs, please, report it by opening an issue.

LICENSE

This project is licensed under the Apache License, Version 2.0.

Please review the license terms for details on permissions and restrictions.

About Defactor

As pioneers in the integration of Real-World Assets (RWA) with Decentralized Finance (DeFi), we're dedicated to unlocking liquidity and fostering innovation in the financial sector. Our platform is designed to streamline the adoption of DeFi solutions by businesses, underpinned by the real-world value of tokenized assets.

We're excited to see how you'll leverage Defactor to revolutionize the world of finance!


For more information on Defactor and our mission, visit our website.