@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/index.js CHANGED
@@ -7,7 +7,6 @@ import { Magic } from 'magic-sdk';
7
7
  import { OpenIdExtension } from '@magic-ext/oidc';
8
8
  import BN from 'bn.js';
9
9
  import * as encUtils from 'enc-utils';
10
- import { ItemType, SEAPORT_CONTRACT_NAME, SEAPORT_CONTRACT_VERSION_V1_4, EIP_712_ORDER_TYPE, OrderType } from '@opensea/seaport-js/lib/constants';
11
10
  import FormData from 'form-data';
12
11
  import { Seaport as Seaport$1 } from '@opensea/seaport-js';
13
12
  import { parseUnits } from '@ethersproject/units';
@@ -1053,7 +1052,7 @@ class APIError extends Error {
1053
1052
 
1054
1053
  /* eslint-disable implicit-arrow-linebreak */
1055
1054
  const defaultHeaders = {
1056
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.1.8-alpha',
1055
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.1.8-alpha.1',
1057
1056
  };
1058
1057
  /**
1059
1058
  * createAPIConfiguration to create a custom APIConfiguration
@@ -1289,7 +1288,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
1289
1288
  chainID,
1290
1289
  coreContractAddress,
1291
1290
  registrationContractAddress,
1292
- sdkVersion: 'ts-immutable-sdk-0.1.8-alpha',
1291
+ sdkVersion: 'ts-immutable-sdk-0.1.8-alpha.1',
1293
1292
  });
1294
1293
  /**
1295
1294
  * Sets `sdkVersion` at the time of build
@@ -3262,6 +3261,265 @@ var SellItem;
3262
3261
  })(SellItem.item_type || (SellItem.item_type = {}));
3263
3262
  })(SellItem || (SellItem = {}));
3264
3263
 
3264
+ /* eslint-disable */
3265
+ // TODO: Resolve these from seaport-js.
3266
+ // There is some bundling issue that is preventing this from working
3267
+ const SEAPORT_CONTRACT_NAME = 'Seaport';
3268
+ const SEAPORT_CONTRACT_VERSION_V1_4 = '1.4';
3269
+ const EIP_712_ORDER_TYPE = {
3270
+ OrderComponents: [
3271
+ { name: 'offerer', type: 'address' },
3272
+ { name: 'zone', type: 'address' },
3273
+ { name: 'offer', type: 'OfferItem[]' },
3274
+ { name: 'consideration', type: 'ConsiderationItem[]' },
3275
+ { name: 'orderType', type: 'uint8' },
3276
+ { name: 'startTime', type: 'uint256' },
3277
+ { name: 'endTime', type: 'uint256' },
3278
+ { name: 'zoneHash', type: 'bytes32' },
3279
+ { name: 'salt', type: 'uint256' },
3280
+ { name: 'conduitKey', type: 'bytes32' },
3281
+ { name: 'counter', type: 'uint256' },
3282
+ ],
3283
+ OfferItem: [
3284
+ { name: 'itemType', type: 'uint8' },
3285
+ { name: 'token', type: 'address' },
3286
+ { name: 'identifierOrCriteria', type: 'uint256' },
3287
+ { name: 'startAmount', type: 'uint256' },
3288
+ { name: 'endAmount', type: 'uint256' },
3289
+ ],
3290
+ ConsiderationItem: [
3291
+ { name: 'itemType', type: 'uint8' },
3292
+ { name: 'token', type: 'address' },
3293
+ { name: 'identifierOrCriteria', type: 'uint256' },
3294
+ { name: 'startAmount', type: 'uint256' },
3295
+ { name: 'endAmount', type: 'uint256' },
3296
+ { name: 'recipient', type: 'address' },
3297
+ ],
3298
+ };
3299
+ var OrderType;
3300
+ (function (OrderType) {
3301
+ OrderType[OrderType["FULL_OPEN"] = 0] = "FULL_OPEN";
3302
+ OrderType[OrderType["PARTIAL_OPEN"] = 1] = "PARTIAL_OPEN";
3303
+ OrderType[OrderType["FULL_RESTRICTED"] = 2] = "FULL_RESTRICTED";
3304
+ OrderType[OrderType["PARTIAL_RESTRICTED"] = 3] = "PARTIAL_RESTRICTED";
3305
+ })(OrderType || (OrderType = {}));
3306
+ var ItemType;
3307
+ (function (ItemType) {
3308
+ ItemType[ItemType["NATIVE"] = 0] = "NATIVE";
3309
+ ItemType[ItemType["ERC20"] = 1] = "ERC20";
3310
+ ItemType[ItemType["ERC721"] = 2] = "ERC721";
3311
+ ItemType[ItemType["ERC1155"] = 3] = "ERC1155";
3312
+ ItemType[ItemType["ERC721_WITH_CRITERIA"] = 4] = "ERC721_WITH_CRITERIA";
3313
+ ItemType[ItemType["ERC1155_WITH_CRITERIA"] = 5] = "ERC1155_WITH_CRITERIA";
3314
+ })(ItemType || (ItemType = {}));
3315
+ var Side;
3316
+ (function (Side) {
3317
+ Side[Side["OFFER"] = 0] = "OFFER";
3318
+ Side[Side["CONSIDERATION"] = 1] = "CONSIDERATION";
3319
+ })(Side || (Side = {}));
3320
+ var BasicOrderRouteType;
3321
+ (function (BasicOrderRouteType) {
3322
+ BasicOrderRouteType[BasicOrderRouteType["ETH_TO_ERC721"] = 0] = "ETH_TO_ERC721";
3323
+ BasicOrderRouteType[BasicOrderRouteType["ETH_TO_ERC1155"] = 1] = "ETH_TO_ERC1155";
3324
+ BasicOrderRouteType[BasicOrderRouteType["ERC20_TO_ERC721"] = 2] = "ERC20_TO_ERC721";
3325
+ BasicOrderRouteType[BasicOrderRouteType["ERC20_TO_ERC1155"] = 3] = "ERC20_TO_ERC1155";
3326
+ BasicOrderRouteType[BasicOrderRouteType["ERC721_TO_ERC20"] = 4] = "ERC721_TO_ERC20";
3327
+ BasicOrderRouteType[BasicOrderRouteType["ERC1155_TO_ERC20"] = 5] = "ERC1155_TO_ERC20";
3328
+ })(BasicOrderRouteType || (BasicOrderRouteType = {}));
3329
+
3330
+ function getOrderComponentsFromMessage(orderMessage) {
3331
+ const data = JSON.parse(orderMessage);
3332
+ const orderComponents = data.message;
3333
+ orderComponents.salt = BigNumber.from(orderComponents.salt).toHexString();
3334
+ return orderComponents;
3335
+ }
3336
+
3337
+ // Add 20% more gas than estimate to prevent out of gas errors
3338
+ // This can always be overwritten by the user signing the transaction
3339
+ async function prepareTransaction(transactionMethods) {
3340
+ const transaction = await transactionMethods.buildTransaction();
3341
+ transaction.gasLimit = await transactionMethods.estimateGas();
3342
+ transaction.gasLimit = transaction.gasLimit
3343
+ .add(transaction.gasLimit.div(5));
3344
+ return transaction;
3345
+ }
3346
+
3347
+ function mapImmutableOrderToSeaportOrderComponents(order, counter, zoneAddress) {
3348
+ const considerationItems = order.buy.map((buyItem) => ({
3349
+ startAmount: buyItem.start_amount,
3350
+ endAmount: buyItem.start_amount,
3351
+ itemType: buyItem.item_type === 'ERC20' ? ItemType.ERC20 : ItemType.NATIVE,
3352
+ recipient: order.account_address,
3353
+ token: buyItem.contract_address || constants.AddressZero,
3354
+ identifierOrCriteria: '0',
3355
+ }));
3356
+ const fees = order.buy_fees.map((fee) => ({
3357
+ startAmount: fee.amount,
3358
+ endAmount: fee.amount,
3359
+ itemType: order.buy[0].item_type === 'ERC20' ? ItemType.ERC20 : ItemType.NATIVE,
3360
+ recipient: fee.recipient,
3361
+ token: order.buy[0].contract_address || constants.AddressZero,
3362
+ identifierOrCriteria: '0',
3363
+ }));
3364
+ return {
3365
+ conduitKey: constants.HashZero,
3366
+ consideration: [...considerationItems, ...fees],
3367
+ offer: order.sell.map((sellItem) => ({
3368
+ startAmount: '1',
3369
+ endAmount: '1',
3370
+ itemType: ItemType.ERC721,
3371
+ token: sellItem.contract_address,
3372
+ identifierOrCriteria: sellItem.token_id,
3373
+ })),
3374
+ counter,
3375
+ endTime: Math.round(new Date(order.end_time).getTime() / 1000).toString(),
3376
+ startTime: Math.round(new Date(order.start_time).getTime() / 1000).toString(),
3377
+ salt: order.salt,
3378
+ offerer: order.account_address,
3379
+ zone: zoneAddress,
3380
+ totalOriginalConsiderationItems: 2,
3381
+ orderType: OrderType.FULL_RESTRICTED,
3382
+ zoneHash: constants.HashZero,
3383
+ };
3384
+ }
3385
+
3386
+ class Seaport {
3387
+ seaport;
3388
+ provider;
3389
+ seaportContractAddress;
3390
+ zoneContractAddress;
3391
+ constructor(seaport, provider, seaportContractAddress, zoneContractAddress) {
3392
+ this.seaport = seaport;
3393
+ this.provider = provider;
3394
+ this.seaportContractAddress = seaportContractAddress;
3395
+ this.zoneContractAddress = zoneContractAddress;
3396
+ }
3397
+ async prepareSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry) {
3398
+ const { actions } = await this.createSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry);
3399
+ let approvalTransaction;
3400
+ const approvalAction = actions
3401
+ .find((action) => action.type === 'approval');
3402
+ if (approvalAction) {
3403
+ approvalTransaction = await prepareTransaction(approvalAction.transactionMethods);
3404
+ }
3405
+ const createAction = actions
3406
+ .find((action) => action.type === 'create');
3407
+ if (!createAction) {
3408
+ throw new Error('No create order action found');
3409
+ }
3410
+ const orderMessageToSign = await createAction.getMessageToSign();
3411
+ const orderComponents = getOrderComponentsFromMessage(orderMessageToSign);
3412
+ return {
3413
+ unsignedApprovalTransaction: approvalTransaction,
3414
+ typedOrderMessageForSigning: await this.getTypedDataFromOrderComponents(orderComponents),
3415
+ orderComponents,
3416
+ orderHash: await this.seaport.getOrderHash(orderComponents),
3417
+ };
3418
+ }
3419
+ async fulfilOrder(order, account) {
3420
+ const orderComponents = await this.mapImmutableOrderToSeaportOrderComponents(order);
3421
+ const { actions } = await this.seaport.fulfillOrders({
3422
+ accountAddress: account,
3423
+ fulfillOrderDetails: [{
3424
+ order: {
3425
+ parameters: orderComponents,
3426
+ signature: order.signature,
3427
+ },
3428
+ extraData: order.protocol_data.operator_signature,
3429
+ }],
3430
+ });
3431
+ let approvalTransaction;
3432
+ const approvalAction = actions
3433
+ .find((action) => action.type === 'approval');
3434
+ if (approvalAction) {
3435
+ approvalTransaction = await prepareTransaction(approvalAction.transactionMethods);
3436
+ }
3437
+ const fulfillmentAction = actions
3438
+ .find((action) => action.type === 'exchange');
3439
+ if (!fulfillmentAction) {
3440
+ throw new Error('No exchange action found');
3441
+ }
3442
+ const fulfillmentTransaction = await prepareTransaction(fulfillmentAction.transactionMethods);
3443
+ return {
3444
+ unsignedApprovalTransaction: approvalTransaction,
3445
+ unsignedFulfillmentTransaction: fulfillmentTransaction,
3446
+ };
3447
+ }
3448
+ async cancelOrder(order, account) {
3449
+ const orderComponents = await this.mapImmutableOrderToSeaportOrderComponents(order);
3450
+ const cancellationTransaction = await this.seaport.cancelOrders([orderComponents], account);
3451
+ return prepareTransaction(cancellationTransaction);
3452
+ }
3453
+ async mapImmutableOrderToSeaportOrderComponents(order) {
3454
+ const counterForOfferer = await this.seaport.getCounter(order.account_address);
3455
+ return mapImmutableOrderToSeaportOrderComponents(order, counterForOfferer.toString(), this.zoneContractAddress);
3456
+ }
3457
+ createSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry) {
3458
+ return this.seaport.createOrder({
3459
+ allowPartialFills: false,
3460
+ offer: [
3461
+ {
3462
+ itemType: ItemType.ERC721,
3463
+ token: listingItem.contractAddress,
3464
+ identifier: listingItem.tokenId,
3465
+ },
3466
+ ],
3467
+ consideration: [
3468
+ {
3469
+ token: considerationItem.type === 'ERC20' ? considerationItem.contractAddress : undefined,
3470
+ amount: considerationItem.amount,
3471
+ recipient: offerer,
3472
+ },
3473
+ {
3474
+ token: considerationItem.type === 'ERC20' ? considerationItem.contractAddress : undefined,
3475
+ amount: royaltyInfo.amountRequired,
3476
+ recipient: royaltyInfo.recipient,
3477
+ },
3478
+ ],
3479
+ startTime: (orderStart.getTime() / 1000).toFixed(0),
3480
+ endTime: (orderExpiry.getTime() / 1000).toFixed(0),
3481
+ zone: this.zoneContractAddress,
3482
+ restrictedByZone: true,
3483
+ }, offerer);
3484
+ }
3485
+ async getTypedDataFromOrderComponents(orderComponents) {
3486
+ const { chainId } = await this.provider.getNetwork();
3487
+ const domainData = {
3488
+ name: SEAPORT_CONTRACT_NAME,
3489
+ version: SEAPORT_CONTRACT_VERSION_V1_4,
3490
+ chainId,
3491
+ verifyingContract: this.seaportContractAddress,
3492
+ };
3493
+ return {
3494
+ domain: domainData,
3495
+ types: EIP_712_ORDER_TYPE,
3496
+ value: orderComponents,
3497
+ };
3498
+ }
3499
+ }
3500
+
3501
+ class SeaportFactory {
3502
+ seaportContractAddress;
3503
+ zoneContractAddress;
3504
+ provider;
3505
+ seaport;
3506
+ constructor(seaportContractAddress, zoneContractAddress, provider) {
3507
+ this.seaportContractAddress = seaportContractAddress;
3508
+ this.zoneContractAddress = zoneContractAddress;
3509
+ this.provider = provider;
3510
+ this.seaport = new Seaport$1(provider, {
3511
+ seaportVersion: '1.4',
3512
+ balanceAndApprovalChecksOnOrderCreation: true,
3513
+ overrides: {
3514
+ contractAddress: seaportContractAddress,
3515
+ },
3516
+ });
3517
+ }
3518
+ create() {
3519
+ return new Seaport(this.seaport, this.provider, this.seaportContractAddress, this.zoneContractAddress);
3520
+ }
3521
+ }
3522
+
3265
3523
  class ImmutableApiClient {
3266
3524
  orderbookService;
3267
3525
  chainId;
@@ -4266,199 +4524,6 @@ class ERC721Factory {
4266
4524
  }
4267
4525
  }
4268
4526
 
4269
- function getOrderComponentsFromMessage(orderMessage) {
4270
- const data = JSON.parse(orderMessage);
4271
- const orderComponents = data.message;
4272
- orderComponents.salt = BigNumber.from(orderComponents.salt).toHexString();
4273
- return orderComponents;
4274
- }
4275
-
4276
- // Add 20% more gas than estimate to prevent out of gas errors
4277
- // This can always be overwritten by the user signing the transaction
4278
- async function prepareTransaction(transactionMethods) {
4279
- const transaction = await transactionMethods.buildTransaction();
4280
- transaction.gasLimit = await transactionMethods.estimateGas();
4281
- transaction.gasLimit = transaction.gasLimit
4282
- .add(transaction.gasLimit.div(5));
4283
- return transaction;
4284
- }
4285
-
4286
- function mapImmutableOrderToSeaportOrderComponents(order, counter, zoneAddress) {
4287
- const considerationItems = order.buy.map((buyItem) => ({
4288
- startAmount: buyItem.start_amount,
4289
- endAmount: buyItem.start_amount,
4290
- itemType: buyItem.item_type === 'ERC20' ? ItemType.ERC20 : ItemType.NATIVE,
4291
- recipient: order.account_address,
4292
- token: buyItem.contract_address || constants.AddressZero,
4293
- identifierOrCriteria: '0',
4294
- }));
4295
- const fees = order.buy_fees.map((fee) => ({
4296
- startAmount: fee.amount,
4297
- endAmount: fee.amount,
4298
- itemType: order.buy[0].item_type === 'ERC20' ? ItemType.ERC20 : ItemType.NATIVE,
4299
- recipient: fee.recipient,
4300
- token: order.buy[0].contract_address || constants.AddressZero,
4301
- identifierOrCriteria: '0',
4302
- }));
4303
- return {
4304
- conduitKey: constants.HashZero,
4305
- consideration: [...considerationItems, ...fees],
4306
- offer: order.sell.map((sellItem) => ({
4307
- startAmount: '1',
4308
- endAmount: '1',
4309
- itemType: ItemType.ERC721,
4310
- token: sellItem.contract_address,
4311
- identifierOrCriteria: sellItem.token_id,
4312
- })),
4313
- counter,
4314
- endTime: Math.round(new Date(order.end_time).getTime() / 1000).toString(),
4315
- startTime: Math.round(new Date(order.start_time).getTime() / 1000).toString(),
4316
- salt: order.salt,
4317
- offerer: order.account_address,
4318
- zone: zoneAddress,
4319
- totalOriginalConsiderationItems: 2,
4320
- orderType: OrderType.FULL_RESTRICTED,
4321
- zoneHash: constants.HashZero,
4322
- };
4323
- }
4324
-
4325
- class Seaport {
4326
- seaport;
4327
- provider;
4328
- seaportContractAddress;
4329
- zoneContractAddress;
4330
- constructor(seaport, provider, seaportContractAddress, zoneContractAddress) {
4331
- this.seaport = seaport;
4332
- this.provider = provider;
4333
- this.seaportContractAddress = seaportContractAddress;
4334
- this.zoneContractAddress = zoneContractAddress;
4335
- }
4336
- async prepareSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry) {
4337
- const { actions } = await this.createSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry);
4338
- let approvalTransaction;
4339
- const approvalAction = actions
4340
- .find((action) => action.type === 'approval');
4341
- if (approvalAction) {
4342
- approvalTransaction = await prepareTransaction(approvalAction.transactionMethods);
4343
- }
4344
- const createAction = actions
4345
- .find((action) => action.type === 'create');
4346
- if (!createAction) {
4347
- throw new Error('No create order action found');
4348
- }
4349
- const orderMessageToSign = await createAction.getMessageToSign();
4350
- const orderComponents = getOrderComponentsFromMessage(orderMessageToSign);
4351
- return {
4352
- unsignedApprovalTransaction: approvalTransaction,
4353
- typedOrderMessageForSigning: await this.getTypedDataFromOrderComponents(orderComponents),
4354
- orderComponents,
4355
- orderHash: await this.seaport.getOrderHash(orderComponents),
4356
- };
4357
- }
4358
- async fulfilOrder(order, account) {
4359
- const orderComponents = await this.mapImmutableOrderToSeaportOrderComponents(order);
4360
- const { actions } = await this.seaport.fulfillOrders({
4361
- accountAddress: account,
4362
- fulfillOrderDetails: [{
4363
- order: {
4364
- parameters: orderComponents,
4365
- signature: order.signature,
4366
- },
4367
- extraData: order.protocol_data.operator_signature,
4368
- }],
4369
- });
4370
- let approvalTransaction;
4371
- const approvalAction = actions
4372
- .find((action) => action.type === 'approval');
4373
- if (approvalAction) {
4374
- approvalTransaction = await prepareTransaction(approvalAction.transactionMethods);
4375
- }
4376
- const fulfillmentAction = actions
4377
- .find((action) => action.type === 'exchange');
4378
- if (!fulfillmentAction) {
4379
- throw new Error('No exchange action found');
4380
- }
4381
- const fulfillmentTransaction = await prepareTransaction(fulfillmentAction.transactionMethods);
4382
- return {
4383
- unsignedApprovalTransaction: approvalTransaction,
4384
- unsignedFulfillmentTransaction: fulfillmentTransaction,
4385
- };
4386
- }
4387
- async cancelOrder(order, account) {
4388
- const orderComponents = await this.mapImmutableOrderToSeaportOrderComponents(order);
4389
- const cancellationTransaction = await this.seaport.cancelOrders([orderComponents], account);
4390
- return prepareTransaction(cancellationTransaction);
4391
- }
4392
- async mapImmutableOrderToSeaportOrderComponents(order) {
4393
- const counterForOfferer = await this.seaport.getCounter(order.account_address);
4394
- return mapImmutableOrderToSeaportOrderComponents(order, counterForOfferer.toString(), this.zoneContractAddress);
4395
- }
4396
- createSeaportOrder(offerer, listingItem, considerationItem, royaltyInfo, orderStart, orderExpiry) {
4397
- return this.seaport.createOrder({
4398
- allowPartialFills: false,
4399
- offer: [
4400
- {
4401
- itemType: ItemType.ERC721,
4402
- token: listingItem.contractAddress,
4403
- identifier: listingItem.tokenId,
4404
- },
4405
- ],
4406
- consideration: [
4407
- {
4408
- token: considerationItem.type === 'ERC20' ? considerationItem.contractAddress : undefined,
4409
- amount: considerationItem.amount,
4410
- recipient: offerer,
4411
- },
4412
- {
4413
- token: considerationItem.type === 'ERC20' ? considerationItem.contractAddress : undefined,
4414
- amount: royaltyInfo.amountRequired,
4415
- recipient: royaltyInfo.recipient,
4416
- },
4417
- ],
4418
- startTime: (orderStart.getTime() / 1000).toFixed(0),
4419
- endTime: (orderExpiry.getTime() / 1000).toFixed(0),
4420
- zone: this.zoneContractAddress,
4421
- restrictedByZone: true,
4422
- }, offerer);
4423
- }
4424
- async getTypedDataFromOrderComponents(orderComponents) {
4425
- const { chainId } = await this.provider.getNetwork();
4426
- const domainData = {
4427
- name: SEAPORT_CONTRACT_NAME,
4428
- version: SEAPORT_CONTRACT_VERSION_V1_4,
4429
- chainId,
4430
- verifyingContract: this.seaportContractAddress,
4431
- };
4432
- return {
4433
- domain: domainData,
4434
- types: EIP_712_ORDER_TYPE,
4435
- value: orderComponents,
4436
- };
4437
- }
4438
- }
4439
-
4440
- class SeaportFactory {
4441
- seaportContractAddress;
4442
- zoneContractAddress;
4443
- provider;
4444
- seaport;
4445
- constructor(seaportContractAddress, zoneContractAddress, provider) {
4446
- this.seaportContractAddress = seaportContractAddress;
4447
- this.zoneContractAddress = zoneContractAddress;
4448
- this.provider = provider;
4449
- this.seaport = new Seaport$1(provider, {
4450
- seaportVersion: '1.4',
4451
- balanceAndApprovalChecksOnOrderCreation: true,
4452
- overrides: {
4453
- contractAddress: seaportContractAddress,
4454
- },
4455
- });
4456
- }
4457
- create() {
4458
- return new Seaport(this.seaport, this.provider, this.seaportContractAddress, this.zoneContractAddress);
4459
- }
4460
- }
4461
-
4462
4527
  /**
4463
4528
  * zkEVM orderbook SDK
4464
4529
  * @constructor