mirror of
https://github.com/Instadapp/assembly.git
synced 2024-07-29 22:37:06 +00:00
wip
This commit is contained in:
parent
e87acafd6c
commit
f0f7167712
|
@ -85,7 +85,7 @@ export function useStrategy(defineStrategy: DefineStrategy) {
|
||||||
}
|
}
|
||||||
|
|
||||||
strategy.setProps({
|
strategy.setProps({
|
||||||
convertTokenAmountToBigNumber: valInt,
|
convertTokenAmountToWei: valInt,
|
||||||
getTokenByKey,
|
getTokenByKey,
|
||||||
position
|
position
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,13 +6,13 @@ export interface IStrategyContext {
|
||||||
dsa: DSA;
|
dsa: DSA;
|
||||||
web3: Web3;
|
web3: Web3;
|
||||||
inputs: IStrategyInput<StrategyInputType>[];
|
inputs: IStrategyInput<StrategyInputType>[];
|
||||||
dsadsaBalances?: { [address: string]: IStrategyToken };
|
dsaBalances?: { [address: string]: IStrategyToken };
|
||||||
userdsaBalances?: { [address: string]: IStrategyToken };
|
userBalances?: { [address: string]: IStrategyToken };
|
||||||
tokens?: { [address: string]: IStrategyToken };
|
tokens?: { [address: string]: IStrategyToken };
|
||||||
convertTokenAmountToBigNumber?: (value: any, decimals: any) => string;
|
convertTokenAmountToWei?: (value: any, decimals: any) => string;
|
||||||
getTokenByKey?: (key: string) => IStrategyToken;
|
getTokenByKey?: (key: string) => IStrategyToken;
|
||||||
position?: any;
|
position?: any;
|
||||||
variables?: object;
|
variables?: { [key: string]: any };
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IStrategyToken {
|
export interface IStrategyToken {
|
||||||
|
@ -42,7 +42,7 @@ export interface IStrategyInput<InputType extends StrategyInputType> {
|
||||||
type: InputType;
|
type: InputType;
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
variables?: object;
|
variables?: { [key: string]: any };
|
||||||
|
|
||||||
placeholder?: (
|
placeholder?: (
|
||||||
context: IStrategyContext & {
|
context: IStrategyContext & {
|
||||||
|
|
|
@ -34,8 +34,7 @@ export class Strategy {
|
||||||
|
|
||||||
getContext(): IStrategyContext {
|
getContext(): IStrategyContext {
|
||||||
return {
|
return {
|
||||||
...this.context,
|
...this.getBaseContext(),
|
||||||
...this.props,
|
|
||||||
inputs: this.inputs
|
inputs: this.inputs
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import BigNumber from "bignumber.js";
|
||||||
import {
|
import {
|
||||||
defineStrategy,
|
defineStrategy,
|
||||||
defineInput,
|
defineInput,
|
||||||
|
@ -18,12 +19,46 @@ export default defineStrategy({
|
||||||
|
|
||||||
author: "Instadapp Team",
|
author: "Instadapp Team",
|
||||||
|
|
||||||
|
variables: {
|
||||||
|
collateralTokenKey: "eth",
|
||||||
|
debtTokenKey: "dai",
|
||||||
|
debtRateMode: 2,
|
||||||
|
},
|
||||||
|
|
||||||
inputs: [
|
inputs: [
|
||||||
|
defineInput({
|
||||||
|
type: StrategyInputType.INPUT_WITH_TOKEN,
|
||||||
|
name: "Collateral",
|
||||||
|
placeholder: ({ input }) =>
|
||||||
|
input.token ? `${input.token.symbol} to Deposit` : "",
|
||||||
|
validate: ({ input, dsaBalances }) => {
|
||||||
|
if (!input.token) {
|
||||||
|
return "Collateral token is required";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!input.value) {
|
||||||
|
return "Collateral amount is required";
|
||||||
|
}
|
||||||
|
|
||||||
|
const collateralBalance = new BigNumber(
|
||||||
|
dsaBalances[input.token.address]?.balance
|
||||||
|
);
|
||||||
|
|
||||||
|
if (new BigNumber(collateralBalance).lt(input.value)) {
|
||||||
|
const collateralBalanceFormatted = collateralBalance.toFixed(2);
|
||||||
|
return `Your amount exceeds your maximum limit of ${collateralBalanceFormatted} ${input.token.symbol}`;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
defaults: ({ getTokenByKey, variables }) => ({
|
||||||
|
token: getTokenByKey?.(variables.collateralTokenKey)
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
|
||||||
defineInput({
|
defineInput({
|
||||||
type: StrategyInputType.INPUT_WITH_TOKEN,
|
type: StrategyInputType.INPUT_WITH_TOKEN,
|
||||||
name: "Debt",
|
name: "Debt",
|
||||||
placeholder: ({ input }) =>
|
placeholder: ({ input }) =>
|
||||||
input.token ? `${input.token.symbol} to Payback` : "",
|
input.token ? `${input.token.symbol} to Borrow` : "",
|
||||||
validate: ({ input }) => {
|
validate: ({ input }) => {
|
||||||
if (!input.token) {
|
if (!input.token) {
|
||||||
return "Debt token is required";
|
return "Debt token is required";
|
||||||
|
@ -32,46 +67,21 @@ export default defineStrategy({
|
||||||
if (!input.value) {
|
if (!input.value) {
|
||||||
return "Debt amount is required";
|
return "Debt amount is required";
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (input.token.balance < input.value) {
|
|
||||||
// return "Your amount exceeds your maximum limit.";
|
|
||||||
// }
|
|
||||||
},
|
},
|
||||||
defaults: ({ getTokenByKey }) => ({
|
defaults: ({ getTokenByKey, variables }) => ({
|
||||||
token: getTokenByKey?.("eth")
|
token: getTokenByKey?.(variables.debtTokenKey)
|
||||||
})
|
|
||||||
}),
|
|
||||||
defineInput({
|
|
||||||
type: StrategyInputType.INPUT_WITH_TOKEN,
|
|
||||||
name: "Collateral",
|
|
||||||
placeholder: ({ input }) =>
|
|
||||||
input.token ? `${input.token.symbol} to Withdraw` : "",
|
|
||||||
validate: ({ input }) => {
|
|
||||||
if (!input.token) {
|
|
||||||
return "Collateral token is required";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!input.value) {
|
|
||||||
return "Collateral amount is required";
|
|
||||||
}
|
|
||||||
},
|
|
||||||
defaults: ({ getTokenByKey }) => ({
|
|
||||||
token: getTokenByKey?.("dai")
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
|
||||||
spells: async ({ inputs, convertTokenAmountToBigNumber }) => {
|
spells: async ({ inputs, convertTokenAmountToWei, variables }) => {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
connector: "aave_v2",
|
connector: "aave_v2",
|
||||||
method: "deposit",
|
method: "deposit",
|
||||||
args: [
|
args: [
|
||||||
inputs[0].token.address,
|
inputs[0].token.address,
|
||||||
convertTokenAmountToBigNumber(
|
convertTokenAmountToWei(inputs[0].value, inputs[0].token.decimals),
|
||||||
inputs[0].value,
|
|
||||||
inputs[0].token.decimals
|
|
||||||
),
|
|
||||||
0,
|
0,
|
||||||
0
|
0
|
||||||
]
|
]
|
||||||
|
@ -81,11 +91,8 @@ export default defineStrategy({
|
||||||
method: "borrow",
|
method: "borrow",
|
||||||
args: [
|
args: [
|
||||||
inputs[1].token.address,
|
inputs[1].token.address,
|
||||||
convertTokenAmountToBigNumber(
|
convertTokenAmountToWei(inputs[1].value, inputs[1].token.decimals),
|
||||||
inputs[1].value,
|
variables.debtRateMode,
|
||||||
inputs[1].token.decimals
|
|
||||||
),
|
|
||||||
2,
|
|
||||||
0,
|
0,
|
||||||
0
|
0
|
||||||
]
|
]
|
||||||
|
|
|
@ -48,14 +48,14 @@ export default defineStrategy({
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
|
||||||
spells: async ({ inputs, convertTokenAmountToBigNumber }) => {
|
spells: async ({ inputs, convertTokenAmountToWei }) => {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
connector: "aave_v2",
|
connector: "aave_v2",
|
||||||
method: "payback",
|
method: "payback",
|
||||||
args: [
|
args: [
|
||||||
inputs[0].token.address,
|
inputs[0].token.address,
|
||||||
convertTokenAmountToBigNumber(
|
convertTokenAmountToWei(
|
||||||
inputs[0].value,
|
inputs[0].value,
|
||||||
inputs[0].token.decimals
|
inputs[0].token.decimals
|
||||||
),
|
),
|
||||||
|
@ -69,7 +69,7 @@ export default defineStrategy({
|
||||||
method: "withdraw",
|
method: "withdraw",
|
||||||
args: [
|
args: [
|
||||||
inputs[1].token.address,
|
inputs[1].token.address,
|
||||||
convertTokenAmountToBigNumber(
|
convertTokenAmountToWei(
|
||||||
inputs[1].value,
|
inputs[1].value,
|
||||||
inputs[1].token.decimals
|
inputs[1].token.decimals
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user