diff --git a/ocean-client/.vscode/settings.json b/ocean-client/.vscode/settings.json new file mode 100644 index 0000000..5ea90bb --- /dev/null +++ b/ocean-client/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "editor.formatOnSaveMode": "modifications", + "editor.formatOnSave": true +} \ No newline at end of file diff --git a/ocean-client/src/programs/vault-maxi-program.ts b/ocean-client/src/programs/vault-maxi-program.ts index c367a24..c392f80 100644 --- a/ocean-client/src/programs/vault-maxi-program.ts +++ b/ocean-client/src/programs/vault-maxi-program.ts @@ -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 } diff --git a/ocean-client/src/vault-maxi.ts b/ocean-client/src/vault-maxi.ts index 1546201..f2053aa 100644 --- a/ocean-client/src/vault-maxi.ts +++ b/ocean-client/src/vault-maxi.ts @@ -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