Skip to content

Commit

Permalink
feat: vault state property
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmellis committed Dec 13, 2023
1 parent 0656ef9 commit 327f15e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/core/src/vaults/fetchVaults/transformVault.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Zero } from '@nftx/constants';
import { mapObj } from '../../utils';
import type { Response } from '../fetchSubgraphVaults';
import type { Address, Vault } from '@nftx/types';
import type { Address, Vault, VaultState } from '@nftx/types';

const transformVault = ({
vault: x,
Expand All @@ -16,6 +16,19 @@ const transformVault = ({
vTokenToEth: bigint;
collection: { slug: string };
}) => {
const state: VaultState = (() => {
if (x.shutdownDate && x.shutdownDate !== '0') {
return 'shutdown';
}
if (!x.isFinalized) {
return 'unfinalized';
}
if (x.totalHoldings === '0') {
return 'empty';
}
return 'active';
})();

const rawFees = (x.usesFactoryFees && globalFees ? globalFees : x.fees) ?? {};
const fees: Vault['fees'] = mapObj(rawFees, (key, value) => {
return [key, BigInt(value as string)];
Expand Down Expand Up @@ -47,6 +60,7 @@ const transformVault = ({
vaultId: `${x.vaultId}`,
slug: `${x.token.symbol}-${x.vaultId}`.toLowerCase(),
collectionSlug: (collection?.slug || x.asset.symbol).toLowerCase(),
state,
asset: {
...x.asset,
id: x.asset.id as Address,
Expand Down
4 changes: 4 additions & 0 deletions packages/types/src/vaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ export type VaultFees = {
swapFee: bigint;
};

export type VaultState = 'unfinalized' | 'empty' | 'active' | 'shutdown';

export type Vault = {
vaultId: string;
id: Address;
slug: string;
collectionSlug: string;
/** The current state of the vault */
state: VaultState;
asset: Token;
createdBy: { id: Address };
createdAt: number;
Expand Down

0 comments on commit 327f15e

Please sign in to comment.