mirror of
https://github.com/Instadapp/assembly.git
synced 2024-07-29 22:37:06 +00:00
wip
This commit is contained in:
parent
27cca10cc5
commit
4951b6733b
49
core/strategies/helpers/strategy.ts
Normal file
49
core/strategies/helpers/strategy.ts
Normal 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
5
core/strategies/index.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import AaveV2 from "./protocols/aave-v2"
|
||||
|
||||
export const strategies = {
|
||||
aaveV2 : AaveV2,
|
||||
}
|
49
core/strategies/protocols/aave-v2/deposit-and-borrow.ts
Normal file
49
core/strategies/protocols/aave-v2/deposit-and-borrow.ts
Normal 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;
|
||||
}
|
||||
});
|
6
core/strategies/protocols/aave-v2/index.ts
Normal file
6
core/strategies/protocols/aave-v2/index.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
import depositAndBorrow from "./deposit-and-borrow"
|
||||
|
||||
export default [
|
||||
depositAndBorrow
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user