loans-sdk is a Javascript library for communicating with the API of loans. It is used to take pluto-loans and/or withdraw the collateral.
See the accepted assets for taking a loan and settle the debt
This project is built using Typescript, and vitest for unit testing
See the examples to use the SDK
- Install it using npm:
npm i plutodao-loans-sdk
- import/require into your project:
import * as loansSdk from 'plutodao-loans-sdk';
getLoanIntent(server: ApiStellarNetwork, borrower: string, entryBalance: BalanceDto)
Returns a loan intent transaction XDR
getLoanStatus(server: ApiStellarNetwork, borrower: string)
Returns the loan status
getSettleDebtIntent(server: ApiStellarNetwork, borrower: string, debtCancellationAsset: ILoanAssetRequest)
Returns a repay withdraw collateral intent transaction XDR to be signed by the borrower to cancel the remaining debt
getWithdrawCollateralIntent(server: ApiStellarNetwork, borrower: string)
Returns a withdraw collateral intent transaction XDR to be signed by the borrower once the loan has paid itself
sendLoan(server: ApiStellarNetwork, borrower: string, loanSignedTransaction: string)
Submits a signed loan intent transaction XDR to get a loan
sendWithdrawCollateral(server: ApiStellarNetwork, borrower: string, withdrawCollateralSignedXdr: string)
Submits a signed withdraw collateral intent transaction XDR to withdraw the loan collateral
A class representing the asset required for the API
class LoanAssetRequest implements ILoanAssetRequest {
public code?: string;
public issuer?: string;
public isNative: boolean;
constructor(isNative: boolean, assetCode?: string, assetIssuer?: string) {
this.code = assetCode;
this.issuer = assetIssuer;
this.isNative = isNative;
if (isNative) {
this.code = 'XLM';
}
}
}
A class representing the status of a loan
class LoanStatusResponse implements ILoanStatusResponse {
public percentagePaid: number;
public remainingDebt: number;
public userTotalYusdcInVault: number;
constructor(
percentagePaid: number,
remainingDebt: number,
userTotalYusdcInVault: number,
) {
this.percentagePaid = percentagePaid;
this.remainingDebt = remainingDebt;
this.userTotalYusdcInVault = userTotalYusdcInVault;
}
}
A class representing the required info to determine which asset is used to take the loan and how much will be the amount
class BalanceDto implements IBalanceDto {
public asset: LoanAssetRequest;
public amount: string;
constructor(asset: LoanAssetRequest, amount: string) {
this.asset = asset;
this.amount = amount;
}
}
- XLM
- YXLM
- PUSD
- USDC
- YUSDC
- ARS
- ARST
- AQUA
- BTC
- ETH
- PUSD
- USDC
- YUSDC