-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from OasisDEX/jt/sc-14516/sc-spark-add-missing…
…-operations-and-strategies ✨ feat(withdraw spark ops): spark add missing operations
- Loading branch information
Showing
8 changed files
with
201 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/deploy-configurations/operation-definitions/spark/borrow/withdraw-to-debt.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { loadContractNames, OPERATION_NAMES } from '@deploy-configurations/constants' | ||
import { Network } from '@deploy-configurations/types/network' | ||
import { getActionHash } from '@deploy-configurations/utils/action-hash' | ||
|
||
export function getSparkWithdrawToDebtOperationDefinition(network: Network) { | ||
const SERVICE_REGISTRY_NAMES = loadContractNames(network) | ||
|
||
return { | ||
name: OPERATION_NAMES.spark.WITHDRAW_TO_DEBT, | ||
actions: [ | ||
{ | ||
hash: getActionHash(SERVICE_REGISTRY_NAMES.spark.WITHDRAW), | ||
optional: false, | ||
}, | ||
{ | ||
hash: getActionHash(SERVICE_REGISTRY_NAMES.common.COLLECT_FEE), | ||
optional: false, | ||
}, | ||
{ | ||
hash: getActionHash(SERVICE_REGISTRY_NAMES.common.SWAP), | ||
optional: false, | ||
}, | ||
{ | ||
hash: getActionHash(SERVICE_REGISTRY_NAMES.common.UNWRAP_ETH), | ||
optional: false, | ||
}, | ||
{ | ||
hash: getActionHash(SERVICE_REGISTRY_NAMES.common.RETURN_FUNDS), | ||
optional: false, | ||
}, | ||
], | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
packages/deploy-configurations/operation-definitions/spark/borrow/withdraw.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
import { loadContractNames, OPERATION_NAMES } from '@deploy-configurations/constants' | ||
import { Network } from '@deploy-configurations/types/network' | ||
import { getActionHash } from '@deploy-configurations/utils/action-hash' | ||
|
||
export function getSparkWithdrawOperationDefinition(network: Network) { | ||
const SERVICE_REGISTRY_NAMES = loadContractNames(network) | ||
|
||
return { | ||
name: OPERATION_NAMES.spark.WITHDRAW, | ||
actions: [ | ||
{ | ||
hash: getActionHash(SERVICE_REGISTRY_NAMES.spark.WITHDRAW), | ||
optional: false, | ||
}, | ||
{ | ||
hash: getActionHash(SERVICE_REGISTRY_NAMES.common.COLLECT_FEE), | ||
optional: false, | ||
}, | ||
{ | ||
hash: getActionHash(SERVICE_REGISTRY_NAMES.common.UNWRAP_ETH), | ||
optional: false, | ||
}, | ||
{ | ||
hash: getActionHash(SERVICE_REGISTRY_NAMES.common.RETURN_FUNDS), | ||
optional: false, | ||
}, | ||
], | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/dma-library/src/operations/spark/borrow/withdraw-to-debt.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { getSparkWithdrawToDebtOperationDefinition } from '@deploy-configurations/operation-definitions' | ||
import { Network } from '@deploy-configurations/types/network' | ||
import { MAX_UINT, ZERO } from '@dma-common/constants' | ||
import { actions } from '@dma-library/actions' | ||
import { AaveLikeStrategyAddresses } from '@dma-library/operations/aave-like' | ||
import { IOperation } from '@dma-library/types' | ||
import BigNumber from 'bignumber.js' | ||
|
||
type WithdrawToDebtArgs = { | ||
withdrawAmount: BigNumber | ||
receiveAtLeast: BigNumber | ||
swapData: string | ||
collateralTokenAddress: string | ||
debtTokenAddress: string | ||
debtIsEth: boolean | ||
proxy: string | ||
addresses: AaveLikeStrategyAddresses | ||
network: Network | ||
} | ||
|
||
export type SparkWithdrawToDebtOperation = (args: WithdrawToDebtArgs) => Promise<IOperation> | ||
|
||
export const withdrawToDebt: SparkWithdrawToDebtOperation = async args => { | ||
const { network } = args | ||
|
||
const withdrawCollateralFromSpark = actions.spark.withdraw(args.network, { | ||
asset: args.collateralTokenAddress, | ||
amount: args.withdrawAmount, | ||
to: args.proxy, | ||
}) | ||
|
||
const collectFeeAfterWithdraw = actions.common.collectFee( | ||
args.network, | ||
{ | ||
asset: args.collateralTokenAddress, | ||
}, | ||
[1], | ||
) | ||
|
||
const swapCollateralTokensForDebtTokens = actions.common.swap(network, { | ||
fromAsset: args.collateralTokenAddress, | ||
toAsset: args.debtTokenAddress, | ||
amount: args.withdrawAmount, | ||
receiveAtLeast: args.receiveAtLeast, | ||
fee: ZERO.toNumber(), | ||
withData: args.swapData, | ||
// Not relevant here | ||
collectFeeInFromToken: true, | ||
}) | ||
|
||
const unwrapEth = actions.common.unwrapEth(network, { | ||
amount: new BigNumber(MAX_UINT), | ||
}) | ||
|
||
const returnFunds = actions.common.returnFunds(network, { | ||
asset: args.debtIsEth ? args.addresses.tokens.ETH : args.debtTokenAddress, | ||
}) | ||
|
||
const calls = [ | ||
withdrawCollateralFromSpark, | ||
collectFeeAfterWithdraw, | ||
swapCollateralTokensForDebtTokens, | ||
unwrapEth, | ||
returnFunds, | ||
] | ||
|
||
return { | ||
calls: calls, | ||
operationName: getSparkWithdrawToDebtOperationDefinition(args.network).name, | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
packages/dma-library/src/operations/spark/borrow/withdraw.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { getSparkWithdrawOperationDefinition } from '@deploy-configurations/operation-definitions' | ||
import { Network } from '@deploy-configurations/types/network' | ||
import { MAX_UINT } from '@dma-common/constants' | ||
import { actions } from '@dma-library/actions' | ||
import { AaveLikeStrategyAddresses } from '@dma-library/operations/aave-like' | ||
import { IOperation } from '@dma-library/types' | ||
import BigNumber from 'bignumber.js' | ||
|
||
type WithdrawArgs = { | ||
withdrawAmount: BigNumber | ||
collateralTokenAddress: string | ||
collateralIsEth: boolean | ||
proxy: string | ||
addresses: AaveLikeStrategyAddresses | ||
network: Network | ||
} | ||
|
||
export type SparkWithdrawOperation = (args: WithdrawArgs) => Promise<IOperation> | ||
|
||
export const withdraw: SparkWithdrawOperation = async args => { | ||
const { network } = args | ||
|
||
const withdrawCollateralFromSpark = actions.spark.withdraw(args.network, { | ||
asset: args.collateralTokenAddress, | ||
amount: args.withdrawAmount, | ||
to: args.proxy, | ||
}) | ||
|
||
const collectFeeAfterWithdraw = actions.common.collectFee( | ||
args.network, | ||
{ | ||
asset: args.collateralTokenAddress, | ||
}, | ||
[1], | ||
) | ||
|
||
const unwrapEth = actions.common.unwrapEth(network, { | ||
amount: new BigNumber(MAX_UINT), | ||
}) | ||
|
||
const returnFunds = actions.common.returnFunds(network, { | ||
asset: args.collateralIsEth ? args.addresses.tokens.ETH : args.collateralTokenAddress, | ||
}) | ||
|
||
const calls = [withdrawCollateralFromSpark, collectFeeAfterWithdraw, unwrapEth, returnFunds] | ||
|
||
return { | ||
calls: calls, | ||
operationName: getSparkWithdrawOperationDefinition(args.network).name, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters