Skip to content

Commit

Permalink
feat: Move in try
Browse files Browse the repository at this point in the history
  • Loading branch information
ChefMomota committed Dec 21, 2023
1 parent 1cb6811 commit 1d26908
Showing 1 changed file with 37 additions and 37 deletions.
74 changes: 37 additions & 37 deletions src/pools/service/alpFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,73 +3,73 @@ import BigNumber from "bignumber.js";
import { Address } from "viem";
import { getViemClients } from "../../utils/viem";

const WEEK = 7
const YEAR = 365
const API_URL = 'https://perp.pancakeswap.finance/bapi/futures/v1/public/future/apx/fee/info?chain='
const WEEK = 7;
const YEAR = 365;
const API_URL = "https://perp.pancakeswap.finance/bapi/futures/v1/public/future/apx/fee/info?chain=";

const CONTRACT_ADDRESS: Record<number, Address> = {
[ChainId.OPBNB]: '0x5A5454A6030FB50ceb3eb78977D140198A27be5e',
[ChainId.ARBITRUM_ONE]: '0xB3879E95a4B8e3eE570c232B19d520821F540E48',
}
[ChainId.OPBNB]: "0x5A5454A6030FB50ceb3eb78977D140198A27be5e",
[ChainId.ARBITRUM_ONE]: "0xB3879E95a4B8e3eE570c232B19d520821F540E48",
};

const CHAIN_NAME_MAP: Record<number, string> = {
[ChainId.OPBNB]: 'OPBNB',
[ChainId.ARBITRUM_ONE]: 'ARB',
}
[ChainId.OPBNB]: "OPBNB",
[ChainId.ARBITRUM_ONE]: "ARB",
};

export const alpFee = async (chainId: ChainId) => {
const client = getViemClients({ chainId });
try {
const client = getViemClients({ chainId });
const [totalValue] = await client.multicall({
contracts: [
{
abi: [
{
inputs: [],
name: 'totalValue',
name: "totalValue",
outputs: [
{
components: [
{ internalType: 'address', name: 'tokenAddress', type: 'address' },
{ internalType: 'int256', name: 'value', type: 'int256' },
{ internalType: 'uint8', name: 'decimals', type: 'uint8' },
{ internalType: 'int256', name: 'valueUsd', type: 'int256' },
{ internalType: 'uint16', name: 'targetWeight', type: 'uint16' },
{ internalType: 'uint16', name: 'feeBasisPoints', type: 'uint16' },
{ internalType: 'uint16', name: 'taxBasisPoints', type: 'uint16' },
{ internalType: 'bool', name: 'dynamicFee', type: 'bool' },
{ internalType: "address", name: "tokenAddress", type: "address" },
{ internalType: "int256", name: "value", type: "int256" },
{ internalType: "uint8", name: "decimals", type: "uint8" },
{ internalType: "int256", name: "valueUsd", type: "int256" },
{ internalType: "uint16", name: "targetWeight", type: "uint16" },
{ internalType: "uint16", name: "feeBasisPoints", type: "uint16" },
{ internalType: "uint16", name: "taxBasisPoints", type: "uint16" },
{ internalType: "bool", name: "dynamicFee", type: "bool" },
],
internalType: 'struct IVault.LpItem[]',
name: 'lpItems',
type: 'tuple[]',
internalType: "struct IVault.LpItem[]",
name: "lpItems",
type: "tuple[]",
},
],
stateMutability: 'view',
type: 'function',
stateMutability: "view",
type: "function",
},
] as const,
address: CONTRACT_ADDRESS?.[chainId],
functionName: 'totalValue',
functionName: "totalValue",
},
],
allowFailure: false,
})
});

const totalValueUsd = totalValue
.map((i) => new BigNumber(i.valueUsd.toString()).div(1e18).toNumber())
.reduce((a, b) => a + b, 0)
.reduce((a, b) => a + b, 0);

const response = await fetch(`${API_URL}${CHAIN_NAME_MAP[chainId]}`)
const result = await response.json()
const response = await fetch(`${API_URL}${CHAIN_NAME_MAP[chainId]}`);
const result = await response.json();

const { alpFundingFee, alpTradingFee, alpLipFee } = result.data
const apr = new BigNumber(alpFundingFee).plus(alpTradingFee).plus(alpLipFee)
const totalApr = apr.div(totalValueUsd.toString()).div(WEEK)
const { alpFundingFee, alpTradingFee, alpLipFee } = result.data;
const apr = new BigNumber(alpFundingFee).plus(alpTradingFee).plus(alpLipFee);
const totalApr = apr.div(totalValueUsd.toString()).div(WEEK);

const apy = totalApr.plus(1).exponentiatedBy(YEAR).minus(1).times(100)
return apy.toNumber()
const apy = totalApr.plus(1).exponentiatedBy(YEAR).minus(1).times(100);
return apy.toNumber();
} catch (error) {
console.info('Fetch ALP boosted fee error: ', error)
return 0
console.info("Fetch ALP boosted fee error: ", error);
return 0;
}
}
};

0 comments on commit 1d26908

Please sign in to comment.