Skip to content

Commit

Permalink
Merge branch 'main' into ormi-0xgraph-deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
levalleux-ludo committed Sep 23, 2024
2 parents 7a38e0e + c2b0d3f commit 3be9696
Show file tree
Hide file tree
Showing 30 changed files with 214 additions and 119 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
- name: Build
run: |
npm run build -- --cache-dir=".turbo"
- run: cd e2e && docker-compose build && cd ..
- run: cd e2e && docker compose build && cd ..
# In this step, this action saves a list of existing images,
# the cache is created without them in the post run.
# It also restores the cache if it exists.
Expand Down
6 changes: 3 additions & 3 deletions e2e/run-e2e-services.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ call npm ci
cd ..
cd e2e

docker-compose up -d
docker compose up -d

echo *** Waiting for services... ***
timeout /t 15 /nobreak >nul
echo.

echo *** Deploying contracts... ***
docker-compose exec hardhat-node npm run deploy
docker compose exec hardhat-node npm run deploy
if %ERRORLEVEL% NEQ 0 (
echo Contracts couldn't be deployed
exit /B 1
Expand All @@ -34,6 +34,6 @@ echo *** Successfully deployed subgraph ***
echo.

set /p DUMMY=*** Press any key to shutdown services ***
docker-compose down -v
docker compose down -v
rmdir /S /Q .\data
cd ..
4 changes: 2 additions & 2 deletions e2e/run-e2e-services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
trap cleanup EXIT INT TERM

function cleanup() {
docker-compose down -v
docker compose down -v
rm -rf ./data
exit
}
Expand All @@ -14,7 +14,7 @@ npm ci
cd ..
cd e2e

docker-compose up -d #--build
docker compose up -d #--build

echo "Waiting for services..."
sleep 15
Expand Down
6 changes: 3 additions & 3 deletions e2e/run-e2e-suite.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ call npm ci
cd ..
cd e2e

docker-compose up -d
docker compose up -d

echo *** Waiting for services... ***
timeout /t 15 /nobreak >nul
echo.

echo *** Deploying contracts... ***
docker-compose exec hardhat-node npm run deploy
docker compose exec hardhat-node npm run deploy
if %ERRORLEVEL% NEQ 0 (
echo Contracts couldn't be deployed
exit /B 1
Expand All @@ -35,6 +35,6 @@ call npm run e2e:test -- --no-cache
set EXIT_STATUS=%ERRORLEVEL%

cd e2e
docker-compose down -v
docker compose down -v
cd ..
exit %EXIT_STATUS%
4 changes: 2 additions & 2 deletions e2e/run-e2e-suite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ trap cleanup EXIT INT TERM
function cleanup() {
exit_status=$?
cd e2e
docker-compose down -v
docker compose down -v
exit "$exit_status"
}

Expand All @@ -15,7 +15,7 @@ npm ci
cd ..
cd e2e

docker-compose up -d
docker compose up -d

echo "Waiting for services..."
sleep 15
Expand Down
12 changes: 5 additions & 7 deletions e2e/tests/opensea-price-discovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,13 +532,11 @@ describe("Opensea Price Discovery", () => {
sellerCoreSDK
);
// Call commitToPriceDiscoveryOffer, that will fulfil the Order on Seaport
const fulfilmentData = await openseaSdkSeller.generateFulfilmentData(
{
contract: voucherContract,
tokenId: listing.asset.tokenId
},
true // withWrapper
);
const fulfilmentData = await openseaSdkSeller.generateFulfilmentData({
contract: voucherContract,
tokenId: listing.asset.tokenId,
withWrapper: true
});
const txCommit = await sellerCoreSDK.commitToPriceDiscoveryOffer(
buyerWallet.address,
listing.asset.tokenId,
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion packages/core-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bosonprotocol/core-sdk",
"version": "1.41.0-alpha.0",
"version": "1.41.0-alpha.8",
"description": "Facilitates interaction with the contracts and subgraphs of the Boson Protocol",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
Expand Down
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
1 change: 1 addition & 0 deletions packages/core-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export * as groups from "./groups";
export * as forwarder from "./forwarder";
export * as voucher from "./voucher";
export * as seaport from "./seaport";
export * as marketplaces from "./marketplaces";

export {
envConfigs,
Expand Down
1 change: 1 addition & 0 deletions packages/core-sdk/src/marketplaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./types";
69 changes: 51 additions & 18 deletions packages/core-sdk/src/marketplaces/opensea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
FulfillmentDataResponse,
GetNFTResponse,
OrderAPIOptions,
OrderSide,
OrderV2,
OrdersQueryOptions,
ProtocolData
Expand All @@ -18,6 +17,8 @@ import {
Marketplace,
MarketplaceType,
Order,
OrderFilterOptions,
OrderSide,
SignedOrder,
Wrapper
} from "./types";
Expand Down Expand Up @@ -68,6 +69,9 @@ export type OpenSeaSDKHandler = {
api: {
apiBaseUrl: string;
getOrder(order: Omit<OrdersQueryOptions, "limit">): Promise<OrderV2>;
getOrders(
order: Omit<OrdersQueryOptions, "limit">
): Promise<{ orders: OrderV2[] }>;
generateFulfillmentData(
fulfillerAddress: string,
orderHash: string,
Expand Down Expand Up @@ -253,7 +257,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 +269,26 @@ export class OpenSeaMarketplace extends Marketplace {
return this.convertOsOrder(osOrder);
}

public async buildAdvancedOrder(asset: {
contract: string;
tokenId: string;
}): Promise<AdvancedOrder> {
// Asumption: we're fulfilling a Bid Order (don't know if it makes sense with an Ask order)
public async buildAdvancedOrder(
asset: {
contract: string;
tokenId: string;
withWrapper?: boolean;
},
filter: OrderFilterOptions = {}
): Promise<AdvancedOrder> {
// Assumption: 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
side: OrderSide.BID,
...filter
});
const fulfillerAddress = asset.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 All @@ -291,13 +303,12 @@ export class OpenSeaMarketplace extends Marketplace {
return inputData.orders[0];
}

public async generateFulfilmentData(
asset: {
contract: string;
tokenId: string;
},
withWrapper = false
): Promise<PriceDiscoveryStruct> {
public async generateFulfilmentData(asset: {
contract: string;
tokenId: string;
withWrapper?: boolean;
}): Promise<PriceDiscoveryStruct> {
const withWrapper = !!asset.withWrapper;
const wrapper = withWrapper
? await this.getOrCreateVouchersWrapper(asset.contract)
: undefined;
Expand Down Expand Up @@ -583,12 +594,14 @@ export class OpenSeaMarketplace extends Marketplace {
contract: string;
tokenId: string;
},
side: Side
side: Side,
filter: OrderFilterOptions = {}
): Promise<SignedOrder> {
const osOrder = await this._handler.api.getOrder({
assetContractAddress: asset.contract,
tokenId: asset.tokenId,
side: side === Side.Ask ? OrderSide.ASK : OrderSide.BID
side: side === Side.Ask ? OrderSide.ASK : OrderSide.BID,
...filter
});
return osOrder
? {
Expand All @@ -597,4 +610,24 @@ export class OpenSeaMarketplace extends Marketplace {
}
: undefined;
}

public async getOrders(
asset: {
contract: string;
tokenIds: string[];
},
side: Side,
filter: OrderFilterOptions = {}
): Promise<SignedOrder[]> {
const { orders } = await this._handler.api.getOrders({
assetContractAddress: asset.contract,
tokenIds: asset.tokenIds,
side: side === Side.Ask ? OrderSide.ASK : OrderSide.BID,
...filter
});
return orders.map((osOrder) => ({
...this.convertOsOrder(osOrder),
signature: osOrder.protocolData?.signature
}));
}
}
Loading

0 comments on commit 3be9696

Please sign in to comment.