From 20114df469ccc684b39be538ecf02d54132ff367 Mon Sep 17 00:00:00 2001 From: alt Date: Mon, 8 Jul 2024 22:04:59 +0200 Subject: [PATCH 1/3] add ignore .env --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fd3dbb5..ba1a0b6 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ yarn-error.log* # typescript *.tsbuildinfo next-env.d.ts +.env \ No newline at end of file From d68c422c307b13a5d00694e0e09da5e6ebc66c0d Mon Sep 17 00:00:00 2001 From: alt Date: Mon, 8 Jul 2024 23:24:51 +0200 Subject: [PATCH 2/3] update DNMM behind the scenes, activate USDC maxi again --- src/app/strategy/page.tsx | 2 +- src/components/Strategies.tsx | 5 ++- src/store/strategies.atoms.ts | 8 ++-- src/store/transactions.atom.ts | 10 +++-- src/strategies/delta_neutral_mm.ts | 62 +++++++++++++++++++++++------- 5 files changed, 63 insertions(+), 24 deletions(-) diff --git a/src/app/strategy/page.tsx b/src/app/strategy/page.tsx index 8323d07..612210e 100644 --- a/src/app/strategy/page.tsx +++ b/src/app/strategy/page.tsx @@ -306,7 +306,7 @@ export default function Strategy() { fontSize={'14px'} > - {index + 1} {action.name} + {index + 1}{")"} {action.name} - {strat.leverage.toFixed(1)}x higher returns + {strat.leverage.toFixed(1)}x diff --git a/src/store/strategies.atoms.ts b/src/store/strategies.atoms.ts index 93692d4..2b09d80 100644 --- a/src/store/strategies.atoms.ts +++ b/src/store/strategies.atoms.ts @@ -32,8 +32,8 @@ export const strategiesAtom = atom((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( @@ -42,7 +42,7 @@ export const strategiesAtom = atom((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( @@ -51,7 +51,7 @@ export const strategiesAtom = atom((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, ); diff --git a/src/store/transactions.atom.ts b/src/store/transactions.atom.ts index c95b50f..7d9fa93 100644 --- a/src/store/transactions.atom.ts +++ b/src/store/transactions.atom.ts @@ -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; diff --git a/src/strategies/delta_neutral_mm.ts b/src/strategies/delta_neutral_mm.ts index 915d116..3a57a56 100644 --- a/src/strategies/delta_neutral_mm.ts +++ b/src/strategies/delta_neutral_mm.ts @@ -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], }, @@ -73,6 +73,11 @@ 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, @@ -80,7 +85,7 @@ export class DeltaNeutralMM extends IStrategy { }, ]; - if (stepAmountFactors.length != this.steps.length) { + if (stepAmountFactors.length != 4) { throw new Error( 'stepAmountFactors length should be equal to steps length', ); @@ -127,36 +132,67 @@ export class DeltaNeutralMM extends IStrategy { actions: StrategyAction[], ): StrategyAction[] { console.log('optimizer', actions.length, this.stepAmountFactors); + let _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 = 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: 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, }, ]; From f9a5893ff383567f5d6166b67f97219f3d5dada3 Mon Sep 17 00:00:00 2001 From: alt Date: Mon, 8 Jul 2024 23:27:12 +0200 Subject: [PATCH 3/3] formatting fix --- src/app/strategy/page.tsx | 3 +- src/store/jedi.store.ts | 3 +- src/store/myswap.store.ts | 2 +- src/store/nostradegen.store.ts | 2 +- src/strategies/delta_neutral_mm.ts | 55 ++++++++++++++++++++---------- 5 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/app/strategy/page.tsx b/src/app/strategy/page.tsx index 612210e..3869781 100644 --- a/src/app/strategy/page.tsx +++ b/src/app/strategy/page.tsx @@ -306,7 +306,8 @@ export default function Strategy() { fontSize={'14px'} > - {index + 1}{")"} {action.name} + {index + 1} + {')'} {action.name} { 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 []; @@ -74,7 +74,6 @@ export class Jediswap extends IDapp { title: 'STRK rewards', description: 'Starknet DeFi Spring incentives', }, - ], category, type: PoolType.DEXV2, diff --git a/src/store/myswap.store.ts b/src/store/myswap.store.ts index dde50ef..fe321bc 100644 --- a/src/store/myswap.store.ts +++ b/src/store/myswap.store.ts @@ -250,4 +250,4 @@ const MySwapAtoms: ProtocolAtoms = { return empty; }), }; -export default MySwapAtoms; \ No newline at end of file +export default MySwapAtoms; diff --git a/src/store/nostradegen.store.ts b/src/store/nostradegen.store.ts index 3a4a352..edbe6c1 100644 --- a/src/store/nostradegen.store.ts +++ b/src/store/nostradegen.store.ts @@ -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: { diff --git a/src/strategies/delta_neutral_mm.ts b/src/strategies/delta_neutral_mm.ts index 3a57a56..40a3aea 100644 --- a/src/strategies/delta_neutral_mm.ts +++ b/src/strategies/delta_neutral_mm.ts @@ -132,7 +132,9 @@ export class DeltaNeutralMM extends IStrategy { actions: StrategyAction[], ): StrategyAction[] { console.log('optimizer', actions.length, this.stepAmountFactors); - let _amount = (Number(amount) * this.stepAmountFactors[actions.length]).toFixed(2); + const _amount = ( + Number(amount) * this.stepAmountFactors[actions.length] + ).toFixed(2); return [ ...actions, { @@ -143,34 +145,44 @@ export class DeltaNeutralMM extends IStrategy { ]; } - getLookRepeatYieldAmount(eligiblePools: PoolInfo[], + getLookRepeatYieldAmount( + eligiblePools: PoolInfo[], amount: string, - actions: StrategyAction[]) { + actions: StrategyAction[], + ) { console.log('getLookRepeatYieldAmount', amount, actions); let full_amount = Number(amount); this.stepAmountFactors.forEach((factor, i) => { - full_amount = full_amount / factor; + full_amount /= factor; }); const amount1 = 0.52 * full_amount; - const exp1 = amount1 * this.actions[0].pool.apr + 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 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 exp3 = -amount3 * this.actions[3].pool.borrow.apr; const effecitveAmount = amount1 - amount3; const effectiveAPR = (exp1 + exp2 + exp3) / effecitveAmount; - const pool: PoolInfo = {...eligiblePools[0]}; + const pool: PoolInfo = { ...eligiblePools[0] }; pool.apr = effectiveAPR; const strategyAction: StrategyAction = { - pool: pool, + 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 - ]; + isDeposit: true, + }; + console.log( + 'getLookRepeatYieldAmount exp1', + exp1, + full_amount, + exp2, + amount2, + this.actions[2], + this.actions[1], + exp3, + amount3, + ); + return [...actions, strategyAction]; } compounder( @@ -179,7 +191,7 @@ export class DeltaNeutralMM extends IStrategy { actions: StrategyAction[], ): StrategyAction[] { const amountWeights = this.actions.reduce((a, pool) => { - const sign = (pool.isDeposit ? 1 : -1 ); + 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; @@ -187,7 +199,14 @@ export class DeltaNeutralMM extends IStrategy { const amountIn = Number(this.actions[0].amount); const baseApr = amountWeights / amountIn; const compoundingApr = (1 + baseApr / 26) ** 26 - 1; - console.log('compounder', amountIn, amountWeights, baseApr, compoundingApr, actions); + console.log( + 'compounder', + amountIn, + amountWeights, + baseApr, + compoundingApr, + actions, + ); return [ ...actions, {