mirror of
https://github.com/Instadapp/assembly.git
synced 2024-07-29 22:37:06 +00:00
rename input to component in strategy
This commit is contained in:
parent
ce95773f6c
commit
60b01e884a
|
@ -24,38 +24,38 @@
|
||||||
<div class="mx-auto h-full" style="max-width: 296px">
|
<div class="mx-auto h-full" style="max-width: 296px">
|
||||||
<div class="space-y-4 py-9 h-full flex flex-col">
|
<div class="space-y-4 py-9 h-full flex flex-col">
|
||||||
<div class="flex-1">
|
<div class="flex-1">
|
||||||
<div v-for="(input, index) in inputs" :key="index" class="mb-6">
|
<div v-for="(component, index) in components" :key="index" class="mb-6">
|
||||||
<input-amount
|
<input-amount
|
||||||
v-if="input.type === 'input-with-token'"
|
v-if="component.type === 'input-with-token'"
|
||||||
:key="index"
|
:key="index"
|
||||||
:value="input.value"
|
:value="component.value"
|
||||||
:token-key="input.token ? input.token.key : 'eth'"
|
:token-key="component.token ? component.token.key : 'eth'"
|
||||||
:token-keys="
|
:token-keys="
|
||||||
input.tokenKeys
|
component.tokenKeys
|
||||||
? input.tokenKeys
|
? component.tokenKeys
|
||||||
: activeStrategy.getContext()['tokenKeys']
|
: activeStrategy.getContext()['tokenKeys']
|
||||||
"
|
"
|
||||||
:error="input.error"
|
:error="component.error"
|
||||||
:placeholder="input.placeholder()"
|
:placeholder="component.placeholder()"
|
||||||
@input="$event => input.onInput($event)"
|
@input="$event => component.onInput($event)"
|
||||||
@tokenKeyChanged="
|
@tokenKeyChanged="
|
||||||
tokenKey => {
|
tokenKey => {
|
||||||
input.onCustomInput({
|
component.onCustomInput({
|
||||||
token: getTokenByKey(tokenKey)
|
token: getTokenByKey(tokenKey)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
/>
|
/>
|
||||||
<SidebarContextHeading
|
<SidebarContextHeading
|
||||||
v-else-if="input.type === 'heading'"
|
v-else-if="component.type === 'heading'"
|
||||||
:key="index"
|
:key="index"
|
||||||
>
|
>
|
||||||
{{ input.name }}
|
{{ component.name }}
|
||||||
</SidebarContextHeading>
|
</SidebarContextHeading>
|
||||||
|
|
||||||
<div v-else-if="input.type === 'value'" :key="index">
|
<div v-else-if="component.type === 'value'" :key="index">
|
||||||
<value-display :label="input.name">
|
<value-display :label="component.name">
|
||||||
{{ input.value }}
|
{{ component.value }}
|
||||||
</value-display>
|
</value-display>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -112,7 +112,7 @@ export default defineComponent({
|
||||||
protocolStrategies[props.protocol] || [];
|
protocolStrategies[props.protocol] || [];
|
||||||
|
|
||||||
const {
|
const {
|
||||||
inputs,
|
components,
|
||||||
submit,
|
submit,
|
||||||
error,
|
error,
|
||||||
strategy: activeStrategy,
|
strategy: activeStrategy,
|
||||||
|
@ -122,7 +122,7 @@ export default defineComponent({
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
inputs,
|
components,
|
||||||
error,
|
error,
|
||||||
submit,
|
submit,
|
||||||
activeStrategy,
|
activeStrategy,
|
||||||
|
|
|
@ -42,7 +42,7 @@ export function useStrategy(defineStrategy: DefineStrategy) {
|
||||||
} = useNotification();
|
} = useNotification();
|
||||||
|
|
||||||
const strategy = buildStrategy(defineStrategy);
|
const strategy = buildStrategy(defineStrategy);
|
||||||
const inputs = ref(strategy.inputs);
|
const components = ref(strategy.components);
|
||||||
const error = ref("");
|
const error = ref("");
|
||||||
const pending = ref(false);
|
const pending = ref(false);
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ export function useStrategy(defineStrategy: DefineStrategy) {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
strategy,
|
strategy,
|
||||||
inputs,
|
components,
|
||||||
submit,
|
submit,
|
||||||
error,
|
error,
|
||||||
pending
|
pending
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { useFormatting } from "~/composables/useFormatting";
|
||||||
export interface IStrategyContext {
|
export interface IStrategyContext {
|
||||||
dsa: DSA;
|
dsa: DSA;
|
||||||
web3: Web3;
|
web3: Web3;
|
||||||
inputs: IStrategyInput<StrategyInputType>[];
|
components: IStrategyComponent<StrategyComponentType>[];
|
||||||
|
|
||||||
// TODO: add types in useStrategy.ts
|
// TODO: add types in useStrategy.ts
|
||||||
dsaBalances?: { [address: string]: IStrategyToken };
|
dsaBalances?: { [address: string]: IStrategyToken };
|
||||||
|
@ -35,7 +35,7 @@ export interface IStrategyToken {
|
||||||
// borrow: string;
|
// borrow: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum StrategyInputType {
|
export enum StrategyComponentType {
|
||||||
// INPUT = "input",
|
// INPUT = "input",
|
||||||
INPUT_WITH_TOKEN = "input-with-token",
|
INPUT_WITH_TOKEN = "input-with-token",
|
||||||
|
|
||||||
|
@ -43,38 +43,38 @@ export enum StrategyInputType {
|
||||||
VALUE = "value"
|
VALUE = "value"
|
||||||
}
|
}
|
||||||
|
|
||||||
export type StrategyInputParameterMap = {
|
export type StrategyComponentParameterMap = {
|
||||||
// [StrategyInputType.INPUT]: {};
|
// [StrategyInputType.INPUT]: {};
|
||||||
|
|
||||||
[StrategyInputType.INPUT_WITH_TOKEN]: {
|
[StrategyComponentType.INPUT_WITH_TOKEN]: {
|
||||||
token?: IStrategyToken;
|
token?: IStrategyToken;
|
||||||
};
|
};
|
||||||
|
|
||||||
[StrategyInputType.HEADING]: {};
|
[StrategyComponentType.HEADING]: {};
|
||||||
[StrategyInputType.VALUE]: {};
|
[StrategyComponentType.VALUE]: {};
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface IStrategyInput<InputType extends StrategyInputType> {
|
export interface IStrategyComponent<ComponentType extends StrategyComponentType> {
|
||||||
type: InputType;
|
type: ComponentType;
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
variables?: { [key: string]: any };
|
variables?: { [key: string]: any };
|
||||||
|
|
||||||
placeholder?: (
|
placeholder?: (
|
||||||
context: IStrategyContext & {
|
context: IStrategyContext & {
|
||||||
input: IStrategyInput<InputType> & StrategyInputParameterMap[InputType];
|
component: IStrategyComponent<ComponentType> & StrategyComponentParameterMap[ComponentType];
|
||||||
}
|
}
|
||||||
) => string;
|
) => string;
|
||||||
validate?: (
|
validate?: (
|
||||||
context: IStrategyContext & {
|
context: IStrategyContext & {
|
||||||
input: IStrategyInput<InputType> & StrategyInputParameterMap[InputType];
|
component: IStrategyComponent<ComponentType> & StrategyComponentParameterMap[ComponentType];
|
||||||
}
|
}
|
||||||
) => string | void;
|
) => string | void;
|
||||||
|
|
||||||
defaults?: (context: Omit<IStrategyContext, "inputs">) => object;
|
defaults?: (context: Omit<IStrategyContext, "components">) => object;
|
||||||
update?: (
|
update?: (
|
||||||
context: IStrategyContext & {
|
context: IStrategyContext & {
|
||||||
input: IStrategyInput<InputType> & StrategyInputParameterMap[InputType];
|
component: IStrategyComponent<ComponentType> & StrategyComponentParameterMap[ComponentType];
|
||||||
}
|
}
|
||||||
) => void;
|
) => void;
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ export interface IStrategy {
|
||||||
details?: string;
|
details?: string;
|
||||||
author?: string;
|
author?: string;
|
||||||
|
|
||||||
inputs: IStrategyInput<StrategyInputType>[];
|
components: IStrategyComponent<StrategyComponentType>[];
|
||||||
|
|
||||||
variables?: object;
|
variables?: object;
|
||||||
|
|
||||||
|
@ -109,10 +109,10 @@ export interface IStrategy {
|
||||||
submitText?: string;
|
submitText?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function defineInput<InputType extends StrategyInputType>(
|
export function defineStrategyComponent<ComponentType extends StrategyComponentType>(
|
||||||
input: IStrategyInput<InputType>
|
component: IStrategyComponent<ComponentType>
|
||||||
) {
|
) {
|
||||||
return input as IStrategyInput<InputType>;
|
return component as IStrategyComponent<ComponentType>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function defineStrategy(strategy: IStrategy) {
|
export function defineStrategy(strategy: IStrategy) {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { DefineStrategy, IStrategyContext } from ".";
|
||||||
|
|
||||||
export class Strategy {
|
export class Strategy {
|
||||||
schema: DefineStrategy;
|
schema: DefineStrategy;
|
||||||
inputs = [];
|
components = [];
|
||||||
context = {
|
context = {
|
||||||
web3: null as Web3,
|
web3: null as Web3,
|
||||||
dsa: null as DSA
|
dsa: null as DSA
|
||||||
|
@ -21,10 +21,10 @@ export class Strategy {
|
||||||
constructor(schema: DefineStrategy) {
|
constructor(schema: DefineStrategy) {
|
||||||
this.schema = schema;
|
this.schema = schema;
|
||||||
|
|
||||||
this.inputs = this.generateInputs(this.schema.inputs);
|
this.components = this.generateComponents(this.schema.components);
|
||||||
}
|
}
|
||||||
|
|
||||||
getBaseContext(): Omit<IStrategyContext, "inputs"> {
|
getBaseContext(): Omit<IStrategyContext, "components"> {
|
||||||
return {
|
return {
|
||||||
...this.context,
|
...this.context,
|
||||||
...this.props,
|
...this.props,
|
||||||
|
@ -35,65 +35,65 @@ export class Strategy {
|
||||||
getContext(): IStrategyContext {
|
getContext(): IStrategyContext {
|
||||||
return {
|
return {
|
||||||
...this.getBaseContext(),
|
...this.getBaseContext(),
|
||||||
inputs: this.inputs
|
components: this.components
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
setProps(props: object) {
|
setProps(props: object) {
|
||||||
Object.assign(this.props, props);
|
Object.assign(this.props, props);
|
||||||
|
|
||||||
const inputs = this.inputs;
|
const components = this.components;
|
||||||
|
|
||||||
for (const input of inputs) {
|
for (const component of components) {
|
||||||
if (typeof input.defaults !== "function") {
|
if (typeof component.defaults !== "function") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.defaulted) {
|
if (component.defaulted) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(input, input.defaults(this.getBaseContext()));
|
Object.assign(component, component.defaults(this.getBaseContext()));
|
||||||
|
|
||||||
input.defaulted = true;
|
component.defaulted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.notifyListeners();
|
this.notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
generateInputs(inputs) {
|
generateComponents(components) {
|
||||||
return inputs.map((input, idx) => {
|
return components.map((component, idx) => {
|
||||||
const computedInput = {
|
const computedComponent = {
|
||||||
...input,
|
...component,
|
||||||
value: input.value || "",
|
value: component.value || "",
|
||||||
error: input.error || "",
|
error: component.error || "",
|
||||||
placeholder: () => {
|
placeholder: () => {
|
||||||
return input.placeholder
|
return component.placeholder
|
||||||
? input.placeholder({
|
? component.placeholder({
|
||||||
...this.getContext(),
|
...this.getContext(),
|
||||||
input: this.inputs[idx]
|
component: this.components[idx]
|
||||||
})
|
})
|
||||||
: null;
|
: null;
|
||||||
},
|
},
|
||||||
onInput: (val: any) => {
|
onInput: (val: any) => {
|
||||||
this.inputs[idx].error = "";
|
this.components[idx].error = "";
|
||||||
this.inputs[idx].value = val;
|
this.components[idx].value = val;
|
||||||
|
|
||||||
if (val) {
|
if (val) {
|
||||||
this.inputs[idx].error = this.inputs[idx].validate({
|
this.components[idx].error = this.components[idx].validate({
|
||||||
...this.getContext(),
|
...this.getContext(),
|
||||||
input: this.inputs[idx]
|
component: this.components[idx]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.notifyListeners();
|
this.notifyListeners();
|
||||||
},
|
},
|
||||||
onCustomInput: (values: object) => {
|
onCustomInput: (values: object) => {
|
||||||
this.inputs[idx] = Object.assign(this.inputs[idx], values);
|
this.components[idx] = Object.assign(this.components[idx], values);
|
||||||
|
|
||||||
this.inputs[idx].error = this.inputs[idx].validate({
|
this.components[idx].error = this.components[idx].validate({
|
||||||
...this.getContext(),
|
...this.getContext(),
|
||||||
input: this.inputs[idx]
|
component: this.components[idx]
|
||||||
});
|
});
|
||||||
this.notifyListeners();
|
this.notifyListeners();
|
||||||
}
|
}
|
||||||
|
@ -101,12 +101,12 @@ export class Strategy {
|
||||||
|
|
||||||
let defaults = {};
|
let defaults = {};
|
||||||
|
|
||||||
if (input.defaults) {
|
if (component.defaults) {
|
||||||
defaults = input.defaults(this.getBaseContext());
|
defaults = component.defaults(this.getBaseContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...computedInput,
|
...computedComponent,
|
||||||
...defaults
|
...defaults
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -135,16 +135,16 @@ export class Strategy {
|
||||||
}
|
}
|
||||||
|
|
||||||
async validate() {
|
async validate() {
|
||||||
const inputs = this.inputs;
|
const components = this.components;
|
||||||
|
|
||||||
for (const input of inputs) {
|
for (const component of components) {
|
||||||
if (typeof input.validate !== "function") {
|
if (typeof component.validate !== "function") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await input.validate({
|
const result = await component.validate({
|
||||||
...this.getContext(),
|
...this.getContext(),
|
||||||
input
|
component
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof result === "string") {
|
if (typeof result === "string") {
|
||||||
|
@ -178,10 +178,12 @@ export class Strategy {
|
||||||
await listener(this);
|
await listener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.inputs.forEach(input => input.update?.({
|
this.components.forEach(component =>
|
||||||
...this.getContext(),
|
component.update?.({
|
||||||
input
|
...this.getContext(),
|
||||||
}));
|
component
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
onUpdated(cb) {
|
onUpdated(cb) {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import BigNumber from "bignumber.js";
|
import BigNumber from "bignumber.js";
|
||||||
import {
|
import {
|
||||||
defineStrategy,
|
defineStrategy,
|
||||||
defineInput,
|
defineStrategyComponent,
|
||||||
StrategyInputType,
|
StrategyComponentType,
|
||||||
StrategyProtocol
|
StrategyProtocol
|
||||||
} from "../../helpers";
|
} from "../../helpers";
|
||||||
|
|
||||||
|
@ -27,13 +27,13 @@ export default defineStrategy({
|
||||||
debtRateMode: 2
|
debtRateMode: 2
|
||||||
},
|
},
|
||||||
|
|
||||||
inputs: [
|
components: [
|
||||||
defineInput({
|
defineStrategyComponent({
|
||||||
type: StrategyInputType.INPUT_WITH_TOKEN,
|
type: StrategyComponentType.INPUT_WITH_TOKEN,
|
||||||
name: "Collateral",
|
name: "Collateral",
|
||||||
placeholder: ({ input }) =>
|
placeholder: ({ component: input }) =>
|
||||||
input.token ? `${input.token.symbol} to Deposit` : "",
|
input.token ? `${input.token.symbol} to Deposit` : "",
|
||||||
validate: ({ input, dsaBalances, toBN }) => {
|
validate: ({ component: input, dsaBalances, toBN }) => {
|
||||||
if (!input.token) {
|
if (!input.token) {
|
||||||
return "Collateral token is required";
|
return "Collateral token is required";
|
||||||
}
|
}
|
||||||
|
@ -56,12 +56,12 @@ export default defineStrategy({
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
|
|
||||||
defineInput({
|
defineStrategyComponent({
|
||||||
type: StrategyInputType.INPUT_WITH_TOKEN,
|
type: StrategyComponentType.INPUT_WITH_TOKEN,
|
||||||
name: "Debt",
|
name: "Debt",
|
||||||
placeholder: ({ input }) =>
|
placeholder: ({ component: input }) =>
|
||||||
input.token ? `${input.token.symbol} to Borrow` : "",
|
input.token ? `${input.token.symbol} to Borrow` : "",
|
||||||
validate: ({ input }) => {
|
validate: ({ component: input }) => {
|
||||||
if (!input.token) {
|
if (!input.token) {
|
||||||
return "Debt token is required";
|
return "Debt token is required";
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ export default defineStrategy({
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
|
||||||
validate: async ({ position, inputs, toBN }) => {
|
validate: async ({ position, components: inputs, toBN }) => {
|
||||||
if (toBN(inputs[0].value).isZero() && toBN(inputs[1].value).isZero()) {
|
if (toBN(inputs[0].value).isZero() && toBN(inputs[1].value).isZero()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ export default defineStrategy({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
spells: async ({ inputs, convertTokenAmountToWei, variables }) => {
|
spells: async ({ components: inputs, convertTokenAmountToWei, variables }) => {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
connector: "aave_v2",
|
connector: "aave_v2",
|
||||||
|
|
|
@ -2,8 +2,8 @@ import BigNumber from "bignumber.js";
|
||||||
import tokens from "~/constant/tokens";
|
import tokens from "~/constant/tokens";
|
||||||
import {
|
import {
|
||||||
defineStrategy,
|
defineStrategy,
|
||||||
defineInput,
|
defineStrategyComponent,
|
||||||
StrategyInputType,
|
StrategyComponentType,
|
||||||
StrategyProtocol
|
StrategyProtocol
|
||||||
} from "../../helpers";
|
} from "../../helpers";
|
||||||
|
|
||||||
|
@ -21,13 +21,13 @@ export default defineStrategy({
|
||||||
<li>Withdraw collateral</li>
|
<li>Withdraw collateral</li>
|
||||||
</ul>`,
|
</ul>`,
|
||||||
|
|
||||||
inputs: [
|
components: [
|
||||||
defineInput({
|
defineStrategyComponent({
|
||||||
type: StrategyInputType.INPUT_WITH_TOKEN,
|
type: StrategyComponentType.INPUT_WITH_TOKEN,
|
||||||
name: "Debt",
|
name: "Debt",
|
||||||
placeholder: ({ input }) =>
|
placeholder: ({ component: input }) =>
|
||||||
input.token ? `${input.token.symbol} to Payback` : "",
|
input.token ? `${input.token.symbol} to Payback` : "",
|
||||||
validate: ({ input, toBN, dsaBalances }) => {
|
validate: ({ component: input, toBN, dsaBalances }) => {
|
||||||
if (!input.token) {
|
if (!input.token) {
|
||||||
return "Debt token is required";
|
return "Debt token is required";
|
||||||
}
|
}
|
||||||
|
@ -42,12 +42,12 @@ export default defineStrategy({
|
||||||
token: getTokenByKey?.("dai")
|
token: getTokenByKey?.("dai")
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
defineInput({
|
defineStrategyComponent({
|
||||||
type: StrategyInputType.INPUT_WITH_TOKEN,
|
type: StrategyComponentType.INPUT_WITH_TOKEN,
|
||||||
name: "Collateral",
|
name: "Collateral",
|
||||||
placeholder: ({ input }) =>
|
placeholder: ({ component: input }) =>
|
||||||
input.token ? `${input.token.symbol} to Withdraw` : "",
|
input.token ? `${input.token.symbol} to Withdraw` : "",
|
||||||
validate: ({ input, position, toBN }) => {
|
validate: ({ component: input, position, toBN }) => {
|
||||||
if (!input.token) {
|
if (!input.token) {
|
||||||
return "Collateral token is required";
|
return "Collateral token is required";
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ export default defineStrategy({
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
|
||||||
validate: async ({ position, inputs, toBN }) => {
|
validate: async ({ position, components: inputs, toBN }) => {
|
||||||
if (toBN(inputs[0].value).isZero() && toBN(inputs[1].value).isZero()) {
|
if (toBN(inputs[0].value).isZero() && toBN(inputs[1].value).isZero()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,7 @@ export default defineStrategy({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
spells: async ({ inputs, convertTokenAmountToWei }) => {
|
spells: async ({ components: inputs, convertTokenAmountToWei }) => {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
connector: "aave_v2",
|
connector: "aave_v2",
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import BigNumber from "bignumber.js";
|
import BigNumber from "bignumber.js";
|
||||||
import {
|
import {
|
||||||
defineStrategy,
|
defineStrategy,
|
||||||
defineInput,
|
defineStrategyComponent,
|
||||||
StrategyInputType,
|
StrategyComponentType,
|
||||||
StrategyProtocol
|
StrategyProtocol
|
||||||
} from "../../helpers";
|
} from "../../helpers";
|
||||||
|
|
||||||
|
@ -26,13 +26,13 @@ export default defineStrategy({
|
||||||
debtTokenKey: "dai"
|
debtTokenKey: "dai"
|
||||||
},
|
},
|
||||||
|
|
||||||
inputs: [
|
components: [
|
||||||
defineInput({
|
defineStrategyComponent({
|
||||||
type: StrategyInputType.INPUT_WITH_TOKEN,
|
type: StrategyComponentType.INPUT_WITH_TOKEN,
|
||||||
name: "Collateral",
|
name: "Collateral",
|
||||||
placeholder: ({ input }) =>
|
placeholder: ({ component: input }) =>
|
||||||
input.token ? `${input.token.symbol} to Deposit` : "",
|
input.token ? `${input.token.symbol} to Deposit` : "",
|
||||||
validate: ({ input, dsaBalances, toBN }) => {
|
validate: ({ component: input, dsaBalances, toBN }) => {
|
||||||
if (!input.token) {
|
if (!input.token) {
|
||||||
return "Collateral token is required";
|
return "Collateral token is required";
|
||||||
}
|
}
|
||||||
|
@ -55,12 +55,12 @@ export default defineStrategy({
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
|
|
||||||
defineInput({
|
defineStrategyComponent({
|
||||||
type: StrategyInputType.INPUT_WITH_TOKEN,
|
type: StrategyComponentType.INPUT_WITH_TOKEN,
|
||||||
name: "Debt",
|
name: "Debt",
|
||||||
placeholder: ({ input }) =>
|
placeholder: ({ component: input }) =>
|
||||||
input.token ? `${input.token.symbol} to Borrow` : "",
|
input.token ? `${input.token.symbol} to Borrow` : "",
|
||||||
validate: ({ input }) => {
|
validate: ({ component: input }) => {
|
||||||
if (!input.token) {
|
if (!input.token) {
|
||||||
return "Debt token is required";
|
return "Debt token is required";
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ export default defineStrategy({
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
|
||||||
validate: async ({ position, inputs, toBN, tokenIdMapping }) => {
|
validate: async ({ position, components: inputs, toBN, tokenIdMapping }) => {
|
||||||
if (toBN(inputs[0].value).isZero() && toBN(inputs[1].value).isZero()) {
|
if (toBN(inputs[0].value).isZero() && toBN(inputs[1].value).isZero()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ export default defineStrategy({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
spells: async ({ inputs, convertTokenAmountToWei, tokenIdMapping }) => {
|
spells: async ({ components: inputs, convertTokenAmountToWei, tokenIdMapping }) => {
|
||||||
const { tokenToId } = tokenIdMapping;
|
const { tokenToId } = tokenIdMapping;
|
||||||
|
|
||||||
const collateralTokenId = tokenToId.compound[inputs[0].token.key];
|
const collateralTokenId = tokenToId.compound[inputs[0].token.key];
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import BigNumber from "bignumber.js";
|
import BigNumber from "bignumber.js";
|
||||||
import {
|
import {
|
||||||
defineStrategy,
|
defineStrategy,
|
||||||
defineInput,
|
defineStrategyComponent,
|
||||||
StrategyInputType,
|
StrategyComponentType,
|
||||||
StrategyProtocol
|
StrategyProtocol
|
||||||
} from "../../helpers";
|
} from "../../helpers";
|
||||||
|
|
||||||
|
@ -20,13 +20,13 @@ export default defineStrategy({
|
||||||
<li>Withdraw collateral</li>
|
<li>Withdraw collateral</li>
|
||||||
</ul>`,
|
</ul>`,
|
||||||
|
|
||||||
inputs: [
|
components: [
|
||||||
defineInput({
|
defineStrategyComponent({
|
||||||
type: StrategyInputType.INPUT_WITH_TOKEN,
|
type: StrategyComponentType.INPUT_WITH_TOKEN,
|
||||||
name: "Debt",
|
name: "Debt",
|
||||||
placeholder: ({ input }) =>
|
placeholder: ({ component: input }) =>
|
||||||
input.token ? `${input.token.symbol} to Payback` : "",
|
input.token ? `${input.token.symbol} to Payback` : "",
|
||||||
validate: ({ input, toBN, dsaBalances }) => {
|
validate: ({ component: input, toBN, dsaBalances }) => {
|
||||||
if (!input.token) {
|
if (!input.token) {
|
||||||
return "Debt token is required";
|
return "Debt token is required";
|
||||||
}
|
}
|
||||||
|
@ -41,12 +41,12 @@ export default defineStrategy({
|
||||||
token: getTokenByKey?.("dai")
|
token: getTokenByKey?.("dai")
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
defineInput({
|
defineStrategyComponent({
|
||||||
type: StrategyInputType.INPUT_WITH_TOKEN,
|
type: StrategyComponentType.INPUT_WITH_TOKEN,
|
||||||
name: "Collateral",
|
name: "Collateral",
|
||||||
placeholder: ({ input }) =>
|
placeholder: ({ component: input }) =>
|
||||||
input.token ? `${input.token.symbol} to Withdraw` : "",
|
input.token ? `${input.token.symbol} to Withdraw` : "",
|
||||||
validate: ({ input, position, toBN, tokenIdMapping }) => {
|
validate: ({ component: input, position, toBN, tokenIdMapping }) => {
|
||||||
if (!input.token) {
|
if (!input.token) {
|
||||||
return "Collateral token is required";
|
return "Collateral token is required";
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ export default defineStrategy({
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
|
||||||
validate: async ({ position, inputs, toBN, tokenIdMapping }) => {
|
validate: async ({ position, components: inputs, toBN, tokenIdMapping }) => {
|
||||||
if (toBN(inputs[0].value).isZero() && toBN(inputs[1].value).isZero()) {
|
if (toBN(inputs[0].value).isZero() && toBN(inputs[1].value).isZero()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ export default defineStrategy({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
spells: async ({ inputs, convertTokenAmountToWei, tokenIdMapping }) => {
|
spells: async ({ components: inputs, convertTokenAmountToWei, tokenIdMapping }) => {
|
||||||
const { tokenToId } = tokenIdMapping;
|
const { tokenToId } = tokenIdMapping;
|
||||||
|
|
||||||
const debtTokenId = tokenToId.compound[inputs[0].token.key];
|
const debtTokenId = tokenToId.compound[inputs[0].token.key];
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import {
|
import {
|
||||||
defineStrategy,
|
defineStrategy,
|
||||||
StrategyProtocol,
|
StrategyProtocol,
|
||||||
StrategyInputType,
|
StrategyComponentType,
|
||||||
defineInput
|
defineStrategyComponent
|
||||||
} from "../../helpers";
|
} from "../../helpers";
|
||||||
|
|
||||||
export default defineStrategy({
|
export default defineStrategy({
|
||||||
|
@ -19,41 +19,41 @@ export default defineStrategy({
|
||||||
<li>Close Trove</li>
|
<li>Close Trove</li>
|
||||||
</ul>`,
|
</ul>`,
|
||||||
|
|
||||||
inputs: [
|
components: [
|
||||||
defineInput({
|
defineStrategyComponent({
|
||||||
type: StrategyInputType.HEADING,
|
type: StrategyComponentType.HEADING,
|
||||||
name: "Payback"
|
name: "Payback"
|
||||||
}),
|
}),
|
||||||
defineInput({
|
defineStrategyComponent({
|
||||||
type: StrategyInputType.VALUE,
|
type: StrategyComponentType.VALUE,
|
||||||
name: "Net Debt",
|
name: "Net Debt",
|
||||||
update: ({ position, positionExtra, input, formatting, toBN }) => {
|
update: ({ position, positionExtra, component, formatting, toBN }) => {
|
||||||
const troveOverallDetails = positionExtra["troveOverallDetails"];
|
const troveOverallDetails = positionExtra["troveOverallDetails"];
|
||||||
|
|
||||||
const netDebt = toBN(position.debt).minus(
|
const netDebt = toBN(position.debt).minus(
|
||||||
troveOverallDetails.liquidationReserve
|
troveOverallDetails.liquidationReserve
|
||||||
);
|
);
|
||||||
|
|
||||||
input.value = `${formatting.formatDecimal(netDebt, 2)} LUSD`;
|
component.value = `${formatting.formatDecimal(netDebt, 2)} LUSD`;
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
defineInput({
|
defineStrategyComponent({
|
||||||
type: StrategyInputType.HEADING,
|
type: StrategyComponentType.HEADING,
|
||||||
name: "Withdraw"
|
name: "Withdraw"
|
||||||
}),
|
}),
|
||||||
defineInput({
|
defineStrategyComponent({
|
||||||
type: StrategyInputType.VALUE,
|
type: StrategyComponentType.VALUE,
|
||||||
name: "Collateral",
|
name: "Collateral",
|
||||||
update: ({ position, input, formatting }) => {
|
update: ({ position, component, formatting }) => {
|
||||||
input.value = `${formatting.formatDecimal(position.collateral, 2)} ETH`;
|
component.value = `${formatting.formatDecimal(position.collateral, 2)} ETH`;
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
defineInput({
|
defineStrategyComponent({
|
||||||
type: StrategyInputType.VALUE,
|
type: StrategyComponentType.VALUE,
|
||||||
name: "Liquidation Reserve",
|
name: "Liquidation Reserve",
|
||||||
update: ({ positionExtra, input, formatting }) => {
|
update: ({ positionExtra, component, formatting }) => {
|
||||||
const troveOverallDetails = positionExtra["troveOverallDetails"];
|
const troveOverallDetails = positionExtra["troveOverallDetails"];
|
||||||
input.value = `${formatting.formatDecimal(
|
component.value = `${formatting.formatDecimal(
|
||||||
troveOverallDetails.liquidationReserve,
|
troveOverallDetails.liquidationReserve,
|
||||||
2
|
2
|
||||||
)} LUSD`;
|
)} LUSD`;
|
||||||
|
|
|
@ -2,8 +2,8 @@ import abis from "~/constant/abis";
|
||||||
import addresses from "~/constant/addresses";
|
import addresses from "~/constant/addresses";
|
||||||
import {
|
import {
|
||||||
defineStrategy,
|
defineStrategy,
|
||||||
defineInput,
|
defineStrategyComponent,
|
||||||
StrategyInputType,
|
StrategyComponentType,
|
||||||
StrategyProtocol
|
StrategyProtocol
|
||||||
} from "../../helpers";
|
} from "../../helpers";
|
||||||
|
|
||||||
|
@ -27,13 +27,13 @@ export default defineStrategy({
|
||||||
debtTokenKey: "lusd"
|
debtTokenKey: "lusd"
|
||||||
},
|
},
|
||||||
|
|
||||||
inputs: [
|
components: [
|
||||||
defineInput({
|
defineStrategyComponent({
|
||||||
type: StrategyInputType.INPUT_WITH_TOKEN,
|
type: StrategyComponentType.INPUT_WITH_TOKEN,
|
||||||
name: "Collateral",
|
name: "Collateral",
|
||||||
placeholder: ({ input }) =>
|
placeholder: ({ component: input }) =>
|
||||||
input.token ? `${input.token.symbol} to Deposit` : "",
|
input.token ? `${input.token.symbol} to Deposit` : "",
|
||||||
validate: ({ input, dsaBalances, toBN }) => {
|
validate: ({ component: input, dsaBalances, toBN }) => {
|
||||||
if (!input.token) {
|
if (!input.token) {
|
||||||
return "Collateral token is required";
|
return "Collateral token is required";
|
||||||
}
|
}
|
||||||
|
@ -56,12 +56,12 @@ export default defineStrategy({
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
|
|
||||||
defineInput({
|
defineStrategyComponent({
|
||||||
type: StrategyInputType.INPUT_WITH_TOKEN,
|
type: StrategyComponentType.INPUT_WITH_TOKEN,
|
||||||
name: "Debt",
|
name: "Debt",
|
||||||
placeholder: ({ input }) =>
|
placeholder: ({ component: input }) =>
|
||||||
input.token ? `${input.token.symbol} to Borrow` : "",
|
input.token ? `${input.token.symbol} to Borrow` : "",
|
||||||
validate: ({ input, toBN, position, positionExtra }) => {
|
validate: ({ component: input, toBN, position, positionExtra }) => {
|
||||||
if (!input.token) {
|
if (!input.token) {
|
||||||
return "Debt token is required";
|
return "Debt token is required";
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ export default defineStrategy({
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
|
||||||
validate: async ({ position, positionExtra, inputs, toBN }) => {
|
validate: async ({ position, positionExtra, components: inputs, toBN }) => {
|
||||||
if (toBN(inputs[0].value).isZero() && toBN(inputs[1].value).isZero()) {
|
if (toBN(inputs[0].value).isZero() && toBN(inputs[1].value).isZero()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ export default defineStrategy({
|
||||||
},
|
},
|
||||||
|
|
||||||
spells: async ({
|
spells: async ({
|
||||||
inputs,
|
components: inputs,
|
||||||
position,
|
position,
|
||||||
positionExtra,
|
positionExtra,
|
||||||
getTokenByKey,
|
getTokenByKey,
|
||||||
|
|
|
@ -3,8 +3,8 @@ import abis from "~/constant/abis";
|
||||||
import addresses from "~/constant/addresses";
|
import addresses from "~/constant/addresses";
|
||||||
import {
|
import {
|
||||||
defineStrategy,
|
defineStrategy,
|
||||||
defineInput,
|
defineStrategyComponent,
|
||||||
StrategyInputType,
|
StrategyComponentType,
|
||||||
StrategyProtocol
|
StrategyProtocol
|
||||||
} from "../../helpers";
|
} from "../../helpers";
|
||||||
|
|
||||||
|
@ -22,13 +22,13 @@ export default defineStrategy({
|
||||||
<li>Withdraw collateral</li>
|
<li>Withdraw collateral</li>
|
||||||
</ul>`,
|
</ul>`,
|
||||||
|
|
||||||
inputs: [
|
components: [
|
||||||
defineInput({
|
defineStrategyComponent({
|
||||||
type: StrategyInputType.INPUT_WITH_TOKEN,
|
type: StrategyComponentType.INPUT_WITH_TOKEN,
|
||||||
name: "Debt",
|
name: "Debt",
|
||||||
placeholder: ({ input }) =>
|
placeholder: ({ component: input }) =>
|
||||||
input.token ? `${input.token.symbol} to Payback` : "",
|
input.token ? `${input.token.symbol} to Payback` : "",
|
||||||
validate: ({ input, toBN, position, positionExtra }) => {
|
validate: ({ component: input, toBN, position, positionExtra }) => {
|
||||||
if (!input.token) {
|
if (!input.token) {
|
||||||
return "Debt token is required";
|
return "Debt token is required";
|
||||||
}
|
}
|
||||||
|
@ -64,12 +64,12 @@ export default defineStrategy({
|
||||||
token: getTokenByKey?.("lusd")
|
token: getTokenByKey?.("lusd")
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
defineInput({
|
defineStrategyComponent({
|
||||||
type: StrategyInputType.INPUT_WITH_TOKEN,
|
type: StrategyComponentType.INPUT_WITH_TOKEN,
|
||||||
name: "Collateral",
|
name: "Collateral",
|
||||||
placeholder: ({ input }) =>
|
placeholder: ({ component: input }) =>
|
||||||
input.token ? `${input.token.symbol} to Withdraw` : "",
|
input.token ? `${input.token.symbol} to Withdraw` : "",
|
||||||
validate: ({ input, dsaBalances, toBN }) => {
|
validate: ({ component: input, dsaBalances, toBN }) => {
|
||||||
if (!input.token) {
|
if (!input.token) {
|
||||||
return "Collateral token is required";
|
return "Collateral token is required";
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ export default defineStrategy({
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
|
||||||
validate: async ({ position, inputs, toBN }) => {
|
validate: async ({ position, components: inputs, toBN }) => {
|
||||||
if (toBN(inputs[0].value).isZero() && toBN(inputs[1].value).isZero()) {
|
if (toBN(inputs[0].value).isZero() && toBN(inputs[1].value).isZero()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ export default defineStrategy({
|
||||||
},
|
},
|
||||||
|
|
||||||
spells: async ({
|
spells: async ({
|
||||||
inputs,
|
components: inputs,
|
||||||
position,
|
position,
|
||||||
positionExtra,
|
positionExtra,
|
||||||
getTokenByKey,
|
getTokenByKey,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user