From e21d0d358fc90e5a93466494b6253306281bda22 Mon Sep 17 00:00:00 2001 From: Jacob Bryant Date: Fri, 31 Mar 2023 08:51:49 -0400 Subject: [PATCH 001/242] adding new VR contracts --- src/config/contracts.ts | 5 + src/contracts/VRCauldron.d.ts | 1721 +++++++++++++++++ src/contracts/VRLadle.d.ts | 1596 +++++++++++++++ src/contracts/abis/VRCauldron.json | 573 ++++++ src/contracts/abis/VRLadle.json | 502 +++++ .../factories/VRCauldron__factory.ts | 1295 +++++++++++++ src/contracts/factories/VRLadle__factory.ts | 1119 +++++++++++ 7 files changed, 6811 insertions(+) create mode 100644 src/contracts/VRCauldron.d.ts create mode 100644 src/contracts/VRLadle.d.ts create mode 100644 src/contracts/abis/VRCauldron.json create mode 100644 src/contracts/abis/VRLadle.json create mode 100644 src/contracts/factories/VRCauldron__factory.ts create mode 100644 src/contracts/factories/VRLadle__factory.ts diff --git a/src/config/contracts.ts b/src/config/contracts.ts index e2d1679f9..a6f2a8646 100644 --- a/src/config/contracts.ts +++ b/src/config/contracts.ts @@ -2,9 +2,12 @@ import { Contract } from 'ethers'; export enum ContractNames { CAULDRON = 'Cauldron', + VR_CAULDRON = 'VRCauldron', WITCH = 'Witch', + VR_WITCH = 'VRWitch', WITCHV2 = 'WitchV2', LADLE = 'Ladle', + VR_LADLE = 'VRLadle', WRAP_ETHER_MODULE = 'WrapEtherModule', CONVEX_LADLE_MODULE = 'ConvexLadleModule', TRANSFER_1155_MODULE = 'Transfer1155Module', @@ -22,7 +25,9 @@ const contractAddresses: ContractAddresses = { 1, new Map([ [ContractNames.CAULDRON, '0xc88191F8cb8e6D4a668B047c1C8503432c3Ca867'], + [ContractNames.VR_CAULDRON, '0x8fd04c6153a0e33afc669689c9bc36ae2e1e6501'], [ContractNames.LADLE, '0x6cB18fF2A33e981D1e38A663Ca056c0a5265066A'], + [ContractNames.VR_LADLE, '0x35d8f478ce6597548256d02b374972a775df927d'], [ContractNames.WITCH, '0x53C3760670f6091E1eC76B4dd27f73ba4CAd5061'], [ContractNames.WITCHV2, '0x08d2f5c96bb1f6be04b49bcd869d5af01db4c400'], [ContractNames.TRANSFER_1155_MODULE, '0x97f1d43A217aDD678bB6Dcd3C5D51F40b6729d06'], diff --git a/src/contracts/VRCauldron.d.ts b/src/contracts/VRCauldron.d.ts new file mode 100644 index 000000000..cf183b5ec --- /dev/null +++ b/src/contracts/VRCauldron.d.ts @@ -0,0 +1,1721 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { + ethers, + EventFilter, + Signer, + BigNumber, + BigNumberish, + PopulatedTransaction, + BaseContract, + ContractTransaction, + Overrides, + CallOverrides, +} from "ethers"; +import { BytesLike } from "@ethersproject/bytes"; +import { Listener, Provider } from "@ethersproject/providers"; +import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi"; +import type { TypedEventFilter, TypedEvent, TypedListener } from "./common"; + +interface VRCauldronInterface extends ethers.utils.Interface { + functions: { + "LOCK()": FunctionFragment; + "LOCK8605463013()": FunctionFragment; + "ROOT()": FunctionFragment; + "ROOT4146650865()": FunctionFragment; + "addAsset(bytes6,address)": FunctionFragment; + "addBase(bytes6)": FunctionFragment; + "addIlks(bytes6,bytes6[])": FunctionFragment; + "assets(bytes6)": FunctionFragment; + "balances(bytes12)": FunctionFragment; + "bases(bytes6)": FunctionFragment; + "build(address,bytes12,bytes6,bytes6)": FunctionFragment; + "debt(bytes6,bytes6)": FunctionFragment; + "debtFromBase(bytes6,uint128)": FunctionFragment; + "debtToBase(bytes6,uint128)": FunctionFragment; + "destroy(bytes12)": FunctionFragment; + "getRoleAdmin(bytes4)": FunctionFragment; + "give(bytes12,address)": FunctionFragment; + "grantRole(bytes4,address)": FunctionFragment; + "grantRoles(bytes4[],address)": FunctionFragment; + "hasRole(bytes4,address)": FunctionFragment; + "ilks(bytes6,bytes6)": FunctionFragment; + "level(bytes12)": FunctionFragment; + "lockRole(bytes4)": FunctionFragment; + "pour(bytes12,int128,int128)": FunctionFragment; + "rateOracles(bytes6)": FunctionFragment; + "renounceRole(bytes4,address)": FunctionFragment; + "revokeRole(bytes4,address)": FunctionFragment; + "revokeRoles(bytes4[],address)": FunctionFragment; + "setDebtLimits(bytes6,bytes6,uint96,uint24,uint8)": FunctionFragment; + "setRateOracle(bytes6,address)": FunctionFragment; + "setRoleAdmin(bytes4,bytes4)": FunctionFragment; + "setSpotOracle(bytes6,bytes6,address,uint32)": FunctionFragment; + "slurp(bytes12,uint128,uint128)": FunctionFragment; + "spotOracles(bytes6,bytes6)": FunctionFragment; + "stir(bytes12,bytes12,uint128,uint128)": FunctionFragment; + "tweak(bytes12,bytes6,bytes6)": FunctionFragment; + "vaults(bytes12)": FunctionFragment; + }; + + encodeFunctionData(functionFragment: "LOCK", values?: undefined): string; + encodeFunctionData( + functionFragment: "LOCK8605463013", + values?: undefined + ): string; + encodeFunctionData(functionFragment: "ROOT", values?: undefined): string; + encodeFunctionData( + functionFragment: "ROOT4146650865", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "addAsset", + values: [BytesLike, string] + ): string; + encodeFunctionData(functionFragment: "addBase", values: [BytesLike]): string; + encodeFunctionData( + functionFragment: "addIlks", + values: [BytesLike, BytesLike[]] + ): string; + encodeFunctionData(functionFragment: "assets", values: [BytesLike]): string; + encodeFunctionData(functionFragment: "balances", values: [BytesLike]): string; + encodeFunctionData(functionFragment: "bases", values: [BytesLike]): string; + encodeFunctionData( + functionFragment: "build", + values: [string, BytesLike, BytesLike, BytesLike] + ): string; + encodeFunctionData( + functionFragment: "debt", + values: [BytesLike, BytesLike] + ): string; + encodeFunctionData( + functionFragment: "debtFromBase", + values: [BytesLike, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "debtToBase", + values: [BytesLike, BigNumberish] + ): string; + encodeFunctionData(functionFragment: "destroy", values: [BytesLike]): string; + encodeFunctionData( + functionFragment: "getRoleAdmin", + values: [BytesLike] + ): string; + encodeFunctionData( + functionFragment: "give", + values: [BytesLike, string] + ): string; + encodeFunctionData( + functionFragment: "grantRole", + values: [BytesLike, string] + ): string; + encodeFunctionData( + functionFragment: "grantRoles", + values: [BytesLike[], string] + ): string; + encodeFunctionData( + functionFragment: "hasRole", + values: [BytesLike, string] + ): string; + encodeFunctionData( + functionFragment: "ilks", + values: [BytesLike, BytesLike] + ): string; + encodeFunctionData(functionFragment: "level", values: [BytesLike]): string; + encodeFunctionData(functionFragment: "lockRole", values: [BytesLike]): string; + encodeFunctionData( + functionFragment: "pour", + values: [BytesLike, BigNumberish, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "rateOracles", + values: [BytesLike] + ): string; + encodeFunctionData( + functionFragment: "renounceRole", + values: [BytesLike, string] + ): string; + encodeFunctionData( + functionFragment: "revokeRole", + values: [BytesLike, string] + ): string; + encodeFunctionData( + functionFragment: "revokeRoles", + values: [BytesLike[], string] + ): string; + encodeFunctionData( + functionFragment: "setDebtLimits", + values: [BytesLike, BytesLike, BigNumberish, BigNumberish, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "setRateOracle", + values: [BytesLike, string] + ): string; + encodeFunctionData( + functionFragment: "setRoleAdmin", + values: [BytesLike, BytesLike] + ): string; + encodeFunctionData( + functionFragment: "setSpotOracle", + values: [BytesLike, BytesLike, string, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "slurp", + values: [BytesLike, BigNumberish, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "spotOracles", + values: [BytesLike, BytesLike] + ): string; + encodeFunctionData( + functionFragment: "stir", + values: [BytesLike, BytesLike, BigNumberish, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "tweak", + values: [BytesLike, BytesLike, BytesLike] + ): string; + encodeFunctionData(functionFragment: "vaults", values: [BytesLike]): string; + + decodeFunctionResult(functionFragment: "LOCK", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "LOCK8605463013", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "ROOT", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "ROOT4146650865", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "addAsset", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "addBase", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "addIlks", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "assets", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "balances", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "bases", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "build", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "debt", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "debtFromBase", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "debtToBase", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "destroy", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "getRoleAdmin", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "give", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "grantRole", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "grantRoles", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "hasRole", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "ilks", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "level", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "lockRole", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "pour", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "rateOracles", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "renounceRole", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "revokeRole", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "revokeRoles", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "setDebtLimits", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "setRateOracle", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "setRoleAdmin", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "setSpotOracle", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "slurp", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "spotOracles", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "stir", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "tweak", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "vaults", data: BytesLike): Result; + + events: { + "AssetAdded(bytes6,address)": EventFragment; + "BaseAdded(bytes6)": EventFragment; + "DebtLimitsSet(bytes6,bytes6,uint96,uint24,uint8)": EventFragment; + "IlkAdded(bytes6,bytes6)": EventFragment; + "RateOracleAdded(bytes6,address)": EventFragment; + "RoleAdminChanged(bytes4,bytes4)": EventFragment; + "RoleGranted(bytes4,address,address)": EventFragment; + "RoleRevoked(bytes4,address,address)": EventFragment; + "SpotOracleAdded(bytes6,bytes6,address,uint32)": EventFragment; + "VaultBuilt(bytes12,address,bytes6,bytes6)": EventFragment; + "VaultDestroyed(bytes12)": EventFragment; + "VaultGiven(bytes12,address)": EventFragment; + "VaultPoured(bytes12,bytes6,bytes6,int128,int128)": EventFragment; + "VaultStirred(bytes12,bytes12,uint128,uint128)": EventFragment; + "VaultTweaked(bytes12,bytes6,bytes6)": EventFragment; + }; + + getEvent(nameOrSignatureOrTopic: "AssetAdded"): EventFragment; + getEvent(nameOrSignatureOrTopic: "BaseAdded"): EventFragment; + getEvent(nameOrSignatureOrTopic: "DebtLimitsSet"): EventFragment; + getEvent(nameOrSignatureOrTopic: "IlkAdded"): EventFragment; + getEvent(nameOrSignatureOrTopic: "RateOracleAdded"): EventFragment; + getEvent(nameOrSignatureOrTopic: "RoleAdminChanged"): EventFragment; + getEvent(nameOrSignatureOrTopic: "RoleGranted"): EventFragment; + getEvent(nameOrSignatureOrTopic: "RoleRevoked"): EventFragment; + getEvent(nameOrSignatureOrTopic: "SpotOracleAdded"): EventFragment; + getEvent(nameOrSignatureOrTopic: "VaultBuilt"): EventFragment; + getEvent(nameOrSignatureOrTopic: "VaultDestroyed"): EventFragment; + getEvent(nameOrSignatureOrTopic: "VaultGiven"): EventFragment; + getEvent(nameOrSignatureOrTopic: "VaultPoured"): EventFragment; + getEvent(nameOrSignatureOrTopic: "VaultStirred"): EventFragment; + getEvent(nameOrSignatureOrTopic: "VaultTweaked"): EventFragment; +} + +export type AssetAddedEvent = TypedEvent< + [string, string] & { assetId: string; asset: string } +>; + +export type BaseAddedEvent = TypedEvent<[string] & { baseId: string }>; + +export type DebtLimitsSetEvent = TypedEvent< + [string, string, BigNumber, number, number] & { + baseId: string; + ilkId: string; + max: BigNumber; + min: number; + dec: number; + } +>; + +export type IlkAddedEvent = TypedEvent< + [string, string] & { baseId: string; ilkId: string } +>; + +export type RateOracleAddedEvent = TypedEvent< + [string, string] & { baseId: string; oracle: string } +>; + +export type RoleAdminChangedEvent = TypedEvent< + [string, string] & { role: string; newAdminRole: string } +>; + +export type RoleGrantedEvent = TypedEvent< + [string, string, string] & { role: string; account: string; sender: string } +>; + +export type RoleRevokedEvent = TypedEvent< + [string, string, string] & { role: string; account: string; sender: string } +>; + +export type SpotOracleAddedEvent = TypedEvent< + [string, string, string, number] & { + baseId: string; + ilkId: string; + oracle: string; + ratio: number; + } +>; + +export type VaultBuiltEvent = TypedEvent< + [string, string, string, string] & { + vaultId: string; + owner: string; + baseId: string; + ilkId: string; + } +>; + +export type VaultDestroyedEvent = TypedEvent<[string] & { vaultId: string }>; + +export type VaultGivenEvent = TypedEvent< + [string, string] & { vaultId: string; receiver: string } +>; + +export type VaultPouredEvent = TypedEvent< + [string, string, string, BigNumber, BigNumber] & { + vaultId: string; + baseId: string; + ilkId: string; + ink: BigNumber; + art: BigNumber; + } +>; + +export type VaultStirredEvent = TypedEvent< + [string, string, BigNumber, BigNumber] & { + from: string; + to: string; + ink: BigNumber; + art: BigNumber; + } +>; + +export type VaultTweakedEvent = TypedEvent< + [string, string, string] & { vaultId: string; baseId: string; ilkId: string } +>; + +export class VRCauldron extends BaseContract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + listeners, EventArgsObject>( + eventFilter?: TypedEventFilter + ): Array>; + off, EventArgsObject>( + eventFilter: TypedEventFilter, + listener: TypedListener + ): this; + on, EventArgsObject>( + eventFilter: TypedEventFilter, + listener: TypedListener + ): this; + once, EventArgsObject>( + eventFilter: TypedEventFilter, + listener: TypedListener + ): this; + removeListener, EventArgsObject>( + eventFilter: TypedEventFilter, + listener: TypedListener + ): this; + removeAllListeners, EventArgsObject>( + eventFilter: TypedEventFilter + ): this; + + listeners(eventName?: string): Array; + off(eventName: string, listener: Listener): this; + on(eventName: string, listener: Listener): this; + once(eventName: string, listener: Listener): this; + removeListener(eventName: string, listener: Listener): this; + removeAllListeners(eventName?: string): this; + + queryFilter, EventArgsObject>( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + + interface: VRCauldronInterface; + + functions: { + LOCK(overrides?: CallOverrides): Promise<[string]>; + + LOCK8605463013(overrides?: CallOverrides): Promise<[string]>; + + ROOT(overrides?: CallOverrides): Promise<[string]>; + + ROOT4146650865(overrides?: CallOverrides): Promise<[string]>; + + addAsset( + assetId: BytesLike, + asset: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addBase( + baseId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addIlks( + baseId: BytesLike, + ilkIds: BytesLike[], + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + assets(arg0: BytesLike, overrides?: CallOverrides): Promise<[string]>; + + balances( + arg0: BytesLike, + overrides?: CallOverrides + ): Promise<[BigNumber, BigNumber] & { art: BigNumber; ink: BigNumber }>; + + bases(arg0: BytesLike, overrides?: CallOverrides): Promise<[boolean]>; + + build( + owner: string, + vaultId: BytesLike, + baseId: BytesLike, + ilkId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + debt( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise< + [BigNumber, number, number, BigNumber] & { + max: BigNumber; + min: number; + dec: number; + sum: BigNumber; + } + >; + + debtFromBase( + baseId: BytesLike, + base: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + debtToBase( + baseId: BytesLike, + art: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + destroy( + vaultId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + getRoleAdmin(role: BytesLike, overrides?: CallOverrides): Promise<[string]>; + + give( + vaultId: BytesLike, + receiver: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + grantRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + grantRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise<[boolean]>; + + ilks( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise<[boolean]>; + + level( + vaultId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + lockRole( + role: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + pour( + vaultId: BytesLike, + ink: BigNumberish, + base: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + rateOracles(arg0: BytesLike, overrides?: CallOverrides): Promise<[string]>; + + renounceRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setDebtLimits( + baseId: BytesLike, + ilkId: BytesLike, + max: BigNumberish, + min: BigNumberish, + dec: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setRateOracle( + baseId: BytesLike, + oracle: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setRoleAdmin( + role: BytesLike, + adminRole: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setSpotOracle( + baseId: BytesLike, + ilkId: BytesLike, + oracle: string, + ratio: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + slurp( + vaultId: BytesLike, + ink: BigNumberish, + base: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + spotOracles( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise<[string, number] & { oracle: string; ratio: number }>; + + stir( + from: BytesLike, + to: BytesLike, + ink: BigNumberish, + art: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + tweak( + vaultId: BytesLike, + baseId: BytesLike, + ilkId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + vaults( + arg0: BytesLike, + overrides?: CallOverrides + ): Promise< + [string, string, string] & { + owner: string; + baseId: string; + ilkId: string; + } + >; + }; + + LOCK(overrides?: CallOverrides): Promise; + + LOCK8605463013(overrides?: CallOverrides): Promise; + + ROOT(overrides?: CallOverrides): Promise; + + ROOT4146650865(overrides?: CallOverrides): Promise; + + addAsset( + assetId: BytesLike, + asset: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addBase( + baseId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addIlks( + baseId: BytesLike, + ilkIds: BytesLike[], + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + assets(arg0: BytesLike, overrides?: CallOverrides): Promise; + + balances( + arg0: BytesLike, + overrides?: CallOverrides + ): Promise<[BigNumber, BigNumber] & { art: BigNumber; ink: BigNumber }>; + + bases(arg0: BytesLike, overrides?: CallOverrides): Promise; + + build( + owner: string, + vaultId: BytesLike, + baseId: BytesLike, + ilkId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + debt( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise< + [BigNumber, number, number, BigNumber] & { + max: BigNumber; + min: number; + dec: number; + sum: BigNumber; + } + >; + + debtFromBase( + baseId: BytesLike, + base: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + debtToBase( + baseId: BytesLike, + art: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + destroy( + vaultId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + getRoleAdmin(role: BytesLike, overrides?: CallOverrides): Promise; + + give( + vaultId: BytesLike, + receiver: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + grantRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + grantRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + ilks( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise; + + level( + vaultId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + lockRole( + role: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + pour( + vaultId: BytesLike, + ink: BigNumberish, + base: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + rateOracles(arg0: BytesLike, overrides?: CallOverrides): Promise; + + renounceRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setDebtLimits( + baseId: BytesLike, + ilkId: BytesLike, + max: BigNumberish, + min: BigNumberish, + dec: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setRateOracle( + baseId: BytesLike, + oracle: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setRoleAdmin( + role: BytesLike, + adminRole: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setSpotOracle( + baseId: BytesLike, + ilkId: BytesLike, + oracle: string, + ratio: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + slurp( + vaultId: BytesLike, + ink: BigNumberish, + base: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + spotOracles( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise<[string, number] & { oracle: string; ratio: number }>; + + stir( + from: BytesLike, + to: BytesLike, + ink: BigNumberish, + art: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + tweak( + vaultId: BytesLike, + baseId: BytesLike, + ilkId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + vaults( + arg0: BytesLike, + overrides?: CallOverrides + ): Promise< + [string, string, string] & { owner: string; baseId: string; ilkId: string } + >; + + callStatic: { + LOCK(overrides?: CallOverrides): Promise; + + LOCK8605463013(overrides?: CallOverrides): Promise; + + ROOT(overrides?: CallOverrides): Promise; + + ROOT4146650865(overrides?: CallOverrides): Promise; + + addAsset( + assetId: BytesLike, + asset: string, + overrides?: CallOverrides + ): Promise; + + addBase(baseId: BytesLike, overrides?: CallOverrides): Promise; + + addIlks( + baseId: BytesLike, + ilkIds: BytesLike[], + overrides?: CallOverrides + ): Promise; + + assets(arg0: BytesLike, overrides?: CallOverrides): Promise; + + balances( + arg0: BytesLike, + overrides?: CallOverrides + ): Promise<[BigNumber, BigNumber] & { art: BigNumber; ink: BigNumber }>; + + bases(arg0: BytesLike, overrides?: CallOverrides): Promise; + + build( + owner: string, + vaultId: BytesLike, + baseId: BytesLike, + ilkId: BytesLike, + overrides?: CallOverrides + ): Promise< + [string, string, string] & { + owner: string; + baseId: string; + ilkId: string; + } + >; + + debt( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise< + [BigNumber, number, number, BigNumber] & { + max: BigNumber; + min: number; + dec: number; + sum: BigNumber; + } + >; + + debtFromBase( + baseId: BytesLike, + base: BigNumberish, + overrides?: CallOverrides + ): Promise; + + debtToBase( + baseId: BytesLike, + art: BigNumberish, + overrides?: CallOverrides + ): Promise; + + destroy(vaultId: BytesLike, overrides?: CallOverrides): Promise; + + getRoleAdmin(role: BytesLike, overrides?: CallOverrides): Promise; + + give( + vaultId: BytesLike, + receiver: string, + overrides?: CallOverrides + ): Promise< + [string, string, string] & { + owner: string; + baseId: string; + ilkId: string; + } + >; + + grantRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + grantRoles( + roles: BytesLike[], + account: string, + overrides?: CallOverrides + ): Promise; + + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + ilks( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise; + + level(vaultId: BytesLike, overrides?: CallOverrides): Promise; + + lockRole(role: BytesLike, overrides?: CallOverrides): Promise; + + pour( + vaultId: BytesLike, + ink: BigNumberish, + base: BigNumberish, + overrides?: CallOverrides + ): Promise<[BigNumber, BigNumber] & { art: BigNumber; ink: BigNumber }>; + + rateOracles(arg0: BytesLike, overrides?: CallOverrides): Promise; + + renounceRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + revokeRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + revokeRoles( + roles: BytesLike[], + account: string, + overrides?: CallOverrides + ): Promise; + + setDebtLimits( + baseId: BytesLike, + ilkId: BytesLike, + max: BigNumberish, + min: BigNumberish, + dec: BigNumberish, + overrides?: CallOverrides + ): Promise; + + setRateOracle( + baseId: BytesLike, + oracle: string, + overrides?: CallOverrides + ): Promise; + + setRoleAdmin( + role: BytesLike, + adminRole: BytesLike, + overrides?: CallOverrides + ): Promise; + + setSpotOracle( + baseId: BytesLike, + ilkId: BytesLike, + oracle: string, + ratio: BigNumberish, + overrides?: CallOverrides + ): Promise; + + slurp( + vaultId: BytesLike, + ink: BigNumberish, + base: BigNumberish, + overrides?: CallOverrides + ): Promise<[BigNumber, BigNumber] & { art: BigNumber; ink: BigNumber }>; + + spotOracles( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise<[string, number] & { oracle: string; ratio: number }>; + + stir( + from: BytesLike, + to: BytesLike, + ink: BigNumberish, + art: BigNumberish, + overrides?: CallOverrides + ): Promise< + [ + [BigNumber, BigNumber] & { art: BigNumber; ink: BigNumber }, + [BigNumber, BigNumber] & { art: BigNumber; ink: BigNumber } + ] + >; + + tweak( + vaultId: BytesLike, + baseId: BytesLike, + ilkId: BytesLike, + overrides?: CallOverrides + ): Promise< + [string, string, string] & { + owner: string; + baseId: string; + ilkId: string; + } + >; + + vaults( + arg0: BytesLike, + overrides?: CallOverrides + ): Promise< + [string, string, string] & { + owner: string; + baseId: string; + ilkId: string; + } + >; + }; + + filters: { + "AssetAdded(bytes6,address)"( + assetId?: BytesLike | null, + asset?: string | null + ): TypedEventFilter<[string, string], { assetId: string; asset: string }>; + + AssetAdded( + assetId?: BytesLike | null, + asset?: string | null + ): TypedEventFilter<[string, string], { assetId: string; asset: string }>; + + "BaseAdded(bytes6)"( + baseId?: BytesLike | null + ): TypedEventFilter<[string], { baseId: string }>; + + BaseAdded( + baseId?: BytesLike | null + ): TypedEventFilter<[string], { baseId: string }>; + + "DebtLimitsSet(bytes6,bytes6,uint96,uint24,uint8)"( + baseId?: BytesLike | null, + ilkId?: BytesLike | null, + max?: null, + min?: null, + dec?: null + ): TypedEventFilter< + [string, string, BigNumber, number, number], + { + baseId: string; + ilkId: string; + max: BigNumber; + min: number; + dec: number; + } + >; + + DebtLimitsSet( + baseId?: BytesLike | null, + ilkId?: BytesLike | null, + max?: null, + min?: null, + dec?: null + ): TypedEventFilter< + [string, string, BigNumber, number, number], + { + baseId: string; + ilkId: string; + max: BigNumber; + min: number; + dec: number; + } + >; + + "IlkAdded(bytes6,bytes6)"( + baseId?: BytesLike | null, + ilkId?: BytesLike | null + ): TypedEventFilter<[string, string], { baseId: string; ilkId: string }>; + + IlkAdded( + baseId?: BytesLike | null, + ilkId?: BytesLike | null + ): TypedEventFilter<[string, string], { baseId: string; ilkId: string }>; + + "RateOracleAdded(bytes6,address)"( + baseId?: BytesLike | null, + oracle?: string | null + ): TypedEventFilter<[string, string], { baseId: string; oracle: string }>; + + RateOracleAdded( + baseId?: BytesLike | null, + oracle?: string | null + ): TypedEventFilter<[string, string], { baseId: string; oracle: string }>; + + "RoleAdminChanged(bytes4,bytes4)"( + role?: BytesLike | null, + newAdminRole?: BytesLike | null + ): TypedEventFilter< + [string, string], + { role: string; newAdminRole: string } + >; + + RoleAdminChanged( + role?: BytesLike | null, + newAdminRole?: BytesLike | null + ): TypedEventFilter< + [string, string], + { role: string; newAdminRole: string } + >; + + "RoleGranted(bytes4,address,address)"( + role?: BytesLike | null, + account?: string | null, + sender?: string | null + ): TypedEventFilter< + [string, string, string], + { role: string; account: string; sender: string } + >; + + RoleGranted( + role?: BytesLike | null, + account?: string | null, + sender?: string | null + ): TypedEventFilter< + [string, string, string], + { role: string; account: string; sender: string } + >; + + "RoleRevoked(bytes4,address,address)"( + role?: BytesLike | null, + account?: string | null, + sender?: string | null + ): TypedEventFilter< + [string, string, string], + { role: string; account: string; sender: string } + >; + + RoleRevoked( + role?: BytesLike | null, + account?: string | null, + sender?: string | null + ): TypedEventFilter< + [string, string, string], + { role: string; account: string; sender: string } + >; + + "SpotOracleAdded(bytes6,bytes6,address,uint32)"( + baseId?: BytesLike | null, + ilkId?: BytesLike | null, + oracle?: string | null, + ratio?: null + ): TypedEventFilter< + [string, string, string, number], + { baseId: string; ilkId: string; oracle: string; ratio: number } + >; + + SpotOracleAdded( + baseId?: BytesLike | null, + ilkId?: BytesLike | null, + oracle?: string | null, + ratio?: null + ): TypedEventFilter< + [string, string, string, number], + { baseId: string; ilkId: string; oracle: string; ratio: number } + >; + + "VaultBuilt(bytes12,address,bytes6,bytes6)"( + vaultId?: BytesLike | null, + owner?: string | null, + baseId?: BytesLike | null, + ilkId?: null + ): TypedEventFilter< + [string, string, string, string], + { vaultId: string; owner: string; baseId: string; ilkId: string } + >; + + VaultBuilt( + vaultId?: BytesLike | null, + owner?: string | null, + baseId?: BytesLike | null, + ilkId?: null + ): TypedEventFilter< + [string, string, string, string], + { vaultId: string; owner: string; baseId: string; ilkId: string } + >; + + "VaultDestroyed(bytes12)"( + vaultId?: BytesLike | null + ): TypedEventFilter<[string], { vaultId: string }>; + + VaultDestroyed( + vaultId?: BytesLike | null + ): TypedEventFilter<[string], { vaultId: string }>; + + "VaultGiven(bytes12,address)"( + vaultId?: BytesLike | null, + receiver?: string | null + ): TypedEventFilter< + [string, string], + { vaultId: string; receiver: string } + >; + + VaultGiven( + vaultId?: BytesLike | null, + receiver?: string | null + ): TypedEventFilter< + [string, string], + { vaultId: string; receiver: string } + >; + + "VaultPoured(bytes12,bytes6,bytes6,int128,int128)"( + vaultId?: BytesLike | null, + baseId?: BytesLike | null, + ilkId?: BytesLike | null, + ink?: null, + art?: null + ): TypedEventFilter< + [string, string, string, BigNumber, BigNumber], + { + vaultId: string; + baseId: string; + ilkId: string; + ink: BigNumber; + art: BigNumber; + } + >; + + VaultPoured( + vaultId?: BytesLike | null, + baseId?: BytesLike | null, + ilkId?: BytesLike | null, + ink?: null, + art?: null + ): TypedEventFilter< + [string, string, string, BigNumber, BigNumber], + { + vaultId: string; + baseId: string; + ilkId: string; + ink: BigNumber; + art: BigNumber; + } + >; + + "VaultStirred(bytes12,bytes12,uint128,uint128)"( + from?: BytesLike | null, + to?: BytesLike | null, + ink?: null, + art?: null + ): TypedEventFilter< + [string, string, BigNumber, BigNumber], + { from: string; to: string; ink: BigNumber; art: BigNumber } + >; + + VaultStirred( + from?: BytesLike | null, + to?: BytesLike | null, + ink?: null, + art?: null + ): TypedEventFilter< + [string, string, BigNumber, BigNumber], + { from: string; to: string; ink: BigNumber; art: BigNumber } + >; + + "VaultTweaked(bytes12,bytes6,bytes6)"( + vaultId?: BytesLike | null, + baseId?: BytesLike | null, + ilkId?: BytesLike | null + ): TypedEventFilter< + [string, string, string], + { vaultId: string; baseId: string; ilkId: string } + >; + + VaultTweaked( + vaultId?: BytesLike | null, + baseId?: BytesLike | null, + ilkId?: BytesLike | null + ): TypedEventFilter< + [string, string, string], + { vaultId: string; baseId: string; ilkId: string } + >; + }; + + estimateGas: { + LOCK(overrides?: CallOverrides): Promise; + + LOCK8605463013(overrides?: CallOverrides): Promise; + + ROOT(overrides?: CallOverrides): Promise; + + ROOT4146650865(overrides?: CallOverrides): Promise; + + addAsset( + assetId: BytesLike, + asset: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addBase( + baseId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addIlks( + baseId: BytesLike, + ilkIds: BytesLike[], + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + assets(arg0: BytesLike, overrides?: CallOverrides): Promise; + + balances(arg0: BytesLike, overrides?: CallOverrides): Promise; + + bases(arg0: BytesLike, overrides?: CallOverrides): Promise; + + build( + owner: string, + vaultId: BytesLike, + baseId: BytesLike, + ilkId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + debt( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise; + + debtFromBase( + baseId: BytesLike, + base: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + debtToBase( + baseId: BytesLike, + art: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + destroy( + vaultId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + getRoleAdmin( + role: BytesLike, + overrides?: CallOverrides + ): Promise; + + give( + vaultId: BytesLike, + receiver: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + grantRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + grantRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + ilks( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise; + + level( + vaultId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + lockRole( + role: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + pour( + vaultId: BytesLike, + ink: BigNumberish, + base: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + rateOracles(arg0: BytesLike, overrides?: CallOverrides): Promise; + + renounceRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setDebtLimits( + baseId: BytesLike, + ilkId: BytesLike, + max: BigNumberish, + min: BigNumberish, + dec: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setRateOracle( + baseId: BytesLike, + oracle: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setRoleAdmin( + role: BytesLike, + adminRole: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setSpotOracle( + baseId: BytesLike, + ilkId: BytesLike, + oracle: string, + ratio: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + slurp( + vaultId: BytesLike, + ink: BigNumberish, + base: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + spotOracles( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise; + + stir( + from: BytesLike, + to: BytesLike, + ink: BigNumberish, + art: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + tweak( + vaultId: BytesLike, + baseId: BytesLike, + ilkId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + vaults(arg0: BytesLike, overrides?: CallOverrides): Promise; + }; + + populateTransaction: { + LOCK(overrides?: CallOverrides): Promise; + + LOCK8605463013(overrides?: CallOverrides): Promise; + + ROOT(overrides?: CallOverrides): Promise; + + ROOT4146650865(overrides?: CallOverrides): Promise; + + addAsset( + assetId: BytesLike, + asset: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addBase( + baseId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addIlks( + baseId: BytesLike, + ilkIds: BytesLike[], + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + assets( + arg0: BytesLike, + overrides?: CallOverrides + ): Promise; + + balances( + arg0: BytesLike, + overrides?: CallOverrides + ): Promise; + + bases( + arg0: BytesLike, + overrides?: CallOverrides + ): Promise; + + build( + owner: string, + vaultId: BytesLike, + baseId: BytesLike, + ilkId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + debt( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise; + + debtFromBase( + baseId: BytesLike, + base: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + debtToBase( + baseId: BytesLike, + art: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + destroy( + vaultId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + getRoleAdmin( + role: BytesLike, + overrides?: CallOverrides + ): Promise; + + give( + vaultId: BytesLike, + receiver: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + grantRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + grantRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + ilks( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise; + + level( + vaultId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + lockRole( + role: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + pour( + vaultId: BytesLike, + ink: BigNumberish, + base: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + rateOracles( + arg0: BytesLike, + overrides?: CallOverrides + ): Promise; + + renounceRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setDebtLimits( + baseId: BytesLike, + ilkId: BytesLike, + max: BigNumberish, + min: BigNumberish, + dec: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setRateOracle( + baseId: BytesLike, + oracle: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setRoleAdmin( + role: BytesLike, + adminRole: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setSpotOracle( + baseId: BytesLike, + ilkId: BytesLike, + oracle: string, + ratio: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + slurp( + vaultId: BytesLike, + ink: BigNumberish, + base: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + spotOracles( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise; + + stir( + from: BytesLike, + to: BytesLike, + ink: BigNumberish, + art: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + tweak( + vaultId: BytesLike, + baseId: BytesLike, + ilkId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + vaults( + arg0: BytesLike, + overrides?: CallOverrides + ): Promise; + }; +} diff --git a/src/contracts/VRLadle.d.ts b/src/contracts/VRLadle.d.ts new file mode 100644 index 000000000..6265c04ca --- /dev/null +++ b/src/contracts/VRLadle.d.ts @@ -0,0 +1,1596 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { + ethers, + EventFilter, + Signer, + BigNumber, + BigNumberish, + PopulatedTransaction, + BaseContract, + ContractTransaction, + Overrides, + PayableOverrides, + CallOverrides, +} from "ethers"; +import { BytesLike } from "@ethersproject/bytes"; +import { Listener, Provider } from "@ethersproject/providers"; +import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi"; +import type { TypedEventFilter, TypedEvent, TypedListener } from "./common"; + +interface VRLadleInterface extends ethers.utils.Interface { + functions: { + "LOCK()": FunctionFragment; + "LOCK8605463013()": FunctionFragment; + "ROOT()": FunctionFragment; + "ROOT4146650865()": FunctionFragment; + "addIntegration(address,bool)": FunctionFragment; + "addJoin(bytes6,address)": FunctionFragment; + "addModule(address,bool)": FunctionFragment; + "addToken(address,bool)": FunctionFragment; + "batch(bytes[])": FunctionFragment; + "borrowingFee()": FunctionFragment; + "build(bytes6,bytes6,uint8)": FunctionFragment; + "cauldron()": FunctionFragment; + "destroy(bytes12)": FunctionFragment; + "exitEther(address)": FunctionFragment; + "forwardDaiPermit(address,address,uint256,uint256,bool,uint8,bytes32,bytes32)": FunctionFragment; + "forwardPermit(address,address,uint256,uint256,uint8,bytes32,bytes32)": FunctionFragment; + "getRoleAdmin(bytes4)": FunctionFragment; + "give(bytes12,address)": FunctionFragment; + "grantRole(bytes4,address)": FunctionFragment; + "grantRoles(bytes4[],address)": FunctionFragment; + "hasRole(bytes4,address)": FunctionFragment; + "integrations(address)": FunctionFragment; + "joinEther(bytes6)": FunctionFragment; + "joins(bytes6)": FunctionFragment; + "lockRole(bytes4)": FunctionFragment; + "moduleCall(address,bytes)": FunctionFragment; + "modules(address)": FunctionFragment; + "pour(bytes12,address,int128,int128)": FunctionFragment; + "renounceRole(bytes4,address)": FunctionFragment; + "repay(bytes12,address,address,int128)": FunctionFragment; + "retrieve(address,address)": FunctionFragment; + "revokeRole(bytes4,address)": FunctionFragment; + "revokeRoles(bytes4[],address)": FunctionFragment; + "route(address,bytes)": FunctionFragment; + "router()": FunctionFragment; + "setFee(uint256)": FunctionFragment; + "setRoleAdmin(bytes4,bytes4)": FunctionFragment; + "stir(bytes12,bytes12,uint128,uint128)": FunctionFragment; + "tokens(address)": FunctionFragment; + "transfer(address,address,uint128)": FunctionFragment; + "tweak(bytes12,bytes6,bytes6)": FunctionFragment; + "weth()": FunctionFragment; + }; + + encodeFunctionData(functionFragment: "LOCK", values?: undefined): string; + encodeFunctionData( + functionFragment: "LOCK8605463013", + values?: undefined + ): string; + encodeFunctionData(functionFragment: "ROOT", values?: undefined): string; + encodeFunctionData( + functionFragment: "ROOT4146650865", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "addIntegration", + values: [string, boolean] + ): string; + encodeFunctionData( + functionFragment: "addJoin", + values: [BytesLike, string] + ): string; + encodeFunctionData( + functionFragment: "addModule", + values: [string, boolean] + ): string; + encodeFunctionData( + functionFragment: "addToken", + values: [string, boolean] + ): string; + encodeFunctionData(functionFragment: "batch", values: [BytesLike[]]): string; + encodeFunctionData( + functionFragment: "borrowingFee", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "build", + values: [BytesLike, BytesLike, BigNumberish] + ): string; + encodeFunctionData(functionFragment: "cauldron", values?: undefined): string; + encodeFunctionData(functionFragment: "destroy", values: [BytesLike]): string; + encodeFunctionData(functionFragment: "exitEther", values: [string]): string; + encodeFunctionData( + functionFragment: "forwardDaiPermit", + values: [ + string, + string, + BigNumberish, + BigNumberish, + boolean, + BigNumberish, + BytesLike, + BytesLike + ] + ): string; + encodeFunctionData( + functionFragment: "forwardPermit", + values: [ + string, + string, + BigNumberish, + BigNumberish, + BigNumberish, + BytesLike, + BytesLike + ] + ): string; + encodeFunctionData( + functionFragment: "getRoleAdmin", + values: [BytesLike] + ): string; + encodeFunctionData( + functionFragment: "give", + values: [BytesLike, string] + ): string; + encodeFunctionData( + functionFragment: "grantRole", + values: [BytesLike, string] + ): string; + encodeFunctionData( + functionFragment: "grantRoles", + values: [BytesLike[], string] + ): string; + encodeFunctionData( + functionFragment: "hasRole", + values: [BytesLike, string] + ): string; + encodeFunctionData( + functionFragment: "integrations", + values: [string] + ): string; + encodeFunctionData( + functionFragment: "joinEther", + values: [BytesLike] + ): string; + encodeFunctionData(functionFragment: "joins", values: [BytesLike]): string; + encodeFunctionData(functionFragment: "lockRole", values: [BytesLike]): string; + encodeFunctionData( + functionFragment: "moduleCall", + values: [string, BytesLike] + ): string; + encodeFunctionData(functionFragment: "modules", values: [string]): string; + encodeFunctionData( + functionFragment: "pour", + values: [BytesLike, string, BigNumberish, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "renounceRole", + values: [BytesLike, string] + ): string; + encodeFunctionData( + functionFragment: "repay", + values: [BytesLike, string, string, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "retrieve", + values: [string, string] + ): string; + encodeFunctionData( + functionFragment: "revokeRole", + values: [BytesLike, string] + ): string; + encodeFunctionData( + functionFragment: "revokeRoles", + values: [BytesLike[], string] + ): string; + encodeFunctionData( + functionFragment: "route", + values: [string, BytesLike] + ): string; + encodeFunctionData(functionFragment: "router", values?: undefined): string; + encodeFunctionData( + functionFragment: "setFee", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "setRoleAdmin", + values: [BytesLike, BytesLike] + ): string; + encodeFunctionData( + functionFragment: "stir", + values: [BytesLike, BytesLike, BigNumberish, BigNumberish] + ): string; + encodeFunctionData(functionFragment: "tokens", values: [string]): string; + encodeFunctionData( + functionFragment: "transfer", + values: [string, string, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "tweak", + values: [BytesLike, BytesLike, BytesLike] + ): string; + encodeFunctionData(functionFragment: "weth", values?: undefined): string; + + decodeFunctionResult(functionFragment: "LOCK", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "LOCK8605463013", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "ROOT", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "ROOT4146650865", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "addIntegration", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "addJoin", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "addModule", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "addToken", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "batch", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "borrowingFee", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "build", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "cauldron", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "destroy", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "exitEther", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "forwardDaiPermit", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "forwardPermit", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getRoleAdmin", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "give", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "grantRole", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "grantRoles", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "hasRole", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "integrations", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "joinEther", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "joins", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "lockRole", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "moduleCall", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "modules", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "pour", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "renounceRole", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "repay", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "retrieve", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "revokeRole", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "revokeRoles", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "route", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "router", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "setFee", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "setRoleAdmin", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "stir", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "tokens", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "transfer", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "tweak", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "weth", data: BytesLike): Result; + + events: { + "FeeSet(uint256)": EventFragment; + "IntegrationAdded(address,bool)": EventFragment; + "JoinAdded(bytes6,address)": EventFragment; + "ModuleAdded(address,bool)": EventFragment; + "RoleAdminChanged(bytes4,bytes4)": EventFragment; + "RoleGranted(bytes4,address,address)": EventFragment; + "RoleRevoked(bytes4,address,address)": EventFragment; + "TokenAdded(address,bool)": EventFragment; + }; + + getEvent(nameOrSignatureOrTopic: "FeeSet"): EventFragment; + getEvent(nameOrSignatureOrTopic: "IntegrationAdded"): EventFragment; + getEvent(nameOrSignatureOrTopic: "JoinAdded"): EventFragment; + getEvent(nameOrSignatureOrTopic: "ModuleAdded"): EventFragment; + getEvent(nameOrSignatureOrTopic: "RoleAdminChanged"): EventFragment; + getEvent(nameOrSignatureOrTopic: "RoleGranted"): EventFragment; + getEvent(nameOrSignatureOrTopic: "RoleRevoked"): EventFragment; + getEvent(nameOrSignatureOrTopic: "TokenAdded"): EventFragment; +} + +export type FeeSetEvent = TypedEvent<[BigNumber] & { fee: BigNumber }>; + +export type IntegrationAddedEvent = TypedEvent< + [string, boolean] & { integration: string; set: boolean } +>; + +export type JoinAddedEvent = TypedEvent< + [string, string] & { assetId: string; join: string } +>; + +export type ModuleAddedEvent = TypedEvent< + [string, boolean] & { module: string; set: boolean } +>; + +export type RoleAdminChangedEvent = TypedEvent< + [string, string] & { role: string; newAdminRole: string } +>; + +export type RoleGrantedEvent = TypedEvent< + [string, string, string] & { role: string; account: string; sender: string } +>; + +export type RoleRevokedEvent = TypedEvent< + [string, string, string] & { role: string; account: string; sender: string } +>; + +export type TokenAddedEvent = TypedEvent< + [string, boolean] & { token: string; set: boolean } +>; + +export class VRLadle extends BaseContract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + listeners, EventArgsObject>( + eventFilter?: TypedEventFilter + ): Array>; + off, EventArgsObject>( + eventFilter: TypedEventFilter, + listener: TypedListener + ): this; + on, EventArgsObject>( + eventFilter: TypedEventFilter, + listener: TypedListener + ): this; + once, EventArgsObject>( + eventFilter: TypedEventFilter, + listener: TypedListener + ): this; + removeListener, EventArgsObject>( + eventFilter: TypedEventFilter, + listener: TypedListener + ): this; + removeAllListeners, EventArgsObject>( + eventFilter: TypedEventFilter + ): this; + + listeners(eventName?: string): Array; + off(eventName: string, listener: Listener): this; + on(eventName: string, listener: Listener): this; + once(eventName: string, listener: Listener): this; + removeListener(eventName: string, listener: Listener): this; + removeAllListeners(eventName?: string): this; + + queryFilter, EventArgsObject>( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + + interface: VRLadleInterface; + + functions: { + LOCK(overrides?: CallOverrides): Promise<[string]>; + + LOCK8605463013(overrides?: CallOverrides): Promise<[string]>; + + ROOT(overrides?: CallOverrides): Promise<[string]>; + + ROOT4146650865(overrides?: CallOverrides): Promise<[string]>; + + addIntegration( + integration: string, + set: boolean, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addJoin( + assetId: BytesLike, + join: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addModule( + module: string, + set: boolean, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addToken( + token: string, + set: boolean, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + batch( + calls: BytesLike[], + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + borrowingFee(overrides?: CallOverrides): Promise<[BigNumber]>; + + build( + baseId: BytesLike, + ilkId: BytesLike, + salt: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + cauldron(overrides?: CallOverrides): Promise<[string]>; + + destroy( + vaultId_: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + exitEther( + to: string, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + forwardDaiPermit( + token: string, + spender: string, + nonce: BigNumberish, + deadline: BigNumberish, + allowed: boolean, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + forwardPermit( + token: string, + spender: string, + amount: BigNumberish, + deadline: BigNumberish, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + getRoleAdmin(role: BytesLike, overrides?: CallOverrides): Promise<[string]>; + + give( + vaultId_: BytesLike, + receiver: string, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + grantRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + grantRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise<[boolean]>; + + integrations(arg0: string, overrides?: CallOverrides): Promise<[boolean]>; + + joinEther( + etherId: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + joins(arg0: BytesLike, overrides?: CallOverrides): Promise<[string]>; + + lockRole( + role: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + moduleCall( + module: string, + data: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + modules(arg0: string, overrides?: CallOverrides): Promise<[boolean]>; + + pour( + vaultId_: BytesLike, + to: string, + ink: BigNumberish, + base: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + renounceRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + repay( + vaultId_: BytesLike, + inkTo: string, + refundTo: string, + ink: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + retrieve( + token: string, + to: string, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + revokeRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + route( + integration: string, + data: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + router(overrides?: CallOverrides): Promise<[string]>; + + setFee( + fee: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setRoleAdmin( + role: BytesLike, + adminRole: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + stir( + from: BytesLike, + to: BytesLike, + ink: BigNumberish, + art: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + tokens(arg0: string, overrides?: CallOverrides): Promise<[boolean]>; + + transfer( + token: string, + receiver: string, + wad: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + tweak( + vaultId_: BytesLike, + baseId: BytesLike, + ilkId: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + weth(overrides?: CallOverrides): Promise<[string]>; + }; + + LOCK(overrides?: CallOverrides): Promise; + + LOCK8605463013(overrides?: CallOverrides): Promise; + + ROOT(overrides?: CallOverrides): Promise; + + ROOT4146650865(overrides?: CallOverrides): Promise; + + addIntegration( + integration: string, + set: boolean, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addJoin( + assetId: BytesLike, + join: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addModule( + module: string, + set: boolean, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addToken( + token: string, + set: boolean, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + batch( + calls: BytesLike[], + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + borrowingFee(overrides?: CallOverrides): Promise; + + build( + baseId: BytesLike, + ilkId: BytesLike, + salt: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + cauldron(overrides?: CallOverrides): Promise; + + destroy( + vaultId_: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + exitEther( + to: string, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + forwardDaiPermit( + token: string, + spender: string, + nonce: BigNumberish, + deadline: BigNumberish, + allowed: boolean, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + forwardPermit( + token: string, + spender: string, + amount: BigNumberish, + deadline: BigNumberish, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + getRoleAdmin(role: BytesLike, overrides?: CallOverrides): Promise; + + give( + vaultId_: BytesLike, + receiver: string, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + grantRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + grantRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + integrations(arg0: string, overrides?: CallOverrides): Promise; + + joinEther( + etherId: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + joins(arg0: BytesLike, overrides?: CallOverrides): Promise; + + lockRole( + role: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + moduleCall( + module: string, + data: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + modules(arg0: string, overrides?: CallOverrides): Promise; + + pour( + vaultId_: BytesLike, + to: string, + ink: BigNumberish, + base: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + renounceRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + repay( + vaultId_: BytesLike, + inkTo: string, + refundTo: string, + ink: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + retrieve( + token: string, + to: string, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + revokeRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + route( + integration: string, + data: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + router(overrides?: CallOverrides): Promise; + + setFee( + fee: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setRoleAdmin( + role: BytesLike, + adminRole: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + stir( + from: BytesLike, + to: BytesLike, + ink: BigNumberish, + art: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + tokens(arg0: string, overrides?: CallOverrides): Promise; + + transfer( + token: string, + receiver: string, + wad: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + tweak( + vaultId_: BytesLike, + baseId: BytesLike, + ilkId: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + weth(overrides?: CallOverrides): Promise; + + callStatic: { + LOCK(overrides?: CallOverrides): Promise; + + LOCK8605463013(overrides?: CallOverrides): Promise; + + ROOT(overrides?: CallOverrides): Promise; + + ROOT4146650865(overrides?: CallOverrides): Promise; + + addIntegration( + integration: string, + set: boolean, + overrides?: CallOverrides + ): Promise; + + addJoin( + assetId: BytesLike, + join: string, + overrides?: CallOverrides + ): Promise; + + addModule( + module: string, + set: boolean, + overrides?: CallOverrides + ): Promise; + + addToken( + token: string, + set: boolean, + overrides?: CallOverrides + ): Promise; + + batch(calls: BytesLike[], overrides?: CallOverrides): Promise; + + borrowingFee(overrides?: CallOverrides): Promise; + + build( + baseId: BytesLike, + ilkId: BytesLike, + salt: BigNumberish, + overrides?: CallOverrides + ): Promise< + [ + string, + [string, string, string] & { + owner: string; + baseId: string; + ilkId: string; + } + ] + >; + + cauldron(overrides?: CallOverrides): Promise; + + destroy(vaultId_: BytesLike, overrides?: CallOverrides): Promise; + + exitEther(to: string, overrides?: CallOverrides): Promise; + + forwardDaiPermit( + token: string, + spender: string, + nonce: BigNumberish, + deadline: BigNumberish, + allowed: boolean, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: CallOverrides + ): Promise; + + forwardPermit( + token: string, + spender: string, + amount: BigNumberish, + deadline: BigNumberish, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: CallOverrides + ): Promise; + + getRoleAdmin(role: BytesLike, overrides?: CallOverrides): Promise; + + give( + vaultId_: BytesLike, + receiver: string, + overrides?: CallOverrides + ): Promise< + [string, string, string] & { + owner: string; + baseId: string; + ilkId: string; + } + >; + + grantRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + grantRoles( + roles: BytesLike[], + account: string, + overrides?: CallOverrides + ): Promise; + + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + integrations(arg0: string, overrides?: CallOverrides): Promise; + + joinEther( + etherId: BytesLike, + overrides?: CallOverrides + ): Promise; + + joins(arg0: BytesLike, overrides?: CallOverrides): Promise; + + lockRole(role: BytesLike, overrides?: CallOverrides): Promise; + + moduleCall( + module: string, + data: BytesLike, + overrides?: CallOverrides + ): Promise; + + modules(arg0: string, overrides?: CallOverrides): Promise; + + pour( + vaultId_: BytesLike, + to: string, + ink: BigNumberish, + base: BigNumberish, + overrides?: CallOverrides + ): Promise; + + renounceRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + repay( + vaultId_: BytesLike, + inkTo: string, + refundTo: string, + ink: BigNumberish, + overrides?: CallOverrides + ): Promise<[BigNumber, BigNumber] & { base: BigNumber; refund: BigNumber }>; + + retrieve( + token: string, + to: string, + overrides?: CallOverrides + ): Promise; + + revokeRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + revokeRoles( + roles: BytesLike[], + account: string, + overrides?: CallOverrides + ): Promise; + + route( + integration: string, + data: BytesLike, + overrides?: CallOverrides + ): Promise; + + router(overrides?: CallOverrides): Promise; + + setFee(fee: BigNumberish, overrides?: CallOverrides): Promise; + + setRoleAdmin( + role: BytesLike, + adminRole: BytesLike, + overrides?: CallOverrides + ): Promise; + + stir( + from: BytesLike, + to: BytesLike, + ink: BigNumberish, + art: BigNumberish, + overrides?: CallOverrides + ): Promise; + + tokens(arg0: string, overrides?: CallOverrides): Promise; + + transfer( + token: string, + receiver: string, + wad: BigNumberish, + overrides?: CallOverrides + ): Promise; + + tweak( + vaultId_: BytesLike, + baseId: BytesLike, + ilkId: BytesLike, + overrides?: CallOverrides + ): Promise< + [string, string, string] & { + owner: string; + baseId: string; + ilkId: string; + } + >; + + weth(overrides?: CallOverrides): Promise; + }; + + filters: { + "FeeSet(uint256)"( + fee?: null + ): TypedEventFilter<[BigNumber], { fee: BigNumber }>; + + FeeSet(fee?: null): TypedEventFilter<[BigNumber], { fee: BigNumber }>; + + "IntegrationAdded(address,bool)"( + integration?: string | null, + set?: boolean | null + ): TypedEventFilter< + [string, boolean], + { integration: string; set: boolean } + >; + + IntegrationAdded( + integration?: string | null, + set?: boolean | null + ): TypedEventFilter< + [string, boolean], + { integration: string; set: boolean } + >; + + "JoinAdded(bytes6,address)"( + assetId?: BytesLike | null, + join?: string | null + ): TypedEventFilter<[string, string], { assetId: string; join: string }>; + + JoinAdded( + assetId?: BytesLike | null, + join?: string | null + ): TypedEventFilter<[string, string], { assetId: string; join: string }>; + + "ModuleAdded(address,bool)"( + module?: string | null, + set?: boolean | null + ): TypedEventFilter<[string, boolean], { module: string; set: boolean }>; + + ModuleAdded( + module?: string | null, + set?: boolean | null + ): TypedEventFilter<[string, boolean], { module: string; set: boolean }>; + + "RoleAdminChanged(bytes4,bytes4)"( + role?: BytesLike | null, + newAdminRole?: BytesLike | null + ): TypedEventFilter< + [string, string], + { role: string; newAdminRole: string } + >; + + RoleAdminChanged( + role?: BytesLike | null, + newAdminRole?: BytesLike | null + ): TypedEventFilter< + [string, string], + { role: string; newAdminRole: string } + >; + + "RoleGranted(bytes4,address,address)"( + role?: BytesLike | null, + account?: string | null, + sender?: string | null + ): TypedEventFilter< + [string, string, string], + { role: string; account: string; sender: string } + >; + + RoleGranted( + role?: BytesLike | null, + account?: string | null, + sender?: string | null + ): TypedEventFilter< + [string, string, string], + { role: string; account: string; sender: string } + >; + + "RoleRevoked(bytes4,address,address)"( + role?: BytesLike | null, + account?: string | null, + sender?: string | null + ): TypedEventFilter< + [string, string, string], + { role: string; account: string; sender: string } + >; + + RoleRevoked( + role?: BytesLike | null, + account?: string | null, + sender?: string | null + ): TypedEventFilter< + [string, string, string], + { role: string; account: string; sender: string } + >; + + "TokenAdded(address,bool)"( + token?: string | null, + set?: boolean | null + ): TypedEventFilter<[string, boolean], { token: string; set: boolean }>; + + TokenAdded( + token?: string | null, + set?: boolean | null + ): TypedEventFilter<[string, boolean], { token: string; set: boolean }>; + }; + + estimateGas: { + LOCK(overrides?: CallOverrides): Promise; + + LOCK8605463013(overrides?: CallOverrides): Promise; + + ROOT(overrides?: CallOverrides): Promise; + + ROOT4146650865(overrides?: CallOverrides): Promise; + + addIntegration( + integration: string, + set: boolean, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addJoin( + assetId: BytesLike, + join: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addModule( + module: string, + set: boolean, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addToken( + token: string, + set: boolean, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + batch( + calls: BytesLike[], + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + borrowingFee(overrides?: CallOverrides): Promise; + + build( + baseId: BytesLike, + ilkId: BytesLike, + salt: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + cauldron(overrides?: CallOverrides): Promise; + + destroy( + vaultId_: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + exitEther( + to: string, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + forwardDaiPermit( + token: string, + spender: string, + nonce: BigNumberish, + deadline: BigNumberish, + allowed: boolean, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + forwardPermit( + token: string, + spender: string, + amount: BigNumberish, + deadline: BigNumberish, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + getRoleAdmin( + role: BytesLike, + overrides?: CallOverrides + ): Promise; + + give( + vaultId_: BytesLike, + receiver: string, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + grantRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + grantRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + integrations(arg0: string, overrides?: CallOverrides): Promise; + + joinEther( + etherId: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + joins(arg0: BytesLike, overrides?: CallOverrides): Promise; + + lockRole( + role: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + moduleCall( + module: string, + data: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + modules(arg0: string, overrides?: CallOverrides): Promise; + + pour( + vaultId_: BytesLike, + to: string, + ink: BigNumberish, + base: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + renounceRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + repay( + vaultId_: BytesLike, + inkTo: string, + refundTo: string, + ink: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + retrieve( + token: string, + to: string, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + revokeRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + route( + integration: string, + data: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + router(overrides?: CallOverrides): Promise; + + setFee( + fee: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setRoleAdmin( + role: BytesLike, + adminRole: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + stir( + from: BytesLike, + to: BytesLike, + ink: BigNumberish, + art: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + tokens(arg0: string, overrides?: CallOverrides): Promise; + + transfer( + token: string, + receiver: string, + wad: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + tweak( + vaultId_: BytesLike, + baseId: BytesLike, + ilkId: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + weth(overrides?: CallOverrides): Promise; + }; + + populateTransaction: { + LOCK(overrides?: CallOverrides): Promise; + + LOCK8605463013(overrides?: CallOverrides): Promise; + + ROOT(overrides?: CallOverrides): Promise; + + ROOT4146650865(overrides?: CallOverrides): Promise; + + addIntegration( + integration: string, + set: boolean, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addJoin( + assetId: BytesLike, + join: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addModule( + module: string, + set: boolean, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addToken( + token: string, + set: boolean, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + batch( + calls: BytesLike[], + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + borrowingFee(overrides?: CallOverrides): Promise; + + build( + baseId: BytesLike, + ilkId: BytesLike, + salt: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + cauldron(overrides?: CallOverrides): Promise; + + destroy( + vaultId_: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + exitEther( + to: string, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + forwardDaiPermit( + token: string, + spender: string, + nonce: BigNumberish, + deadline: BigNumberish, + allowed: boolean, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + forwardPermit( + token: string, + spender: string, + amount: BigNumberish, + deadline: BigNumberish, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + getRoleAdmin( + role: BytesLike, + overrides?: CallOverrides + ): Promise; + + give( + vaultId_: BytesLike, + receiver: string, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + grantRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + grantRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + integrations( + arg0: string, + overrides?: CallOverrides + ): Promise; + + joinEther( + etherId: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + joins( + arg0: BytesLike, + overrides?: CallOverrides + ): Promise; + + lockRole( + role: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + moduleCall( + module: string, + data: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + modules( + arg0: string, + overrides?: CallOverrides + ): Promise; + + pour( + vaultId_: BytesLike, + to: string, + ink: BigNumberish, + base: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + renounceRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + repay( + vaultId_: BytesLike, + inkTo: string, + refundTo: string, + ink: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + retrieve( + token: string, + to: string, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + revokeRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + route( + integration: string, + data: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + router(overrides?: CallOverrides): Promise; + + setFee( + fee: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setRoleAdmin( + role: BytesLike, + adminRole: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + stir( + from: BytesLike, + to: BytesLike, + ink: BigNumberish, + art: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + tokens( + arg0: string, + overrides?: CallOverrides + ): Promise; + + transfer( + token: string, + receiver: string, + wad: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + tweak( + vaultId_: BytesLike, + baseId: BytesLike, + ilkId: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + weth(overrides?: CallOverrides): Promise; + }; +} diff --git a/src/contracts/abis/VRCauldron.json b/src/contracts/abis/VRCauldron.json new file mode 100644 index 000000000..6d734a696 --- /dev/null +++ b/src/contracts/abis/VRCauldron.json @@ -0,0 +1,573 @@ +[ + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes6", "name": "assetId", "type": "bytes6" }, + { "indexed": true, "internalType": "address", "name": "asset", "type": "address" } + ], + "name": "AssetAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": true, "internalType": "bytes6", "name": "baseId", "type": "bytes6" }], + "name": "BaseAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "indexed": true, "internalType": "bytes6", "name": "ilkId", "type": "bytes6" }, + { "indexed": false, "internalType": "uint96", "name": "max", "type": "uint96" }, + { "indexed": false, "internalType": "uint24", "name": "min", "type": "uint24" }, + { "indexed": false, "internalType": "uint8", "name": "dec", "type": "uint8" } + ], + "name": "DebtLimitsSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "indexed": true, "internalType": "bytes6", "name": "ilkId", "type": "bytes6" } + ], + "name": "IlkAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "indexed": true, "internalType": "address", "name": "oracle", "type": "address" } + ], + "name": "RateOracleAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "indexed": true, "internalType": "bytes4", "name": "newAdminRole", "type": "bytes4" } + ], + "name": "RoleAdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "indexed": true, "internalType": "address", "name": "account", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "sender", "type": "address" } + ], + "name": "RoleGranted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "indexed": true, "internalType": "address", "name": "account", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "sender", "type": "address" } + ], + "name": "RoleRevoked", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "indexed": true, "internalType": "bytes6", "name": "ilkId", "type": "bytes6" }, + { "indexed": true, "internalType": "address", "name": "oracle", "type": "address" }, + { "indexed": false, "internalType": "uint32", "name": "ratio", "type": "uint32" } + ], + "name": "SpotOracleAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }, + { "indexed": true, "internalType": "address", "name": "owner", "type": "address" }, + { "indexed": true, "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "indexed": false, "internalType": "bytes6", "name": "ilkId", "type": "bytes6" } + ], + "name": "VaultBuilt", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": true, "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }], + "name": "VaultDestroyed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }, + { "indexed": true, "internalType": "address", "name": "receiver", "type": "address" } + ], + "name": "VaultGiven", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }, + { "indexed": true, "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "indexed": true, "internalType": "bytes6", "name": "ilkId", "type": "bytes6" }, + { "indexed": false, "internalType": "int128", "name": "ink", "type": "int128" }, + { "indexed": false, "internalType": "int128", "name": "art", "type": "int128" } + ], + "name": "VaultPoured", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes12", "name": "from", "type": "bytes12" }, + { "indexed": true, "internalType": "bytes12", "name": "to", "type": "bytes12" }, + { "indexed": false, "internalType": "uint128", "name": "ink", "type": "uint128" }, + { "indexed": false, "internalType": "uint128", "name": "art", "type": "uint128" } + ], + "name": "VaultStirred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }, + { "indexed": true, "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "indexed": true, "internalType": "bytes6", "name": "ilkId", "type": "bytes6" } + ], + "name": "VaultTweaked", + "type": "event" + }, + { + "inputs": [], + "name": "LOCK", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "LOCK8605463013", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ROOT", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ROOT4146650865", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes6", "name": "assetId", "type": "bytes6" }, + { "internalType": "address", "name": "asset", "type": "address" } + ], + "name": "addAsset", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes6", "name": "baseId", "type": "bytes6" }], + "name": "addBase", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "internalType": "bytes6[]", "name": "ilkIds", "type": "bytes6[]" } + ], + "name": "addIlks", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes6", "name": "", "type": "bytes6" }], + "name": "assets", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes12", "name": "", "type": "bytes12" }], + "name": "balances", + "outputs": [ + { "internalType": "uint128", "name": "art", "type": "uint128" }, + { "internalType": "uint128", "name": "ink", "type": "uint128" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes6", "name": "", "type": "bytes6" }], + "name": "bases", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }, + { "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "internalType": "bytes6", "name": "ilkId", "type": "bytes6" } + ], + "name": "build", + "outputs": [ + { + "components": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "internalType": "bytes6", "name": "ilkId", "type": "bytes6" } + ], + "internalType": "struct VRDataTypes.Vault", + "name": "vault", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes6", "name": "", "type": "bytes6" }, + { "internalType": "bytes6", "name": "", "type": "bytes6" } + ], + "name": "debt", + "outputs": [ + { "internalType": "uint96", "name": "max", "type": "uint96" }, + { "internalType": "uint24", "name": "min", "type": "uint24" }, + { "internalType": "uint8", "name": "dec", "type": "uint8" }, + { "internalType": "uint128", "name": "sum", "type": "uint128" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "internalType": "uint128", "name": "base", "type": "uint128" } + ], + "name": "debtFromBase", + "outputs": [{ "internalType": "uint128", "name": "art", "type": "uint128" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "internalType": "uint128", "name": "art", "type": "uint128" } + ], + "name": "debtToBase", + "outputs": [{ "internalType": "uint128", "name": "base", "type": "uint128" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }], + "name": "destroy", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes4", "name": "role", "type": "bytes4" }], + "name": "getRoleAdmin", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }, + { "internalType": "address", "name": "receiver", "type": "address" } + ], + "name": "give", + "outputs": [ + { + "components": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "internalType": "bytes6", "name": "ilkId", "type": "bytes6" } + ], + "internalType": "struct VRDataTypes.Vault", + "name": "vault", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "grantRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4[]", "name": "roles", "type": "bytes4[]" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "grantRoles", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "hasRole", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes6", "name": "", "type": "bytes6" }, + { "internalType": "bytes6", "name": "", "type": "bytes6" } + ], + "name": "ilks", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }], + "name": "level", + "outputs": [{ "internalType": "int256", "name": "", "type": "int256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes4", "name": "role", "type": "bytes4" }], + "name": "lockRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }, + { "internalType": "int128", "name": "ink", "type": "int128" }, + { "internalType": "int128", "name": "base", "type": "int128" } + ], + "name": "pour", + "outputs": [ + { + "components": [ + { "internalType": "uint128", "name": "art", "type": "uint128" }, + { "internalType": "uint128", "name": "ink", "type": "uint128" } + ], + "internalType": "struct DataTypes.Balances", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes6", "name": "", "type": "bytes6" }], + "name": "rateOracles", + "outputs": [{ "internalType": "contract IOracle", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "renounceRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "revokeRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4[]", "name": "roles", "type": "bytes4[]" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "revokeRoles", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "internalType": "bytes6", "name": "ilkId", "type": "bytes6" }, + { "internalType": "uint96", "name": "max", "type": "uint96" }, + { "internalType": "uint24", "name": "min", "type": "uint24" }, + { "internalType": "uint8", "name": "dec", "type": "uint8" } + ], + "name": "setDebtLimits", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "internalType": "contract IOracle", "name": "oracle", "type": "address" } + ], + "name": "setRateOracle", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "internalType": "bytes4", "name": "adminRole", "type": "bytes4" } + ], + "name": "setRoleAdmin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "internalType": "bytes6", "name": "ilkId", "type": "bytes6" }, + { "internalType": "contract IOracle", "name": "oracle", "type": "address" }, + { "internalType": "uint32", "name": "ratio", "type": "uint32" } + ], + "name": "setSpotOracle", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }, + { "internalType": "uint128", "name": "ink", "type": "uint128" }, + { "internalType": "uint128", "name": "base", "type": "uint128" } + ], + "name": "slurp", + "outputs": [ + { + "components": [ + { "internalType": "uint128", "name": "art", "type": "uint128" }, + { "internalType": "uint128", "name": "ink", "type": "uint128" } + ], + "internalType": "struct DataTypes.Balances", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes6", "name": "", "type": "bytes6" }, + { "internalType": "bytes6", "name": "", "type": "bytes6" } + ], + "name": "spotOracles", + "outputs": [ + { "internalType": "contract IOracle", "name": "oracle", "type": "address" }, + { "internalType": "uint32", "name": "ratio", "type": "uint32" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes12", "name": "from", "type": "bytes12" }, + { "internalType": "bytes12", "name": "to", "type": "bytes12" }, + { "internalType": "uint128", "name": "ink", "type": "uint128" }, + { "internalType": "uint128", "name": "art", "type": "uint128" } + ], + "name": "stir", + "outputs": [ + { + "components": [ + { "internalType": "uint128", "name": "art", "type": "uint128" }, + { "internalType": "uint128", "name": "ink", "type": "uint128" } + ], + "internalType": "struct DataTypes.Balances", + "name": "", + "type": "tuple" + }, + { + "components": [ + { "internalType": "uint128", "name": "art", "type": "uint128" }, + { "internalType": "uint128", "name": "ink", "type": "uint128" } + ], + "internalType": "struct DataTypes.Balances", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }, + { "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "internalType": "bytes6", "name": "ilkId", "type": "bytes6" } + ], + "name": "tweak", + "outputs": [ + { + "components": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "internalType": "bytes6", "name": "ilkId", "type": "bytes6" } + ], + "internalType": "struct VRDataTypes.Vault", + "name": "vault", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes12", "name": "", "type": "bytes12" }], + "name": "vaults", + "outputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "internalType": "bytes6", "name": "ilkId", "type": "bytes6" } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/src/contracts/abis/VRLadle.json b/src/contracts/abis/VRLadle.json new file mode 100644 index 000000000..276c8869f --- /dev/null +++ b/src/contracts/abis/VRLadle.json @@ -0,0 +1,502 @@ +[ + { + "inputs": [ + { "internalType": "contract IVRCauldron", "name": "cauldron", "type": "address" }, + { "internalType": "contract IWETH9", "name": "weth", "type": "address" } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "uint256", "name": "fee", "type": "uint256" }], + "name": "FeeSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "integration", "type": "address" }, + { "indexed": true, "internalType": "bool", "name": "set", "type": "bool" } + ], + "name": "IntegrationAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes6", "name": "assetId", "type": "bytes6" }, + { "indexed": true, "internalType": "address", "name": "join", "type": "address" } + ], + "name": "JoinAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "module", "type": "address" }, + { "indexed": true, "internalType": "bool", "name": "set", "type": "bool" } + ], + "name": "ModuleAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "indexed": true, "internalType": "bytes4", "name": "newAdminRole", "type": "bytes4" } + ], + "name": "RoleAdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "indexed": true, "internalType": "address", "name": "account", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "sender", "type": "address" } + ], + "name": "RoleGranted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "indexed": true, "internalType": "address", "name": "account", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "sender", "type": "address" } + ], + "name": "RoleRevoked", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "token", "type": "address" }, + { "indexed": true, "internalType": "bool", "name": "set", "type": "bool" } + ], + "name": "TokenAdded", + "type": "event" + }, + { + "inputs": [], + "name": "LOCK", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "LOCK8605463013", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ROOT", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ROOT4146650865", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "integration", "type": "address" }, + { "internalType": "bool", "name": "set", "type": "bool" } + ], + "name": "addIntegration", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes6", "name": "assetId", "type": "bytes6" }, + { "internalType": "contract IJoin", "name": "join", "type": "address" } + ], + "name": "addJoin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "module", "type": "address" }, + { "internalType": "bool", "name": "set", "type": "bool" } + ], + "name": "addModule", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "token", "type": "address" }, + { "internalType": "bool", "name": "set", "type": "bool" } + ], + "name": "addToken", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes[]", "name": "calls", "type": "bytes[]" }], + "name": "batch", + "outputs": [{ "internalType": "bytes[]", "name": "results", "type": "bytes[]" }], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "borrowingFee", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "internalType": "bytes6", "name": "ilkId", "type": "bytes6" }, + { "internalType": "uint8", "name": "salt", "type": "uint8" } + ], + "name": "build", + "outputs": [ + { "internalType": "bytes12", "name": "", "type": "bytes12" }, + { + "components": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "internalType": "bytes6", "name": "ilkId", "type": "bytes6" } + ], + "internalType": "struct VRDataTypes.Vault", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "cauldron", + "outputs": [{ "internalType": "contract IVRCauldron", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes12", "name": "vaultId_", "type": "bytes12" }], + "name": "destroy", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address payable", "name": "to", "type": "address" }], + "name": "exitEther", + "outputs": [{ "internalType": "uint256", "name": "ethTransferred", "type": "uint256" }], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract DaiAbstract", "name": "token", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { "internalType": "bool", "name": "allowed", "type": "bool" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "forwardDaiPermit", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IERC2612", "name": "token", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "forwardPermit", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes4", "name": "role", "type": "bytes4" }], + "name": "getRoleAdmin", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes12", "name": "vaultId_", "type": "bytes12" }, + { "internalType": "address", "name": "receiver", "type": "address" } + ], + "name": "give", + "outputs": [ + { + "components": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "internalType": "bytes6", "name": "ilkId", "type": "bytes6" } + ], + "internalType": "struct VRDataTypes.Vault", + "name": "vault", + "type": "tuple" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "grantRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4[]", "name": "roles", "type": "bytes4[]" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "grantRoles", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "hasRole", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "integrations", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes6", "name": "etherId", "type": "bytes6" }], + "name": "joinEther", + "outputs": [{ "internalType": "uint256", "name": "ethTransferred", "type": "uint256" }], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes6", "name": "", "type": "bytes6" }], + "name": "joins", + "outputs": [{ "internalType": "contract IJoin", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes4", "name": "role", "type": "bytes4" }], + "name": "lockRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "module", "type": "address" }, + { "internalType": "bytes", "name": "data", "type": "bytes" } + ], + "name": "moduleCall", + "outputs": [{ "internalType": "bytes", "name": "result", "type": "bytes" }], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "modules", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes12", "name": "vaultId_", "type": "bytes12" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "int128", "name": "ink", "type": "int128" }, + { "internalType": "int128", "name": "base", "type": "int128" } + ], + "name": "pour", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "renounceRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes12", "name": "vaultId_", "type": "bytes12" }, + { "internalType": "address", "name": "inkTo", "type": "address" }, + { "internalType": "address", "name": "refundTo", "type": "address" }, + { "internalType": "int128", "name": "ink", "type": "int128" } + ], + "name": "repay", + "outputs": [ + { "internalType": "uint128", "name": "base", "type": "uint128" }, + { "internalType": "uint256", "name": "refund", "type": "uint256" } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" } + ], + "name": "retrieve", + "outputs": [{ "internalType": "uint256", "name": "amount", "type": "uint256" }], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "revokeRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4[]", "name": "roles", "type": "bytes4[]" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "revokeRoles", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "integration", "type": "address" }, + { "internalType": "bytes", "name": "data", "type": "bytes" } + ], + "name": "route", + "outputs": [{ "internalType": "bytes", "name": "result", "type": "bytes" }], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "router", + "outputs": [{ "internalType": "contract Router", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "fee", "type": "uint256" }], + "name": "setFee", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "internalType": "bytes4", "name": "adminRole", "type": "bytes4" } + ], + "name": "setRoleAdmin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes12", "name": "from", "type": "bytes12" }, + { "internalType": "bytes12", "name": "to", "type": "bytes12" }, + { "internalType": "uint128", "name": "ink", "type": "uint128" }, + { "internalType": "uint128", "name": "art", "type": "uint128" } + ], + "name": "stir", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "tokens", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "internalType": "address", "name": "receiver", "type": "address" }, + { "internalType": "uint128", "name": "wad", "type": "uint128" } + ], + "name": "transfer", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes12", "name": "vaultId_", "type": "bytes12" }, + { "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "internalType": "bytes6", "name": "ilkId", "type": "bytes6" } + ], + "name": "tweak", + "outputs": [ + { + "components": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "internalType": "bytes6", "name": "ilkId", "type": "bytes6" } + ], + "internalType": "struct VRDataTypes.Vault", + "name": "vault", + "type": "tuple" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "weth", + "outputs": [{ "internalType": "contract IWETH9", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { "stateMutability": "payable", "type": "receive" } +] diff --git a/src/contracts/factories/VRCauldron__factory.ts b/src/contracts/factories/VRCauldron__factory.ts new file mode 100644 index 000000000..c6b730841 --- /dev/null +++ b/src/contracts/factories/VRCauldron__factory.ts @@ -0,0 +1,1295 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer, utils } from "ethers"; +import { Provider } from "@ethersproject/providers"; +import type { VRCauldron, VRCauldronInterface } from "../VRCauldron"; + +const _abi = [ + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes6", + name: "assetId", + type: "bytes6", + }, + { + indexed: true, + internalType: "address", + name: "asset", + type: "address", + }, + ], + name: "AssetAdded", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + ], + name: "BaseAdded", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + indexed: true, + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + { + indexed: false, + internalType: "uint96", + name: "max", + type: "uint96", + }, + { + indexed: false, + internalType: "uint24", + name: "min", + type: "uint24", + }, + { + indexed: false, + internalType: "uint8", + name: "dec", + type: "uint8", + }, + ], + name: "DebtLimitsSet", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + indexed: true, + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + ], + name: "IlkAdded", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + indexed: true, + internalType: "address", + name: "oracle", + type: "address", + }, + ], + name: "RateOracleAdded", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + indexed: true, + internalType: "bytes4", + name: "newAdminRole", + type: "bytes4", + }, + ], + name: "RoleAdminChanged", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + indexed: true, + internalType: "address", + name: "account", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "sender", + type: "address", + }, + ], + name: "RoleGranted", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + indexed: true, + internalType: "address", + name: "account", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "sender", + type: "address", + }, + ], + name: "RoleRevoked", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + indexed: true, + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + { + indexed: true, + internalType: "address", + name: "oracle", + type: "address", + }, + { + indexed: false, + internalType: "uint32", + name: "ratio", + type: "uint32", + }, + ], + name: "SpotOracleAdded", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + { + indexed: true, + internalType: "address", + name: "owner", + type: "address", + }, + { + indexed: true, + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + indexed: false, + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + ], + name: "VaultBuilt", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + ], + name: "VaultDestroyed", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + { + indexed: true, + internalType: "address", + name: "receiver", + type: "address", + }, + ], + name: "VaultGiven", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + { + indexed: true, + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + indexed: true, + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + { + indexed: false, + internalType: "int128", + name: "ink", + type: "int128", + }, + { + indexed: false, + internalType: "int128", + name: "art", + type: "int128", + }, + ], + name: "VaultPoured", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes12", + name: "from", + type: "bytes12", + }, + { + indexed: true, + internalType: "bytes12", + name: "to", + type: "bytes12", + }, + { + indexed: false, + internalType: "uint128", + name: "ink", + type: "uint128", + }, + { + indexed: false, + internalType: "uint128", + name: "art", + type: "uint128", + }, + ], + name: "VaultStirred", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + { + indexed: true, + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + indexed: true, + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + ], + name: "VaultTweaked", + type: "event", + }, + { + inputs: [], + name: "LOCK", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "LOCK8605463013", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "ROOT", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "ROOT4146650865", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes6", + name: "assetId", + type: "bytes6", + }, + { + internalType: "address", + name: "asset", + type: "address", + }, + ], + name: "addAsset", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + ], + name: "addBase", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + internalType: "bytes6[]", + name: "ilkIds", + type: "bytes6[]", + }, + ], + name: "addIlks", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes6", + name: "", + type: "bytes6", + }, + ], + name: "assets", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "", + type: "bytes12", + }, + ], + name: "balances", + outputs: [ + { + internalType: "uint128", + name: "art", + type: "uint128", + }, + { + internalType: "uint128", + name: "ink", + type: "uint128", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes6", + name: "", + type: "bytes6", + }, + ], + name: "bases", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "owner", + type: "address", + }, + { + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + ], + name: "build", + outputs: [ + { + components: [ + { + internalType: "address", + name: "owner", + type: "address", + }, + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + ], + internalType: "struct VRDataTypes.Vault", + name: "vault", + type: "tuple", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes6", + name: "", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "", + type: "bytes6", + }, + ], + name: "debt", + outputs: [ + { + internalType: "uint96", + name: "max", + type: "uint96", + }, + { + internalType: "uint24", + name: "min", + type: "uint24", + }, + { + internalType: "uint8", + name: "dec", + type: "uint8", + }, + { + internalType: "uint128", + name: "sum", + type: "uint128", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + internalType: "uint128", + name: "base", + type: "uint128", + }, + ], + name: "debtFromBase", + outputs: [ + { + internalType: "uint128", + name: "art", + type: "uint128", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + internalType: "uint128", + name: "art", + type: "uint128", + }, + ], + name: "debtToBase", + outputs: [ + { + internalType: "uint128", + name: "base", + type: "uint128", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + ], + name: "destroy", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + ], + name: "getRoleAdmin", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + { + internalType: "address", + name: "receiver", + type: "address", + }, + ], + name: "give", + outputs: [ + { + components: [ + { + internalType: "address", + name: "owner", + type: "address", + }, + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + ], + internalType: "struct VRDataTypes.Vault", + name: "vault", + type: "tuple", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "grantRole", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4[]", + name: "roles", + type: "bytes4[]", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "grantRoles", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "hasRole", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes6", + name: "", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "", + type: "bytes6", + }, + ], + name: "ilks", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + ], + name: "level", + outputs: [ + { + internalType: "int256", + name: "", + type: "int256", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + ], + name: "lockRole", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + { + internalType: "int128", + name: "ink", + type: "int128", + }, + { + internalType: "int128", + name: "base", + type: "int128", + }, + ], + name: "pour", + outputs: [ + { + components: [ + { + internalType: "uint128", + name: "art", + type: "uint128", + }, + { + internalType: "uint128", + name: "ink", + type: "uint128", + }, + ], + internalType: "struct DataTypes.Balances", + name: "", + type: "tuple", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes6", + name: "", + type: "bytes6", + }, + ], + name: "rateOracles", + outputs: [ + { + internalType: "contract IOracle", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "renounceRole", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "revokeRole", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4[]", + name: "roles", + type: "bytes4[]", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "revokeRoles", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + { + internalType: "uint96", + name: "max", + type: "uint96", + }, + { + internalType: "uint24", + name: "min", + type: "uint24", + }, + { + internalType: "uint8", + name: "dec", + type: "uint8", + }, + ], + name: "setDebtLimits", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + internalType: "contract IOracle", + name: "oracle", + type: "address", + }, + ], + name: "setRateOracle", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + internalType: "bytes4", + name: "adminRole", + type: "bytes4", + }, + ], + name: "setRoleAdmin", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + { + internalType: "contract IOracle", + name: "oracle", + type: "address", + }, + { + internalType: "uint32", + name: "ratio", + type: "uint32", + }, + ], + name: "setSpotOracle", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + { + internalType: "uint128", + name: "ink", + type: "uint128", + }, + { + internalType: "uint128", + name: "base", + type: "uint128", + }, + ], + name: "slurp", + outputs: [ + { + components: [ + { + internalType: "uint128", + name: "art", + type: "uint128", + }, + { + internalType: "uint128", + name: "ink", + type: "uint128", + }, + ], + internalType: "struct DataTypes.Balances", + name: "", + type: "tuple", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes6", + name: "", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "", + type: "bytes6", + }, + ], + name: "spotOracles", + outputs: [ + { + internalType: "contract IOracle", + name: "oracle", + type: "address", + }, + { + internalType: "uint32", + name: "ratio", + type: "uint32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "from", + type: "bytes12", + }, + { + internalType: "bytes12", + name: "to", + type: "bytes12", + }, + { + internalType: "uint128", + name: "ink", + type: "uint128", + }, + { + internalType: "uint128", + name: "art", + type: "uint128", + }, + ], + name: "stir", + outputs: [ + { + components: [ + { + internalType: "uint128", + name: "art", + type: "uint128", + }, + { + internalType: "uint128", + name: "ink", + type: "uint128", + }, + ], + internalType: "struct DataTypes.Balances", + name: "", + type: "tuple", + }, + { + components: [ + { + internalType: "uint128", + name: "art", + type: "uint128", + }, + { + internalType: "uint128", + name: "ink", + type: "uint128", + }, + ], + internalType: "struct DataTypes.Balances", + name: "", + type: "tuple", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + ], + name: "tweak", + outputs: [ + { + components: [ + { + internalType: "address", + name: "owner", + type: "address", + }, + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + ], + internalType: "struct VRDataTypes.Vault", + name: "vault", + type: "tuple", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "", + type: "bytes12", + }, + ], + name: "vaults", + outputs: [ + { + internalType: "address", + name: "owner", + type: "address", + }, + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + ], + stateMutability: "view", + type: "function", + }, +]; + +export class VRCauldron__factory { + static readonly abi = _abi; + static createInterface(): VRCauldronInterface { + return new utils.Interface(_abi) as VRCauldronInterface; + } + static connect( + address: string, + signerOrProvider: Signer | Provider + ): VRCauldron { + return new Contract(address, _abi, signerOrProvider) as VRCauldron; + } +} diff --git a/src/contracts/factories/VRLadle__factory.ts b/src/contracts/factories/VRLadle__factory.ts new file mode 100644 index 000000000..076f6f625 --- /dev/null +++ b/src/contracts/factories/VRLadle__factory.ts @@ -0,0 +1,1119 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer, utils } from "ethers"; +import { Provider } from "@ethersproject/providers"; +import type { VRLadle, VRLadleInterface } from "../VRLadle"; + +const _abi = [ + { + inputs: [ + { + internalType: "contract IVRCauldron", + name: "cauldron", + type: "address", + }, + { + internalType: "contract IWETH9", + name: "weth", + type: "address", + }, + ], + stateMutability: "nonpayable", + type: "constructor", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "uint256", + name: "fee", + type: "uint256", + }, + ], + name: "FeeSet", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "integration", + type: "address", + }, + { + indexed: true, + internalType: "bool", + name: "set", + type: "bool", + }, + ], + name: "IntegrationAdded", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes6", + name: "assetId", + type: "bytes6", + }, + { + indexed: true, + internalType: "address", + name: "join", + type: "address", + }, + ], + name: "JoinAdded", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "module", + type: "address", + }, + { + indexed: true, + internalType: "bool", + name: "set", + type: "bool", + }, + ], + name: "ModuleAdded", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + indexed: true, + internalType: "bytes4", + name: "newAdminRole", + type: "bytes4", + }, + ], + name: "RoleAdminChanged", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + indexed: true, + internalType: "address", + name: "account", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "sender", + type: "address", + }, + ], + name: "RoleGranted", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + indexed: true, + internalType: "address", + name: "account", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "sender", + type: "address", + }, + ], + name: "RoleRevoked", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "token", + type: "address", + }, + { + indexed: true, + internalType: "bool", + name: "set", + type: "bool", + }, + ], + name: "TokenAdded", + type: "event", + }, + { + inputs: [], + name: "LOCK", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "LOCK8605463013", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "ROOT", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "ROOT4146650865", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "integration", + type: "address", + }, + { + internalType: "bool", + name: "set", + type: "bool", + }, + ], + name: "addIntegration", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes6", + name: "assetId", + type: "bytes6", + }, + { + internalType: "contract IJoin", + name: "join", + type: "address", + }, + ], + name: "addJoin", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "module", + type: "address", + }, + { + internalType: "bool", + name: "set", + type: "bool", + }, + ], + name: "addModule", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "token", + type: "address", + }, + { + internalType: "bool", + name: "set", + type: "bool", + }, + ], + name: "addToken", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes[]", + name: "calls", + type: "bytes[]", + }, + ], + name: "batch", + outputs: [ + { + internalType: "bytes[]", + name: "results", + type: "bytes[]", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [], + name: "borrowingFee", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + { + internalType: "uint8", + name: "salt", + type: "uint8", + }, + ], + name: "build", + outputs: [ + { + internalType: "bytes12", + name: "", + type: "bytes12", + }, + { + components: [ + { + internalType: "address", + name: "owner", + type: "address", + }, + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + ], + internalType: "struct VRDataTypes.Vault", + name: "", + type: "tuple", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [], + name: "cauldron", + outputs: [ + { + internalType: "contract IVRCauldron", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "vaultId_", + type: "bytes12", + }, + ], + name: "destroy", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "address payable", + name: "to", + type: "address", + }, + ], + name: "exitEther", + outputs: [ + { + internalType: "uint256", + name: "ethTransferred", + type: "uint256", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "contract DaiAbstract", + name: "token", + type: "address", + }, + { + internalType: "address", + name: "spender", + type: "address", + }, + { + internalType: "uint256", + name: "nonce", + type: "uint256", + }, + { + internalType: "uint256", + name: "deadline", + type: "uint256", + }, + { + internalType: "bool", + name: "allowed", + type: "bool", + }, + { + internalType: "uint8", + name: "v", + type: "uint8", + }, + { + internalType: "bytes32", + name: "r", + type: "bytes32", + }, + { + internalType: "bytes32", + name: "s", + type: "bytes32", + }, + ], + name: "forwardDaiPermit", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "contract IERC2612", + name: "token", + type: "address", + }, + { + internalType: "address", + name: "spender", + type: "address", + }, + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + { + internalType: "uint256", + name: "deadline", + type: "uint256", + }, + { + internalType: "uint8", + name: "v", + type: "uint8", + }, + { + internalType: "bytes32", + name: "r", + type: "bytes32", + }, + { + internalType: "bytes32", + name: "s", + type: "bytes32", + }, + ], + name: "forwardPermit", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + ], + name: "getRoleAdmin", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "vaultId_", + type: "bytes12", + }, + { + internalType: "address", + name: "receiver", + type: "address", + }, + ], + name: "give", + outputs: [ + { + components: [ + { + internalType: "address", + name: "owner", + type: "address", + }, + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + ], + internalType: "struct VRDataTypes.Vault", + name: "vault", + type: "tuple", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "grantRole", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4[]", + name: "roles", + type: "bytes4[]", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "grantRoles", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "hasRole", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + name: "integrations", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes6", + name: "etherId", + type: "bytes6", + }, + ], + name: "joinEther", + outputs: [ + { + internalType: "uint256", + name: "ethTransferred", + type: "uint256", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes6", + name: "", + type: "bytes6", + }, + ], + name: "joins", + outputs: [ + { + internalType: "contract IJoin", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + ], + name: "lockRole", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "module", + type: "address", + }, + { + internalType: "bytes", + name: "data", + type: "bytes", + }, + ], + name: "moduleCall", + outputs: [ + { + internalType: "bytes", + name: "result", + type: "bytes", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + name: "modules", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "vaultId_", + type: "bytes12", + }, + { + internalType: "address", + name: "to", + type: "address", + }, + { + internalType: "int128", + name: "ink", + type: "int128", + }, + { + internalType: "int128", + name: "base", + type: "int128", + }, + ], + name: "pour", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "renounceRole", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "vaultId_", + type: "bytes12", + }, + { + internalType: "address", + name: "inkTo", + type: "address", + }, + { + internalType: "address", + name: "refundTo", + type: "address", + }, + { + internalType: "int128", + name: "ink", + type: "int128", + }, + ], + name: "repay", + outputs: [ + { + internalType: "uint128", + name: "base", + type: "uint128", + }, + { + internalType: "uint256", + name: "refund", + type: "uint256", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "contract IERC20", + name: "token", + type: "address", + }, + { + internalType: "address", + name: "to", + type: "address", + }, + ], + name: "retrieve", + outputs: [ + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "revokeRole", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4[]", + name: "roles", + type: "bytes4[]", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "revokeRoles", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "integration", + type: "address", + }, + { + internalType: "bytes", + name: "data", + type: "bytes", + }, + ], + name: "route", + outputs: [ + { + internalType: "bytes", + name: "result", + type: "bytes", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [], + name: "router", + outputs: [ + { + internalType: "contract Router", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "fee", + type: "uint256", + }, + ], + name: "setFee", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + internalType: "bytes4", + name: "adminRole", + type: "bytes4", + }, + ], + name: "setRoleAdmin", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "from", + type: "bytes12", + }, + { + internalType: "bytes12", + name: "to", + type: "bytes12", + }, + { + internalType: "uint128", + name: "ink", + type: "uint128", + }, + { + internalType: "uint128", + name: "art", + type: "uint128", + }, + ], + name: "stir", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + name: "tokens", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "contract IERC20", + name: "token", + type: "address", + }, + { + internalType: "address", + name: "receiver", + type: "address", + }, + { + internalType: "uint128", + name: "wad", + type: "uint128", + }, + ], + name: "transfer", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "vaultId_", + type: "bytes12", + }, + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + ], + name: "tweak", + outputs: [ + { + components: [ + { + internalType: "address", + name: "owner", + type: "address", + }, + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + ], + internalType: "struct VRDataTypes.Vault", + name: "vault", + type: "tuple", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [], + name: "weth", + outputs: [ + { + internalType: "contract IWETH9", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + stateMutability: "payable", + type: "receive", + }, +]; + +export class VRLadle__factory { + static readonly abi = _abi; + static createInterface(): VRLadleInterface { + return new utils.Interface(_abi) as VRLadleInterface; + } + static connect( + address: string, + signerOrProvider: Signer | Provider + ): VRLadle { + return new Contract(address, _abi, signerOrProvider) as VRLadle; + } +} From 8711d5ef647fc83826ee3a7be16ea217930673b0 Mon Sep 17 00:00:00 2001 From: Jacob Bryant Date: Tue, 11 Apr 2023 18:56:25 -0400 Subject: [PATCH 002/242] rough initial work --- .env.local | 2 +- src/components/positionItems/VaultItem.tsx | 4 +- src/components/selectors/AssetSelector.tsx | 8 +- src/components/selectors/SeriesSelector.tsx | 6 +- src/components/selectors/VariableRate.tsx | 180 ++ .../selectors/VaultPositionSelector.tsx | 2 + src/components/settings/SupportSettings.tsx | 10 +- src/components/views/Borrow.tsx | 126 +- src/components/views/VaultPosition.tsx | 48 +- src/config/contracts.ts | 1 + src/config/series.ts | 4 +- src/contexts/HistoryContext.tsx | 84 +- src/contexts/SettingsContext.tsx | 8 +- src/contexts/UserContext.tsx | 147 +- src/contexts/types/user.ts | 15 +- src/contracts/VRWitch.d.ts | 1563 +++++++++++++++++ src/contracts/abis/VRWitch.json | 535 ++++++ src/contracts/factories/VRWitch__factory.ts | 1238 +++++++++++++ src/contracts/index.ts | 6 + .../useAddCollateralVariableRate.ts | 0 src/hooks/actionHooks/useBorrow.ts | 3 +- .../actionHooks/useBorrowVariableRate.ts | 211 +++ .../actionHooks/useRepayDebtVariableRate.ts | 241 +++ src/hooks/higherOrderHooks/useAssetPair.ts | 20 + .../higherOrderHooks/useCollateralHelpers.ts | 18 + ...eAssetPair.ts => useAssetPairFixedRate.ts} | 7 +- src/hooks/useAssetPairVariableRate.tsx | 176 ++ src/hooks/useChain.ts | 7 +- src/hooks/useInputValidation.ts | 3 + src/hooks/useProcess.ts | 1 + src/hooks/viewHelperHooks/useBorrowHelpers.ts | 173 +- ...rs.ts => useCollateralHelpersFixedRate.ts} | 6 +- .../useCollateralHelpersVariableRate.ts | 282 +++ .../viewHelperHooks/useDashboardHelpers.ts | 2 +- src/types/index.ts | 24 +- src/types/operations.ts | 5 + 36 files changed, 5021 insertions(+), 145 deletions(-) create mode 100644 src/components/selectors/VariableRate.tsx create mode 100644 src/contracts/VRWitch.d.ts create mode 100644 src/contracts/abis/VRWitch.json create mode 100644 src/contracts/factories/VRWitch__factory.ts create mode 100644 src/hooks/actionHooks/useAddCollateralVariableRate.ts create mode 100644 src/hooks/actionHooks/useBorrowVariableRate.ts create mode 100644 src/hooks/actionHooks/useRepayDebtVariableRate.ts create mode 100644 src/hooks/higherOrderHooks/useAssetPair.ts create mode 100644 src/hooks/higherOrderHooks/useCollateralHelpers.ts rename src/hooks/{useAssetPair.ts => useAssetPairFixedRate.ts} (95%) create mode 100644 src/hooks/useAssetPairVariableRate.tsx rename src/hooks/viewHelperHooks/{useCollateralHelpers.ts => useCollateralHelpersFixedRate.ts} (98%) create mode 100644 src/hooks/viewHelperHooks/useCollateralHelpersVariableRate.ts diff --git a/.env.local b/.env.local index 706fd8ad0..cb06d8b9f 100644 --- a/.env.local +++ b/.env.local @@ -4,7 +4,7 @@ REACT_APP_VERSION=$npm_package_version REACT_APP_RPC_URL_1='https://eth-mainnet.g.alchemy.com/v2/ZXDCq5iy0KrKR0XjsqC6E4QG7Z_FuXDv' REACT_APP_RPC_URL_42161='https://arb-mainnet.g.alchemy.com/v2/vtMM4_eLnOvkjkdckprVw3cIa64EVkDZ' -REACT_APP_DEFAULT_FORK_RPC_URL='https://rpc.tenderly.co/fork/5d734736-afd1-485d-b18c-d51453425706' +REACT_APP_DEFAULT_FORK_RPC_URL='https://rpc.tenderly.co/fork/ec327385-00b4-4e6b-9c4d-0a1cb566904b' REACT_APP_LOCALHOST_RPC_URL='http://127.0.0.1:8545' REACT_APP_RPC_URL_421611='https://arb-rinkeby.g.alchemy.com/v2/AY_Q_Uy-Kcfwmf5In5qwG636vaOIoA8L' diff --git a/src/components/positionItems/VaultItem.tsx b/src/components/positionItems/VaultItem.tsx index 6c9306833..02d9c7202 100644 --- a/src/components/positionItems/VaultItem.tsx +++ b/src/components/positionItems/VaultItem.tsx @@ -9,7 +9,7 @@ import PositionAvatar from '../PositionAvatar'; import ItemWrap from '../wraps/ItemWrap'; import SkeletonWrap from '../wraps/SkeletonWrap'; import { useBorrowHelpers } from '../../hooks/viewHelperHooks/useBorrowHelpers'; -import useAssetPair from '../../hooks/useAssetPair'; +import useAssetPair from '../../hooks/higherOrderHooks/useAssetPair'; import { cleanValue } from '../../utils/appUtils'; import { GA_Event, GA_Properties } from '../../types/analytics'; import useAnalytics from '../../hooks/useAnalytics'; @@ -38,6 +38,8 @@ function VaultItem({ vault, index, condensed }: { vault: IVault; index: number; const { data: assetPair } = useAssetPair(vaultBase?.id, vaultIlk?.id); const { debtInBase_ } = useBorrowHelpers(undefined, undefined, vault, assetPair, undefined); + console.log('in VaultItem', vaultsLoading, vault.displayName, vault, debtInBase_); + return ( handleSelect(vault)} diff --git a/src/components/selectors/AssetSelector.tsx b/src/components/selectors/AssetSelector.tsx index 5814e2652..5dcef0846 100644 --- a/src/components/selectors/AssetSelector.tsx +++ b/src/components/selectors/AssetSelector.tsx @@ -12,7 +12,7 @@ import AssetSelectModal from './AssetSelectModal'; import Logo from '../logos/Logo'; import { GA_Event, GA_Properties } from '../../types/analytics'; import useAnalytics from '../../hooks/useAnalytics'; -import useAssetPair from '../../hooks/useAssetPair'; +import useAssetPair from '../../hooks/higherOrderHooks/useAssetPair'; interface IAssetSelectorProps { selectCollateral?: boolean; @@ -37,12 +37,13 @@ function AssetSelector({ selectCollateral, isModal }: IAssetSelectorProps) { } = useContext(SettingsContext); const { userState, userActions } = useContext(UserContext); - const { assetMap, selectedIlk, selectedBase, selectedSeries } = userState; + const { assetMap, selectedIlk, selectedBase, selectedSeries, selectedVR } = userState; const { setSelectedIlk, setSelectedBase, setSelectedSeries, setSelectedStrategy } = userActions; const [options, setOptions] = useState([]); const [modalOpen, toggleModal] = useState(false); const { logAnalyticsEvent } = useAnalytics(); + const { validIlks, validIlksLoading } = useAssetPair(undefined, undefined, selectedSeries?.id); const optionText = (asset: IAsset | undefined) => @@ -79,6 +80,7 @@ function AssetSelector({ selectCollateral, isModal }: IAssetSelectorProps) { /* update options on any changes */ useEffect(() => { + console.log('%c in assetSelector useEffect', 'font-size: 36px;', selectCollateral, validIlks, selectedSeries); const opts = (selectCollateral ? validIlks! : Array.from(assetMap.values())) .filter((a) => a.showToken) .filter((a) => (showWrappedTokens ? true : !a.isWrappedToken)); // filter based on whether wrapped tokens are shown or not @@ -154,7 +156,7 @@ function AssetSelector({ selectCollateral, isModal }: IAssetSelectorProps) { (false && selectCollateral && options.filter((o, i) => (o.balance?.eq(ethers.constants.Zero) ? i : null))) || - (selectCollateral ? selectedSeries?.seriesIsMature || !selectedSeries : undefined) + (selectCollateral ? selectedSeries?.seriesIsMature || (!selectedSeries && !selectedVR) : undefined) } size="small" // eslint-disable-next-line react/no-children-prop diff --git a/src/components/selectors/SeriesSelector.tsx b/src/components/selectors/SeriesSelector.tsx index 669a855ec..a6a006cfc 100644 --- a/src/components/selectors/SeriesSelector.tsx +++ b/src/components/selectors/SeriesSelector.tsx @@ -193,8 +193,9 @@ function SeriesSelector({ selectSeriesLocally, inputValue, actionType, cardLayou ]); const handleSelect = (_series: ISeries) => { + userActions.setSelectedVR(false); if (!selectSeriesLocally) { - diagnostics && console.log('Series selected globally: ', _series.id); + diagnostics && console.log('Series selected globally: ', _series); userActions.setSelectedSeries(_series); } else { /* used for passing a selected series to the parent component */ @@ -291,8 +292,7 @@ function SeriesSelector({ selectSeriesLocally, inputValue, actionType, cardLayou {series.seriesMark} - { - series.allowActions.includes('allow_all') || + {series.allowActions.includes('allow_all') || (series.allowActions.includes(ActionCodes.BORROW) && actionType === ActionType.BORROW) || (series.allowActions.includes(ActionCodes.LEND) && actionType === ActionType.LEND) ? ( void; + // returns?: IReturns; + // } + props: any +) => { + const { + settingsState: { darkMode }, + } = useContext(SettingsContext); + + const { userState, userActions } = useContext(UserContext); + + const { selectedVR } = userState; + + return ( + { + userActions.setSelectedSeries(null); + userActions.setSelectedVR(true); + console.log('vr click', selectedVR); + }} + className="VR-container" + > + + + + + + + + + {/* {formatStrategyName(strategy.name!)} */} + Variable Rate + + + + + {/* Rolling {displayName} */} + Indefinite + + + + + {/* {strategy.rewardsRate!.gt(ZERO_BN) && ( */} + + + NEW + + + {/* )} */} + + {/* {returns?.blendedAPY && ( */} + + {/* */} + {/* {strategy.currentSeries?.allowActions.includes('allow_all') || + strategy.currentSeries?.allowActions.includes(ActionCodes.ADD_LIQUIDITY) ? ( */} + + + {2.7} % {'APR'} + + + {/* // ) : ( */} + {/* + + */} + {/* )} */} + {/* */} + + {/* )} */} + + + ); +}; + +export default VariableRate; diff --git a/src/components/selectors/VaultPositionSelector.tsx b/src/components/selectors/VaultPositionSelector.tsx index 363a34a79..0ed6b5236 100644 --- a/src/components/selectors/VaultPositionSelector.tsx +++ b/src/components/selectors/VaultPositionSelector.tsx @@ -34,6 +34,7 @@ function VaultPositionSelector(target: any) { const handleFilter = useCallback( ({ base, series, ilk }: IVaultFilter) => { + console.log('vaultMap in VaultPositionSelector.tsx: ', vaultMap); if (!vaultMap) return; const _filteredVaults = Array.from(vaultMap.values()) .filter((vault) => !dashHideInactiveVaults || vault.isActive) @@ -44,6 +45,7 @@ function VaultPositionSelector(target: any) { .sort((vaultA, vaultB) => (vaultA.art.lt(vaultB.art) ? 1 : -1)); setFilter({ base, series, ilk }); setFilteredVaults(_filteredVaults); + console.log('filteredVaults in VaultPositionSelector.tsx: ', _filteredVaults); }, [vaultMap, dashHideInactiveVaults] ); diff --git a/src/components/settings/SupportSettings.tsx b/src/components/settings/SupportSettings.tsx index c1e967209..75e2dc7f4 100644 --- a/src/components/settings/SupportSettings.tsx +++ b/src/components/settings/SupportSettings.tsx @@ -45,11 +45,11 @@ const SupportSettings = () => { const [allowSupport, setAllowSupport] = useState(false); useEffect(() => { const allowList = process.env.ALLOWED_SUPPORT_ADDRESSES ? process.env.ALLOWED_SUPPORT_ADDRESSES.split(',') : []; - if (address && allowList.includes(address)) { - setAllowSupport(true); - } else { - setAllowSupport(false); - } + // if (address && allowList.includes(address)) { + setAllowSupport(true); + // } else { + // setAllowSupport(false); + // } }, [address]); return ( diff --git a/src/components/views/Borrow.tsx b/src/components/views/Borrow.tsx index a59b82a44..6a41982c7 100644 --- a/src/components/views/Borrow.tsx +++ b/src/components/views/Borrow.tsx @@ -34,7 +34,7 @@ import { useInputValidation } from '../../hooks/useInputValidation'; import AltText from '../texts/AltText'; import YieldCardHeader from '../YieldCardHeader'; import { useBorrow } from '../../hooks/actionHooks/useBorrow'; -import { useCollateralHelpers } from '../../hooks/viewHelperHooks/useCollateralHelpers'; +import { useCollateralHelpers } from '../../hooks/higherOrderHooks/useCollateralHelpers'; import { useBorrowHelpers } from '../../hooks/viewHelperHooks/useBorrowHelpers'; import InputInfoWrap from '../wraps/InputInfoWrap'; import ColorText from '../texts/ColorText'; @@ -44,7 +44,7 @@ import DummyVaultItem from '../positionItems/DummyVaultItem'; import SeriesOrStrategySelectorModal from '../selectors/SeriesOrStrategySelectorModal'; import Navigation from '../Navigation'; import VaultItem from '../positionItems/VaultItem'; -import useAssetPair from '../../hooks/useAssetPair'; +import useAssetPair from '../../hooks/higherOrderHooks/useAssetPair'; import Line from '../elements/Line'; import { useAccount, useNetwork } from 'wagmi'; import { GA_Event, GA_Properties, GA_View } from '../../types/analytics'; @@ -53,6 +53,9 @@ import { WETH } from '../../config/assets'; import useContracts from '../../hooks/useContracts'; import useAccountPlus from '../../hooks/useAccountPlus'; +import VariableRate from '../selectors/VariableRate'; +import { useBorrowVariableRate } from '../../hooks/actionHooks/useBorrowVariableRate'; + const Borrow = () => { const mobile: boolean = useContext(ResponsiveContext) === 'small'; @@ -60,8 +63,17 @@ const Borrow = () => { /* STATE FROM CONTEXT */ const { userState, userActions } = useContext(UserContext); - const { assetMap, vaultMap, vaultsLoading, seriesMap, selectedSeries, selectedIlk, selectedBase, selectedVault } = - userState; + const { + assetMap, + vaultMap, + vaultsLoading, + seriesMap, + selectedSeries, + selectedIlk, + selectedBase, + selectedVault, + selectedVR, + } = userState; const { setSelectedIlk } = userActions; const { address: activeAccount } = useAccountPlus(); @@ -85,10 +97,15 @@ const Borrow = () => { const [currentGaugeColor, setCurrentGaugeColor] = useState('#EF4444'); const borrow = useBorrow(); + + const borrowVariableRate = useBorrowVariableRate(); + const { apr } = useApr(borrowInput, ActionType.BORROW, selectedSeries); + console.log('apr in borrow', apr); const { data: assetPair } = useAssetPair(selectedBase?.id, selectedIlk?.id); - const { validIlks } = useAssetPair(undefined, undefined, selectedSeries?.id); + + const { validIlks } = useAssetPair(selectedBase?.id, undefined, selectedSeries?.id); const { collateralizationPercent, @@ -100,7 +117,7 @@ const Borrow = () => { minCollatRatioPct, totalCollateral_, liquidationPrice_, - } = useCollateralHelpers(borrowInput, collatInput, vaultToUse, assetPair); + } = useCollateralHelpers(borrowInput, collatInput, vaultToUse, assetPair, selectedVR); const { minDebt_, maxDebt_, borrowPossible, borrowEstimate_ } = useBorrowHelpers( borrowInput, @@ -140,6 +157,10 @@ const Borrow = () => { } as GA_Properties.transaction_initiated); }; + const handleBorrowVariableRate = () => { + borrowVariableRate(undefined, borrowInput, collatInput); + }; + /** Interaction handlers */ const handleNavAction = (_stepPosition: number) => { _stepPosition === 0 && setSelectedIlk(selectedIlk || assetMap?.get('0x303000000000')!); @@ -183,7 +204,7 @@ const Borrow = () => { /* if ANY of the following conditions are met: block action */ !activeAccount || !borrowInput || - !selectedSeries || + (!selectedSeries && !selectedVR) || !selectedIlk || undercollateralized || borrowInputError || @@ -195,6 +216,7 @@ const Borrow = () => { borrowInput, collatInput, selectedSeries, + selectedVR, selectedIlk, activeAccount, borrowInputError, @@ -206,19 +228,29 @@ const Borrow = () => { /* if ANY of the following conditions are met: block next step action */ useEffect(() => { - !borrowInput || - !selectedSeries || - borrowInputError || - selectedSeries?.seriesIsMature || - (stepPosition === 1 && undercollateralized) || - (stepPosition === 1 && collatInputError) || - selectedSeries.baseId !== selectedBase?.proxyId - ? setStepDisabled(true) - : setStepDisabled(false); /* else if all pass, then unlock borrowing */ + if (!selectedVR) { + !borrowInput || + !selectedSeries || + borrowInputError || + selectedSeries?.seriesIsMature || + (stepPosition === 1 && undercollateralized) || + (stepPosition === 1 && collatInputError) || + selectedSeries.baseId !== selectedBase?.proxyId + ? setStepDisabled(true) + : setStepDisabled(false); /* else if all pass, then unlock borrowing */ + } else { + !borrowInput || + borrowInputError || + (stepPosition === 1 && undercollateralized) || + (stepPosition === 1 && collatInputError) + ? setStepDisabled(true) + : setStepDisabled(false); /* else if all pass, then unlock borrowing */ + } }, [ borrowInput, borrowInputError, selectedSeries, + selectedVR, activeAccount, stepPosition, collatInput, @@ -269,6 +301,7 @@ const Borrow = () => { /* make sure ilk is valid */ useEffect(() => { if (validIlks) { + console.log('validIlks in borrow useEffect', validIlks, typeof validIlks); !validIlks.map((a) => a.proxyId)?.includes(selectedIlk?.proxyId!) && setSelectedIlk(validIlks[0]); } }, [selectedIlk?.proxyId, setSelectedIlk, validIlks]); @@ -286,14 +319,14 @@ const Borrow = () => { {stepPosition === 0 && ( // INITIAL STEP - + BORROW Borrow popular ERC20 tokens at a{' '} - fixed rate + fixed or variable rate @@ -328,15 +361,20 @@ const Borrow = () => { setOpen={toggleModal} /> ) : ( - - - + + + + + + + + )} @@ -351,7 +389,7 @@ const Borrow = () => { )} - {!borrowInputError && borrowInput && borrowPossible && selectedSeries && ( + {!borrowInputError && borrowInput && borrowPossible && (selectedSeries || selectedVR) && ( Requires equivalent of {nFormatter(parseFloat(minCollateral_!), selectedIlk?.digitFormat!)}{' '} @@ -432,7 +470,7 @@ const Borrow = () => { onChange={(event: any) => setCollatInput(cleanValue(event.target.value, selectedIlk?.decimals)) } - disabled={!selectedSeries || selectedSeries.seriesIsMature} + disabled={(!selectedSeries || selectedSeries.seriesIsMature) && !selectedVR} /> maxCollateral && handleMaxAction(ActionCodes.ADD_COLLATERAL)} @@ -507,14 +545,23 @@ const Borrow = () => { icon={} value={`${cleanValue(borrowInput, selectedBase?.digitFormat!)} ${selectedBase?.displaySymbol}`} /> - } value={`${selectedSeries?.displayName}`} /> - } - value={`${cleanValue(borrowEstimate_, selectedBase?.digitFormat!)} ${ - selectedBase?.displaySymbol - }`} - /> + {!selectedVR && ( +
+ } + value={`${selectedSeries?.displayName}`} + /> + + } + value={`${cleanValue(borrowEstimate_, selectedBase?.digitFormat!)} ${ + selectedBase?.displaySymbol + }`} + /> +
+ )} } value={`${apr}%`} /> { // label={ Next step } label={ - {borrowInput && (!selectedSeries || selectedBase?.proxyId !== selectedSeries.baseId) + {borrowInput && (!selectedSeries || selectedBase?.proxyId !== selectedSeries.baseId) && !selectedVR ? `Select a${selectedBase?.id === WETH ? 'n' : ''} ${selectedBase?.displaySymbol}${ selectedBase && '-based' } Maturity` @@ -613,7 +660,8 @@ const Borrow = () => { } ${selectedBase?.displaySymbol || ''}`} } - onClick={() => handleBorrow()} + // onClick={() => handleBorrow()} + onClick={() => handleBorrowVariableRate()} disabled={borrowDisabled || borrowProcess?.processActive || !disclaimerChecked} /> )} diff --git a/src/components/views/VaultPosition.tsx b/src/components/views/VaultPosition.tsx index af09030b9..8d986c4ea 100644 --- a/src/components/views/VaultPosition.tsx +++ b/src/components/views/VaultPosition.tsx @@ -28,8 +28,11 @@ import ModalWrap from '../wraps/ModalWrap'; import { useCachedState } from '../../hooks/generalHooks'; import { useRepayDebt } from '../../hooks/actionHooks/useRepayDebt'; + +import { useRepayDebtVariableRate } from '../../hooks/actionHooks/useRepayDebtVariableRate'; + import { useRollDebt } from '../../hooks/actionHooks/useRollDebt'; -import { useCollateralHelpers } from '../../hooks/viewHelperHooks/useCollateralHelpers'; +import { useCollateralHelpers } from '../../hooks/higherOrderHooks/useCollateralHelpers'; import { useAddCollateral } from '../../hooks/actionHooks/useAddCollateral'; import { useRemoveCollateral } from '../../hooks/actionHooks/useRemoveCollateral'; import { useBorrowHelpers } from '../../hooks/viewHelperHooks/useBorrowHelpers'; @@ -38,7 +41,7 @@ import CopyWrap from '../wraps/CopyWrap'; import { useProcess } from '../../hooks/useProcess'; import ExitButton from '../buttons/ExitButton'; import { ZERO_BN } from '../../utils/constants'; -import useAssetPair from '../../hooks/useAssetPair'; +import useAssetPair from '../../hooks/higherOrderHooks/useAssetPair'; import Logo from '../logos/Logo'; import { useAccount, useBalance } from 'wagmi'; import useAnalytics from '../../hooks/useAnalytics'; @@ -66,6 +69,7 @@ const VaultPosition = () => { const vaultBase = assetMap?.get(_selectedVault?.baseId!); const vaultIlk = assetMap?.get(_selectedVault?.ilkId!); const vaultSeries = seriesMap?.get(_selectedVault?.seriesId!); + const vaultIsVR = !!_selectedVault?.seriesId; const { data: assetPair } = useAssetPair(vaultBase?.id, vaultIlk?.id); const { data: ilkBal } = useBalance({ @@ -127,6 +131,9 @@ const VaultPosition = () => { /* HOOK FNS */ const repay = useRepayDebt(); + + const repayVariableRate = useRepayDebtVariableRate(); + const rollDebt = useRollDebt(); const { logAnalyticsEvent } = useAnalytics(); @@ -142,23 +149,25 @@ const VaultPosition = () => { unhealthyCollatRatio, liquidationPrice_, minSafeCollatRatioPct, - } = useCollateralHelpers('0', '0', _selectedVault, assetPair); + } = useCollateralHelpers('0', '0', _selectedVault, assetPair, vaultIsVR); const { collateralizationPercent: repayCollEst } = useCollateralHelpers( `-${repayInput! || '0'}`, '0', _selectedVault, - assetPair + assetPair, + vaultIsVR ); const { collateralizationPercent: removeCollEst, unhealthyCollatRatio: removeCollEstUnhealthyRatio } = - useCollateralHelpers('0', `-${removeCollatInput! || '0'}`, _selectedVault, assetPair); + useCollateralHelpers('0', `-${removeCollatInput! || '0'}`, _selectedVault, assetPair, vaultIsVR); const { collateralizationPercent: addCollEst } = useCollateralHelpers( '0', `${addCollatInput! || '0'}`, _selectedVault, - assetPair + assetPair, + vaultIsVR ); const { @@ -214,9 +223,11 @@ const VaultPosition = () => { ); const handleRepay = () => { + console.log('%c handleRepay', 'color: #00ff00; font-size: 16px;', repayDisabled); if (repayDisabled) return; setRepayDisabled(true); - repay(_selectedVault!, repayInput?.toString(), reclaimCollateral); + // repay(_selectedVault!, repayInput?.toString(), reclaimCollateral); + repayVariableRate(_selectedVault!, repayInput?.toString(), reclaimCollateral); logAnalyticsEvent(GA_Event.transaction_initiated, { view: GA_View.BORROW, @@ -493,13 +504,22 @@ const VaultPosition = () => { dropProps={{ round: 'small' }} plain size="small" - options={[ - { text: 'Repay Debt', index: 0 }, - { text: 'Roll Vault', index: 1, disabled: !rollPossible }, - { text: 'Add More Collateral', index: 2 }, - { text: 'Remove Collateral', index: 3 }, - { text: 'View Transaction History', index: 4 }, - ]} + options={ + _selectedVault?.seriesId + ? [ + { text: 'Repay Debt', index: 0 }, + { text: 'Roll Vault', index: 1, disabled: !rollPossible }, + { text: 'Add More Collateral', index: 2 }, + { text: 'Remove Collateral', index: 3 }, + { text: 'View Transaction History', index: 4 }, + ] + : [ + { text: 'Repay Debt', index: 0 }, + { text: 'Add More Collateral', index: 2 }, + { text: 'Remove Collateral', index: 3 }, + { text: 'View Transaction History', index: 4 }, + ] + } icon={} labelKey="text" valueKey="index" diff --git a/src/config/contracts.ts b/src/config/contracts.ts index a6f2a8646..18e2351b0 100644 --- a/src/config/contracts.ts +++ b/src/config/contracts.ts @@ -28,6 +28,7 @@ const contractAddresses: ContractAddresses = { [ContractNames.VR_CAULDRON, '0x8fd04c6153a0e33afc669689c9bc36ae2e1e6501'], [ContractNames.LADLE, '0x6cB18fF2A33e981D1e38A663Ca056c0a5265066A'], [ContractNames.VR_LADLE, '0x35d8f478ce6597548256d02b374972a775df927d'], + [ContractNames.VR_WITCH, '0x1b831a29427c50ca412ef5c19eb2cf2a300a48a6'], [ContractNames.WITCH, '0x53C3760670f6091E1eC76B4dd27f73ba4CAd5061'], [ContractNames.WITCHV2, '0x08d2f5c96bb1f6be04b49bcd869d5af01db4c400'], [ContractNames.TRANSFER_1155_MODULE, '0x97f1d43A217aDD678bB6Dcd3C5D51F40b6729d06'], diff --git a/src/config/series.ts b/src/config/series.ts index ae3887057..043e5df42 100644 --- a/src/config/series.ts +++ b/src/config/series.ts @@ -60,14 +60,12 @@ const WETH_2306 = '0x0030ff00028b'; const WETH_2309 = '0x0030ff00028e'; const FRAX_2306 = '0x0138ff00028b'; - const FRAX_2309 = '0x0138ff00028e'; const USDT_2306 = '0x00a0ff00028b'; const USDT_2303 = '0x00a0ff000288'; const USDT_2309 = '0x00a0ff00028e'; - export const validateSeries = async (provider: BaseProvider, cauldronAddress: string) => { const preText = '### SERIES SET VALIDATION ERROR ### '; const chainId = (await provider.getNetwork()).chainId; @@ -621,7 +619,7 @@ SERIES.set( ts: '12989823246', g1: '16602069666338596454', g2: '20496382304121724017', - allowActions: [ActionCodes.REPAY], + allowActions: [ActionCodes.REPAY, ActionCodes.BORROW], }, ], diff --git a/src/contexts/HistoryContext.tsx b/src/contexts/HistoryContext.tsx index 6bbb9dc1f..c4aea428f 100644 --- a/src/contexts/HistoryContext.tsx +++ b/src/contexts/HistoryContext.tsx @@ -17,12 +17,13 @@ import { import { ChainContext } from './ChainContext'; import { abbreviateHash, cleanValue } from '../utils/appUtils'; import { ZERO_BN } from '../utils/constants'; -import { Cauldron } from '../contracts'; +import { Cauldron, VRCauldron } from '../contracts'; import { SettingsContext } from './SettingsContext'; import { TransferEvent } from '../contracts/Strategy'; import { LiquidityEvent, TradeEvent } from '../contracts/Pool'; import { VaultGivenEvent, VaultPouredEvent, VaultRolledEvent } from '../contracts/Cauldron'; +import { VaultPouredEvent as VRVaultPouredEvent } from '../contracts/VRCauldron'; import { useAccount, useProvider } from 'wagmi'; import useContracts from '../hooks/useContracts'; @@ -383,6 +384,71 @@ const HistoryProvider = ({ children }: any) => { [assetRootMap, provider] ); + // new function to parse VR pour logs + const _parseVRPourLogs = useCallback( + (eventList: VRVaultPouredEvent[], contract: VRCauldron, vault: IVault) => { + return Promise.all( + eventList.map(async (e) => { + const { blockNumber, transactionHash } = e; + + // event VaultPoured(bytes12 indexed vaultId, bytes6 indexed seriesId, bytes6 indexed ilkId, int128 ink, int128 art) + const { ilkId, ink, art, baseId } = e.args; + const base_ = assetRootMap.get(baseId); + const ilk = assetRootMap.get(ilkId); + const date = (await provider.getBlock(blockNumber)).timestamp; + + const actionCode = _inferTransactionType(art, ink); + + let primaryInfo: string = ''; + if (actionCode === ActionCodes.BORROW) + primaryInfo = ` + ${cleanValue( + ethers.utils.formatUnits(vault.art, base_?.decimals), + base_?.digitFormat! + )} ${base_?.displaySymbol!} @ + ${cleanValue(vault.rate_, 2)}%`; + /* + will need to uncomment and test below when we have a fork + with the wrap module - jacob b + */ + // else if (actionCode === ActionCodes.REPAY) + // primaryInfo = `${cleanValue( + // ethers.utils.formatUnits(baseTraded.abs(), base_?.decimals), + // base_?.digitFormat! + // )} ${base_?.displaySymbol!}`; + else if (actionCode === ActionCodes.ADD_COLLATERAL || actionCode === ActionCodes.REMOVE_COLLATERAL) + primaryInfo = `${cleanValue(ethers.utils.formatUnits(ink, ilk?.decimals), ilk?.digitFormat!)} ${ + ilk?.displaySymbol + }`; + + console.log('primaryInfo', primaryInfo, base_, cleanValue(vault.rate_, 2), vault); + + return { + /* histItem base */ + blockNumber, + date, + transactionHash, + actionCode, + primaryInfo, + + /* args info */ + ilkId, + ink, + art, + baseId, + + /* Formatted values: */ + date_: dateFormat(date), + ink_: ethers.utils.formatUnits(ink, 18), + art_: ethers.utils.formatUnits(art, base_?.decimals), + }; + // as IBaseHistItem; + }) + ); + }, + [assetRootMap, provider] + ); + const _parseGivenLogs = useCallback( (eventList: VaultGivenEvent[], contract: Cauldron, series: ISeries) => Promise.all( @@ -446,6 +512,7 @@ const HistoryProvider = ({ children }: any) => { const vaultHistMap = new Map([]); const cauldronContract = contracts.get(ContractNames.CAULDRON) as Cauldron; + const VRcauldronContract = contracts.get(ContractNames.VR_CAULDRON) as VRCauldron; /* Get all the Vault historical Pour transactions */ await Promise.all( @@ -465,6 +532,14 @@ const HistoryProvider = ({ children }: any) => { cauldronContract.queryFilter(rolledFilter, useForkedEnv ? forkStartBlock : 'earliest'), ]); + /* get VR logs */ + const [vrPourEventList, vrGivenEventList] = await Promise.all([ + VRcauldronContract.queryFilter(pourFilter, useForkedEnv ? forkStartBlock : 'earliest'), + VRcauldronContract.queryFilter(givenFilter, useForkedEnv ? forkStartBlock : 'earliest'), + ]); + + console.log('%c eventList', 'font-size: 36px; color: yellow;', vrPourEventList, vault); + /* parse/process the log information */ const [pourLogs, givenLogs, rolledLogs] = await Promise.all([ _parsePourLogs(pourEventList, cauldronContract, series), @@ -472,7 +547,12 @@ const HistoryProvider = ({ children }: any) => { _parseRolledLogs(rolledEventList, cauldronContract, series), ]); - const combinedLogs = [...pourLogs, ...givenLogs, ...rolledLogs].sort((a, b) => a.blockNumber - b.blockNumber); + /* VR data */ + const [vrPourLogs] = await Promise.all([_parseVRPourLogs(vrPourEventList, VRcauldronContract, vault)]); + + const combinedLogs = [...pourLogs, ...givenLogs, ...rolledLogs, ...vrPourLogs].sort( + (a, b) => a.blockNumber - b.blockNumber + ); vaultHistMap.set(vaultId, combinedLogs); }) ); diff --git a/src/contexts/SettingsContext.tsx b/src/contexts/SettingsContext.tsx index 013d376c6..15b9cbb13 100644 --- a/src/contexts/SettingsContext.tsx +++ b/src/contexts/SettingsContext.tsx @@ -39,11 +39,11 @@ const initState: ISettingsContextState = { /* Development settings */ /* Always force transctions to the chain -> even if they will likely fail */ - forceTransactions: false, + forceTransactions: true, /* Show diagnostic messages in the console */ - diagnostics: false, - + diagnostics: true, + /* use a forked network */ useForkedEnv: false, forkEnvUrl: @@ -69,7 +69,6 @@ const SettingsContext = createContext<{ }); function settingsReducer(state: ISettingsContextState, action: SettingsContextAction): ISettingsContextState { - /* Helper: if different from existing , update the state and cache */ const cacheAndUpdate = (_action: SettingsContextAction) => { if (state[action.type] === _action.payload) { @@ -82,7 +81,6 @@ function settingsReducer(state: ISettingsContextState, action: SettingsContextAc } const SettingsProvider = ({ children }: { children: ReactNode }) => { - /* LOCAL STATE */ const [settingsState, updateState] = useReducer(settingsReducer, initState); diff --git a/src/contexts/UserContext.tsx b/src/contexts/UserContext.tsx index e5959f754..d1f461f5d 100644 --- a/src/contexts/UserContext.tsx +++ b/src/contexts/UserContext.tsx @@ -15,7 +15,17 @@ import { } from '@yield-protocol/ui-math'; import Decimal from 'decimal.js'; -import { IAssetRoot, ISeriesRoot, IVaultRoot, ISeries, IAsset, IVault, IStrategyRoot, IStrategy } from '../types'; +import { + IAssetRoot, + ISeriesRoot, + IVaultRoot, + ISeries, + IAsset, + IVault, + IStrategyRoot, + IStrategy, + IVaultVR, +} from '../types'; import { ChainContext } from './ChainContext'; import { cleanValue, generateVaultName } from '../utils/appUtils'; @@ -55,6 +65,7 @@ const initState: IUserContextState = { selectedBase: null, // initial base selectedVault: null, selectedStrategy: null, + selectedVR: null, }; const initActions: IUserContextActions = { @@ -67,6 +78,7 @@ const initActions: IUserContextActions = { setSelectedSeries: () => null, setSelectedBase: () => null, setSelectedStrategy: () => null, + setSelectedVR: () => null, }; const UserContext = createContext<{ @@ -116,6 +128,8 @@ function userReducer(state: IUserContextState, action: UserContextAction): IUser case UserState.SELECTED_STRATEGY: return { ...state, selectedStrategy: action.payload }; + case UserState.SELECTED_VR: + return { ...state, selectedVR: action.payload }; default: return state; } @@ -195,6 +209,7 @@ const UserProvider = ({ children }: { children: ReactNode }) => { if (!contracts) return; const Cauldron = contracts.get(ContractNames.CAULDRON) as contractTypes.Cauldron; + const VRCauldron = contracts.get(ContractNames.VR_CAULDRON) as contractTypes.VRCauldron; const cacheKey = `vaults_${account}_${chainId}`; const cachedVaults = JSON.parse(localStorage.getItem(cacheKey)!); @@ -222,6 +237,25 @@ const UserProvider = ({ children }: { children: ReactNode }) => { }; }); + console.log('vaults built', vaultsBuilt); + + /* get a list of the VR vaults that were BUILT */ + const VRvaultsBuiltFilter = VRCauldron.filters.VaultBuilt(null, account, null); + const VRvaultsBuilt = (await VRCauldron.queryFilter(VRvaultsBuiltFilter!, lastVaultUpdate)) || []; + const VRbuildEventList = VRvaultsBuilt.map((x) => { + const { vaultId: id, ilkId, baseId } = x.args; + const asset = assetRootMap.get(baseId); + return { + id, + baseId, + ilkId, + displayName: generateVaultName(id), + decimals: asset?.decimals!, + }; + }); + + console.log('vaults built VR', VRvaultsBuilt); + /* Get a list of the vaults that were RECEIVED */ const vaultsReceivedFilter = Cauldron.filters.VaultGiven(null, account); const vaultsReceived = (await Cauldron.queryFilter(vaultsReceivedFilter, lastVaultUpdate)) || []; @@ -241,8 +275,45 @@ const UserProvider = ({ children }: { children: ReactNode }) => { }) ); + console.log('vaults received', vaultsReceived); + + /* get a list of VR vaults that were RECEIVED */ + const VRvaultsReceivedFilter = VRCauldron.filters.VaultGiven(null, account); + const VRvaultsReceived = (await VRCauldron.queryFilter(VRvaultsReceivedFilter, lastVaultUpdate)) || []; + const VRreceivedEventsList = await Promise.all( + VRvaultsReceived.map(async (x): Promise => { + const { vaultId: id } = x.args; + const { ilkId, baseId } = await VRCauldron.vaults(id); + const asset = assetRootMap.get(baseId); + return { + id, + baseId, + ilkId, + displayName: generateVaultName(id), + decimals: asset?.decimals!, + }; + }) + ); + + console.log('vaults received VR', VRvaultsReceived); + /* all vaults */ - const allVaultList = [...buildEventList, ...receivedEventsList, ...cachedVaultList]; + const allVaultList = [ + ...buildEventList, + ...receivedEventsList, + ...cachedVaultList, // this is causing us to have vault dupes - is this intentional? + ...VRbuildEventList, + ...VRvaultsReceived, + ]; + + console.log( + 'allVaultList components', + buildEventList, + receivedEventsList, + cachedVaultList, + VRbuildEventList, + VRvaultsReceived + ); /* Cache results */ const latestBlock = (await provider.getBlockNumber()).toString(); @@ -622,8 +693,10 @@ const UserProvider = ({ children }: { children: ReactNode }) => { let _vaults: IVaultRoot[] | undefined = vaultList; const Cauldron = contracts.get(ContractNames.CAULDRON) as contractTypes.Cauldron; + const VRCauldron = contracts.get(ContractNames.VR_CAULDRON) as contractTypes.VRCauldron; const WitchV1 = contracts.get(ContractNames.WITCH) as contractTypes.Witch; const Witch = contracts.get(ContractNames.WITCHV2) as contractTypes.WitchV2; + const VRWitch = contracts.get(ContractNames.VR_WITCH) as contractTypes.VRWitch; /** * if vaultList is empty, clear local app memory and fetch complete Vaultlist from chain via _getVaults */ @@ -635,17 +708,77 @@ const UserProvider = ({ children }: { children: ReactNode }) => { /* if fetching vaults fails */ if (!_vaults) return; + console.log('Updating _vaults with dynamic data ...', _vaults); + const updatedVaults = await Promise.all( _vaults.map(async (vault) => { + // check for a series id. if there isn't one, we know its VR and need + // to use the VR contracts + if (!vault.seriesId) { + // VR vault logic + console.log('VR vault here: ', vault); + + const [{ ink, art }, { owner, ilkId, baseId }] = await Promise.all([ + VRCauldron?.balances(vault.id), // change this back to CAULDRON + VRCauldron?.vaults(vault.id), + ]); + + // console.log('VR vault res: ', res, vault.id); + // return; + + const baseRoot = assetRootMap.get(baseId); + const ilkRoot = assetRootMap.get(ilkId); + if (!baseRoot) return; + + const liquidationEvents = !useForkedEnv + ? await VRWitch.queryFilter(Witch.filters.Bought(bytesToBytes32(vault.id, 12), null, null, null)) + : []; + const hasBeenLiquidated = liquidationEvents.flat().length > 0; + + // looking for a rate - seems to always return 1 - jacob b + const rateOracleAddr = await VRCauldron.rateOracles(vault.baseId); + const RateOracle = contractTypes.CompoundMultiOracle__factory.connect(rateOracleAddr, provider); // using compount multi here, but all rate oracles follow the same func sig methodology + + let accruedArt: BigNumber = art; + // let rate: BigNumber = BigNumber.from('1'); + let rate: BigNumber; + + [rate] = await RateOracle.peek(bytesToBytes32(vault.baseId, 6), RATE, '0'); + + console.log('%c VR rate: ', 'color: #00ff00; font-size: 36px;', rate.toString(), vault.baseId); + + const newVault: IVaultVR = { + ...vault, + owner, // refreshed in case owner has been updated + isWitchOwner: Witch.address === owner || WitchV1.address === owner, // check if witch is the owner (in liquidation process) + hasBeenLiquidated, + isActive: owner === account, // refreshed in case owner has been updated + ilkId, // refreshed in case ilkId has been updated + ink, + art, + accruedArt, + rate, + + rate_: cleanValue(ethers.utils.formatUnits(rate, 18), 2), // always 18 decimals when getting rate from rate oracle, + ink_: cleanValue(ethers.utils.formatUnits(ink, ilkRoot?.decimals), ilkRoot?.digitFormat), // for display purposes only + art_: cleanValue(ethers.utils.formatUnits(art, baseRoot?.decimals), baseRoot?.digitFormat), // for display purposes only + accruedArt_: cleanValue(ethers.utils.formatUnits(accruedArt, baseRoot?.decimals), baseRoot?.digitFormat), // display purposes + }; + + return newVault; + } + const [ { ink, art }, { owner, seriesId, ilkId }, // update balance and series (series - because a vault can have been rolled to another series) */ ] = await Promise.all([Cauldron?.balances(vault.id), Cauldron?.vaults(vault.id)]); + console.log('regular cauldron', Cauldron); + const series = seriesRootMap.get(seriesId); if (!series) return; - const isVaultMature = isMature(series.maturity); + const isVaultMature = isMature(series?.maturity!); const liquidationEvents = !useForkedEnv ? await Promise.all([ @@ -703,6 +836,8 @@ const UserProvider = ({ children }: { children: ReactNode }) => { }) ); + console.log('updatedVaults: ', updatedVaults); + const newVaultMap = updatedVaults.reduce((acc, item) => { if (item) { return acc.set(item.id, item); @@ -773,7 +908,7 @@ const UserProvider = ({ children }: { children: ReactNode }) => { [] ), setSelectedSeries: useCallback( - (series: ISeries | null) => updateState({ type: UserState.SELECTED_SERIES, payload: series! }), + (series: ISeries | null | string) => updateState({ type: UserState.SELECTED_SERIES, payload: series! }), [] ), setSelectedBase: useCallback( @@ -784,6 +919,10 @@ const UserProvider = ({ children }: { children: ReactNode }) => { (strategy: IStrategy | null) => updateState({ type: UserState.SELECTED_STRATEGY, payload: strategy! }), [] ), + setSelectedVR: useCallback((vr: boolean) => { + updateState({ type: UserState.SELECTED_VR, payload: vr }); + console.log('%c setSelectedVR', 'color: #00ff00; font-size: 24px;', vr); + }, []), } as IUserContextActions; return {children}; diff --git a/src/contexts/types/user.ts b/src/contexts/types/user.ts index 7e26c8c71..cf5384c5a 100644 --- a/src/contexts/types/user.ts +++ b/src/contexts/types/user.ts @@ -16,6 +16,7 @@ export interface IUserContextActions { setSelectedBase: (base: IAsset | null) => void; setSelectedVault: (vault: IVault | IDummyVault | null) => void; setSelectedStrategy: (strategy: IStrategy | null) => void; + setSelectedVR: (vr: boolean | null) => void; } export interface IUserContextState { @@ -36,7 +37,7 @@ export interface IUserContextState { selectedBase: IAsset | null; selectedVault: IVault | null; selectedStrategy: IStrategy | null; - + selectedVR: boolean | null; } export enum UserState { @@ -59,7 +60,7 @@ export enum UserState { SELECTED_ILK = 'selectedIlk', SELECTED_BASE = 'selectedBase', SELECTED_STRATEGY = 'selectedStrategy', - + SELECTED_VR = 'selectedVR', } export type UserLoadingAction = { @@ -125,18 +126,21 @@ export type SelectedIlkAction = { payload: IAsset; }; - export type SelectedBaseAction = { type: UserState.SELECTED_BASE; payload: IAsset; }; - export type SelectedStrategyAction = { type: UserState.SELECTED_STRATEGY; payload: IStrategy; }; +export type SelectedVRAction = { + type: UserState.SELECTED_VR; + payload: boolean; +}; + export type UserContextAction = | UserLoadingAction | VaultsLoadingAction @@ -152,4 +156,5 @@ export type UserContextAction = | SelectedSeriesAction | SelectedIlkAction | SelectedBaseAction - | SelectedStrategyAction; + | SelectedStrategyAction + | SelectedVRAction; diff --git a/src/contracts/VRWitch.d.ts b/src/contracts/VRWitch.d.ts new file mode 100644 index 000000000..4c6f3dca3 --- /dev/null +++ b/src/contracts/VRWitch.d.ts @@ -0,0 +1,1563 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { + ethers, + EventFilter, + Signer, + BigNumber, + BigNumberish, + PopulatedTransaction, + BaseContract, + ContractTransaction, + Overrides, + CallOverrides, +} from "ethers"; +import { BytesLike } from "@ethersproject/bytes"; +import { Listener, Provider } from "@ethersproject/providers"; +import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi"; +import type { TypedEventFilter, TypedEvent, TypedListener } from "./common"; + +interface VRWitchInterface extends ethers.utils.Interface { + functions: { + "LOCK()": FunctionFragment; + "LOCK8605463013()": FunctionFragment; + "ONE_HUNDRED_PERCENT()": FunctionFragment; + "ONE_PERCENT()": FunctionFragment; + "ROOT()": FunctionFragment; + "ROOT4146650865()": FunctionFragment; + "auction(bytes12,address)": FunctionFragment; + "auctioneerReward()": FunctionFragment; + "auctions(bytes12)": FunctionFragment; + "calcPayout(bytes12,address,uint256)": FunctionFragment; + "cancel(bytes12)": FunctionFragment; + "cauldron()": FunctionFragment; + "clear(bytes12)": FunctionFragment; + "getRoleAdmin(bytes4)": FunctionFragment; + "grantRole(bytes4,address)": FunctionFragment; + "grantRoles(bytes4[],address)": FunctionFragment; + "hasRole(bytes4,address)": FunctionFragment; + "ladle()": FunctionFragment; + "limits(bytes6,bytes6)": FunctionFragment; + "lines(bytes6,bytes6)": FunctionFragment; + "lockRole(bytes4)": FunctionFragment; + "payBase(bytes12,address,uint128,uint128)": FunctionFragment; + "point(bytes32,address)": FunctionFragment; + "protected(address)": FunctionFragment; + "renounceRole(bytes4,address)": FunctionFragment; + "revokeRole(bytes4,address)": FunctionFragment; + "revokeRoles(bytes4[],address)": FunctionFragment; + "setAuctioneerReward(uint256)": FunctionFragment; + "setLineAndLimit(bytes6,bytes6,uint32,uint64,uint64,uint128)": FunctionFragment; + "setProtected(address,bool)": FunctionFragment; + "setRoleAdmin(bytes4,bytes4)": FunctionFragment; + }; + + encodeFunctionData(functionFragment: "LOCK", values?: undefined): string; + encodeFunctionData( + functionFragment: "LOCK8605463013", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "ONE_HUNDRED_PERCENT", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "ONE_PERCENT", + values?: undefined + ): string; + encodeFunctionData(functionFragment: "ROOT", values?: undefined): string; + encodeFunctionData( + functionFragment: "ROOT4146650865", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "auction", + values: [BytesLike, string] + ): string; + encodeFunctionData( + functionFragment: "auctioneerReward", + values?: undefined + ): string; + encodeFunctionData(functionFragment: "auctions", values: [BytesLike]): string; + encodeFunctionData( + functionFragment: "calcPayout", + values: [BytesLike, string, BigNumberish] + ): string; + encodeFunctionData(functionFragment: "cancel", values: [BytesLike]): string; + encodeFunctionData(functionFragment: "cauldron", values?: undefined): string; + encodeFunctionData(functionFragment: "clear", values: [BytesLike]): string; + encodeFunctionData( + functionFragment: "getRoleAdmin", + values: [BytesLike] + ): string; + encodeFunctionData( + functionFragment: "grantRole", + values: [BytesLike, string] + ): string; + encodeFunctionData( + functionFragment: "grantRoles", + values: [BytesLike[], string] + ): string; + encodeFunctionData( + functionFragment: "hasRole", + values: [BytesLike, string] + ): string; + encodeFunctionData(functionFragment: "ladle", values?: undefined): string; + encodeFunctionData( + functionFragment: "limits", + values: [BytesLike, BytesLike] + ): string; + encodeFunctionData( + functionFragment: "lines", + values: [BytesLike, BytesLike] + ): string; + encodeFunctionData(functionFragment: "lockRole", values: [BytesLike]): string; + encodeFunctionData( + functionFragment: "payBase", + values: [BytesLike, string, BigNumberish, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "point", + values: [BytesLike, string] + ): string; + encodeFunctionData(functionFragment: "protected", values: [string]): string; + encodeFunctionData( + functionFragment: "renounceRole", + values: [BytesLike, string] + ): string; + encodeFunctionData( + functionFragment: "revokeRole", + values: [BytesLike, string] + ): string; + encodeFunctionData( + functionFragment: "revokeRoles", + values: [BytesLike[], string] + ): string; + encodeFunctionData( + functionFragment: "setAuctioneerReward", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "setLineAndLimit", + values: [ + BytesLike, + BytesLike, + BigNumberish, + BigNumberish, + BigNumberish, + BigNumberish + ] + ): string; + encodeFunctionData( + functionFragment: "setProtected", + values: [string, boolean] + ): string; + encodeFunctionData( + functionFragment: "setRoleAdmin", + values: [BytesLike, BytesLike] + ): string; + + decodeFunctionResult(functionFragment: "LOCK", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "LOCK8605463013", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "ONE_HUNDRED_PERCENT", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "ONE_PERCENT", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "ROOT", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "ROOT4146650865", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "auction", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "auctioneerReward", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "auctions", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "calcPayout", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "cancel", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "cauldron", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "clear", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "getRoleAdmin", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "grantRole", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "grantRoles", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "hasRole", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "ladle", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "limits", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "lines", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "lockRole", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "payBase", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "point", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "protected", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "renounceRole", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "revokeRole", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "revokeRoles", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "setAuctioneerReward", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "setLineAndLimit", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "setProtected", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "setRoleAdmin", + data: BytesLike + ): Result; + + events: { + "Auctioned(bytes12,tuple,uint256,uint256)": EventFragment; + "AuctioneerRewardSet(uint256)": EventFragment; + "Bought(bytes12,address,uint256,uint256)": EventFragment; + "Cancelled(bytes12)": EventFragment; + "Cleared(bytes12)": EventFragment; + "Ended(bytes12)": EventFragment; + "LimitSet(bytes6,bytes6,uint128)": EventFragment; + "LineSet(bytes6,bytes6,uint32,uint64,uint64)": EventFragment; + "Point(bytes32,address,address)": EventFragment; + "ProtectedSet(address,bool)": EventFragment; + "RoleAdminChanged(bytes4,bytes4)": EventFragment; + "RoleGranted(bytes4,address,address)": EventFragment; + "RoleRevoked(bytes4,address,address)": EventFragment; + }; + + getEvent(nameOrSignatureOrTopic: "Auctioned"): EventFragment; + getEvent(nameOrSignatureOrTopic: "AuctioneerRewardSet"): EventFragment; + getEvent(nameOrSignatureOrTopic: "Bought"): EventFragment; + getEvent(nameOrSignatureOrTopic: "Cancelled"): EventFragment; + getEvent(nameOrSignatureOrTopic: "Cleared"): EventFragment; + getEvent(nameOrSignatureOrTopic: "Ended"): EventFragment; + getEvent(nameOrSignatureOrTopic: "LimitSet"): EventFragment; + getEvent(nameOrSignatureOrTopic: "LineSet"): EventFragment; + getEvent(nameOrSignatureOrTopic: "Point"): EventFragment; + getEvent(nameOrSignatureOrTopic: "ProtectedSet"): EventFragment; + getEvent(nameOrSignatureOrTopic: "RoleAdminChanged"): EventFragment; + getEvent(nameOrSignatureOrTopic: "RoleGranted"): EventFragment; + getEvent(nameOrSignatureOrTopic: "RoleRevoked"): EventFragment; +} + +export type AuctionedEvent = TypedEvent< + [ + string, + [string, number, string, BigNumber, BigNumber, string, string, string] & { + owner: string; + start: number; + baseId: string; + ink: BigNumber; + art: BigNumber; + auctioneer: string; + ilkId: string; + seriesId: string; + }, + BigNumber, + BigNumber + ] & { + vaultId: string; + auction: [ + string, + number, + string, + BigNumber, + BigNumber, + string, + string, + string + ] & { + owner: string; + start: number; + baseId: string; + ink: BigNumber; + art: BigNumber; + auctioneer: string; + ilkId: string; + seriesId: string; + }; + duration: BigNumber; + initialCollateralProportion: BigNumber; + } +>; + +export type AuctioneerRewardSetEvent = TypedEvent< + [BigNumber] & { auctioneerReward: BigNumber } +>; + +export type BoughtEvent = TypedEvent< + [string, string, BigNumber, BigNumber] & { + vaultId: string; + buyer: string; + ink: BigNumber; + art: BigNumber; + } +>; + +export type CancelledEvent = TypedEvent<[string] & { vaultId: string }>; + +export type ClearedEvent = TypedEvent<[string] & { vaultId: string }>; + +export type EndedEvent = TypedEvent<[string] & { vaultId: string }>; + +export type LimitSetEvent = TypedEvent< + [string, string, BigNumber] & { + ilkId: string; + baseId: string; + max: BigNumber; + } +>; + +export type LineSetEvent = TypedEvent< + [string, string, number, BigNumber, BigNumber] & { + ilkId: string; + baseId: string; + duration: number; + vaultProportion: BigNumber; + collateralProportion: BigNumber; + } +>; + +export type PointEvent = TypedEvent< + [string, string, string] & { + param: string; + oldValue: string; + newValue: string; + } +>; + +export type ProtectedSetEvent = TypedEvent< + [string, boolean] & { value: string; protected: boolean } +>; + +export type RoleAdminChangedEvent = TypedEvent< + [string, string] & { role: string; newAdminRole: string } +>; + +export type RoleGrantedEvent = TypedEvent< + [string, string, string] & { role: string; account: string; sender: string } +>; + +export type RoleRevokedEvent = TypedEvent< + [string, string, string] & { role: string; account: string; sender: string } +>; + +export class VRWitch extends BaseContract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + listeners, EventArgsObject>( + eventFilter?: TypedEventFilter + ): Array>; + off, EventArgsObject>( + eventFilter: TypedEventFilter, + listener: TypedListener + ): this; + on, EventArgsObject>( + eventFilter: TypedEventFilter, + listener: TypedListener + ): this; + once, EventArgsObject>( + eventFilter: TypedEventFilter, + listener: TypedListener + ): this; + removeListener, EventArgsObject>( + eventFilter: TypedEventFilter, + listener: TypedListener + ): this; + removeAllListeners, EventArgsObject>( + eventFilter: TypedEventFilter + ): this; + + listeners(eventName?: string): Array; + off(eventName: string, listener: Listener): this; + on(eventName: string, listener: Listener): this; + once(eventName: string, listener: Listener): this; + removeListener(eventName: string, listener: Listener): this; + removeAllListeners(eventName?: string): this; + + queryFilter, EventArgsObject>( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + + interface: VRWitchInterface; + + functions: { + LOCK(overrides?: CallOverrides): Promise<[string]>; + + LOCK8605463013(overrides?: CallOverrides): Promise<[string]>; + + ONE_HUNDRED_PERCENT(overrides?: CallOverrides): Promise<[BigNumber]>; + + ONE_PERCENT(overrides?: CallOverrides): Promise<[BigNumber]>; + + ROOT(overrides?: CallOverrides): Promise<[string]>; + + ROOT4146650865(overrides?: CallOverrides): Promise<[string]>; + + auction( + vaultId: BytesLike, + to: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + auctioneerReward(overrides?: CallOverrides): Promise<[BigNumber]>; + + auctions( + arg0: BytesLike, + overrides?: CallOverrides + ): Promise< + [string, number, string, BigNumber, BigNumber, string, string, string] & { + owner: string; + start: number; + baseId: string; + ink: BigNumber; + art: BigNumber; + auctioneer: string; + ilkId: string; + seriesId: string; + } + >; + + calcPayout( + vaultId: BytesLike, + to: string, + maxArtIn: BigNumberish, + overrides?: CallOverrides + ): Promise< + [BigNumber, BigNumber, BigNumber] & { + liquidatorCut: BigNumber; + auctioneerCut: BigNumber; + artIn: BigNumber; + } + >; + + cancel( + vaultId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + cauldron(overrides?: CallOverrides): Promise<[string]>; + + clear( + vaultId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + getRoleAdmin(role: BytesLike, overrides?: CallOverrides): Promise<[string]>; + + grantRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + grantRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise<[boolean]>; + + ladle(overrides?: CallOverrides): Promise<[string]>; + + limits( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise<[BigNumber, BigNumber] & { max: BigNumber; sum: BigNumber }>; + + lines( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise< + [number, BigNumber, BigNumber] & { + duration: number; + vaultProportion: BigNumber; + collateralProportion: BigNumber; + } + >; + + lockRole( + role: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + payBase( + vaultId: BytesLike, + to: string, + minInkOut: BigNumberish, + maxBaseIn: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + point( + param: BytesLike, + value: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + protected(arg0: string, overrides?: CallOverrides): Promise<[boolean]>; + + renounceRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setAuctioneerReward( + auctioneerReward_: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setLineAndLimit( + ilkId: BytesLike, + baseId: BytesLike, + duration: BigNumberish, + vaultProportion: BigNumberish, + collateralProportion: BigNumberish, + max: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setProtected( + owner: string, + _protected: boolean, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setRoleAdmin( + role: BytesLike, + adminRole: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + }; + + LOCK(overrides?: CallOverrides): Promise; + + LOCK8605463013(overrides?: CallOverrides): Promise; + + ONE_HUNDRED_PERCENT(overrides?: CallOverrides): Promise; + + ONE_PERCENT(overrides?: CallOverrides): Promise; + + ROOT(overrides?: CallOverrides): Promise; + + ROOT4146650865(overrides?: CallOverrides): Promise; + + auction( + vaultId: BytesLike, + to: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + auctioneerReward(overrides?: CallOverrides): Promise; + + auctions( + arg0: BytesLike, + overrides?: CallOverrides + ): Promise< + [string, number, string, BigNumber, BigNumber, string, string, string] & { + owner: string; + start: number; + baseId: string; + ink: BigNumber; + art: BigNumber; + auctioneer: string; + ilkId: string; + seriesId: string; + } + >; + + calcPayout( + vaultId: BytesLike, + to: string, + maxArtIn: BigNumberish, + overrides?: CallOverrides + ): Promise< + [BigNumber, BigNumber, BigNumber] & { + liquidatorCut: BigNumber; + auctioneerCut: BigNumber; + artIn: BigNumber; + } + >; + + cancel( + vaultId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + cauldron(overrides?: CallOverrides): Promise; + + clear( + vaultId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + getRoleAdmin(role: BytesLike, overrides?: CallOverrides): Promise; + + grantRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + grantRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + ladle(overrides?: CallOverrides): Promise; + + limits( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise<[BigNumber, BigNumber] & { max: BigNumber; sum: BigNumber }>; + + lines( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise< + [number, BigNumber, BigNumber] & { + duration: number; + vaultProportion: BigNumber; + collateralProportion: BigNumber; + } + >; + + lockRole( + role: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + payBase( + vaultId: BytesLike, + to: string, + minInkOut: BigNumberish, + maxBaseIn: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + point( + param: BytesLike, + value: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + protected(arg0: string, overrides?: CallOverrides): Promise; + + renounceRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setAuctioneerReward( + auctioneerReward_: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setLineAndLimit( + ilkId: BytesLike, + baseId: BytesLike, + duration: BigNumberish, + vaultProportion: BigNumberish, + collateralProportion: BigNumberish, + max: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setProtected( + owner: string, + _protected: boolean, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setRoleAdmin( + role: BytesLike, + adminRole: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + callStatic: { + LOCK(overrides?: CallOverrides): Promise; + + LOCK8605463013(overrides?: CallOverrides): Promise; + + ONE_HUNDRED_PERCENT(overrides?: CallOverrides): Promise; + + ONE_PERCENT(overrides?: CallOverrides): Promise; + + ROOT(overrides?: CallOverrides): Promise; + + ROOT4146650865(overrides?: CallOverrides): Promise; + + auction( + vaultId: BytesLike, + to: string, + overrides?: CallOverrides + ): Promise< + [ + [ + string, + number, + string, + BigNumber, + BigNumber, + string, + string, + string + ] & { + owner: string; + start: number; + baseId: string; + ink: BigNumber; + art: BigNumber; + auctioneer: string; + ilkId: string; + seriesId: string; + }, + [string, string, string] & { + owner: string; + baseId: string; + ilkId: string; + } + ] & { + auction_: [ + string, + number, + string, + BigNumber, + BigNumber, + string, + string, + string + ] & { + owner: string; + start: number; + baseId: string; + ink: BigNumber; + art: BigNumber; + auctioneer: string; + ilkId: string; + seriesId: string; + }; + vault: [string, string, string] & { + owner: string; + baseId: string; + ilkId: string; + }; + } + >; + + auctioneerReward(overrides?: CallOverrides): Promise; + + auctions( + arg0: BytesLike, + overrides?: CallOverrides + ): Promise< + [string, number, string, BigNumber, BigNumber, string, string, string] & { + owner: string; + start: number; + baseId: string; + ink: BigNumber; + art: BigNumber; + auctioneer: string; + ilkId: string; + seriesId: string; + } + >; + + calcPayout( + vaultId: BytesLike, + to: string, + maxArtIn: BigNumberish, + overrides?: CallOverrides + ): Promise< + [BigNumber, BigNumber, BigNumber] & { + liquidatorCut: BigNumber; + auctioneerCut: BigNumber; + artIn: BigNumber; + } + >; + + cancel(vaultId: BytesLike, overrides?: CallOverrides): Promise; + + cauldron(overrides?: CallOverrides): Promise; + + clear(vaultId: BytesLike, overrides?: CallOverrides): Promise; + + getRoleAdmin(role: BytesLike, overrides?: CallOverrides): Promise; + + grantRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + grantRoles( + roles: BytesLike[], + account: string, + overrides?: CallOverrides + ): Promise; + + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + ladle(overrides?: CallOverrides): Promise; + + limits( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise<[BigNumber, BigNumber] & { max: BigNumber; sum: BigNumber }>; + + lines( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise< + [number, BigNumber, BigNumber] & { + duration: number; + vaultProportion: BigNumber; + collateralProportion: BigNumber; + } + >; + + lockRole(role: BytesLike, overrides?: CallOverrides): Promise; + + payBase( + vaultId: BytesLike, + to: string, + minInkOut: BigNumberish, + maxBaseIn: BigNumberish, + overrides?: CallOverrides + ): Promise< + [BigNumber, BigNumber, BigNumber] & { + liquidatorCut: BigNumber; + auctioneerCut: BigNumber; + baseIn: BigNumber; + } + >; + + point( + param: BytesLike, + value: string, + overrides?: CallOverrides + ): Promise; + + protected(arg0: string, overrides?: CallOverrides): Promise; + + renounceRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + revokeRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + revokeRoles( + roles: BytesLike[], + account: string, + overrides?: CallOverrides + ): Promise; + + setAuctioneerReward( + auctioneerReward_: BigNumberish, + overrides?: CallOverrides + ): Promise; + + setLineAndLimit( + ilkId: BytesLike, + baseId: BytesLike, + duration: BigNumberish, + vaultProportion: BigNumberish, + collateralProportion: BigNumberish, + max: BigNumberish, + overrides?: CallOverrides + ): Promise; + + setProtected( + owner: string, + _protected: boolean, + overrides?: CallOverrides + ): Promise; + + setRoleAdmin( + role: BytesLike, + adminRole: BytesLike, + overrides?: CallOverrides + ): Promise; + }; + + filters: { + "Auctioned(bytes12,tuple,uint256,uint256)"( + vaultId?: BytesLike | null, + auction?: null, + duration?: null, + initialCollateralProportion?: null + ): TypedEventFilter< + [ + string, + [ + string, + number, + string, + BigNumber, + BigNumber, + string, + string, + string + ] & { + owner: string; + start: number; + baseId: string; + ink: BigNumber; + art: BigNumber; + auctioneer: string; + ilkId: string; + seriesId: string; + }, + BigNumber, + BigNumber + ], + { + vaultId: string; + auction: [ + string, + number, + string, + BigNumber, + BigNumber, + string, + string, + string + ] & { + owner: string; + start: number; + baseId: string; + ink: BigNumber; + art: BigNumber; + auctioneer: string; + ilkId: string; + seriesId: string; + }; + duration: BigNumber; + initialCollateralProportion: BigNumber; + } + >; + + Auctioned( + vaultId?: BytesLike | null, + auction?: null, + duration?: null, + initialCollateralProportion?: null + ): TypedEventFilter< + [ + string, + [ + string, + number, + string, + BigNumber, + BigNumber, + string, + string, + string + ] & { + owner: string; + start: number; + baseId: string; + ink: BigNumber; + art: BigNumber; + auctioneer: string; + ilkId: string; + seriesId: string; + }, + BigNumber, + BigNumber + ], + { + vaultId: string; + auction: [ + string, + number, + string, + BigNumber, + BigNumber, + string, + string, + string + ] & { + owner: string; + start: number; + baseId: string; + ink: BigNumber; + art: BigNumber; + auctioneer: string; + ilkId: string; + seriesId: string; + }; + duration: BigNumber; + initialCollateralProportion: BigNumber; + } + >; + + "AuctioneerRewardSet(uint256)"( + auctioneerReward?: null + ): TypedEventFilter<[BigNumber], { auctioneerReward: BigNumber }>; + + AuctioneerRewardSet( + auctioneerReward?: null + ): TypedEventFilter<[BigNumber], { auctioneerReward: BigNumber }>; + + "Bought(bytes12,address,uint256,uint256)"( + vaultId?: BytesLike | null, + buyer?: string | null, + ink?: null, + art?: null + ): TypedEventFilter< + [string, string, BigNumber, BigNumber], + { vaultId: string; buyer: string; ink: BigNumber; art: BigNumber } + >; + + Bought( + vaultId?: BytesLike | null, + buyer?: string | null, + ink?: null, + art?: null + ): TypedEventFilter< + [string, string, BigNumber, BigNumber], + { vaultId: string; buyer: string; ink: BigNumber; art: BigNumber } + >; + + "Cancelled(bytes12)"( + vaultId?: BytesLike | null + ): TypedEventFilter<[string], { vaultId: string }>; + + Cancelled( + vaultId?: BytesLike | null + ): TypedEventFilter<[string], { vaultId: string }>; + + "Cleared(bytes12)"( + vaultId?: BytesLike | null + ): TypedEventFilter<[string], { vaultId: string }>; + + Cleared( + vaultId?: BytesLike | null + ): TypedEventFilter<[string], { vaultId: string }>; + + "Ended(bytes12)"( + vaultId?: BytesLike | null + ): TypedEventFilter<[string], { vaultId: string }>; + + Ended( + vaultId?: BytesLike | null + ): TypedEventFilter<[string], { vaultId: string }>; + + "LimitSet(bytes6,bytes6,uint128)"( + ilkId?: BytesLike | null, + baseId?: BytesLike | null, + max?: null + ): TypedEventFilter< + [string, string, BigNumber], + { ilkId: string; baseId: string; max: BigNumber } + >; + + LimitSet( + ilkId?: BytesLike | null, + baseId?: BytesLike | null, + max?: null + ): TypedEventFilter< + [string, string, BigNumber], + { ilkId: string; baseId: string; max: BigNumber } + >; + + "LineSet(bytes6,bytes6,uint32,uint64,uint64)"( + ilkId?: BytesLike | null, + baseId?: BytesLike | null, + duration?: null, + vaultProportion?: null, + collateralProportion?: null + ): TypedEventFilter< + [string, string, number, BigNumber, BigNumber], + { + ilkId: string; + baseId: string; + duration: number; + vaultProportion: BigNumber; + collateralProportion: BigNumber; + } + >; + + LineSet( + ilkId?: BytesLike | null, + baseId?: BytesLike | null, + duration?: null, + vaultProportion?: null, + collateralProportion?: null + ): TypedEventFilter< + [string, string, number, BigNumber, BigNumber], + { + ilkId: string; + baseId: string; + duration: number; + vaultProportion: BigNumber; + collateralProportion: BigNumber; + } + >; + + "Point(bytes32,address,address)"( + param?: BytesLike | null, + oldValue?: string | null, + newValue?: string | null + ): TypedEventFilter< + [string, string, string], + { param: string; oldValue: string; newValue: string } + >; + + Point( + param?: BytesLike | null, + oldValue?: string | null, + newValue?: string | null + ): TypedEventFilter< + [string, string, string], + { param: string; oldValue: string; newValue: string } + >; + + "ProtectedSet(address,bool)"( + value?: string | null, + protected?: null + ): TypedEventFilter< + [string, boolean], + { value: string; protected: boolean } + >; + + ProtectedSet( + value?: string | null, + protected?: null + ): TypedEventFilter< + [string, boolean], + { value: string; protected: boolean } + >; + + "RoleAdminChanged(bytes4,bytes4)"( + role?: BytesLike | null, + newAdminRole?: BytesLike | null + ): TypedEventFilter< + [string, string], + { role: string; newAdminRole: string } + >; + + RoleAdminChanged( + role?: BytesLike | null, + newAdminRole?: BytesLike | null + ): TypedEventFilter< + [string, string], + { role: string; newAdminRole: string } + >; + + "RoleGranted(bytes4,address,address)"( + role?: BytesLike | null, + account?: string | null, + sender?: string | null + ): TypedEventFilter< + [string, string, string], + { role: string; account: string; sender: string } + >; + + RoleGranted( + role?: BytesLike | null, + account?: string | null, + sender?: string | null + ): TypedEventFilter< + [string, string, string], + { role: string; account: string; sender: string } + >; + + "RoleRevoked(bytes4,address,address)"( + role?: BytesLike | null, + account?: string | null, + sender?: string | null + ): TypedEventFilter< + [string, string, string], + { role: string; account: string; sender: string } + >; + + RoleRevoked( + role?: BytesLike | null, + account?: string | null, + sender?: string | null + ): TypedEventFilter< + [string, string, string], + { role: string; account: string; sender: string } + >; + }; + + estimateGas: { + LOCK(overrides?: CallOverrides): Promise; + + LOCK8605463013(overrides?: CallOverrides): Promise; + + ONE_HUNDRED_PERCENT(overrides?: CallOverrides): Promise; + + ONE_PERCENT(overrides?: CallOverrides): Promise; + + ROOT(overrides?: CallOverrides): Promise; + + ROOT4146650865(overrides?: CallOverrides): Promise; + + auction( + vaultId: BytesLike, + to: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + auctioneerReward(overrides?: CallOverrides): Promise; + + auctions(arg0: BytesLike, overrides?: CallOverrides): Promise; + + calcPayout( + vaultId: BytesLike, + to: string, + maxArtIn: BigNumberish, + overrides?: CallOverrides + ): Promise; + + cancel( + vaultId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + cauldron(overrides?: CallOverrides): Promise; + + clear( + vaultId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + getRoleAdmin( + role: BytesLike, + overrides?: CallOverrides + ): Promise; + + grantRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + grantRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + ladle(overrides?: CallOverrides): Promise; + + limits( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise; + + lines( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise; + + lockRole( + role: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + payBase( + vaultId: BytesLike, + to: string, + minInkOut: BigNumberish, + maxBaseIn: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + point( + param: BytesLike, + value: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + protected(arg0: string, overrides?: CallOverrides): Promise; + + renounceRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setAuctioneerReward( + auctioneerReward_: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setLineAndLimit( + ilkId: BytesLike, + baseId: BytesLike, + duration: BigNumberish, + vaultProportion: BigNumberish, + collateralProportion: BigNumberish, + max: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setProtected( + owner: string, + _protected: boolean, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setRoleAdmin( + role: BytesLike, + adminRole: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + }; + + populateTransaction: { + LOCK(overrides?: CallOverrides): Promise; + + LOCK8605463013(overrides?: CallOverrides): Promise; + + ONE_HUNDRED_PERCENT( + overrides?: CallOverrides + ): Promise; + + ONE_PERCENT(overrides?: CallOverrides): Promise; + + ROOT(overrides?: CallOverrides): Promise; + + ROOT4146650865(overrides?: CallOverrides): Promise; + + auction( + vaultId: BytesLike, + to: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + auctioneerReward(overrides?: CallOverrides): Promise; + + auctions( + arg0: BytesLike, + overrides?: CallOverrides + ): Promise; + + calcPayout( + vaultId: BytesLike, + to: string, + maxArtIn: BigNumberish, + overrides?: CallOverrides + ): Promise; + + cancel( + vaultId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + cauldron(overrides?: CallOverrides): Promise; + + clear( + vaultId: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + getRoleAdmin( + role: BytesLike, + overrides?: CallOverrides + ): Promise; + + grantRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + grantRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + ladle(overrides?: CallOverrides): Promise; + + limits( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise; + + lines( + arg0: BytesLike, + arg1: BytesLike, + overrides?: CallOverrides + ): Promise; + + lockRole( + role: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + payBase( + vaultId: BytesLike, + to: string, + minInkOut: BigNumberish, + maxBaseIn: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + point( + param: BytesLike, + value: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + protected( + arg0: string, + overrides?: CallOverrides + ): Promise; + + renounceRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setAuctioneerReward( + auctioneerReward_: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setLineAndLimit( + ilkId: BytesLike, + baseId: BytesLike, + duration: BigNumberish, + vaultProportion: BigNumberish, + collateralProportion: BigNumberish, + max: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setProtected( + owner: string, + _protected: boolean, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setRoleAdmin( + role: BytesLike, + adminRole: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + }; +} diff --git a/src/contracts/abis/VRWitch.json b/src/contracts/abis/VRWitch.json new file mode 100644 index 000000000..37206a114 --- /dev/null +++ b/src/contracts/abis/VRWitch.json @@ -0,0 +1,535 @@ +[ + { + "inputs": [ + { "internalType": "contract ICauldron", "name": "cauldron_", "type": "address" }, + { "internalType": "contract ILadle", "name": "ladle_", "type": "address" } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [{ "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }], + "name": "AuctionIsCorrect", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "max", "type": "uint256" }, + { "internalType": "uint256", "name": "actual", "type": "uint256" } + ], + "name": "AuctioneerRewardTooHigh", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "current", "type": "uint256" }, + { "internalType": "uint256", "name": "max", "type": "uint256" } + ], + "name": "CollateralLimitExceeded", + "type": "error" + }, + { "inputs": [{ "internalType": "bytes6", "name": "id", "type": "bytes6" }], "name": "JoinNotFound", "type": "error" }, + { + "inputs": [ + { "internalType": "uint256", "name": "remainder", "type": "uint256" }, + { "internalType": "uint256", "name": "min", "type": "uint256" } + ], + "name": "LeavesDust", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "expected", "type": "uint256" }, + { "internalType": "uint256", "name": "got", "type": "uint256" } + ], + "name": "NotEnoughBought", + "type": "error" + }, + { + "inputs": [{ "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }], + "name": "NotUnderCollateralised", + "type": "error" + }, + { + "inputs": [{ "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }], + "name": "UnderCollateralised", + "type": "error" + }, + { + "inputs": [{ "internalType": "bytes32", "name": "param", "type": "bytes32" }], + "name": "UnrecognisedParam", + "type": "error" + }, + { + "inputs": [ + { "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }, + { "internalType": "address", "name": "witch", "type": "address" } + ], + "name": "VaultAlreadyUnderAuction", + "type": "error" + }, + { + "inputs": [ + { "internalType": "bytes6", "name": "ilkId", "type": "bytes6" }, + { "internalType": "bytes6", "name": "baseId", "type": "bytes6" } + ], + "name": "VaultNotLiquidatable", + "type": "error" + }, + { + "inputs": [{ "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }], + "name": "VaultNotUnderAuction", + "type": "error" + }, + { "inputs": [], "name": "WitchIsDead", "type": "error" }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }, + { + "components": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "uint32", "name": "start", "type": "uint32" }, + { "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "internalType": "uint128", "name": "ink", "type": "uint128" }, + { "internalType": "uint128", "name": "art", "type": "uint128" }, + { "internalType": "address", "name": "auctioneer", "type": "address" }, + { "internalType": "bytes6", "name": "ilkId", "type": "bytes6" }, + { "internalType": "bytes6", "name": "seriesId", "type": "bytes6" } + ], + "indexed": false, + "internalType": "struct DataTypes.Auction", + "name": "auction", + "type": "tuple" + }, + { "indexed": false, "internalType": "uint256", "name": "duration", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "initialCollateralProportion", "type": "uint256" } + ], + "name": "Auctioned", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "uint256", "name": "auctioneerReward", "type": "uint256" }], + "name": "AuctioneerRewardSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }, + { "indexed": true, "internalType": "address", "name": "buyer", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "ink", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "art", "type": "uint256" } + ], + "name": "Bought", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": true, "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }], + "name": "Cancelled", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": true, "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }], + "name": "Cleared", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": true, "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }], + "name": "Ended", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes6", "name": "ilkId", "type": "bytes6" }, + { "indexed": true, "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "indexed": false, "internalType": "uint128", "name": "max", "type": "uint128" } + ], + "name": "LimitSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes6", "name": "ilkId", "type": "bytes6" }, + { "indexed": true, "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "indexed": false, "internalType": "uint32", "name": "duration", "type": "uint32" }, + { "indexed": false, "internalType": "uint64", "name": "vaultProportion", "type": "uint64" }, + { "indexed": false, "internalType": "uint64", "name": "collateralProportion", "type": "uint64" } + ], + "name": "LineSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes32", "name": "param", "type": "bytes32" }, + { "indexed": true, "internalType": "address", "name": "oldValue", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "newValue", "type": "address" } + ], + "name": "Point", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "value", "type": "address" }, + { "indexed": false, "internalType": "bool", "name": "protected", "type": "bool" } + ], + "name": "ProtectedSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "indexed": true, "internalType": "bytes4", "name": "newAdminRole", "type": "bytes4" } + ], + "name": "RoleAdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "indexed": true, "internalType": "address", "name": "account", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "sender", "type": "address" } + ], + "name": "RoleGranted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "indexed": true, "internalType": "address", "name": "account", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "sender", "type": "address" } + ], + "name": "RoleRevoked", + "type": "event" + }, + { + "inputs": [], + "name": "LOCK", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "LOCK8605463013", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ONE_HUNDRED_PERCENT", + "outputs": [{ "internalType": "uint128", "name": "", "type": "uint128" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ONE_PERCENT", + "outputs": [{ "internalType": "uint128", "name": "", "type": "uint128" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ROOT", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ROOT4146650865", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }, + { "internalType": "address", "name": "to", "type": "address" } + ], + "name": "auction", + "outputs": [ + { + "components": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "uint32", "name": "start", "type": "uint32" }, + { "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "internalType": "uint128", "name": "ink", "type": "uint128" }, + { "internalType": "uint128", "name": "art", "type": "uint128" }, + { "internalType": "address", "name": "auctioneer", "type": "address" }, + { "internalType": "bytes6", "name": "ilkId", "type": "bytes6" }, + { "internalType": "bytes6", "name": "seriesId", "type": "bytes6" } + ], + "internalType": "struct DataTypes.Auction", + "name": "auction_", + "type": "tuple" + }, + { + "components": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "internalType": "bytes6", "name": "ilkId", "type": "bytes6" } + ], + "internalType": "struct VRDataTypes.Vault", + "name": "vault", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "auctioneerReward", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes12", "name": "", "type": "bytes12" }], + "name": "auctions", + "outputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "uint32", "name": "start", "type": "uint32" }, + { "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "internalType": "uint128", "name": "ink", "type": "uint128" }, + { "internalType": "uint128", "name": "art", "type": "uint128" }, + { "internalType": "address", "name": "auctioneer", "type": "address" }, + { "internalType": "bytes6", "name": "ilkId", "type": "bytes6" }, + { "internalType": "bytes6", "name": "seriesId", "type": "bytes6" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "maxArtIn", "type": "uint256" } + ], + "name": "calcPayout", + "outputs": [ + { "internalType": "uint256", "name": "liquidatorCut", "type": "uint256" }, + { "internalType": "uint256", "name": "auctioneerCut", "type": "uint256" }, + { "internalType": "uint256", "name": "artIn", "type": "uint256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }], + "name": "cancel", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "cauldron", + "outputs": [{ "internalType": "contract ICauldron", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }], + "name": "clear", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes4", "name": "role", "type": "bytes4" }], + "name": "getRoleAdmin", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "grantRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4[]", "name": "roles", "type": "bytes4[]" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "grantRoles", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "hasRole", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ladle", + "outputs": [{ "internalType": "contract ILadle", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes6", "name": "", "type": "bytes6" }, + { "internalType": "bytes6", "name": "", "type": "bytes6" } + ], + "name": "limits", + "outputs": [ + { "internalType": "uint128", "name": "max", "type": "uint128" }, + { "internalType": "uint128", "name": "sum", "type": "uint128" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes6", "name": "", "type": "bytes6" }, + { "internalType": "bytes6", "name": "", "type": "bytes6" } + ], + "name": "lines", + "outputs": [ + { "internalType": "uint32", "name": "duration", "type": "uint32" }, + { "internalType": "uint64", "name": "vaultProportion", "type": "uint64" }, + { "internalType": "uint64", "name": "collateralProportion", "type": "uint64" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes4", "name": "role", "type": "bytes4" }], + "name": "lockRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes12", "name": "vaultId", "type": "bytes12" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint128", "name": "minInkOut", "type": "uint128" }, + { "internalType": "uint128", "name": "maxBaseIn", "type": "uint128" } + ], + "name": "payBase", + "outputs": [ + { "internalType": "uint256", "name": "liquidatorCut", "type": "uint256" }, + { "internalType": "uint256", "name": "auctioneerCut", "type": "uint256" }, + { "internalType": "uint256", "name": "baseIn", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "param", "type": "bytes32" }, + { "internalType": "address", "name": "value", "type": "address" } + ], + "name": "point", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "protected", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "renounceRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "revokeRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4[]", "name": "roles", "type": "bytes4[]" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "revokeRoles", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "auctioneerReward_", "type": "uint256" }], + "name": "setAuctioneerReward", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes6", "name": "ilkId", "type": "bytes6" }, + { "internalType": "bytes6", "name": "baseId", "type": "bytes6" }, + { "internalType": "uint32", "name": "duration", "type": "uint32" }, + { "internalType": "uint64", "name": "vaultProportion", "type": "uint64" }, + { "internalType": "uint64", "name": "collateralProportion", "type": "uint64" }, + { "internalType": "uint128", "name": "max", "type": "uint128" } + ], + "name": "setLineAndLimit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "bool", "name": "_protected", "type": "bool" } + ], + "name": "setProtected", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "internalType": "bytes4", "name": "adminRole", "type": "bytes4" } + ], + "name": "setRoleAdmin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/src/contracts/factories/VRWitch__factory.ts b/src/contracts/factories/VRWitch__factory.ts new file mode 100644 index 000000000..1e70c817b --- /dev/null +++ b/src/contracts/factories/VRWitch__factory.ts @@ -0,0 +1,1238 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer, utils } from "ethers"; +import { Provider } from "@ethersproject/providers"; +import type { VRWitch, VRWitchInterface } from "../VRWitch"; + +const _abi = [ + { + inputs: [ + { + internalType: "contract ICauldron", + name: "cauldron_", + type: "address", + }, + { + internalType: "contract ILadle", + name: "ladle_", + type: "address", + }, + ], + stateMutability: "nonpayable", + type: "constructor", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + ], + name: "AuctionIsCorrect", + type: "error", + }, + { + inputs: [ + { + internalType: "uint256", + name: "max", + type: "uint256", + }, + { + internalType: "uint256", + name: "actual", + type: "uint256", + }, + ], + name: "AuctioneerRewardTooHigh", + type: "error", + }, + { + inputs: [ + { + internalType: "uint256", + name: "current", + type: "uint256", + }, + { + internalType: "uint256", + name: "max", + type: "uint256", + }, + ], + name: "CollateralLimitExceeded", + type: "error", + }, + { + inputs: [ + { + internalType: "bytes6", + name: "id", + type: "bytes6", + }, + ], + name: "JoinNotFound", + type: "error", + }, + { + inputs: [ + { + internalType: "uint256", + name: "remainder", + type: "uint256", + }, + { + internalType: "uint256", + name: "min", + type: "uint256", + }, + ], + name: "LeavesDust", + type: "error", + }, + { + inputs: [ + { + internalType: "uint256", + name: "expected", + type: "uint256", + }, + { + internalType: "uint256", + name: "got", + type: "uint256", + }, + ], + name: "NotEnoughBought", + type: "error", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + ], + name: "NotUnderCollateralised", + type: "error", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + ], + name: "UnderCollateralised", + type: "error", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "param", + type: "bytes32", + }, + ], + name: "UnrecognisedParam", + type: "error", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + { + internalType: "address", + name: "witch", + type: "address", + }, + ], + name: "VaultAlreadyUnderAuction", + type: "error", + }, + { + inputs: [ + { + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + ], + name: "VaultNotLiquidatable", + type: "error", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + ], + name: "VaultNotUnderAuction", + type: "error", + }, + { + inputs: [], + name: "WitchIsDead", + type: "error", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + { + components: [ + { + internalType: "address", + name: "owner", + type: "address", + }, + { + internalType: "uint32", + name: "start", + type: "uint32", + }, + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + internalType: "uint128", + name: "ink", + type: "uint128", + }, + { + internalType: "uint128", + name: "art", + type: "uint128", + }, + { + internalType: "address", + name: "auctioneer", + type: "address", + }, + { + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "seriesId", + type: "bytes6", + }, + ], + indexed: false, + internalType: "struct DataTypes.Auction", + name: "auction", + type: "tuple", + }, + { + indexed: false, + internalType: "uint256", + name: "duration", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "initialCollateralProportion", + type: "uint256", + }, + ], + name: "Auctioned", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "uint256", + name: "auctioneerReward", + type: "uint256", + }, + ], + name: "AuctioneerRewardSet", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + { + indexed: true, + internalType: "address", + name: "buyer", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "ink", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "art", + type: "uint256", + }, + ], + name: "Bought", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + ], + name: "Cancelled", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + ], + name: "Cleared", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + ], + name: "Ended", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + { + indexed: true, + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + indexed: false, + internalType: "uint128", + name: "max", + type: "uint128", + }, + ], + name: "LimitSet", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + { + indexed: true, + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + indexed: false, + internalType: "uint32", + name: "duration", + type: "uint32", + }, + { + indexed: false, + internalType: "uint64", + name: "vaultProportion", + type: "uint64", + }, + { + indexed: false, + internalType: "uint64", + name: "collateralProportion", + type: "uint64", + }, + ], + name: "LineSet", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes32", + name: "param", + type: "bytes32", + }, + { + indexed: true, + internalType: "address", + name: "oldValue", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "newValue", + type: "address", + }, + ], + name: "Point", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "value", + type: "address", + }, + { + indexed: false, + internalType: "bool", + name: "protected", + type: "bool", + }, + ], + name: "ProtectedSet", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + indexed: true, + internalType: "bytes4", + name: "newAdminRole", + type: "bytes4", + }, + ], + name: "RoleAdminChanged", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + indexed: true, + internalType: "address", + name: "account", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "sender", + type: "address", + }, + ], + name: "RoleGranted", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + indexed: true, + internalType: "address", + name: "account", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "sender", + type: "address", + }, + ], + name: "RoleRevoked", + type: "event", + }, + { + inputs: [], + name: "LOCK", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "LOCK8605463013", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "ONE_HUNDRED_PERCENT", + outputs: [ + { + internalType: "uint128", + name: "", + type: "uint128", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "ONE_PERCENT", + outputs: [ + { + internalType: "uint128", + name: "", + type: "uint128", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "ROOT", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "ROOT4146650865", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + { + internalType: "address", + name: "to", + type: "address", + }, + ], + name: "auction", + outputs: [ + { + components: [ + { + internalType: "address", + name: "owner", + type: "address", + }, + { + internalType: "uint32", + name: "start", + type: "uint32", + }, + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + internalType: "uint128", + name: "ink", + type: "uint128", + }, + { + internalType: "uint128", + name: "art", + type: "uint128", + }, + { + internalType: "address", + name: "auctioneer", + type: "address", + }, + { + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "seriesId", + type: "bytes6", + }, + ], + internalType: "struct DataTypes.Auction", + name: "auction_", + type: "tuple", + }, + { + components: [ + { + internalType: "address", + name: "owner", + type: "address", + }, + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + ], + internalType: "struct VRDataTypes.Vault", + name: "vault", + type: "tuple", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "auctioneerReward", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "", + type: "bytes12", + }, + ], + name: "auctions", + outputs: [ + { + internalType: "address", + name: "owner", + type: "address", + }, + { + internalType: "uint32", + name: "start", + type: "uint32", + }, + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + internalType: "uint128", + name: "ink", + type: "uint128", + }, + { + internalType: "uint128", + name: "art", + type: "uint128", + }, + { + internalType: "address", + name: "auctioneer", + type: "address", + }, + { + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "seriesId", + type: "bytes6", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + { + internalType: "address", + name: "to", + type: "address", + }, + { + internalType: "uint256", + name: "maxArtIn", + type: "uint256", + }, + ], + name: "calcPayout", + outputs: [ + { + internalType: "uint256", + name: "liquidatorCut", + type: "uint256", + }, + { + internalType: "uint256", + name: "auctioneerCut", + type: "uint256", + }, + { + internalType: "uint256", + name: "artIn", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + ], + name: "cancel", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "cauldron", + outputs: [ + { + internalType: "contract ICauldron", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + ], + name: "clear", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + ], + name: "getRoleAdmin", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "grantRole", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4[]", + name: "roles", + type: "bytes4[]", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "grantRoles", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "hasRole", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "ladle", + outputs: [ + { + internalType: "contract ILadle", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes6", + name: "", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "", + type: "bytes6", + }, + ], + name: "limits", + outputs: [ + { + internalType: "uint128", + name: "max", + type: "uint128", + }, + { + internalType: "uint128", + name: "sum", + type: "uint128", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes6", + name: "", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "", + type: "bytes6", + }, + ], + name: "lines", + outputs: [ + { + internalType: "uint32", + name: "duration", + type: "uint32", + }, + { + internalType: "uint64", + name: "vaultProportion", + type: "uint64", + }, + { + internalType: "uint64", + name: "collateralProportion", + type: "uint64", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + ], + name: "lockRole", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes12", + name: "vaultId", + type: "bytes12", + }, + { + internalType: "address", + name: "to", + type: "address", + }, + { + internalType: "uint128", + name: "minInkOut", + type: "uint128", + }, + { + internalType: "uint128", + name: "maxBaseIn", + type: "uint128", + }, + ], + name: "payBase", + outputs: [ + { + internalType: "uint256", + name: "liquidatorCut", + type: "uint256", + }, + { + internalType: "uint256", + name: "auctioneerCut", + type: "uint256", + }, + { + internalType: "uint256", + name: "baseIn", + type: "uint256", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "param", + type: "bytes32", + }, + { + internalType: "address", + name: "value", + type: "address", + }, + ], + name: "point", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + name: "protected", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "renounceRole", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "revokeRole", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4[]", + name: "roles", + type: "bytes4[]", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "revokeRoles", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "auctioneerReward_", + type: "uint256", + }, + ], + name: "setAuctioneerReward", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes6", + name: "ilkId", + type: "bytes6", + }, + { + internalType: "bytes6", + name: "baseId", + type: "bytes6", + }, + { + internalType: "uint32", + name: "duration", + type: "uint32", + }, + { + internalType: "uint64", + name: "vaultProportion", + type: "uint64", + }, + { + internalType: "uint64", + name: "collateralProportion", + type: "uint64", + }, + { + internalType: "uint128", + name: "max", + type: "uint128", + }, + ], + name: "setLineAndLimit", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "owner", + type: "address", + }, + { + internalType: "bool", + name: "_protected", + type: "bool", + }, + ], + name: "setProtected", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + internalType: "bytes4", + name: "adminRole", + type: "bytes4", + }, + ], + name: "setRoleAdmin", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, +]; + +export class VRWitch__factory { + static readonly abi = _abi; + static createInterface(): VRWitchInterface { + return new utils.Interface(_abi) as VRWitchInterface; + } + static connect( + address: string, + signerOrProvider: Signer | Provider + ): VRWitch { + return new Contract(address, _abi, signerOrProvider) as VRWitch; + } +} diff --git a/src/contracts/index.ts b/src/contracts/index.ts index eb26a04ae..d092d6d2b 100644 --- a/src/contracts/index.ts +++ b/src/contracts/index.ts @@ -22,6 +22,9 @@ export type { Pool } from "./Pool"; export type { Strategy } from "./Strategy"; export type { Transfer1155Module } from "./Transfer1155Module"; export type { UniswapV3Oracle } from "./UniswapV3Oracle"; +export type { VRCauldron } from "./VRCauldron"; +export type { VRLadle } from "./VRLadle"; +export type { VRWitch } from "./VRWitch"; export type { Witch } from "./Witch"; export type { WitchV2 } from "./WitchV2"; export type { WrapEtherModule } from "./WrapEtherModule"; @@ -48,6 +51,9 @@ export { Pool__factory } from "./factories/Pool__factory"; export { Strategy__factory } from "./factories/Strategy__factory"; export { Transfer1155Module__factory } from "./factories/Transfer1155Module__factory"; export { UniswapV3Oracle__factory } from "./factories/UniswapV3Oracle__factory"; +export { VRCauldron__factory } from "./factories/VRCauldron__factory"; +export { VRLadle__factory } from "./factories/VRLadle__factory"; +export { VRWitch__factory } from "./factories/VRWitch__factory"; export { Witch__factory } from "./factories/Witch__factory"; export { WitchV2__factory } from "./factories/WitchV2__factory"; export { WrapEtherModule__factory } from "./factories/WrapEtherModule__factory"; diff --git a/src/hooks/actionHooks/useAddCollateralVariableRate.ts b/src/hooks/actionHooks/useAddCollateralVariableRate.ts new file mode 100644 index 000000000..e69de29bb diff --git a/src/hooks/actionHooks/useBorrow.ts b/src/hooks/actionHooks/useBorrow.ts index a9104bce1..4f6995088 100644 --- a/src/hooks/actionHooks/useBorrow.ts +++ b/src/hooks/actionHooks/useBorrow.ts @@ -48,13 +48,12 @@ export const useBorrow = () => { const { sign, transact } = useChain(); const { getTimeTillMaturity } = useTimeTillMaturity(); - const {isActionAllowed} = useAllowAction(); + const { isActionAllowed } = useAllowAction(); const borrow = async (vault: IVault | undefined, input: string | undefined, collInput: string | undefined) => { if (!contracts) return; if (!isActionAllowed(ActionCodes.BORROW)) return; // return if action is not allowed - /* generate the reproducible txCode for tx tracking and tracing */ const txCode = getTxCode(ActionCodes.BORROW, selectedSeries?.id!); /* use the vault id provided OR 0 if new/ not provided */ diff --git a/src/hooks/actionHooks/useBorrowVariableRate.ts b/src/hooks/actionHooks/useBorrowVariableRate.ts new file mode 100644 index 000000000..34ae1c767 --- /dev/null +++ b/src/hooks/actionHooks/useBorrowVariableRate.ts @@ -0,0 +1,211 @@ +import { ethers } from 'ethers'; +import { useContext } from 'react'; + +import { SettingsContext } from '../../contexts/SettingsContext'; +import { UserContext } from '../../contexts/UserContext'; +import { ICallData, IVault, ActionCodes, LadleActions, ISeries, IAsset } from '../../types'; +import { cleanValue, getTxCode } from '../../utils/appUtils'; +import { BLANK_VAULT, ONE_BN, ZERO_BN } from '../../utils/constants'; + +import { CONVEX_BASED_ASSETS, ETH_BASED_ASSETS, WETH } from '../../config/assets'; + +import { useChain } from '../useChain'; +import { useWrapUnwrapAsset } from './useWrapUnwrapAsset'; +import { useAddRemoveEth } from './useAddRemoveEth'; +import { ModuleActions } from '../../types/operations'; +import { ConvexLadleModule } from '../../contracts'; +import { Address, useBalance } from 'wagmi'; +import useContracts from '../useContracts'; +import useAccountPlus from '../useAccountPlus'; +import { ContractNames } from '../../config/contracts'; +import useAllowAction from '../useAllowAction'; + +export const useBorrowVariableRate = () => { + const { + settingsState: { slippageTolerance }, + } = useContext(SettingsContext); + + const { userState, userActions } = useContext(UserContext); + const { selectedBase, selectedIlk, selectedSeries, seriesMap, assetMap } = userState; + const { updateVaults, updateAssets, updateSeries } = userActions; + const { address: account } = useAccountPlus(); + const contracts = useContracts(); + + const { refetch: refetchIlkBal } = useBalance({ + address: account, + token: selectedIlk?.address as Address, + }); + const { refetch: refetchBaseBal } = useBalance({ + address: account, + token: selectedBase?.address as Address, + }); + + const { addEth, removeEth } = useAddRemoveEth(); + + const { wrapAsset } = useWrapUnwrapAsset(); + const { sign, transact } = useChain(); + + const { isActionAllowed } = useAllowAction(); + + const borrowVariableRate = async ( + vault: IVault | undefined, + input: string | undefined, + collInput: string | undefined + ) => { + if (!contracts) return; + + /* generate the reproducible txCode for tx tracking and tracing */ + const txCode = getTxCode(ActionCodes.BORROW, 'VR'); + // TODO whats our second argument? vaultId if exisitng vault? look into what we do with this TX code - jacob b + /* use the vault id provided OR 0 if new/ not provided */ + const vaultId = vault?.id || BLANK_VAULT; + + const ladleAddress = contracts.get(ContractNames.VR_LADLE)?.address; + + /* Set the series and ilk based on the vault that has been selected or if it's a new vault, get from the globally selected SeriesId */ + + const base: IAsset = assetMap?.get(selectedBase!.id)!; + + const ilkToUse: IAsset = vault ? assetMap?.get(vault.ilkId)! : assetMap?.get(selectedIlk?.proxyId!)!; // note: we use the wrapped version if required + + /* is ETH used as collateral */ + const isEthCollateral = ETH_BASED_ASSETS.includes(selectedIlk?.proxyId!); + /* is ETH being Borrowed */ + const isEthBase = ETH_BASED_ASSETS.includes(selectedBase!.id); + + /* is convex-type collateral */ + const isConvexCollateral = CONVEX_BASED_ASSETS.includes(selectedIlk?.proxyId!); + const ConvexLadleModuleContract = contracts.get(ContractNames.CONVEX_LADLE_MODULE) as ConvexLadleModule; + + /* parse inputs (clean down to base/ilk decimals so that there is never an underlow) */ + const cleanInput = cleanValue(input, base.decimals); + const _input = input ? ethers.utils.parseUnits(cleanInput, base.decimals) : ethers.constants.Zero; + const cleanCollInput = cleanValue(collInput, ilkToUse.decimals); + const _collInput = collInput ? ethers.utils.parseUnits(cleanCollInput, ilkToUse.decimals) : ethers.constants.Zero; + + /* + Here is where we buy base in the previous borrow hook, + but in this case, we will need a new buyBase function, + the old one requires a maturity date, but for VR we won't + have one. we also have no series. Will we have series for VR? + + check for preview function + + const _expectedFyToken = buyBase( + series.sharesReserves, + series.fyTokenReserves, + series.getShares(_input), // convert input in base to shares + getTimeTillMaturity(series.maturity), + series.ts, + series.g2, + series.decimals, + series.c, + series.mu + ); + const _expectedFyTokenWithSlippage = calculateSlippage(_expectedFyToken, slippageTolerance.toString()); + */ + + /* if approveMAx, check if signature is required : note: getAllowance may return FALSE if ERC1155 */ + const _allowance = await ilkToUse.getAllowance(account!, ilkToUse.joinAddress); + + const alreadyApproved = ethers.BigNumber.isBigNumber(_allowance) ? _allowance.gte(_collInput) : _allowance; + console.log('Already approved', alreadyApproved); + + /* handle ETH deposit as Collateral, if required (only if collateral used is ETH-based ), else send ZERO_BN */ + const addEthCallData: ICallData[] = addEth(isEthCollateral ? _collInput : ZERO_BN); + /* handle remove/unwrap WETH > if ETH is what is being borrowed */ + const removeEthCallData: ICallData[] = removeEth(isEthBase ? ONE_BN : ZERO_BN); // (exit_ether sweeps all the eth out the ladle, so exact amount is not importnat -> just greater than zero) + /* handle wrapping of collateral if required */ + const wrapAssetCallData: ICallData[] = await wrapAsset(_collInput, selectedIlk!, txCode); // note: selected ilk used here, not wrapped version + + /* Gather all the required signatures - sign() processes them and returns them as ICallData types */ + const permitCallData: ICallData[] = await sign( + [ + { + target: ilkToUse, + spender: ilkToUse.joinAddress, + amount: _collInput, + ignoreIf: + alreadyApproved === true || // Ignore if already approved + ETH_BASED_ASSETS.includes(ilkToUse.id) || // Ignore if dealing with an eTH based collateral + _collInput.eq(ethers.constants.Zero), // || // ignore if zero collateral value + // wrapAssetCallData.length > 0, // Ignore if dealing with a wrapped collateral! + }, + ], + txCode + ); + + /* if ETH is being borrowed, send the borrowed tokens (WETH) to ladle for unwrapping */ + const serveToAddress = () => { + if (isEthBase) return ladleAddress; + // if ( wrapping ) return wrapHandler + return account; + }; + + /** + * + * Collate all the calls required for the process (including depositing ETH, signing permits, and building vault if needed) + * + * */ + const calls: ICallData[] = [ + /* handle wrapped token deposit, if required */ + ...wrapAssetCallData, + + /* Include all the signatures gathered, if required */ + ...permitCallData, + + /* add in the ETH deposit if required */ + ...addEthCallData, + + /* If vault is null, build a new vault, else ignore */ + { + operation: LadleActions.Fn.BUILD, + // swap out selectedSeries for selectedBase + // will also need to add LadleActions changes for VR args - jacob b + args: [selectedBase?.id, ilkToUse.id, '0'] as LadleActions.Args.BUILD_VR, + ignoreIf: !!vault, + }, + + /* If convex-type collateral, add vault using convex ladle module */ + + { + operation: LadleActions.Fn.MODULE, + fnName: ModuleActions.Fn.ADD_VAULT, + args: [ilkToUse.joinAddress, vaultId] as ModuleActions.Args.ADD_VAULT, + targetContract: ConvexLadleModuleContract, + ignoreIf: !!vault || !isConvexCollateral, + }, + + /* commenting out, as VR recipe book doesnt use serve */ + // { + // operation: LadleActions.Fn.SERVE, + // args: [vaultId, serveToAddress(), _collInput, _input, _expectedFyTokenWithSlippage] as LadleActions.Args.SERVE, + // ignoreIf: false, + // }, + + // testing new pour action - jacob b + { + operation: LadleActions.Fn.POUR, + args: [vaultId, ladleAddress, _collInput, _input] as LadleActions.Args.POUR, // TODO - update types - jacob b + ignoreIf: false, + }, + + ...removeEthCallData, + ]; + + /* finally, handle the transaction */ + await transact(calls, txCode); + + /* When complete, update vaults. + If a vault was provided, update it only, + else update ALL vaults (by passing an empty array) + */ + if (selectedBase?.id !== WETH) refetchBaseBal(); + if (selectedIlk?.proxyId !== WETH) refetchIlkBal(); + updateVaults(); + updateAssets([base, ilkToUse, selectedIlk!]); + // updateSeries([series]); -- TODO - do we need to update selectedVR here? - jacob b + }; + + return borrowVariableRate; +}; diff --git a/src/hooks/actionHooks/useRepayDebtVariableRate.ts b/src/hooks/actionHooks/useRepayDebtVariableRate.ts new file mode 100644 index 000000000..2dbdfc4a0 --- /dev/null +++ b/src/hooks/actionHooks/useRepayDebtVariableRate.ts @@ -0,0 +1,241 @@ +import { ethers } from 'ethers'; +import { useContext } from 'react'; +import { calculateSlippage, maxBaseIn, MAX_256, sellBase } from '@yield-protocol/ui-math'; + +import { UserContext } from '../../contexts/UserContext'; +import { ICallData, IVault, ISeries, ActionCodes, LadleActions, IAsset, RoutedActions } from '../../types'; +import { cleanValue, getTxCode } from '../../utils/appUtils'; +import { useChain } from '../useChain'; +import { CONVEX_BASED_ASSETS, ETH_BASED_ASSETS, USDT, WETH } from '../../config/assets'; +import { SettingsContext } from '../../contexts/SettingsContext'; +import { useAddRemoveEth } from './useAddRemoveEth'; +import { ONE_BN, ZERO_BN } from '../../utils/constants'; +import { useWrapUnwrapAsset } from './useWrapUnwrapAsset'; +import { ConvexJoin__factory } from '../../contracts'; +import useTimeTillMaturity from '../useTimeTillMaturity'; +import { Address, useBalance, useNetwork, useProvider } from 'wagmi'; +import useContracts from '../useContracts'; +import useChainId from '../useChainId'; +import useAccountPlus from '../useAccountPlus'; +import { ContractNames } from '../../config/contracts'; +import useAllowAction from '../useAllowAction'; + +export const useRepayDebtVariableRate = () => { + const { + settingsState: { slippageTolerance, diagnostics }, + } = useContext(SettingsContext); + + const { userState, userActions } = useContext(UserContext); + const { seriesMap, assetMap, selectedIlk, selectedBase } = userState; + const { updateVaults, updateAssets, updateSeries } = userActions; + const { address: account } = useAccountPlus(); + const { chain } = useNetwork(); + const provider = useProvider(); + const contracts = useContracts(); + const { refetch: refetchIlkBal } = useBalance({ + address: account, + token: selectedIlk?.address as Address, + }); + const { refetch: refetchBaseBal } = useBalance({ + address: account, + token: selectedBase?.id === WETH ? undefined : (selectedBase?.address as Address), + }); + + const { addEth, removeEth } = useAddRemoveEth(); + const { unwrapAsset } = useWrapUnwrapAsset(); + const { sign, transact } = useChain(); + const { getTimeTillMaturity, isMature } = useTimeTillMaturity(); + const chainId = useChainId(); + + const { isActionAllowed } = useAllowAction(); + + /** + * REPAY FN + * @param vault + * @param input + * @param reclaimCollateral + */ + const repayVariableRate = async (vault: IVault, input: string | undefined, reclaimCollateral: boolean) => { + if (!contracts) return; + + const txCode = getTxCode(ActionCodes.REPAY, vault.id); + + const ladleAddress = contracts.get(ContractNames.VR_LADLE)?.address; + + const vrCauldronAddress = contracts.get(ContractNames.VR_CAULDRON)?.address; + // const series: ISeries = seriesMap?.get(vault.seriesId)!; + const base: IAsset = assetMap?.get(vault.baseId)!; + const ilk: IAsset = assetMap?.get(vault.ilkId)!; + + // if (!isActionAllowed(ActionCodes.REPAY)) return; // return if action is not allowed + + const isEthCollateral = ETH_BASED_ASSETS.includes(vault.ilkId); + const isEthBase = ETH_BASED_ASSETS.includes(base.id); + + /* is convex-type collateral */ + const isConvexCollateral = CONVEX_BASED_ASSETS.includes(ilk.proxyId); + const convexJoinContract = ConvexJoin__factory.connect(ilk.joinAddress, provider); + + /* Parse inputs */ + const cleanInput = cleanValue(input, base.decimals); + const _input = input ? ethers.utils.parseUnits(cleanInput, base.decimals) : ethers.constants.Zero; + + /* + we won't be able to do the below maxSharesIn calculation for VR because + theres no series. Will need to follow up on what to do here - jacob b + + can call Cauldron.balances here to get the debt + call when selects user vault - also worth it to try + and calcultate in the UI + */ + + // const _maxSharesIn = series.sharesReserves.eq(ZERO_BN) + // ? ZERO_BN + // : maxBaseIn( + // series.sharesReserves, + // series.fyTokenReserves, + // getTimeTillMaturity(series.maturity), + // series.ts, + // series.g1, + // series.decimals, + // series.c, + // series.mu + // ); + + /* Check if the trade of that size is possible */ + // assuming all trades are possible for now, but will need to revisit - jacob b + const tradeIsNotPossible = false; + + diagnostics && tradeIsNotPossible ? console.log('Trade is not possible:') : console.log('Trade is possible:'); + diagnostics && tradeIsNotPossible && console.log('Trade input', _input.toString()); + + const _inputAsFyTokenWithSlippage = calculateSlippage( + // remove fyToken references - jacob b + _input, + slippageTolerance.toString(), + true // minimize + ); + + /* Check if input is more than the debt */ + const inputGreaterThanEqualDebt: boolean = ethers.BigNumber.from(_input).gte(vault.accruedArt); + + /* If requested, and all debt will be repaid, automatically remove collateral */ + const _collateralToRemove = + reclaimCollateral && inputGreaterThanEqualDebt ? vault.ink.mul(-1) : ethers.constants.Zero; + + /* Cap the amount to transfer: check that if input is greater than debt, used after maturity only repay the max debt (or accrued debt) */ + const _inputCappedAtArt = vault.art.gt(ZERO_BN) && vault.art.lte(_input) ? vault.art : _input; + + /* Set the amount to transfer ( + 0.1% after maturity ) */ + /* assuming mature here as well - is this right? - jacob b */ + const amountToTransfer = _input.mul(10001).div(10000); + + /* In low liq situations/or mature, send repay funds to join not pool */ + /* I believe we transfer our repayment directly to the ladle, could be wrong here - jacob b */ + // maybe the cauldron directly? - jacob b + const transferToAddress = vrCauldronAddress; + + /* Check if already approved */ + const alreadyApproved = (await base.getAllowance(account!, ladleAddress!)).gte(amountToTransfer); + + // const wrapAssetCallData : ICallData[] = await wrapAsset(ilk, account!); + const unwrapAssetCallData: ICallData[] = reclaimCollateral ? await unwrapAsset(ilk, account!) : []; + + const approveAmount = base.id === USDT && chainId !== 42161 ? MAX_256 : amountToTransfer.mul(110).div(100); + const permitCallData: ICallData[] = await sign( + [ + { + // before maturity + target: base, + spender: 'LADLE', + amount: approveAmount, // generous approval permits on repayment we can refine at a later stage + ignoreIf: alreadyApproved === true, + }, + ], + txCode + ); + + /* Remove ETH collateral. (exit_ether sweeps all the eth out of the ladle, so exact amount is not importnat -> just greater than zero) */ + const removeEthCallData = isEthCollateral ? removeEth(ONE_BN) : []; + + /* Address to send the funds to either ladle (if eth is used as collateral) or account */ + const reclaimToAddress = () => { + if (isEthCollateral) return ladleAddress; + if (unwrapAssetCallData.length && ilk.unwrapHandlerAddresses?.has(chain?.id!)) + return ilk.unwrapHandlerAddresses?.get(chain?.id!); // if there is somethign to unwrap + return account; + }; + + const calls: ICallData[] = [ + ...permitCallData, + + /* Reqd. when we have a wrappedBase */ + // ...wrapAssetCallData + + /* If ethBase, Send ETH to either base join or pool */ + ...addEth(isEthBase ? amountToTransfer : ZERO_BN, transferToAddress), // destination = either join or series depending if tradeable + ...addEth(isEthBase ? amountToTransfer : ZERO_BN), // no destination defined after maturity , input +1% will will go to weth join + + /* Else, Send Token to either join or pool via a ladle.transfer() */ + + // think this is good - jacob b + { + operation: LadleActions.Fn.TRANSFER, + args: [base.address, transferToAddress, amountToTransfer] as LadleActions.Args.TRANSFER, + ignoreIf: isEthBase, + }, + + /* convex-type collateral; ensure checkpoint before giving collateral back to account */ + { + operation: LadleActions.Fn.ROUTE, + args: [vault.owner] as RoutedActions.Args.CHECKPOINT, + fnName: RoutedActions.Fn.CHECKPOINT, + targetContract: convexJoinContract, // use the convex join contract to checkpoint + ignoreIf: !isConvexCollateral || _collateralToRemove.eq(ethers.constants.Zero), + }, + + /* BEFORE MATURITY - !series.seriesIsMature */ + { + operation: LadleActions.Fn.REPAY, + args: [vault.id, account, ladleAddress, _inputAsFyTokenWithSlippage] as LadleActions.Args.REPAY, + ignoreIf: inputGreaterThanEqualDebt || tradeIsNotPossible, + }, + + // { + // operation: LadleActions.Fn.REPAY_VAULT, + // args: [vault.id, reclaimToAddress(), _collateralToRemove, _input] as LadleActions.Args.REPAY_VAULT, + // ignoreIf: + // series.seriesIsMature || + // !inputGreaterThanEqualDebt || // ie ignore if use if input IS NOT more than debt + // tradeIsNotPossible, + // }, + + /* EdgeCase in lowLiq situations : Input GreaterThanMaxbaseIn ( user incurs a penalty because repaid at 1:1 ) */ + // { + // operation: LadleActions.Fn.CLOSE, + // args: [vault.id, reclaimToAddress(), _collateralToRemove, _inputCappedAtArt.mul(-1)] as LadleActions.Args.CLOSE, + // ignoreIf: series.seriesIsMature || !tradeIsNotPossible, // (ie. ignore if trade IS possible ) + // }, + + /* AFTER MATURITY - series.seriesIsMature */ + // { + // operation: LadleActions.Fn.CLOSE, + // args: [vault.id, reclaimToAddress(), _collateralToRemove, _inputCappedAtArt.mul(-1)] as LadleActions.Args.CLOSE, + // ignoreIf: !series.seriesIsMature, + // }, + + ...removeEthCallData, + ...unwrapAssetCallData, + ]; + await transact(calls, txCode); + + if (selectedBase?.proxyId !== WETH) refetchBaseBal(); + if (selectedIlk?.proxyId !== WETH) refetchIlkBal(); + + updateVaults([vault]); + updateAssets([base, ilk, userState.selectedIlk!]); + // updateSeries([series]); + }; + + return repayVariableRate; +}; diff --git a/src/hooks/higherOrderHooks/useAssetPair.ts b/src/hooks/higherOrderHooks/useAssetPair.ts new file mode 100644 index 000000000..fc647bd3e --- /dev/null +++ b/src/hooks/higherOrderHooks/useAssetPair.ts @@ -0,0 +1,20 @@ +/* HOOKS */ +import useAssetPairFixedRate from '../useAssetPairFixedRate'; +import useAssetPairVariableRate from '../useAssetPairVariableRate'; +import { useContext } from 'react'; + +/* CONTEXTS */ +import { UserContext } from '../../contexts/UserContext'; + +const useAssetPair = (baseId?: string, ilkId?: string, seriesId?: string) => { + const { userState } = useContext(UserContext); + const { selectedVR } = userState; + + if (selectedVR) { + return useAssetPairVariableRate(baseId, ilkId); + } else { + return useAssetPairFixedRate(baseId, ilkId, seriesId); + } +}; + +export default useAssetPair; diff --git a/src/hooks/higherOrderHooks/useCollateralHelpers.ts b/src/hooks/higherOrderHooks/useCollateralHelpers.ts new file mode 100644 index 000000000..0762599b6 --- /dev/null +++ b/src/hooks/higherOrderHooks/useCollateralHelpers.ts @@ -0,0 +1,18 @@ +/* HOOKS */ +import { useCollateralHelpersFixedRate } from '../viewHelperHooks/useCollateralHelpersFixedRate'; +import { useCollateralHelpersVariableRate } from '../viewHelperHooks/useCollateralHelpersVariableRate'; + +/* TYPES */ +import { IAssetPair, IVault } from '../../types'; + +export const useCollateralHelpers = ( + debtInput: string | undefined, + collInput: string | undefined, + vault: IVault | undefined, + assetPairInfo: IAssetPair | undefined | null, + isVariableRate: boolean | undefined | null +) => { + const baseHook = isVariableRate ? useCollateralHelpersVariableRate : useCollateralHelpersFixedRate; + + return baseHook(debtInput, collInput, vault, assetPairInfo); +}; diff --git a/src/hooks/useAssetPair.ts b/src/hooks/useAssetPairFixedRate.ts similarity index 95% rename from src/hooks/useAssetPair.ts rename to src/hooks/useAssetPairFixedRate.ts index a8f550435..21735b811 100644 --- a/src/hooks/useAssetPair.ts +++ b/src/hooks/useAssetPairFixedRate.ts @@ -16,7 +16,7 @@ import useDefaultProvider from './useDefaultProvider'; import { SettingsContext } from '../contexts/SettingsContext'; // This hook is used to get the asset pair info for a given base and collateral (ilk) -const useAssetPair = (baseId?: string, ilkId?: string, seriesId?: string) => { +const useAssetPairFixedRate = (baseId?: string, ilkId?: string, seriesId?: string) => { /* CONTEXT STATE */ const { userState: { assetMap }, @@ -156,6 +156,9 @@ const useAssetPair = (baseId?: string, ilkId?: string, seriesId?: string) => { } ); + console.log('validIlks non VR: ', validIlks, baseId, ilkId, seriesId); + console.log('useAssetPair data: ', data); + return { data, error, @@ -167,4 +170,4 @@ const useAssetPair = (baseId?: string, ilkId?: string, seriesId?: string) => { }; }; -export default useAssetPair; +export default useAssetPairFixedRate; diff --git a/src/hooks/useAssetPairVariableRate.tsx b/src/hooks/useAssetPairVariableRate.tsx new file mode 100644 index 000000000..7ee1a8e8a --- /dev/null +++ b/src/hooks/useAssetPairVariableRate.tsx @@ -0,0 +1,176 @@ +import { useCallback, useContext, useEffect, useMemo } from 'react'; +import { IAsset, IAssetPair } from '../types'; +import { BigNumber, ethers } from 'ethers'; +import useSWR from 'swr'; + +import { bytesToBytes32, decimal18ToDecimalN, WAD_BN } from '@yield-protocol/ui-math'; +import useContracts from './useContracts'; +import { VRCauldron, CompositeMultiOracle__factory } from '../contracts'; +import useChainId from './useChainId'; +import { UserContext } from '../contexts/UserContext'; +import { stETH, wstETH } from '../config/assets'; +import { ContractNames } from '../config/contracts'; +import useFork from './useFork'; +import { JsonRpcProvider, Provider } from '@ethersproject/providers'; +import useDefaultProvider from './useDefaultProvider'; +import { SettingsContext } from '../contexts/SettingsContext'; + +// This hook is used to get the asset pair info for a given base and collateral (ilk) +const useAssetPairVariableRate = (baseId?: string, ilkId?: string) => { + console.log('useAssetPairVariableRate args: ', baseId, ilkId); + + /* CONTEXT STATE */ + const { + userState: { assetMap }, + } = useContext(UserContext); + + const { + settingsState: { diagnostics }, + } = useContext(SettingsContext); + + const chainId = useChainId(); + + /* HOOKS */ + const provider = useDefaultProvider(); + const { useForkedEnv, provider: forkProvider, forkUrl, forkStartBlock } = useFork(); + const contracts = useContracts(); + + /* GET PAIR INFO */ + const getAssetPair = async (baseId: string, ilkId: string): Promise => { + const Cauldron = contracts?.get(ContractNames.VR_CAULDRON) as VRCauldron; + + const _base = assetMap.get(baseId); + const _ilk = assetMap.get(ilkId); + + if (!_base || !_ilk) { + return undefined; + } + + const [oracleAddr] = await Cauldron.spotOracles(baseId, ilkId); + + if (oracleAddr === ethers.constants.AddressZero) { + throw new Error(`no oracle set for base: ${baseId} and ilk: ${ilkId}}`); + } + + const oracleContract = CompositeMultiOracle__factory.connect(oracleAddr, provider); // using the composite multi oracle but all oracles should have the same interface + + diagnostics && console.log('Getting Asset Pair Info VR: ', baseId, ilkId); + + /* Get debt params and spot ratios */ + const [{ max, min, sum, dec }, { ratio }] = await Promise.all([ + Cauldron.debt(baseId, ilkId), + Cauldron.spotOracles(baseId, ilkId), + ]); + + /* get pricing if available */ + let price: BigNumber; + try { + [price] = await oracleContract.peek( + bytesToBytes32(ilkId, 6), + bytesToBytes32(baseId, 6), + decimal18ToDecimalN(WAD_BN, _ilk.decimals) + ); + } catch (error) { + console.log('Error getting pricing for: ', baseId, ilkId, error); + price = ethers.constants.Zero; + } + + return { + baseId, + ilkId, + limitDecimals: dec, + minDebtLimit: BigNumber.from(min).mul(BigNumber.from('10').pow(dec)), // NB use limit decimals here > might not be same as base/ilk decimals + maxDebtLimit: max.mul(BigNumber.from('10').pow(dec)), // NB use limit decimals here > might not be same as base/ilk decimals + pairTotalDebt: sum, + pairPrice: price, // value of 1 ilk (1x10**n) in terms of base. + minRatio: parseFloat(ethers.utils.formatUnits(ratio, 6)), // pre-format ratio + baseDecimals: _base.decimals, + }; + }; + + // This function is used to generate the key for the useSWR hook + const genKey = useCallback( + (baseId: string, ilkId: string) => { + return ['assetPair', chainId, baseId, ilkId]; + }, + [chainId] + ); + + const { data, error } = useSWR( + baseId && ilkId ? () => genKey(baseId, ilkId) : null, + () => getAssetPair(baseId!, ilkId!), + { + revalidateIfStale: false, + revalidateOnFocus: false, + revalidateOnReconnect: false, + } + ); + + const getSeriesEntityIlks = useCallback(async () => { + if (!baseId) return undefined; + + console.log('baseId in getSeriesEntity Ilks', bytesToBytes32(baseId, 6), provider); + + const getIlkAddedEvents = async ( + provider: JsonRpcProvider | Provider, + baseId: string, + fromBlock?: number | string + ) => { + const cauldron = contracts?.get(ContractNames.VR_CAULDRON)?.connect(provider) as VRCauldron; + console.log('gettingIlkAddedEvents VR', provider); + try { + return await cauldron.queryFilter( + cauldron.filters.IlkAdded(bytesToBytes32(baseId, 6)), + + fromBlock || 'earliest' + ); + } catch (e) { + console.log('error getting ilk added events: ', e); + return []; + } + }; + + let ilkAddedEvents = new Set(await getIlkAddedEvents(provider, baseId)); + + // get cauldron ilkAdded events for this series id using fork env + if (useForkedEnv && forkProvider) { + ilkAddedEvents = new Set([...ilkAddedEvents, ...(await getIlkAddedEvents(forkProvider, baseId, forkStartBlock))]); + } + console.log('ilkAddedEvents VR', ilkAddedEvents, baseId); + + return [...ilkAddedEvents.values()].reduce((acc, { args: { ilkId } }) => { + const asset = assetMap.get(ilkId.toLowerCase()); + if (!asset) return acc; + + // handle/add stETH if wstETH; it's wrapped to wstETH by default and doesn't have an addIlk event + return asset.id.toLowerCase() === wstETH.toLowerCase() + ? [...acc, asset, assetMap.get(stETH.toLowerCase())!] + : [...acc, asset]; + }, [] as IAsset[]); + }, [assetMap, contracts, forkProvider, forkStartBlock, provider, useForkedEnv]); + + const { data: validIlks, error: validIlksError } = useSWR( + baseId ? ['baseIlks', chainId, useForkedEnv, forkUrl, baseId] : null, + getSeriesEntityIlks, + { + shouldRetryOnError: false, + revalidateOnFocus: false, + } + ); + + console.log('validIlks VR: ', validIlks, baseId, ilkId); + + console.log('useAssetPairVariableRate data: ', data); + + return { + data, + error, + isLoading: !data && !error, + getAssetPair, + genKey, + validIlks, + validIlksLoading: !validIlks && !validIlksError, + }; +}; + +export default useAssetPairVariableRate; diff --git a/src/hooks/useChain.ts b/src/hooks/useChain.ts index 6f9624db7..185d6e81f 100644 --- a/src/hooks/useChain.ts +++ b/src/hooks/useChain.ts @@ -6,7 +6,7 @@ import { TxContext } from '../contexts/TxContext'; import { ApprovalType, ICallData, ISignData, LadleActions, TokenType } from '../types'; import { MAX_256, ZERO_BN } from '../utils/constants'; -import { ERC1155__factory, ERC20Permit__factory, Ladle } from '../contracts'; +import { ERC1155__factory, ERC20Permit__factory, Ladle, VRLadle } from '../contracts'; import { useApprovalMethod } from './useApprovalMethod'; import { SettingsContext } from '../contexts/SettingsContext'; import { useNetwork, useSigner } from 'wagmi'; @@ -51,9 +51,10 @@ export const useChain = () => { */ const transact = async (calls: ICallData[], txCode: string): Promise => { if (!contracts) return; - + /* Set the router contract instance, ladle by default */ - const _contract: Contract = contracts.get(ContractNames.LADLE)?.connect(signer!) as Ladle; + // const _contract: Contract = contracts.get(ContractNames.LADLE)?.connect(signer!) as Ladle; + const _contract: Contract = contracts.get(ContractNames.VR_LADLE)?.connect(signer!) as VRLadle; /* First, filter out any ignored calls */ const _calls = calls.filter((call: ICallData) => !call.ignoreIf); diff --git a/src/hooks/useInputValidation.ts b/src/hooks/useInputValidation.ts index 2f974e410..bd211f92c 100644 --- a/src/hooks/useInputValidation.ts +++ b/src/hooks/useInputValidation.ts @@ -14,6 +14,8 @@ export const useInputValidation = ( limits: (number | string | undefined)[], vault?: IVault | undefined ) => { + console.log('useInputValidation args: ', input, actionCode, series, limits, vault); + /* STATE FROM CONTEXT */ const { userState } = useContext(UserContext); const { assetMap, selectedSeries, selectedBase } = userState; @@ -63,6 +65,7 @@ export const useInputValidation = ( case ActionCodes.REPAY: case ActionCodes.ROLL_DEBT: + console.log('useInputValidation: REPAY || ROLL_DEBT', limits[0], _inputAsFloat, actionCode); /* set dust limit Error between 0 and dustLimit */ limits[0] && _inputAsFloat > parseFloat(limits[0].toString()) && diff --git a/src/hooks/useProcess.ts b/src/hooks/useProcess.ts index 23ef6eb81..7be14aaf2 100644 --- a/src/hooks/useProcess.ts +++ b/src/hooks/useProcess.ts @@ -33,6 +33,7 @@ export const useProcess = ( useEffect(() => { const _process = processes.get(txCode); + console.log('useProcess: ', _process); if (_process) setTxProcess(_process); }, [processes, txCode]); diff --git a/src/hooks/viewHelperHooks/useBorrowHelpers.ts b/src/hooks/viewHelperHooks/useBorrowHelpers.ts index 3191f01aa..5d2cb1d11 100644 --- a/src/hooks/viewHelperHooks/useBorrowHelpers.ts +++ b/src/hooks/viewHelperHooks/useBorrowHelpers.ts @@ -109,6 +109,7 @@ export const useBorrowHelpers = ( const input_ = ethers.utils.parseUnits(cleanedInput, vault.decimals); /* remaining debt is debt in base less input (with a minimum of zero) */ const remainingDebt = debtInBase.sub(input_).gte(ZERO_BN) ? debtInBase.sub(input_) : ZERO_BN; + console.log('remainingDebt', debtInBase.sub(input_).gte(ZERO_BN)); setDebtAfterRepay(remainingDebt); } }, [input, vault, debtInBase]); @@ -139,7 +140,7 @@ export const useBorrowHelpers = ( /* SET MAX ROLL and ROLLABLE including Check if the rollToSeries have sufficient base value AND won't be undercollaterallised */ useEffect(() => { - if (futureSeries && vault && vault.accruedArt) { + if (futureSeries && vault && vault.accruedArt && vault.seriesId) { const _maxFyTokenIn = maxFyTokenIn( futureSeries.sharesReserves, futureSeries.fyTokenReserves, @@ -201,48 +202,29 @@ export const useBorrowHelpers = ( /* Update the Min Max repayable amounts */ useEffect(() => { if (account && vault && vaultBase && minDebt) { - const vaultSeries = seriesMap.get(vault?.seriesId!); - if (!vaultSeries) return; - - /* estimate max fyToken out to assess protocol limits */ - const _maxFyTokenOut = maxFyTokenOut( - vaultSeries.sharesReserves, - vaultSeries.fyTokenReserves, - getTimeTillMaturity(vaultSeries.maturity), - vaultSeries.ts, - vaultSeries.g1, - vaultSeries.decimals, - vaultSeries.c, - vaultSeries.mu - ); + console.log('in borrowHelpers just below useEffect if', vault, vaultBase, minDebt); - const limited = _maxFyTokenOut.lt(vault.accruedArt); + const isVRVault = !vault?.seriesId; - /* adjust max repayable to vault art if protocol limited */ - if (limited) { - const accruedArt_ = ethers.utils.formatUnits(vault.accruedArt, vault.decimals); - setMaxRepay(vault.accruedArt); - setMaxRepay_(accruedArt_); + if (isVRVault) { + console.log('%c VR VAULT', 'color: green; font-weight: bold; font-size: 36px;'); + // setMaxRepay(vault.accruedArt); + // setMaxRepay_(vault.accruedArt_); setDebtInBase(vault.accruedArt); - setDebtInBase_(accruedArt_); - } else { - const _sharesRequired = buyFYToken( - vaultSeries.sharesReserves, - vaultSeries.fyTokenReserves, - vault.accruedArt, - getTimeTillMaturity(vaultSeries.maturity), - vaultSeries.ts, - vaultSeries.g1, - vaultSeries.decimals, - vaultSeries.c, - vaultSeries.mu - ); + setDebtInBase_(vault.accruedArt_); - const _baseRequired = vault.accruedArt.eq(ethers.constants.Zero) - ? ethers.constants.Zero - : vaultSeries.getBase(_sharesRequired); + // some of the below is dupe code from the else statement - TODO refactor - jacob b + + /* + an assumption is made in much of the below logic that because VR borrows arent series, + and thus have no maturity date, I've modified the conditionals from the else statement to default + to the isMature option. Is this the right way to think about it? - jacob b + */ + + const _baseRequired = vault.accruedArt.eq(ethers.constants.Zero) ? ethers.constants.Zero : vault.accruedArt; // modified this logic from original, TODO verify this logic - jacob b + // const _debtInBase = vault.accruedArt; + const _debtInBase = _baseRequired; - const _debtInBase = isMature(vaultSeries.maturity) ? vault.accruedArt : _baseRequired; // add buffer to handle moving interest accumulation const _debtInBaseWithBuffer = _debtInBase.mul(1000).div(999); @@ -258,16 +240,82 @@ export const useBorrowHelpers = ( _maxToDust && setMinRepayable(_maxToDust); _maxToDust && setMinRepayable_(ethers.utils.formatUnits(_maxToDust, vaultBase?.decimals)?.toString()); - /* if the series is mature re-set max as all debt (if balance allows) */ - if (vaultSeries.seriesIsMature) { - const _accruedArt = vault.accruedArt.gt(baseBalance?.value || ethers.constants.Zero) - ? baseBalance?.value! - : vault.accruedArt; - setMaxRepay(_accruedArt); - setMaxRepay_(ethers.utils.formatUnits(_accruedArt, vaultBase?.decimals)?.toString()); + const _accruedArt = vault.accruedArt.gt(baseBalance?.value || ethers.constants.Zero) + ? baseBalance?.value! + : vault.accruedArt; + setMaxRepay(_accruedArt); + setMaxRepay_(debtInBase_); + } else { + const vaultSeries = seriesMap.get(vault?.seriesId!); + if (!vaultSeries) return; + + /* estimate max fyToken out to assess protocol limits */ + const _maxFyTokenOut = maxFyTokenOut( + vaultSeries.sharesReserves, + vaultSeries.fyTokenReserves, + getTimeTillMaturity(vaultSeries.maturity), + vaultSeries.ts, + vaultSeries.g1, + vaultSeries.decimals, + vaultSeries.c, + vaultSeries.mu + ); + + const limited = _maxFyTokenOut.lt(vault.accruedArt); + + /* adjust max repayable to vault art if protocol limited */ + if (limited) { + const accruedArt_ = ethers.utils.formatUnits(vault.accruedArt, vault.decimals); // is this necessary? seems this is already done in vault - jacob b + setMaxRepay(vault.accruedArt); + setMaxRepay_(accruedArt_); + setDebtInBase(vault.accruedArt); + setDebtInBase_(accruedArt_); } else { - setMaxRepay_(ethers.utils.formatUnits(_maxRepayable, vaultBase.decimals)); - setMaxRepay(_maxRepayable); + const _sharesRequired = buyFYToken( + vaultSeries.sharesReserves, + vaultSeries.fyTokenReserves, + vault.accruedArt, + getTimeTillMaturity(vaultSeries.maturity), + vaultSeries.ts, + vaultSeries.g1, + vaultSeries.decimals, + vaultSeries.c, + vaultSeries.mu + ); + + const _baseRequired = vault.accruedArt.eq(ethers.constants.Zero) + ? ethers.constants.Zero + : vaultSeries.getBase(_sharesRequired); + + const _debtInBase = isMature(vaultSeries.maturity) ? vault.accruedArt : _baseRequired; + // add buffer to handle moving interest accumulation + const _debtInBaseWithBuffer = _debtInBase.mul(1000).div(999); + + setDebtInBase(_debtInBaseWithBuffer); + setDebtInBase_(ethers.utils.formatUnits(_debtInBaseWithBuffer, vaultBase.decimals)); + + /* maxRepayable is either the max tokens they have or max debt */ + const _maxRepayable = + baseBalance?.value && _debtInBaseWithBuffer.gt(baseBalance.value) + ? baseBalance.value + : _debtInBaseWithBuffer; + + /* set the min repayable up to the dust limit */ + const _maxToDust = vault.accruedArt.gt(minDebt) ? _maxRepayable.sub(minDebt) : vault.accruedArt; + _maxToDust && setMinRepayable(_maxToDust); + _maxToDust && setMinRepayable_(ethers.utils.formatUnits(_maxToDust, vaultBase?.decimals)?.toString()); + + /* if the series is mature re-set max as all debt (if balance allows) */ + if (vaultSeries.seriesIsMature) { + const _accruedArt = vault.accruedArt.gt(baseBalance?.value || ethers.constants.Zero) + ? baseBalance?.value! + : vault.accruedArt; + setMaxRepay(_accruedArt); + setMaxRepay_(ethers.utils.formatUnits(_accruedArt, vaultBase?.decimals)?.toString()); + } else { + setMaxRepay_(ethers.utils.formatUnits(_maxRepayable, vaultBase.decimals)); + setMaxRepay(_maxRepayable); + } } } } @@ -283,6 +331,37 @@ export const useBorrowHelpers = ( vaultBase, ]); + console.log('useBorrowHelpers RETURNs', vault, debtAfterRepay?.toString(), vaultBase); + console.table({ + borrowPossible, + rollPossible, + rollProtocolLimited, + + borrowEstimate, + borrowEstimate_, + + maxRepay_, + maxRepay, + + debtInBase, + debtInBase_, + + debtAfterRepay, + + minRepayable, + minRepayable_, + + maxRoll, + maxRoll_, + + userBaseBalance: baseBalance?.value, + userBaseBalance_: baseBalance?.formatted, + maxDebt, + minDebt, + maxDebt_, + minDebt_, + }); + return { borrowPossible, rollPossible, diff --git a/src/hooks/viewHelperHooks/useCollateralHelpers.ts b/src/hooks/viewHelperHooks/useCollateralHelpersFixedRate.ts similarity index 98% rename from src/hooks/viewHelperHooks/useCollateralHelpers.ts rename to src/hooks/viewHelperHooks/useCollateralHelpersFixedRate.ts index ce296f173..0aac02c73 100644 --- a/src/hooks/viewHelperHooks/useCollateralHelpers.ts +++ b/src/hooks/viewHelperHooks/useCollateralHelpersFixedRate.ts @@ -18,11 +18,11 @@ import { WETH } from '../../config/assets'; import useAccountPlus from '../useAccountPlus'; /* Collateralization hook calculates collateralization metrics */ -export const useCollateralHelpers = ( +export const useCollateralHelpersFixedRate = ( debtInput: string | undefined, collInput: string | undefined, vault: IVault | undefined, - assetPairInfo: IAssetPair | undefined| null + assetPairInfo: IAssetPair | undefined | null ) => { /* STATE FROM CONTEXT */ const { @@ -38,7 +38,7 @@ export const useCollateralHelpers = ( const { address: activeAccount } = useAccountPlus(); const { data: userIlkBalance } = useBalance({ address: activeAccount, - token: _selectedIlk?.proxyId === WETH ? undefined : _selectedIlk?.address as Address, + token: _selectedIlk?.proxyId === WETH ? undefined : (_selectedIlk?.address as Address), enabled: !!_selectedIlk, }); diff --git a/src/hooks/viewHelperHooks/useCollateralHelpersVariableRate.ts b/src/hooks/viewHelperHooks/useCollateralHelpersVariableRate.ts new file mode 100644 index 000000000..149eb7ef7 --- /dev/null +++ b/src/hooks/viewHelperHooks/useCollateralHelpersVariableRate.ts @@ -0,0 +1,282 @@ +import { BigNumber, ethers } from 'ethers'; +import { useContext, useEffect, useState } from 'react'; +import { + calcLiquidationPrice, + calculateCollateralizationRatio, + calculateMinCollateral, + decimalNToDecimal18, +} from '@yield-protocol/ui-math'; + +import { UserContext } from '../../contexts/UserContext'; +import { IAssetPair, IVault } from '../../types'; +import { cleanValue } from '../../utils/appUtils'; +import { ZERO_BN } from '../../utils/constants'; +import { Address, useAccount, useBalance } from 'wagmi'; +import { WETH } from '../../config/assets'; +import useAccountPlus from '../useAccountPlus'; + +/* Collateralization hook calculates collateralization metrics */ +export const useCollateralHelpersVariableRate = ( + debtInput: string | undefined, + collInput: string | undefined, + vault: IVault | undefined, + assetPairInfo: IAssetPair | undefined | null +) => { + /* STATE FROM CONTEXT */ + const { + userState: { selectedBase, selectedIlk, selectedSeries, assetMap, seriesMap }, + } = useContext(UserContext); + + const _selectedBase = vault ? assetMap?.get(vault.baseId) : selectedBase; + const _selectedIlk = vault ? assetMap?.get(vault.ilkId) : selectedIlk; + // const _selectedSeries = vault ? seriesMap?.get(vault.seriesId) : selectedSeries; + + /* HOOKS */ + const { address: activeAccount } = useAccountPlus(); + const { data: userIlkBalance } = useBalance({ + address: activeAccount, + token: _selectedIlk?.proxyId === WETH ? undefined : (_selectedIlk?.address as Address), + enabled: !!_selectedIlk, + }); + + /* LOCAL STATE */ + const [collateralizationRatio, setCollateralizationRatio] = useState(); + const [collateralizationPercent, setCollateralizationPercent] = useState(); + const [undercollateralized, setUndercollateralized] = useState(true); + const [unhealthyCollatRatio, setUnhealthyCollatRatio] = useState(false); + + const [oraclePrice, setOraclePrice] = useState(ethers.constants.Zero); + + const [liquidationPrice_, setLiquidationPrice_] = useState(); + + const [minCollateral, setMinCollateral] = useState(); + const [minCollateral_, setMinCollateral_] = useState(); + + const [minCollatRatio, setMinCollatRatio] = useState(); + const [minCollatRatioPct, setMinCollatRatioPct] = useState(); + const [minSafeCollatRatio, setMinSafeCollatRatio] = useState(); + const [minSafeCollatRatioPct, setMinSafeCollatRatioPct] = useState(); + const [minSafeCollateral, setMinSafeCollateral] = useState(); + const [maxRemovableCollateral, setMaxRemovableCollateral] = useState(); + const [maxCollateral, setMaxCollateral] = useState(); + + const [totalDebt, setTotalDebt] = useState(); + const [totalDebt_, setTotalDebt_] = useState(); + + const [totalCollateral, setTotalCollateral] = useState(); + const [totalCollateral_, setTotalCollateral_] = useState(); + + /* update the prices/limits if anything changes with the asset pair */ + useEffect(() => { + if (assetPairInfo) { + /* set the pertinent oracle price */ + setOraclePrice(decimalNToDecimal18(assetPairInfo.pairPrice, assetPairInfo.baseDecimals)); + + /* set min collaterateralisation ratio */ + setMinCollatRatio(assetPairInfo.minRatio); + setMinCollatRatioPct(Math.round(assetPairInfo.minRatio * 100).toString()); + + /* set min safe coll ratio */ + const _minSafe = () => { + if (assetPairInfo.minRatio >= 1.5) return assetPairInfo.minRatio + 1; // eg. 150% -> 250% + if (assetPairInfo.minRatio < 1.5 && assetPairInfo.minRatio >= 1.4) return assetPairInfo.minRatio + 0.65; // eg. 140% -> 200% + if (assetPairInfo.minRatio < 1.4 && assetPairInfo.minRatio > 1.01) return assetPairInfo.minRatio + 0.1; // eg. 133% -> 143% + return assetPairInfo.minRatio; // eg. 110% -> 110% + }; + + setMinSafeCollatRatio(_minSafe()); + setMinSafeCollatRatioPct((_minSafe() * 100).toString()); + + const liqPrice = vault + ? cleanValue( + calcLiquidationPrice(vault.ink_, vault.accruedArt_, assetPairInfo.minRatio), + _selectedBase?.digitFormat + ) + : cleanValue( + calcLiquidationPrice(totalCollateral_!, totalDebt_!, assetPairInfo.minRatio), + _selectedBase?.digitFormat + ); + + setLiquidationPrice_(liqPrice); + } + }, [_selectedBase?.digitFormat, assetPairInfo, totalCollateral_, totalDebt_, vault]); + + /* CHECK collateral selection and sets the max available collateral a user can add based on his balance */ + useEffect(() => { + setMaxCollateral(userIlkBalance?.formatted); + }, [userIlkBalance?.formatted]); + + /* handle changes to input values */ + useEffect(() => { + /* NOTE: this whole function ONLY deals with decimal18, existing values are converted to decimal18 */ + const _existingCollateral = vault?.ink ? vault.ink : ethers.constants.Zero; + const existingCollateralAsWei = decimalNToDecimal18(_existingCollateral, _selectedIlk?.decimals || 18); + + const newCollateralAsWei = + collInput && Math.abs(parseFloat(collInput)) > 0 ? ethers.utils.parseUnits(collInput, 18) : ethers.constants.Zero; + const _totalCollateral = existingCollateralAsWei.add(newCollateralAsWei); + + setTotalCollateral(_totalCollateral); + setTotalCollateral_(ethers.utils.formatUnits(_totalCollateral, 18)); + + console.log('useCollateralHelpers VR', _existingCollateral, existingCollateralAsWei, newCollateralAsWei); + + const existingDebt_ = vault?.accruedArt ? vault.accruedArt : ethers.constants.Zero; + const existingDebtAsWei = decimalNToDecimal18(existingDebt_, _selectedBase?.decimals || 18); + const newDebt = + debtInput && Math.abs(parseFloat(debtInput)) > 0 + ? ethers.utils.parseUnits(debtInput, _selectedBase?.decimals) + : ethers.constants.Zero; // TODO: why is this not decimal18 + + // console.log('newDebt in useCollateralHelpers', newDebt); + + const newDebtAsWei = decimalNToDecimal18(newDebt, _selectedBase?.decimals || 18); + const _totalDebt = existingDebtAsWei.add(newDebtAsWei); + + // console.log('useCollateralHelpers VR', _totalDebt, ethers.utils.formatUnits(_totalDebt, 18)); + // the above value seems right for totalDebt - Jacob b + + setTotalDebt(_totalDebt); + setTotalDebt_(ethers.utils.formatUnits(_totalDebt, 18)); + + console.log( + 'useCollateralHelpers VR before calc if/else', + oraclePrice.gt(ethers.constants.Zero), + _totalCollateral.gt(ethers.constants.Zero) + ); + + /* set the collateral ratio when collateral is entered */ + if (oraclePrice.gt(ethers.constants.Zero) && _totalCollateral.gt(ethers.constants.Zero)) { + const ratio = calculateCollateralizationRatio(_totalCollateral, oraclePrice, _totalDebt, false); + const percent = calculateCollateralizationRatio(_totalCollateral, oraclePrice, _totalDebt, true); + setCollateralizationRatio(ratio?.toString() || '0'); + setCollateralizationPercent(parseFloat(percent?.toString()! || '0').toFixed(2)); + + console.log( + '%c in if useCollateralHelpers, trying to calc collat ratio', + 'font-size: 35px;', + calculateCollateralizationRatio(_totalCollateral, oraclePrice, _totalDebt, false), + + _totalCollateral, + oraclePrice.toString(), + _totalDebt.toString() + ); + } else { + console.log('%c in else useCollateralHelpers, setting collat ratio to 0', 'font-size: 48px;'); + + setCollateralizationRatio('0.0'); + setCollateralizationPercent(cleanValue('0.0', 2)); + } + + /* check minimum collateral required base on debt */ + if (oraclePrice.gt(ethers.constants.Zero)) { + const min = calculateMinCollateral(oraclePrice, _totalDebt, minCollatRatio!.toString(), existingCollateralAsWei); + const minSafeCalc = calculateMinCollateral( + oraclePrice, + _totalDebt, + (minSafeCollatRatio || 2.5).toString(), + existingCollateralAsWei + ); + + /* + Check max collateral that is removable (based on exisiting debt) + use a buffer of 1% if there is vault debt to prevent undercollateralized failed tx's + else use the existing collateral + UPDATE: not required anymore + */ + const _maxRemove = vault?.accruedArt?.gt(ethers.constants.Zero) + ? existingCollateralAsWei.sub(min).mul(95).div(100) + : existingCollateralAsWei; + setMaxRemovableCollateral( + ethers.utils + .formatUnits(_maxRemove.gt(ethers.constants.Zero) ? _maxRemove : ethers.constants.Zero, 18) + .toString() + ); + + // factor in the current collateral input if there is a valid chosen vault + const minSafeWithCollat = BigNumber.from(minSafeCalc).sub(existingCollateralAsWei); + + // check for valid min safe scenarios + const minSafe = minSafeWithCollat.gt(ethers.constants.Zero) + ? ethers.utils.formatUnits(minSafeWithCollat, 18).toString() + : undefined; + setMinSafeCollateral(minSafe); + + setMinCollateral(min as BigNumber); + setMinCollateral_(ethers.utils.formatUnits(min, 18).toString()); + } else { + setMinCollateral(ZERO_BN); + setMinCollateral_('0'); + } + }, [ + collInput, + debtInput, + _selectedIlk, + oraclePrice, + vault, + collateralizationRatio, + _selectedBase, + minCollatRatio, + minSafeCollatRatio, + ]); + + /* Monitor for undercollaterization/ danger-collateralisation, and set flags if reqd. */ + useEffect(() => { + parseFloat(collateralizationRatio!) >= minCollatRatio! + ? setUndercollateralized(false) + : setUndercollateralized(true); + + collateralizationRatio && + vault && + vault.accruedArt?.gt(ethers.constants.Zero) && + assetPairInfo?.minRatio! > 1.2 && + parseFloat(collateralizationRatio) > 0 && + parseFloat(collateralizationRatio) < assetPairInfo?.minRatio! + 0.2 + ? setUnhealthyCollatRatio(true) + : setUnhealthyCollatRatio(false); + }, [assetPairInfo?.minRatio, collateralizationRatio, minCollatRatio, vault]); + + console.log('%c useCollateralHelpers returns', 'color: #00ff00; font-size: 24px;', { + collateralizationRatio, + collateralizationPercent, + undercollateralized, + minCollateral, + minCollateral_, + minCollatRatioPct, + minSafeCollatRatioPct, + minSafeCollateral, + maxCollateral, + maxRemovableCollateral, + unhealthyCollatRatio, + + totalDebt, + totalDebt_, + + totalCollateral, + totalCollateral_, + + liquidationPrice_, + }); + + return { + collateralizationRatio, + collateralizationPercent, + undercollateralized, + minCollateral, + minCollateral_, + minCollatRatioPct, + minSafeCollatRatioPct, + minSafeCollateral, + maxCollateral, + maxRemovableCollateral, + unhealthyCollatRatio, + + totalDebt, + totalDebt_, + + totalCollateral, + totalCollateral_, + + liquidationPrice_, + }; +}; diff --git a/src/hooks/viewHelperHooks/useDashboardHelpers.ts b/src/hooks/viewHelperHooks/useDashboardHelpers.ts index b42a5db0c..857b1da92 100644 --- a/src/hooks/viewHelperHooks/useDashboardHelpers.ts +++ b/src/hooks/viewHelperHooks/useDashboardHelpers.ts @@ -9,7 +9,7 @@ import { cleanValue } from '../../utils/appUtils'; import { USDC, USDT, WETH } from '../../config/assets'; import { ZERO_BN } from '../../utils/constants'; import useTimeTillMaturity from '../useTimeTillMaturity'; -import useAssetPair from '../useAssetPair'; +import useAssetPair from '../useAssetPairFixedRate'; import { unstable_serialize, useSWRConfig } from 'swr'; import { toast } from 'react-toastify'; diff --git a/src/types/index.ts b/src/types/index.ts index baed47107..5cdcdf9b5 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -111,7 +111,7 @@ export interface ISeriesRoot extends ISignable { oppEndColor: string; seriesMark: ReactNode; - + allowActions: (ActionCodes | 'allow_all' | 'allow_none')[]; } @@ -206,7 +206,7 @@ export interface IVaultRoot { id: string; ilkId: string; baseId: string; - seriesId: string; + seriesId?: string; // VR vaults won't have a series displayName: string; decimals: number; } @@ -266,6 +266,26 @@ export interface IVault extends IVaultRoot { accruedArt_: string; } +export interface IVaultVR extends IVaultRoot { + owner: string; + + isWitchOwner: boolean; + hasBeenLiquidated: boolean; + + isActive: boolean; + ink: BigNumber; + art: BigNumber; + accruedArt: BigNumber; // TODO how do i get this value? -jacob b + + ink_: string; + art_: string; + + rate: BigNumber; + rate_: string; + + accruedArt_: string; +} + export interface IStrategy extends IStrategyRoot { currentSeries: ISeries | undefined; active: boolean; diff --git a/src/types/operations.ts b/src/types/operations.ts index fbaa89137..e59cead5f 100644 --- a/src/types/operations.ts +++ b/src/types/operations.ts @@ -31,6 +31,11 @@ export namespace LadleActions { export namespace Args { export type BUILD = [seriesId_bytes6: string, ilkId_bytes6: string, salt_bytes8: string]; + + // new for VR - should we augment this type instead of creating a new one? - jacob b + export type BUILD_VR = [baseId_bytes6: string, ilkId_bytes6: string, salt_bytes8: string]; // TODO - update types - jacob b + export type TRANSFER_VR = [ilkId_bytes6: string, to: string, base: BigNumberish, art: BigNumberish]; // TODO - update types - jacob b + export type ROLL = [vaultId: string, newSeriesId: string, loan: BigNumberish, max: BigNumberish]; export type TWEAK = [vaultId: string, seriesId: string, ilkId: string]; export type GIVE = [vaultId: string, to: string]; From 2e4c1ab36368b03926128e32151a1bac64b41ea9 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Wed, 12 Apr 2023 11:38:44 -0700 Subject: [PATCH 003/242] chore: clean --- src/components/selectors/VariableRate.tsx | 55 +++-------------------- 1 file changed, 7 insertions(+), 48 deletions(-) diff --git a/src/components/selectors/VariableRate.tsx b/src/components/selectors/VariableRate.tsx index 51c8d83f3..2fe17c927 100644 --- a/src/components/selectors/VariableRate.tsx +++ b/src/components/selectors/VariableRate.tsx @@ -1,16 +1,8 @@ -import { useContext, useEffect, useState } from 'react'; +import { useContext } from 'react'; import { Avatar, Box, Text } from 'grommet'; -import { toast } from 'react-toastify'; -import { FiAlertTriangle, FiSlash } from 'react-icons/fi'; - import styled from 'styled-components'; -import { ActionCodes, IStrategy } from '../../types'; import { UserContext } from '../../contexts/UserContext'; -import { formatStrategyName } from '../../utils/appUtils'; -import Skeleton from '../wraps/SkeletonWrap'; import { SettingsContext } from '../../contexts/SettingsContext'; -import { ZERO_BN } from '../../utils/constants'; -import useStrategyReturns, { IReturns } from '../../hooks/useStrategyReturns'; import YieldMark from '../logos/YieldMark'; const StyledBox = styled(Box)` @@ -76,29 +68,15 @@ const ShineyBox = styled(Box)` } `; -const VariableRate = ( - // { - // strategy, - // selected, - // displayName, - // handleClick, - // returns, - // }: { - // strategy: IStrategy; - // selected: boolean; - // displayName: string; - // handleClick: (strategy: IStrategy) => void; - // returns?: IReturns; - // } - props: any -) => { +const VariableRate = () => { const { settingsState: { darkMode }, } = useContext(SettingsContext); - const { userState, userActions } = useContext(UserContext); - - const { selectedVR } = userState; + const { + userState: { selectedVR }, + userActions: { setSelectedVR, setSelectedSeries }, + } = useContext(UserContext); return ( { - userActions.setSelectedSeries(null); - userActions.setSelectedVR(true); - console.log('vr click', selectedVR); - }} + onClick={() => setSelectedVR(true)} className="VR-container" > @@ -128,19 +102,16 @@ const VariableRate = ( - {/* {formatStrategyName(strategy.name!)} */} Variable Rate - {/* Rolling {displayName} */} Indefinite - {/* {strategy.rewardsRate!.gt(ZERO_BN) && ( */} - {/* )} */} - {/* {returns?.blendedAPY && ( */} - {/* */} - {/* {strategy.currentSeries?.allowActions.includes('allow_all') || - strategy.currentSeries?.allowActions.includes(ActionCodes.ADD_LIQUIDITY) ? ( */} {2.7} % {'APR'} - {/* // ) : ( */} - {/* - - */} - {/* )} */} - {/* */} - {/* )} */}
); From c18861fcbc48b6fa40275e9cb9daf8775254c5f1 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Wed, 12 Apr 2023 11:39:15 -0700 Subject: [PATCH 004/242] feat: hook to fetch valid vr bases --- src/hooks/views/useBasesVR.ts | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/hooks/views/useBasesVR.ts diff --git a/src/hooks/views/useBasesVR.ts b/src/hooks/views/useBasesVR.ts new file mode 100644 index 000000000..f46f9c21b --- /dev/null +++ b/src/hooks/views/useBasesVR.ts @@ -0,0 +1,48 @@ +import { ContractNames } from '../../config/contracts'; +import { VRCauldron } from '../../contracts'; +import useContracts from '../useContracts'; +import useFork from '../useFork'; +import useDefaultProvider from '../useDefaultProvider'; +import useSWR from 'swr'; +import { Provider } from '../../types'; +import { useCallback, useMemo } from 'react'; + +const useBasesVR = () => { + const contracts = useContracts(); + const { provider: forkProvider, useForkedEnv } = useFork(); + const provider = useDefaultProvider(); + + const _getBases = useCallback( + async (provider: Provider | undefined): Promise => { + if (!contracts) return []; + + const cauldron = contracts.get(ContractNames.VR_CAULDRON) as VRCauldron | undefined; + if (!cauldron) return []; + + const baseAddedEvents = await cauldron.queryFilter(cauldron.filters.BaseAdded()); + return baseAddedEvents.map(({ args: { baseId } }) => baseId); + }, + [contracts] + ); + + // combines fork and non-fork data + const getBases = useCallback( + async () => + useForkedEnv + ? [...new Set([...(await _getBases(forkProvider)), ...(await _getBases(provider))])] + : await _getBases(provider), + [_getBases, forkProvider, provider, useForkedEnv] + ); + + const key = useMemo(() => ['basesVR', useForkedEnv, forkProvider, provider], [forkProvider, provider, useForkedEnv]); + + const { data, isLoading, error } = useSWR(key, getBases, { + revalidateIfStale: false, + revalidateOnFocus: false, + revalidateOnReconnect: false, + }); + + return { data, isLoading, error }; +}; + +export default useBasesVR; From 61bd696cd33993c92d115af8efe86d37bb41c295 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Wed, 12 Apr 2023 11:39:31 -0700 Subject: [PATCH 005/242] feat: series entity can be null --- src/contexts/types/user.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/contexts/types/user.ts b/src/contexts/types/user.ts index cf5384c5a..fc28a0a9e 100644 --- a/src/contexts/types/user.ts +++ b/src/contexts/types/user.ts @@ -118,7 +118,7 @@ export type SelectedVaultAction = { export type SelectedSeriesAction = { type: UserState.SELECTED_SERIES; - payload: ISeries; + payload: ISeries | null; }; export type SelectedIlkAction = { From 05882cbd5ed4eb56593cbd4ba94bd521fbac8166 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Wed, 12 Apr 2023 11:41:13 -0700 Subject: [PATCH 006/242] feat: provider type --- src/types/index.ts | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/src/types/index.ts b/src/types/index.ts index 5cdcdf9b5..ef9fade93 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,4 +1,4 @@ -import { Block } from '@ethersproject/providers'; +import { AlchemyProvider, Block } from '@ethersproject/providers'; import { ethers, BigNumber, BigNumberish, ContractTransaction, Contract } from 'ethers'; import { ReactNode } from 'react'; import { IChainContextActions } from '../contexts/types/chain'; @@ -6,6 +6,8 @@ import { FYToken, Pool, Strategy } from '../contracts'; export { LadleActions, RoutedActions } from './operations'; +export type Provider = ethers.providers.Web3Provider | ethers.providers.JsonRpcProvider | AlchemyProvider; + export interface IChainContext { chainState: IChainContextState; chainActions: IChainContextActions; @@ -266,26 +268,6 @@ export interface IVault extends IVaultRoot { accruedArt_: string; } -export interface IVaultVR extends IVaultRoot { - owner: string; - - isWitchOwner: boolean; - hasBeenLiquidated: boolean; - - isActive: boolean; - ink: BigNumber; - art: BigNumber; - accruedArt: BigNumber; // TODO how do i get this value? -jacob b - - ink_: string; - art_: string; - - rate: BigNumber; - rate_: string; - - accruedArt_: string; -} - export interface IStrategy extends IStrategyRoot { currentSeries: ISeries | undefined; active: boolean; From 3be5beb70aa8e09b062f8a00ab9080a096cfb015 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Wed, 12 Apr 2023 11:41:27 -0700 Subject: [PATCH 007/242] feat: update selected seris on selected vr --- src/contexts/UserContext.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/contexts/UserContext.tsx b/src/contexts/UserContext.tsx index d1f461f5d..243c929fc 100644 --- a/src/contexts/UserContext.tsx +++ b/src/contexts/UserContext.tsx @@ -921,6 +921,7 @@ const UserProvider = ({ children }: { children: ReactNode }) => { ), setSelectedVR: useCallback((vr: boolean) => { updateState({ type: UserState.SELECTED_VR, payload: vr }); + updateState({ type: UserState.SELECTED_SERIES, payload: null }); console.log('%c setSelectedVR', 'color: #00ff00; font-size: 24px;', vr); }, []), } as IUserContextActions; From 16973e168027eeba6908537059addd7b527b4ccd Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Wed, 12 Apr 2023 11:42:08 -0700 Subject: [PATCH 008/242] chore: remove unused --- src/components/selectors/VariableRate.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/selectors/VariableRate.tsx b/src/components/selectors/VariableRate.tsx index 2fe17c927..389111fc9 100644 --- a/src/components/selectors/VariableRate.tsx +++ b/src/components/selectors/VariableRate.tsx @@ -75,7 +75,7 @@ const VariableRate = () => { const { userState: { selectedVR }, - userActions: { setSelectedVR, setSelectedSeries }, + userActions: { setSelectedVR }, } = useContext(UserContext); return ( From dea1dc511b45fc8885f7d47f5824253919da4982 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Wed, 12 Apr 2023 12:33:47 -0700 Subject: [PATCH 009/242] chore: format --- src/components/selectors/VariableRate.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/selectors/VariableRate.tsx b/src/components/selectors/VariableRate.tsx index 389111fc9..9d8cc3e1d 100644 --- a/src/components/selectors/VariableRate.tsx +++ b/src/components/selectors/VariableRate.tsx @@ -74,10 +74,12 @@ const VariableRate = () => { } = useContext(SettingsContext); const { - userState: { selectedVR }, + userState: { selectedVR, }, userActions: { setSelectedVR }, } = useContext(UserContext); + + return ( Date: Wed, 12 Apr 2023 12:34:19 -0700 Subject: [PATCH 010/242] feat: handle fetching valid vr bases in borrow view --- src/components/views/Borrow.tsx | 12 ++++++---- src/config/contracts.ts | 2 +- src/hooks/views/useBasesVR.ts | 39 +++++++++++++++++---------------- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/components/views/Borrow.tsx b/src/components/views/Borrow.tsx index 6a41982c7..27774f3cf 100644 --- a/src/components/views/Borrow.tsx +++ b/src/components/views/Borrow.tsx @@ -55,6 +55,7 @@ import useAccountPlus from '../../hooks/useAccountPlus'; import VariableRate from '../selectors/VariableRate'; import { useBorrowVariableRate } from '../../hooks/actionHooks/useBorrowVariableRate'; +import useBasesVR from '../../hooks/views/useBasesVR'; const Borrow = () => { const mobile: boolean = useContext(ResponsiveContext) === 'small'; @@ -101,12 +102,13 @@ const Borrow = () => { const borrowVariableRate = useBorrowVariableRate(); const { apr } = useApr(borrowInput, ActionType.BORROW, selectedSeries); - console.log('apr in borrow', apr); const { data: assetPair } = useAssetPair(selectedBase?.id, selectedIlk?.id); const { validIlks } = useAssetPair(selectedBase?.id, undefined, selectedSeries?.id); + const { data: basesVR } = useBasesVR(); + const { collateralizationPercent, undercollateralized, @@ -371,9 +373,11 @@ const Borrow = () => { > - - - + {basesVR?.length && basesVR.includes(selectedBase.id)&& ( + + + + )}
)}
diff --git a/src/config/contracts.ts b/src/config/contracts.ts index 18e2351b0..22d4dd180 100644 --- a/src/config/contracts.ts +++ b/src/config/contracts.ts @@ -19,7 +19,7 @@ interface ContractAddresses { addresses: Map>; } -const contractAddresses: ContractAddresses = { +export const contractAddresses: ContractAddresses = { addresses: new Map([ [ 1, diff --git a/src/hooks/views/useBasesVR.ts b/src/hooks/views/useBasesVR.ts index f46f9c21b..03fcf7c3b 100644 --- a/src/hooks/views/useBasesVR.ts +++ b/src/hooks/views/useBasesVR.ts @@ -1,46 +1,47 @@ -import { ContractNames } from '../../config/contracts'; -import { VRCauldron } from '../../contracts'; -import useContracts from '../useContracts'; +import contractAddresses, { ContractNames } from '../../config/contracts'; +import { VRCauldron, VRCauldron__factory } from '../../contracts'; import useFork from '../useFork'; import useDefaultProvider from '../useDefaultProvider'; import useSWR from 'swr'; import { Provider } from '../../types'; import { useCallback, useMemo } from 'react'; +import useChainId from '../useChainId'; +import contracts from '../../config/contracts'; const useBasesVR = () => { - const contracts = useContracts(); - const { provider: forkProvider, useForkedEnv } = useFork(); + const chainId = useChainId(); + const { provider: forkProvider, useForkedEnv, forkStartBlock } = useFork(); const provider = useDefaultProvider(); + const cauldronAddr = contractAddresses.addresses.get(chainId)?.get(ContractNames.VR_CAULDRON); + const _getBases = useCallback( - async (provider: Provider | undefined): Promise => { - if (!contracts) return []; + async (provider: Provider | undefined, fromBlock?: string | number): Promise => { + if (!provider || !cauldronAddr) return []; - const cauldron = contracts.get(ContractNames.VR_CAULDRON) as VRCauldron | undefined; - if (!cauldron) return []; + const cauldron = VRCauldron__factory.connect(cauldronAddr, provider); - const baseAddedEvents = await cauldron.queryFilter(cauldron.filters.BaseAdded()); + const baseAddedEvents = await cauldron.queryFilter(cauldron.filters.BaseAdded(), fromBlock || 'earliest'); return baseAddedEvents.map(({ args: { baseId } }) => baseId); }, - [contracts] + [cauldronAddr] ); // combines fork and non-fork data const getBases = useCallback( async () => useForkedEnv - ? [...new Set([...(await _getBases(forkProvider)), ...(await _getBases(provider))])] + ? [...new Set([...(await _getBases(forkProvider, forkStartBlock)), ...(await _getBases(provider))])] : await _getBases(provider), - [_getBases, forkProvider, provider, useForkedEnv] + [_getBases, forkProvider, forkStartBlock, provider, useForkedEnv] ); - const key = useMemo(() => ['basesVR', useForkedEnv, forkProvider, provider], [forkProvider, provider, useForkedEnv]); + const key = useMemo( + () => ['basesVR', useForkedEnv, forkProvider, provider, _getBases], + [forkProvider, provider, useForkedEnv, _getBases] + ); - const { data, isLoading, error } = useSWR(key, getBases, { - revalidateIfStale: false, - revalidateOnFocus: false, - revalidateOnReconnect: false, - }); + const { data, isLoading, error } = useSWR(key, getBases, { revalidateOnFocus: false }); return { data, isLoading, error }; }; From 92badc54c6b67ce977b6ba1c2d12c4a37d9d1a9b Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Wed, 12 Apr 2023 12:35:55 -0700 Subject: [PATCH 011/242] fix: revalidation options --- src/hooks/views/useBasesVR.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/hooks/views/useBasesVR.ts b/src/hooks/views/useBasesVR.ts index 03fcf7c3b..7cbb7de93 100644 --- a/src/hooks/views/useBasesVR.ts +++ b/src/hooks/views/useBasesVR.ts @@ -41,7 +41,11 @@ const useBasesVR = () => { [forkProvider, provider, useForkedEnv, _getBases] ); - const { data, isLoading, error } = useSWR(key, getBases, { revalidateOnFocus: false }); + const { data, isLoading, error } = useSWR(key, getBases, { + revalidateOnFocus: false, + revalidateOnReconnect: false, + revalidateOnMount: false, + }); return { data, isLoading, error }; }; From 19d242cbc3e12a1a822bab6d0ba2fb384afbdea8 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Wed, 12 Apr 2023 12:36:45 -0700 Subject: [PATCH 012/242] fix: checking vr bases --- src/components/views/Borrow.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/Borrow.tsx b/src/components/views/Borrow.tsx index 27774f3cf..758485212 100644 --- a/src/components/views/Borrow.tsx +++ b/src/components/views/Borrow.tsx @@ -373,7 +373,7 @@ const Borrow = () => { > - {basesVR?.length && basesVR.includes(selectedBase.id)&& ( + {basesVR?.length && basesVR.includes(selectedBase?.id!) && ( From b774ac296f77805e871f03ac3fa07e8169eb92b0 Mon Sep 17 00:00:00 2001 From: Jacob Bryant Date: Thu, 13 Apr 2023 16:20:43 -0400 Subject: [PATCH 013/242] init VR lending work --- src/components/selectors/VariableRate.tsx | 4 +- src/components/views/Borrow.tsx | 14 +- src/components/views/Lend.tsx | 44 +- src/components/views/VaultPosition.tsx | 26 +- src/config/contracts.ts | 6 +- .../actionHooks/useAddCollateral/index.ts | 16 + .../useAddCollateralFR.ts} | 45 +- .../useAddCollateral/useAddCollateralVR.ts | 156 +++++++ src/hooks/actionHooks/useBorrow/index.ts | 16 + .../useBorrowFR.ts} | 38 +- .../useBorrowVR.ts} | 36 +- .../{useLend.ts => useLend.old.ts} | 0 src/hooks/actionHooks/useLend/index.ts | 15 + src/hooks/actionHooks/useLend/useLendFR.ts | 125 ++++++ src/hooks/actionHooks/useLend/useLendVR.ts | 133 ++++++ .../actionHooks/useRemoveCollateral/index.ts | 9 + .../useRemoveCollateralFR.ts} | 31 +- .../useRemoveCollateralVR.ts | 109 +++++ src/hooks/actionHooks/useRepayDebt/index.ts | 16 + .../useRepayDebtFR.ts} | 69 ++- .../useRepayDebtVR.ts} | 80 +--- .../useBorrowHelpers/index.ts} | 0 .../useBorrowHelpers/useBorrowHelpersFR.ts | 394 ++++++++++++++++++ .../useBorrowHelpers/useBorrowHelpersVR.ts | 1 + .../useCollateralHelpers/index.ts | 17 + .../useCollateralHelpersFR.ts | 249 +++++++++++ .../useCollateralHelpersVR.ts | 282 +++++++++++++ .../viewHelperHooks/usePoolHelpers/index.ts | 0 .../usePoolHelpers/usePoolHelpersFR.ts | 0 .../usePoolHelpers/usePoolHelpersVR.ts | 0 src/types/operations.ts | 4 + 31 files changed, 1720 insertions(+), 215 deletions(-) create mode 100644 src/hooks/actionHooks/useAddCollateral/index.ts rename src/hooks/actionHooks/{useAddCollateral.ts => useAddCollateral/useAddCollateralFR.ts} (80%) create mode 100644 src/hooks/actionHooks/useAddCollateral/useAddCollateralVR.ts create mode 100644 src/hooks/actionHooks/useBorrow/index.ts rename src/hooks/actionHooks/{useBorrow.ts => useBorrow/useBorrowFR.ts} (88%) rename src/hooks/actionHooks/{useBorrowVariableRate.ts => useBorrow/useBorrowVR.ts} (90%) rename src/hooks/actionHooks/{useLend.ts => useLend.old.ts} (100%) create mode 100644 src/hooks/actionHooks/useLend/index.ts create mode 100644 src/hooks/actionHooks/useLend/useLendFR.ts create mode 100644 src/hooks/actionHooks/useLend/useLendVR.ts create mode 100644 src/hooks/actionHooks/useRemoveCollateral/index.ts rename src/hooks/actionHooks/{useRemoveCollateral.ts => useRemoveCollateral/useRemoveCollateralFR.ts} (83%) create mode 100644 src/hooks/actionHooks/useRemoveCollateral/useRemoveCollateralVR.ts create mode 100644 src/hooks/actionHooks/useRepayDebt/index.ts rename src/hooks/actionHooks/{useRepayDebt.ts => useRepayDebt/useRepayDebtFR.ts} (85%) rename src/hooks/actionHooks/{useRepayDebtVariableRate.ts => useRepayDebt/useRepayDebtVR.ts} (73%) rename src/hooks/{actionHooks/useAddCollateralVariableRate.ts => viewHelperHooks/useBorrowHelpers/index.ts} (100%) create mode 100644 src/hooks/viewHelperHooks/useBorrowHelpers/useBorrowHelpersFR.ts create mode 100644 src/hooks/viewHelperHooks/useBorrowHelpers/useBorrowHelpersVR.ts create mode 100644 src/hooks/viewHelperHooks/useCollateralHelpers/index.ts create mode 100644 src/hooks/viewHelperHooks/useCollateralHelpers/useCollateralHelpersFR.ts create mode 100644 src/hooks/viewHelperHooks/useCollateralHelpers/useCollateralHelpersVR.ts create mode 100644 src/hooks/viewHelperHooks/usePoolHelpers/index.ts create mode 100644 src/hooks/viewHelperHooks/usePoolHelpers/usePoolHelpersFR.ts create mode 100644 src/hooks/viewHelperHooks/usePoolHelpers/usePoolHelpersVR.ts diff --git a/src/components/selectors/VariableRate.tsx b/src/components/selectors/VariableRate.tsx index 9d8cc3e1d..389111fc9 100644 --- a/src/components/selectors/VariableRate.tsx +++ b/src/components/selectors/VariableRate.tsx @@ -74,12 +74,10 @@ const VariableRate = () => { } = useContext(SettingsContext); const { - userState: { selectedVR, }, + userState: { selectedVR }, userActions: { setSelectedVR }, } = useContext(UserContext); - - return ( >>>>>> Stashed changes const Borrow = () => { const mobile: boolean = useContext(ResponsiveContext) === 'small'; @@ -99,8 +102,6 @@ const Borrow = () => { const borrow = useBorrow(); - const borrowVariableRate = useBorrowVariableRate(); - const { apr } = useApr(borrowInput, ActionType.BORROW, selectedSeries); const { data: assetPair } = useAssetPair(selectedBase?.id, selectedIlk?.id); @@ -159,10 +160,6 @@ const Borrow = () => { } as GA_Properties.transaction_initiated); }; - const handleBorrowVariableRate = () => { - borrowVariableRate(undefined, borrowInput, collatInput); - }; - /** Interaction handlers */ const handleNavAction = (_stepPosition: number) => { _stepPosition === 0 && setSelectedIlk(selectedIlk || assetMap?.get('0x303000000000')!); @@ -664,8 +661,7 @@ const Borrow = () => { } ${selectedBase?.displaySymbol || ''}`} } - // onClick={() => handleBorrow()} - onClick={() => handleBorrowVariableRate()} + onClick={() => handleBorrow()} disabled={borrowDisabled || borrowProcess?.processActive || !disclaimerChecked} /> )} diff --git a/src/components/views/Lend.tsx b/src/components/views/Lend.tsx index 4d5ad693e..ce0638ab6 100644 --- a/src/components/views/Lend.tsx +++ b/src/components/views/Lend.tsx @@ -10,6 +10,7 @@ import MainViewWrap from '../wraps/MainViewWrap'; import SeriesSelector from '../selectors/SeriesSelector'; import { cleanValue, nFormatter } from '../../utils/appUtils'; import SectionWrap from '../wraps/SectionWrap'; +import VariableRate from '../selectors/VariableRate'; import { UserContext } from '../../contexts/UserContext'; import { ActionCodes, ActionType, ProcessStage, TxState } from '../../types'; @@ -51,7 +52,7 @@ const Lend = () => { /* STATE FROM CONTEXT */ const { userState } = useContext(UserContext); - const { selectedSeries, selectedBase, seriesMap } = userState; + const { selectedVR, selectedSeries, selectedBase, seriesMap } = userState; const { address: activeAccount } = useAccountPlus(); @@ -111,9 +112,11 @@ const Lend = () => { /* ACTION DISABLING LOGIC - if conditions are met: allow action */ useEffect(() => { - activeAccount && lendInput && selectedSeries && !lendError ? setLendDisabled(false) : setLendDisabled(true); - lendInput && selectedSeries && !lendError ? setStepDisabled(false) : setStepDisabled(true); - }, [lendInput, activeAccount, lendError, selectedSeries]); + activeAccount && lendInput && (selectedSeries || selectedVR) && !lendError + ? setLendDisabled(false) + : setLendDisabled(true); + lendInput && (selectedSeries || selectedVR) && !lendError ? setStepDisabled(false) : setStepDisabled(true); + }, [lendInput, activeAccount, lendError, selectedSeries, selectedVR]); /* Watch process timeouts */ useEffect(() => { @@ -140,7 +143,7 @@ const Lend = () => { Lend popular ERC20 tokens for{' '} - fixed returns + fixed or variable returns @@ -188,17 +191,22 @@ const Lend = () => { setOpen={toggleModal} /> ) : ( - - - + + + + + + + + )} @@ -243,7 +251,9 @@ const Lend = () => { icon={} value={`${cleanValue(lendInput, selectedBase?.digitFormat!)} ${selectedBase?.displaySymbol}`} /> - } value={`${selectedSeries?.displayName}`} /> + {!selectedVR && ( + } value={`${selectedSeries?.displayName}`} /> + )} } diff --git a/src/components/views/VaultPosition.tsx b/src/components/views/VaultPosition.tsx index 8d986c4ea..8abea4814 100644 --- a/src/components/views/VaultPosition.tsx +++ b/src/components/views/VaultPosition.tsx @@ -29,11 +29,10 @@ import ModalWrap from '../wraps/ModalWrap'; import { useCachedState } from '../../hooks/generalHooks'; import { useRepayDebt } from '../../hooks/actionHooks/useRepayDebt'; -import { useRepayDebtVariableRate } from '../../hooks/actionHooks/useRepayDebtVariableRate'; - import { useRollDebt } from '../../hooks/actionHooks/useRollDebt'; -import { useCollateralHelpers } from '../../hooks/higherOrderHooks/useCollateralHelpers'; +import { useCollateralHelpers } from '../../hooks/viewHelperHooks/useCollateralHelpers'; import { useAddCollateral } from '../../hooks/actionHooks/useAddCollateral'; + import { useRemoveCollateral } from '../../hooks/actionHooks/useRemoveCollateral'; import { useBorrowHelpers } from '../../hooks/viewHelperHooks/useBorrowHelpers'; import InputInfoWrap from '../wraps/InputInfoWrap'; @@ -69,7 +68,7 @@ const VaultPosition = () => { const vaultBase = assetMap?.get(_selectedVault?.baseId!); const vaultIlk = assetMap?.get(_selectedVault?.ilkId!); const vaultSeries = seriesMap?.get(_selectedVault?.seriesId!); - const vaultIsVR = !!_selectedVault?.seriesId; + const vaultIsVR = !_selectedVault?.seriesId; const { data: assetPair } = useAssetPair(vaultBase?.id, vaultIlk?.id); const { data: ilkBal } = useBalance({ @@ -132,14 +131,12 @@ const VaultPosition = () => { /* HOOK FNS */ const repay = useRepayDebt(); - const repayVariableRate = useRepayDebtVariableRate(); - const rollDebt = useRollDebt(); const { logAnalyticsEvent } = useAnalytics(); const { addCollateral } = useAddCollateral(); - const { removeCollateral } = useRemoveCollateral(); + const { removeCollateral } = useRemoveCollateral(vaultIsVR); const { maxCollateral, @@ -223,11 +220,9 @@ const VaultPosition = () => { ); const handleRepay = () => { - console.log('%c handleRepay', 'color: #00ff00; font-size: 16px;', repayDisabled); if (repayDisabled) return; setRepayDisabled(true); - // repay(_selectedVault!, repayInput?.toString(), reclaimCollateral); - repayVariableRate(_selectedVault!, repayInput?.toString(), reclaimCollateral); + repay(_selectedVault!, repayInput?.toString(), reclaimCollateral); logAnalyticsEvent(GA_Event.transaction_initiated, { view: GA_View.BORROW, @@ -249,6 +244,7 @@ const VaultPosition = () => { }; const handleCollateral = (action: 'ADD' | 'REMOVE') => { + console.log('handleCollateral', action, removeCollateralDisabled); if (action === 'REMOVE') { if (removeCollateralDisabled) return; setRemoveCollateralDisabled(true); @@ -262,6 +258,16 @@ const VaultPosition = () => { } else { if (addCollateralDisabled) return; setAddCollateralDisabled(true); + + console.log( + '%c handleCollateral in VaultPosition', + 'color: #00ff00; font-size: 16px;', + action, + addCollateralDisabled, + removeCollateralDisabled + ); + + // addCollateral(_selectedVault, addCollatInput); addCollateral(_selectedVault, addCollatInput); logAnalyticsEvent(GA_Event.transaction_initiated, { diff --git a/src/config/contracts.ts b/src/config/contracts.ts index 22d4dd180..f74fa90f1 100644 --- a/src/config/contracts.ts +++ b/src/config/contracts.ts @@ -25,10 +25,10 @@ export const contractAddresses: ContractAddresses = { 1, new Map([ [ContractNames.CAULDRON, '0xc88191F8cb8e6D4a668B047c1C8503432c3Ca867'], - [ContractNames.VR_CAULDRON, '0x8fd04c6153a0e33afc669689c9bc36ae2e1e6501'], + [ContractNames.VR_CAULDRON, '0xe9b81548704a0bf1ebe85ed504bc3e248ce15733'], [ContractNames.LADLE, '0x6cB18fF2A33e981D1e38A663Ca056c0a5265066A'], - [ContractNames.VR_LADLE, '0x35d8f478ce6597548256d02b374972a775df927d'], - [ContractNames.VR_WITCH, '0x1b831a29427c50ca412ef5c19eb2cf2a300a48a6'], + [ContractNames.VR_LADLE, '0x3fa3116da426af606826eaf2e58344fbd56b6489'], + [ContractNames.VR_WITCH, '0xe7901efbfb59ef0c4831d06f77edc740ed98adc8'], [ContractNames.WITCH, '0x53C3760670f6091E1eC76B4dd27f73ba4CAd5061'], [ContractNames.WITCHV2, '0x08d2f5c96bb1f6be04b49bcd869d5af01db4c400'], [ContractNames.TRANSFER_1155_MODULE, '0x97f1d43A217aDD678bB6Dcd3C5D51F40b6729d06'], diff --git a/src/hooks/actionHooks/useAddCollateral/index.ts b/src/hooks/actionHooks/useAddCollateral/index.ts new file mode 100644 index 000000000..fc9ae8042 --- /dev/null +++ b/src/hooks/actionHooks/useAddCollateral/index.ts @@ -0,0 +1,16 @@ +// Hooks +import { useAddCollateralVR } from './useAddCollateralVR'; +import { useAddCollateralFR } from './useAddCollateralFR'; + +// Contexts +import { useContext } from 'react'; +import { UserContext } from '../../../contexts/UserContext'; + +export const useAddCollateral = () => { + const { userState } = useContext(UserContext); + const { selectedSeries } = userState; + + const baseHook = selectedSeries ? useAddCollateralFR : useAddCollateralVR; + + return baseHook(); +}; diff --git a/src/hooks/actionHooks/useAddCollateral.ts b/src/hooks/actionHooks/useAddCollateral/useAddCollateralFR.ts similarity index 80% rename from src/hooks/actionHooks/useAddCollateral.ts rename to src/hooks/actionHooks/useAddCollateral/useAddCollateralFR.ts index 3423ab4d7..5e0092eac 100644 --- a/src/hooks/actionHooks/useAddCollateral.ts +++ b/src/hooks/actionHooks/useAddCollateral/useAddCollateralFR.ts @@ -1,25 +1,25 @@ import { ethers } from 'ethers'; import { useContext } from 'react'; -import { UserContext } from '../../contexts/UserContext'; - -import { ICallData, IVault, ActionCodes, LadleActions, IAsset, IHistoryContext } from '../../types'; - -import { cleanValue, getTxCode } from '../../utils/appUtils'; -import { BLANK_VAULT, ZERO_BN } from '../../utils/constants'; -import { CONVEX_BASED_ASSETS, ETH_BASED_ASSETS } from '../../config/assets'; -import { useChain } from '../useChain'; -import { useWrapUnwrapAsset } from './useWrapUnwrapAsset'; -import { useAddRemoveEth } from './useAddRemoveEth'; -import { ConvexLadleModule } from '../../contracts'; -import { ModuleActions } from '../../types/operations'; -import { HistoryContext } from '../../contexts/HistoryContext'; +import { UserContext } from '../../../contexts/UserContext'; + +import { ICallData, IVault, ActionCodes, LadleActions, IAsset, IHistoryContext } from '../../../types'; + +import { cleanValue, getTxCode } from '../../../utils/appUtils'; +import { BLANK_VAULT, ZERO_BN } from '../../../utils/constants'; +import { CONVEX_BASED_ASSETS, ETH_BASED_ASSETS } from '../../../config/assets'; +import { useChain } from '../../useChain'; +import { useWrapUnwrapAsset } from '../useWrapUnwrapAsset'; +import { useAddRemoveEth } from '../useAddRemoveEth'; +import { ConvexLadleModule } from '../../../contracts'; +import { ModuleActions } from '../../../types/operations'; +import { HistoryContext } from '../../../contexts/HistoryContext'; import { Address, useBalance } from 'wagmi'; -import useContracts from '../useContracts'; -import useAccountPlus from '../useAccountPlus'; -import { ContractNames } from '../../config/contracts'; -import useAllowAction from '../useAllowAction'; +import useContracts from '../../useContracts'; +import useAccountPlus from '../../useAccountPlus'; +import { ContractNames } from '../../../config/contracts'; +import useAllowAction from '../../useAllowAction'; -export const useAddCollateral = () => { +export const useAddCollateralFR = () => { const { userState, userActions } = useContext(UserContext); const { selectedBase, selectedIlk, selectedSeries, assetMap } = userState; const { updateAssets, updateVaults } = userActions; @@ -34,7 +34,7 @@ export const useAddCollateral = () => { const { wrapAsset } = useWrapUnwrapAsset(); const { addEth } = useAddRemoveEth(); - const {isActionAllowed} = useAllowAction(); + const { isActionAllowed } = useAllowAction(); const { refetch: refetchBaseBal } = useBalance({ address: account, @@ -109,13 +109,6 @@ export const useAddCollateral = () => { * BUILD CALL DATA ARRAY * */ const calls: ICallData[] = [ - /* If vault is null, build a new vault, else ignore */ - { - operation: LadleActions.Fn.BUILD, - args: [selectedSeries?.id, selectedIlk?.proxyId, '0'] as LadleActions.Args.BUILD, - ignoreIf: !!vault, // ignore if vault exists - }, - /* If convex-type collateral, add vault using convex ladle module */ { operation: LadleActions.Fn.MODULE, diff --git a/src/hooks/actionHooks/useAddCollateral/useAddCollateralVR.ts b/src/hooks/actionHooks/useAddCollateral/useAddCollateralVR.ts new file mode 100644 index 000000000..b6276946b --- /dev/null +++ b/src/hooks/actionHooks/useAddCollateral/useAddCollateralVR.ts @@ -0,0 +1,156 @@ +import { ethers } from 'ethers'; +import { useContext } from 'react'; +import { UserContext } from '../../../contexts/UserContext'; + +import { ICallData, IVault, ActionCodes, LadleActions, IAsset, IHistoryContext } from '../../../types'; + +import { cleanValue, getTxCode } from '../../../utils/appUtils'; +import { BLANK_VAULT, ZERO_BN } from '../../../utils/constants'; +import { CONVEX_BASED_ASSETS, ETH_BASED_ASSETS } from '../../../config/assets'; +import { useChain } from '../../useChain'; +import { useWrapUnwrapAsset } from '../useWrapUnwrapAsset'; +import { useAddRemoveEth } from '../useAddRemoveEth'; +import { ConvexLadleModule } from '../../../contracts'; +import { ModuleActions } from '../../../types/operations'; +import { HistoryContext } from '../../../contexts/HistoryContext'; +import { Address, useBalance } from 'wagmi'; +import useContracts from '../../useContracts'; +import useAccountPlus from '../../useAccountPlus'; +import { ContractNames } from '../../../config/contracts'; +import useAllowAction from '../../useAllowAction'; + +export const useAddCollateralVR = () => { + const { userState, userActions } = useContext(UserContext); + const { selectedBase, selectedIlk, selectedSeries, assetMap } = userState; + const { updateAssets, updateVaults } = userActions; + const { address: account } = useAccountPlus(); + const contracts = useContracts(); + + const { + historyActions: { updateVaultHistory }, + } = useContext(HistoryContext) as IHistoryContext; + + const { sign, transact } = useChain(); + const { wrapAsset } = useWrapUnwrapAsset(); + const { addEth } = useAddRemoveEth(); + + const { isActionAllowed } = useAllowAction(); + + const { refetch: refetchBaseBal } = useBalance({ + address: account, + token: selectedBase?.address as Address, + }); + const { refetch: refetchIlkBal } = useBalance({ + address: account, + token: selectedIlk?.address as Address, + }); + + const addCollateral = async (vault: IVault | undefined, input: string) => { + if (!contracts) return; + + if (!isActionAllowed(ActionCodes.ADD_COLLATERAL) && selectedSeries) return; // return if action is not allowed + + /* use the vault id provided OR 0 if new/ not provided */ + const vaultId = vault?.id || BLANK_VAULT; + + /* set the ilk based on if a vault has been selected or it's a new vault */ + const ilk: IAsset | null | undefined = vault ? assetMap?.get(vault.ilkId) : selectedIlk; + const base: IAsset | null | undefined = vault ? assetMap?.get(vault.baseId) : selectedBase; + + const ladleAddress = contracts.get(ContractNames.VR_LADLE)?.address; + + /* generate the reproducible txCode for tx tracking and tracing */ + const txCode = getTxCode(ActionCodes.ADD_COLLATERAL, vaultId); + + /* parse inputs to BigNumber in Wei */ + const cleanedInput = cleanValue(input, ilk?.decimals); + const _input = ethers.utils.parseUnits(cleanedInput, ilk?.decimals); + + /* check if the ilk/asset is an eth asset variety, if so pour to Ladle */ + const isEthCollateral = ETH_BASED_ASSETS.includes(ilk?.proxyId!); + + /* is convex-type collateral */ + const isConvexCollateral = CONVEX_BASED_ASSETS.includes(selectedIlk?.proxyId!); + const ConvexLadleModuleContract = contracts.get(ContractNames.CONVEX_LADLE_MODULE) as ConvexLadleModule; + + /* if approveMAx, check if signature is required : note: getAllowance may return FALSE if ERC1155 */ + const _allowance = await ilk?.getAllowance(account!, ilk.joinAddress); + const alreadyApproved = ethers.BigNumber.isBigNumber(_allowance) ? _allowance.gte(_input) : _allowance; + + /* Handle wrapping of tokens: */ + const wrapAssetCallData: ICallData[] = await wrapAsset(_input, ilk!, txCode); + + /* conditionally set build args for ladle for fixed rate or variable rate ladle */ + const buildArgs = selectedSeries + ? [selectedSeries?.id, selectedIlk?.proxyId, '0'] + : [base?.id, selectedIlk?.proxyId, '0']; + + /* Gather all the required signatures - sign() processes them and returns them as ICallData types */ + const permitCallData: ICallData[] = await sign( + [ + { + target: ilk!, + spender: ilk?.joinAddress!, + amount: _input, + /* ignore if: 1) collateral is ETH 2) approved already 3) wrapAssets call is > 0 (because the permit is handled with wrapping) */ + ignoreIf: isEthCollateral || alreadyApproved === true || wrapAssetCallData.length > 0, + }, + ], + txCode + ); + + /* Handle adding eth if required (ie. if the ilk is ETH_BASED). If not, else simply sent ZERO to the addEth fn */ + const addEthCallData: ICallData[] = addEth( + ETH_BASED_ASSETS.includes(selectedIlk?.proxyId!) ? _input : ZERO_BN, + undefined, + selectedIlk?.proxyId + ); + + /* pour destination based on ilk/asset is an eth asset variety */ + const pourToAddress = () => { + if (isEthCollateral) return ladleAddress; + return account; + }; + + /** + * BUILD CALL DATA ARRAY + * */ + const calls: ICallData[] = [ + /* If convex-type collateral, add vault using convex ladle module */ + { + operation: LadleActions.Fn.MODULE, + fnName: ModuleActions.Fn.ADD_VAULT, + args: [selectedIlk?.joinAddress, vaultId] as ModuleActions.Args.ADD_VAULT, + targetContract: ConvexLadleModuleContract, + ignoreIf: !!vault || !isConvexCollateral, + }, + + /* handle wrapped token deposit, if required */ + ...wrapAssetCallData, + + /* add in add ETH calls */ + ...addEthCallData, + + /* handle permits if required */ + ...permitCallData, + + { + operation: LadleActions.Fn.POUR, + args: [vaultId, pourToAddress(), _input, ethers.constants.Zero] as LadleActions.Args.POUR, + ignoreIf: false, // never ignore + }, + ]; + + /* TRANSACT */ + await transact(calls, txCode); + + /* then update UI */ + refetchBaseBal(); + refetchIlkBal(); + updateVaults([vault!]); + updateAssets([base!, ilk!]); + updateVaultHistory([vault!]); + }; + + return { addCollateral }; +}; diff --git a/src/hooks/actionHooks/useBorrow/index.ts b/src/hooks/actionHooks/useBorrow/index.ts new file mode 100644 index 000000000..6cee5f2a0 --- /dev/null +++ b/src/hooks/actionHooks/useBorrow/index.ts @@ -0,0 +1,16 @@ +// HOOKS +import { useBorrowFR } from './useBorrowFR'; +import { useBorrowVR } from './useBorrowVR'; + +// CONTEXTS +import { useContext } from 'react'; +import { UserContext } from '../../../contexts/UserContext'; + +export const useBorrow = () => { + const { userState } = useContext(UserContext); + const { selectedVR } = userState; + + const baseHook = selectedVR ? useBorrowVR : useBorrowFR; + + return baseHook(); +}; diff --git a/src/hooks/actionHooks/useBorrow.ts b/src/hooks/actionHooks/useBorrow/useBorrowFR.ts similarity index 88% rename from src/hooks/actionHooks/useBorrow.ts rename to src/hooks/actionHooks/useBorrow/useBorrowFR.ts index 4f6995088..175cad5f8 100644 --- a/src/hooks/actionHooks/useBorrow.ts +++ b/src/hooks/actionHooks/useBorrow/useBorrowFR.ts @@ -2,27 +2,27 @@ import { ethers } from 'ethers'; import { useContext } from 'react'; import { buyBase, calculateSlippage } from '@yield-protocol/ui-math'; -import { SettingsContext } from '../../contexts/SettingsContext'; -import { UserContext } from '../../contexts/UserContext'; -import { ICallData, IVault, ActionCodes, LadleActions, ISeries, IAsset } from '../../types'; -import { cleanValue, getTxCode } from '../../utils/appUtils'; -import { BLANK_VAULT, ONE_BN, ZERO_BN } from '../../utils/constants'; - -import { CONVEX_BASED_ASSETS, ETH_BASED_ASSETS, WETH } from '../../config/assets'; - -import { useChain } from '../useChain'; -import { useWrapUnwrapAsset } from './useWrapUnwrapAsset'; -import { useAddRemoveEth } from './useAddRemoveEth'; -import { ModuleActions } from '../../types/operations'; -import { ConvexLadleModule } from '../../contracts'; -import useTimeTillMaturity from '../useTimeTillMaturity'; +import { SettingsContext } from '../../../contexts/SettingsContext'; +import { UserContext } from '../../../contexts/UserContext'; +import { ICallData, IVault, ActionCodes, LadleActions, ISeries, IAsset } from '../../../types'; +import { cleanValue, getTxCode } from '../../../utils/appUtils'; +import { BLANK_VAULT, ONE_BN, ZERO_BN } from '../../../utils/constants'; + +import { CONVEX_BASED_ASSETS, ETH_BASED_ASSETS, WETH } from '../../../config/assets'; + +import { useChain } from '../../useChain'; +import { useWrapUnwrapAsset } from '../useWrapUnwrapAsset'; +import { useAddRemoveEth } from '../useAddRemoveEth'; +import { ModuleActions } from '../../../types/operations'; +import { ConvexLadleModule } from '../../../contracts'; +import useTimeTillMaturity from '../../useTimeTillMaturity'; import { Address, useBalance } from 'wagmi'; -import useContracts from '../useContracts'; -import useAccountPlus from '../useAccountPlus'; -import { ContractNames } from '../../config/contracts'; -import useAllowAction from '../useAllowAction'; +import useContracts from '../../useContracts'; +import useAccountPlus from '../../useAccountPlus'; +import { ContractNames } from '../../../config/contracts'; +import useAllowAction from '../../useAllowAction'; -export const useBorrow = () => { +export const useBorrowFR = () => { const { settingsState: { slippageTolerance }, } = useContext(SettingsContext); diff --git a/src/hooks/actionHooks/useBorrowVariableRate.ts b/src/hooks/actionHooks/useBorrow/useBorrowVR.ts similarity index 90% rename from src/hooks/actionHooks/useBorrowVariableRate.ts rename to src/hooks/actionHooks/useBorrow/useBorrowVR.ts index 34ae1c767..3dadb2e4d 100644 --- a/src/hooks/actionHooks/useBorrowVariableRate.ts +++ b/src/hooks/actionHooks/useBorrow/useBorrowVR.ts @@ -1,26 +1,26 @@ import { ethers } from 'ethers'; import { useContext } from 'react'; -import { SettingsContext } from '../../contexts/SettingsContext'; -import { UserContext } from '../../contexts/UserContext'; -import { ICallData, IVault, ActionCodes, LadleActions, ISeries, IAsset } from '../../types'; -import { cleanValue, getTxCode } from '../../utils/appUtils'; -import { BLANK_VAULT, ONE_BN, ZERO_BN } from '../../utils/constants'; - -import { CONVEX_BASED_ASSETS, ETH_BASED_ASSETS, WETH } from '../../config/assets'; - -import { useChain } from '../useChain'; -import { useWrapUnwrapAsset } from './useWrapUnwrapAsset'; -import { useAddRemoveEth } from './useAddRemoveEth'; -import { ModuleActions } from '../../types/operations'; -import { ConvexLadleModule } from '../../contracts'; +import { SettingsContext } from '../../../contexts/SettingsContext'; +import { UserContext } from '../../../contexts/UserContext'; +import { ICallData, IVault, ActionCodes, LadleActions, ISeries, IAsset } from '../../../types'; +import { cleanValue, getTxCode } from '../../../utils/appUtils'; +import { BLANK_VAULT, ONE_BN, ZERO_BN } from '../../../utils/constants'; + +import { CONVEX_BASED_ASSETS, ETH_BASED_ASSETS, WETH } from '../../../config/assets'; + +import { useChain } from '../../useChain'; +import { useWrapUnwrapAsset } from '../useWrapUnwrapAsset'; +import { useAddRemoveEth } from '../useAddRemoveEth'; +import { ModuleActions } from '../../../types/operations'; +import { ConvexLadleModule } from '../../../contracts'; import { Address, useBalance } from 'wagmi'; -import useContracts from '../useContracts'; -import useAccountPlus from '../useAccountPlus'; -import { ContractNames } from '../../config/contracts'; -import useAllowAction from '../useAllowAction'; +import useContracts from '../../useContracts'; +import useAccountPlus from '../../useAccountPlus'; +import { ContractNames } from '../../../config/contracts'; +import useAllowAction from '../../useAllowAction'; -export const useBorrowVariableRate = () => { +export const useBorrowVR = () => { const { settingsState: { slippageTolerance }, } = useContext(SettingsContext); diff --git a/src/hooks/actionHooks/useLend.ts b/src/hooks/actionHooks/useLend.old.ts similarity index 100% rename from src/hooks/actionHooks/useLend.ts rename to src/hooks/actionHooks/useLend.old.ts diff --git a/src/hooks/actionHooks/useLend/index.ts b/src/hooks/actionHooks/useLend/index.ts new file mode 100644 index 000000000..19cad9370 --- /dev/null +++ b/src/hooks/actionHooks/useLend/index.ts @@ -0,0 +1,15 @@ +// HOOKS +import { useLendFR } from './useLendFR'; +import { useLendVR } from './useLendVR'; + +// CONTEXTS +import { useContext } from 'react'; +import { UserContext } from '../../../contexts/UserContext'; + +export const useLend = () => { + console.log('useLend firing index.ts'); + const { userState } = useContext(UserContext); + const { selectedVR } = userState; + + return selectedVR ? useLendVR() : useLendFR(); +}; diff --git a/src/hooks/actionHooks/useLend/useLendFR.ts b/src/hooks/actionHooks/useLend/useLendFR.ts new file mode 100644 index 000000000..5b62f0a07 --- /dev/null +++ b/src/hooks/actionHooks/useLend/useLendFR.ts @@ -0,0 +1,125 @@ +import { ethers } from 'ethers'; +import { useContext } from 'react'; +import { calculateSlippage, MAX_256, sellBase } from '@yield-protocol/ui-math'; + +import { ETH_BASED_ASSETS, USDT } from '../../../config/assets'; +import { HistoryContext } from '../../../contexts/HistoryContext'; +import { SettingsContext } from '../../../contexts/SettingsContext'; +import { UserContext } from '../../../contexts/UserContext'; +import { ICallData, ISeries, ActionCodes, LadleActions, RoutedActions } from '../../../types'; +import { cleanValue, getTxCode } from '../../../utils/appUtils'; +import { useChain } from '../../useChain'; +import { useAddRemoveEth } from '../useAddRemoveEth'; +import useTimeTillMaturity from '../../useTimeTillMaturity'; +import { Address, useBalance } from 'wagmi'; +import useContracts from '../../useContracts'; +import useChainId from '../../useChainId'; +import useAccountPlus from '../../useAccountPlus'; +import { ContractNames } from '../../../config/contracts'; +import useAllowAction from '../../useAllowAction'; + +/* Lend Actions Hook */ +export const useLendFR = () => { + const { + settingsState: { slippageTolerance }, + } = useContext(SettingsContext); + + const { userState, userActions } = useContext(UserContext); + const { assetMap, selectedSeries, selectedBase } = userState; + const { updateSeries, updateAssets } = userActions; + const { address: account } = useAccountPlus(); + const chainId = useChainId(); + const { isActionAllowed } = useAllowAction(); + + const { refetch: refetchFyTokenBal } = useBalance({ address: account, token: selectedSeries?.address as Address }); + const { refetch: refetchBaseBal } = useBalance({ + address: account, + token: selectedBase?.address as Address, + }); + + const { + historyActions: { updateTradeHistory }, + } = useContext(HistoryContext); + + const { sign, transact } = useChain(); + const { addEth } = useAddRemoveEth(); + const { getTimeTillMaturity } = useTimeTillMaturity(); + const contracts = useContracts(); + + const lend = async (input: string | undefined, series: ISeries) => { + if (!contracts) return; + if (!isActionAllowed(ActionCodes.LEND)) return; // return if action is not allowed + + /* generate the reproducible txCode for tx tracking and tracing */ + const txCode = getTxCode(ActionCodes.LEND, series.id); + + const base = assetMap?.get(series.baseId)!; + const cleanedInput = cleanValue(input, base?.decimals); + const _input = input ? ethers.utils.parseUnits(cleanedInput, base?.decimals) : ethers.constants.Zero; + + const ladleAddress = contracts.get(ContractNames.LADLE)?.address; + + const _inputAsFyToken = sellBase( + series.sharesReserves, + series.fyTokenReserves, + series.getShares(_input), // convert base input to shares + getTimeTillMaturity(series.maturity), + series.ts, + series.g1, + series.decimals, + series.c, + series.mu + ); + + const _inputAsFyTokenWithSlippage = calculateSlippage(_inputAsFyToken, slippageTolerance.toString(), true); + + /* if approveMAx, check if signature is required */ + const alreadyApproved = (await base.getAllowance(account!, ladleAddress!)).gte(_input); + + /* ETH is used as a base */ + const isEthBase = ETH_BASED_ASSETS.includes(series.baseId); + + const permitCallData: ICallData[] = await sign( + [ + { + target: base, + spender: 'LADLE', + amount: base.id === USDT && chainId !== 42161 ? MAX_256 : _input, // USDT allowance when non-zero needs to be set to 0 explicitly before settting to a non-zero amount; instead of having multiple approvals, we approve max from the outset on mainnet + ignoreIf: alreadyApproved === true, + }, + ], + txCode + ); + + const addEthCallData = () => { + if (isEthBase) return addEth(_input, series.poolAddress); + return []; + }; + + const calls: ICallData[] = [ + ...permitCallData, + ...addEthCallData(), + { + operation: LadleActions.Fn.TRANSFER, + args: [base.address, series.poolAddress, _input] as LadleActions.Args.TRANSFER, + ignoreIf: isEthBase, + }, + { + operation: LadleActions.Fn.ROUTE, + args: [account, _inputAsFyTokenWithSlippage] as RoutedActions.Args.SELL_BASE, + fnName: RoutedActions.Fn.SELL_BASE, + targetContract: series.poolContract, + ignoreIf: false, + }, + ]; + + await transact(calls, txCode); + refetchBaseBal(); + refetchFyTokenBal(); + updateSeries([series]); + updateAssets([base]); + updateTradeHistory([series]); + }; + + return lend; +}; diff --git a/src/hooks/actionHooks/useLend/useLendVR.ts b/src/hooks/actionHooks/useLend/useLendVR.ts new file mode 100644 index 000000000..0a8aa9a50 --- /dev/null +++ b/src/hooks/actionHooks/useLend/useLendVR.ts @@ -0,0 +1,133 @@ +import { ethers } from 'ethers'; +import { useContext } from 'react'; +import { calculateSlippage, MAX_256, sellBase } from '@yield-protocol/ui-math'; + +import { ETH_BASED_ASSETS, USDT } from '../../../config/assets'; +import { HistoryContext } from '../../../contexts/HistoryContext'; +import { SettingsContext } from '../../../contexts/SettingsContext'; +import { UserContext } from '../../../contexts/UserContext'; +import { ICallData, ISeries, ActionCodes, LadleActions, RoutedActions } from '../../../types'; +import { cleanValue, getTxCode } from '../../../utils/appUtils'; +import { useChain } from '../../useChain'; +import { useAddRemoveEth } from '../useAddRemoveEth'; +import useTimeTillMaturity from '../../useTimeTillMaturity'; +import { Address, useBalance, useProvider } from 'wagmi'; +import useContracts from '../../useContracts'; +import useChainId from '../../useChainId'; +import useAccountPlus from '../../useAccountPlus'; +import { ContractNames } from '../../../config/contracts'; +import useAllowAction from '../../useAllowAction'; +import { VRLadle__factory } from '../../../contracts'; + +/* Lend Actions Hook */ +export const useLendVR = () => { + const { + settingsState: { slippageTolerance }, + } = useContext(SettingsContext); + + const { userState, userActions } = useContext(UserContext); + const { assetMap, selectedSeries, selectedBase } = userState; + const { updateSeries, updateAssets } = userActions; + const { address: account } = useAccountPlus(); + const chainId = useChainId(); + const { isActionAllowed } = useAllowAction(); + + // const { refetch: refetchFyTokenBal } = useBalance({ address: account, token: selectedSeries?.address as Address }); + const { refetch: refetchBaseBal } = useBalance({ + address: account, + token: selectedBase?.address as Address, + }); + + const { + historyActions: { updateTradeHistory }, + } = useContext(HistoryContext); + + const { sign, transact } = useChain(); + const { addEth } = useAddRemoveEth(); + // const { getTimeTillMaturity } = useTimeTillMaturity(); + const contracts = useContracts(); + + const lend = async (input: string | undefined, series: ISeries) => { + if (!contracts) return; + // if (!isActionAllowed(ActionCodes.LEND)) return; // return if action is not allowed -- TODO implement for VR - jacob b + + /* generate the reproducible txCode for tx tracking and tracing */ + const txCode = getTxCode(ActionCodes.LEND, series.id); + + const base = selectedBase!; + const cleanedInput = cleanValue(input, base?.decimals); + const _input = input ? ethers.utils.parseUnits(cleanedInput, base?.decimals) : ethers.constants.Zero; + + // const provider = useProvider(); + const ladleAddress = contracts.get(ContractNames.VR_LADLE)?.address; + // const ladle = VRLadle__factory.connect(ladleAddress!, provider); + // const joinAddress = await ladle.joins(base.id); + + console.log('fetch joinAddresses'); + return; + + // const _inputAsFyToken = sellBase( + // series.sharesReserves, + // series.fyTokenReserves, + // series.getShares(_input), // convert base input to shares + // getTimeTillMaturity(series.maturity), + // series.ts, + // series.g1, + // series.decimals, + // series.c, + // series.mu + // ); + + // how do we get our slippage tolerance? - jacob b + // const _inputAsFyTokenWithSlippage = calculateSlippage(_inputAsFyToken, slippageTolerance.toString(), true); + + /* if approveMAx, check if signature is required */ + const alreadyApproved = (await base.getAllowance(account!, ladleAddress!)).gte(_input); + + /* ETH is used as a base */ + const isEthBase = ETH_BASED_ASSETS.includes(series.baseId); + + const permitCallData: ICallData[] = await sign( + [ + { + target: base, + spender: 'LADLE', + amount: base.id === USDT && chainId !== 42161 ? MAX_256 : _input, // USDT allowance when non-zero needs to be set to 0 explicitly before settting to a non-zero amount; instead of having multiple approvals, we approve max from the outset on mainnet + ignoreIf: alreadyApproved === true, + }, + ], + txCode + ); + + const addEthCallData = () => { + if (isEthBase) return addEth(_input, series.poolAddress); + return []; + }; + + const calls: ICallData[] = [ + // ...permitCallData, - dont think we need this for VR - check recipe book - jacob b + ...addEthCallData(), + { + operation: LadleActions.Fn.TRANSFER, + args: [base.address, joinAddress, _input] as LadleActions.Args.TRANSFER, + ignoreIf: isEthBase, + }, + { + operation: LadleActions.Fn.ROUTE, + args: [account, _input] as RoutedActions.Args.SELL_BASE, + fnName: RoutedActions.Fn.SELL_BASE, + targetContract: series.poolContract, + ignoreIf: false, + }, + ]; + + await transact(calls, txCode); + refetchBaseBal(); + // refetchFyTokenBal(); + // updateSeries([series]); + updateAssets([base]); + // updateTradeHistory([series]); -- TODO - need to update this for VR - jacob b + }; + + return lend; +}; diff --git a/src/hooks/actionHooks/useRemoveCollateral/index.ts b/src/hooks/actionHooks/useRemoveCollateral/index.ts new file mode 100644 index 000000000..41f3a0eb3 --- /dev/null +++ b/src/hooks/actionHooks/useRemoveCollateral/index.ts @@ -0,0 +1,9 @@ +// HOOKS +import { useRemoveCollateralVR } from './useRemoveCollateralVR'; +import { useRemoveCollateralFR } from './useRemoveCollateralFR'; + +export const useRemoveCollateral = (isVRVault: boolean) => { + const baseHook = isVRVault ? useRemoveCollateralVR : useRemoveCollateralFR; + + return baseHook(); +}; diff --git a/src/hooks/actionHooks/useRemoveCollateral.ts b/src/hooks/actionHooks/useRemoveCollateral/useRemoveCollateralFR.ts similarity index 83% rename from src/hooks/actionHooks/useRemoveCollateral.ts rename to src/hooks/actionHooks/useRemoveCollateral/useRemoveCollateralFR.ts index 5b61bebab..02b41c439 100644 --- a/src/hooks/actionHooks/useRemoveCollateral.ts +++ b/src/hooks/actionHooks/useRemoveCollateral/useRemoveCollateralFR.ts @@ -1,22 +1,22 @@ import { ethers } from 'ethers'; import { useContext } from 'react'; -import { UserContext } from '../../contexts/UserContext'; -import { ICallData, IVault, ActionCodes, LadleActions, RoutedActions, IHistoryContext } from '../../types'; -import { cleanValue, getTxCode } from '../../utils/appUtils'; -import { CONVEX_BASED_ASSETS, ETH_BASED_ASSETS, WETH } from '../../config/assets'; -import { useChain } from '../useChain'; -import { useWrapUnwrapAsset } from './useWrapUnwrapAsset'; -import { useAddRemoveEth } from './useAddRemoveEth'; -import { ONE_BN, ZERO_BN } from '../../utils/constants'; -import { ConvexJoin__factory } from '../../contracts'; -import { HistoryContext } from '../../contexts/HistoryContext'; +import { UserContext } from '../../../contexts/UserContext'; +import { ICallData, IVault, ActionCodes, LadleActions, RoutedActions, IHistoryContext } from '../../../types'; +import { cleanValue, getTxCode } from '../../../utils/appUtils'; +import { CONVEX_BASED_ASSETS, ETH_BASED_ASSETS, WETH } from '../../../config/assets'; +import { useChain } from '../../useChain'; +import { useWrapUnwrapAsset } from '../useWrapUnwrapAsset'; +import { useAddRemoveEth } from '../useAddRemoveEth'; +import { ONE_BN, ZERO_BN } from '../../../utils/constants'; +import { ConvexJoin__factory } from '../../../contracts'; +import { HistoryContext } from '../../../contexts/HistoryContext'; import { Address, useBalance, useNetwork, useProvider } from 'wagmi'; -import useContracts from '../useContracts'; -import useAccountPlus from '../useAccountPlus'; -import { ContractNames } from '../../config/contracts'; -import useAllowAction from '../useAllowAction'; +import useContracts from '../../useContracts'; +import useAccountPlus from '../../useAccountPlus'; +import { ContractNames } from '../../../config/contracts'; +import useAllowAction from '../../useAllowAction'; -export const useRemoveCollateral = () => { +export const useRemoveCollateralFR = () => { const { userState, userActions } = useContext(UserContext); const { selectedIlk, assetMap } = userState; const { address: account } = useAccountPlus(); @@ -42,7 +42,6 @@ export const useRemoveCollateral = () => { if (!contracts) return; if (!isActionAllowed(ActionCodes.REMOVE_COLLATERAL)) return; // return if action is not allowed - /* generate the txCode for tx tracking and tracing */ const txCode = getTxCode(ActionCodes.REMOVE_COLLATERAL, vault.id); diff --git a/src/hooks/actionHooks/useRemoveCollateral/useRemoveCollateralVR.ts b/src/hooks/actionHooks/useRemoveCollateral/useRemoveCollateralVR.ts new file mode 100644 index 000000000..bfd68d3d0 --- /dev/null +++ b/src/hooks/actionHooks/useRemoveCollateral/useRemoveCollateralVR.ts @@ -0,0 +1,109 @@ +import { ethers } from 'ethers'; +import { useContext } from 'react'; +import { UserContext } from '../../../contexts/UserContext'; +import { ICallData, IVault, ActionCodes, LadleActions, RoutedActions, IHistoryContext } from '../../../types'; +import { cleanValue, getTxCode } from '../../../utils/appUtils'; +import { CONVEX_BASED_ASSETS, ETH_BASED_ASSETS, WETH } from '../../../config/assets'; +import { useChain } from '../../useChain'; +import { useWrapUnwrapAsset } from '../useWrapUnwrapAsset'; +import { useAddRemoveEth } from '../useAddRemoveEth'; +import { ONE_BN, ZERO_BN } from '../../../utils/constants'; +import { ConvexJoin__factory } from '../../../contracts'; +import { HistoryContext } from '../../../contexts/HistoryContext'; +import { Address, useBalance, useNetwork, useProvider } from 'wagmi'; +import useContracts from '../../useContracts'; +import useAccountPlus from '../../useAccountPlus'; +import { ContractNames } from '../../../config/contracts'; +import useAllowAction from '../../useAllowAction'; + +export const useRemoveCollateralVR = () => { + const { userState, userActions } = useContext(UserContext); + const { selectedIlk, assetMap } = userState; + const { address: account } = useAccountPlus(); + const { chain } = useNetwork(); + const provider = useProvider(); + const contracts = useContracts(); + const { refetch: refetchIlkBal } = useBalance({ + address: account, + token: selectedIlk?.address as Address, + }); + + const { + historyActions: { updateVaultHistory }, + } = useContext(HistoryContext) as IHistoryContext; + + const { updateAssets, updateVaults } = userActions; + const { transact } = useChain(); + const { removeEth } = useAddRemoveEth(); + const { unwrapAsset } = useWrapUnwrapAsset(); + const { isActionAllowed } = useAllowAction(); + + const removeCollateral = async (vault: IVault, input: string, unwrapOnRemove: boolean = true) => { + if (!contracts) return; + // if (!isActionAllowed(ActionCodes.REMOVE_COLLATERAL)) return; // return if action is not allowed + + /* generate the txCode for tx tracking and tracing */ + const txCode = getTxCode(ActionCodes.REMOVE_COLLATERAL, vault.id); + + /* get associated ilk */ + const ilk = assetMap?.get(vault.ilkId)!; + const ladleAddress = contracts.get(ContractNames.VR_LADLE)?.address; + /* get unwrap handler if required */ + const unwrapHandlerAddress = ilk.unwrapHandlerAddresses?.get(chain?.id!); + /* check if the ilk/asset is an eth asset variety OR if it is wrapped token, if so pour to Ladle */ + const isEthCollateral = ETH_BASED_ASSETS.includes(ilk.proxyId); + + /* parse inputs to BigNumber in Wei, and NEGATE */ + const cleanedInput = cleanValue(input, ilk.decimals); + const _input = ethers.utils.parseUnits(cleanedInput, ilk.decimals); + + /* handle wrapped tokens: */ + const unwrapCallData: ICallData[] = unwrapOnRemove ? await unwrapAsset(ilk, account!) : []; + const removeEthCallData: ICallData[] = isEthCollateral ? removeEth(ONE_BN) : []; // (exit_ether sweeps all the eth out the ladle, so exact amount is not importnat -> just greater than zero) + + /* is convex-type collateral */ + const isConvexCollateral = CONVEX_BASED_ASSETS.includes(selectedIlk?.proxyId!); + const convexJoinContract = ConvexJoin__factory.connect(ilk.joinAddress, provider); + + /* pour destination based on ilk/asset is an eth asset variety ( or unwrapHadnler address if unwrapping) */ + const pourToAddress = () => { + console.log('Requires unwrapping? ', unwrapCallData.length); + if (isEthCollateral) return ladleAddress; + if (unwrapCallData.length) return unwrapHandlerAddress; // if there is something to unwrap + return account; + }; + + const calls: ICallData[] = [ + /* convex-type collateral; ensure checkpoint before giving collateral back to account */ + { + operation: LadleActions.Fn.ROUTE, + args: [vault.owner] as RoutedActions.Args.CHECKPOINT, + fnName: RoutedActions.Fn.CHECKPOINT, + targetContract: convexJoinContract, // use the convex join contract to checkpoint + ignoreIf: !isConvexCollateral, + }, + { + operation: LadleActions.Fn.POUR, + args: [ + vault.id, + pourToAddress(), + _input.mul(-1), // NOTE: negated value! + ZERO_BN, // No debt written off + ] as LadleActions.Args.POUR, + ignoreIf: false, + }, + ...removeEthCallData, + ...unwrapCallData, + ]; + + await transact(calls, txCode); + if (selectedIlk?.proxyId !== WETH) refetchIlkBal(); + updateVaults([vault]); + updateAssets([ilk, selectedIlk!]); + updateVaultHistory([vault]); + }; + + return { + removeCollateral, + }; +}; diff --git a/src/hooks/actionHooks/useRepayDebt/index.ts b/src/hooks/actionHooks/useRepayDebt/index.ts new file mode 100644 index 000000000..7ca13d7b5 --- /dev/null +++ b/src/hooks/actionHooks/useRepayDebt/index.ts @@ -0,0 +1,16 @@ +// HOOKS +import { useRepayDebtVR } from './useRepayDebtVR'; +import { useRepayDebtFR } from './useRepayDebtFR'; + +// CONTEXTS +import { useContext } from 'react'; +import { UserContext } from '../../../contexts/UserContext'; + +export const useRepayDebt = () => { + const { userState } = useContext(UserContext); + const { selectedSeries } = userState; + + const baseHook = selectedSeries ? useRepayDebtFR : useRepayDebtVR; + + return baseHook(); +}; diff --git a/src/hooks/actionHooks/useRepayDebt.ts b/src/hooks/actionHooks/useRepayDebt/useRepayDebtFR.ts similarity index 85% rename from src/hooks/actionHooks/useRepayDebt.ts rename to src/hooks/actionHooks/useRepayDebt/useRepayDebtFR.ts index eaca59a12..44893187e 100644 --- a/src/hooks/actionHooks/useRepayDebt.ts +++ b/src/hooks/actionHooks/useRepayDebt/useRepayDebtFR.ts @@ -2,25 +2,25 @@ import { ethers } from 'ethers'; import { useContext } from 'react'; import { calculateSlippage, maxBaseIn, MAX_256, sellBase } from '@yield-protocol/ui-math'; -import { UserContext } from '../../contexts/UserContext'; -import { ICallData, IVault, ISeries, ActionCodes, LadleActions, IAsset, RoutedActions } from '../../types'; -import { cleanValue, getTxCode } from '../../utils/appUtils'; -import { useChain } from '../useChain'; -import { CONVEX_BASED_ASSETS, ETH_BASED_ASSETS, USDT, WETH } from '../../config/assets'; -import { SettingsContext } from '../../contexts/SettingsContext'; -import { useAddRemoveEth } from './useAddRemoveEth'; -import { ONE_BN, ZERO_BN } from '../../utils/constants'; -import { useWrapUnwrapAsset } from './useWrapUnwrapAsset'; -import { ConvexJoin__factory } from '../../contracts'; -import useTimeTillMaturity from '../useTimeTillMaturity'; +import { UserContext } from '../../../contexts/UserContext'; +import { ICallData, IVault, ISeries, ActionCodes, LadleActions, IAsset, RoutedActions } from '../../../types'; +import { cleanValue, getTxCode } from '../../../utils/appUtils'; +import { useChain } from '../../useChain'; +import { CONVEX_BASED_ASSETS, ETH_BASED_ASSETS, USDT, WETH } from '../../../config/assets'; +import { SettingsContext } from '../../../contexts/SettingsContext'; +import { useAddRemoveEth } from '../useAddRemoveEth'; +import { ONE_BN, ZERO_BN } from '../../../utils/constants'; +import { useWrapUnwrapAsset } from '../useWrapUnwrapAsset'; +import { ConvexJoin__factory } from '../../../contracts'; +import useTimeTillMaturity from '../../useTimeTillMaturity'; import { Address, useBalance, useNetwork, useProvider } from 'wagmi'; -import useContracts from '../useContracts'; -import useChainId from '../useChainId'; -import useAccountPlus from '../useAccountPlus'; -import { ContractNames } from '../../config/contracts'; -import useAllowAction from '../useAllowAction'; +import useContracts from '../../useContracts'; +import useChainId from '../../useChainId'; +import useAccountPlus from '../../useAccountPlus'; +import { ContractNames } from '../../../config/contracts'; +import useAllowAction from '../../useAllowAction'; -export const useRepayDebt = () => { +export const useRepayDebtFR = () => { const { settingsState: { slippageTolerance, diagnostics }, } = useContext(SettingsContext); @@ -47,7 +47,7 @@ export const useRepayDebt = () => { const { getTimeTillMaturity, isMature } = useTimeTillMaturity(); const chainId = useChainId(); - const {isActionAllowed} = useAllowAction(); + const { isActionAllowed } = useAllowAction(); /** * REPAY FN @@ -56,9 +56,8 @@ export const useRepayDebt = () => { * @param reclaimCollateral */ const repay = async (vault: IVault, input: string | undefined, reclaimCollateral: boolean) => { - if (!contracts) return; - + const txCode = getTxCode(ActionCodes.REPAY, vault.id); const ladleAddress = contracts.get(ContractNames.LADLE)?.address; @@ -66,7 +65,7 @@ export const useRepayDebt = () => { const base: IAsset = assetMap?.get(vault.baseId)!; const ilk: IAsset = assetMap?.get(vault.ilkId)!; - if (!isActionAllowed(ActionCodes.REPAY, series )) return; // return if action is not allowed + if (!isActionAllowed(ActionCodes.REPAY, series)) return; // return if action is not allowed const isEthCollateral = ETH_BASED_ASSETS.includes(vault.ilkId); const isEthBase = ETH_BASED_ASSETS.includes(series.baseId); @@ -79,22 +78,23 @@ export const useRepayDebt = () => { const cleanInput = cleanValue(input, base.decimals); const _input = input ? ethers.utils.parseUnits(cleanInput, base.decimals) : ethers.constants.Zero; - const _maxSharesIn = series.sharesReserves.eq(ZERO_BN) ? ZERO_BN - : maxBaseIn( - series.sharesReserves, - series.fyTokenReserves, - getTimeTillMaturity(series.maturity), - series.ts, - series.g1, - series.decimals, - series.c, - series.mu - ); + const _maxSharesIn = series.sharesReserves.eq(ZERO_BN) + ? ZERO_BN + : maxBaseIn( + series.sharesReserves, + series.fyTokenReserves, + getTimeTillMaturity(series.maturity), + series.ts, + series.g1, + series.decimals, + series.c, + series.mu + ); /* Check if the trade of that size is possible */ - const tradeIsNotPossible = series.getShares(_input).gt(_maxSharesIn); + const tradeIsNotPossible = series.getShares(_input).gt(_maxSharesIn); - diagnostics && tradeIsNotPossible ? console.log('Trade is not possible:'): console.log('Trade is possible:') + diagnostics && tradeIsNotPossible ? console.log('Trade is not possible:') : console.log('Trade is possible:'); diagnostics && tradeIsNotPossible && console.log('Trade input', _input.toString()); diagnostics && tradeIsNotPossible && console.log('TradeMax base in:', _maxSharesIn.toString()); @@ -221,7 +221,6 @@ export const useRepayDebt = () => { ...removeEthCallData, ...unwrapAssetCallData, - ]; await transact(calls, txCode); diff --git a/src/hooks/actionHooks/useRepayDebtVariableRate.ts b/src/hooks/actionHooks/useRepayDebt/useRepayDebtVR.ts similarity index 73% rename from src/hooks/actionHooks/useRepayDebtVariableRate.ts rename to src/hooks/actionHooks/useRepayDebt/useRepayDebtVR.ts index 2dbdfc4a0..a72c6cef9 100644 --- a/src/hooks/actionHooks/useRepayDebtVariableRate.ts +++ b/src/hooks/actionHooks/useRepayDebt/useRepayDebtVR.ts @@ -1,33 +1,32 @@ import { ethers } from 'ethers'; import { useContext } from 'react'; -import { calculateSlippage, maxBaseIn, MAX_256, sellBase } from '@yield-protocol/ui-math'; - -import { UserContext } from '../../contexts/UserContext'; -import { ICallData, IVault, ISeries, ActionCodes, LadleActions, IAsset, RoutedActions } from '../../types'; -import { cleanValue, getTxCode } from '../../utils/appUtils'; -import { useChain } from '../useChain'; -import { CONVEX_BASED_ASSETS, ETH_BASED_ASSETS, USDT, WETH } from '../../config/assets'; -import { SettingsContext } from '../../contexts/SettingsContext'; -import { useAddRemoveEth } from './useAddRemoveEth'; -import { ONE_BN, ZERO_BN } from '../../utils/constants'; -import { useWrapUnwrapAsset } from './useWrapUnwrapAsset'; -import { ConvexJoin__factory } from '../../contracts'; -import useTimeTillMaturity from '../useTimeTillMaturity'; +import { calculateSlippage, MAX_256 } from '@yield-protocol/ui-math'; + +import { UserContext } from '../../../contexts/UserContext'; +import { ICallData, IVault, ActionCodes, LadleActions, IAsset, RoutedActions } from '../../../types'; +import { cleanValue, getTxCode } from '../../../utils/appUtils'; +import { useChain } from '../../useChain'; +import { CONVEX_BASED_ASSETS, ETH_BASED_ASSETS, USDT, WETH } from '../../../config/assets'; +import { SettingsContext } from '../../../contexts/SettingsContext'; +import { useAddRemoveEth } from '../useAddRemoveEth'; +import { ONE_BN, ZERO_BN } from '../../../utils/constants'; +import { useWrapUnwrapAsset } from '../useWrapUnwrapAsset'; +import { ConvexJoin__factory } from '../../../contracts'; import { Address, useBalance, useNetwork, useProvider } from 'wagmi'; -import useContracts from '../useContracts'; -import useChainId from '../useChainId'; -import useAccountPlus from '../useAccountPlus'; -import { ContractNames } from '../../config/contracts'; -import useAllowAction from '../useAllowAction'; +import useContracts from '../../useContracts'; +import useChainId from '../../useChainId'; +import useAccountPlus from '../../useAccountPlus'; +import { ContractNames } from '../../../config/contracts'; +import useAllowAction from '../../useAllowAction'; -export const useRepayDebtVariableRate = () => { +export const useRepayDebtVR = () => { const { settingsState: { slippageTolerance, diagnostics }, } = useContext(SettingsContext); const { userState, userActions } = useContext(UserContext); - const { seriesMap, assetMap, selectedIlk, selectedBase } = userState; - const { updateVaults, updateAssets, updateSeries } = userActions; + const { assetMap, selectedIlk, selectedBase } = userState; + const { updateVaults, updateAssets } = userActions; const { address: account } = useAccountPlus(); const { chain } = useNetwork(); const provider = useProvider(); @@ -44,7 +43,6 @@ export const useRepayDebtVariableRate = () => { const { addEth, removeEth } = useAddRemoveEth(); const { unwrapAsset } = useWrapUnwrapAsset(); const { sign, transact } = useChain(); - const { getTimeTillMaturity, isMature } = useTimeTillMaturity(); const chainId = useChainId(); const { isActionAllowed } = useAllowAction(); @@ -89,19 +87,6 @@ export const useRepayDebtVariableRate = () => { and calcultate in the UI */ - // const _maxSharesIn = series.sharesReserves.eq(ZERO_BN) - // ? ZERO_BN - // : maxBaseIn( - // series.sharesReserves, - // series.fyTokenReserves, - // getTimeTillMaturity(series.maturity), - // series.ts, - // series.g1, - // series.decimals, - // series.c, - // series.mu - // ); - /* Check if the trade of that size is possible */ // assuming all trades are possible for now, but will need to revisit - jacob b const tradeIsNotPossible = false; @@ -159,6 +144,7 @@ export const useRepayDebtVariableRate = () => { const removeEthCallData = isEthCollateral ? removeEth(ONE_BN) : []; /* Address to send the funds to either ladle (if eth is used as collateral) or account */ + // TODO - Need to test with this after we get a VR fork with WETH module - jacob b const reclaimToAddress = () => { if (isEthCollateral) return ladleAddress; if (unwrapAssetCallData.length && ilk.unwrapHandlerAddresses?.has(chain?.id!)) @@ -178,7 +164,6 @@ export const useRepayDebtVariableRate = () => { /* Else, Send Token to either join or pool via a ladle.transfer() */ - // think this is good - jacob b { operation: LadleActions.Fn.TRANSFER, args: [base.address, transferToAddress, amountToTransfer] as LadleActions.Args.TRANSFER, @@ -201,29 +186,6 @@ export const useRepayDebtVariableRate = () => { ignoreIf: inputGreaterThanEqualDebt || tradeIsNotPossible, }, - // { - // operation: LadleActions.Fn.REPAY_VAULT, - // args: [vault.id, reclaimToAddress(), _collateralToRemove, _input] as LadleActions.Args.REPAY_VAULT, - // ignoreIf: - // series.seriesIsMature || - // !inputGreaterThanEqualDebt || // ie ignore if use if input IS NOT more than debt - // tradeIsNotPossible, - // }, - - /* EdgeCase in lowLiq situations : Input GreaterThanMaxbaseIn ( user incurs a penalty because repaid at 1:1 ) */ - // { - // operation: LadleActions.Fn.CLOSE, - // args: [vault.id, reclaimToAddress(), _collateralToRemove, _inputCappedAtArt.mul(-1)] as LadleActions.Args.CLOSE, - // ignoreIf: series.seriesIsMature || !tradeIsNotPossible, // (ie. ignore if trade IS possible ) - // }, - - /* AFTER MATURITY - series.seriesIsMature */ - // { - // operation: LadleActions.Fn.CLOSE, - // args: [vault.id, reclaimToAddress(), _collateralToRemove, _inputCappedAtArt.mul(-1)] as LadleActions.Args.CLOSE, - // ignoreIf: !series.seriesIsMature, - // }, - ...removeEthCallData, ...unwrapAssetCallData, ]; diff --git a/src/hooks/actionHooks/useAddCollateralVariableRate.ts b/src/hooks/viewHelperHooks/useBorrowHelpers/index.ts similarity index 100% rename from src/hooks/actionHooks/useAddCollateralVariableRate.ts rename to src/hooks/viewHelperHooks/useBorrowHelpers/index.ts diff --git a/src/hooks/viewHelperHooks/useBorrowHelpers/useBorrowHelpersFR.ts b/src/hooks/viewHelperHooks/useBorrowHelpers/useBorrowHelpersFR.ts new file mode 100644 index 000000000..759e3a100 --- /dev/null +++ b/src/hooks/viewHelperHooks/useBorrowHelpers/useBorrowHelpersFR.ts @@ -0,0 +1,394 @@ +import { BigNumber, ethers } from 'ethers'; +import { useContext, useEffect, useState } from 'react'; +import { + buyBase, + buyFYToken, + calculateMinCollateral, + decimalNToDecimal18, + maxFyTokenIn, + maxFyTokenOut, +} from '@yield-protocol/ui-math'; + +import { SettingsContext } from '../../../contexts/SettingsContext'; +import { UserContext } from '../../../contexts/UserContext'; +import { IVault, ISeries, IAssetPair } from '../../../types'; +import { cleanValue } from '../../../utils/appUtils'; +import { ZERO_BN } from '../../../utils/constants'; +import useTimeTillMaturity from '../../useTimeTillMaturity'; +import { Address, useAccount, useBalance } from 'wagmi'; +import { WETH } from '../../../config/assets'; +import useAccountPlus from '../../useAccountPlus'; + +/* Collateralization hook calculates collateralization metrics */ +export const useBorrowHelpers = ( + input: string | undefined, + collateralInput: string | undefined, + vault: IVault | undefined, + assetPairInfo: IAssetPair | null | undefined, + futureSeries: ISeries | null = null // Future or rollToSeries +) => { + /* STATE FROM CONTEXT */ + const { + settingsState: { diagnostics }, + } = useContext(SettingsContext); + + const { + userState: { assetMap, seriesMap, selectedSeries }, + } = useContext(UserContext); + + const vaultBase = assetMap.get(vault?.baseId!); + const vaultIlk = assetMap.get(vault?.ilkId!); + + const { address: account } = useAccountPlus(); + const { data: baseBalance } = useBalance({ + address: account, + token: vaultBase?.proxyId === WETH ? undefined : (vaultBase?.address as Address), + }); + + const { getTimeTillMaturity, isMature } = useTimeTillMaturity(); + + /* LOCAL STATE */ + const [borrowEstimate, setBorrowEstimate] = useState(ethers.constants.Zero); + const [borrowEstimate_, setBorrowEstimate_] = useState(); + + const [debtAfterRepay, setDebtAfterRepay] = useState(); + + /* the accrued art in base terms at this moment */ + /* before maturity, this is the estimated amount of fyToken (using art) that can be bought using base */ + /* after maturity, this is the vault's art plus any variable rate accrued art */ + + const [debtInBase, setDebtInBase] = useState(ethers.constants.Zero); + const [debtInBase_, setDebtInBase_] = useState(); + + const [minDebt, setMinDebt] = useState(); + const [minDebt_, setMinDebt_] = useState(); + + const [maxDebt, setMaxDebt] = useState(); + const [maxDebt_, setMaxDebt_] = useState(); + + const [maxRepay, setMaxRepay] = useState(ethers.constants.Zero); + const [maxRepay_, setMaxRepay_] = useState(); + + const [minRepayable, setMinRepayable] = useState(ethers.constants.Zero); + const [minRepayable_, setMinRepayable_] = useState(); + + const [maxRoll, setMaxRoll] = useState(ethers.constants.Zero); + const [maxRoll_, setMaxRoll_] = useState(); + + const [borrowPossible, setBorrowPossible] = useState(false); + const [rollPossible, setRollPossible] = useState(false); + const [rollProtocolLimited, setRollProtocolLimited] = useState(false); + + /* Update the borrow limits if asset pair changes */ + useEffect(() => { + if (assetPairInfo) { + const _decimals = assetPairInfo.limitDecimals; + const _maxLessTotal = assetPairInfo.maxDebtLimit.sub(assetPairInfo.pairTotalDebt); + const _min = assetPairInfo.minDebtLimit; + + setMaxDebt(_maxLessTotal); + setMaxDebt_(ethers.utils.formatUnits(_maxLessTotal, _decimals)?.toString()); + setMinDebt(_min); + setMinDebt_(ethers.utils.formatUnits(_min, assetPairInfo.baseDecimals)?.toString()); + } + }, [assetPairInfo]); + + /* check if the user can borrow the specified amount based on protocol base reserves */ + useEffect(() => { + if (input && selectedSeries && parseFloat(input) > 0) { + const cleanedInput = cleanValue(input, selectedSeries.decimals); + const input_ = ethers.utils.parseUnits(cleanedInput, selectedSeries.decimals); + input_.lte(selectedSeries.sharesReserves) ? setBorrowPossible(true) : setBorrowPossible(false); + } + }, [input, selectedSeries, selectedSeries?.sharesReserves]); + + /* check the new debt level after potential repaying */ + useEffect(() => { + if (input && vault && parseFloat(input) > 0) { + const cleanedInput = cleanValue(input, vault.decimals); + const input_ = ethers.utils.parseUnits(cleanedInput, vault.decimals); + /* remaining debt is debt in base less input (with a minimum of zero) */ + const remainingDebt = debtInBase.sub(input_).gte(ZERO_BN) ? debtInBase.sub(input_) : ZERO_BN; + console.log('remainingDebt', debtInBase.sub(input_).gte(ZERO_BN)); + setDebtAfterRepay(remainingDebt); + } + }, [input, vault, debtInBase]); + + /* Calculate an estimated sale based on the input and future strategy, assuming correct collateralisation */ + useEffect(() => { + if (input && futureSeries && parseFloat(input) > 0) { + const cleanedInput = cleanValue(input, futureSeries.decimals); + const input_ = ethers.utils.parseUnits(cleanedInput, futureSeries.decimals); + const estimate = buyBase( + futureSeries.sharesReserves, + futureSeries.fyTokenReserves, + futureSeries.getShares(input_), + getTimeTillMaturity(futureSeries.maturity), + futureSeries.ts, + futureSeries.g2, + futureSeries.decimals, + futureSeries.c, + futureSeries.mu + ); + const estimatePlusVaultUsed = vault?.accruedArt?.gt(ethers.constants.Zero) + ? estimate.add(vault.accruedArt) + : estimate; + setBorrowEstimate(estimatePlusVaultUsed); + setBorrowEstimate_(ethers.utils.formatUnits(estimatePlusVaultUsed, futureSeries.decimals).toString()); + } + }, [input, futureSeries, vault, getTimeTillMaturity]); + + /* SET MAX ROLL and ROLLABLE including Check if the rollToSeries have sufficient base value AND won't be undercollaterallised */ + useEffect(() => { + if (futureSeries && vault && vault.accruedArt && vault.seriesId) { + const _maxFyTokenIn = maxFyTokenIn( + futureSeries.sharesReserves, + futureSeries.fyTokenReserves, + getTimeTillMaturity(futureSeries.maturity), + futureSeries.ts, + futureSeries.g2, + futureSeries.decimals, + futureSeries.c, + futureSeries.mu + ); + + const newDebt = buyBase( + futureSeries.sharesReserves, + futureSeries.fyTokenReserves, + futureSeries.getShares(vault.accruedArt), + getTimeTillMaturity(futureSeries.maturity), + futureSeries.ts, + futureSeries.g2, + futureSeries.decimals, + futureSeries.c, + futureSeries.mu + ); + + const _minCollat = calculateMinCollateral( + assetPairInfo?.pairPrice!, + newDebt, + assetPairInfo?.minRatio.toString()!, + undefined + ); + diagnostics && console.log('min Collat of roll to series', _minCollat.toString()); + + /* SET MAX ROLL */ + if (vault.accruedArt.lt(_maxFyTokenIn)) { + setMaxRoll(vault.accruedArt); + setMaxRoll_(ethers.utils.formatUnits(vault.accruedArt, futureSeries.decimals).toString()); + setRollProtocolLimited(false); + } else { + setMaxRoll(_maxFyTokenIn); + setMaxRoll_(ethers.utils.formatUnits(_maxFyTokenIn, futureSeries.decimals).toString()); + setRollProtocolLimited(true); + } + + // conditions for allowing rolling + const conditionsMet = + vault.accruedArt.lt(_maxFyTokenIn) && + decimalNToDecimal18(vault.ink, vaultIlk?.decimals || 18).gt(_minCollat) && + vault.accruedArt.gt(minDebt!); + + /* SET ROLLABLE */ + const rollable = vault.accruedArt.eq(ZERO_BN) // always rollable if zero debt + ? true + : conditionsMet; + + diagnostics && console.log('Roll possible: ', rollable); + setRollPossible(rollable); + } + }, [futureSeries, vault, diagnostics, assetPairInfo, minDebt, vaultIlk?.decimals, getTimeTillMaturity]); + + /* Update the Min Max repayable amounts */ + useEffect(() => { + if (account && vault && vaultBase && minDebt) { + console.log('in borrowHelpers just below useEffect if', vault, vaultBase, minDebt); + + const isVRVault = !vault?.seriesId; + + if (isVRVault) { + console.log('%c VR VAULT', 'color: green; font-weight: bold; font-size: 36px;'); + // setMaxRepay(vault.accruedArt); + // setMaxRepay_(vault.accruedArt_); + setDebtInBase(vault.accruedArt); + setDebtInBase_(vault.accruedArt_); + + // some of the below is dupe code from the else statement - TODO refactor - jacob b + + /* + an assumption is made in much of the below logic that because VR borrows arent series, + and thus have no maturity date, I've modified the conditionals from the else statement to default + to the isMature option. Is this the right way to think about it? - jacob b + */ + + const _baseRequired = vault.accruedArt.eq(ethers.constants.Zero) ? ethers.constants.Zero : vault.accruedArt; // modified this logic from original, TODO verify this logic - jacob b + // const _debtInBase = vault.accruedArt; + const _debtInBase = _baseRequired; + + // add buffer to handle moving interest accumulation + const _debtInBaseWithBuffer = _debtInBase.mul(1000).div(999); + + setDebtInBase(_debtInBaseWithBuffer); + setDebtInBase_(ethers.utils.formatUnits(_debtInBaseWithBuffer, vaultBase.decimals)); + + /* maxRepayable is either the max tokens they have or max debt */ + const _maxRepayable = + baseBalance?.value && _debtInBaseWithBuffer.gt(baseBalance.value) ? baseBalance.value : _debtInBaseWithBuffer; + + /* set the min repayable up to the dust limit */ + const _maxToDust = vault.accruedArt.gt(minDebt) ? _maxRepayable.sub(minDebt) : vault.accruedArt; + _maxToDust && setMinRepayable(_maxToDust); + _maxToDust && setMinRepayable_(ethers.utils.formatUnits(_maxToDust, vaultBase?.decimals)?.toString()); + + const _accruedArt = vault.accruedArt.gt(baseBalance?.value || ethers.constants.Zero) + ? baseBalance?.value! + : vault.accruedArt; + setMaxRepay(_accruedArt); + setMaxRepay_(debtInBase_); + } else { + const vaultSeries = seriesMap.get(vault?.seriesId!); + if (!vaultSeries) return; + + /* estimate max fyToken out to assess protocol limits */ + const _maxFyTokenOut = maxFyTokenOut( + vaultSeries.sharesReserves, + vaultSeries.fyTokenReserves, + getTimeTillMaturity(vaultSeries.maturity), + vaultSeries.ts, + vaultSeries.g1, + vaultSeries.decimals, + vaultSeries.c, + vaultSeries.mu + ); + + const limited = _maxFyTokenOut.lt(vault.accruedArt); + + /* adjust max repayable to vault art if protocol limited */ + if (limited) { + const accruedArt_ = ethers.utils.formatUnits(vault.accruedArt, vault.decimals); // is this necessary? seems this is already done in vault - jacob b + setMaxRepay(vault.accruedArt); + setMaxRepay_(accruedArt_); + setDebtInBase(vault.accruedArt); + setDebtInBase_(accruedArt_); + } else { + const _sharesRequired = buyFYToken( + vaultSeries.sharesReserves, + vaultSeries.fyTokenReserves, + vault.accruedArt, + getTimeTillMaturity(vaultSeries.maturity), + vaultSeries.ts, + vaultSeries.g1, + vaultSeries.decimals, + vaultSeries.c, + vaultSeries.mu + ); + + const _baseRequired = vault.accruedArt.eq(ethers.constants.Zero) + ? ethers.constants.Zero + : vaultSeries.getBase(_sharesRequired); + + const _debtInBase = isMature(vaultSeries.maturity) ? vault.accruedArt : _baseRequired; + // add buffer to handle moving interest accumulation + const _debtInBaseWithBuffer = _debtInBase.mul(1000).div(999); + + setDebtInBase(_debtInBaseWithBuffer); + setDebtInBase_(ethers.utils.formatUnits(_debtInBaseWithBuffer, vaultBase.decimals)); + + /* maxRepayable is either the max tokens they have or max debt */ + const _maxRepayable = + baseBalance?.value && _debtInBaseWithBuffer.gt(baseBalance.value) + ? baseBalance.value + : _debtInBaseWithBuffer; + + /* set the min repayable up to the dust limit */ + const _maxToDust = vault.accruedArt.gt(minDebt) ? _maxRepayable.sub(minDebt) : vault.accruedArt; + _maxToDust && setMinRepayable(_maxToDust); + _maxToDust && setMinRepayable_(ethers.utils.formatUnits(_maxToDust, vaultBase?.decimals)?.toString()); + + /* if the series is mature re-set max as all debt (if balance allows) */ + if (vaultSeries.seriesIsMature) { + const _accruedArt = vault.accruedArt.gt(baseBalance?.value || ethers.constants.Zero) + ? baseBalance?.value! + : vault.accruedArt; + setMaxRepay(_accruedArt); + setMaxRepay_(ethers.utils.formatUnits(_accruedArt, vaultBase?.decimals)?.toString()); + } else { + setMaxRepay_(ethers.utils.formatUnits(_maxRepayable, vaultBase.decimals)); + setMaxRepay(_maxRepayable); + } + } + } + } + }, [ + account, + baseBalance?.formatted, + baseBalance?.value, + getTimeTillMaturity, + isMature, + minDebt, + seriesMap, + vault, + vaultBase, + ]); + + console.log('useBorrowHelpers RETURNs', vault, debtAfterRepay?.toString(), vaultBase); + console.table({ + borrowPossible, + rollPossible, + rollProtocolLimited, + + borrowEstimate, + borrowEstimate_, + + maxRepay_, + maxRepay, + + debtInBase, + debtInBase_, + + debtAfterRepay, + + minRepayable, + minRepayable_, + + maxRoll, + maxRoll_, + + userBaseBalance: baseBalance?.value, + userBaseBalance_: baseBalance?.formatted, + maxDebt, + minDebt, + maxDebt_, + minDebt_, + }); + + return { + borrowPossible, + rollPossible, + rollProtocolLimited, + + borrowEstimate, + borrowEstimate_, + + maxRepay_, + maxRepay, + + debtInBase, + debtInBase_, + + debtAfterRepay, + + minRepayable, + minRepayable_, + + maxRoll, + maxRoll_, + + userBaseBalance: baseBalance?.value, + userBaseBalance_: baseBalance?.formatted, + maxDebt, + minDebt, + maxDebt_, + minDebt_, + }; +}; diff --git a/src/hooks/viewHelperHooks/useBorrowHelpers/useBorrowHelpersVR.ts b/src/hooks/viewHelperHooks/useBorrowHelpers/useBorrowHelpersVR.ts new file mode 100644 index 000000000..70b786d12 --- /dev/null +++ b/src/hooks/viewHelperHooks/useBorrowHelpers/useBorrowHelpersVR.ts @@ -0,0 +1 @@ +// TODO diff --git a/src/hooks/viewHelperHooks/useCollateralHelpers/index.ts b/src/hooks/viewHelperHooks/useCollateralHelpers/index.ts new file mode 100644 index 000000000..eb0e60feb --- /dev/null +++ b/src/hooks/viewHelperHooks/useCollateralHelpers/index.ts @@ -0,0 +1,17 @@ +import { useCollateralHelpersFR } from './useCollateralHelpersFR'; // TODO update exports +import { useCollateralHelpersVR } from './useCollateralHelpersVR'; // TODO update exports + +/* TYPES */ +import { IAssetPair, IVault } from '../../../types'; + +export const useCollateralHelpers = ( + debtInput: string | undefined, + collInput: string | undefined, + vault: IVault | undefined, + assetPairInfo: IAssetPair | undefined | null, + isVariableRate: boolean | undefined | null +) => { + const baseHook = isVariableRate ? useCollateralHelpersVR : useCollateralHelpersFR; + + return baseHook(debtInput, collInput, vault, assetPairInfo); +}; diff --git a/src/hooks/viewHelperHooks/useCollateralHelpers/useCollateralHelpersFR.ts b/src/hooks/viewHelperHooks/useCollateralHelpers/useCollateralHelpersFR.ts new file mode 100644 index 000000000..0ba8f3ee2 --- /dev/null +++ b/src/hooks/viewHelperHooks/useCollateralHelpers/useCollateralHelpersFR.ts @@ -0,0 +1,249 @@ +import { BigNumber, ethers } from 'ethers'; +import { useContext, useEffect, useState } from 'react'; +import { + buyBase, + calcLiquidationPrice, + calculateCollateralizationRatio, + calculateMinCollateral, + decimalNToDecimal18, +} from '@yield-protocol/ui-math'; + +import { UserContext } from '../../../contexts/UserContext'; +import { IAssetPair, IVault } from '../../../types'; +import { cleanValue } from '../../../utils/appUtils'; +import { ZERO_BN } from '../../../utils/constants'; +import useTimeTillMaturity from '../../useTimeTillMaturity'; +import { Address, useAccount, useBalance } from 'wagmi'; +import { WETH } from '../../../config/assets'; +import useAccountPlus from '../../useAccountPlus'; + +/* Collateralization hook calculates collateralization metrics */ +export const useCollateralHelpersFR = ( + debtInput: string | undefined, + collInput: string | undefined, + vault: IVault | undefined, + assetPairInfo: IAssetPair | undefined | null +) => { + /* STATE FROM CONTEXT */ + const { + userState: { selectedBase, selectedIlk, selectedSeries, assetMap, seriesMap }, + } = useContext(UserContext); + + const _selectedBase = vault ? assetMap?.get(vault.baseId) : selectedBase; + const _selectedIlk = vault ? assetMap?.get(vault.ilkId) : selectedIlk; + const _selectedSeries = vault ? seriesMap?.get(vault.seriesId) : selectedSeries; + + /* HOOKS */ + const { getTimeTillMaturity } = useTimeTillMaturity(); + const { address: activeAccount } = useAccountPlus(); + const { data: userIlkBalance } = useBalance({ + address: activeAccount, + token: _selectedIlk?.proxyId === WETH ? undefined : (_selectedIlk?.address as Address), + enabled: !!_selectedIlk, + }); + + /* LOCAL STATE */ + const [collateralizationRatio, setCollateralizationRatio] = useState(); + const [collateralizationPercent, setCollateralizationPercent] = useState(); + const [undercollateralized, setUndercollateralized] = useState(true); + const [unhealthyCollatRatio, setUnhealthyCollatRatio] = useState(false); + + const [oraclePrice, setOraclePrice] = useState(ethers.constants.Zero); + + const [liquidationPrice_, setLiquidationPrice_] = useState(); + + const [minCollateral, setMinCollateral] = useState(); + const [minCollateral_, setMinCollateral_] = useState(); + + const [minCollatRatio, setMinCollatRatio] = useState(); + const [minCollatRatioPct, setMinCollatRatioPct] = useState(); + const [minSafeCollatRatio, setMinSafeCollatRatio] = useState(); + const [minSafeCollatRatioPct, setMinSafeCollatRatioPct] = useState(); + const [minSafeCollateral, setMinSafeCollateral] = useState(); + const [maxRemovableCollateral, setMaxRemovableCollateral] = useState(); + const [maxCollateral, setMaxCollateral] = useState(); + + const [totalDebt, setTotalDebt] = useState(); + const [totalDebt_, setTotalDebt_] = useState(); + + const [totalCollateral, setTotalCollateral] = useState(); + const [totalCollateral_, setTotalCollateral_] = useState(); + + /* update the prices/limits if anything changes with the asset pair */ + useEffect(() => { + if (assetPairInfo) { + /* set the pertinent oracle price */ + setOraclePrice(decimalNToDecimal18(assetPairInfo.pairPrice, assetPairInfo.baseDecimals)); + + /* set min collaterateralisation ratio */ + setMinCollatRatio(assetPairInfo.minRatio); + setMinCollatRatioPct(Math.round(assetPairInfo.minRatio * 100).toString()); + + /* set min safe coll ratio */ + const _minSafe = () => { + if (assetPairInfo.minRatio >= 1.5) return assetPairInfo.minRatio + 1; // eg. 150% -> 250% + if (assetPairInfo.minRatio < 1.5 && assetPairInfo.minRatio >= 1.4) return assetPairInfo.minRatio + 0.65; // eg. 140% -> 200% + if (assetPairInfo.minRatio < 1.4 && assetPairInfo.minRatio > 1.01) return assetPairInfo.minRatio + 0.1; // eg. 133% -> 143% + return assetPairInfo.minRatio; // eg. 110% -> 110% + }; + + setMinSafeCollatRatio(_minSafe()); + setMinSafeCollatRatioPct((_minSafe() * 100).toString()); + + const liqPrice = vault + ? cleanValue( + calcLiquidationPrice(vault.ink_, vault.accruedArt_, assetPairInfo.minRatio), + _selectedBase?.digitFormat + ) + : cleanValue( + calcLiquidationPrice(totalCollateral_!, totalDebt_!, assetPairInfo.minRatio), + _selectedBase?.digitFormat + ); + + setLiquidationPrice_(liqPrice); + } + }, [_selectedBase?.digitFormat, assetPairInfo, totalCollateral_, totalDebt_, vault]); + + /* CHECK collateral selection and sets the max available collateral a user can add based on his balance */ + useEffect(() => { + setMaxCollateral(userIlkBalance?.formatted); + }, [userIlkBalance?.formatted]); + + /* handle changes to input values */ + useEffect(() => { + /* NOTE: this whole function ONLY deals with decimal18, existing values are converted to decimal18 */ + const _existingCollateral = vault?.ink ? vault.ink : ethers.constants.Zero; + const existingCollateralAsWei = decimalNToDecimal18(_existingCollateral, _selectedIlk?.decimals || 18); + + const newCollateralAsWei = + collInput && Math.abs(parseFloat(collInput)) > 0 ? ethers.utils.parseUnits(collInput, 18) : ethers.constants.Zero; + const _totalCollateral = existingCollateralAsWei.add(newCollateralAsWei); + + setTotalCollateral(_totalCollateral); + setTotalCollateral_(ethers.utils.formatUnits(_totalCollateral, 18)); + + const existingDebt_ = vault?.accruedArt ? vault.accruedArt : ethers.constants.Zero; + const existingDebtAsWei = decimalNToDecimal18(existingDebt_, _selectedBase?.decimals || 18); + const newDebt = + debtInput && Math.abs(parseFloat(debtInput)) > 0 && _selectedSeries + ? buyBase( + _selectedSeries.sharesReserves, + _selectedSeries.fyTokenReserves, + _selectedSeries.getShares(ethers.utils.parseUnits(debtInput, _selectedBase?.decimals)), + getTimeTillMaturity(_selectedSeries.maturity), + _selectedSeries.ts, + _selectedSeries.g2, + _selectedSeries.decimals, + _selectedSeries.c, + _selectedSeries.mu + ) + : ZERO_BN; + const newDebtAsWei = decimalNToDecimal18(newDebt, _selectedBase?.decimals || 18); + const _totalDebt = existingDebtAsWei.add(newDebtAsWei); + + setTotalDebt(_totalDebt); + setTotalDebt_(ethers.utils.formatUnits(_totalDebt, 18)); + + /* set the collateral ratio when collateral is entered */ + if (oraclePrice.gt(ethers.constants.Zero) && _totalCollateral.gt(ethers.constants.Zero)) { + const ratio = calculateCollateralizationRatio(_totalCollateral, oraclePrice, _totalDebt, false); + const percent = calculateCollateralizationRatio(_totalCollateral, oraclePrice, _totalDebt, true); + setCollateralizationRatio(ratio?.toString() || '0'); + setCollateralizationPercent(parseFloat(percent?.toString()! || '0').toFixed(2)); + } else { + setCollateralizationRatio('0.0'); + setCollateralizationPercent(cleanValue('0.0', 2)); + } + + /* check minimum collateral required base on debt */ + if (oraclePrice.gt(ethers.constants.Zero)) { + const min = calculateMinCollateral(oraclePrice, _totalDebt, minCollatRatio!.toString(), existingCollateralAsWei); + const minSafeCalc = calculateMinCollateral( + oraclePrice, + _totalDebt, + (minSafeCollatRatio || 2.5).toString(), + existingCollateralAsWei + ); + + /* + Check max collateral that is removable (based on exisiting debt) + use a buffer of 1% if there is vault debt to prevent undercollateralized failed tx's + else use the existing collateral + UPDATE: not required anymore + */ + const _maxRemove = vault?.accruedArt?.gt(ethers.constants.Zero) + ? existingCollateralAsWei.sub(min).mul(95).div(100) + : existingCollateralAsWei; + setMaxRemovableCollateral( + ethers.utils + .formatUnits(_maxRemove.gt(ethers.constants.Zero) ? _maxRemove : ethers.constants.Zero, 18) + .toString() + ); + + // factor in the current collateral input if there is a valid chosen vault + const minSafeWithCollat = BigNumber.from(minSafeCalc).sub(existingCollateralAsWei); + + // check for valid min safe scenarios + const minSafe = minSafeWithCollat.gt(ethers.constants.Zero) + ? ethers.utils.formatUnits(minSafeWithCollat, 18).toString() + : undefined; + setMinSafeCollateral(minSafe); + + setMinCollateral(min as BigNumber); + setMinCollateral_(ethers.utils.formatUnits(min, 18).toString()); + } else { + setMinCollateral(ZERO_BN); + setMinCollateral_('0'); + } + }, [ + collInput, + debtInput, + _selectedIlk, + oraclePrice, + vault, + collateralizationRatio, + _selectedBase, + minCollatRatio, + minSafeCollatRatio, + _selectedSeries, + getTimeTillMaturity, + ]); + + /* Monitor for undercollaterization/ danger-collateralisation, and set flags if reqd. */ + useEffect(() => { + parseFloat(collateralizationRatio!) >= minCollatRatio! + ? setUndercollateralized(false) + : setUndercollateralized(true); + + collateralizationRatio && + vault && + vault.accruedArt?.gt(ethers.constants.Zero) && + assetPairInfo?.minRatio! > 1.2 && + parseFloat(collateralizationRatio) > 0 && + parseFloat(collateralizationRatio) < assetPairInfo?.minRatio! + 0.2 + ? setUnhealthyCollatRatio(true) + : setUnhealthyCollatRatio(false); + }, [assetPairInfo?.minRatio, collateralizationRatio, minCollatRatio, vault]); + + return { + collateralizationRatio, + collateralizationPercent, + undercollateralized, + minCollateral, + minCollateral_, + minCollatRatioPct, + minSafeCollatRatioPct, + minSafeCollateral, + maxCollateral, + maxRemovableCollateral, + unhealthyCollatRatio, + + totalDebt, + totalDebt_, + + totalCollateral, + totalCollateral_, + + liquidationPrice_, + }; +}; diff --git a/src/hooks/viewHelperHooks/useCollateralHelpers/useCollateralHelpersVR.ts b/src/hooks/viewHelperHooks/useCollateralHelpers/useCollateralHelpersVR.ts new file mode 100644 index 000000000..cb7300121 --- /dev/null +++ b/src/hooks/viewHelperHooks/useCollateralHelpers/useCollateralHelpersVR.ts @@ -0,0 +1,282 @@ +import { BigNumber, ethers } from 'ethers'; +import { useContext, useEffect, useState } from 'react'; +import { + calcLiquidationPrice, + calculateCollateralizationRatio, + calculateMinCollateral, + decimalNToDecimal18, +} from '@yield-protocol/ui-math'; + +import { UserContext } from '../../../contexts/UserContext'; +import { IAssetPair, IVault } from '../../../types'; +import { cleanValue } from '../../../utils/appUtils'; +import { ZERO_BN } from '../../../utils/constants'; +import { Address, useAccount, useBalance } from 'wagmi'; +import { WETH } from '../../../config/assets'; +import useAccountPlus from '../../useAccountPlus'; + +/* Collateralization hook calculates collateralization metrics */ +export const useCollateralHelpersVR = ( + debtInput: string | undefined, + collInput: string | undefined, + vault: IVault | undefined, + assetPairInfo: IAssetPair | undefined | null +) => { + /* STATE FROM CONTEXT */ + const { + userState: { selectedBase, selectedIlk, selectedSeries, assetMap, seriesMap }, + } = useContext(UserContext); + + const _selectedBase = vault ? assetMap?.get(vault.baseId) : selectedBase; + const _selectedIlk = vault ? assetMap?.get(vault.ilkId) : selectedIlk; + // const _selectedSeries = vault ? seriesMap?.get(vault.seriesId) : selectedSeries; + + /* HOOKS */ + const { address: activeAccount } = useAccountPlus(); + const { data: userIlkBalance } = useBalance({ + address: activeAccount, + token: _selectedIlk?.proxyId === WETH ? undefined : (_selectedIlk?.address as Address), + enabled: !!_selectedIlk, + }); + + /* LOCAL STATE */ + const [collateralizationRatio, setCollateralizationRatio] = useState(); + const [collateralizationPercent, setCollateralizationPercent] = useState(); + const [undercollateralized, setUndercollateralized] = useState(true); + const [unhealthyCollatRatio, setUnhealthyCollatRatio] = useState(false); + + const [oraclePrice, setOraclePrice] = useState(ethers.constants.Zero); + + const [liquidationPrice_, setLiquidationPrice_] = useState(); + + const [minCollateral, setMinCollateral] = useState(); + const [minCollateral_, setMinCollateral_] = useState(); + + const [minCollatRatio, setMinCollatRatio] = useState(); + const [minCollatRatioPct, setMinCollatRatioPct] = useState(); + const [minSafeCollatRatio, setMinSafeCollatRatio] = useState(); + const [minSafeCollatRatioPct, setMinSafeCollatRatioPct] = useState(); + const [minSafeCollateral, setMinSafeCollateral] = useState(); + const [maxRemovableCollateral, setMaxRemovableCollateral] = useState(); + const [maxCollateral, setMaxCollateral] = useState(); + + const [totalDebt, setTotalDebt] = useState(); + const [totalDebt_, setTotalDebt_] = useState(); + + const [totalCollateral, setTotalCollateral] = useState(); + const [totalCollateral_, setTotalCollateral_] = useState(); + + /* update the prices/limits if anything changes with the asset pair */ + useEffect(() => { + if (assetPairInfo) { + /* set the pertinent oracle price */ + setOraclePrice(decimalNToDecimal18(assetPairInfo.pairPrice, assetPairInfo.baseDecimals)); + + /* set min collaterateralisation ratio */ + setMinCollatRatio(assetPairInfo.minRatio); + setMinCollatRatioPct(Math.round(assetPairInfo.minRatio * 100).toString()); + + /* set min safe coll ratio */ + const _minSafe = () => { + if (assetPairInfo.minRatio >= 1.5) return assetPairInfo.minRatio + 1; // eg. 150% -> 250% + if (assetPairInfo.minRatio < 1.5 && assetPairInfo.minRatio >= 1.4) return assetPairInfo.minRatio + 0.65; // eg. 140% -> 200% + if (assetPairInfo.minRatio < 1.4 && assetPairInfo.minRatio > 1.01) return assetPairInfo.minRatio + 0.1; // eg. 133% -> 143% + return assetPairInfo.minRatio; // eg. 110% -> 110% + }; + + setMinSafeCollatRatio(_minSafe()); + setMinSafeCollatRatioPct((_minSafe() * 100).toString()); + + const liqPrice = vault + ? cleanValue( + calcLiquidationPrice(vault.ink_, vault.accruedArt_, assetPairInfo.minRatio), + _selectedBase?.digitFormat + ) + : cleanValue( + calcLiquidationPrice(totalCollateral_!, totalDebt_!, assetPairInfo.minRatio), + _selectedBase?.digitFormat + ); + + setLiquidationPrice_(liqPrice); + } + }, [_selectedBase?.digitFormat, assetPairInfo, totalCollateral_, totalDebt_, vault]); + + /* CHECK collateral selection and sets the max available collateral a user can add based on his balance */ + useEffect(() => { + setMaxCollateral(userIlkBalance?.formatted); + }, [userIlkBalance?.formatted]); + + /* handle changes to input values */ + useEffect(() => { + /* NOTE: this whole function ONLY deals with decimal18, existing values are converted to decimal18 */ + const _existingCollateral = vault?.ink ? vault.ink : ethers.constants.Zero; + const existingCollateralAsWei = decimalNToDecimal18(_existingCollateral, _selectedIlk?.decimals || 18); + + const newCollateralAsWei = + collInput && Math.abs(parseFloat(collInput)) > 0 ? ethers.utils.parseUnits(collInput, 18) : ethers.constants.Zero; + const _totalCollateral = existingCollateralAsWei.add(newCollateralAsWei); + + setTotalCollateral(_totalCollateral); + setTotalCollateral_(ethers.utils.formatUnits(_totalCollateral, 18)); + + console.log('useCollateralHelpers VR', _existingCollateral, existingCollateralAsWei, newCollateralAsWei); + + const existingDebt_ = vault?.accruedArt ? vault.accruedArt : ethers.constants.Zero; + const existingDebtAsWei = decimalNToDecimal18(existingDebt_, _selectedBase?.decimals || 18); + const newDebt = + debtInput && Math.abs(parseFloat(debtInput)) > 0 + ? ethers.utils.parseUnits(debtInput, _selectedBase?.decimals) + : ethers.constants.Zero; // TODO: why is this not decimal18 + + // console.log('newDebt in useCollateralHelpers', newDebt); + + const newDebtAsWei = decimalNToDecimal18(newDebt, _selectedBase?.decimals || 18); + const _totalDebt = existingDebtAsWei.add(newDebtAsWei); + + // console.log('useCollateralHelpers VR', _totalDebt, ethers.utils.formatUnits(_totalDebt, 18)); + // the above value seems right for totalDebt - Jacob b + + setTotalDebt(_totalDebt); + setTotalDebt_(ethers.utils.formatUnits(_totalDebt, 18)); + + console.log( + 'useCollateralHelpers VR before calc if/else', + oraclePrice.gt(ethers.constants.Zero), + _totalCollateral.gt(ethers.constants.Zero) + ); + + /* set the collateral ratio when collateral is entered */ + if (oraclePrice.gt(ethers.constants.Zero) && _totalCollateral.gt(ethers.constants.Zero)) { + const ratio = calculateCollateralizationRatio(_totalCollateral, oraclePrice, _totalDebt, false); + const percent = calculateCollateralizationRatio(_totalCollateral, oraclePrice, _totalDebt, true); + setCollateralizationRatio(ratio?.toString() || '0'); + setCollateralizationPercent(parseFloat(percent?.toString()! || '0').toFixed(2)); + + console.log( + '%c in if useCollateralHelpers, trying to calc collat ratio', + 'font-size: 35px;', + calculateCollateralizationRatio(_totalCollateral, oraclePrice, _totalDebt, false), + + _totalCollateral, + oraclePrice.toString(), + _totalDebt.toString() + ); + } else { + console.log('%c in else useCollateralHelpers, setting collat ratio to 0', 'font-size: 48px;'); + + setCollateralizationRatio('0.0'); + setCollateralizationPercent(cleanValue('0.0', 2)); + } + + /* check minimum collateral required base on debt */ + if (oraclePrice.gt(ethers.constants.Zero)) { + const min = calculateMinCollateral(oraclePrice, _totalDebt, minCollatRatio!.toString(), existingCollateralAsWei); + const minSafeCalc = calculateMinCollateral( + oraclePrice, + _totalDebt, + (minSafeCollatRatio || 2.5).toString(), + existingCollateralAsWei + ); + + /* + Check max collateral that is removable (based on exisiting debt) + use a buffer of 1% if there is vault debt to prevent undercollateralized failed tx's + else use the existing collateral + UPDATE: not required anymore + */ + const _maxRemove = vault?.accruedArt?.gt(ethers.constants.Zero) + ? existingCollateralAsWei.sub(min).mul(95).div(100) + : existingCollateralAsWei; + setMaxRemovableCollateral( + ethers.utils + .formatUnits(_maxRemove.gt(ethers.constants.Zero) ? _maxRemove : ethers.constants.Zero, 18) + .toString() + ); + + // factor in the current collateral input if there is a valid chosen vault + const minSafeWithCollat = BigNumber.from(minSafeCalc).sub(existingCollateralAsWei); + + // check for valid min safe scenarios + const minSafe = minSafeWithCollat.gt(ethers.constants.Zero) + ? ethers.utils.formatUnits(minSafeWithCollat, 18).toString() + : undefined; + setMinSafeCollateral(minSafe); + + setMinCollateral(min as BigNumber); + setMinCollateral_(ethers.utils.formatUnits(min, 18).toString()); + } else { + setMinCollateral(ZERO_BN); + setMinCollateral_('0'); + } + }, [ + collInput, + debtInput, + _selectedIlk, + oraclePrice, + vault, + collateralizationRatio, + _selectedBase, + minCollatRatio, + minSafeCollatRatio, + ]); + + /* Monitor for undercollaterization/ danger-collateralisation, and set flags if reqd. */ + useEffect(() => { + parseFloat(collateralizationRatio!) >= minCollatRatio! + ? setUndercollateralized(false) + : setUndercollateralized(true); + + collateralizationRatio && + vault && + vault.accruedArt?.gt(ethers.constants.Zero) && + assetPairInfo?.minRatio! > 1.2 && + parseFloat(collateralizationRatio) > 0 && + parseFloat(collateralizationRatio) < assetPairInfo?.minRatio! + 0.2 + ? setUnhealthyCollatRatio(true) + : setUnhealthyCollatRatio(false); + }, [assetPairInfo?.minRatio, collateralizationRatio, minCollatRatio, vault]); + + console.log('%c useCollateralHelpers returns', 'color: #00ff00; font-size: 24px;', { + collateralizationRatio, + collateralizationPercent, + undercollateralized, + minCollateral, + minCollateral_, + minCollatRatioPct, + minSafeCollatRatioPct, + minSafeCollateral, + maxCollateral, + maxRemovableCollateral, + unhealthyCollatRatio, + + totalDebt, + totalDebt_, + + totalCollateral, + totalCollateral_, + + liquidationPrice_, + }); + + return { + collateralizationRatio, + collateralizationPercent, + undercollateralized, + minCollateral, + minCollateral_, + minCollatRatioPct, + minSafeCollatRatioPct, + minSafeCollateral, + maxCollateral, + maxRemovableCollateral, + unhealthyCollatRatio, + + totalDebt, + totalDebt_, + + totalCollateral, + totalCollateral_, + + liquidationPrice_, + }; +}; diff --git a/src/hooks/viewHelperHooks/usePoolHelpers/index.ts b/src/hooks/viewHelperHooks/usePoolHelpers/index.ts new file mode 100644 index 000000000..e69de29bb diff --git a/src/hooks/viewHelperHooks/usePoolHelpers/usePoolHelpersFR.ts b/src/hooks/viewHelperHooks/usePoolHelpers/usePoolHelpersFR.ts new file mode 100644 index 000000000..e69de29bb diff --git a/src/hooks/viewHelperHooks/usePoolHelpers/usePoolHelpersVR.ts b/src/hooks/viewHelperHooks/usePoolHelpers/usePoolHelpersVR.ts new file mode 100644 index 000000000..e69de29bb diff --git a/src/types/operations.ts b/src/types/operations.ts index e59cead5f..f58542e66 100644 --- a/src/types/operations.ts +++ b/src/types/operations.ts @@ -100,12 +100,16 @@ export namespace RoutedActions { UNWRAP = 'unwrap', CHECKPOINT = 'checkpoint', // convex + DEPOSIT = 'deposit', // for VR lending } export namespace Args { export type SELL_BASE = [receiver: string, min: BigNumberish]; export type SELL_FYTOKEN = [receiver: string, min: BigNumberish]; + // new for VR + export type DEPOSIT = [receiver: string, amount: BigNumberish]; + export type MINT_POOL_TOKENS = [to: string, remainderTo: string, minRatio: BigNumberish, maxRatio: BigNumberish]; export type BURN_POOL_TOKENS = [baseTo: string, fyTokenTo: string, minRatio: BigNumberish, maxRatio: BigNumberish]; From 931ded3f50bfcdb7fd7481e46253cbc89cf59ef4 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Fri, 14 Apr 2023 10:08:40 -0700 Subject: [PATCH 014/242] feat: logs --- src/hooks/actionHooks/useLend/useLendFR.ts | 1 + src/hooks/actionHooks/useLend/useLendVR.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/hooks/actionHooks/useLend/useLendFR.ts b/src/hooks/actionHooks/useLend/useLendFR.ts index 5b62f0a07..ef95a7b9c 100644 --- a/src/hooks/actionHooks/useLend/useLendFR.ts +++ b/src/hooks/actionHooks/useLend/useLendFR.ts @@ -47,6 +47,7 @@ export const useLendFR = () => { const contracts = useContracts(); const lend = async (input: string | undefined, series: ISeries) => { + console.log('🦄 ~ file: useLendFR.ts:49 ~ lend ~ input, series', input, series); if (!contracts) return; if (!isActionAllowed(ActionCodes.LEND)) return; // return if action is not allowed diff --git a/src/hooks/actionHooks/useLend/useLendVR.ts b/src/hooks/actionHooks/useLend/useLendVR.ts index 0a8aa9a50..2d1ecb8e4 100644 --- a/src/hooks/actionHooks/useLend/useLendVR.ts +++ b/src/hooks/actionHooks/useLend/useLendVR.ts @@ -48,6 +48,7 @@ export const useLendVR = () => { const contracts = useContracts(); const lend = async (input: string | undefined, series: ISeries) => { + console.log('🦄 ~ file: useLendVR.ts:68 ~ lend ~ input, series', input, series); if (!contracts) return; // if (!isActionAllowed(ActionCodes.LEND)) return; // return if action is not allowed -- TODO implement for VR - jacob b From 3192137f15b4c7d72f1cc5a708dc7f783748c66f Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Fri, 14 Apr 2023 10:09:14 -0700 Subject: [PATCH 015/242] feat: use fr or vr lend based on selectedVR --- src/hooks/actionHooks/useLend/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/hooks/actionHooks/useLend/index.ts b/src/hooks/actionHooks/useLend/index.ts index 19cad9370..0376448a2 100644 --- a/src/hooks/actionHooks/useLend/index.ts +++ b/src/hooks/actionHooks/useLend/index.ts @@ -7,9 +7,12 @@ import { useContext } from 'react'; import { UserContext } from '../../../contexts/UserContext'; export const useLend = () => { - console.log('useLend firing index.ts'); + const lendFR = useLendFR(); + const lendVR = useLendVR(); const { userState } = useContext(UserContext); const { selectedVR } = userState; - return selectedVR ? useLendVR() : useLendFR(); + return selectedVR ? lendVR : lendFR; }; + +export default useLend; From 631051cf53bdecdb5c52afa69506cd33c93ce2dd Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Fri, 14 Apr 2023 10:09:33 -0700 Subject: [PATCH 016/242] chore: remove logs for other log visibility --- src/hooks/useInputValidation.ts | 2 -- src/hooks/useProcess.ts | 1 - 2 files changed, 3 deletions(-) diff --git a/src/hooks/useInputValidation.ts b/src/hooks/useInputValidation.ts index bd211f92c..d7edb2782 100644 --- a/src/hooks/useInputValidation.ts +++ b/src/hooks/useInputValidation.ts @@ -14,8 +14,6 @@ export const useInputValidation = ( limits: (number | string | undefined)[], vault?: IVault | undefined ) => { - console.log('useInputValidation args: ', input, actionCode, series, limits, vault); - /* STATE FROM CONTEXT */ const { userState } = useContext(UserContext); const { assetMap, selectedSeries, selectedBase } = userState; diff --git a/src/hooks/useProcess.ts b/src/hooks/useProcess.ts index 7be14aaf2..23ef6eb81 100644 --- a/src/hooks/useProcess.ts +++ b/src/hooks/useProcess.ts @@ -33,7 +33,6 @@ export const useProcess = ( useEffect(() => { const _process = processes.get(txCode); - console.log('useProcess: ', _process); if (_process) setTxProcess(_process); }, [processes, txCode]); From e7f8160226e05524a4e1d05ded8849af190348e0 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Fri, 14 Apr 2023 10:12:22 -0700 Subject: [PATCH 017/242] chore: use default import --- src/components/views/Lend.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/Lend.tsx b/src/components/views/Lend.tsx index ce0638ab6..f9cfedbe1 100644 --- a/src/components/views/Lend.tsx +++ b/src/components/views/Lend.tsx @@ -31,7 +31,7 @@ import { useInputValidation } from '../../hooks/useInputValidation'; import AltText from '../texts/AltText'; import YieldCardHeader from '../YieldCardHeader'; import { useLendHelpers } from '../../hooks/viewHelperHooks/useLendHelpers'; -import { useLend } from '../../hooks/actionHooks/useLend'; +import useLend from '../../hooks/actionHooks/useLend'; import ColorText from '../texts/ColorText'; import { useProcess } from '../../hooks/useProcess'; From 6b47cf7788f7e0c1f464c3c529e2fd81329f40d4 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Fri, 14 Apr 2023 10:51:20 -0700 Subject: [PATCH 018/242] feat: templated vr lend func --- src/hooks/actionHooks/useLend/useLendVR.ts | 77 ++++++++-------------- src/types/index.ts | 1 + 2 files changed, 30 insertions(+), 48 deletions(-) diff --git a/src/hooks/actionHooks/useLend/useLendVR.ts b/src/hooks/actionHooks/useLend/useLendVR.ts index 2d1ecb8e4..a746f57d7 100644 --- a/src/hooks/actionHooks/useLend/useLendVR.ts +++ b/src/hooks/actionHooks/useLend/useLendVR.ts @@ -1,6 +1,6 @@ import { ethers } from 'ethers'; import { useContext } from 'react'; -import { calculateSlippage, MAX_256, sellBase } from '@yield-protocol/ui-math'; +import { MAX_256 } from '@yield-protocol/ui-math'; import { ETH_BASED_ASSETS, USDT } from '../../../config/assets'; import { HistoryContext } from '../../../contexts/HistoryContext'; @@ -11,13 +11,12 @@ import { cleanValue, getTxCode } from '../../../utils/appUtils'; import { useChain } from '../../useChain'; import { useAddRemoveEth } from '../useAddRemoveEth'; import useTimeTillMaturity from '../../useTimeTillMaturity'; -import { Address, useBalance, useProvider } from 'wagmi'; +import { Address, useBalance } from 'wagmi'; import useContracts from '../../useContracts'; import useChainId from '../../useChainId'; import useAccountPlus from '../../useAccountPlus'; import { ContractNames } from '../../../config/contracts'; import useAllowAction from '../../useAllowAction'; -import { VRLadle__factory } from '../../../contracts'; /* Lend Actions Hook */ export const useLendVR = () => { @@ -26,13 +25,12 @@ export const useLendVR = () => { } = useContext(SettingsContext); const { userState, userActions } = useContext(UserContext); - const { assetMap, selectedSeries, selectedBase } = userState; + const { assetMap, selectedBase } = userState; const { updateSeries, updateAssets } = userActions; const { address: account } = useAccountPlus(); const chainId = useChainId(); const { isActionAllowed } = useAllowAction(); - // const { refetch: refetchFyTokenBal } = useBalance({ address: account, token: selectedSeries?.address as Address }); const { refetch: refetchBaseBal } = useBalance({ address: account, token: selectedBase?.address as Address, @@ -44,55 +42,37 @@ export const useLendVR = () => { const { sign, transact } = useChain(); const { addEth } = useAddRemoveEth(); - // const { getTimeTillMaturity } = useTimeTillMaturity(); + const { getTimeTillMaturity } = useTimeTillMaturity(); const contracts = useContracts(); - const lend = async (input: string | undefined, series: ISeries) => { - console.log('🦄 ~ file: useLendVR.ts:68 ~ lend ~ input, series', input, series); - if (!contracts) return; - // if (!isActionAllowed(ActionCodes.LEND)) return; // return if action is not allowed -- TODO implement for VR - jacob b + const lend = async (input: string | undefined) => { + if (!selectedBase || !contracts || !assetMap || !account) return; + if (!isActionAllowed(ActionCodes.LEND_FR)) return; /* generate the reproducible txCode for tx tracking and tracing */ - const txCode = getTxCode(ActionCodes.LEND, series.id); + const txCode = getTxCode(ActionCodes.LEND, `${selectedBase?.id}-vr`); - const base = selectedBase!; - const cleanedInput = cleanValue(input, base?.decimals); + const base = assetMap.get(selectedBase.id); + if (!base) return; + + const cleanedInput = cleanValue(input, base.decimals); const _input = input ? ethers.utils.parseUnits(cleanedInput, base?.decimals) : ethers.constants.Zero; - // const provider = useProvider(); const ladleAddress = contracts.get(ContractNames.VR_LADLE)?.address; - // const ladle = VRLadle__factory.connect(ladleAddress!, provider); - // const joinAddress = await ladle.joins(base.id); - - console.log('fetch joinAddresses'); - return; - - // const _inputAsFyToken = sellBase( - // series.sharesReserves, - // series.fyTokenReserves, - // series.getShares(_input), // convert base input to shares - // getTimeTillMaturity(series.maturity), - // series.ts, - // series.g1, - // series.decimals, - // series.c, - // series.mu - // ); - - // how do we get our slippage tolerance? - jacob b - // const _inputAsFyTokenWithSlippage = calculateSlippage(_inputAsFyToken, slippageTolerance.toString(), true); - - /* if approveMAx, check if signature is required */ - const alreadyApproved = (await base.getAllowance(account!, ladleAddress!)).gte(_input); + + if (!ladleAddress) return; + + /* check if signature is required */ + const alreadyApproved = (await base.getAllowance(account, ladleAddress)).gte(_input); /* ETH is used as a base */ - const isEthBase = ETH_BASED_ASSETS.includes(series.baseId); + const isEthBase = ETH_BASED_ASSETS.includes(selectedBase.id); const permitCallData: ICallData[] = await sign( [ { target: base, - spender: 'LADLE', + spender: ladleAddress, amount: base.id === USDT && chainId !== 42161 ? MAX_256 : _input, // USDT allowance when non-zero needs to be set to 0 explicitly before settting to a non-zero amount; instead of having multiple approvals, we approve max from the outset on mainnet ignoreIf: alreadyApproved === true, }, @@ -101,33 +81,34 @@ export const useLendVR = () => { ); const addEthCallData = () => { - if (isEthBase) return addEth(_input, series.poolAddress); + // if (isEthBase) return addEth(_input, series.poolAddress); // TODO addETH using vr return []; }; + const vyPool = 'something'; // TODO + const proxyContract = 'something' as ProxyContractVR; // TODO + const calls: ICallData[] = [ - // ...permitCallData, - dont think we need this for VR - check recipe book - jacob b + ...permitCallData, ...addEthCallData(), { operation: LadleActions.Fn.TRANSFER, - args: [base.address, joinAddress, _input] as LadleActions.Args.TRANSFER, + args: [base.address, vyPool, _input] as LadleActions.Args.TRANSFER, ignoreIf: isEthBase, }, { operation: LadleActions.Fn.ROUTE, - args: [account, _input] as RoutedActions.Args.SELL_BASE, - fnName: RoutedActions.Fn.SELL_BASE, - targetContract: series.poolContract, + args: [account, _input] as RoutedActions.Args.LEND, // TODO get real routed action/func args + fnName: RoutedActions.Fn.LEND_VR, // TODO get real routed action/func name + targetContract: proxyContract, ignoreIf: false, }, ]; await transact(calls, txCode); refetchBaseBal(); - // refetchFyTokenBal(); - // updateSeries([series]); updateAssets([base]); - // updateTradeHistory([series]); -- TODO - need to update this for VR - jacob b + updateLendVRHistory(); // TODO update vr lend history }; return lend; diff --git a/src/types/index.ts b/src/types/index.ts index ef9fade93..d297b4311 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -434,6 +434,7 @@ export enum ActionCodes { ROLL_DEBT = 'Roll Debt', // LEND LEND = 'Lend', + LEND_FR = 'Lend_FR', CLOSE_POSITION = 'Redeem Position', ROLL_POSITION = 'Roll Position', REDEEM = 'Redeem', From f5f9cafef7eb7aed4d46873cba6a93fa4d63dc9f Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Fri, 14 Apr 2023 10:54:05 -0700 Subject: [PATCH 019/242] feat: get join addr --- src/hooks/actionHooks/useLend/useLendVR.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/hooks/actionHooks/useLend/useLendVR.ts b/src/hooks/actionHooks/useLend/useLendVR.ts index a746f57d7..a042bb6da 100644 --- a/src/hooks/actionHooks/useLend/useLendVR.ts +++ b/src/hooks/actionHooks/useLend/useLendVR.ts @@ -17,6 +17,7 @@ import useChainId from '../../useChainId'; import useAccountPlus from '../../useAccountPlus'; import { ContractNames } from '../../../config/contracts'; import useAllowAction from '../../useAllowAction'; +import { VRLadle } from '../../../contracts'; /* Lend Actions Hook */ export const useLendVR = () => { @@ -58,12 +59,12 @@ export const useLendVR = () => { const cleanedInput = cleanValue(input, base.decimals); const _input = input ? ethers.utils.parseUnits(cleanedInput, base?.decimals) : ethers.constants.Zero; - const ladleAddress = contracts.get(ContractNames.VR_LADLE)?.address; + const ladle = contracts.get(ContractNames.VR_LADLE) as VRLadle | undefined; - if (!ladleAddress) return; + if (!ladle?.address) return; /* check if signature is required */ - const alreadyApproved = (await base.getAllowance(account, ladleAddress)).gte(_input); + const alreadyApproved = (await base.getAllowance(account, ladle.address)).gte(_input); /* ETH is used as a base */ const isEthBase = ETH_BASED_ASSETS.includes(selectedBase.id); @@ -84,7 +85,7 @@ export const useLendVR = () => { // if (isEthBase) return addEth(_input, series.poolAddress); // TODO addETH using vr return []; }; - + const joinAddr = await ladle.joins(base.id); const vyPool = 'something'; // TODO const proxyContract = 'something' as ProxyContractVR; // TODO @@ -93,7 +94,7 @@ export const useLendVR = () => { ...addEthCallData(), { operation: LadleActions.Fn.TRANSFER, - args: [base.address, vyPool, _input] as LadleActions.Args.TRANSFER, + args: [base.address, joinAddr, _input] as LadleActions.Args.TRANSFER, ignoreIf: isEthBase, }, { From 7cfdc73efb2f1a9ee5937581f37bc406d74012c4 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Fri, 14 Apr 2023 10:55:58 -0700 Subject: [PATCH 020/242] feat: update with real func name --- src/hooks/actionHooks/useLend/useLendVR.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/hooks/actionHooks/useLend/useLendVR.ts b/src/hooks/actionHooks/useLend/useLendVR.ts index a042bb6da..93557f5b2 100644 --- a/src/hooks/actionHooks/useLend/useLendVR.ts +++ b/src/hooks/actionHooks/useLend/useLendVR.ts @@ -86,8 +86,7 @@ export const useLendVR = () => { return []; }; const joinAddr = await ladle.joins(base.id); - const vyPool = 'something'; // TODO - const proxyContract = 'something' as ProxyContractVR; // TODO + const vyTokenAddr = 'something'; // TODO const calls: ICallData[] = [ ...permitCallData, @@ -99,9 +98,9 @@ export const useLendVR = () => { }, { operation: LadleActions.Fn.ROUTE, - args: [account, _input] as RoutedActions.Args.LEND, // TODO get real routed action/func args - fnName: RoutedActions.Fn.LEND_VR, // TODO get real routed action/func name - targetContract: proxyContract, + args: [account, _input] as RoutedActions.Args.DEPOSIT, + fnName: RoutedActions.Fn.DEPOSIT, + targetContract: vyTokenContract, ignoreIf: false, }, ]; From 509c743ea1fd41f14acbf74cf7b2567f0513f4ec Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Fri, 14 Apr 2023 11:00:05 -0700 Subject: [PATCH 021/242] feat: clean --- src/hooks/actionHooks/useLend/useLendVR.ts | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/hooks/actionHooks/useLend/useLendVR.ts b/src/hooks/actionHooks/useLend/useLendVR.ts index 93557f5b2..a1fecb24c 100644 --- a/src/hooks/actionHooks/useLend/useLendVR.ts +++ b/src/hooks/actionHooks/useLend/useLendVR.ts @@ -4,14 +4,12 @@ import { MAX_256 } from '@yield-protocol/ui-math'; import { ETH_BASED_ASSETS, USDT } from '../../../config/assets'; import { HistoryContext } from '../../../contexts/HistoryContext'; -import { SettingsContext } from '../../../contexts/SettingsContext'; import { UserContext } from '../../../contexts/UserContext'; -import { ICallData, ISeries, ActionCodes, LadleActions, RoutedActions } from '../../../types'; +import { ICallData, ActionCodes, LadleActions, RoutedActions } from '../../../types'; import { cleanValue, getTxCode } from '../../../utils/appUtils'; import { useChain } from '../../useChain'; import { useAddRemoveEth } from '../useAddRemoveEth'; -import useTimeTillMaturity from '../../useTimeTillMaturity'; -import { Address, useBalance } from 'wagmi'; +import { Address, useBalance, useProvider } from 'wagmi'; import useContracts from '../../useContracts'; import useChainId from '../../useChainId'; import useAccountPlus from '../../useAccountPlus'; @@ -21,13 +19,10 @@ import { VRLadle } from '../../../contracts'; /* Lend Actions Hook */ export const useLendVR = () => { - const { - settingsState: { slippageTolerance }, - } = useContext(SettingsContext); - const { userState, userActions } = useContext(UserContext); + const provider = useProvider(); const { assetMap, selectedBase } = userState; - const { updateSeries, updateAssets } = userActions; + const { updateAssets } = userActions; const { address: account } = useAccountPlus(); const chainId = useChainId(); const { isActionAllowed } = useAllowAction(); @@ -38,12 +33,11 @@ export const useLendVR = () => { }); const { - historyActions: { updateTradeHistory }, + historyActions: { updateTradeHistory }, // vr deposit history } = useContext(HistoryContext); const { sign, transact } = useChain(); const { addEth } = useAddRemoveEth(); - const { getTimeTillMaturity } = useTimeTillMaturity(); const contracts = useContracts(); const lend = async (input: string | undefined) => { @@ -73,7 +67,7 @@ export const useLendVR = () => { [ { target: base, - spender: ladleAddress, + spender: ladle.address, amount: base.id === USDT && chainId !== 42161 ? MAX_256 : _input, // USDT allowance when non-zero needs to be set to 0 explicitly before settting to a non-zero amount; instead of having multiple approvals, we approve max from the outset on mainnet ignoreIf: alreadyApproved === true, }, @@ -87,6 +81,7 @@ export const useLendVR = () => { }; const joinAddr = await ladle.joins(base.id); const vyTokenAddr = 'something'; // TODO + const vyTokenContract = VYTokenFactory.connect(vyTokenAddr, provider); const calls: ICallData[] = [ ...permitCallData, @@ -108,7 +103,7 @@ export const useLendVR = () => { await transact(calls, txCode); refetchBaseBal(); updateAssets([base]); - updateLendVRHistory(); // TODO update vr lend history + // updateLendVRHistory(); // TODO update vr lend history }; return lend; From e66d9bf2569440d5fb5a7c6de959ead81e29f5c3 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Fri, 14 Apr 2023 11:01:21 -0700 Subject: [PATCH 022/242] feat: allow all vr actions for now --- src/hooks/useAllowAction.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/hooks/useAllowAction.ts b/src/hooks/useAllowAction.ts index 3aaaaf903..7a48f9472 100644 --- a/src/hooks/useAllowAction.ts +++ b/src/hooks/useAllowAction.ts @@ -10,14 +10,20 @@ import { ActionCodes, ISeries } from '../types'; * @returns boolean */ const useAllowAction = () => { - const { userState } = useContext(UserContext); + const { + userState: { selectedSeries, selectedVR }, + } = useContext(UserContext); const isActionAllowed = (action: ActionCodes, series?: ISeries): boolean => { - const seriesToUse = series || userState.selectedSeries; + const seriesToUse = series || selectedSeries; + + // allow all vr actions for now + if (selectedVR) return true; if (seriesToUse) { - if (seriesToUse.allowActions.includes('allow_all') || seriesToUse.allowActions.includes(action)) {return true} - else { + if (seriesToUse.allowActions.includes('allow_all') || seriesToUse.allowActions.includes(action)) { + return true; + } else { toast.warn(`Action temporarily not allowed on this series.`); return false; } From ca08500208d967807a50dd491625d1b83bf9825f Mon Sep 17 00:00:00 2001 From: Jacob Bryant Date: Fri, 14 Apr 2023 14:04:49 -0400 Subject: [PATCH 023/242] contracts/abis --- src/config/contracts.ts | 6 +- src/contracts/VYToken.d.ts | 1911 +++++++++++++++++ src/contracts/VYTokenProxy.d.ts | 126 ++ src/contracts/abis/VYToken.json | 578 +++++ src/contracts/abis/VYTokenProxy.json | 33 + .../factories/VYTokenProxy__factory.ts | 92 + src/contracts/factories/VYToken__factory.ts | 1316 ++++++++++++ src/contracts/index.ts | 4 + 8 files changed, 4063 insertions(+), 3 deletions(-) create mode 100644 src/contracts/VYToken.d.ts create mode 100644 src/contracts/VYTokenProxy.d.ts create mode 100644 src/contracts/abis/VYToken.json create mode 100644 src/contracts/abis/VYTokenProxy.json create mode 100644 src/contracts/factories/VYTokenProxy__factory.ts create mode 100644 src/contracts/factories/VYToken__factory.ts diff --git a/src/config/contracts.ts b/src/config/contracts.ts index f74fa90f1..eb51a39f0 100644 --- a/src/config/contracts.ts +++ b/src/config/contracts.ts @@ -25,10 +25,10 @@ export const contractAddresses: ContractAddresses = { 1, new Map([ [ContractNames.CAULDRON, '0xc88191F8cb8e6D4a668B047c1C8503432c3Ca867'], - [ContractNames.VR_CAULDRON, '0xe9b81548704a0bf1ebe85ed504bc3e248ce15733'], + [ContractNames.VR_CAULDRON, '0xe199a0559516d8dd4739c978ad91ff1e6e228ecb'], [ContractNames.LADLE, '0x6cB18fF2A33e981D1e38A663Ca056c0a5265066A'], - [ContractNames.VR_LADLE, '0x3fa3116da426af606826eaf2e58344fbd56b6489'], - [ContractNames.VR_WITCH, '0xe7901efbfb59ef0c4831d06f77edc740ed98adc8'], + [ContractNames.VR_LADLE, '0x122ea911f1c2d78b67a77f95cae04dea10fee47b'], + [ContractNames.VR_WITCH, '0x556c5d86ab9497e2d12aa5bd2547f15bcb66065d'], [ContractNames.WITCH, '0x53C3760670f6091E1eC76B4dd27f73ba4CAd5061'], [ContractNames.WITCHV2, '0x08d2f5c96bb1f6be04b49bcd869d5af01db4c400'], [ContractNames.TRANSFER_1155_MODULE, '0x97f1d43A217aDD678bB6Dcd3C5D51F40b6729d06'], diff --git a/src/contracts/VYToken.d.ts b/src/contracts/VYToken.d.ts new file mode 100644 index 000000000..d4c484bb7 --- /dev/null +++ b/src/contracts/VYToken.d.ts @@ -0,0 +1,1911 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { + ethers, + EventFilter, + Signer, + BigNumber, + BigNumberish, + PopulatedTransaction, + BaseContract, + ContractTransaction, + Overrides, + PayableOverrides, + CallOverrides, +} from "ethers"; +import { BytesLike } from "@ethersproject/bytes"; +import { Listener, Provider } from "@ethersproject/providers"; +import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi"; +import type { TypedEventFilter, TypedEvent, TypedListener } from "./common"; + +interface VYTokenInterface extends ethers.utils.Interface { + functions: { + "DOMAIN_SEPARATOR()": FunctionFragment; + "LOCK()": FunctionFragment; + "LOCK8605463013()": FunctionFragment; + "PERMIT_TYPEHASH()": FunctionFragment; + "ROOT()": FunctionFragment; + "ROOT4146650865()": FunctionFragment; + "allowance(address,address)": FunctionFragment; + "approve(address,uint256)": FunctionFragment; + "balanceOf(address)": FunctionFragment; + "convertToPrincipal(uint256)": FunctionFragment; + "convertToUnderlying(uint256)": FunctionFragment; + "decimals()": FunctionFragment; + "deploymentChainId()": FunctionFragment; + "deposit(address,uint256)": FunctionFragment; + "flashFee(address,uint256)": FunctionFragment; + "flashFeeFactor()": FunctionFragment; + "flashLoan(address,address,uint256,bytes)": FunctionFragment; + "getRoleAdmin(bytes4)": FunctionFragment; + "grantRole(bytes4,address)": FunctionFragment; + "grantRoles(bytes4[],address)": FunctionFragment; + "hasRole(bytes4,address)": FunctionFragment; + "initialize(address)": FunctionFragment; + "initialized()": FunctionFragment; + "join()": FunctionFragment; + "lockRole(bytes4)": FunctionFragment; + "maxDeposit(address)": FunctionFragment; + "maxFlashLoan(address)": FunctionFragment; + "maxMint(address)": FunctionFragment; + "maxRedeem(address)": FunctionFragment; + "maxWithdraw(address)": FunctionFragment; + "mint(address,uint256)": FunctionFragment; + "name()": FunctionFragment; + "nonces(address)": FunctionFragment; + "oracle()": FunctionFragment; + "permit(address,address,uint256,uint256,uint8,bytes32,bytes32)": FunctionFragment; + "previewDeposit(uint256)": FunctionFragment; + "previewMint(uint256)": FunctionFragment; + "previewRedeem(uint256)": FunctionFragment; + "previewWithdraw(uint256)": FunctionFragment; + "proxiableUUID()": FunctionFragment; + "redeem(address,uint256)": FunctionFragment; + "renounceRole(bytes4,address)": FunctionFragment; + "revokeRole(bytes4,address)": FunctionFragment; + "revokeRoles(bytes4[],address)": FunctionFragment; + "setFlashFeeFactor(uint256)": FunctionFragment; + "setRoleAdmin(bytes4,bytes4)": FunctionFragment; + "symbol()": FunctionFragment; + "totalSupply()": FunctionFragment; + "transfer(address,uint256)": FunctionFragment; + "transferFrom(address,address,uint256)": FunctionFragment; + "underlying()": FunctionFragment; + "underlyingId()": FunctionFragment; + "upgradeTo(address)": FunctionFragment; + "upgradeToAndCall(address,bytes)": FunctionFragment; + "version()": FunctionFragment; + "withdraw(uint256,address,address)": FunctionFragment; + }; + + encodeFunctionData( + functionFragment: "DOMAIN_SEPARATOR", + values?: undefined + ): string; + encodeFunctionData(functionFragment: "LOCK", values?: undefined): string; + encodeFunctionData( + functionFragment: "LOCK8605463013", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "PERMIT_TYPEHASH", + values?: undefined + ): string; + encodeFunctionData(functionFragment: "ROOT", values?: undefined): string; + encodeFunctionData( + functionFragment: "ROOT4146650865", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "allowance", + values: [string, string] + ): string; + encodeFunctionData( + functionFragment: "approve", + values: [string, BigNumberish] + ): string; + encodeFunctionData(functionFragment: "balanceOf", values: [string]): string; + encodeFunctionData( + functionFragment: "convertToPrincipal", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "convertToUnderlying", + values: [BigNumberish] + ): string; + encodeFunctionData(functionFragment: "decimals", values?: undefined): string; + encodeFunctionData( + functionFragment: "deploymentChainId", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "deposit", + values: [string, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "flashFee", + values: [string, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "flashFeeFactor", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "flashLoan", + values: [string, string, BigNumberish, BytesLike] + ): string; + encodeFunctionData( + functionFragment: "getRoleAdmin", + values: [BytesLike] + ): string; + encodeFunctionData( + functionFragment: "grantRole", + values: [BytesLike, string] + ): string; + encodeFunctionData( + functionFragment: "grantRoles", + values: [BytesLike[], string] + ): string; + encodeFunctionData( + functionFragment: "hasRole", + values: [BytesLike, string] + ): string; + encodeFunctionData(functionFragment: "initialize", values: [string]): string; + encodeFunctionData( + functionFragment: "initialized", + values?: undefined + ): string; + encodeFunctionData(functionFragment: "join", values?: undefined): string; + encodeFunctionData(functionFragment: "lockRole", values: [BytesLike]): string; + encodeFunctionData(functionFragment: "maxDeposit", values: [string]): string; + encodeFunctionData( + functionFragment: "maxFlashLoan", + values: [string] + ): string; + encodeFunctionData(functionFragment: "maxMint", values: [string]): string; + encodeFunctionData(functionFragment: "maxRedeem", values: [string]): string; + encodeFunctionData(functionFragment: "maxWithdraw", values: [string]): string; + encodeFunctionData( + functionFragment: "mint", + values: [string, BigNumberish] + ): string; + encodeFunctionData(functionFragment: "name", values?: undefined): string; + encodeFunctionData(functionFragment: "nonces", values: [string]): string; + encodeFunctionData(functionFragment: "oracle", values?: undefined): string; + encodeFunctionData( + functionFragment: "permit", + values: [ + string, + string, + BigNumberish, + BigNumberish, + BigNumberish, + BytesLike, + BytesLike + ] + ): string; + encodeFunctionData( + functionFragment: "previewDeposit", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "previewMint", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "previewRedeem", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "previewWithdraw", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "proxiableUUID", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "redeem", + values: [string, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "renounceRole", + values: [BytesLike, string] + ): string; + encodeFunctionData( + functionFragment: "revokeRole", + values: [BytesLike, string] + ): string; + encodeFunctionData( + functionFragment: "revokeRoles", + values: [BytesLike[], string] + ): string; + encodeFunctionData( + functionFragment: "setFlashFeeFactor", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "setRoleAdmin", + values: [BytesLike, BytesLike] + ): string; + encodeFunctionData(functionFragment: "symbol", values?: undefined): string; + encodeFunctionData( + functionFragment: "totalSupply", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "transfer", + values: [string, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "transferFrom", + values: [string, string, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "underlying", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "underlyingId", + values?: undefined + ): string; + encodeFunctionData(functionFragment: "upgradeTo", values: [string]): string; + encodeFunctionData( + functionFragment: "upgradeToAndCall", + values: [string, BytesLike] + ): string; + encodeFunctionData(functionFragment: "version", values?: undefined): string; + encodeFunctionData( + functionFragment: "withdraw", + values: [BigNumberish, string, string] + ): string; + + decodeFunctionResult( + functionFragment: "DOMAIN_SEPARATOR", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "LOCK", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "LOCK8605463013", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "PERMIT_TYPEHASH", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "ROOT", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "ROOT4146650865", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "allowance", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "approve", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "balanceOf", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "convertToPrincipal", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "convertToUnderlying", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "decimals", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "deploymentChainId", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "deposit", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "flashFee", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "flashFeeFactor", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "flashLoan", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "getRoleAdmin", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "grantRole", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "grantRoles", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "hasRole", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "initialize", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "initialized", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "join", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "lockRole", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "maxDeposit", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "maxFlashLoan", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "maxMint", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "maxRedeem", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "maxWithdraw", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "mint", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "name", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "nonces", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "oracle", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "permit", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "previewDeposit", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "previewMint", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "previewRedeem", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "previewWithdraw", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "proxiableUUID", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "redeem", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "renounceRole", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "revokeRole", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "revokeRoles", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "setFlashFeeFactor", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "setRoleAdmin", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "symbol", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "totalSupply", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "transfer", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "transferFrom", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "underlying", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "underlyingId", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "upgradeTo", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "upgradeToAndCall", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "version", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "withdraw", data: BytesLike): Result; + + events: { + "AdminChanged(address,address)": EventFragment; + "Approval(address,address,uint256)": EventFragment; + "BeaconUpgraded(address)": EventFragment; + "FlashFeeFactorSet(uint256)": EventFragment; + "Point(bytes32,address)": EventFragment; + "Redeemed(address,address,uint256,uint256)": EventFragment; + "RoleAdminChanged(bytes4,bytes4)": EventFragment; + "RoleGranted(bytes4,address,address)": EventFragment; + "RoleRevoked(bytes4,address,address)": EventFragment; + "Transfer(address,address,uint256)": EventFragment; + "Upgraded(address)": EventFragment; + }; + + getEvent(nameOrSignatureOrTopic: "AdminChanged"): EventFragment; + getEvent(nameOrSignatureOrTopic: "Approval"): EventFragment; + getEvent(nameOrSignatureOrTopic: "BeaconUpgraded"): EventFragment; + getEvent(nameOrSignatureOrTopic: "FlashFeeFactorSet"): EventFragment; + getEvent(nameOrSignatureOrTopic: "Point"): EventFragment; + getEvent(nameOrSignatureOrTopic: "Redeemed"): EventFragment; + getEvent(nameOrSignatureOrTopic: "RoleAdminChanged"): EventFragment; + getEvent(nameOrSignatureOrTopic: "RoleGranted"): EventFragment; + getEvent(nameOrSignatureOrTopic: "RoleRevoked"): EventFragment; + getEvent(nameOrSignatureOrTopic: "Transfer"): EventFragment; + getEvent(nameOrSignatureOrTopic: "Upgraded"): EventFragment; +} + +export type AdminChangedEvent = TypedEvent< + [string, string] & { previousAdmin: string; newAdmin: string } +>; + +export type ApprovalEvent = TypedEvent< + [string, string, BigNumber] & { + owner: string; + spender: string; + value: BigNumber; + } +>; + +export type BeaconUpgradedEvent = TypedEvent<[string] & { beacon: string }>; + +export type FlashFeeFactorSetEvent = TypedEvent< + [BigNumber] & { fee: BigNumber } +>; + +export type PointEvent = TypedEvent< + [string, string] & { param: string; value: string } +>; + +export type RedeemedEvent = TypedEvent< + [string, string, BigNumber, BigNumber] & { + holder: string; + receiver: string; + principalAmount: BigNumber; + underlyingAmount: BigNumber; + } +>; + +export type RoleAdminChangedEvent = TypedEvent< + [string, string] & { role: string; newAdminRole: string } +>; + +export type RoleGrantedEvent = TypedEvent< + [string, string, string] & { role: string; account: string; sender: string } +>; + +export type RoleRevokedEvent = TypedEvent< + [string, string, string] & { role: string; account: string; sender: string } +>; + +export type TransferEvent = TypedEvent< + [string, string, BigNumber] & { from: string; to: string; value: BigNumber } +>; + +export type UpgradedEvent = TypedEvent<[string] & { implementation: string }>; + +export class VYToken extends BaseContract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + listeners, EventArgsObject>( + eventFilter?: TypedEventFilter + ): Array>; + off, EventArgsObject>( + eventFilter: TypedEventFilter, + listener: TypedListener + ): this; + on, EventArgsObject>( + eventFilter: TypedEventFilter, + listener: TypedListener + ): this; + once, EventArgsObject>( + eventFilter: TypedEventFilter, + listener: TypedListener + ): this; + removeListener, EventArgsObject>( + eventFilter: TypedEventFilter, + listener: TypedListener + ): this; + removeAllListeners, EventArgsObject>( + eventFilter: TypedEventFilter + ): this; + + listeners(eventName?: string): Array; + off(eventName: string, listener: Listener): this; + on(eventName: string, listener: Listener): this; + once(eventName: string, listener: Listener): this; + removeListener(eventName: string, listener: Listener): this; + removeAllListeners(eventName?: string): this; + + queryFilter, EventArgsObject>( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + + interface: VYTokenInterface; + + functions: { + DOMAIN_SEPARATOR(overrides?: CallOverrides): Promise<[string]>; + + LOCK(overrides?: CallOverrides): Promise<[string]>; + + LOCK8605463013(overrides?: CallOverrides): Promise<[string]>; + + PERMIT_TYPEHASH(overrides?: CallOverrides): Promise<[string]>; + + ROOT(overrides?: CallOverrides): Promise<[string]>; + + ROOT4146650865(overrides?: CallOverrides): Promise<[string]>; + + allowance( + owner: string, + spender: string, + overrides?: CallOverrides + ): Promise<[BigNumber]>; + + approve( + spender: string, + wad: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + balanceOf(guy: string, overrides?: CallOverrides): Promise<[BigNumber]>; + + convertToPrincipal( + underlyingAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + convertToUnderlying( + principalAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + decimals(overrides?: CallOverrides): Promise<[number]>; + + deploymentChainId(overrides?: CallOverrides): Promise<[BigNumber]>; + + deposit( + receiver: string, + underlyingAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + flashFee( + token: string, + principalAmount: BigNumberish, + overrides?: CallOverrides + ): Promise<[BigNumber]>; + + flashFeeFactor(overrides?: CallOverrides): Promise<[BigNumber]>; + + flashLoan( + receiver: string, + token: string, + principalAmount: BigNumberish, + data: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + getRoleAdmin(role: BytesLike, overrides?: CallOverrides): Promise<[string]>; + + grantRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + grantRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise<[boolean]>; + + initialize( + root_: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + initialized(overrides?: CallOverrides): Promise<[boolean]>; + + join(overrides?: CallOverrides): Promise<[string]>; + + lockRole( + role: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + maxDeposit( + arg0: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + maxFlashLoan( + token: string, + overrides?: CallOverrides + ): Promise<[BigNumber]>; + + maxMint( + arg0: string, + overrides?: CallOverrides + ): Promise<[BigNumber] & { maxPrincipalAmount: BigNumber }>; + + maxRedeem( + holder: string, + overrides?: CallOverrides + ): Promise<[BigNumber] & { maxPrincipalAmount: BigNumber }>; + + maxWithdraw( + holder: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + mint( + receiver: string, + principalAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + name(overrides?: CallOverrides): Promise<[string]>; + + nonces(arg0: string, overrides?: CallOverrides): Promise<[BigNumber]>; + + oracle(overrides?: CallOverrides): Promise<[string]>; + + permit( + owner: string, + spender: string, + amount: BigNumberish, + deadline: BigNumberish, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + previewDeposit( + underlyingAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + previewMint( + principalAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + previewRedeem( + principalAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + previewWithdraw( + underlyingAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + proxiableUUID(overrides?: CallOverrides): Promise<[string]>; + + "redeem(address,uint256)"( + receiver: string, + principalAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + "redeem(uint256,address,address)"( + principalAmount: BigNumberish, + receiver: string, + holder: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + renounceRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setFlashFeeFactor( + flashFeeFactor_: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setRoleAdmin( + role: BytesLike, + adminRole: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + symbol(overrides?: CallOverrides): Promise<[string]>; + + totalSupply(overrides?: CallOverrides): Promise<[BigNumber]>; + + transfer( + dst: string, + wad: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + transferFrom( + src: string, + dst: string, + wad: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + underlying(overrides?: CallOverrides): Promise<[string]>; + + underlyingId(overrides?: CallOverrides): Promise<[string]>; + + upgradeTo( + newImplementation: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + upgradeToAndCall( + newImplementation: string, + data: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + version(overrides?: CallOverrides): Promise<[string]>; + + withdraw( + underlyingAmount: BigNumberish, + receiver: string, + holder: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + }; + + DOMAIN_SEPARATOR(overrides?: CallOverrides): Promise; + + LOCK(overrides?: CallOverrides): Promise; + + LOCK8605463013(overrides?: CallOverrides): Promise; + + PERMIT_TYPEHASH(overrides?: CallOverrides): Promise; + + ROOT(overrides?: CallOverrides): Promise; + + ROOT4146650865(overrides?: CallOverrides): Promise; + + allowance( + owner: string, + spender: string, + overrides?: CallOverrides + ): Promise; + + approve( + spender: string, + wad: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + balanceOf(guy: string, overrides?: CallOverrides): Promise; + + convertToPrincipal( + underlyingAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + convertToUnderlying( + principalAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + decimals(overrides?: CallOverrides): Promise; + + deploymentChainId(overrides?: CallOverrides): Promise; + + deposit( + receiver: string, + underlyingAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + flashFee( + token: string, + principalAmount: BigNumberish, + overrides?: CallOverrides + ): Promise; + + flashFeeFactor(overrides?: CallOverrides): Promise; + + flashLoan( + receiver: string, + token: string, + principalAmount: BigNumberish, + data: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + getRoleAdmin(role: BytesLike, overrides?: CallOverrides): Promise; + + grantRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + grantRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + initialize( + root_: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + initialized(overrides?: CallOverrides): Promise; + + join(overrides?: CallOverrides): Promise; + + lockRole( + role: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + maxDeposit( + arg0: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + maxFlashLoan(token: string, overrides?: CallOverrides): Promise; + + maxMint(arg0: string, overrides?: CallOverrides): Promise; + + maxRedeem(holder: string, overrides?: CallOverrides): Promise; + + maxWithdraw( + holder: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + mint( + receiver: string, + principalAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + name(overrides?: CallOverrides): Promise; + + nonces(arg0: string, overrides?: CallOverrides): Promise; + + oracle(overrides?: CallOverrides): Promise; + + permit( + owner: string, + spender: string, + amount: BigNumberish, + deadline: BigNumberish, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + previewDeposit( + underlyingAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + previewMint( + principalAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + previewRedeem( + principalAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + previewWithdraw( + underlyingAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + proxiableUUID(overrides?: CallOverrides): Promise; + + "redeem(address,uint256)"( + receiver: string, + principalAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + "redeem(uint256,address,address)"( + principalAmount: BigNumberish, + receiver: string, + holder: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + renounceRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setFlashFeeFactor( + flashFeeFactor_: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setRoleAdmin( + role: BytesLike, + adminRole: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + symbol(overrides?: CallOverrides): Promise; + + totalSupply(overrides?: CallOverrides): Promise; + + transfer( + dst: string, + wad: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + transferFrom( + src: string, + dst: string, + wad: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + underlying(overrides?: CallOverrides): Promise; + + underlyingId(overrides?: CallOverrides): Promise; + + upgradeTo( + newImplementation: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + upgradeToAndCall( + newImplementation: string, + data: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + version(overrides?: CallOverrides): Promise; + + withdraw( + underlyingAmount: BigNumberish, + receiver: string, + holder: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + callStatic: { + DOMAIN_SEPARATOR(overrides?: CallOverrides): Promise; + + LOCK(overrides?: CallOverrides): Promise; + + LOCK8605463013(overrides?: CallOverrides): Promise; + + PERMIT_TYPEHASH(overrides?: CallOverrides): Promise; + + ROOT(overrides?: CallOverrides): Promise; + + ROOT4146650865(overrides?: CallOverrides): Promise; + + allowance( + owner: string, + spender: string, + overrides?: CallOverrides + ): Promise; + + approve( + spender: string, + wad: BigNumberish, + overrides?: CallOverrides + ): Promise; + + balanceOf(guy: string, overrides?: CallOverrides): Promise; + + convertToPrincipal( + underlyingAmount: BigNumberish, + overrides?: CallOverrides + ): Promise; + + convertToUnderlying( + principalAmount: BigNumberish, + overrides?: CallOverrides + ): Promise; + + decimals(overrides?: CallOverrides): Promise; + + deploymentChainId(overrides?: CallOverrides): Promise; + + deposit( + receiver: string, + underlyingAmount: BigNumberish, + overrides?: CallOverrides + ): Promise; + + flashFee( + token: string, + principalAmount: BigNumberish, + overrides?: CallOverrides + ): Promise; + + flashFeeFactor(overrides?: CallOverrides): Promise; + + flashLoan( + receiver: string, + token: string, + principalAmount: BigNumberish, + data: BytesLike, + overrides?: CallOverrides + ): Promise; + + getRoleAdmin(role: BytesLike, overrides?: CallOverrides): Promise; + + grantRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + grantRoles( + roles: BytesLike[], + account: string, + overrides?: CallOverrides + ): Promise; + + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + initialize(root_: string, overrides?: CallOverrides): Promise; + + initialized(overrides?: CallOverrides): Promise; + + join(overrides?: CallOverrides): Promise; + + lockRole(role: BytesLike, overrides?: CallOverrides): Promise; + + maxDeposit(arg0: string, overrides?: CallOverrides): Promise; + + maxFlashLoan(token: string, overrides?: CallOverrides): Promise; + + maxMint(arg0: string, overrides?: CallOverrides): Promise; + + maxRedeem(holder: string, overrides?: CallOverrides): Promise; + + maxWithdraw(holder: string, overrides?: CallOverrides): Promise; + + mint( + receiver: string, + principalAmount: BigNumberish, + overrides?: CallOverrides + ): Promise; + + name(overrides?: CallOverrides): Promise; + + nonces(arg0: string, overrides?: CallOverrides): Promise; + + oracle(overrides?: CallOverrides): Promise; + + permit( + owner: string, + spender: string, + amount: BigNumberish, + deadline: BigNumberish, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: CallOverrides + ): Promise; + + previewDeposit( + underlyingAmount: BigNumberish, + overrides?: CallOverrides + ): Promise; + + previewMint( + principalAmount: BigNumberish, + overrides?: CallOverrides + ): Promise; + + previewRedeem( + principalAmount: BigNumberish, + overrides?: CallOverrides + ): Promise; + + previewWithdraw( + underlyingAmount: BigNumberish, + overrides?: CallOverrides + ): Promise; + + proxiableUUID(overrides?: CallOverrides): Promise; + + "redeem(address,uint256)"( + receiver: string, + principalAmount: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "redeem(uint256,address,address)"( + principalAmount: BigNumberish, + receiver: string, + holder: string, + overrides?: CallOverrides + ): Promise; + + renounceRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + revokeRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + revokeRoles( + roles: BytesLike[], + account: string, + overrides?: CallOverrides + ): Promise; + + setFlashFeeFactor( + flashFeeFactor_: BigNumberish, + overrides?: CallOverrides + ): Promise; + + setRoleAdmin( + role: BytesLike, + adminRole: BytesLike, + overrides?: CallOverrides + ): Promise; + + symbol(overrides?: CallOverrides): Promise; + + totalSupply(overrides?: CallOverrides): Promise; + + transfer( + dst: string, + wad: BigNumberish, + overrides?: CallOverrides + ): Promise; + + transferFrom( + src: string, + dst: string, + wad: BigNumberish, + overrides?: CallOverrides + ): Promise; + + underlying(overrides?: CallOverrides): Promise; + + underlyingId(overrides?: CallOverrides): Promise; + + upgradeTo( + newImplementation: string, + overrides?: CallOverrides + ): Promise; + + upgradeToAndCall( + newImplementation: string, + data: BytesLike, + overrides?: CallOverrides + ): Promise; + + version(overrides?: CallOverrides): Promise; + + withdraw( + underlyingAmount: BigNumberish, + receiver: string, + holder: string, + overrides?: CallOverrides + ): Promise; + }; + + filters: { + "AdminChanged(address,address)"( + previousAdmin?: null, + newAdmin?: null + ): TypedEventFilter< + [string, string], + { previousAdmin: string; newAdmin: string } + >; + + AdminChanged( + previousAdmin?: null, + newAdmin?: null + ): TypedEventFilter< + [string, string], + { previousAdmin: string; newAdmin: string } + >; + + "Approval(address,address,uint256)"( + owner?: string | null, + spender?: string | null, + value?: null + ): TypedEventFilter< + [string, string, BigNumber], + { owner: string; spender: string; value: BigNumber } + >; + + Approval( + owner?: string | null, + spender?: string | null, + value?: null + ): TypedEventFilter< + [string, string, BigNumber], + { owner: string; spender: string; value: BigNumber } + >; + + "BeaconUpgraded(address)"( + beacon?: string | null + ): TypedEventFilter<[string], { beacon: string }>; + + BeaconUpgraded( + beacon?: string | null + ): TypedEventFilter<[string], { beacon: string }>; + + "FlashFeeFactorSet(uint256)"( + fee?: BigNumberish | null + ): TypedEventFilter<[BigNumber], { fee: BigNumber }>; + + FlashFeeFactorSet( + fee?: BigNumberish | null + ): TypedEventFilter<[BigNumber], { fee: BigNumber }>; + + "Point(bytes32,address)"( + param?: BytesLike | null, + value?: null + ): TypedEventFilter<[string, string], { param: string; value: string }>; + + Point( + param?: BytesLike | null, + value?: null + ): TypedEventFilter<[string, string], { param: string; value: string }>; + + "Redeemed(address,address,uint256,uint256)"( + holder?: string | null, + receiver?: string | null, + principalAmount?: null, + underlyingAmount?: null + ): TypedEventFilter< + [string, string, BigNumber, BigNumber], + { + holder: string; + receiver: string; + principalAmount: BigNumber; + underlyingAmount: BigNumber; + } + >; + + Redeemed( + holder?: string | null, + receiver?: string | null, + principalAmount?: null, + underlyingAmount?: null + ): TypedEventFilter< + [string, string, BigNumber, BigNumber], + { + holder: string; + receiver: string; + principalAmount: BigNumber; + underlyingAmount: BigNumber; + } + >; + + "RoleAdminChanged(bytes4,bytes4)"( + role?: BytesLike | null, + newAdminRole?: BytesLike | null + ): TypedEventFilter< + [string, string], + { role: string; newAdminRole: string } + >; + + RoleAdminChanged( + role?: BytesLike | null, + newAdminRole?: BytesLike | null + ): TypedEventFilter< + [string, string], + { role: string; newAdminRole: string } + >; + + "RoleGranted(bytes4,address,address)"( + role?: BytesLike | null, + account?: string | null, + sender?: string | null + ): TypedEventFilter< + [string, string, string], + { role: string; account: string; sender: string } + >; + + RoleGranted( + role?: BytesLike | null, + account?: string | null, + sender?: string | null + ): TypedEventFilter< + [string, string, string], + { role: string; account: string; sender: string } + >; + + "RoleRevoked(bytes4,address,address)"( + role?: BytesLike | null, + account?: string | null, + sender?: string | null + ): TypedEventFilter< + [string, string, string], + { role: string; account: string; sender: string } + >; + + RoleRevoked( + role?: BytesLike | null, + account?: string | null, + sender?: string | null + ): TypedEventFilter< + [string, string, string], + { role: string; account: string; sender: string } + >; + + "Transfer(address,address,uint256)"( + from?: string | null, + to?: string | null, + value?: null + ): TypedEventFilter< + [string, string, BigNumber], + { from: string; to: string; value: BigNumber } + >; + + Transfer( + from?: string | null, + to?: string | null, + value?: null + ): TypedEventFilter< + [string, string, BigNumber], + { from: string; to: string; value: BigNumber } + >; + + "Upgraded(address)"( + implementation?: string | null + ): TypedEventFilter<[string], { implementation: string }>; + + Upgraded( + implementation?: string | null + ): TypedEventFilter<[string], { implementation: string }>; + }; + + estimateGas: { + DOMAIN_SEPARATOR(overrides?: CallOverrides): Promise; + + LOCK(overrides?: CallOverrides): Promise; + + LOCK8605463013(overrides?: CallOverrides): Promise; + + PERMIT_TYPEHASH(overrides?: CallOverrides): Promise; + + ROOT(overrides?: CallOverrides): Promise; + + ROOT4146650865(overrides?: CallOverrides): Promise; + + allowance( + owner: string, + spender: string, + overrides?: CallOverrides + ): Promise; + + approve( + spender: string, + wad: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + balanceOf(guy: string, overrides?: CallOverrides): Promise; + + convertToPrincipal( + underlyingAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + convertToUnderlying( + principalAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + decimals(overrides?: CallOverrides): Promise; + + deploymentChainId(overrides?: CallOverrides): Promise; + + deposit( + receiver: string, + underlyingAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + flashFee( + token: string, + principalAmount: BigNumberish, + overrides?: CallOverrides + ): Promise; + + flashFeeFactor(overrides?: CallOverrides): Promise; + + flashLoan( + receiver: string, + token: string, + principalAmount: BigNumberish, + data: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + getRoleAdmin( + role: BytesLike, + overrides?: CallOverrides + ): Promise; + + grantRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + grantRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + initialize( + root_: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + initialized(overrides?: CallOverrides): Promise; + + join(overrides?: CallOverrides): Promise; + + lockRole( + role: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + maxDeposit( + arg0: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + maxFlashLoan(token: string, overrides?: CallOverrides): Promise; + + maxMint(arg0: string, overrides?: CallOverrides): Promise; + + maxRedeem(holder: string, overrides?: CallOverrides): Promise; + + maxWithdraw( + holder: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + mint( + receiver: string, + principalAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + name(overrides?: CallOverrides): Promise; + + nonces(arg0: string, overrides?: CallOverrides): Promise; + + oracle(overrides?: CallOverrides): Promise; + + permit( + owner: string, + spender: string, + amount: BigNumberish, + deadline: BigNumberish, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + previewDeposit( + underlyingAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + previewMint( + principalAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + previewRedeem( + principalAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + previewWithdraw( + underlyingAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + proxiableUUID(overrides?: CallOverrides): Promise; + + "redeem(address,uint256)"( + receiver: string, + principalAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + "redeem(uint256,address,address)"( + principalAmount: BigNumberish, + receiver: string, + holder: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + renounceRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setFlashFeeFactor( + flashFeeFactor_: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setRoleAdmin( + role: BytesLike, + adminRole: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + symbol(overrides?: CallOverrides): Promise; + + totalSupply(overrides?: CallOverrides): Promise; + + transfer( + dst: string, + wad: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + transferFrom( + src: string, + dst: string, + wad: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + underlying(overrides?: CallOverrides): Promise; + + underlyingId(overrides?: CallOverrides): Promise; + + upgradeTo( + newImplementation: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + upgradeToAndCall( + newImplementation: string, + data: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + version(overrides?: CallOverrides): Promise; + + withdraw( + underlyingAmount: BigNumberish, + receiver: string, + holder: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + }; + + populateTransaction: { + DOMAIN_SEPARATOR(overrides?: CallOverrides): Promise; + + LOCK(overrides?: CallOverrides): Promise; + + LOCK8605463013(overrides?: CallOverrides): Promise; + + PERMIT_TYPEHASH(overrides?: CallOverrides): Promise; + + ROOT(overrides?: CallOverrides): Promise; + + ROOT4146650865(overrides?: CallOverrides): Promise; + + allowance( + owner: string, + spender: string, + overrides?: CallOverrides + ): Promise; + + approve( + spender: string, + wad: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + balanceOf( + guy: string, + overrides?: CallOverrides + ): Promise; + + convertToPrincipal( + underlyingAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + convertToUnderlying( + principalAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + decimals(overrides?: CallOverrides): Promise; + + deploymentChainId(overrides?: CallOverrides): Promise; + + deposit( + receiver: string, + underlyingAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + flashFee( + token: string, + principalAmount: BigNumberish, + overrides?: CallOverrides + ): Promise; + + flashFeeFactor(overrides?: CallOverrides): Promise; + + flashLoan( + receiver: string, + token: string, + principalAmount: BigNumberish, + data: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + getRoleAdmin( + role: BytesLike, + overrides?: CallOverrides + ): Promise; + + grantRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + grantRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + initialize( + root_: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + initialized(overrides?: CallOverrides): Promise; + + join(overrides?: CallOverrides): Promise; + + lockRole( + role: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + maxDeposit( + arg0: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + maxFlashLoan( + token: string, + overrides?: CallOverrides + ): Promise; + + maxMint( + arg0: string, + overrides?: CallOverrides + ): Promise; + + maxRedeem( + holder: string, + overrides?: CallOverrides + ): Promise; + + maxWithdraw( + holder: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + mint( + receiver: string, + principalAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + name(overrides?: CallOverrides): Promise; + + nonces( + arg0: string, + overrides?: CallOverrides + ): Promise; + + oracle(overrides?: CallOverrides): Promise; + + permit( + owner: string, + spender: string, + amount: BigNumberish, + deadline: BigNumberish, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + previewDeposit( + underlyingAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + previewMint( + principalAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + previewRedeem( + principalAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + previewWithdraw( + underlyingAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + proxiableUUID(overrides?: CallOverrides): Promise; + + "redeem(address,uint256)"( + receiver: string, + principalAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + "redeem(uint256,address,address)"( + principalAmount: BigNumberish, + receiver: string, + holder: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + renounceRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + revokeRoles( + roles: BytesLike[], + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setFlashFeeFactor( + flashFeeFactor_: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setRoleAdmin( + role: BytesLike, + adminRole: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + symbol(overrides?: CallOverrides): Promise; + + totalSupply(overrides?: CallOverrides): Promise; + + transfer( + dst: string, + wad: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + transferFrom( + src: string, + dst: string, + wad: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + underlying(overrides?: CallOverrides): Promise; + + underlyingId(overrides?: CallOverrides): Promise; + + upgradeTo( + newImplementation: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + upgradeToAndCall( + newImplementation: string, + data: BytesLike, + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + version(overrides?: CallOverrides): Promise; + + withdraw( + underlyingAmount: BigNumberish, + receiver: string, + holder: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + }; +} diff --git a/src/contracts/VYTokenProxy.d.ts b/src/contracts/VYTokenProxy.d.ts new file mode 100644 index 000000000..4ea3bb5d2 --- /dev/null +++ b/src/contracts/VYTokenProxy.d.ts @@ -0,0 +1,126 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { + ethers, + EventFilter, + Signer, + BigNumber, + BigNumberish, + PopulatedTransaction, + BaseContract, + ContractTransaction, +} from "ethers"; +import { BytesLike } from "@ethersproject/bytes"; +import { Listener, Provider } from "@ethersproject/providers"; +import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi"; +import type { TypedEventFilter, TypedEvent, TypedListener } from "./common"; + +interface VYTokenProxyInterface extends ethers.utils.Interface { + functions: {}; + + events: { + "AdminChanged(address,address)": EventFragment; + "BeaconUpgraded(address)": EventFragment; + "Upgraded(address)": EventFragment; + }; + + getEvent(nameOrSignatureOrTopic: "AdminChanged"): EventFragment; + getEvent(nameOrSignatureOrTopic: "BeaconUpgraded"): EventFragment; + getEvent(nameOrSignatureOrTopic: "Upgraded"): EventFragment; +} + +export type AdminChangedEvent = TypedEvent< + [string, string] & { previousAdmin: string; newAdmin: string } +>; + +export type BeaconUpgradedEvent = TypedEvent<[string] & { beacon: string }>; + +export type UpgradedEvent = TypedEvent<[string] & { implementation: string }>; + +export class VYTokenProxy extends BaseContract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + listeners, EventArgsObject>( + eventFilter?: TypedEventFilter + ): Array>; + off, EventArgsObject>( + eventFilter: TypedEventFilter, + listener: TypedListener + ): this; + on, EventArgsObject>( + eventFilter: TypedEventFilter, + listener: TypedListener + ): this; + once, EventArgsObject>( + eventFilter: TypedEventFilter, + listener: TypedListener + ): this; + removeListener, EventArgsObject>( + eventFilter: TypedEventFilter, + listener: TypedListener + ): this; + removeAllListeners, EventArgsObject>( + eventFilter: TypedEventFilter + ): this; + + listeners(eventName?: string): Array; + off(eventName: string, listener: Listener): this; + on(eventName: string, listener: Listener): this; + once(eventName: string, listener: Listener): this; + removeListener(eventName: string, listener: Listener): this; + removeAllListeners(eventName?: string): this; + + queryFilter, EventArgsObject>( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + + interface: VYTokenProxyInterface; + + functions: {}; + + callStatic: {}; + + filters: { + "AdminChanged(address,address)"( + previousAdmin?: null, + newAdmin?: null + ): TypedEventFilter< + [string, string], + { previousAdmin: string; newAdmin: string } + >; + + AdminChanged( + previousAdmin?: null, + newAdmin?: null + ): TypedEventFilter< + [string, string], + { previousAdmin: string; newAdmin: string } + >; + + "BeaconUpgraded(address)"( + beacon?: string | null + ): TypedEventFilter<[string], { beacon: string }>; + + BeaconUpgraded( + beacon?: string | null + ): TypedEventFilter<[string], { beacon: string }>; + + "Upgraded(address)"( + implementation?: string | null + ): TypedEventFilter<[string], { implementation: string }>; + + Upgraded( + implementation?: string | null + ): TypedEventFilter<[string], { implementation: string }>; + }; + + estimateGas: {}; + + populateTransaction: {}; +} diff --git a/src/contracts/abis/VYToken.json b/src/contracts/abis/VYToken.json new file mode 100644 index 000000000..7b6eed3ab --- /dev/null +++ b/src/contracts/abis/VYToken.json @@ -0,0 +1,578 @@ +[ + { + "inputs": [ + { "internalType": "bytes6", "name": "underlyingId_", "type": "bytes6" }, + { "internalType": "contract IOracle", "name": "oracle_", "type": "address" }, + { "internalType": "contract IJoin", "name": "join_", "type": "address" }, + { "internalType": "string", "name": "name", "type": "string" }, + { "internalType": "string", "name": "symbol", "type": "string" } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "internalType": "address", "name": "previousAdmin", "type": "address" }, + { "indexed": false, "internalType": "address", "name": "newAdmin", "type": "address" } + ], + "name": "AdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "owner", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "spender", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": true, "internalType": "address", "name": "beacon", "type": "address" }], + "name": "BeaconUpgraded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": true, "internalType": "uint256", "name": "fee", "type": "uint256" }], + "name": "FlashFeeFactorSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes32", "name": "param", "type": "bytes32" }, + { "indexed": false, "internalType": "address", "name": "value", "type": "address" } + ], + "name": "Point", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "holder", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "receiver", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "principalAmount", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "underlyingAmount", "type": "uint256" } + ], + "name": "Redeemed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "indexed": true, "internalType": "bytes4", "name": "newAdminRole", "type": "bytes4" } + ], + "name": "RoleAdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "indexed": true, "internalType": "address", "name": "account", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "sender", "type": "address" } + ], + "name": "RoleGranted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "indexed": true, "internalType": "address", "name": "account", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "sender", "type": "address" } + ], + "name": "RoleRevoked", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "from", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": true, "internalType": "address", "name": "implementation", "type": "address" }], + "name": "Upgraded", + "type": "event" + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "LOCK", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "LOCK8605463013", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "PERMIT_TYPEHASH", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ROOT", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ROOT4146650865", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" } + ], + "name": "allowance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "wad", "type": "uint256" } + ], + "name": "approve", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "guy", "type": "address" }], + "name": "balanceOf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "underlyingAmount", "type": "uint256" }], + "name": "convertToPrincipal", + "outputs": [{ "internalType": "uint256", "name": "principalAmount", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "principalAmount", "type": "uint256" }], + "name": "convertToUnderlying", + "outputs": [{ "internalType": "uint256", "name": "underlyingAmount", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "deploymentChainId", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "receiver", "type": "address" }, + { "internalType": "uint256", "name": "underlyingAmount", "type": "uint256" } + ], + "name": "deposit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "token", "type": "address" }, + { "internalType": "uint256", "name": "principalAmount", "type": "uint256" } + ], + "name": "flashFee", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "flashFeeFactor", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IERC3156FlashBorrower", "name": "receiver", "type": "address" }, + { "internalType": "address", "name": "token", "type": "address" }, + { "internalType": "uint256", "name": "principalAmount", "type": "uint256" }, + { "internalType": "bytes", "name": "data", "type": "bytes" } + ], + "name": "flashLoan", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes4", "name": "role", "type": "bytes4" }], + "name": "getRoleAdmin", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "grantRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4[]", "name": "roles", "type": "bytes4[]" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "grantRoles", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "hasRole", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "root_", "type": "address" }], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "initialized", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "join", + "outputs": [{ "internalType": "contract IJoin", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes4", "name": "role", "type": "bytes4" }], + "name": "lockRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "maxDeposit", + "outputs": [{ "internalType": "uint256", "name": "maxUnderlyingAmount", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "token", "type": "address" }], + "name": "maxFlashLoan", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "maxMint", + "outputs": [{ "internalType": "uint256", "name": "maxPrincipalAmount", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "holder", "type": "address" }], + "name": "maxRedeem", + "outputs": [{ "internalType": "uint256", "name": "maxPrincipalAmount", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "holder", "type": "address" }], + "name": "maxWithdraw", + "outputs": [{ "internalType": "uint256", "name": "maxUnderlyingAmount", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "receiver", "type": "address" }, + { "internalType": "uint256", "name": "principalAmount", "type": "uint256" } + ], + "name": "mint", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "nonces", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "oracle", + "outputs": [{ "internalType": "contract IOracle", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "permit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "underlyingAmount", "type": "uint256" }], + "name": "previewDeposit", + "outputs": [{ "internalType": "uint256", "name": "principalAmount", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "principalAmount", "type": "uint256" }], + "name": "previewMint", + "outputs": [{ "internalType": "uint256", "name": "underlyingAmount", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "principalAmount", "type": "uint256" }], + "name": "previewRedeem", + "outputs": [{ "internalType": "uint256", "name": "underlyingAmount", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "underlyingAmount", "type": "uint256" }], + "name": "previewWithdraw", + "outputs": [{ "internalType": "uint256", "name": "principalAmount", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "proxiableUUID", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "receiver", "type": "address" }, + { "internalType": "uint256", "name": "principalAmount", "type": "uint256" } + ], + "name": "redeem", + "outputs": [{ "internalType": "uint256", "name": "underlyingAmount", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "principalAmount", "type": "uint256" }, + { "internalType": "address", "name": "receiver", "type": "address" }, + { "internalType": "address", "name": "holder", "type": "address" } + ], + "name": "redeem", + "outputs": [{ "internalType": "uint256", "name": "underlyingAmount", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "renounceRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "revokeRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4[]", "name": "roles", "type": "bytes4[]" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "revokeRoles", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "flashFeeFactor_", "type": "uint256" }], + "name": "setFlashFeeFactor", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4", "name": "role", "type": "bytes4" }, + { "internalType": "bytes4", "name": "adminRole", "type": "bytes4" } + ], + "name": "setRoleAdmin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "dst", "type": "address" }, + { "internalType": "uint256", "name": "wad", "type": "uint256" } + ], + "name": "transfer", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "src", "type": "address" }, + { "internalType": "address", "name": "dst", "type": "address" }, + { "internalType": "uint256", "name": "wad", "type": "uint256" } + ], + "name": "transferFrom", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "underlying", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "underlyingId", + "outputs": [{ "internalType": "bytes6", "name": "", "type": "bytes6" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "newImplementation", "type": "address" }], + "name": "upgradeTo", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "newImplementation", "type": "address" }, + { "internalType": "bytes", "name": "data", "type": "bytes" } + ], + "name": "upgradeToAndCall", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "version", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "underlyingAmount", "type": "uint256" }, + { "internalType": "address", "name": "receiver", "type": "address" }, + { "internalType": "address", "name": "holder", "type": "address" } + ], + "name": "withdraw", + "outputs": [{ "internalType": "uint256", "name": "principalAmount", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/src/contracts/abis/VYTokenProxy.json b/src/contracts/abis/VYTokenProxy.json new file mode 100644 index 000000000..4a324aebe --- /dev/null +++ b/src/contracts/abis/VYTokenProxy.json @@ -0,0 +1,33 @@ +[ + { + "inputs": [ + { "internalType": "address", "name": "_logic", "type": "address" }, + { "internalType": "bytes", "name": "_data", "type": "bytes" } + ], + "stateMutability": "payable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "internalType": "address", "name": "previousAdmin", "type": "address" }, + { "indexed": false, "internalType": "address", "name": "newAdmin", "type": "address" } + ], + "name": "AdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": true, "internalType": "address", "name": "beacon", "type": "address" }], + "name": "BeaconUpgraded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": true, "internalType": "address", "name": "implementation", "type": "address" }], + "name": "Upgraded", + "type": "event" + }, + { "stateMutability": "payable", "type": "fallback" }, + { "stateMutability": "payable", "type": "receive" } +] diff --git a/src/contracts/factories/VYTokenProxy__factory.ts b/src/contracts/factories/VYTokenProxy__factory.ts new file mode 100644 index 000000000..3319ecdb4 --- /dev/null +++ b/src/contracts/factories/VYTokenProxy__factory.ts @@ -0,0 +1,92 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer, utils } from "ethers"; +import { Provider } from "@ethersproject/providers"; +import type { VYTokenProxy, VYTokenProxyInterface } from "../VYTokenProxy"; + +const _abi = [ + { + inputs: [ + { + internalType: "address", + name: "_logic", + type: "address", + }, + { + internalType: "bytes", + name: "_data", + type: "bytes", + }, + ], + stateMutability: "payable", + type: "constructor", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "address", + name: "previousAdmin", + type: "address", + }, + { + indexed: false, + internalType: "address", + name: "newAdmin", + type: "address", + }, + ], + name: "AdminChanged", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "beacon", + type: "address", + }, + ], + name: "BeaconUpgraded", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "implementation", + type: "address", + }, + ], + name: "Upgraded", + type: "event", + }, + { + stateMutability: "payable", + type: "fallback", + }, + { + stateMutability: "payable", + type: "receive", + }, +]; + +export class VYTokenProxy__factory { + static readonly abi = _abi; + static createInterface(): VYTokenProxyInterface { + return new utils.Interface(_abi) as VYTokenProxyInterface; + } + static connect( + address: string, + signerOrProvider: Signer | Provider + ): VYTokenProxy { + return new Contract(address, _abi, signerOrProvider) as VYTokenProxy; + } +} diff --git a/src/contracts/factories/VYToken__factory.ts b/src/contracts/factories/VYToken__factory.ts new file mode 100644 index 000000000..d13ed0cde --- /dev/null +++ b/src/contracts/factories/VYToken__factory.ts @@ -0,0 +1,1316 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer, utils } from "ethers"; +import { Provider } from "@ethersproject/providers"; +import type { VYToken, VYTokenInterface } from "../VYToken"; + +const _abi = [ + { + inputs: [ + { + internalType: "bytes6", + name: "underlyingId_", + type: "bytes6", + }, + { + internalType: "contract IOracle", + name: "oracle_", + type: "address", + }, + { + internalType: "contract IJoin", + name: "join_", + type: "address", + }, + { + internalType: "string", + name: "name", + type: "string", + }, + { + internalType: "string", + name: "symbol", + type: "string", + }, + ], + stateMutability: "nonpayable", + type: "constructor", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "address", + name: "previousAdmin", + type: "address", + }, + { + indexed: false, + internalType: "address", + name: "newAdmin", + type: "address", + }, + ], + name: "AdminChanged", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "owner", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "spender", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "value", + type: "uint256", + }, + ], + name: "Approval", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "beacon", + type: "address", + }, + ], + name: "BeaconUpgraded", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "uint256", + name: "fee", + type: "uint256", + }, + ], + name: "FlashFeeFactorSet", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes32", + name: "param", + type: "bytes32", + }, + { + indexed: false, + internalType: "address", + name: "value", + type: "address", + }, + ], + name: "Point", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "holder", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "receiver", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "principalAmount", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "underlyingAmount", + type: "uint256", + }, + ], + name: "Redeemed", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + indexed: true, + internalType: "bytes4", + name: "newAdminRole", + type: "bytes4", + }, + ], + name: "RoleAdminChanged", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + indexed: true, + internalType: "address", + name: "account", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "sender", + type: "address", + }, + ], + name: "RoleGranted", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + indexed: true, + internalType: "address", + name: "account", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "sender", + type: "address", + }, + ], + name: "RoleRevoked", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "from", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "to", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "value", + type: "uint256", + }, + ], + name: "Transfer", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "implementation", + type: "address", + }, + ], + name: "Upgraded", + type: "event", + }, + { + inputs: [], + name: "DOMAIN_SEPARATOR", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "LOCK", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "LOCK8605463013", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "PERMIT_TYPEHASH", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "ROOT", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "ROOT4146650865", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "owner", + type: "address", + }, + { + internalType: "address", + name: "spender", + type: "address", + }, + ], + name: "allowance", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "spender", + type: "address", + }, + { + internalType: "uint256", + name: "wad", + type: "uint256", + }, + ], + name: "approve", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "guy", + type: "address", + }, + ], + name: "balanceOf", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "underlyingAmount", + type: "uint256", + }, + ], + name: "convertToPrincipal", + outputs: [ + { + internalType: "uint256", + name: "principalAmount", + type: "uint256", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "principalAmount", + type: "uint256", + }, + ], + name: "convertToUnderlying", + outputs: [ + { + internalType: "uint256", + name: "underlyingAmount", + type: "uint256", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "decimals", + outputs: [ + { + internalType: "uint8", + name: "", + type: "uint8", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "deploymentChainId", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "receiver", + type: "address", + }, + { + internalType: "uint256", + name: "underlyingAmount", + type: "uint256", + }, + ], + name: "deposit", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "token", + type: "address", + }, + { + internalType: "uint256", + name: "principalAmount", + type: "uint256", + }, + ], + name: "flashFee", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "flashFeeFactor", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "contract IERC3156FlashBorrower", + name: "receiver", + type: "address", + }, + { + internalType: "address", + name: "token", + type: "address", + }, + { + internalType: "uint256", + name: "principalAmount", + type: "uint256", + }, + { + internalType: "bytes", + name: "data", + type: "bytes", + }, + ], + name: "flashLoan", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + ], + name: "getRoleAdmin", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "grantRole", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4[]", + name: "roles", + type: "bytes4[]", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "grantRoles", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "hasRole", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "root_", + type: "address", + }, + ], + name: "initialize", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "initialized", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "join", + outputs: [ + { + internalType: "contract IJoin", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + ], + name: "lockRole", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + name: "maxDeposit", + outputs: [ + { + internalType: "uint256", + name: "maxUnderlyingAmount", + type: "uint256", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "token", + type: "address", + }, + ], + name: "maxFlashLoan", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + name: "maxMint", + outputs: [ + { + internalType: "uint256", + name: "maxPrincipalAmount", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "holder", + type: "address", + }, + ], + name: "maxRedeem", + outputs: [ + { + internalType: "uint256", + name: "maxPrincipalAmount", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "holder", + type: "address", + }, + ], + name: "maxWithdraw", + outputs: [ + { + internalType: "uint256", + name: "maxUnderlyingAmount", + type: "uint256", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "receiver", + type: "address", + }, + { + internalType: "uint256", + name: "principalAmount", + type: "uint256", + }, + ], + name: "mint", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "name", + outputs: [ + { + internalType: "string", + name: "", + type: "string", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + name: "nonces", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "oracle", + outputs: [ + { + internalType: "contract IOracle", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "owner", + type: "address", + }, + { + internalType: "address", + name: "spender", + type: "address", + }, + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + { + internalType: "uint256", + name: "deadline", + type: "uint256", + }, + { + internalType: "uint8", + name: "v", + type: "uint8", + }, + { + internalType: "bytes32", + name: "r", + type: "bytes32", + }, + { + internalType: "bytes32", + name: "s", + type: "bytes32", + }, + ], + name: "permit", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "underlyingAmount", + type: "uint256", + }, + ], + name: "previewDeposit", + outputs: [ + { + internalType: "uint256", + name: "principalAmount", + type: "uint256", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "principalAmount", + type: "uint256", + }, + ], + name: "previewMint", + outputs: [ + { + internalType: "uint256", + name: "underlyingAmount", + type: "uint256", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "principalAmount", + type: "uint256", + }, + ], + name: "previewRedeem", + outputs: [ + { + internalType: "uint256", + name: "underlyingAmount", + type: "uint256", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "underlyingAmount", + type: "uint256", + }, + ], + name: "previewWithdraw", + outputs: [ + { + internalType: "uint256", + name: "principalAmount", + type: "uint256", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "proxiableUUID", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "receiver", + type: "address", + }, + { + internalType: "uint256", + name: "principalAmount", + type: "uint256", + }, + ], + name: "redeem", + outputs: [ + { + internalType: "uint256", + name: "underlyingAmount", + type: "uint256", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "principalAmount", + type: "uint256", + }, + { + internalType: "address", + name: "receiver", + type: "address", + }, + { + internalType: "address", + name: "holder", + type: "address", + }, + ], + name: "redeem", + outputs: [ + { + internalType: "uint256", + name: "underlyingAmount", + type: "uint256", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "renounceRole", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "revokeRole", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4[]", + name: "roles", + type: "bytes4[]", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "revokeRoles", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "flashFeeFactor_", + type: "uint256", + }, + ], + name: "setFlashFeeFactor", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "role", + type: "bytes4", + }, + { + internalType: "bytes4", + name: "adminRole", + type: "bytes4", + }, + ], + name: "setRoleAdmin", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "symbol", + outputs: [ + { + internalType: "string", + name: "", + type: "string", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "totalSupply", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "dst", + type: "address", + }, + { + internalType: "uint256", + name: "wad", + type: "uint256", + }, + ], + name: "transfer", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "src", + type: "address", + }, + { + internalType: "address", + name: "dst", + type: "address", + }, + { + internalType: "uint256", + name: "wad", + type: "uint256", + }, + ], + name: "transferFrom", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "underlying", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "underlyingId", + outputs: [ + { + internalType: "bytes6", + name: "", + type: "bytes6", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "newImplementation", + type: "address", + }, + ], + name: "upgradeTo", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "newImplementation", + type: "address", + }, + { + internalType: "bytes", + name: "data", + type: "bytes", + }, + ], + name: "upgradeToAndCall", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [], + name: "version", + outputs: [ + { + internalType: "string", + name: "", + type: "string", + }, + ], + stateMutability: "pure", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "underlyingAmount", + type: "uint256", + }, + { + internalType: "address", + name: "receiver", + type: "address", + }, + { + internalType: "address", + name: "holder", + type: "address", + }, + ], + name: "withdraw", + outputs: [ + { + internalType: "uint256", + name: "principalAmount", + type: "uint256", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, +]; + +export class VYToken__factory { + static readonly abi = _abi; + static createInterface(): VYTokenInterface { + return new utils.Interface(_abi) as VYTokenInterface; + } + static connect( + address: string, + signerOrProvider: Signer | Provider + ): VYToken { + return new Contract(address, _abi, signerOrProvider) as VYToken; + } +} diff --git a/src/contracts/index.ts b/src/contracts/index.ts index d092d6d2b..a52861653 100644 --- a/src/contracts/index.ts +++ b/src/contracts/index.ts @@ -25,6 +25,8 @@ export type { UniswapV3Oracle } from "./UniswapV3Oracle"; export type { VRCauldron } from "./VRCauldron"; export type { VRLadle } from "./VRLadle"; export type { VRWitch } from "./VRWitch"; +export type { VYToken } from "./VYToken"; +export type { VYTokenProxy } from "./VYTokenProxy"; export type { Witch } from "./Witch"; export type { WitchV2 } from "./WitchV2"; export type { WrapEtherModule } from "./WrapEtherModule"; @@ -54,6 +56,8 @@ export { UniswapV3Oracle__factory } from "./factories/UniswapV3Oracle__factory"; export { VRCauldron__factory } from "./factories/VRCauldron__factory"; export { VRLadle__factory } from "./factories/VRLadle__factory"; export { VRWitch__factory } from "./factories/VRWitch__factory"; +export { VYToken__factory } from "./factories/VYToken__factory"; +export { VYTokenProxy__factory } from "./factories/VYTokenProxy__factory"; export { Witch__factory } from "./factories/Witch__factory"; export { WitchV2__factory } from "./factories/WitchV2__factory"; export { WrapEtherModule__factory } from "./factories/WrapEtherModule__factory"; From 928aa2594e9fc98e583f8d230dbf9ab81937b974 Mon Sep 17 00:00:00 2001 From: Jacob Bryant Date: Fri, 14 Apr 2023 14:22:24 -0400 Subject: [PATCH 024/242] addresses in asset config --- src/config/assets.ts | 12 ++++++++++++ src/hooks/actionHooks/useLend/useLendVR.ts | 12 +++++++----- src/types/index.ts | 3 +++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/config/assets.ts b/src/config/assets.ts index 290ef7d24..92efe4b9b 100644 --- a/src/config/assets.ts +++ b/src/config/assets.ts @@ -21,6 +21,7 @@ export interface AssetStaticInfo { wrapHandlerAddresses?: Map; // mapping a chain id to the corresponding wrap handler address unwrapHandlerAddresses?: Map; // mapping a chain id to the correpsonding unwrap handler address proxyId?: string; // associated token (eg. ) + joinAddressVR?: string; // address of the VR join contract } export const WETH = '0x303000000000'; @@ -85,6 +86,9 @@ ASSETS.set( { assetAddress: '0x6B175474E89094C44Da98b954EedeAC495271d0F', joinAddress: '0x4fE92119CDf873Cf8826F4E6EcfD4E578E3D44Dc', + joinAddressVR: '0x039a8f570f2a4f29c464386686712dcf1ed2cba5', + VYTokenAddress: '0x1220a98d8501eb449f334097f890a35efbb776fe', + VYTokenProxyAddress: '0xb31c695dCbC93db35c98b0C0995001730F8e61AA', version: '1', name: 'Dai Stablecoin', decimals: 18, @@ -100,6 +104,9 @@ ASSETS.set( { assetAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', joinAddress: '0x0d9A1A773be5a83eEbda23bf98efB8585C3ae4f4', + joinAddressVR: '0xbbf2c848f6e5cd8b410f0e0322550624ec5b9158', + VYTokenAddress: '0x7b1da3113a40270b100c4a339b9280f5c72c46b0', + VYTokenProxyAddress: '0x8bA91be1B11950824d530FdA325f05f632996c09', version: '1', name: 'USD Coin', decimals: 6, @@ -145,6 +152,9 @@ ASSETS.set( { assetAddress: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', joinAddress: '0x3bDb887Dc46ec0E964Df89fFE2980db0121f0fD0', + joinAddressVR: '0x40ef99c9c3b51cc0dc69ca56debe9680c69acada', + VYTokenAddress: '0x53b12053de0f3b3c221d4d1941edad5bf0737423', + VYTokenProxyAddress: '0xF00114b156C369d80a1B3cBe4edA445A4f19f6c8', version: '1', name: 'Wrapped Ether', decimals: 18, @@ -246,6 +256,8 @@ ASSETS.set( { assetAddress: '0x853d955aCEf822Db058eb8505911ED77F175b99e', joinAddress: '0x5655A973A49e1F9c1408bb9A617Fd0DBD0352464', + joinAddressVR: '0xe80ae7222ca938a918ec7c7367d7a8d9f9cc6314', + VYTokenAddress: '0x3d8ede89b7371ff31650a18f326a5afe1132ed67', version: '1', name: 'Frax', decimals: 18, diff --git a/src/hooks/actionHooks/useLend/useLendVR.ts b/src/hooks/actionHooks/useLend/useLendVR.ts index a1fecb24c..9b846e3b3 100644 --- a/src/hooks/actionHooks/useLend/useLendVR.ts +++ b/src/hooks/actionHooks/useLend/useLendVR.ts @@ -1,6 +1,7 @@ import { ethers } from 'ethers'; import { useContext } from 'react'; -import { MAX_256 } from '@yield-protocol/ui-math'; +import { calculateSlippage, MAX_256, sellBase } from '@yield-protocol/ui-math'; +import * as contractTypes from '../../../contracts'; import { ETH_BASED_ASSETS, USDT } from '../../../config/assets'; import { HistoryContext } from '../../../contexts/HistoryContext'; @@ -15,7 +16,8 @@ import useChainId from '../../useChainId'; import useAccountPlus from '../../useAccountPlus'; import { ContractNames } from '../../../config/contracts'; import useAllowAction from '../../useAllowAction'; -import { VRLadle } from '../../../contracts'; +import { VYToken__factory, Join__factory, VYTokenProxy__factory } from '../../../contracts'; +import useFork from '../../useFork'; /* Lend Actions Hook */ export const useLendVR = () => { @@ -53,7 +55,7 @@ export const useLendVR = () => { const cleanedInput = cleanValue(input, base.decimals); const _input = input ? ethers.utils.parseUnits(cleanedInput, base?.decimals) : ethers.constants.Zero; - const ladle = contracts.get(ContractNames.VR_LADLE) as VRLadle | undefined; + const ladle = contracts.get(ContractNames.VR_LADLE) as contractTypes.VRLadle | undefined; if (!ladle?.address) return; @@ -80,8 +82,8 @@ export const useLendVR = () => { return []; }; const joinAddr = await ladle.joins(base.id); - const vyTokenAddr = 'something'; // TODO - const vyTokenContract = VYTokenFactory.connect(vyTokenAddr, provider); + const vyTokenAddr = base.VYTokenAddress!; + const vyTokenContract = VYToken__factory.connect(vyTokenAddr, provider); const calls: ICallData[] = [ ...permitCallData, diff --git a/src/types/index.ts b/src/types/index.ts index d297b4311..f14ee9e96 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -161,6 +161,9 @@ export interface IAssetRoot extends IAssetStaticInfo, ISignable { displayName: string; displayNameMobile: string; joinAddress: string; + joinAddressVR?: string; // for VR if we can't query - jacob b + VYTokenAddress?: string; // for VR if we can't query - jacob b + VYTokenProxyAddress?: string; // for VR if we can't query - jacob b digitFormat: number; assetContract: Contract; From 0591359fff1857028dab91cb9d81bba0fb3b796c Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Fri, 14 Apr 2023 11:31:22 -0700 Subject: [PATCH 025/242] feat: get vyToken proxy contract --- src/hooks/actionHooks/useLend/useLendVR.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/hooks/actionHooks/useLend/useLendVR.ts b/src/hooks/actionHooks/useLend/useLendVR.ts index 9b846e3b3..4c1c12f55 100644 --- a/src/hooks/actionHooks/useLend/useLendVR.ts +++ b/src/hooks/actionHooks/useLend/useLendVR.ts @@ -81,9 +81,12 @@ export const useLendVR = () => { // if (isEthBase) return addEth(_input, series.poolAddress); // TODO addETH using vr return []; }; + const joinAddr = await ladle.joins(base.id); - const vyTokenAddr = base.VYTokenAddress!; - const vyTokenContract = VYToken__factory.connect(vyTokenAddr, provider); + + const vyTokenAddr = base.VYTokenProxyAddress; + if (!vyTokenAddr) return; + const vyTokenProxyContract = VYToken__factory.connect(vyTokenAddr, provider); const calls: ICallData[] = [ ...permitCallData, @@ -97,7 +100,7 @@ export const useLendVR = () => { operation: LadleActions.Fn.ROUTE, args: [account, _input] as RoutedActions.Args.DEPOSIT, fnName: RoutedActions.Fn.DEPOSIT, - targetContract: vyTokenContract, + targetContract: vyTokenProxyContract, ignoreIf: false, }, ]; From 7673f917b3b6620c68a7393a5c0962ec9a224682 Mon Sep 17 00:00:00 2001 From: Jacob Bryant Date: Fri, 14 Apr 2023 14:34:24 -0400 Subject: [PATCH 026/242] updating type --- src/config/assets.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/config/assets.ts b/src/config/assets.ts index 92efe4b9b..fc07c4457 100644 --- a/src/config/assets.ts +++ b/src/config/assets.ts @@ -22,6 +22,8 @@ export interface AssetStaticInfo { unwrapHandlerAddresses?: Map; // mapping a chain id to the correpsonding unwrap handler address proxyId?: string; // associated token (eg. ) joinAddressVR?: string; // address of the VR join contract + VYTokenAddress?: string; // address of the VYToken contract + VYTokenProxyAddress?: string; // address of the VYTokenProxy contract } export const WETH = '0x303000000000'; From 1fa09f95ba941eb520f590c6ebeff3b233c40adc Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Fri, 14 Apr 2023 11:36:56 -0700 Subject: [PATCH 027/242] fix: update default fork --- .env.local | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.local b/.env.local index cb06d8b9f..fa6b7bd64 100644 --- a/.env.local +++ b/.env.local @@ -4,7 +4,7 @@ REACT_APP_VERSION=$npm_package_version REACT_APP_RPC_URL_1='https://eth-mainnet.g.alchemy.com/v2/ZXDCq5iy0KrKR0XjsqC6E4QG7Z_FuXDv' REACT_APP_RPC_URL_42161='https://arb-mainnet.g.alchemy.com/v2/vtMM4_eLnOvkjkdckprVw3cIa64EVkDZ' -REACT_APP_DEFAULT_FORK_RPC_URL='https://rpc.tenderly.co/fork/ec327385-00b4-4e6b-9c4d-0a1cb566904b' +REACT_APP_DEFAULT_FORK_RPC_URL='https://rpc.tenderly.co/fork/8d7d8b03-48f4-48c2-b37c-22fcdeb6fcb5' REACT_APP_LOCALHOST_RPC_URL='http://127.0.0.1:8545' REACT_APP_RPC_URL_421611='https://arb-rinkeby.g.alchemy.com/v2/AY_Q_Uy-Kcfwmf5In5qwG636vaOIoA8L' From 4a891753599a3150a4ceecccc157e80d98818e30 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Fri, 14 Apr 2023 13:32:10 -0700 Subject: [PATCH 028/242] feat: using correct contracts --- src/hooks/actionHooks/useLend/useLendVR.ts | 30 +++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/hooks/actionHooks/useLend/useLendVR.ts b/src/hooks/actionHooks/useLend/useLendVR.ts index 4c1c12f55..b0cb6491a 100644 --- a/src/hooks/actionHooks/useLend/useLendVR.ts +++ b/src/hooks/actionHooks/useLend/useLendVR.ts @@ -1,6 +1,5 @@ import { ethers } from 'ethers'; import { useContext } from 'react'; -import { calculateSlippage, MAX_256, sellBase } from '@yield-protocol/ui-math'; import * as contractTypes from '../../../contracts'; import { ETH_BASED_ASSETS, USDT } from '../../../config/assets'; @@ -16,8 +15,8 @@ import useChainId from '../../useChainId'; import useAccountPlus from '../../useAccountPlus'; import { ContractNames } from '../../../config/contracts'; import useAllowAction from '../../useAllowAction'; -import { VYToken__factory, Join__factory, VYTokenProxy__factory } from '../../../contracts'; -import useFork from '../../useFork'; +import { VYToken__factory } from '../../../contracts'; +import { MAX_256 } from '@yield-protocol/ui-math'; /* Lend Actions Hook */ export const useLendVR = () => { @@ -43,21 +42,26 @@ export const useLendVR = () => { const contracts = useContracts(); const lend = async (input: string | undefined) => { - if (!selectedBase || !contracts || !assetMap || !account) return; - if (!isActionAllowed(ActionCodes.LEND_FR)) return; + console.log('in lend vr'); + + if (!selectedBase || !contracts || !assetMap || !account) + return console.error('no selectedBase || !contracts || !assetMap || !account'); + if (!isActionAllowed(ActionCodes.LEND_FR)) return console.log('lend action not allowed'); /* generate the reproducible txCode for tx tracking and tracing */ const txCode = getTxCode(ActionCodes.LEND, `${selectedBase?.id}-vr`); const base = assetMap.get(selectedBase.id); - if (!base) return; + if (!base) return console.error('no base'); + + if (!input) return console.error('no input'); const cleanedInput = cleanValue(input, base.decimals); - const _input = input ? ethers.utils.parseUnits(cleanedInput, base?.decimals) : ethers.constants.Zero; + const _input = ethers.utils.parseUnits(cleanedInput, base.decimals); const ladle = contracts.get(ContractNames.VR_LADLE) as contractTypes.VRLadle | undefined; - if (!ladle?.address) return; + if (!ladle?.address) return console.error('no ladle'); /* check if signature is required */ const alreadyApproved = (await base.getAllowance(account, ladle.address)).gte(_input); @@ -82,11 +86,13 @@ export const useLendVR = () => { return []; }; - const joinAddr = await ladle.joins(base.id); + // const joinAddr = await ladle.joins(base.id); TODO figure out why not working + const joinAddr = base.joinAddressVR; + if (!joinAddr) return console.error('no joinAddr'); - const vyTokenAddr = base.VYTokenProxyAddress; - if (!vyTokenAddr) return; - const vyTokenProxyContract = VYToken__factory.connect(vyTokenAddr, provider); + const vyTokenProxyAddr = base.VYTokenProxyAddress; + if (!vyTokenProxyAddr) return console.error('no vyTokenAddr'); + const vyTokenProxyContract = VYToken__factory.connect(vyTokenProxyAddr, provider); const calls: ICallData[] = [ ...permitCallData, From 4655e354bc401e6f5f6709c28d696207d3678d51 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Fri, 14 Apr 2023 13:37:24 -0700 Subject: [PATCH 029/242] feat: use proxy --- src/config/contracts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/contracts.ts b/src/config/contracts.ts index eb51a39f0..6e2aa11ae 100644 --- a/src/config/contracts.ts +++ b/src/config/contracts.ts @@ -27,7 +27,7 @@ export const contractAddresses: ContractAddresses = { [ContractNames.CAULDRON, '0xc88191F8cb8e6D4a668B047c1C8503432c3Ca867'], [ContractNames.VR_CAULDRON, '0xe199a0559516d8dd4739c978ad91ff1e6e228ecb'], [ContractNames.LADLE, '0x6cB18fF2A33e981D1e38A663Ca056c0a5265066A'], - [ContractNames.VR_LADLE, '0x122ea911f1c2d78b67a77f95cae04dea10fee47b'], + [ContractNames.VR_LADLE, '0x3405402FeE8d274fD5c2aC73F829c775B5a017AB'], [ContractNames.VR_WITCH, '0x556c5d86ab9497e2d12aa5bd2547f15bcb66065d'], [ContractNames.WITCH, '0x53C3760670f6091E1eC76B4dd27f73ba4CAd5061'], [ContractNames.WITCHV2, '0x08d2f5c96bb1f6be04b49bcd869d5af01db4c400'], From 684f70795cdced68b56974b030b8dbc9b550129c Mon Sep 17 00:00:00 2001 From: Jacob Bryant Date: Mon, 17 Apr 2023 07:38:57 -0400 Subject: [PATCH 030/242] updated addresses for VR 5 fork --- .env.local | 2 +- src/config/assets.ts | 23 ++++++++++++----------- src/config/contracts.ts | 6 +++--- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.env.local b/.env.local index fa6b7bd64..3a650fe2b 100644 --- a/.env.local +++ b/.env.local @@ -4,7 +4,7 @@ REACT_APP_VERSION=$npm_package_version REACT_APP_RPC_URL_1='https://eth-mainnet.g.alchemy.com/v2/ZXDCq5iy0KrKR0XjsqC6E4QG7Z_FuXDv' REACT_APP_RPC_URL_42161='https://arb-mainnet.g.alchemy.com/v2/vtMM4_eLnOvkjkdckprVw3cIa64EVkDZ' -REACT_APP_DEFAULT_FORK_RPC_URL='https://rpc.tenderly.co/fork/8d7d8b03-48f4-48c2-b37c-22fcdeb6fcb5' +REACT_APP_DEFAULT_FORK_RPC_URL='https://rpc.tenderly.co/fork/7cc113d1-6240-415e-bbad-5836c9c99bfa' REACT_APP_LOCALHOST_RPC_URL='http://127.0.0.1:8545' REACT_APP_RPC_URL_421611='https://arb-rinkeby.g.alchemy.com/v2/AY_Q_Uy-Kcfwmf5In5qwG636vaOIoA8L' diff --git a/src/config/assets.ts b/src/config/assets.ts index fc07c4457..ac37cf3b3 100644 --- a/src/config/assets.ts +++ b/src/config/assets.ts @@ -88,9 +88,9 @@ ASSETS.set( { assetAddress: '0x6B175474E89094C44Da98b954EedeAC495271d0F', joinAddress: '0x4fE92119CDf873Cf8826F4E6EcfD4E578E3D44Dc', - joinAddressVR: '0x039a8f570f2a4f29c464386686712dcf1ed2cba5', - VYTokenAddress: '0x1220a98d8501eb449f334097f890a35efbb776fe', - VYTokenProxyAddress: '0xb31c695dCbC93db35c98b0C0995001730F8e61AA', + joinAddressVR: '0x9eaCB025AB57A9d250BAb776B9d532039f0dAA3A', + VYTokenAddress: '0x96b99a8dA9554770A708F63485954c90473E0cA1', + VYTokenProxyAddress: '0x9aA81D23DE44F210Fd9e8E17a99D4cF8Ef16CBB0', version: '1', name: 'Dai Stablecoin', decimals: 18, @@ -106,9 +106,9 @@ ASSETS.set( { assetAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', joinAddress: '0x0d9A1A773be5a83eEbda23bf98efB8585C3ae4f4', - joinAddressVR: '0xbbf2c848f6e5cd8b410f0e0322550624ec5b9158', - VYTokenAddress: '0x7b1da3113a40270b100c4a339b9280f5c72c46b0', - VYTokenProxyAddress: '0x8bA91be1B11950824d530FdA325f05f632996c09', + joinAddressVR: '0x119672DDfFb496C6FAF4E2EB490d21D5e74BB6ae', + VYTokenAddress: '0xc3D163EaC4db5c62046345E5c780C7EaB9763353', + VYTokenProxyAddress: '0x62F8cA169555CE5692b9F72FB73237fdf01FA7A4', version: '1', name: 'USD Coin', decimals: 6, @@ -154,9 +154,9 @@ ASSETS.set( { assetAddress: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', joinAddress: '0x3bDb887Dc46ec0E964Df89fFE2980db0121f0fD0', - joinAddressVR: '0x40ef99c9c3b51cc0dc69ca56debe9680c69acada', - VYTokenAddress: '0x53b12053de0f3b3c221d4d1941edad5bf0737423', - VYTokenProxyAddress: '0xF00114b156C369d80a1B3cBe4edA445A4f19f6c8', + joinAddressVR: '0xd4bd75B00D3dcecAE262Dd34F8E94d59bF16c6EF', + VYTokenAddress: '0xEFCF601949Eeb126c2D3d8203f3d4F99Bf5dd1f1', + VYTokenProxyAddress: '0x4e65d89A12B38C5C4530be902fBEb9c0F14aECF2', version: '1', name: 'Wrapped Ether', decimals: 18, @@ -258,8 +258,9 @@ ASSETS.set( { assetAddress: '0x853d955aCEf822Db058eb8505911ED77F175b99e', joinAddress: '0x5655A973A49e1F9c1408bb9A617Fd0DBD0352464', - joinAddressVR: '0xe80ae7222ca938a918ec7c7367d7a8d9f9cc6314', - VYTokenAddress: '0x3d8ede89b7371ff31650a18f326a5afe1132ed67', + joinAddressVR: '0x22956932A4F395B17A0F687923f386453a2c92Cb', + VYTokenAddress: '0x3951bEa7D8611f3c9146C9E5BDFb81ee4b32B441', + VYTokenProxyAddress: '0xCE207D07D8F79B48B4b7618CF1e543bE2f98Fed2', version: '1', name: 'Frax', decimals: 18, diff --git a/src/config/contracts.ts b/src/config/contracts.ts index 6e2aa11ae..9b16da59e 100644 --- a/src/config/contracts.ts +++ b/src/config/contracts.ts @@ -25,10 +25,10 @@ export const contractAddresses: ContractAddresses = { 1, new Map([ [ContractNames.CAULDRON, '0xc88191F8cb8e6D4a668B047c1C8503432c3Ca867'], - [ContractNames.VR_CAULDRON, '0xe199a0559516d8dd4739c978ad91ff1e6e228ecb'], + [ContractNames.VR_CAULDRON, '0x567758c5f081B0E8596Ef3Ecd5B9bf83265F6B97'], [ContractNames.LADLE, '0x6cB18fF2A33e981D1e38A663Ca056c0a5265066A'], - [ContractNames.VR_LADLE, '0x3405402FeE8d274fD5c2aC73F829c775B5a017AB'], - [ContractNames.VR_WITCH, '0x556c5d86ab9497e2d12aa5bd2547f15bcb66065d'], + [ContractNames.VR_LADLE, '0x726385Cc84389831956f4dE883aB6001b9aDB91a'], + [ContractNames.VR_WITCH, '0xc508Ee2FF40fA6C33d3D333661028f1EfA68277A'], [ContractNames.WITCH, '0x53C3760670f6091E1eC76B4dd27f73ba4CAd5061'], [ContractNames.WITCHV2, '0x08d2f5c96bb1f6be04b49bcd869d5af01db4c400'], [ContractNames.TRANSFER_1155_MODULE, '0x97f1d43A217aDD678bB6Dcd3C5D51F40b6729d06'], From aaf6f22930089d098ed7481175ac0d8c107939af Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Tue, 18 Apr 2023 13:47:17 -0700 Subject: [PATCH 031/242] feat: useVYTokens --- src/hooks/entities/useVYTokens.ts | 70 +++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/hooks/entities/useVYTokens.ts diff --git a/src/hooks/entities/useVYTokens.ts b/src/hooks/entities/useVYTokens.ts new file mode 100644 index 000000000..2a3f46f11 --- /dev/null +++ b/src/hooks/entities/useVYTokens.ts @@ -0,0 +1,70 @@ +import useSWR from 'swr'; +import { VYToken__factory } from '../../contracts'; +import { useCallback, useContext, useMemo } from 'react'; +import useFork from '../useFork'; +import { UserContext } from '../../contexts/UserContext'; +import useDefaultProvider from '../useDefaultProvider'; +import useAccountPlus from '../useAccountPlus'; +import { ISignable } from '../../types'; + +export interface IVYToken extends ISignable { + id: string; // vyToken address + decimals: number; + baseAddress: string; // associated base addr + baseId: string; // associated base id + displayName?: string; + displayNameMobile?: string; +} + +const useVYTokens = () => { + const { address: account } = useAccountPlus(); + const { useForkedEnv, provider: forkProvider } = useFork(); + const provider = useDefaultProvider(); + const { + userState: { assetMap }, + } = useContext(UserContext); + + const get = useCallback(async () => { + return await Array.from(assetMap.values()) + .map((a) => a.VYTokenProxyAddress) // get asset's vyTokenProxy addr + .reduce(async (vyTokens, address) => { + if (!address) return await vyTokens; + + const contract = VYToken__factory.connect(address, useForkedEnv && forkProvider ? forkProvider : provider); + const [name, symbol, decimals, version, baseAddress, baseId] = await Promise.all([ + contract.name(), + contract.symbol(), + contract.decimals(), + contract.version(), + contract.underlying(), + contract.underlyingId(), + ]); + + const data: IVYToken = { + id: address, + address, + name, + symbol, + decimals, + version, + baseAddress, + baseId, + displayName: `Variable Rate ${name.substring(2)}`, + displayNameMobile: `Variable Rate ${name.substring(2)}`, + }; + + return (await vyTokens).set(address, data); + }, Promise.resolve(new Map())); + }, [assetMap, forkProvider, provider, useForkedEnv]); + + const key = useMemo( + () => ['lendPositionsVR', account, assetMap, forkProvider, provider, useForkedEnv], + [account, assetMap, forkProvider, provider, useForkedEnv] + ); + + const { data, error, isLoading } = useSWR(key, get, { revalidateOnFocus: false }); + + return { data, error, isLoading }; +}; + +export default useVYTokens; From 0fb2caf0fcf7f5f4171a15828a297dfe15a96af5 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Tue, 18 Apr 2023 14:19:36 -0700 Subject: [PATCH 032/242] feat: handling both fr and vr lend positions --- src/components/PositionAvatar.tsx | 3 +- src/components/positionItems/LendItem.tsx | 45 +++---- .../selectors/LendPositionSelector.tsx | 112 ++++++++++-------- src/components/views/Lend.tsx | 4 +- src/components/views/LendPosition.tsx | 14 +-- 5 files changed, 94 insertions(+), 84 deletions(-) diff --git a/src/components/PositionAvatar.tsx b/src/components/PositionAvatar.tsx index 3b8c5b09a..33db9b47e 100644 --- a/src/components/PositionAvatar.tsx +++ b/src/components/PositionAvatar.tsx @@ -6,6 +6,7 @@ import styled from 'styled-components'; import { UserContext } from '../contexts/UserContext'; import { IVault, ISeries, IAsset, IStrategy, ActionType } from '../types'; import Logo from './logos/Logo'; +import { IVYToken } from '../hooks/entities/useVYTokens'; const Outer = styled(Box)` position: relative; @@ -31,7 +32,7 @@ function PositionAvatar({ condensed, actionType, }: { - position: IVault | ISeries | IStrategy; + position: IVault | ISeries | IStrategy | IVYToken; actionType: ActionType; condensed?: boolean; }) { diff --git a/src/components/positionItems/LendItem.tsx b/src/components/positionItems/LendItem.tsx index dd651eb07..ca3b3fa66 100644 --- a/src/components/positionItems/LendItem.tsx +++ b/src/components/positionItems/LendItem.tsx @@ -1,7 +1,7 @@ import { useRouter } from 'next/router'; import { useContext } from 'react'; import { Box, Text } from 'grommet'; -import { ActionType, ISeries } from '../../types'; +import { ActionType } from '../../types'; import { UserContext } from '../../contexts/UserContext'; import { cleanValue } from '../../utils/appUtils'; import PositionAvatar from '../PositionAvatar'; @@ -10,40 +10,37 @@ import { useLendHelpers } from '../../hooks/viewHelperHooks/useLendHelpers'; import SkeletonWrap from '../wraps/SkeletonWrap'; import useAnalytics from '../../hooks/useAnalytics'; import { GA_Event, GA_Properties } from '../../types/analytics'; +import { IPosition } from '../selectors/LendPositionSelector'; -function LendItem({ - series, - index, - actionType, - condensed, -}: { - series: ISeries; +interface LendItemProps { + item: IPosition; index: number; - actionType: ActionType; condensed?: boolean; -}) { +} + +function LendItem({ item, index, condensed }: LendItemProps) { const router = useRouter(); const { logAnalyticsEvent } = useAnalytics(); const { - userState: { assetMap, seriesLoading, selectedSeries, selectedBase }, - userActions, + userState: { assetMap, seriesLoading, selectedSeries, selectedBase, seriesMap }, + userActions: { setSelectedBase, setSelectedSeries }, } = useContext(UserContext); - const { fyTokenMarketValue } = useLendHelpers(series!, '0'); - const seriesBase = assetMap?.get(series.baseId)!; - const isSelectedBaseAndSeries = series.baseId === seriesBase.proxyId && series.id === selectedSeries?.id; + const { fyTokenMarketValue } = useLendHelpers(selectedSeries, '0'); + const series = [...seriesMap.values()].find((s) => s.address === item.address); + const base = assetMap.get(item.baseId); - const handleSelect = (_series: ISeries) => { - userActions.setSelectedBase(selectedBase); - userActions.setSelectedSeries(_series); - router.push(`/${actionType.toLowerCase()}position/${_series.id}`); + const handleSelect = () => { + base && setSelectedBase(base); + series && setSelectedSeries(series); + router.push(`/lendposition/${item.address}`); logAnalyticsEvent(GA_Event.position_opened, { id: selectedSeries?.name, } as GA_Properties.position_opened); }; return ( - handleSelect(series)} index={index}> + - {series.displayName} + {item.displayName} {fyTokenMarketValue !== 'Low liquidity' && ( @@ -62,11 +59,7 @@ function LendItem({ Balance: - {seriesLoading && isSelectedBaseAndSeries ? ( - - ) : ( - cleanValue(fyTokenMarketValue, seriesBase?.digitFormat!) - )} + {seriesLoading ? : cleanValue(fyTokenMarketValue, base?.digitFormat!)} )} diff --git a/src/components/selectors/LendPositionSelector.tsx b/src/components/selectors/LendPositionSelector.tsx index 46a137e8c..2c04d0683 100644 --- a/src/components/selectors/LendPositionSelector.tsx +++ b/src/components/selectors/LendPositionSelector.tsx @@ -1,72 +1,88 @@ import { useCallback, useContext, useEffect, useState } from 'react'; import { FiX } from 'react-icons/fi'; import { Box, Button, Text } from 'grommet'; - import { UserContext } from '../../contexts/UserContext'; - -import { ActionType, IAsset, ISeries } from '../../types'; - -import { ZERO_BN } from '../../utils/constants'; +import { IAsset, ISeries } from '../../types'; import LendItem from '../positionItems/LendItem'; import ListWrap from '../wraps/ListWrap'; -import { useAccount } from 'wagmi'; import useAccountPlus from '../../hooks/useAccountPlus'; +import useVYTokens from '../../hooks/entities/useVYTokens'; +import { BigNumber, ethers } from 'ethers'; interface IPositionFilter { - base: IAsset | undefined; - series: ISeries | undefined; + base?: IAsset | null; + id?: string; // fyToken or vyToken address +} + +export interface IPosition { + address: string; // fyToken or vyToken address + baseId: string; // underlying base id + displayName: string; + balance: BigNumber; } -function PositionSelector({ actionType }: { actionType: ActionType }) { +function LendPositionSelector() { + const { data: vyTokens } = useVYTokens(); + console.log('🦄 ~ file: LendPositionSelector.tsx:25 ~ LendPositionSelector ~ vyTokens:', vyTokens); + /* STATE FROM CONTEXT */ const { userState } = useContext(UserContext); - const { seriesMap, selectedSeries, selectedBase } = userState; + const { seriesMap, selectedBase, selectedVR, selectedSeries } = userState; const { address: activeAccount } = useAccountPlus(); - const [allPositions, setAllPositions] = useState([]); + const [allPositions, setAllPositions] = useState([]); const [showAllPositions, setShowAllPositions] = useState(false); const [currentFilter, setCurrentFilter] = useState(); const [filterLabels, setFilterLabels] = useState<(string | undefined)[]>([]); - const [filteredSeries, setFilteredSeries] = useState([]); + const [filteredPositions, setFilteredPositions] = useState([]); const handleFilter = useCallback( - ({ base, series }: IPositionFilter) => { - /* filter all positions by base if base is selected */ - const _filteredSeries: ISeries[] = Array.from(seriesMap?.values()!) - /* filter by positive balances on either pool tokens or fyTokens */ - .filter((_series: ISeries) => (actionType === 'LEND' && _series ? _series.fyTokenBalance?.gt(ZERO_BN) : true)) - .filter((_series: ISeries) => (actionType === 'POOL' && _series ? _series.poolTokens?.gt(ZERO_BN) : true)) - .filter((_series: ISeries) => (base ? _series.baseId === base.proxyId : true)) - .filter((_series: ISeries) => (series ? _series.id === series.id : true)); - setCurrentFilter({ base, series }); - setFilterLabels([base?.symbol, series?.displayNameMobile]); - setFilteredSeries(_filteredSeries); + ({ base, id }: IPositionFilter) => { + const filtered = allPositions + // .filter((item) => item.balance.gt(ethers.constants.Zero)) + /* filter all positions by base if base is selected */ + .filter((item) => (base ? item.baseId === base.proxyId : true)) + .filter((item) => (id ? item.address === id : true)); + + setCurrentFilter({ base, id }); + setFilterLabels([base?.symbol]); + setFilteredPositions(filtered); }, - [seriesMap, actionType] + [allPositions] ); + const handleSort = (positions: IPosition[]) => positions.sort((a, b) => (a.balance.gt(b.balance) ? -1 : 1)); + /* CHECK the list of current vaults which match the current base series selection */ useEffect(() => { - /* only if veiwing the main screen (not when modal is showing) */ - // if (!showPositionModal) { - const _allPositions: ISeries[] = Array.from(seriesMap?.values()!) - /* filter by positive balances on either pool tokens or fyTokens */ - .filter((_series: ISeries) => (actionType === 'LEND' && _series ? _series.fyTokenBalance?.gt(ZERO_BN) : true)) - .filter((_series: ISeries) => (actionType === 'POOL' && _series ? _series.poolTokens?.gt(ZERO_BN) : true)) - .sort((_seriesA: ISeries, _seriesB: ISeries) => - actionType === 'LEND' && _seriesA.fyTokenBalance?.gt(_seriesB.fyTokenBalance!) ? 1 : -1 - ) - .sort((_seriesA: ISeries, _seriesB: ISeries) => - actionType === 'POOL' && _seriesA.poolTokens?.lt(_seriesB.poolTokens!) ? 1 : -1 - ); - setAllPositions(_allPositions); - - if (selectedBase) handleFilter({ base: selectedBase, series: undefined }); - if (selectedBase && selectedSeries) handleFilter({ base: selectedBase, series: selectedSeries }); - // } - }, [selectedBase, selectedSeries, handleFilter, seriesMap, actionType]); + (async () => { + /* only if viewing the main screen (not when modal is showing) */ + const getPositions = async () => + activeAccount + ? [...seriesMap.values()].reduce(async (acc, item) => { + const position: IPosition = { + baseId: item.baseId, + address: item.address, + balance: ethers.constants.Zero, + displayName: item.displayName, + }; + + return [...(await acc), position]; + }, Promise.resolve([])) + : []; + + setAllPositions(await getPositions()); + })(); + }, [activeAccount, seriesMap]); + + useEffect(() => { + handleFilter({ + base: selectedBase, + id: selectedSeries ? selectedSeries?.id : selectedVR ? selectedBase?.VYTokenProxyAddress : undefined, + }); + }, [handleFilter, selectedBase, selectedSeries, selectedVR]); useEffect(() => { allPositions.length <= 5 && setShowAllPositions(true); @@ -89,14 +105,14 @@ function PositionSelector({ actionType }: { actionType: ActionType }) { - {filteredSeries.length === 0 && !showAllPositions && ( + {filteredPositions.length === 0 && !showAllPositions && ( No suggested positions )} - {(!showAllPositions ? filteredSeries : allPositions).map((x: ISeries, i: number) => ( - + {(!showAllPositions ? filteredPositions : allPositions).map((x, i) => ( + ))} @@ -116,8 +132,8 @@ function PositionSelector({ actionType }: { actionType: ActionType }) { onClick={() => handleFilter({ ...currentFilter, - base: undefined, - } as IPositionFilter) + base: null, + }) } >