Skip to content

Commit

Permalink
Fix/consistency on empty vault (#89)
Browse files Browse the repository at this point in the history
* FIX maxi: consistency check on empty vault

* maxi: added prettier
  • Loading branch information
kuegi authored Sep 26, 2022
1 parent f8bccd4 commit 8083490
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
4 changes: 4 additions & 0 deletions ocean-client/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.formatOnSaveMode": "modifications",
"editor.formatOnSave": true
}
38 changes: 26 additions & 12 deletions ocean-client/src/programs/vault-maxi-program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,32 @@ export class VaultMaxiProgram extends CommonProgram {
const loanValue = vault.loanAmounts
.map(coll => new BigNumber(coll.amount).times(coll.activePrice?.active?.amount ?? 1))
.reduce((prev, cur) => prev.plus(cur), new BigNumber(0))
console.log("calculated values: collValue: " + collValue.toFixed(8) + " loanValue: " + loanValue.toFixed(8) + " ratio: " + collValue.div(loanValue).times(100).toFixed(8))
if (loanValue.minus(vault.loanValue).absoluteValue().div(loanValue).gt(this.maxPercentDiffInConsistencyChecks/100)) { // more than 1% difference -> problem
console.warn("inconsistency in loanValue: " + loanValue.toFixed(8) + " vs " + vault.loanValue)
return false
}
if (collValue.minus(vault.collateralValue).absoluteValue().div(collValue).gt(this.maxPercentDiffInConsistencyChecks/100)) {// more than 1% difference -> problem
console.warn("inconsistency in collateralValue: " + collValue.toFixed(8) + " vs " + vault.collateralValue)
return false
}
if (collValue.div(loanValue).times(100).minus(vault.informativeRatio).absoluteValue().gt(this.maxPercentDiffInConsistencyChecks)) {
console.warn("inconsistency in collRatio: " + collValue.div(loanValue).times(100).toFixed(8) + " vs " + vault.informativeRatio)
return false
const ratio = loanValue.gt(0) ? collValue.div(loanValue).times(100) : new BigNumber(-1)
console.log(
'calculated values: collValue: ' +
collValue.toFixed(8) +
' loanValue: ' +
loanValue.toFixed(8) +
' ratio: ' +
ratio.toFixed(8),
)
const percThreshold = this.maxPercentDiffInConsistencyChecks / 100
if (loanValue.minus(vault.loanValue).absoluteValue().div(loanValue).gt(percThreshold)) {
// more than 1% difference -> problem
console.warn('inconsistency in loanValue: ' + loanValue.toFixed(8) + ' vs ' + vault.loanValue)
return false
}
if (collValue.minus(vault.collateralValue).absoluteValue().div(collValue).gt(percThreshold)) {
// more than 1% difference -> problem
console.warn('inconsistency in collateralValue: ' + collValue.toFixed(8) + ' vs ' + vault.collateralValue)
return false
}
if (
loanValue.gt(collValue.div(100)) && //super low loan (empty or ratio > 10000%) could lead to floating point errors or div by zero -> no need to check consistency anyway
ratio.minus(vault.informativeRatio).absoluteValue().gt(this.maxPercentDiffInConsistencyChecks)
) {
console.warn('inconsistency in collRatio: ' + ratio.toFixed(8) + ' vs ' + vault.informativeRatio)
return false
}
return true
}
Expand Down
2 changes: 1 addition & 1 deletion ocean-client/src/vault-maxi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class maxiEvent {

const MIN_TIME_PER_ACTION_MS = 300 * 1000 //min 5 minutes for action. probably only needs 1-2, but safety first?

export const VERSION = "v2.3.1"
export const VERSION = "v2.3.2"
export const DONATION_ADDRESS = "df1qqtlz4uw9w5s4pupwgucv4shl6atqw7xlz2wn07"
export const DONATION_ADDRESS_TESTNET= "tZ1GuasY57oin5cej1Wp3MA1pAE4y3tmzq"
export const DONATION_MAX_PERCENTAGE = 50
Expand Down

0 comments on commit 8083490

Please sign in to comment.