-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from iiAku/fix/update-collateral-ratio
fix: make sure all computations are on-chain value collateral ratio b…
- Loading branch information
Showing
11 changed files
with
82 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import BigNumber from "bignumber.js" | ||
/* | ||
Credits goes to: https://github.com/Hover-Labs/kolibri-js/blob/master/src/oven-client.ts | ||
As the vast majority of helpers from here were either took, modified or inspired from kolibri-js module | ||
*/ | ||
|
||
const MUTEZ_DIGITS = 6 | ||
const SHARD_DIGITS = 18 | ||
|
||
const MUTEZ_TO_SHARD = new BigNumber(Math.pow(10, SHARD_DIGITS - MUTEZ_DIGITS)) | ||
|
||
const SHARD_PRECISION = new BigNumber(Math.pow(10, SHARD_DIGITS)) | ||
|
||
export const customGetCollateralUtilization = ( | ||
price, | ||
balance, | ||
outstandingTokens | ||
) => { | ||
const priceShard = price.multipliedBy(MUTEZ_TO_SHARD) | ||
const collateralValue = balance | ||
.multipliedBy(MUTEZ_TO_SHARD) | ||
.multipliedBy(priceShard) | ||
.dividedBy(SHARD_PRECISION) | ||
|
||
return new BigNumber( | ||
outstandingTokens | ||
.times(Math.pow(10, SHARD_DIGITS)) | ||
.dividedBy(collateralValue) | ||
.toFixed(0) | ||
) | ||
} |