Team-Kujira / kujira.js

JS Interfaces for the Kujira Blockchain
24 stars 24 forks source link

Giving an updated example, plz #35

Open Subfortytwo opened 4 months ago

Subfortytwo commented 4 months ago

Hi,

Would you mind giving us an example about how we are supposed to use your sdk? For instance ghost.ts, it's not clear. I ended up recoding everything on my side because you have 0 example, 0 comment and complex structures we don't know where to get them from:

export const castVaultState = (res: {
  deposited: string;
  borrowed: string;
  rate: string;
  apr: number;
  deposit_redemption_ratio: string;
  debt_share_ratio: string;
}): VaultState => {
  const deposited = BigNumber.from(res.deposited);
  const lent = BigNumber.from(res.borrowed);
  const interestRate = parseFloat(res.rate);

  return {
    deposited,
    lent,
    available: deposited.sub(lent),
    interestRate,
    apr: divToNumber(mulDec(lent, interestRate), deposited),
    redemptionRate: parseFixed(res.deposit_redemption_ratio, 18),
    debtShareRatio: parseFixed(res.debt_share_ratio, 18),
  };
};

Thank you.