@imtbl/sdk 0.4.0-alpha.2 → 0.4.0-alpha.3

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,4 +1,4 @@
1
- import { OrderbookOverrides, OrderbookModuleConfiguration } from 'config/config';
1
+ import { OrderbookOverrides } from 'config/config';
2
2
  import { ListingResult, ListListingsResult } from 'openapi/sdk';
3
3
  import { ListListingsParams, PrepareListingParams, PrepareListingResponse, CreateListingParams, FulfillOrderResponse, CancelOrderResponse } from 'types';
4
4
 
@@ -28,7 +28,7 @@ declare class Orderbook {
28
28
  private apiClient;
29
29
  private seaport;
30
30
  private orderbookConfig;
31
- constructor(config: ModuleConfiguration<OrderbookOverrides>, localConfig?: OrderbookModuleConfiguration);
31
+ constructor(config: ModuleConfiguration<OrderbookOverrides>);
32
32
  /**
33
33
  * Get an order by ID
34
34
  * @param {string} listingId - The listingId to find.
package/dist/orderbook.js CHANGED
@@ -3,6 +3,12 @@ import FormData from 'form-data';
3
3
  import { providers, BigNumber, constants, utils, Contract } from 'ethers';
4
4
  import { Seaport as Seaport$1 } from '@opensea/seaport-js';
5
5
 
6
+ var Environment;
7
+ (function (Environment) {
8
+ Environment["PRODUCTION"] = "production";
9
+ Environment["SANDBOX"] = "sandbox";
10
+ })(Environment || (Environment = {}));
11
+
6
12
  class BaseHttpRequest {
7
13
  config;
8
14
  constructor(config) {
@@ -898,31 +904,25 @@ class ImmutableApiClientFactory {
898
904
  }
899
905
  }
900
906
 
901
- const DEVNET_CHAIN_NAME = 'imtbl-zkevm-devnet';
902
907
  const TESTNET_CHAIN_NAME = 'imtbl-zkevm-testnet';
903
908
  const MAINNET_CHAIN_NAME = 'imtbl-zkevm-mainnet';
904
- function getOrderbookConfig(chainName) {
905
- switch (chainName) {
906
- case DEVNET_CHAIN_NAME:
907
- return {
908
- seaportContractAddress: '0x41388404Efb7a68Fd31d75CEf71dF91e2BDBa2fb',
909
- zoneContractAddress: '0xCb5063b0c1dcF4f7fed8E7eaa79faf9859792767',
910
- apiEndpoint: 'https://order-book-mr.dev.imtbl.com',
911
- provider: new providers.JsonRpcProvider('https://zkevm-rpc.dev.x.immutable.com'),
912
- };
913
- case TESTNET_CHAIN_NAME:
909
+ function getOrderbookConfig(environment) {
910
+ switch (environment) {
911
+ case Environment.SANDBOX:
914
912
  return {
915
- seaportContractAddress: '0x45E23dA18804F99Cf67408AeBE85F67c958381Ff',
916
- zoneContractAddress: '0x25b00b7eb97eab6194798E9B8eF63Aa526D5bd7E',
913
+ seaportContractAddress: '0x474989C4D25DD41B0B9b1ECb4643B9Fe25f83B19',
914
+ zoneContractAddress: '0x6FeDb4949E5b452700A8a8956999a7E05B6770F3',
917
915
  apiEndpoint: 'https://order-book-mr.sandbox.imtbl.com',
916
+ chainName: TESTNET_CHAIN_NAME,
918
917
  provider: new providers.JsonRpcProvider('https://zkevm-rpc.sandbox.x.immutable.com'),
919
918
  };
920
- case MAINNET_CHAIN_NAME:
921
- // not yet deployed
919
+ // not yet deployed
920
+ case Environment.PRODUCTION:
922
921
  return {
923
922
  seaportContractAddress: '',
924
923
  zoneContractAddress: '',
925
924
  apiEndpoint: 'https://order-book-mr.imtbl.com',
925
+ chainName: MAINNET_CHAIN_NAME,
926
926
  provider: new providers.JsonRpcProvider('https://zkevm-rpc.x.immutable.com'),
927
927
  };
928
928
  default:
@@ -1881,21 +1881,19 @@ class Orderbook {
1881
1881
  apiClient;
1882
1882
  seaport;
1883
1883
  orderbookConfig;
1884
- constructor(config, localConfig) {
1885
- // either use preconfigured config or local config passed in
1886
- const maybeConfig = getOrderbookConfig(config.overrides?.chainName) || localConfig;
1887
- if (!maybeConfig) {
1888
- throw new Error('Orderbook configuration not passed, either select one of the preseet chainNames or pass in localConfig');
1884
+ constructor(config) {
1885
+ const obConfig = getOrderbookConfig(config.baseConfig.environment);
1886
+ const finalConfig = {
1887
+ ...obConfig,
1888
+ ...config.overrides,
1889
+ };
1890
+ if (!finalConfig) {
1891
+ throw new Error('Orderbook configuration not passed, please specify the environment under config.baseConfig.environment');
1889
1892
  }
1890
- this.orderbookConfig = maybeConfig;
1891
- const { apiEndpoint } = this.orderbookConfig;
1893
+ this.orderbookConfig = finalConfig;
1894
+ const { apiEndpoint, chainName } = this.orderbookConfig;
1892
1895
  if (!apiEndpoint) {
1893
- throw new Error('API endpoint must be provided as an override');
1894
- }
1895
- // TODO: Move chainId lookup to a map based on env. Just using override to get dev started
1896
- const chainName = config.overrides?.chainName;
1897
- if (!chainName) {
1898
- throw new Error('chainName must be provided as an override');
1896
+ throw new Error('API endpoint must be provided');
1899
1897
  }
1900
1898
  this.apiClient = new ImmutableApiClientFactory(apiEndpoint, chainName, this.orderbookConfig.seaportContractAddress).create();
1901
1899
  const seaportLibFactory = new SeaportLibFactory(this.orderbookConfig.seaportContractAddress, this.orderbookConfig.provider);
@@ -203,7 +203,7 @@ declare abstract class ForkEvent extends Description {
203
203
  }
204
204
  declare type EventType = string | Array<string | Array<string>> | EventFilter | ForkEvent;
205
205
  declare type Listener = (...args: Array<any>) => void;
206
- declare abstract class Provider implements OnceBlockable {
206
+ declare abstract class Provider$1 implements OnceBlockable {
207
207
  abstract getNetwork(): Promise<Network>;
208
208
  abstract getBlockNumber(): Promise<number>;
209
209
  abstract getGasPrice(): Promise<BigNumber>;
@@ -222,27 +222,27 @@ declare abstract class Provider implements OnceBlockable {
222
222
  abstract getLogs(filter: Filter): Promise<Array<Log>>;
223
223
  abstract resolveName(name: string | Promise<string>): Promise<null | string>;
224
224
  abstract lookupAddress(address: string | Promise<string>): Promise<null | string>;
225
- abstract on(eventName: EventType, listener: Listener): Provider;
226
- abstract once(eventName: EventType, listener: Listener): Provider;
225
+ abstract on(eventName: EventType, listener: Listener): Provider$1;
226
+ abstract once(eventName: EventType, listener: Listener): Provider$1;
227
227
  abstract emit(eventName: EventType, ...args: Array<any>): boolean;
228
228
  abstract listenerCount(eventName?: EventType): number;
229
229
  abstract listeners(eventName?: EventType): Array<Listener>;
230
- abstract off(eventName: EventType, listener?: Listener): Provider;
231
- abstract removeAllListeners(eventName?: EventType): Provider;
232
- addListener(eventName: EventType, listener: Listener): Provider;
233
- removeListener(eventName: EventType, listener: Listener): Provider;
230
+ abstract off(eventName: EventType, listener?: Listener): Provider$1;
231
+ abstract removeAllListeners(eventName?: EventType): Provider$1;
232
+ addListener(eventName: EventType, listener: Listener): Provider$1;
233
+ removeListener(eventName: EventType, listener: Listener): Provider$1;
234
234
  abstract waitForTransaction(transactionHash: string, confirmations?: number, timeout?: number): Promise<TransactionReceipt>;
235
235
  readonly _isProvider: boolean;
236
236
  constructor();
237
- static isProvider(value: any): value is Provider;
237
+ static isProvider(value: any): value is Provider$1;
238
238
  }
239
239
 
240
240
  declare abstract class Signer {
241
- readonly provider?: Provider;
241
+ readonly provider?: Provider$1;
242
242
  abstract getAddress(): Promise<string>;
243
243
  abstract signMessage(message: Bytes | string): Promise<string>;
244
244
  abstract signTransaction(transaction: Deferrable<TransactionRequest>): Promise<string>;
245
- abstract connect(provider: Provider): Signer;
245
+ abstract connect(provider: Provider$1): Signer;
246
246
  readonly _isSigner: boolean;
247
247
  constructor();
248
248
  getBalance(blockTag?: BlockTag): Promise<BigNumber>;
@@ -10352,14 +10352,14 @@ declare class ImmutableXClient {
10352
10352
  * @returns a promise that resolves with the requested Order
10353
10353
  * @throws {@link index.IMXError}
10354
10354
  */
10355
- getOrder(request: OrdersApiGetOrderRequest): Promise<Order>;
10355
+ getOrder(request: OrdersApiGetOrderRequest): Promise<OrderV3>;
10356
10356
  /**
10357
10357
  * Get a list of Orders
10358
10358
  * @param request - optional object containing the parameters to be provided in the API request
10359
10359
  * @returns a promise that resolves with the requested list of Orders
10360
10360
  * @throws {@link index.IMXError}
10361
10361
  */
10362
- listOrders(request?: OrdersApiListOrdersRequest): Promise<ListOrdersResponse>;
10362
+ listOrders(request?: OrdersApiListOrdersRequest): Promise<ListOrdersResponseV3>;
10363
10363
  /**
10364
10364
  * Get details of a Trade with the given ID
10365
10365
  * @param request - the request object containing the parameters to be provided in the API request
@@ -10473,6 +10473,7 @@ declare enum Networks {
10473
10473
  interface OidcConfiguration {
10474
10474
  clientId: string;
10475
10475
  logoutRedirectUri: string;
10476
+ logoutMode?: 'redirect' | 'silent';
10476
10477
  redirectUri: string;
10477
10478
  scope?: string;
10478
10479
  audience?: string;
@@ -10485,6 +10486,12 @@ interface PassportOverrides {
10485
10486
  passportDomain: string;
10486
10487
  imxPublicApiDomain: string;
10487
10488
  immutableXClient: ImmutableXClient;
10489
+ zkEvmRpcUrl: string;
10490
+ zkEvmChainId: string;
10491
+ relayerUrl: string;
10492
+ indexerMrBasePath: string;
10493
+ orderBookMrBasePath: string;
10494
+ passportMrBasePath: string;
10488
10495
  }
10489
10496
  interface PassportModuleConfiguration extends ModuleConfiguration<PassportOverrides>, OidcConfiguration {
10490
10497
  }
@@ -10502,6 +10509,58 @@ type DeviceTokenResponse = {
10502
10509
  expires_in: number;
10503
10510
  };
10504
10511
 
10512
+ /**
10513
+ * ProviderErrors should take priority over RpcErrorCodes
10514
+ */
10515
+ declare enum ProviderErrorCode {
10516
+ USER_REJECTED_REQUEST = 4001,
10517
+ UNAUTHORIZED = 4100,
10518
+ UNSUPPORTED_METHOD = 4200,
10519
+ DISCONNECTED = 4900
10520
+ }
10521
+ declare enum RpcErrorCode {
10522
+ RPC_SERVER_ERROR = -32000,
10523
+ INVALID_REQUEST = -32600,
10524
+ METHOD_NOT_FOUND = -32601,
10525
+ INVALID_PARAMS = -32602,
10526
+ INTERNAL_ERROR = -32603,
10527
+ PARSE_ERROR = -32700
10528
+ }
10529
+ declare class JsonRpcError extends Error {
10530
+ readonly message: string;
10531
+ readonly code: ProviderErrorCode | RpcErrorCode;
10532
+ constructor(code: ProviderErrorCode | RpcErrorCode, message: string);
10533
+ }
10534
+
10535
+ interface RequestArguments {
10536
+ method: string;
10537
+ params?: Array<any>;
10538
+ }
10539
+ type JsonRpcRequestPayload = RequestArguments & {
10540
+ jsonrpc?: string;
10541
+ id?: string | number;
10542
+ };
10543
+ interface JsonRpcRequestCallback {
10544
+ (err: JsonRpcError | null, result?: JsonRpcResponsePayload | (JsonRpcResponsePayload | null)[] | null): void;
10545
+ }
10546
+ interface JsonRpcResponsePayload {
10547
+ result?: Array<any> | null;
10548
+ error?: JsonRpcError | null;
10549
+ jsonrpc?: string;
10550
+ id?: string | number;
10551
+ }
10552
+ type Provider = {
10553
+ request: (request: RequestArguments) => Promise<any>;
10554
+ sendAsync: (request: JsonRpcRequestPayload | JsonRpcRequestPayload[], callback: JsonRpcRequestCallback) => void;
10555
+ send: (request: string | JsonRpcRequestPayload | JsonRpcRequestPayload[], callbackOrParams?: JsonRpcRequestCallback | Array<any>, callback?: JsonRpcRequestCallback) => void;
10556
+ on: (event: string, listener: (...args: any[]) => void) => void;
10557
+ removeListener: (event: string, listener: (...args: any[]) => void) => void;
10558
+ };
10559
+ declare enum ProviderEvent {
10560
+ ACCOUNTS_CHANGED = "accountsChanged"
10561
+ }
10562
+ type AccountsChangedEvent = Array<string>;
10563
+
10505
10564
  declare class Passport {
10506
10565
  private readonly authManager;
10507
10566
  private readonly config;
@@ -10509,6 +10568,7 @@ declare class Passport {
10509
10568
  private readonly immutableXClient;
10510
10569
  private readonly magicAdapter;
10511
10570
  private readonly passportImxProviderFactory;
10571
+ private readonly multiRollupApiClients;
10512
10572
  constructor(passportModuleConfiguration: PassportModuleConfiguration);
10513
10573
  connectImxSilent(): Promise<IMXProvider | null>;
10514
10574
  connectImx(): Promise<IMXProvider>;
@@ -10519,8 +10579,14 @@ declare class Passport {
10519
10579
  */
10520
10580
  checkStoredDeviceFlowCredentials(): DeviceTokenResponse | null;
10521
10581
  connectImxWithCredentials(tokenResponse: DeviceTokenResponse): Promise<IMXProvider | null>;
10582
+ protected connectEvm(): Provider;
10522
10583
  loginCallback(): Promise<void>;
10523
10584
  logout(): Promise<void>;
10585
+ /**
10586
+ * This method should only be called from the logout redirect uri
10587
+ * when logout mode is 'silent'.
10588
+ */
10589
+ logoutSilentCallback(url: string): Promise<void>;
10524
10590
  logoutDeviceFlow(): Promise<void>;
10525
10591
  getUserInfo(): Promise<UserProfile | undefined>;
10526
10592
  getUserInfoDeviceFlow(): Promise<UserProfile | undefined>;
@@ -10528,4 +10594,4 @@ declare class Passport {
10528
10594
  getAccessToken(): Promise<string | undefined>;
10529
10595
  }
10530
10596
 
10531
- export { DeviceConnectResponse, DeviceTokenResponse, Networks, Passport, PassportError, PassportModuleConfiguration, PassportOverrides, UserProfile };
10597
+ export { AccountsChangedEvent, DeviceConnectResponse, DeviceTokenResponse, JsonRpcError, JsonRpcRequestCallback, JsonRpcRequestPayload, JsonRpcResponsePayload, Networks, Passport, PassportError, PassportModuleConfiguration, PassportOverrides, Provider, ProviderErrorCode, ProviderEvent, RequestArguments, RpcErrorCode, UserProfile };