This commit is contained in:
Georges KABBOUCHI 2021-08-22 14:27:02 +03:00
parent 27cca10cc5
commit 4951b6733b
4 changed files with 109 additions and 0 deletions

View File

@ -0,0 +1,49 @@
import DSA from "dsa-connect";
import Web3 from "web3";
export interface IStrategyContext {
dsa: typeof DSA;
web3: Web3;
inputs: IStrategyInput[];
}
export interface IStrategyToken {
address: string
key: string
symbol: string
balance: string
supply: string
borrow: string
}
export enum StrategyInputType {
INPUT = "input",
INPUT_WITH_TOKEN = "input-with-token"
}
export interface IStrategyInput {
type: StrategyInputType;
name: string;
placeholder:
| string
| ((context: IStrategyContext & { input: IStrategyInput }) => string);
validate?: ((context: IStrategyContext & { input: IStrategyInput }) => boolean|string);
// If type is "input-with-token", this is the token
token?: IStrategyToken;
value?: any;
}
export interface IStrategy {
name: string;
description: string;
author?: string;
inputs: IStrategyInput[];
spells: (context: IStrategyContext) => any;
}
export function defineStrategy(strategy: IStrategy): IStrategy {
return strategy;
}

5
core/strategies/index.ts Normal file
View File

@ -0,0 +1,5 @@
import AaveV2 from "./protocols/aave-v2"
export const strategies = {
aaveV2 : AaveV2,
}

View File

@ -0,0 +1,49 @@
import { defineStrategy, StrategyInputType } from "../../helpers/strategy";
export default defineStrategy({
name: "Deposit & Borrow",
description: "Deposit collateral & borrow asset in a single txn.",
author: "Instadapp Team",
inputs: [
{
type: StrategyInputType.INPUT_WITH_TOKEN,
name: "Debt",
placeholder: ({ input }) => `${input.token.symbol} to Payback`,
validate: ({ input }) => {
if (!input.token) {
return "Token is required";
}
if (input.token.balance < input.value) {
return "Your amount exceeds your maximum limit.";
}
return true;
}
},
{
type: StrategyInputType.INPUT_WITH_TOKEN,
name: "Collateral",
placeholder: ({ input }) => `${input.token.symbol} to Withdraw`
}
],
spells: async ({ dsa, inputs }) => {
const spells = dsa.Spells();
spells.add({
connector: "aave_v2",
method: "deposit",
args: [inputs[0].token.address, inputs[0].value, 0, 0]
});
spells.add({
connector: "aave_v2",
method: "borrow",
args: [inputs[1].token.address, inputs[1].value, 0, 0, 0]
});
return spells;
}
});

View File

@ -0,0 +1,6 @@
import depositAndBorrow from "./deposit-and-borrow"
export default [
depositAndBorrow
]