mirror of
https://github.com/Instadapp/assembly.git
synced 2024-07-29 22:37:06 +00:00
wip
This commit is contained in:
parent
e87acafd6c
commit
f0f7167712
|
@ -85,7 +85,7 @@ export function useStrategy(defineStrategy: DefineStrategy) {
|
|||
}
|
||||
|
||||
strategy.setProps({
|
||||
convertTokenAmountToBigNumber: valInt,
|
||||
convertTokenAmountToWei: valInt,
|
||||
getTokenByKey,
|
||||
position
|
||||
});
|
||||
|
|
|
@ -6,13 +6,13 @@ export interface IStrategyContext {
|
|||
dsa: DSA;
|
||||
web3: Web3;
|
||||
inputs: IStrategyInput<StrategyInputType>[];
|
||||
dsadsaBalances?: { [address: string]: IStrategyToken };
|
||||
userdsaBalances?: { [address: string]: IStrategyToken };
|
||||
dsaBalances?: { [address: string]: IStrategyToken };
|
||||
userBalances?: { [address: string]: IStrategyToken };
|
||||
tokens?: { [address: string]: IStrategyToken };
|
||||
convertTokenAmountToBigNumber?: (value: any, decimals: any) => string;
|
||||
convertTokenAmountToWei?: (value: any, decimals: any) => string;
|
||||
getTokenByKey?: (key: string) => IStrategyToken;
|
||||
position?: any;
|
||||
variables?: object;
|
||||
variables?: { [key: string]: any };
|
||||
}
|
||||
|
||||
export interface IStrategyToken {
|
||||
|
@ -42,7 +42,7 @@ export interface IStrategyInput<InputType extends StrategyInputType> {
|
|||
type: InputType;
|
||||
name: string;
|
||||
|
||||
variables?: object;
|
||||
variables?: { [key: string]: any };
|
||||
|
||||
placeholder?: (
|
||||
context: IStrategyContext & {
|
||||
|
|
|
@ -34,8 +34,7 @@ export class Strategy {
|
|||
|
||||
getContext(): IStrategyContext {
|
||||
return {
|
||||
...this.context,
|
||||
...this.props,
|
||||
...this.getBaseContext(),
|
||||
inputs: this.inputs
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import BigNumber from "bignumber.js";
|
||||
import {
|
||||
defineStrategy,
|
||||
defineInput,
|
||||
|
@ -18,12 +19,46 @@ export default defineStrategy({
|
|||
|
||||
author: "Instadapp Team",
|
||||
|
||||
variables: {
|
||||
collateralTokenKey: "eth",
|
||||
debtTokenKey: "dai",
|
||||
debtRateMode: 2,
|
||||
},
|
||||
|
||||
inputs: [
|
||||
defineInput({
|
||||
type: StrategyInputType.INPUT_WITH_TOKEN,
|
||||
name: "Collateral",
|
||||
placeholder: ({ input }) =>
|
||||
input.token ? `${input.token.symbol} to Deposit` : "",
|
||||
validate: ({ input, dsaBalances }) => {
|
||||
if (!input.token) {
|
||||
return "Collateral token is required";
|
||||
}
|
||||
|
||||
if (!input.value) {
|
||||
return "Collateral amount is required";
|
||||
}
|
||||
|
||||
const collateralBalance = new BigNumber(
|
||||
dsaBalances[input.token.address]?.balance
|
||||
);
|
||||
|
||||
if (new BigNumber(collateralBalance).lt(input.value)) {
|
||||
const collateralBalanceFormatted = collateralBalance.toFixed(2);
|
||||
return `Your amount exceeds your maximum limit of ${collateralBalanceFormatted} ${input.token.symbol}`;
|
||||
}
|
||||
},
|
||||
defaults: ({ getTokenByKey, variables }) => ({
|
||||
token: getTokenByKey?.(variables.collateralTokenKey)
|
||||
})
|
||||
}),
|
||||
|
||||
defineInput({
|
||||
type: StrategyInputType.INPUT_WITH_TOKEN,
|
||||
name: "Debt",
|
||||
placeholder: ({ input }) =>
|
||||
input.token ? `${input.token.symbol} to Payback` : "",
|
||||
input.token ? `${input.token.symbol} to Borrow` : "",
|
||||
validate: ({ input }) => {
|
||||
if (!input.token) {
|
||||
return "Debt token is required";
|
||||
|
@ -32,46 +67,21 @@ export default defineStrategy({
|
|||
if (!input.value) {
|
||||
return "Debt amount is required";
|
||||
}
|
||||
|
||||
// if (input.token.balance < input.value) {
|
||||
// return "Your amount exceeds your maximum limit.";
|
||||
// }
|
||||
},
|
||||
defaults: ({ getTokenByKey }) => ({
|
||||
token: getTokenByKey?.("eth")
|
||||
})
|
||||
}),
|
||||
defineInput({
|
||||
type: StrategyInputType.INPUT_WITH_TOKEN,
|
||||
name: "Collateral",
|
||||
placeholder: ({ input }) =>
|
||||
input.token ? `${input.token.symbol} to Withdraw` : "",
|
||||
validate: ({ input }) => {
|
||||
if (!input.token) {
|
||||
return "Collateral token is required";
|
||||
}
|
||||
|
||||
if (!input.value) {
|
||||
return "Collateral amount is required";
|
||||
}
|
||||
},
|
||||
defaults: ({ getTokenByKey }) => ({
|
||||
token: getTokenByKey?.("dai")
|
||||
defaults: ({ getTokenByKey, variables }) => ({
|
||||
token: getTokenByKey?.(variables.debtTokenKey)
|
||||
})
|
||||
})
|
||||
],
|
||||
|
||||
spells: async ({ inputs, convertTokenAmountToBigNumber }) => {
|
||||
spells: async ({ inputs, convertTokenAmountToWei, variables }) => {
|
||||
return [
|
||||
{
|
||||
connector: "aave_v2",
|
||||
method: "deposit",
|
||||
args: [
|
||||
inputs[0].token.address,
|
||||
convertTokenAmountToBigNumber(
|
||||
inputs[0].value,
|
||||
inputs[0].token.decimals
|
||||
),
|
||||
convertTokenAmountToWei(inputs[0].value, inputs[0].token.decimals),
|
||||
0,
|
||||
0
|
||||
]
|
||||
|
@ -81,11 +91,8 @@ export default defineStrategy({
|
|||
method: "borrow",
|
||||
args: [
|
||||
inputs[1].token.address,
|
||||
convertTokenAmountToBigNumber(
|
||||
inputs[1].value,
|
||||
inputs[1].token.decimals
|
||||
),
|
||||
2,
|
||||
convertTokenAmountToWei(inputs[1].value, inputs[1].token.decimals),
|
||||
variables.debtRateMode,
|
||||
0,
|
||||
0
|
||||
]
|
||||
|
|
|
@ -48,14 +48,14 @@ export default defineStrategy({
|
|||
})
|
||||
],
|
||||
|
||||
spells: async ({ inputs, convertTokenAmountToBigNumber }) => {
|
||||
spells: async ({ inputs, convertTokenAmountToWei }) => {
|
||||
return [
|
||||
{
|
||||
connector: "aave_v2",
|
||||
method: "payback",
|
||||
args: [
|
||||
inputs[0].token.address,
|
||||
convertTokenAmountToBigNumber(
|
||||
convertTokenAmountToWei(
|
||||
inputs[0].value,
|
||||
inputs[0].token.decimals
|
||||
),
|
||||
|
@ -69,7 +69,7 @@ export default defineStrategy({
|
|||
method: "withdraw",
|
||||
args: [
|
||||
inputs[1].token.address,
|
||||
convertTokenAmountToBigNumber(
|
||||
convertTokenAmountToWei(
|
||||
inputs[1].value,
|
||||
inputs[1].token.decimals
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue
Block a user