@imtbl/sdk 0.13.2-alpha → 0.14.0-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.
@@ -1,7 +1,7 @@
1
1
  import { ethers, ContractFactory, utils, Contract as Contract$1, BigNumber as BigNumber$1, providers, constants as constants$1 } from 'ethers';
2
2
  import { Web3Provider, JsonRpcProvider } from '@ethersproject/providers';
3
3
  import $7v2Z6$metamaskdetectprovider from '@metamask/detect-provider';
4
- import { Token, TradeType, Percent, CurrencyAmount } from '@uniswap/sdk-core';
4
+ import { TradeType, Token, Percent, CurrencyAmount } from '@uniswap/sdk-core';
5
5
  import assert from 'assert';
6
6
  import { BigNumber as BigNumber$2 } from '@ethersproject/bignumber';
7
7
  import { FeeAmount, Route, SwapQuoter, Pool, Trade, toHex as toHex$1, encodeRouteToPath } from '@uniswap/v3-sdk';
@@ -12897,20 +12897,12 @@ function applySlippage(tradeType, amount, slippage) {
12897
12897
  return ethers.BigNumber.from(amountWithSlippage.toString());
12898
12898
  }
12899
12899
  function prepareUserQuote(otherToken, tradeInfo, slippage, fees) {
12900
- const resultToken = otherToken.wrapped;
12901
- const tokenInfo = {
12902
- chainId: resultToken.chainId,
12903
- address: resultToken.address,
12904
- decimals: resultToken.decimals,
12905
- symbol: resultToken.symbol,
12906
- name: resultToken.name,
12907
- };
12908
12900
  const quote = getQuoteAmountFromTradeType(tradeInfo);
12909
12901
  const amountWithSlippage = applySlippage(tradeInfo.tradeType, quote.value, slippage);
12910
12902
  return {
12911
12903
  amount: quote,
12912
12904
  amountWithMaxSlippage: {
12913
- token: tokenInfo,
12905
+ token: otherToken,
12914
12906
  value: amountWithSlippage,
12915
12907
  },
12916
12908
  slippage,
@@ -14931,13 +14923,6 @@ function isValidNonZeroAddress(address) {
14931
14923
  }
14932
14924
  }
14933
14925
  const tokenInfoToUniswapToken = (tokenInfo) => new Token(tokenInfo.chainId, tokenInfo.address, tokenInfo.decimals, tokenInfo.symbol, tokenInfo.name);
14934
- const uniswapTokenToTokenInfo = (token) => ({
14935
- chainId: token.chainId,
14936
- address: token.address,
14937
- decimals: token.decimals,
14938
- symbol: token.symbol,
14939
- name: token.name,
14940
- });
14941
14926
  const toCurrencyAmount = (amount) => {
14942
14927
  const token = tokenInfoToUniswapToken(amount.token);
14943
14928
  return CurrencyAmount.fromRawAmount(token, amount.value.toString());
@@ -14998,6 +14983,7 @@ async function getQuotesForRoutes(multicallContract, quoterContractAddress, rout
14998
14983
  amountIn: tradeType === TradeType.EXACT_INPUT ? amountSpecified : newAmount(quoteAmount, routes[i].input),
14999
14984
  amountOut: tradeType === TradeType.EXACT_INPUT ? newAmount(quoteAmount, routes[i].output) : amountSpecified,
15000
14985
  gasEstimate: ethers.BigNumber.from(decodedQuoteResult[gasEstimateIndex]),
14986
+ tradeType,
15001
14987
  });
15002
14988
  }
15003
14989
  }
@@ -15160,14 +15146,7 @@ class Router {
15160
15146
  throw new NoRoutesAvailableError();
15161
15147
  }
15162
15148
  // Get the best quote from all of the given routes
15163
- const { amountIn, amountOut, gasEstimate, route, } = await this.getBestQuoteFromRoutes(multicallContract, routes, amountSpecified, tradeType);
15164
- return {
15165
- route,
15166
- amountIn,
15167
- amountOut,
15168
- tradeType,
15169
- gasEstimate,
15170
- };
15149
+ return await this.getBestQuoteFromRoutes(multicallContract, routes, amountSpecified, tradeType);
15171
15150
  }
15172
15151
  async getBestQuoteFromRoutes(multicallContract, routes, amountSpecified, tradeType) {
15173
15152
  const quotes = await getQuotesForRoutes(multicallContract, this.routingContracts.quoterAddress, routes, amountSpecified, tradeType);
@@ -15176,23 +15155,11 @@ class Router {
15176
15155
  }
15177
15156
  // We want to maximise the amountOut for the EXACT_INPUT type
15178
15157
  if (tradeType === TradeType.EXACT_INPUT) {
15179
- const bestQuote = this.bestQuoteForAmountIn(quotes);
15180
- return {
15181
- route: bestQuote.route,
15182
- amountIn: bestQuote.amountIn,
15183
- amountOut: bestQuote.amountOut,
15184
- gasEstimate: bestQuote.gasEstimate,
15185
- };
15158
+ return this.bestQuoteForAmountIn(quotes);
15186
15159
  }
15187
15160
  // We want to minimise the amountIn for the EXACT_OUTPUT type
15188
15161
  if (tradeType === TradeType.EXACT_OUTPUT) {
15189
- const bestQuote = this.bestQuoteForAmountOut(quotes);
15190
- return {
15191
- route: bestQuote.route,
15192
- amountIn: bestQuote.amountIn,
15193
- amountOut: bestQuote.amountOut,
15194
- gasEstimate: bestQuote.gasEstimate,
15195
- };
15162
+ return this.bestQuoteForAmountOut(quotes);
15196
15163
  }
15197
15164
  throw new Error('Invalid trade type');
15198
15165
  }
@@ -15231,9 +15198,9 @@ maxHops, // the maximum number of pools that can be traversed
15231
15198
  currentRoute = [], // list of pools already traversed
15232
15199
  routes = [], // list of all routes found so far
15233
15200
  startTokenIn = tokenIn) => {
15234
- const currencyIn = new Token(tokenIn.chainId, tokenIn.address, tokenIn.decimals);
15235
- const currencyOut = new Token(tokenOut.chainId, tokenOut.address, tokenOut.decimals);
15236
- const startCurrencyIn = new Token(startTokenIn.chainId, startTokenIn.address, startTokenIn.decimals);
15201
+ const currencyIn = tokenInfoToUniswapToken(tokenIn);
15202
+ const currencyOut = tokenInfoToUniswapToken(tokenOut);
15203
+ const startCurrencyIn = tokenInfoToUniswapToken(startTokenIn);
15237
15204
  for (const pool of pools) {
15238
15205
  // if the pool doesn't have the tokenIn or if it has already been traversed,
15239
15206
  // skip to the next pool
@@ -15263,7 +15230,7 @@ class Fees {
15263
15230
  amount;
15264
15231
  constructor(secondaryFees, token) {
15265
15232
  this.secondaryFees = secondaryFees;
15266
- this.amount = { token, value: BigNumber$1.from(0) };
15233
+ this.amount = newAmount(BigNumber$1.from(0), token);
15267
15234
  }
15268
15235
  addAmount(amount) {
15269
15236
  this.amount = addAmount(this.amount, amount);
@@ -15576,20 +15543,21 @@ class Exchange {
15576
15543
  getERC20Decimals(tokenOutAddress, this.provider),
15577
15544
  this.getSecondaryFees(),
15578
15545
  ]);
15579
- const tokenIn = new Token(this.chainId, tokenInAddress, tokenInDecimals);
15580
- const tokenOut = new Token(this.chainId, tokenOutAddress, tokenOutDecimals);
15546
+ const tokenIn = {
15547
+ address: tokenInAddress,
15548
+ chainId: this.chainId,
15549
+ decimals: tokenInDecimals,
15550
+ };
15551
+ const tokenOut = {
15552
+ address: tokenOutAddress,
15553
+ chainId: this.chainId,
15554
+ decimals: tokenOutDecimals,
15555
+ };
15581
15556
  // determine which amount was specified for the swap from the TradeType
15582
- let amountSpecified;
15583
- let otherToken;
15584
- if (tradeType === TradeType.EXACT_INPUT) {
15585
- amountSpecified = newAmount(amount, tokenIn);
15586
- otherToken = tokenOut;
15587
- }
15588
- else {
15589
- amountSpecified = newAmount(amount, tokenOut);
15590
- otherToken = tokenIn;
15591
- }
15592
- const fees = new Fees(secondaryFees, uniswapTokenToTokenInfo(tokenIn));
15557
+ const [tokenSpecified, otherToken] = tradeType === TradeType.EXACT_INPUT
15558
+ ? [tokenIn, tokenOut] : [tokenOut, tokenIn];
15559
+ const amountSpecified = newAmount(amount, tokenSpecified);
15560
+ const fees = new Fees(secondaryFees, tokenIn);
15593
15561
  const ourQuoteReqAmount = getOurQuoteReqAmount(amountSpecified, fees, tradeType);
15594
15562
  // get quote and gas details
15595
15563
  const [ourQuote, gasPrice] = await Promise.all([
@@ -16557,7 +16525,7 @@ class ImmutableApiClient {
16557
16525
  ],
16558
16526
  fees: makerFee ? [{
16559
16527
  amount: makerFee.amount,
16560
- fee_type: makerFee.type,
16528
+ fee_type: FeeType.MAKER_MARKETPLACE,
16561
16529
  recipient: makerFee.recipient,
16562
16530
  }] : [],
16563
16531
  end_time: new Date(parseInt(`${orderComponents.endTime.toString()}000`, 10)).toISOString(),
@@ -16626,6 +16594,67 @@ function getOrderbookConfig(environment) {
16626
16594
  }
16627
16595
  }
16628
16596
 
16597
+ function mapFromOpenApiOrder(order) {
16598
+ const buyItems = order.buy.map((item) => {
16599
+ if (item.item_type === 'ERC20') {
16600
+ return {
16601
+ type: 'ERC20',
16602
+ contractAddress: item.contract_address,
16603
+ amount: item.start_amount,
16604
+ };
16605
+ }
16606
+ if (item.item_type === 'NATIVE') {
16607
+ return {
16608
+ type: 'NATIVE',
16609
+ amount: item.start_amount,
16610
+ };
16611
+ }
16612
+ throw new Error('Buy items must be either ERC20 or NATIVE');
16613
+ });
16614
+ const sellItems = order.sell.map((item) => {
16615
+ if (item.item_type === 'ERC721') {
16616
+ return {
16617
+ type: 'ERC721',
16618
+ contractAddress: item.contract_address,
16619
+ tokenId: item.token_id,
16620
+ };
16621
+ }
16622
+ throw new Error('Sell items must ERC721');
16623
+ });
16624
+ return {
16625
+ id: order.id,
16626
+ accountAddress: order.account_address,
16627
+ buy: buyItems,
16628
+ sell: sellItems,
16629
+ fees: order.fees.map((fee) => ({
16630
+ amount: fee.amount,
16631
+ recipient: fee.recipient,
16632
+ type: fee.fee_type,
16633
+ })),
16634
+ chain: order.chain,
16635
+ createTime: order.create_time,
16636
+ endTime: order.end_time,
16637
+ protocolData: {
16638
+ counter: order.protocol_data.counter,
16639
+ orderType: order.protocol_data.order_type,
16640
+ seaportAddress: order.protocol_data.seaport_address,
16641
+ seaportVersion: order.protocol_data.seaport_version,
16642
+ zoneAddress: order.protocol_data.zone_address,
16643
+ },
16644
+ salt: order.salt,
16645
+ signature: order.signature,
16646
+ startTime: order.start_time,
16647
+ status: order.status,
16648
+ updateTime: order.update_time,
16649
+ };
16650
+ }
16651
+ function mapFromOpenApiPage(page) {
16652
+ return {
16653
+ nextCursor: page.next_cursor,
16654
+ previousCursor: page.previous_cursor,
16655
+ };
16656
+ }
16657
+
16629
16658
  class SeaportLibFactory {
16630
16659
  defaultSeaportContractAddress;
16631
16660
  provider;
@@ -16685,8 +16714,11 @@ class Orderbook {
16685
16714
  * @param {string} listingId - The listingId to find.
16686
16715
  * @return {ListingResult} The returned order result.
16687
16716
  */
16688
- getListing(listingId) {
16689
- return this.apiClient.getListing(listingId);
16717
+ async getListing(listingId) {
16718
+ const apiListing = await this.apiClient.getListing(listingId);
16719
+ return {
16720
+ result: mapFromOpenApiOrder(apiListing.result),
16721
+ };
16690
16722
  }
16691
16723
  /**
16692
16724
  * List orders. This method is used to get a list of orders filtered by conditions specified
@@ -16694,8 +16726,12 @@ class Orderbook {
16694
16726
  * @param {ListListingsParams} listOrderParams - Filtering, ordering and page parameters.
16695
16727
  * @return {ListListingsResult} The paged orders.
16696
16728
  */
16697
- listListings(listOrderParams) {
16698
- return this.apiClient.listListings(listOrderParams);
16729
+ async listListings(listOrderParams) {
16730
+ const apiListings = await this.apiClient.listListings(listOrderParams);
16731
+ return {
16732
+ page: mapFromOpenApiPage(apiListings.page),
16733
+ result: apiListings.result.map(mapFromOpenApiOrder),
16734
+ };
16699
16735
  }
16700
16736
  /**
16701
16737
  * Get required transactions and messages for signing prior to creating a listing
@@ -16717,8 +16753,20 @@ class Orderbook {
16717
16753
  * @param {CreateListingParams} createListingParams - create an order with the given params.
16718
16754
  * @return {ListingResult} The result of the order created in the Immutable services.
16719
16755
  */
16720
- createListing(createListingParams) {
16721
- return this.apiClient.createListing(createListingParams);
16756
+ async createListing(createListingParams) {
16757
+ const makerFee = createListingParams.makerFee
16758
+ ? {
16759
+ ...createListingParams.makerFee,
16760
+ type: FeeType.MAKER_MARKETPLACE,
16761
+ }
16762
+ : undefined;
16763
+ const apiListingResponse = await this.apiClient.createListing({
16764
+ ...createListingParams,
16765
+ makerFee,
16766
+ });
16767
+ return {
16768
+ result: mapFromOpenApiOrder(apiListingResponse.result),
16769
+ };
16722
16770
  }
16723
16771
  /**
16724
16772
  * Get unsigned transactions that can be submitted to fulfil an open order. If the approval
@@ -16735,7 +16783,7 @@ class Orderbook {
16735
16783
  fee: takerFee
16736
16784
  ? {
16737
16785
  amount: takerFee.amount,
16738
- fee_type: takerFee.type,
16786
+ fee_type: FeeType.TAKER_MARKETPLACE,
16739
16787
  recipient: takerFee.recipient,
16740
16788
  }
16741
16789
  : undefined,
@@ -18388,13 +18436,13 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
18388
18436
  let type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE;
18389
18437
  let contractAddress = "";
18390
18438
  const buyArray = order.result.buy;
18391
- if (buyArray.length > 0) switch(buyArray[0].item_type){
18439
+ if (buyArray.length > 0) switch(buyArray[0].type){
18392
18440
  case "NATIVE":
18393
18441
  type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE;
18394
18442
  break;
18395
18443
  case "ERC20":
18396
18444
  type = ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20;
18397
- contractAddress = buyArray[0].contract_address;
18445
+ contractAddress = buyArray[0].contractAddress;
18398
18446
  break;
18399
18447
  default:
18400
18448
  throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Purchasing token type is unsupported", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).UNSUPPORTED_TOKEN_TYPE_ERROR, {
@@ -18402,7 +18450,7 @@ const $64863c39386de592$export$7f8e2b98eca5a7f0 = async (config, provider, order
18402
18450
  });
18403
18451
  }
18404
18452
  buyArray.forEach((item)=>{
18405
- if (item.item_type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721) amount = amount.add((BigNumber$1).from(item.start_amount));
18453
+ if (item.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721) amount = amount.add((BigNumber$1).from(item.amount));
18406
18454
  });
18407
18455
  const feeArray = order.result.fees;
18408
18456
  feeArray.forEach((item)=>{
@@ -4,7 +4,7 @@ import { useEffect } from 'react';
4
4
  function $parcel$export(e, n, v, s) {
5
5
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
6
  }
7
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.13.2-alpha";
7
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.14.0-alpha.1";
8
8
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
9
9
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
10
10
 
@@ -270,6 +270,14 @@ declare namespace ERC721Hybrid {
270
270
  to: string;
271
271
  quantity: BigNumber;
272
272
  };
273
+ type IDBurnStruct = {
274
+ owner: PromiseOrValue<string>;
275
+ tokenIds: PromiseOrValue<BigNumberish>[];
276
+ };
277
+ type IDBurnStructOutput = [string, BigNumber[]] & {
278
+ owner: string;
279
+ tokenIds: BigNumber[];
280
+ };
273
281
  type TransferRequestStruct = {
274
282
  from: PromiseOrValue<string>;
275
283
  tos: PromiseOrValue<string>[];
@@ -285,7 +293,8 @@ declare namespace ERC721Hybrid {
285
293
  type Mint = ERC721Hybrid.MintStruct;
286
294
  type IDMint = ERC721Hybrid.IDMintStruct;
287
295
  type TransferRequest = ERC721Hybrid.TransferRequestStruct;
288
- declare class ERC721HybridPermissionedMintable {
296
+ type IDBurn = ERC721Hybrid.IDBurnStruct;
297
+ declare class ERC721 {
289
298
  private readonly contract;
290
299
  constructor(contractAddress: string);
291
300
  /**
@@ -388,6 +397,18 @@ declare class ERC721HybridPermissionedMintable {
388
397
  populateBurnBatch(tokenIds: PromiseOrValue<BigNumberish>[], overrides?: Overrides & {
389
398
  from?: PromiseOrValue<string>;
390
399
  }): Promise<PopulatedTransaction>;
400
+ /**
401
+ * @returns a populated transaction for the safe burn contract function
402
+ */
403
+ populateSafeBurn(owner: PromiseOrValue<string>, tokenId: PromiseOrValue<BigNumberish>, overrides?: Overrides & {
404
+ from?: PromiseOrValue<string>;
405
+ }): Promise<PopulatedTransaction>;
406
+ /**
407
+ * @returns a populated transaction for the safe burn batch contract function
408
+ */
409
+ populateSafeBurnBatch(burns: IDBurn[], overrides?: Overrides & {
410
+ from?: PromiseOrValue<string>;
411
+ }): Promise<PopulatedTransaction>;
391
412
  /**
392
413
  * @returns a populated transaction for the grantMinterRole contract function
393
414
  */
@@ -403,13 +424,13 @@ declare class ERC721HybridPermissionedMintable {
403
424
  /**
404
425
  * @returns a populated transaction for the mint by ID contract function
405
426
  */
406
- populateMintByID(to: PromiseOrValue<string>, tokenId: PromiseOrValue<BigNumberish>, overrides?: Overrides & {
427
+ populateMint(to: PromiseOrValue<string>, tokenId: PromiseOrValue<BigNumberish>, overrides?: Overrides & {
407
428
  from?: PromiseOrValue<string>;
408
429
  }): Promise<PopulatedTransaction>;
409
430
  /**
410
431
  * @returns a populated transaction for the safe mint by ID contract function
411
432
  */
412
- populateSafeMintByID(to: PromiseOrValue<string>, tokenId: PromiseOrValue<BigNumberish>, overrides?: Overrides & {
433
+ populateSafeMint(to: PromiseOrValue<string>, tokenId: PromiseOrValue<BigNumberish>, overrides?: Overrides & {
413
434
  from?: PromiseOrValue<string>;
414
435
  }): Promise<PopulatedTransaction>;
415
436
  /**
@@ -427,25 +448,25 @@ declare class ERC721HybridPermissionedMintable {
427
448
  /**
428
449
  * @returns a populated transaction for the batch mint by quantity contract function
429
450
  */
430
- populateBatchMintByQuantity(mints: Mint[], overrides?: Overrides & {
451
+ populateMintBatchByQuantity(mints: Mint[], overrides?: Overrides & {
431
452
  from?: PromiseOrValue<string>;
432
453
  }): Promise<PopulatedTransaction>;
433
454
  /**
434
455
  * @returns a populated transaction for the batch safe mint by quantity contract function
435
456
  */
436
- populateBatchSafeMintByQuantity(mints: Mint[], overrides?: Overrides & {
457
+ populateSafeMintBatchByQuantity(mints: Mint[], overrides?: Overrides & {
437
458
  from?: PromiseOrValue<string>;
438
459
  }): Promise<PopulatedTransaction>;
439
460
  /**
440
461
  * @returns a populated transaction for the batch mint by ID to multiple recipients contract function
441
462
  */
442
- populateBatchMintByIDToMultiple(mints: IDMint[], overrides?: Overrides & {
463
+ populateMintBatch(mints: IDMint[], overrides?: Overrides & {
443
464
  from?: PromiseOrValue<string>;
444
465
  }): Promise<PopulatedTransaction>;
445
466
  /**
446
467
  * @returns a populated transaction for the batch safe mint by ID to multiple recipients contract function
447
468
  */
448
- populateBatchSafeMintByIDToMultiple(mints: IDMint[], overrides?: Overrides & {
469
+ populateSafeMintBatch(mints: IDMint[], overrides?: Overrides & {
449
470
  from?: PromiseOrValue<string>;
450
471
  }): Promise<PopulatedTransaction>;
451
472
  /**
@@ -528,4 +549,4 @@ declare class ERC721HybridPermissionedMintable {
528
549
  }): Promise<PopulatedTransaction>;
529
550
  }
530
551
 
531
- export { ERC721HybridPermissionedMintable };
552
+ export { ERC721 };