Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Fix inconsistent APY issues #162

Merged
merged 9 commits into from
Oct 3, 2024
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<img src="https://avatars.githubusercontent.com/u/165751591?s=200&v=4" height="150">
</div>
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<!-- prettier-ignore-end -->

# STRKFarm

Expand Down
2 changes: 1 addition & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const nextConfig = {
// output: 'export',
compiler: {
removeConsole: {
exclude: ['error'],
exclude: ['error', 'debug'],
},
},
async rewrites() {
Expand Down
16 changes: 16 additions & 0 deletions src/app/api/strategies/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
const hasRequiredPools = minProtocolsRequired.every((p) => {
if (!allPools) return false;
return allPools.some(
(pool) => pool.protocol.name === p && pool.type == PoolType.Lending,

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

View workflow job for this annotation

GitHub Actions / Performs linting, formatting on the application

Expected '===' and instead saw '=='
);
});
const MAX_RETRIES = 120;
Expand Down Expand Up @@ -71,10 +71,26 @@
},
riskFactor: strategy.riskFactor,
logo: strategy.holdingTokens[0].logo,
actions: strategy.actions.map((action) => {
return {
name: action.name || '',
protocol: {
name: action.pool.protocol.name,
logo: action.pool.protocol.logo,
},
token: {
name: action.pool.pool.name,
logo: action.pool.pool.logos[0],
},
amount: action.amount,
isDeposit: action.isDeposit,
apy: action.isDeposit ? action.pool.apr : -action.pool.borrow.apr,
};
}),
};
}

export async function GET(req: Request) {

Check warning on line 93 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();

Expand Down
1 change: 1 addition & 0 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export default function Navbar(props: NavbarProps) {

// set address atom
useEffect(() => {
console.log('tncinfo address', address);
setAddress(address);
}, [address]);

Expand Down
5 changes: 3 additions & 2 deletions src/components/TncModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { LATEST_TNC_DOC_VERSION, SIGNING_DATA } from '@/constants';
import { LATEST_TNC_DOC_VERSION, SIGNING_DATA, TnC_DOC_URL } from '@/constants';
import { addressAtom } from '@/store/claims.atoms';
import {
Button,
Expand Down Expand Up @@ -61,6 +61,7 @@ const TncModal: React.FC<TncModalProps> = (props) => {
(async () => {
if (userTncInfo.success && userTncInfo.user) {
setReferralCode(userTncInfo.user.referralCode);
console.log(`tncinfo`, userTncInfo.user);
if (
(userTncInfo.user.isTncSigned &&
userTncInfo.user.tncDocVersion !== LATEST_TNC_DOC_VERSION) ||
Expand Down Expand Up @@ -166,7 +167,7 @@ const TncModal: React.FC<TncModalProps> = (props) => {
as={'a'}
width={'100%'}
fontWeight={'bold'}
href={SIGNING_DATA.message.document}
href={TnC_DOC_URL}
color="white"
target="_blank"
_hover={{ textDecor: 'underline' }}
Expand Down
4 changes: 2 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export const NFTS: NFTInfo[] = [
// ? When updating this, ensure there is redirect available for this route
// ? to respect version of doc in github
export const LATEST_TNC_DOC_VERSION = 'tnc/v1';

export const TnC_DOC_URL = `${getEndpoint()}/${LATEST_TNC_DOC_VERSION}`;
export const SIGNING_DATA = {
types: {
StarkNetDomain: [
Expand All @@ -219,7 +219,7 @@ export const SIGNING_DATA = {
},
message: {
message: 'Read and Agree T&C',
document: `${getEndpoint().replace('https://', '').replace('http://', '')}/${LATEST_TNC_DOC_VERSION}`,
document: `${TnC_DOC_URL.replace('https://', '').replace('http://', '')}`,
},
};

Expand Down
15 changes: 15 additions & 0 deletions src/store/strkfarm.atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ export interface STRKFarmStrategyAPIResult {
};
riskFactor: number;
logo: string;

actions: {
name: string;
protocol: {
name: string;
logo: string;
};
token: {
name: string;
logo: string;
};
amount: string;
isDeposit: boolean;
apy: number;
}[];
}

export class STRKFarm extends IDapp<STRKFarmStrategyAPIResult> {
Expand Down
4 changes: 2 additions & 2 deletions src/strategies/IStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,15 @@ export class IStrategy extends IStrategyProps {
return;
}

console.debug('Completed solving actions');
console.debug('Completed solving actions', this.actions.length);
this.actions.forEach((action) => {
const sign = action.isDeposit ? 1 : -1;
const apr = action.isDeposit ? action.pool.apr : action.pool.borrow.apr;
netYield += sign * apr * Number(action.amount);
console.debug('netYield1', sign, apr, action.amount, netYield);
});
this.netYield = netYield / Number(amount);
console.debug('netYield', netYield, this.netYield);
console.debug('netYield', netYield, this.netYield, Number(amount));
this.leverage = this.netYield / this.actions[0].pool.apr;

this.postSolve();
Expand Down
17 changes: 11 additions & 6 deletions src/utils/customAtomWithFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,25 @@ export const customAtomWithFetch = (args: {
return customAtomWithQuery({
queryKey,
queryFn: async () => {
const urlPrefix =
typeof window === 'undefined' && !url.includes('http')
? process.env.HOSTNAME || 'https://app.strkfarm.xyz'
: '';

try {
const urlPrefix =
typeof window === 'undefined' && !url.includes('http')
? 'http://localhost:3000'
: '';
const options = args.fetchOptions || { method: 'GET' };
const res = await fetch(`${urlPrefix}${url}`, options);
if (!res.ok) {
console.error('Error fetching url', res.statusText);
console.error(
'Error fetching url',
`${urlPrefix}${url}`,
res.statusText,
);
throw new Error('Error fetching url');
}
return res.json();
} catch (err) {
console.error('Error fetching url', err);
console.error('Error fetching url', `${urlPrefix}${url}`, err);
throw err;
}
},
Expand Down
Loading