Skip to content

Commit

Permalink
Error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
toliaqat committed May 22, 2024
1 parent 694d8b1 commit ec4f992
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/mappings/events/vaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const vaultsEventKit = (block: any, data: any, module: string, path: stri
return promises;
}

async function updateDailyVaultState(
async function updateVaultStatesDaily(
oldState: string | undefined,
newState: string,
blockTime: Date,
Expand Down Expand Up @@ -106,27 +106,29 @@ export const vaultsEventKit = (block: any, data: any, module: string, path: stri
[VAULT_STATES.LIQUIDATED]: 'liquidatedClosed',
};

if (oldState) {
vaultState.blockHeightLast = BigInt(blockHeight);
vaultState.blockTimeLast = blockTime;

if (oldState && propertyMap[oldState]) {
const oldProperty = propertyMap[oldState];
if ((vaultState as any)[oldProperty] === BigInt(0)) {
throw Error(oldState + ' vaults are 0. cannot subtract more');
}
(vaultState as any)[oldProperty] -= BigInt(1);
}

const newProperty =
newState === VAULT_STATES.CLOSED && oldState ? closedPropertyMap[oldState] : propertyMap[newState];
(vaultState as any)[newProperty] += BigInt(1);

vaultState.blockHeightLast = BigInt(blockHeight);
vaultState.blockTimeLast = blockTime;
if ((newState && propertyMap[newState]) || (oldState && closedPropertyMap[oldState])) {
const newProperty =
newState === VAULT_STATES.CLOSED && oldState ? closedPropertyMap[oldState] : propertyMap[newState];
(vaultState as any)[newProperty] += BigInt(1);
}

return vaultState;
}

async function saveVaults(payload: any): Promise<Promise<any>[]> {
let vault = await Vault.get(path);
const dailyVaultState = await updateDailyVaultState(
const dailyVaultState = await updateVaultStatesDaily(
vault?.state,
payload?.vaultState,
block.block.header.time,
Expand Down

0 comments on commit ec4f992

Please sign in to comment.