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