@imtbl/sdk 0.1.3 → 0.1.5-alpha
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/checkout_sdk.d.ts +986 -0
- package/dist/checkout_sdk.js +626 -0
- package/dist/checkout_widgets.d.ts +15057 -0
- package/dist/checkout_widgets.js +251 -0
- package/dist/immutablex_client.d.ts +9 -9
- package/dist/immutablex_client.js +34 -31
- package/dist/index.cjs +2144 -174
- package/dist/index.d.ts +15302 -17
- package/dist/index.js +2134 -177
- package/dist/passport.d.ts +9935 -154
- package/dist/passport.js +661 -141
- package/dist/provider.d.ts +962 -0
- package/dist/provider.js +1139 -0
- package/package.json +15 -3
package/dist/index.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import { ImmutableX, Config,
|
|
1
|
+
import { ImmutableX, Config, generateLegacyStarkPrivateKey, createStarkSigner, TransfersApi, OrdersApi, UsersApi, Contracts, TradesApi, ExchangesApi, WithdrawalsApi, MintsApi, DepositsApi, EncodingApi, TokensApi } from '@imtbl/core-sdk';
|
|
2
2
|
export { createStarkSigner as imxClientCreateStarkSigner, generateLegacyStarkPrivateKey as imxClientGenerateLegacyStarkPrivateKey } from '@imtbl/core-sdk';
|
|
3
3
|
import { UserManager } from 'oidc-client-ts';
|
|
4
|
-
import { ethers } from 'ethers';
|
|
4
|
+
import { ethers, utils, Contract } from 'ethers';
|
|
5
5
|
import { Magic } from 'magic-sdk';
|
|
6
6
|
import { OpenIdExtension } from '@magic-ext/oidc';
|
|
7
7
|
import BN from 'bn.js';
|
|
8
8
|
import * as encUtils from 'enc-utils';
|
|
9
|
+
import { parseUnits } from '@ethersproject/units';
|
|
10
|
+
import { BigNumber } from '@ethersproject/bignumber';
|
|
11
|
+
import detectEthereumProvider from '@metamask/detect-provider';
|
|
12
|
+
import { Web3Provider } from '@ethersproject/providers';
|
|
13
|
+
import { jsx } from 'react/jsx-runtime';
|
|
14
|
+
import 'react';
|
|
9
15
|
|
|
10
16
|
var Environment;
|
|
11
17
|
(function (Environment) {
|
|
@@ -21,26 +27,26 @@ class ImmutableConfiguration {
|
|
|
21
27
|
}
|
|
22
28
|
}
|
|
23
29
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
};
|
|
30
|
+
/**
|
|
31
|
+
* Set `sdkVersion` on config
|
|
32
|
+
*/
|
|
33
|
+
const production = () => Config.createConfig({
|
|
34
|
+
basePath: 'https://api.x.immutable.com',
|
|
35
|
+
chainID: 1,
|
|
36
|
+
coreContractAddress: '0x5FDCCA53617f4d2b9134B29090C87D01058e27e9',
|
|
37
|
+
registrationContractAddress: '0x72a06bf2a1CE5e39cBA06c0CAb824960B587d64c',
|
|
38
|
+
sdkVersion: 'ts-immutable-sdk-0.1.5-alpha',
|
|
39
|
+
});
|
|
40
|
+
/**
|
|
41
|
+
* Set `sdkVersion` on config
|
|
42
|
+
*/
|
|
43
|
+
const sandbox = () => Config.createConfig({
|
|
44
|
+
basePath: 'https://api.sandbox.x.immutable.com',
|
|
45
|
+
chainID: 5,
|
|
46
|
+
coreContractAddress: '0x7917eDb51ecD6CdB3F9854c3cc593F33de10c623',
|
|
47
|
+
registrationContractAddress: '0x1C97Ada273C9A52253f463042f29117090Cd7D83',
|
|
48
|
+
sdkVersion: 'ts-immutable-sdk-0.1.5-alpha',
|
|
49
|
+
});
|
|
44
50
|
class ImxConfiguration {
|
|
45
51
|
immutableXConfig;
|
|
46
52
|
baseConfig;
|
|
@@ -52,13 +58,16 @@ class ImxConfiguration {
|
|
|
52
58
|
else {
|
|
53
59
|
switch (baseConfig.environment) {
|
|
54
60
|
case Environment.SANDBOX: {
|
|
55
|
-
this.immutableXConfig =
|
|
61
|
+
this.immutableXConfig = sandbox();
|
|
56
62
|
break;
|
|
57
63
|
}
|
|
58
64
|
case Environment.PRODUCTION: {
|
|
59
|
-
this.immutableXConfig =
|
|
65
|
+
this.immutableXConfig = production();
|
|
60
66
|
break;
|
|
61
67
|
}
|
|
68
|
+
default: {
|
|
69
|
+
this.immutableXConfig = sandbox();
|
|
70
|
+
}
|
|
62
71
|
}
|
|
63
72
|
}
|
|
64
73
|
}
|
|
@@ -113,7 +122,7 @@ class ImmutableXClient {
|
|
|
113
122
|
}
|
|
114
123
|
/**
|
|
115
124
|
* Get a list of Deposits
|
|
116
|
-
* @param request - optional
|
|
125
|
+
* @param request - optional object containing the parameters to be provided in the API request
|
|
117
126
|
* @returns a promise that resolves with the requested list of Deposits
|
|
118
127
|
* @throws {@link index.IMXError}
|
|
119
128
|
*/
|
|
@@ -140,7 +149,7 @@ class ImmutableXClient {
|
|
|
140
149
|
}
|
|
141
150
|
/**
|
|
142
151
|
* Get a list of Assets
|
|
143
|
-
* @param request - optional
|
|
152
|
+
* @param request - optional object containing the parameters to be provided in the API request
|
|
144
153
|
* @returns a promise that resolves with the requested list of Assets
|
|
145
154
|
* @throws {@link index.IMXError}
|
|
146
155
|
*/
|
|
@@ -177,7 +186,7 @@ class ImmutableXClient {
|
|
|
177
186
|
}
|
|
178
187
|
/**
|
|
179
188
|
* Get a list of Collections
|
|
180
|
-
* @param request - optional
|
|
189
|
+
* @param request - optional object containing the parameters to be provided in the API request
|
|
181
190
|
* @returns a promise that resolves with the requested list of Collections
|
|
182
191
|
* @throws {@link index.IMXError}
|
|
183
192
|
*/
|
|
@@ -333,7 +342,7 @@ class ImmutableXClient {
|
|
|
333
342
|
}
|
|
334
343
|
/**
|
|
335
344
|
* Get a list of Mints
|
|
336
|
-
* @param request optional
|
|
345
|
+
* @param request optional object containing the parameters to be provided in the API request
|
|
337
346
|
* @returns a promise that resolves with the requested list of Mints
|
|
338
347
|
* @throws {@link index.IMXError}
|
|
339
348
|
*/
|
|
@@ -352,7 +361,7 @@ class ImmutableXClient {
|
|
|
352
361
|
}
|
|
353
362
|
/**
|
|
354
363
|
* Get a list of Withdrawals
|
|
355
|
-
* @param request - optional
|
|
364
|
+
* @param request - optional object containing the parameters to be provided in the API request
|
|
356
365
|
* @returns a promise that resolves with the requested list of Withdrawals
|
|
357
366
|
* @throws {@link index.IMXError}
|
|
358
367
|
*/
|
|
@@ -379,7 +388,7 @@ class ImmutableXClient {
|
|
|
379
388
|
}
|
|
380
389
|
/**
|
|
381
390
|
* Get a list of Orders
|
|
382
|
-
* @param request - optional
|
|
391
|
+
* @param request - optional object containing the parameters to be provided in the API request
|
|
383
392
|
* @returns a promise that resolves with the requested list of Orders
|
|
384
393
|
* @throws {@link index.IMXError}
|
|
385
394
|
*/
|
|
@@ -397,7 +406,7 @@ class ImmutableXClient {
|
|
|
397
406
|
}
|
|
398
407
|
/**
|
|
399
408
|
* Get a list of Trades
|
|
400
|
-
* @param request - optional
|
|
409
|
+
* @param request - optional object containing the parameters to be provided in the API request
|
|
401
410
|
* @returns a promise that resolves with the requested list of Trades
|
|
402
411
|
* @throws {@link index.IMXError}
|
|
403
412
|
*/
|
|
@@ -415,7 +424,7 @@ class ImmutableXClient {
|
|
|
415
424
|
}
|
|
416
425
|
/**
|
|
417
426
|
* Get a list of Tokens
|
|
418
|
-
* @param request - optional
|
|
427
|
+
* @param request - optional object containing the parameters to be provided in the API request
|
|
419
428
|
* @returns a promise that resolves with the requested list of Tokens
|
|
420
429
|
* @throws {@link index.IMXError}
|
|
421
430
|
*/
|
|
@@ -433,7 +442,7 @@ class ImmutableXClient {
|
|
|
433
442
|
}
|
|
434
443
|
/**
|
|
435
444
|
* Get a list of Transfers
|
|
436
|
-
* @param request - optional
|
|
445
|
+
* @param request - optional object containing the parameters to be provided in the API request
|
|
437
446
|
* @returns a promise that resolves with the requested list of Transfers
|
|
438
447
|
* @throws {@link index.IMXError}
|
|
439
448
|
*/
|
|
@@ -549,6 +558,15 @@ async function signRaw(payload, signer) {
|
|
|
549
558
|
const signature = deserializeSignature(await signer.signMessage(payload));
|
|
550
559
|
return serializeEthSignature(signature);
|
|
551
560
|
}
|
|
561
|
+
async function signMessage(message, signer) {
|
|
562
|
+
const ethAddress = await signer.getAddress();
|
|
563
|
+
const ethSignature = await signRaw(message, signer);
|
|
564
|
+
return {
|
|
565
|
+
message,
|
|
566
|
+
ethAddress,
|
|
567
|
+
ethSignature,
|
|
568
|
+
};
|
|
569
|
+
}
|
|
552
570
|
|
|
553
571
|
/**
|
|
554
572
|
* Helper method to convert token type to a SignableToken type
|
|
@@ -645,9 +663,9 @@ const getAuthConfiguration = ({ oidcConfiguration, authenticationDomain, }) => {
|
|
|
645
663
|
authorization_endpoint: `${authenticationDomain}/authorize`,
|
|
646
664
|
token_endpoint: `${authenticationDomain}/oauth/token`,
|
|
647
665
|
userinfo_endpoint: `${authenticationDomain}/userinfo`,
|
|
648
|
-
end_session_endpoint: `${authenticationDomain}/v2/logout`
|
|
649
|
-
`?returnTo=${encodeURIComponent(oidcConfiguration.logoutRedirectUri)}`
|
|
650
|
-
`&client_id=${oidcConfiguration.clientId}`,
|
|
666
|
+
end_session_endpoint: `${authenticationDomain}/v2/logout`
|
|
667
|
+
+ `?returnTo=${encodeURIComponent(oidcConfiguration.logoutRedirectUri)}`
|
|
668
|
+
+ `&client_id=${oidcConfiguration.clientId}`,
|
|
651
669
|
},
|
|
652
670
|
mergeClaims: true,
|
|
653
671
|
loadUserInfo: true,
|
|
@@ -667,7 +685,7 @@ class AuthManager {
|
|
|
667
685
|
this.config = config;
|
|
668
686
|
this.userManager = new UserManager(getAuthConfiguration(config));
|
|
669
687
|
}
|
|
670
|
-
mapOidcUserToDomainModel = (oidcUser) => {
|
|
688
|
+
static mapOidcUserToDomainModel = (oidcUser) => {
|
|
671
689
|
const passport = oidcUser.profile?.passport;
|
|
672
690
|
return {
|
|
673
691
|
expired: oidcUser.expired,
|
|
@@ -688,7 +706,7 @@ class AuthManager {
|
|
|
688
706
|
const oidcUser = await this.userManager.signinPopup({
|
|
689
707
|
popupWindowFeatures,
|
|
690
708
|
});
|
|
691
|
-
return
|
|
709
|
+
return AuthManager.mapOidcUserToDomainModel(oidcUser);
|
|
692
710
|
}, PassportErrorType.AUTHENTICATION_ERROR);
|
|
693
711
|
}
|
|
694
712
|
async loginCallback() {
|
|
@@ -707,7 +725,7 @@ class AuthManager {
|
|
|
707
725
|
if (!oidcUser) {
|
|
708
726
|
return null;
|
|
709
727
|
}
|
|
710
|
-
return
|
|
728
|
+
return AuthManager.mapOidcUserToDomainModel(oidcUser);
|
|
711
729
|
}, PassportErrorType.SILENT_LOGIN_ERROR);
|
|
712
730
|
}
|
|
713
731
|
async getUser() {
|
|
@@ -716,7 +734,7 @@ class AuthManager {
|
|
|
716
734
|
if (!oidcUser) {
|
|
717
735
|
return null;
|
|
718
736
|
}
|
|
719
|
-
return
|
|
737
|
+
return AuthManager.mapOidcUserToDomainModel(oidcUser);
|
|
720
738
|
}, PassportErrorType.NOT_LOGGED_IN_ERROR);
|
|
721
739
|
}
|
|
722
740
|
async requestRefreshTokenAfterRegistration() {
|
|
@@ -724,18 +742,18 @@ class AuthManager {
|
|
|
724
742
|
const updatedUser = await retryWithDelay(async () => {
|
|
725
743
|
const user = await this.userManager.signinSilent();
|
|
726
744
|
const passportMetadata = user?.profile?.passport;
|
|
727
|
-
const metadataExists = !!passportMetadata?.ether_key
|
|
728
|
-
!!passportMetadata?.stark_key
|
|
729
|
-
!!passportMetadata?.user_admin_key;
|
|
745
|
+
const metadataExists = !!passportMetadata?.ether_key
|
|
746
|
+
&& !!passportMetadata?.stark_key
|
|
747
|
+
&& !!passportMetadata?.user_admin_key;
|
|
730
748
|
if (metadataExists) {
|
|
731
749
|
return user;
|
|
732
750
|
}
|
|
733
|
-
return Promise.reject('user wallet addresses not exist');
|
|
751
|
+
return Promise.reject(new Error('user wallet addresses not exist'));
|
|
734
752
|
});
|
|
735
753
|
if (!updatedUser) {
|
|
736
754
|
return null;
|
|
737
755
|
}
|
|
738
|
-
return
|
|
756
|
+
return AuthManager.mapOidcUserToDomainModel(updatedUser);
|
|
739
757
|
}, PassportErrorType.REFRESH_TOKEN_ERROR);
|
|
740
758
|
}
|
|
741
759
|
}
|
|
@@ -774,12 +792,24 @@ var SendMessage;
|
|
|
774
792
|
})(SendMessage || (SendMessage = {}));
|
|
775
793
|
var TransactionTypes;
|
|
776
794
|
(function (TransactionTypes) {
|
|
795
|
+
// TODO: remove this once the naming has been fixed
|
|
796
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
777
797
|
TransactionTypes["CancelOrder"] = "delete:v1/orders";
|
|
798
|
+
// TODO: remove this once the naming has been fixed
|
|
799
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
778
800
|
TransactionTypes["CreateOrder"] = "post:v1/orders";
|
|
801
|
+
// TODO: remove this once the naming has been fixed
|
|
802
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
779
803
|
TransactionTypes["CreateTrade"] = "post:v1/trades";
|
|
804
|
+
// TODO: remove this once the naming has been fixed
|
|
805
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
780
806
|
TransactionTypes["CreateTransfer"] = "post:v1/transfers";
|
|
807
|
+
// TODO: remove this once the naming has been fixed
|
|
808
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
781
809
|
TransactionTypes["CreateBatchTransfer"] = "post:v2/transfers";
|
|
782
810
|
})(TransactionTypes || (TransactionTypes = {}));
|
|
811
|
+
// TODO: remove this once the naming has been fixed
|
|
812
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
783
813
|
const PassportEventType = 'imx_passport_confirmation';
|
|
784
814
|
|
|
785
815
|
const openPopupCenter = ({ url, title, width, height, }) => {
|
|
@@ -799,10 +829,10 @@ const openPopupCenter = ({ url, title, width, height, }) => {
|
|
|
799
829
|
return newWindow;
|
|
800
830
|
};
|
|
801
831
|
|
|
802
|
-
const
|
|
803
|
-
const
|
|
804
|
-
const
|
|
805
|
-
const
|
|
832
|
+
const CONFIRMATION_WINDOW_TITLE = 'Confirm this transaction';
|
|
833
|
+
const CONFIRMATION_WINDOW_HEIGHT = 380;
|
|
834
|
+
const CONFIRMATION_WINDOW_WIDTH = 480;
|
|
835
|
+
const CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION = 1000;
|
|
806
836
|
class ConfirmationScreen {
|
|
807
837
|
config;
|
|
808
838
|
constructor(config) {
|
|
@@ -818,12 +848,14 @@ class ConfirmationScreen {
|
|
|
818
848
|
startTransaction(accessToken, transaction, popupOptions) {
|
|
819
849
|
return new Promise((resolve, reject) => {
|
|
820
850
|
const messageHandler = ({ data, origin }) => {
|
|
821
|
-
if (origin
|
|
822
|
-
data.eventType
|
|
851
|
+
if (origin !== this.config.passportDomain
|
|
852
|
+
|| data.eventType !== PassportEventType) {
|
|
823
853
|
return;
|
|
824
854
|
}
|
|
825
855
|
switch (data.messageType) {
|
|
826
856
|
case ReceiveMessage.CONFIRMATION_WINDOW_READY: {
|
|
857
|
+
// TODO: remove once fixed
|
|
858
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
827
859
|
this.postMessage(confirmationWindow, accessToken, {
|
|
828
860
|
messageType: SendMessage.TRANSACTION_START,
|
|
829
861
|
messageData: transaction,
|
|
@@ -845,87 +877,87 @@ class ConfirmationScreen {
|
|
|
845
877
|
window.addEventListener('message', messageHandler);
|
|
846
878
|
const confirmationWindow = openPopupCenter({
|
|
847
879
|
url: `${this.config.passportDomain}/transaction-confirmation`,
|
|
848
|
-
title:
|
|
849
|
-
width: popupOptions?.width ||
|
|
850
|
-
height: popupOptions?.height ||
|
|
880
|
+
title: CONFIRMATION_WINDOW_TITLE,
|
|
881
|
+
width: popupOptions?.width || CONFIRMATION_WINDOW_WIDTH,
|
|
882
|
+
height: popupOptions?.height || CONFIRMATION_WINDOW_HEIGHT,
|
|
851
883
|
});
|
|
852
884
|
// https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
|
|
853
|
-
const timer = setInterval(
|
|
885
|
+
const timer = setInterval(() => {
|
|
854
886
|
if (confirmationWindow.closed) {
|
|
855
887
|
clearInterval(timer);
|
|
856
888
|
window.removeEventListener('message', messageHandler);
|
|
857
889
|
resolve({ confirmed: false });
|
|
858
890
|
}
|
|
859
|
-
},
|
|
891
|
+
}, CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION);
|
|
860
892
|
});
|
|
861
893
|
}
|
|
862
894
|
}
|
|
863
895
|
|
|
864
896
|
const ERC721$1 = 'ERC721';
|
|
865
|
-
const transfer = ({ request, transfersApi, starkSigner, user, passportConfig,
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
897
|
+
const transfer$1 = ({ request, transfersApi, starkSigner, user, passportConfig,
|
|
898
|
+
// TODO: remove this eslint disable once we have a better solution
|
|
899
|
+
// eslint-disable-next-line max-len
|
|
900
|
+
}) => withPassportError(async () => {
|
|
901
|
+
const transferAmount = request.type === ERC721$1 ? '1' : request.amount;
|
|
902
|
+
const getSignableTransferRequest = {
|
|
903
|
+
sender: user.etherKey,
|
|
904
|
+
token: convertToSignableToken(request),
|
|
905
|
+
amount: transferAmount,
|
|
906
|
+
receiver: request.receiver,
|
|
907
|
+
};
|
|
908
|
+
const signableResult = await transfersApi.getSignableTransferV1({
|
|
909
|
+
getSignableTransferRequest,
|
|
910
|
+
});
|
|
911
|
+
const confirmationScreen = new ConfirmationScreen(passportConfig);
|
|
912
|
+
const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
|
|
913
|
+
transactionType: TransactionTypes.CreateTransfer,
|
|
914
|
+
transactionData: getSignableTransferRequest,
|
|
915
|
+
});
|
|
916
|
+
if (!confirmationResult.confirmed) {
|
|
917
|
+
throw new Error('Transaction rejected by user');
|
|
918
|
+
}
|
|
919
|
+
const signableResultData = signableResult.data;
|
|
920
|
+
const { payload_hash: payloadHash } = signableResultData;
|
|
921
|
+
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
922
|
+
const senderStarkKey = await starkSigner.getAddress();
|
|
923
|
+
const transferSigningParams = {
|
|
924
|
+
sender_stark_key: signableResultData.sender_stark_key || senderStarkKey,
|
|
925
|
+
sender_vault_id: signableResultData.sender_vault_id,
|
|
926
|
+
receiver_stark_key: signableResultData.receiver_stark_key,
|
|
927
|
+
receiver_vault_id: signableResultData.receiver_vault_id,
|
|
928
|
+
asset_id: signableResultData.asset_id,
|
|
929
|
+
amount: signableResultData.amount,
|
|
930
|
+
nonce: signableResultData.nonce,
|
|
931
|
+
expiration_timestamp: signableResultData.expiration_timestamp,
|
|
932
|
+
stark_signature: starkSignature,
|
|
933
|
+
};
|
|
934
|
+
const createTransferRequest = {
|
|
935
|
+
createTransferRequest: transferSigningParams,
|
|
936
|
+
};
|
|
937
|
+
const headers = {
|
|
938
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
939
|
+
Authorization: `Bearer ${user.accessToken}`,
|
|
940
|
+
};
|
|
941
|
+
const { data: responseData } = await transfersApi.createTransferV1(createTransferRequest, { headers });
|
|
942
|
+
return {
|
|
943
|
+
sent_signature: responseData.sent_signature,
|
|
944
|
+
status: responseData.status?.toString(),
|
|
945
|
+
time: responseData.time,
|
|
946
|
+
transfer_id: responseData.transfer_id,
|
|
947
|
+
};
|
|
948
|
+
}, PassportErrorType.TRANSFER_ERROR);
|
|
915
949
|
async function batchNftTransfer({ user, starkSigner, request, transfersApi, passportConfig, }) {
|
|
916
950
|
return withPassportError(async () => {
|
|
917
951
|
const ethAddress = user.etherKey;
|
|
918
|
-
const signableRequests = request.map((nftTransfer) => {
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
};
|
|
928
|
-
});
|
|
952
|
+
const signableRequests = request.map((nftTransfer) => ({
|
|
953
|
+
amount: '1',
|
|
954
|
+
token: convertToSignableToken({
|
|
955
|
+
type: ERC721$1,
|
|
956
|
+
tokenId: nftTransfer.tokenId,
|
|
957
|
+
tokenAddress: nftTransfer.tokenAddress,
|
|
958
|
+
}),
|
|
959
|
+
receiver: nftTransfer.receiver,
|
|
960
|
+
}));
|
|
929
961
|
const getSignableTransferRequestV2 = {
|
|
930
962
|
sender_ether_key: ethAddress,
|
|
931
963
|
signable_requests: signableRequests,
|
|
@@ -960,7 +992,8 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, pass
|
|
|
960
992
|
requests,
|
|
961
993
|
};
|
|
962
994
|
const headers = {
|
|
963
|
-
|
|
995
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
996
|
+
Authorization: `Bearer ${user.accessToken}`,
|
|
964
997
|
};
|
|
965
998
|
const response = await transfersApi.createTransfer({
|
|
966
999
|
createTransferRequestV2: transferSigningParams,
|
|
@@ -972,7 +1005,7 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, pass
|
|
|
972
1005
|
}
|
|
973
1006
|
|
|
974
1007
|
const ERC721 = 'ERC721';
|
|
975
|
-
async function createOrder({ starkSigner, user, request, ordersApi, passportConfig, }) {
|
|
1008
|
+
async function createOrder$1({ starkSigner, user, request, ordersApi, passportConfig, }) {
|
|
976
1009
|
return withPassportError(async () => {
|
|
977
1010
|
const ethAddress = user.etherKey;
|
|
978
1011
|
const amountSell = request.sell.type === ERC721 ? '1' : request.sell.amount;
|
|
@@ -1017,7 +1050,8 @@ async function createOrder({ starkSigner, user, request, ordersApi, passportConf
|
|
|
1017
1050
|
},
|
|
1018
1051
|
};
|
|
1019
1052
|
const headers = {
|
|
1020
|
-
|
|
1053
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1054
|
+
Authorization: `Bearer ${user.accessToken}`,
|
|
1021
1055
|
};
|
|
1022
1056
|
const createOrderResponse = await ordersApi.createOrder(orderParams, {
|
|
1023
1057
|
headers,
|
|
@@ -1027,7 +1061,7 @@ async function createOrder({ starkSigner, user, request, ordersApi, passportConf
|
|
|
1027
1061
|
};
|
|
1028
1062
|
}, PassportErrorType.CREATE_ORDER_ERROR);
|
|
1029
1063
|
}
|
|
1030
|
-
async function cancelOrder({ user, starkSigner, request, ordersApi, passportConfig, }) {
|
|
1064
|
+
async function cancelOrder$1({ user, starkSigner, request, ordersApi, passportConfig, }) {
|
|
1031
1065
|
return withPassportError(async () => {
|
|
1032
1066
|
const getSignableCancelOrderRequest = {
|
|
1033
1067
|
order_id: request.order_id,
|
|
@@ -1046,7 +1080,8 @@ async function cancelOrder({ user, starkSigner, request, ordersApi, passportConf
|
|
|
1046
1080
|
const { payload_hash: payloadHash } = getSignableCancelOrderResponse.data;
|
|
1047
1081
|
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
1048
1082
|
const headers = {
|
|
1049
|
-
|
|
1083
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1084
|
+
Authorization: `Bearer ${user.accessToken}`,
|
|
1050
1085
|
};
|
|
1051
1086
|
const cancelOrderResponse = await ordersApi.cancelOrder({
|
|
1052
1087
|
id: request.order_id.toString(),
|
|
@@ -1062,7 +1097,7 @@ async function cancelOrder({ user, starkSigner, request, ordersApi, passportConf
|
|
|
1062
1097
|
}, PassportErrorType.CANCEL_ORDER_ERROR);
|
|
1063
1098
|
}
|
|
1064
1099
|
|
|
1065
|
-
async function exchangeTransfer({ user, starkSigner, request, exchangesApi, }) {
|
|
1100
|
+
async function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, }) {
|
|
1066
1101
|
return withPassportError(async () => {
|
|
1067
1102
|
const ethAddress = user.etherKey;
|
|
1068
1103
|
const transferAmount = request.amount;
|
|
@@ -1090,7 +1125,8 @@ async function exchangeTransfer({ user, starkSigner, request, exchangesApi, }) {
|
|
|
1090
1125
|
stark_signature: starkSignature,
|
|
1091
1126
|
};
|
|
1092
1127
|
const headers = {
|
|
1093
|
-
|
|
1128
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1129
|
+
Authorization: `Bearer ${user.accessToken}`,
|
|
1094
1130
|
};
|
|
1095
1131
|
const response = await exchangesApi.createExchangeTransfer({
|
|
1096
1132
|
id: request.transactionID,
|
|
@@ -1105,7 +1141,7 @@ async function exchangeTransfer({ user, starkSigner, request, exchangesApi, }) {
|
|
|
1105
1141
|
}, PassportErrorType.EXCHANGE_TRANSFER_ERROR);
|
|
1106
1142
|
}
|
|
1107
1143
|
|
|
1108
|
-
async function createTrade({ request, tradesApi, user, starkSigner, passportConfig, }) {
|
|
1144
|
+
async function createTrade$1({ request, tradesApi, user, starkSigner, passportConfig, }) {
|
|
1109
1145
|
return withPassportError(async () => {
|
|
1110
1146
|
const ethAddress = user.etherKey;
|
|
1111
1147
|
const getSignableTradeRequest = {
|
|
@@ -1146,7 +1182,8 @@ async function createTrade({ request, tradesApi, user, starkSigner, passportConf
|
|
|
1146
1182
|
vault_id_sell: signableResultData.vault_id_sell,
|
|
1147
1183
|
},
|
|
1148
1184
|
};
|
|
1149
|
-
|
|
1185
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1186
|
+
const headers = { Authorization: `Bearer ${user.accessToken}` };
|
|
1150
1187
|
const { data: createTradeResponse } = await tradesApi.createTradeV3(tradeParams, {
|
|
1151
1188
|
headers,
|
|
1152
1189
|
});
|
|
@@ -1157,62 +1194,57 @@ async function createTrade({ request, tradesApi, user, starkSigner, passportConf
|
|
|
1157
1194
|
class PassportImxProvider {
|
|
1158
1195
|
user;
|
|
1159
1196
|
starkSigner;
|
|
1160
|
-
transfersApi;
|
|
1161
|
-
ordersApi;
|
|
1162
1197
|
passportConfig;
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
constructor({ user, starkSigner, passportConfig }) {
|
|
1198
|
+
immutableXClient;
|
|
1199
|
+
constructor({ user, starkSigner, passportConfig, immutableXClient, }) {
|
|
1166
1200
|
this.user = user;
|
|
1167
1201
|
this.starkSigner = starkSigner;
|
|
1168
1202
|
this.passportConfig = passportConfig;
|
|
1169
|
-
|
|
1170
|
-
basePath: passportConfig.imxApiBasePath,
|
|
1171
|
-
});
|
|
1172
|
-
this.transfersApi = new TransfersApi(apiConfig);
|
|
1173
|
-
this.ordersApi = new OrdersApi(apiConfig);
|
|
1174
|
-
this.exchangesApi = new ExchangesApi(apiConfig);
|
|
1175
|
-
this.tradesApi = new TradesApi(apiConfig);
|
|
1203
|
+
this.immutableXClient = immutableXClient;
|
|
1176
1204
|
}
|
|
1177
1205
|
async transfer(request) {
|
|
1178
|
-
return transfer({
|
|
1206
|
+
return transfer$1({
|
|
1179
1207
|
request,
|
|
1180
1208
|
user: this.user,
|
|
1181
1209
|
starkSigner: this.starkSigner,
|
|
1182
|
-
transfersApi: this.transfersApi,
|
|
1210
|
+
transfersApi: this.immutableXClient.transfersApi,
|
|
1183
1211
|
passportConfig: this.passportConfig,
|
|
1184
1212
|
});
|
|
1185
1213
|
}
|
|
1214
|
+
// TODO: Remove once implemented
|
|
1215
|
+
// eslint-disable-next-line class-methods-use-this
|
|
1186
1216
|
registerOffchain() {
|
|
1187
1217
|
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
1188
1218
|
}
|
|
1219
|
+
// TODO: Remove once implemented
|
|
1220
|
+
// eslint-disable-next-line class-methods-use-this
|
|
1189
1221
|
isRegisteredOnchain() {
|
|
1190
1222
|
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
1191
1223
|
}
|
|
1192
1224
|
createOrder(request) {
|
|
1193
|
-
return createOrder({
|
|
1225
|
+
return createOrder$1({
|
|
1194
1226
|
request,
|
|
1195
1227
|
user: this.user,
|
|
1196
1228
|
starkSigner: this.starkSigner,
|
|
1197
|
-
ordersApi: this.ordersApi,
|
|
1229
|
+
ordersApi: this.immutableXClient.ordersApi,
|
|
1198
1230
|
passportConfig: this.passportConfig,
|
|
1199
1231
|
});
|
|
1200
1232
|
}
|
|
1201
1233
|
cancelOrder(request) {
|
|
1202
|
-
return cancelOrder({
|
|
1234
|
+
return cancelOrder$1({
|
|
1203
1235
|
request,
|
|
1204
1236
|
user: this.user,
|
|
1205
1237
|
starkSigner: this.starkSigner,
|
|
1206
|
-
ordersApi: this.ordersApi,
|
|
1238
|
+
ordersApi: this.immutableXClient.ordersApi,
|
|
1207
1239
|
passportConfig: this.passportConfig,
|
|
1208
1240
|
});
|
|
1209
1241
|
}
|
|
1210
1242
|
createTrade(request) {
|
|
1211
|
-
return createTrade({
|
|
1243
|
+
return createTrade$1({
|
|
1212
1244
|
request,
|
|
1213
1245
|
user: this.user,
|
|
1214
1246
|
starkSigner: this.starkSigner,
|
|
1215
|
-
tradesApi: this.tradesApi,
|
|
1247
|
+
tradesApi: this.immutableXClient.tradesApi,
|
|
1216
1248
|
passportConfig: this.passportConfig,
|
|
1217
1249
|
});
|
|
1218
1250
|
}
|
|
@@ -1221,26 +1253,30 @@ class PassportImxProvider {
|
|
|
1221
1253
|
request,
|
|
1222
1254
|
user: this.user,
|
|
1223
1255
|
starkSigner: this.starkSigner,
|
|
1224
|
-
transfersApi: this.transfersApi,
|
|
1256
|
+
transfersApi: this.immutableXClient.transfersApi,
|
|
1225
1257
|
passportConfig: this.passportConfig,
|
|
1226
1258
|
});
|
|
1227
1259
|
}
|
|
1228
1260
|
exchangeTransfer(request) {
|
|
1229
|
-
return exchangeTransfer({
|
|
1261
|
+
return exchangeTransfer$1({
|
|
1230
1262
|
request,
|
|
1231
1263
|
user: this.user,
|
|
1232
1264
|
starkSigner: this.starkSigner,
|
|
1233
|
-
exchangesApi: this.
|
|
1265
|
+
exchangesApi: this.immutableXClient.exchangeApi,
|
|
1234
1266
|
});
|
|
1235
1267
|
}
|
|
1236
|
-
//
|
|
1268
|
+
// TODO: Remove once implemented
|
|
1269
|
+
// eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
|
|
1237
1270
|
deposit(deposit) {
|
|
1238
1271
|
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
1239
1272
|
}
|
|
1240
|
-
//
|
|
1273
|
+
// TODO: Remove once implemented
|
|
1274
|
+
// eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
|
|
1241
1275
|
prepareWithdrawal(request) {
|
|
1242
1276
|
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
1243
1277
|
}
|
|
1278
|
+
// TODO: Remove once implemented
|
|
1279
|
+
// eslint-disable-next-line class-methods-use-this
|
|
1244
1280
|
completeWithdrawal(
|
|
1245
1281
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1246
1282
|
starkPublicKey,
|
|
@@ -1277,7 +1313,6 @@ class PassportConfiguration {
|
|
|
1277
1313
|
passportDomain;
|
|
1278
1314
|
magicPublishableApiKey;
|
|
1279
1315
|
magicProviderId;
|
|
1280
|
-
imxApiBasePath;
|
|
1281
1316
|
oidcConfiguration;
|
|
1282
1317
|
baseConfig;
|
|
1283
1318
|
constructor({ baseConfig, overrides, ...oidcConfiguration }) {
|
|
@@ -1295,33 +1330,30 @@ class PassportConfiguration {
|
|
|
1295
1330
|
'magicPublishableApiKey',
|
|
1296
1331
|
'magicProviderId',
|
|
1297
1332
|
'passportDomain',
|
|
1298
|
-
'imxApiBasePath',
|
|
1299
1333
|
], 'overrides');
|
|
1300
1334
|
this.network = overrides.network;
|
|
1301
1335
|
this.authenticationDomain = overrides.authenticationDomain;
|
|
1302
1336
|
this.passportDomain = overrides.passportDomain;
|
|
1303
1337
|
this.magicPublishableApiKey = overrides.magicPublishableApiKey;
|
|
1304
1338
|
this.magicProviderId = overrides.magicProviderId;
|
|
1305
|
-
this.imxApiBasePath = overrides.imxApiBasePath;
|
|
1306
1339
|
}
|
|
1307
1340
|
else {
|
|
1308
1341
|
switch (baseConfig.environment) {
|
|
1309
|
-
case Environment.
|
|
1310
|
-
this.network = Networks.
|
|
1342
|
+
case Environment.PRODUCTION: {
|
|
1343
|
+
this.network = Networks.PRODUCTION;
|
|
1311
1344
|
this.authenticationDomain = 'https://auth.immutable.com';
|
|
1312
1345
|
this.magicPublishableApiKey = 'pk_live_10F423798A540ED7';
|
|
1313
1346
|
this.magicProviderId = 'fSMzaRQ4O7p4fttl7pCyGVtJS_G70P8SNsLXtPPGHo0=';
|
|
1314
|
-
this.passportDomain = 'https://passport.
|
|
1315
|
-
this.imxApiBasePath = 'https://api.sandbox.x.immutable.com';
|
|
1347
|
+
this.passportDomain = 'https://passport.immutable.com';
|
|
1316
1348
|
break;
|
|
1317
1349
|
}
|
|
1318
|
-
case Environment.
|
|
1319
|
-
|
|
1350
|
+
case Environment.SANDBOX:
|
|
1351
|
+
default: {
|
|
1352
|
+
this.network = Networks.SANDBOX;
|
|
1320
1353
|
this.authenticationDomain = 'https://auth.immutable.com';
|
|
1321
1354
|
this.magicPublishableApiKey = 'pk_live_10F423798A540ED7';
|
|
1322
1355
|
this.magicProviderId = 'fSMzaRQ4O7p4fttl7pCyGVtJS_G70P8SNsLXtPPGHo0=';
|
|
1323
|
-
this.passportDomain = 'https://passport.immutable.com';
|
|
1324
|
-
this.imxApiBasePath = 'https://api.x.immutable.com';
|
|
1356
|
+
this.passportDomain = 'https://passport.sandbox.immutable.com';
|
|
1325
1357
|
break;
|
|
1326
1358
|
}
|
|
1327
1359
|
}
|
|
@@ -1329,12 +1361,12 @@ class PassportConfiguration {
|
|
|
1329
1361
|
}
|
|
1330
1362
|
}
|
|
1331
1363
|
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
};
|
|
1364
|
+
// TODO: remove this eslint disable once we have a better solution
|
|
1365
|
+
// eslint-disable-next-line max-len
|
|
1366
|
+
const getStarkSigner = async (signer) => withPassportError(async () => {
|
|
1367
|
+
const privateKey = await generateLegacyStarkPrivateKey(signer);
|
|
1368
|
+
return createStarkSigner(privateKey);
|
|
1369
|
+
}, PassportErrorType.WALLET_CONNECTION_ERROR);
|
|
1338
1370
|
|
|
1339
1371
|
async function registerPassport({ ethSigner, starkSigner, usersApi }, authorization) {
|
|
1340
1372
|
return withPassportError(async () => {
|
|
@@ -1350,7 +1382,7 @@ async function registerPassport({ ethSigner, starkSigner, usersApi }, authorizat
|
|
|
1350
1382
|
const ethSignature = await signRaw(signableMessage, ethSigner);
|
|
1351
1383
|
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
1352
1384
|
const response = await usersApi.registerPassportUser({
|
|
1353
|
-
authorization: `Bearer
|
|
1385
|
+
authorization: `Bearer ${authorization}`,
|
|
1354
1386
|
registerPassportUserRequest: {
|
|
1355
1387
|
eth_signature: ethSignature,
|
|
1356
1388
|
ether_key: userAddress,
|
|
@@ -1362,15 +1394,20 @@ async function registerPassport({ ethSigner, starkSigner, usersApi }, authorizat
|
|
|
1362
1394
|
}, PassportErrorType.USER_REGISTRATION_ERROR);
|
|
1363
1395
|
}
|
|
1364
1396
|
|
|
1397
|
+
// TODO: Remove this once the dependency has been added
|
|
1365
1398
|
class Passport {
|
|
1366
1399
|
authManager;
|
|
1367
1400
|
magicAdapter;
|
|
1368
1401
|
config;
|
|
1402
|
+
immutableXClient;
|
|
1369
1403
|
constructor(passportModuleConfiguration) {
|
|
1370
|
-
|
|
1371
|
-
this.config = passportConfiguration;
|
|
1404
|
+
this.config = new PassportConfiguration(passportModuleConfiguration);
|
|
1372
1405
|
this.authManager = new AuthManager(this.config);
|
|
1373
1406
|
this.magicAdapter = new MagicAdapter(this.config);
|
|
1407
|
+
this.immutableXClient = passportModuleConfiguration.overrides?.immutableXClient
|
|
1408
|
+
|| new ImmutableXClient({
|
|
1409
|
+
baseConfig: passportModuleConfiguration.baseConfig,
|
|
1410
|
+
});
|
|
1374
1411
|
}
|
|
1375
1412
|
async getImxProvider(user) {
|
|
1376
1413
|
if (!user || !user.idToken) {
|
|
@@ -1385,6 +1422,7 @@ class Passport {
|
|
|
1385
1422
|
user: updatedUser,
|
|
1386
1423
|
starkSigner,
|
|
1387
1424
|
passportConfig: this.config,
|
|
1425
|
+
immutableXClient: this.immutableXClient,
|
|
1388
1426
|
});
|
|
1389
1427
|
}
|
|
1390
1428
|
const userWithEtherKey = user;
|
|
@@ -1392,6 +1430,7 @@ class Passport {
|
|
|
1392
1430
|
user: userWithEtherKey,
|
|
1393
1431
|
starkSigner,
|
|
1394
1432
|
passportConfig: this.config,
|
|
1433
|
+
immutableXClient: this.immutableXClient,
|
|
1395
1434
|
});
|
|
1396
1435
|
}
|
|
1397
1436
|
async connectImxSilent() {
|
|
@@ -1424,14 +1463,10 @@ class Passport {
|
|
|
1424
1463
|
return user?.accessToken;
|
|
1425
1464
|
}
|
|
1426
1465
|
async registerUser(userAdminKeySigner, starkSigner, jwt) {
|
|
1427
|
-
const configuration = new Configuration({
|
|
1428
|
-
basePath: this.config.imxApiBasePath,
|
|
1429
|
-
});
|
|
1430
|
-
const usersApi = new UsersApi(configuration);
|
|
1431
1466
|
await registerPassport({
|
|
1432
1467
|
ethSigner: userAdminKeySigner,
|
|
1433
1468
|
starkSigner,
|
|
1434
|
-
usersApi,
|
|
1469
|
+
usersApi: this.immutableXClient.usersApi,
|
|
1435
1470
|
}, jwt);
|
|
1436
1471
|
const updatedUser = await this.authManager.requestRefreshTokenAfterRegistration();
|
|
1437
1472
|
if (!updatedUser) {
|
|
@@ -1441,4 +1476,1926 @@ class Passport {
|
|
|
1441
1476
|
}
|
|
1442
1477
|
}
|
|
1443
1478
|
|
|
1444
|
-
|
|
1479
|
+
function isChainValid(chainID, config) {
|
|
1480
|
+
return chainID === config.ethConfiguration.chainID;
|
|
1481
|
+
}
|
|
1482
|
+
async function validateChain(signer, config) {
|
|
1483
|
+
const chainID = await signer.getChainId();
|
|
1484
|
+
if (!isChainValid(chainID, config))
|
|
1485
|
+
throw new Error('The wallet used for this operation is not connected to the correct network.');
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
async function transfer({ signers: { ethSigner, starkSigner }, request, config, }) {
|
|
1489
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
1490
|
+
const ethAddress = await ethSigner.getAddress();
|
|
1491
|
+
const transfersApi = new TransfersApi(config.immutableXConfig.apiConfiguration);
|
|
1492
|
+
const transferAmount = request.type === 'ERC721' ? '1' : request.amount;
|
|
1493
|
+
const signableResult = await transfersApi.getSignableTransferV1({
|
|
1494
|
+
getSignableTransferRequest: {
|
|
1495
|
+
sender: ethAddress,
|
|
1496
|
+
token: convertToSignableToken(request),
|
|
1497
|
+
amount: transferAmount,
|
|
1498
|
+
receiver: request.receiver,
|
|
1499
|
+
},
|
|
1500
|
+
});
|
|
1501
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
1502
|
+
const ethSignature = await signRaw(signableMessage, ethSigner);
|
|
1503
|
+
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
1504
|
+
const transferSigningParams = {
|
|
1505
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1506
|
+
sender_stark_key: signableResult.data.sender_stark_key,
|
|
1507
|
+
sender_vault_id: signableResult.data.sender_vault_id,
|
|
1508
|
+
receiver_stark_key: signableResult.data.receiver_stark_key,
|
|
1509
|
+
receiver_vault_id: signableResult.data.receiver_vault_id,
|
|
1510
|
+
asset_id: signableResult.data.asset_id,
|
|
1511
|
+
amount: signableResult.data.amount,
|
|
1512
|
+
nonce: signableResult.data.nonce,
|
|
1513
|
+
expiration_timestamp: signableResult.data.expiration_timestamp,
|
|
1514
|
+
stark_signature: starkSignature,
|
|
1515
|
+
};
|
|
1516
|
+
const response = await transfersApi.createTransferV1({
|
|
1517
|
+
createTransferRequest: transferSigningParams,
|
|
1518
|
+
xImxEthAddress: ethAddress,
|
|
1519
|
+
xImxEthSignature: ethSignature,
|
|
1520
|
+
});
|
|
1521
|
+
return {
|
|
1522
|
+
sent_signature: response?.data.sent_signature,
|
|
1523
|
+
status: response?.data.status?.toString(),
|
|
1524
|
+
time: response?.data.time,
|
|
1525
|
+
transfer_id: response?.data.transfer_id,
|
|
1526
|
+
};
|
|
1527
|
+
}
|
|
1528
|
+
async function batchTransfer({ signers: { ethSigner, starkSigner }, request, config, }) {
|
|
1529
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
1530
|
+
const ethAddress = await ethSigner.getAddress();
|
|
1531
|
+
const transfersApi = new TransfersApi(config.immutableXConfig.apiConfiguration);
|
|
1532
|
+
const signableRequests = request.map((nftTransfer) => {
|
|
1533
|
+
return {
|
|
1534
|
+
amount: '1',
|
|
1535
|
+
token: convertToSignableToken({
|
|
1536
|
+
type: 'ERC721',
|
|
1537
|
+
tokenId: nftTransfer.tokenId,
|
|
1538
|
+
tokenAddress: nftTransfer.tokenAddress,
|
|
1539
|
+
}),
|
|
1540
|
+
receiver: nftTransfer.receiver,
|
|
1541
|
+
};
|
|
1542
|
+
});
|
|
1543
|
+
const signableResult = await transfersApi.getSignableTransfer({
|
|
1544
|
+
getSignableTransferRequestV2: {
|
|
1545
|
+
sender_ether_key: ethAddress,
|
|
1546
|
+
signable_requests: signableRequests,
|
|
1547
|
+
},
|
|
1548
|
+
});
|
|
1549
|
+
const signableMessage = signableResult.data.signable_message;
|
|
1550
|
+
if (signableMessage === undefined) {
|
|
1551
|
+
throw new Error('Invalid response from Signable registration offchain');
|
|
1552
|
+
}
|
|
1553
|
+
const ethSignature = await signRaw(signableMessage, ethSigner);
|
|
1554
|
+
const requests = [];
|
|
1555
|
+
for (const resp of signableResult.data.signable_responses) {
|
|
1556
|
+
const starkSignature = await starkSigner.signMessage(resp.payload_hash);
|
|
1557
|
+
const req = {
|
|
1558
|
+
sender_vault_id: resp.sender_vault_id,
|
|
1559
|
+
receiver_stark_key: resp.receiver_stark_key,
|
|
1560
|
+
receiver_vault_id: resp.receiver_vault_id,
|
|
1561
|
+
asset_id: resp.asset_id,
|
|
1562
|
+
amount: resp.amount,
|
|
1563
|
+
nonce: resp.nonce,
|
|
1564
|
+
expiration_timestamp: resp.expiration_timestamp,
|
|
1565
|
+
stark_signature: starkSignature,
|
|
1566
|
+
};
|
|
1567
|
+
requests.push(req);
|
|
1568
|
+
}
|
|
1569
|
+
// TODO: throw error on missing payload hash?
|
|
1570
|
+
const transferSigningParams = {
|
|
1571
|
+
sender_stark_key: signableResult.data.sender_stark_key,
|
|
1572
|
+
requests,
|
|
1573
|
+
};
|
|
1574
|
+
const response = await transfersApi.createTransfer({
|
|
1575
|
+
createTransferRequestV2: transferSigningParams,
|
|
1576
|
+
xImxEthAddress: ethAddress,
|
|
1577
|
+
xImxEthSignature: ethSignature,
|
|
1578
|
+
});
|
|
1579
|
+
return {
|
|
1580
|
+
transfer_ids: response?.data.transfer_ids,
|
|
1581
|
+
};
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
async function createOrder({ signers, request, config, }) {
|
|
1585
|
+
await validateChain(signers.ethSigner, config.immutableXConfig);
|
|
1586
|
+
const ethAddress = await signers.ethSigner.getAddress();
|
|
1587
|
+
const ordersApi = new OrdersApi(config.immutableXConfig.apiConfiguration);
|
|
1588
|
+
const amountSell = request.sell.type === 'ERC721' ? '1' : request.sell.amount;
|
|
1589
|
+
const amountBuy = request.buy.type === 'ERC721' ? '1' : request.buy.amount;
|
|
1590
|
+
const getSignableOrderRequest = {
|
|
1591
|
+
user: ethAddress,
|
|
1592
|
+
amount_buy: amountBuy,
|
|
1593
|
+
token_buy: convertToSignableToken(request.buy),
|
|
1594
|
+
amount_sell: amountSell,
|
|
1595
|
+
token_sell: convertToSignableToken(request.sell),
|
|
1596
|
+
fees: request.fees,
|
|
1597
|
+
expiration_timestamp: request.expiration_timestamp,
|
|
1598
|
+
};
|
|
1599
|
+
const getSignableOrderResponse = await ordersApi.getSignableOrder({
|
|
1600
|
+
getSignableOrderRequestV3: getSignableOrderRequest,
|
|
1601
|
+
});
|
|
1602
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = getSignableOrderResponse.data;
|
|
1603
|
+
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
1604
|
+
const starkSignature = await signers.starkSigner.signMessage(payloadHash);
|
|
1605
|
+
const resp = getSignableOrderResponse.data;
|
|
1606
|
+
const orderParams = {
|
|
1607
|
+
createOrderRequest: {
|
|
1608
|
+
amount_buy: resp.amount_buy,
|
|
1609
|
+
amount_sell: resp.amount_sell,
|
|
1610
|
+
asset_id_buy: resp.asset_id_buy,
|
|
1611
|
+
asset_id_sell: resp.asset_id_sell,
|
|
1612
|
+
expiration_timestamp: resp.expiration_timestamp,
|
|
1613
|
+
include_fees: true,
|
|
1614
|
+
fees: request.fees,
|
|
1615
|
+
nonce: resp.nonce,
|
|
1616
|
+
stark_key: resp.stark_key,
|
|
1617
|
+
stark_signature: starkSignature,
|
|
1618
|
+
vault_id_buy: resp.vault_id_buy,
|
|
1619
|
+
vault_id_sell: resp.vault_id_sell,
|
|
1620
|
+
},
|
|
1621
|
+
xImxEthAddress: ethAddress,
|
|
1622
|
+
xImxEthSignature: ethSignature,
|
|
1623
|
+
};
|
|
1624
|
+
const createOrderResponse = await ordersApi.createOrder(orderParams);
|
|
1625
|
+
return {
|
|
1626
|
+
...createOrderResponse.data,
|
|
1627
|
+
};
|
|
1628
|
+
}
|
|
1629
|
+
async function cancelOrder({ signers, request, config, }) {
|
|
1630
|
+
const ordersApi = new OrdersApi(config.immutableXConfig.apiConfiguration);
|
|
1631
|
+
const getSignableCancelOrderResponse = await ordersApi.getSignableCancelOrder({
|
|
1632
|
+
getSignableCancelOrderRequest: {
|
|
1633
|
+
order_id: request.order_id,
|
|
1634
|
+
},
|
|
1635
|
+
});
|
|
1636
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = getSignableCancelOrderResponse.data;
|
|
1637
|
+
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
1638
|
+
const starkSignature = await signers.starkSigner.signMessage(payloadHash);
|
|
1639
|
+
const ethAddress = await signers.ethSigner.getAddress();
|
|
1640
|
+
const cancelOrderResponse = await ordersApi.cancelOrder({
|
|
1641
|
+
id: request.order_id.toString(),
|
|
1642
|
+
cancelOrderRequest: {
|
|
1643
|
+
order_id: request.order_id,
|
|
1644
|
+
stark_signature: starkSignature,
|
|
1645
|
+
},
|
|
1646
|
+
xImxEthAddress: ethAddress,
|
|
1647
|
+
xImxEthSignature: ethSignature,
|
|
1648
|
+
});
|
|
1649
|
+
return {
|
|
1650
|
+
order_id: cancelOrderResponse.data.order_id,
|
|
1651
|
+
status: cancelOrderResponse.data.status,
|
|
1652
|
+
};
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
async function registerOffchain(signers, config) {
|
|
1656
|
+
await validateChain(signers.ethSigner, config.immutableXConfig);
|
|
1657
|
+
const usersApi = new UsersApi(config.immutableXConfig.apiConfiguration);
|
|
1658
|
+
const userAddress = await signers.ethSigner.getAddress();
|
|
1659
|
+
const starkPublicKey = await signers.starkSigner.getAddress();
|
|
1660
|
+
const signableResult = await usersApi.getSignableRegistrationOffchain({
|
|
1661
|
+
getSignableRegistrationRequest: {
|
|
1662
|
+
ether_key: userAddress,
|
|
1663
|
+
stark_key: starkPublicKey,
|
|
1664
|
+
},
|
|
1665
|
+
});
|
|
1666
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
1667
|
+
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
1668
|
+
const starkSignature = await signers.starkSigner.signMessage(payloadHash);
|
|
1669
|
+
const registeredUser = await usersApi.registerUser({
|
|
1670
|
+
registerUserRequest: {
|
|
1671
|
+
eth_signature: ethSignature,
|
|
1672
|
+
ether_key: userAddress,
|
|
1673
|
+
stark_signature: starkSignature,
|
|
1674
|
+
stark_key: starkPublicKey,
|
|
1675
|
+
},
|
|
1676
|
+
});
|
|
1677
|
+
return registeredUser.data;
|
|
1678
|
+
}
|
|
1679
|
+
async function isRegisteredOnChain(starkPublicKey, ethSigner, config) {
|
|
1680
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
1681
|
+
const registrationContract = Contracts.Registration.connect(config.immutableXConfig.ethConfiguration.registrationContractAddress, ethSigner);
|
|
1682
|
+
try {
|
|
1683
|
+
return await registrationContract.isRegistered(starkPublicKey);
|
|
1684
|
+
}
|
|
1685
|
+
catch (ex) {
|
|
1686
|
+
if (ex.reason === 'USER_UNREGISTERED') {
|
|
1687
|
+
return false;
|
|
1688
|
+
}
|
|
1689
|
+
throw ex;
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
async function getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi) {
|
|
1693
|
+
const response = await usersApi.getSignableRegistration({
|
|
1694
|
+
getSignableRegistrationRequest: {
|
|
1695
|
+
ether_key: etherKey,
|
|
1696
|
+
stark_key: starkPublicKey,
|
|
1697
|
+
},
|
|
1698
|
+
});
|
|
1699
|
+
return {
|
|
1700
|
+
operator_signature: response.data.operator_signature,
|
|
1701
|
+
payload_hash: response.data.payload_hash,
|
|
1702
|
+
};
|
|
1703
|
+
}
|
|
1704
|
+
|
|
1705
|
+
const assertIsDefined = (value) => {
|
|
1706
|
+
if (value !== undefined)
|
|
1707
|
+
return value;
|
|
1708
|
+
throw new Error('undefined field exception');
|
|
1709
|
+
};
|
|
1710
|
+
async function prepareWithdrawalAction(params) {
|
|
1711
|
+
const { signers: { ethSigner, starkSigner }, type, config, } = params;
|
|
1712
|
+
await validateChain(ethSigner, params.config);
|
|
1713
|
+
const withdrawalsApi = new WithdrawalsApi(config.apiConfiguration);
|
|
1714
|
+
const withdrawalAmount = type === 'ERC721' ? '1' : params.amount;
|
|
1715
|
+
const signableWithdrawalResult = await withdrawalsApi.getSignableWithdrawal({
|
|
1716
|
+
getSignableWithdrawalRequest: {
|
|
1717
|
+
user: await ethSigner.getAddress(),
|
|
1718
|
+
token: convertToSignableToken(params),
|
|
1719
|
+
amount: withdrawalAmount,
|
|
1720
|
+
},
|
|
1721
|
+
});
|
|
1722
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = signableWithdrawalResult.data;
|
|
1723
|
+
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
1724
|
+
const { ethAddress, ethSignature } = await signMessage(signableMessage, ethSigner);
|
|
1725
|
+
const prepareWithdrawalResponse = await withdrawalsApi.createWithdrawal({
|
|
1726
|
+
createWithdrawalRequest: {
|
|
1727
|
+
stark_key: assertIsDefined(signableWithdrawalResult.data.stark_key),
|
|
1728
|
+
amount: withdrawalAmount,
|
|
1729
|
+
asset_id: assertIsDefined(signableWithdrawalResult.data.asset_id),
|
|
1730
|
+
vault_id: assertIsDefined(signableWithdrawalResult.data.vault_id),
|
|
1731
|
+
nonce: assertIsDefined(signableWithdrawalResult.data.nonce),
|
|
1732
|
+
stark_signature: starkSignature,
|
|
1733
|
+
},
|
|
1734
|
+
xImxEthAddress: ethAddress,
|
|
1735
|
+
xImxEthSignature: ethSignature,
|
|
1736
|
+
});
|
|
1737
|
+
return prepareWithdrawalResponse.data;
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
async function getEncodeAssetInfo(assetType, tokenType, config, tokenData) {
|
|
1741
|
+
const encodingApi = new EncodingApi(config.apiConfiguration);
|
|
1742
|
+
const result = await encodingApi.encodeAsset({
|
|
1743
|
+
assetType,
|
|
1744
|
+
encodeAssetRequest: {
|
|
1745
|
+
token: {
|
|
1746
|
+
type: tokenType,
|
|
1747
|
+
...(tokenData && { data: tokenData }),
|
|
1748
|
+
},
|
|
1749
|
+
},
|
|
1750
|
+
});
|
|
1751
|
+
return result.data;
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
async function executeRegisterAndWithdrawERC20({ ethSigner, assetType, starkPublicKey, config, }) {
|
|
1755
|
+
const etherKey = await ethSigner.getAddress();
|
|
1756
|
+
const imxConfig = config.immutableXConfig;
|
|
1757
|
+
const usersApi = new UsersApi(imxConfig.apiConfiguration);
|
|
1758
|
+
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
1759
|
+
const contract = Contracts.Registration.connect(config.immutableXConfig.ethConfiguration.registrationContractAddress, ethSigner);
|
|
1760
|
+
const populatedTransaction = await contract.populateTransaction.registerAndWithdraw(etherKey, starkPublicKey, signableResult.operator_signature, assetType);
|
|
1761
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
1762
|
+
}
|
|
1763
|
+
async function executeWithdrawERC20(ethSigner, assetType, starkPublicKey, config) {
|
|
1764
|
+
const contract = Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
1765
|
+
const populatedTransaction = await contract.populateTransaction.withdraw(starkPublicKey, assetType);
|
|
1766
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
1767
|
+
}
|
|
1768
|
+
async function completeERC20WithdrawalAction({ ethSigner, starkPublicKey, token, config, }) {
|
|
1769
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
1770
|
+
const imxConfig = config.immutableXConfig;
|
|
1771
|
+
const assetType = await getEncodeAssetInfo('asset', 'ERC20', imxConfig, {
|
|
1772
|
+
token_address: token.tokenAddress,
|
|
1773
|
+
});
|
|
1774
|
+
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
1775
|
+
if (!isRegistered) {
|
|
1776
|
+
return executeRegisterAndWithdrawERC20({
|
|
1777
|
+
ethSigner,
|
|
1778
|
+
assetType: assetType.asset_type,
|
|
1779
|
+
starkPublicKey,
|
|
1780
|
+
config,
|
|
1781
|
+
});
|
|
1782
|
+
}
|
|
1783
|
+
else {
|
|
1784
|
+
return executeWithdrawERC20(ethSigner, assetType.asset_type, starkPublicKey, imxConfig);
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
async function executeWithdrawMintableERC721(ethSigner, assetType, starkPublicKey, mintingBlob, config) {
|
|
1789
|
+
const contract = Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
1790
|
+
const populatedTransaction = await contract.populateTransaction.withdrawAndMint(starkPublicKey, assetType, mintingBlob);
|
|
1791
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
1792
|
+
}
|
|
1793
|
+
async function executeRegisterAndWithdrawMintableERC721(ethSigner, assetType, starkPublicKey, mintingBlob, config) {
|
|
1794
|
+
const etherKey = await ethSigner.getAddress();
|
|
1795
|
+
const usersApi = new UsersApi(config.apiConfiguration);
|
|
1796
|
+
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
1797
|
+
const contract = Contracts.Registration.connect(config.ethConfiguration.registrationContractAddress, ethSigner);
|
|
1798
|
+
const populatedTransaction = await contract.populateTransaction.regsiterAndWithdrawAndMint(etherKey, starkPublicKey, signableResult.operator_signature, assetType, mintingBlob);
|
|
1799
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
1800
|
+
}
|
|
1801
|
+
function getMintingBlob(token) {
|
|
1802
|
+
const id = token.data.id;
|
|
1803
|
+
const blueprint = token.data.blueprint || '';
|
|
1804
|
+
return encUtils.sanitizeHex(encUtils.utf8ToHex(`{${id}}:{${blueprint}}`));
|
|
1805
|
+
}
|
|
1806
|
+
async function completeMintableERC721Withdrawal(ethSigner, starkPublicKey, token, config) {
|
|
1807
|
+
const imxConfig = config.immutableXConfig;
|
|
1808
|
+
const assetType = await getEncodeAssetInfo('mintable-asset', 'ERC721', imxConfig, {
|
|
1809
|
+
id: token.data.id,
|
|
1810
|
+
token_address: token.data.tokenAddress,
|
|
1811
|
+
...(token.data.blueprint && { blueprint: token.data.blueprint }),
|
|
1812
|
+
});
|
|
1813
|
+
const mintingBlob = getMintingBlob(token);
|
|
1814
|
+
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
1815
|
+
if (!isRegistered) {
|
|
1816
|
+
return executeRegisterAndWithdrawMintableERC721(ethSigner, assetType.asset_type, starkPublicKey, mintingBlob, imxConfig);
|
|
1817
|
+
}
|
|
1818
|
+
else {
|
|
1819
|
+
return executeWithdrawMintableERC721(ethSigner, assetType.asset_type, starkPublicKey, mintingBlob, imxConfig);
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
async function executeRegisterAndWithdrawERC721(ethSigner, assetType, starkPublicKey, tokenId, config) {
|
|
1823
|
+
const etherKey = await ethSigner.getAddress();
|
|
1824
|
+
const usersApi = new UsersApi(config.apiConfiguration);
|
|
1825
|
+
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
1826
|
+
const contract = Contracts.Registration.connect(config.ethConfiguration.registrationContractAddress, ethSigner);
|
|
1827
|
+
const populatedTransaction = await contract.populateTransaction.registerAndWithdrawNft(etherKey, starkPublicKey, signableResult.operator_signature, assetType, tokenId);
|
|
1828
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
1829
|
+
}
|
|
1830
|
+
async function executeWithdrawERC721(ethSigner, assetType, starkPublicKey, tokenId, config) {
|
|
1831
|
+
const contract = Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
1832
|
+
const populatedTransaction = await contract.populateTransaction.withdrawNft(starkPublicKey, assetType, tokenId);
|
|
1833
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
1834
|
+
}
|
|
1835
|
+
async function completeERC721Withdrawal(ethSigner, starkPublicKey, token, config) {
|
|
1836
|
+
const imxConfig = config.immutableXConfig;
|
|
1837
|
+
const assetType = await getEncodeAssetInfo('asset', 'ERC721', imxConfig, {
|
|
1838
|
+
token_id: token.tokenId,
|
|
1839
|
+
token_address: token.tokenAddress,
|
|
1840
|
+
});
|
|
1841
|
+
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
1842
|
+
if (!isRegistered) {
|
|
1843
|
+
return executeRegisterAndWithdrawERC721(ethSigner, assetType.asset_type, starkPublicKey, token.tokenId, imxConfig);
|
|
1844
|
+
}
|
|
1845
|
+
else {
|
|
1846
|
+
return executeWithdrawERC721(ethSigner, assetType.asset_type, starkPublicKey, token.tokenId, imxConfig);
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
async function completeERC721WithdrawalAction({ ethSigner, starkPublicKey, token, config, }) {
|
|
1850
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
1851
|
+
const tokenAddress = token.tokenAddress;
|
|
1852
|
+
const tokenId = token.tokenId;
|
|
1853
|
+
const imxConfig = config.immutableXConfig;
|
|
1854
|
+
const mintsApi = new MintsApi(imxConfig.apiConfiguration);
|
|
1855
|
+
return await mintsApi
|
|
1856
|
+
.getMintableTokenDetailsByClientTokenId({
|
|
1857
|
+
tokenAddress,
|
|
1858
|
+
tokenId,
|
|
1859
|
+
})
|
|
1860
|
+
.then((mintableToken) => completeMintableERC721Withdrawal(ethSigner, starkPublicKey, {
|
|
1861
|
+
type: 'ERC721',
|
|
1862
|
+
data: {
|
|
1863
|
+
id: tokenId,
|
|
1864
|
+
tokenAddress: tokenAddress,
|
|
1865
|
+
blueprint: mintableToken.data.blueprint,
|
|
1866
|
+
},
|
|
1867
|
+
}, config))
|
|
1868
|
+
.catch((error) => {
|
|
1869
|
+
if (error.response?.status === 404) {
|
|
1870
|
+
// token is already minted on L1
|
|
1871
|
+
return completeERC721Withdrawal(ethSigner, starkPublicKey, token, config);
|
|
1872
|
+
}
|
|
1873
|
+
throw error; // unable to recover from any other kind of error
|
|
1874
|
+
});
|
|
1875
|
+
}
|
|
1876
|
+
|
|
1877
|
+
async function executeRegisterAndWithdrawEth(ethSigner, assetType, starkPublicKey, config) {
|
|
1878
|
+
const etherKey = await ethSigner.getAddress();
|
|
1879
|
+
const usersApi = new UsersApi(config.apiConfiguration);
|
|
1880
|
+
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
1881
|
+
const contract = Contracts.Registration.connect(config.ethConfiguration.registrationContractAddress, ethSigner);
|
|
1882
|
+
const populatedTransaction = await contract.populateTransaction.registerAndWithdraw(etherKey, starkPublicKey, signableResult.operator_signature, assetType);
|
|
1883
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
1884
|
+
}
|
|
1885
|
+
async function executeWithdrawEth(ethSigner, assetType, starkPublicKey, config) {
|
|
1886
|
+
const contract = Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
1887
|
+
const populatedTransaction = await contract.populateTransaction.withdraw(starkPublicKey, assetType);
|
|
1888
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
1889
|
+
}
|
|
1890
|
+
async function completeEthWithdrawalAction({ ethSigner, starkPublicKey, config, }) {
|
|
1891
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
1892
|
+
const imxConfig = config.immutableXConfig;
|
|
1893
|
+
const assetType = await getEncodeAssetInfo('asset', 'ETH', imxConfig);
|
|
1894
|
+
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
1895
|
+
if (!isRegistered) {
|
|
1896
|
+
return executeRegisterAndWithdrawEth(ethSigner, assetType.asset_type, starkPublicKey, imxConfig);
|
|
1897
|
+
}
|
|
1898
|
+
else {
|
|
1899
|
+
return executeWithdrawEth(ethSigner, assetType.asset_type, starkPublicKey, imxConfig);
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
|
|
1903
|
+
async function prepareWithdrawal({ signers, withdrawal, config, }) {
|
|
1904
|
+
return prepareWithdrawalAction({
|
|
1905
|
+
signers,
|
|
1906
|
+
config: config.immutableXConfig,
|
|
1907
|
+
...withdrawal,
|
|
1908
|
+
});
|
|
1909
|
+
}
|
|
1910
|
+
async function completeWithdrawal({ signers: { ethSigner }, starkPublicKey, token, config, }) {
|
|
1911
|
+
switch (token.type) {
|
|
1912
|
+
case 'ETH':
|
|
1913
|
+
return completeEthWithdrawalAction({ ethSigner, starkPublicKey, config });
|
|
1914
|
+
case 'ERC20':
|
|
1915
|
+
return completeERC20WithdrawalAction({
|
|
1916
|
+
ethSigner,
|
|
1917
|
+
starkPublicKey,
|
|
1918
|
+
token,
|
|
1919
|
+
config,
|
|
1920
|
+
});
|
|
1921
|
+
case 'ERC721':
|
|
1922
|
+
return completeERC721WithdrawalAction({
|
|
1923
|
+
ethSigner,
|
|
1924
|
+
starkPublicKey,
|
|
1925
|
+
token,
|
|
1926
|
+
config,
|
|
1927
|
+
});
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
async function createTrade({ signers: { ethSigner, starkSigner }, request, config, }) {
|
|
1932
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
1933
|
+
const ethAddress = await ethSigner.getAddress();
|
|
1934
|
+
const tradesApi = new TradesApi(config.immutableXConfig.apiConfiguration);
|
|
1935
|
+
const signableResult = await tradesApi.getSignableTrade({
|
|
1936
|
+
getSignableTradeRequest: {
|
|
1937
|
+
user: ethAddress,
|
|
1938
|
+
order_id: request.order_id,
|
|
1939
|
+
fees: request.fees,
|
|
1940
|
+
},
|
|
1941
|
+
});
|
|
1942
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
1943
|
+
const ethSignature = await signRaw(signableMessage, ethSigner);
|
|
1944
|
+
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
1945
|
+
const createTradeResponse = await tradesApi.createTrade({
|
|
1946
|
+
createTradeRequest: {
|
|
1947
|
+
amount_buy: signableResult.data.amount_buy,
|
|
1948
|
+
amount_sell: signableResult.data.amount_sell,
|
|
1949
|
+
asset_id_buy: signableResult.data.asset_id_buy,
|
|
1950
|
+
asset_id_sell: signableResult.data.asset_id_sell,
|
|
1951
|
+
expiration_timestamp: signableResult.data.expiration_timestamp,
|
|
1952
|
+
fee_info: signableResult.data.fee_info,
|
|
1953
|
+
fees: request.fees,
|
|
1954
|
+
include_fees: true,
|
|
1955
|
+
nonce: signableResult.data.nonce,
|
|
1956
|
+
order_id: request.order_id,
|
|
1957
|
+
stark_key: signableResult.data.stark_key,
|
|
1958
|
+
vault_id_buy: signableResult.data.vault_id_buy,
|
|
1959
|
+
vault_id_sell: signableResult.data.vault_id_sell,
|
|
1960
|
+
stark_signature: starkSignature,
|
|
1961
|
+
},
|
|
1962
|
+
xImxEthAddress: ethAddress,
|
|
1963
|
+
xImxEthSignature: ethSignature,
|
|
1964
|
+
});
|
|
1965
|
+
return createTradeResponse.data;
|
|
1966
|
+
}
|
|
1967
|
+
|
|
1968
|
+
async function depositEth({ signers: { ethSigner }, deposit, config, }) {
|
|
1969
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
1970
|
+
const user = await ethSigner.getAddress();
|
|
1971
|
+
const data = {
|
|
1972
|
+
decimals: 18,
|
|
1973
|
+
};
|
|
1974
|
+
const amount = parseUnits(deposit.amount, 'wei');
|
|
1975
|
+
const imxConfig = config.immutableXConfig;
|
|
1976
|
+
const depositsApi = new DepositsApi(imxConfig.apiConfiguration);
|
|
1977
|
+
const encodingApi = new EncodingApi(imxConfig.apiConfiguration);
|
|
1978
|
+
const usersApi = new UsersApi(imxConfig.apiConfiguration);
|
|
1979
|
+
const getSignableDepositRequest = {
|
|
1980
|
+
user,
|
|
1981
|
+
token: {
|
|
1982
|
+
type: deposit.type,
|
|
1983
|
+
data,
|
|
1984
|
+
},
|
|
1985
|
+
amount: amount.toString(),
|
|
1986
|
+
};
|
|
1987
|
+
const signableDepositResult = await depositsApi.getSignableDeposit({
|
|
1988
|
+
getSignableDepositRequest,
|
|
1989
|
+
});
|
|
1990
|
+
const encodingResult = await encodingApi.encodeAsset({
|
|
1991
|
+
assetType: 'asset',
|
|
1992
|
+
encodeAssetRequest: {
|
|
1993
|
+
token: {
|
|
1994
|
+
type: deposit.type,
|
|
1995
|
+
},
|
|
1996
|
+
},
|
|
1997
|
+
});
|
|
1998
|
+
const assetType = encodingResult.data.asset_type;
|
|
1999
|
+
const starkPublicKey = signableDepositResult.data.stark_key;
|
|
2000
|
+
const vaultId = signableDepositResult.data.vault_id;
|
|
2001
|
+
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
2002
|
+
if (!isRegistered) {
|
|
2003
|
+
return executeRegisterAndDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, imxConfig, usersApi);
|
|
2004
|
+
}
|
|
2005
|
+
else {
|
|
2006
|
+
return executeDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, imxConfig);
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
async function executeRegisterAndDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, config, usersApi) {
|
|
2010
|
+
const etherKey = await ethSigner.getAddress();
|
|
2011
|
+
const coreContract = Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
2012
|
+
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
2013
|
+
const populatedTransaction = await coreContract.populateTransaction.registerAndDepositEth(etherKey, starkPublicKey, signableResult.operator_signature, assetType, vaultId);
|
|
2014
|
+
return ethSigner.sendTransaction({ ...populatedTransaction, value: amount });
|
|
2015
|
+
}
|
|
2016
|
+
async function executeDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, config) {
|
|
2017
|
+
const coreContract = Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
2018
|
+
const populatedTransaction = await coreContract.populateTransaction['deposit(uint256,uint256,uint256)'](starkPublicKey, assetType, vaultId);
|
|
2019
|
+
return ethSigner.sendTransaction({ ...populatedTransaction, value: amount });
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
async function depositERC20({ signers: { ethSigner }, deposit, config, }) {
|
|
2023
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
2024
|
+
const { apiConfiguration, ethConfiguration } = config.immutableXConfig;
|
|
2025
|
+
const user = await ethSigner.getAddress();
|
|
2026
|
+
const tokensApi = new TokensApi(apiConfiguration);
|
|
2027
|
+
const depositsApi = new DepositsApi(apiConfiguration);
|
|
2028
|
+
const encodingApi = new EncodingApi(apiConfiguration);
|
|
2029
|
+
const usersApi = new UsersApi(apiConfiguration);
|
|
2030
|
+
// Get decimals for this specific ERC20
|
|
2031
|
+
const token = await tokensApi.getToken({ address: deposit.tokenAddress });
|
|
2032
|
+
const decimals = parseInt(token.data.decimals);
|
|
2033
|
+
const data = {
|
|
2034
|
+
decimals,
|
|
2035
|
+
token_address: deposit.tokenAddress,
|
|
2036
|
+
};
|
|
2037
|
+
const amount = parseUnits(deposit.amount, 0); // 0 to always use undecimalized value
|
|
2038
|
+
// Approve whether an amount of token from an account can be spent by a third-party account
|
|
2039
|
+
const tokenContract = Contracts.IERC20.connect(deposit.tokenAddress, ethSigner);
|
|
2040
|
+
const approveTransaction = await tokenContract.populateTransaction.approve(ethConfiguration.coreContractAddress, amount);
|
|
2041
|
+
await ethSigner.sendTransaction(approveTransaction);
|
|
2042
|
+
const getSignableDepositRequest = {
|
|
2043
|
+
user,
|
|
2044
|
+
token: {
|
|
2045
|
+
type: deposit.type,
|
|
2046
|
+
data,
|
|
2047
|
+
},
|
|
2048
|
+
amount: amount.toString(),
|
|
2049
|
+
};
|
|
2050
|
+
const signableDepositResult = await depositsApi.getSignableDeposit({
|
|
2051
|
+
getSignableDepositRequest,
|
|
2052
|
+
});
|
|
2053
|
+
// Perform encoding on asset details to get an assetType (required for stark contract request)
|
|
2054
|
+
const encodingResult = await encodingApi.encodeAsset({
|
|
2055
|
+
assetType: 'asset',
|
|
2056
|
+
encodeAssetRequest: {
|
|
2057
|
+
token: {
|
|
2058
|
+
type: deposit.type,
|
|
2059
|
+
data: {
|
|
2060
|
+
token_address: deposit.tokenAddress,
|
|
2061
|
+
},
|
|
2062
|
+
},
|
|
2063
|
+
},
|
|
2064
|
+
});
|
|
2065
|
+
const assetType = encodingResult.data.asset_type;
|
|
2066
|
+
const starkPublicKey = signableDepositResult.data.stark_key;
|
|
2067
|
+
const vaultId = signableDepositResult.data.vault_id;
|
|
2068
|
+
const quantizedAmount = BigNumber.from(signableDepositResult.data.amount);
|
|
2069
|
+
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
2070
|
+
if (!isRegistered) {
|
|
2071
|
+
return executeRegisterAndDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, ethConfiguration, usersApi);
|
|
2072
|
+
}
|
|
2073
|
+
else {
|
|
2074
|
+
return executeDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, ethConfiguration);
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
async function executeDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, config) {
|
|
2078
|
+
const coreContract = Contracts.Core.connect(config.coreContractAddress, ethSigner);
|
|
2079
|
+
const populatedTransaction = await coreContract.populateTransaction.depositERC20(starkPublicKey, assetType, vaultId, quantizedAmount);
|
|
2080
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
2081
|
+
}
|
|
2082
|
+
async function executeRegisterAndDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, config, usersApi) {
|
|
2083
|
+
const etherKey = await ethSigner.getAddress();
|
|
2084
|
+
const coreContract = Contracts.Core.connect(config.coreContractAddress, ethSigner);
|
|
2085
|
+
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
2086
|
+
const populatedTransaction = await coreContract.populateTransaction.registerAndDepositERC20(etherKey, starkPublicKey, signableResult.operator_signature, assetType, vaultId, quantizedAmount);
|
|
2087
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
2088
|
+
}
|
|
2089
|
+
|
|
2090
|
+
async function depositERC721({ signers: { ethSigner }, deposit, config, }) {
|
|
2091
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
2092
|
+
const user = await ethSigner.getAddress();
|
|
2093
|
+
const { immutableXConfig } = config;
|
|
2094
|
+
const depositsApi = new DepositsApi(immutableXConfig.apiConfiguration);
|
|
2095
|
+
const encodingApi = new EncodingApi(immutableXConfig.apiConfiguration);
|
|
2096
|
+
const usersApi = new UsersApi(immutableXConfig.apiConfiguration);
|
|
2097
|
+
const data = {
|
|
2098
|
+
token_address: deposit.tokenAddress,
|
|
2099
|
+
token_id: deposit.tokenId,
|
|
2100
|
+
};
|
|
2101
|
+
const amount = '1';
|
|
2102
|
+
const getSignableDepositRequest = {
|
|
2103
|
+
user,
|
|
2104
|
+
token: {
|
|
2105
|
+
type: deposit.type,
|
|
2106
|
+
data,
|
|
2107
|
+
},
|
|
2108
|
+
amount: amount.toString(),
|
|
2109
|
+
};
|
|
2110
|
+
const signableDepositResult = await depositsApi.getSignableDeposit({
|
|
2111
|
+
getSignableDepositRequest,
|
|
2112
|
+
});
|
|
2113
|
+
// Perform encoding on asset details to get an assetType (required for stark contract request)
|
|
2114
|
+
const encodingResult = await encodingApi.encodeAsset({
|
|
2115
|
+
assetType: 'asset',
|
|
2116
|
+
encodeAssetRequest: {
|
|
2117
|
+
token: {
|
|
2118
|
+
type: deposit.type,
|
|
2119
|
+
data: {
|
|
2120
|
+
token_address: deposit.tokenAddress,
|
|
2121
|
+
token_id: deposit.tokenId,
|
|
2122
|
+
},
|
|
2123
|
+
},
|
|
2124
|
+
},
|
|
2125
|
+
});
|
|
2126
|
+
const assetType = encodingResult.data.asset_type;
|
|
2127
|
+
const starkPublicKey = signableDepositResult.data.stark_key;
|
|
2128
|
+
const vaultId = signableDepositResult.data.vault_id;
|
|
2129
|
+
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
2130
|
+
// Approve whether an amount of token from an account can be spent by a third-party account
|
|
2131
|
+
const tokenContract = Contracts.IERC721.connect(deposit.tokenAddress, ethSigner);
|
|
2132
|
+
const operator = immutableXConfig.ethConfiguration.coreContractAddress;
|
|
2133
|
+
const isApprovedForAll = await tokenContract.isApprovedForAll(user, operator);
|
|
2134
|
+
if (!isApprovedForAll) {
|
|
2135
|
+
await tokenContract.setApprovalForAll(operator, true);
|
|
2136
|
+
}
|
|
2137
|
+
if (!isRegistered) {
|
|
2138
|
+
const signableResult = await getSignableRegistrationOnchain(user, starkPublicKey, usersApi);
|
|
2139
|
+
const coreContract = Contracts.Core.connect(immutableXConfig.ethConfiguration.coreContractAddress, ethSigner);
|
|
2140
|
+
// Note: proxy registration contract registerAndDepositNft method is not used as it currently fails erc721 transfer ownership check
|
|
2141
|
+
await coreContract.registerUser(user, starkPublicKey, signableResult.operator_signature);
|
|
2142
|
+
}
|
|
2143
|
+
return executeDepositERC721(ethSigner, deposit.tokenId, assetType, starkPublicKey, vaultId, immutableXConfig);
|
|
2144
|
+
}
|
|
2145
|
+
async function executeDepositERC721(ethSigner, tokenId, assetType, starkPublicKey, vaultId, config) {
|
|
2146
|
+
const coreContract = Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
2147
|
+
const populatedTransaction = await coreContract.populateTransaction.depositNft(starkPublicKey, assetType, vaultId, tokenId);
|
|
2148
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
2149
|
+
}
|
|
2150
|
+
|
|
2151
|
+
async function deposit({ signers, deposit, config }) {
|
|
2152
|
+
switch (deposit.type) {
|
|
2153
|
+
case 'ETH':
|
|
2154
|
+
return depositEth({ signers, deposit, config });
|
|
2155
|
+
case 'ERC20':
|
|
2156
|
+
return depositERC20({ signers, deposit, config });
|
|
2157
|
+
case 'ERC721':
|
|
2158
|
+
return depositERC721({ signers, deposit, config });
|
|
2159
|
+
}
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
async function exchangeTransfer({ signers, request, config, }) {
|
|
2163
|
+
await validateChain(signers.ethSigner, config.immutableXConfig);
|
|
2164
|
+
const exchangeApi = new ExchangesApi(config.immutableXConfig.apiConfiguration);
|
|
2165
|
+
const ethAddress = await signers.ethSigner.getAddress();
|
|
2166
|
+
const transferAmount = request.amount;
|
|
2167
|
+
const signableResult = await exchangeApi.getExchangeSignableTransfer({
|
|
2168
|
+
id: request.transactionID,
|
|
2169
|
+
getSignableTransferRequest: {
|
|
2170
|
+
sender: ethAddress,
|
|
2171
|
+
token: convertToSignableToken(request),
|
|
2172
|
+
amount: transferAmount,
|
|
2173
|
+
receiver: request.receiver,
|
|
2174
|
+
},
|
|
2175
|
+
});
|
|
2176
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
2177
|
+
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
2178
|
+
const starkSignature = await signers.starkSigner.signMessage(payloadHash);
|
|
2179
|
+
const transferSigningParams = {
|
|
2180
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
2181
|
+
sender_stark_key: signableResult.data.sender_stark_key,
|
|
2182
|
+
sender_vault_id: signableResult.data.sender_vault_id,
|
|
2183
|
+
receiver_stark_key: signableResult.data.receiver_stark_key,
|
|
2184
|
+
receiver_vault_id: signableResult.data.receiver_vault_id,
|
|
2185
|
+
asset_id: signableResult.data.asset_id,
|
|
2186
|
+
amount: signableResult.data.amount,
|
|
2187
|
+
nonce: signableResult.data.nonce,
|
|
2188
|
+
expiration_timestamp: signableResult.data.expiration_timestamp,
|
|
2189
|
+
stark_signature: starkSignature,
|
|
2190
|
+
};
|
|
2191
|
+
const response = await exchangeApi.createExchangeTransfer({
|
|
2192
|
+
id: request.transactionID,
|
|
2193
|
+
createTransferRequest: transferSigningParams,
|
|
2194
|
+
xImxEthAddress: ethAddress,
|
|
2195
|
+
xImxEthSignature: ethSignature,
|
|
2196
|
+
});
|
|
2197
|
+
return {
|
|
2198
|
+
sent_signature: response?.data.sent_signature,
|
|
2199
|
+
status: response?.data.status?.toString(),
|
|
2200
|
+
time: response?.data.time,
|
|
2201
|
+
transfer_id: response?.data.transfer_id,
|
|
2202
|
+
};
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2205
|
+
class GenericIMXProvider {
|
|
2206
|
+
config;
|
|
2207
|
+
signers;
|
|
2208
|
+
constructor(config, ethSigner, starkSigner) {
|
|
2209
|
+
this.config = config;
|
|
2210
|
+
this.signers = { ethSigner, starkSigner };
|
|
2211
|
+
}
|
|
2212
|
+
async getAddress() {
|
|
2213
|
+
return await this.signers.ethSigner.getAddress();
|
|
2214
|
+
}
|
|
2215
|
+
registerOffchain() {
|
|
2216
|
+
return registerOffchain(this.signers, this.config);
|
|
2217
|
+
}
|
|
2218
|
+
batchNftTransfer(request) {
|
|
2219
|
+
return batchTransfer({
|
|
2220
|
+
signers: this.signers,
|
|
2221
|
+
request,
|
|
2222
|
+
config: this.config,
|
|
2223
|
+
});
|
|
2224
|
+
}
|
|
2225
|
+
cancelOrder(request) {
|
|
2226
|
+
return cancelOrder({
|
|
2227
|
+
signers: this.signers,
|
|
2228
|
+
request,
|
|
2229
|
+
config: this.config,
|
|
2230
|
+
});
|
|
2231
|
+
}
|
|
2232
|
+
completeWithdrawal(starkPublicKey, token) {
|
|
2233
|
+
return completeWithdrawal({
|
|
2234
|
+
config: this.config,
|
|
2235
|
+
signers: this.signers,
|
|
2236
|
+
token,
|
|
2237
|
+
starkPublicKey,
|
|
2238
|
+
});
|
|
2239
|
+
}
|
|
2240
|
+
createOrder(request) {
|
|
2241
|
+
return createOrder({
|
|
2242
|
+
signers: this.signers,
|
|
2243
|
+
request,
|
|
2244
|
+
config: this.config,
|
|
2245
|
+
});
|
|
2246
|
+
}
|
|
2247
|
+
createTrade(request) {
|
|
2248
|
+
return createTrade({
|
|
2249
|
+
signers: this.signers,
|
|
2250
|
+
request,
|
|
2251
|
+
config: this.config,
|
|
2252
|
+
});
|
|
2253
|
+
}
|
|
2254
|
+
deposit(tokenAmount) {
|
|
2255
|
+
return deposit({
|
|
2256
|
+
signers: this.signers,
|
|
2257
|
+
deposit: tokenAmount,
|
|
2258
|
+
config: this.config,
|
|
2259
|
+
});
|
|
2260
|
+
}
|
|
2261
|
+
exchangeTransfer(request) {
|
|
2262
|
+
return exchangeTransfer({
|
|
2263
|
+
signers: this.signers,
|
|
2264
|
+
request,
|
|
2265
|
+
config: this.config,
|
|
2266
|
+
});
|
|
2267
|
+
}
|
|
2268
|
+
async isRegisteredOnchain() {
|
|
2269
|
+
const starkPublicKey = await this.signers.starkSigner.getAddress();
|
|
2270
|
+
return isRegisteredOnChain(starkPublicKey, this.signers.ethSigner, this.config);
|
|
2271
|
+
}
|
|
2272
|
+
prepareWithdrawal(request) {
|
|
2273
|
+
return prepareWithdrawal({
|
|
2274
|
+
signers: this.signers,
|
|
2275
|
+
withdrawal: request,
|
|
2276
|
+
config: this.config,
|
|
2277
|
+
});
|
|
2278
|
+
}
|
|
2279
|
+
transfer(request) {
|
|
2280
|
+
return transfer({
|
|
2281
|
+
signers: this.signers,
|
|
2282
|
+
request,
|
|
2283
|
+
config: this.config,
|
|
2284
|
+
});
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
|
|
2288
|
+
const WALLET_ACTION = {
|
|
2289
|
+
SWITCH_CHAIN: 'wallet_switchEthereumChain',
|
|
2290
|
+
CONNECT: 'eth_requestAccounts',
|
|
2291
|
+
};
|
|
2292
|
+
function isRequestableProvider(provider) {
|
|
2293
|
+
return !!provider?.request;
|
|
2294
|
+
}
|
|
2295
|
+
async function connectProvider(provider, chainID) {
|
|
2296
|
+
await provider.request({ method: WALLET_ACTION.CONNECT });
|
|
2297
|
+
if (chainID) {
|
|
2298
|
+
await provider.request({
|
|
2299
|
+
method: WALLET_ACTION.SWITCH_CHAIN,
|
|
2300
|
+
params: [{ chainId: `0x${chainID.toString(16)}` }],
|
|
2301
|
+
});
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
|
|
2305
|
+
const ERRORS = {
|
|
2306
|
+
PROVIDER_NOT_FOUND: 'The Metamask provider was not found',
|
|
2307
|
+
};
|
|
2308
|
+
async function connect$1({ chainID, }) {
|
|
2309
|
+
const provider = (await detectEthereumProvider());
|
|
2310
|
+
if (!isRequestableProvider(provider)) {
|
|
2311
|
+
throw new Error(ERRORS.PROVIDER_NOT_FOUND);
|
|
2312
|
+
}
|
|
2313
|
+
await connectProvider(provider, chainID);
|
|
2314
|
+
// NOTE: if we want to listen to Metamask events in the future, we can add a
|
|
2315
|
+
// listener here.
|
|
2316
|
+
return new ethers.providers.Web3Provider(provider);
|
|
2317
|
+
}
|
|
2318
|
+
|
|
2319
|
+
const COMMUNICATION_TYPE = 'message';
|
|
2320
|
+
var RequestEventType;
|
|
2321
|
+
(function (RequestEventType) {
|
|
2322
|
+
RequestEventType["GET_CONNECTION_REQUEST"] = "GET_CONNECTION_REQUEST";
|
|
2323
|
+
RequestEventType["CONNECT_WALLET_REQUEST"] = "CONNECT_WALLET_REQUEST";
|
|
2324
|
+
RequestEventType["SIGN_MESSAGE_REQUEST"] = "SIGN_MESSAGE_REQUEST";
|
|
2325
|
+
RequestEventType["DISCONNECT_WALLET_REQUEST"] = "DISCONNECT_WALLET_REQUEST";
|
|
2326
|
+
})(RequestEventType || (RequestEventType = {}));
|
|
2327
|
+
var ResponseEventType;
|
|
2328
|
+
(function (ResponseEventType) {
|
|
2329
|
+
ResponseEventType["CONNECT_WALLET_RESPONSE"] = "CONNECT_WALLET_RESPONSE";
|
|
2330
|
+
ResponseEventType["SIGN_MESSAGE_RESPONSE"] = "SIGN_MESSAGE_RESPONSE";
|
|
2331
|
+
ResponseEventType["GET_CONNECTION_RESPONSE"] = "GET_CONNECTION_RESPONSE";
|
|
2332
|
+
ResponseEventType["DISCONNECT_WALLET_RESPONSE"] = "DISCONNECT_WALLET_RESPONSE";
|
|
2333
|
+
})(ResponseEventType || (ResponseEventType = {}));
|
|
2334
|
+
|
|
2335
|
+
function postRequestMessage(iframe, payload) {
|
|
2336
|
+
if (iframe && iframe.contentWindow) {
|
|
2337
|
+
iframe.contentWindow.postMessage(payload, new URL(iframe.src).origin);
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
|
|
2341
|
+
function messageResponseListener(iframe, event, eventType, callback) {
|
|
2342
|
+
if (iframe && event.source !== iframe.contentWindow) {
|
|
2343
|
+
return;
|
|
2344
|
+
}
|
|
2345
|
+
const l2WalletMessage = event.data;
|
|
2346
|
+
if (l2WalletMessage.type !== eventType) {
|
|
2347
|
+
return;
|
|
2348
|
+
}
|
|
2349
|
+
callback(l2WalletMessage.details);
|
|
2350
|
+
}
|
|
2351
|
+
|
|
2352
|
+
class ImxSigner {
|
|
2353
|
+
publicAddress;
|
|
2354
|
+
iframe;
|
|
2355
|
+
constructor(publicAddress, iframe) {
|
|
2356
|
+
this.publicAddress = publicAddress;
|
|
2357
|
+
this.iframe = iframe;
|
|
2358
|
+
}
|
|
2359
|
+
getAddress() {
|
|
2360
|
+
return this.publicAddress;
|
|
2361
|
+
}
|
|
2362
|
+
signMessage(rawMessage) {
|
|
2363
|
+
return new Promise((resolve, reject) => {
|
|
2364
|
+
const listener = (event) => {
|
|
2365
|
+
messageResponseListener(this.iframe, event, ResponseEventType.SIGN_MESSAGE_RESPONSE, (messageDetails) => {
|
|
2366
|
+
window.removeEventListener(COMMUNICATION_TYPE, listener);
|
|
2367
|
+
if (!messageDetails.success) {
|
|
2368
|
+
reject(new Error(messageDetails.error?.message));
|
|
2369
|
+
}
|
|
2370
|
+
resolve(messageDetails.data.signedMessage);
|
|
2371
|
+
});
|
|
2372
|
+
};
|
|
2373
|
+
window.addEventListener(COMMUNICATION_TYPE, listener);
|
|
2374
|
+
postRequestMessage(this.iframe, {
|
|
2375
|
+
type: RequestEventType.SIGN_MESSAGE_REQUEST,
|
|
2376
|
+
details: { starkPublicKey: this.publicAddress, message: rawMessage },
|
|
2377
|
+
});
|
|
2378
|
+
});
|
|
2379
|
+
}
|
|
2380
|
+
getIFrame() {
|
|
2381
|
+
return this.iframe;
|
|
2382
|
+
}
|
|
2383
|
+
}
|
|
2384
|
+
|
|
2385
|
+
const IMX_WALLET_IFRAME_ID = 'imx-wallet-app';
|
|
2386
|
+
const IMX_WALLET_IFRAME_HOSTS = {
|
|
2387
|
+
[Environment.SANDBOX]: 'https://wallets.sandbox.immutable.com',
|
|
2388
|
+
[Environment.PRODUCTION]: 'https://wallets.immutable.com',
|
|
2389
|
+
};
|
|
2390
|
+
const IMX_WALLET_IFRAME_STYLE = 'display: none;';
|
|
2391
|
+
function getIFrame() {
|
|
2392
|
+
return document.querySelector(`iframe#${IMX_WALLET_IFRAME_ID}`);
|
|
2393
|
+
}
|
|
2394
|
+
async function setupIFrame(env) {
|
|
2395
|
+
return new Promise((resolve) => {
|
|
2396
|
+
const iframe = document.createElement('iframe');
|
|
2397
|
+
iframe.setAttribute('id', IMX_WALLET_IFRAME_ID);
|
|
2398
|
+
iframe.setAttribute('src', IMX_WALLET_IFRAME_HOSTS[env]);
|
|
2399
|
+
iframe.setAttribute('style', IMX_WALLET_IFRAME_STYLE);
|
|
2400
|
+
document.body.appendChild(iframe);
|
|
2401
|
+
iframe.onload = () => resolve(iframe);
|
|
2402
|
+
});
|
|
2403
|
+
}
|
|
2404
|
+
async function getOrSetupIFrame(env) {
|
|
2405
|
+
const iframe = getIFrame();
|
|
2406
|
+
if (iframe)
|
|
2407
|
+
return iframe;
|
|
2408
|
+
return await setupIFrame(env);
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2411
|
+
const DEFAULT_CONNECTION_MESSAGE = 'Only sign this request if you’ve initiated an action with Immutable X.';
|
|
2412
|
+
const CONNECTION_FAILED_ERROR = 'The L2 IMX Wallet connection has failed';
|
|
2413
|
+
async function connect(l1Provider, env) {
|
|
2414
|
+
const l1Signer = l1Provider.getSigner();
|
|
2415
|
+
const address = await l1Signer.getAddress();
|
|
2416
|
+
const signature = await l1Signer.signMessage(DEFAULT_CONNECTION_MESSAGE);
|
|
2417
|
+
const iframe = await getOrSetupIFrame(env);
|
|
2418
|
+
return new Promise((resolve, reject) => {
|
|
2419
|
+
const listener = (event) => {
|
|
2420
|
+
messageResponseListener(iframe, event, ResponseEventType.CONNECT_WALLET_RESPONSE, (messageDetails) => {
|
|
2421
|
+
window.removeEventListener(COMMUNICATION_TYPE, listener);
|
|
2422
|
+
if (!messageDetails.success) {
|
|
2423
|
+
reject(new Error(CONNECTION_FAILED_ERROR));
|
|
2424
|
+
}
|
|
2425
|
+
resolve(new ImxSigner(messageDetails.data.starkPublicKey, iframe));
|
|
2426
|
+
});
|
|
2427
|
+
};
|
|
2428
|
+
window.addEventListener(COMMUNICATION_TYPE, listener);
|
|
2429
|
+
postRequestMessage(iframe, {
|
|
2430
|
+
type: RequestEventType.CONNECT_WALLET_REQUEST,
|
|
2431
|
+
details: { ethAddress: address, signature },
|
|
2432
|
+
});
|
|
2433
|
+
});
|
|
2434
|
+
}
|
|
2435
|
+
async function disconnect(imxSigner) {
|
|
2436
|
+
const iframe = imxSigner.getIFrame();
|
|
2437
|
+
return new Promise((resolve, reject) => {
|
|
2438
|
+
const listener = (event) => {
|
|
2439
|
+
messageResponseListener(iframe, event, ResponseEventType.DISCONNECT_WALLET_RESPONSE, (messageDetails) => {
|
|
2440
|
+
window.removeEventListener(COMMUNICATION_TYPE, listener);
|
|
2441
|
+
if (!messageDetails.success && messageDetails.error) {
|
|
2442
|
+
reject(messageDetails.error);
|
|
2443
|
+
}
|
|
2444
|
+
iframe.remove();
|
|
2445
|
+
resolve();
|
|
2446
|
+
});
|
|
2447
|
+
};
|
|
2448
|
+
window.addEventListener(COMMUNICATION_TYPE, listener);
|
|
2449
|
+
postRequestMessage(iframe, {
|
|
2450
|
+
type: RequestEventType.DISCONNECT_WALLET_REQUEST,
|
|
2451
|
+
details: { starkPublicKey: imxSigner.getAddress() },
|
|
2452
|
+
});
|
|
2453
|
+
});
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2456
|
+
var ProviderErrorType;
|
|
2457
|
+
(function (ProviderErrorType) {
|
|
2458
|
+
ProviderErrorType["PROVIDER_CONNECTION_ERROR"] = "PROVIDER_CONNECTION_ERROR";
|
|
2459
|
+
ProviderErrorType["WALLET_CONNECTION_ERROR"] = "WALLET_CONNECTION_ERROR";
|
|
2460
|
+
})(ProviderErrorType || (ProviderErrorType = {}));
|
|
2461
|
+
class ProviderError extends Error {
|
|
2462
|
+
type;
|
|
2463
|
+
constructor(message, type) {
|
|
2464
|
+
super(message);
|
|
2465
|
+
this.type = type;
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
const withProviderError = async (fn, customError) => {
|
|
2469
|
+
try {
|
|
2470
|
+
return await fn();
|
|
2471
|
+
}
|
|
2472
|
+
catch (error) {
|
|
2473
|
+
const errorMessage = customError.message || `${error.message}` || 'UnknownError';
|
|
2474
|
+
throw new ProviderError(errorMessage, customError.type);
|
|
2475
|
+
}
|
|
2476
|
+
};
|
|
2477
|
+
|
|
2478
|
+
class MetaMaskIMXProvider extends GenericIMXProvider {
|
|
2479
|
+
static imxSigner;
|
|
2480
|
+
constructor(config, ethSigner, starkSigner) {
|
|
2481
|
+
super(config, ethSigner, starkSigner);
|
|
2482
|
+
}
|
|
2483
|
+
static async connect(config) {
|
|
2484
|
+
return await withProviderError(async () => {
|
|
2485
|
+
const metaMaskProvider = await connect$1({
|
|
2486
|
+
chainID: config.immutableXConfig.ethConfiguration.chainID,
|
|
2487
|
+
});
|
|
2488
|
+
this.imxSigner = await connect(metaMaskProvider, config.baseConfig.environment);
|
|
2489
|
+
return new MetaMaskIMXProvider(config, metaMaskProvider.getSigner(), this.imxSigner);
|
|
2490
|
+
}, { type: ProviderErrorType.WALLET_CONNECTION_ERROR });
|
|
2491
|
+
}
|
|
2492
|
+
static async disconnect() {
|
|
2493
|
+
if (!this.imxSigner) {
|
|
2494
|
+
throw new ProviderError('Attempted to disconnect from the MetaMask IMX provider without an established connection', ProviderErrorType.PROVIDER_CONNECTION_ERROR);
|
|
2495
|
+
}
|
|
2496
|
+
return withProviderError(async () => {
|
|
2497
|
+
await disconnect(this.imxSigner);
|
|
2498
|
+
}, { type: ProviderErrorType.PROVIDER_CONNECTION_ERROR });
|
|
2499
|
+
}
|
|
2500
|
+
static async signMessage(message) {
|
|
2501
|
+
if (!this.imxSigner) {
|
|
2502
|
+
throw new ProviderError('Attempted to sign a message with the MetaMask IMX provider without an established connection', ProviderErrorType.PROVIDER_CONNECTION_ERROR);
|
|
2503
|
+
}
|
|
2504
|
+
return withProviderError(async () => {
|
|
2505
|
+
return await this.imxSigner.signMessage(message);
|
|
2506
|
+
}, { type: ProviderErrorType.PROVIDER_CONNECTION_ERROR });
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2509
|
+
|
|
2510
|
+
class ProviderConfiguration {
|
|
2511
|
+
immutableXConfig;
|
|
2512
|
+
baseConfig;
|
|
2513
|
+
constructor({ baseConfig, overrides }) {
|
|
2514
|
+
this.baseConfig = baseConfig;
|
|
2515
|
+
if (overrides) {
|
|
2516
|
+
this.immutableXConfig = overrides.immutableXConfig;
|
|
2517
|
+
}
|
|
2518
|
+
else {
|
|
2519
|
+
switch (baseConfig.environment) {
|
|
2520
|
+
case Environment.SANDBOX: {
|
|
2521
|
+
this.immutableXConfig = Config.SANDBOX;
|
|
2522
|
+
break;
|
|
2523
|
+
}
|
|
2524
|
+
case Environment.PRODUCTION: {
|
|
2525
|
+
this.immutableXConfig = Config.PRODUCTION;
|
|
2526
|
+
break;
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
|
|
2533
|
+
function $parcel$interopDefault(a) {
|
|
2534
|
+
return a && a.__esModule ? a.default : a;
|
|
2535
|
+
}
|
|
2536
|
+
|
|
2537
|
+
const $762782b6c862d954$export$db5daa1b5156ccfe = [
|
|
2538
|
+
{
|
|
2539
|
+
constant: true,
|
|
2540
|
+
inputs: [],
|
|
2541
|
+
name: "name",
|
|
2542
|
+
outputs: [
|
|
2543
|
+
{
|
|
2544
|
+
name: "",
|
|
2545
|
+
type: "string"
|
|
2546
|
+
}
|
|
2547
|
+
],
|
|
2548
|
+
payable: false,
|
|
2549
|
+
type: "function"
|
|
2550
|
+
},
|
|
2551
|
+
{
|
|
2552
|
+
constant: true,
|
|
2553
|
+
inputs: [],
|
|
2554
|
+
name: "decimals",
|
|
2555
|
+
outputs: [
|
|
2556
|
+
{
|
|
2557
|
+
name: "",
|
|
2558
|
+
type: "uint8"
|
|
2559
|
+
}
|
|
2560
|
+
],
|
|
2561
|
+
payable: false,
|
|
2562
|
+
type: "function"
|
|
2563
|
+
},
|
|
2564
|
+
{
|
|
2565
|
+
constant: true,
|
|
2566
|
+
inputs: [
|
|
2567
|
+
{
|
|
2568
|
+
name: "_owner",
|
|
2569
|
+
type: "address"
|
|
2570
|
+
}
|
|
2571
|
+
],
|
|
2572
|
+
name: "balanceOf",
|
|
2573
|
+
outputs: [
|
|
2574
|
+
{
|
|
2575
|
+
name: "balance",
|
|
2576
|
+
type: "uint256"
|
|
2577
|
+
}
|
|
2578
|
+
],
|
|
2579
|
+
payable: false,
|
|
2580
|
+
type: "function"
|
|
2581
|
+
},
|
|
2582
|
+
{
|
|
2583
|
+
constant: true,
|
|
2584
|
+
inputs: [],
|
|
2585
|
+
name: "symbol",
|
|
2586
|
+
outputs: [
|
|
2587
|
+
{
|
|
2588
|
+
name: "",
|
|
2589
|
+
type: "string"
|
|
2590
|
+
}
|
|
2591
|
+
],
|
|
2592
|
+
payable: false,
|
|
2593
|
+
type: "function"
|
|
2594
|
+
}
|
|
2595
|
+
];
|
|
2596
|
+
|
|
2597
|
+
|
|
2598
|
+
let $d176a05e966364ba$export$3bfad4d03ada24c4;
|
|
2599
|
+
(function(ConnectionProviders) {
|
|
2600
|
+
ConnectionProviders["METAMASK"] = "metamask";
|
|
2601
|
+
})($d176a05e966364ba$export$3bfad4d03ada24c4 || ($d176a05e966364ba$export$3bfad4d03ada24c4 = {}));
|
|
2602
|
+
|
|
2603
|
+
|
|
2604
|
+
let $a47e48dd2c04791b$export$c06e1e7429de6283;
|
|
2605
|
+
(function(ChainId) {
|
|
2606
|
+
ChainId[ChainId["ETHEREUM"] = 1] = "ETHEREUM";
|
|
2607
|
+
ChainId[ChainId["GOERLI"] = 5] = "GOERLI";
|
|
2608
|
+
ChainId[ChainId["POLYGON"] = 137] = "POLYGON";
|
|
2609
|
+
})($a47e48dd2c04791b$export$c06e1e7429de6283 || ($a47e48dd2c04791b$export$c06e1e7429de6283 = {}));
|
|
2610
|
+
const $a47e48dd2c04791b$export$f61f4aaec62f6be9 = {
|
|
2611
|
+
[$a47e48dd2c04791b$export$c06e1e7429de6283.ETHEREUM]: {
|
|
2612
|
+
chainIdHex: "0x1",
|
|
2613
|
+
chainName: "Ethereum",
|
|
2614
|
+
rpcUrls: [
|
|
2615
|
+
"https://mainnet.infura.io/v3/"
|
|
2616
|
+
],
|
|
2617
|
+
nativeCurrency: {
|
|
2618
|
+
name: "Ethereum",
|
|
2619
|
+
symbol: "ETH",
|
|
2620
|
+
decimals: 18
|
|
2621
|
+
},
|
|
2622
|
+
blockExplorerUrls: [
|
|
2623
|
+
"https://etherscan.io/"
|
|
2624
|
+
]
|
|
2625
|
+
},
|
|
2626
|
+
[$a47e48dd2c04791b$export$c06e1e7429de6283.GOERLI]: {
|
|
2627
|
+
chainIdHex: "0x5",
|
|
2628
|
+
chainName: "Goerli",
|
|
2629
|
+
rpcUrls: [
|
|
2630
|
+
"https://goerli.infura.io/v3/"
|
|
2631
|
+
],
|
|
2632
|
+
nativeCurrency: {
|
|
2633
|
+
name: "Goerli Eth",
|
|
2634
|
+
symbol: "ETH",
|
|
2635
|
+
decimals: 18
|
|
2636
|
+
},
|
|
2637
|
+
blockExplorerUrls: [
|
|
2638
|
+
"https://goerli.etherscan.io/"
|
|
2639
|
+
]
|
|
2640
|
+
},
|
|
2641
|
+
[$a47e48dd2c04791b$export$c06e1e7429de6283.POLYGON]: {
|
|
2642
|
+
chainIdHex: "0x89",
|
|
2643
|
+
chainName: "Polygon",
|
|
2644
|
+
rpcUrls: [
|
|
2645
|
+
"https://polygon-rpc.com"
|
|
2646
|
+
],
|
|
2647
|
+
nativeCurrency: {
|
|
2648
|
+
name: "MATIC",
|
|
2649
|
+
symbol: "MATIC",
|
|
2650
|
+
decimals: 18
|
|
2651
|
+
},
|
|
2652
|
+
blockExplorerUrls: [
|
|
2653
|
+
"https://polygonscan.com/"
|
|
2654
|
+
]
|
|
2655
|
+
}
|
|
2656
|
+
};
|
|
2657
|
+
let $a47e48dd2c04791b$export$1f05a55fe0680cc7;
|
|
2658
|
+
(function(NetworkFilterTypes) {
|
|
2659
|
+
NetworkFilterTypes["ALL"] = "all";
|
|
2660
|
+
})($a47e48dd2c04791b$export$1f05a55fe0680cc7 || ($a47e48dd2c04791b$export$1f05a55fe0680cc7 = {}));
|
|
2661
|
+
|
|
2662
|
+
|
|
2663
|
+
let $08d5ddc39acd6833$export$fd9b17d87f4121d2;
|
|
2664
|
+
(function(TokenFilterTypes) {
|
|
2665
|
+
TokenFilterTypes["SWAP"] = "swap";
|
|
2666
|
+
TokenFilterTypes["BRIDGE"] = "bridge";
|
|
2667
|
+
TokenFilterTypes["ALL"] = "all";
|
|
2668
|
+
})($08d5ddc39acd6833$export$fd9b17d87f4121d2 || ($08d5ddc39acd6833$export$fd9b17d87f4121d2 = {}));
|
|
2669
|
+
|
|
2670
|
+
|
|
2671
|
+
|
|
2672
|
+
|
|
2673
|
+
const $4f91c5f280efe242$export$a130407f3423b97d = {
|
|
2674
|
+
CHECK_CONNECTION: "eth_accounts",
|
|
2675
|
+
CONNECT: "eth_requestAccounts",
|
|
2676
|
+
ADD_NETWORK: "wallet_addEthereumChain",
|
|
2677
|
+
SWITCH_NETWORK: "wallet_switchEthereumChain"
|
|
2678
|
+
};
|
|
2679
|
+
let $4f91c5f280efe242$export$a75605c67ea83a5a;
|
|
2680
|
+
(function(WalletFilterTypes) {
|
|
2681
|
+
WalletFilterTypes["ALL"] = "all";
|
|
2682
|
+
WalletFilterTypes["DESKTOP"] = "desktop";
|
|
2683
|
+
WalletFilterTypes["MOBILE"] = "mobile";
|
|
2684
|
+
})($4f91c5f280efe242$export$a75605c67ea83a5a || ($4f91c5f280efe242$export$a75605c67ea83a5a = {}));
|
|
2685
|
+
|
|
2686
|
+
|
|
2687
|
+
let $090d3502d165f17d$export$c5ab8fbcabac8c11;
|
|
2688
|
+
(function(SupportedFiatCurrencies) {
|
|
2689
|
+
SupportedFiatCurrencies["USD"] = "USD";
|
|
2690
|
+
})($090d3502d165f17d$export$c5ab8fbcabac8c11 || ($090d3502d165f17d$export$c5ab8fbcabac8c11 = {}));
|
|
2691
|
+
|
|
2692
|
+
|
|
2693
|
+
|
|
2694
|
+
|
|
2695
|
+
/**
|
|
2696
|
+
* The different types of errors that can be returned by the checkout process.
|
|
2697
|
+
*/ let $a8bc256d81a5e2c1$export$e3dc0620abde7f5a;
|
|
2698
|
+
(function(CheckoutErrorType) {
|
|
2699
|
+
CheckoutErrorType["PROVIDER_PREFERENCE_ERROR"] = "PROVIDER_PREFERENCE_ERROR";
|
|
2700
|
+
CheckoutErrorType["CONNECT_PROVIDER_ERROR"] = "CONNECT_PROVIDER_ERROR";
|
|
2701
|
+
CheckoutErrorType["GET_BALANCE_ERROR"] = "GET_BALANCE_ERROR";
|
|
2702
|
+
CheckoutErrorType["GET_ERC20_BALANCE_ERROR"] = "GET_ERC20_BALANCE_ERROR";
|
|
2703
|
+
CheckoutErrorType["GET_NETWORK_INFO_ERROR"] = "GET_NETWORK_INFO_ERROR";
|
|
2704
|
+
CheckoutErrorType["METAMASK_PROVIDER_ERROR"] = "METAMASK_PROVIDER_ERROR";
|
|
2705
|
+
CheckoutErrorType["CHAIN_NOT_SUPPORTED_ERROR"] = "CHAIN_NOT_SUPPORTED_ERROR";
|
|
2706
|
+
CheckoutErrorType["PROVIDER_REQUEST_MISSING_ERROR"] = "PROVIDER_REQUEST_MISSING_ERROR";
|
|
2707
|
+
CheckoutErrorType["PROVIDER_REQUEST_FAILED_ERROR"] = "PROVIDER_REQUEST_FAILED_ERROR";
|
|
2708
|
+
CheckoutErrorType["USER_REJECTED_REQUEST_ERROR"] = "USER_REJECTED_REQUEST_ERROR";
|
|
2709
|
+
CheckoutErrorType["TRANSACTION_ERROR"] = "TRANSACTION_ERROR";
|
|
2710
|
+
CheckoutErrorType["FIAT_CONVERSION_ERROR"] = "FIAT_CONVERSION_ERROR";
|
|
2711
|
+
CheckoutErrorType["TOKEN_NOT_SUPPORTED_ERROR"] = "TOKEN_NOT_SUPPORTED_ERROR";
|
|
2712
|
+
CheckoutErrorType["FIAT_CURRENCY_NOT_SUPPORTED_ERROR"] = "FIAT_CURRENCY_NOT_SUPPORTED_ERROR";
|
|
2713
|
+
})($a8bc256d81a5e2c1$export$e3dc0620abde7f5a || ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a = {}));
|
|
2714
|
+
class $a8bc256d81a5e2c1$export$b722478a3cbfa3bc extends Error {
|
|
2715
|
+
constructor(message, type, data){
|
|
2716
|
+
super(message);
|
|
2717
|
+
this.message = message;
|
|
2718
|
+
this.type = type;
|
|
2719
|
+
this.data = data;
|
|
2720
|
+
}
|
|
2721
|
+
}
|
|
2722
|
+
let $a8bc256d81a5e2c1$export$a22d4e0719ee6def;
|
|
2723
|
+
(function(CheckoutInternalErrorType) {
|
|
2724
|
+
CheckoutInternalErrorType["REJECTED_SWITCH_AFTER_ADDING_NETWORK"] = "REJECTED_SWITCH_AFTER_ADDING_NETWORK";
|
|
2725
|
+
})($a8bc256d81a5e2c1$export$a22d4e0719ee6def || ($a8bc256d81a5e2c1$export$a22d4e0719ee6def = {}));
|
|
2726
|
+
const $a8bc256d81a5e2c1$export$bacc563de539c6c3 = async (fn, customError)=>{
|
|
2727
|
+
try {
|
|
2728
|
+
return await fn();
|
|
2729
|
+
} catch (error) {
|
|
2730
|
+
const cause = `${error.message}` || "UnknownError";
|
|
2731
|
+
const errorMessage = customError.message ? `[${customError.type}]:${customError.message}. Cause:${cause}` : `[${customError.type}] Cause:${cause}`;
|
|
2732
|
+
if (error instanceof $a8bc256d81a5e2c1$export$b722478a3cbfa3bc) throw new $a8bc256d81a5e2c1$export$b722478a3cbfa3bc(errorMessage, customError.type, {
|
|
2733
|
+
...customError.data,
|
|
2734
|
+
innerErrorType: error.type,
|
|
2735
|
+
...error.data
|
|
2736
|
+
});
|
|
2737
|
+
throw new $a8bc256d81a5e2c1$export$b722478a3cbfa3bc(errorMessage, customError.type, {
|
|
2738
|
+
...customError.data
|
|
2739
|
+
});
|
|
2740
|
+
}
|
|
2741
|
+
};
|
|
2742
|
+
|
|
2743
|
+
|
|
2744
|
+
|
|
2745
|
+
|
|
2746
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2747
|
+
|
|
2748
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2749
|
+
|
|
2750
|
+
|
|
2751
|
+
|
|
2752
|
+
async function $c99672cf2294e839$export$2d040992269b4717(providerPreference) {
|
|
2753
|
+
const provider = await $c99672cf2294e839$var$getWalletProviderForPreference(providerPreference);
|
|
2754
|
+
if (!provider.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Incompatible provider", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_MISSING_ERROR, {
|
|
2755
|
+
details: `Unsupported provider for ${providerPreference}`
|
|
2756
|
+
});
|
|
2757
|
+
let accounts = [];
|
|
2758
|
+
try {
|
|
2759
|
+
accounts = await provider.provider.request({
|
|
2760
|
+
method: (0, $4f91c5f280efe242$export$a130407f3423b97d).CHECK_CONNECTION,
|
|
2761
|
+
params: []
|
|
2762
|
+
});
|
|
2763
|
+
} catch (err) {
|
|
2764
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`Check wallet connection request failed`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_FAILED_ERROR, {
|
|
2765
|
+
rpcMethod: ($4f91c5f280efe242$export$a130407f3423b97d).CHECK_CONNECTION
|
|
2766
|
+
});
|
|
2767
|
+
}
|
|
2768
|
+
// accounts[0] will have the active account if connected.
|
|
2769
|
+
return {
|
|
2770
|
+
isConnected: accounts && accounts.length > 0,
|
|
2771
|
+
walletAddress: accounts[0] ?? ""
|
|
2772
|
+
};
|
|
2773
|
+
}
|
|
2774
|
+
async function $c99672cf2294e839$export$fba2f6c3656e07c1(params) {
|
|
2775
|
+
const web3Provider = await $c99672cf2294e839$var$getWalletProviderForPreference(params.providerPreference);
|
|
2776
|
+
await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2777
|
+
if (!web3Provider || !web3Provider?.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Incompatible provider", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_MISSING_ERROR, {
|
|
2778
|
+
details: `Unsupported provider for ${params.providerPreference}`
|
|
2779
|
+
});
|
|
2780
|
+
// this makes the request to the wallet to connect i.e request eth accounts ('eth_requestAccounts')
|
|
2781
|
+
await web3Provider.provider.request({
|
|
2782
|
+
method: ($4f91c5f280efe242$export$a130407f3423b97d).CONNECT,
|
|
2783
|
+
params: []
|
|
2784
|
+
});
|
|
2785
|
+
}, {
|
|
2786
|
+
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR
|
|
2787
|
+
});
|
|
2788
|
+
return web3Provider;
|
|
2789
|
+
}
|
|
2790
|
+
async function $c99672cf2294e839$var$getWalletProviderForPreference(providerPreference) {
|
|
2791
|
+
let web3Provider = null;
|
|
2792
|
+
switch(providerPreference){
|
|
2793
|
+
case ($d176a05e966364ba$export$3bfad4d03ada24c4).METAMASK:
|
|
2794
|
+
web3Provider = await $c99672cf2294e839$var$getMetaMaskProvider();
|
|
2795
|
+
break;
|
|
2796
|
+
default:
|
|
2797
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Provider preference is not supported", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_PREFERENCE_ERROR);
|
|
2798
|
+
}
|
|
2799
|
+
return web3Provider;
|
|
2800
|
+
}
|
|
2801
|
+
async function $c99672cf2294e839$var$getMetaMaskProvider() {
|
|
2802
|
+
const provider = await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2803
|
+
return await (detectEthereumProvider)();
|
|
2804
|
+
}, {
|
|
2805
|
+
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).METAMASK_PROVIDER_ERROR
|
|
2806
|
+
});
|
|
2807
|
+
if (!provider || !provider.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No MetaMask provider installed.", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).METAMASK_PROVIDER_ERROR);
|
|
2808
|
+
return new (Web3Provider)(provider);
|
|
2809
|
+
}
|
|
2810
|
+
|
|
2811
|
+
|
|
2812
|
+
var $497c134ecbc8a50f$exports = {};
|
|
2813
|
+
$497c134ecbc8a50f$exports = JSON.parse('[{"chainId":1},{"chainId":137}]');
|
|
2814
|
+
|
|
2815
|
+
|
|
2816
|
+
const $de192de6ef100f9f$var$UNRECOGNISED_CHAIN_ERROR_CODE = 4902; // error code (MetaMask)
|
|
2817
|
+
async function $de192de6ef100f9f$export$79f13b4cfaaf0d09(provider) {
|
|
2818
|
+
return ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2819
|
+
const network = await provider.getNetwork();
|
|
2820
|
+
if (!Object.values(($a47e48dd2c04791b$export$c06e1e7429de6283)).includes(network.chainId)) // return empty details
|
|
2821
|
+
return {
|
|
2822
|
+
chainId: network.chainId,
|
|
2823
|
+
name: network.name,
|
|
2824
|
+
isSupported: false
|
|
2825
|
+
};
|
|
2826
|
+
const chainIdNetworkInfo = ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[network.chainId];
|
|
2827
|
+
return {
|
|
2828
|
+
name: chainIdNetworkInfo.chainName,
|
|
2829
|
+
chainId: parseInt(chainIdNetworkInfo.chainIdHex, 16),
|
|
2830
|
+
nativeCurrency: chainIdNetworkInfo.nativeCurrency,
|
|
2831
|
+
isSupported: true
|
|
2832
|
+
};
|
|
2833
|
+
}, {
|
|
2834
|
+
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_NETWORK_INFO_ERROR
|
|
2835
|
+
});
|
|
2836
|
+
}
|
|
2837
|
+
async function $de192de6ef100f9f$export$b827d9418aeb5dbd(providerPreference, provider, chainId) {
|
|
2838
|
+
let currentProvider = provider;
|
|
2839
|
+
if (!Object.values(($a47e48dd2c04791b$export$c06e1e7429de6283)).includes(chainId)) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`Chain:${chainId} is not a supported chain`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CHAIN_NOT_SUPPORTED_ERROR);
|
|
2840
|
+
if (!currentProvider || !currentProvider.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Incompatible provider", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_MISSING_ERROR, {
|
|
2841
|
+
details: `Unsupported provider`
|
|
2842
|
+
});
|
|
2843
|
+
// WT-1146 - Refer to the README in this folder for explantion on the switch network flow
|
|
2844
|
+
try {
|
|
2845
|
+
await $de192de6ef100f9f$var$switchNetworkInWallet(currentProvider, chainId);
|
|
2846
|
+
} catch (err) {
|
|
2847
|
+
if (err.code === $de192de6ef100f9f$var$UNRECOGNISED_CHAIN_ERROR_CODE) try {
|
|
2848
|
+
await $de192de6ef100f9f$var$addNetworkToWallet(currentProvider, chainId);
|
|
2849
|
+
} catch (err) {
|
|
2850
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("User cancelled add network request", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR);
|
|
2851
|
+
}
|
|
2852
|
+
else throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("User cancelled switch network request", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR);
|
|
2853
|
+
}
|
|
2854
|
+
currentProvider = await ($c99672cf2294e839$export$fba2f6c3656e07c1)({
|
|
2855
|
+
providerPreference: providerPreference
|
|
2856
|
+
});
|
|
2857
|
+
if ((await currentProvider.getNetwork()).chainId !== chainId) // user didn't actually switch
|
|
2858
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("User cancelled switch network request", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR);
|
|
2859
|
+
// we can assume that if the above succeeds then user has successfully
|
|
2860
|
+
// switched to the network specified
|
|
2861
|
+
const newNetwork = ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId];
|
|
2862
|
+
return {
|
|
2863
|
+
network: {
|
|
2864
|
+
name: newNetwork.chainName,
|
|
2865
|
+
chainId: parseInt(newNetwork.chainIdHex, 16),
|
|
2866
|
+
nativeCurrency: newNetwork.nativeCurrency
|
|
2867
|
+
},
|
|
2868
|
+
provider: currentProvider
|
|
2869
|
+
};
|
|
2870
|
+
}
|
|
2871
|
+
async function $de192de6ef100f9f$export$3043f6442a9ef563({ type: type = ($a47e48dd2c04791b$export$1f05a55fe0680cc7).ALL , exclude: exclude }) {
|
|
2872
|
+
const list = ((/*@__PURE__*/$parcel$interopDefault($497c134ecbc8a50f$exports))).filter((network)=>{
|
|
2873
|
+
const allowAllTokens = type === ($a47e48dd2c04791b$export$1f05a55fe0680cc7).ALL;
|
|
2874
|
+
const networkNotExcluded = !(exclude || []).map((exc)=>exc.chainId).includes(network.chainId);
|
|
2875
|
+
return allowAllTokens && networkNotExcluded;
|
|
2876
|
+
});
|
|
2877
|
+
const allowedNetworks = [];
|
|
2878
|
+
list.forEach((element)=>{
|
|
2879
|
+
const newNetwork = ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[element.chainId];
|
|
2880
|
+
allowedNetworks.push({
|
|
2881
|
+
name: newNetwork.chainName,
|
|
2882
|
+
chainId: parseInt(newNetwork.chainIdHex, 16),
|
|
2883
|
+
nativeCurrency: newNetwork.nativeCurrency,
|
|
2884
|
+
isSupported: true
|
|
2885
|
+
});
|
|
2886
|
+
});
|
|
2887
|
+
return {
|
|
2888
|
+
networks: allowedNetworks
|
|
2889
|
+
};
|
|
2890
|
+
}
|
|
2891
|
+
// these functions should not be exported. These functions should be used as part of an exported function e.g switchWalletNetwork() above.
|
|
2892
|
+
// make sure to check if(provider.provider?.request) in the exported function and throw an error
|
|
2893
|
+
async function $de192de6ef100f9f$var$switchNetworkInWallet(provider, chainId) {
|
|
2894
|
+
if (provider.provider?.request) return await provider.provider.request({
|
|
2895
|
+
method: ($4f91c5f280efe242$export$a130407f3423b97d).SWITCH_NETWORK,
|
|
2896
|
+
params: [
|
|
2897
|
+
{
|
|
2898
|
+
chainId: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].chainIdHex
|
|
2899
|
+
}
|
|
2900
|
+
]
|
|
2901
|
+
});
|
|
2902
|
+
}
|
|
2903
|
+
async function $de192de6ef100f9f$var$addNetworkToWallet(provider, chainId) {
|
|
2904
|
+
if (provider.provider?.request) {
|
|
2905
|
+
const addNetwork = {
|
|
2906
|
+
chainId: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].chainIdHex,
|
|
2907
|
+
chainName: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].chainName,
|
|
2908
|
+
rpcUrls: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].rpcUrls,
|
|
2909
|
+
nativeCurrency: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].nativeCurrency,
|
|
2910
|
+
blockExplorerUrls: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].blockExplorerUrls
|
|
2911
|
+
};
|
|
2912
|
+
return await provider.provider.request({
|
|
2913
|
+
method: ($4f91c5f280efe242$export$a130407f3423b97d).ADD_NETWORK,
|
|
2914
|
+
params: [
|
|
2915
|
+
addNetwork
|
|
2916
|
+
]
|
|
2917
|
+
});
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
|
|
2921
|
+
|
|
2922
|
+
|
|
2923
|
+
|
|
2924
|
+
|
|
2925
|
+
var $cda6003506e4182e$exports = {};
|
|
2926
|
+
$cda6003506e4182e$exports = JSON.parse("[{\"address\":\"0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0\",\"chainId\":137,\"name\":\"Matic\",\"symbol\":\"MATIC\",\"decimals\":18,\"icon\":\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='utf-8'%3F%3E%3Csvg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 38.4 33.5' style='enable-background:new 0 0 38.4 33.5;' xml:space='preserve'%3E%3Cstyle type='text/css'%3E .st0%7Bfill:%238247E5;%7D%0A%3C/style%3E%3Cg%3E%3Cpath class='st0' d='M29,10.2c-0.7-0.4-1.6-0.4-2.4,0L21,13.5l-3.8,2.1l-5.5,3.3c-0.7,0.4-1.6,0.4-2.4,0L5,16.3 c-0.7-0.4-1.2-1.2-1.2-2.1v-5c0-0.8,0.4-1.6,1.2-2.1l4.3-2.5c0.7-0.4,1.6-0.4,2.4,0L16,7.2c0.7,0.4,1.2,1.2,1.2,2.1v3.3l3.8-2.2V7 c0-0.8-0.4-1.6-1.2-2.1l-8-4.7c-0.7-0.4-1.6-0.4-2.4,0L1.2,5C0.4,5.4,0,6.2,0,7v9.4c0,0.8,0.4,1.6,1.2,2.1l8.1,4.7 c0.7,0.4,1.6,0.4,2.4,0l5.5-3.2l3.8-2.2l5.5-3.2c0.7-0.4,1.6-0.4,2.4,0l4.3,2.5c0.7,0.4,1.2,1.2,1.2,2.1v5c0,0.8-0.4,1.6-1.2,2.1 L29,28.8c-0.7,0.4-1.6,0.4-2.4,0l-4.3-2.5c-0.7-0.4-1.2-1.2-1.2-2.1V21l-3.8,2.2v3.3c0,0.8,0.4,1.6,1.2,2.1l8.1,4.7 c0.7,0.4,1.6,0.4,2.4,0l8.1-4.7c0.7-0.4,1.2-1.2,1.2-2.1V17c0-0.8-0.4-1.6-1.2-2.1L29,10.2z'/%3E%3C/g%3E%3C/svg%3E%0A\",\"tokenFeatures\":[\"swap\",\"bridge\"]},{\"name\":\"Ethereum\",\"symbol\":\"ETH\",\"decimals\":18,\"icon\":\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3C!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3E%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' width='100%25' height='100%25' version='1.1' shape-rendering='geometricPrecision' text-rendering='geometricPrecision' image-rendering='optimizeQuality' fill-rule='evenodd' clip-rule='evenodd'%0AviewBox='0 0 784.37 1277.39' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:xodm='http://www.corel.com/coreldraw/odm/2003'%3E%3Cg id='Layer_x0020_1'%3E%3Cmetadata id='CorelCorpID_0Corel-Layer'/%3E%3Cg id='_1421394342400'%3E%3Cg%3E%3Cpolygon fill='%23343434' fill-rule='nonzero' points='392.07,0 383.5,29.11 383.5,873.74 392.07,882.29 784.13,650.54 '/%3E%3Cpolygon fill='%238C8C8C' fill-rule='nonzero' points='392.07,0 -0,650.54 392.07,882.29 392.07,472.33 '/%3E%3Cpolygon fill='%233C3C3B' fill-rule='nonzero' points='392.07,956.52 387.24,962.41 387.24,1263.28 392.07,1277.38 784.37,724.89 '/%3E%3Cpolygon fill='%238C8C8C' fill-rule='nonzero' points='392.07,1277.38 392.07,956.52 -0,724.89 '/%3E%3Cpolygon fill='%23141414' fill-rule='nonzero' points='392.07,882.29 784.13,650.54 392.07,472.33 '/%3E%3Cpolygon fill='%23393939' fill-rule='nonzero' points='0,650.54 392.07,882.29 392.07,472.33 '/%3E%3C/g%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A\",\"chainId\":1,\"tokenFeatures\":[\"swap\",\"bridge\"]},{\"address\":\"0xF57e7e7C23978C3cAEC3C3548E3D615c346e79fF\",\"chainId\":1,\"name\":\"Immutable X\",\"symbol\":\"IMX\",\"decimals\":18,\"icon\":\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='utf-8'%3F%3E%3Csvg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 139 113' style='enable-background:new 0 0 139 113;' xml:space='preserve'%3E%3Cstyle type='text/css'%3E .st0%7Bclip-path:url(%23SVGID_00000053504646934646330740000009134454895836103350_);%7D .st1%7Bfill:%2317B5CB;%7D%0A%3C/style%3E%3Cg%3E%3Cdefs%3E%3Crect id='SVGID_1_' width='139' height='113'/%3E%3C/defs%3E%3CclipPath id='SVGID_00000035518931339590433170000002358037249938198420_'%3E%3Cuse xlink:href='%23SVGID_1_' style='overflow:visible;'/%3E%3C/clipPath%3E%3Cg style='clip-path:url(%23SVGID_00000035518931339590433170000002358037249938198420_);'%3E%3Cpath class='st1' d='M124.1,0h14.6L79.5,67.6c-1.5,1.7-1.6,4.3-0.1,6.1l34.1,39.7H98.3L66.8,76.6l-1.6-2c-1.5-1.7-1.4-4.4,0.1-6.1 L124.1,0z'/%3E%3Cpath class='st1' d='M91.2,73.7c-1-1.1-1.3-2.7-1-4.1c0.3-0.8,0.8-1.6,1.4-2.2l3.9-4.3l43.5,50.3h-13.8 C125.2,113.4,99.7,83.6,91.2,73.7z'/%3E%3Cpath class='st1' d='M15.2,113.4H0l46.6-53.9c1.5-1.7,1.5-4.3,0-6L0.4,0H15l46.5,53.9c1.2,1.6,1.4,3.9,0.1,5.4 C49.4,73.4,15.2,113.4,15.2,113.4z'/%3E%3Cpath class='st1' d='M40.6,0h-14l43.1,49.9c0,0,0.1-0.1,4.9-5.8c1.3-1.5,1.6-3.4,0.1-4.9C65.7,30,40.6,0,40.6,0z'/%3E%3Cpath class='st1' d='M82.6,34.8L112.5,0H98.3L82.7,18.2l-4.5,5.3c-1.5,1.7-1.6,4.3-0.1,6.1C79.2,30.9,82.6,34.8,82.6,34.8z'/%3E%3Cpath class='st1' d='M56.6,78.6l-29.9,34.8h14.1l15.6-18.2l4.5-5.3c1.5-1.7,1.6-4.3,0.1-6.1C59.9,82.5,56.6,78.6,56.6,78.6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A\",\"tokenFeatures\":[\"swap\",\"bridge\"]},{\"address\":\"0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0\",\"chainId\":1,\"name\":\"Matic\",\"symbol\":\"MATIC\",\"decimals\":18,\"icon\":\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='utf-8'%3F%3E%3Csvg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 38.4 33.5' style='enable-background:new 0 0 38.4 33.5;' xml:space='preserve'%3E%3Cstyle type='text/css'%3E .st0%7Bfill:%238247E5;%7D%0A%3C/style%3E%3Cg%3E%3Cpath class='st0' d='M29,10.2c-0.7-0.4-1.6-0.4-2.4,0L21,13.5l-3.8,2.1l-5.5,3.3c-0.7,0.4-1.6,0.4-2.4,0L5,16.3 c-0.7-0.4-1.2-1.2-1.2-2.1v-5c0-0.8,0.4-1.6,1.2-2.1l4.3-2.5c0.7-0.4,1.6-0.4,2.4,0L16,7.2c0.7,0.4,1.2,1.2,1.2,2.1v3.3l3.8-2.2V7 c0-0.8-0.4-1.6-1.2-2.1l-8-4.7c-0.7-0.4-1.6-0.4-2.4,0L1.2,5C0.4,5.4,0,6.2,0,7v9.4c0,0.8,0.4,1.6,1.2,2.1l8.1,4.7 c0.7,0.4,1.6,0.4,2.4,0l5.5-3.2l3.8-2.2l5.5-3.2c0.7-0.4,1.6-0.4,2.4,0l4.3,2.5c0.7,0.4,1.2,1.2,1.2,2.1v5c0,0.8-0.4,1.6-1.2,2.1 L29,28.8c-0.7,0.4-1.6,0.4-2.4,0l-4.3-2.5c-0.7-0.4-1.2-1.2-1.2-2.1V21l-3.8,2.2v3.3c0,0.8,0.4,1.6,1.2,2.1l8.1,4.7 c0.7,0.4,1.6,0.4,2.4,0l8.1-4.7c0.7-0.4,1.2-1.2,1.2-2.1V17c0-0.8-0.4-1.6-1.2-2.1L29,10.2z'/%3E%3C/g%3E%3C/svg%3E%0A\",\"tokenFeatures\":[\"swap\",\"bridge\"]},{\"name\":\"Ethereum\",\"symbol\":\"ETH\",\"decimals\":18,\"icon\":\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3C!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3E%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' width='100%25' height='100%25' version='1.1' shape-rendering='geometricPrecision' text-rendering='geometricPrecision' image-rendering='optimizeQuality' fill-rule='evenodd' clip-rule='evenodd'%0AviewBox='0 0 784.37 1277.39' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:xodm='http://www.corel.com/coreldraw/odm/2003'%3E%3Cg id='Layer_x0020_1'%3E%3Cmetadata id='CorelCorpID_0Corel-Layer'/%3E%3Cg id='_1421394342400'%3E%3Cg%3E%3Cpolygon fill='%23343434' fill-rule='nonzero' points='392.07,0 383.5,29.11 383.5,873.74 392.07,882.29 784.13,650.54 '/%3E%3Cpolygon fill='%238C8C8C' fill-rule='nonzero' points='392.07,0 -0,650.54 392.07,882.29 392.07,472.33 '/%3E%3Cpolygon fill='%233C3C3B' fill-rule='nonzero' points='392.07,956.52 387.24,962.41 387.24,1263.28 392.07,1277.38 784.37,724.89 '/%3E%3Cpolygon fill='%238C8C8C' fill-rule='nonzero' points='392.07,1277.38 392.07,956.52 -0,724.89 '/%3E%3Cpolygon fill='%23141414' fill-rule='nonzero' points='392.07,882.29 784.13,650.54 392.07,472.33 '/%3E%3Cpolygon fill='%23393939' fill-rule='nonzero' points='0,650.54 392.07,882.29 392.07,472.33 '/%3E%3C/g%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A\",\"chainId\":5,\"tokenFeatures\":[\"swap\",\"bridge\"]},{\"address\":\"0x1facdd0165489f373255a90304650e15481b2c85\",\"chainId\":5,\"name\":\"Immutable X\",\"symbol\":\"IMX\",\"decimals\":18,\"icon\":\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='utf-8'%3F%3E%3Csvg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 139 113' style='enable-background:new 0 0 139 113;' xml:space='preserve'%3E%3Cstyle type='text/css'%3E .st0%7Bclip-path:url(%23SVGID_00000053504646934646330740000009134454895836103350_);%7D .st1%7Bfill:%2317B5CB;%7D%0A%3C/style%3E%3Cg%3E%3Cdefs%3E%3Crect id='SVGID_1_' width='139' height='113'/%3E%3C/defs%3E%3CclipPath id='SVGID_00000035518931339590433170000002358037249938198420_'%3E%3Cuse xlink:href='%23SVGID_1_' style='overflow:visible;'/%3E%3C/clipPath%3E%3Cg style='clip-path:url(%23SVGID_00000035518931339590433170000002358037249938198420_);'%3E%3Cpath class='st1' d='M124.1,0h14.6L79.5,67.6c-1.5,1.7-1.6,4.3-0.1,6.1l34.1,39.7H98.3L66.8,76.6l-1.6-2c-1.5-1.7-1.4-4.4,0.1-6.1 L124.1,0z'/%3E%3Cpath class='st1' d='M91.2,73.7c-1-1.1-1.3-2.7-1-4.1c0.3-0.8,0.8-1.6,1.4-2.2l3.9-4.3l43.5,50.3h-13.8 C125.2,113.4,99.7,83.6,91.2,73.7z'/%3E%3Cpath class='st1' d='M15.2,113.4H0l46.6-53.9c1.5-1.7,1.5-4.3,0-6L0.4,0H15l46.5,53.9c1.2,1.6,1.4,3.9,0.1,5.4 C49.4,73.4,15.2,113.4,15.2,113.4z'/%3E%3Cpath class='st1' d='M40.6,0h-14l43.1,49.9c0,0,0.1-0.1,4.9-5.8c1.3-1.5,1.6-3.4,0.1-4.9C65.7,30,40.6,0,40.6,0z'/%3E%3Cpath class='st1' d='M82.6,34.8L112.5,0H98.3L82.7,18.2l-4.5,5.3c-1.5,1.7-1.6,4.3-0.1,6.1C79.2,30.9,82.6,34.8,82.6,34.8z'/%3E%3Cpath class='st1' d='M56.6,78.6l-29.9,34.8h14.1l15.6-18.2l4.5-5.3c1.5-1.7,1.6-4.3,0.1-6.1C59.9,82.5,56.6,78.6,56.6,78.6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A\",\"tokenFeatures\":[\"swap\",\"bridge\"]},{\"address\":\"0x123456789\",\"chainId\":5,\"name\":\"Swap Coin\",\"symbol\":\"SWC\",\"decimals\":18,\"tokenFeatures\":[\"swap\",\"fakeFeature\"]},{\"address\":\"0x123456789\",\"chainId\":5,\"name\":\"Bridge Coin\",\"symbol\":\"BDC\",\"decimals\":18,\"tokenFeatures\":[\"bridge\",\"fakeFeature\"]}]");
|
|
2927
|
+
|
|
2928
|
+
|
|
2929
|
+
const $efe60cea83bfc4e8$var$filterTokenList = function({ type: type , chainId: chainId , exclude: exclude }) {
|
|
2930
|
+
return ((/*@__PURE__*/$parcel$interopDefault($cda6003506e4182e$exports))).filter((token)=>{
|
|
2931
|
+
const skipChainIdCheck = !chainId;
|
|
2932
|
+
const chainIdMatches = token.chainId == chainId;
|
|
2933
|
+
const tokenNotExcluded = !exclude?.map((excludeToken)=>excludeToken.address).includes(token.address || "");
|
|
2934
|
+
const allowAllTokens = type === ($08d5ddc39acd6833$export$fd9b17d87f4121d2).ALL;
|
|
2935
|
+
const tokenAllowedForType = token.tokenFeatures.includes(type);
|
|
2936
|
+
return (skipChainIdCheck || chainIdMatches) && tokenNotExcluded && (allowAllTokens || tokenAllowedForType);
|
|
2937
|
+
});
|
|
2938
|
+
};
|
|
2939
|
+
const $efe60cea83bfc4e8$export$473cec51305fdae8 = async function({ type: type = ($08d5ddc39acd6833$export$fd9b17d87f4121d2).ALL , chainId: chainId , exclude: exclude }) {
|
|
2940
|
+
// todo:For API call, use the CheckoutError with errorType:API_CALL_ERROR?? or any other
|
|
2941
|
+
const filteredTokenList = $efe60cea83bfc4e8$var$filterTokenList({
|
|
2942
|
+
type: type,
|
|
2943
|
+
chainId: chainId,
|
|
2944
|
+
exclude: exclude
|
|
2945
|
+
}).map((token)=>{
|
|
2946
|
+
const { chainId: chainId , tokenFeatures: tokenFeatures , ...tokenInfo } = token;
|
|
2947
|
+
return tokenInfo;
|
|
2948
|
+
});
|
|
2949
|
+
return {
|
|
2950
|
+
tokens: filteredTokenList
|
|
2951
|
+
};
|
|
2952
|
+
};
|
|
2953
|
+
|
|
2954
|
+
|
|
2955
|
+
|
|
2956
|
+
|
|
2957
|
+
const $1564e43dde50bb61$export$df96cd8d56be0ab1 = async (provider, walletAddress)=>{
|
|
2958
|
+
return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2959
|
+
const networkInfo = await ($de192de6ef100f9f$export$79f13b4cfaaf0d09)(provider);
|
|
2960
|
+
if (!networkInfo.isSupported) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`Chain:${networkInfo.chainId} is not a supported chain`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CHAIN_NOT_SUPPORTED_ERROR, {
|
|
2961
|
+
chainName: networkInfo.name
|
|
2962
|
+
});
|
|
2963
|
+
const balance = await provider.getBalance(walletAddress);
|
|
2964
|
+
return {
|
|
2965
|
+
balance: balance,
|
|
2966
|
+
formattedBalance: (utils).formatUnits(balance, networkInfo.nativeCurrency.decimals),
|
|
2967
|
+
token: networkInfo.nativeCurrency
|
|
2968
|
+
};
|
|
2969
|
+
}, {
|
|
2970
|
+
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_BALANCE_ERROR
|
|
2971
|
+
});
|
|
2972
|
+
};
|
|
2973
|
+
async function $1564e43dde50bb61$export$60e0fe116a0e6ed0(provider, walletAddress, contractAddress) {
|
|
2974
|
+
return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2975
|
+
const contract = new (Contract)(contractAddress, JSON.stringify(($762782b6c862d954$export$db5daa1b5156ccfe)), provider);
|
|
2976
|
+
const name = await contract.name();
|
|
2977
|
+
const symbol = await contract.symbol();
|
|
2978
|
+
const balance = await contract.balanceOf(walletAddress);
|
|
2979
|
+
const decimals = await contract.decimals();
|
|
2980
|
+
const formattedBalance = (utils).formatUnits(balance, decimals);
|
|
2981
|
+
return {
|
|
2982
|
+
balance: balance,
|
|
2983
|
+
formattedBalance: formattedBalance,
|
|
2984
|
+
token: {
|
|
2985
|
+
name: name,
|
|
2986
|
+
symbol: symbol,
|
|
2987
|
+
decimals: decimals,
|
|
2988
|
+
address: contractAddress
|
|
2989
|
+
}
|
|
2990
|
+
};
|
|
2991
|
+
}, {
|
|
2992
|
+
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC20_BALANCE_ERROR
|
|
2993
|
+
});
|
|
2994
|
+
}
|
|
2995
|
+
const $1564e43dde50bb61$export$fee49741664a4d7e = async (provider, walletAddress, chainId)=>{
|
|
2996
|
+
if (!Object.values(($a47e48dd2c04791b$export$c06e1e7429de6283)).includes(chainId)) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`ChainId ${chainId} is not supported`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CHAIN_NOT_SUPPORTED_ERROR);
|
|
2997
|
+
if (!provider.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("provider object is missing request function", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_MISSING_ERROR);
|
|
2998
|
+
const tokenList = await ($efe60cea83bfc4e8$export$473cec51305fdae8)({
|
|
2999
|
+
type: ($08d5ddc39acd6833$export$fd9b17d87f4121d2).ALL,
|
|
3000
|
+
chainId: chainId
|
|
3001
|
+
});
|
|
3002
|
+
const allBalancePromises = [];
|
|
3003
|
+
allBalancePromises.push($1564e43dde50bb61$export$df96cd8d56be0ab1(provider, walletAddress));
|
|
3004
|
+
tokenList.tokens.filter((token)=>token.address).forEach((token)=>allBalancePromises.push($1564e43dde50bb61$export$60e0fe116a0e6ed0(provider, walletAddress, token.address ?? "")));
|
|
3005
|
+
const balanceResults = await Promise.allSettled(allBalancePromises);
|
|
3006
|
+
const getBalanceResults = balanceResults.filter((result)=>result.status === "fulfilled").map((fulfilledResult)=>fulfilledResult.value);
|
|
3007
|
+
return {
|
|
3008
|
+
balances: getBalanceResults
|
|
3009
|
+
};
|
|
3010
|
+
};
|
|
3011
|
+
|
|
3012
|
+
|
|
3013
|
+
|
|
3014
|
+
|
|
3015
|
+
|
|
3016
|
+
|
|
3017
|
+
|
|
3018
|
+
|
|
3019
|
+
|
|
3020
|
+
var $6f3c55a615003cbf$exports = {};
|
|
3021
|
+
$6f3c55a615003cbf$exports = JSON.parse('[{"connectionProvider":"metamask","icon":"some-icon-url","name":"MetaMask","description":"complete web3 wallet solution","platform":["desktop"]},{"connectionProvider":"passport","icon":"pp-icon","name":"Passport","description":"Web3 with your email!","platform":["mobile","desktop"]},{"connectionProvider":"gamestop","icon":"gme-icon","name":"GameStop","description":"Never stopping the game!","platform":["mobile"]}]');
|
|
3022
|
+
|
|
3023
|
+
|
|
3024
|
+
async function $5cdde2ffe6360fec$export$a822caa90d7eef09({ type: type = ($4f91c5f280efe242$export$a75605c67ea83a5a).ALL , exclude: exclude }) {
|
|
3025
|
+
// todo:For async API call, use the CheckoutError with errorType:API_CALL_ERROR?? or any other
|
|
3026
|
+
const filteredWalletsList = ((/*@__PURE__*/$parcel$interopDefault($6f3c55a615003cbf$exports))).filter((wallet)=>{
|
|
3027
|
+
const walletNotExcluded = !exclude?.map((excludeWallet)=>excludeWallet.connectionProvider).includes(wallet.connectionProvider);
|
|
3028
|
+
const allowAllWallets = type === ($4f91c5f280efe242$export$a75605c67ea83a5a).ALL;
|
|
3029
|
+
const walletsAllowedForType = wallet.platform.includes(type);
|
|
3030
|
+
return walletNotExcluded && (allowAllWallets || walletsAllowedForType);
|
|
3031
|
+
}).map((wallet)=>{
|
|
3032
|
+
const { platform: platform , ...walletInfo } = wallet;
|
|
3033
|
+
return walletInfo;
|
|
3034
|
+
});
|
|
3035
|
+
return {
|
|
3036
|
+
wallets: filteredWalletsList
|
|
3037
|
+
};
|
|
3038
|
+
}
|
|
3039
|
+
|
|
3040
|
+
|
|
3041
|
+
|
|
3042
|
+
|
|
3043
|
+
|
|
3044
|
+
|
|
3045
|
+
const $dbe95599a4661140$export$8e0e7ffc78696d30 = async (params)=>{
|
|
3046
|
+
const { provider: provider , transaction: transaction } = params;
|
|
3047
|
+
return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
3048
|
+
const transactionResponse = await provider.getSigner().sendTransaction(transaction);
|
|
3049
|
+
return {
|
|
3050
|
+
transactionResponse: transactionResponse
|
|
3051
|
+
};
|
|
3052
|
+
}, {
|
|
3053
|
+
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).TRANSACTION_ERROR
|
|
3054
|
+
});
|
|
3055
|
+
};
|
|
3056
|
+
|
|
3057
|
+
|
|
3058
|
+
|
|
3059
|
+
|
|
3060
|
+
|
|
3061
|
+
class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
|
|
3062
|
+
/**
|
|
3063
|
+
* Check if a wallet is connected to the current application without requesting permission from the wallet and hence triggering a connect popup.
|
|
3064
|
+
* @param {CheckConnectionParams} params - The necessary data required to verify a wallet connection status.
|
|
3065
|
+
* @returns Wallet connection status details.
|
|
3066
|
+
* @throws {@link ErrorType}
|
|
3067
|
+
*/ async checkIsWalletConnected(params) {
|
|
3068
|
+
return $c99672cf2294e839$export$2d040992269b4717(params.providerPreference);
|
|
3069
|
+
}
|
|
3070
|
+
/**
|
|
3071
|
+
* Establish a connection with a wallet provider such as MetaMask and returns the provider object and the current network details.
|
|
3072
|
+
* @param {ConnectParams} params - The necessary data required to establish a connection with a wallet provider.
|
|
3073
|
+
* @returns Wallet provider and current network information.
|
|
3074
|
+
* @throws {@link ErrorType}
|
|
3075
|
+
*/ async connect(params) {
|
|
3076
|
+
this.providerPreference = params.providerPreference;
|
|
3077
|
+
const provider = await $c99672cf2294e839$export$fba2f6c3656e07c1(params);
|
|
3078
|
+
const networkInfo = await $de192de6ef100f9f$export$79f13b4cfaaf0d09(provider);
|
|
3079
|
+
return {
|
|
3080
|
+
provider: provider,
|
|
3081
|
+
network: networkInfo
|
|
3082
|
+
};
|
|
3083
|
+
}
|
|
3084
|
+
/**
|
|
3085
|
+
* Switch the currently connected wallet to a new network.
|
|
3086
|
+
* @param {SwitchNetworkParams} params - The necessary data required to switch network.
|
|
3087
|
+
* @returns The new network information.
|
|
3088
|
+
* @throws {@link ErrorType}
|
|
3089
|
+
*/ async switchNetwork(params) {
|
|
3090
|
+
if (!this.providerPreference) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`connect should be called before switchNetwork to set the provider preference`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_PREFERENCE_ERROR);
|
|
3091
|
+
return await $de192de6ef100f9f$export$b827d9418aeb5dbd(this.providerPreference, params.provider, params.chainId);
|
|
3092
|
+
}
|
|
3093
|
+
/**
|
|
3094
|
+
* Fetch the balance of the native token of the current connected network or, if a contract address is provided, it will return the balance of that ERC20 token. For example, if the wallet is connected to the Ethereum Mainnet then the function gets the wallet ETH L1 balance.
|
|
3095
|
+
* @param {GetBalanceParams} params - The necessary data required to fetch the wallet balance.
|
|
3096
|
+
* @returns Native token balance for the given wallet.
|
|
3097
|
+
* @throws {@link ErrorType}
|
|
3098
|
+
*/ async getBalance(params) {
|
|
3099
|
+
if (!params.contractAddress || params.contractAddress === "") return await $1564e43dde50bb61$export$df96cd8d56be0ab1(params.provider, params.walletAddress);
|
|
3100
|
+
return await $1564e43dde50bb61$export$60e0fe116a0e6ed0(params.provider, params.walletAddress, params.contractAddress);
|
|
3101
|
+
}
|
|
3102
|
+
/**
|
|
3103
|
+
* Fetch all available balances (ERC20 & Native) of the current connected network of the given wallet. It will loop through the list of allowed tokens and check for balance on each one.
|
|
3104
|
+
* @param {GetAllBalancesParams} params - The necessary data required to fetch all the wallet balances.
|
|
3105
|
+
* @returns List of tokens balance for the given wallet.
|
|
3106
|
+
* @throws {@link ErrorType}
|
|
3107
|
+
*/ async getAllBalances(params) {
|
|
3108
|
+
return $1564e43dde50bb61$export$fee49741664a4d7e(params.provider, params.walletAddress, params.chainId);
|
|
3109
|
+
}
|
|
3110
|
+
/**
|
|
3111
|
+
* Fetch the list of available networks that a wallet can add or/and switch to.
|
|
3112
|
+
* @param {GetNetworkAllowListParams} params - The necessary data required to fetch the list of available networks.
|
|
3113
|
+
* @returns List of networks.
|
|
3114
|
+
* @throws {@link ErrorType}
|
|
3115
|
+
*/ async getNetworkAllowList(params) {
|
|
3116
|
+
return await $de192de6ef100f9f$export$3043f6442a9ef563(params);
|
|
3117
|
+
}
|
|
3118
|
+
/**
|
|
3119
|
+
* Get the list of tokens which are allowed to be used with the product.
|
|
3120
|
+
* @param {GetTokenAllowListParams} params - The necessary data required to fetch the list of allowed tokens.
|
|
3121
|
+
* @returns List of allowed tokens.
|
|
3122
|
+
* @throws {@link ErrorType}
|
|
3123
|
+
*/ async getTokenAllowList(params) {
|
|
3124
|
+
return await $efe60cea83bfc4e8$export$473cec51305fdae8(params);
|
|
3125
|
+
}
|
|
3126
|
+
/**
|
|
3127
|
+
* Fetch the list of wallets which are available to connect with.
|
|
3128
|
+
* @param {GetWalletAllowListParams} params - The necessary data required to fetch the list of allowed wallets.
|
|
3129
|
+
* @returns List of allowed wallets.
|
|
3130
|
+
* @throws {@link ErrorType}
|
|
3131
|
+
*/ async getWalletAllowList(params) {
|
|
3132
|
+
return await $5cdde2ffe6360fec$export$a822caa90d7eef09(params);
|
|
3133
|
+
}
|
|
3134
|
+
/**
|
|
3135
|
+
* Send a generic transaction to the provider.
|
|
3136
|
+
* @param {SendTransactionParams} params - The necessary data required to send a transaction.
|
|
3137
|
+
* @returns Transaction response.
|
|
3138
|
+
* @throws {@link ErrorType}
|
|
3139
|
+
* @remarks
|
|
3140
|
+
* Further documenation can be found at [MetaMask | Sending Transactions](https://docs.metamask.io/guide/sending-transactions.html).
|
|
3141
|
+
*/ async sendTransaction(params) {
|
|
3142
|
+
return await $dbe95599a4661140$export$8e0e7ffc78696d30(params);
|
|
3143
|
+
}
|
|
3144
|
+
/**
|
|
3145
|
+
* Get network information about the currently selected network.
|
|
3146
|
+
* @param {GetNetworkParams} params - The necessary data required to get the current network information.
|
|
3147
|
+
* @returns Network details.
|
|
3148
|
+
* @throws {@link ErrorType}
|
|
3149
|
+
*/ async getNetworkInfo(params) {
|
|
3150
|
+
return await $de192de6ef100f9f$export$79f13b4cfaaf0d09(params.provider);
|
|
3151
|
+
}
|
|
3152
|
+
}
|
|
3153
|
+
|
|
3154
|
+
function $parcel$export(e, n, v, s) {
|
|
3155
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
3156
|
+
}
|
|
3157
|
+
var $207ed853f11d19d5$exports = {};
|
|
3158
|
+
|
|
3159
|
+
$parcel$export($207ed853f11d19d5$exports, "IMTBLWidgetEvents", () => $207ed853f11d19d5$export$5a0ace85cae72d45);
|
|
3160
|
+
let $207ed853f11d19d5$export$5a0ace85cae72d45;
|
|
3161
|
+
(function(IMTBLWidgetEvents) {
|
|
3162
|
+
IMTBLWidgetEvents["IMTBL_CONNECT_WIDGET_EVENT"] = "imtbl-connect-widget";
|
|
3163
|
+
IMTBLWidgetEvents["IMTBL_WALLET_WIDGET_EVENT"] = "imtbl-wallet-widget";
|
|
3164
|
+
IMTBLWidgetEvents["IMTBL_SWAP_WIDGET_EVENT"] = "imtbl-swap-widget";
|
|
3165
|
+
IMTBLWidgetEvents["IMTBL_BRIDGE_WIDGET_EVENT"] = "imtbl-bridge-widget";
|
|
3166
|
+
IMTBLWidgetEvents["IMTBL_BUY_WIDGET_EVENT"] = "imtbl-buy-widget";
|
|
3167
|
+
})($207ed853f11d19d5$export$5a0ace85cae72d45 || ($207ed853f11d19d5$export$5a0ace85cae72d45 = {}));
|
|
3168
|
+
|
|
3169
|
+
|
|
3170
|
+
var $a85ecdbd885c58ad$exports = {};
|
|
3171
|
+
|
|
3172
|
+
$parcel$export($a85ecdbd885c58ad$exports, "ConnectEventType", () => $a85ecdbd885c58ad$export$e72e7f9969a47dd3);
|
|
3173
|
+
let $a85ecdbd885c58ad$export$e72e7f9969a47dd3;
|
|
3174
|
+
(function(ConnectEventType) {
|
|
3175
|
+
ConnectEventType["SUCCESS"] = "success";
|
|
3176
|
+
ConnectEventType["FAILURE"] = "failure";
|
|
3177
|
+
ConnectEventType["CLOSE_WIDGET"] = "close-widget";
|
|
3178
|
+
})($a85ecdbd885c58ad$export$e72e7f9969a47dd3 || ($a85ecdbd885c58ad$export$e72e7f9969a47dd3 = {}));
|
|
3179
|
+
|
|
3180
|
+
|
|
3181
|
+
var $77b6aac5c353d4a9$exports = {};
|
|
3182
|
+
|
|
3183
|
+
$parcel$export($77b6aac5c353d4a9$exports, "WalletEventType", () => $77b6aac5c353d4a9$export$d9be06b70b28c742);
|
|
3184
|
+
//wallet widget events
|
|
3185
|
+
let $77b6aac5c353d4a9$export$d9be06b70b28c742;
|
|
3186
|
+
(function(WalletEventType) {
|
|
3187
|
+
WalletEventType["CLOSE_WIDGET"] = "close-widget";
|
|
3188
|
+
WalletEventType["NETWORK_SWITCH"] = "network-switch";
|
|
3189
|
+
})($77b6aac5c353d4a9$export$d9be06b70b28c742 || ($77b6aac5c353d4a9$export$d9be06b70b28c742 = {}));
|
|
3190
|
+
|
|
3191
|
+
|
|
3192
|
+
var $53d219e7f6bf0cd6$exports = {};
|
|
3193
|
+
|
|
3194
|
+
$parcel$export($53d219e7f6bf0cd6$exports, "SwapEventType", () => $53d219e7f6bf0cd6$export$140a49745ab55563);
|
|
3195
|
+
let $53d219e7f6bf0cd6$export$140a49745ab55563;
|
|
3196
|
+
(function(SwapEventType) {
|
|
3197
|
+
SwapEventType["SUCCESS"] = "success";
|
|
3198
|
+
SwapEventType["FAILURE"] = "failure";
|
|
3199
|
+
})($53d219e7f6bf0cd6$export$140a49745ab55563 || ($53d219e7f6bf0cd6$export$140a49745ab55563 = {}));
|
|
3200
|
+
|
|
3201
|
+
|
|
3202
|
+
var $15cc9e120aa6f3bf$exports = {};
|
|
3203
|
+
|
|
3204
|
+
$parcel$export($15cc9e120aa6f3bf$exports, "BridgeEventType", () => $15cc9e120aa6f3bf$export$d1bfa21f7c76447a);
|
|
3205
|
+
let $15cc9e120aa6f3bf$export$d1bfa21f7c76447a;
|
|
3206
|
+
(function(BridgeEventType) {
|
|
3207
|
+
BridgeEventType["CLOSE_WIDGET"] = "close-widget";
|
|
3208
|
+
BridgeEventType["SUCCESS"] = "success";
|
|
3209
|
+
BridgeEventType["FAILURE"] = "failure";
|
|
3210
|
+
})($15cc9e120aa6f3bf$export$d1bfa21f7c76447a || ($15cc9e120aa6f3bf$export$d1bfa21f7c76447a = {}));
|
|
3211
|
+
|
|
3212
|
+
|
|
3213
|
+
var $98cbcca465beec95$exports = {};
|
|
3214
|
+
|
|
3215
|
+
$parcel$export($98cbcca465beec95$exports, "BuyEventType", () => $98cbcca465beec95$export$90db5fe1be5993c1);
|
|
3216
|
+
let $98cbcca465beec95$export$90db5fe1be5993c1;
|
|
3217
|
+
(function(BuyEventType) {
|
|
3218
|
+
BuyEventType["SUCCESS"] = "success";
|
|
3219
|
+
BuyEventType["FAILURE"] = "failure";
|
|
3220
|
+
BuyEventType["NOT_CONNECTED"] = "not_connected";
|
|
3221
|
+
BuyEventType["CLOSE"] = "close";
|
|
3222
|
+
})($98cbcca465beec95$export$90db5fe1be5993c1 || ($98cbcca465beec95$export$90db5fe1be5993c1 = {}));
|
|
3223
|
+
|
|
3224
|
+
|
|
3225
|
+
var $14d7a2bbb79e0dae$exports = {};
|
|
3226
|
+
|
|
3227
|
+
$parcel$export($14d7a2bbb79e0dae$exports, "Network", () => $14d7a2bbb79e0dae$export$95be4ae94445245a);
|
|
3228
|
+
$parcel$export($14d7a2bbb79e0dae$exports, "WidgetTheme", () => $14d7a2bbb79e0dae$export$c88931fdc51854eb);
|
|
3229
|
+
$parcel$export($14d7a2bbb79e0dae$exports, "WidgetConnectionProviders", () => $14d7a2bbb79e0dae$export$2f61dde3bdc320cb);
|
|
3230
|
+
$parcel$export($14d7a2bbb79e0dae$exports, "CheckoutWidgetTagNames", () => $14d7a2bbb79e0dae$export$75be0f6af9650f2c);
|
|
3231
|
+
let $14d7a2bbb79e0dae$export$95be4ae94445245a;
|
|
3232
|
+
(function(Network) {
|
|
3233
|
+
Network["ETHEREUM"] = "Ethereum";
|
|
3234
|
+
Network["GOERLI"] = "Goerli";
|
|
3235
|
+
Network["POLYGON"] = "Polygon";
|
|
3236
|
+
})($14d7a2bbb79e0dae$export$95be4ae94445245a || ($14d7a2bbb79e0dae$export$95be4ae94445245a = {}));
|
|
3237
|
+
let $14d7a2bbb79e0dae$export$c88931fdc51854eb;
|
|
3238
|
+
(function(WidgetTheme) {
|
|
3239
|
+
WidgetTheme["LIGHT"] = "light";
|
|
3240
|
+
WidgetTheme["DARK"] = "dark";
|
|
3241
|
+
WidgetTheme["CUSTOM"] = "custom";
|
|
3242
|
+
})($14d7a2bbb79e0dae$export$c88931fdc51854eb || ($14d7a2bbb79e0dae$export$c88931fdc51854eb = {}));
|
|
3243
|
+
let $14d7a2bbb79e0dae$export$2f61dde3bdc320cb;
|
|
3244
|
+
(function(WidgetConnectionProviders) {
|
|
3245
|
+
WidgetConnectionProviders["METAMASK"] = "metamask";
|
|
3246
|
+
})($14d7a2bbb79e0dae$export$2f61dde3bdc320cb || ($14d7a2bbb79e0dae$export$2f61dde3bdc320cb = {}));
|
|
3247
|
+
let $14d7a2bbb79e0dae$export$75be0f6af9650f2c;
|
|
3248
|
+
(function(CheckoutWidgetTagNames) {
|
|
3249
|
+
CheckoutWidgetTagNames["CONNECT"] = "imtbl-connect";
|
|
3250
|
+
CheckoutWidgetTagNames["WALLET"] = "imtbl-wallet";
|
|
3251
|
+
CheckoutWidgetTagNames["SWAP"] = "imtbl-swap";
|
|
3252
|
+
CheckoutWidgetTagNames["BUY"] = "imtbl-buy";
|
|
3253
|
+
CheckoutWidgetTagNames["BRIDGE"] = "imtbl-bridge";
|
|
3254
|
+
CheckoutWidgetTagNames["EXAMPLe"] = "imtbl-example";
|
|
3255
|
+
})($14d7a2bbb79e0dae$export$75be0f6af9650f2c || ($14d7a2bbb79e0dae$export$75be0f6af9650f2c = {}));
|
|
3256
|
+
|
|
3257
|
+
|
|
3258
|
+
var $1f969328e5988c99$exports = {};
|
|
3259
|
+
|
|
3260
|
+
$parcel$export($1f969328e5988c99$exports, "BridgeReact", () => $1f969328e5988c99$export$30f61ebf204c69f6);
|
|
3261
|
+
|
|
3262
|
+
|
|
3263
|
+
|
|
3264
|
+
function $1f969328e5988c99$export$30f61ebf204c69f6(props) {
|
|
3265
|
+
const { providerPreference: providerPreference , fromContractAddress: fromContractAddress , amount: amount , fromNetwork: fromNetwork } = props;
|
|
3266
|
+
const config = window.ImtblCheckoutWidgetConfig;
|
|
3267
|
+
return /*#__PURE__*/ (jsx)("imtbl-bridge", {
|
|
3268
|
+
providerPreference: providerPreference ?? ($14d7a2bbb79e0dae$export$2f61dde3bdc320cb).METAMASK,
|
|
3269
|
+
theme: config.theme ?? ($14d7a2bbb79e0dae$export$c88931fdc51854eb).DARK,
|
|
3270
|
+
fromContractAddress: fromContractAddress ?? "",
|
|
3271
|
+
fromNetwork: fromNetwork ?? "",
|
|
3272
|
+
amount: amount ?? ""
|
|
3273
|
+
});
|
|
3274
|
+
}
|
|
3275
|
+
|
|
3276
|
+
|
|
3277
|
+
var $f22931ca9e2f35b6$exports = {};
|
|
3278
|
+
|
|
3279
|
+
$parcel$export($f22931ca9e2f35b6$exports, "BuyReact", () => $f22931ca9e2f35b6$export$d13582032b79b401);
|
|
3280
|
+
|
|
3281
|
+
|
|
3282
|
+
|
|
3283
|
+
function $f22931ca9e2f35b6$export$d13582032b79b401(props) {
|
|
3284
|
+
const { providerPreference: providerPreference , orderId: orderId } = props;
|
|
3285
|
+
const config = window.ImtblCheckoutWidgetConfig;
|
|
3286
|
+
return /*#__PURE__*/ (jsx)("imtbl-buy", {
|
|
3287
|
+
providerPreference: providerPreference ?? ($14d7a2bbb79e0dae$export$2f61dde3bdc320cb).METAMASK,
|
|
3288
|
+
theme: config.theme ?? ($14d7a2bbb79e0dae$export$c88931fdc51854eb).DARK,
|
|
3289
|
+
orderId: orderId
|
|
3290
|
+
});
|
|
3291
|
+
}
|
|
3292
|
+
|
|
3293
|
+
|
|
3294
|
+
var $fa90757d8d7a0962$exports = {};
|
|
3295
|
+
|
|
3296
|
+
$parcel$export($fa90757d8d7a0962$exports, "CheckoutWidgets", () => $fa90757d8d7a0962$export$af210a0808087845);
|
|
3297
|
+
$parcel$export($fa90757d8d7a0962$exports, "UpdateConfig", () => $fa90757d8d7a0962$export$bf1548ba7e61c17f);
|
|
3298
|
+
$parcel$export($fa90757d8d7a0962$exports, "SetProvider", () => $fa90757d8d7a0962$export$931068bc678f0d73);
|
|
3299
|
+
function $fa90757d8d7a0962$export$af210a0808087845(config) {
|
|
3300
|
+
var checkoutWidgetJS = document.createElement("script");
|
|
3301
|
+
checkoutWidgetJS.setAttribute("src", "http://localhost:3000/lib/js/imtbl-checkout.js");
|
|
3302
|
+
document.head.appendChild(checkoutWidgetJS);
|
|
3303
|
+
window.ImtblCheckoutWidgetConfig = config;
|
|
3304
|
+
}
|
|
3305
|
+
function $fa90757d8d7a0962$export$bf1548ba7e61c17f(config) {
|
|
3306
|
+
window.ImtblCheckoutWidgetConfig = config;
|
|
3307
|
+
}
|
|
3308
|
+
function $fa90757d8d7a0962$export$931068bc678f0d73(tagName, provider) {
|
|
3309
|
+
if (!provider) {
|
|
3310
|
+
console.error("no provider parsed");
|
|
3311
|
+
return;
|
|
3312
|
+
}
|
|
3313
|
+
const elements = document.getElementsByTagName(tagName);
|
|
3314
|
+
const widget = elements[0];
|
|
3315
|
+
let attempts = 0;
|
|
3316
|
+
const maxAttempts = 10;
|
|
3317
|
+
let timer;
|
|
3318
|
+
const attemptToSetProvider = ()=>{
|
|
3319
|
+
try {
|
|
3320
|
+
widget.setProvider(provider);
|
|
3321
|
+
window.clearInterval(timer);
|
|
3322
|
+
} catch (err) {
|
|
3323
|
+
attempts++;
|
|
3324
|
+
if (attempts >= maxAttempts) {
|
|
3325
|
+
window.clearInterval(timer);
|
|
3326
|
+
console.error("failed to set the provider");
|
|
3327
|
+
}
|
|
3328
|
+
}
|
|
3329
|
+
};
|
|
3330
|
+
timer = window.setInterval(attemptToSetProvider, 10);
|
|
3331
|
+
attemptToSetProvider();
|
|
3332
|
+
}
|
|
3333
|
+
|
|
3334
|
+
|
|
3335
|
+
var $f2083cd30e2f5c56$exports = {};
|
|
3336
|
+
|
|
3337
|
+
$parcel$export($f2083cd30e2f5c56$exports, "ConnectReact", () => $f2083cd30e2f5c56$export$49d62957f420a1e2);
|
|
3338
|
+
|
|
3339
|
+
|
|
3340
|
+
|
|
3341
|
+
function $f2083cd30e2f5c56$export$49d62957f420a1e2(props) {
|
|
3342
|
+
const { providerPreference: providerPreference } = props;
|
|
3343
|
+
const config = window.ImtblCheckoutWidgetConfig;
|
|
3344
|
+
return /*#__PURE__*/ (jsx)("imtbl-connect", {
|
|
3345
|
+
providerPreference: providerPreference ?? ($14d7a2bbb79e0dae$export$2f61dde3bdc320cb).METAMASK,
|
|
3346
|
+
theme: config.theme ?? ($14d7a2bbb79e0dae$export$c88931fdc51854eb).DARK
|
|
3347
|
+
});
|
|
3348
|
+
}
|
|
3349
|
+
|
|
3350
|
+
|
|
3351
|
+
var $a4fbb8e3a6aeff58$exports = {};
|
|
3352
|
+
|
|
3353
|
+
$parcel$export($a4fbb8e3a6aeff58$exports, "SwapReact", () => $a4fbb8e3a6aeff58$export$971e031379577f4);
|
|
3354
|
+
|
|
3355
|
+
|
|
3356
|
+
|
|
3357
|
+
function $a4fbb8e3a6aeff58$export$971e031379577f4(props) {
|
|
3358
|
+
const { providerPreference: providerPreference , fromContractAddress: fromContractAddress , amount: amount , toContractAddress: toContractAddress } = props;
|
|
3359
|
+
const config = window.ImtblCheckoutWidgetConfig;
|
|
3360
|
+
return /*#__PURE__*/ (jsx)("imtbl-swap", {
|
|
3361
|
+
providerPreference: providerPreference ?? ($14d7a2bbb79e0dae$export$2f61dde3bdc320cb).METAMASK,
|
|
3362
|
+
theme: config.theme ?? ($14d7a2bbb79e0dae$export$c88931fdc51854eb).DARK,
|
|
3363
|
+
fromContractAddress: fromContractAddress ?? "",
|
|
3364
|
+
toContractAddress: toContractAddress ?? "",
|
|
3365
|
+
amount: amount ?? ""
|
|
3366
|
+
});
|
|
3367
|
+
}
|
|
3368
|
+
|
|
3369
|
+
|
|
3370
|
+
var $89d55ace0f8f1c07$exports = {};
|
|
3371
|
+
|
|
3372
|
+
$parcel$export($89d55ace0f8f1c07$exports, "WalletReact", () => $89d55ace0f8f1c07$export$ceaac94f34dba154);
|
|
3373
|
+
|
|
3374
|
+
|
|
3375
|
+
|
|
3376
|
+
function $89d55ace0f8f1c07$export$ceaac94f34dba154(props) {
|
|
3377
|
+
const { providerPreference: providerPreference } = props;
|
|
3378
|
+
const config = window.ImtblCheckoutWidgetConfig;
|
|
3379
|
+
return /*#__PURE__*/ (jsx)("imtbl-wallet", {
|
|
3380
|
+
providerPreference: providerPreference ?? ($14d7a2bbb79e0dae$export$2f61dde3bdc320cb).METAMASK,
|
|
3381
|
+
theme: config.theme ?? ($14d7a2bbb79e0dae$export$c88931fdc51854eb).DARK
|
|
3382
|
+
});
|
|
3383
|
+
}
|
|
3384
|
+
|
|
3385
|
+
|
|
3386
|
+
var $d087956fd1002f80$exports = {};
|
|
3387
|
+
|
|
3388
|
+
$parcel$export($d087956fd1002f80$exports, "ExampleReact", () => $d087956fd1002f80$export$fa517eee6594d26c);
|
|
3389
|
+
|
|
3390
|
+
|
|
3391
|
+
|
|
3392
|
+
function $d087956fd1002f80$export$fa517eee6594d26c(props) {
|
|
3393
|
+
const { providerPreference: providerPreference , fromContractAddress: fromContractAddress , amount: amount , fromNetwork: fromNetwork } = props;
|
|
3394
|
+
const config = window.ImtblCheckoutWidgetConfig;
|
|
3395
|
+
return /*#__PURE__*/ (jsx)("imtbl-example", {
|
|
3396
|
+
providerPreference: providerPreference ?? ($14d7a2bbb79e0dae$export$2f61dde3bdc320cb).METAMASK,
|
|
3397
|
+
theme: config.theme ?? ($14d7a2bbb79e0dae$export$c88931fdc51854eb).DARK
|
|
3398
|
+
});
|
|
3399
|
+
}
|
|
3400
|
+
|
|
3401
|
+
export { $15cc9e120aa6f3bf$export$d1bfa21f7c76447a as BridgeEventType, $1f969328e5988c99$export$30f61ebf204c69f6 as BridgeReact, $98cbcca465beec95$export$90db5fe1be5993c1 as BuyEventType, $f22931ca9e2f35b6$export$d13582032b79b401 as BuyReact, $a47e48dd2c04791b$export$c06e1e7429de6283 as ChainId, $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 as Checkout, $a8bc256d81a5e2c1$export$e3dc0620abde7f5a as CheckoutErrorType, $14d7a2bbb79e0dae$export$75be0f6af9650f2c as CheckoutWidgetTagNames, $fa90757d8d7a0962$export$af210a0808087845 as CheckoutWidgets, $a85ecdbd885c58ad$export$e72e7f9969a47dd3 as ConnectEventType, $f2083cd30e2f5c56$export$49d62957f420a1e2 as ConnectReact, $d176a05e966364ba$export$3bfad4d03ada24c4 as ConnectionProviders, Environment, $d087956fd1002f80$export$fa517eee6594d26c as ExampleReact, GenericIMXProvider, $207ed853f11d19d5$export$5a0ace85cae72d45 as IMTBLWidgetEvents, ImmutableConfiguration, ImmutableXClient, MetaMaskIMXProvider, $14d7a2bbb79e0dae$export$95be4ae94445245a as Network, $a47e48dd2c04791b$export$1f05a55fe0680cc7 as NetworkFilterTypes, Passport, PassportError, ProviderConfiguration, $fa90757d8d7a0962$export$931068bc678f0d73 as SetProvider, $090d3502d165f17d$export$c5ab8fbcabac8c11 as SupportedFiatCurrencies, $53d219e7f6bf0cd6$export$140a49745ab55563 as SwapEventType, $a4fbb8e3a6aeff58$export$971e031379577f4 as SwapReact, $08d5ddc39acd6833$export$fd9b17d87f4121d2 as TokenFilterTypes, $fa90757d8d7a0962$export$bf1548ba7e61c17f as UpdateConfig, $77b6aac5c353d4a9$export$d9be06b70b28c742 as WalletEventType, $4f91c5f280efe242$export$a75605c67ea83a5a as WalletFilterTypes, $89d55ace0f8f1c07$export$ceaac94f34dba154 as WalletReact, $14d7a2bbb79e0dae$export$2f61dde3bdc320cb as WidgetConnectionProviders, $14d7a2bbb79e0dae$export$c88931fdc51854eb as WidgetTheme };
|