-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add oraclePrice and goverance data to liquidated vaults #20
Changes from 3 commits
8dcbfba
1cb5e76
a72a70a
004753d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import { | |
Wallet, | ||
Vault, | ||
VaultLiquidation, | ||
OraclePrice, | ||
} from '../../types'; | ||
import { VAULT_STATES } from '../constants'; | ||
import { dateToDayKey, extractBrand } from '../utils'; | ||
|
@@ -77,6 +78,9 @@ export const vaultsEventKit = (block: any, data: any, module: string, path: stri | |
async function saveVaultsLiquidation(payload: any): Promise<any> { | ||
const id = `${path}-${payload?.vaultState}`; | ||
const liquidatingId = `${path}-${VAULT_STATES.LIQUIDATING}`; | ||
|
||
const denom = payload?.locked?.__brand; | ||
|
||
let vault = await VaultLiquidation.get(id); | ||
if (!vault) { | ||
vault = new VaultLiquidation( | ||
|
@@ -89,8 +93,26 @@ export const vaultsEventKit = (block: any, data: any, module: string, path: stri | |
); | ||
} | ||
|
||
vault.coin = payload?.locked?.__brand; | ||
vault.denom = payload?.locked?.__brand; | ||
const vaultGovernanceId = id.split('.').slice(0, 4).join('.') + '.governance'; | ||
const vaultManagerGovernance = await VaultManagerGovernance.get(vaultGovernanceId); | ||
|
||
const oraclPriceId = `${denom}-USD`; | ||
const oraclePrice = await OraclePrice.get(oraclPriceId); | ||
|
||
if (vaultManagerGovernance && vault.vaultManagerGovernance === undefined) | ||
vault.vaultManagerGovernance = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should also handle the case when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
liquidationMarginNumerator: vaultManagerGovernance.liquidationMarginNumerator, | ||
liquidationMarginDenominator: vaultManagerGovernance.liquidationMarginDenominator, | ||
}; | ||
|
||
if (oraclePrice && vault.oraclePrice === undefined) | ||
vault.oraclePrice = { | ||
typeInAmount: oraclePrice.typeInAmount, | ||
typeOutAmount: oraclePrice.typeOutAmount, | ||
}; | ||
|
||
vault.coin = denom; | ||
vault.denom = denom; | ||
vault.debt = payload?.debtSnapshot?.debt?.__value; | ||
vault.balance = payload?.locked?.__value; | ||
vault.lockedValue = payload?.locked?.__value; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add optional chaining on line 96:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id here should exist in all cases. if we put optional chaining here, we will get an invalid id. crashing in case the id format is invalid would be the preferred option here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, I see. I reckon it's the we're using the
id
declared on line79
?Do you think we should have some sort of validation for id over there?
It's possible that
id
can have the valueundefined-null.governance
whenpath
andpayload?.vaultState
have falsy values.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function is only triggered from line: src/mappings/mappingHandlers.ts:214 where we perform a regex check on the path. so there is no way it is falsy.
in any case i've added a regex check just to be safe