Skip to content

Commit

Permalink
Merge branch 'dev' into jt/remove-current-position-from-deps
Browse files Browse the repository at this point in the history
  • Loading branch information
zerotucks authored Aug 21, 2023
2 parents 467ab1d + af07df4 commit e4f370d
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 27 deletions.
2 changes: 1 addition & 1 deletion packages/addresses/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oasisdex/addresses",
"version": "0.0.38-alpha.2",
"version": "0.0.39",
"typings": "lib/index.d.ts",
"types": "lib/index.d.ts",
"main": "lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/deploy-configurations/configs/goerli.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ export const config: SystemConfig = {
},
ERC20PoolFactory: {
name: 'ERC20PoolFactory',
address: '0x0000000000000000000000000000000000000000',
address: '0x01Da8a85A5B525D476cA2b51e44fe7087fFafaFF',
serviceRegistryName: SERVICE_REGISTRY_NAMES.ajna.ERC20_POOL_FACTORY,
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/deploy-configurations/configs/optimism.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export const config: SystemConfig = {
},
MerkleRedeemer: {
name: 'MerkleRedeemer',
address: ADDRESS_ZERO,
address: '0x34792F2481a3e2ADAD4d0000D8D202814090eFb5',
},
DssCharter: {
name: 'DssCharter',
Expand Down
2 changes: 1 addition & 1 deletion packages/dma-common/utils/swap/calculate-fee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import BigNumber from 'bignumber.js'
export function calculateFee(amountWei: BigNumber, fee: number = DEFAULT_FEE): BigNumber {
return amountWei
.times(fee)
.div(new BigNumber(fee).plus(FEE_BASE))
.div(new BigNumber(fee).plus(new BigNumber(FEE_BASE)))
.abs()
.integerValue(BigNumber.ROUND_DOWN)
}
2 changes: 1 addition & 1 deletion packages/dma-library/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oasisdex/dma-library",
"version": "0.4.6-alpha.2",
"version": "0.4.7",
"typings": "lib/index.d.ts",
"types": "lib/index.d.ts",
"main": "lib/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,15 @@ export async function getSwapDataForCloseToCollateral({

// 4. Get Swap Data
// This is the actual swap data that will be used in the transaction.
// We're inflating the needed collateral by the fee amount
// This is for when fees is collected on the other end of the swap
const amountNeededToEnsureRemainingDebtIsRepaid = calculateNeededCollateralToPaybackDebt(
debtPrice,
debtTokenPrecision,
colPrice,
collateralTokenPrecision,
outstandingDebt,
fee.div(FEE_BASE),
slippage,
)

const swapData = await getSwapData(
collateralToken.address,
debtToken.address,
amountNeededToEnsureRemainingDebtIsRepaid,
fee.div(new BigNumber(FEE_BASE).plus(fee)),
slippage,
)

Expand All @@ -129,6 +124,15 @@ export async function getSwapDataForCloseToCollateral({
? calculateFee(amountNeededToEnsureRemainingDebtIsRepaid, fee.toNumber())
: ZERO

// 5. Get Swap Data
// The swap amount needs to be the collateral needed minus the preSwapFee
const swapData = await getSwapData(
collateralToken.address,
debtToken.address,
amountNeededToEnsureRemainingDebtIsRepaid.minus(preSwapFee),
slippage,
)

return {
swapData,
collectFeeFrom,
Expand Down
7 changes: 5 additions & 2 deletions packages/dma-library/src/types/ajna/ajna-earn-position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ export class AjnaEarnPosition implements IAjnaEarn {
public quotePrice: BigNumber,
public rewards: BigNumber,
public netValue: BigNumber,
public pnl: BigNumber,
public totalEarnings: BigNumber,
public pnl: {
withFees: BigNumber
withoutFees: BigNumber
},
public totalEarnings: { withFees: BigNumber; withoutFees: BigNumber },
) {
this.fundsLockedUntil = Date.now() + 5 * 60 * 60 * 1000 // MOCK funds locked until 5h from now
this.price = priceIndex ? priceIndexToPrice(priceIndex) : ZERO
Expand Down
45 changes: 33 additions & 12 deletions packages/dma-library/src/views/ajna/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ interface EarnData {
lps: BigNumber
priceIndex: BigNumber | null
nftID: string | null
cumulativeDeposit: BigNumber
cumulativeFees: BigNumber
cumulativeWithdraw: BigNumber
earnCumulativeFeesInQuoteToken: BigNumber
earnCumulativeQuoteTokenDeposit: BigNumber
earnCumulativeQuoteTokenWithdraw: BigNumber
}

export interface GetEarnData {
Expand Down Expand Up @@ -79,7 +79,14 @@ export async function getEarnPosition(
const rewardsManager = new ethers.Contract(rewardsManagerAddress, rewardsManagerAbi, provider)

const [pool, earnData] = await Promise.all([getPoolData(poolAddress), getEarnData(proxyAddress)])
const { cumulativeDeposit, cumulativeFees, cumulativeWithdraw, lps, nftID, priceIndex } = earnData
const {
lps,
nftID,
priceIndex,
earnCumulativeFeesInQuoteToken,
earnCumulativeQuoteTokenDeposit,
earnCumulativeQuoteTokenWithdraw,
} = earnData

const quoteTokenAmount: BigNumber =
lps.eq(ZERO) || priceIndex == null
Expand Down Expand Up @@ -109,14 +116,28 @@ export async function getEarnPosition(
: ZERO

const netValue = quoteTokenAmount.times(quotePrice)
const pnl = cumulativeWithdraw
.plus(netValue)
.minus(cumulativeFees)
.minus(cumulativeDeposit)
.div(cumulativeDeposit)
const totalEarnings = netValue
.minus(cumulativeDeposit.minus(cumulativeWithdraw).plus(cumulativeFees))
.div(quotePrice)

const pnl = {
withFees: earnCumulativeQuoteTokenWithdraw
.plus(quoteTokenAmount)
.minus(earnCumulativeFeesInQuoteToken)
.minus(earnCumulativeQuoteTokenDeposit)
.div(earnCumulativeQuoteTokenDeposit),
withoutFees: earnCumulativeQuoteTokenWithdraw
.plus(quoteTokenAmount)
.minus(earnCumulativeQuoteTokenDeposit)
.div(earnCumulativeQuoteTokenDeposit),
}
const totalEarnings = {
withFees: quoteTokenAmount.minus(
earnCumulativeQuoteTokenDeposit
.minus(earnCumulativeQuoteTokenWithdraw)
.plus(earnCumulativeFeesInQuoteToken),
),
withoutFees: quoteTokenAmount.minus(
earnCumulativeQuoteTokenDeposit.minus(earnCumulativeQuoteTokenWithdraw),
),
}

return new AjnaEarnPosition(
pool,
Expand Down

0 comments on commit e4f370d

Please sign in to comment.