From b1628bbd884e8b65a0b74398e148022a1658fccb Mon Sep 17 00:00:00 2001 From: Leandro Boscariol Date: Wed, 22 Dec 2021 05:20:50 -0800 Subject: [PATCH] vCow contracts (#2029) * Added vCow contract json abi * Added generated types for vCow contract * Added temporary rinkeby contract address * Added hook useVCowContract * Shaved off most of vCow ABI and left only a minimal set * Reset generated file to previous formating Co-authored-by: Leandro Boscariol --- src/custom/abis/types/VCow.d.ts | 304 ++++++++++++++++++ .../abis/types/factories/VCow__factory.ts | 170 ++++++++++ src/custom/abis/types/index.ts | 2 + src/custom/abis/vCow.json | 152 +++++++++ src/custom/constants/index.ts | 8 + src/custom/hooks/useContract.ts | 10 +- 6 files changed, 644 insertions(+), 2 deletions(-) create mode 100644 src/custom/abis/types/VCow.d.ts create mode 100644 src/custom/abis/types/factories/VCow__factory.ts create mode 100644 src/custom/abis/vCow.json diff --git a/src/custom/abis/types/VCow.d.ts b/src/custom/abis/types/VCow.d.ts new file mode 100644 index 000000000..53ef9b8d6 --- /dev/null +++ b/src/custom/abis/types/VCow.d.ts @@ -0,0 +1,304 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { + ethers, + EventFilter, + Signer, + BigNumber, + BigNumberish, + PopulatedTransaction, + BaseContract, + ContractTransaction, + 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 VCowInterface extends ethers.utils.Interface { + functions: { + "claim(uint256,uint8,address,uint256,uint256,bytes32[])": FunctionFragment; + "claimMany(uint256[],uint8[],address[],uint256[],uint256[],bytes32[][],uint256[])": FunctionFragment; + "isClaimed(uint256)": FunctionFragment; + "merkleRoot()": FunctionFragment; + }; + + encodeFunctionData( + functionFragment: "claim", + values: [ + BigNumberish, + BigNumberish, + string, + BigNumberish, + BigNumberish, + BytesLike[] + ] + ): string; + encodeFunctionData( + functionFragment: "claimMany", + values: [ + BigNumberish[], + BigNumberish[], + string[], + BigNumberish[], + BigNumberish[], + BytesLike[][], + BigNumberish[] + ] + ): string; + encodeFunctionData( + functionFragment: "isClaimed", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "merkleRoot", + values?: undefined + ): string; + + decodeFunctionResult(functionFragment: "claim", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "claimMany", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "isClaimed", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "merkleRoot", data: BytesLike): Result; + + events: { + "Claimed(uint256,uint8,address,uint256,uint256)": EventFragment; + }; + + getEvent(nameOrSignatureOrTopic: "Claimed"): EventFragment; +} + +export type ClaimedEvent = TypedEvent< + [BigNumber, number, string, BigNumber, BigNumber] & { + index: BigNumber; + claimType: number; + claimant: string; + claimableAmount: BigNumber; + claimedAmount: BigNumber; + } +>; + +export class VCow 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: VCowInterface; + + functions: { + claim( + index: BigNumberish, + claimType: BigNumberish, + claimant: string, + claimableAmount: BigNumberish, + claimedAmount: BigNumberish, + merkleProof: BytesLike[], + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + claimMany( + indices: BigNumberish[], + claimTypes: BigNumberish[], + claimants: string[], + claimableAmounts: BigNumberish[], + claimedAmounts: BigNumberish[], + merkleProofs: BytesLike[][], + sentEth: BigNumberish[], + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + isClaimed( + index: BigNumberish, + overrides?: CallOverrides + ): Promise<[boolean]>; + + merkleRoot(overrides?: CallOverrides): Promise<[string]>; + }; + + claim( + index: BigNumberish, + claimType: BigNumberish, + claimant: string, + claimableAmount: BigNumberish, + claimedAmount: BigNumberish, + merkleProof: BytesLike[], + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + claimMany( + indices: BigNumberish[], + claimTypes: BigNumberish[], + claimants: string[], + claimableAmounts: BigNumberish[], + claimedAmounts: BigNumberish[], + merkleProofs: BytesLike[][], + sentEth: BigNumberish[], + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + isClaimed(index: BigNumberish, overrides?: CallOverrides): Promise; + + merkleRoot(overrides?: CallOverrides): Promise; + + callStatic: { + claim( + index: BigNumberish, + claimType: BigNumberish, + claimant: string, + claimableAmount: BigNumberish, + claimedAmount: BigNumberish, + merkleProof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + claimMany( + indices: BigNumberish[], + claimTypes: BigNumberish[], + claimants: string[], + claimableAmounts: BigNumberish[], + claimedAmounts: BigNumberish[], + merkleProofs: BytesLike[][], + sentEth: BigNumberish[], + overrides?: CallOverrides + ): Promise; + + isClaimed(index: BigNumberish, overrides?: CallOverrides): Promise; + + merkleRoot(overrides?: CallOverrides): Promise; + }; + + filters: { + "Claimed(uint256,uint8,address,uint256,uint256)"( + index?: null, + claimType?: null, + claimant?: null, + claimableAmount?: null, + claimedAmount?: null + ): TypedEventFilter< + [BigNumber, number, string, BigNumber, BigNumber], + { + index: BigNumber; + claimType: number; + claimant: string; + claimableAmount: BigNumber; + claimedAmount: BigNumber; + } + >; + + Claimed( + index?: null, + claimType?: null, + claimant?: null, + claimableAmount?: null, + claimedAmount?: null + ): TypedEventFilter< + [BigNumber, number, string, BigNumber, BigNumber], + { + index: BigNumber; + claimType: number; + claimant: string; + claimableAmount: BigNumber; + claimedAmount: BigNumber; + } + >; + }; + + estimateGas: { + claim( + index: BigNumberish, + claimType: BigNumberish, + claimant: string, + claimableAmount: BigNumberish, + claimedAmount: BigNumberish, + merkleProof: BytesLike[], + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + claimMany( + indices: BigNumberish[], + claimTypes: BigNumberish[], + claimants: string[], + claimableAmounts: BigNumberish[], + claimedAmounts: BigNumberish[], + merkleProofs: BytesLike[][], + sentEth: BigNumberish[], + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + isClaimed( + index: BigNumberish, + overrides?: CallOverrides + ): Promise; + + merkleRoot(overrides?: CallOverrides): Promise; + }; + + populateTransaction: { + claim( + index: BigNumberish, + claimType: BigNumberish, + claimant: string, + claimableAmount: BigNumberish, + claimedAmount: BigNumberish, + merkleProof: BytesLike[], + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + claimMany( + indices: BigNumberish[], + claimTypes: BigNumberish[], + claimants: string[], + claimableAmounts: BigNumberish[], + claimedAmounts: BigNumberish[], + merkleProofs: BytesLike[][], + sentEth: BigNumberish[], + overrides?: PayableOverrides & { from?: string | Promise } + ): Promise; + + isClaimed( + index: BigNumberish, + overrides?: CallOverrides + ): Promise; + + merkleRoot(overrides?: CallOverrides): Promise; + }; +} diff --git a/src/custom/abis/types/factories/VCow__factory.ts b/src/custom/abis/types/factories/VCow__factory.ts new file mode 100644 index 000000000..c942e62af --- /dev/null +++ b/src/custom/abis/types/factories/VCow__factory.ts @@ -0,0 +1,170 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer, utils } from "ethers"; +import { Provider } from "@ethersproject/providers"; +import type { VCow, VCowInterface } from "../VCow"; + +const _abi = [ + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "uint256", + name: "index", + type: "uint256", + }, + { + indexed: false, + internalType: "enum ClaimingInterface.ClaimType", + name: "claimType", + type: "uint8", + }, + { + indexed: false, + internalType: "address", + name: "claimant", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "claimableAmount", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "claimedAmount", + type: "uint256", + }, + ], + name: "Claimed", + type: "event", + }, + { + inputs: [ + { + internalType: "uint256", + name: "index", + type: "uint256", + }, + { + internalType: "enum ClaimingInterface.ClaimType", + name: "claimType", + type: "uint8", + }, + { + internalType: "address", + name: "claimant", + type: "address", + }, + { + internalType: "uint256", + name: "claimableAmount", + type: "uint256", + }, + { + internalType: "uint256", + name: "claimedAmount", + type: "uint256", + }, + { + internalType: "bytes32[]", + name: "merkleProof", + type: "bytes32[]", + }, + ], + name: "claim", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256[]", + name: "indices", + type: "uint256[]", + }, + { + internalType: "enum ClaimingInterface.ClaimType[]", + name: "claimTypes", + type: "uint8[]", + }, + { + internalType: "address[]", + name: "claimants", + type: "address[]", + }, + { + internalType: "uint256[]", + name: "claimableAmounts", + type: "uint256[]", + }, + { + internalType: "uint256[]", + name: "claimedAmounts", + type: "uint256[]", + }, + { + internalType: "bytes32[][]", + name: "merkleProofs", + type: "bytes32[][]", + }, + { + internalType: "uint256[]", + name: "sentEth", + type: "uint256[]", + }, + ], + name: "claimMany", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "index", + type: "uint256", + }, + ], + name: "isClaimed", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "merkleRoot", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, +]; + +export class VCow__factory { + static readonly abi = _abi; + static createInterface(): VCowInterface { + return new utils.Interface(_abi) as VCowInterface; + } + static connect(address: string, signerOrProvider: Signer | Provider): VCow { + return new Contract(address, _abi, signerOrProvider) as VCow; + } +} diff --git a/src/custom/abis/types/index.ts b/src/custom/abis/types/index.ts index 0d2194a41..8c555de40 100644 --- a/src/custom/abis/types/index.ts +++ b/src/custom/abis/types/index.ts @@ -2,7 +2,9 @@ /* tslint:disable */ /* eslint-disable */ export type { GPv2Settlement } from './GPv2Settlement' +export type { VCow } from './VCow' export { GPv2Settlement__factory } from './factories/GPv2Settlement__factory' +export { VCow__factory } from './factories/VCow__factory' export * from '@src/abis/types' diff --git a/src/custom/abis/vCow.json b/src/custom/abis/vCow.json new file mode 100644 index 000000000..a9d9a6f5c --- /dev/null +++ b/src/custom/abis/vCow.json @@ -0,0 +1,152 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "index", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "enum ClaimingInterface.ClaimType", + "name": "claimType", + "type": "uint8" + }, + { + "indexed": false, + "internalType": "address", + "name": "claimant", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "claimableAmount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "claimedAmount", + "type": "uint256" + } + ], + "name": "Claimed", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + }, + { + "internalType": "enum ClaimingInterface.ClaimType", + "name": "claimType", + "type": "uint8" + }, + { + "internalType": "address", + "name": "claimant", + "type": "address" + }, + { + "internalType": "uint256", + "name": "claimableAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "claimedAmount", + "type": "uint256" + }, + { + "internalType": "bytes32[]", + "name": "merkleProof", + "type": "bytes32[]" + } + ], + "name": "claim", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256[]", + "name": "indices", + "type": "uint256[]" + }, + { + "internalType": "enum ClaimingInterface.ClaimType[]", + "name": "claimTypes", + "type": "uint8[]" + }, + { + "internalType": "address[]", + "name": "claimants", + "type": "address[]" + }, + { + "internalType": "uint256[]", + "name": "claimableAmounts", + "type": "uint256[]" + }, + { + "internalType": "uint256[]", + "name": "claimedAmounts", + "type": "uint256[]" + }, + { + "internalType": "bytes32[][]", + "name": "merkleProofs", + "type": "bytes32[][]" + }, + { + "internalType": "uint256[]", + "name": "sentEth", + "type": "uint256[]" + } + ], + "name": "claimMany", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "isClaimed", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "merkleRoot", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/src/custom/constants/index.ts b/src/custom/constants/index.ts index a695fe2d3..d2a7508a6 100644 --- a/src/custom/constants/index.ts +++ b/src/custom/constants/index.ts @@ -52,6 +52,14 @@ export const GP_VAULT_RELAYER: Partial> = { [ChainId.XDAI]: GPv2VaultRelayer[ChainId.XDAI].address, } +export const V_COW_CONTRACT_ADDRESS: Partial> = { + // TODO: load addresses from contract package when available + // [ChainId.MAINNET]: GPv2Settlement[ChainId.MAINNET].address, + // [ChainId.RINKEBY]: GPv2Settlement[ChainId.RINKEBY].address, + // [ChainId.XDAI]: GPv2Settlement[ChainId.XDAI].address, + [ChainId.RINKEBY]: '0x8f07778b703f9feb93521fc5230e859dbd032b6b', +} + // See https://github.com/gnosis/gp-v2-contracts/commit/821b5a8da213297b0f7f1d8b17c893c5627020af#diff-12bbbe13cd5cf42d639e34a39d8795021ba40d3ee1e1a8282df652eb161a11d6R13 export const NATIVE_CURRENCY_BUY_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE' export const NATIVE_CURRENCY_BUY_TOKEN: { [chainId in ChainId | number]: Token } = { diff --git a/src/custom/hooks/useContract.ts b/src/custom/hooks/useContract.ts index 8dfd0d40c..a4d49afd2 100644 --- a/src/custom/hooks/useContract.ts +++ b/src/custom/hooks/useContract.ts @@ -4,7 +4,7 @@ import { useActiveWeb3React } from 'hooks/web3' import { useContract } from '@src/hooks/useContract' -import { GP_SETTLEMENT_CONTRACT_ADDRESS } from 'constants/index' +import { GP_SETTLEMENT_CONTRACT_ADDRESS, V_COW_CONTRACT_ADDRESS } from 'constants/index' import { SupportedChainId as ChainId } from 'constants/chains' import ENS_ABI from 'abis/ens-registrar.json' @@ -12,8 +12,9 @@ import { getContract } from 'utils' import ERC20_ABI from 'abis/erc20.json' import ERC20_BYTES32_ABI from 'abis/erc20_bytes32.json' -import { GPv2Settlement, Erc20 } from 'abis/types' +import { GPv2Settlement, Erc20, VCow } from 'abis/types' import GPv2_SETTLEMENT_ABI from 'abis/GPv2Settlement.json' +import V_COW_ABI from 'abis/vCow.json' export * from '@src/hooks/useContract' @@ -26,6 +27,11 @@ export function useGP2SettlementContract(): GPv2Settlement | null { ) } +export function useVCowContract() { + const { chainId } = useActiveWeb3React() + return useContract(chainId ? V_COW_CONTRACT_ADDRESS[chainId] : undefined, V_COW_ABI, true) +} + export function useENSRegistrarContract(withSignerIfPossible?: boolean): Contract | null { const { chainId } = useActiveWeb3React() let address: string | undefined