Skip to content

API Reference

Core Components

Strategy

The core data structure representing a lending strategy.

interface Strategy {
  id: string;
  name: string;
  description?: string;
  terms: {
    creditAssets: Asset[];
    collateralAssets: Asset[];
    apr: Record<string, number>;
    ltv: Record<string, number>;
    durationDays: number;
    expirationDays: number;
    minCreditAmountPercentage: number;
  };
  lendingStats: {
    totalCommittedAmount: bigint;
    totalUtilizedAmount: bigint;
    totalAvailableAmount: bigint;
  };
  borrowingStats: {
    totalBorrowedAmount: bigint;
    totalRepaidAmount: bigint;
    totalDefaultedAmount: bigint;
    activeBorrowedAmount: bigint;
  };
  curator?: {
    name: string;
    description?: string;
    avatar?: string;
  };
}

Asset

Represents a token that can be used as credit or collateral.

interface Asset {
  address: string;
  chainId: number;
  name: string;
  symbol: string;
  decimals: number;
}

React/Next.js Hooks

useStrategies

Hook for fetching all available strategies.

function useStrategies(chain: SupportedChain) => {
  data: Strategy[];
  isLoading: boolean;
  error: Error | null;
}

useStrategy

Hook for fetching a single strategy by ID.

function useStrategy(strategyId: string) => {
  data: Strategy | null;
  isLoading: boolean;
  error: Error | null;
}

useMakeProposals

Hook for creating new strategy proposals. Supports both single and multiple proposal creation.

function useMakeProposals(user: UserWithNonceManager) => {
  mutateAsync: (params: ProposalParamWithDeps<ImplementedProposalTypes>[]) => Promise<ProposalWithSignature[]>;
  isPending: boolean;
  isSuccess: boolean;
  error: Error | null;
  data: ProposalWithSignature[] | null;
}

useRevokeNonces

Hook for revoking proposal nonces.

function useRevokeNonces() => {
  mutateAsync: (params: {
    proposalNonces: bigint[];
    chainId: SupportedChain;
    owner: AddressString;
    nonceSpace: bigint;
  }) => Promise<void>;
  isPending: boolean;
  isSuccess: boolean;
  error: Error | null;
}

useUserWithNonce

Hook for managing user nonces across chains.

function useUserWithNonce(chains: SupportedChain[]) => {
  userWithNonce: UserWithNonceManager | null;
  isLoading: boolean;
  error: Error | null;
}

Vue.js Composables

useStrategy

Composable for fetching strategy data.

function useStrategy(strategyId: string) => {
  data: Strategy | null;
  isLoading: boolean;
  error: Error | null;
}

useMakeProposals

Composable for creating new proposals.

function useMakeProposals(user: UserWithNonceManager) => {
  mutateAsync: (params: ProposalParamWithDeps<ImplementedProposalTypes>[]) => Promise<ProposalWithSignature[]>;
  isPending: boolean;
  isSuccess: boolean;
  error: Error | null;
  data: ProposalWithSignature[] | null;
}

useRevokeNonces

Composable for revoking proposal nonces.

function useRevokeNonces() => {
  mutateAsync: (params: {
    proposalNonces: bigint[];
    chainId: SupportedChain;
    owner: AddressString;
    nonceSpace: bigint;
  }) => Promise<void>;
  isPending: boolean;
  isSuccess: boolean;
  error: Error | null;
}

Core Functions

getStrategy

Fetches a strategy by ID.

async function getStrategy(strategyId: string): Promise<Strategy>

createElasticProposals

Helper function to create elastic proposal parameters.

function createElasticProposals(
  strategy: Strategy,
  address: AddressString,
  creditAmount: string,
  config: Config,
): ProposalParamWithDeps<ImplementedProposalTypes>[]

makeProposals

Core function to create multiple proposals in a single transaction.

async function makeProposals<T extends ImplementedProposalTypes>(
  config: Config,
  proposalParams: ProposalParamWithDeps<T>[],
  user: UserWithNonceManager,
): Promise<ProposalWithSignature[]>

revokeProposals

Core function to revoke proposal nonces.

async function revokeProposals(
  proposalNonces: bigint[],
  chainId: SupportedChain,
  owner: AddressString,
  nonceSpace: bigint,
  contract: RevokedNonceContract,
): Promise<void>

Types

ProposalParamWithDeps

Type representing a proposal with its dependencies.

interface ProposalParamWithDeps<T extends ImplementedProposalTypes> {
  type: T;
  params: Parameters<(typeof proposalTypes)[T]>[0];
  deps: {
    api: IProposalElasticAPIDeps;
    contract: IProposalContract<any>;
    loanContract: ILoanContract;
  };
}

ProposalWithSignature

Type representing a signed proposal.

interface ProposalWithSignature extends ProposalWithHash {
  signature: string | null;
  isOnChain: boolean;
}

ProposalWithHash

Type representing a proposal with its hash.

interface ProposalWithHash extends Proposal {
  hash: string;
}

UserWithNonceManager

Type representing a user with nonce management capabilities.

class UserWithNonceManager {
  user: User;
  nonces: Partial<Record<SupportedChain, [bigint, bigint]>>;
  address: string;
  
  getNextNonce(chain: SupportedChain): bigint;
  getNonceSpace(chain: SupportedChain): bigint;
  getUsedNonces(): Partial<Record<SupportedChain, bigint>>;
}

Error Handling

All hooks and functions may throw or return errors in the following cases:

  • Network errors
  • Invalid input parameters
  • Unauthorized access
  • Contract interaction failures
  • Wallet connection issues
  • Nonce management errors
  • Invalid nonce revocation attempts
  • Nonce space validation failures

It's recommended to always implement proper error handling and loading states in your application.

Constants

ProposalType

Available types of proposals.

enum ProposalType {
  Elastic = 'elastic'
  // Add other proposal types as they become available
}

SupportedChain

Supported blockchain networks.

enum SupportedChain {
  World = 'world',
  Sepolia = 'sepolia'
  // Add other chains as they become available
}

API Dependencies

IProposalElasticAPIDeps

Interface for required API dependencies when creating proposals.

interface IProposalElasticAPIDeps {
  persistProposal: typeof API.post.persistProposal;
  getAssetUsdUnitPrice: typeof API.get.getAssetUsdUnitPrice;
  persistProposals: typeof API.post.persistProposals;
  updateNonces: typeof API.post.updateNonce;
}