@imtbl/sdk 0.14.0-alpha → 0.14.0-alpha.2
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/checkout_sdk.d.ts +2 -0
- package/dist/checkout_sdk.js +436 -39
- package/dist/checkout_widgets.js +1 -1
- package/dist/immutablex_client.js +1 -1
- package/dist/index.browser.js +8 -8
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +440 -43
- package/dist/index.d.ts +87 -25
- package/dist/index.js +440 -43
- package/dist/orderbook.d.ts +72 -16
- package/dist/orderbook.js +99 -9
- package/dist/passport.js +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2398,7 +2398,7 @@ class MultiRollupApiClients {
|
|
|
2398
2398
|
}
|
|
2399
2399
|
|
|
2400
2400
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
2401
|
-
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.14.0-alpha' };
|
|
2401
|
+
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.14.0-alpha.2' };
|
|
2402
2402
|
const createConfig = ({ basePath, headers, }) => {
|
|
2403
2403
|
if (!basePath.trim()) {
|
|
2404
2404
|
throw Error('basePath can not be empty');
|
|
@@ -2458,7 +2458,7 @@ class APIError extends Error {
|
|
|
2458
2458
|
|
|
2459
2459
|
/* eslint-disable implicit-arrow-linebreak */
|
|
2460
2460
|
const defaultHeaders = {
|
|
2461
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.14.0-alpha',
|
|
2461
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.14.0-alpha.2',
|
|
2462
2462
|
};
|
|
2463
2463
|
/**
|
|
2464
2464
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -2730,7 +2730,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
2730
2730
|
chainID,
|
|
2731
2731
|
coreContractAddress,
|
|
2732
2732
|
registrationContractAddress,
|
|
2733
|
-
sdkVersion: 'ts-immutable-sdk-0.14.0-alpha',
|
|
2733
|
+
sdkVersion: 'ts-immutable-sdk-0.14.0-alpha.2',
|
|
2734
2734
|
});
|
|
2735
2735
|
/**
|
|
2736
2736
|
* Sets `sdkVersion` at the time of build
|
|
@@ -9506,6 +9506,67 @@ var ActionType;
|
|
|
9506
9506
|
ActionType["SIGNABLE"] = "SIGNABLE";
|
|
9507
9507
|
})(ActionType || (ActionType = {}));
|
|
9508
9508
|
|
|
9509
|
+
function mapFromOpenApiOrder(order) {
|
|
9510
|
+
const buyItems = order.buy.map((item) => {
|
|
9511
|
+
if (item.item_type === 'ERC20') {
|
|
9512
|
+
return {
|
|
9513
|
+
type: 'ERC20',
|
|
9514
|
+
contractAddress: item.contract_address,
|
|
9515
|
+
amount: item.start_amount,
|
|
9516
|
+
};
|
|
9517
|
+
}
|
|
9518
|
+
if (item.item_type === 'NATIVE') {
|
|
9519
|
+
return {
|
|
9520
|
+
type: 'NATIVE',
|
|
9521
|
+
amount: item.start_amount,
|
|
9522
|
+
};
|
|
9523
|
+
}
|
|
9524
|
+
throw new Error('Buy items must be either ERC20 or NATIVE');
|
|
9525
|
+
});
|
|
9526
|
+
const sellItems = order.sell.map((item) => {
|
|
9527
|
+
if (item.item_type === 'ERC721') {
|
|
9528
|
+
return {
|
|
9529
|
+
type: 'ERC721',
|
|
9530
|
+
contractAddress: item.contract_address,
|
|
9531
|
+
tokenId: item.token_id,
|
|
9532
|
+
};
|
|
9533
|
+
}
|
|
9534
|
+
throw new Error('Sell items must ERC721');
|
|
9535
|
+
});
|
|
9536
|
+
return {
|
|
9537
|
+
id: order.id,
|
|
9538
|
+
accountAddress: order.account_address,
|
|
9539
|
+
buy: buyItems,
|
|
9540
|
+
sell: sellItems,
|
|
9541
|
+
fees: order.fees.map((fee) => ({
|
|
9542
|
+
amount: fee.amount,
|
|
9543
|
+
recipient: fee.recipient,
|
|
9544
|
+
type: fee.fee_type,
|
|
9545
|
+
})),
|
|
9546
|
+
chain: order.chain,
|
|
9547
|
+
createTime: order.create_time,
|
|
9548
|
+
endTime: order.end_time,
|
|
9549
|
+
protocolData: {
|
|
9550
|
+
counter: order.protocol_data.counter,
|
|
9551
|
+
orderType: order.protocol_data.order_type,
|
|
9552
|
+
seaportAddress: order.protocol_data.seaport_address,
|
|
9553
|
+
seaportVersion: order.protocol_data.seaport_version,
|
|
9554
|
+
zoneAddress: order.protocol_data.zone_address,
|
|
9555
|
+
},
|
|
9556
|
+
salt: order.salt,
|
|
9557
|
+
signature: order.signature,
|
|
9558
|
+
startTime: order.start_time,
|
|
9559
|
+
status: order.status,
|
|
9560
|
+
updateTime: order.update_time,
|
|
9561
|
+
};
|
|
9562
|
+
}
|
|
9563
|
+
function mapFromOpenApiPage(page) {
|
|
9564
|
+
return {
|
|
9565
|
+
nextCursor: page.next_cursor,
|
|
9566
|
+
previousCursor: page.previous_cursor,
|
|
9567
|
+
};
|
|
9568
|
+
}
|
|
9569
|
+
|
|
9509
9570
|
/* eslint-disable */
|
|
9510
9571
|
// TODO: Resolve these from seaport-js.
|
|
9511
9572
|
// There is some bundling issue that is preventing this from working
|
|
@@ -9735,7 +9796,17 @@ class Seaport {
|
|
|
9735
9796
|
buildTransaction: prepareTransaction(fulfilOrderAction.transactionMethods),
|
|
9736
9797
|
purpose: TransactionPurpose.FULFILL_ORDER,
|
|
9737
9798
|
});
|
|
9738
|
-
|
|
9799
|
+
// Expirtaion bytes in SIP7 extra data [21:29]
|
|
9800
|
+
// In hex string -> [21 * 2 + 2 (0x) : 29 * 2]
|
|
9801
|
+
// In JS slice (start, end_inclusive), (44,60)
|
|
9802
|
+
// 8 bytes uint64 epoch time in seconds
|
|
9803
|
+
const expirationHex = extraData.slice(44, 60);
|
|
9804
|
+
const expirationInSeconds = parseInt(expirationHex, 16);
|
|
9805
|
+
return {
|
|
9806
|
+
actions: fulfillmentActions,
|
|
9807
|
+
expiration: (new Date(expirationInSeconds * 1000)).toISOString(),
|
|
9808
|
+
order: mapFromOpenApiOrder(order),
|
|
9809
|
+
};
|
|
9739
9810
|
}
|
|
9740
9811
|
async cancelOrder(order, account) {
|
|
9741
9812
|
const { orderComponents } = this.mapImmutableOrderToSeaportOrderComponents(order);
|
|
@@ -9855,7 +9926,7 @@ class ImmutableApiClient {
|
|
|
9855
9926
|
],
|
|
9856
9927
|
fees: makerFee ? [{
|
|
9857
9928
|
amount: makerFee.amount,
|
|
9858
|
-
fee_type:
|
|
9929
|
+
fee_type: FeeType.MAKER_MARKETPLACE,
|
|
9859
9930
|
recipient: makerFee.recipient,
|
|
9860
9931
|
}] : [],
|
|
9861
9932
|
end_time: new Date(parseInt(`${orderComponents.endTime.toString()}000`, 10)).toISOString(),
|
|
@@ -9983,8 +10054,11 @@ class Orderbook {
|
|
|
9983
10054
|
* @param {string} listingId - The listingId to find.
|
|
9984
10055
|
* @return {ListingResult} The returned order result.
|
|
9985
10056
|
*/
|
|
9986
|
-
getListing(listingId) {
|
|
9987
|
-
|
|
10057
|
+
async getListing(listingId) {
|
|
10058
|
+
const apiListing = await this.apiClient.getListing(listingId);
|
|
10059
|
+
return {
|
|
10060
|
+
result: mapFromOpenApiOrder(apiListing.result),
|
|
10061
|
+
};
|
|
9988
10062
|
}
|
|
9989
10063
|
/**
|
|
9990
10064
|
* List orders. This method is used to get a list of orders filtered by conditions specified
|
|
@@ -9992,8 +10066,12 @@ class Orderbook {
|
|
|
9992
10066
|
* @param {ListListingsParams} listOrderParams - Filtering, ordering and page parameters.
|
|
9993
10067
|
* @return {ListListingsResult} The paged orders.
|
|
9994
10068
|
*/
|
|
9995
|
-
listListings(listOrderParams) {
|
|
9996
|
-
|
|
10069
|
+
async listListings(listOrderParams) {
|
|
10070
|
+
const apiListings = await this.apiClient.listListings(listOrderParams);
|
|
10071
|
+
return {
|
|
10072
|
+
page: mapFromOpenApiPage(apiListings.page),
|
|
10073
|
+
result: apiListings.result.map(mapFromOpenApiOrder),
|
|
10074
|
+
};
|
|
9997
10075
|
}
|
|
9998
10076
|
/**
|
|
9999
10077
|
* Get required transactions and messages for signing prior to creating a listing
|
|
@@ -10015,8 +10093,20 @@ class Orderbook {
|
|
|
10015
10093
|
* @param {CreateListingParams} createListingParams - create an order with the given params.
|
|
10016
10094
|
* @return {ListingResult} The result of the order created in the Immutable services.
|
|
10017
10095
|
*/
|
|
10018
|
-
createListing(createListingParams) {
|
|
10019
|
-
|
|
10096
|
+
async createListing(createListingParams) {
|
|
10097
|
+
const makerFee = createListingParams.makerFee
|
|
10098
|
+
? {
|
|
10099
|
+
...createListingParams.makerFee,
|
|
10100
|
+
type: FeeType.MAKER_MARKETPLACE,
|
|
10101
|
+
}
|
|
10102
|
+
: undefined;
|
|
10103
|
+
const apiListingResponse = await this.apiClient.createListing({
|
|
10104
|
+
...createListingParams,
|
|
10105
|
+
makerFee,
|
|
10106
|
+
});
|
|
10107
|
+
return {
|
|
10108
|
+
result: mapFromOpenApiOrder(apiListingResponse.result),
|
|
10109
|
+
};
|
|
10020
10110
|
}
|
|
10021
10111
|
/**
|
|
10022
10112
|
* Get unsigned transactions that can be submitted to fulfil an open order. If the approval
|
|
@@ -10033,7 +10123,7 @@ class Orderbook {
|
|
|
10033
10123
|
fee: takerFee
|
|
10034
10124
|
? {
|
|
10035
10125
|
amount: takerFee.amount,
|
|
10036
|
-
fee_type:
|
|
10126
|
+
fee_type: FeeType.TAKER_MARKETPLACE,
|
|
10037
10127
|
recipient: takerFee.recipient,
|
|
10038
10128
|
}
|
|
10039
10129
|
: undefined,
|
|
@@ -26837,6 +26927,8 @@ const $e768639828688ca3$export$44dde05038008549 = {
|
|
|
26837
26927
|
|
|
26838
26928
|
|
|
26839
26929
|
const $d85ad1457a3f1a83$export$7d3a9eeba384fa59 = "development";
|
|
26930
|
+
const $d85ad1457a3f1a83$export$b80040cb173ba6e9 = "0x0000000000000000000000000000000000001010";
|
|
26931
|
+
const $d85ad1457a3f1a83$export$903389470ba9433c = 18;
|
|
26840
26932
|
const $d85ad1457a3f1a83$export$161d4a74df65fc08 = {
|
|
26841
26933
|
[$d85ad1457a3f1a83$export$7d3a9eeba384fa59]: "https://checkout-api.dev.immutable.com",
|
|
26842
26934
|
[(Environment$1).SANDBOX]: "https://checkout-api.sandbox.immutable.com",
|
|
@@ -27119,6 +27211,25 @@ const $d85ad1457a3f1a83$export$8b8be7a2a654f23e = [
|
|
|
27119
27211
|
payable: false,
|
|
27120
27212
|
stateMutability: "view",
|
|
27121
27213
|
type: "function"
|
|
27214
|
+
},
|
|
27215
|
+
{
|
|
27216
|
+
inputs: [
|
|
27217
|
+
{
|
|
27218
|
+
internalType: "uint256",
|
|
27219
|
+
name: "tokenId",
|
|
27220
|
+
type: "uint256"
|
|
27221
|
+
}
|
|
27222
|
+
],
|
|
27223
|
+
name: "ownerOf",
|
|
27224
|
+
outputs: [
|
|
27225
|
+
{
|
|
27226
|
+
internalType: "address",
|
|
27227
|
+
name: "",
|
|
27228
|
+
type: "address"
|
|
27229
|
+
}
|
|
27230
|
+
],
|
|
27231
|
+
stateMutability: "view",
|
|
27232
|
+
type: "function"
|
|
27122
27233
|
}
|
|
27123
27234
|
];
|
|
27124
27235
|
|
|
@@ -27160,6 +27271,7 @@ var $4b58188d47aafe8d$export$5d3b0ad129b9b98e;
|
|
|
27160
27271
|
CheckoutErrorType["CONNECT_PROVIDER_ERROR"] = "CONNECT_PROVIDER_ERROR";
|
|
27161
27272
|
CheckoutErrorType["GET_BALANCE_ERROR"] = "GET_BALANCE_ERROR";
|
|
27162
27273
|
CheckoutErrorType["GET_ERC20_BALANCE_ERROR"] = "GET_ERC20_BALANCE_ERROR";
|
|
27274
|
+
CheckoutErrorType["GET_ERC721_BALANCE_ERROR"] = "GET_ERC721_BALANCE_ERROR";
|
|
27163
27275
|
CheckoutErrorType["GET_NETWORK_INFO_ERROR"] = "GET_NETWORK_INFO_ERROR";
|
|
27164
27276
|
CheckoutErrorType["METAMASK_PROVIDER_ERROR"] = "METAMASK_PROVIDER_ERROR";
|
|
27165
27277
|
CheckoutErrorType["CHAIN_NOT_SUPPORTED_ERROR"] = "CHAIN_NOT_SUPPORTED_ERROR";
|
|
@@ -27171,6 +27283,7 @@ var $4b58188d47aafe8d$export$5d3b0ad129b9b98e;
|
|
|
27171
27283
|
CheckoutErrorType["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
|
|
27172
27284
|
CheckoutErrorType["INVALID_GAS_ESTIMATE_TYPE"] = "INVALID_GAS_ESTIMATE_TYPE";
|
|
27173
27285
|
CheckoutErrorType["UNSUPPORTED_TOKEN_TYPE_ERROR"] = "UNSUPPORTED_TOKEN_TYPE_ERROR";
|
|
27286
|
+
CheckoutErrorType["UNSUPPORTED_BALANCE_REQUIREMENT_ERROR"] = "UNSUPPORTED_BALANCE_REQUIREMENT_ERROR";
|
|
27174
27287
|
CheckoutErrorType["GET_ORDER_LISTING_ERROR"] = "GET_ORDER_LISTING_ERROR";
|
|
27175
27288
|
CheckoutErrorType["SWITCH_NETWORK_UNSUPPORTED"] = "SWITCH_NETWORK_UNSUPPORTED";
|
|
27176
27289
|
CheckoutErrorType["GET_ERC20_ALLOWANCE_ERROR"] = "GET_ERC20_ALLOWANCE_ERROR";
|
|
@@ -27392,39 +27505,48 @@ const $1564e43dde50bb61$export$df96cd8d56be0ab1 = async (config, web3Provider, w
|
|
|
27392
27505
|
async function $1564e43dde50bb61$export$60e0fe116a0e6ed0(web3Provider, walletAddress, contractAddress) {
|
|
27393
27506
|
return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
27394
27507
|
const contract = new (Contract$1)(contractAddress, JSON.stringify(($d85ad1457a3f1a83$export$db5daa1b5156ccfe)), web3Provider);
|
|
27395
|
-
|
|
27396
|
-
|
|
27397
|
-
|
|
27398
|
-
|
|
27399
|
-
|
|
27400
|
-
|
|
27401
|
-
|
|
27402
|
-
|
|
27403
|
-
|
|
27404
|
-
|
|
27405
|
-
|
|
27406
|
-
|
|
27407
|
-
|
|
27408
|
-
|
|
27409
|
-
|
|
27508
|
+
return Promise.all([
|
|
27509
|
+
contract.name(),
|
|
27510
|
+
contract.symbol(),
|
|
27511
|
+
contract.balanceOf(walletAddress),
|
|
27512
|
+
contract.decimals()
|
|
27513
|
+
]).then(([name, symbol, balance, decimals])=>{
|
|
27514
|
+
const formattedBalance = (utils$1).formatUnits(balance, decimals);
|
|
27515
|
+
return {
|
|
27516
|
+
balance: balance,
|
|
27517
|
+
formattedBalance: formattedBalance,
|
|
27518
|
+
token: {
|
|
27519
|
+
name: name,
|
|
27520
|
+
symbol: symbol,
|
|
27521
|
+
decimals: decimals,
|
|
27522
|
+
address: contractAddress
|
|
27523
|
+
}
|
|
27524
|
+
};
|
|
27525
|
+
});
|
|
27410
27526
|
}, {
|
|
27411
27527
|
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC20_BALANCE_ERROR
|
|
27412
27528
|
});
|
|
27413
27529
|
}
|
|
27414
|
-
const $1564e43dde50bb61$export$
|
|
27415
|
-
const tokenList = await ($efe60cea83bfc4e8$export$473cec51305fdae8)(config, {
|
|
27416
|
-
type: ($08d5ddc39acd6833$export$fd9b17d87f4121d2).ALL,
|
|
27417
|
-
chainId: chainId
|
|
27418
|
-
});
|
|
27530
|
+
const $1564e43dde50bb61$export$a3238cee431627c6 = async (config, web3Provider, walletAddress, tokens)=>{
|
|
27419
27531
|
const allBalancePromises = [];
|
|
27420
|
-
|
|
27421
|
-
|
|
27532
|
+
tokens.forEach((token)=>{
|
|
27533
|
+
// Check for NATIVE token
|
|
27534
|
+
if (!token.address || token.address === ($d85ad1457a3f1a83$export$b80040cb173ba6e9)) allBalancePromises.push($1564e43dde50bb61$export$df96cd8d56be0ab1(config, web3Provider, walletAddress));
|
|
27535
|
+
else allBalancePromises.push($1564e43dde50bb61$export$60e0fe116a0e6ed0(web3Provider, walletAddress, token.address));
|
|
27536
|
+
});
|
|
27422
27537
|
const balanceResults = await Promise.allSettled(allBalancePromises);
|
|
27423
|
-
const
|
|
27538
|
+
const balances = balanceResults.filter((result)=>result.status === "fulfilled").map((fulfilledResult)=>fulfilledResult.value);
|
|
27424
27539
|
return {
|
|
27425
|
-
balances:
|
|
27540
|
+
balances: balances
|
|
27426
27541
|
};
|
|
27427
27542
|
};
|
|
27543
|
+
const $1564e43dde50bb61$export$fee49741664a4d7e = async (config, web3Provider, walletAddress, chainId)=>{
|
|
27544
|
+
const { tokens: tokens } = await ($efe60cea83bfc4e8$export$473cec51305fdae8)(config, {
|
|
27545
|
+
type: ($08d5ddc39acd6833$export$fd9b17d87f4121d2).ALL,
|
|
27546
|
+
chainId: chainId
|
|
27547
|
+
});
|
|
27548
|
+
return await $1564e43dde50bb61$export$a3238cee431627c6(config, web3Provider, walletAddress, tokens);
|
|
27549
|
+
};
|
|
27428
27550
|
|
|
27429
27551
|
|
|
27430
27552
|
|
|
@@ -28173,6 +28295,278 @@ const $35c3fc7013888ba5$export$be546c525d418988 = async (provider, ownerAddress,
|
|
|
28173
28295
|
|
|
28174
28296
|
|
|
28175
28297
|
|
|
28298
|
+
/* eslint-disable arrow-body-style */
|
|
28299
|
+
|
|
28300
|
+
|
|
28301
|
+
|
|
28302
|
+
|
|
28303
|
+
|
|
28304
|
+
const $aa6caea9a60d18c7$export$f4d35754ad350071 = (itemRequirements)=>{
|
|
28305
|
+
const aggregatedMap = new Map();
|
|
28306
|
+
const aggregatedItemRequirements = [];
|
|
28307
|
+
itemRequirements.forEach((itemRequirement)=>{
|
|
28308
|
+
const { type: type } = itemRequirement;
|
|
28309
|
+
if (type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) {
|
|
28310
|
+
aggregatedItemRequirements.push(itemRequirement);
|
|
28311
|
+
return;
|
|
28312
|
+
}
|
|
28313
|
+
const { amount: amount } = itemRequirement;
|
|
28314
|
+
const aggregateItem = aggregatedMap.get(type);
|
|
28315
|
+
if (aggregateItem && aggregateItem.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) aggregateItem.amount = (BigNumber$1).from(aggregateItem.amount).add(amount);
|
|
28316
|
+
else aggregatedMap.set(type, {
|
|
28317
|
+
...itemRequirement
|
|
28318
|
+
});
|
|
28319
|
+
});
|
|
28320
|
+
return aggregatedItemRequirements.concat(Array.from(aggregatedMap.values()));
|
|
28321
|
+
};
|
|
28322
|
+
const $aa6caea9a60d18c7$export$b8de545554d50911 = (itemRequirements)=>{
|
|
28323
|
+
const aggregatedMap = new Map();
|
|
28324
|
+
const aggregatedItemRequirements = [];
|
|
28325
|
+
itemRequirements.forEach((itemRequirement)=>{
|
|
28326
|
+
const { type: type } = itemRequirement;
|
|
28327
|
+
if (type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
|
|
28328
|
+
aggregatedItemRequirements.push(itemRequirement);
|
|
28329
|
+
return;
|
|
28330
|
+
}
|
|
28331
|
+
const { contractAddress: contractAddress, amount: amount } = itemRequirement;
|
|
28332
|
+
const key = `${contractAddress}`;
|
|
28333
|
+
const aggregateItem = aggregatedMap.get(key);
|
|
28334
|
+
if (aggregateItem && aggregateItem.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) aggregateItem.amount = (BigNumber$1).from(aggregateItem.amount).add(amount);
|
|
28335
|
+
else aggregatedMap.set(key, {
|
|
28336
|
+
...itemRequirement
|
|
28337
|
+
});
|
|
28338
|
+
});
|
|
28339
|
+
return aggregatedItemRequirements.concat(Array.from(aggregatedMap.values()));
|
|
28340
|
+
};
|
|
28341
|
+
const $aa6caea9a60d18c7$export$74fbc29ef48b4f31 = (itemRequirements)=>{
|
|
28342
|
+
const aggregatedMap = new Map();
|
|
28343
|
+
const aggregatedItemRequirements = [];
|
|
28344
|
+
itemRequirements.forEach((itemRequirement)=>{
|
|
28345
|
+
const { type: type } = itemRequirement;
|
|
28346
|
+
if (type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721) {
|
|
28347
|
+
aggregatedItemRequirements.push(itemRequirement);
|
|
28348
|
+
return;
|
|
28349
|
+
}
|
|
28350
|
+
const { contractAddress: contractAddress, id: id } = itemRequirement;
|
|
28351
|
+
const key = `${contractAddress}${id}`;
|
|
28352
|
+
const aggregateItem = aggregatedMap.get(key);
|
|
28353
|
+
if (!aggregateItem) aggregatedMap.set(key, {
|
|
28354
|
+
...itemRequirement
|
|
28355
|
+
});
|
|
28356
|
+
});
|
|
28357
|
+
return aggregatedItemRequirements.concat(Array.from(aggregatedMap.values()));
|
|
28358
|
+
};
|
|
28359
|
+
const $aa6caea9a60d18c7$export$f96d1c819a615a64 = (itemRequirements)=>$aa6caea9a60d18c7$export$74fbc29ef48b4f31($aa6caea9a60d18c7$export$b8de545554d50911($aa6caea9a60d18c7$export$f4d35754ad350071(itemRequirements)));
|
|
28360
|
+
|
|
28361
|
+
|
|
28362
|
+
/* eslint-disable arrow-body-style */
|
|
28363
|
+
|
|
28364
|
+
const $73d2282a108cc7e2$export$ed7929b58bab85da = (itemRequirements)=>itemRequirements.map((itemRequirement)=>{
|
|
28365
|
+
if (itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return {
|
|
28366
|
+
name: "IMX",
|
|
28367
|
+
symbol: "IMX",
|
|
28368
|
+
address: ($d85ad1457a3f1a83$export$b80040cb173ba6e9)
|
|
28369
|
+
};
|
|
28370
|
+
return {
|
|
28371
|
+
name: itemRequirement.type,
|
|
28372
|
+
address: itemRequirement.contractAddress
|
|
28373
|
+
};
|
|
28374
|
+
});
|
|
28375
|
+
const $73d2282a108cc7e2$export$9b757e40b19984c3 = (itemRequirement, balances)=>{
|
|
28376
|
+
const requiredBalance = (BigNumber$1).from(1);
|
|
28377
|
+
// Find the requirements related balance
|
|
28378
|
+
const itemBalanceResult = balances.find((balance)=>{
|
|
28379
|
+
const balanceERC721Result = balance;
|
|
28380
|
+
return balanceERC721Result.contractAddress === itemRequirement.contractAddress && balanceERC721Result.id === itemRequirement.id;
|
|
28381
|
+
});
|
|
28382
|
+
// Calculate the balance delta
|
|
28383
|
+
const sufficient = requiredBalance.isNegative() || requiredBalance.isZero() || (itemBalanceResult?.balance.gte(requiredBalance) ?? false);
|
|
28384
|
+
const delta = requiredBalance.sub(itemBalanceResult?.balance ?? (BigNumber$1).from(0));
|
|
28385
|
+
let erc721BalanceResult = itemBalanceResult;
|
|
28386
|
+
if (!erc721BalanceResult) erc721BalanceResult = {
|
|
28387
|
+
balance: (BigNumber$1).from(0),
|
|
28388
|
+
formattedBalance: "0",
|
|
28389
|
+
contractAddress: itemRequirement.contractAddress,
|
|
28390
|
+
id: itemRequirement.id
|
|
28391
|
+
};
|
|
28392
|
+
return {
|
|
28393
|
+
sufficient: sufficient,
|
|
28394
|
+
type: itemRequirement.type,
|
|
28395
|
+
delta: {
|
|
28396
|
+
balance: delta,
|
|
28397
|
+
formattedBalance: delta.toString()
|
|
28398
|
+
},
|
|
28399
|
+
current: erc721BalanceResult,
|
|
28400
|
+
required: {
|
|
28401
|
+
...erc721BalanceResult,
|
|
28402
|
+
balance: (BigNumber$1).from(1),
|
|
28403
|
+
formattedBalance: "1"
|
|
28404
|
+
}
|
|
28405
|
+
};
|
|
28406
|
+
};
|
|
28407
|
+
const $73d2282a108cc7e2$export$6ab9757fda54db7e = (itemRequirement, balances)=>{
|
|
28408
|
+
let itemBalanceResult;
|
|
28409
|
+
// Get the requirements related balance
|
|
28410
|
+
if (itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) itemBalanceResult = balances.find((balance)=>{
|
|
28411
|
+
return balance.token?.address === itemRequirement.contractAddress;
|
|
28412
|
+
});
|
|
28413
|
+
else if (itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) itemBalanceResult = balances.find((balance)=>{
|
|
28414
|
+
return !("address" in balance.token) || balance.token?.address === ($d85ad1457a3f1a83$export$b80040cb173ba6e9);
|
|
28415
|
+
});
|
|
28416
|
+
// Calculate the balance delta
|
|
28417
|
+
const requiredBalance = itemRequirement.amount;
|
|
28418
|
+
const sufficient = requiredBalance.isNegative() || requiredBalance.isZero() || (itemBalanceResult?.balance.gte(requiredBalance) ?? false);
|
|
28419
|
+
const delta = requiredBalance.sub(itemBalanceResult?.balance ?? (BigNumber$1).from(0));
|
|
28420
|
+
let decimals = ($d85ad1457a3f1a83$export$903389470ba9433c);
|
|
28421
|
+
if (itemBalanceResult) decimals = itemBalanceResult.token?.decimals ?? ($d85ad1457a3f1a83$export$903389470ba9433c);
|
|
28422
|
+
let tokenBalanceResult = itemBalanceResult;
|
|
28423
|
+
if (itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) {
|
|
28424
|
+
// No token balance so mark as zero native
|
|
28425
|
+
if (!tokenBalanceResult) tokenBalanceResult = {
|
|
28426
|
+
balance: (BigNumber$1).from(0),
|
|
28427
|
+
formattedBalance: "0",
|
|
28428
|
+
token: {
|
|
28429
|
+
name: "IMX",
|
|
28430
|
+
symbol: "IMX",
|
|
28431
|
+
decimals: ($d85ad1457a3f1a83$export$903389470ba9433c),
|
|
28432
|
+
address: ($d85ad1457a3f1a83$export$b80040cb173ba6e9)
|
|
28433
|
+
}
|
|
28434
|
+
};
|
|
28435
|
+
return {
|
|
28436
|
+
sufficient: sufficient,
|
|
28437
|
+
type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE,
|
|
28438
|
+
delta: {
|
|
28439
|
+
balance: delta,
|
|
28440
|
+
formattedBalance: (utils$1).formatUnits(delta, decimals)
|
|
28441
|
+
},
|
|
28442
|
+
current: tokenBalanceResult,
|
|
28443
|
+
required: {
|
|
28444
|
+
...tokenBalanceResult,
|
|
28445
|
+
balance: (BigNumber$1).from(itemRequirement.amount),
|
|
28446
|
+
formattedBalance: (utils$1).formatUnits(itemRequirement.amount, decimals)
|
|
28447
|
+
}
|
|
28448
|
+
};
|
|
28449
|
+
}
|
|
28450
|
+
// No token balance so mark as zero
|
|
28451
|
+
if (!tokenBalanceResult) tokenBalanceResult = {
|
|
28452
|
+
balance: (BigNumber$1).from(0),
|
|
28453
|
+
formattedBalance: "0",
|
|
28454
|
+
token: {
|
|
28455
|
+
address: itemRequirement.contractAddress
|
|
28456
|
+
}
|
|
28457
|
+
};
|
|
28458
|
+
return {
|
|
28459
|
+
sufficient: sufficient,
|
|
28460
|
+
type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20,
|
|
28461
|
+
delta: {
|
|
28462
|
+
balance: delta,
|
|
28463
|
+
formattedBalance: (utils$1).formatUnits(delta, decimals)
|
|
28464
|
+
},
|
|
28465
|
+
current: tokenBalanceResult,
|
|
28466
|
+
required: {
|
|
28467
|
+
...tokenBalanceResult,
|
|
28468
|
+
balance: (BigNumber$1).from(itemRequirement.amount),
|
|
28469
|
+
formattedBalance: (utils$1).formatUnits(itemRequirement.amount, decimals)
|
|
28470
|
+
}
|
|
28471
|
+
};
|
|
28472
|
+
};
|
|
28473
|
+
|
|
28474
|
+
|
|
28475
|
+
/**
|
|
28476
|
+
* Gets the balances for all NATIVE and ERC20 balance requirements.
|
|
28477
|
+
*/ const $beb896e098e41faf$var$getTokenBalances = async (config, provider, ownerAddress, itemRequirements)=>{
|
|
28478
|
+
let tokenBalances = [];
|
|
28479
|
+
try {
|
|
28480
|
+
const tokenList = (0, $73d2282a108cc7e2$export$ed7929b58bab85da)(itemRequirements);
|
|
28481
|
+
const { balances: balances } = await (0, $1564e43dde50bb61$export$a3238cee431627c6)(config, provider, ownerAddress, tokenList);
|
|
28482
|
+
tokenBalances = [
|
|
28483
|
+
...balances.map((balance)=>balance)
|
|
28484
|
+
];
|
|
28485
|
+
} catch (error) {
|
|
28486
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Failed to get balances", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_BALANCE_ERROR);
|
|
28487
|
+
}
|
|
28488
|
+
return tokenBalances;
|
|
28489
|
+
};
|
|
28490
|
+
/**
|
|
28491
|
+
* Gets the balances for all ERC721 balance requirements.
|
|
28492
|
+
*/ const $beb896e098e41faf$var$getERC721Balances = async (provider, ownerAddress, itemRequirements)=>{
|
|
28493
|
+
const erc721Balances = [];
|
|
28494
|
+
// Setup maps to be able to link data back to the associated promises
|
|
28495
|
+
const erc721s = new Map();
|
|
28496
|
+
const erc721OwnershipPromises = new Map();
|
|
28497
|
+
itemRequirements.filter((itemRequirement)=>itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721).forEach((itemRequirement)=>{
|
|
28498
|
+
const erc721Requirement = itemRequirement;
|
|
28499
|
+
const contract = new (Contract$1)(erc721Requirement.contractAddress, JSON.stringify(($d85ad1457a3f1a83$export$8b8be7a2a654f23e)), provider);
|
|
28500
|
+
erc721s.set(erc721Requirement.contractAddress, itemRequirement);
|
|
28501
|
+
erc721OwnershipPromises.set(erc721Requirement.contractAddress, contract.ownerOf(erc721Requirement.id));
|
|
28502
|
+
});
|
|
28503
|
+
try {
|
|
28504
|
+
// Convert ERC721 ownership into a balance result
|
|
28505
|
+
const erc721Owners = await Promise.all(erc721OwnershipPromises.values());
|
|
28506
|
+
const erc721OwnersPromiseIds = Array.from(erc721OwnershipPromises.keys());
|
|
28507
|
+
erc721Owners.forEach((erc721OwnerAddress, index)=>{
|
|
28508
|
+
const itemRequirement = erc721s.get(erc721OwnersPromiseIds[index]);
|
|
28509
|
+
let itemCount = 0;
|
|
28510
|
+
if (itemRequirement && ownerAddress === erc721OwnerAddress) itemCount = 1;
|
|
28511
|
+
erc721Balances.push({
|
|
28512
|
+
balance: (0, BigNumber$1).from(itemCount),
|
|
28513
|
+
formattedBalance: itemCount.toString(),
|
|
28514
|
+
contractAddress: itemRequirement.contractAddress,
|
|
28515
|
+
id: itemRequirement.id
|
|
28516
|
+
});
|
|
28517
|
+
});
|
|
28518
|
+
} catch (error) {
|
|
28519
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Failed to get ERC721 balances", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC721_BALANCE_ERROR);
|
|
28520
|
+
}
|
|
28521
|
+
return erc721Balances;
|
|
28522
|
+
};
|
|
28523
|
+
const $beb896e098e41faf$export$ddfc885f43c3cb6e = async (config, provider, ownerAddress, itemRequirements)=>{
|
|
28524
|
+
const aggregatedItems = ($aa6caea9a60d18c7$export$f96d1c819a615a64)(itemRequirements);
|
|
28525
|
+
if (aggregatedItems.filter((itemRequirement)=>{
|
|
28526
|
+
return itemRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721 && itemRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20 && itemRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE;
|
|
28527
|
+
}).length > 0) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Unsupported item requirement balance check", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).UNSUPPORTED_BALANCE_REQUIREMENT_ERROR);
|
|
28528
|
+
// Get all ERC20 and NATIVE balances
|
|
28529
|
+
const currentBalances = [];
|
|
28530
|
+
const tokenItemRequirements = aggregatedItems.filter((itemRequirement)=>itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20 || itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE);
|
|
28531
|
+
if (tokenItemRequirements.length > 0) currentBalances.push($beb896e098e41faf$var$getTokenBalances(config, provider, ownerAddress, aggregatedItems));
|
|
28532
|
+
// Get all ERC721 balances
|
|
28533
|
+
const erc721ItemRequirements = aggregatedItems.filter((itemRequirement)=>itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721);
|
|
28534
|
+
if (erc721ItemRequirements.length > 0) currentBalances.push($beb896e098e41faf$var$getERC721Balances(provider, ownerAddress, aggregatedItems));
|
|
28535
|
+
// Wait for all balances and calculate the requirements
|
|
28536
|
+
const balanceRequirements = await Promise.all(currentBalances).then((balances)=>{
|
|
28537
|
+
const requirements = [];
|
|
28538
|
+
if (balances.length > 1 || tokenItemRequirements.length > 0) {
|
|
28539
|
+
const tokenBalances = balances[0];
|
|
28540
|
+
tokenItemRequirements.forEach((tokenItemRequirement)=>{
|
|
28541
|
+
requirements.push(($73d2282a108cc7e2$export$6ab9757fda54db7e)(tokenItemRequirement, tokenBalances));
|
|
28542
|
+
});
|
|
28543
|
+
if (erc721ItemRequirements.length > 0) {
|
|
28544
|
+
const erc721Balances = balances[1];
|
|
28545
|
+
erc721ItemRequirements.forEach((erc721ItemRequirement)=>{
|
|
28546
|
+
requirements.push(($73d2282a108cc7e2$export$9b757e40b19984c3)(erc721ItemRequirement, erc721Balances));
|
|
28547
|
+
});
|
|
28548
|
+
}
|
|
28549
|
+
} else if (erc721ItemRequirements.length > 0) {
|
|
28550
|
+
// Only erc721
|
|
28551
|
+
const erc721Balances = balances[0];
|
|
28552
|
+
erc721ItemRequirements.forEach((erc721ItemRequirement)=>{
|
|
28553
|
+
requirements.push(($73d2282a108cc7e2$export$9b757e40b19984c3)(erc721ItemRequirement, erc721Balances));
|
|
28554
|
+
});
|
|
28555
|
+
}
|
|
28556
|
+
return requirements;
|
|
28557
|
+
});
|
|
28558
|
+
const sufficient = balanceRequirements.reduce((acc, balanceRequirement)=>{
|
|
28559
|
+
return acc && balanceRequirement.sufficient;
|
|
28560
|
+
}, true);
|
|
28561
|
+
return {
|
|
28562
|
+
sufficient: sufficient,
|
|
28563
|
+
itemRequirements: balanceRequirements
|
|
28564
|
+
};
|
|
28565
|
+
};
|
|
28566
|
+
|
|
28567
|
+
|
|
28568
|
+
|
|
28569
|
+
|
|
28176
28570
|
|
|
28177
28571
|
|
|
28178
28572
|
|
|
@@ -28229,7 +28623,7 @@ const $7d1bfafb81e64d74$export$3a4140bd9e983e4e = async (provider, insufficientI
|
|
|
28229
28623
|
};
|
|
28230
28624
|
|
|
28231
28625
|
|
|
28232
|
-
const $0e7419077c373b24$export$9e073f9ada8c81e6 = async (provider, itemRequirements, transactionOrGasAmount)=>{
|
|
28626
|
+
const $0e7419077c373b24$export$9e073f9ada8c81e6 = async (config, provider, itemRequirements, transactionOrGasAmount)=>{
|
|
28233
28627
|
// eslint-disable-next-line no-console
|
|
28234
28628
|
console.log(provider, itemRequirements, transactionOrGasAmount);
|
|
28235
28629
|
const ownerAddress = await provider.getSigner().getAddress();
|
|
@@ -28248,6 +28642,9 @@ const $0e7419077c373b24$export$9e073f9ada8c81e6 = async (provider, itemRequireme
|
|
|
28248
28642
|
}
|
|
28249
28643
|
// eslint-disable-next-line no-console
|
|
28250
28644
|
console.log("Aggregated Items", aggregatedItems);
|
|
28645
|
+
const balanceRequirements = await ($beb896e098e41faf$export$ddfc885f43c3cb6e)(config, provider, ownerAddress, aggregatedItems);
|
|
28646
|
+
// eslint-disable-next-line no-console
|
|
28647
|
+
console.log("Balance Requirements", balanceRequirements);
|
|
28251
28648
|
return {
|
|
28252
28649
|
sufficient: true,
|
|
28253
28650
|
transactionRequirements: [
|
|
@@ -28345,13 +28742,13 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
|
|
|
28345
28742
|
let type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE;
|
|
28346
28743
|
let contractAddress = "";
|
|
28347
28744
|
const buyArray = order.result.buy;
|
|
28348
|
-
if (buyArray.length > 0) switch(buyArray[0].
|
|
28745
|
+
if (buyArray.length > 0) switch(buyArray[0].type){
|
|
28349
28746
|
case "NATIVE":
|
|
28350
28747
|
type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE;
|
|
28351
28748
|
break;
|
|
28352
28749
|
case "ERC20":
|
|
28353
28750
|
type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20;
|
|
28354
|
-
contractAddress = buyArray[0].
|
|
28751
|
+
contractAddress = buyArray[0].contractAddress;
|
|
28355
28752
|
break;
|
|
28356
28753
|
default:
|
|
28357
28754
|
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Purchasing token type is unsupported", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).UNSUPPORTED_TOKEN_TYPE_ERROR, {
|
|
@@ -28359,7 +28756,7 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
|
|
|
28359
28756
|
});
|
|
28360
28757
|
}
|
|
28361
28758
|
buyArray.forEach((item)=>{
|
|
28362
|
-
if (item.
|
|
28759
|
+
if (item.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721) amount = amount.add((BigNumber$1).from(item.amount));
|
|
28363
28760
|
});
|
|
28364
28761
|
const feeArray = order.result.fees;
|
|
28365
28762
|
feeArray.forEach((item)=>{
|
|
@@ -28368,7 +28765,7 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
|
|
|
28368
28765
|
const itemRequirements = [
|
|
28369
28766
|
$64863c39386de592$export$4249179755829904(type, contractAddress, amount, spenderAddress)
|
|
28370
28767
|
];
|
|
28371
|
-
await ($0e7419077c373b24$export$9e073f9ada8c81e6)(provider, itemRequirements, $64863c39386de592$export$8f2ff92ab8657f0b(gasLimit, unsignedTransaction));
|
|
28768
|
+
await ($0e7419077c373b24$export$9e073f9ada8c81e6)(config, provider, itemRequirements, $64863c39386de592$export$8f2ff92ab8657f0b(gasLimit, unsignedTransaction));
|
|
28372
28769
|
return {
|
|
28373
28770
|
itemRequirements: itemRequirements,
|
|
28374
28771
|
gasToken: {
|
|
@@ -28537,7 +28934,7 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
|
|
|
28537
28934
|
// eslint-disable-next-line no-console
|
|
28538
28935
|
console.warn("This endpoint is currently under construction.");
|
|
28539
28936
|
const web3Provider = await $bb88265fe45a0393$export$9e1fd9cc88c637a0(this.config, params.provider);
|
|
28540
|
-
await $0e7419077c373b24$export$9e073f9ada8c81e6(web3Provider, params.itemRequirements, params.transactionOrGasAmount);
|
|
28937
|
+
await $0e7419077c373b24$export$9e073f9ada8c81e6(this.config, web3Provider, params.itemRequirements, params.transactionOrGasAmount);
|
|
28541
28938
|
}
|
|
28542
28939
|
/**
|
|
28543
28940
|
* Checks if the given object is a Web3 provider.
|
|
@@ -28576,7 +28973,7 @@ var checkout_sdk = /*#__PURE__*/Object.freeze({
|
|
|
28576
28973
|
function $parcel$export(e, n, v, s) {
|
|
28577
28974
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
28578
28975
|
}
|
|
28579
|
-
const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.14.0-alpha";
|
|
28976
|
+
const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.14.0-alpha.2";
|
|
28580
28977
|
const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
|
|
28581
28978
|
const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
|
|
28582
28979
|
|