From e09f7b079da87651af3b65bb41858f0f759800ae Mon Sep 17 00:00:00 2001 From: yep Date: Mon, 4 Dec 2023 18:09:15 +0800 Subject: [PATCH] CD-1921 update sdk --- abis/ERC1155.json | 196 ++++++++ abis/ERC721.json | 157 ++++++- abis/PaymentPlanV2.json | 251 +++++++++++ src/api.ts | 29 +- src/contracts/ERC1155.ts | 420 ++++++++++++++++++ src/contracts/ERC721.ts | 286 +++++++++++- src/contracts/PaymentPlanV2.ts | 224 ++++++++++ src/contracts/factories/ERC1155__factory.ts | 217 +++++++++ src/contracts/factories/ERC721__factory.ts | 153 ++++++- .../factories/PaymentPlanV2__factory.ts | 251 +++++++++++ src/contracts/factories/index.ts | 1 + src/contracts/index.ts | 2 + src/sdk.ts | 166 ++++++- src/types.ts | 120 ++++- 14 files changed, 2451 insertions(+), 22 deletions(-) create mode 100644 abis/ERC1155.json create mode 100644 src/contracts/ERC1155.ts create mode 100644 src/contracts/factories/ERC1155__factory.ts diff --git a/abis/ERC1155.json b/abis/ERC1155.json new file mode 100644 index 0000000..fed5f2e --- /dev/null +++ b/abis/ERC1155.json @@ -0,0 +1,196 @@ +[ + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "internalType": "uint256", + "name": "id", + "type": "uint256" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address[]", + "name": "accounts", + "type": "address[]" + }, + { + "internalType": "uint256[]", + "name": "ids", + "type": "uint256[]" + } + ], + "name": "balanceOfBatch", + "outputs": [ + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "internalType": "address", + "name": "operator", + "type": "address" + } + ], + "name": "isApprovedForAll", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256[]", + "name": "ids", + "type": "uint256[]" + }, + { + "internalType": "uint256[]", + "name": "amounts", + "type": "uint256[]" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "safeBatchTransferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "id", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "safeTransferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "operator", + "type": "address" + }, + { + "internalType": "bool", + "name": "approved", + "type": "bool" + } + ], + "name": "setApprovalForAll", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes4", + "name": "interfaceId", + "type": "bytes4" + } + ], + "name": "supportsInterface", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "id", + "type": "uint256" + } + ], + "name": "uri", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/abis/ERC721.json b/abis/ERC721.json index 69013e5..d4fdf8a 100644 --- a/abis/ERC721.json +++ b/abis/ERC721.json @@ -14,10 +14,98 @@ ], "name": "approve", "outputs": [], - "stateMutability": "nonpayable", "type": "function" }, { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "safeTransferFrom", + "outputs": [], + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "bool", + "name": "approved", + "type": "bool" + } + ], + "name": "setApprovalForAll", + "outputs": [], + + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [], + + "type": "function" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "constant": true, "inputs": [ { "internalType": "uint256", @@ -33,6 +121,73 @@ "type": "address" } ], + + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "operator", + "type": "address" + } + ], + "name": "isApprovedForAll", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "ownerOf", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes4", + "name": "interfaceId", + "type": "bytes4" + } + ], + "name": "supportsInterface", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], "stateMutability": "view", "type": "function" } diff --git a/abis/PaymentPlanV2.json b/abis/PaymentPlanV2.json index 08877d7..3d956fa 100644 --- a/abis/PaymentPlanV2.json +++ b/abis/PaymentPlanV2.json @@ -470,5 +470,256 @@ ], "stateMutability": "view", "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "planId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "sellPrice", + "type": "uint256" + }, + { + "components": [ + { + "components": [ + { + "components": [ + { + "internalType": "address", + "name": "offerer", + "type": "address" + }, + { + "internalType": "address", + "name": "zone", + "type": "address" + }, + { + "components": [ + { + "internalType": "enum ISeaport.ItemType", + "name": "itemType", + "type": "uint8" + }, + { + "internalType": "address", + "name": "token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "identifierOrCriteria", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "startAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "endAmount", + "type": "uint256" + } + ], + "internalType": "struct ISeaport.OfferItem[]", + "name": "offer", + "type": "tuple[]" + }, + { + "components": [ + { + "internalType": "enum ISeaport.ItemType", + "name": "itemType", + "type": "uint8" + }, + { + "internalType": "address", + "name": "token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "identifierOrCriteria", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "startAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "endAmount", + "type": "uint256" + }, + { + "internalType": "address payable", + "name": "recipient", + "type": "address" + } + ], + "internalType": "struct ISeaport.ConsiderationItem[]", + "name": "consideration", + "type": "tuple[]" + }, + { + "internalType": "enum ISeaport.OrderType", + "name": "orderType", + "type": "uint8" + }, + { + "internalType": "uint256", + "name": "startTime", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "endTime", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "zoneHash", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "salt", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "conduitKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "totalOriginalConsiderationItems", + "type": "uint256" + } + ], + "internalType": "struct ISeaport.OrderParameters", + "name": "parameters", + "type": "tuple" + }, + { + "internalType": "uint120", + "name": "numerator", + "type": "uint120" + }, + { + "internalType": "uint120", + "name": "denominator", + "type": "uint120" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "extraData", + "type": "bytes" + } + ], + "internalType": "struct ISeaport.AdvancedOrder[]", + "name": "orders", + "type": "tuple[]" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "orderIndex", + "type": "uint256" + }, + { + "internalType": "enum ISeaport.Side", + "name": "side", + "type": "uint8" + }, + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "identifier", + "type": "uint256" + }, + { + "internalType": "bytes32[]", + "name": "criteriaProof", + "type": "bytes32[]" + } + ], + "internalType": "struct ISeaport.CriteriaResolver[]", + "name": "criteriaResolvers", + "type": "tuple[]" + }, + { + "components": [ + { + "components": [ + { + "internalType": "uint256", + "name": "orderIndex", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "itemIndex", + "type": "uint256" + } + ], + "internalType": "struct ISeaport.FulfillmentComponent[]", + "name": "offerComponents", + "type": "tuple[]" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "orderIndex", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "itemIndex", + "type": "uint256" + } + ], + "internalType": "struct ISeaport.FulfillmentComponent[]", + "name": "considerationComponents", + "type": "tuple[]" + } + ], + "internalType": "struct ISeaport.Fulfillment[]", + "name": "fulfillments", + "type": "tuple[]" + }, + { + "internalType": "address", + "name": "recipient", + "type": "address" + } + ], + "internalType": "struct ISeaport.OfferData", + "name": "offer", + "type": "tuple" + } + ], + "name": "earlyUnwind", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" } ] diff --git a/src/api.ts b/src/api.ts index 4170838..a3cc95e 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,5 +1,14 @@ import { BigNumber } from 'ethers'; -import { IConfigs, ICreateAcceptance, IPlan, IPricerStep1, IPricerStep2 } from './types'; +import { + IConfigs, + ICreateAcceptance, + IFulfillOffer, + IGetCollectionTopBid, + IOffer, + IPlan, + IPricerStep1, + IPricerStep2, +} from './types'; import { HttpError } from './errors'; export class CyanAPI { @@ -103,4 +112,22 @@ export class CyanAPI { public async getUserPlans(address: string): Promise { return await this.fetchData(`/v2/plans?wallet=${address}`); } + + public async getCollectionTopBid(body: IGetCollectionTopBid['request']): Promise { + const { collectionAddress, tokenId, chain } = body; + const queryParams = new URLSearchParams({ + chain: chain as string, + }); + if (tokenId) queryParams.append('tokenId', tokenId); + return await this.fetchData(`/v2/collections/${collectionAddress}/top-bid?${queryParams}`); + } + + public async getFulfillOffer(body: IFulfillOffer['request']): Promise { + const { planId, chain, offerHash } = body; + const queryParams = new URLSearchParams({ + chain: chain as string, + offerHash, + }); + return await this.fetchData(`/v2/plans/${planId}/fulfill-offer?${queryParams}`); + } } diff --git a/src/contracts/ERC1155.ts b/src/contracts/ERC1155.ts new file mode 100644 index 0000000..44211b5 --- /dev/null +++ b/src/contracts/ERC1155.ts @@ -0,0 +1,420 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + BaseContract, + BigNumber, + BigNumberish, + BytesLike, + CallOverrides, + ContractTransaction, + Overrides, + PopulatedTransaction, + Signer, + utils, +} from "ethers"; +import type { FunctionFragment, Result } from "@ethersproject/abi"; +import type { Listener, Provider } from "@ethersproject/providers"; +import type { + TypedEventFilter, + TypedEvent, + TypedListener, + OnEvent, + PromiseOrValue, +} from "./common"; + +export interface ERC1155Interface extends utils.Interface { + functions: { + "balanceOf(address,uint256)": FunctionFragment; + "balanceOfBatch(address[],uint256[])": FunctionFragment; + "isApprovedForAll(address,address)": FunctionFragment; + "safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)": FunctionFragment; + "safeTransferFrom(address,address,uint256,uint256,bytes)": FunctionFragment; + "setApprovalForAll(address,bool)": FunctionFragment; + "supportsInterface(bytes4)": FunctionFragment; + "uri(uint256)": FunctionFragment; + }; + + getFunction( + nameOrSignatureOrTopic: + | "balanceOf" + | "balanceOfBatch" + | "isApprovedForAll" + | "safeBatchTransferFrom" + | "safeTransferFrom" + | "setApprovalForAll" + | "supportsInterface" + | "uri" + ): FunctionFragment; + + encodeFunctionData( + functionFragment: "balanceOf", + values: [PromiseOrValue, PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "balanceOfBatch", + values: [PromiseOrValue[], PromiseOrValue[]] + ): string; + encodeFunctionData( + functionFragment: "isApprovedForAll", + values: [PromiseOrValue, PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "safeBatchTransferFrom", + values: [ + PromiseOrValue, + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue[], + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "safeTransferFrom", + values: [ + PromiseOrValue, + PromiseOrValue, + PromiseOrValue, + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "setApprovalForAll", + values: [PromiseOrValue, PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "supportsInterface", + values: [PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "uri", + values: [PromiseOrValue] + ): string; + + decodeFunctionResult(functionFragment: "balanceOf", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "balanceOfBatch", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "isApprovedForAll", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "safeBatchTransferFrom", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "safeTransferFrom", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "setApprovalForAll", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "supportsInterface", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "uri", data: BytesLike): Result; + + events: {}; +} + +export interface ERC1155 extends BaseContract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + interface: ERC1155Interface; + + queryFilter( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>; + + listeners( + eventFilter?: TypedEventFilter + ): Array>; + listeners(eventName?: string): Array; + removeAllListeners( + eventFilter: TypedEventFilter + ): this; + removeAllListeners(eventName?: string): this; + off: OnEvent; + on: OnEvent; + once: OnEvent; + removeListener: OnEvent; + + functions: { + balanceOf( + account: PromiseOrValue, + id: PromiseOrValue, + overrides?: CallOverrides + ): Promise<[BigNumber]>; + + balanceOfBatch( + accounts: PromiseOrValue[], + ids: PromiseOrValue[], + overrides?: CallOverrides + ): Promise<[BigNumber[]]>; + + isApprovedForAll( + account: PromiseOrValue, + operator: PromiseOrValue, + overrides?: CallOverrides + ): Promise<[boolean]>; + + safeBatchTransferFrom( + from: PromiseOrValue, + to: PromiseOrValue, + ids: PromiseOrValue[], + amounts: PromiseOrValue[], + data: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + safeTransferFrom( + from: PromiseOrValue, + to: PromiseOrValue, + id: PromiseOrValue, + amount: PromiseOrValue, + data: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setApprovalForAll( + operator: PromiseOrValue, + approved: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + supportsInterface( + interfaceId: PromiseOrValue, + overrides?: CallOverrides + ): Promise<[boolean]>; + + uri( + id: PromiseOrValue, + overrides?: CallOverrides + ): Promise<[string]>; + }; + + balanceOf( + account: PromiseOrValue, + id: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + balanceOfBatch( + accounts: PromiseOrValue[], + ids: PromiseOrValue[], + overrides?: CallOverrides + ): Promise; + + isApprovedForAll( + account: PromiseOrValue, + operator: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + safeBatchTransferFrom( + from: PromiseOrValue, + to: PromiseOrValue, + ids: PromiseOrValue[], + amounts: PromiseOrValue[], + data: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + safeTransferFrom( + from: PromiseOrValue, + to: PromiseOrValue, + id: PromiseOrValue, + amount: PromiseOrValue, + data: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setApprovalForAll( + operator: PromiseOrValue, + approved: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + supportsInterface( + interfaceId: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + uri( + id: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + callStatic: { + balanceOf( + account: PromiseOrValue, + id: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + balanceOfBatch( + accounts: PromiseOrValue[], + ids: PromiseOrValue[], + overrides?: CallOverrides + ): Promise; + + isApprovedForAll( + account: PromiseOrValue, + operator: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + safeBatchTransferFrom( + from: PromiseOrValue, + to: PromiseOrValue, + ids: PromiseOrValue[], + amounts: PromiseOrValue[], + data: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + safeTransferFrom( + from: PromiseOrValue, + to: PromiseOrValue, + id: PromiseOrValue, + amount: PromiseOrValue, + data: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + setApprovalForAll( + operator: PromiseOrValue, + approved: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + supportsInterface( + interfaceId: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + uri( + id: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + }; + + filters: {}; + + estimateGas: { + balanceOf( + account: PromiseOrValue, + id: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + balanceOfBatch( + accounts: PromiseOrValue[], + ids: PromiseOrValue[], + overrides?: CallOverrides + ): Promise; + + isApprovedForAll( + account: PromiseOrValue, + operator: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + safeBatchTransferFrom( + from: PromiseOrValue, + to: PromiseOrValue, + ids: PromiseOrValue[], + amounts: PromiseOrValue[], + data: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + safeTransferFrom( + from: PromiseOrValue, + to: PromiseOrValue, + id: PromiseOrValue, + amount: PromiseOrValue, + data: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setApprovalForAll( + operator: PromiseOrValue, + approved: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + supportsInterface( + interfaceId: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + uri( + id: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + }; + + populateTransaction: { + balanceOf( + account: PromiseOrValue, + id: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + balanceOfBatch( + accounts: PromiseOrValue[], + ids: PromiseOrValue[], + overrides?: CallOverrides + ): Promise; + + isApprovedForAll( + account: PromiseOrValue, + operator: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + safeBatchTransferFrom( + from: PromiseOrValue, + to: PromiseOrValue, + ids: PromiseOrValue[], + amounts: PromiseOrValue[], + data: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + safeTransferFrom( + from: PromiseOrValue, + to: PromiseOrValue, + id: PromiseOrValue, + amount: PromiseOrValue, + data: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setApprovalForAll( + operator: PromiseOrValue, + approved: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + supportsInterface( + interfaceId: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + uri( + id: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + }; +} diff --git a/src/contracts/ERC721.ts b/src/contracts/ERC721.ts index 6768a1b..ea00d7c 100644 --- a/src/contracts/ERC721.ts +++ b/src/contracts/ERC721.ts @@ -13,7 +13,11 @@ import type { Signer, utils, } from "ethers"; -import type { FunctionFragment, Result } from "@ethersproject/abi"; +import type { + FunctionFragment, + Result, + EventFragment, +} from "@ethersproject/abi"; import type { Listener, Provider } from "@ethersproject/providers"; import type { TypedEventFilter, @@ -26,31 +30,114 @@ import type { export interface ERC721Interface extends utils.Interface { functions: { "approve(address,uint256)": FunctionFragment; + "safeTransferFrom(address,address,uint256)": FunctionFragment; + "setApprovalForAll(address,bool)": FunctionFragment; + "transferFrom(address,address,uint256)": FunctionFragment; "getApproved(uint256)": FunctionFragment; + "isApprovedForAll(address,address)": FunctionFragment; + "ownerOf(uint256)": FunctionFragment; + "supportsInterface(bytes4)": FunctionFragment; }; getFunction( - nameOrSignatureOrTopic: "approve" | "getApproved" + nameOrSignatureOrTopic: + | "approve" + | "safeTransferFrom" + | "setApprovalForAll" + | "transferFrom" + | "getApproved" + | "isApprovedForAll" + | "ownerOf" + | "supportsInterface" ): FunctionFragment; encodeFunctionData( functionFragment: "approve", values: [PromiseOrValue, PromiseOrValue] ): string; + encodeFunctionData( + functionFragment: "safeTransferFrom", + values: [ + PromiseOrValue, + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "setApprovalForAll", + values: [PromiseOrValue, PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "transferFrom", + values: [ + PromiseOrValue, + PromiseOrValue, + PromiseOrValue + ] + ): string; encodeFunctionData( functionFragment: "getApproved", values: [PromiseOrValue] ): string; + encodeFunctionData( + functionFragment: "isApprovedForAll", + values: [PromiseOrValue, PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "ownerOf", + values: [PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "supportsInterface", + values: [PromiseOrValue] + ): string; decodeFunctionResult(functionFragment: "approve", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "safeTransferFrom", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "setApprovalForAll", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "transferFrom", + data: BytesLike + ): Result; decodeFunctionResult( functionFragment: "getApproved", data: BytesLike ): Result; + decodeFunctionResult( + functionFragment: "isApprovedForAll", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "ownerOf", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "supportsInterface", + data: BytesLike + ): Result; - events: {}; + events: { + "Transfer(address,address,uint256)": EventFragment; + }; + + getEvent(nameOrSignatureOrTopic: "Transfer"): EventFragment; } +export interface TransferEventObject { + from: string; + to: string; + tokenId: BigNumber; +} +export type TransferEvent = TypedEvent< + [string, string, BigNumber], + TransferEventObject +>; + +export type TransferEventFilter = TypedEventFilter; + export interface ERC721 extends BaseContract { connect(signerOrProvider: Signer | Provider | string): this; attach(addressOrName: string): this; @@ -84,10 +171,46 @@ export interface ERC721 extends BaseContract { overrides?: Overrides & { from?: PromiseOrValue } ): Promise; + safeTransferFrom( + from: PromiseOrValue, + to: PromiseOrValue, + tokenId: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setApprovalForAll( + to: PromiseOrValue, + approved: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + transferFrom( + from: PromiseOrValue, + to: PromiseOrValue, + tokenId: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + getApproved( tokenId: PromiseOrValue, overrides?: CallOverrides ): Promise<[string]>; + + isApprovedForAll( + owner: PromiseOrValue, + operator: PromiseOrValue, + overrides?: CallOverrides + ): Promise<[boolean]>; + + ownerOf( + tokenId: PromiseOrValue, + overrides?: CallOverrides + ): Promise<[string]>; + + supportsInterface( + interfaceId: PromiseOrValue, + overrides?: CallOverrides + ): Promise<[boolean]>; }; approve( @@ -96,11 +219,47 @@ export interface ERC721 extends BaseContract { overrides?: Overrides & { from?: PromiseOrValue } ): Promise; + safeTransferFrom( + from: PromiseOrValue, + to: PromiseOrValue, + tokenId: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setApprovalForAll( + to: PromiseOrValue, + approved: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + transferFrom( + from: PromiseOrValue, + to: PromiseOrValue, + tokenId: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + getApproved( tokenId: PromiseOrValue, overrides?: CallOverrides ): Promise; + isApprovedForAll( + owner: PromiseOrValue, + operator: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + ownerOf( + tokenId: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + supportsInterface( + interfaceId: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + callStatic: { approve( to: PromiseOrValue, @@ -108,13 +267,60 @@ export interface ERC721 extends BaseContract { overrides?: CallOverrides ): Promise; + safeTransferFrom( + from: PromiseOrValue, + to: PromiseOrValue, + tokenId: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + setApprovalForAll( + to: PromiseOrValue, + approved: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + transferFrom( + from: PromiseOrValue, + to: PromiseOrValue, + tokenId: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + getApproved( tokenId: PromiseOrValue, overrides?: CallOverrides ): Promise; + + isApprovedForAll( + owner: PromiseOrValue, + operator: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + ownerOf( + tokenId: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + supportsInterface( + interfaceId: PromiseOrValue, + overrides?: CallOverrides + ): Promise; }; - filters: {}; + filters: { + "Transfer(address,address,uint256)"( + from?: PromiseOrValue | null, + to?: PromiseOrValue | null, + tokenId?: PromiseOrValue | null + ): TransferEventFilter; + Transfer( + from?: PromiseOrValue | null, + to?: PromiseOrValue | null, + tokenId?: PromiseOrValue | null + ): TransferEventFilter; + }; estimateGas: { approve( @@ -123,10 +329,46 @@ export interface ERC721 extends BaseContract { overrides?: Overrides & { from?: PromiseOrValue } ): Promise; + safeTransferFrom( + from: PromiseOrValue, + to: PromiseOrValue, + tokenId: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setApprovalForAll( + to: PromiseOrValue, + approved: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + transferFrom( + from: PromiseOrValue, + to: PromiseOrValue, + tokenId: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + getApproved( tokenId: PromiseOrValue, overrides?: CallOverrides ): Promise; + + isApprovedForAll( + owner: PromiseOrValue, + operator: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + ownerOf( + tokenId: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + supportsInterface( + interfaceId: PromiseOrValue, + overrides?: CallOverrides + ): Promise; }; populateTransaction: { @@ -136,9 +378,45 @@ export interface ERC721 extends BaseContract { overrides?: Overrides & { from?: PromiseOrValue } ): Promise; + safeTransferFrom( + from: PromiseOrValue, + to: PromiseOrValue, + tokenId: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setApprovalForAll( + to: PromiseOrValue, + approved: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + transferFrom( + from: PromiseOrValue, + to: PromiseOrValue, + tokenId: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + getApproved( tokenId: PromiseOrValue, overrides?: CallOverrides ): Promise; + + isApprovedForAll( + owner: PromiseOrValue, + operator: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + ownerOf( + tokenId: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + supportsInterface( + interfaceId: PromiseOrValue, + overrides?: CallOverrides + ): Promise; }; } diff --git a/src/contracts/PaymentPlanV2.ts b/src/contracts/PaymentPlanV2.ts index d4b19e2..82ae235 100644 --- a/src/contracts/PaymentPlanV2.ts +++ b/src/contracts/PaymentPlanV2.ts @@ -79,6 +79,181 @@ export declare namespace CyanPaymentPlanV2 { }; } +export declare namespace ISeaport { + export type OfferItemStruct = { + itemType: PromiseOrValue; + token: PromiseOrValue; + identifierOrCriteria: PromiseOrValue; + startAmount: PromiseOrValue; + endAmount: PromiseOrValue; + }; + + export type OfferItemStructOutput = [ + number, + string, + BigNumber, + BigNumber, + BigNumber + ] & { + itemType: number; + token: string; + identifierOrCriteria: BigNumber; + startAmount: BigNumber; + endAmount: BigNumber; + }; + + export type ConsiderationItemStruct = { + itemType: PromiseOrValue; + token: PromiseOrValue; + identifierOrCriteria: PromiseOrValue; + startAmount: PromiseOrValue; + endAmount: PromiseOrValue; + recipient: PromiseOrValue; + }; + + export type ConsiderationItemStructOutput = [ + number, + string, + BigNumber, + BigNumber, + BigNumber, + string + ] & { + itemType: number; + token: string; + identifierOrCriteria: BigNumber; + startAmount: BigNumber; + endAmount: BigNumber; + recipient: string; + }; + + export type OrderParametersStruct = { + offerer: PromiseOrValue; + zone: PromiseOrValue; + offer: ISeaport.OfferItemStruct[]; + consideration: ISeaport.ConsiderationItemStruct[]; + orderType: PromiseOrValue; + startTime: PromiseOrValue; + endTime: PromiseOrValue; + zoneHash: PromiseOrValue; + salt: PromiseOrValue; + conduitKey: PromiseOrValue; + totalOriginalConsiderationItems: PromiseOrValue; + }; + + export type OrderParametersStructOutput = [ + string, + string, + ISeaport.OfferItemStructOutput[], + ISeaport.ConsiderationItemStructOutput[], + number, + BigNumber, + BigNumber, + string, + BigNumber, + string, + BigNumber + ] & { + offerer: string; + zone: string; + offer: ISeaport.OfferItemStructOutput[]; + consideration: ISeaport.ConsiderationItemStructOutput[]; + orderType: number; + startTime: BigNumber; + endTime: BigNumber; + zoneHash: string; + salt: BigNumber; + conduitKey: string; + totalOriginalConsiderationItems: BigNumber; + }; + + export type AdvancedOrderStruct = { + parameters: ISeaport.OrderParametersStruct; + numerator: PromiseOrValue; + denominator: PromiseOrValue; + signature: PromiseOrValue; + extraData: PromiseOrValue; + }; + + export type AdvancedOrderStructOutput = [ + ISeaport.OrderParametersStructOutput, + BigNumber, + BigNumber, + string, + string + ] & { + parameters: ISeaport.OrderParametersStructOutput; + numerator: BigNumber; + denominator: BigNumber; + signature: string; + extraData: string; + }; + + export type CriteriaResolverStruct = { + orderIndex: PromiseOrValue; + side: PromiseOrValue; + index: PromiseOrValue; + identifier: PromiseOrValue; + criteriaProof: PromiseOrValue[]; + }; + + export type CriteriaResolverStructOutput = [ + BigNumber, + number, + BigNumber, + BigNumber, + string[] + ] & { + orderIndex: BigNumber; + side: number; + index: BigNumber; + identifier: BigNumber; + criteriaProof: string[]; + }; + + export type FulfillmentComponentStruct = { + orderIndex: PromiseOrValue; + itemIndex: PromiseOrValue; + }; + + export type FulfillmentComponentStructOutput = [BigNumber, BigNumber] & { + orderIndex: BigNumber; + itemIndex: BigNumber; + }; + + export type FulfillmentStruct = { + offerComponents: ISeaport.FulfillmentComponentStruct[]; + considerationComponents: ISeaport.FulfillmentComponentStruct[]; + }; + + export type FulfillmentStructOutput = [ + ISeaport.FulfillmentComponentStructOutput[], + ISeaport.FulfillmentComponentStructOutput[] + ] & { + offerComponents: ISeaport.FulfillmentComponentStructOutput[]; + considerationComponents: ISeaport.FulfillmentComponentStructOutput[]; + }; + + export type OfferDataStruct = { + orders: ISeaport.AdvancedOrderStruct[]; + criteriaResolvers: ISeaport.CriteriaResolverStruct[]; + fulfillments: ISeaport.FulfillmentStruct[]; + recipient: PromiseOrValue; + }; + + export type OfferDataStructOutput = [ + ISeaport.AdvancedOrderStructOutput[], + ISeaport.CriteriaResolverStructOutput[], + ISeaport.FulfillmentStructOutput[], + string + ] & { + orders: ISeaport.AdvancedOrderStructOutput[]; + criteriaResolvers: ISeaport.CriteriaResolverStructOutput[]; + fulfillments: ISeaport.FulfillmentStructOutput[]; + recipient: string; + }; +} + export interface PaymentPlanV2Interface extends utils.Interface { functions: { "createPawn((uint256,uint256,address,address,uint8),(uint256,uint32,uint32,uint32,uint32,uint8,uint8,uint8),uint256,uint256,bytes)": FunctionFragment; @@ -87,6 +262,7 @@ export interface PaymentPlanV2Interface extends utils.Interface { "getExpectedPlan((uint256,uint32,uint32,uint32,uint32,uint8,uint8,uint8))": FunctionFragment; "getPaymentInfoByPlanId(uint256,bool)": FunctionFragment; "getCurrencyAddressByPlanId(uint256)": FunctionFragment; + "earlyUnwind(uint256,uint256,(((address,address,(uint8,address,uint256,uint256,uint256)[],(uint8,address,uint256,uint256,uint256,address)[],uint8,uint256,uint256,bytes32,uint256,bytes32,uint256),uint120,uint120,bytes,bytes)[],(uint256,uint8,uint256,uint256,bytes32[])[],((uint256,uint256)[],(uint256,uint256)[])[],address))": FunctionFragment; }; getFunction( @@ -97,6 +273,7 @@ export interface PaymentPlanV2Interface extends utils.Interface { | "getExpectedPlan" | "getPaymentInfoByPlanId" | "getCurrencyAddressByPlanId" + | "earlyUnwind" ): FunctionFragment; encodeFunctionData( @@ -135,6 +312,14 @@ export interface PaymentPlanV2Interface extends utils.Interface { functionFragment: "getCurrencyAddressByPlanId", values: [PromiseOrValue] ): string; + encodeFunctionData( + functionFragment: "earlyUnwind", + values: [ + PromiseOrValue, + PromiseOrValue, + ISeaport.OfferDataStruct + ] + ): string; decodeFunctionResult(functionFragment: "createPawn", data: BytesLike): Result; decodeFunctionResult(functionFragment: "createBNPL", data: BytesLike): Result; @@ -151,6 +336,10 @@ export interface PaymentPlanV2Interface extends utils.Interface { functionFragment: "getCurrencyAddressByPlanId", data: BytesLike ): Result; + decodeFunctionResult( + functionFragment: "earlyUnwind", + data: BytesLike + ): Result; events: {}; } @@ -221,6 +410,13 @@ export interface PaymentPlanV2 extends BaseContract { planId: PromiseOrValue, overrides?: CallOverrides ): Promise<[string]>; + + earlyUnwind( + planId: PromiseOrValue, + sellPrice: PromiseOrValue, + offer: ISeaport.OfferDataStruct, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; }; createPawn( @@ -263,6 +459,13 @@ export interface PaymentPlanV2 extends BaseContract { overrides?: CallOverrides ): Promise; + earlyUnwind( + planId: PromiseOrValue, + sellPrice: PromiseOrValue, + offer: ISeaport.OfferDataStruct, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + callStatic: { createPawn( item: CyanPaymentPlanV2.ItemStruct, @@ -303,6 +506,13 @@ export interface PaymentPlanV2 extends BaseContract { planId: PromiseOrValue, overrides?: CallOverrides ): Promise; + + earlyUnwind( + planId: PromiseOrValue, + sellPrice: PromiseOrValue, + offer: ISeaport.OfferDataStruct, + overrides?: CallOverrides + ): Promise; }; filters: {}; @@ -347,6 +557,13 @@ export interface PaymentPlanV2 extends BaseContract { planId: PromiseOrValue, overrides?: CallOverrides ): Promise; + + earlyUnwind( + planId: PromiseOrValue, + sellPrice: PromiseOrValue, + offer: ISeaport.OfferDataStruct, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; }; populateTransaction: { @@ -389,5 +606,12 @@ export interface PaymentPlanV2 extends BaseContract { planId: PromiseOrValue, overrides?: CallOverrides ): Promise; + + earlyUnwind( + planId: PromiseOrValue, + sellPrice: PromiseOrValue, + offer: ISeaport.OfferDataStruct, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; }; } diff --git a/src/contracts/factories/ERC1155__factory.ts b/src/contracts/factories/ERC1155__factory.ts new file mode 100644 index 0000000..72a36e9 --- /dev/null +++ b/src/contracts/factories/ERC1155__factory.ts @@ -0,0 +1,217 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer, utils } from "ethers"; +import type { Provider } from "@ethersproject/providers"; +import type { ERC1155, ERC1155Interface } from "../ERC1155"; + +const _abi = [ + { + inputs: [ + { + internalType: "address", + name: "account", + type: "address", + }, + { + internalType: "uint256", + name: "id", + type: "uint256", + }, + ], + name: "balanceOf", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address[]", + name: "accounts", + type: "address[]", + }, + { + internalType: "uint256[]", + name: "ids", + type: "uint256[]", + }, + ], + name: "balanceOfBatch", + outputs: [ + { + internalType: "uint256[]", + name: "", + type: "uint256[]", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "account", + type: "address", + }, + { + internalType: "address", + name: "operator", + type: "address", + }, + ], + name: "isApprovedForAll", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "from", + type: "address", + }, + { + internalType: "address", + name: "to", + type: "address", + }, + { + internalType: "uint256[]", + name: "ids", + type: "uint256[]", + }, + { + internalType: "uint256[]", + name: "amounts", + type: "uint256[]", + }, + { + internalType: "bytes", + name: "data", + type: "bytes", + }, + ], + name: "safeBatchTransferFrom", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "from", + type: "address", + }, + { + internalType: "address", + name: "to", + type: "address", + }, + { + internalType: "uint256", + name: "id", + type: "uint256", + }, + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + { + internalType: "bytes", + name: "data", + type: "bytes", + }, + ], + name: "safeTransferFrom", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "operator", + type: "address", + }, + { + internalType: "bool", + name: "approved", + type: "bool", + }, + ], + name: "setApprovalForAll", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "interfaceId", + type: "bytes4", + }, + ], + name: "supportsInterface", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "id", + type: "uint256", + }, + ], + name: "uri", + outputs: [ + { + internalType: "string", + name: "", + type: "string", + }, + ], + stateMutability: "view", + type: "function", + }, +] as const; + +export class ERC1155__factory { + static readonly abi = _abi; + static createInterface(): ERC1155Interface { + return new utils.Interface(_abi) as ERC1155Interface; + } + static connect( + address: string, + signerOrProvider: Signer | Provider + ): ERC1155 { + return new Contract(address, _abi, signerOrProvider) as ERC1155; + } +} diff --git a/src/contracts/factories/ERC721__factory.ts b/src/contracts/factories/ERC721__factory.ts index 7b2e9e6..bb75aa9 100644 --- a/src/contracts/factories/ERC721__factory.ts +++ b/src/contracts/factories/ERC721__factory.ts @@ -22,10 +22,96 @@ const _abi = [ ], name: "approve", outputs: [], - stateMutability: "nonpayable", type: "function", }, { + inputs: [ + { + internalType: "address", + name: "from", + type: "address", + }, + { + internalType: "address", + name: "to", + type: "address", + }, + { + internalType: "uint256", + name: "tokenId", + type: "uint256", + }, + ], + name: "safeTransferFrom", + outputs: [], + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "to", + type: "address", + }, + { + internalType: "bool", + name: "approved", + type: "bool", + }, + ], + name: "setApprovalForAll", + outputs: [], + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "from", + type: "address", + }, + { + internalType: "address", + name: "to", + type: "address", + }, + { + internalType: "uint256", + name: "tokenId", + type: "uint256", + }, + ], + name: "transferFrom", + outputs: [], + type: "function", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "from", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "to", + type: "address", + }, + { + indexed: true, + internalType: "uint256", + name: "tokenId", + type: "uint256", + }, + ], + name: "Transfer", + type: "event", + }, + { + constant: true, inputs: [ { internalType: "uint256", @@ -44,6 +130,71 @@ const _abi = [ stateMutability: "view", type: "function", }, + { + constant: true, + inputs: [ + { + internalType: "address", + name: "owner", + type: "address", + }, + { + internalType: "address", + name: "operator", + type: "address", + }, + ], + name: "isApprovedForAll", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + constant: true, + inputs: [ + { + internalType: "uint256", + name: "tokenId", + type: "uint256", + }, + ], + name: "ownerOf", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + constant: true, + inputs: [ + { + internalType: "bytes4", + name: "interfaceId", + type: "bytes4", + }, + ], + name: "supportsInterface", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, ] as const; export class ERC721__factory { diff --git a/src/contracts/factories/PaymentPlanV2__factory.ts b/src/contracts/factories/PaymentPlanV2__factory.ts index 5f45116..136141f 100644 --- a/src/contracts/factories/PaymentPlanV2__factory.ts +++ b/src/contracts/factories/PaymentPlanV2__factory.ts @@ -478,6 +478,257 @@ const _abi = [ stateMutability: "view", type: "function", }, + { + inputs: [ + { + internalType: "uint256", + name: "planId", + type: "uint256", + }, + { + internalType: "uint256", + name: "sellPrice", + type: "uint256", + }, + { + components: [ + { + components: [ + { + components: [ + { + internalType: "address", + name: "offerer", + type: "address", + }, + { + internalType: "address", + name: "zone", + type: "address", + }, + { + components: [ + { + internalType: "enum ISeaport.ItemType", + name: "itemType", + type: "uint8", + }, + { + internalType: "address", + name: "token", + type: "address", + }, + { + internalType: "uint256", + name: "identifierOrCriteria", + type: "uint256", + }, + { + internalType: "uint256", + name: "startAmount", + type: "uint256", + }, + { + internalType: "uint256", + name: "endAmount", + type: "uint256", + }, + ], + internalType: "struct ISeaport.OfferItem[]", + name: "offer", + type: "tuple[]", + }, + { + components: [ + { + internalType: "enum ISeaport.ItemType", + name: "itemType", + type: "uint8", + }, + { + internalType: "address", + name: "token", + type: "address", + }, + { + internalType: "uint256", + name: "identifierOrCriteria", + type: "uint256", + }, + { + internalType: "uint256", + name: "startAmount", + type: "uint256", + }, + { + internalType: "uint256", + name: "endAmount", + type: "uint256", + }, + { + internalType: "address payable", + name: "recipient", + type: "address", + }, + ], + internalType: "struct ISeaport.ConsiderationItem[]", + name: "consideration", + type: "tuple[]", + }, + { + internalType: "enum ISeaport.OrderType", + name: "orderType", + type: "uint8", + }, + { + internalType: "uint256", + name: "startTime", + type: "uint256", + }, + { + internalType: "uint256", + name: "endTime", + type: "uint256", + }, + { + internalType: "bytes32", + name: "zoneHash", + type: "bytes32", + }, + { + internalType: "uint256", + name: "salt", + type: "uint256", + }, + { + internalType: "bytes32", + name: "conduitKey", + type: "bytes32", + }, + { + internalType: "uint256", + name: "totalOriginalConsiderationItems", + type: "uint256", + }, + ], + internalType: "struct ISeaport.OrderParameters", + name: "parameters", + type: "tuple", + }, + { + internalType: "uint120", + name: "numerator", + type: "uint120", + }, + { + internalType: "uint120", + name: "denominator", + type: "uint120", + }, + { + internalType: "bytes", + name: "signature", + type: "bytes", + }, + { + internalType: "bytes", + name: "extraData", + type: "bytes", + }, + ], + internalType: "struct ISeaport.AdvancedOrder[]", + name: "orders", + type: "tuple[]", + }, + { + components: [ + { + internalType: "uint256", + name: "orderIndex", + type: "uint256", + }, + { + internalType: "enum ISeaport.Side", + name: "side", + type: "uint8", + }, + { + internalType: "uint256", + name: "index", + type: "uint256", + }, + { + internalType: "uint256", + name: "identifier", + type: "uint256", + }, + { + internalType: "bytes32[]", + name: "criteriaProof", + type: "bytes32[]", + }, + ], + internalType: "struct ISeaport.CriteriaResolver[]", + name: "criteriaResolvers", + type: "tuple[]", + }, + { + components: [ + { + components: [ + { + internalType: "uint256", + name: "orderIndex", + type: "uint256", + }, + { + internalType: "uint256", + name: "itemIndex", + type: "uint256", + }, + ], + internalType: "struct ISeaport.FulfillmentComponent[]", + name: "offerComponents", + type: "tuple[]", + }, + { + components: [ + { + internalType: "uint256", + name: "orderIndex", + type: "uint256", + }, + { + internalType: "uint256", + name: "itemIndex", + type: "uint256", + }, + ], + internalType: "struct ISeaport.FulfillmentComponent[]", + name: "considerationComponents", + type: "tuple[]", + }, + ], + internalType: "struct ISeaport.Fulfillment[]", + name: "fulfillments", + type: "tuple[]", + }, + { + internalType: "address", + name: "recipient", + type: "address", + }, + ], + internalType: "struct ISeaport.OfferData", + name: "offer", + type: "tuple", + }, + ], + name: "earlyUnwind", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, ] as const; export class PaymentPlanV2__factory { diff --git a/src/contracts/factories/index.ts b/src/contracts/factories/index.ts index 269bee4..2f33266 100644 --- a/src/contracts/factories/index.ts +++ b/src/contracts/factories/index.ts @@ -3,6 +3,7 @@ /* eslint-disable */ export { CyanFactory__factory } from "./CyanFactory__factory"; export { CyanWallet__factory } from "./CyanWallet__factory"; +export { ERC1155__factory } from "./ERC1155__factory"; export { ERC20__factory } from "./ERC20__factory"; export { ERC721__factory } from "./ERC721__factory"; export { PaymentPlanV2__factory } from "./PaymentPlanV2__factory"; diff --git a/src/contracts/index.ts b/src/contracts/index.ts index 3c7f0b8..de24305 100644 --- a/src/contracts/index.ts +++ b/src/contracts/index.ts @@ -3,12 +3,14 @@ /* eslint-disable */ export type { CyanFactory } from "./CyanFactory"; export type { CyanWallet } from "./CyanWallet"; +export type { ERC1155 } from "./ERC1155"; export type { ERC20 } from "./ERC20"; export type { ERC721 } from "./ERC721"; export type { PaymentPlanV2 } from "./PaymentPlanV2"; export * as factories from "./factories"; export { CyanFactory__factory } from "./factories/CyanFactory__factory"; export { CyanWallet__factory } from "./factories/CyanWallet__factory"; +export { ERC1155__factory } from "./factories/ERC1155__factory"; export { ERC20__factory } from "./factories/ERC20__factory"; export { ERC721__factory } from "./factories/ERC721__factory"; export { PaymentPlanV2__factory } from "./factories/PaymentPlanV2__factory"; diff --git a/src/sdk.ts b/src/sdk.ts index bbfd96b..b5d9197 100644 --- a/src/sdk.ts +++ b/src/sdk.ts @@ -1,5 +1,5 @@ import { JsonRpcSigner } from '@ethersproject/providers'; -import { BigNumber, constants as ethConsts, ContractTransaction } from 'ethers'; +import { BigNumber, constants as ethConsts, ContractTransaction, ethers } from 'ethers'; import { CyanAPI } from './api'; import { @@ -11,6 +11,7 @@ import { CyanWallet__factory as CyanWalletFactory, ERC721__factory as ERC721Factory, ERC20__factory as ERC20Factory, + ERC1155__factory as ERC1155Factory, } from './contracts'; import { CyanError, NoWalletError } from './errors'; @@ -25,6 +26,9 @@ import { IPricerStep2, IItem, IItemWithPrice, + IOffer, + ICurrency, + INftType, } from './types'; import { generateBnplOptions, @@ -267,20 +271,36 @@ export class CyanSDK { } /** - * Approve Payment Plan Contract to spend a specific ERC721 token on behalf of the signer. - * @param {string} address - The address of the ERC721 contract. + * Approve Payment Plan Contract to spend a specific ERC721 or ERC1155 token on behalf of the signer. + * @param {string} address - The address of the ERC721 or ERC1155 contract. * @param {string} tokenId - The ID of the token to approve. * @returns {Promise} - A Promise that resolves when the transaction is confirmed. * @throws {Error} - Throws an error if the PaymentPlan contract is not found or if the transaction fails. */ - public async getApproval(address: string, tokenId: string): Promise { + public async getApproval(address: string, tokenId: string, tokenType?: INftType): Promise { const paymentPlanContract = await this.getPaymentPlanContract(); - const erc721Contract = ERC721Factory.connect(address, this.signer); - const approvedTo = await erc721Contract.getApproved(tokenId); - - if (approvedTo.toLowerCase() === paymentPlanContract.address.toLowerCase()) return; - - const tx = await erc721Contract.approve(paymentPlanContract.address, tokenId); + let tx: ContractTransaction | undefined = undefined; + if (tokenType == INftType.ERC1155) { + const erc1155Contract = ERC1155Factory.connect(address, this.signer); + const isApprovedForAll = await erc1155Contract.isApprovedForAll( + this.signer.getAddress(), + paymentPlanContract.address + ); + + if (isApprovedForAll) return; + tx = await erc1155Contract.setApprovalForAll(paymentPlanContract.address, true); + } else { + const erc721Contract = ERC721Factory.connect(address, this.signer); + const isApprovedForAll = await erc721Contract.isApprovedForAll( + this.signer.getAddress(), + paymentPlanContract.address + ); + if (isApprovedForAll) return; + const approvedTo = await erc721Contract.getApproved(tokenId); + + if (approvedTo.toLowerCase() === paymentPlanContract.address.toLowerCase()) return; + tx = await erc721Contract.approve(paymentPlanContract.address, tokenId); + } await tx.wait(); return; } @@ -433,7 +453,9 @@ export class CyanSDK { if (!isNativeCurrency) { await this.checkAndAllowCurrencyForPlan(currencyAddress, BigNumber.from(currentPayment)); } - return await contract.pay(plan.planId, isEarlyRepayment, { value: isNativeCurrency ? currentPayment : 0 }); + return await contract.pay(plan.planId, isEarlyRepayment, { + value: isNativeCurrency ? currentPayment : 0, + }); } private async _buildStep2Request(args: ISdkPricerStep2['params']): Promise { @@ -494,6 +516,7 @@ export class CyanSDK { const CHAINS: Record = { 1: 'mainnet', 5: 'goerli', + 11155111: 'sepolia', 137: 'polygon', 80001: 'mumbai', 42161: 'arbitrum', @@ -502,6 +525,127 @@ export class CyanSDK { }; return CHAINS[chainId]; } + public async getTopBid(collectionAddress: string, tokenId?: string): Promise { + const chain = await this._getChain(); + const topBids = await this.api.getCollectionTopBid({ chain, collectionAddress, tokenId }); + return topBids; + } + + public async fulfillOffer(plan: IPlan, offer: IOffer): Promise { + const chain = await this._getChain(); + const contract = PaymentPlanV2Factory.connect(plan.paymentPlanContractAddress, this.signer); + + const offerFulfillment = await this.api.getFulfillOffer({ + chain, + planId: plan.planId, + offerHash: offer.hash, + }); + + return await contract.earlyUnwind(plan.planId, offer.price.netAmount.raw, offerFulfillment); + } + + public async payBulk(plans: IPlan[], isEarlyPayment: boolean, releaseWallet: string): Promise { + const plansWithNextPayment = await Promise.all( + plans.map(async plan => { + const nextPayment = await this.getPaymentInfo(plan, isEarlyPayment); + return { + ...plan, + nextPayment, + }; + }) + ); + const totalRepaymentAmountByCurrency = plansWithNextPayment.reduce<{ + [key: string]: { + totalCost: BigNumber; + currency: ICurrency; + isNativeCurrency: boolean; + }; + }>((acc, cur) => { + if (acc[cur.currency.address.toLowerCase()]) { + acc[cur.currency.address.toLowerCase()] = { + totalCost: acc[cur.currency.address.toLowerCase()].totalCost.add( + cur.nextPayment?.currentPayment || 0 + ), + currency: cur.currency, + isNativeCurrency: cur.currency.address.toLowerCase() === ethers.constants.AddressZero.toLowerCase(), + }; + } else { + acc[cur.currency.address.toLowerCase()] = { + totalCost: BigNumber.from(cur.nextPayment?.currentPayment) || BigNumber.from(0), + currency: cur.currency, + isNativeCurrency: cur.currency.address.toLowerCase() === ethers.constants.AddressZero.toLowerCase(), + }; + } + return acc; + }, {}); + + const currencyValues = Object.values(totalRepaymentAmountByCurrency); + const cyanWallet = await this.getCyanWallet(); + const contract = PaymentPlanV2Factory.connect(plans[0].paymentPlanContractAddress, this.signer); + + const bulkTransactions = []; + for (const { currency, totalCost, isNativeCurrency } of currencyValues) { + if (!isNativeCurrency) { + const erc20 = ERC20Factory.connect(currency.address, this.signer); + const userAllowance = await erc20.allowance(this.signer.getAddress(), cyanWallet.address); + if (userAllowance.lt(totalCost)) { + const encodedAllowanceFnData = erc20.interface.encodeFunctionData('approve', [ + cyanWallet.address, + totalCost, + ]); + bulkTransactions.push({ + to: currency.address, + data: encodedAllowanceFnData, + value: 0, + }); + } + } + } + for (const plan of plansWithNextPayment) { + const isNativeCurrency = plan.currency.address.toLowerCase() === ethers.constants.AddressZero.toLowerCase(); + const encodedPayFnData = contract.interface.encodeFunctionData('pay', [plan.planId, isEarlyPayment]); + + bulkTransactions.push({ + to: plan.paymentPlanContractAddress, + data: encodedPayFnData, + value: isNativeCurrency ? plan.nextPayment.currentPayment : 0, + }); + const totalNumOfPaymentsLeft = plan.totalNumOfPayments - plan.currentNumOfPayments; + if ( + (totalNumOfPaymentsLeft === 1 || isEarlyPayment) && + cyanWallet.address.toLowerCase() !== releaseWallet.toLowerCase() + ) { + if (plan.tokenType === INftType.ERC1155) { + const contractIFace = ERC1155Factory.createInterface(); + const encodedFnDataTransfer = contractIFace.encodeFunctionData('safeTransferFrom', [ + cyanWallet.address, + releaseWallet, + plan.tokenId, + 1, + [], + ]); + bulkTransactions.push({ + to: plan.collectionAddress, + data: encodedFnDataTransfer, + value: 0, + }); + } else { + const sampleContractIFace = ERC721Factory.createInterface(); + const encodedFnDataTransfer = sampleContractIFace.encodeFunctionData('safeTransferFrom', [ + cyanWallet.address, + releaseWallet, + plan.tokenId, + ]); + bulkTransactions.push({ + to: plan.collectionAddress, + data: encodedFnDataTransfer, + value: 0, + }); + } + } + } + return await cyanWallet.executeBatch(bulkTransactions); + } } export default CyanSDK; diff --git a/src/types.ts b/src/types.ts index d909efd..b48600d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,4 @@ -import { BigNumber } from 'ethers'; +import { BigNumber, BigNumberish } from 'ethers'; import { Web3Provider } from '@ethersproject/providers'; export type ICyanSDKConstructor = { @@ -7,7 +7,7 @@ export type ICyanSDKConstructor = { provider: Web3Provider; }; -export const chains = ['mainnet', 'goerli', 'polygon', 'mumbai', 'arbitrum', 'bsc', 'optimism'] as const; +export const chains = ['mainnet', 'goerli', 'sepolia', 'polygon', 'mumbai', 'arbitrum', 'bsc', 'optimism'] as const; export type IChain = typeof chains[keyof typeof chains]; const statusType = { @@ -19,7 +19,20 @@ export type IPlanStatus = typeof statusType[keyof typeof statusType]; export enum AutoRepayStatus { Disabled = 0, - Active = 1, + FromCyanWallet = 1, + FromMainWallet = 2, +} + +export type ICurrency = { + symbol: string; + address: string; + decimal: number; +}; + +export enum INftType { + ERC721 = 1, + ERC1155 = 2, + CryptoPunks = 3, } export type IPlan = { @@ -34,6 +47,8 @@ export type IPlan = { collectionAddress: string; autoRepayStatus: AutoRepayStatus; tokenId: string; + currency: ICurrency; + tokenType: INftType; }; export type FnGetExpectedPlanSync = { @@ -149,7 +164,7 @@ export type IPricerStep2 = { items: IItem[]; currencyAddress: string; option: number[]; - autoRepayStatus: 0 | 1; + autoRepayStatus: AutoRepayStatus; wallet: string; }; response: { @@ -182,3 +197,100 @@ export type ISdkPricerStep2 = { }; result: Errored[]; }; + +export type IOffer = { + hash: string; + contract: string; + price: { + currency: { + contract: string; + decimals: number; + symbol: string; + name: string; + }; + amount: { + raw: string; + decimal: number; + }; + netAmount: { + raw: string; + decimal: number; + }; + }; + validUntil: number; +}; + +export type IGetCollectionTopBid = { + request: { chain: IChain; tokenId?: string; collectionAddress: string }; + result: IOffer[]; +}; + +enum OrderType { + FULL_OPEN = 0, // No partial fills, anyone can execute + PARTIAL_OPEN = 1, // Partial fills supported, anyone can execute + FULL_RESTRICTED = 2, // No partial fills, only offerer or zone can execute + PARTIAL_RESTRICTED = 3, // Partial fills supported, only offerer or zone can execute +} + +type OfferItem = { + itemType: ItemType; + token: string; + identifierOrCriteria: string; + startAmount: string; + endAmount: string; +}; +type ConsiderationItem = { + itemType: ItemType; + token: string; + identifierOrCriteria: string; + startAmount: string; + endAmount: string; + recipient: string; +}; + +type OrderParameters = { + offerer: string; + zone: string; + orderType: OrderType; + startTime: BigNumberish; + endTime: BigNumberish; + zoneHash: string; + salt: string; + offer: OfferItem[]; + consideration: ConsiderationItem[]; + totalOriginalConsiderationItems: BigNumberish; + conduitKey: string; +}; +type MatchOrdersFulfillmentComponent = { + orderIndex: number; + itemIndex: number; +}; + +export type IFulfillOffer = { + request: { + chain: IChain; + planId: number; + offerHash: string; + }; + result: { + orders: { + parameters: OrderParameters; + signature: string; + extraData: string; + denominator: number; + numerator: number; + }[]; + fulfillments: { + offerComponents: MatchOrdersFulfillmentComponent[]; + considerationComponents: MatchOrdersFulfillmentComponent[]; + }[]; + criteriaResolvers: { + orderIndex: string; + side: number; + index: string; + identifier: string; + criteriaProof: string[]; + }[]; + recipient: string; + }; +};