@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.cjs
CHANGED
|
@@ -2420,7 +2420,7 @@ class MultiRollupApiClients {
|
|
|
2420
2420
|
}
|
|
2421
2421
|
|
|
2422
2422
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
2423
|
-
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.14.0-alpha' };
|
|
2423
|
+
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.14.0-alpha.2' };
|
|
2424
2424
|
const createConfig = ({ basePath, headers, }) => {
|
|
2425
2425
|
if (!basePath.trim()) {
|
|
2426
2426
|
throw Error('basePath can not be empty');
|
|
@@ -2480,7 +2480,7 @@ class APIError extends Error {
|
|
|
2480
2480
|
|
|
2481
2481
|
/* eslint-disable implicit-arrow-linebreak */
|
|
2482
2482
|
const defaultHeaders = {
|
|
2483
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.14.0-alpha',
|
|
2483
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.14.0-alpha.2',
|
|
2484
2484
|
};
|
|
2485
2485
|
/**
|
|
2486
2486
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -2752,7 +2752,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
2752
2752
|
chainID,
|
|
2753
2753
|
coreContractAddress,
|
|
2754
2754
|
registrationContractAddress,
|
|
2755
|
-
sdkVersion: 'ts-immutable-sdk-0.14.0-alpha',
|
|
2755
|
+
sdkVersion: 'ts-immutable-sdk-0.14.0-alpha.2',
|
|
2756
2756
|
});
|
|
2757
2757
|
/**
|
|
2758
2758
|
* Sets `sdkVersion` at the time of build
|
|
@@ -9528,6 +9528,67 @@ var ActionType;
|
|
|
9528
9528
|
ActionType["SIGNABLE"] = "SIGNABLE";
|
|
9529
9529
|
})(ActionType || (ActionType = {}));
|
|
9530
9530
|
|
|
9531
|
+
function mapFromOpenApiOrder(order) {
|
|
9532
|
+
const buyItems = order.buy.map((item) => {
|
|
9533
|
+
if (item.item_type === 'ERC20') {
|
|
9534
|
+
return {
|
|
9535
|
+
type: 'ERC20',
|
|
9536
|
+
contractAddress: item.contract_address,
|
|
9537
|
+
amount: item.start_amount,
|
|
9538
|
+
};
|
|
9539
|
+
}
|
|
9540
|
+
if (item.item_type === 'NATIVE') {
|
|
9541
|
+
return {
|
|
9542
|
+
type: 'NATIVE',
|
|
9543
|
+
amount: item.start_amount,
|
|
9544
|
+
};
|
|
9545
|
+
}
|
|
9546
|
+
throw new Error('Buy items must be either ERC20 or NATIVE');
|
|
9547
|
+
});
|
|
9548
|
+
const sellItems = order.sell.map((item) => {
|
|
9549
|
+
if (item.item_type === 'ERC721') {
|
|
9550
|
+
return {
|
|
9551
|
+
type: 'ERC721',
|
|
9552
|
+
contractAddress: item.contract_address,
|
|
9553
|
+
tokenId: item.token_id,
|
|
9554
|
+
};
|
|
9555
|
+
}
|
|
9556
|
+
throw new Error('Sell items must ERC721');
|
|
9557
|
+
});
|
|
9558
|
+
return {
|
|
9559
|
+
id: order.id,
|
|
9560
|
+
accountAddress: order.account_address,
|
|
9561
|
+
buy: buyItems,
|
|
9562
|
+
sell: sellItems,
|
|
9563
|
+
fees: order.fees.map((fee) => ({
|
|
9564
|
+
amount: fee.amount,
|
|
9565
|
+
recipient: fee.recipient,
|
|
9566
|
+
type: fee.fee_type,
|
|
9567
|
+
})),
|
|
9568
|
+
chain: order.chain,
|
|
9569
|
+
createTime: order.create_time,
|
|
9570
|
+
endTime: order.end_time,
|
|
9571
|
+
protocolData: {
|
|
9572
|
+
counter: order.protocol_data.counter,
|
|
9573
|
+
orderType: order.protocol_data.order_type,
|
|
9574
|
+
seaportAddress: order.protocol_data.seaport_address,
|
|
9575
|
+
seaportVersion: order.protocol_data.seaport_version,
|
|
9576
|
+
zoneAddress: order.protocol_data.zone_address,
|
|
9577
|
+
},
|
|
9578
|
+
salt: order.salt,
|
|
9579
|
+
signature: order.signature,
|
|
9580
|
+
startTime: order.start_time,
|
|
9581
|
+
status: order.status,
|
|
9582
|
+
updateTime: order.update_time,
|
|
9583
|
+
};
|
|
9584
|
+
}
|
|
9585
|
+
function mapFromOpenApiPage(page) {
|
|
9586
|
+
return {
|
|
9587
|
+
nextCursor: page.next_cursor,
|
|
9588
|
+
previousCursor: page.previous_cursor,
|
|
9589
|
+
};
|
|
9590
|
+
}
|
|
9591
|
+
|
|
9531
9592
|
/* eslint-disable */
|
|
9532
9593
|
// TODO: Resolve these from seaport-js.
|
|
9533
9594
|
// There is some bundling issue that is preventing this from working
|
|
@@ -9757,7 +9818,17 @@ class Seaport {
|
|
|
9757
9818
|
buildTransaction: prepareTransaction(fulfilOrderAction.transactionMethods),
|
|
9758
9819
|
purpose: TransactionPurpose.FULFILL_ORDER,
|
|
9759
9820
|
});
|
|
9760
|
-
|
|
9821
|
+
// Expirtaion bytes in SIP7 extra data [21:29]
|
|
9822
|
+
// In hex string -> [21 * 2 + 2 (0x) : 29 * 2]
|
|
9823
|
+
// In JS slice (start, end_inclusive), (44,60)
|
|
9824
|
+
// 8 bytes uint64 epoch time in seconds
|
|
9825
|
+
const expirationHex = extraData.slice(44, 60);
|
|
9826
|
+
const expirationInSeconds = parseInt(expirationHex, 16);
|
|
9827
|
+
return {
|
|
9828
|
+
actions: fulfillmentActions,
|
|
9829
|
+
expiration: (new Date(expirationInSeconds * 1000)).toISOString(),
|
|
9830
|
+
order: mapFromOpenApiOrder(order),
|
|
9831
|
+
};
|
|
9761
9832
|
}
|
|
9762
9833
|
async cancelOrder(order, account) {
|
|
9763
9834
|
const { orderComponents } = this.mapImmutableOrderToSeaportOrderComponents(order);
|
|
@@ -9877,7 +9948,7 @@ class ImmutableApiClient {
|
|
|
9877
9948
|
],
|
|
9878
9949
|
fees: makerFee ? [{
|
|
9879
9950
|
amount: makerFee.amount,
|
|
9880
|
-
fee_type:
|
|
9951
|
+
fee_type: FeeType.MAKER_MARKETPLACE,
|
|
9881
9952
|
recipient: makerFee.recipient,
|
|
9882
9953
|
}] : [],
|
|
9883
9954
|
end_time: new Date(parseInt(`${orderComponents.endTime.toString()}000`, 10)).toISOString(),
|
|
@@ -10005,8 +10076,11 @@ class Orderbook {
|
|
|
10005
10076
|
* @param {string} listingId - The listingId to find.
|
|
10006
10077
|
* @return {ListingResult} The returned order result.
|
|
10007
10078
|
*/
|
|
10008
|
-
getListing(listingId) {
|
|
10009
|
-
|
|
10079
|
+
async getListing(listingId) {
|
|
10080
|
+
const apiListing = await this.apiClient.getListing(listingId);
|
|
10081
|
+
return {
|
|
10082
|
+
result: mapFromOpenApiOrder(apiListing.result),
|
|
10083
|
+
};
|
|
10010
10084
|
}
|
|
10011
10085
|
/**
|
|
10012
10086
|
* List orders. This method is used to get a list of orders filtered by conditions specified
|
|
@@ -10014,8 +10088,12 @@ class Orderbook {
|
|
|
10014
10088
|
* @param {ListListingsParams} listOrderParams - Filtering, ordering and page parameters.
|
|
10015
10089
|
* @return {ListListingsResult} The paged orders.
|
|
10016
10090
|
*/
|
|
10017
|
-
listListings(listOrderParams) {
|
|
10018
|
-
|
|
10091
|
+
async listListings(listOrderParams) {
|
|
10092
|
+
const apiListings = await this.apiClient.listListings(listOrderParams);
|
|
10093
|
+
return {
|
|
10094
|
+
page: mapFromOpenApiPage(apiListings.page),
|
|
10095
|
+
result: apiListings.result.map(mapFromOpenApiOrder),
|
|
10096
|
+
};
|
|
10019
10097
|
}
|
|
10020
10098
|
/**
|
|
10021
10099
|
* Get required transactions and messages for signing prior to creating a listing
|
|
@@ -10037,8 +10115,20 @@ class Orderbook {
|
|
|
10037
10115
|
* @param {CreateListingParams} createListingParams - create an order with the given params.
|
|
10038
10116
|
* @return {ListingResult} The result of the order created in the Immutable services.
|
|
10039
10117
|
*/
|
|
10040
|
-
createListing(createListingParams) {
|
|
10041
|
-
|
|
10118
|
+
async createListing(createListingParams) {
|
|
10119
|
+
const makerFee = createListingParams.makerFee
|
|
10120
|
+
? {
|
|
10121
|
+
...createListingParams.makerFee,
|
|
10122
|
+
type: FeeType.MAKER_MARKETPLACE,
|
|
10123
|
+
}
|
|
10124
|
+
: undefined;
|
|
10125
|
+
const apiListingResponse = await this.apiClient.createListing({
|
|
10126
|
+
...createListingParams,
|
|
10127
|
+
makerFee,
|
|
10128
|
+
});
|
|
10129
|
+
return {
|
|
10130
|
+
result: mapFromOpenApiOrder(apiListingResponse.result),
|
|
10131
|
+
};
|
|
10042
10132
|
}
|
|
10043
10133
|
/**
|
|
10044
10134
|
* Get unsigned transactions that can be submitted to fulfil an open order. If the approval
|
|
@@ -10055,7 +10145,7 @@ class Orderbook {
|
|
|
10055
10145
|
fee: takerFee
|
|
10056
10146
|
? {
|
|
10057
10147
|
amount: takerFee.amount,
|
|
10058
|
-
fee_type:
|
|
10148
|
+
fee_type: FeeType.TAKER_MARKETPLACE,
|
|
10059
10149
|
recipient: takerFee.recipient,
|
|
10060
10150
|
}
|
|
10061
10151
|
: undefined,
|
|
@@ -26859,6 +26949,8 @@ const $e768639828688ca3$export$44dde05038008549 = {
|
|
|
26859
26949
|
|
|
26860
26950
|
|
|
26861
26951
|
const $d85ad1457a3f1a83$export$7d3a9eeba384fa59 = "development";
|
|
26952
|
+
const $d85ad1457a3f1a83$export$b80040cb173ba6e9 = "0x0000000000000000000000000000000000001010";
|
|
26953
|
+
const $d85ad1457a3f1a83$export$903389470ba9433c = 18;
|
|
26862
26954
|
const $d85ad1457a3f1a83$export$161d4a74df65fc08 = {
|
|
26863
26955
|
[$d85ad1457a3f1a83$export$7d3a9eeba384fa59]: "https://checkout-api.dev.immutable.com",
|
|
26864
26956
|
[(Environment$1).SANDBOX]: "https://checkout-api.sandbox.immutable.com",
|
|
@@ -27141,6 +27233,25 @@ const $d85ad1457a3f1a83$export$8b8be7a2a654f23e = [
|
|
|
27141
27233
|
payable: false,
|
|
27142
27234
|
stateMutability: "view",
|
|
27143
27235
|
type: "function"
|
|
27236
|
+
},
|
|
27237
|
+
{
|
|
27238
|
+
inputs: [
|
|
27239
|
+
{
|
|
27240
|
+
internalType: "uint256",
|
|
27241
|
+
name: "tokenId",
|
|
27242
|
+
type: "uint256"
|
|
27243
|
+
}
|
|
27244
|
+
],
|
|
27245
|
+
name: "ownerOf",
|
|
27246
|
+
outputs: [
|
|
27247
|
+
{
|
|
27248
|
+
internalType: "address",
|
|
27249
|
+
name: "",
|
|
27250
|
+
type: "address"
|
|
27251
|
+
}
|
|
27252
|
+
],
|
|
27253
|
+
stateMutability: "view",
|
|
27254
|
+
type: "function"
|
|
27144
27255
|
}
|
|
27145
27256
|
];
|
|
27146
27257
|
|
|
@@ -27182,6 +27293,7 @@ var $4b58188d47aafe8d$export$5d3b0ad129b9b98e;
|
|
|
27182
27293
|
CheckoutErrorType["CONNECT_PROVIDER_ERROR"] = "CONNECT_PROVIDER_ERROR";
|
|
27183
27294
|
CheckoutErrorType["GET_BALANCE_ERROR"] = "GET_BALANCE_ERROR";
|
|
27184
27295
|
CheckoutErrorType["GET_ERC20_BALANCE_ERROR"] = "GET_ERC20_BALANCE_ERROR";
|
|
27296
|
+
CheckoutErrorType["GET_ERC721_BALANCE_ERROR"] = "GET_ERC721_BALANCE_ERROR";
|
|
27185
27297
|
CheckoutErrorType["GET_NETWORK_INFO_ERROR"] = "GET_NETWORK_INFO_ERROR";
|
|
27186
27298
|
CheckoutErrorType["METAMASK_PROVIDER_ERROR"] = "METAMASK_PROVIDER_ERROR";
|
|
27187
27299
|
CheckoutErrorType["CHAIN_NOT_SUPPORTED_ERROR"] = "CHAIN_NOT_SUPPORTED_ERROR";
|
|
@@ -27193,6 +27305,7 @@ var $4b58188d47aafe8d$export$5d3b0ad129b9b98e;
|
|
|
27193
27305
|
CheckoutErrorType["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
|
|
27194
27306
|
CheckoutErrorType["INVALID_GAS_ESTIMATE_TYPE"] = "INVALID_GAS_ESTIMATE_TYPE";
|
|
27195
27307
|
CheckoutErrorType["UNSUPPORTED_TOKEN_TYPE_ERROR"] = "UNSUPPORTED_TOKEN_TYPE_ERROR";
|
|
27308
|
+
CheckoutErrorType["UNSUPPORTED_BALANCE_REQUIREMENT_ERROR"] = "UNSUPPORTED_BALANCE_REQUIREMENT_ERROR";
|
|
27196
27309
|
CheckoutErrorType["GET_ORDER_LISTING_ERROR"] = "GET_ORDER_LISTING_ERROR";
|
|
27197
27310
|
CheckoutErrorType["SWITCH_NETWORK_UNSUPPORTED"] = "SWITCH_NETWORK_UNSUPPORTED";
|
|
27198
27311
|
CheckoutErrorType["GET_ERC20_ALLOWANCE_ERROR"] = "GET_ERC20_ALLOWANCE_ERROR";
|
|
@@ -27414,39 +27527,48 @@ const $1564e43dde50bb61$export$df96cd8d56be0ab1 = async (config, web3Provider, w
|
|
|
27414
27527
|
async function $1564e43dde50bb61$export$60e0fe116a0e6ed0(web3Provider, walletAddress, contractAddress) {
|
|
27415
27528
|
return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
27416
27529
|
const contract = new (ethers.Contract)(contractAddress, JSON.stringify(($d85ad1457a3f1a83$export$db5daa1b5156ccfe)), web3Provider);
|
|
27417
|
-
|
|
27418
|
-
|
|
27419
|
-
|
|
27420
|
-
|
|
27421
|
-
|
|
27422
|
-
|
|
27423
|
-
|
|
27424
|
-
|
|
27425
|
-
|
|
27426
|
-
|
|
27427
|
-
|
|
27428
|
-
|
|
27429
|
-
|
|
27430
|
-
|
|
27431
|
-
|
|
27530
|
+
return Promise.all([
|
|
27531
|
+
contract.name(),
|
|
27532
|
+
contract.symbol(),
|
|
27533
|
+
contract.balanceOf(walletAddress),
|
|
27534
|
+
contract.decimals()
|
|
27535
|
+
]).then(([name, symbol, balance, decimals])=>{
|
|
27536
|
+
const formattedBalance = (ethers.utils).formatUnits(balance, decimals);
|
|
27537
|
+
return {
|
|
27538
|
+
balance: balance,
|
|
27539
|
+
formattedBalance: formattedBalance,
|
|
27540
|
+
token: {
|
|
27541
|
+
name: name,
|
|
27542
|
+
symbol: symbol,
|
|
27543
|
+
decimals: decimals,
|
|
27544
|
+
address: contractAddress
|
|
27545
|
+
}
|
|
27546
|
+
};
|
|
27547
|
+
});
|
|
27432
27548
|
}, {
|
|
27433
27549
|
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC20_BALANCE_ERROR
|
|
27434
27550
|
});
|
|
27435
27551
|
}
|
|
27436
|
-
const $1564e43dde50bb61$export$
|
|
27437
|
-
const tokenList = await ($efe60cea83bfc4e8$export$473cec51305fdae8)(config, {
|
|
27438
|
-
type: ($08d5ddc39acd6833$export$fd9b17d87f4121d2).ALL,
|
|
27439
|
-
chainId: chainId
|
|
27440
|
-
});
|
|
27552
|
+
const $1564e43dde50bb61$export$a3238cee431627c6 = async (config, web3Provider, walletAddress, tokens)=>{
|
|
27441
27553
|
const allBalancePromises = [];
|
|
27442
|
-
|
|
27443
|
-
|
|
27554
|
+
tokens.forEach((token)=>{
|
|
27555
|
+
// Check for NATIVE token
|
|
27556
|
+
if (!token.address || token.address === ($d85ad1457a3f1a83$export$b80040cb173ba6e9)) allBalancePromises.push($1564e43dde50bb61$export$df96cd8d56be0ab1(config, web3Provider, walletAddress));
|
|
27557
|
+
else allBalancePromises.push($1564e43dde50bb61$export$60e0fe116a0e6ed0(web3Provider, walletAddress, token.address));
|
|
27558
|
+
});
|
|
27444
27559
|
const balanceResults = await Promise.allSettled(allBalancePromises);
|
|
27445
|
-
const
|
|
27560
|
+
const balances = balanceResults.filter((result)=>result.status === "fulfilled").map((fulfilledResult)=>fulfilledResult.value);
|
|
27446
27561
|
return {
|
|
27447
|
-
balances:
|
|
27562
|
+
balances: balances
|
|
27448
27563
|
};
|
|
27449
27564
|
};
|
|
27565
|
+
const $1564e43dde50bb61$export$fee49741664a4d7e = async (config, web3Provider, walletAddress, chainId)=>{
|
|
27566
|
+
const { tokens: tokens } = await ($efe60cea83bfc4e8$export$473cec51305fdae8)(config, {
|
|
27567
|
+
type: ($08d5ddc39acd6833$export$fd9b17d87f4121d2).ALL,
|
|
27568
|
+
chainId: chainId
|
|
27569
|
+
});
|
|
27570
|
+
return await $1564e43dde50bb61$export$a3238cee431627c6(config, web3Provider, walletAddress, tokens);
|
|
27571
|
+
};
|
|
27450
27572
|
|
|
27451
27573
|
|
|
27452
27574
|
|
|
@@ -28195,6 +28317,278 @@ const $35c3fc7013888ba5$export$be546c525d418988 = async (provider, ownerAddress,
|
|
|
28195
28317
|
|
|
28196
28318
|
|
|
28197
28319
|
|
|
28320
|
+
/* eslint-disable arrow-body-style */
|
|
28321
|
+
|
|
28322
|
+
|
|
28323
|
+
|
|
28324
|
+
|
|
28325
|
+
|
|
28326
|
+
const $aa6caea9a60d18c7$export$f4d35754ad350071 = (itemRequirements)=>{
|
|
28327
|
+
const aggregatedMap = new Map();
|
|
28328
|
+
const aggregatedItemRequirements = [];
|
|
28329
|
+
itemRequirements.forEach((itemRequirement)=>{
|
|
28330
|
+
const { type: type } = itemRequirement;
|
|
28331
|
+
if (type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) {
|
|
28332
|
+
aggregatedItemRequirements.push(itemRequirement);
|
|
28333
|
+
return;
|
|
28334
|
+
}
|
|
28335
|
+
const { amount: amount } = itemRequirement;
|
|
28336
|
+
const aggregateItem = aggregatedMap.get(type);
|
|
28337
|
+
if (aggregateItem && aggregateItem.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) aggregateItem.amount = (ethers.BigNumber).from(aggregateItem.amount).add(amount);
|
|
28338
|
+
else aggregatedMap.set(type, {
|
|
28339
|
+
...itemRequirement
|
|
28340
|
+
});
|
|
28341
|
+
});
|
|
28342
|
+
return aggregatedItemRequirements.concat(Array.from(aggregatedMap.values()));
|
|
28343
|
+
};
|
|
28344
|
+
const $aa6caea9a60d18c7$export$b8de545554d50911 = (itemRequirements)=>{
|
|
28345
|
+
const aggregatedMap = new Map();
|
|
28346
|
+
const aggregatedItemRequirements = [];
|
|
28347
|
+
itemRequirements.forEach((itemRequirement)=>{
|
|
28348
|
+
const { type: type } = itemRequirement;
|
|
28349
|
+
if (type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
|
|
28350
|
+
aggregatedItemRequirements.push(itemRequirement);
|
|
28351
|
+
return;
|
|
28352
|
+
}
|
|
28353
|
+
const { contractAddress: contractAddress, amount: amount } = itemRequirement;
|
|
28354
|
+
const key = `${contractAddress}`;
|
|
28355
|
+
const aggregateItem = aggregatedMap.get(key);
|
|
28356
|
+
if (aggregateItem && aggregateItem.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) aggregateItem.amount = (ethers.BigNumber).from(aggregateItem.amount).add(amount);
|
|
28357
|
+
else aggregatedMap.set(key, {
|
|
28358
|
+
...itemRequirement
|
|
28359
|
+
});
|
|
28360
|
+
});
|
|
28361
|
+
return aggregatedItemRequirements.concat(Array.from(aggregatedMap.values()));
|
|
28362
|
+
};
|
|
28363
|
+
const $aa6caea9a60d18c7$export$74fbc29ef48b4f31 = (itemRequirements)=>{
|
|
28364
|
+
const aggregatedMap = new Map();
|
|
28365
|
+
const aggregatedItemRequirements = [];
|
|
28366
|
+
itemRequirements.forEach((itemRequirement)=>{
|
|
28367
|
+
const { type: type } = itemRequirement;
|
|
28368
|
+
if (type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721) {
|
|
28369
|
+
aggregatedItemRequirements.push(itemRequirement);
|
|
28370
|
+
return;
|
|
28371
|
+
}
|
|
28372
|
+
const { contractAddress: contractAddress, id: id } = itemRequirement;
|
|
28373
|
+
const key = `${contractAddress}${id}`;
|
|
28374
|
+
const aggregateItem = aggregatedMap.get(key);
|
|
28375
|
+
if (!aggregateItem) aggregatedMap.set(key, {
|
|
28376
|
+
...itemRequirement
|
|
28377
|
+
});
|
|
28378
|
+
});
|
|
28379
|
+
return aggregatedItemRequirements.concat(Array.from(aggregatedMap.values()));
|
|
28380
|
+
};
|
|
28381
|
+
const $aa6caea9a60d18c7$export$f96d1c819a615a64 = (itemRequirements)=>$aa6caea9a60d18c7$export$74fbc29ef48b4f31($aa6caea9a60d18c7$export$b8de545554d50911($aa6caea9a60d18c7$export$f4d35754ad350071(itemRequirements)));
|
|
28382
|
+
|
|
28383
|
+
|
|
28384
|
+
/* eslint-disable arrow-body-style */
|
|
28385
|
+
|
|
28386
|
+
const $73d2282a108cc7e2$export$ed7929b58bab85da = (itemRequirements)=>itemRequirements.map((itemRequirement)=>{
|
|
28387
|
+
if (itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return {
|
|
28388
|
+
name: "IMX",
|
|
28389
|
+
symbol: "IMX",
|
|
28390
|
+
address: ($d85ad1457a3f1a83$export$b80040cb173ba6e9)
|
|
28391
|
+
};
|
|
28392
|
+
return {
|
|
28393
|
+
name: itemRequirement.type,
|
|
28394
|
+
address: itemRequirement.contractAddress
|
|
28395
|
+
};
|
|
28396
|
+
});
|
|
28397
|
+
const $73d2282a108cc7e2$export$9b757e40b19984c3 = (itemRequirement, balances)=>{
|
|
28398
|
+
const requiredBalance = (ethers.BigNumber).from(1);
|
|
28399
|
+
// Find the requirements related balance
|
|
28400
|
+
const itemBalanceResult = balances.find((balance)=>{
|
|
28401
|
+
const balanceERC721Result = balance;
|
|
28402
|
+
return balanceERC721Result.contractAddress === itemRequirement.contractAddress && balanceERC721Result.id === itemRequirement.id;
|
|
28403
|
+
});
|
|
28404
|
+
// Calculate the balance delta
|
|
28405
|
+
const sufficient = requiredBalance.isNegative() || requiredBalance.isZero() || (itemBalanceResult?.balance.gte(requiredBalance) ?? false);
|
|
28406
|
+
const delta = requiredBalance.sub(itemBalanceResult?.balance ?? (ethers.BigNumber).from(0));
|
|
28407
|
+
let erc721BalanceResult = itemBalanceResult;
|
|
28408
|
+
if (!erc721BalanceResult) erc721BalanceResult = {
|
|
28409
|
+
balance: (ethers.BigNumber).from(0),
|
|
28410
|
+
formattedBalance: "0",
|
|
28411
|
+
contractAddress: itemRequirement.contractAddress,
|
|
28412
|
+
id: itemRequirement.id
|
|
28413
|
+
};
|
|
28414
|
+
return {
|
|
28415
|
+
sufficient: sufficient,
|
|
28416
|
+
type: itemRequirement.type,
|
|
28417
|
+
delta: {
|
|
28418
|
+
balance: delta,
|
|
28419
|
+
formattedBalance: delta.toString()
|
|
28420
|
+
},
|
|
28421
|
+
current: erc721BalanceResult,
|
|
28422
|
+
required: {
|
|
28423
|
+
...erc721BalanceResult,
|
|
28424
|
+
balance: (ethers.BigNumber).from(1),
|
|
28425
|
+
formattedBalance: "1"
|
|
28426
|
+
}
|
|
28427
|
+
};
|
|
28428
|
+
};
|
|
28429
|
+
const $73d2282a108cc7e2$export$6ab9757fda54db7e = (itemRequirement, balances)=>{
|
|
28430
|
+
let itemBalanceResult;
|
|
28431
|
+
// Get the requirements related balance
|
|
28432
|
+
if (itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) itemBalanceResult = balances.find((balance)=>{
|
|
28433
|
+
return balance.token?.address === itemRequirement.contractAddress;
|
|
28434
|
+
});
|
|
28435
|
+
else if (itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) itemBalanceResult = balances.find((balance)=>{
|
|
28436
|
+
return !("address" in balance.token) || balance.token?.address === ($d85ad1457a3f1a83$export$b80040cb173ba6e9);
|
|
28437
|
+
});
|
|
28438
|
+
// Calculate the balance delta
|
|
28439
|
+
const requiredBalance = itemRequirement.amount;
|
|
28440
|
+
const sufficient = requiredBalance.isNegative() || requiredBalance.isZero() || (itemBalanceResult?.balance.gte(requiredBalance) ?? false);
|
|
28441
|
+
const delta = requiredBalance.sub(itemBalanceResult?.balance ?? (ethers.BigNumber).from(0));
|
|
28442
|
+
let decimals = ($d85ad1457a3f1a83$export$903389470ba9433c);
|
|
28443
|
+
if (itemBalanceResult) decimals = itemBalanceResult.token?.decimals ?? ($d85ad1457a3f1a83$export$903389470ba9433c);
|
|
28444
|
+
let tokenBalanceResult = itemBalanceResult;
|
|
28445
|
+
if (itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) {
|
|
28446
|
+
// No token balance so mark as zero native
|
|
28447
|
+
if (!tokenBalanceResult) tokenBalanceResult = {
|
|
28448
|
+
balance: (ethers.BigNumber).from(0),
|
|
28449
|
+
formattedBalance: "0",
|
|
28450
|
+
token: {
|
|
28451
|
+
name: "IMX",
|
|
28452
|
+
symbol: "IMX",
|
|
28453
|
+
decimals: ($d85ad1457a3f1a83$export$903389470ba9433c),
|
|
28454
|
+
address: ($d85ad1457a3f1a83$export$b80040cb173ba6e9)
|
|
28455
|
+
}
|
|
28456
|
+
};
|
|
28457
|
+
return {
|
|
28458
|
+
sufficient: sufficient,
|
|
28459
|
+
type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE,
|
|
28460
|
+
delta: {
|
|
28461
|
+
balance: delta,
|
|
28462
|
+
formattedBalance: (ethers.utils).formatUnits(delta, decimals)
|
|
28463
|
+
},
|
|
28464
|
+
current: tokenBalanceResult,
|
|
28465
|
+
required: {
|
|
28466
|
+
...tokenBalanceResult,
|
|
28467
|
+
balance: (ethers.BigNumber).from(itemRequirement.amount),
|
|
28468
|
+
formattedBalance: (ethers.utils).formatUnits(itemRequirement.amount, decimals)
|
|
28469
|
+
}
|
|
28470
|
+
};
|
|
28471
|
+
}
|
|
28472
|
+
// No token balance so mark as zero
|
|
28473
|
+
if (!tokenBalanceResult) tokenBalanceResult = {
|
|
28474
|
+
balance: (ethers.BigNumber).from(0),
|
|
28475
|
+
formattedBalance: "0",
|
|
28476
|
+
token: {
|
|
28477
|
+
address: itemRequirement.contractAddress
|
|
28478
|
+
}
|
|
28479
|
+
};
|
|
28480
|
+
return {
|
|
28481
|
+
sufficient: sufficient,
|
|
28482
|
+
type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20,
|
|
28483
|
+
delta: {
|
|
28484
|
+
balance: delta,
|
|
28485
|
+
formattedBalance: (ethers.utils).formatUnits(delta, decimals)
|
|
28486
|
+
},
|
|
28487
|
+
current: tokenBalanceResult,
|
|
28488
|
+
required: {
|
|
28489
|
+
...tokenBalanceResult,
|
|
28490
|
+
balance: (ethers.BigNumber).from(itemRequirement.amount),
|
|
28491
|
+
formattedBalance: (ethers.utils).formatUnits(itemRequirement.amount, decimals)
|
|
28492
|
+
}
|
|
28493
|
+
};
|
|
28494
|
+
};
|
|
28495
|
+
|
|
28496
|
+
|
|
28497
|
+
/**
|
|
28498
|
+
* Gets the balances for all NATIVE and ERC20 balance requirements.
|
|
28499
|
+
*/ const $beb896e098e41faf$var$getTokenBalances = async (config, provider, ownerAddress, itemRequirements)=>{
|
|
28500
|
+
let tokenBalances = [];
|
|
28501
|
+
try {
|
|
28502
|
+
const tokenList = (0, $73d2282a108cc7e2$export$ed7929b58bab85da)(itemRequirements);
|
|
28503
|
+
const { balances: balances } = await (0, $1564e43dde50bb61$export$a3238cee431627c6)(config, provider, ownerAddress, tokenList);
|
|
28504
|
+
tokenBalances = [
|
|
28505
|
+
...balances.map((balance)=>balance)
|
|
28506
|
+
];
|
|
28507
|
+
} catch (error) {
|
|
28508
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Failed to get balances", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_BALANCE_ERROR);
|
|
28509
|
+
}
|
|
28510
|
+
return tokenBalances;
|
|
28511
|
+
};
|
|
28512
|
+
/**
|
|
28513
|
+
* Gets the balances for all ERC721 balance requirements.
|
|
28514
|
+
*/ const $beb896e098e41faf$var$getERC721Balances = async (provider, ownerAddress, itemRequirements)=>{
|
|
28515
|
+
const erc721Balances = [];
|
|
28516
|
+
// Setup maps to be able to link data back to the associated promises
|
|
28517
|
+
const erc721s = new Map();
|
|
28518
|
+
const erc721OwnershipPromises = new Map();
|
|
28519
|
+
itemRequirements.filter((itemRequirement)=>itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721).forEach((itemRequirement)=>{
|
|
28520
|
+
const erc721Requirement = itemRequirement;
|
|
28521
|
+
const contract = new (ethers.Contract)(erc721Requirement.contractAddress, JSON.stringify(($d85ad1457a3f1a83$export$8b8be7a2a654f23e)), provider);
|
|
28522
|
+
erc721s.set(erc721Requirement.contractAddress, itemRequirement);
|
|
28523
|
+
erc721OwnershipPromises.set(erc721Requirement.contractAddress, contract.ownerOf(erc721Requirement.id));
|
|
28524
|
+
});
|
|
28525
|
+
try {
|
|
28526
|
+
// Convert ERC721 ownership into a balance result
|
|
28527
|
+
const erc721Owners = await Promise.all(erc721OwnershipPromises.values());
|
|
28528
|
+
const erc721OwnersPromiseIds = Array.from(erc721OwnershipPromises.keys());
|
|
28529
|
+
erc721Owners.forEach((erc721OwnerAddress, index)=>{
|
|
28530
|
+
const itemRequirement = erc721s.get(erc721OwnersPromiseIds[index]);
|
|
28531
|
+
let itemCount = 0;
|
|
28532
|
+
if (itemRequirement && ownerAddress === erc721OwnerAddress) itemCount = 1;
|
|
28533
|
+
erc721Balances.push({
|
|
28534
|
+
balance: (0, ethers.BigNumber).from(itemCount),
|
|
28535
|
+
formattedBalance: itemCount.toString(),
|
|
28536
|
+
contractAddress: itemRequirement.contractAddress,
|
|
28537
|
+
id: itemRequirement.id
|
|
28538
|
+
});
|
|
28539
|
+
});
|
|
28540
|
+
} catch (error) {
|
|
28541
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Failed to get ERC721 balances", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC721_BALANCE_ERROR);
|
|
28542
|
+
}
|
|
28543
|
+
return erc721Balances;
|
|
28544
|
+
};
|
|
28545
|
+
const $beb896e098e41faf$export$ddfc885f43c3cb6e = async (config, provider, ownerAddress, itemRequirements)=>{
|
|
28546
|
+
const aggregatedItems = ($aa6caea9a60d18c7$export$f96d1c819a615a64)(itemRequirements);
|
|
28547
|
+
if (aggregatedItems.filter((itemRequirement)=>{
|
|
28548
|
+
return itemRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721 && itemRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20 && itemRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE;
|
|
28549
|
+
}).length > 0) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Unsupported item requirement balance check", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).UNSUPPORTED_BALANCE_REQUIREMENT_ERROR);
|
|
28550
|
+
// Get all ERC20 and NATIVE balances
|
|
28551
|
+
const currentBalances = [];
|
|
28552
|
+
const tokenItemRequirements = aggregatedItems.filter((itemRequirement)=>itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20 || itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE);
|
|
28553
|
+
if (tokenItemRequirements.length > 0) currentBalances.push($beb896e098e41faf$var$getTokenBalances(config, provider, ownerAddress, aggregatedItems));
|
|
28554
|
+
// Get all ERC721 balances
|
|
28555
|
+
const erc721ItemRequirements = aggregatedItems.filter((itemRequirement)=>itemRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721);
|
|
28556
|
+
if (erc721ItemRequirements.length > 0) currentBalances.push($beb896e098e41faf$var$getERC721Balances(provider, ownerAddress, aggregatedItems));
|
|
28557
|
+
// Wait for all balances and calculate the requirements
|
|
28558
|
+
const balanceRequirements = await Promise.all(currentBalances).then((balances)=>{
|
|
28559
|
+
const requirements = [];
|
|
28560
|
+
if (balances.length > 1 || tokenItemRequirements.length > 0) {
|
|
28561
|
+
const tokenBalances = balances[0];
|
|
28562
|
+
tokenItemRequirements.forEach((tokenItemRequirement)=>{
|
|
28563
|
+
requirements.push(($73d2282a108cc7e2$export$6ab9757fda54db7e)(tokenItemRequirement, tokenBalances));
|
|
28564
|
+
});
|
|
28565
|
+
if (erc721ItemRequirements.length > 0) {
|
|
28566
|
+
const erc721Balances = balances[1];
|
|
28567
|
+
erc721ItemRequirements.forEach((erc721ItemRequirement)=>{
|
|
28568
|
+
requirements.push(($73d2282a108cc7e2$export$9b757e40b19984c3)(erc721ItemRequirement, erc721Balances));
|
|
28569
|
+
});
|
|
28570
|
+
}
|
|
28571
|
+
} else if (erc721ItemRequirements.length > 0) {
|
|
28572
|
+
// Only erc721
|
|
28573
|
+
const erc721Balances = balances[0];
|
|
28574
|
+
erc721ItemRequirements.forEach((erc721ItemRequirement)=>{
|
|
28575
|
+
requirements.push(($73d2282a108cc7e2$export$9b757e40b19984c3)(erc721ItemRequirement, erc721Balances));
|
|
28576
|
+
});
|
|
28577
|
+
}
|
|
28578
|
+
return requirements;
|
|
28579
|
+
});
|
|
28580
|
+
const sufficient = balanceRequirements.reduce((acc, balanceRequirement)=>{
|
|
28581
|
+
return acc && balanceRequirement.sufficient;
|
|
28582
|
+
}, true);
|
|
28583
|
+
return {
|
|
28584
|
+
sufficient: sufficient,
|
|
28585
|
+
itemRequirements: balanceRequirements
|
|
28586
|
+
};
|
|
28587
|
+
};
|
|
28588
|
+
|
|
28589
|
+
|
|
28590
|
+
|
|
28591
|
+
|
|
28198
28592
|
|
|
28199
28593
|
|
|
28200
28594
|
|
|
@@ -28251,7 +28645,7 @@ const $7d1bfafb81e64d74$export$3a4140bd9e983e4e = async (provider, insufficientI
|
|
|
28251
28645
|
};
|
|
28252
28646
|
|
|
28253
28647
|
|
|
28254
|
-
const $0e7419077c373b24$export$9e073f9ada8c81e6 = async (provider, itemRequirements, transactionOrGasAmount)=>{
|
|
28648
|
+
const $0e7419077c373b24$export$9e073f9ada8c81e6 = async (config, provider, itemRequirements, transactionOrGasAmount)=>{
|
|
28255
28649
|
// eslint-disable-next-line no-console
|
|
28256
28650
|
console.log(provider, itemRequirements, transactionOrGasAmount);
|
|
28257
28651
|
const ownerAddress = await provider.getSigner().getAddress();
|
|
@@ -28270,6 +28664,9 @@ const $0e7419077c373b24$export$9e073f9ada8c81e6 = async (provider, itemRequireme
|
|
|
28270
28664
|
}
|
|
28271
28665
|
// eslint-disable-next-line no-console
|
|
28272
28666
|
console.log("Aggregated Items", aggregatedItems);
|
|
28667
|
+
const balanceRequirements = await ($beb896e098e41faf$export$ddfc885f43c3cb6e)(config, provider, ownerAddress, aggregatedItems);
|
|
28668
|
+
// eslint-disable-next-line no-console
|
|
28669
|
+
console.log("Balance Requirements", balanceRequirements);
|
|
28273
28670
|
return {
|
|
28274
28671
|
sufficient: true,
|
|
28275
28672
|
transactionRequirements: [
|
|
@@ -28367,13 +28764,13 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
|
|
|
28367
28764
|
let type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE;
|
|
28368
28765
|
let contractAddress = "";
|
|
28369
28766
|
const buyArray = order.result.buy;
|
|
28370
|
-
if (buyArray.length > 0) switch(buyArray[0].
|
|
28767
|
+
if (buyArray.length > 0) switch(buyArray[0].type){
|
|
28371
28768
|
case "NATIVE":
|
|
28372
28769
|
type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE;
|
|
28373
28770
|
break;
|
|
28374
28771
|
case "ERC20":
|
|
28375
28772
|
type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20;
|
|
28376
|
-
contractAddress = buyArray[0].
|
|
28773
|
+
contractAddress = buyArray[0].contractAddress;
|
|
28377
28774
|
break;
|
|
28378
28775
|
default:
|
|
28379
28776
|
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Purchasing token type is unsupported", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).UNSUPPORTED_TOKEN_TYPE_ERROR, {
|
|
@@ -28381,7 +28778,7 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
|
|
|
28381
28778
|
});
|
|
28382
28779
|
}
|
|
28383
28780
|
buyArray.forEach((item)=>{
|
|
28384
|
-
if (item.
|
|
28781
|
+
if (item.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721) amount = amount.add((ethers.BigNumber).from(item.amount));
|
|
28385
28782
|
});
|
|
28386
28783
|
const feeArray = order.result.fees;
|
|
28387
28784
|
feeArray.forEach((item)=>{
|
|
@@ -28390,7 +28787,7 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
|
|
|
28390
28787
|
const itemRequirements = [
|
|
28391
28788
|
$64863c39386de592$export$4249179755829904(type, contractAddress, amount, spenderAddress)
|
|
28392
28789
|
];
|
|
28393
|
-
await ($0e7419077c373b24$export$9e073f9ada8c81e6)(provider, itemRequirements, $64863c39386de592$export$8f2ff92ab8657f0b(gasLimit, unsignedTransaction));
|
|
28790
|
+
await ($0e7419077c373b24$export$9e073f9ada8c81e6)(config, provider, itemRequirements, $64863c39386de592$export$8f2ff92ab8657f0b(gasLimit, unsignedTransaction));
|
|
28394
28791
|
return {
|
|
28395
28792
|
itemRequirements: itemRequirements,
|
|
28396
28793
|
gasToken: {
|
|
@@ -28559,7 +28956,7 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
|
|
|
28559
28956
|
// eslint-disable-next-line no-console
|
|
28560
28957
|
console.warn("This endpoint is currently under construction.");
|
|
28561
28958
|
const web3Provider = await $bb88265fe45a0393$export$9e1fd9cc88c637a0(this.config, params.provider);
|
|
28562
|
-
await $0e7419077c373b24$export$9e073f9ada8c81e6(web3Provider, params.itemRequirements, params.transactionOrGasAmount);
|
|
28959
|
+
await $0e7419077c373b24$export$9e073f9ada8c81e6(this.config, web3Provider, params.itemRequirements, params.transactionOrGasAmount);
|
|
28563
28960
|
}
|
|
28564
28961
|
/**
|
|
28565
28962
|
* Checks if the given object is a Web3 provider.
|
|
@@ -28598,7 +28995,7 @@ var checkout_sdk = /*#__PURE__*/Object.freeze({
|
|
|
28598
28995
|
function $parcel$export(e, n, v, s) {
|
|
28599
28996
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
28600
28997
|
}
|
|
28601
|
-
const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.14.0-alpha";
|
|
28998
|
+
const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.14.0-alpha.2";
|
|
28602
28999
|
const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
|
|
28603
29000
|
const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
|
|
28604
29001
|
|