Skip to content

Commit

Permalink
chore: update return values
Browse files Browse the repository at this point in the history
  • Loading branch information
njokuScript committed Dec 24, 2023
1 parent 66d66af commit 1f54dd0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 30 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ Gets detailed information about a vault specified by the owner's address.
```ts
{
healthFactor: 'Safe',
depositedCollateral: '300.0',
collateralLocked: 3.636504000000002,
borrowedAmount: '3000.0',
accruedFees: '0.115509259026984',
currentCollateralRatio: '0.9090924378872408%',
availableCollateral: '296.363496',
availablexNGN: '244499.769094051707348'
depositedCollateral: 670000000n, // returns in 6 decimals - 1e6
collateralLocked: 227255070n, // returns in 6 decimals - 1e6
borrowedAmount: 187391000000000000000000n, // returns in 18 decimals - 1e18
accruedFees: 94431149147375637960n, // returns in 18 decimals - 1e18
currentCollateralRatio: 25439000155922303400n, // returns in 18 decimals - 1e18
availableCollateral: 442744930n, // returns in 6 decimals - 1e6
availablexNGN: 365264568850852624362040n // returns in 18 decimals - 1e18
}
```

Expand Down Expand Up @@ -280,13 +280,13 @@ Gets information about the collateral initialized in `create()`.

```ts
{
totalDepositedCollateral: '300.0',
totalBorrowedAmount: '3000.0',
liquidationThreshold: '75.0%',
debtCeiling: '115792089237316195423570985008687907853269984665640564039457.584007913129639935',
rate: '475.646879',
minDeposit: '0.0',
collateralPrice: '1100.0'
totalDepositedCollateral: 4004000000n, // returns in 6 decimals - 1e6
totalBorrowedAmount: 1668492000000000000000000n, // returns in 18 decimals - 1e18
liquidationThreshold: '75000000000000000000', // returns in 18 decimals - 1e18 - should be represented in percentage
debtCeiling: 115792089237316195423570985008687907853269984665640564039457584007913129639935n, // returns in 18 decimals - 1e18
rate: 2499999994972800000n, // returns in 18 decimals - 1e18
minDeposit: 0n, // returns in 18 decimals - 1e18
collateralPrice: 1100000000n // returns in 6 decimals - 1e6
}
```

Expand Down
30 changes: 14 additions & 16 deletions src/services/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,13 @@ const getVault = async (

return {
healthFactor: healthFactor ? 'Safe' : 'Unsafe',
depositedCollateral: ethers.formatUnits(depositedCollateral.toString(), 6),
collateralLocked:
Number(ethers.formatUnits(depositedCollateral.toString(), 6)) -
Number(ethers.formatUnits(withdrawableCollateral.toString(), 6)),
borrowedAmount: ethers.formatUnits(borrowedAmount.toString(), 18),
accruedFees: ethers.formatUnits(_accruedFees.toString(), 18),
currentCollateralRatio: `${ethers.formatUnits(collateralRatio.toString(), 16)}`,
availableCollateral: ethers.formatUnits(withdrawableCollateral.toString(), 6),
availablexNGN: ethers.formatUnits(borrowableAmount.toString(), 18),
depositedCollateral: depositedCollateral,
collateralLocked: BigInt(depositedCollateral) - BigInt(withdrawableCollateral),
borrowedAmount: borrowedAmount,
accruedFees: _accruedFees,
currentCollateralRatio: collateralRatio[0],
availableCollateral: withdrawableCollateral[0],
availablexNGN: borrowableAmount[0],
};
};

Expand Down Expand Up @@ -147,13 +145,13 @@ const getCollateralData = async (collateral: ICollateral, chainId: string, signe
const returnData = (await getCollateralInfo).map((item) => item);

return {
totalDepositedCollateral: ethers.formatUnits(returnData[0].toString(), 6),
totalBorrowedAmount: ethers.formatUnits(returnData[1].toString(), 18),
liquidationThreshold: `${ethers.formatUnits(returnData[2].toString(), 16)}`,
debtCeiling: ethers.formatUnits(returnData[3].toString(), 18),
rate: ethers.formatUnits(BigInt(returnData[4].toString()), 16),
minDeposit: ethers.formatUnits(returnData[5].toString(), 18),
collateralPrice: ethers.formatUnits(returnData[6].toString(), 6),
totalDepositedCollateral: returnData[0],
totalBorrowedAmount: returnData[1],
liquidationThreshold: returnData[2],
debtCeiling: returnData[3],
rate: returnData[4],
minDeposit: returnData[5],
collateralPrice: returnData[6],
};
};
export { getVault, getCollateralData, checkVaultSetupStatus };
16 changes: 16 additions & 0 deletions src/services/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,25 @@ const getCollateralTokenBalance = async (
const formattedBalance = formatUnits(balance, 6);
return formattedBalance;
};

const getCollateralTokenAllowance = async (
collateral: ICollateral,
owner: string,
spender: string,
chainId: string,
signer: Signer,
) => {
const collateralAddress: any = getContractAddress(collateral)[chainId];

const collateralContract = Contract(collateralAddress, USDC__factory.abi, signer);
const allowance = await collateralContract.allowance(owner, spender);
const formattedAllowance = formatUnits(allowance, 6);
return formattedAllowance;
};
export {
getCollateralTokenBalance,
getCurrencyTokenBalance,
getCollateralTokenAllowance,
approveCollateralToken,
approveCurrencyToken,
};

0 comments on commit 1f54dd0

Please sign in to comment.