Skip to content

Commit

Permalink
feat: publish order
Browse files Browse the repository at this point in the history
  • Loading branch information
uzielflorida committed Mar 4, 2025
1 parent 24fdb3a commit 12b5e75
Show file tree
Hide file tree
Showing 11 changed files with 301 additions and 22 deletions.
2 changes: 1 addition & 1 deletion examples/buyWithSellAndRepay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/cancelOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/makeOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@
"viem": "~2.21.0"
},
"packageManager": "yarn@4.2.1"
}
}
20 changes: 20 additions & 0 deletions src/api/graphql/mutations/orders/publishOrder.gql
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
6 changes: 6 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ListLoansQueryVariables,
ListOffersQueryVariables,
NftOrderInput,
SingleNftOrderInput,
SingleNftSignedOfferInput,
} from '@/generated/graphql';
import { RenegotiationOffer } from '@/model';
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions src/contracts/BaseContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,14 @@ export class BaseContract<TAbi extends Abi> {
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;
},
};
}
}
191 changes: 179 additions & 12 deletions src/generated/graphql/index.ts

Large diffs are not rendered by default.

71 changes: 69 additions & 2 deletions src/generated/graphql/lending-schema.graphql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion src/gondi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,22 @@ export class Gondi {
return await this.api.saveCollectionOffer(signedOffer);
}

async makeOrder(sellAndRepayOrderInput: Parameters<Api['publishSellAndRepayOrder']>[0]) {
async makeOrder(orderInput: Parameters<Api['publishOrder']>[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<Api['publishSellAndRepayOrder']>[0],
) {
let response = await this.api.publishSellAndRepayOrder(sellAndRepayOrderInput);
while (response.__typename === 'SignatureRequest') {
const key = response.key as 'signature' | 'repaymentSignature';
Expand Down

0 comments on commit 12b5e75

Please sign in to comment.