Skip to content

Commit

Permalink
Merge branch 'strkfarm:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Jemiiah authored Sep 14, 2024
2 parents 9aa76e6 + c87626b commit caaefe1
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 40 deletions.
48 changes: 29 additions & 19 deletions src/app/api/strategies/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { RpcProvider } from 'starknet';
import { getStrategies } from '@/store/strategies.atoms';
import { MY_STORE } from '@/store';
import MyNumber from '@/utils/MyNumber';
import { NFTInfo, TokenInfo } from '@/strategies/IStrategy';
import { IStrategy, NFTInfo, TokenInfo } from '@/strategies/IStrategy';

export const revalidate = 3600; // 1 hr

Expand All @@ -34,34 +34,44 @@ const provider = new RpcProvider({
nodeUrl: process.env.RPC_URL || 'https://starknet-mainnet.public.blastapi.io',
});

async function getStrategyInfo(strategy: IStrategy) {
const tvl = await strategy.getTVL();

return {
name: strategy.name,
id: strategy.id,
apy: strategy.netYield,
depositToken: strategy
.depositMethods(MyNumber.fromZero(), '', provider)
.map((t) => t.tokenInfo.token),
leverage: strategy.leverage,
contract: strategy.holdingTokens.map((t) => ({
name: t.name,
address: (<any>t).token ? (<TokenInfo>t).token : (<NFTInfo>t).address,
})),
tvlUsd: tvl.usdValue || 0,
status: strategy.liveStatus,
};
}

export async function GET(req: Request) {

Check warning on line 57 in src/app/api/strategies/route.ts

View workflow job for this annotation

GitHub Actions / Performs linting, formatting on the application

'req' is defined but never used. Allowed unused args must match /^_/u
const allPools = await getPools(MY_STORE);
const strategies = getStrategies();
strategies.forEach((strategy) => {
strategy.solve(allPools, '1000');
});

const stratsDataProms: any[] = [];
for (let i = 0; i < strategies.length; i++) {
stratsDataProms.push(getStrategyInfo(strategies[i]));
}

const stratsData = await Promise.all(stratsDataProms);

try {
return NextResponse.json({
status: true,
strategies: strategies.map((s) => {
return {
name: s.name,
id: s.id,
apy: s.netYield,
depositToken: s
.depositMethods(MyNumber.fromZero(), '', provider)
.map((t) => t.tokenInfo.token),
leverage: s.leverage,
contract: s.holdingTokens.map((t) => ({
name: t.name,
address: (<any>t).token
? (<TokenInfo>t).token
: (<NFTInfo>t).address,
})),
status: s.liveStatus,
};
}),
strategies: stratsData,
});
} catch (err) {
console.error('Error /api/strategies', err);
Expand Down
15 changes: 9 additions & 6 deletions src/app/strategy/[strategyId]/_components/Strategy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
TabPanels,
Tabs,
Text,
Tooltip,
VStack,
Wrap,
WrapItem,
Expand Down Expand Up @@ -159,12 +160,14 @@ const Strategy = ({ params }: StrategyParams) => {
<StatLabel textAlign={{ base: 'left', md: 'right' }}>
APY
</StatLabel>
<StatNumber
color="cyan"
textAlign={{ base: 'left', md: 'right' }}
>
{(strategy.netYield * 100).toFixed(2)}%
</StatNumber>
<Tooltip label="Effective APY after removing fees. We charge a 10% performance fee on the rewards generated.">
<StatNumber
color="cyan"
textAlign={{ base: 'left', md: 'right' }}
>
{(strategy.netYield * 100).toFixed(2)}%
</StatNumber>
</Tooltip>
<StatHelpText textAlign={{ base: 'left', md: 'right' }}>
{strategy.leverage.toFixed(2)}x boosted
</StatHelpText>
Expand Down
9 changes: 0 additions & 9 deletions src/components/Deposit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,6 @@ export default function Deposit(props: DepositProps) {
/>
</Center>

<Text
textAlign="center"
color="disabled_bg"
fontSize="12px"
marginTop="20px"
>
No additional fees by STRKFarm
</Text>

<Box width="100%" marginTop={'15px'}>
<Flex justifyContent="space-between">
<Text fontSize={'12px'} color="color2" fontWeight={'bold'}>
Expand Down
1 change: 1 addition & 0 deletions src/strategies/IStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export class IStrategyProps {
actions: StrategyAction[] = [];
netYield: number = 0;
leverage: number = 0;
fee_factor = 0; // in absolute terms, not %
status = StrategyStatus.UNINTIALISED;

readonly rewardTokens: { logo: string }[];
Expand Down
14 changes: 13 additions & 1 deletion src/strategies/delta_neutral_mm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class DeltaNeutralMM extends IStrategy {
readonly strategyAddress: string;
// Factor of Amount to be deposited/borrowed at each step relative to the previous step
readonly stepAmountFactors: number[];
fee_factor = 0.1; // 10% fee

constructor(
token: TokenInfo,
Expand Down Expand Up @@ -149,10 +150,21 @@ export class DeltaNeutralMM extends IStrategy {
const _amount = (
Number(amount) * this.stepAmountFactors[actions.length]
).toFixed(2);
const pool = { ...eligiblePools[0] };
const isDeposit = actions.length == 0 || actions.length == 2;
const effectiveAPR = pool.aprSplits.reduce((a, b) => {
if (b.apr == 'Err') return a;
if (!isDeposit) return a + Number(b.apr);
if (b.title.includes('STRK rewards')) {
return a + Number(b.apr) * (1 - this.fee_factor);
}
return a + Number(b.apr);
}, 0);
pool.apr = isDeposit ? effectiveAPR : pool.borrow.apr;
return [
...actions,
{
pool: eligiblePools[0],
pool,
amount: _amount,
isDeposit: actions.length == 0 || actions.length == 2,
},
Expand Down
5 changes: 0 additions & 5 deletions src/utils/customAtomWithFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,17 @@ export const customAtomWithFetch = (args: {
return customAtomWithQuery({
queryKey,
queryFn: async () => {
console.log(`zkLend 3`);
try {
const urlPrefix =
typeof window === 'undefined' && !url.includes('http')
? 'http://localhost:3000'
: '';
console.log(`zkLend 4`, `${urlPrefix}${url}`);
const options = args.fetchOptions || { method: 'GET' };
console.log(`zkLend 5`, options);
const res = await fetch(`${urlPrefix}${url}`, options);
console.log(`zkLend 6`, res);
if (!res.ok) {
console.error('Error fetching url', res.statusText);
throw new Error('Error fetching url');
}
console.log(`zkLend 5`);
return res.json();
} catch (err) {
console.error('Error fetching url', err);
Expand Down

0 comments on commit caaefe1

Please sign in to comment.