assembly/core/strategies/protocols/aave-v2/payback-and-withdraw.ts

83 lines
1.9 KiB
TypeScript
Raw Normal View History

2021-08-23 23:07:53 +00:00
import tokens from "~/constant/tokens";
2021-08-25 11:13:23 +00:00
import {
defineStrategy,
defineInput,
StrategyInputType,
StrategyProtocol
} from "../../helpers";
2021-08-23 23:07:53 +00:00
export default defineStrategy({
2021-08-25 11:13:23 +00:00
protocol: StrategyProtocol.AAVE_V2,
2021-08-23 23:07:53 +00:00
name: "Payback & Withdraw",
description: "Payback debt & withdraw collateral in a single txn.",
author: "Instadapp Team",
2021-08-25 11:13:23 +00:00
details: `<p class="text-center">This strategy executes:</p>
<ul>
<li>Payback debt</li>
<li>Withdraw collateral</li>
</ul>`,
2021-08-23 23:07:53 +00:00
inputs: [
defineInput({
type: StrategyInputType.INPUT_WITH_TOKEN,
name: "Debt",
2021-08-25 11:13:23 +00:00
placeholder: ({ input }) =>
input.token ? `${input.token.symbol} to Payback` : "",
2021-08-23 23:07:53 +00:00
validate: ({ input }) => {
if (!input.token) {
return "Token is required";
}
if (input.token.balance < input.value) {
return "Your amount exceeds your maximum limit.";
}
},
2021-08-25 11:13:23 +00:00
defaults: ({ getTokenByKey }) => ({
token: getTokenByKey?.("dai")
})
2021-08-23 23:07:53 +00:00
}),
defineInput({
type: StrategyInputType.INPUT_WITH_TOKEN,
name: "Collateral",
2021-08-25 11:13:23 +00:00
placeholder: ({ input }) =>
input.token ? `${input.token.symbol} to Withdraw` : "",
defaults: ({ getTokenByKey }) => ({
token: getTokenByKey?.("eth")
})
2021-08-23 23:07:53 +00:00
})
],
2021-08-26 16:38:31 +00:00
spells: async ({ inputs, convertTokenAmountToWei }) => {
2021-08-23 23:07:53 +00:00
return [
{
connector: "aave_v2",
method: "payback",
2021-08-25 11:13:23 +00:00
args: [
inputs[0].token.address,
2021-08-26 16:38:31 +00:00
convertTokenAmountToWei(
2021-08-25 11:13:23 +00:00
inputs[0].value,
inputs[0].token.decimals
),
12,
0,
0
]
2021-08-23 23:07:53 +00:00
},
{
connector: "aave_v2",
method: "withdraw",
2021-08-25 11:13:23 +00:00
args: [
inputs[1].token.address,
2021-08-26 16:38:31 +00:00
convertTokenAmountToWei(
2021-08-25 11:13:23 +00:00
inputs[1].value,
inputs[1].token.decimals
),
0,
0
]
2021-08-23 23:07:53 +00:00
}
];
}
});