Skip to content

Commit

Permalink
chore: a few changes required to run the opensea flow on Fermion prot…
Browse files Browse the repository at this point in the history
…ocol (#789)
  • Loading branch information
levalleux-ludo committed Aug 28, 2024
1 parent 9018bd3 commit 14017f8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
5 changes: 4 additions & 1 deletion packages/core-sdk/src/erc20/handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Web3LibAdapter } from "@bosonprotocol/common";
import { Web3LibAdapter, TransactionRequest } from "@bosonprotocol/common";
import { BigNumber, BigNumberish } from "@ethersproject/bignumber";
import { erc20Iface } from "./interface";

Expand All @@ -7,8 +7,10 @@ export async function approve(args: {
spender: string;
value: BigNumberish;
web3Lib: Web3LibAdapter;
txRequest?: TransactionRequest;
}) {
return args.web3Lib.sendTransaction({
...args.txRequest,
to: args.contractAddress,
data: erc20Iface.encodeFunctionData("approve", [args.spender, args.value])
});
Expand Down Expand Up @@ -74,6 +76,7 @@ export async function ensureAllowance(args: {
contractAddress: string;
value: BigNumberish;
web3Lib: Web3LibAdapter;
txRequest?: TransactionRequest;
}) {
const allowance = await getAllowance(args);
if (BigNumber.from(allowance).lt(args.value)) {
Expand Down
4 changes: 3 additions & 1 deletion packages/core-sdk/src/erc721/handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Web3LibAdapter } from "@bosonprotocol/common";
import { TransactionRequest, Web3LibAdapter } from "@bosonprotocol/common";
import { BigNumberish } from "@ethersproject/bignumber";
import { erc721Iface } from "./interface";

Expand Down Expand Up @@ -101,8 +101,10 @@ export async function setApprovalForAll(args: {
operator: string;
approved: boolean;
web3Lib: Web3LibAdapter;
txRequest?: TransactionRequest;
}) {
return args.web3Lib.sendTransaction({
...args.txRequest,
to: args.contractAddress,
data: erc721Iface.encodeFunctionData("setApprovalForAll", [
args.operator,
Expand Down
18 changes: 12 additions & 6 deletions packages/core-sdk/src/marketplaces/opensea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export class OpenSeaMarketplace extends Marketplace {
const protocolAddress = listing.protocolAddress || this._contracts.seaport;
if (!protocolAddress) {
throw new Error(
`Seaport protocol address must be specified in Lsiting or CoreSDK config`
`Seaport protocol address must be specified in Listing or CoreSDK config`
);
}

Expand All @@ -265,18 +265,24 @@ export class OpenSeaMarketplace extends Marketplace {
return this.convertOsOrder(osOrder);
}

public async buildAdvancedOrder(asset: {
contract: string;
tokenId: string;
}): Promise<AdvancedOrder> {
public async buildAdvancedOrder(
asset: {
contract: string;
tokenId: string;
},
withWrapper = false
): Promise<AdvancedOrder> {
// Asumption: we're fulfilling a Bid Order (don't know if it makes sense with an Ask order)
const osOrder = await this._handler.api.getOrder({
assetContractAddress: asset.contract,
tokenId: asset.tokenId,
side: OrderSide.BID
});
const fulfillerAddress = withWrapper
? asset.contract // If the token is wrapped, the fulfiller is the wrapper contract itself
: this._contracts.priceDiscoveryClient; // otherwise the address of the PriceDiscoveryClient contract
const ffd = await this._handler.api.generateFulfillmentData(
this._contracts.priceDiscoveryClient, // the address of the PriceDiscoveryClient contract, which will call the fulfilment method
fulfillerAddress,
osOrder.orderHash,
osOrder.protocolAddress,
osOrder.side
Expand Down
11 changes: 7 additions & 4 deletions packages/core-sdk/src/marketplaces/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@ export abstract class Marketplace {
},
withWrapper?: boolean
): Promise<PriceDiscoveryStruct>;
public abstract buildAdvancedOrder(asset: {
contract: string;
tokenId: string;
}): Promise<AdvancedOrder>;
public abstract buildAdvancedOrder(
asset: {
contract: string;
tokenId: string;
},
withWrapper?: boolean
): Promise<AdvancedOrder>;
public abstract wrapVouchers(
contract: string,
tokenIds: string[]
Expand Down

0 comments on commit 14017f8

Please sign in to comment.