juna
Version:
A cross platform NFT lending client for serious lenders
314 lines (300 loc) • 12.1 kB
TypeScript
type Currency = {
address: `0x${string}`;
symbol: string;
decimals: number;
};
type Currencies = Record<`0x${string}`, Currency>;
type CollectionDetails = {
address: `0x${string}`;
name: string;
gondiCollectionId?: string;
};
type Collections = Record<`0x${string}`, CollectionDetails>;
interface LendingClient {
getListings: () => Promise<Listing[]>;
getListingsForCollection: (address: `0x${string}`) => Promise<Listing[]>;
getLoans: () => Promise<Loan[]>;
getLoansForAccount: (address: `0x${string}`) => Promise<Loan[]>;
getLoansForCollection: (address: `0x${string}`) => Promise<Loan[]>;
getMyLoans: () => Promise<Loan[]>;
createSingleItemOffer: (offerParams: SingleItemOfferParams) => Promise<Offer>;
createCollectionOffer: (offerParams: CollectionOfferParams) => Promise<Offer>;
getOffers: () => Promise<Offer[]>;
getOffersForAccount: (address: `0x${string}`) => Promise<Offer[]>;
getOffersForCollection: (address: `0x${string}`) => Promise<Offer[]>;
getMyOffers: () => Promise<Offer[]>;
deleteOffer: (offerId: string) => Promise<void>;
}
interface LendingClientBlur {
recallLoan: (collectionAddress: `0x${string}`, loanId: string, nftId: number) => Promise<void>;
}
interface LendingClientWithPromissoryNotes extends LendingClient {
getPromissoryNote: (loanId: number) => Promise<PromissoryNote>;
}
interface LendingClientParameters {
apiKey?: string;
privateKey?: `0x${string}`;
rpcUrl?: `https://${string}`;
testnet?: boolean;
}
declare enum LendingPlatform {
nftfi = "nftfi",
arcade = "arcade",
gondi = "gondi",
blur = "blur"
}
interface Listing {
id: string;
}
declare enum LoanStatus {
ongoing = "ongoing",
repaid = "repaid",
auctioned = "auctioned",
liquidated = "liquidated",
defaulted = "defaulted"
}
interface Collateral {
collectionAddress: `0x${string}`;
collectionName: string;
nftId: number;
}
interface Loan {
id: string;
platform: LendingPlatform;
borrower: `0x${string}`;
lender: `0x${string}`;
status: LoanStatus;
startDate: Date;
endDate: Date;
currency: Currency;
principal: number;
interestPayment: number;
durationInDays: number;
apr: number;
collateral: Collateral[];
valuation?: number;
}
declare enum OfferType {
collectionOffer = "collectionOffer",
singleItemOffer = "singleItemOffer"
}
interface Offer {
id: string;
platform: LendingPlatform;
lender: `0x${string}`;
offerDate: Date;
expiryDate: Date;
type: OfferType;
currency: Currency;
principal: number;
durationInDays: number;
apr: number;
collateral: {
collectionAddress: `0x${string}`;
collectionName: string;
nftId: string;
};
}
interface CollectionOfferParams {
collectionAddress: `0x${string}`;
currency: Currency;
principal: number;
apr: number;
durationInDays: number;
expiryInMinutes: number;
slug?: string;
lenderAddress?: `0x${string}`;
limit?: number;
}
interface SingleItemOfferParams extends CollectionOfferParams {
nftId: number;
}
interface PromissoryNote {
address: `0x${string}`;
id: number;
}
type types_Collateral = Collateral;
type types_CollectionDetails = CollectionDetails;
type types_CollectionOfferParams = CollectionOfferParams;
type types_Collections = Collections;
type types_Currencies = Currencies;
type types_Currency = Currency;
type types_LendingClient = LendingClient;
type types_LendingClientBlur = LendingClientBlur;
type types_LendingClientParameters = LendingClientParameters;
type types_LendingClientWithPromissoryNotes = LendingClientWithPromissoryNotes;
type types_LendingPlatform = LendingPlatform;
declare const types_LendingPlatform: typeof LendingPlatform;
type types_Listing = Listing;
type types_Loan = Loan;
type types_LoanStatus = LoanStatus;
declare const types_LoanStatus: typeof LoanStatus;
type types_Offer = Offer;
type types_OfferType = OfferType;
declare const types_OfferType: typeof OfferType;
type types_PromissoryNote = PromissoryNote;
type types_SingleItemOfferParams = SingleItemOfferParams;
declare namespace types {
export { type types_Collateral as Collateral, type types_CollectionDetails as CollectionDetails, type types_CollectionOfferParams as CollectionOfferParams, type types_Collections as Collections, type types_Currencies as Currencies, type types_Currency as Currency, type types_LendingClient as LendingClient, type types_LendingClientBlur as LendingClientBlur, type types_LendingClientParameters as LendingClientParameters, type types_LendingClientWithPromissoryNotes as LendingClientWithPromissoryNotes, types_LendingPlatform as LendingPlatform, type types_Listing as Listing, type types_Loan as Loan, types_LoanStatus as LoanStatus, type types_Offer as Offer, types_OfferType as OfferType, type types_PromissoryNote as PromissoryNote, type types_SingleItemOfferParams as SingleItemOfferParams };
}
declare const WETH: Currency;
declare const DAI: Currency;
declare const USDC: Currency;
declare const BETH: Currency;
declare const currencyFromAddress: (address: `0x${string}`) => Currency;
declare const getErc20Balance: (rpcUrl: `https://${string}`, currency: Currency, walletAddress: `0x${string}`) => Promise<number>;
declare class ArcadeClient implements LendingClientWithPromissoryNotes {
private readonly account;
private readonly http;
private offers;
private loans;
constructor(p: LendingClientParameters);
getListings(): Promise<Listing[]>;
getListingsForCollection(): Promise<Listing[]>;
getLoans(): Promise<Loan[]>;
getLoansForCollection(address: `0x${string}`): Promise<Loan[]>;
getLoansForAccount(address: `0x${string}`): Promise<Loan[]>;
getMyLoans(): Promise<Loan[]>;
createSingleItemOffer(offerParams: SingleItemOfferParams): Promise<Offer>;
createCollectionOffer(offerParams: CollectionOfferParams): Promise<Offer>;
deleteOffer(offerId: string): Promise<void>;
getOffers(): Promise<Offer[]>;
getOffersForAccount(address: `0x${string}`): Promise<Offer[]>;
getOffersForCollection(address: `0x${string}`): Promise<Offer[]>;
getMyOffers(): Promise<Offer[]>;
getPromissoryNote(loanId: number): Promise<PromissoryNote>;
}
declare class NftfiClient implements LendingClient {
private readonly account;
private readonly http;
private rpc;
private offers;
private loans;
constructor(p: LendingClientParameters);
getListings(): Promise<Listing[]>;
getListingsForCollection(): Promise<Listing[]>;
getLoans(): Promise<Loan[]>;
getLoansForCollection(address: `0x${string}`): Promise<Loan[]>;
getLoansForAccount(address: `0x${string}`): Promise<Loan[]>;
getMyLoans(): Promise<Loan[]>;
createSingleItemOffer(offerParams: SingleItemOfferParams): Promise<Offer>;
createCollectionOffer(offerParams: CollectionOfferParams): Promise<Offer>;
deleteOffer(offerId: string): Promise<void>;
getOffers(): Promise<Offer[]>;
getOffersForAccount(address: `0x${string}`): Promise<Offer[]>;
getOffersForCollection(address: `0x${string}`): Promise<Offer[]>;
getMyOffers(): Promise<Offer[]>;
getPromissoryNote(loanId: number): Promise<PromissoryNote>;
}
interface LendingClientParametersGondi extends LendingClientParameters {
originationFeeInPercentage?: number;
}
declare class GondiClient implements LendingClientWithPromissoryNotes {
private http;
private readonly account;
private loans;
private offers;
private client;
private originationFeeInPercentage;
constructor(p: LendingClientParametersGondi);
_getCollectionId(collectionAddress: `0x${string}`, slug?: string): Promise<any>;
getListings(): Promise<Listing[]>;
getListingsForCollection(): Promise<Listing[]>;
getLoans(): Promise<Loan[]>;
getLoansForCollection(address: `0x${string}`): Promise<Loan[]>;
getLoansForAccount(address: `0x${string}`): Promise<Loan[]>;
getMyLoans(): Promise<Loan[]>;
createSingleItemOffer(offerParams: SingleItemOfferParams): Promise<Offer>;
createCollectionOffer(offerParams: CollectionOfferParams): Promise<Offer>;
deleteOffer(offerId: string): Promise<void>;
getOffers(): Promise<Offer[]>;
getOffersForAccount(address: `0x${string}`): Promise<Offer[]>;
getOffersForCollection(address: `0x${string}`): Promise<Offer[]>;
getMyOffers(): Promise<Offer[]>;
getPromissoryNote(loanId: number): Promise<PromissoryNote>;
}
declare class BlurClient implements LendingClientBlur {
private api;
constructor(p: LendingClientParameters);
getListings(): Promise<Listing[]>;
getListingsForCollection(): Promise<Listing[]>;
getLoans(): Promise<Loan[]>;
getLoansForCollection(address: `0x${string}`): Promise<Loan[]>;
getLoansForAccount(address: `0x${string}`): Promise<Loan[]>;
getMyLoans(): Promise<Loan[]>;
createSingleItemOffer(offerParams: SingleItemOfferParams): Promise<Offer>;
createCollectionOffer(offerParams: CollectionOfferParams): Promise<Offer>;
deleteOffer(offerId: string): Promise<void>;
getOffers(): Promise<Offer[]>;
getOffersForAccount(address: `0x${string}`): Promise<Offer[]>;
getOffersForCollection(address: `0x${string}`): Promise<Offer[]>;
getMyOffers(): Promise<Offer[]>;
recallLoan(collectionAddress: `0x${string}`, loanId: string, nftId: number): Promise<void>;
}
declare class DeepNftValueClient {
private readonly apiKey;
private axiosInstance;
constructor(apiKey?: string);
getValuation(collectionAddress: `0x${string}`, tokenId: number, chainId?: number): Promise<number>;
}
type Quotes = {
bid: {
eth: number;
usd: number;
};
ask: {
eth: number;
usd: number;
};
};
declare class ReservoirClient {
private readonly apiKey;
private axiosInstance;
constructor(apiKey?: string);
getQuotes(collectionAddress: `0x${string}`): Promise<Quotes>;
getQuotesBySlug(slug: string): Promise<Quotes>;
getQuotesForPunks(): Promise<Quotes>;
getCollectionActivity(collection: string, attributes: string, continuation: string): Promise<any>;
}
declare class PortfolioClient {
private readonly clients;
private readonly addresses;
private readonly pricer;
constructor(clients: LendingClient[], addresses: `0x${string}`[]);
createCollectionOffer(offerParams: CollectionOfferParams, logs?: boolean): Promise<void>;
getMyLoans(): Promise<Loan[]>;
priceMyLoans(loans: Loan[]): Promise<Loan[]>;
getMyOffers(): Promise<Offer[]>;
}
type LoanTerm = {
currency: Currency;
principal: number;
durationInDays: number;
apr: number;
};
declare class Loaner {
private readonly portfolioClient;
private collectionOffers;
constructor(portfolioClient: PortfolioClient);
updateCollectionOffers(collectionAddress: `0x${string}`, loanTerms: LoanTerm[]): void;
publishCollectionOffers(expiryInMinutes?: number, logs?: boolean): Promise<void>;
}
declare class AccountUnderfunded extends Error {
constructor();
}
declare class UnsufficientAllowance extends Error {
constructor();
}
declare class CollectionNotSupported extends Error {
constructor();
}
type errors_AccountUnderfunded = AccountUnderfunded;
declare const errors_AccountUnderfunded: typeof AccountUnderfunded;
type errors_CollectionNotSupported = CollectionNotSupported;
declare const errors_CollectionNotSupported: typeof CollectionNotSupported;
type errors_UnsufficientAllowance = UnsufficientAllowance;
declare const errors_UnsufficientAllowance: typeof UnsufficientAllowance;
declare namespace errors {
export { errors_AccountUnderfunded as AccountUnderfunded, errors_CollectionNotSupported as CollectionNotSupported, errors_UnsufficientAllowance as UnsufficientAllowance };
}
export { ArcadeClient, BETH, BlurClient, DAI, DeepNftValueClient, GondiClient, Loaner, NftfiClient, PortfolioClient, ReservoirClient, USDC, WETH, currencyFromAddress, errors, getErc20Balance, types };