assembly/core/strategies/helpers/strategy.ts

67 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-08-22 11:27:02 +00:00
import DSA from "dsa-connect";
import Web3 from "web3";
2021-08-22 12:54:23 +00:00
import slugify from "slugify"
2021-08-22 11:27:02 +00:00
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"
}
2021-08-22 12:54:23 +00:00
// type InputTypes = {
// [StrategyInputType.INPUT] : {
// token?: IStrategyToken;
// value?: any;
// };
// }
2021-08-22 11:27:02 +00:00
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;
2021-08-22 12:54:23 +00:00
[key: string]: any;
2021-08-22 11:27:02 +00:00
}
export interface IStrategy {
2021-08-22 12:54:23 +00:00
id?: string;
2021-08-22 11:27:02 +00:00
name: string;
description: string;
author?: string;
inputs: IStrategyInput[];
spells: (context: IStrategyContext) => any;
2021-08-22 12:54:23 +00:00
submitText?: string;
2021-08-22 11:27:02 +00:00
}
export function defineStrategy(strategy: IStrategy): IStrategy {
2021-08-22 12:54:23 +00:00
if(! strategy.id){
strategy.id = slugify(strategy.name).toLowerCase();
}
2021-08-22 11:27:02 +00:00
return strategy;
}