Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
Added userVaultsData schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Padraic-O-Mhuiris committed Feb 16, 2020
1 parent 3f25c8b commit b0af9e2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
27 changes: 23 additions & 4 deletions packages/dai-plugin-mcd/src/schemas/computed.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ import {
DATE_EARNINGS_LAST_ACCRUED,
USER_VAULT_IDS,
USER_VAULT_ADDRESSES,
USER_VAULT_TYPES
USER_VAULT_TYPES,
VAULT
} from './constants';

export const collateralTypePrice = {
Expand Down Expand Up @@ -108,6 +109,8 @@ export const vaultCollateralAndDebt = {
})
};

// TODO This should also account for unencumbered collateral which is collateral on the
// join adapter
export const collateralAmount = {
generate: id => ({
dependencies: [
Expand Down Expand Up @@ -188,11 +191,19 @@ export const minSafeCollateralAmount = {
calcMinSafeCollateralAmount(debtValue, liquidationRatio, price)
})
};

export const collateralAvailableAmount = {
generate: id => ({
dependencies: [[COLLATERAL_AMOUNT, id], [MIN_SAFE_COLLATERAL_AMOUNT, id]],
computed: (collateralAmount, minSafeCollateralAmount) =>
collateralAmount.minus(minSafeCollateralAmount)
computed: (collateralAmount, minSafeCollateralAmount) => {
if (
minSafeCollateralAmount.toBigNumber().gt(collateralAmount.toBigNumber())
) {
return createCurrency(collateralAmount.symbol)(0);
} else {
return collateralAmount.minus(minSafeCollateralAmount);
}
}
})
};

Expand Down Expand Up @@ -399,6 +410,13 @@ export const userVaultsList = {
})
};

export const userVaultsData = {
generate: ids => ({
dependencies: ids.map(id => [VAULT, id]),
computed: (...vaults) => vaults
})
};

export default {
collateralTypePrice,
collateralTypesPrices,
Expand All @@ -420,5 +438,6 @@ export default {
balance,
allowance,
savings,
userVaultsList
userVaultsList,
userVaultsData
};
1 change: 1 addition & 0 deletions packages/dai-plugin-mcd/src/schemas/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const BALANCE = 'balance';
export const ALLOWANCE = 'allowance';
export const SAVINGS = 'savings';
export const USER_VAULTS_LIST = 'userVaultsList';
export const USER_VAULTS_DATA = 'userVaultsData';

// token
export const TOKEN_BALANCE = 'tokenBalance';
Expand Down

0 comments on commit b0af9e2

Please sign in to comment.