import DSA, { Spell } from "dsa-connect"; import Web3 from "web3"; import slugify from "slugify"; import { Strategy } from "./strategy"; export interface IStrategyContext { dsa: DSA; web3: Web3; inputs: IStrategyInput[]; dsaTokens?: IStrategyToken, userTokens?: IStrategyToken, } 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 type StrategyInputParameterMap = { [StrategyInputType.INPUT]: {}; [StrategyInputType.INPUT_WITH_TOKEN]: { token?: IStrategyToken; }; }; export interface IStrategyInput { type: InputType; name: string; placeholder?: ( context: IStrategyContext & { input: IStrategyInput & StrategyInputParameterMap[InputType]; } ) => string; validate?: ( context: IStrategyContext & { input: IStrategyInput & StrategyInputParameterMap[InputType]; } ) => string | void; value?: any; [key: string]: any; } export interface IStrategy { id?: string; name: string; description: string; author?: string; inputs: IStrategyInput[]; spells: (context: IStrategyContext) => Promise | Spell[]; submitText?: string; } export function defineInput( input: IStrategyInput ) { return input as IStrategyInput; } export function defineStrategy(strategy: IStrategy) { return { ...strategy, id: strategy.id ? strategy.id : slugify(strategy.name).toLowerCase() }; } export function buildStrategy(schema: DefineStrategy) { return new Strategy(schema) } export type DefineStrategy = ReturnType;