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

🔨fix - eth/weth mismatch #26

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.5.21-dma-v2-workers.29-auto-withdraw-to-ltv",
"version": "0.5.21-dma-v2-workers.31-auto-withdraw-to-ltv",
"typings": "lib/index.d.ts",
"types": "lib/index.d.ts",
"main": "lib/index.js",
Expand Down
15 changes: 12 additions & 3 deletions packages/dma-library/src/operations/aave/auto/withdraw-to-debt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,30 @@ export const withdrawToDebt: AaveV3WithdrawToDebtOperation = async args => {
const { network } = args

const withdrawCollateralFromAAVE = actions.aave.v3.aaveV3Withdraw(args.network, {
asset: args.collateralTokenAddress,
asset:
args.collateralTokenAddress.toLowerCase() == args.addresses.tokens.ETH.toLowerCase()
? args.addresses.tokens.WETH
: args.collateralTokenAddress,
amount: args.withdrawAmount,
to: args.proxy,
})

const collectFeeAfterWithdraw = actions.common.collectFee(
args.network,
{
asset: args.collateralTokenAddress,
asset:
args.collateralTokenAddress.toLowerCase() == args.addresses.tokens.ETH.toLowerCase()
? args.addresses.tokens.WETH
: args.collateralTokenAddress,
},
[1],
)

const swapCollateralTokensForDebtTokens = actions.common.swap(network, {
fromAsset: args.collateralTokenAddress,
fromAsset:
args.collateralTokenAddress.toLowerCase() == args.addresses.tokens.ETH.toLowerCase()
? args.addresses.tokens.WETH
: args.collateralTokenAddress,
toAsset: args.debtIsEth ? args.addresses.tokens.WETH : args.debtTokenAddress,
amount: args.swapAmount,
receiveAtLeast: args.receiveAtLeast,
Expand Down
10 changes: 8 additions & 2 deletions packages/dma-library/src/operations/aave/auto/withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@ export const withdraw: AaveV3WithdrawOperation = async args => {
const { network } = args

const withdrawCollateralFromAAVE = actions.aave.v3.aaveV3Withdraw(args.network, {
asset: args.collateralTokenAddress,
asset:
args.collateralTokenAddress.toLowerCase() == args.addresses.tokens.ETH.toLowerCase()
? args.addresses.tokens.WETH
: args.collateralTokenAddress,
amount: args.withdrawAmount,
to: args.proxy,
})

const collectFeeAfterWithdraw = actions.common.collectFee(
args.network,
{
asset: args.collateralTokenAddress,
asset:
args.collateralTokenAddress.toLowerCase() == args.addresses.tokens.ETH.toLowerCase()
? args.addresses.tokens.WETH
: args.collateralTokenAddress,
},
[1],
)
Expand Down
15 changes: 12 additions & 3 deletions packages/dma-library/src/operations/spark/auto/withdraw-to-debt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,30 @@ export const withdrawToDebt: SparkWithdrawToDebtOperation = async args => {
const { network } = args

const withdrawCollateralFromSpark = actions.spark.withdraw(args.network, {
asset: args.collateralTokenAddress,
asset:
args.collateralTokenAddress.toLowerCase() == args.addresses.tokens.ETH.toLowerCase()
? args.addresses.tokens.WETH
: args.collateralTokenAddress,
amount: args.withdrawAmount,
to: args.proxy,
})

const collectFeeAfterWithdraw = actions.common.collectFee(
args.network,
{
asset: args.collateralTokenAddress,
asset:
args.collateralTokenAddress.toLowerCase() == args.addresses.tokens.ETH.toLowerCase()
? args.addresses.tokens.WETH
: args.collateralTokenAddress,
},
[1],
)

const swapCollateralTokensForDebtTokens = actions.common.swap(network, {
fromAsset: args.collateralTokenAddress,
fromAsset:
args.collateralTokenAddress.toLowerCase() == args.addresses.tokens.ETH.toLowerCase()
? args.addresses.tokens.WETH
: args.collateralTokenAddress,
toAsset: args.debtIsEth ? args.addresses.tokens.WETH : args.debtTokenAddress,
amount: args.withdrawAmount,
receiveAtLeast: args.receiveAtLeast,
Expand Down
10 changes: 8 additions & 2 deletions packages/dma-library/src/operations/spark/auto/withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@ export const withdraw: SparkWithdrawOperation = async args => {
const { network } = args

const withdrawCollateralFromSpark = actions.spark.withdraw(args.network, {
asset: args.collateralTokenAddress,
asset:
args.collateralTokenAddress.toLowerCase() == args.addresses.tokens.ETH.toLowerCase()
? args.addresses.tokens.WETH
: args.collateralTokenAddress,
amount: args.withdrawAmount,
to: args.proxy,
})

const collectFeeAfterWithdraw = actions.common.collectFee(
args.network,
{
asset: args.collateralTokenAddress,
asset:
args.collateralTokenAddress.toLowerCase() == args.addresses.tokens.ETH.toLowerCase()
? args.addresses.tokens.WETH
: args.collateralTokenAddress,
},
[1],
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ONE, ZERO } from "@dma-common/constants";
import { ZERO } from '@dma-common/constants'
import { withdraw as withdrawOp } from '@dma-library/operations/aave/auto/withdraw'
import { withdrawToDebt } from '@dma-library/operations/aave/auto/withdraw-to-debt'
import { getAaveTokenAddress } from '@dma-library/strategies/aave/common'
Expand Down Expand Up @@ -47,7 +47,7 @@ export const withdraw: AaveV3WithdrawToLTV = async (args, dependencies) => {
if (args.shouldWithdrawToDebt) {
const FEE = new BigNumber(20)
const FEE_BASIS = new BigNumber(10000)
const feeAmount = amountToWithdraw.times(FEE.div(FEE_BASIS)).integerValue(BigNumber.ROUND_FLOOR);
const feeAmount = amountToWithdraw.times(FEE.div(FEE_BASIS)).integerValue(BigNumber.ROUND_FLOOR)
const amountToSwap = amountToWithdraw.minus(feeAmount)
const { swapData } = await getSwapDataHelper<typeof dependencies.addresses, AaveLikeTokens>({
args: {
Expand Down Expand Up @@ -76,7 +76,7 @@ export const withdraw: AaveV3WithdrawToLTV = async (args, dependencies) => {
swapAmount: amountToSwap,
swapData: `${swapData.exchangeCalldata}`,
debtTokenAddress: getTokenAddressFromDependencies(dependencies, debtTokenSymbol),
debtIsEth: debtTokenSymbol === 'ETH',
debtIsEth: debtTokenSymbol === 'WETH' || debtTokenSymbol === 'ETH',
proxy: dependencies.proxy,
addresses: dependencies.addresses,
network: dependencies.network,
Expand All @@ -97,7 +97,7 @@ export const withdraw: AaveV3WithdrawToLTV = async (args, dependencies) => {
dependencies,
currentPosition.collateral.symbol,
),
collateralIsEth: collateralTokenSymbol === 'ETH',
collateralIsEth: collateralTokenSymbol === 'ETH' || collateralTokenSymbol === 'WETH',
proxy: dependencies.proxy,
addresses: dependencies.addresses,
network: dependencies.network,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ZERO } from "@dma-common/constants";
import { ZERO } from '@dma-common/constants'
import { withdraw as withdrawOp } from '@dma-library/operations/spark/auto/withdraw'
import { withdrawToDebt } from '@dma-library/operations/spark/auto/withdraw-to-debt'
import { getAaveTokenAddress } from '@dma-library/strategies/aave/common'
Expand Down Expand Up @@ -45,7 +45,7 @@ export const withdraw: SparkWithdrawToLTV = async (args, dependencies) => {
if (args.shouldWithdrawToDebt) {
const FEE = new BigNumber(20)
const FEE_BASIS = new BigNumber(10000)
const feeAmount = amountToWithdraw.times(FEE.div(FEE_BASIS)).integerValue(BigNumber.ROUND_FLOOR);
const feeAmount = amountToWithdraw.times(FEE.div(FEE_BASIS)).integerValue(BigNumber.ROUND_FLOOR)
const amountToSwap = amountToWithdraw.minus(feeAmount)
const { swapData } = await getSwapDataHelper<typeof dependencies.addresses, AaveLikeTokens>({
args: {
Expand Down Expand Up @@ -74,7 +74,7 @@ export const withdraw: SparkWithdrawToLTV = async (args, dependencies) => {
swapAmount: amountToSwap,
swapData: `${swapData.exchangeCalldata}`,
debtTokenAddress: getTokenAddressFromDependencies(dependencies, debtTokenSymbol),
debtIsEth: debtTokenSymbol === 'ETH',
debtIsEth: debtTokenSymbol === 'WETH' || debtTokenSymbol === 'ETH',
proxy: dependencies.proxy,
addresses: dependencies.addresses,
network: dependencies.network,
Expand All @@ -95,7 +95,7 @@ export const withdraw: SparkWithdrawToLTV = async (args, dependencies) => {
dependencies,
currentPosition.collateral.symbol,
),
collateralIsEth: collateralTokenSymbol === 'ETH',
collateralIsEth: collateralTokenSymbol === 'WETH' || collateralTokenSymbol === 'ETH',
proxy: dependencies.proxy,
addresses: dependencies.addresses,
network: dependencies.network,
Expand Down Expand Up @@ -141,10 +141,7 @@ function determineWithdrawalAmount(
return amountToWithdraw
}

function getTokenAddressFromDependencies(
deps: SparkWithdrawDependencies,
symbol: string,
) {
function getTokenAddressFromDependencies(deps: SparkWithdrawDependencies, symbol: string) {
const address = deps.addresses.tokens[symbol]

if (!address) {
Expand Down
Loading