For the complete documentation index, see llms.txt. This page is also available as Markdown.

๐Ÿ‘›USDFC SDK

Documentation for the USDFC SDK

The USDFC SDK is a comprehensive toolkit for developers to integrate and interact with the USDFC stablecoin protocol.

Overview

USDFC is a collateralized debt platform built on the Filecoin blockchain. Users can lock up FIL as collateral and issue USDFC stablecoin tokens. The USDFC SDK provides a programmatic interface to interact with the protocol, allowing developers to build applications that leverage USDFC functionality.

How It Works

The USDFC SDK is built on top of ethers.js and provides a type-safe interface to interact with the USDFC smart contracts. It abstracts away the complexity of direct contract interactions and provides a more developer-friendly API.

Installation

The USDFC SDK packages are hosted on GitHub Packages registry, not the public NPM registry. You'll need to configure your .npmrc file to access them:

# Add this to your .npmrc file
@secured-finance:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=YOUR_GITHUB_TOKEN

# Then install the individual packages
npm install @secured-finance/stablecoin-lib-ethers
npm install @secured-finance/stablecoin-lib-react
npm install @secured-finance/stablecoin-lib-base

For more details on setting up authentication for GitHub Packages, see the GitHub documentation.

Key Components

The USDFC SDK consists of several packages:

lib-ethers

The core package for interacting with the USDFC protocol using ethers.js.

lib-react

React hooks and components for building USDFC-integrated web applications.

Basic Usage

Connecting to the Protocol

Reading Protocol State

Creating and Managing Troves

Creation takes depositCollateral and borrowDebtToken. Adjustments use depositCollateral or withdrawCollateral, and borrowDebtToken or repayDebtToken. Specify at least one change; do not combine both collateral directions or both debt directions in one adjustment. These are SDK parameter names, not signed collateralChange/debtChange fields.

Stability Pool Operations

Redemption Operations

Liquidation Operations

Advanced Usage

React Integration

collateralRatio(price) is a method; multiply its result by 100 only for percentage display. A displayed price or ratio may be stale and is not a liquidation-risk assessment. Use the source/freshness and same-block checks in Monitoring Liquidation Risk for risk monitoring. Pass an SDK instance connected with useStore set to "blockPolled" to USDFCApp below. SfStablecoinStoreProvider starts the store, waits for its first load and stops it on unmount; do not start that same store separately.

Examples

Creating a Trove and Minting USDFC

Choose the collateral and requested borrow amount explicitly. The opening ratio uses total debt, including the borrowing fee and Liquidation Reserve, not just the USDFC received in the wallet. With reserve 20 USDFC and fee rate 0.5%, borrowing 200 USDFC creates 221 USDFC of total debt; collateral worth $442 gives a 200% ratio at that price. A 200% target is a buffer, not a safety guarantee.

This read-only preview uses the current fee rate and Trove.create() to include the fee and reserve. It also checks the SDK's minimum net debt (borrowing plus fee, excluding the reserve). Confirm that the SDK reserve and minimum-debt configuration match the deployment; the documented Filecoin values are 20 and 200 USDFC respectively.

The returned amounts are SDK Decimal values; use .toString() for display. The preview does not send a transaction and does not check every opening restriction, wallet balance or gas cost. Before calling openTrove, review the resulting ICR, system TCR, mode restrictions and maximum acceptable borrowing fee, and simulate the transaction against current state. Price, fees and mode can change after the preview. See the opening requirements and oracle requirements.

Monitoring Liquidation Risk

This read-only example implements the complete liquidation rules rather than using a single ratio threshold.

The read-only example below uses one block for the Trove (including pending redistribution), total system collateral and debt, oracle state, pool balance and Trove count. It returns unknown on missing data, stale/unknown oracle state or read failures. It does not send transactions or classify any position as "safe."

API baseline: this example uses getPriceWithSource() from SDK source commit 0307461. The oracle-source API is available in @secured-finance/stablecoin-lib-ethers v1.3.0, released on 30 October 2026. Pin that version when reproducing this example; older builds must be upgraded or use an equivalent verified contract reader. BigInt requires an ES2020-compatible runtime.

icrWad and tcrWad use 18-decimal ratio units: 1100000000000000000 means 110%. Preserve integer arithmetic for comparisons and format only for display. Call this function with an already-connected SDK, its provider and the address to inspect. Re-run it as new blocks arrive.

This is a single-Trove snapshot assessment, not a transaction-success promise or a batch-liquidation simulator. Other liquidations can change TCR and Stability Pool coverage before execution; price changes and redistribution can change the Trove. Re-simulate a proposed transaction against current state. Oracle fallback does not by itself block liquidation, but risk-increasing borrower actions require a primary price.

FAQ

How do I handle transaction errors?

The SDK throws descriptive error objects that contain information about the failure. Wrap your transactions in try-catch blocks to handle errors gracefully.

How do I monitor protocol events?

Use the block-polled store to observe changes in protocol state. Register a listener with subscribe(), start the store, and clean up both when finished. This polls state on new blocks; it is not a subscription to every raw contract event. In React, SfStablecoinStoreProvider manages the store lifecycle instead.

What networks does the SDK support?

The SDK supports the Filecoin network, which is the only network where the USDFC protocol is deployed. The USDFC protocol is not available on Ethereum or Arbitrum networks.

Last updated