diff --git a/src/abi/OffchainOracle.json b/src/abi/OffchainOracle.json new file mode 100644 index 0000000..2139259 --- /dev/null +++ b/src/abi/OffchainOracle.json @@ -0,0 +1,175 @@ +[ + { + "inputs": [ + { "internalType": "contract MultiWrapper", "name": "_multiWrapper", "type": "address" }, + { "internalType": "contract IOracle[]", "name": "existingOracles", "type": "address[]" }, + { "internalType": "enum OffchainOracle.OracleType[]", "name": "oracleTypes", "type": "uint8[]" }, + { "internalType": "contract IERC20[]", "name": "existingConnectors", "type": "address[]" }, + { "internalType": "contract IERC20", "name": "wBase", "type": "address" } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "contract IERC20", "name": "connector", "type": "address" }], + "name": "ConnectorAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "contract IERC20", "name": "connector", "type": "address" }], + "name": "ConnectorRemoved", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "contract MultiWrapper", "name": "multiWrapper", "type": "address" }], + "name": "MultiWrapperUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "internalType": "contract IOracle", "name": "oracle", "type": "address" }, + { + "indexed": false, + "internalType": "enum OffchainOracle.OracleType", + "name": "oracleType", + "type": "uint8" + } + ], + "name": "OracleAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "internalType": "contract IOracle", "name": "oracle", "type": "address" }, + { + "indexed": false, + "internalType": "enum OffchainOracle.OracleType", + "name": "oracleType", + "type": "uint8" + } + ], + "name": "OracleRemoved", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "inputs": [{ "internalType": "contract IERC20", "name": "connector", "type": "address" }], + "name": "addConnector", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IOracle", "name": "oracle", "type": "address" }, + { "internalType": "enum OffchainOracle.OracleType", "name": "oracleKind", "type": "uint8" } + ], + "name": "addOracle", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "connectors", + "outputs": [{ "internalType": "contract IERC20[]", "name": "allConnectors", "type": "address[]" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IERC20", "name": "srcToken", "type": "address" }, + { "internalType": "contract IERC20", "name": "dstToken", "type": "address" }, + { "internalType": "bool", "name": "useWrappers", "type": "bool" } + ], + "name": "getRate", + "outputs": [{ "internalType": "uint256", "name": "weightedRate", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IERC20", "name": "srcToken", "type": "address" }, + { "internalType": "bool", "name": "useSrcWrappers", "type": "bool" } + ], + "name": "getRateToEth", + "outputs": [{ "internalType": "uint256", "name": "weightedRate", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "multiWrapper", + "outputs": [{ "internalType": "contract MultiWrapper", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "oracles", + "outputs": [ + { "internalType": "contract IOracle[]", "name": "allOracles", "type": "address[]" }, + { "internalType": "enum OffchainOracle.OracleType[]", "name": "oracleTypes", "type": "uint8[]" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "contract IERC20", "name": "connector", "type": "address" }], + "name": "removeConnector", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IOracle", "name": "oracle", "type": "address" }, + { "internalType": "enum OffchainOracle.OracleType", "name": "oracleKind", "type": "uint8" } + ], + "name": "removeOracle", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "contract MultiWrapper", "name": "_multiWrapper", "type": "address" }], + "name": "setMultiWrapper", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/src/artifacts/OffchainOracle.d.ts b/src/artifacts/OffchainOracle.d.ts new file mode 100644 index 0000000..2ed5556 --- /dev/null +++ b/src/artifacts/OffchainOracle.d.ts @@ -0,0 +1,523 @@ +/* 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 { TypedEventFilter, TypedEvent, TypedListener } from "./commons"; + +interface OffchainOracleInterface extends ethers.utils.Interface { + functions: { + "addConnector(address)": FunctionFragment; + "addOracle(address,uint8)": FunctionFragment; + "connectors()": FunctionFragment; + "getRate(address,address,bool)": FunctionFragment; + "getRateToEth(address,bool)": FunctionFragment; + "multiWrapper()": FunctionFragment; + "oracles()": FunctionFragment; + "owner()": FunctionFragment; + "removeConnector(address)": FunctionFragment; + "removeOracle(address,uint8)": FunctionFragment; + "renounceOwnership()": FunctionFragment; + "setMultiWrapper(address)": FunctionFragment; + "transferOwnership(address)": FunctionFragment; + }; + + encodeFunctionData( + functionFragment: "addConnector", + values: [string] + ): string; + encodeFunctionData( + functionFragment: "addOracle", + values: [string, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "connectors", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "getRate", + values: [string, string, boolean] + ): string; + encodeFunctionData( + functionFragment: "getRateToEth", + values: [string, boolean] + ): string; + encodeFunctionData( + functionFragment: "multiWrapper", + values?: undefined + ): string; + encodeFunctionData(functionFragment: "oracles", values?: undefined): string; + encodeFunctionData(functionFragment: "owner", values?: undefined): string; + encodeFunctionData( + functionFragment: "removeConnector", + values: [string] + ): string; + encodeFunctionData( + functionFragment: "removeOracle", + values: [string, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "renounceOwnership", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "setMultiWrapper", + values: [string] + ): string; + encodeFunctionData( + functionFragment: "transferOwnership", + values: [string] + ): string; + + decodeFunctionResult( + functionFragment: "addConnector", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "addOracle", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "connectors", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "getRate", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "getRateToEth", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "multiWrapper", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "oracles", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "owner", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "removeConnector", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "removeOracle", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "renounceOwnership", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "setMultiWrapper", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "transferOwnership", + data: BytesLike + ): Result; + + events: { + "ConnectorAdded(address)": EventFragment; + "ConnectorRemoved(address)": EventFragment; + "MultiWrapperUpdated(address)": EventFragment; + "OracleAdded(address,uint8)": EventFragment; + "OracleRemoved(address,uint8)": EventFragment; + "OwnershipTransferred(address,address)": EventFragment; + }; + + getEvent(nameOrSignatureOrTopic: "ConnectorAdded"): EventFragment; + getEvent(nameOrSignatureOrTopic: "ConnectorRemoved"): EventFragment; + getEvent(nameOrSignatureOrTopic: "MultiWrapperUpdated"): EventFragment; + getEvent(nameOrSignatureOrTopic: "OracleAdded"): EventFragment; + getEvent(nameOrSignatureOrTopic: "OracleRemoved"): EventFragment; + getEvent(nameOrSignatureOrTopic: "OwnershipTransferred"): EventFragment; +} + +export class OffchainOracle 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: OffchainOracleInterface; + + functions: { + addConnector( + connector: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addOracle( + oracle: string, + oracleKind: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + connectors( + overrides?: CallOverrides + ): Promise<[string[]] & { allConnectors: string[] }>; + + getRate( + srcToken: string, + dstToken: string, + useWrappers: boolean, + overrides?: CallOverrides + ): Promise<[BigNumber] & { weightedRate: BigNumber }>; + + getRateToEth( + srcToken: string, + useSrcWrappers: boolean, + overrides?: CallOverrides + ): Promise<[BigNumber] & { weightedRate: BigNumber }>; + + multiWrapper(overrides?: CallOverrides): Promise<[string]>; + + oracles( + overrides?: CallOverrides + ): Promise< + [string[], number[]] & { allOracles: string[]; oracleTypes: number[] } + >; + + owner(overrides?: CallOverrides): Promise<[string]>; + + removeConnector( + connector: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + removeOracle( + oracle: string, + oracleKind: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + renounceOwnership( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setMultiWrapper( + _multiWrapper: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + transferOwnership( + newOwner: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + }; + + addConnector( + connector: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addOracle( + oracle: string, + oracleKind: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + connectors(overrides?: CallOverrides): Promise; + + getRate( + srcToken: string, + dstToken: string, + useWrappers: boolean, + overrides?: CallOverrides + ): Promise; + + getRateToEth( + srcToken: string, + useSrcWrappers: boolean, + overrides?: CallOverrides + ): Promise; + + multiWrapper(overrides?: CallOverrides): Promise; + + oracles( + overrides?: CallOverrides + ): Promise< + [string[], number[]] & { allOracles: string[]; oracleTypes: number[] } + >; + + owner(overrides?: CallOverrides): Promise; + + removeConnector( + connector: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + removeOracle( + oracle: string, + oracleKind: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + renounceOwnership( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setMultiWrapper( + _multiWrapper: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + transferOwnership( + newOwner: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + callStatic: { + addConnector(connector: string, overrides?: CallOverrides): Promise; + + addOracle( + oracle: string, + oracleKind: BigNumberish, + overrides?: CallOverrides + ): Promise; + + connectors(overrides?: CallOverrides): Promise; + + getRate( + srcToken: string, + dstToken: string, + useWrappers: boolean, + overrides?: CallOverrides + ): Promise; + + getRateToEth( + srcToken: string, + useSrcWrappers: boolean, + overrides?: CallOverrides + ): Promise; + + multiWrapper(overrides?: CallOverrides): Promise; + + oracles( + overrides?: CallOverrides + ): Promise< + [string[], number[]] & { allOracles: string[]; oracleTypes: number[] } + >; + + owner(overrides?: CallOverrides): Promise; + + removeConnector( + connector: string, + overrides?: CallOverrides + ): Promise; + + removeOracle( + oracle: string, + oracleKind: BigNumberish, + overrides?: CallOverrides + ): Promise; + + renounceOwnership(overrides?: CallOverrides): Promise; + + setMultiWrapper( + _multiWrapper: string, + overrides?: CallOverrides + ): Promise; + + transferOwnership( + newOwner: string, + overrides?: CallOverrides + ): Promise; + }; + + filters: { + ConnectorAdded( + connector?: null + ): TypedEventFilter<[string], { connector: string }>; + + ConnectorRemoved( + connector?: null + ): TypedEventFilter<[string], { connector: string }>; + + MultiWrapperUpdated( + multiWrapper?: null + ): TypedEventFilter<[string], { multiWrapper: string }>; + + OracleAdded( + oracle?: null, + oracleType?: null + ): TypedEventFilter< + [string, number], + { oracle: string; oracleType: number } + >; + + OracleRemoved( + oracle?: null, + oracleType?: null + ): TypedEventFilter< + [string, number], + { oracle: string; oracleType: number } + >; + + OwnershipTransferred( + previousOwner?: string | null, + newOwner?: string | null + ): TypedEventFilter< + [string, string], + { previousOwner: string; newOwner: string } + >; + }; + + estimateGas: { + addConnector( + connector: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addOracle( + oracle: string, + oracleKind: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + connectors(overrides?: CallOverrides): Promise; + + getRate( + srcToken: string, + dstToken: string, + useWrappers: boolean, + overrides?: CallOverrides + ): Promise; + + getRateToEth( + srcToken: string, + useSrcWrappers: boolean, + overrides?: CallOverrides + ): Promise; + + multiWrapper(overrides?: CallOverrides): Promise; + + oracles(overrides?: CallOverrides): Promise; + + owner(overrides?: CallOverrides): Promise; + + removeConnector( + connector: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + removeOracle( + oracle: string, + oracleKind: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + renounceOwnership( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setMultiWrapper( + _multiWrapper: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + transferOwnership( + newOwner: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + }; + + populateTransaction: { + addConnector( + connector: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + addOracle( + oracle: string, + oracleKind: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + connectors(overrides?: CallOverrides): Promise; + + getRate( + srcToken: string, + dstToken: string, + useWrappers: boolean, + overrides?: CallOverrides + ): Promise; + + getRateToEth( + srcToken: string, + useSrcWrappers: boolean, + overrides?: CallOverrides + ): Promise; + + multiWrapper(overrides?: CallOverrides): Promise; + + oracles(overrides?: CallOverrides): Promise; + + owner(overrides?: CallOverrides): Promise; + + removeConnector( + connector: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + removeOracle( + oracle: string, + oracleKind: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + renounceOwnership( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setMultiWrapper( + _multiWrapper: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + transferOwnership( + newOwner: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + }; +} diff --git a/src/artifacts/factories/OffchainOracle__factory.ts b/src/artifacts/factories/OffchainOracle__factory.ts new file mode 100644 index 0000000..e4a45e7 --- /dev/null +++ b/src/artifacts/factories/OffchainOracle__factory.ts @@ -0,0 +1,358 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer, utils } from "ethers"; +import { Provider } from "@ethersproject/providers"; +import type { + OffchainOracle, + OffchainOracleInterface, +} from "../OffchainOracle"; + +const _abi = [ + { + inputs: [ + { + internalType: "contract MultiWrapper", + name: "_multiWrapper", + type: "address", + }, + { + internalType: "contract IOracle[]", + name: "existingOracles", + type: "address[]", + }, + { + internalType: "enum OffchainOracle.OracleType[]", + name: "oracleTypes", + type: "uint8[]", + }, + { + internalType: "contract IERC20[]", + name: "existingConnectors", + type: "address[]", + }, + { + internalType: "contract IERC20", + name: "wBase", + type: "address", + }, + ], + stateMutability: "nonpayable", + type: "constructor", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "contract IERC20", + name: "connector", + type: "address", + }, + ], + name: "ConnectorAdded", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "contract IERC20", + name: "connector", + type: "address", + }, + ], + name: "ConnectorRemoved", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "contract MultiWrapper", + name: "multiWrapper", + type: "address", + }, + ], + name: "MultiWrapperUpdated", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "contract IOracle", + name: "oracle", + type: "address", + }, + { + indexed: false, + internalType: "enum OffchainOracle.OracleType", + name: "oracleType", + type: "uint8", + }, + ], + name: "OracleAdded", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "contract IOracle", + name: "oracle", + type: "address", + }, + { + indexed: false, + internalType: "enum OffchainOracle.OracleType", + name: "oracleType", + type: "uint8", + }, + ], + name: "OracleRemoved", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "previousOwner", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "newOwner", + type: "address", + }, + ], + name: "OwnershipTransferred", + type: "event", + }, + { + inputs: [ + { + internalType: "contract IERC20", + name: "connector", + type: "address", + }, + ], + name: "addConnector", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "contract IOracle", + name: "oracle", + type: "address", + }, + { + internalType: "enum OffchainOracle.OracleType", + name: "oracleKind", + type: "uint8", + }, + ], + name: "addOracle", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "connectors", + outputs: [ + { + internalType: "contract IERC20[]", + name: "allConnectors", + type: "address[]", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "contract IERC20", + name: "srcToken", + type: "address", + }, + { + internalType: "contract IERC20", + name: "dstToken", + type: "address", + }, + { + internalType: "bool", + name: "useWrappers", + type: "bool", + }, + ], + name: "getRate", + outputs: [ + { + internalType: "uint256", + name: "weightedRate", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "contract IERC20", + name: "srcToken", + type: "address", + }, + { + internalType: "bool", + name: "useSrcWrappers", + type: "bool", + }, + ], + name: "getRateToEth", + outputs: [ + { + internalType: "uint256", + name: "weightedRate", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "multiWrapper", + outputs: [ + { + internalType: "contract MultiWrapper", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "oracles", + outputs: [ + { + internalType: "contract IOracle[]", + name: "allOracles", + type: "address[]", + }, + { + internalType: "enum OffchainOracle.OracleType[]", + name: "oracleTypes", + type: "uint8[]", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "owner", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "contract IERC20", + name: "connector", + type: "address", + }, + ], + name: "removeConnector", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "contract IOracle", + name: "oracle", + type: "address", + }, + { + internalType: "enum OffchainOracle.OracleType", + name: "oracleKind", + type: "uint8", + }, + ], + name: "removeOracle", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "renounceOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "contract MultiWrapper", + name: "_multiWrapper", + type: "address", + }, + ], + name: "setMultiWrapper", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "newOwner", + type: "address", + }, + ], + name: "transferOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, +]; + +export class OffchainOracle__factory { + static readonly abi = _abi; + static createInterface(): OffchainOracleInterface { + return new utils.Interface(_abi) as OffchainOracleInterface; + } + static connect( + address: string, + signerOrProvider: Signer | Provider + ): OffchainOracle { + return new Contract(address, _abi, signerOrProvider) as OffchainOracle; + } +} diff --git a/src/artifacts/index.ts b/src/artifacts/index.ts index b321162..5c1fcbd 100644 --- a/src/artifacts/index.ts +++ b/src/artifacts/index.ts @@ -1,6 +1,8 @@ /* Autogenerated file. Do not edit manually. */ /* tslint:disable */ /* eslint-disable */ +export type { OffchainOracle } from "./OffchainOracle"; export type { TornadoPool } from "./TornadoPool"; +export { OffchainOracle__factory } from "./factories/OffchainOracle__factory"; export { TornadoPool__factory } from "./factories/TornadoPool__factory"; diff --git a/src/constants/contracts.ts b/src/constants/contracts.ts index b4052fe..089eab3 100644 --- a/src/constants/contracts.ts +++ b/src/constants/contracts.ts @@ -4,12 +4,14 @@ export const CONTRACT_NETWORKS: { [chainId in ChainId]: string } = { // [ChainId.MAINNET]: '0x8Bfac9EF3d73cE08C7CEC339C0fE3B2e57814c1E', [ChainId.GOERLI]: '0xE2D9aF526edeB16a02FBC3B68B0eB9B534f9c114', [ChainId.OPTIMISM]: '0xcd7318c299A82E887f5180EF865a4c350dFC9fe5', - [ChainId.XDAI]: '0xf7Ca3B0522A4Db061eEeaE4A086a79E48F2aCD25', + [ChainId.XDAI]: '0x4d701A6EE8c13D3AB0d2CE4dfA773c04fa4C5933', }; export const RPC_LIST: { [chainId in ChainId]: string } = { - // [ChainId.MAINNET]: 'https://mainnet.infura.io/v3/eb6a84e726614079948e0b1efce5baa5', + [ChainId.MAINNET]: 'https://mainnet.infura.io/v3/eb6a84e726614079948e0b1efce5baa5', [ChainId.GOERLI]: 'https://eth-goerli.alchemyapi.io/v2/hlSj0EqPUuLGyyTExs6UqFKnXDrc_eOh', [ChainId.OPTIMISM]: 'https://optimism-kovan.infura.io/v3/8f786b96d16046b78e0287fa61c6fcf8', [ChainId.XDAI]: 'https://rpc.xdaichain.com', }; + +export const OFF_CHAIN_ORACLE = '0x07D91f5fb9Bf7798734C3f606dB065549F6893bb'; diff --git a/src/constants/variables.ts b/src/constants/variables.ts index d7bbc45..57938f4 100644 --- a/src/constants/variables.ts +++ b/src/constants/variables.ts @@ -43,8 +43,9 @@ const BG_ZERO = BigNumber.from(numbers.ZERO); const FIELD_SIZE = BigNumber.from('21888242871839275222246405745257275088548364400416034343698204186575808495617'); const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; +const DAI_ADDRESS = '0x6b175474e89094c44da98b954eedeac495271d0f'; -export { numbers, NETWORKS_INFO, FIELD_SIZE, BG_ZERO, ZERO_ADDRESS }; +export { numbers, NETWORKS_INFO, DAI_ADDRESS, FIELD_SIZE, BG_ZERO, ZERO_ADDRESS }; export const CONTRACT_ERRORS = [ 'Invalid merkle root', diff --git a/src/modules/api/api.service.ts b/src/modules/api/api.service.ts index d4c2bd9..36780d1 100644 --- a/src/modules/api/api.service.ts +++ b/src/modules/api/api.service.ts @@ -7,6 +7,7 @@ import { ProviderService } from '@/services'; import { ConfigService } from '@nestjs/config'; import { Transaction } from '@/types'; + @Injectable() class ApiService { constructor( diff --git a/src/modules/queue/queue.module.ts b/src/modules/queue/queue.module.ts index 85cdb0f..fee502a 100644 --- a/src/modules/queue/queue.module.ts +++ b/src/modules/queue/queue.module.ts @@ -1,7 +1,7 @@ import { BullModule } from '@nestjs/bull'; import { Module } from '@nestjs/common'; -import { GasPriceService, ProviderService } from '@/services'; +import { GasPriceService, ProviderService, OffchainPriceService } from '@/services'; import { TransactionProcessor } from './transaction.processor'; @@ -9,7 +9,7 @@ import bullConfig from '@/config/bull.config'; @Module({ imports: [BullModule.registerQueue(bullConfig())], - providers: [GasPriceService, ProviderService, TransactionProcessor], + providers: [GasPriceService, ProviderService, TransactionProcessor, OffchainPriceService], exports: [BullModule], }) export class QueueModule {} diff --git a/src/modules/queue/transaction.processor.ts b/src/modules/queue/transaction.processor.ts index c800d15..6cec662 100644 --- a/src/modules/queue/transaction.processor.ts +++ b/src/modules/queue/transaction.processor.ts @@ -7,9 +7,10 @@ import { ConfigService } from '@nestjs/config'; import { InjectQueue, Process, Processor, OnQueueActive, OnQueueCompleted, OnQueueFailed } from '@nestjs/bull'; import { Transaction } from '@/types'; +import { getToIntegerMultiplier, toWei } from '@/utilities'; import { numbers, CONTRACT_ERRORS, jobStatus } from '@/constants'; -import { getToIntegerMultiplier } from '@/utilities'; -import { GasPriceService, ProviderService } from '@/services'; +import { GasPriceService, ProviderService, OffchainPriceService } from '@/services'; + import txMangerConfig from '@/config/txManager.config'; import { BaseProcessor } from './base.processor'; @@ -19,9 +20,10 @@ import { BaseProcessor } from './base.processor'; export class TransactionProcessor extends BaseProcessor { constructor( @InjectQueue('transaction') public transactionQueue: Queue, + private configService: ConfigService, private gasPriceService: GasPriceService, private providerService: ProviderService, - private configService: ConfigService, + private offChainPriceService: OffchainPriceService, ) { super(); this.queueName = 'transaction'; @@ -132,13 +134,15 @@ export class TransactionProcessor extends BaseProcessor { async checkFee({ fee, externalAmount }) { const { gasLimit } = this.configService.get('base'); - const { fast } = await this.gasPriceService.getGasPrice(); - const expense = BigNumber.from(fast).mul(gasLimit); + const operationFee = BigNumber.from(fast).mul(gasLimit); const feePercent = this.getServiceFee(externalAmount); + const ethPrice = await this.offChainPriceService.getDaiEthPrice(); + + const expense = operationFee.mul(ethPrice).div(toWei('1')); const desiredFee = expense.add(feePercent); if (BigNumber.from(fee).lt(desiredFee)) { diff --git a/src/services/oracle.service.ts b/src/services/gas-price.service.ts similarity index 90% rename from src/services/oracle.service.ts rename to src/services/gas-price.service.ts index 11de71b..d692eee 100644 --- a/src/services/oracle.service.ts +++ b/src/services/gas-price.service.ts @@ -30,8 +30,8 @@ export class GasPriceService { const bnGas = BigNumber.from(toWei(String(fast), 'gwei')); return { - instant: bnGas.mul(130).div(100).toHexString(), - fast: bnGas, + instant: bnGas.mul(150).div(100).toHexString(), + fast: bnGas.mul(130).div(100).toHexString(), standard: bnGas.mul(85).div(100).toHexString(), low: bnGas.mul(50).div(100).toHexString(), }; diff --git a/src/services/index.ts b/src/services/index.ts index d8656bc..a99ab18 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -1,2 +1,4 @@ -export * from './oracle.service'; export * from './provider.service'; + +export * from './gas-price.service'; +export * from './offchain-price.service'; diff --git a/src/services/offchain-price.service.ts b/src/services/offchain-price.service.ts new file mode 100644 index 0000000..53ac76c --- /dev/null +++ b/src/services/offchain-price.service.ts @@ -0,0 +1,30 @@ +import { Injectable } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; + +import { BigNumber } from 'ethers'; + +import { ChainId } from '@/types'; +import { DAI_ADDRESS } from '@/constants'; +import { ProviderService } from '@/services'; +import { toWei } from '@/utilities'; + +@Injectable() +export class OffchainPriceService { + private readonly chainId: number; + + constructor(private configService: ConfigService, private providerService: ProviderService) { + this.chainId = ChainId.MAINNET; + } + + async getDaiEthPrice() { + const contract = this.providerService.getOffChainOracle(); + + const rate = await contract.callStatic.getRateToEth(DAI_ADDRESS, false); + + const numerator = BigNumber.from(toWei('1')); + const denominator = BigNumber.from(toWei('1')); + + // price = rate * "token decimals" / "eth decimals" (dai = eth decimals) + return BigNumber.from(rate).mul(numerator).div(denominator); + } +} diff --git a/src/services/provider.service.ts b/src/services/provider.service.ts index 5ae07a4..315e211 100644 --- a/src/services/provider.service.ts +++ b/src/services/provider.service.ts @@ -2,8 +2,9 @@ import { ethers } from 'ethers'; import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; -import { CONTRACT_NETWORKS, RPC_LIST } from '@/constants'; -import { TornadoPool__factory as TornadoPoolFactory } from '@/artifacts'; +import { ChainId } from '@/types'; +import { CONTRACT_NETWORKS, OFF_CHAIN_ORACLE, RPC_LIST } from '@/constants'; +import { TornadoPool__factory as TornadoPool, OffchainOracle__factory as OffchainOracle } from '@/artifacts'; @Injectable() export class ProviderService { @@ -20,7 +21,12 @@ export class ProviderService { } getTornadoPool() { - return TornadoPoolFactory.connect(CONTRACT_NETWORKS[this.chainId], this.getProviderWithSigner()); + return TornadoPool.connect(CONTRACT_NETWORKS[this.chainId], this.getProviderWithSigner()); + } + + getOffChainOracle() { + const provider = ethers.providers.getDefaultProvider(RPC_LIST[ChainId.MAINNET]); + return OffchainOracle.connect(OFF_CHAIN_ORACLE, provider); } async checkSenderBalance() {