From 59bc5369db3cd8e48dc85ba17503af9722646a10 Mon Sep 17 00:00:00 2001 From: Georges KABBOUCHI Date: Sun, 22 Aug 2021 16:49:31 +0300 Subject: [PATCH] wip --- .../context/strategy/SidebarStrategy.vue | 54 +++-- core/strategies/helpers/strategy.ts | 67 ++++-- core/strategies/index.ts | 4 +- pages/aave-v2.vue | 45 +++- pages/mainnet/aave-v2.vue | 216 ------------------ 5 files changed, 128 insertions(+), 258 deletions(-) delete mode 100644 pages/mainnet/aave-v2.vue diff --git a/components/sidebar/context/strategy/SidebarStrategy.vue b/components/sidebar/context/strategy/SidebarStrategy.vue index cc9ac52..f21bc7d 100644 --- a/components/sidebar/context/strategy/SidebarStrategy.vue +++ b/components/sidebar/context/strategy/SidebarStrategy.vue @@ -6,46 +6,62 @@
{{ $props }}
+
{{ selectedStrategy }}
+ +
- \ No newline at end of file diff --git a/core/strategies/helpers/strategy.ts b/core/strategies/helpers/strategy.ts index b1f94e1..b9043ba 100644 --- a/core/strategies/helpers/strategy.ts +++ b/core/strategies/helpers/strategy.ts @@ -1,6 +1,6 @@ import DSA from "dsa-connect"; import Web3 from "web3"; -import slugify from "slugify" +import slugify from "slugify"; export interface IStrategyContext { dsa: typeof DSA; web3: Web3; @@ -8,13 +8,13 @@ export interface IStrategyContext { } export interface IStrategyToken { - address: string - key: string - symbol: string - balance: string + address: string; + key: string; + symbol: string; + balance: string; - supply: string - borrow: string + supply: string; + borrow: string; } export enum StrategyInputType { @@ -35,7 +35,9 @@ export interface IStrategyInput { placeholder: | string | ((context: IStrategyContext & { input: IStrategyInput }) => string); - validate?: ((context: IStrategyContext & { input: IStrategyInput }) => boolean|string); + validate?: ( + context: IStrategyContext & { input: IStrategyInput } + ) => boolean | string; // If type is "input-with-token", this is the token token?: IStrategyToken; value?: any; @@ -56,11 +58,50 @@ export interface IStrategy { submitText?: string; } -export function defineStrategy(strategy: IStrategy): IStrategy { +export function defineStrategy(strategy: IStrategy) { + return { + ...strategy, + id: strategy.id ? strategy.id : slugify(strategy.name).toLowerCase(), + inputs: strategy.inputs.map(input => ({ + ...input, + value: null, + onInput: (val: any) => { + input.value = val; + } + })), + submit: async (context: Pick) => { + await this.validate({ + ...context, + inputs: strategy.inputs + }); - if(! strategy.id){ - strategy.id = slugify(strategy.name).toLowerCase(); - } + const spells = strategy.spells({ + ...context, + inputs: strategy.inputs + }); - return strategy; + return await context.dsa.cast({ + spells, + onReceipt: this.onReceipt + }); + }, + validate: async (context: IStrategyContext) => { + for (const input of this.inputs) { + const result = await input.validate({ + ...context, + inputs: strategy.inputs, + input + }); + + if (result !== true) { + throw new Error(result || "Error has occurred"); + } + } + }, + onReceipt: (txHash: string, txReceipt: any) => { + // do something + } + }; } + +export type DefineStrategy = ReturnType; diff --git a/core/strategies/index.ts b/core/strategies/index.ts index 03f0341..6fc2f7e 100644 --- a/core/strategies/index.ts +++ b/core/strategies/index.ts @@ -2,4 +2,6 @@ import AaveV2 from "./protocols/aave-v2" export const protocolStrategies = { aaveV2 : AaveV2, -} \ No newline at end of file +} + +export * from "./helpers/strategy" \ No newline at end of file diff --git a/pages/aave-v2.vue b/pages/aave-v2.vue index e1c64c0..3b00a21 100644 --- a/pages/aave-v2.vue +++ b/pages/aave-v2.vue @@ -10,18 +10,43 @@ -
-
+
+
- +
+ +
+

Aave v2

-

Aave v2

+ + + Strategies + + + + +
@@ -166,12 +191,14 @@ import { useStatus } from "~/composables/useStatus"; import { useBigNumber } from "~/composables/useBigNumber"; import CardAave from "~/components/protocols/CardAave.vue"; import AaveIcon from "~/assets/icons/aave.svg?inline"; +import ButtonCTAOutlined from "~/components/common/input/ButtonCTAOutlined.vue"; export default defineComponent({ components: { BackIcon, CardAave, - AaveIcon + AaveIcon, + ButtonCTAOutlined, }, setup() { const { diff --git a/pages/mainnet/aave-v2.vue b/pages/mainnet/aave-v2.vue deleted file mode 100644 index 46501dc..0000000 --- a/pages/mainnet/aave-v2.vue +++ /dev/null @@ -1,216 +0,0 @@ - - -