@imtbl/sdk 0.1.8-alpha → 0.1.8-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blockchain-data.js +1 -1
- package/dist/browser/checkout.js +2 -2
- package/dist/immutablex_client.js +1 -1
- package/dist/index.cjs +261 -196
- package/dist/index.js +261 -196
- package/dist/orderbook.js +259 -194
- package/dist/passport.js +1 -1
- package/package.json +1 -1
|
@@ -16,7 +16,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
16
16
|
chainID,
|
|
17
17
|
coreContractAddress,
|
|
18
18
|
registrationContractAddress,
|
|
19
|
-
sdkVersion: 'ts-immutable-sdk-0.1.8-alpha',
|
|
19
|
+
sdkVersion: 'ts-immutable-sdk-0.1.8-alpha.1',
|
|
20
20
|
});
|
|
21
21
|
/**
|
|
22
22
|
* Sets `sdkVersion` at the time of build
|
package/dist/index.cjs
CHANGED
|
@@ -8,7 +8,6 @@ var magicSdk = require('magic-sdk');
|
|
|
8
8
|
var oidc = require('@magic-ext/oidc');
|
|
9
9
|
var BN = require('bn.js');
|
|
10
10
|
var encUtils = require('enc-utils');
|
|
11
|
-
var constants = require('@opensea/seaport-js/lib/constants');
|
|
12
11
|
var FormData = require('form-data');
|
|
13
12
|
var seaportJs = require('@opensea/seaport-js');
|
|
14
13
|
var units = require('@ethersproject/units');
|
|
@@ -3282,6 +3281,265 @@ var SellItem;
|
|
|
3282
3281
|
})(SellItem.item_type || (SellItem.item_type = {}));
|
|
3283
3282
|
})(SellItem || (SellItem = {}));
|
|
3284
3283
|
|
|
3284
|
+
/* eslint-disable */
|
|
3285
|
+
// TODO: Resolve these from seaport-js.
|
|
3286
|
+
// There is some bundling issue that is preventing this from working
|
|
3287
|
+
const SEAPORT_CONTRACT_NAME = 'Seaport';
|
|
3288
|
+
const SEAPORT_CONTRACT_VERSION_V1_4 = '1.4';
|
|
3289
|
+
const EIP_712_ORDER_TYPE = {
|
|
3290
|
+
OrderComponents: [
|
|
3291
|
+
{ name: 'offerer', type: 'address' },
|
|
3292
|
+
{ name: 'zone', type: 'address' },
|
|
3293
|
+
{ name: 'offer', type: 'OfferItem[]' },
|
|
3294
|
+
{ name: 'consideration', type: 'ConsiderationItem[]' },
|
|
3295
|
+
{ name: 'orderType', type: 'uint8' },
|
|
3296
|
+
{ name: 'startTime', type: 'uint256' },
|
|
3297
|
+
{ name: 'endTime', type: 'uint256' },
|
|
3298
|
+
{ name: 'zoneHash', type: 'bytes32' },
|
|
3299
|
+
{ name: 'salt', type: 'uint256' },
|
|
3300
|
+
{ name: 'conduitKey', type: 'bytes32' },
|
|
3301
|
+
{ name: 'counter', type: 'uint256' },
|
|
3302
|
+
],
|
|
3303
|
+
OfferItem: [
|
|
3304
|
+
{ name: 'itemType', type: 'uint8' },
|
|
3305
|
+
{ name: 'token', type: 'address' },
|
|
3306
|
+
{ name: 'identifierOrCriteria', type: 'uint256' },
|
|
3307
|
+
{ name: 'startAmount', type: 'uint256' },
|
|
3308
|
+
{ name: 'endAmount', type: 'uint256' },
|
|
3309
|
+
],
|
|
3310
|
+
ConsiderationItem: [
|
|
3311
|
+
{ name: 'itemType', type: 'uint8' },
|
|
3312
|
+
{ name: 'token', type: 'address' },
|
|
3313
|
+
{ name: 'identifierOrCriteria', type: 'uint256' },
|
|
3314
|
+
{ name: 'startAmount', type: 'uint256' },
|
|
3315
|
+
{ name: 'endAmount', type: 'uint256' },
|
|
3316
|
+
{ name: 'recipient', type: 'address' },
|
|
3317
|
+
],
|
|
3318
|
+
};
|
|
3319
|
+
var OrderType;
|
|
3320
|
+
(function (OrderType) {
|
|
3321
|
+
OrderType[OrderType["FULL_OPEN"] = 0] = "FULL_OPEN";
|
|
3322
|
+
OrderType[OrderType["PARTIAL_OPEN"] = 1] = "PARTIAL_OPEN";
|
|
3323
|
+
OrderType[OrderType["FULL_RESTRICTED"] = 2] = "FULL_RESTRICTED";
|
|
3324
|
+
OrderType[OrderType["PARTIAL_RESTRICTED"] = 3] = "PARTIAL_RESTRICTED";
|
|
3325
|
+
})(OrderType || (OrderType = {}));
|
|
3326
|
+
var ItemType;
|
|
3327
|
+
(function (ItemType) {
|
|
3328
|
+
ItemType[ItemType["NATIVE"] = 0] = "NATIVE";
|
|
3329
|
+
ItemType[ItemType["ERC20"] = 1] = "ERC20";
|
|
3330
|
+
ItemType[ItemType["ERC721"] = 2] = "ERC721";
|
|
3331
|
+
ItemType[ItemType["ERC1155"] = 3] = "ERC1155";
|
|
3332
|
+
ItemType[ItemType["ERC721_WITH_CRITERIA"] = 4] = "ERC721_WITH_CRITERIA";
|
|
3333
|
+
ItemType[ItemType["ERC1155_WITH_CRITERIA"] = 5] = "ERC1155_WITH_CRITERIA";
|
|
3334
|
+
})(ItemType || (ItemType = {}));
|
|
3335
|
+
var Side;
|
|
3336
|
+
(function (Side) {
|
|
3337
|
+
Side[Side["OFFER"] = 0] = "OFFER";
|
|
3338
|
+
Side[Side["CONSIDERATION"] = 1] = "CONSIDERATION";
|
|
3339
|
+
})(Side || (Side = {}));
|
|
3340
|
+
var BasicOrderRouteType;
|
|
3341
|
+
(function (BasicOrderRouteType) {
|
|
3342
|
+
BasicOrderRouteType[BasicOrderRouteType["ETH_TO_ERC721"] = 0] = "ETH_TO_ERC721";
|
|
3343
|
+
BasicOrderRouteType[BasicOrderRouteType["ETH_TO_ERC1155"] = 1] = "ETH_TO_ERC1155";
|
|
3344
|
+
BasicOrderRouteType[BasicOrderRouteType["ERC20_TO_ERC721"] = 2] = "ERC20_TO_ERC721";
|
|
3345
|
+
BasicOrderRouteType[BasicOrderRouteType["ERC20_TO_ERC1155"] = 3] = "ERC20_TO_ERC1155";
|
|
3346
|
+
BasicOrderRouteType[BasicOrderRouteType["ERC721_TO_ERC20"] = 4] = "ERC721_TO_ERC20";
|
|
3347
|
+
BasicOrderRouteType[BasicOrderRouteType["ERC1155_TO_ERC20"] = 5] = "ERC1155_TO_ERC20";
|
|
3348
|
+
})(BasicOrderRouteType || (BasicOrderRouteType = {}));
|
|
3349
|
+
|
|
3350
|
+
function getOrderComponentsFromMessage(orderMessage) {
|
|
3351
|
+
const data = JSON.parse(orderMessage);
|
|
3352
|
+
const orderComponents = data.message;
|
|
3353
|
+
orderComponents.salt = ethers.BigNumber.from(orderComponents.salt).toHexString();
|
|
3354
|
+
return orderComponents;
|
|
3355
|
+
}
|
|
3356
|
+
|
|
3357
|
+
// Add 20% more gas than estimate to prevent out of gas errors
|
|
3358
|
+
// This can always be overwritten by the user signing the transaction
|
|
3359
|
+
async function prepareTransaction(transactionMethods) {
|
|
3360
|
+
const transaction = await transactionMethods.buildTransaction();
|
|
3361
|
+
transaction.gasLimit = await transactionMethods.estimateGas();
|
|
3362
|
+
transaction.gasLimit = transaction.gasLimit
|
|
3363
|
+
.add(transaction.gasLimit.div(5));
|
|
3364
|
+
return transaction;
|
|
3365
|
+
}
|
|
3366
|
+
|
|
3367
|
+
function mapImmutableOrderToSeaportOrderComponents(order, counter, zoneAddress) {
|
|
3368
|
+
const considerationItems = order.buy.map((buyItem) => ({
|
|
3369
|
+
startAmount: buyItem.start_amount,
|
|
3370
|
+
endAmount: buyItem.start_amount,
|
|
3371
|
+
itemType: buyItem.item_type === 'ERC20' ? ItemType.ERC20 : ItemType.NATIVE,
|
|
3372
|
+
recipient: order.account_address,
|
|
3373
|
+
token: buyItem.contract_address || ethers.constants.AddressZero,
|
|
3374
|
+
identifierOrCriteria: '0',
|
|
3375
|
+
}));
|
|
3376
|
+
const fees = order.buy_fees.map((fee) => ({
|
|
3377
|
+
startAmount: fee.amount,
|
|
3378
|
+
endAmount: fee.amount,
|
|
3379
|
+
itemType: order.buy[0].item_type === 'ERC20' ? ItemType.ERC20 : ItemType.NATIVE,
|
|
3380
|
+
recipient: fee.recipient,
|
|
3381
|
+
token: order.buy[0].contract_address || ethers.constants.AddressZero,
|
|
3382
|
+
identifierOrCriteria: '0',
|
|
3383
|
+
}));
|
|
3384
|
+
return {
|
|
3385
|
+
conduitKey: ethers.constants.HashZero,
|
|
3386
|
+
consideration: [...considerationItems, ...fees],
|
|
3387
|
+
offer: order.sell.map((sellItem) => ({
|
|
3388
|
+
startAmount: '1',
|
|
3389
|
+
endAmount: '1',
|
|
3390
|
+
itemType: ItemType.ERC721,
|
|
3391
|
+
token: sellItem.contract_address,
|
|
3392
|
+
identifierOrCriteria: sellItem.token_id,
|
|
3393
|
+
})),
|
|
3394
|
+
counter,
|
|
3395
|
+
endTime: Math.round(new Date(order.end_time).getTime() / 1000).toString(),
|
|
3396
|
+
startTime: Math.round(new Date(order.start_time).getTime() / 1000).toString(),
|
|
3397
|
+
salt: order.salt,
|
|
3398
|
+
offerer: order.account_address,
|
|
3399
|
+
zone: zoneAddress,
|
|
3400
|
+
totalOriginalConsiderationItems: 2,
|
|
3401
|
+
orderType: OrderType.FULL_RESTRICTED,
|
|
3402
|
+
zoneHash: ethers.constants.HashZero,
|
|
3403
|
+
};
|
|
3404
|
+
}
|
|
3405
|
+
|
|
3406
|
+
class Seaport {
|
|
3407
|
+
seaport;
|
|
3408
|
+
provider;
|
|
3409
|
+
seaportContractAddress;
|
|
3410
|
+
zoneContractAddress;
|
|
3411
|
+
constructor(seaport, provider, seaportContractAddress, zoneContractAddress) {
|
|
3412
|
+
this.seaport = seaport;
|
|
3413
|
+
this.provider = provider;
|
|
3414
|
+
this.seaportContractAddress = seaportContractAddress;
|
|
3415
|
+
this.zoneContractAddress = zoneContractAddress;
|
|
3416
|
+
}
|
|
3417
|
+
async prepareSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry) {
|
|
3418
|
+
const { actions } = await this.createSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry);
|
|
3419
|
+
let approvalTransaction;
|
|
3420
|
+
const approvalAction = actions
|
|
3421
|
+
.find((action) => action.type === 'approval');
|
|
3422
|
+
if (approvalAction) {
|
|
3423
|
+
approvalTransaction = await prepareTransaction(approvalAction.transactionMethods);
|
|
3424
|
+
}
|
|
3425
|
+
const createAction = actions
|
|
3426
|
+
.find((action) => action.type === 'create');
|
|
3427
|
+
if (!createAction) {
|
|
3428
|
+
throw new Error('No create order action found');
|
|
3429
|
+
}
|
|
3430
|
+
const orderMessageToSign = await createAction.getMessageToSign();
|
|
3431
|
+
const orderComponents = getOrderComponentsFromMessage(orderMessageToSign);
|
|
3432
|
+
return {
|
|
3433
|
+
unsignedApprovalTransaction: approvalTransaction,
|
|
3434
|
+
typedOrderMessageForSigning: await this.getTypedDataFromOrderComponents(orderComponents),
|
|
3435
|
+
orderComponents,
|
|
3436
|
+
orderHash: await this.seaport.getOrderHash(orderComponents),
|
|
3437
|
+
};
|
|
3438
|
+
}
|
|
3439
|
+
async fulfilOrder(order, account) {
|
|
3440
|
+
const orderComponents = await this.mapImmutableOrderToSeaportOrderComponents(order);
|
|
3441
|
+
const { actions } = await this.seaport.fulfillOrders({
|
|
3442
|
+
accountAddress: account,
|
|
3443
|
+
fulfillOrderDetails: [{
|
|
3444
|
+
order: {
|
|
3445
|
+
parameters: orderComponents,
|
|
3446
|
+
signature: order.signature,
|
|
3447
|
+
},
|
|
3448
|
+
extraData: order.protocol_data.operator_signature,
|
|
3449
|
+
}],
|
|
3450
|
+
});
|
|
3451
|
+
let approvalTransaction;
|
|
3452
|
+
const approvalAction = actions
|
|
3453
|
+
.find((action) => action.type === 'approval');
|
|
3454
|
+
if (approvalAction) {
|
|
3455
|
+
approvalTransaction = await prepareTransaction(approvalAction.transactionMethods);
|
|
3456
|
+
}
|
|
3457
|
+
const fulfillmentAction = actions
|
|
3458
|
+
.find((action) => action.type === 'exchange');
|
|
3459
|
+
if (!fulfillmentAction) {
|
|
3460
|
+
throw new Error('No exchange action found');
|
|
3461
|
+
}
|
|
3462
|
+
const fulfillmentTransaction = await prepareTransaction(fulfillmentAction.transactionMethods);
|
|
3463
|
+
return {
|
|
3464
|
+
unsignedApprovalTransaction: approvalTransaction,
|
|
3465
|
+
unsignedFulfillmentTransaction: fulfillmentTransaction,
|
|
3466
|
+
};
|
|
3467
|
+
}
|
|
3468
|
+
async cancelOrder(order, account) {
|
|
3469
|
+
const orderComponents = await this.mapImmutableOrderToSeaportOrderComponents(order);
|
|
3470
|
+
const cancellationTransaction = await this.seaport.cancelOrders([orderComponents], account);
|
|
3471
|
+
return prepareTransaction(cancellationTransaction);
|
|
3472
|
+
}
|
|
3473
|
+
async mapImmutableOrderToSeaportOrderComponents(order) {
|
|
3474
|
+
const counterForOfferer = await this.seaport.getCounter(order.account_address);
|
|
3475
|
+
return mapImmutableOrderToSeaportOrderComponents(order, counterForOfferer.toString(), this.zoneContractAddress);
|
|
3476
|
+
}
|
|
3477
|
+
createSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry) {
|
|
3478
|
+
return this.seaport.createOrder({
|
|
3479
|
+
allowPartialFills: false,
|
|
3480
|
+
offer: [
|
|
3481
|
+
{
|
|
3482
|
+
itemType: ItemType.ERC721,
|
|
3483
|
+
token: listingItem.contractAddress,
|
|
3484
|
+
identifier: listingItem.tokenId,
|
|
3485
|
+
},
|
|
3486
|
+
],
|
|
3487
|
+
consideration: [
|
|
3488
|
+
{
|
|
3489
|
+
token: considerationItem.type === 'ERC20' ? considerationItem.contractAddress : undefined,
|
|
3490
|
+
amount: considerationItem.amount,
|
|
3491
|
+
recipient: offerer,
|
|
3492
|
+
},
|
|
3493
|
+
{
|
|
3494
|
+
token: considerationItem.type === 'ERC20' ? considerationItem.contractAddress : undefined,
|
|
3495
|
+
amount: royaltyInfo.amountRequired,
|
|
3496
|
+
recipient: royaltyInfo.recipient,
|
|
3497
|
+
},
|
|
3498
|
+
],
|
|
3499
|
+
startTime: (orderStart.getTime() / 1000).toFixed(0),
|
|
3500
|
+
endTime: (orderExpiry.getTime() / 1000).toFixed(0),
|
|
3501
|
+
zone: this.zoneContractAddress,
|
|
3502
|
+
restrictedByZone: true,
|
|
3503
|
+
}, offerer);
|
|
3504
|
+
}
|
|
3505
|
+
async getTypedDataFromOrderComponents(orderComponents) {
|
|
3506
|
+
const { chainId } = await this.provider.getNetwork();
|
|
3507
|
+
const domainData = {
|
|
3508
|
+
name: SEAPORT_CONTRACT_NAME,
|
|
3509
|
+
version: SEAPORT_CONTRACT_VERSION_V1_4,
|
|
3510
|
+
chainId,
|
|
3511
|
+
verifyingContract: this.seaportContractAddress,
|
|
3512
|
+
};
|
|
3513
|
+
return {
|
|
3514
|
+
domain: domainData,
|
|
3515
|
+
types: EIP_712_ORDER_TYPE,
|
|
3516
|
+
value: orderComponents,
|
|
3517
|
+
};
|
|
3518
|
+
}
|
|
3519
|
+
}
|
|
3520
|
+
|
|
3521
|
+
class SeaportFactory {
|
|
3522
|
+
seaportContractAddress;
|
|
3523
|
+
zoneContractAddress;
|
|
3524
|
+
provider;
|
|
3525
|
+
seaport;
|
|
3526
|
+
constructor(seaportContractAddress, zoneContractAddress, provider) {
|
|
3527
|
+
this.seaportContractAddress = seaportContractAddress;
|
|
3528
|
+
this.zoneContractAddress = zoneContractAddress;
|
|
3529
|
+
this.provider = provider;
|
|
3530
|
+
this.seaport = new seaportJs.Seaport(provider, {
|
|
3531
|
+
seaportVersion: '1.4',
|
|
3532
|
+
balanceAndApprovalChecksOnOrderCreation: true,
|
|
3533
|
+
overrides: {
|
|
3534
|
+
contractAddress: seaportContractAddress,
|
|
3535
|
+
},
|
|
3536
|
+
});
|
|
3537
|
+
}
|
|
3538
|
+
create() {
|
|
3539
|
+
return new Seaport(this.seaport, this.provider, this.seaportContractAddress, this.zoneContractAddress);
|
|
3540
|
+
}
|
|
3541
|
+
}
|
|
3542
|
+
|
|
3285
3543
|
class ImmutableApiClient {
|
|
3286
3544
|
orderbookService;
|
|
3287
3545
|
chainId;
|
|
@@ -3302,7 +3560,7 @@ class ImmutableApiClient {
|
|
|
3302
3560
|
if (orderComponents.offer.length !== 1) {
|
|
3303
3561
|
throw new Error('Only one item can be listed at a time');
|
|
3304
3562
|
}
|
|
3305
|
-
if (Number(orderComponents.offer[0].itemType) !==
|
|
3563
|
+
if (Number(orderComponents.offer[0].itemType) !== ItemType.ERC721) {
|
|
3306
3564
|
throw new Error('Only ERC721 tokens can be listed');
|
|
3307
3565
|
}
|
|
3308
3566
|
const considerationItemTypeTheSame = new Set([...orderComponents.consideration.map((c) => c.itemType)]).size === 1;
|
|
@@ -3316,7 +3574,7 @@ class ImmutableApiClient {
|
|
|
3316
3574
|
account_address: offerer,
|
|
3317
3575
|
buy: [
|
|
3318
3576
|
{
|
|
3319
|
-
item_type: Number(orderComponents.consideration[0].itemType) ===
|
|
3577
|
+
item_type: Number(orderComponents.consideration[0].itemType) === ItemType.NATIVE
|
|
3320
3578
|
? BuyItem.item_type.NATIVE
|
|
3321
3579
|
: BuyItem.item_type.ERC20,
|
|
3322
3580
|
start_amount: orderComponents.consideration[0].startAmount,
|
|
@@ -4286,199 +4544,6 @@ class ERC721Factory {
|
|
|
4286
4544
|
}
|
|
4287
4545
|
}
|
|
4288
4546
|
|
|
4289
|
-
function getOrderComponentsFromMessage(orderMessage) {
|
|
4290
|
-
const data = JSON.parse(orderMessage);
|
|
4291
|
-
const orderComponents = data.message;
|
|
4292
|
-
orderComponents.salt = ethers.BigNumber.from(orderComponents.salt).toHexString();
|
|
4293
|
-
return orderComponents;
|
|
4294
|
-
}
|
|
4295
|
-
|
|
4296
|
-
// Add 20% more gas than estimate to prevent out of gas errors
|
|
4297
|
-
// This can always be overwritten by the user signing the transaction
|
|
4298
|
-
async function prepareTransaction(transactionMethods) {
|
|
4299
|
-
const transaction = await transactionMethods.buildTransaction();
|
|
4300
|
-
transaction.gasLimit = await transactionMethods.estimateGas();
|
|
4301
|
-
transaction.gasLimit = transaction.gasLimit
|
|
4302
|
-
.add(transaction.gasLimit.div(5));
|
|
4303
|
-
return transaction;
|
|
4304
|
-
}
|
|
4305
|
-
|
|
4306
|
-
function mapImmutableOrderToSeaportOrderComponents(order, counter, zoneAddress) {
|
|
4307
|
-
const considerationItems = order.buy.map((buyItem) => ({
|
|
4308
|
-
startAmount: buyItem.start_amount,
|
|
4309
|
-
endAmount: buyItem.start_amount,
|
|
4310
|
-
itemType: buyItem.item_type === 'ERC20' ? constants.ItemType.ERC20 : constants.ItemType.NATIVE,
|
|
4311
|
-
recipient: order.account_address,
|
|
4312
|
-
token: buyItem.contract_address || ethers.constants.AddressZero,
|
|
4313
|
-
identifierOrCriteria: '0',
|
|
4314
|
-
}));
|
|
4315
|
-
const fees = order.buy_fees.map((fee) => ({
|
|
4316
|
-
startAmount: fee.amount,
|
|
4317
|
-
endAmount: fee.amount,
|
|
4318
|
-
itemType: order.buy[0].item_type === 'ERC20' ? constants.ItemType.ERC20 : constants.ItemType.NATIVE,
|
|
4319
|
-
recipient: fee.recipient,
|
|
4320
|
-
token: order.buy[0].contract_address || ethers.constants.AddressZero,
|
|
4321
|
-
identifierOrCriteria: '0',
|
|
4322
|
-
}));
|
|
4323
|
-
return {
|
|
4324
|
-
conduitKey: ethers.constants.HashZero,
|
|
4325
|
-
consideration: [...considerationItems, ...fees],
|
|
4326
|
-
offer: order.sell.map((sellItem) => ({
|
|
4327
|
-
startAmount: '1',
|
|
4328
|
-
endAmount: '1',
|
|
4329
|
-
itemType: constants.ItemType.ERC721,
|
|
4330
|
-
token: sellItem.contract_address,
|
|
4331
|
-
identifierOrCriteria: sellItem.token_id,
|
|
4332
|
-
})),
|
|
4333
|
-
counter,
|
|
4334
|
-
endTime: Math.round(new Date(order.end_time).getTime() / 1000).toString(),
|
|
4335
|
-
startTime: Math.round(new Date(order.start_time).getTime() / 1000).toString(),
|
|
4336
|
-
salt: order.salt,
|
|
4337
|
-
offerer: order.account_address,
|
|
4338
|
-
zone: zoneAddress,
|
|
4339
|
-
totalOriginalConsiderationItems: 2,
|
|
4340
|
-
orderType: constants.OrderType.FULL_RESTRICTED,
|
|
4341
|
-
zoneHash: ethers.constants.HashZero,
|
|
4342
|
-
};
|
|
4343
|
-
}
|
|
4344
|
-
|
|
4345
|
-
class Seaport {
|
|
4346
|
-
seaport;
|
|
4347
|
-
provider;
|
|
4348
|
-
seaportContractAddress;
|
|
4349
|
-
zoneContractAddress;
|
|
4350
|
-
constructor(seaport, provider, seaportContractAddress, zoneContractAddress) {
|
|
4351
|
-
this.seaport = seaport;
|
|
4352
|
-
this.provider = provider;
|
|
4353
|
-
this.seaportContractAddress = seaportContractAddress;
|
|
4354
|
-
this.zoneContractAddress = zoneContractAddress;
|
|
4355
|
-
}
|
|
4356
|
-
async prepareSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry) {
|
|
4357
|
-
const { actions } = await this.createSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry);
|
|
4358
|
-
let approvalTransaction;
|
|
4359
|
-
const approvalAction = actions
|
|
4360
|
-
.find((action) => action.type === 'approval');
|
|
4361
|
-
if (approvalAction) {
|
|
4362
|
-
approvalTransaction = await prepareTransaction(approvalAction.transactionMethods);
|
|
4363
|
-
}
|
|
4364
|
-
const createAction = actions
|
|
4365
|
-
.find((action) => action.type === 'create');
|
|
4366
|
-
if (!createAction) {
|
|
4367
|
-
throw new Error('No create order action found');
|
|
4368
|
-
}
|
|
4369
|
-
const orderMessageToSign = await createAction.getMessageToSign();
|
|
4370
|
-
const orderComponents = getOrderComponentsFromMessage(orderMessageToSign);
|
|
4371
|
-
return {
|
|
4372
|
-
unsignedApprovalTransaction: approvalTransaction,
|
|
4373
|
-
typedOrderMessageForSigning: await this.getTypedDataFromOrderComponents(orderComponents),
|
|
4374
|
-
orderComponents,
|
|
4375
|
-
orderHash: await this.seaport.getOrderHash(orderComponents),
|
|
4376
|
-
};
|
|
4377
|
-
}
|
|
4378
|
-
async fulfilOrder(order, account) {
|
|
4379
|
-
const orderComponents = await this.mapImmutableOrderToSeaportOrderComponents(order);
|
|
4380
|
-
const { actions } = await this.seaport.fulfillOrders({
|
|
4381
|
-
accountAddress: account,
|
|
4382
|
-
fulfillOrderDetails: [{
|
|
4383
|
-
order: {
|
|
4384
|
-
parameters: orderComponents,
|
|
4385
|
-
signature: order.signature,
|
|
4386
|
-
},
|
|
4387
|
-
extraData: order.protocol_data.operator_signature,
|
|
4388
|
-
}],
|
|
4389
|
-
});
|
|
4390
|
-
let approvalTransaction;
|
|
4391
|
-
const approvalAction = actions
|
|
4392
|
-
.find((action) => action.type === 'approval');
|
|
4393
|
-
if (approvalAction) {
|
|
4394
|
-
approvalTransaction = await prepareTransaction(approvalAction.transactionMethods);
|
|
4395
|
-
}
|
|
4396
|
-
const fulfillmentAction = actions
|
|
4397
|
-
.find((action) => action.type === 'exchange');
|
|
4398
|
-
if (!fulfillmentAction) {
|
|
4399
|
-
throw new Error('No exchange action found');
|
|
4400
|
-
}
|
|
4401
|
-
const fulfillmentTransaction = await prepareTransaction(fulfillmentAction.transactionMethods);
|
|
4402
|
-
return {
|
|
4403
|
-
unsignedApprovalTransaction: approvalTransaction,
|
|
4404
|
-
unsignedFulfillmentTransaction: fulfillmentTransaction,
|
|
4405
|
-
};
|
|
4406
|
-
}
|
|
4407
|
-
async cancelOrder(order, account) {
|
|
4408
|
-
const orderComponents = await this.mapImmutableOrderToSeaportOrderComponents(order);
|
|
4409
|
-
const cancellationTransaction = await this.seaport.cancelOrders([orderComponents], account);
|
|
4410
|
-
return prepareTransaction(cancellationTransaction);
|
|
4411
|
-
}
|
|
4412
|
-
async mapImmutableOrderToSeaportOrderComponents(order) {
|
|
4413
|
-
const counterForOfferer = await this.seaport.getCounter(order.account_address);
|
|
4414
|
-
return mapImmutableOrderToSeaportOrderComponents(order, counterForOfferer.toString(), this.zoneContractAddress);
|
|
4415
|
-
}
|
|
4416
|
-
createSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry) {
|
|
4417
|
-
return this.seaport.createOrder({
|
|
4418
|
-
allowPartialFills: false,
|
|
4419
|
-
offer: [
|
|
4420
|
-
{
|
|
4421
|
-
itemType: constants.ItemType.ERC721,
|
|
4422
|
-
token: listingItem.contractAddress,
|
|
4423
|
-
identifier: listingItem.tokenId,
|
|
4424
|
-
},
|
|
4425
|
-
],
|
|
4426
|
-
consideration: [
|
|
4427
|
-
{
|
|
4428
|
-
token: considerationItem.type === 'ERC20' ? considerationItem.contractAddress : undefined,
|
|
4429
|
-
amount: considerationItem.amount,
|
|
4430
|
-
recipient: offerer,
|
|
4431
|
-
},
|
|
4432
|
-
{
|
|
4433
|
-
token: considerationItem.type === 'ERC20' ? considerationItem.contractAddress : undefined,
|
|
4434
|
-
amount: royaltyInfo.amountRequired,
|
|
4435
|
-
recipient: royaltyInfo.recipient,
|
|
4436
|
-
},
|
|
4437
|
-
],
|
|
4438
|
-
startTime: (orderStart.getTime() / 1000).toFixed(0),
|
|
4439
|
-
endTime: (orderExpiry.getTime() / 1000).toFixed(0),
|
|
4440
|
-
zone: this.zoneContractAddress,
|
|
4441
|
-
restrictedByZone: true,
|
|
4442
|
-
}, offerer);
|
|
4443
|
-
}
|
|
4444
|
-
async getTypedDataFromOrderComponents(orderComponents) {
|
|
4445
|
-
const { chainId } = await this.provider.getNetwork();
|
|
4446
|
-
const domainData = {
|
|
4447
|
-
name: constants.SEAPORT_CONTRACT_NAME,
|
|
4448
|
-
version: constants.SEAPORT_CONTRACT_VERSION_V1_4,
|
|
4449
|
-
chainId,
|
|
4450
|
-
verifyingContract: this.seaportContractAddress,
|
|
4451
|
-
};
|
|
4452
|
-
return {
|
|
4453
|
-
domain: domainData,
|
|
4454
|
-
types: constants.EIP_712_ORDER_TYPE,
|
|
4455
|
-
value: orderComponents,
|
|
4456
|
-
};
|
|
4457
|
-
}
|
|
4458
|
-
}
|
|
4459
|
-
|
|
4460
|
-
class SeaportFactory {
|
|
4461
|
-
seaportContractAddress;
|
|
4462
|
-
zoneContractAddress;
|
|
4463
|
-
provider;
|
|
4464
|
-
seaport;
|
|
4465
|
-
constructor(seaportContractAddress, zoneContractAddress, provider) {
|
|
4466
|
-
this.seaportContractAddress = seaportContractAddress;
|
|
4467
|
-
this.zoneContractAddress = zoneContractAddress;
|
|
4468
|
-
this.provider = provider;
|
|
4469
|
-
this.seaport = new seaportJs.Seaport(provider, {
|
|
4470
|
-
seaportVersion: '1.4',
|
|
4471
|
-
balanceAndApprovalChecksOnOrderCreation: true,
|
|
4472
|
-
overrides: {
|
|
4473
|
-
contractAddress: seaportContractAddress,
|
|
4474
|
-
},
|
|
4475
|
-
});
|
|
4476
|
-
}
|
|
4477
|
-
create() {
|
|
4478
|
-
return new Seaport(this.seaport, this.provider, this.seaportContractAddress, this.zoneContractAddress);
|
|
4479
|
-
}
|
|
4480
|
-
}
|
|
4481
|
-
|
|
4482
4547
|
/**
|
|
4483
4548
|
* zkEVM orderbook SDK
|
|
4484
4549
|
* @constructor
|