From 12b5e7512fef6e76cfb4b66553d4230076656b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uziel=20Ludue=C3=B1a?= Date: Tue, 4 Mar 2025 16:05:57 -0300 Subject: [PATCH] feat: publish order --- examples/buyWithSellAndRepay.ts | 2 +- examples/cancelOrder.ts | 2 +- examples/makeOrder.ts | 2 +- package.json | 2 +- .../graphql/mutations/orders/publishOrder.gql | 20 ++ ...blish.gql => publishSellAndRepayOrder.gql} | 0 src/api/index.ts | 6 + src/contracts/BaseContract.ts | 10 +- src/generated/graphql/index.ts | 191 ++++++++++++++++-- src/generated/graphql/lending-schema.graphql | 71 ++++++- src/gondi.ts | 17 +- 11 files changed, 301 insertions(+), 22 deletions(-) create mode 100644 src/api/graphql/mutations/orders/publishOrder.gql rename src/api/graphql/mutations/orders/{publish.gql => publishSellAndRepayOrder.gql} (100%) diff --git a/examples/buyWithSellAndRepay.ts b/examples/buyWithSellAndRepay.ts index 3805ed4f..a895f382 100644 --- a/examples/buyWithSellAndRepay.ts +++ b/examples/buyWithSellAndRepay.ts @@ -21,7 +21,7 @@ const sellAndRepay = async () => { await sleep(2000); try { const price = 100n; - const signedOrder = await owner.makeOrder({ + const signedOrder = await owner.makeSellAndRepayOrder({ collectionContractAddress: test721Collection.contractAddress, tokenId: testTokenId, price, diff --git a/examples/cancelOrder.ts b/examples/cancelOrder.ts index 3c1b4c97..b7c4264f 100644 --- a/examples/cancelOrder.ts +++ b/examples/cancelOrder.ts @@ -16,7 +16,7 @@ const cancelOrder = async () => { }); const { loan, loanId } = await emitLoan.waitTxInBlock(); try { - const order = await users[1].makeOrder({ + const order = await users[1].makeSellAndRepayOrder({ collectionContractAddress: test721Collection.contractAddress, tokenId: testTokenId, price: 1n, diff --git a/examples/makeOrder.ts b/examples/makeOrder.ts index 2df25582..b9d0ac6b 100644 --- a/examples/makeOrder.ts +++ b/examples/makeOrder.ts @@ -16,7 +16,7 @@ const makeOrder = async () => { }); const { loan, loanId } = await emitLoan.waitTxInBlock(); try { - const signedOrder = await users[1].makeOrder({ + const signedOrder = await users[1].makeSellAndRepayOrder({ startTime: BigInt(Math.floor(Date.now() * 1_000)), contractAddress: test721Collection.contractAddress, tokenId: testTokenId, diff --git a/package.json b/package.json index cfb61391..2079c12e 100644 --- a/package.json +++ b/package.json @@ -80,4 +80,4 @@ "viem": "~2.21.0" }, "packageManager": "yarn@4.2.1" -} \ No newline at end of file +} diff --git a/src/api/graphql/mutations/orders/publishOrder.gql b/src/api/graphql/mutations/orders/publishOrder.gql new file mode 100644 index 00000000..a407a7d5 --- /dev/null +++ b/src/api/graphql/mutations/orders/publishOrder.gql @@ -0,0 +1,20 @@ +mutation publishOrderForNft($orderInput: SingleNFTOrderInput!) { + result: publishOrderForNft(orderInput: $orderInput) { + ... on SingleNFTOrder { + id + status + signature + cancelCalldata + marketPlaceAddress + } + ... on SignatureRequest { + key + typedData { + types + primaryType + domain + message + } + } + } +} diff --git a/src/api/graphql/mutations/orders/publish.gql b/src/api/graphql/mutations/orders/publishSellAndRepayOrder.gql similarity index 100% rename from src/api/graphql/mutations/orders/publish.gql rename to src/api/graphql/mutations/orders/publishSellAndRepayOrder.gql diff --git a/src/api/index.ts b/src/api/index.ts index 654331a3..594a1787 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -11,6 +11,7 @@ import { ListLoansQueryVariables, ListOffersQueryVariables, NftOrderInput, + SingleNftOrderInput, SingleNftSignedOfferInput, } from '@/generated/graphql'; import { RenegotiationOffer } from '@/model'; @@ -92,6 +93,11 @@ export class Api { }; } + async publishOrder(orderInput: SingleNftOrderInput) { + const response = await this.api.publishOrderForNft({ orderInput }); + return response.result; + } + async publishSellAndRepayOrder(orderInput: NftOrderInput) { const response = await this.api.publishSellAndRepayOrder({ orderInput }); return response.result; diff --git a/src/contracts/BaseContract.ts b/src/contracts/BaseContract.ts index 70c3b1b0..a35add88 100644 --- a/src/contracts/BaseContract.ts +++ b/src/contracts/BaseContract.ts @@ -94,10 +94,14 @@ export class BaseContract { const txHash = await this.wallet.sendTransaction({ data, to: this.address }); return { txHash, - waitTxInBlock: () => - this.bcClient.waitForTransactionReceipt({ + waitTxInBlock: async () => { + const receipt = await this.bcClient.waitForTransactionReceipt({ hash: txHash, - }), + }); + if (receipt.status === 'reverted') + throw new Error(`Transaction reverted to:${this.address}, data:${data}`); + return receipt; + }, }; } } diff --git a/src/generated/graphql/index.ts b/src/generated/graphql/index.ts index a6daa5cb..2bf8659a 100644 --- a/src/generated/graphql/index.ts +++ b/src/generated/graphql/index.ts @@ -208,6 +208,7 @@ export type BigIntInterval = { export type BuyNowPayLaterOrder = Activity & Node & Order & { __typename?: 'BuyNowPayLaterOrder'; + cancelCalldata: Scalars['Hex']; createdDate: Scalars['DateTime']; currency: Currency; currencyAddress: Scalars['Address']; @@ -369,6 +370,7 @@ export type CollectionOfferStatistics = { export type CollectionOrder = Activity & Node & Order & { __typename?: 'CollectionOrder'; + cancelCalldata: Scalars['Hex']; collection: Collection; createdDate: Scalars['DateTime']; currency: Currency; @@ -382,6 +384,7 @@ export type CollectionOrder = Activity & Node & Order & { isPrivate: Scalars['Boolean']; maker: Scalars['Address']; marketPlace: Scalars['String']; + marketPlaceAddress: Scalars['Address']; netAmount: Scalars['BigInt']; nonce: Scalars['BigInt']; orderType: Scalars['String']; @@ -1003,6 +1006,7 @@ export type LoansData = { export type LostSource = Node & { __typename?: 'LostSource'; accruedInterest: Scalars['BigInt']; + activity: LoanActivity; activityId: Scalars['String']; aprBps: Scalars['BigInt']; duration: Scalars['BigInt']; @@ -1133,6 +1137,7 @@ export type Mutation = { markNotificationIdsAsRead?: Maybe; markNotificationsAsRead?: Maybe; publishBuyNowPayLaterOrder: BuyNowPayLaterOrderSignatureRequest; + publishOrderForNft: SingleNftOrderSignatureRequest; publishSellAndRepayOrder: SellAndRepayOrderSignatureRequest; removeListing: Listing; removeListingsOfNftsFromUser?: Maybe; @@ -1227,6 +1232,11 @@ export type MutationPublishBuyNowPayLaterOrderArgs = { }; +export type MutationPublishOrderForNftArgs = { + orderInput: SingleNftOrderInput; +}; + + export type MutationPublishSellAndRepayOrderArgs = { orderInput: NftOrderInput; }; @@ -1604,6 +1614,7 @@ export type OffersSortInput = { }; export type Order = { + cancelCalldata: Scalars['Hex']; createdDate: Scalars['DateTime']; currency: Currency; currencyAddress: Scalars['Address']; @@ -1616,6 +1627,7 @@ export type Order = { isPrivate: Scalars['Boolean']; maker: Scalars['Address']; marketPlace: Scalars['String']; + marketPlaceAddress: Scalars['Address']; netAmount: Scalars['BigInt']; nonce: Scalars['BigInt']; orderType: Scalars['String']; @@ -1643,7 +1655,10 @@ export type OrderEdge = { }; export enum OrderSortField { - Expiration = 'EXPIRATION' + Expiration = 'EXPIRATION', + Fee = 'FEE', + NetAmount = 'NET_AMOUNT', + Price = 'PRICE' } export type OrderSortInput = { @@ -1660,6 +1675,15 @@ export enum OrderStatusType { Outperformed = 'Outperformed' } +export type OrderTermsFilter = { + netAmount?: InputMaybe; +}; + +export enum OrderType { + Ask = 'ASK', + Bid = 'BID' +} + export enum Ordering { Asc = 'ASC', Desc = 'DESC' @@ -1770,6 +1794,7 @@ export type Query = { listNftsFromUser: NftConnection; listNotifications: NotificationConnection; listOffers: OfferConnection; + listOrders: OrderConnection; listRenegotiations: RenegotiationConnection; listSources: SourceLostSourceConnection; me?: Maybe; @@ -2053,6 +2078,23 @@ export type QueryListOffersArgs = { }; +export type QueryListOrdersArgs = { + after?: InputMaybe; + currencyAddresses?: InputMaybe>; + first?: InputMaybe; + hidden?: InputMaybe; + ids?: InputMaybe>; + marketplaceIds?: InputMaybe>; + marketplaces?: InputMaybe>; + nftIds?: InputMaybe>; + orderType?: InputMaybe; + sortBy?: InputMaybe>; + statuses?: InputMaybe>; + taker?: InputMaybe; + terms?: InputMaybe; +}; + + export type QueryListRenegotiationsArgs = { after?: InputMaybe; collections?: InputMaybe>; @@ -2106,6 +2148,7 @@ export type Renegotiation = Node & { createdDate?: Maybe; duration: Scalars['BigInt']; expirationTime: Scalars['BigInt']; + fallbackOfferId?: Maybe; feeAmount: Scalars['BigInt']; hidden?: Maybe; id: Scalars['String']; @@ -2328,6 +2371,7 @@ export type SingleNftOfferInput = { export type SingleNftOrder = Activity & Node & Order & { __typename?: 'SingleNFTOrder'; + cancelCalldata: Scalars['Hex']; createdDate: Scalars['DateTime']; currency: Currency; currencyAddress: Scalars['Address']; @@ -2340,6 +2384,7 @@ export type SingleNftOrder = Activity & Node & Order & { isPrivate: Scalars['Boolean']; maker: Scalars['Address']; marketPlace: Scalars['String']; + marketPlaceAddress: Scalars['Address']; netAmount: Scalars['BigInt']; nft: Nft; nftId: Scalars['Int']; @@ -2355,6 +2400,20 @@ export type SingleNftOrder = Activity & Node & Order & { txHash?: Maybe; }; +export type SingleNftOrderInput = { + amount: Scalars['BigInt']; + contractAddress: Scalars['Address']; + currencyAddress: Scalars['Address']; + expirationTime: Scalars['BigInt']; + isAsk: Scalars['Boolean']; + signature?: InputMaybe; + startTime: Scalars['BigInt']; + taker?: InputMaybe; + tokenId: Scalars['BigInt']; +}; + +export type SingleNftOrderSignatureRequest = SignatureRequest | SingleNftOrder; + export type SingleNftSignedOfferInput = { aprBps: Scalars['BigInt']; borrowerAddress: Scalars['Address']; @@ -2529,6 +2588,37 @@ export type TraitKeyValueOptionsInput = { values: Array; }; +export type TraitOrder = Activity & Node & Order & { + __typename?: 'TraitOrder'; + cancelCalldata: Scalars['Hex']; + collectionId: Scalars['Int']; + createdDate: Scalars['DateTime']; + currency: Currency; + currencyAddress: Scalars['Address']; + evmOrder?: Maybe; + expiration: Scalars['DateTime']; + fees: Scalars['BigInt']; + hidden: Scalars['Boolean']; + id: Scalars['String']; + isAsk: Scalars['Boolean']; + isPrivate: Scalars['Boolean']; + maker: Scalars['Address']; + marketPlace: Scalars['String']; + marketPlaceAddress: Scalars['Address']; + netAmount: Scalars['BigInt']; + nonce: Scalars['BigInt']; + orderType: Scalars['String']; + originalId: Scalars['Hash']; + price: Scalars['BigInt']; + signature: Scalars['Signature']; + startTime: Scalars['DateTime']; + status: Scalars['String']; + taker: Scalars['Address']; + timestamp: Scalars['DateTime']; + traitId: Scalars['Int']; + txHash?: Maybe; +}; + export type TraitRangeOptionsInput = { key: Scalars['String']; range: RangeInput; @@ -2836,7 +2926,14 @@ export type HideOrderMutationVariables = Exact<{ }>; -export type HideOrderMutation = { __typename?: 'Mutation', hideOrder: { __typename?: 'BuyNowPayLaterOrder', id: string } | { __typename?: 'CollectionOrder', id: string } | { __typename?: 'SellAndRepayOrder', id: string } | { __typename?: 'SingleNFTOrder', id: string } }; +export type HideOrderMutation = { __typename?: 'Mutation', hideOrder: { __typename?: 'BuyNowPayLaterOrder', id: string } | { __typename?: 'CollectionOrder', id: string } | { __typename?: 'SellAndRepayOrder', id: string } | { __typename?: 'SingleNFTOrder', id: string } | { __typename?: 'TraitOrder', id: string } }; + +export type PublishOrderForNftMutationVariables = Exact<{ + orderInput: SingleNftOrderInput; +}>; + + +export type PublishOrderForNftMutation = { __typename?: 'Mutation', result: { __typename?: 'SignatureRequest', key: string, typedData: { __typename?: 'TypedData', types: object, primaryType: string, domain: object, message: object } } | { __typename?: 'SingleNFTOrder', id: string, status: string, signature: Hex, cancelCalldata: Hex, marketPlaceAddress: Address } }; export type PublishSellAndRepayOrderMutationVariables = Exact<{ orderInput: NftOrderInput; @@ -2850,7 +2947,7 @@ export type ShowOrderMutationVariables = Exact<{ }>; -export type ShowOrderMutation = { __typename?: 'Mutation', showOrder: { __typename?: 'BuyNowPayLaterOrder', id: string } | { __typename?: 'CollectionOrder', id: string } | { __typename?: 'SellAndRepayOrder', id: string } | { __typename?: 'SingleNFTOrder', id: string } }; +export type ShowOrderMutation = { __typename?: 'Mutation', showOrder: { __typename?: 'BuyNowPayLaterOrder', id: string } | { __typename?: 'CollectionOrder', id: string } | { __typename?: 'SellAndRepayOrder', id: string } | { __typename?: 'SingleNFTOrder', id: string } | { __typename?: 'TraitOrder', id: string } }; export type GenerateRenegotiationOfferHashMutationVariables = Exact<{ renegotiationInput: RenegotiationOfferInput; @@ -2965,7 +3062,7 @@ export type OwnedNftsQueryVariables = Exact<{ }>; -export type OwnedNftsQuery = { __typename?: 'Query', ownedNfts: { __typename?: 'NFTConnection', pageInfo: { __typename?: 'PageInfo', endCursor?: string | null, hasNextPage: boolean }, edges: Array<{ __typename?: 'NFTEdge', node: { __typename?: 'NFT', id: string, tokenId: bigint, collection?: { __typename?: 'Collection', id: string, contractData: { __typename?: 'ContractData', contractAddress: Address }, wrapperCollections: Array<{ __typename?: 'Collection', contractData: { __typename?: 'ContractData', contractAddress: Address } }> } | null, activeLoan?: { __typename?: 'MultiSourceLoan', id: string } | null, statistics: { __typename?: 'NftStatistics', lastSale?: { __typename?: 'Sale', order: { __typename?: 'BuyNowPayLaterOrder', price: bigint, currency: { __typename?: 'Currency', address: Address, decimals: number } } | { __typename?: 'CollectionOrder', price: bigint, currency: { __typename?: 'Currency', address: Address, decimals: number } } | { __typename?: 'SellAndRepayOrder', price: bigint, currency: { __typename?: 'Currency', address: Address, decimals: number } } | { __typename?: 'SingleNFTOrder', price: bigint, currency: { __typename?: 'Currency', address: Address, decimals: number } } } | null, topTraitFloorPrice?: { __typename?: 'CurrencyAmount', amount: number, currency: { __typename?: 'Currency', address: Address, decimals: number } } | null } } }> } }; +export type OwnedNftsQuery = { __typename?: 'Query', ownedNfts: { __typename?: 'NFTConnection', pageInfo: { __typename?: 'PageInfo', endCursor?: string | null, hasNextPage: boolean }, edges: Array<{ __typename?: 'NFTEdge', node: { __typename?: 'NFT', id: string, tokenId: bigint, collection?: { __typename?: 'Collection', id: string, contractData: { __typename?: 'ContractData', contractAddress: Address }, wrapperCollections: Array<{ __typename?: 'Collection', contractData: { __typename?: 'ContractData', contractAddress: Address } }> } | null, activeLoan?: { __typename?: 'MultiSourceLoan', id: string } | null, statistics: { __typename?: 'NftStatistics', lastSale?: { __typename?: 'Sale', order: { __typename?: 'BuyNowPayLaterOrder', price: bigint, currency: { __typename?: 'Currency', address: Address, decimals: number } } | { __typename?: 'CollectionOrder', price: bigint, currency: { __typename?: 'Currency', address: Address, decimals: number } } | { __typename?: 'SellAndRepayOrder', price: bigint, currency: { __typename?: 'Currency', address: Address, decimals: number } } | { __typename?: 'SingleNFTOrder', price: bigint, currency: { __typename?: 'Currency', address: Address, decimals: number } } | { __typename?: 'TraitOrder', price: bigint, currency: { __typename?: 'Currency', address: Address, decimals: number } } } | null, topTraitFloorPrice?: { __typename?: 'CurrencyAmount', amount: number, currency: { __typename?: 'Currency', address: Address, decimals: number } } | null } } }> } }; export type ListOffersQueryVariables = Exact<{ borrowerAddress?: InputMaybe; @@ -3110,8 +3207,9 @@ export type BigIntCurrencyAmountFieldPolicy = { amount?: FieldPolicy | FieldReadFunction, currency?: FieldPolicy | FieldReadFunction }; -export type BuyNowPayLaterOrderKeySpecifier = ('createdDate' | 'currency' | 'currencyAddress' | 'emitCalldata' | 'evmOrder' | 'expiration' | 'fees' | 'hidden' | 'id' | 'isAsk' | 'isPrivate' | 'maker' | 'marketPlace' | 'marketPlaceAddress' | 'netAmount' | 'nft' | 'nftId' | 'nonce' | 'orderType' | 'originalId' | 'price' | 'signature' | 'startTime' | 'status' | 'taker' | 'timestamp' | 'txHash' | BuyNowPayLaterOrderKeySpecifier)[]; +export type BuyNowPayLaterOrderKeySpecifier = ('cancelCalldata' | 'createdDate' | 'currency' | 'currencyAddress' | 'emitCalldata' | 'evmOrder' | 'expiration' | 'fees' | 'hidden' | 'id' | 'isAsk' | 'isPrivate' | 'maker' | 'marketPlace' | 'marketPlaceAddress' | 'netAmount' | 'nft' | 'nftId' | 'nonce' | 'orderType' | 'originalId' | 'price' | 'signature' | 'startTime' | 'status' | 'taker' | 'timestamp' | 'txHash' | BuyNowPayLaterOrderKeySpecifier)[]; export type BuyNowPayLaterOrderFieldPolicy = { + cancelCalldata?: FieldPolicy | FieldReadFunction, createdDate?: FieldPolicy | FieldReadFunction, currency?: FieldPolicy | FieldReadFunction, currencyAddress?: FieldPolicy | FieldReadFunction, @@ -3233,8 +3331,9 @@ export type CollectionOfferStatisticsFieldPolicy = { acceptedLoans?: FieldPolicy | FieldReadFunction, consumedCapacity?: FieldPolicy | FieldReadFunction }; -export type CollectionOrderKeySpecifier = ('collection' | 'createdDate' | 'currency' | 'currencyAddress' | 'evmOrder' | 'expiration' | 'fees' | 'hidden' | 'id' | 'isAsk' | 'isPrivate' | 'maker' | 'marketPlace' | 'netAmount' | 'nonce' | 'orderType' | 'originalId' | 'price' | 'signature' | 'startTime' | 'status' | 'taker' | 'timestamp' | 'txHash' | CollectionOrderKeySpecifier)[]; +export type CollectionOrderKeySpecifier = ('cancelCalldata' | 'collection' | 'createdDate' | 'currency' | 'currencyAddress' | 'evmOrder' | 'expiration' | 'fees' | 'hidden' | 'id' | 'isAsk' | 'isPrivate' | 'maker' | 'marketPlace' | 'marketPlaceAddress' | 'netAmount' | 'nonce' | 'orderType' | 'originalId' | 'price' | 'signature' | 'startTime' | 'status' | 'taker' | 'timestamp' | 'txHash' | CollectionOrderKeySpecifier)[]; export type CollectionOrderFieldPolicy = { + cancelCalldata?: FieldPolicy | FieldReadFunction, collection?: FieldPolicy | FieldReadFunction, createdDate?: FieldPolicy | FieldReadFunction, currency?: FieldPolicy | FieldReadFunction, @@ -3248,6 +3347,7 @@ export type CollectionOrderFieldPolicy = { isPrivate?: FieldPolicy | FieldReadFunction, maker?: FieldPolicy | FieldReadFunction, marketPlace?: FieldPolicy | FieldReadFunction, + marketPlaceAddress?: FieldPolicy | FieldReadFunction, netAmount?: FieldPolicy | FieldReadFunction, nonce?: FieldPolicy | FieldReadFunction, orderType?: FieldPolicy | FieldReadFunction, @@ -3651,9 +3751,10 @@ export type LoansDataFieldPolicy = { minPrincipalAmount?: FieldPolicy | FieldReadFunction, minRemainingTime?: FieldPolicy | FieldReadFunction }; -export type LostSourceKeySpecifier = ('accruedInterest' | 'activityId' | 'aprBps' | 'duration' | 'earnedInterest' | 'endDate' | 'expectedInterestLeft' | 'id' | 'lenderAddress' | 'lenderEaprBps' | 'loan' | 'originationFee' | 'principalAmount' | 'profit' | 'repaidInterest' | 'startTime' | LostSourceKeySpecifier)[]; +export type LostSourceKeySpecifier = ('accruedInterest' | 'activity' | 'activityId' | 'aprBps' | 'duration' | 'earnedInterest' | 'endDate' | 'expectedInterestLeft' | 'id' | 'lenderAddress' | 'lenderEaprBps' | 'loan' | 'originationFee' | 'principalAmount' | 'profit' | 'repaidInterest' | 'startTime' | LostSourceKeySpecifier)[]; export type LostSourceFieldPolicy = { accruedInterest?: FieldPolicy | FieldReadFunction, + activity?: FieldPolicy | FieldReadFunction, activityId?: FieldPolicy | FieldReadFunction, aprBps?: FieldPolicy | FieldReadFunction, duration?: FieldPolicy | FieldReadFunction, @@ -3741,7 +3842,7 @@ export type MultiSourceLoanHistoryFieldPolicy = { sources?: FieldPolicy | FieldReadFunction, startTime?: FieldPolicy | FieldReadFunction }; -export type MutationKeySpecifier = ('addListingsOfNftsFromUser' | 'addOrUpdateListing' | 'addOrUpdateRenegotiationRequest' | 'addOrUpdateTopUpRequest' | 'generateCollectionOfferToBeSigned' | 'generateRenegotiationOfferToBeSigned' | 'generateSingleNftOfferToBeSigned' | 'hideAllOffers' | 'hideOffer' | 'hideOrder' | 'hideRenegotiation' | 'markNotificationIdsAsRead' | 'markNotificationsAsRead' | 'publishBuyNowPayLaterOrder' | 'publishSellAndRepayOrder' | 'removeListing' | 'removeListingsOfNftsFromUser' | 'removeRenegotiationRequest' | 'removeTopUpRequest' | 'saveRenegotiationSignedOffer' | 'saveSignedCollectionOffer' | 'saveSignedSingleNftOffer' | 'setReferral' | 'showOffer' | 'showOrder' | 'showRenegotiation' | MutationKeySpecifier)[]; +export type MutationKeySpecifier = ('addListingsOfNftsFromUser' | 'addOrUpdateListing' | 'addOrUpdateRenegotiationRequest' | 'addOrUpdateTopUpRequest' | 'generateCollectionOfferToBeSigned' | 'generateRenegotiationOfferToBeSigned' | 'generateSingleNftOfferToBeSigned' | 'hideAllOffers' | 'hideOffer' | 'hideOrder' | 'hideRenegotiation' | 'markNotificationIdsAsRead' | 'markNotificationsAsRead' | 'publishBuyNowPayLaterOrder' | 'publishOrderForNft' | 'publishSellAndRepayOrder' | 'removeListing' | 'removeListingsOfNftsFromUser' | 'removeRenegotiationRequest' | 'removeTopUpRequest' | 'saveRenegotiationSignedOffer' | 'saveSignedCollectionOffer' | 'saveSignedSingleNftOffer' | 'setReferral' | 'showOffer' | 'showOrder' | 'showRenegotiation' | MutationKeySpecifier)[]; export type MutationFieldPolicy = { addListingsOfNftsFromUser?: FieldPolicy | FieldReadFunction, addOrUpdateListing?: FieldPolicy | FieldReadFunction, @@ -3757,6 +3858,7 @@ export type MutationFieldPolicy = { markNotificationIdsAsRead?: FieldPolicy | FieldReadFunction, markNotificationsAsRead?: FieldPolicy | FieldReadFunction, publishBuyNowPayLaterOrder?: FieldPolicy | FieldReadFunction, + publishOrderForNft?: FieldPolicy | FieldReadFunction, publishSellAndRepayOrder?: FieldPolicy | FieldReadFunction, removeListing?: FieldPolicy | FieldReadFunction, removeListingsOfNftsFromUser?: FieldPolicy | FieldReadFunction, @@ -3946,8 +4048,9 @@ export type OfferValidatorFieldPolicy = { offerId?: FieldPolicy | FieldReadFunction, validator?: FieldPolicy | FieldReadFunction }; -export type OrderKeySpecifier = ('createdDate' | 'currency' | 'currencyAddress' | 'evmOrder' | 'expiration' | 'fees' | 'hidden' | 'id' | 'isAsk' | 'isPrivate' | 'maker' | 'marketPlace' | 'netAmount' | 'nonce' | 'orderType' | 'originalId' | 'price' | 'signature' | 'startTime' | 'status' | 'taker' | 'timestamp' | 'txHash' | OrderKeySpecifier)[]; +export type OrderKeySpecifier = ('cancelCalldata' | 'createdDate' | 'currency' | 'currencyAddress' | 'evmOrder' | 'expiration' | 'fees' | 'hidden' | 'id' | 'isAsk' | 'isPrivate' | 'maker' | 'marketPlace' | 'marketPlaceAddress' | 'netAmount' | 'nonce' | 'orderType' | 'originalId' | 'price' | 'signature' | 'startTime' | 'status' | 'taker' | 'timestamp' | 'txHash' | OrderKeySpecifier)[]; export type OrderFieldPolicy = { + cancelCalldata?: FieldPolicy | FieldReadFunction, createdDate?: FieldPolicy | FieldReadFunction, currency?: FieldPolicy | FieldReadFunction, currencyAddress?: FieldPolicy | FieldReadFunction, @@ -3960,6 +4063,7 @@ export type OrderFieldPolicy = { isPrivate?: FieldPolicy | FieldReadFunction, maker?: FieldPolicy | FieldReadFunction, marketPlace?: FieldPolicy | FieldReadFunction, + marketPlaceAddress?: FieldPolicy | FieldReadFunction, netAmount?: FieldPolicy | FieldReadFunction, nonce?: FieldPolicy | FieldReadFunction, orderType?: FieldPolicy | FieldReadFunction, @@ -4034,7 +4138,7 @@ export type PointActivityEdgeFieldPolicy = { cursor?: FieldPolicy | FieldReadFunction, node?: FieldPolicy | FieldReadFunction }; -export type QueryKeySpecifier = ('getCollectionActivitiesCount' | 'getCollectionBySlug' | 'getCollectionLoansData' | 'getCollectionsByContractAddress' | 'getListingById' | 'getLoanActivitiesStatisticsByMonth' | 'getLoanById' | 'getNftByContractAddressAndTokenId' | 'getNftBySlugAndTokenId' | 'getOutstandingLoanStatistics' | 'getPointsFromReferrals' | 'getReferredWallets' | 'getSourcesStatistics' | 'getSourcesStatisticsByCollection' | 'getUserPointActivities' | 'getUserPoints' | 'listAuctions' | 'listBids' | 'listCollections' | 'listCollectionsWithListings' | 'listCollectionsWithLoans' | 'listListings' | 'listListingsForSale' | 'listLoanActivities' | 'listLoanEvents' | 'listLoans' | 'listNftDelegations' | 'listNftOffersAndRenegotiations' | 'listNftsFromCollections' | 'listNftsFromUser' | 'listNotifications' | 'listOffers' | 'listRenegotiations' | 'listSources' | 'me' | QueryKeySpecifier)[]; +export type QueryKeySpecifier = ('getCollectionActivitiesCount' | 'getCollectionBySlug' | 'getCollectionLoansData' | 'getCollectionsByContractAddress' | 'getListingById' | 'getLoanActivitiesStatisticsByMonth' | 'getLoanById' | 'getNftByContractAddressAndTokenId' | 'getNftBySlugAndTokenId' | 'getOutstandingLoanStatistics' | 'getPointsFromReferrals' | 'getReferredWallets' | 'getSourcesStatistics' | 'getSourcesStatisticsByCollection' | 'getUserPointActivities' | 'getUserPoints' | 'listAuctions' | 'listBids' | 'listCollections' | 'listCollectionsWithListings' | 'listCollectionsWithLoans' | 'listListings' | 'listListingsForSale' | 'listLoanActivities' | 'listLoanEvents' | 'listLoans' | 'listNftDelegations' | 'listNftOffersAndRenegotiations' | 'listNftsFromCollections' | 'listNftsFromUser' | 'listNotifications' | 'listOffers' | 'listOrders' | 'listRenegotiations' | 'listSources' | 'me' | QueryKeySpecifier)[]; export type QueryFieldPolicy = { getCollectionActivitiesCount?: FieldPolicy | FieldReadFunction, getCollectionBySlug?: FieldPolicy | FieldReadFunction, @@ -4068,17 +4172,19 @@ export type QueryFieldPolicy = { listNftsFromUser?: FieldPolicy | FieldReadFunction, listNotifications?: FieldPolicy | FieldReadFunction, listOffers?: FieldPolicy | FieldReadFunction, + listOrders?: FieldPolicy | FieldReadFunction, listRenegotiations?: FieldPolicy | FieldReadFunction, listSources?: FieldPolicy | FieldReadFunction, me?: FieldPolicy | FieldReadFunction }; -export type RenegotiationKeySpecifier = ('aprBps' | 'availablePrincipalAmount' | 'createdDate' | 'duration' | 'expirationTime' | 'feeAmount' | 'hidden' | 'id' | 'isAddNewTranche' | 'lenderAddress' | 'loan' | 'loanAddress' | 'loanId' | 'loanReferenceId' | 'nft' | 'offerHash' | 'principalAmount' | 'renegotiationId' | 'repayment' | 'requiresLiquidation' | 'signature' | 'signerAddress' | 'status' | 'strictImprovement' | RenegotiationKeySpecifier)[]; +export type RenegotiationKeySpecifier = ('aprBps' | 'availablePrincipalAmount' | 'createdDate' | 'duration' | 'expirationTime' | 'fallbackOfferId' | 'feeAmount' | 'hidden' | 'id' | 'isAddNewTranche' | 'lenderAddress' | 'loan' | 'loanAddress' | 'loanId' | 'loanReferenceId' | 'nft' | 'offerHash' | 'principalAmount' | 'renegotiationId' | 'repayment' | 'requiresLiquidation' | 'signature' | 'signerAddress' | 'status' | 'strictImprovement' | RenegotiationKeySpecifier)[]; export type RenegotiationFieldPolicy = { aprBps?: FieldPolicy | FieldReadFunction, availablePrincipalAmount?: FieldPolicy | FieldReadFunction, createdDate?: FieldPolicy | FieldReadFunction, duration?: FieldPolicy | FieldReadFunction, expirationTime?: FieldPolicy | FieldReadFunction, + fallbackOfferId?: FieldPolicy | FieldReadFunction, feeAmount?: FieldPolicy | FieldReadFunction, hidden?: FieldPolicy | FieldReadFunction, id?: FieldPolicy | FieldReadFunction, @@ -4226,8 +4332,9 @@ export type SingleNFTOfferCollectionOfferRenegotiationEdgeFieldPolicy = { cursor?: FieldPolicy | FieldReadFunction, node?: FieldPolicy | FieldReadFunction }; -export type SingleNFTOrderKeySpecifier = ('createdDate' | 'currency' | 'currencyAddress' | 'evmOrder' | 'expiration' | 'fees' | 'hidden' | 'id' | 'isAsk' | 'isPrivate' | 'maker' | 'marketPlace' | 'netAmount' | 'nft' | 'nftId' | 'nonce' | 'orderType' | 'originalId' | 'price' | 'signature' | 'startTime' | 'status' | 'taker' | 'timestamp' | 'txHash' | SingleNFTOrderKeySpecifier)[]; +export type SingleNFTOrderKeySpecifier = ('cancelCalldata' | 'createdDate' | 'currency' | 'currencyAddress' | 'evmOrder' | 'expiration' | 'fees' | 'hidden' | 'id' | 'isAsk' | 'isPrivate' | 'maker' | 'marketPlace' | 'marketPlaceAddress' | 'netAmount' | 'nft' | 'nftId' | 'nonce' | 'orderType' | 'originalId' | 'price' | 'signature' | 'startTime' | 'status' | 'taker' | 'timestamp' | 'txHash' | SingleNFTOrderKeySpecifier)[]; export type SingleNFTOrderFieldPolicy = { + cancelCalldata?: FieldPolicy | FieldReadFunction, createdDate?: FieldPolicy | FieldReadFunction, currency?: FieldPolicy | FieldReadFunction, currencyAddress?: FieldPolicy | FieldReadFunction, @@ -4240,6 +4347,7 @@ export type SingleNFTOrderFieldPolicy = { isPrivate?: FieldPolicy | FieldReadFunction, maker?: FieldPolicy | FieldReadFunction, marketPlace?: FieldPolicy | FieldReadFunction, + marketPlaceAddress?: FieldPolicy | FieldReadFunction, netAmount?: FieldPolicy | FieldReadFunction, nft?: FieldPolicy | FieldReadFunction, nftId?: FieldPolicy | FieldReadFunction, @@ -4354,6 +4462,36 @@ export type TraitFieldPolicy = { type?: FieldPolicy | FieldReadFunction, value?: FieldPolicy | FieldReadFunction }; +export type TraitOrderKeySpecifier = ('cancelCalldata' | 'collectionId' | 'createdDate' | 'currency' | 'currencyAddress' | 'evmOrder' | 'expiration' | 'fees' | 'hidden' | 'id' | 'isAsk' | 'isPrivate' | 'maker' | 'marketPlace' | 'marketPlaceAddress' | 'netAmount' | 'nonce' | 'orderType' | 'originalId' | 'price' | 'signature' | 'startTime' | 'status' | 'taker' | 'timestamp' | 'traitId' | 'txHash' | TraitOrderKeySpecifier)[]; +export type TraitOrderFieldPolicy = { + cancelCalldata?: FieldPolicy | FieldReadFunction, + collectionId?: FieldPolicy | FieldReadFunction, + createdDate?: FieldPolicy | FieldReadFunction, + currency?: FieldPolicy | FieldReadFunction, + currencyAddress?: FieldPolicy | FieldReadFunction, + evmOrder?: FieldPolicy | FieldReadFunction, + expiration?: FieldPolicy | FieldReadFunction, + fees?: FieldPolicy | FieldReadFunction, + hidden?: FieldPolicy | FieldReadFunction, + id?: FieldPolicy | FieldReadFunction, + isAsk?: FieldPolicy | FieldReadFunction, + isPrivate?: FieldPolicy | FieldReadFunction, + maker?: FieldPolicy | FieldReadFunction, + marketPlace?: FieldPolicy | FieldReadFunction, + marketPlaceAddress?: FieldPolicy | FieldReadFunction, + netAmount?: FieldPolicy | FieldReadFunction, + nonce?: FieldPolicy | FieldReadFunction, + orderType?: FieldPolicy | FieldReadFunction, + originalId?: FieldPolicy | FieldReadFunction, + price?: FieldPolicy | FieldReadFunction, + signature?: FieldPolicy | FieldReadFunction, + startTime?: FieldPolicy | FieldReadFunction, + status?: FieldPolicy | FieldReadFunction, + taker?: FieldPolicy | FieldReadFunction, + timestamp?: FieldPolicy | FieldReadFunction, + traitId?: FieldPolicy | FieldReadFunction, + txHash?: FieldPolicy | FieldReadFunction +}; export type TypedDataKeySpecifier = ('domain' | 'message' | 'primaryType' | 'types' | TypedDataKeySpecifier)[]; export type TypedDataFieldPolicy = { domain?: FieldPolicy | FieldReadFunction, @@ -4878,6 +5016,10 @@ export type StrictTypedTypePolicies = { keyFields?: false | TraitKeySpecifier | (() => undefined | TraitKeySpecifier), fields?: TraitFieldPolicy, }, + TraitOrder?: Omit & { + keyFields?: false | TraitOrderKeySpecifier | (() => undefined | TraitOrderKeySpecifier), + fields?: TraitOrderFieldPolicy, + }, TypedData?: Omit & { keyFields?: false | TypedDataKeySpecifier | (() => undefined | TypedDataKeySpecifier), fields?: TypedDataFieldPolicy, @@ -5034,6 +5176,28 @@ export const HideOrderDocument = gql` } } `; +export const PublishOrderForNftDocument = gql` + mutation publishOrderForNft($orderInput: SingleNFTOrderInput!) { + result: publishOrderForNft(orderInput: $orderInput) { + ... on SingleNFTOrder { + id + status + signature + cancelCalldata + marketPlaceAddress + } + ... on SignatureRequest { + key + typedData { + types + primaryType + domain + message + } + } + } +} + `; export const PublishSellAndRepayOrderDocument = gql` mutation publishSellAndRepayOrder($orderInput: NFTOrderInput!) { result: publishSellAndRepayOrder(orderInput: $orderInput) { @@ -5509,6 +5673,9 @@ export function getSdk(requester: Requester) { hideOrder(variables: HideOrderMutationVariables, options?: C): Promise { return requester(HideOrderDocument, variables, options) as Promise; }, + publishOrderForNft(variables: PublishOrderForNftMutationVariables, options?: C): Promise { + return requester(PublishOrderForNftDocument, variables, options) as Promise; + }, publishSellAndRepayOrder(variables: PublishSellAndRepayOrderMutationVariables, options?: C): Promise { return requester(PublishSellAndRepayOrderDocument, variables, options) as Promise; }, diff --git a/src/generated/graphql/lending-schema.graphql b/src/generated/graphql/lending-schema.graphql index 59127449..691cb219 100644 --- a/src/generated/graphql/lending-schema.graphql +++ b/src/generated/graphql/lending-schema.graphql @@ -170,6 +170,7 @@ input BigIntInterval { } type BuyNowPayLaterOrder implements Activity & Node & Order { + cancelCalldata: Hex! createdDate: DateTime! currency: Currency! currencyAddress: Address! @@ -316,6 +317,7 @@ type CollectionOfferStatistics { } type CollectionOrder implements Activity & Node & Order { + cancelCalldata: Hex! collection: Collection! createdDate: DateTime! currency: Currency! @@ -329,6 +331,7 @@ type CollectionOrder implements Activity & Node & Order { isPrivate: Boolean! maker: Address! marketPlace: String! + marketPlaceAddress: Address! netAmount: BigInt! nonce: BigInt! orderType: String! @@ -866,6 +869,7 @@ type LoansData { type LostSource implements Node { accruedInterest: BigInt! + activity: LoanActivity! activityId: String! aprBps: BigInt! duration: BigInt! @@ -984,10 +988,11 @@ type Mutation { hideAllOffers(contractAddress: Address!, minOfferId: String!): [Offer!]! hideOffer(contractAddress: Address!, offerId: String!): Offer! hideOrder(orderId: Int!): Order! - hideRenegotiation(contractAddress: Address = "0xca5a494ca20483e21ec1e41fe1d9461da77595bd", renegotiationId: String!): Renegotiation! + hideRenegotiation(contractAddress: Address = "0xcf7ed3acca5a467e9e704c703e8d87f634fb0fc9", renegotiationId: String!): Renegotiation! markNotificationIdsAsRead(ids: [Int!]): Void markNotificationsAsRead: Void publishBuyNowPayLaterOrder(orderInput: BNPLOrderInput!): BuyNowPayLaterOrderSignatureRequest! + publishOrderForNft(orderInput: SingleNFTOrderInput!): SingleNFTOrderSignatureRequest! publishSellAndRepayOrder(orderInput: NFTOrderInput!): SellAndRepayOrderSignatureRequest! removeListing(nftId: Int!): Listing! removeListingsOfNftsFromUser(excludeCollections: [String!] = null, onlyCollections: [String!] = null, searchTerm: String = null): Void @@ -999,7 +1004,7 @@ type Mutation { setReferral(referrerId: Int!): Void showOffer(contractAddress: Address!, offerId: String!): Offer! showOrder(orderId: Int!): Order! - showRenegotiation(contractAddress: Address = "0xca5a494ca20483e21ec1e41fe1d9461da77595bd", renegotiationId: String!): Renegotiation! + showRenegotiation(contractAddress: Address = "0xcf7ed3acca5a467e9e704c703e8d87f634fb0fc9", renegotiationId: String!): Renegotiation! } type NFT implements Node { @@ -1272,6 +1277,7 @@ input OffersSortInput { } interface Order implements Activity & Node { + cancelCalldata: Hex! createdDate: DateTime! currency: Currency! currencyAddress: Address! @@ -1284,6 +1290,7 @@ interface Order implements Activity & Node { isPrivate: Boolean! maker: Address! marketPlace: String! + marketPlaceAddress: Address! netAmount: BigInt! nonce: BigInt! orderType: String! @@ -1310,6 +1317,9 @@ type OrderEdge { enum OrderSortField { EXPIRATION + FEE + NET_AMOUNT + PRICE } input OrderSortInput { @@ -1326,6 +1336,15 @@ enum OrderStatusType { Outperformed } +input OrderTermsFilter { + netAmount: BigIntInterval = null +} + +enum OrderType { + ASK + BID +} + enum Ordering { ASC DESC @@ -1442,6 +1461,7 @@ type Query { listNftsFromUser(after: String, collectionAddresses: [Address!] = null, first: Int = 10, includeInStash: Boolean! = false, searchTerm: String = null, sortBy: [NftSortInput!] = null, standards: [TokenStandardType!] = null, withLoans: Boolean = false, withNoWraps: Boolean = false): NFTConnection! listNotifications(after: String, first: Int = 50, notificationTypes: [NotificationType!] = null, onlyRead: Boolean! = false, onlyUnread: Boolean! = false): NotificationConnection! listOffers(after: String, borrowerAddress: String = null, collections: [Int!] = null, contractAddress: Address = null, currencyAddress: Address = null, first: Int = 10, hidden: Boolean = null, lenders: [String!] = null, nfts: [Int!] = null, onlyCollectionOffers: Boolean = false, onlySingleNftOffers: Boolean = false, sortBy: [OffersSortInput!] = null, statuses: [OfferStatus!] = null, terms: TermsFilter = null, worseOffers: Boolean = true): OfferConnection! + listOrders(after: String, currencyAddresses: [Address!] = null, first: Int = 10, hidden: Boolean = null, ids: [Int!] = null, marketplaceIds: [String!] = null, marketplaces: [MarketPlaceType!] = null, nftIds: [Int!] = null, orderType: OrderType = null, sortBy: [OrderSortInput!] = null, statuses: [OrderStatusType!] = null, taker: Address = null, terms: OrderTermsFilter = null): OrderConnection! listRenegotiations(after: String, collections: [Int!] = null, first: Int = 10, hidden: Boolean = null, isAddNewTranche: Boolean = null, loanId: String = null, sortBy: [OffersSortInput!] = null, statuses: [OfferStatus!] = null, terms: RefinanceTermsFilter = null): RenegotiationConnection! listSources(after: String, collections: [Int!] = null, contractAddresses: [Address!] = null, currencyAddress: Address = null, excludeAddresses: [Address!] = null, first: Int! = 10, hideEndLocked: Boolean = null, hideLocked: Boolean = null, includeLost: Boolean = null, lenders: [String!] = null, loanPrincipal: Interval = null, sortBy: [SourceSortInput!] = null, statuses: [LoanStatusType!] = null, terms: TermsFilter = null, withdrawalQueues: [Int!] = null): SourceLostSourceConnection! me: User @@ -1468,6 +1488,7 @@ type Renegotiation implements Node { createdDate: DateTime duration: BigInt! expirationTime: BigInt! + fallbackOfferId: String feeAmount: BigInt! hidden: Boolean id: String! @@ -1679,6 +1700,7 @@ input SingleNFTOfferInput { } type SingleNFTOrder implements Activity & Node & Order { + cancelCalldata: Hex! createdDate: DateTime! currency: Currency! currencyAddress: Address! @@ -1691,6 +1713,7 @@ type SingleNFTOrder implements Activity & Node & Order { isPrivate: Boolean! maker: Address! marketPlace: String! + marketPlaceAddress: Address! netAmount: BigInt! nft: NFT! nftId: Int! @@ -1706,6 +1729,20 @@ type SingleNFTOrder implements Activity & Node & Order { txHash: Hash } +input SingleNFTOrderInput { + amount: BigInt! + contractAddress: Address! + currencyAddress: Address! + expirationTime: BigInt! + isAsk: Boolean! + signature: Signature = null + startTime: BigInt! + taker: Address = null + tokenId: BigInt! +} + +union SingleNFTOrderSignatureRequest = SignatureRequest | SingleNFTOrder + input SingleNFTSignedOfferInput { aprBps: BigInt! borrowerAddress: Address! @@ -1870,6 +1907,36 @@ input TraitKeyValueOptionsInput { values: [String!]! } +type TraitOrder implements Activity & Node & Order { + cancelCalldata: Hex! + collectionId: Int! + createdDate: DateTime! + currency: Currency! + currencyAddress: Address! + evmOrder: JSON + expiration: DateTime! + fees: BigInt! + hidden: Boolean! + id: String! + isAsk: Boolean! + isPrivate: Boolean! + maker: Address! + marketPlace: String! + marketPlaceAddress: Address! + netAmount: BigInt! + nonce: BigInt! + orderType: String! + originalId: Hash! + price: BigInt! + signature: Signature! + startTime: DateTime! + status: String! + taker: Address! + timestamp: DateTime! + traitId: Int! + txHash: Hash +} + input TraitRangeOptionsInput { key: String! range: RangeInput! diff --git a/src/gondi.ts b/src/gondi.ts index ce154607..c71d8098 100644 --- a/src/gondi.ts +++ b/src/gondi.ts @@ -207,7 +207,22 @@ export class Gondi { return await this.api.saveCollectionOffer(signedOffer); } - async makeOrder(sellAndRepayOrderInput: Parameters[0]) { + async makeOrder(orderInput: Parameters[0]) { + let response = await this.api.publishOrder(orderInput); + while (response.__typename === 'SignatureRequest') { + const key = response.key as 'signature'; + orderInput[key] = await this.wallet.signTypedData(response.typedData as TypedDataDefinition); + response = await this.api.publishOrder(orderInput); + } + + if (response.__typename !== 'SingleNFTOrder') throw new Error('This should never happen'); + + return { ...response, ...orderInput }; + } + + async makeSellAndRepayOrder( + sellAndRepayOrderInput: Parameters[0], + ) { let response = await this.api.publishSellAndRepayOrder(sellAndRepayOrderInput); while (response.__typename === 'SignatureRequest') { const key = response.key as 'signature' | 'repaymentSignature';