@widolabs/collateral-swap-sdk
Version:
TypeScript SDK for interacting with the Wido protocol to allow collateral swaps on Compound Comet.
150 lines (149 loc) • 4.21 kB
TypeScript
import { BigNumber, Signer } from 'ethers';
import type { TypedDataSigner } from "@ethersproject/abstract-signer";
import { Assets, CollateralSwapRoute, Deployments, Position, UserAssets } from './types';
export declare class WidoCompoundSdk {
private readonly comet;
private readonly signer;
private readonly priceFetcher;
constructor(signer: Signer & TypedDataSigner, comet: string);
/**
* Returns a list of the existing deployments
*/
static getDeployments(): Deployments;
/**
* Returns a list of the collaterals supported by the given Comet
*/
getSupportedCollaterals(): Promise<Assets>;
/**
* Returns a list of user owned collaterals on the given Comet
*/
getUserCollaterals(): Promise<UserAssets>;
/**
* Returns the user's current position details in a Comet
*/
getUserCurrentPosition(): Promise<Position>;
/**
* Returns the user's current position details in a Comet
* @param swapQuote
*/
getUserPredictedPosition(swapQuote: CollateralSwapRoute): Promise<Position>;
/**
* Quotes the possible outcome of the collateral swap
* @param fromCollateral
* @param toCollateral
* @param amount
*/
getCollateralSwapRoute(fromCollateral: string, toCollateral: string, amount: BigNumber): Promise<CollateralSwapRoute>;
/**
* Executes a collateral swap on a Comet given an existing quote
* @param swapQuote
*/
swapCollateral(swapQuote: CollateralSwapRoute): Promise<string>;
/**
* Find and return the best provider for the current asset/amount
* @param chainId
* @param asset
* @param amount
* @private
*/
private getBestProvider;
/**
* Returns the info of all supported assets in the Comet
* @private
*/
private getAssetsInfo;
/**
* Returns the decimals of all the assets
* @private
*/
private getDecimals;
/**
* Fetch and return the base token details of a Comet
* @private
*/
private static getBaseTokenDetails;
/**
* Fetch and return the details of the collaterals of a user on a Comet
* @param cometContract
* @param infos
* @param userAddress
* @private
*/
private static getCollateralsDetails;
/**
* Returns the summary of a position on the Comet given the list of balances/prices
* @param cometContract
* @param userAddress
* @param infos
* @param balances
* @param prices
* @private
*/
private static getPositionDetails;
/**
* Returns the amount of borrowed base token
* @param cometContract
* @param userAddress
* @private
*/
private static getBorrowedInBaseUnits;
/**
* Generates to EIP712 signatures.
* One to allow WidoRouter to withdraw asset,
* the other to revoke that permission.
* @param chainId
* @param cometAddress
* @param manager
* @private
*/
private createSignatures;
/**
* Generates a signature for an allow operation
* @param chainId
* @param cometAddress
* @param owner
* @param manager
* @param isAllowed
* @param nonce
* @param name
* @param version
* @private
*/
private createAllowSignature;
/**
* Fetch prices of both assets and converts the fees into a single USD amount
* @param fromAsset
* @param widoFee
* @param toAsset
* @param providerFee
* @param chainId
* @private
*/
private getUsdFees;
/**
* Returns user public address
* @private
*/
private getUserAddress;
/**
* Builds an instance of the Comet contract given the comet key
*/
private getCometContract;
/**
* Builds an instance of the Wido contract on a given chain
* @param chainId
* @param provider
*/
private getWidoContract;
/**
* Checks that the wallet is in the right chain
* @private
*/
private checkWalletInRightChain;
/**
* Checks the given `comet` is a supported deployment
* @param comet
* @private
*/
private static validateComet;
}