Skip to content

Commit

Permalink
feat(@nftx/config): new package
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmellis committed Dec 16, 2022
1 parent 154e4cb commit 9c28a19
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
2 changes: 2 additions & 0 deletions packages/constants/src/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ export const ZEROX_URL = {
// TODO: only enable this once contracts support the 0x api, otherwise we'll end up with conflicting prices
// [Network.Mainnet]: 'https://api.0x.org',
};

export const NFTX_APR_URL = 'https://aprs.nftx.xyz';
4 changes: 2 additions & 2 deletions packages/web3/src/tokens/fetchReservesForTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ function formatTokenReserves(token: TokenPair, network: number): TokenReserve {
);

if (wethPair) {
const reserveVtoken = parseEther(wethPair.reserve0 || '0');
const reserveWeth = parseEther(wethPair.reserve1 || '0');
const reserveVtoken = parseEther(wethPair.reserve1 || '0');
const reserveWeth = parseEther(wethPair.reserve0 || '0');
const midPrice = calcMidPrice(reserveVtoken, reserveWeth);

return {
Expand Down
25 changes: 20 additions & 5 deletions packages/web3/src/vaults/fetchVaultAprs.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
import { NFTX_APR_URL } from '@nftx/constants';
import { addressEqual } from '../web3';
import type { VaultAddress, VaultApr } from './types';

type Response = Array<{
vault_id: string;
inventoryApr: Record<string, string>;
liquidityApr: Record<string, string>;
}>;

const fetchVaultAprs = async ({
vaultAddresses,
}: {
vaultAddresses: VaultAddress[];
}): Promise<VaultApr[]> => {
// TODO: implement this
console.warn('fetchVaultAprs is currently stubbed');
const response = await fetch(NFTX_APR_URL);
let data: Response;
try {
data = await response.json();
} catch {
data = [];
}

return vaultAddresses.map((vaultAddress): VaultApr => {
const x = data.find(({ vault_id }) => addressEqual(vault_id, vaultAddress));

return {
vaultAddress,
vaultId: '0',
liquidityApr: Math.floor(Math.random() * 300) / 100,
inventoryApr: Math.floor(Math.random() * 100) / 100,
liquidityApr: Number(Object.values(x?.liquidityApr ?? {})[0] ?? '0'),
inventoryApr: Number(Object.values(x?.inventoryApr ?? {})[0] ?? '0'),
};
});
};
Expand Down
1 change: 0 additions & 1 deletion packages/web3/src/vaults/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export type Vault = {
};

export type VaultApr = {
vaultId: VaultId;
vaultAddress: VaultAddress;
inventoryApr: number;
liquidityApr: number;
Expand Down

0 comments on commit 9c28a19

Please sign in to comment.