Skip to content

Commit

Permalink
Merge pull request #63 from strkfarm/akira/dnmm
Browse files Browse the repository at this point in the history
Akira/dnmm
  • Loading branch information
akiraonstarknet authored Jul 8, 2024
2 parents 25ae84a + f9a5893 commit 7f7f414
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts
.env
3 changes: 2 additions & 1 deletion src/app/strategy/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ export default function Strategy() {
fontSize={'14px'}
>
<Text width={{ base: '100%', md: '50%' }} padding={'5px 10px'}>
{index + 1} {action.name}
{index + 1}
{')'} {action.name}
</Text>
<Text width={{ base: '100%', md: '30%' }} padding={'5px 10px'}>
<Avatar
Expand Down
5 changes: 3 additions & 2 deletions src/components/Strategies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,10 @@ export default function Strategies() {
textAlign={{ base: 'left', md: 'right' }}
width="100%"
float={'left'}
color="color1_light"
color="#eeeeee"
fontWeight={'bold'}
>
{strat.leverage.toFixed(1)}x higher returns
{strat.leverage.toFixed(1)}x
</Text>
</Tooltip>
</Box>
Expand Down
3 changes: 1 addition & 2 deletions src/store/jedi.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class Jediswap extends IDapp<string> {
link = 'https://app.jediswap.xyz/#/pool';
logo = 'https://app.jediswap.xyz/favicon/favicon-32x32.png';
incentiveDataKey = 'Jediswap_v1';
_computePoolsInfo(data: any) {
_computePoolsInfo(data: any) {
try {
const myData = data[this.incentiveDataKey];
if (!myData) return [];
Expand Down Expand Up @@ -74,7 +74,6 @@ export class Jediswap extends IDapp<string> {
title: 'STRK rewards',
description: 'Starknet DeFi Spring incentives',
},

],
category,
type: PoolType.DEXV2,
Expand Down
2 changes: 1 addition & 1 deletion src/store/myswap.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,4 @@ const MySwapAtoms: ProtocolAtoms = {
return empty;
}),
};
export default MySwapAtoms;
export default MySwapAtoms;
2 changes: 1 addition & 1 deletion src/store/nostradegen.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class NostraDegen extends Jediswap {
const logo1 = CONSTANTS.LOGOS[tokens[0]];
const logo2 = CONSTANTS.LOGOS[tokens[1]];
const baseApr =
poolData.baseApr === '0' ? 0.00 : parseFloat(poolData.baseApr);
poolData.baseApr === '0' ? 0.0 : parseFloat(poolData.baseApr);
const rewardApr = parseFloat(poolData.rewardApr);
const poolInfo: PoolInfo = {
pool: {
Expand Down
8 changes: 4 additions & 4 deletions src/store/strategies.atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export const strategiesAtom = atom<StrategyInfo[]>((get) => {
Mustache.render(DNMMDescription, { token1: 'USDC', token2: 'ETH' }),
'ETH',
CONSTANTS.CONTRACTS.DeltaNeutralMMUSDCETH,
[1.52, 0.618, 1, 0.553, 1.923], // precomputed factors based on strategy math
StrategyLiveStatus.COMING_SOON,
[1, 0.618, 1, 0.553], // precomputed factors based on strategy math
StrategyLiveStatus.ACTIVE,
);

const deltaNeutralMMETHUSDC = new DeltaNeutralMM(
Expand All @@ -42,7 +42,7 @@ export const strategiesAtom = atom<StrategyInfo[]>((get) => {
'USDC',
// ! change this later
CONSTANTS.CONTRACTS.DeltaNeutralMMUSDCETH,
[1.52, 0.618, 1, 0.553, 1.923],
[1, 0.618, 1, 0.553], // precomputed factors based on strategy math
StrategyLiveStatus.COMING_SOON,
);
const deltaNeutralMMSTRKUSDC = new DeltaNeutralMM(
Expand All @@ -51,7 +51,7 @@ export const strategiesAtom = atom<StrategyInfo[]>((get) => {
'USDC',
// ! change this later
CONSTANTS.CONTRACTS.DeltaNeutralMMUSDCETH,
[1.52, 0.618, 1, 0.553, 1.923],
[1, 0.618, 1, 0.553], // precomputed factors based on strategy math
StrategyLiveStatus.COMING_SOON,
);

Expand Down
10 changes: 6 additions & 4 deletions src/store/transactions.atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ async function deserialiseTxInfo(key: string, initialValue: TransactionInfo[]) {
? JSON.parse(storedValue)
: initialValue;
txs.forEach((tx) => {
tx.info.amount = new MyNumber(
tx.info.amount.bigNumber.toString(),
tx.info.amount.decimals,
);
if (tx.info.amount) {
tx.info.amount = new MyNumber(
tx.info.amount.bigNumber.toString(),
tx.info.amount.decimals,
);
}
tx.createdAt = new Date(tx.createdAt);
});
return txs;
Expand Down
81 changes: 68 additions & 13 deletions src/strategies/delta_neutral_mm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class DeltaNeutralMM extends IStrategy {

this.steps = [
{
name: `Supplies your ${token} to zkLend [1.52x]`,
name: `Supplies your ${token} to zkLend`,
optimizer: this.optimizer,
filter: [this.filterMainToken],
},
Expand All @@ -73,14 +73,19 @@ export class DeltaNeutralMM extends IStrategy {
optimizer: this.optimizer,
filter: [this.filterMainToken],
},
{
name: `Loop back to step 1, repeat 3 more times`,
optimizer: this.getLookRepeatYieldAmount,
filter: [this.filterMainToken],
},
{
name: `Re-invest your STRK Rewards every 14 days`,
optimizer: this.compounder,
filter: [this.filterStrkzkLend],
},
];

if (stepAmountFactors.length != this.steps.length) {
if (stepAmountFactors.length != 4) {
throw new Error(
'stepAmountFactors length should be equal to steps length',
);
Expand Down Expand Up @@ -127,36 +132,86 @@ export class DeltaNeutralMM extends IStrategy {
actions: StrategyAction[],
): StrategyAction[] {
console.log('optimizer', actions.length, this.stepAmountFactors);
const _amount = (
Number(amount) * this.stepAmountFactors[actions.length]
).toFixed(2);
return [
...actions,
{
pool: eligiblePools[0],
amount: (
Number(amount) * this.stepAmountFactors[actions.length]
).toFixed(2),
amount: _amount,
isDeposit: actions.length == 0 || actions.length == 2,
},
];
}

getLookRepeatYieldAmount(
eligiblePools: PoolInfo[],
amount: string,
actions: StrategyAction[],
) {
console.log('getLookRepeatYieldAmount', amount, actions);
let full_amount = Number(amount);
this.stepAmountFactors.forEach((factor, i) => {
full_amount /= factor;
});
const amount1 = 0.52 * full_amount;
const exp1 = amount1 * this.actions[0].pool.apr;
const amount2 = this.stepAmountFactors[1] * 0.52 * full_amount;
const exp2 =
amount2 * (this.actions[2].pool.apr - this.actions[1].pool.borrow.apr);
const amount3 = this.stepAmountFactors[3] * amount2;
const exp3 = -amount3 * this.actions[3].pool.borrow.apr;
const effecitveAmount = amount1 - amount3;
const effectiveAPR = (exp1 + exp2 + exp3) / effecitveAmount;
const pool: PoolInfo = { ...eligiblePools[0] };
pool.apr = effectiveAPR;
const strategyAction: StrategyAction = {
pool,
amount: effecitveAmount.toString(),
isDeposit: true,
};
console.log(
'getLookRepeatYieldAmount exp1',
exp1,
full_amount,
exp2,
amount2,
this.actions[2],
this.actions[1],
exp3,
amount3,
);
return [...actions, strategyAction];
}

compounder(
eligiblePools: PoolInfo[],
amount: string,
actions: StrategyAction[],
): StrategyAction[] {
const baseApr = actions.reduce(
(acc, a) => acc + (a.isDeposit ? a.pool.apr : -a.pool.borrow.apr),
0,
);
const amountWeights = this.actions.reduce((a, pool) => {
const sign = pool.isDeposit ? 1 : -1;
const apr = pool.isDeposit ? pool.pool.apr : pool.pool.borrow.apr;
console.log('compounder2', sign, pool.amount, apr);
return sign * Number(pool.amount) * apr + a;
}, 0);
const amountIn = Number(this.actions[0].amount);
const baseApr = amountWeights / amountIn;
const compoundingApr = (1 + baseApr / 26) ** 26 - 1;
console.log('compounder', baseApr, compoundingApr, actions);
console.log(
'compounder',
amountIn,
amountWeights,
baseApr,
compoundingApr,
actions,
);
return [
...actions,
{
pool: { ...eligiblePools[0], apr: compoundingApr - baseApr },
amount: (
Number(amount) * this.stepAmountFactors[actions.length]
).toFixed(2),
amount: amountIn.toFixed(2),
isDeposit: true,
},
];
Expand Down

0 comments on commit 7f7f414

Please sign in to comment.