@imtbl/sdk 0.0.1-alpha.2 → 0.1.0-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/README.md +28 -0
- package/dist/checkout_sdk.d.ts +293 -2
- package/dist/checkout_sdk.js +283 -142
- package/dist/checkout_widgets.d.ts +22 -6
- package/dist/checkout_widgets.js +32 -12
- package/dist/config.d.ts +18 -0
- package/dist/config.js +15 -0
- package/dist/{starkex.d.ts → immutablex_client.d.ts} +2571 -720
- package/dist/immutablex_client.js +510 -0
- package/dist/index.cjs +2547 -1872
- package/dist/index.d.ts +2490 -620
- package/dist/index.js +2531 -1862
- package/dist/passport.d.ts +45 -16
- package/dist/passport.js +128 -99
- package/dist/provider.d.ts +36 -20
- package/dist/provider.js +102 -91
- package/package.json +23 -15
- package/dist/base.d.ts +0 -123
- package/dist/base.js +0 -27
- package/dist/browser/checkout.js +0 -2
- package/dist/starkex.js +0 -10
package/dist/index.cjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var coreSdk = require('@imtbl/core-sdk');
|
|
4
|
+
var oidcClientTs = require('oidc-client-ts');
|
|
5
|
+
var ethers = require('ethers');
|
|
6
|
+
var magicSdk = require('magic-sdk');
|
|
7
|
+
var oidc = require('@magic-ext/oidc');
|
|
4
8
|
var BN = require('bn.js');
|
|
5
9
|
var encUtils = require('enc-utils');
|
|
6
10
|
var units = require('@ethersproject/units');
|
|
7
11
|
var bignumber = require('@ethersproject/bignumber');
|
|
8
|
-
var ethers = require('ethers');
|
|
9
12
|
var detectEthereumProvider = require('@metamask/detect-provider');
|
|
10
|
-
var oidcClientTs = require('oidc-client-ts');
|
|
11
|
-
var magicSdk = require('magic-sdk');
|
|
12
|
-
var oidc = require('@magic-ext/oidc');
|
|
13
13
|
var providers = require('@ethersproject/providers');
|
|
14
14
|
|
|
15
15
|
function _interopNamespaceDefault(e) {
|
|
@@ -33,34 +33,517 @@ var encUtils__namespace = /*#__PURE__*/_interopNamespaceDefault(encUtils);
|
|
|
33
33
|
|
|
34
34
|
exports.Environment = void 0;
|
|
35
35
|
(function (Environment) {
|
|
36
|
-
Environment["DEVELOPMENT"] = "development";
|
|
37
|
-
Environment["SANDBOX"] = "sandbox";
|
|
38
36
|
Environment["PRODUCTION"] = "production";
|
|
37
|
+
Environment["SANDBOX"] = "sandbox";
|
|
39
38
|
})(exports.Environment || (exports.Environment = {}));
|
|
40
|
-
class
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
39
|
+
class ImmutableConfiguration {
|
|
40
|
+
environment;
|
|
41
|
+
apiKey;
|
|
42
|
+
constructor(options) {
|
|
43
|
+
this.environment = options.environment;
|
|
44
|
+
this.apiKey = options.apiKey;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Set `sdkVersion` on config
|
|
49
|
+
const PRODUCTION = () => {
|
|
50
|
+
return coreSdk.Config.createConfig({
|
|
51
|
+
basePath: 'https://api.x.immutable.com',
|
|
52
|
+
chainID: 1,
|
|
53
|
+
coreContractAddress: '0x5FDCCA53617f4d2b9134B29090C87D01058e27e9',
|
|
54
|
+
registrationContractAddress: '0x72a06bf2a1CE5e39cBA06c0CAb824960B587d64c',
|
|
55
|
+
sdkVersion: 'ts-immutable-sdk-__SDK_VERSION__',
|
|
56
|
+
});
|
|
52
57
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
// Set `sdkVersion` on config
|
|
59
|
+
const SANDBOX = () => {
|
|
60
|
+
return coreSdk.Config.createConfig({
|
|
61
|
+
basePath: 'https://api.sandbox.x.immutable.com',
|
|
62
|
+
chainID: 5,
|
|
63
|
+
coreContractAddress: '0x7917eDb51ecD6CdB3F9854c3cc593F33de10c623',
|
|
64
|
+
registrationContractAddress: '0x1C97Ada273C9A52253f463042f29117090Cd7D83',
|
|
65
|
+
sdkVersion: 'ts-immutable-sdk-__SDK_VERSION__',
|
|
66
|
+
});
|
|
56
67
|
};
|
|
68
|
+
class ImxConfiguration {
|
|
69
|
+
immutableXConfig;
|
|
70
|
+
baseConfig;
|
|
71
|
+
constructor({ baseConfig, overrides }) {
|
|
72
|
+
this.baseConfig = baseConfig;
|
|
73
|
+
if (overrides) {
|
|
74
|
+
this.immutableXConfig = overrides.immutableXConfig;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
switch (baseConfig.environment) {
|
|
78
|
+
case exports.Environment.SANDBOX: {
|
|
79
|
+
this.immutableXConfig = SANDBOX();
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
case exports.Environment.PRODUCTION: {
|
|
83
|
+
this.immutableXConfig = PRODUCTION();
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
57
90
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
91
|
+
class ImmutableXClient {
|
|
92
|
+
immutableX;
|
|
93
|
+
depositsApi;
|
|
94
|
+
mintsApi;
|
|
95
|
+
ordersApi;
|
|
96
|
+
tokensApi;
|
|
97
|
+
tradesApi;
|
|
98
|
+
transfersApi;
|
|
99
|
+
exchangeApi;
|
|
100
|
+
nftCheckoutPrimaryApi;
|
|
101
|
+
usersApi;
|
|
102
|
+
withdrawalsApi;
|
|
103
|
+
balanceApi;
|
|
104
|
+
assetApi;
|
|
105
|
+
collectionApi;
|
|
106
|
+
metadataApi;
|
|
107
|
+
metadataRefreshesApi;
|
|
108
|
+
projectsApi;
|
|
109
|
+
constructor(config) {
|
|
110
|
+
const imxConfig = new ImxConfiguration(config);
|
|
111
|
+
this.immutableX = new coreSdk.ImmutableX(imxConfig.immutableXConfig);
|
|
112
|
+
this.depositsApi = this.immutableX.depositsApi;
|
|
113
|
+
this.mintsApi = this.immutableX.mintsApi;
|
|
114
|
+
this.ordersApi = this.immutableX.ordersApi;
|
|
115
|
+
this.tokensApi = this.immutableX.tokensApi;
|
|
116
|
+
this.tradesApi = this.immutableX.tradesApi;
|
|
117
|
+
this.transfersApi = this.immutableX.transfersApi;
|
|
118
|
+
this.exchangeApi = this.immutableX.exchangeApi;
|
|
119
|
+
this.usersApi = this.immutableX.usersApi;
|
|
120
|
+
this.withdrawalsApi = this.immutableX.withdrawalsApi;
|
|
121
|
+
this.balanceApi = this.immutableX.balanceApi;
|
|
122
|
+
this.assetApi = this.immutableX.assetApi;
|
|
123
|
+
this.collectionApi = this.immutableX.collectionApi;
|
|
124
|
+
this.metadataApi = this.immutableX.metadataApi;
|
|
125
|
+
this.metadataRefreshesApi = this.immutableX.metadataRefreshesApi;
|
|
126
|
+
this.nftCheckoutPrimaryApi = this.immutableX.nftCheckoutPrimaryApi;
|
|
127
|
+
this.projectsApi = this.immutableX.projectsApi;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get details of a Deposit with the given ID
|
|
131
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
132
|
+
* @returns a promise that resolves with the requested Deposit
|
|
133
|
+
* @throws {@link index.IMXError}
|
|
134
|
+
*/
|
|
135
|
+
getDeposit(request) {
|
|
136
|
+
return this.immutableX.getDeposit(request);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Get a list of Deposits
|
|
140
|
+
* @param request - optional request object containing the parameters to be provided in the API request
|
|
141
|
+
* @returns a promise that resolves with the requested list of Deposits
|
|
142
|
+
* @throws {@link index.IMXError}
|
|
143
|
+
*/
|
|
144
|
+
listDeposits(request) {
|
|
145
|
+
return this.immutableX.listDeposits(request);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get Stark keys for a registered User
|
|
149
|
+
* @param ethAddress - the eth address of the User
|
|
150
|
+
* @returns a promise that resolves with the requested User
|
|
151
|
+
* @throws {@link index.IMXError}
|
|
152
|
+
*/
|
|
153
|
+
getUser(ethAddress) {
|
|
154
|
+
return this.immutableX.getUser(ethAddress);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Get details of an Asset
|
|
158
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
159
|
+
* @returns a promise that resolves with the requested Asset
|
|
160
|
+
* @throws {@link index.IMXError}
|
|
161
|
+
*/
|
|
162
|
+
getAsset(request) {
|
|
163
|
+
return this.immutableX.getAsset(request);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Get a list of Assets
|
|
167
|
+
* @param request - optional request object containing the parameters to be provided in the API request
|
|
168
|
+
* @returns a promise that resolves with the requested list of Assets
|
|
169
|
+
* @throws {@link index.IMXError}
|
|
170
|
+
*/
|
|
171
|
+
listAssets(request) {
|
|
172
|
+
return this.immutableX.listAssets(request);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Create a Collection
|
|
176
|
+
* @param ethSigner - the L1 signer
|
|
177
|
+
* @param request - the request object to be provided in the API request
|
|
178
|
+
* @returns a promise that resolves with the created Collection
|
|
179
|
+
* @throws {@link index.IMXError}
|
|
180
|
+
*/
|
|
181
|
+
createCollection(ethSigner, request) {
|
|
182
|
+
return this.immutableX.createCollection(ethSigner, request);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Get details of a Collection at the given address
|
|
186
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
187
|
+
* @returns a promise that resolves with the requested Collection
|
|
188
|
+
* @throws {@link index.IMXError}
|
|
189
|
+
*/
|
|
190
|
+
getCollection(request) {
|
|
191
|
+
return this.immutableX.getCollection(request);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Get a list of Collection filters
|
|
195
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
196
|
+
* @returns a promise that resolves with the requested list of Collection Filters
|
|
197
|
+
* @throws {@link index.IMXError}
|
|
198
|
+
*/
|
|
199
|
+
listCollectionFilters(request) {
|
|
200
|
+
return this.immutableX.listCollectionFilters(request);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Get a list of Collections
|
|
204
|
+
* @param request - optional request object containing the parameters to be provided in the API request
|
|
205
|
+
* @returns a promise that resolves with the requested list of Collections
|
|
206
|
+
* @throws {@link index.IMXError}
|
|
207
|
+
*/
|
|
208
|
+
listCollections(request) {
|
|
209
|
+
return this.collectionApi.listCollections(request).then((res) => res.data);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Update a Collection
|
|
213
|
+
* @param ethSigner - the L1 signer
|
|
214
|
+
* @param collectionAddress - the Collection contract address
|
|
215
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
216
|
+
* @returns a promise that resolves with the updated Collection
|
|
217
|
+
* @throws {@link index.IMXError}
|
|
218
|
+
*/
|
|
219
|
+
updateCollection(ethSigner, collectionAddress, request) {
|
|
220
|
+
return this.immutableX.updateCollection(ethSigner, collectionAddress, request);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Add metadata schema to Collection
|
|
224
|
+
* @param ethSigner - the L1 signer
|
|
225
|
+
* @param collectionAddress - the Collection contract address
|
|
226
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
227
|
+
* @returns a promise that resolves with the SuccessResponse if successful
|
|
228
|
+
* @throws {@link index.IMXError}
|
|
229
|
+
*/
|
|
230
|
+
addMetadataSchemaToCollection(ethSigner, collectionAddress, request) {
|
|
231
|
+
return this.immutableX.addMetadataSchemaToCollection(ethSigner, collectionAddress, request);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Get Metadata schema
|
|
235
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
236
|
+
* @returns a promise that resolves with the requested Metadata schema
|
|
237
|
+
* @throws {@link index.IMXError}
|
|
238
|
+
*/
|
|
239
|
+
getMetadataSchema(request) {
|
|
240
|
+
return this.immutableX.getMetadataSchema(request);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Update metadata schema by name
|
|
244
|
+
* @param ethSigner - the L1 signer
|
|
245
|
+
* @param collectionAddress - the Collection contract address
|
|
246
|
+
* @param name - the Metadata schema name
|
|
247
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
248
|
+
* @returns a promise that resolves with the SuccessResponse if successful
|
|
249
|
+
* @throws {@link index.IMXError}
|
|
250
|
+
*/
|
|
251
|
+
updateMetadataSchemaByName(ethSigner, collectionAddress, name, request) {
|
|
252
|
+
return this.immutableX.updateMetadataSchemaByName(ethSigner, collectionAddress, name, request);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Get a list of metadata refreshes
|
|
256
|
+
* @param ethSigner - the L1 signer
|
|
257
|
+
* @param collectionAddress - the Collection contract address
|
|
258
|
+
* @param pageSize - the page size of the result
|
|
259
|
+
* @param cursor - the cursor
|
|
260
|
+
* @returns a promise that resolves with the requested metadata refreshes
|
|
261
|
+
* @throws {@link index.IMXError}
|
|
262
|
+
*/
|
|
263
|
+
listMetadataRefreshes(ethSigner, collectionAddress, pageSize, cursor) {
|
|
264
|
+
return this.immutableX.listMetadataRefreshes(ethSigner, collectionAddress, pageSize, cursor);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Get a list of metadata refresh errors
|
|
268
|
+
* @param ethSigner - the L1 signer
|
|
269
|
+
* @param refreshId - the metadata refresh ID
|
|
270
|
+
* @param pageSize - the page size of the result
|
|
271
|
+
* @param cursor - the cursor
|
|
272
|
+
* @returns a promise that resolves with the requested metadata refresh errors
|
|
273
|
+
* @throws {@link index.IMXError}
|
|
274
|
+
*/
|
|
275
|
+
getMetadataRefreshErrors(ethSigner, refreshId, pageSize, cursor) {
|
|
276
|
+
return this.immutableX.getMetadataRefreshErrors(ethSigner, refreshId, pageSize, cursor);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Get a list of metadata refresh results
|
|
280
|
+
* @param ethSigner - the L1 signer
|
|
281
|
+
* @param refreshId - the metadata refresh ID
|
|
282
|
+
* @returns a promise that resolves with the requested metadata refresh results
|
|
283
|
+
* @throws {@link index.IMXError}
|
|
284
|
+
*/
|
|
285
|
+
getMetadataRefreshResults(ethSigner, refreshId) {
|
|
286
|
+
return this.immutableX.getMetadataRefreshResults(ethSigner, refreshId);
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Request a metadata refresh
|
|
290
|
+
* @param ethSigner - the L1 signer
|
|
291
|
+
* @param request the request object containing the parameters to be provided in the API request
|
|
292
|
+
* @returns a promise that resolves with the requested metadata refresh
|
|
293
|
+
* @throws {@link index.IMXError}
|
|
294
|
+
*/
|
|
295
|
+
createMetadataRefresh(ethSigner, request) {
|
|
296
|
+
return this.immutableX.createMetadataRefresh(ethSigner, request);
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Create a Project
|
|
300
|
+
* @param ethSigner - the L1 signer
|
|
301
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
302
|
+
* @returns a promise that resolves with the created Project
|
|
303
|
+
* @throws {@link index.IMXError}
|
|
304
|
+
*/
|
|
305
|
+
async createProject(ethSigner, request) {
|
|
306
|
+
return this.immutableX.createProject(ethSigner, request);
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Get a Project
|
|
310
|
+
* @param ethSigner - the L1 signer
|
|
311
|
+
* @param id - the Project ID
|
|
312
|
+
* @returns a promise that resolves with the requested Project
|
|
313
|
+
* @throws {@link index.IMXError}
|
|
314
|
+
*/
|
|
315
|
+
async getProject(ethSigner, id) {
|
|
316
|
+
return this.immutableX.getProject(ethSigner, id);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Get Projects owned by the given User
|
|
320
|
+
* @param ethSigner - the L1 signer
|
|
321
|
+
* @param pageSize - the page size of the result
|
|
322
|
+
* @param cursor - the cursor
|
|
323
|
+
* @param orderBy - the property to sort by
|
|
324
|
+
* @param direction - direction to sort (asc/desc)
|
|
325
|
+
* @returns a promise that resolves with the requested Projects
|
|
326
|
+
* @throws {@link index.IMXError}
|
|
327
|
+
*/
|
|
328
|
+
async getProjects(ethSigner, pageSize, cursor, orderBy, direction) {
|
|
329
|
+
return this.immutableX.getProjects(ethSigner, pageSize, cursor, orderBy, direction);
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Get the token Balances of the User
|
|
333
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
334
|
+
* @returns a promise that resolves with the requested Balance
|
|
335
|
+
* @throws {@link index.IMXError}
|
|
336
|
+
*/
|
|
337
|
+
getBalance(request) {
|
|
338
|
+
return this.immutableX.getBalance(request);
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Get a list of Balances for given User
|
|
342
|
+
* @param request the request object containing the parameters to be provided in the API request
|
|
343
|
+
* @returns a promise that resolves with the requested list of Balances
|
|
344
|
+
* @throws {@link index.IMXError}
|
|
345
|
+
*/
|
|
346
|
+
listBalances(request) {
|
|
347
|
+
return this.immutableX.listBalances(request);
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Get details of a Mint with the given ID
|
|
351
|
+
* @param request the request object containing the parameters to be provided in the API request
|
|
352
|
+
* @returns a promise that resolves with the requested Mint
|
|
353
|
+
* @throws {@link index.IMXError}
|
|
354
|
+
*/
|
|
355
|
+
getMint(request) {
|
|
356
|
+
return this.immutableX.getMint(request);
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Get a list of Mints
|
|
360
|
+
* @param request optional request object containing the parameters to be provided in the API request
|
|
361
|
+
* @returns a promise that resolves with the requested list of Mints
|
|
362
|
+
* @throws {@link index.IMXError}
|
|
363
|
+
*/
|
|
364
|
+
listMints(request) {
|
|
365
|
+
return this.immutableX.listMints(request);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Mint tokens in a batch with fees
|
|
369
|
+
* @param ethSigner - the L1 signer
|
|
370
|
+
* @param request - the request object to be provided in the API request
|
|
371
|
+
* @returns a promise that resolves with the minted tokens
|
|
372
|
+
* @throws {@link index.IMXError}
|
|
373
|
+
*/
|
|
374
|
+
mint(ethSigner, request) {
|
|
375
|
+
return this.immutableX.mint(ethSigner, request);
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Get a list of Withdrawals
|
|
379
|
+
* @param request - optional request object containing the parameters to be provided in the API request
|
|
380
|
+
* @returns a promise that resolves with the requested list of Withdrawals
|
|
381
|
+
* @throws {@link index.IMXError}
|
|
382
|
+
*/
|
|
383
|
+
listWithdrawals(request) {
|
|
384
|
+
return this.immutableX.listWithdrawals(request);
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Get details of Withdrawal with the given ID
|
|
388
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
389
|
+
* @returns a promise that resolves with the requested Withdrawal
|
|
390
|
+
* @throws {@link index.IMXError}
|
|
391
|
+
*/
|
|
392
|
+
getWithdrawal(request) {
|
|
393
|
+
return this.immutableX.getWithdrawal(request);
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Get details of an Order with the given ID
|
|
397
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
398
|
+
* @returns a promise that resolves with the requested Order
|
|
399
|
+
* @throws {@link index.IMXError}
|
|
400
|
+
*/
|
|
401
|
+
getOrder(request) {
|
|
402
|
+
return this.immutableX.getOrder(request);
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Get a list of Orders
|
|
406
|
+
* @param request - optional request object containing the parameters to be provided in the API request
|
|
407
|
+
* @returns a promise that resolves with the requested list of Orders
|
|
408
|
+
* @throws {@link index.IMXError}
|
|
409
|
+
*/
|
|
410
|
+
listOrders(request) {
|
|
411
|
+
return this.immutableX.listOrders(request);
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Get details of a Trade with the given ID
|
|
415
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
416
|
+
* @returns a promise that resolves with the requested Trade
|
|
417
|
+
* @throws {@link index.IMXError}
|
|
418
|
+
*/
|
|
419
|
+
getTrade(request) {
|
|
420
|
+
return this.immutableX.getTrade(request);
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Get a list of Trades
|
|
424
|
+
* @param request - optional request object containing the parameters to be provided in the API request
|
|
425
|
+
* @returns a promise that resolves with the requested list of Trades
|
|
426
|
+
* @throws {@link index.IMXError}
|
|
427
|
+
*/
|
|
428
|
+
listTrades(request) {
|
|
429
|
+
return this.immutableX.listTrades(request);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Get details of a Token
|
|
433
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
434
|
+
* @returns a promise that resolves with the requested Token
|
|
435
|
+
* @throws {@link index.IMXError}
|
|
436
|
+
*/
|
|
437
|
+
getToken(request) {
|
|
438
|
+
return this.immutableX.getToken(request);
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Get a list of Tokens
|
|
442
|
+
* @param request - optional request object containing the parameters to be provided in the API request
|
|
443
|
+
* @returns a promise that resolves with the requested list of Tokens
|
|
444
|
+
* @throws {@link index.IMXError}
|
|
445
|
+
*/
|
|
446
|
+
listTokens(request) {
|
|
447
|
+
return this.immutableX.listTokens(request);
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Get details of a Transfer with the given ID
|
|
451
|
+
* @param request - the request object containing the parameters to be provided in the API request
|
|
452
|
+
* @returns a promise that resolves with the requested Transfer
|
|
453
|
+
* @throws {@link index.IMXError}
|
|
454
|
+
*/
|
|
455
|
+
getTransfer(request) {
|
|
456
|
+
return this.immutableX.getTransfer(request);
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Get a list of Transfers
|
|
460
|
+
* @param request - optional request object containing the parameters to be provided in the API request
|
|
461
|
+
* @returns a promise that resolves with the requested list of Transfers
|
|
462
|
+
* @throws {@link index.IMXError}
|
|
463
|
+
*/
|
|
464
|
+
listTransfers(request) {
|
|
465
|
+
return this.immutableX.listTransfers(request);
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Create a new Exchange transaction
|
|
469
|
+
* @param request - the request object to be provided in the API request
|
|
470
|
+
* @returns a promise that resolves with the created Exchange Transaction
|
|
471
|
+
* @throws {@link index.IMXError}
|
|
472
|
+
*/
|
|
473
|
+
createExchange(request) {
|
|
474
|
+
return this.immutableX.createExchange(request).then((res) => res.data);
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Get an Exchange transaction
|
|
478
|
+
* @param request - the request object to be provided in the API request
|
|
479
|
+
* @returns a promise that resolves with the Exchange Transaction
|
|
480
|
+
* @throws {@link index.IMXError}
|
|
481
|
+
*/
|
|
482
|
+
getExchange(request) {
|
|
483
|
+
return this.immutableX.getExchange(request).then((res) => res.data);
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Get Exchange transactions
|
|
487
|
+
* @param request - the request object to be provided in the API request
|
|
488
|
+
* @returns a promise that resolves with Exchange Transactions
|
|
489
|
+
* @throws {@link index.IMXError}
|
|
490
|
+
*/
|
|
491
|
+
getExchanges(request) {
|
|
492
|
+
return this.immutableX.getExchanges(request).then((res) => res.data);
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Create a new Transfer request
|
|
496
|
+
* @param walletConnection - the pair of Eth/Stark signers
|
|
497
|
+
* @param request - the request object to be provided in the API request
|
|
498
|
+
* @returns a promise that resolves with the created Exchange Transfer
|
|
499
|
+
* @throws {@link index.IMXError}
|
|
500
|
+
*/
|
|
501
|
+
exchangeTransfer(walletConnection, request) {
|
|
502
|
+
return this.immutableX.exchangeTransfer(walletConnection, request);
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Create a new nft primary transaction
|
|
506
|
+
* @param request - the request object to be provided in the API request
|
|
507
|
+
* @returns a promise that resolves with the created nft primary Transaction
|
|
508
|
+
* @throws {@link index.IMXError}
|
|
509
|
+
*/
|
|
510
|
+
createNftPrimary(request) {
|
|
511
|
+
return this.immutableX.createNftPrimary(request).then((res) => res.data);
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Get nft primary supported currencies and their limits
|
|
515
|
+
* @param request - the request object to be provided in the API request
|
|
516
|
+
* @returns a promise that resolves with nft primary Currencies
|
|
517
|
+
* @throws {@link index.IMXError}
|
|
518
|
+
*/
|
|
519
|
+
getCurrenciesNFTCheckoutPrimary(request) {
|
|
520
|
+
return this.immutableX
|
|
521
|
+
.getCurrenciesNFTCheckoutPrimary(request)
|
|
522
|
+
.then((res) => res.data);
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Get nft primary transaction by transaction id
|
|
526
|
+
* @param request - the request object to be provided in the API request
|
|
527
|
+
* @returns a promise that resolves with nft primary transaction
|
|
528
|
+
* @throws {@link index.IMXError}
|
|
529
|
+
*/
|
|
530
|
+
getNftPrimaryTransaction(request) {
|
|
531
|
+
return this.immutableX
|
|
532
|
+
.getNftPrimaryTransaction(request)
|
|
533
|
+
.then((res) => res.data);
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Get list of nft primary transactions
|
|
537
|
+
* @param request - the request object to be provided in the API request
|
|
538
|
+
* @returns a promise that resolves with nft primary transaction
|
|
539
|
+
* @throws {@link index.IMXError}
|
|
540
|
+
*/
|
|
541
|
+
getNftPrimaryTransactions(request) {
|
|
542
|
+
return this.immutableX
|
|
543
|
+
.getNftPrimaryTransactions(request)
|
|
544
|
+
.then((res) => res.data);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
64
547
|
|
|
65
548
|
// used to sign message with L1 keys. Used for registration
|
|
66
549
|
function serializeEthSignature(sig) {
|
|
@@ -132,1876 +615,1923 @@ function convertToSignableToken(token) {
|
|
|
132
615
|
}
|
|
133
616
|
}
|
|
134
617
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
618
|
+
var PassportErrorType;
|
|
619
|
+
(function (PassportErrorType) {
|
|
620
|
+
PassportErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
|
|
621
|
+
PassportErrorType["INVALID_CONFIGURATION"] = "INVALID_CONFIGURATION";
|
|
622
|
+
PassportErrorType["WALLET_CONNECTION_ERROR"] = "WALLET_CONNECTION_ERROR";
|
|
623
|
+
PassportErrorType["NOT_LOGGED_IN_ERROR"] = "NOT_LOGGED_IN_ERROR";
|
|
624
|
+
PassportErrorType["SILENT_LOGIN_ERROR"] = "SILENT_LOGIN_ERROR";
|
|
625
|
+
PassportErrorType["REFRESH_TOKEN_ERROR"] = "REFRESH_TOKEN_ERROR";
|
|
626
|
+
PassportErrorType["USER_REGISTRATION_ERROR"] = "USER_REGISTRATION_ERROR";
|
|
627
|
+
PassportErrorType["LOGOUT_ERROR"] = "LOGOUT_ERROR";
|
|
628
|
+
PassportErrorType["TRANSFER_ERROR"] = "TRANSFER_ERROR";
|
|
629
|
+
PassportErrorType["CREATE_ORDER_ERROR"] = "CREATE_ORDER_ERROR";
|
|
630
|
+
PassportErrorType["CANCEL_ORDER_ERROR"] = "CANCEL_ORDER_ERROR";
|
|
631
|
+
PassportErrorType["EXCHANGE_TRANSFER_ERROR"] = "EXCHANGE_TRANSFER_ERROR";
|
|
632
|
+
PassportErrorType["CREATE_TRADE_ERROR"] = "CREATE_TRADE_ERROR";
|
|
633
|
+
PassportErrorType["OPERATION_NOT_SUPPORTED_ERROR"] = "OPERATION_NOT_SUPPORTED_ERROR";
|
|
634
|
+
})(PassportErrorType || (PassportErrorType = {}));
|
|
635
|
+
class PassportError extends Error {
|
|
636
|
+
type;
|
|
637
|
+
constructor(message, type) {
|
|
638
|
+
super(message);
|
|
639
|
+
this.type = type;
|
|
640
|
+
}
|
|
142
641
|
}
|
|
642
|
+
const withPassportError = async (fn, customErrorType) => {
|
|
643
|
+
try {
|
|
644
|
+
return await fn();
|
|
645
|
+
}
|
|
646
|
+
catch (error) {
|
|
647
|
+
const errorMessage = `${customErrorType}: ${error.message}` || 'UnknownError';
|
|
648
|
+
throw new PassportError(errorMessage, customErrorType);
|
|
649
|
+
}
|
|
650
|
+
};
|
|
143
651
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
652
|
+
const POLL_INTERVAL = 1 * 1000; // every 1 second
|
|
653
|
+
const MAX_RETRIES = 3;
|
|
654
|
+
const wait = (ms) => new Promise((resolve) => {
|
|
655
|
+
setTimeout(() => resolve(), ms);
|
|
656
|
+
});
|
|
657
|
+
const retryWithDelay = async (fn, options) => {
|
|
658
|
+
const { retries = MAX_RETRIES, interval = POLL_INTERVAL, finalErr = Error('Retry failed'), } = options || {};
|
|
659
|
+
try {
|
|
660
|
+
return await fn();
|
|
661
|
+
}
|
|
662
|
+
catch (err) {
|
|
663
|
+
if (retries <= 0) {
|
|
664
|
+
return Promise.reject(finalErr);
|
|
665
|
+
}
|
|
666
|
+
await wait(interval);
|
|
667
|
+
return retryWithDelay(fn, { retries: retries - 1, finalErr });
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
const getAuthConfiguration = ({ oidcConfiguration, authenticationDomain, }) => {
|
|
672
|
+
const baseConfiguration = {
|
|
673
|
+
authority: authenticationDomain,
|
|
674
|
+
redirect_uri: oidcConfiguration.redirectUri,
|
|
675
|
+
popup_redirect_uri: oidcConfiguration.redirectUri,
|
|
676
|
+
client_id: oidcConfiguration.clientId,
|
|
677
|
+
metadata: {
|
|
678
|
+
authorization_endpoint: `${authenticationDomain}/authorize`,
|
|
679
|
+
token_endpoint: `${authenticationDomain}/oauth/token`,
|
|
680
|
+
userinfo_endpoint: `${authenticationDomain}/userinfo`,
|
|
681
|
+
end_session_endpoint: `${authenticationDomain}/v2/logout` +
|
|
682
|
+
`?returnTo=${encodeURIComponent(oidcConfiguration.logoutRedirectUri)}` +
|
|
683
|
+
`&client_id=${oidcConfiguration.clientId}`,
|
|
155
684
|
},
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const starkSignature = await starkExSigner.signMessage(payloadHash);
|
|
160
|
-
const transferSigningParams = {
|
|
161
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
162
|
-
sender_stark_key: signableResult.data.sender_stark_key,
|
|
163
|
-
sender_vault_id: signableResult.data.sender_vault_id,
|
|
164
|
-
receiver_stark_key: signableResult.data.receiver_stark_key,
|
|
165
|
-
receiver_vault_id: signableResult.data.receiver_vault_id,
|
|
166
|
-
asset_id: signableResult.data.asset_id,
|
|
167
|
-
amount: signableResult.data.amount,
|
|
168
|
-
nonce: signableResult.data.nonce,
|
|
169
|
-
expiration_timestamp: signableResult.data.expiration_timestamp,
|
|
170
|
-
stark_signature: starkSignature,
|
|
171
|
-
};
|
|
172
|
-
const response = await transfersApi.createTransferV1({
|
|
173
|
-
createTransferRequest: transferSigningParams,
|
|
174
|
-
xImxEthAddress: ethAddress,
|
|
175
|
-
xImxEthSignature: ethSignature,
|
|
176
|
-
});
|
|
177
|
-
return {
|
|
178
|
-
sent_signature: response?.data.sent_signature,
|
|
179
|
-
status: response?.data.status?.toString(),
|
|
180
|
-
time: response?.data.time,
|
|
181
|
-
transfer_id: response?.data.transfer_id,
|
|
685
|
+
mergeClaims: true,
|
|
686
|
+
loadUserInfo: true,
|
|
687
|
+
scope: oidcConfiguration.scope,
|
|
182
688
|
};
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const ethAddress = await ethSigner.getAddress();
|
|
187
|
-
const transfersApi = new coreSdk.TransfersApi(config.getStarkExConfig().apiConfiguration);
|
|
188
|
-
const signableRequests = request.map((nftTransfer) => {
|
|
189
|
-
return {
|
|
190
|
-
amount: '1',
|
|
191
|
-
token: convertToSignableToken({
|
|
192
|
-
type: 'ERC721',
|
|
193
|
-
tokenId: nftTransfer.tokenId,
|
|
194
|
-
tokenAddress: nftTransfer.tokenAddress,
|
|
195
|
-
}),
|
|
196
|
-
receiver: nftTransfer.receiver,
|
|
689
|
+
if (oidcConfiguration.audience) {
|
|
690
|
+
baseConfiguration.extraQueryParams = {
|
|
691
|
+
audience: oidcConfiguration.audience,
|
|
197
692
|
};
|
|
198
|
-
});
|
|
199
|
-
const signableResult = await transfersApi.getSignableTransfer({
|
|
200
|
-
getSignableTransferRequestV2: {
|
|
201
|
-
sender_ether_key: ethAddress,
|
|
202
|
-
signable_requests: signableRequests,
|
|
203
|
-
},
|
|
204
|
-
});
|
|
205
|
-
const signableMessage = signableResult.data.signable_message;
|
|
206
|
-
if (signableMessage === undefined) {
|
|
207
|
-
throw new Error('Invalid response from Signable registration offchain');
|
|
208
693
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
asset_id: resp.asset_id,
|
|
218
|
-
amount: resp.amount,
|
|
219
|
-
nonce: resp.nonce,
|
|
220
|
-
expiration_timestamp: resp.expiration_timestamp,
|
|
221
|
-
stark_signature: starkSignature,
|
|
222
|
-
};
|
|
223
|
-
requests.push(req);
|
|
694
|
+
return baseConfiguration;
|
|
695
|
+
};
|
|
696
|
+
class AuthManager {
|
|
697
|
+
userManager;
|
|
698
|
+
config;
|
|
699
|
+
constructor(config) {
|
|
700
|
+
this.config = config;
|
|
701
|
+
this.userManager = new oidcClientTs.UserManager(getAuthConfiguration(config));
|
|
224
702
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
703
|
+
mapOidcUserToDomainModel = (oidcUser) => {
|
|
704
|
+
const passport = oidcUser.profile?.passport;
|
|
705
|
+
return {
|
|
706
|
+
expired: oidcUser.expired,
|
|
707
|
+
idToken: oidcUser.id_token,
|
|
708
|
+
accessToken: oidcUser.access_token,
|
|
709
|
+
refreshToken: oidcUser.refresh_token,
|
|
710
|
+
profile: {
|
|
711
|
+
sub: oidcUser.profile.sub,
|
|
712
|
+
email: oidcUser.profile.email,
|
|
713
|
+
nickname: oidcUser.profile.nickname,
|
|
714
|
+
},
|
|
715
|
+
etherKey: passport?.ether_key || '',
|
|
716
|
+
};
|
|
237
717
|
};
|
|
718
|
+
async login() {
|
|
719
|
+
return withPassportError(async () => {
|
|
720
|
+
const popupWindowFeatures = { width: 410, height: 450 };
|
|
721
|
+
const oidcUser = await this.userManager.signinPopup({
|
|
722
|
+
popupWindowFeatures,
|
|
723
|
+
});
|
|
724
|
+
return this.mapOidcUserToDomainModel(oidcUser);
|
|
725
|
+
}, PassportErrorType.AUTHENTICATION_ERROR);
|
|
726
|
+
}
|
|
727
|
+
async loginCallback() {
|
|
728
|
+
return withPassportError(async () => this.userManager.signinPopupCallback(), PassportErrorType.AUTHENTICATION_ERROR);
|
|
729
|
+
}
|
|
730
|
+
async logout() {
|
|
731
|
+
return withPassportError(async () => this.userManager.signoutRedirect(), PassportErrorType.LOGOUT_ERROR);
|
|
732
|
+
}
|
|
733
|
+
async loginSilent() {
|
|
734
|
+
return withPassportError(async () => {
|
|
735
|
+
const existedUser = await this.getUser();
|
|
736
|
+
if (!existedUser) {
|
|
737
|
+
return null;
|
|
738
|
+
}
|
|
739
|
+
const oidcUser = await this.userManager.signinSilent();
|
|
740
|
+
if (!oidcUser) {
|
|
741
|
+
return null;
|
|
742
|
+
}
|
|
743
|
+
return this.mapOidcUserToDomainModel(oidcUser);
|
|
744
|
+
}, PassportErrorType.SILENT_LOGIN_ERROR);
|
|
745
|
+
}
|
|
746
|
+
async getUser() {
|
|
747
|
+
return withPassportError(async () => {
|
|
748
|
+
const oidcUser = await this.userManager.getUser();
|
|
749
|
+
if (!oidcUser) {
|
|
750
|
+
return null;
|
|
751
|
+
}
|
|
752
|
+
return this.mapOidcUserToDomainModel(oidcUser);
|
|
753
|
+
}, PassportErrorType.NOT_LOGGED_IN_ERROR);
|
|
754
|
+
}
|
|
755
|
+
async requestRefreshTokenAfterRegistration() {
|
|
756
|
+
return withPassportError(async () => {
|
|
757
|
+
const updatedUser = await retryWithDelay(async () => {
|
|
758
|
+
const user = await this.userManager.signinSilent();
|
|
759
|
+
const passportMetadata = user?.profile?.passport;
|
|
760
|
+
const metadataExists = !!passportMetadata?.ether_key &&
|
|
761
|
+
!!passportMetadata?.stark_key &&
|
|
762
|
+
!!passportMetadata?.user_admin_key;
|
|
763
|
+
if (metadataExists) {
|
|
764
|
+
return user;
|
|
765
|
+
}
|
|
766
|
+
return Promise.reject('user wallet addresses not exist');
|
|
767
|
+
});
|
|
768
|
+
if (!updatedUser) {
|
|
769
|
+
return null;
|
|
770
|
+
}
|
|
771
|
+
return this.mapOidcUserToDomainModel(updatedUser);
|
|
772
|
+
}, PassportErrorType.REFRESH_TOKEN_ERROR);
|
|
773
|
+
}
|
|
238
774
|
}
|
|
239
775
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
token_buy: convertToSignableToken(request.buy),
|
|
250
|
-
amount_sell: amountSell,
|
|
251
|
-
token_sell: convertToSignableToken(request.sell),
|
|
252
|
-
fees: request.fees,
|
|
253
|
-
expiration_timestamp: request.expiration_timestamp,
|
|
254
|
-
};
|
|
255
|
-
const getSignableOrderResponse = await ordersApi.getSignableOrder({
|
|
256
|
-
getSignableOrderRequestV3: getSignableOrderRequest,
|
|
257
|
-
});
|
|
258
|
-
const { signable_message: signableMessage, payload_hash: payloadHash } = getSignableOrderResponse.data;
|
|
259
|
-
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
260
|
-
const starkSignature = await signers.starkExSigner.signMessage(payloadHash);
|
|
261
|
-
const resp = getSignableOrderResponse.data;
|
|
262
|
-
const orderParams = {
|
|
263
|
-
createOrderRequest: {
|
|
264
|
-
amount_buy: resp.amount_buy,
|
|
265
|
-
amount_sell: resp.amount_sell,
|
|
266
|
-
asset_id_buy: resp.asset_id_buy,
|
|
267
|
-
asset_id_sell: resp.asset_id_sell,
|
|
268
|
-
expiration_timestamp: resp.expiration_timestamp,
|
|
269
|
-
include_fees: true,
|
|
270
|
-
fees: request.fees,
|
|
271
|
-
nonce: resp.nonce,
|
|
272
|
-
stark_key: resp.stark_key,
|
|
273
|
-
stark_signature: starkSignature,
|
|
274
|
-
vault_id_buy: resp.vault_id_buy,
|
|
275
|
-
vault_id_sell: resp.vault_id_sell,
|
|
276
|
-
},
|
|
277
|
-
xImxEthAddress: ethAddress,
|
|
278
|
-
xImxEthSignature: ethSignature,
|
|
279
|
-
};
|
|
280
|
-
const createOrderResponse = await ordersApi.createOrder(orderParams);
|
|
281
|
-
return {
|
|
282
|
-
...createOrderResponse.data,
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
async function cancelOrder$1({ signers, request, config, }) {
|
|
286
|
-
const ordersApi = new coreSdk.OrdersApi(config.getStarkExConfig().apiConfiguration);
|
|
287
|
-
const getSignableCancelOrderResponse = await ordersApi.getSignableCancelOrder({
|
|
288
|
-
getSignableCancelOrderRequest: {
|
|
289
|
-
order_id: request.order_id,
|
|
290
|
-
},
|
|
291
|
-
});
|
|
292
|
-
const { signable_message: signableMessage, payload_hash: payloadHash } = getSignableCancelOrderResponse.data;
|
|
293
|
-
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
294
|
-
const starkSignature = await signers.starkExSigner.signMessage(payloadHash);
|
|
295
|
-
const ethAddress = await signers.ethSigner.getAddress();
|
|
296
|
-
const cancelOrderResponse = await ordersApi.cancelOrder({
|
|
297
|
-
id: request.order_id.toString(),
|
|
298
|
-
cancelOrderRequest: {
|
|
299
|
-
order_id: request.order_id,
|
|
300
|
-
stark_signature: starkSignature,
|
|
301
|
-
},
|
|
302
|
-
xImxEthAddress: ethAddress,
|
|
303
|
-
xImxEthSignature: ethSignature,
|
|
304
|
-
});
|
|
305
|
-
return {
|
|
306
|
-
order_id: cancelOrderResponse.data.order_id,
|
|
307
|
-
status: cancelOrderResponse.data.status,
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
async function registerOffchain(signers, config) {
|
|
312
|
-
await validateChain(signers.ethSigner, config.getStarkExConfig());
|
|
313
|
-
const usersApi = new coreSdk.UsersApi(config.getStarkExConfig().apiConfiguration);
|
|
314
|
-
const userAddress = await signers.ethSigner.getAddress();
|
|
315
|
-
const starkPublicKey = await signers.starkExSigner.getAddress();
|
|
316
|
-
const signableResult = await usersApi.getSignableRegistrationOffchain({
|
|
317
|
-
getSignableRegistrationRequest: {
|
|
318
|
-
ether_key: userAddress,
|
|
319
|
-
stark_key: starkPublicKey,
|
|
320
|
-
},
|
|
321
|
-
});
|
|
322
|
-
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
323
|
-
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
324
|
-
const starkSignature = await signers.starkExSigner.signMessage(payloadHash);
|
|
325
|
-
const registeredUser = await usersApi.registerUser({
|
|
326
|
-
registerUserRequest: {
|
|
327
|
-
eth_signature: ethSignature,
|
|
328
|
-
ether_key: userAddress,
|
|
329
|
-
stark_signature: starkSignature,
|
|
330
|
-
stark_key: starkPublicKey,
|
|
331
|
-
},
|
|
332
|
-
});
|
|
333
|
-
return registeredUser.data;
|
|
334
|
-
}
|
|
335
|
-
async function isRegisteredOnChain(starkPublicKey, ethSigner, config) {
|
|
336
|
-
await validateChain(ethSigner, config.getStarkExConfig());
|
|
337
|
-
const registrationContract = coreSdk.Contracts.Registration.connect(config.getStarkExConfig().ethConfiguration.registrationContractAddress, ethSigner);
|
|
338
|
-
try {
|
|
339
|
-
return await registrationContract.isRegistered(starkPublicKey);
|
|
776
|
+
class MagicAdapter {
|
|
777
|
+
magicClient;
|
|
778
|
+
config;
|
|
779
|
+
constructor(config) {
|
|
780
|
+
this.config = config;
|
|
781
|
+
this.magicClient = new magicSdk.Magic(config.magicPublishableApiKey, {
|
|
782
|
+
network: config.network,
|
|
783
|
+
extensions: [new oidc.OpenIdExtension()],
|
|
784
|
+
});
|
|
340
785
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
786
|
+
async login(idToken) {
|
|
787
|
+
return withPassportError(async () => {
|
|
788
|
+
await this.magicClient.openid.loginWithOIDC({
|
|
789
|
+
jwt: idToken,
|
|
790
|
+
providerId: this.config.magicProviderId,
|
|
791
|
+
});
|
|
792
|
+
return new ethers.ethers.providers.Web3Provider(this.magicClient
|
|
793
|
+
.rpcProvider);
|
|
794
|
+
}, PassportErrorType.WALLET_CONNECTION_ERROR);
|
|
346
795
|
}
|
|
347
796
|
}
|
|
348
|
-
async function getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi) {
|
|
349
|
-
const response = await usersApi.getSignableRegistration({
|
|
350
|
-
getSignableRegistrationRequest: {
|
|
351
|
-
ether_key: etherKey,
|
|
352
|
-
stark_key: starkPublicKey,
|
|
353
|
-
},
|
|
354
|
-
});
|
|
355
|
-
return {
|
|
356
|
-
operator_signature: response.data.operator_signature,
|
|
357
|
-
payload_hash: response.data.payload_hash,
|
|
358
|
-
};
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
const assertIsDefined = (value) => {
|
|
362
|
-
if (value !== undefined)
|
|
363
|
-
return value;
|
|
364
|
-
throw new Error('undefined field exception');
|
|
365
|
-
};
|
|
366
|
-
async function prepareWithdrawalAction(params) {
|
|
367
|
-
const { signers: { ethSigner, starkExSigner }, type, config, } = params;
|
|
368
|
-
await validateChain(ethSigner, params.config);
|
|
369
|
-
const withdrawalsApi = new coreSdk.WithdrawalsApi(config.apiConfiguration);
|
|
370
|
-
const withdrawalAmount = type === 'ERC721' ? '1' : params.amount;
|
|
371
|
-
const signableWithdrawalResult = await withdrawalsApi.getSignableWithdrawal({
|
|
372
|
-
getSignableWithdrawalRequest: {
|
|
373
|
-
user: await ethSigner.getAddress(),
|
|
374
|
-
token: convertToSignableToken(params),
|
|
375
|
-
amount: withdrawalAmount,
|
|
376
|
-
},
|
|
377
|
-
});
|
|
378
|
-
const { signable_message: signableMessage, payload_hash: payloadHash } = signableWithdrawalResult.data;
|
|
379
|
-
const starkSignature = await starkExSigner.signMessage(payloadHash);
|
|
380
|
-
const { ethAddress, ethSignature } = await signMessage(signableMessage, ethSigner);
|
|
381
|
-
const prepareWithdrawalResponse = await withdrawalsApi.createWithdrawal({
|
|
382
|
-
createWithdrawalRequest: {
|
|
383
|
-
stark_key: assertIsDefined(signableWithdrawalResult.data.stark_key),
|
|
384
|
-
amount: withdrawalAmount,
|
|
385
|
-
asset_id: assertIsDefined(signableWithdrawalResult.data.asset_id),
|
|
386
|
-
vault_id: assertIsDefined(signableWithdrawalResult.data.vault_id),
|
|
387
|
-
nonce: assertIsDefined(signableWithdrawalResult.data.nonce),
|
|
388
|
-
stark_signature: starkSignature,
|
|
389
|
-
},
|
|
390
|
-
xImxEthAddress: ethAddress,
|
|
391
|
-
xImxEthSignature: ethSignature,
|
|
392
|
-
});
|
|
393
|
-
return prepareWithdrawalResponse.data;
|
|
394
|
-
}
|
|
395
797
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
798
|
+
var ReceiveMessage;
|
|
799
|
+
(function (ReceiveMessage) {
|
|
800
|
+
ReceiveMessage["CONFIRMATION_WINDOW_READY"] = "confirmation_window_ready";
|
|
801
|
+
ReceiveMessage["TRANSACTION_CONFIRMED"] = "transaction_confirmed";
|
|
802
|
+
ReceiveMessage["TRANSACTION_ERROR"] = "transaction_error";
|
|
803
|
+
})(ReceiveMessage || (ReceiveMessage = {}));
|
|
804
|
+
var SendMessage;
|
|
805
|
+
(function (SendMessage) {
|
|
806
|
+
SendMessage["TRANSACTION_START"] = "transaction_start";
|
|
807
|
+
})(SendMessage || (SendMessage = {}));
|
|
808
|
+
var TransactionTypes;
|
|
809
|
+
(function (TransactionTypes) {
|
|
810
|
+
TransactionTypes["CancelOrder"] = "delete:v1/orders";
|
|
811
|
+
TransactionTypes["CreateOrder"] = "post:v1/orders";
|
|
812
|
+
TransactionTypes["CreateTrade"] = "post:v1/trades";
|
|
813
|
+
TransactionTypes["CreateTransfer"] = "post:v1/transfers";
|
|
814
|
+
TransactionTypes["CreateBatchTransfer"] = "post:v2/transfers";
|
|
815
|
+
})(TransactionTypes || (TransactionTypes = {}));
|
|
816
|
+
const PassportEventType = 'imx_passport_confirmation';
|
|
409
817
|
|
|
410
|
-
|
|
411
|
-
const
|
|
412
|
-
const
|
|
413
|
-
const
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
423
|
-
}
|
|
424
|
-
async function completeERC20WithdrawalAction({ ethSigner, starkPublicKey, token, config, }) {
|
|
425
|
-
await validateChain(ethSigner, config.getStarkExConfig());
|
|
426
|
-
const starkExConfig = config.getStarkExConfig();
|
|
427
|
-
const assetType = await getEncodeAssetInfo('asset', 'ERC20', starkExConfig, {
|
|
428
|
-
token_address: token.tokenAddress,
|
|
429
|
-
});
|
|
430
|
-
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
431
|
-
if (!isRegistered) {
|
|
432
|
-
return executeRegisterAndWithdrawERC20({
|
|
433
|
-
ethSigner,
|
|
434
|
-
assetType: assetType.asset_type,
|
|
435
|
-
starkPublicKey,
|
|
436
|
-
config,
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
else {
|
|
440
|
-
return executeWithdrawERC20(ethSigner, assetType.asset_type, starkPublicKey, starkExConfig);
|
|
818
|
+
const openPopupCenter = ({ url, title, width, height, }) => {
|
|
819
|
+
const left = Math.max(0, Math.round(window.screenX + (window.outerWidth - width) / 2));
|
|
820
|
+
const top = Math.max(0, Math.round(window.screenY + (window.outerHeight - height) / 2));
|
|
821
|
+
const newWindow = window.open(url, title, `
|
|
822
|
+
scrollbars=yes,
|
|
823
|
+
width=${width},
|
|
824
|
+
height=${height},
|
|
825
|
+
top=${top},
|
|
826
|
+
left=${left}
|
|
827
|
+
`);
|
|
828
|
+
if (!newWindow) {
|
|
829
|
+
throw new Error('Failed to open confirmation screen');
|
|
441
830
|
}
|
|
442
|
-
|
|
831
|
+
newWindow.focus();
|
|
832
|
+
return newWindow;
|
|
833
|
+
};
|
|
443
834
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
453
|
-
const contract = coreSdk.Contracts.Registration.connect(config.ethConfiguration.registrationContractAddress, ethSigner);
|
|
454
|
-
const populatedTransaction = await contract.populateTransaction.regsiterAndWithdrawAndMint(etherKey, starkPublicKey, signableResult.operator_signature, assetType, mintingBlob);
|
|
455
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
456
|
-
}
|
|
457
|
-
function getMintingBlob(token) {
|
|
458
|
-
const id = token.data.id;
|
|
459
|
-
const blueprint = token.data.blueprint || '';
|
|
460
|
-
return encUtils__namespace.sanitizeHex(encUtils__namespace.utf8ToHex(`{${id}}:{${blueprint}}`));
|
|
461
|
-
}
|
|
462
|
-
async function completeMintableERC721Withdrawal(ethSigner, starkPublicKey, token, config) {
|
|
463
|
-
const starkExConfig = config.getStarkExConfig();
|
|
464
|
-
const assetType = await getEncodeAssetInfo('mintable-asset', 'ERC721', starkExConfig, {
|
|
465
|
-
id: token.data.id,
|
|
466
|
-
token_address: token.data.tokenAddress,
|
|
467
|
-
...(token.data.blueprint && { blueprint: token.data.blueprint }),
|
|
468
|
-
});
|
|
469
|
-
const mintingBlob = getMintingBlob(token);
|
|
470
|
-
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
471
|
-
if (!isRegistered) {
|
|
472
|
-
return executeRegisterAndWithdrawMintableERC721(ethSigner, assetType.asset_type, starkPublicKey, mintingBlob, starkExConfig);
|
|
835
|
+
const ConfirmationWindowTitle = 'Confirm this transaction';
|
|
836
|
+
const ConfirmationWindowHeight = 380;
|
|
837
|
+
const ConfirmationWindowWidth = 480;
|
|
838
|
+
const ConfirmationWindowClosedPollingDuration = 1000;
|
|
839
|
+
class ConfirmationScreen {
|
|
840
|
+
config;
|
|
841
|
+
constructor(config) {
|
|
842
|
+
this.config = config;
|
|
473
843
|
}
|
|
474
|
-
|
|
475
|
-
|
|
844
|
+
postMessage(destinationWindow, accessToken, message) {
|
|
845
|
+
destinationWindow.postMessage({
|
|
846
|
+
eventType: PassportEventType,
|
|
847
|
+
accessToken,
|
|
848
|
+
...message,
|
|
849
|
+
}, this.config.passportDomain);
|
|
476
850
|
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
tokenAddress: tokenAddress,
|
|
521
|
-
blueprint: mintableToken.data.blueprint,
|
|
522
|
-
},
|
|
523
|
-
}, config))
|
|
524
|
-
.catch((error) => {
|
|
525
|
-
if (error.response?.status === 404) {
|
|
526
|
-
// token is already minted on L1
|
|
527
|
-
return completeERC721Withdrawal(ethSigner, starkPublicKey, token, config);
|
|
528
|
-
}
|
|
529
|
-
throw error; // unable to recover from any other kind of error
|
|
530
|
-
});
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
async function executeRegisterAndWithdrawEth(ethSigner, assetType, starkPublicKey, config) {
|
|
534
|
-
const etherKey = await ethSigner.getAddress();
|
|
535
|
-
const usersApi = new coreSdk.UsersApi(config.apiConfiguration);
|
|
536
|
-
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
537
|
-
const contract = coreSdk.Contracts.Registration.connect(config.ethConfiguration.registrationContractAddress, ethSigner);
|
|
538
|
-
const populatedTransaction = await contract.populateTransaction.registerAndWithdraw(etherKey, starkPublicKey, signableResult.operator_signature, assetType);
|
|
539
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
540
|
-
}
|
|
541
|
-
async function executeWithdrawEth(ethSigner, assetType, starkPublicKey, config) {
|
|
542
|
-
const contract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
543
|
-
const populatedTransaction = await contract.populateTransaction.withdraw(starkPublicKey, assetType);
|
|
544
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
545
|
-
}
|
|
546
|
-
async function completeEthWithdrawalAction({ ethSigner, starkPublicKey, config, }) {
|
|
547
|
-
await validateChain(ethSigner, config.getStarkExConfig());
|
|
548
|
-
const starkExConfig = config.getStarkExConfig();
|
|
549
|
-
const assetType = await getEncodeAssetInfo('asset', 'ETH', starkExConfig);
|
|
550
|
-
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
551
|
-
if (!isRegistered) {
|
|
552
|
-
return executeRegisterAndWithdrawEth(ethSigner, assetType.asset_type, starkPublicKey, starkExConfig);
|
|
553
|
-
}
|
|
554
|
-
else {
|
|
555
|
-
return executeWithdrawEth(ethSigner, assetType.asset_type, starkPublicKey, starkExConfig);
|
|
851
|
+
startTransaction(accessToken, transaction, popupOptions) {
|
|
852
|
+
return new Promise((resolve, reject) => {
|
|
853
|
+
const messageHandler = ({ data, origin }) => {
|
|
854
|
+
if (origin != this.config.passportDomain ||
|
|
855
|
+
data.eventType != PassportEventType) {
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
858
|
+
switch (data.messageType) {
|
|
859
|
+
case ReceiveMessage.CONFIRMATION_WINDOW_READY: {
|
|
860
|
+
this.postMessage(confirmationWindow, accessToken, {
|
|
861
|
+
messageType: SendMessage.TRANSACTION_START,
|
|
862
|
+
messageData: transaction,
|
|
863
|
+
});
|
|
864
|
+
break;
|
|
865
|
+
}
|
|
866
|
+
case ReceiveMessage.TRANSACTION_CONFIRMED: {
|
|
867
|
+
resolve({ confirmed: true });
|
|
868
|
+
break;
|
|
869
|
+
}
|
|
870
|
+
case ReceiveMessage.TRANSACTION_ERROR: {
|
|
871
|
+
reject(new Error('Transaction error'));
|
|
872
|
+
break;
|
|
873
|
+
}
|
|
874
|
+
default:
|
|
875
|
+
reject(new Error('Unsupported message type'));
|
|
876
|
+
}
|
|
877
|
+
};
|
|
878
|
+
window.addEventListener('message', messageHandler);
|
|
879
|
+
const confirmationWindow = openPopupCenter({
|
|
880
|
+
url: `${this.config.passportDomain}/transaction-confirmation`,
|
|
881
|
+
title: ConfirmationWindowTitle,
|
|
882
|
+
width: popupOptions?.width || ConfirmationWindowWidth,
|
|
883
|
+
height: popupOptions?.height || ConfirmationWindowHeight,
|
|
884
|
+
});
|
|
885
|
+
// https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
|
|
886
|
+
const timer = setInterval(function () {
|
|
887
|
+
if (confirmationWindow.closed) {
|
|
888
|
+
clearInterval(timer);
|
|
889
|
+
window.removeEventListener('message', messageHandler);
|
|
890
|
+
resolve({ confirmed: false });
|
|
891
|
+
}
|
|
892
|
+
}, ConfirmationWindowClosedPollingDuration);
|
|
893
|
+
});
|
|
556
894
|
}
|
|
557
895
|
}
|
|
558
896
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
return
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
897
|
+
const ERC721$1 = 'ERC721';
|
|
898
|
+
const transfer$1 = ({ request, transfersApi, starkSigner, user, passportConfig, }) => {
|
|
899
|
+
return withPassportError(async () => {
|
|
900
|
+
const transferAmount = request.type === ERC721$1 ? '1' : request.amount;
|
|
901
|
+
const getSignableTransferRequest = {
|
|
902
|
+
sender: user.etherKey,
|
|
903
|
+
token: convertToSignableToken(request),
|
|
904
|
+
amount: transferAmount,
|
|
905
|
+
receiver: request.receiver,
|
|
906
|
+
};
|
|
907
|
+
const signableResult = await transfersApi.getSignableTransferV1({
|
|
908
|
+
getSignableTransferRequest,
|
|
909
|
+
});
|
|
910
|
+
const confirmationScreen = new ConfirmationScreen(passportConfig);
|
|
911
|
+
const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
|
|
912
|
+
transactionType: TransactionTypes.CreateTransfer,
|
|
913
|
+
transactionData: getSignableTransferRequest,
|
|
914
|
+
});
|
|
915
|
+
if (!confirmationResult.confirmed) {
|
|
916
|
+
throw new Error('Transaction rejected by user');
|
|
917
|
+
}
|
|
918
|
+
const signableResultData = signableResult.data;
|
|
919
|
+
const { payload_hash: payloadHash } = signableResultData;
|
|
920
|
+
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
921
|
+
const senderStarkKey = await starkSigner.getAddress();
|
|
922
|
+
const transferSigningParams = {
|
|
923
|
+
sender_stark_key: signableResultData.sender_stark_key || senderStarkKey,
|
|
924
|
+
sender_vault_id: signableResultData.sender_vault_id,
|
|
925
|
+
receiver_stark_key: signableResultData.receiver_stark_key,
|
|
926
|
+
receiver_vault_id: signableResultData.receiver_vault_id,
|
|
927
|
+
asset_id: signableResultData.asset_id,
|
|
928
|
+
amount: signableResultData.amount,
|
|
929
|
+
nonce: signableResultData.nonce,
|
|
930
|
+
expiration_timestamp: signableResultData.expiration_timestamp,
|
|
931
|
+
stark_signature: starkSignature,
|
|
932
|
+
};
|
|
933
|
+
const createTransferRequest = {
|
|
934
|
+
createTransferRequest: transferSigningParams,
|
|
935
|
+
};
|
|
936
|
+
const headers = {
|
|
937
|
+
Authorization: 'Bearer ' + user.accessToken,
|
|
938
|
+
};
|
|
939
|
+
const { data: responseData } = await transfersApi.createTransferV1(createTransferRequest, { headers });
|
|
940
|
+
return {
|
|
941
|
+
sent_signature: responseData.sent_signature,
|
|
942
|
+
status: responseData.status?.toString(),
|
|
943
|
+
time: responseData.time,
|
|
944
|
+
transfer_id: responseData.transfer_id,
|
|
945
|
+
};
|
|
946
|
+
}, PassportErrorType.TRANSFER_ERROR);
|
|
947
|
+
};
|
|
948
|
+
async function batchNftTransfer({ user, starkSigner, request, transfersApi, passportConfig, }) {
|
|
949
|
+
return withPassportError(async () => {
|
|
950
|
+
const ethAddress = user.etherKey;
|
|
951
|
+
const signableRequests = request.map((nftTransfer) => {
|
|
952
|
+
return {
|
|
953
|
+
amount: '1',
|
|
954
|
+
token: convertToSignableToken({
|
|
955
|
+
type: ERC721$1,
|
|
956
|
+
tokenId: nftTransfer.tokenId,
|
|
957
|
+
tokenAddress: nftTransfer.tokenAddress,
|
|
958
|
+
}),
|
|
959
|
+
receiver: nftTransfer.receiver,
|
|
960
|
+
};
|
|
961
|
+
});
|
|
962
|
+
const getSignableTransferRequestV2 = {
|
|
963
|
+
sender_ether_key: ethAddress,
|
|
964
|
+
signable_requests: signableRequests,
|
|
965
|
+
};
|
|
966
|
+
const signableResult = await transfersApi.getSignableTransfer({
|
|
967
|
+
getSignableTransferRequestV2,
|
|
968
|
+
});
|
|
969
|
+
const confirmationScreen = new ConfirmationScreen(passportConfig);
|
|
970
|
+
const popupWindowSize = { width: 480, height: 784 };
|
|
971
|
+
const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
|
|
972
|
+
transactionType: TransactionTypes.CreateBatchTransfer,
|
|
973
|
+
transactionData: getSignableTransferRequestV2,
|
|
974
|
+
}, popupWindowSize);
|
|
975
|
+
if (!confirmationResult.confirmed) {
|
|
976
|
+
throw new Error('Transaction rejected by user');
|
|
977
|
+
}
|
|
978
|
+
const requests = await Promise.all(signableResult.data.signable_responses.map(async (resp) => {
|
|
979
|
+
const starkSignature = await starkSigner.signMessage(resp.payload_hash);
|
|
980
|
+
return {
|
|
981
|
+
sender_vault_id: resp.sender_vault_id,
|
|
982
|
+
receiver_stark_key: resp.receiver_stark_key,
|
|
983
|
+
receiver_vault_id: resp.receiver_vault_id,
|
|
984
|
+
asset_id: resp.asset_id,
|
|
985
|
+
amount: resp.amount,
|
|
986
|
+
nonce: resp.nonce,
|
|
987
|
+
expiration_timestamp: resp.expiration_timestamp,
|
|
988
|
+
stark_signature: starkSignature,
|
|
989
|
+
};
|
|
990
|
+
}));
|
|
991
|
+
const transferSigningParams = {
|
|
992
|
+
sender_stark_key: signableResult.data.sender_stark_key,
|
|
993
|
+
requests,
|
|
994
|
+
};
|
|
995
|
+
const headers = {
|
|
996
|
+
Authorization: 'Bearer ' + user.accessToken,
|
|
997
|
+
};
|
|
998
|
+
const response = await transfersApi.createTransfer({
|
|
999
|
+
createTransferRequestV2: transferSigningParams,
|
|
1000
|
+
}, { headers });
|
|
1001
|
+
return {
|
|
1002
|
+
transfer_ids: response?.data.transfer_ids,
|
|
1003
|
+
};
|
|
1004
|
+
}, PassportErrorType.TRANSFER_ERROR);
|
|
586
1005
|
}
|
|
587
1006
|
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
1007
|
+
const ERC721 = 'ERC721';
|
|
1008
|
+
async function createOrder$1({ starkSigner, user, request, ordersApi, passportConfig, }) {
|
|
1009
|
+
return withPassportError(async () => {
|
|
1010
|
+
const ethAddress = user.etherKey;
|
|
1011
|
+
const amountSell = request.sell.type === ERC721 ? '1' : request.sell.amount;
|
|
1012
|
+
const amountBuy = request.buy.type === ERC721 ? '1' : request.buy.amount;
|
|
1013
|
+
const getSignableOrderRequestV3 = {
|
|
594
1014
|
user: ethAddress,
|
|
595
|
-
|
|
1015
|
+
amount_buy: amountBuy,
|
|
1016
|
+
token_buy: convertToSignableToken(request.buy),
|
|
1017
|
+
amount_sell: amountSell,
|
|
1018
|
+
token_sell: convertToSignableToken(request.sell),
|
|
596
1019
|
fees: request.fees,
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
const user = await ethSigner.getAddress();
|
|
628
|
-
const data = {
|
|
629
|
-
decimals: 18,
|
|
630
|
-
};
|
|
631
|
-
const amount = units.parseUnits(deposit.amount, 'wei');
|
|
632
|
-
const starkExConfig = config.getStarkExConfig();
|
|
633
|
-
const depositsApi = new coreSdk.DepositsApi(starkExConfig.apiConfiguration);
|
|
634
|
-
const encodingApi = new coreSdk.EncodingApi(starkExConfig.apiConfiguration);
|
|
635
|
-
const usersApi = new coreSdk.UsersApi(starkExConfig.apiConfiguration);
|
|
636
|
-
const getSignableDepositRequest = {
|
|
637
|
-
user,
|
|
638
|
-
token: {
|
|
639
|
-
type: deposit.type,
|
|
640
|
-
data,
|
|
641
|
-
},
|
|
642
|
-
amount: amount.toString(),
|
|
643
|
-
};
|
|
644
|
-
const signableDepositResult = await depositsApi.getSignableDeposit({
|
|
645
|
-
getSignableDepositRequest,
|
|
646
|
-
});
|
|
647
|
-
const encodingResult = await encodingApi.encodeAsset({
|
|
648
|
-
assetType: 'asset',
|
|
649
|
-
encodeAssetRequest: {
|
|
650
|
-
token: {
|
|
651
|
-
type: deposit.type,
|
|
1020
|
+
expiration_timestamp: request.expiration_timestamp,
|
|
1021
|
+
};
|
|
1022
|
+
const getSignableOrderResponse = await ordersApi.getSignableOrder({
|
|
1023
|
+
getSignableOrderRequestV3,
|
|
1024
|
+
});
|
|
1025
|
+
const confirmationScreen = new ConfirmationScreen(passportConfig);
|
|
1026
|
+
const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
|
|
1027
|
+
transactionType: TransactionTypes.CreateOrder,
|
|
1028
|
+
transactionData: getSignableOrderRequestV3,
|
|
1029
|
+
});
|
|
1030
|
+
if (!confirmationResult.confirmed) {
|
|
1031
|
+
throw new Error('Transaction rejected by user');
|
|
1032
|
+
}
|
|
1033
|
+
const { payload_hash: payloadHash } = getSignableOrderResponse.data;
|
|
1034
|
+
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
1035
|
+
const signableResultData = getSignableOrderResponse.data;
|
|
1036
|
+
const orderParams = {
|
|
1037
|
+
createOrderRequest: {
|
|
1038
|
+
include_fees: true,
|
|
1039
|
+
fees: request.fees,
|
|
1040
|
+
stark_signature: starkSignature,
|
|
1041
|
+
amount_buy: signableResultData.amount_buy,
|
|
1042
|
+
amount_sell: signableResultData.amount_sell,
|
|
1043
|
+
asset_id_buy: signableResultData.asset_id_buy,
|
|
1044
|
+
asset_id_sell: signableResultData.asset_id_sell,
|
|
1045
|
+
expiration_timestamp: signableResultData.expiration_timestamp,
|
|
1046
|
+
nonce: signableResultData.nonce,
|
|
1047
|
+
stark_key: signableResultData.stark_key,
|
|
1048
|
+
vault_id_buy: signableResultData.vault_id_buy,
|
|
1049
|
+
vault_id_sell: signableResultData.vault_id_sell,
|
|
652
1050
|
},
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
return
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
async function executeRegisterAndDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, config, usersApi) {
|
|
667
|
-
const etherKey = await ethSigner.getAddress();
|
|
668
|
-
const coreContract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
669
|
-
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
670
|
-
const populatedTransaction = await coreContract.populateTransaction.registerAndDepositEth(etherKey, starkPublicKey, signableResult.operator_signature, assetType, vaultId);
|
|
671
|
-
return ethSigner.sendTransaction({ ...populatedTransaction, value: amount });
|
|
1051
|
+
};
|
|
1052
|
+
const headers = {
|
|
1053
|
+
Authorization: 'Bearer ' + user.accessToken,
|
|
1054
|
+
};
|
|
1055
|
+
const createOrderResponse = await ordersApi.createOrder(orderParams, {
|
|
1056
|
+
headers,
|
|
1057
|
+
});
|
|
1058
|
+
return {
|
|
1059
|
+
...createOrderResponse.data,
|
|
1060
|
+
};
|
|
1061
|
+
}, PassportErrorType.CREATE_ORDER_ERROR);
|
|
672
1062
|
}
|
|
673
|
-
async function
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
1063
|
+
async function cancelOrder$1({ user, starkSigner, request, ordersApi, passportConfig, }) {
|
|
1064
|
+
return withPassportError(async () => {
|
|
1065
|
+
const getSignableCancelOrderRequest = {
|
|
1066
|
+
order_id: request.order_id,
|
|
1067
|
+
};
|
|
1068
|
+
const getSignableCancelOrderResponse = await ordersApi.getSignableCancelOrder({
|
|
1069
|
+
getSignableCancelOrderRequest,
|
|
1070
|
+
});
|
|
1071
|
+
const confirmationScreen = new ConfirmationScreen(passportConfig);
|
|
1072
|
+
const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
|
|
1073
|
+
transactionType: TransactionTypes.CancelOrder,
|
|
1074
|
+
transactionData: getSignableCancelOrderRequest,
|
|
1075
|
+
});
|
|
1076
|
+
if (!confirmationResult.confirmed) {
|
|
1077
|
+
throw new Error('Transaction rejected by user');
|
|
1078
|
+
}
|
|
1079
|
+
const { payload_hash: payloadHash } = getSignableCancelOrderResponse.data;
|
|
1080
|
+
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
1081
|
+
const headers = {
|
|
1082
|
+
Authorization: 'Bearer ' + user.accessToken,
|
|
1083
|
+
};
|
|
1084
|
+
const cancelOrderResponse = await ordersApi.cancelOrder({
|
|
1085
|
+
id: request.order_id.toString(),
|
|
1086
|
+
cancelOrderRequest: {
|
|
1087
|
+
order_id: request.order_id,
|
|
1088
|
+
stark_signature: starkSignature,
|
|
1089
|
+
},
|
|
1090
|
+
}, { headers });
|
|
1091
|
+
return {
|
|
1092
|
+
order_id: cancelOrderResponse.data.order_id,
|
|
1093
|
+
status: cancelOrderResponse.data.status,
|
|
1094
|
+
};
|
|
1095
|
+
}, PassportErrorType.CANCEL_ORDER_ERROR);
|
|
677
1096
|
}
|
|
678
1097
|
|
|
679
|
-
async function
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
const data = {
|
|
691
|
-
decimals,
|
|
692
|
-
token_address: deposit.tokenAddress,
|
|
693
|
-
};
|
|
694
|
-
const amount = units.parseUnits(deposit.amount, 0); // 0 to always use undecimalized value
|
|
695
|
-
// Approve whether an amount of token from an account can be spent by a third-party account
|
|
696
|
-
const tokenContract = coreSdk.Contracts.IERC20.connect(deposit.tokenAddress, ethSigner);
|
|
697
|
-
const approveTransaction = await tokenContract.populateTransaction.approve(ethConfiguration.coreContractAddress, amount);
|
|
698
|
-
await ethSigner.sendTransaction(approveTransaction);
|
|
699
|
-
const getSignableDepositRequest = {
|
|
700
|
-
user,
|
|
701
|
-
token: {
|
|
702
|
-
type: deposit.type,
|
|
703
|
-
data,
|
|
704
|
-
},
|
|
705
|
-
amount: amount.toString(),
|
|
706
|
-
};
|
|
707
|
-
const signableDepositResult = await depositsApi.getSignableDeposit({
|
|
708
|
-
getSignableDepositRequest,
|
|
709
|
-
});
|
|
710
|
-
// Perform encoding on asset details to get an assetType (required for stark contract request)
|
|
711
|
-
const encodingResult = await encodingApi.encodeAsset({
|
|
712
|
-
assetType: 'asset',
|
|
713
|
-
encodeAssetRequest: {
|
|
714
|
-
token: {
|
|
715
|
-
type: deposit.type,
|
|
716
|
-
data: {
|
|
717
|
-
token_address: deposit.tokenAddress,
|
|
718
|
-
},
|
|
1098
|
+
async function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, }) {
|
|
1099
|
+
return withPassportError(async () => {
|
|
1100
|
+
const ethAddress = user.etherKey;
|
|
1101
|
+
const transferAmount = request.amount;
|
|
1102
|
+
const signableResult = await exchangesApi.getExchangeSignableTransfer({
|
|
1103
|
+
id: request.transactionID,
|
|
1104
|
+
getSignableTransferRequest: {
|
|
1105
|
+
sender: ethAddress,
|
|
1106
|
+
token: convertToSignableToken(request),
|
|
1107
|
+
amount: transferAmount,
|
|
1108
|
+
receiver: request.receiver,
|
|
719
1109
|
},
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
1110
|
+
});
|
|
1111
|
+
const starkAddress = await starkSigner.getAddress();
|
|
1112
|
+
const { payload_hash: payloadHash } = signableResult.data;
|
|
1113
|
+
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
1114
|
+
const transferSigningParams = {
|
|
1115
|
+
sender_stark_key: signableResult.data.sender_stark_key || starkAddress,
|
|
1116
|
+
sender_vault_id: signableResult.data.sender_vault_id,
|
|
1117
|
+
receiver_stark_key: signableResult.data.receiver_stark_key,
|
|
1118
|
+
receiver_vault_id: signableResult.data.receiver_vault_id,
|
|
1119
|
+
asset_id: signableResult.data.asset_id,
|
|
1120
|
+
amount: signableResult.data.amount,
|
|
1121
|
+
nonce: signableResult.data.nonce,
|
|
1122
|
+
expiration_timestamp: signableResult.data.expiration_timestamp,
|
|
1123
|
+
stark_signature: starkSignature,
|
|
1124
|
+
};
|
|
1125
|
+
const headers = {
|
|
1126
|
+
Authorization: 'Bearer ' + user.accessToken,
|
|
1127
|
+
};
|
|
1128
|
+
const response = await exchangesApi.createExchangeTransfer({
|
|
1129
|
+
id: request.transactionID,
|
|
1130
|
+
createTransferRequest: transferSigningParams,
|
|
1131
|
+
}, { headers });
|
|
1132
|
+
return {
|
|
1133
|
+
sent_signature: response?.data.sent_signature,
|
|
1134
|
+
status: response?.data.status?.toString(),
|
|
1135
|
+
time: response?.data.time,
|
|
1136
|
+
transfer_id: response?.data.transfer_id,
|
|
1137
|
+
};
|
|
1138
|
+
}, PassportErrorType.EXCHANGE_TRANSFER_ERROR);
|
|
745
1139
|
}
|
|
746
1140
|
|
|
747
|
-
async function
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
user,
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
1141
|
+
async function createTrade$1({ request, tradesApi, user, starkSigner, passportConfig, }) {
|
|
1142
|
+
return withPassportError(async () => {
|
|
1143
|
+
const ethAddress = user.etherKey;
|
|
1144
|
+
const getSignableTradeRequest = {
|
|
1145
|
+
expiration_timestamp: request.expiration_timestamp,
|
|
1146
|
+
fees: request.fees,
|
|
1147
|
+
order_id: request.order_id,
|
|
1148
|
+
user: ethAddress,
|
|
1149
|
+
};
|
|
1150
|
+
const getSignableTradeResponse = await tradesApi.getSignableTrade({
|
|
1151
|
+
getSignableTradeRequest,
|
|
1152
|
+
});
|
|
1153
|
+
const confirmationScreen = new ConfirmationScreen(passportConfig);
|
|
1154
|
+
const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
|
|
1155
|
+
transactionType: TransactionTypes.CreateTrade,
|
|
1156
|
+
transactionData: getSignableTradeRequest,
|
|
1157
|
+
});
|
|
1158
|
+
if (!confirmationResult.confirmed) {
|
|
1159
|
+
throw new Error('Transaction rejected by user');
|
|
1160
|
+
}
|
|
1161
|
+
const { payload_hash: payloadHash } = getSignableTradeResponse.data;
|
|
1162
|
+
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
1163
|
+
const { data: signableResultData } = getSignableTradeResponse;
|
|
1164
|
+
const tradeParams = {
|
|
1165
|
+
createTradeRequest: {
|
|
1166
|
+
include_fees: true,
|
|
1167
|
+
fees: request?.fees,
|
|
1168
|
+
stark_signature: starkSignature,
|
|
1169
|
+
order_id: request?.order_id,
|
|
1170
|
+
fee_info: signableResultData.fee_info,
|
|
1171
|
+
amount_buy: signableResultData.amount_buy,
|
|
1172
|
+
amount_sell: signableResultData.amount_sell,
|
|
1173
|
+
asset_id_buy: signableResultData.asset_id_buy,
|
|
1174
|
+
asset_id_sell: signableResultData.asset_id_sell,
|
|
1175
|
+
expiration_timestamp: signableResultData.expiration_timestamp,
|
|
1176
|
+
nonce: signableResultData.nonce,
|
|
1177
|
+
stark_key: signableResultData.stark_key,
|
|
1178
|
+
vault_id_buy: signableResultData.vault_id_buy,
|
|
1179
|
+
vault_id_sell: signableResultData.vault_id_sell,
|
|
780
1180
|
},
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
const tokenContract = coreSdk.Contracts.IERC721.connect(deposit.tokenAddress, ethSigner);
|
|
789
|
-
const operator = starkExConfig.ethConfiguration.coreContractAddress;
|
|
790
|
-
const isApprovedForAll = await tokenContract.isApprovedForAll(user, operator);
|
|
791
|
-
if (!isApprovedForAll) {
|
|
792
|
-
await tokenContract.setApprovalForAll(operator, true);
|
|
793
|
-
}
|
|
794
|
-
if (!isRegistered) {
|
|
795
|
-
const signableResult = await getSignableRegistrationOnchain(user, starkPublicKey, usersApi);
|
|
796
|
-
const coreContract = coreSdk.Contracts.Core.connect(starkExConfig.ethConfiguration.coreContractAddress, ethSigner);
|
|
797
|
-
// Note: proxy registration contract registerAndDepositNft method is not used as it currently fails erc721 transfer ownership check
|
|
798
|
-
await coreContract.registerUser(user, starkPublicKey, signableResult.operator_signature);
|
|
799
|
-
}
|
|
800
|
-
return executeDepositERC721(ethSigner, deposit.tokenId, assetType, starkPublicKey, vaultId, starkExConfig);
|
|
801
|
-
}
|
|
802
|
-
async function executeDepositERC721(ethSigner, tokenId, assetType, starkPublicKey, vaultId, config) {
|
|
803
|
-
const coreContract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
804
|
-
const populatedTransaction = await coreContract.populateTransaction.depositNft(starkPublicKey, assetType, vaultId, tokenId);
|
|
805
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
async function deposit({ signers, deposit, config }) {
|
|
809
|
-
switch (deposit.type) {
|
|
810
|
-
case 'ETH':
|
|
811
|
-
return depositEth({ signers, deposit, config });
|
|
812
|
-
case 'ERC20':
|
|
813
|
-
return depositERC20({ signers, deposit, config });
|
|
814
|
-
case 'ERC721':
|
|
815
|
-
return depositERC721({ signers, deposit, config });
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
async function exchangeTransfer$1({ signers, request, config, }) {
|
|
820
|
-
await validateChain(signers.ethSigner, config.getStarkExConfig());
|
|
821
|
-
const exchangeApi = new coreSdk.ExchangesApi(config.getStarkExConfig().apiConfiguration);
|
|
822
|
-
const ethAddress = await signers.ethSigner.getAddress();
|
|
823
|
-
const transferAmount = request.amount;
|
|
824
|
-
const signableResult = await exchangeApi.getExchangeSignableTransfer({
|
|
825
|
-
id: request.transactionID,
|
|
826
|
-
getSignableTransferRequest: {
|
|
827
|
-
sender: ethAddress,
|
|
828
|
-
token: convertToSignableToken(request),
|
|
829
|
-
amount: transferAmount,
|
|
830
|
-
receiver: request.receiver,
|
|
831
|
-
},
|
|
832
|
-
});
|
|
833
|
-
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
834
|
-
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
835
|
-
const starkSignature = await signers.starkExSigner.signMessage(payloadHash);
|
|
836
|
-
const transferSigningParams = {
|
|
837
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
838
|
-
sender_stark_key: signableResult.data.sender_stark_key,
|
|
839
|
-
sender_vault_id: signableResult.data.sender_vault_id,
|
|
840
|
-
receiver_stark_key: signableResult.data.receiver_stark_key,
|
|
841
|
-
receiver_vault_id: signableResult.data.receiver_vault_id,
|
|
842
|
-
asset_id: signableResult.data.asset_id,
|
|
843
|
-
amount: signableResult.data.amount,
|
|
844
|
-
nonce: signableResult.data.nonce,
|
|
845
|
-
expiration_timestamp: signableResult.data.expiration_timestamp,
|
|
846
|
-
stark_signature: starkSignature,
|
|
847
|
-
};
|
|
848
|
-
const response = await exchangeApi.createExchangeTransfer({
|
|
849
|
-
id: request.transactionID,
|
|
850
|
-
createTransferRequest: transferSigningParams,
|
|
851
|
-
xImxEthAddress: ethAddress,
|
|
852
|
-
xImxEthSignature: ethSignature,
|
|
853
|
-
});
|
|
854
|
-
return {
|
|
855
|
-
sent_signature: response?.data.sent_signature,
|
|
856
|
-
status: response?.data.status?.toString(),
|
|
857
|
-
time: response?.data.time,
|
|
858
|
-
transfer_id: response?.data.transfer_id,
|
|
859
|
-
};
|
|
1181
|
+
};
|
|
1182
|
+
const headers = { Authorization: 'Bearer ' + user.accessToken };
|
|
1183
|
+
const { data: createTradeResponse } = await tradesApi.createTradeV3(tradeParams, {
|
|
1184
|
+
headers,
|
|
1185
|
+
});
|
|
1186
|
+
return createTradeResponse;
|
|
1187
|
+
}, PassportErrorType.CREATE_TRADE_ERROR);
|
|
860
1188
|
}
|
|
861
1189
|
|
|
862
|
-
class
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
1190
|
+
class PassportImxProvider {
|
|
1191
|
+
user;
|
|
1192
|
+
starkSigner;
|
|
1193
|
+
transfersApi;
|
|
1194
|
+
ordersApi;
|
|
1195
|
+
passportConfig;
|
|
1196
|
+
exchangesApi;
|
|
1197
|
+
tradesApi;
|
|
1198
|
+
constructor({ user, starkSigner, passportConfig }) {
|
|
1199
|
+
this.user = user;
|
|
1200
|
+
this.starkSigner = starkSigner;
|
|
1201
|
+
this.passportConfig = passportConfig;
|
|
1202
|
+
const apiConfig = new coreSdk.Configuration({
|
|
1203
|
+
basePath: passportConfig.imxApiBasePath,
|
|
1204
|
+
});
|
|
1205
|
+
this.transfersApi = new coreSdk.TransfersApi(apiConfig);
|
|
1206
|
+
this.ordersApi = new coreSdk.OrdersApi(apiConfig);
|
|
1207
|
+
this.exchangesApi = new coreSdk.ExchangesApi(apiConfig);
|
|
1208
|
+
this.tradesApi = new coreSdk.TradesApi(apiConfig);
|
|
868
1209
|
}
|
|
869
|
-
async
|
|
870
|
-
return
|
|
1210
|
+
async transfer(request) {
|
|
1211
|
+
return transfer$1({
|
|
1212
|
+
request,
|
|
1213
|
+
user: this.user,
|
|
1214
|
+
starkSigner: this.starkSigner,
|
|
1215
|
+
transfersApi: this.transfersApi,
|
|
1216
|
+
passportConfig: this.passportConfig,
|
|
1217
|
+
});
|
|
871
1218
|
}
|
|
872
1219
|
registerOffchain() {
|
|
873
|
-
|
|
1220
|
+
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
874
1221
|
}
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
1222
|
+
isRegisteredOnchain() {
|
|
1223
|
+
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
1224
|
+
}
|
|
1225
|
+
createOrder(request) {
|
|
1226
|
+
return createOrder$1({
|
|
878
1227
|
request,
|
|
879
|
-
|
|
1228
|
+
user: this.user,
|
|
1229
|
+
starkSigner: this.starkSigner,
|
|
1230
|
+
ordersApi: this.ordersApi,
|
|
1231
|
+
passportConfig: this.passportConfig,
|
|
880
1232
|
});
|
|
881
1233
|
}
|
|
882
1234
|
cancelOrder(request) {
|
|
883
1235
|
return cancelOrder$1({
|
|
884
|
-
signers: this.signers,
|
|
885
|
-
request,
|
|
886
|
-
config: this.config,
|
|
887
|
-
});
|
|
888
|
-
}
|
|
889
|
-
completeWithdrawal(starkPublicKey, token) {
|
|
890
|
-
return completeWithdrawal({
|
|
891
|
-
config: this.config,
|
|
892
|
-
signers: this.signers,
|
|
893
|
-
token,
|
|
894
|
-
starkPublicKey,
|
|
895
|
-
});
|
|
896
|
-
}
|
|
897
|
-
createOrder(request) {
|
|
898
|
-
return createOrder$1({
|
|
899
|
-
signers: this.signers,
|
|
900
1236
|
request,
|
|
901
|
-
|
|
1237
|
+
user: this.user,
|
|
1238
|
+
starkSigner: this.starkSigner,
|
|
1239
|
+
ordersApi: this.ordersApi,
|
|
1240
|
+
passportConfig: this.passportConfig,
|
|
902
1241
|
});
|
|
903
1242
|
}
|
|
904
1243
|
createTrade(request) {
|
|
905
1244
|
return createTrade$1({
|
|
906
|
-
signers: this.signers,
|
|
907
1245
|
request,
|
|
908
|
-
|
|
1246
|
+
user: this.user,
|
|
1247
|
+
starkSigner: this.starkSigner,
|
|
1248
|
+
tradesApi: this.tradesApi,
|
|
1249
|
+
passportConfig: this.passportConfig,
|
|
909
1250
|
});
|
|
910
1251
|
}
|
|
911
|
-
|
|
912
|
-
return
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
1252
|
+
batchNftTransfer(request) {
|
|
1253
|
+
return batchNftTransfer({
|
|
1254
|
+
request,
|
|
1255
|
+
user: this.user,
|
|
1256
|
+
starkSigner: this.starkSigner,
|
|
1257
|
+
transfersApi: this.transfersApi,
|
|
1258
|
+
passportConfig: this.passportConfig,
|
|
916
1259
|
});
|
|
917
1260
|
}
|
|
918
1261
|
exchangeTransfer(request) {
|
|
919
1262
|
return exchangeTransfer$1({
|
|
920
|
-
signers: this.signers,
|
|
921
1263
|
request,
|
|
922
|
-
|
|
1264
|
+
user: this.user,
|
|
1265
|
+
starkSigner: this.starkSigner,
|
|
1266
|
+
exchangesApi: this.exchangesApi,
|
|
923
1267
|
});
|
|
924
1268
|
}
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
1269
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1270
|
+
deposit(deposit) {
|
|
1271
|
+
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
928
1272
|
}
|
|
1273
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
929
1274
|
prepareWithdrawal(request) {
|
|
930
|
-
|
|
931
|
-
signers: this.signers,
|
|
932
|
-
withdrawal: request,
|
|
933
|
-
config: this.config,
|
|
934
|
-
});
|
|
1275
|
+
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
935
1276
|
}
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
1277
|
+
completeWithdrawal(
|
|
1278
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1279
|
+
starkPublicKey,
|
|
1280
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1281
|
+
token) {
|
|
1282
|
+
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
1283
|
+
}
|
|
1284
|
+
getAddress() {
|
|
1285
|
+
return Promise.resolve(this.starkSigner.getAddress());
|
|
942
1286
|
}
|
|
943
1287
|
}
|
|
944
1288
|
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
return !!provider?.request;
|
|
951
|
-
}
|
|
952
|
-
async function connectProvider(provider, chainID) {
|
|
953
|
-
await provider.request({ method: WALLET_ACTION.CONNECT });
|
|
954
|
-
if (chainID) {
|
|
955
|
-
await provider.request({
|
|
956
|
-
method: WALLET_ACTION.SWITCH_CHAIN,
|
|
957
|
-
params: [{ chainId: `0x${chainID.toString(16)}` }],
|
|
958
|
-
});
|
|
959
|
-
}
|
|
960
|
-
}
|
|
1289
|
+
var Networks;
|
|
1290
|
+
(function (Networks) {
|
|
1291
|
+
Networks["PRODUCTION"] = "mainnet";
|
|
1292
|
+
Networks["SANDBOX"] = "goerli";
|
|
1293
|
+
})(Networks || (Networks = {}));
|
|
961
1294
|
|
|
962
|
-
const
|
|
963
|
-
|
|
1295
|
+
const validateConfiguration = (configuration, requiredKeys, prefix) => {
|
|
1296
|
+
const missingKeys = requiredKeys
|
|
1297
|
+
.map((key) => !configuration[key] && key)
|
|
1298
|
+
.filter((n) => n)
|
|
1299
|
+
.join(', ');
|
|
1300
|
+
if (missingKeys !== '') {
|
|
1301
|
+
const errorMessage = prefix
|
|
1302
|
+
? `${prefix} - ${missingKeys} cannot be null`
|
|
1303
|
+
: `${missingKeys} cannot be null`;
|
|
1304
|
+
throw new PassportError(errorMessage, PassportErrorType.INVALID_CONFIGURATION);
|
|
1305
|
+
}
|
|
964
1306
|
};
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
1307
|
+
class PassportConfiguration {
|
|
1308
|
+
network;
|
|
1309
|
+
authenticationDomain;
|
|
1310
|
+
passportDomain;
|
|
1311
|
+
magicPublishableApiKey;
|
|
1312
|
+
magicProviderId;
|
|
1313
|
+
imxApiBasePath;
|
|
1314
|
+
oidcConfiguration;
|
|
1315
|
+
baseConfig;
|
|
1316
|
+
constructor({ baseConfig, overrides, ...oidcConfiguration }) {
|
|
1317
|
+
validateConfiguration(oidcConfiguration, [
|
|
1318
|
+
'clientId',
|
|
1319
|
+
'logoutRedirectUri',
|
|
1320
|
+
'redirectUri',
|
|
1321
|
+
]);
|
|
1322
|
+
this.oidcConfiguration = oidcConfiguration;
|
|
1323
|
+
this.baseConfig = baseConfig;
|
|
1324
|
+
if (overrides) {
|
|
1325
|
+
validateConfiguration(overrides, [
|
|
1326
|
+
'network',
|
|
1327
|
+
'authenticationDomain',
|
|
1328
|
+
'magicPublishableApiKey',
|
|
1329
|
+
'magicProviderId',
|
|
1330
|
+
'passportDomain',
|
|
1331
|
+
'imxApiBasePath',
|
|
1332
|
+
], 'overrides');
|
|
1333
|
+
this.network = overrides.network;
|
|
1334
|
+
this.authenticationDomain = overrides.authenticationDomain;
|
|
1335
|
+
this.passportDomain = overrides.passportDomain;
|
|
1336
|
+
this.magicPublishableApiKey = overrides.magicPublishableApiKey;
|
|
1337
|
+
this.magicProviderId = overrides.magicProviderId;
|
|
1338
|
+
this.imxApiBasePath = overrides.imxApiBasePath;
|
|
1339
|
+
}
|
|
1340
|
+
else {
|
|
1341
|
+
switch (baseConfig.environment) {
|
|
1342
|
+
case exports.Environment.SANDBOX: {
|
|
1343
|
+
this.network = Networks.SANDBOX;
|
|
1344
|
+
this.authenticationDomain = 'https://auth.immutable.com';
|
|
1345
|
+
this.magicPublishableApiKey = 'pk_live_10F423798A540ED7';
|
|
1346
|
+
this.magicProviderId = 'fSMzaRQ4O7p4fttl7pCyGVtJS_G70P8SNsLXtPPGHo0=';
|
|
1347
|
+
this.passportDomain = 'https://passport.sandbox.immutable.com';
|
|
1348
|
+
this.imxApiBasePath = 'https://api.sandbox.x.immutable.com';
|
|
1349
|
+
break;
|
|
1350
|
+
}
|
|
1351
|
+
case exports.Environment.PRODUCTION: {
|
|
1352
|
+
this.network = Networks.PRODUCTION;
|
|
1353
|
+
this.authenticationDomain = 'https://auth.immutable.com';
|
|
1354
|
+
this.magicPublishableApiKey = 'pk_live_10F423798A540ED7';
|
|
1355
|
+
this.magicProviderId = 'fSMzaRQ4O7p4fttl7pCyGVtJS_G70P8SNsLXtPPGHo0=';
|
|
1356
|
+
this.passportDomain = 'https://passport.immutable.com';
|
|
1357
|
+
this.imxApiBasePath = 'https://api.x.immutable.com';
|
|
1358
|
+
break;
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
969
1362
|
}
|
|
970
|
-
await connectProvider(provider, chainID);
|
|
971
|
-
// NOTE: if we want to listen to Metamask events in the future, we can add a
|
|
972
|
-
// listener here.
|
|
973
|
-
return new ethers.ethers.providers.Web3Provider(provider);
|
|
974
1363
|
}
|
|
975
1364
|
|
|
976
|
-
const
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
RequestEventType["DISCONNECT_WALLET_REQUEST"] = "DISCONNECT_WALLET_REQUEST";
|
|
983
|
-
})(RequestEventType || (RequestEventType = {}));
|
|
984
|
-
var ResponseEventType;
|
|
985
|
-
(function (ResponseEventType) {
|
|
986
|
-
ResponseEventType["CONNECT_WALLET_RESPONSE"] = "CONNECT_WALLET_RESPONSE";
|
|
987
|
-
ResponseEventType["SIGN_MESSAGE_RESPONSE"] = "SIGN_MESSAGE_RESPONSE";
|
|
988
|
-
ResponseEventType["GET_CONNECTION_RESPONSE"] = "GET_CONNECTION_RESPONSE";
|
|
989
|
-
ResponseEventType["DISCONNECT_WALLET_RESPONSE"] = "DISCONNECT_WALLET_RESPONSE";
|
|
990
|
-
})(ResponseEventType || (ResponseEventType = {}));
|
|
1365
|
+
const getStarkSigner = async (signer) => {
|
|
1366
|
+
return withPassportError(async () => {
|
|
1367
|
+
const privateKey = await coreSdk.generateLegacyStarkPrivateKey(signer);
|
|
1368
|
+
return coreSdk.createStarkSigner(privateKey);
|
|
1369
|
+
}, PassportErrorType.WALLET_CONNECTION_ERROR);
|
|
1370
|
+
};
|
|
991
1371
|
|
|
992
|
-
function
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
1372
|
+
async function registerPassport({ ethSigner, starkSigner, usersApi }, authorization) {
|
|
1373
|
+
return withPassportError(async () => {
|
|
1374
|
+
const userAddress = await ethSigner.getAddress();
|
|
1375
|
+
const starkPublicKey = await starkSigner.getAddress();
|
|
1376
|
+
const signableResult = await usersApi.getSignableRegistrationOffchain({
|
|
1377
|
+
getSignableRegistrationRequest: {
|
|
1378
|
+
ether_key: userAddress,
|
|
1379
|
+
stark_key: starkPublicKey,
|
|
1380
|
+
},
|
|
1381
|
+
});
|
|
1382
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
1383
|
+
const ethSignature = await signRaw(signableMessage, ethSigner);
|
|
1384
|
+
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
1385
|
+
const response = await usersApi.registerPassportUser({
|
|
1386
|
+
authorization: `Bearer ` + authorization,
|
|
1387
|
+
registerPassportUserRequest: {
|
|
1388
|
+
eth_signature: ethSignature,
|
|
1389
|
+
ether_key: userAddress,
|
|
1390
|
+
stark_signature: starkSignature,
|
|
1391
|
+
stark_key: starkPublicKey,
|
|
1392
|
+
},
|
|
1393
|
+
});
|
|
1394
|
+
return response.statusText;
|
|
1395
|
+
}, PassportErrorType.USER_REGISTRATION_ERROR);
|
|
996
1396
|
}
|
|
997
1397
|
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1398
|
+
class Passport {
|
|
1399
|
+
authManager;
|
|
1400
|
+
magicAdapter;
|
|
1401
|
+
config;
|
|
1402
|
+
constructor(passportModuleConfiguration) {
|
|
1403
|
+
const passportConfiguration = new PassportConfiguration(passportModuleConfiguration);
|
|
1404
|
+
this.config = passportConfiguration;
|
|
1405
|
+
this.authManager = new AuthManager(this.config);
|
|
1406
|
+
this.magicAdapter = new MagicAdapter(this.config);
|
|
1001
1407
|
}
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1408
|
+
async getImxProvider(user) {
|
|
1409
|
+
if (!user || !user.idToken) {
|
|
1410
|
+
throw new PassportError('Failed to initialise', PassportErrorType.WALLET_CONNECTION_ERROR);
|
|
1411
|
+
}
|
|
1412
|
+
const provider = await this.magicAdapter.login(user.idToken);
|
|
1413
|
+
const ethSigner = provider.getSigner();
|
|
1414
|
+
const starkSigner = await getStarkSigner(ethSigner);
|
|
1415
|
+
if (!user.etherKey) {
|
|
1416
|
+
const updatedUser = await this.registerUser(ethSigner, starkSigner, user.accessToken);
|
|
1417
|
+
return new PassportImxProvider({
|
|
1418
|
+
user: updatedUser,
|
|
1419
|
+
starkSigner,
|
|
1420
|
+
passportConfig: this.config,
|
|
1421
|
+
});
|
|
1422
|
+
}
|
|
1423
|
+
const userWithEtherKey = user;
|
|
1424
|
+
return new PassportImxProvider({
|
|
1425
|
+
user: userWithEtherKey,
|
|
1426
|
+
starkSigner,
|
|
1427
|
+
passportConfig: this.config,
|
|
1428
|
+
});
|
|
1005
1429
|
}
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
constructor(publicAddress, iframe) {
|
|
1013
|
-
this.publicAddress = publicAddress;
|
|
1014
|
-
this.iframe = iframe;
|
|
1430
|
+
async connectImxSilent() {
|
|
1431
|
+
const user = await this.authManager.loginSilent();
|
|
1432
|
+
if (!user) {
|
|
1433
|
+
return null;
|
|
1434
|
+
}
|
|
1435
|
+
return this.getImxProvider(user);
|
|
1015
1436
|
}
|
|
1016
|
-
|
|
1017
|
-
|
|
1437
|
+
async connectImx() {
|
|
1438
|
+
const user = await this.authManager.login();
|
|
1439
|
+
return this.getImxProvider(user);
|
|
1018
1440
|
}
|
|
1019
|
-
|
|
1020
|
-
return
|
|
1021
|
-
const listener = (event) => {
|
|
1022
|
-
messageResponseListener(this.iframe, event, ResponseEventType.SIGN_MESSAGE_RESPONSE, (messageDetails) => {
|
|
1023
|
-
window.removeEventListener(COMMUNICATION_TYPE, listener);
|
|
1024
|
-
if (!messageDetails.success) {
|
|
1025
|
-
reject(new Error(messageDetails.error?.message));
|
|
1026
|
-
}
|
|
1027
|
-
resolve(messageDetails.data.signedMessage);
|
|
1028
|
-
});
|
|
1029
|
-
};
|
|
1030
|
-
window.addEventListener(COMMUNICATION_TYPE, listener);
|
|
1031
|
-
postRequestMessage(this.iframe, {
|
|
1032
|
-
type: RequestEventType.SIGN_MESSAGE_REQUEST,
|
|
1033
|
-
details: { starkPublicKey: this.publicAddress, message: rawMessage },
|
|
1034
|
-
});
|
|
1035
|
-
});
|
|
1441
|
+
async loginCallback() {
|
|
1442
|
+
return this.authManager.loginCallback();
|
|
1036
1443
|
}
|
|
1037
|
-
|
|
1038
|
-
return this.
|
|
1444
|
+
async logout() {
|
|
1445
|
+
return this.authManager.logout();
|
|
1446
|
+
}
|
|
1447
|
+
async getUserInfo() {
|
|
1448
|
+
const user = await this.authManager.getUser();
|
|
1449
|
+
return user?.profile;
|
|
1450
|
+
}
|
|
1451
|
+
async getIdToken() {
|
|
1452
|
+
const user = await this.authManager.getUser();
|
|
1453
|
+
return user?.idToken;
|
|
1454
|
+
}
|
|
1455
|
+
async getAccessToken() {
|
|
1456
|
+
const user = await this.authManager.getUser();
|
|
1457
|
+
return user?.accessToken;
|
|
1458
|
+
}
|
|
1459
|
+
async registerUser(userAdminKeySigner, starkSigner, jwt) {
|
|
1460
|
+
const configuration = new coreSdk.Configuration({
|
|
1461
|
+
basePath: this.config.imxApiBasePath,
|
|
1462
|
+
});
|
|
1463
|
+
const usersApi = new coreSdk.UsersApi(configuration);
|
|
1464
|
+
await registerPassport({
|
|
1465
|
+
ethSigner: userAdminKeySigner,
|
|
1466
|
+
starkSigner,
|
|
1467
|
+
usersApi,
|
|
1468
|
+
}, jwt);
|
|
1469
|
+
const updatedUser = await this.authManager.requestRefreshTokenAfterRegistration();
|
|
1470
|
+
if (!updatedUser) {
|
|
1471
|
+
throw new PassportError('Failed to get refresh token', PassportErrorType.REFRESH_TOKEN_ERROR);
|
|
1472
|
+
}
|
|
1473
|
+
return updatedUser;
|
|
1039
1474
|
}
|
|
1040
1475
|
}
|
|
1041
1476
|
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
[exports.Environment.DEVELOPMENT]: 'http://localhost:8080',
|
|
1045
|
-
[exports.Environment.SANDBOX]: 'https://wallets.sandbox.immutable.com',
|
|
1046
|
-
[exports.Environment.PRODUCTION]: 'https://wallets.immutable.com',
|
|
1047
|
-
};
|
|
1048
|
-
const IMX_WALLET_IFRAME_STYLE = 'display: none;';
|
|
1049
|
-
function getIFrame() {
|
|
1050
|
-
return document.querySelector(`iframe#${IMX_WALLET_IFRAME_ID}`);
|
|
1051
|
-
}
|
|
1052
|
-
async function setupIFrame(env) {
|
|
1053
|
-
return new Promise((resolve) => {
|
|
1054
|
-
const iframe = document.createElement('iframe');
|
|
1055
|
-
iframe.setAttribute('id', IMX_WALLET_IFRAME_ID);
|
|
1056
|
-
iframe.setAttribute('src', IMX_WALLET_IFRAME_HOSTS[env]);
|
|
1057
|
-
iframe.setAttribute('style', IMX_WALLET_IFRAME_STYLE);
|
|
1058
|
-
document.body.appendChild(iframe);
|
|
1059
|
-
iframe.onload = () => resolve(iframe);
|
|
1060
|
-
});
|
|
1477
|
+
function isChainValid(chainID, config) {
|
|
1478
|
+
return chainID === config.ethConfiguration.chainID;
|
|
1061
1479
|
}
|
|
1062
|
-
async function
|
|
1063
|
-
const
|
|
1064
|
-
if (
|
|
1065
|
-
|
|
1066
|
-
return await setupIFrame(env);
|
|
1480
|
+
async function validateChain(signer, config) {
|
|
1481
|
+
const chainID = await signer.getChainId();
|
|
1482
|
+
if (!isChainValid(chainID, config))
|
|
1483
|
+
throw new Error('The wallet used for this operation is not connected to the correct network.');
|
|
1067
1484
|
}
|
|
1068
1485
|
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
const
|
|
1073
|
-
const
|
|
1074
|
-
const
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
reject(new Error(CONNECTION_FAILED_ERROR));
|
|
1082
|
-
}
|
|
1083
|
-
resolve(new ImxSigner(messageDetails.data.starkPublicKey, iframe));
|
|
1084
|
-
});
|
|
1085
|
-
};
|
|
1086
|
-
window.addEventListener(COMMUNICATION_TYPE, listener);
|
|
1087
|
-
postRequestMessage(iframe, {
|
|
1088
|
-
type: RequestEventType.CONNECT_WALLET_REQUEST,
|
|
1089
|
-
details: { ethAddress: address, signature },
|
|
1090
|
-
});
|
|
1091
|
-
});
|
|
1092
|
-
}
|
|
1093
|
-
async function disconnect(imxSigner) {
|
|
1094
|
-
const iframe = imxSigner.getIFrame();
|
|
1095
|
-
return new Promise((resolve, reject) => {
|
|
1096
|
-
const listener = (event) => {
|
|
1097
|
-
messageResponseListener(iframe, event, ResponseEventType.DISCONNECT_WALLET_RESPONSE, (messageDetails) => {
|
|
1098
|
-
window.removeEventListener(COMMUNICATION_TYPE, listener);
|
|
1099
|
-
if (!messageDetails.success && messageDetails.error) {
|
|
1100
|
-
reject(messageDetails.error);
|
|
1101
|
-
}
|
|
1102
|
-
iframe.remove();
|
|
1103
|
-
resolve();
|
|
1104
|
-
});
|
|
1105
|
-
};
|
|
1106
|
-
window.addEventListener(COMMUNICATION_TYPE, listener);
|
|
1107
|
-
postRequestMessage(iframe, {
|
|
1108
|
-
type: RequestEventType.DISCONNECT_WALLET_REQUEST,
|
|
1109
|
-
details: { starkPublicKey: imxSigner.getAddress() },
|
|
1110
|
-
});
|
|
1486
|
+
async function transfer({ signers: { ethSigner, starkSigner }, request, config, }) {
|
|
1487
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
1488
|
+
const ethAddress = await ethSigner.getAddress();
|
|
1489
|
+
const transfersApi = new coreSdk.TransfersApi(config.immutableXConfig.apiConfiguration);
|
|
1490
|
+
const transferAmount = request.type === 'ERC721' ? '1' : request.amount;
|
|
1491
|
+
const signableResult = await transfersApi.getSignableTransferV1({
|
|
1492
|
+
getSignableTransferRequest: {
|
|
1493
|
+
sender: ethAddress,
|
|
1494
|
+
token: convertToSignableToken(request),
|
|
1495
|
+
amount: transferAmount,
|
|
1496
|
+
receiver: request.receiver,
|
|
1497
|
+
},
|
|
1111
1498
|
});
|
|
1499
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
1500
|
+
const ethSignature = await signRaw(signableMessage, ethSigner);
|
|
1501
|
+
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
1502
|
+
const transferSigningParams = {
|
|
1503
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1504
|
+
sender_stark_key: signableResult.data.sender_stark_key,
|
|
1505
|
+
sender_vault_id: signableResult.data.sender_vault_id,
|
|
1506
|
+
receiver_stark_key: signableResult.data.receiver_stark_key,
|
|
1507
|
+
receiver_vault_id: signableResult.data.receiver_vault_id,
|
|
1508
|
+
asset_id: signableResult.data.asset_id,
|
|
1509
|
+
amount: signableResult.data.amount,
|
|
1510
|
+
nonce: signableResult.data.nonce,
|
|
1511
|
+
expiration_timestamp: signableResult.data.expiration_timestamp,
|
|
1512
|
+
stark_signature: starkSignature,
|
|
1513
|
+
};
|
|
1514
|
+
const response = await transfersApi.createTransferV1({
|
|
1515
|
+
createTransferRequest: transferSigningParams,
|
|
1516
|
+
xImxEthAddress: ethAddress,
|
|
1517
|
+
xImxEthSignature: ethSignature,
|
|
1518
|
+
});
|
|
1519
|
+
return {
|
|
1520
|
+
sent_signature: response?.data.sent_signature,
|
|
1521
|
+
status: response?.data.status?.toString(),
|
|
1522
|
+
time: response?.data.time,
|
|
1523
|
+
transfer_id: response?.data.transfer_id,
|
|
1524
|
+
};
|
|
1112
1525
|
}
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
}
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
static imxSigner;
|
|
1138
|
-
constructor(config, ethSigner, starkExSigner) {
|
|
1139
|
-
super(config, ethSigner, starkExSigner);
|
|
1140
|
-
}
|
|
1141
|
-
static async connect(config) {
|
|
1142
|
-
const starkExConfig = config.getStarkExConfig();
|
|
1143
|
-
return await withProviderError(async () => {
|
|
1144
|
-
const metaMaskProvider = await connect$1({
|
|
1145
|
-
chainID: starkExConfig.ethConfiguration.chainID,
|
|
1146
|
-
});
|
|
1147
|
-
this.imxSigner = await connect(metaMaskProvider, starkExConfig.env);
|
|
1148
|
-
return new MetaMaskIMXProvider(config, metaMaskProvider.getSigner(), this.imxSigner);
|
|
1149
|
-
}, { type: ProviderErrorType.WALLET_CONNECTION_ERROR });
|
|
1150
|
-
}
|
|
1151
|
-
static async disconnect() {
|
|
1152
|
-
if (!this.imxSigner) {
|
|
1153
|
-
throw new ProviderError('Attempted to disconnect from the MetaMask IMX provider without an established connection', ProviderErrorType.PROVIDER_CONNECTION_ERROR);
|
|
1154
|
-
}
|
|
1155
|
-
return withProviderError(async () => {
|
|
1156
|
-
await disconnect(this.imxSigner);
|
|
1157
|
-
}, { type: ProviderErrorType.PROVIDER_CONNECTION_ERROR });
|
|
1526
|
+
async function batchTransfer({ signers: { ethSigner, starkSigner }, request, config, }) {
|
|
1527
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
1528
|
+
const ethAddress = await ethSigner.getAddress();
|
|
1529
|
+
const transfersApi = new coreSdk.TransfersApi(config.immutableXConfig.apiConfiguration);
|
|
1530
|
+
const signableRequests = request.map((nftTransfer) => {
|
|
1531
|
+
return {
|
|
1532
|
+
amount: '1',
|
|
1533
|
+
token: convertToSignableToken({
|
|
1534
|
+
type: 'ERC721',
|
|
1535
|
+
tokenId: nftTransfer.tokenId,
|
|
1536
|
+
tokenAddress: nftTransfer.tokenAddress,
|
|
1537
|
+
}),
|
|
1538
|
+
receiver: nftTransfer.receiver,
|
|
1539
|
+
};
|
|
1540
|
+
});
|
|
1541
|
+
const signableResult = await transfersApi.getSignableTransfer({
|
|
1542
|
+
getSignableTransferRequestV2: {
|
|
1543
|
+
sender_ether_key: ethAddress,
|
|
1544
|
+
signable_requests: signableRequests,
|
|
1545
|
+
},
|
|
1546
|
+
});
|
|
1547
|
+
const signableMessage = signableResult.data.signable_message;
|
|
1548
|
+
if (signableMessage === undefined) {
|
|
1549
|
+
throw new Error('Invalid response from Signable registration offchain');
|
|
1158
1550
|
}
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1551
|
+
const ethSignature = await signRaw(signableMessage, ethSigner);
|
|
1552
|
+
const requests = [];
|
|
1553
|
+
for (const resp of signableResult.data.signable_responses) {
|
|
1554
|
+
const starkSignature = await starkSigner.signMessage(resp.payload_hash);
|
|
1555
|
+
const req = {
|
|
1556
|
+
sender_vault_id: resp.sender_vault_id,
|
|
1557
|
+
receiver_stark_key: resp.receiver_stark_key,
|
|
1558
|
+
receiver_vault_id: resp.receiver_vault_id,
|
|
1559
|
+
asset_id: resp.asset_id,
|
|
1560
|
+
amount: resp.amount,
|
|
1561
|
+
nonce: resp.nonce,
|
|
1562
|
+
expiration_timestamp: resp.expiration_timestamp,
|
|
1563
|
+
stark_signature: starkSignature,
|
|
1564
|
+
};
|
|
1565
|
+
requests.push(req);
|
|
1166
1566
|
}
|
|
1567
|
+
// TODO: throw error on missing payload hash?
|
|
1568
|
+
const transferSigningParams = {
|
|
1569
|
+
sender_stark_key: signableResult.data.sender_stark_key,
|
|
1570
|
+
requests,
|
|
1571
|
+
};
|
|
1572
|
+
const response = await transfersApi.createTransfer({
|
|
1573
|
+
createTransferRequestV2: transferSigningParams,
|
|
1574
|
+
xImxEthAddress: ethAddress,
|
|
1575
|
+
xImxEthSignature: ethSignature,
|
|
1576
|
+
});
|
|
1577
|
+
return {
|
|
1578
|
+
transfer_ids: response?.data.transfer_ids,
|
|
1579
|
+
};
|
|
1167
1580
|
}
|
|
1168
1581
|
|
|
1169
|
-
|
|
1170
|
-
(
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1582
|
+
async function createOrder({ signers, request, config, }) {
|
|
1583
|
+
await validateChain(signers.ethSigner, config.immutableXConfig);
|
|
1584
|
+
const ethAddress = await signers.ethSigner.getAddress();
|
|
1585
|
+
const ordersApi = new coreSdk.OrdersApi(config.immutableXConfig.apiConfiguration);
|
|
1586
|
+
const amountSell = request.sell.type === 'ERC721' ? '1' : request.sell.amount;
|
|
1587
|
+
const amountBuy = request.buy.type === 'ERC721' ? '1' : request.buy.amount;
|
|
1588
|
+
const getSignableOrderRequest = {
|
|
1589
|
+
user: ethAddress,
|
|
1590
|
+
amount_buy: amountBuy,
|
|
1591
|
+
token_buy: convertToSignableToken(request.buy),
|
|
1592
|
+
amount_sell: amountSell,
|
|
1593
|
+
token_sell: convertToSignableToken(request.sell),
|
|
1594
|
+
fees: request.fees,
|
|
1595
|
+
expiration_timestamp: request.expiration_timestamp,
|
|
1596
|
+
};
|
|
1597
|
+
const getSignableOrderResponse = await ordersApi.getSignableOrder({
|
|
1598
|
+
getSignableOrderRequestV3: getSignableOrderRequest,
|
|
1599
|
+
});
|
|
1600
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = getSignableOrderResponse.data;
|
|
1601
|
+
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
1602
|
+
const starkSignature = await signers.starkSigner.signMessage(payloadHash);
|
|
1603
|
+
const resp = getSignableOrderResponse.data;
|
|
1604
|
+
const orderParams = {
|
|
1605
|
+
createOrderRequest: {
|
|
1606
|
+
amount_buy: resp.amount_buy,
|
|
1607
|
+
amount_sell: resp.amount_sell,
|
|
1608
|
+
asset_id_buy: resp.asset_id_buy,
|
|
1609
|
+
asset_id_sell: resp.asset_id_sell,
|
|
1610
|
+
expiration_timestamp: resp.expiration_timestamp,
|
|
1611
|
+
include_fees: true,
|
|
1612
|
+
fees: request.fees,
|
|
1613
|
+
nonce: resp.nonce,
|
|
1614
|
+
stark_key: resp.stark_key,
|
|
1615
|
+
stark_signature: starkSignature,
|
|
1616
|
+
vault_id_buy: resp.vault_id_buy,
|
|
1617
|
+
vault_id_sell: resp.vault_id_sell,
|
|
1618
|
+
},
|
|
1619
|
+
xImxEthAddress: ethAddress,
|
|
1620
|
+
xImxEthSignature: ethSignature,
|
|
1621
|
+
};
|
|
1622
|
+
const createOrderResponse = await ordersApi.createOrder(orderParams);
|
|
1623
|
+
return {
|
|
1624
|
+
...createOrderResponse.data,
|
|
1625
|
+
};
|
|
1626
|
+
}
|
|
1627
|
+
async function cancelOrder({ signers, request, config, }) {
|
|
1628
|
+
const ordersApi = new coreSdk.OrdersApi(config.immutableXConfig.apiConfiguration);
|
|
1629
|
+
const getSignableCancelOrderResponse = await ordersApi.getSignableCancelOrder({
|
|
1630
|
+
getSignableCancelOrderRequest: {
|
|
1631
|
+
order_id: request.order_id,
|
|
1632
|
+
},
|
|
1633
|
+
});
|
|
1634
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = getSignableCancelOrderResponse.data;
|
|
1635
|
+
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
1636
|
+
const starkSignature = await signers.starkSigner.signMessage(payloadHash);
|
|
1637
|
+
const ethAddress = await signers.ethSigner.getAddress();
|
|
1638
|
+
const cancelOrderResponse = await ordersApi.cancelOrder({
|
|
1639
|
+
id: request.order_id.toString(),
|
|
1640
|
+
cancelOrderRequest: {
|
|
1641
|
+
order_id: request.order_id,
|
|
1642
|
+
stark_signature: starkSignature,
|
|
1643
|
+
},
|
|
1644
|
+
xImxEthAddress: ethAddress,
|
|
1645
|
+
xImxEthSignature: ethSignature,
|
|
1646
|
+
});
|
|
1647
|
+
return {
|
|
1648
|
+
order_id: cancelOrderResponse.data.order_id,
|
|
1649
|
+
status: cancelOrderResponse.data.status,
|
|
1650
|
+
};
|
|
1191
1651
|
}
|
|
1192
|
-
const withPassportError = async (fn, customErrorType) => {
|
|
1193
|
-
try {
|
|
1194
|
-
return await fn();
|
|
1195
|
-
}
|
|
1196
|
-
catch (error) {
|
|
1197
|
-
const errorMessage = `${customErrorType}: ${error.message}` || 'UnknownError';
|
|
1198
|
-
throw new PassportError(errorMessage, customErrorType);
|
|
1199
|
-
}
|
|
1200
|
-
};
|
|
1201
1652
|
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
const
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
const
|
|
1208
|
-
|
|
1653
|
+
async function registerOffchain(signers, config) {
|
|
1654
|
+
await validateChain(signers.ethSigner, config.immutableXConfig);
|
|
1655
|
+
const usersApi = new coreSdk.UsersApi(config.immutableXConfig.apiConfiguration);
|
|
1656
|
+
const userAddress = await signers.ethSigner.getAddress();
|
|
1657
|
+
const starkPublicKey = await signers.starkSigner.getAddress();
|
|
1658
|
+
const signableResult = await usersApi.getSignableRegistrationOffchain({
|
|
1659
|
+
getSignableRegistrationRequest: {
|
|
1660
|
+
ether_key: userAddress,
|
|
1661
|
+
stark_key: starkPublicKey,
|
|
1662
|
+
},
|
|
1663
|
+
});
|
|
1664
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
1665
|
+
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
1666
|
+
const starkSignature = await signers.starkSigner.signMessage(payloadHash);
|
|
1667
|
+
const registeredUser = await usersApi.registerUser({
|
|
1668
|
+
registerUserRequest: {
|
|
1669
|
+
eth_signature: ethSignature,
|
|
1670
|
+
ether_key: userAddress,
|
|
1671
|
+
stark_signature: starkSignature,
|
|
1672
|
+
stark_key: starkPublicKey,
|
|
1673
|
+
},
|
|
1674
|
+
});
|
|
1675
|
+
return registeredUser.data;
|
|
1676
|
+
}
|
|
1677
|
+
async function isRegisteredOnChain(starkPublicKey, ethSigner, config) {
|
|
1678
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
1679
|
+
const registrationContract = coreSdk.Contracts.Registration.connect(config.immutableXConfig.ethConfiguration.registrationContractAddress, ethSigner);
|
|
1209
1680
|
try {
|
|
1210
|
-
return await
|
|
1681
|
+
return await registrationContract.isRegistered(starkPublicKey);
|
|
1211
1682
|
}
|
|
1212
|
-
catch (
|
|
1213
|
-
if (
|
|
1214
|
-
return
|
|
1683
|
+
catch (ex) {
|
|
1684
|
+
if (ex.reason === 'USER_UNREGISTERED') {
|
|
1685
|
+
return false;
|
|
1215
1686
|
}
|
|
1216
|
-
|
|
1217
|
-
return retryWithDelay(fn, { retries: retries - 1, finalErr });
|
|
1687
|
+
throw ex;
|
|
1218
1688
|
}
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
const
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
popup_redirect_uri: oidcConfiguration.redirectUri,
|
|
1226
|
-
client_id: oidcConfiguration.clientId,
|
|
1227
|
-
metadata: {
|
|
1228
|
-
authorization_endpoint: `${oidcConfiguration.authenticationDomain}/authorize`,
|
|
1229
|
-
token_endpoint: `${oidcConfiguration.authenticationDomain}/oauth/token`,
|
|
1230
|
-
userinfo_endpoint: `${oidcConfiguration.authenticationDomain}/userinfo`,
|
|
1231
|
-
end_session_endpoint: `${oidcConfiguration.authenticationDomain}/v2/logout` +
|
|
1232
|
-
`?returnTo=${encodeURIComponent(oidcConfiguration.logoutRedirectUri)}` +
|
|
1233
|
-
`&client_id=${oidcConfiguration.clientId}`,
|
|
1689
|
+
}
|
|
1690
|
+
async function getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi) {
|
|
1691
|
+
const response = await usersApi.getSignableRegistration({
|
|
1692
|
+
getSignableRegistrationRequest: {
|
|
1693
|
+
ether_key: etherKey,
|
|
1694
|
+
stark_key: starkPublicKey,
|
|
1234
1695
|
},
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1696
|
+
});
|
|
1697
|
+
return {
|
|
1698
|
+
operator_signature: response.data.operator_signature,
|
|
1699
|
+
payload_hash: response.data.payload_hash,
|
|
1238
1700
|
};
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
const assertIsDefined = (value) => {
|
|
1704
|
+
if (value !== undefined)
|
|
1705
|
+
return value;
|
|
1706
|
+
throw new Error('undefined field exception');
|
|
1245
1707
|
};
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
config;
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1708
|
+
async function prepareWithdrawalAction(params) {
|
|
1709
|
+
const { signers: { ethSigner, starkSigner }, type, config, } = params;
|
|
1710
|
+
await validateChain(ethSigner, params.config);
|
|
1711
|
+
const withdrawalsApi = new coreSdk.WithdrawalsApi(config.apiConfiguration);
|
|
1712
|
+
const withdrawalAmount = type === 'ERC721' ? '1' : params.amount;
|
|
1713
|
+
const signableWithdrawalResult = await withdrawalsApi.getSignableWithdrawal({
|
|
1714
|
+
getSignableWithdrawalRequest: {
|
|
1715
|
+
user: await ethSigner.getAddress(),
|
|
1716
|
+
token: convertToSignableToken(params),
|
|
1717
|
+
amount: withdrawalAmount,
|
|
1718
|
+
},
|
|
1719
|
+
});
|
|
1720
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = signableWithdrawalResult.data;
|
|
1721
|
+
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
1722
|
+
const { ethAddress, ethSignature } = await signMessage(signableMessage, ethSigner);
|
|
1723
|
+
const prepareWithdrawalResponse = await withdrawalsApi.createWithdrawal({
|
|
1724
|
+
createWithdrawalRequest: {
|
|
1725
|
+
stark_key: assertIsDefined(signableWithdrawalResult.data.stark_key),
|
|
1726
|
+
amount: withdrawalAmount,
|
|
1727
|
+
asset_id: assertIsDefined(signableWithdrawalResult.data.asset_id),
|
|
1728
|
+
vault_id: assertIsDefined(signableWithdrawalResult.data.vault_id),
|
|
1729
|
+
nonce: assertIsDefined(signableWithdrawalResult.data.nonce),
|
|
1730
|
+
stark_signature: starkSignature,
|
|
1731
|
+
},
|
|
1732
|
+
xImxEthAddress: ethAddress,
|
|
1733
|
+
xImxEthSignature: ethSignature,
|
|
1734
|
+
});
|
|
1735
|
+
return prepareWithdrawalResponse.data;
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1738
|
+
async function getEncodeAssetInfo(assetType, tokenType, config, tokenData) {
|
|
1739
|
+
const encodingApi = new coreSdk.EncodingApi(config.apiConfiguration);
|
|
1740
|
+
const result = await encodingApi.encodeAsset({
|
|
1741
|
+
assetType,
|
|
1742
|
+
encodeAssetRequest: {
|
|
1743
|
+
token: {
|
|
1744
|
+
type: tokenType,
|
|
1745
|
+
...(tokenData && { data: tokenData }),
|
|
1263
1746
|
},
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1747
|
+
},
|
|
1748
|
+
});
|
|
1749
|
+
return result.data;
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
async function executeRegisterAndWithdrawERC20({ ethSigner, assetType, starkPublicKey, config, }) {
|
|
1753
|
+
const etherKey = await ethSigner.getAddress();
|
|
1754
|
+
const imxConfig = config.immutableXConfig;
|
|
1755
|
+
const usersApi = new coreSdk.UsersApi(imxConfig.apiConfiguration);
|
|
1756
|
+
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
1757
|
+
const contract = coreSdk.Contracts.Registration.connect(config.immutableXConfig.ethConfiguration.registrationContractAddress, ethSigner);
|
|
1758
|
+
const populatedTransaction = await contract.populateTransaction.registerAndWithdraw(etherKey, starkPublicKey, signableResult.operator_signature, assetType);
|
|
1759
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
1760
|
+
}
|
|
1761
|
+
async function executeWithdrawERC20(ethSigner, assetType, starkPublicKey, config) {
|
|
1762
|
+
const contract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
1763
|
+
const populatedTransaction = await contract.populateTransaction.withdraw(starkPublicKey, assetType);
|
|
1764
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
1765
|
+
}
|
|
1766
|
+
async function completeERC20WithdrawalAction({ ethSigner, starkPublicKey, token, config, }) {
|
|
1767
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
1768
|
+
const imxConfig = config.immutableXConfig;
|
|
1769
|
+
const assetType = await getEncodeAssetInfo('asset', 'ERC20', imxConfig, {
|
|
1770
|
+
token_address: token.tokenAddress,
|
|
1771
|
+
});
|
|
1772
|
+
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
1773
|
+
if (!isRegistered) {
|
|
1774
|
+
return executeRegisterAndWithdrawERC20({
|
|
1775
|
+
ethSigner,
|
|
1776
|
+
assetType: assetType.asset_type,
|
|
1777
|
+
starkPublicKey,
|
|
1778
|
+
config,
|
|
1779
|
+
});
|
|
1272
1780
|
}
|
|
1273
|
-
|
|
1274
|
-
return
|
|
1781
|
+
else {
|
|
1782
|
+
return executeWithdrawERC20(ethSigner, assetType.asset_type, starkPublicKey, imxConfig);
|
|
1275
1783
|
}
|
|
1276
|
-
|
|
1277
|
-
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
async function executeWithdrawMintableERC721(ethSigner, assetType, starkPublicKey, mintingBlob, config) {
|
|
1787
|
+
const contract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
1788
|
+
const populatedTransaction = await contract.populateTransaction.withdrawAndMint(starkPublicKey, assetType, mintingBlob);
|
|
1789
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
1790
|
+
}
|
|
1791
|
+
async function executeRegisterAndWithdrawMintableERC721(ethSigner, assetType, starkPublicKey, mintingBlob, config) {
|
|
1792
|
+
const etherKey = await ethSigner.getAddress();
|
|
1793
|
+
const usersApi = new coreSdk.UsersApi(config.apiConfiguration);
|
|
1794
|
+
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
1795
|
+
const contract = coreSdk.Contracts.Registration.connect(config.ethConfiguration.registrationContractAddress, ethSigner);
|
|
1796
|
+
const populatedTransaction = await contract.populateTransaction.regsiterAndWithdrawAndMint(etherKey, starkPublicKey, signableResult.operator_signature, assetType, mintingBlob);
|
|
1797
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
1798
|
+
}
|
|
1799
|
+
function getMintingBlob(token) {
|
|
1800
|
+
const id = token.data.id;
|
|
1801
|
+
const blueprint = token.data.blueprint || '';
|
|
1802
|
+
return encUtils__namespace.sanitizeHex(encUtils__namespace.utf8ToHex(`{${id}}:{${blueprint}}`));
|
|
1803
|
+
}
|
|
1804
|
+
async function completeMintableERC721Withdrawal(ethSigner, starkPublicKey, token, config) {
|
|
1805
|
+
const imxConfig = config.immutableXConfig;
|
|
1806
|
+
const assetType = await getEncodeAssetInfo('mintable-asset', 'ERC721', imxConfig, {
|
|
1807
|
+
id: token.data.id,
|
|
1808
|
+
token_address: token.data.tokenAddress,
|
|
1809
|
+
...(token.data.blueprint && { blueprint: token.data.blueprint }),
|
|
1810
|
+
});
|
|
1811
|
+
const mintingBlob = getMintingBlob(token);
|
|
1812
|
+
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
1813
|
+
if (!isRegistered) {
|
|
1814
|
+
return executeRegisterAndWithdrawMintableERC721(ethSigner, assetType.asset_type, starkPublicKey, mintingBlob, imxConfig);
|
|
1278
1815
|
}
|
|
1279
|
-
|
|
1280
|
-
return
|
|
1281
|
-
const oidcUser = await this.userManager.getUser();
|
|
1282
|
-
if (!oidcUser) {
|
|
1283
|
-
throw new Error('Failed to retrieve user');
|
|
1284
|
-
}
|
|
1285
|
-
return this.mapOidcUserToDomainModel(oidcUser);
|
|
1286
|
-
}, PassportErrorType.NOT_LOGGED_IN_ERROR);
|
|
1816
|
+
else {
|
|
1817
|
+
return executeWithdrawMintableERC721(ethSigner, assetType.asset_type, starkPublicKey, mintingBlob, imxConfig);
|
|
1287
1818
|
}
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1819
|
+
}
|
|
1820
|
+
async function executeRegisterAndWithdrawERC721(ethSigner, assetType, starkPublicKey, tokenId, config) {
|
|
1821
|
+
const etherKey = await ethSigner.getAddress();
|
|
1822
|
+
const usersApi = new coreSdk.UsersApi(config.apiConfiguration);
|
|
1823
|
+
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
1824
|
+
const contract = coreSdk.Contracts.Registration.connect(config.ethConfiguration.registrationContractAddress, ethSigner);
|
|
1825
|
+
const populatedTransaction = await contract.populateTransaction.registerAndWithdrawNft(etherKey, starkPublicKey, signableResult.operator_signature, assetType, tokenId);
|
|
1826
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
1827
|
+
}
|
|
1828
|
+
async function executeWithdrawERC721(ethSigner, assetType, starkPublicKey, tokenId, config) {
|
|
1829
|
+
const contract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
1830
|
+
const populatedTransaction = await contract.populateTransaction.withdrawNft(starkPublicKey, assetType, tokenId);
|
|
1831
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
1832
|
+
}
|
|
1833
|
+
async function completeERC721Withdrawal(ethSigner, starkPublicKey, token, config) {
|
|
1834
|
+
const imxConfig = config.immutableXConfig;
|
|
1835
|
+
const assetType = await getEncodeAssetInfo('asset', 'ERC721', imxConfig, {
|
|
1836
|
+
token_id: token.tokenId,
|
|
1837
|
+
token_address: token.tokenAddress,
|
|
1838
|
+
});
|
|
1839
|
+
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
1840
|
+
if (!isRegistered) {
|
|
1841
|
+
return executeRegisterAndWithdrawERC721(ethSigner, assetType.asset_type, starkPublicKey, token.tokenId, imxConfig);
|
|
1842
|
+
}
|
|
1843
|
+
else {
|
|
1844
|
+
return executeWithdrawERC721(ethSigner, assetType.asset_type, starkPublicKey, token.tokenId, imxConfig);
|
|
1306
1845
|
}
|
|
1307
1846
|
}
|
|
1847
|
+
async function completeERC721WithdrawalAction({ ethSigner, starkPublicKey, token, config, }) {
|
|
1848
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
1849
|
+
const tokenAddress = token.tokenAddress;
|
|
1850
|
+
const tokenId = token.tokenId;
|
|
1851
|
+
const imxConfig = config.immutableXConfig;
|
|
1852
|
+
const mintsApi = new coreSdk.MintsApi(imxConfig.apiConfiguration);
|
|
1853
|
+
return await mintsApi
|
|
1854
|
+
.getMintableTokenDetailsByClientTokenId({
|
|
1855
|
+
tokenAddress,
|
|
1856
|
+
tokenId,
|
|
1857
|
+
})
|
|
1858
|
+
.then((mintableToken) => completeMintableERC721Withdrawal(ethSigner, starkPublicKey, {
|
|
1859
|
+
type: 'ERC721',
|
|
1860
|
+
data: {
|
|
1861
|
+
id: tokenId,
|
|
1862
|
+
tokenAddress: tokenAddress,
|
|
1863
|
+
blueprint: mintableToken.data.blueprint,
|
|
1864
|
+
},
|
|
1865
|
+
}, config))
|
|
1866
|
+
.catch((error) => {
|
|
1867
|
+
if (error.response?.status === 404) {
|
|
1868
|
+
// token is already minted on L1
|
|
1869
|
+
return completeERC721Withdrawal(ethSigner, starkPublicKey, token, config);
|
|
1870
|
+
}
|
|
1871
|
+
throw error; // unable to recover from any other kind of error
|
|
1872
|
+
});
|
|
1873
|
+
}
|
|
1308
1874
|
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
config;
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1875
|
+
async function executeRegisterAndWithdrawEth(ethSigner, assetType, starkPublicKey, config) {
|
|
1876
|
+
const etherKey = await ethSigner.getAddress();
|
|
1877
|
+
const usersApi = new coreSdk.UsersApi(config.apiConfiguration);
|
|
1878
|
+
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
1879
|
+
const contract = coreSdk.Contracts.Registration.connect(config.ethConfiguration.registrationContractAddress, ethSigner);
|
|
1880
|
+
const populatedTransaction = await contract.populateTransaction.registerAndWithdraw(etherKey, starkPublicKey, signableResult.operator_signature, assetType);
|
|
1881
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
1882
|
+
}
|
|
1883
|
+
async function executeWithdrawEth(ethSigner, assetType, starkPublicKey, config) {
|
|
1884
|
+
const contract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
1885
|
+
const populatedTransaction = await contract.populateTransaction.withdraw(starkPublicKey, assetType);
|
|
1886
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
1887
|
+
}
|
|
1888
|
+
async function completeEthWithdrawalAction({ ethSigner, starkPublicKey, config, }) {
|
|
1889
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
1890
|
+
const imxConfig = config.immutableXConfig;
|
|
1891
|
+
const assetType = await getEncodeAssetInfo('asset', 'ETH', imxConfig);
|
|
1892
|
+
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
1893
|
+
if (!isRegistered) {
|
|
1894
|
+
return executeRegisterAndWithdrawEth(ethSigner, assetType.asset_type, starkPublicKey, imxConfig);
|
|
1318
1895
|
}
|
|
1319
|
-
|
|
1320
|
-
return
|
|
1321
|
-
await this.magicClient.openid.loginWithOIDC({
|
|
1322
|
-
jwt: idToken,
|
|
1323
|
-
providerId: this.config.magicProviderId,
|
|
1324
|
-
});
|
|
1325
|
-
return new ethers.ethers.providers.Web3Provider(this.magicClient
|
|
1326
|
-
.rpcProvider);
|
|
1327
|
-
}, PassportErrorType.WALLET_CONNECTION_ERROR);
|
|
1896
|
+
else {
|
|
1897
|
+
return executeWithdrawEth(ethSigner, assetType.asset_type, starkPublicKey, imxConfig);
|
|
1328
1898
|
}
|
|
1329
1899
|
}
|
|
1330
1900
|
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
})
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
})
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
? window.innerWidth
|
|
1357
|
-
: document.documentElement.clientWidth
|
|
1358
|
-
? document.documentElement.clientWidth
|
|
1359
|
-
: screen.width;
|
|
1360
|
-
const windowHeight = window.innerHeight
|
|
1361
|
-
? window.innerHeight
|
|
1362
|
-
: document.documentElement.clientHeight
|
|
1363
|
-
? document.documentElement.clientHeight
|
|
1364
|
-
: screen.height;
|
|
1365
|
-
const systemZoom = windowWidth / window.screen.availWidth;
|
|
1366
|
-
const left = (windowWidth - width) / 2 / systemZoom + dualScreenLeft;
|
|
1367
|
-
const top = (windowHeight - height) / 2 / systemZoom + dualScreenTop;
|
|
1368
|
-
const newWindow = window.open(url, title, `
|
|
1369
|
-
scrollbars=yes,
|
|
1370
|
-
width=${width / systemZoom},
|
|
1371
|
-
height=${height / systemZoom},
|
|
1372
|
-
top=${top},
|
|
1373
|
-
left=${left}
|
|
1374
|
-
`);
|
|
1375
|
-
if (!newWindow) {
|
|
1376
|
-
throw new Error('Failed to open confirmation screen');
|
|
1901
|
+
async function prepareWithdrawal({ signers, withdrawal, config, }) {
|
|
1902
|
+
return prepareWithdrawalAction({
|
|
1903
|
+
signers,
|
|
1904
|
+
config: config.immutableXConfig,
|
|
1905
|
+
...withdrawal,
|
|
1906
|
+
});
|
|
1907
|
+
}
|
|
1908
|
+
async function completeWithdrawal({ signers: { ethSigner }, starkPublicKey, token, config, }) {
|
|
1909
|
+
switch (token.type) {
|
|
1910
|
+
case 'ETH':
|
|
1911
|
+
return completeEthWithdrawalAction({ ethSigner, starkPublicKey, config });
|
|
1912
|
+
case 'ERC20':
|
|
1913
|
+
return completeERC20WithdrawalAction({
|
|
1914
|
+
ethSigner,
|
|
1915
|
+
starkPublicKey,
|
|
1916
|
+
token,
|
|
1917
|
+
config,
|
|
1918
|
+
});
|
|
1919
|
+
case 'ERC721':
|
|
1920
|
+
return completeERC721WithdrawalAction({
|
|
1921
|
+
ethSigner,
|
|
1922
|
+
starkPublicKey,
|
|
1923
|
+
token,
|
|
1924
|
+
config,
|
|
1925
|
+
});
|
|
1377
1926
|
}
|
|
1378
|
-
|
|
1379
|
-
return newWindow;
|
|
1380
|
-
};
|
|
1927
|
+
}
|
|
1381
1928
|
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
const
|
|
1385
|
-
const
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1929
|
+
async function createTrade({ signers: { ethSigner, starkSigner }, request, config, }) {
|
|
1930
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
1931
|
+
const ethAddress = await ethSigner.getAddress();
|
|
1932
|
+
const tradesApi = new coreSdk.TradesApi(config.immutableXConfig.apiConfiguration);
|
|
1933
|
+
const signableResult = await tradesApi.getSignableTrade({
|
|
1934
|
+
getSignableTradeRequest: {
|
|
1935
|
+
user: ethAddress,
|
|
1936
|
+
order_id: request.order_id,
|
|
1937
|
+
fees: request.fees,
|
|
1938
|
+
},
|
|
1939
|
+
});
|
|
1940
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
1941
|
+
const ethSignature = await signRaw(signableMessage, ethSigner);
|
|
1942
|
+
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
1943
|
+
const createTradeResponse = await tradesApi.createTrade({
|
|
1944
|
+
createTradeRequest: {
|
|
1945
|
+
amount_buy: signableResult.data.amount_buy,
|
|
1946
|
+
amount_sell: signableResult.data.amount_sell,
|
|
1947
|
+
asset_id_buy: signableResult.data.asset_id_buy,
|
|
1948
|
+
asset_id_sell: signableResult.data.asset_id_sell,
|
|
1949
|
+
expiration_timestamp: signableResult.data.expiration_timestamp,
|
|
1950
|
+
fee_info: signableResult.data.fee_info,
|
|
1951
|
+
fees: request.fees,
|
|
1952
|
+
include_fees: true,
|
|
1953
|
+
nonce: signableResult.data.nonce,
|
|
1954
|
+
order_id: request.order_id,
|
|
1955
|
+
stark_key: signableResult.data.stark_key,
|
|
1956
|
+
vault_id_buy: signableResult.data.vault_id_buy,
|
|
1957
|
+
vault_id_sell: signableResult.data.vault_id_sell,
|
|
1958
|
+
stark_signature: starkSignature,
|
|
1959
|
+
},
|
|
1960
|
+
xImxEthAddress: ethAddress,
|
|
1961
|
+
xImxEthSignature: ethSignature,
|
|
1962
|
+
});
|
|
1963
|
+
return createTradeResponse.data;
|
|
1964
|
+
}
|
|
1965
|
+
|
|
1966
|
+
async function depositEth({ signers: { ethSigner }, deposit, config, }) {
|
|
1967
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
1968
|
+
const user = await ethSigner.getAddress();
|
|
1969
|
+
const data = {
|
|
1970
|
+
decimals: 18,
|
|
1971
|
+
};
|
|
1972
|
+
const amount = units.parseUnits(deposit.amount, 'wei');
|
|
1973
|
+
const imxConfig = config.immutableXConfig;
|
|
1974
|
+
const depositsApi = new coreSdk.DepositsApi(imxConfig.apiConfiguration);
|
|
1975
|
+
const encodingApi = new coreSdk.EncodingApi(imxConfig.apiConfiguration);
|
|
1976
|
+
const usersApi = new coreSdk.UsersApi(imxConfig.apiConfiguration);
|
|
1977
|
+
const getSignableDepositRequest = {
|
|
1978
|
+
user,
|
|
1979
|
+
token: {
|
|
1980
|
+
type: deposit.type,
|
|
1981
|
+
data,
|
|
1982
|
+
},
|
|
1983
|
+
amount: amount.toString(),
|
|
1984
|
+
};
|
|
1985
|
+
const signableDepositResult = await depositsApi.getSignableDeposit({
|
|
1986
|
+
getSignableDepositRequest,
|
|
1987
|
+
});
|
|
1988
|
+
const encodingResult = await encodingApi.encodeAsset({
|
|
1989
|
+
assetType: 'asset',
|
|
1990
|
+
encodeAssetRequest: {
|
|
1991
|
+
token: {
|
|
1992
|
+
type: deposit.type,
|
|
1993
|
+
},
|
|
1994
|
+
},
|
|
1995
|
+
});
|
|
1996
|
+
const assetType = encodingResult.data.asset_type;
|
|
1997
|
+
const starkPublicKey = signableDepositResult.data.stark_key;
|
|
1998
|
+
const vaultId = signableDepositResult.data.vault_id;
|
|
1999
|
+
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
2000
|
+
if (!isRegistered) {
|
|
2001
|
+
return executeRegisterAndDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, imxConfig, usersApi);
|
|
1397
2002
|
}
|
|
1398
|
-
|
|
1399
|
-
return
|
|
1400
|
-
const messageHandler = ({ data, origin }) => {
|
|
1401
|
-
if (origin != this.config.passportDomain ||
|
|
1402
|
-
data.eventType != PassportEventType) {
|
|
1403
|
-
return;
|
|
1404
|
-
}
|
|
1405
|
-
switch (data.messageType) {
|
|
1406
|
-
case ReceiveMessage.CONFIRMATION_WINDOW_READY: {
|
|
1407
|
-
this.postMessage(confirmationWindow, accessToken, {
|
|
1408
|
-
messageType: SendMessage.TRANSACTION_START,
|
|
1409
|
-
messageData: transaction,
|
|
1410
|
-
});
|
|
1411
|
-
break;
|
|
1412
|
-
}
|
|
1413
|
-
case ReceiveMessage.TRANSACTION_CONFIRMED: {
|
|
1414
|
-
resolve({ confirmed: true });
|
|
1415
|
-
break;
|
|
1416
|
-
}
|
|
1417
|
-
case ReceiveMessage.TRANSACTION_ERROR: {
|
|
1418
|
-
reject(new Error('Transaction error'));
|
|
1419
|
-
break;
|
|
1420
|
-
}
|
|
1421
|
-
default:
|
|
1422
|
-
reject(new Error('Unsupported message type'));
|
|
1423
|
-
}
|
|
1424
|
-
};
|
|
1425
|
-
window.addEventListener('message', messageHandler);
|
|
1426
|
-
const confirmationWindow = openPopupCenter({
|
|
1427
|
-
url: `${this.config.passportDomain}/transaction-confirmation`,
|
|
1428
|
-
title: ConfirmationWindowTitle,
|
|
1429
|
-
width: ConfirmationWindowWidth,
|
|
1430
|
-
height: ConfirmationWindowHeight,
|
|
1431
|
-
});
|
|
1432
|
-
// https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
|
|
1433
|
-
const timer = setInterval(function () {
|
|
1434
|
-
if (confirmationWindow.closed) {
|
|
1435
|
-
clearInterval(timer);
|
|
1436
|
-
window.removeEventListener('message', messageHandler);
|
|
1437
|
-
resolve({ confirmed: false });
|
|
1438
|
-
}
|
|
1439
|
-
}, ConfirmationWindowClosedPollingDuration);
|
|
1440
|
-
});
|
|
2003
|
+
else {
|
|
2004
|
+
return executeDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, imxConfig);
|
|
1441
2005
|
}
|
|
1442
2006
|
}
|
|
2007
|
+
async function executeRegisterAndDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, config, usersApi) {
|
|
2008
|
+
const etherKey = await ethSigner.getAddress();
|
|
2009
|
+
const coreContract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
2010
|
+
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
2011
|
+
const populatedTransaction = await coreContract.populateTransaction.registerAndDepositEth(etherKey, starkPublicKey, signableResult.operator_signature, assetType, vaultId);
|
|
2012
|
+
return ethSigner.sendTransaction({ ...populatedTransaction, value: amount });
|
|
2013
|
+
}
|
|
2014
|
+
async function executeDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, config) {
|
|
2015
|
+
const coreContract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
2016
|
+
const populatedTransaction = await coreContract.populateTransaction['deposit(uint256,uint256,uint256)'](starkPublicKey, assetType, vaultId);
|
|
2017
|
+
return ethSigner.sendTransaction({ ...populatedTransaction, value: amount });
|
|
2018
|
+
}
|
|
1443
2019
|
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
}
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
}
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
sender_ether_key: ethAddress,
|
|
1511
|
-
signable_requests: signableRequests,
|
|
1512
|
-
};
|
|
1513
|
-
const signableResult = await transfersApi.getSignableTransfer({
|
|
1514
|
-
getSignableTransferRequestV2,
|
|
1515
|
-
});
|
|
1516
|
-
const confirmationScreen = new ConfirmationScreen(passportConfig);
|
|
1517
|
-
const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
|
|
1518
|
-
transactionType: TransactionTypes.CreateBatchTransfer,
|
|
1519
|
-
transactionData: getSignableTransferRequestV2,
|
|
1520
|
-
});
|
|
1521
|
-
if (!confirmationResult.confirmed) {
|
|
1522
|
-
throw new Error('Transaction rejected by user');
|
|
1523
|
-
}
|
|
1524
|
-
const requests = await Promise.all(signableResult.data.signable_responses.map(async (resp) => {
|
|
1525
|
-
const starkSignature = await starkSigner.signMessage(resp.payload_hash);
|
|
1526
|
-
return {
|
|
1527
|
-
sender_vault_id: resp.sender_vault_id,
|
|
1528
|
-
receiver_stark_key: resp.receiver_stark_key,
|
|
1529
|
-
receiver_vault_id: resp.receiver_vault_id,
|
|
1530
|
-
asset_id: resp.asset_id,
|
|
1531
|
-
amount: resp.amount,
|
|
1532
|
-
nonce: resp.nonce,
|
|
1533
|
-
expiration_timestamp: resp.expiration_timestamp,
|
|
1534
|
-
stark_signature: starkSignature,
|
|
1535
|
-
};
|
|
1536
|
-
}));
|
|
1537
|
-
const transferSigningParams = {
|
|
1538
|
-
sender_stark_key: signableResult.data.sender_stark_key,
|
|
1539
|
-
requests,
|
|
1540
|
-
};
|
|
1541
|
-
const headers = {
|
|
1542
|
-
Authorization: 'Bearer ' + user.accessToken,
|
|
1543
|
-
};
|
|
1544
|
-
const response = await transfersApi.createTransfer({
|
|
1545
|
-
createTransferRequestV2: transferSigningParams,
|
|
1546
|
-
}, { headers });
|
|
1547
|
-
return {
|
|
1548
|
-
transfer_ids: response?.data.transfer_ids,
|
|
1549
|
-
};
|
|
1550
|
-
}, PassportErrorType.TRANSFER_ERROR);
|
|
2020
|
+
async function depositERC20({ signers: { ethSigner }, deposit, config, }) {
|
|
2021
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
2022
|
+
const { apiConfiguration, ethConfiguration } = config.immutableXConfig;
|
|
2023
|
+
const user = await ethSigner.getAddress();
|
|
2024
|
+
const tokensApi = new coreSdk.TokensApi(apiConfiguration);
|
|
2025
|
+
const depositsApi = new coreSdk.DepositsApi(apiConfiguration);
|
|
2026
|
+
const encodingApi = new coreSdk.EncodingApi(apiConfiguration);
|
|
2027
|
+
const usersApi = new coreSdk.UsersApi(apiConfiguration);
|
|
2028
|
+
// Get decimals for this specific ERC20
|
|
2029
|
+
const token = await tokensApi.getToken({ address: deposit.tokenAddress });
|
|
2030
|
+
const decimals = parseInt(token.data.decimals);
|
|
2031
|
+
const data = {
|
|
2032
|
+
decimals,
|
|
2033
|
+
token_address: deposit.tokenAddress,
|
|
2034
|
+
};
|
|
2035
|
+
const amount = units.parseUnits(deposit.amount, 0); // 0 to always use undecimalized value
|
|
2036
|
+
// Approve whether an amount of token from an account can be spent by a third-party account
|
|
2037
|
+
const tokenContract = coreSdk.Contracts.IERC20.connect(deposit.tokenAddress, ethSigner);
|
|
2038
|
+
const approveTransaction = await tokenContract.populateTransaction.approve(ethConfiguration.coreContractAddress, amount);
|
|
2039
|
+
await ethSigner.sendTransaction(approveTransaction);
|
|
2040
|
+
const getSignableDepositRequest = {
|
|
2041
|
+
user,
|
|
2042
|
+
token: {
|
|
2043
|
+
type: deposit.type,
|
|
2044
|
+
data,
|
|
2045
|
+
},
|
|
2046
|
+
amount: amount.toString(),
|
|
2047
|
+
};
|
|
2048
|
+
const signableDepositResult = await depositsApi.getSignableDeposit({
|
|
2049
|
+
getSignableDepositRequest,
|
|
2050
|
+
});
|
|
2051
|
+
// Perform encoding on asset details to get an assetType (required for stark contract request)
|
|
2052
|
+
const encodingResult = await encodingApi.encodeAsset({
|
|
2053
|
+
assetType: 'asset',
|
|
2054
|
+
encodeAssetRequest: {
|
|
2055
|
+
token: {
|
|
2056
|
+
type: deposit.type,
|
|
2057
|
+
data: {
|
|
2058
|
+
token_address: deposit.tokenAddress,
|
|
2059
|
+
},
|
|
2060
|
+
},
|
|
2061
|
+
},
|
|
2062
|
+
});
|
|
2063
|
+
const assetType = encodingResult.data.asset_type;
|
|
2064
|
+
const starkPublicKey = signableDepositResult.data.stark_key;
|
|
2065
|
+
const vaultId = signableDepositResult.data.vault_id;
|
|
2066
|
+
const quantizedAmount = bignumber.BigNumber.from(signableDepositResult.data.amount);
|
|
2067
|
+
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
2068
|
+
if (!isRegistered) {
|
|
2069
|
+
return executeRegisterAndDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, ethConfiguration, usersApi);
|
|
2070
|
+
}
|
|
2071
|
+
else {
|
|
2072
|
+
return executeDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, ethConfiguration);
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
async function executeDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, config) {
|
|
2076
|
+
const coreContract = coreSdk.Contracts.Core.connect(config.coreContractAddress, ethSigner);
|
|
2077
|
+
const populatedTransaction = await coreContract.populateTransaction.depositERC20(starkPublicKey, assetType, vaultId, quantizedAmount);
|
|
2078
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
2079
|
+
}
|
|
2080
|
+
async function executeRegisterAndDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, config, usersApi) {
|
|
2081
|
+
const etherKey = await ethSigner.getAddress();
|
|
2082
|
+
const coreContract = coreSdk.Contracts.Core.connect(config.coreContractAddress, ethSigner);
|
|
2083
|
+
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
2084
|
+
const populatedTransaction = await coreContract.populateTransaction.registerAndDepositERC20(etherKey, starkPublicKey, signableResult.operator_signature, assetType, vaultId, quantizedAmount);
|
|
2085
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
1551
2086
|
}
|
|
1552
2087
|
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
}
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
stark_signature: starkSignature,
|
|
1587
|
-
amount_buy: signableResultData.amount_buy,
|
|
1588
|
-
amount_sell: signableResultData.amount_sell,
|
|
1589
|
-
asset_id_buy: signableResultData.asset_id_buy,
|
|
1590
|
-
asset_id_sell: signableResultData.asset_id_sell,
|
|
1591
|
-
expiration_timestamp: signableResultData.expiration_timestamp,
|
|
1592
|
-
nonce: signableResultData.nonce,
|
|
1593
|
-
stark_key: signableResultData.stark_key,
|
|
1594
|
-
vault_id_buy: signableResultData.vault_id_buy,
|
|
1595
|
-
vault_id_sell: signableResultData.vault_id_sell,
|
|
2088
|
+
async function depositERC721({ signers: { ethSigner }, deposit, config, }) {
|
|
2089
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
2090
|
+
const user = await ethSigner.getAddress();
|
|
2091
|
+
const { immutableXConfig } = config;
|
|
2092
|
+
const depositsApi = new coreSdk.DepositsApi(immutableXConfig.apiConfiguration);
|
|
2093
|
+
const encodingApi = new coreSdk.EncodingApi(immutableXConfig.apiConfiguration);
|
|
2094
|
+
const usersApi = new coreSdk.UsersApi(immutableXConfig.apiConfiguration);
|
|
2095
|
+
const data = {
|
|
2096
|
+
token_address: deposit.tokenAddress,
|
|
2097
|
+
token_id: deposit.tokenId,
|
|
2098
|
+
};
|
|
2099
|
+
const amount = '1';
|
|
2100
|
+
const getSignableDepositRequest = {
|
|
2101
|
+
user,
|
|
2102
|
+
token: {
|
|
2103
|
+
type: deposit.type,
|
|
2104
|
+
data,
|
|
2105
|
+
},
|
|
2106
|
+
amount: amount.toString(),
|
|
2107
|
+
};
|
|
2108
|
+
const signableDepositResult = await depositsApi.getSignableDeposit({
|
|
2109
|
+
getSignableDepositRequest,
|
|
2110
|
+
});
|
|
2111
|
+
// Perform encoding on asset details to get an assetType (required for stark contract request)
|
|
2112
|
+
const encodingResult = await encodingApi.encodeAsset({
|
|
2113
|
+
assetType: 'asset',
|
|
2114
|
+
encodeAssetRequest: {
|
|
2115
|
+
token: {
|
|
2116
|
+
type: deposit.type,
|
|
2117
|
+
data: {
|
|
2118
|
+
token_address: deposit.tokenAddress,
|
|
2119
|
+
token_id: deposit.tokenId,
|
|
2120
|
+
},
|
|
1596
2121
|
},
|
|
1597
|
-
}
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
2122
|
+
},
|
|
2123
|
+
});
|
|
2124
|
+
const assetType = encodingResult.data.asset_type;
|
|
2125
|
+
const starkPublicKey = signableDepositResult.data.stark_key;
|
|
2126
|
+
const vaultId = signableDepositResult.data.vault_id;
|
|
2127
|
+
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
2128
|
+
// Approve whether an amount of token from an account can be spent by a third-party account
|
|
2129
|
+
const tokenContract = coreSdk.Contracts.IERC721.connect(deposit.tokenAddress, ethSigner);
|
|
2130
|
+
const operator = immutableXConfig.ethConfiguration.coreContractAddress;
|
|
2131
|
+
const isApprovedForAll = await tokenContract.isApprovedForAll(user, operator);
|
|
2132
|
+
if (!isApprovedForAll) {
|
|
2133
|
+
await tokenContract.setApprovalForAll(operator, true);
|
|
2134
|
+
}
|
|
2135
|
+
if (!isRegistered) {
|
|
2136
|
+
const signableResult = await getSignableRegistrationOnchain(user, starkPublicKey, usersApi);
|
|
2137
|
+
const coreContract = coreSdk.Contracts.Core.connect(immutableXConfig.ethConfiguration.coreContractAddress, ethSigner);
|
|
2138
|
+
// Note: proxy registration contract registerAndDepositNft method is not used as it currently fails erc721 transfer ownership check
|
|
2139
|
+
await coreContract.registerUser(user, starkPublicKey, signableResult.operator_signature);
|
|
2140
|
+
}
|
|
2141
|
+
return executeDepositERC721(ethSigner, deposit.tokenId, assetType, starkPublicKey, vaultId, immutableXConfig);
|
|
1608
2142
|
}
|
|
1609
|
-
async function
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
};
|
|
1614
|
-
const getSignableCancelOrderResponse = await ordersApi.getSignableCancelOrder({
|
|
1615
|
-
getSignableCancelOrderRequest,
|
|
1616
|
-
});
|
|
1617
|
-
const confirmationScreen = new ConfirmationScreen(passportConfig);
|
|
1618
|
-
const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
|
|
1619
|
-
transactionType: TransactionTypes.CancelOrder,
|
|
1620
|
-
transactionData: getSignableCancelOrderRequest,
|
|
1621
|
-
});
|
|
1622
|
-
if (!confirmationResult.confirmed) {
|
|
1623
|
-
throw new Error('Transaction rejected by user');
|
|
1624
|
-
}
|
|
1625
|
-
const { payload_hash: payloadHash } = getSignableCancelOrderResponse.data;
|
|
1626
|
-
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
1627
|
-
const headers = {
|
|
1628
|
-
Authorization: 'Bearer ' + user.accessToken,
|
|
1629
|
-
};
|
|
1630
|
-
const cancelOrderResponse = await ordersApi.cancelOrder({
|
|
1631
|
-
id: request.order_id.toString(),
|
|
1632
|
-
cancelOrderRequest: {
|
|
1633
|
-
order_id: request.order_id,
|
|
1634
|
-
stark_signature: starkSignature,
|
|
1635
|
-
},
|
|
1636
|
-
}, { headers });
|
|
1637
|
-
return {
|
|
1638
|
-
order_id: cancelOrderResponse.data.order_id,
|
|
1639
|
-
status: cancelOrderResponse.data.status,
|
|
1640
|
-
};
|
|
1641
|
-
}, PassportErrorType.CANCEL_ORDER_ERROR);
|
|
2143
|
+
async function executeDepositERC721(ethSigner, tokenId, assetType, starkPublicKey, vaultId, config) {
|
|
2144
|
+
const coreContract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
2145
|
+
const populatedTransaction = await coreContract.populateTransaction.depositNft(starkPublicKey, assetType, vaultId, tokenId);
|
|
2146
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
1642
2147
|
}
|
|
1643
2148
|
|
|
1644
|
-
async function
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
amount: transferAmount,
|
|
1654
|
-
receiver: request.receiver,
|
|
1655
|
-
},
|
|
1656
|
-
});
|
|
1657
|
-
const starkAddress = await starkSigner.getAddress();
|
|
1658
|
-
const { payload_hash: payloadHash } = signableResult.data;
|
|
1659
|
-
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
1660
|
-
const transferSigningParams = {
|
|
1661
|
-
sender_stark_key: signableResult.data.sender_stark_key || starkAddress,
|
|
1662
|
-
sender_vault_id: signableResult.data.sender_vault_id,
|
|
1663
|
-
receiver_stark_key: signableResult.data.receiver_stark_key,
|
|
1664
|
-
receiver_vault_id: signableResult.data.receiver_vault_id,
|
|
1665
|
-
asset_id: signableResult.data.asset_id,
|
|
1666
|
-
amount: signableResult.data.amount,
|
|
1667
|
-
nonce: signableResult.data.nonce,
|
|
1668
|
-
expiration_timestamp: signableResult.data.expiration_timestamp,
|
|
1669
|
-
stark_signature: starkSignature,
|
|
1670
|
-
};
|
|
1671
|
-
const headers = {
|
|
1672
|
-
Authorization: 'Bearer ' + user.accessToken,
|
|
1673
|
-
};
|
|
1674
|
-
const response = await exchangesApi.createExchangeTransfer({
|
|
1675
|
-
id: request.transactionID,
|
|
1676
|
-
createTransferRequest: transferSigningParams,
|
|
1677
|
-
}, { headers });
|
|
1678
|
-
return {
|
|
1679
|
-
sent_signature: response?.data.sent_signature,
|
|
1680
|
-
status: response?.data.status?.toString(),
|
|
1681
|
-
time: response?.data.time,
|
|
1682
|
-
transfer_id: response?.data.transfer_id,
|
|
1683
|
-
};
|
|
1684
|
-
}, PassportErrorType.EXCHANGE_TRANSFER_ERROR);
|
|
2149
|
+
async function deposit({ signers, deposit, config }) {
|
|
2150
|
+
switch (deposit.type) {
|
|
2151
|
+
case 'ETH':
|
|
2152
|
+
return depositEth({ signers, deposit, config });
|
|
2153
|
+
case 'ERC20':
|
|
2154
|
+
return depositERC20({ signers, deposit, config });
|
|
2155
|
+
case 'ERC721':
|
|
2156
|
+
return depositERC721({ signers, deposit, config });
|
|
2157
|
+
}
|
|
1685
2158
|
}
|
|
1686
2159
|
|
|
1687
|
-
async function
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
const headers = { Authorization: 'Bearer ' + user.accessToken };
|
|
1729
|
-
const { data: createTradeResponse } = await tradesApi.createTrade(tradeParams, {
|
|
1730
|
-
headers,
|
|
1731
|
-
});
|
|
1732
|
-
return createTradeResponse;
|
|
1733
|
-
}, PassportErrorType.CREATE_TRADE_ERROR);
|
|
2160
|
+
async function exchangeTransfer({ signers, request, config, }) {
|
|
2161
|
+
await validateChain(signers.ethSigner, config.immutableXConfig);
|
|
2162
|
+
const exchangeApi = new coreSdk.ExchangesApi(config.immutableXConfig.apiConfiguration);
|
|
2163
|
+
const ethAddress = await signers.ethSigner.getAddress();
|
|
2164
|
+
const transferAmount = request.amount;
|
|
2165
|
+
const signableResult = await exchangeApi.getExchangeSignableTransfer({
|
|
2166
|
+
id: request.transactionID,
|
|
2167
|
+
getSignableTransferRequest: {
|
|
2168
|
+
sender: ethAddress,
|
|
2169
|
+
token: convertToSignableToken(request),
|
|
2170
|
+
amount: transferAmount,
|
|
2171
|
+
receiver: request.receiver,
|
|
2172
|
+
},
|
|
2173
|
+
});
|
|
2174
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
2175
|
+
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
2176
|
+
const starkSignature = await signers.starkSigner.signMessage(payloadHash);
|
|
2177
|
+
const transferSigningParams = {
|
|
2178
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
2179
|
+
sender_stark_key: signableResult.data.sender_stark_key,
|
|
2180
|
+
sender_vault_id: signableResult.data.sender_vault_id,
|
|
2181
|
+
receiver_stark_key: signableResult.data.receiver_stark_key,
|
|
2182
|
+
receiver_vault_id: signableResult.data.receiver_vault_id,
|
|
2183
|
+
asset_id: signableResult.data.asset_id,
|
|
2184
|
+
amount: signableResult.data.amount,
|
|
2185
|
+
nonce: signableResult.data.nonce,
|
|
2186
|
+
expiration_timestamp: signableResult.data.expiration_timestamp,
|
|
2187
|
+
stark_signature: starkSignature,
|
|
2188
|
+
};
|
|
2189
|
+
const response = await exchangeApi.createExchangeTransfer({
|
|
2190
|
+
id: request.transactionID,
|
|
2191
|
+
createTransferRequest: transferSigningParams,
|
|
2192
|
+
xImxEthAddress: ethAddress,
|
|
2193
|
+
xImxEthSignature: ethSignature,
|
|
2194
|
+
});
|
|
2195
|
+
return {
|
|
2196
|
+
sent_signature: response?.data.sent_signature,
|
|
2197
|
+
status: response?.data.status?.toString(),
|
|
2198
|
+
time: response?.data.time,
|
|
2199
|
+
transfer_id: response?.data.transfer_id,
|
|
2200
|
+
};
|
|
1734
2201
|
}
|
|
1735
2202
|
|
|
1736
|
-
class
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
exchangesApi;
|
|
1743
|
-
tradesApi;
|
|
1744
|
-
constructor({ user, starkSigner, passportConfig }) {
|
|
1745
|
-
this.user = user;
|
|
1746
|
-
this.starkSigner = starkSigner;
|
|
1747
|
-
this.passportConfig = passportConfig;
|
|
1748
|
-
const apiConfig = new coreSdk.Configuration({
|
|
1749
|
-
basePath: passportConfig.imxAPIConfiguration.basePath,
|
|
1750
|
-
});
|
|
1751
|
-
this.transfersApi = new coreSdk.TransfersApi(apiConfig);
|
|
1752
|
-
this.ordersApi = new coreSdk.OrdersApi(apiConfig);
|
|
1753
|
-
this.exchangesApi = new coreSdk.ExchangesApi(apiConfig);
|
|
1754
|
-
this.tradesApi = new coreSdk.TradesApi(apiConfig);
|
|
2203
|
+
class GenericIMXProvider {
|
|
2204
|
+
config;
|
|
2205
|
+
signers;
|
|
2206
|
+
constructor(config, ethSigner, starkSigner) {
|
|
2207
|
+
this.config = config;
|
|
2208
|
+
this.signers = { ethSigner, starkSigner };
|
|
1755
2209
|
}
|
|
1756
|
-
async
|
|
1757
|
-
return
|
|
1758
|
-
request,
|
|
1759
|
-
user: this.user,
|
|
1760
|
-
starkSigner: this.starkSigner,
|
|
1761
|
-
transfersApi: this.transfersApi,
|
|
1762
|
-
passportConfig: this.passportConfig,
|
|
1763
|
-
});
|
|
2210
|
+
async getAddress() {
|
|
2211
|
+
return await this.signers.ethSigner.getAddress();
|
|
1764
2212
|
}
|
|
1765
2213
|
registerOffchain() {
|
|
1766
|
-
|
|
2214
|
+
return registerOffchain(this.signers, this.config);
|
|
1767
2215
|
}
|
|
1768
|
-
|
|
1769
|
-
|
|
2216
|
+
batchNftTransfer(request) {
|
|
2217
|
+
return batchTransfer({
|
|
2218
|
+
signers: this.signers,
|
|
2219
|
+
request,
|
|
2220
|
+
config: this.config,
|
|
2221
|
+
});
|
|
1770
2222
|
}
|
|
1771
|
-
|
|
1772
|
-
return
|
|
2223
|
+
cancelOrder(request) {
|
|
2224
|
+
return cancelOrder({
|
|
2225
|
+
signers: this.signers,
|
|
1773
2226
|
request,
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
2227
|
+
config: this.config,
|
|
2228
|
+
});
|
|
2229
|
+
}
|
|
2230
|
+
completeWithdrawal(starkPublicKey, token) {
|
|
2231
|
+
return completeWithdrawal({
|
|
2232
|
+
config: this.config,
|
|
2233
|
+
signers: this.signers,
|
|
2234
|
+
token,
|
|
2235
|
+
starkPublicKey,
|
|
1778
2236
|
});
|
|
1779
2237
|
}
|
|
1780
|
-
|
|
1781
|
-
return
|
|
2238
|
+
createOrder(request) {
|
|
2239
|
+
return createOrder({
|
|
2240
|
+
signers: this.signers,
|
|
1782
2241
|
request,
|
|
1783
|
-
|
|
1784
|
-
starkSigner: this.starkSigner,
|
|
1785
|
-
ordersApi: this.ordersApi,
|
|
1786
|
-
passportConfig: this.passportConfig,
|
|
2242
|
+
config: this.config,
|
|
1787
2243
|
});
|
|
1788
2244
|
}
|
|
1789
2245
|
createTrade(request) {
|
|
1790
2246
|
return createTrade({
|
|
2247
|
+
signers: this.signers,
|
|
1791
2248
|
request,
|
|
1792
|
-
|
|
1793
|
-
starkSigner: this.starkSigner,
|
|
1794
|
-
tradesApi: this.tradesApi,
|
|
1795
|
-
passportConfig: this.passportConfig,
|
|
2249
|
+
config: this.config,
|
|
1796
2250
|
});
|
|
1797
2251
|
}
|
|
1798
|
-
|
|
1799
|
-
return
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
transfersApi: this.transfersApi,
|
|
1804
|
-
passportConfig: this.passportConfig,
|
|
2252
|
+
deposit(tokenAmount) {
|
|
2253
|
+
return deposit({
|
|
2254
|
+
signers: this.signers,
|
|
2255
|
+
deposit: tokenAmount,
|
|
2256
|
+
config: this.config,
|
|
1805
2257
|
});
|
|
1806
2258
|
}
|
|
1807
2259
|
exchangeTransfer(request) {
|
|
1808
2260
|
return exchangeTransfer({
|
|
2261
|
+
signers: this.signers,
|
|
1809
2262
|
request,
|
|
1810
|
-
|
|
1811
|
-
starkSigner: this.starkSigner,
|
|
1812
|
-
exchangesApi: this.exchangesApi,
|
|
2263
|
+
config: this.config,
|
|
1813
2264
|
});
|
|
1814
2265
|
}
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
2266
|
+
async isRegisteredOnchain() {
|
|
2267
|
+
const starkPublicKey = await this.signers.starkSigner.getAddress();
|
|
2268
|
+
return isRegisteredOnChain(starkPublicKey, this.signers.ethSigner, this.config);
|
|
1818
2269
|
}
|
|
1819
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1820
2270
|
prepareWithdrawal(request) {
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1827
|
-
token) {
|
|
1828
|
-
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
2271
|
+
return prepareWithdrawal({
|
|
2272
|
+
signers: this.signers,
|
|
2273
|
+
withdrawal: request,
|
|
2274
|
+
config: this.config,
|
|
2275
|
+
});
|
|
1829
2276
|
}
|
|
1830
|
-
|
|
1831
|
-
return
|
|
2277
|
+
transfer(request) {
|
|
2278
|
+
return transfer({
|
|
2279
|
+
signers: this.signers,
|
|
2280
|
+
request,
|
|
2281
|
+
config: this.config,
|
|
2282
|
+
});
|
|
1832
2283
|
}
|
|
1833
2284
|
}
|
|
1834
2285
|
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
2286
|
+
const WALLET_ACTION = {
|
|
2287
|
+
SWITCH_CHAIN: 'wallet_switchEthereumChain',
|
|
2288
|
+
CONNECT: 'eth_requestAccounts',
|
|
2289
|
+
};
|
|
2290
|
+
function isRequestableProvider(provider) {
|
|
2291
|
+
return !!provider?.request;
|
|
2292
|
+
}
|
|
2293
|
+
async function connectProvider(provider, chainID) {
|
|
2294
|
+
await provider.request({ method: WALLET_ACTION.CONNECT });
|
|
2295
|
+
if (chainID) {
|
|
2296
|
+
await provider.request({
|
|
2297
|
+
method: WALLET_ACTION.SWITCH_CHAIN,
|
|
2298
|
+
params: [{ chainId: `0x${chainID.toString(16)}` }],
|
|
2299
|
+
});
|
|
2300
|
+
}
|
|
2301
|
+
}
|
|
1840
2302
|
|
|
1841
|
-
const
|
|
1842
|
-
|
|
1843
|
-
network: Networks.PRODUCTION,
|
|
1844
|
-
authenticationDomain: 'https://auth.immutable.com',
|
|
1845
|
-
magicPublishableApiKey: 'pk_live_10F423798A540ED7',
|
|
1846
|
-
magicProviderId: 'fSMzaRQ4O7p4fttl7pCyGVtJS_G70P8SNsLXtPPGHo0=',
|
|
1847
|
-
baseIMXApiPath: 'https://api.x.immutable.com',
|
|
1848
|
-
passportDomain: 'https://passport.immutable.com',
|
|
1849
|
-
},
|
|
1850
|
-
SANDBOX: {
|
|
1851
|
-
network: Networks.SANDBOX,
|
|
1852
|
-
authenticationDomain: 'https://auth.immutable.com',
|
|
1853
|
-
magicPublishableApiKey: 'pk_live_10F423798A540ED7',
|
|
1854
|
-
magicProviderId: 'fSMzaRQ4O7p4fttl7pCyGVtJS_G70P8SNsLXtPPGHo0=',
|
|
1855
|
-
baseIMXApiPath: 'https://api.sandbox.x.immutable.com',
|
|
1856
|
-
passportDomain: 'https://passport.sandbox.immutable.com',
|
|
1857
|
-
},
|
|
2303
|
+
const ERRORS = {
|
|
2304
|
+
PROVIDER_NOT_FOUND: 'The Metamask provider was not found',
|
|
1858
2305
|
};
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
2306
|
+
async function connect$1({ chainID, }) {
|
|
2307
|
+
const provider = (await detectEthereumProvider());
|
|
2308
|
+
if (!isRequestableProvider(provider)) {
|
|
2309
|
+
throw new Error(ERRORS.PROVIDER_NOT_FOUND);
|
|
1862
2310
|
}
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
2311
|
+
await connectProvider(provider, chainID);
|
|
2312
|
+
// NOTE: if we want to listen to Metamask events in the future, we can add a
|
|
2313
|
+
// listener here.
|
|
2314
|
+
return new ethers.ethers.providers.Web3Provider(provider);
|
|
2315
|
+
}
|
|
2316
|
+
|
|
2317
|
+
const COMMUNICATION_TYPE = 'message';
|
|
2318
|
+
var RequestEventType;
|
|
2319
|
+
(function (RequestEventType) {
|
|
2320
|
+
RequestEventType["GET_CONNECTION_REQUEST"] = "GET_CONNECTION_REQUEST";
|
|
2321
|
+
RequestEventType["CONNECT_WALLET_REQUEST"] = "CONNECT_WALLET_REQUEST";
|
|
2322
|
+
RequestEventType["SIGN_MESSAGE_REQUEST"] = "SIGN_MESSAGE_REQUEST";
|
|
2323
|
+
RequestEventType["DISCONNECT_WALLET_REQUEST"] = "DISCONNECT_WALLET_REQUEST";
|
|
2324
|
+
})(RequestEventType || (RequestEventType = {}));
|
|
2325
|
+
var ResponseEventType;
|
|
2326
|
+
(function (ResponseEventType) {
|
|
2327
|
+
ResponseEventType["CONNECT_WALLET_RESPONSE"] = "CONNECT_WALLET_RESPONSE";
|
|
2328
|
+
ResponseEventType["SIGN_MESSAGE_RESPONSE"] = "SIGN_MESSAGE_RESPONSE";
|
|
2329
|
+
ResponseEventType["GET_CONNECTION_RESPONSE"] = "GET_CONNECTION_RESPONSE";
|
|
2330
|
+
ResponseEventType["DISCONNECT_WALLET_RESPONSE"] = "DISCONNECT_WALLET_RESPONSE";
|
|
2331
|
+
})(ResponseEventType || (ResponseEventType = {}));
|
|
2332
|
+
|
|
2333
|
+
function postRequestMessage(iframe, payload) {
|
|
2334
|
+
if (iframe && iframe.contentWindow) {
|
|
2335
|
+
iframe.contentWindow.postMessage(payload, new URL(iframe.src).origin);
|
|
1869
2336
|
}
|
|
1870
|
-
}
|
|
1871
|
-
const getPassportConfiguration = (environmentConfiguration, oidcConfiguration) => {
|
|
1872
|
-
validateConfiguration('EnvironmentConfiguration', environmentConfiguration, [
|
|
1873
|
-
'network',
|
|
1874
|
-
'authenticationDomain',
|
|
1875
|
-
'magicPublishableApiKey',
|
|
1876
|
-
'magicProviderId',
|
|
1877
|
-
'passportDomain',
|
|
1878
|
-
]);
|
|
1879
|
-
validateConfiguration('OidcConfiguration', oidcConfiguration, [
|
|
1880
|
-
'clientId',
|
|
1881
|
-
'logoutRedirectUri',
|
|
1882
|
-
'redirectUri',
|
|
1883
|
-
]);
|
|
1884
|
-
return {
|
|
1885
|
-
network: environmentConfiguration.network,
|
|
1886
|
-
oidcConfiguration: {
|
|
1887
|
-
authenticationDomain: environmentConfiguration.authenticationDomain,
|
|
1888
|
-
clientId: oidcConfiguration.clientId,
|
|
1889
|
-
logoutRedirectUri: oidcConfiguration.logoutRedirectUri,
|
|
1890
|
-
redirectUri: oidcConfiguration.redirectUri,
|
|
1891
|
-
scope: oidcConfiguration.scope,
|
|
1892
|
-
audience: oidcConfiguration.audience,
|
|
1893
|
-
},
|
|
1894
|
-
imxAPIConfiguration: {
|
|
1895
|
-
basePath: environmentConfiguration.baseIMXApiPath,
|
|
1896
|
-
},
|
|
1897
|
-
passportDomain: environmentConfiguration.passportDomain,
|
|
1898
|
-
magicPublishableApiKey: environmentConfiguration.magicPublishableApiKey,
|
|
1899
|
-
magicProviderId: environmentConfiguration.magicProviderId,
|
|
1900
|
-
};
|
|
1901
|
-
};
|
|
2337
|
+
}
|
|
1902
2338
|
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
2339
|
+
function messageResponseListener(iframe, event, eventType, callback) {
|
|
2340
|
+
if (iframe && event.source !== iframe.contentWindow) {
|
|
2341
|
+
return;
|
|
2342
|
+
}
|
|
2343
|
+
const l2WalletMessage = event.data;
|
|
2344
|
+
if (l2WalletMessage.type !== eventType) {
|
|
2345
|
+
return;
|
|
2346
|
+
}
|
|
2347
|
+
callback(l2WalletMessage.details);
|
|
2348
|
+
}
|
|
2349
|
+
|
|
2350
|
+
class ImxSigner {
|
|
2351
|
+
publicAddress;
|
|
2352
|
+
iframe;
|
|
2353
|
+
constructor(publicAddress, iframe) {
|
|
2354
|
+
this.publicAddress = publicAddress;
|
|
2355
|
+
this.iframe = iframe;
|
|
2356
|
+
}
|
|
2357
|
+
getAddress() {
|
|
2358
|
+
return this.publicAddress;
|
|
2359
|
+
}
|
|
2360
|
+
signMessage(rawMessage) {
|
|
2361
|
+
return new Promise((resolve, reject) => {
|
|
2362
|
+
const listener = (event) => {
|
|
2363
|
+
messageResponseListener(this.iframe, event, ResponseEventType.SIGN_MESSAGE_RESPONSE, (messageDetails) => {
|
|
2364
|
+
window.removeEventListener(COMMUNICATION_TYPE, listener);
|
|
2365
|
+
if (!messageDetails.success) {
|
|
2366
|
+
reject(new Error(messageDetails.error?.message));
|
|
2367
|
+
}
|
|
2368
|
+
resolve(messageDetails.data.signedMessage);
|
|
2369
|
+
});
|
|
2370
|
+
};
|
|
2371
|
+
window.addEventListener(COMMUNICATION_TYPE, listener);
|
|
2372
|
+
postRequestMessage(this.iframe, {
|
|
2373
|
+
type: RequestEventType.SIGN_MESSAGE_REQUEST,
|
|
2374
|
+
details: { starkPublicKey: this.publicAddress, message: rawMessage },
|
|
2375
|
+
});
|
|
2376
|
+
});
|
|
2377
|
+
}
|
|
2378
|
+
getIFrame() {
|
|
2379
|
+
return this.iframe;
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
|
|
2383
|
+
const IMX_WALLET_IFRAME_ID = 'imx-wallet-app';
|
|
2384
|
+
const IMX_WALLET_IFRAME_HOSTS = {
|
|
2385
|
+
[exports.Environment.SANDBOX]: 'https://wallets.sandbox.immutable.com',
|
|
2386
|
+
[exports.Environment.PRODUCTION]: 'https://wallets.immutable.com',
|
|
1908
2387
|
};
|
|
2388
|
+
const IMX_WALLET_IFRAME_STYLE = 'display: none;';
|
|
2389
|
+
function getIFrame() {
|
|
2390
|
+
return document.querySelector(`iframe#${IMX_WALLET_IFRAME_ID}`);
|
|
2391
|
+
}
|
|
2392
|
+
async function setupIFrame(env) {
|
|
2393
|
+
return new Promise((resolve) => {
|
|
2394
|
+
const iframe = document.createElement('iframe');
|
|
2395
|
+
iframe.setAttribute('id', IMX_WALLET_IFRAME_ID);
|
|
2396
|
+
iframe.setAttribute('src', IMX_WALLET_IFRAME_HOSTS[env]);
|
|
2397
|
+
iframe.setAttribute('style', IMX_WALLET_IFRAME_STYLE);
|
|
2398
|
+
document.body.appendChild(iframe);
|
|
2399
|
+
iframe.onload = () => resolve(iframe);
|
|
2400
|
+
});
|
|
2401
|
+
}
|
|
2402
|
+
async function getOrSetupIFrame(env) {
|
|
2403
|
+
const iframe = getIFrame();
|
|
2404
|
+
if (iframe)
|
|
2405
|
+
return iframe;
|
|
2406
|
+
return await setupIFrame(env);
|
|
2407
|
+
}
|
|
1909
2408
|
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
2409
|
+
const DEFAULT_CONNECTION_MESSAGE = 'Only sign this request if you’ve initiated an action with Immutable X.';
|
|
2410
|
+
const CONNECTION_FAILED_ERROR = 'The L2 IMX Wallet connection has failed';
|
|
2411
|
+
async function connect(l1Provider, env) {
|
|
2412
|
+
const l1Signer = l1Provider.getSigner();
|
|
2413
|
+
const address = await l1Signer.getAddress();
|
|
2414
|
+
const signature = await l1Signer.signMessage(DEFAULT_CONNECTION_MESSAGE);
|
|
2415
|
+
const iframe = await getOrSetupIFrame(env);
|
|
2416
|
+
return new Promise((resolve, reject) => {
|
|
2417
|
+
const listener = (event) => {
|
|
2418
|
+
messageResponseListener(iframe, event, ResponseEventType.CONNECT_WALLET_RESPONSE, (messageDetails) => {
|
|
2419
|
+
window.removeEventListener(COMMUNICATION_TYPE, listener);
|
|
2420
|
+
if (!messageDetails.success) {
|
|
2421
|
+
reject(new Error(CONNECTION_FAILED_ERROR));
|
|
2422
|
+
}
|
|
2423
|
+
resolve(new ImxSigner(messageDetails.data.starkPublicKey, iframe));
|
|
2424
|
+
});
|
|
2425
|
+
};
|
|
2426
|
+
window.addEventListener(COMMUNICATION_TYPE, listener);
|
|
2427
|
+
postRequestMessage(iframe, {
|
|
2428
|
+
type: RequestEventType.CONNECT_WALLET_REQUEST,
|
|
2429
|
+
details: { ethAddress: address, signature },
|
|
1919
2430
|
});
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
2431
|
+
});
|
|
2432
|
+
}
|
|
2433
|
+
async function disconnect(imxSigner) {
|
|
2434
|
+
const iframe = imxSigner.getIFrame();
|
|
2435
|
+
return new Promise((resolve, reject) => {
|
|
2436
|
+
const listener = (event) => {
|
|
2437
|
+
messageResponseListener(iframe, event, ResponseEventType.DISCONNECT_WALLET_RESPONSE, (messageDetails) => {
|
|
2438
|
+
window.removeEventListener(COMMUNICATION_TYPE, listener);
|
|
2439
|
+
if (!messageDetails.success && messageDetails.error) {
|
|
2440
|
+
reject(messageDetails.error);
|
|
2441
|
+
}
|
|
2442
|
+
iframe.remove();
|
|
2443
|
+
resolve();
|
|
2444
|
+
});
|
|
2445
|
+
};
|
|
2446
|
+
window.addEventListener(COMMUNICATION_TYPE, listener);
|
|
2447
|
+
postRequestMessage(iframe, {
|
|
2448
|
+
type: RequestEventType.DISCONNECT_WALLET_REQUEST,
|
|
2449
|
+
details: { starkPublicKey: imxSigner.getAddress() },
|
|
1931
2450
|
});
|
|
1932
|
-
|
|
1933
|
-
}, PassportErrorType.USER_REGISTRATION_ERROR);
|
|
2451
|
+
});
|
|
1934
2452
|
}
|
|
1935
2453
|
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
2454
|
+
var ProviderErrorType;
|
|
2455
|
+
(function (ProviderErrorType) {
|
|
2456
|
+
ProviderErrorType["PROVIDER_CONNECTION_ERROR"] = "PROVIDER_CONNECTION_ERROR";
|
|
2457
|
+
ProviderErrorType["WALLET_CONNECTION_ERROR"] = "WALLET_CONNECTION_ERROR";
|
|
2458
|
+
})(ProviderErrorType || (ProviderErrorType = {}));
|
|
2459
|
+
class ProviderError extends Error {
|
|
2460
|
+
type;
|
|
2461
|
+
constructor(message, type) {
|
|
2462
|
+
super(message);
|
|
2463
|
+
this.type = type;
|
|
1945
2464
|
}
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
}
|
|
1951
|
-
const provider = await this.magicAdapter.login(user.idToken);
|
|
1952
|
-
const ethSigner = provider.getSigner();
|
|
1953
|
-
const starkSigner = await getStarkSigner(ethSigner);
|
|
1954
|
-
if (!user.etherKey) {
|
|
1955
|
-
const updatedUser = await this.registerUser(ethSigner, starkSigner, user.accessToken);
|
|
1956
|
-
return new PassportImxProvider({
|
|
1957
|
-
user: updatedUser,
|
|
1958
|
-
starkSigner,
|
|
1959
|
-
passportConfig: this.config,
|
|
1960
|
-
});
|
|
1961
|
-
}
|
|
1962
|
-
const userWithEtherKey = user;
|
|
1963
|
-
return new PassportImxProvider({
|
|
1964
|
-
user: userWithEtherKey,
|
|
1965
|
-
starkSigner,
|
|
1966
|
-
passportConfig: this.config,
|
|
1967
|
-
});
|
|
2465
|
+
}
|
|
2466
|
+
const withProviderError = async (fn, customError) => {
|
|
2467
|
+
try {
|
|
2468
|
+
return await fn();
|
|
1968
2469
|
}
|
|
1969
|
-
|
|
1970
|
-
|
|
2470
|
+
catch (error) {
|
|
2471
|
+
const errorMessage = customError.message || `${error.message}` || 'UnknownError';
|
|
2472
|
+
throw new ProviderError(errorMessage, customError.type);
|
|
1971
2473
|
}
|
|
1972
|
-
|
|
1973
|
-
|
|
2474
|
+
};
|
|
2475
|
+
|
|
2476
|
+
class MetaMaskIMXProvider extends GenericIMXProvider {
|
|
2477
|
+
static imxSigner;
|
|
2478
|
+
constructor(config, ethSigner, starkSigner) {
|
|
2479
|
+
super(config, ethSigner, starkSigner);
|
|
1974
2480
|
}
|
|
1975
|
-
async
|
|
1976
|
-
|
|
1977
|
-
|
|
2481
|
+
static async connect(config) {
|
|
2482
|
+
return await withProviderError(async () => {
|
|
2483
|
+
const metaMaskProvider = await connect$1({
|
|
2484
|
+
chainID: config.immutableXConfig.ethConfiguration.chainID,
|
|
2485
|
+
});
|
|
2486
|
+
this.imxSigner = await connect(metaMaskProvider, config.baseConfig.environment);
|
|
2487
|
+
return new MetaMaskIMXProvider(config, metaMaskProvider.getSigner(), this.imxSigner);
|
|
2488
|
+
}, { type: ProviderErrorType.WALLET_CONNECTION_ERROR });
|
|
1978
2489
|
}
|
|
1979
|
-
async
|
|
1980
|
-
|
|
1981
|
-
|
|
2490
|
+
static async disconnect() {
|
|
2491
|
+
if (!this.imxSigner) {
|
|
2492
|
+
throw new ProviderError('Attempted to disconnect from the MetaMask IMX provider without an established connection', ProviderErrorType.PROVIDER_CONNECTION_ERROR);
|
|
2493
|
+
}
|
|
2494
|
+
return withProviderError(async () => {
|
|
2495
|
+
await disconnect(this.imxSigner);
|
|
2496
|
+
}, { type: ProviderErrorType.PROVIDER_CONNECTION_ERROR });
|
|
1982
2497
|
}
|
|
1983
|
-
async
|
|
1984
|
-
|
|
1985
|
-
|
|
2498
|
+
static async signMessage(message) {
|
|
2499
|
+
if (!this.imxSigner) {
|
|
2500
|
+
throw new ProviderError('Attempted to sign a message with the MetaMask IMX provider without an established connection', ProviderErrorType.PROVIDER_CONNECTION_ERROR);
|
|
2501
|
+
}
|
|
2502
|
+
return withProviderError(async () => {
|
|
2503
|
+
return await this.imxSigner.signMessage(message);
|
|
2504
|
+
}, { type: ProviderErrorType.PROVIDER_CONNECTION_ERROR });
|
|
1986
2505
|
}
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
}
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2506
|
+
}
|
|
2507
|
+
|
|
2508
|
+
class ProviderConfiguration {
|
|
2509
|
+
immutableXConfig;
|
|
2510
|
+
baseConfig;
|
|
2511
|
+
constructor({ baseConfig, overrides }) {
|
|
2512
|
+
this.baseConfig = baseConfig;
|
|
2513
|
+
if (overrides) {
|
|
2514
|
+
this.immutableXConfig = overrides.immutableXConfig;
|
|
2515
|
+
}
|
|
2516
|
+
else {
|
|
2517
|
+
switch (baseConfig.environment) {
|
|
2518
|
+
case exports.Environment.SANDBOX: {
|
|
2519
|
+
this.immutableXConfig = coreSdk.Config.SANDBOX;
|
|
2520
|
+
break;
|
|
2521
|
+
}
|
|
2522
|
+
case exports.Environment.PRODUCTION: {
|
|
2523
|
+
this.immutableXConfig = coreSdk.Config.PRODUCTION;
|
|
2524
|
+
break;
|
|
2525
|
+
}
|
|
2526
|
+
}
|
|
2000
2527
|
}
|
|
2001
|
-
return updatedUser;
|
|
2002
2528
|
}
|
|
2003
2529
|
}
|
|
2004
2530
|
|
|
2531
|
+
function $parcel$interopDefault(a) {
|
|
2532
|
+
return a && a.__esModule ? a.default : a;
|
|
2533
|
+
}
|
|
2534
|
+
|
|
2005
2535
|
const $762782b6c862d954$export$db5daa1b5156ccfe = [
|
|
2006
2536
|
{
|
|
2007
2537
|
constant: true,
|
|
@@ -2122,8 +2652,18 @@ const $a47e48dd2c04791b$export$f61f4aaec62f6be9 = {
|
|
|
2122
2652
|
]
|
|
2123
2653
|
}
|
|
2124
2654
|
};
|
|
2655
|
+
exports.NetworkFilterTypes = void 0;
|
|
2656
|
+
(function(NetworkFilterTypes) {
|
|
2657
|
+
NetworkFilterTypes["ALL"] = "all";
|
|
2658
|
+
})(exports.NetworkFilterTypes || (exports.NetworkFilterTypes = {}));
|
|
2125
2659
|
|
|
2126
2660
|
|
|
2661
|
+
exports.TokenFilterTypes = void 0;
|
|
2662
|
+
(function(TokenFilterTypes) {
|
|
2663
|
+
TokenFilterTypes["SWAP"] = "swap";
|
|
2664
|
+
TokenFilterTypes["BRIDGE"] = "bridge";
|
|
2665
|
+
TokenFilterTypes["ALL"] = "all";
|
|
2666
|
+
})(exports.TokenFilterTypes || (exports.TokenFilterTypes = {}));
|
|
2127
2667
|
|
|
2128
2668
|
|
|
2129
2669
|
|
|
@@ -2134,70 +2674,177 @@ const $4f91c5f280efe242$export$a130407f3423b97d = {
|
|
|
2134
2674
|
ADD_NETWORK: "wallet_addEthereumChain",
|
|
2135
2675
|
SWITCH_NETWORK: "wallet_switchEthereumChain"
|
|
2136
2676
|
};
|
|
2677
|
+
exports.WalletFilterTypes = void 0;
|
|
2678
|
+
(function(WalletFilterTypes) {
|
|
2679
|
+
WalletFilterTypes["ALL"] = "all";
|
|
2680
|
+
WalletFilterTypes["DESKTOP"] = "desktop";
|
|
2681
|
+
WalletFilterTypes["MOBILE"] = "mobile";
|
|
2682
|
+
})(exports.WalletFilterTypes || (exports.WalletFilterTypes = {}));
|
|
2137
2683
|
|
|
2138
2684
|
|
|
2139
2685
|
|
|
2140
2686
|
|
|
2141
|
-
|
|
2687
|
+
/**
|
|
2688
|
+
* The different types of errors that can be returned by the checkout process.
|
|
2689
|
+
*/ exports.CheckoutErrorType = void 0;
|
|
2142
2690
|
(function(CheckoutErrorType) {
|
|
2691
|
+
CheckoutErrorType["PROVIDER_PREFERENCE_ERROR"] = "PROVIDER_PREFERENCE_ERROR";
|
|
2143
2692
|
CheckoutErrorType["CONNECT_PROVIDER_ERROR"] = "CONNECT_PROVIDER_ERROR";
|
|
2144
2693
|
CheckoutErrorType["GET_BALANCE_ERROR"] = "GET_BALANCE_ERROR";
|
|
2145
2694
|
CheckoutErrorType["GET_ERC20_BALANCE_ERROR"] = "GET_ERC20_BALANCE_ERROR";
|
|
2695
|
+
CheckoutErrorType["GET_NETWORK_INFO_ERROR"] = "GET_NETWORK_INFO_ERROR";
|
|
2146
2696
|
CheckoutErrorType["METAMASK_PROVIDER_ERROR"] = "METAMASK_PROVIDER_ERROR";
|
|
2147
2697
|
CheckoutErrorType["CHAIN_NOT_SUPPORTED_ERROR"] = "CHAIN_NOT_SUPPORTED_ERROR";
|
|
2148
2698
|
CheckoutErrorType["PROVIDER_REQUEST_MISSING_ERROR"] = "PROVIDER_REQUEST_MISSING_ERROR";
|
|
2699
|
+
CheckoutErrorType["PROVIDER_REQUEST_FAILED_ERROR"] = "PROVIDER_REQUEST_FAILED_ERROR";
|
|
2149
2700
|
CheckoutErrorType["USER_REJECTED_REQUEST_ERROR"] = "USER_REJECTED_REQUEST_ERROR";
|
|
2150
2701
|
CheckoutErrorType["TRANSACTION_ERROR"] = "TRANSACTION_ERROR";
|
|
2151
|
-
})(
|
|
2702
|
+
})(exports.CheckoutErrorType || (exports.CheckoutErrorType = {}));
|
|
2152
2703
|
class $a8bc256d81a5e2c1$export$b722478a3cbfa3bc extends Error {
|
|
2153
|
-
constructor(message, type){
|
|
2704
|
+
constructor(message, type, data){
|
|
2154
2705
|
super(message);
|
|
2706
|
+
this.message = message;
|
|
2155
2707
|
this.type = type;
|
|
2708
|
+
this.data = data;
|
|
2156
2709
|
}
|
|
2157
2710
|
}
|
|
2711
|
+
let $a8bc256d81a5e2c1$export$a22d4e0719ee6def;
|
|
2712
|
+
(function(CheckoutInternalErrorType) {
|
|
2713
|
+
CheckoutInternalErrorType["REJECTED_SWITCH_AFTER_ADDING_NETWORK"] = "REJECTED_SWITCH_AFTER_ADDING_NETWORK";
|
|
2714
|
+
})($a8bc256d81a5e2c1$export$a22d4e0719ee6def || ($a8bc256d81a5e2c1$export$a22d4e0719ee6def = {}));
|
|
2158
2715
|
const $a8bc256d81a5e2c1$export$bacc563de539c6c3 = async (fn, customError)=>{
|
|
2159
2716
|
try {
|
|
2160
2717
|
return await fn();
|
|
2161
2718
|
} catch (error) {
|
|
2162
|
-
const
|
|
2163
|
-
|
|
2719
|
+
const cause = `${error.message}` || "UnknownError";
|
|
2720
|
+
const errorMessage = customError.message ? `[${customError.type}]:${customError.message}. Cause:${cause}` : `[${customError.type}] Cause:${cause}`;
|
|
2721
|
+
if (error instanceof $a8bc256d81a5e2c1$export$b722478a3cbfa3bc) throw new $a8bc256d81a5e2c1$export$b722478a3cbfa3bc(errorMessage, customError.type, {
|
|
2722
|
+
...customError.data,
|
|
2723
|
+
innerErrorType: error.type,
|
|
2724
|
+
...error.data
|
|
2725
|
+
});
|
|
2726
|
+
throw new $a8bc256d81a5e2c1$export$b722478a3cbfa3bc(errorMessage, customError.type, {
|
|
2727
|
+
...customError.data
|
|
2728
|
+
});
|
|
2164
2729
|
}
|
|
2165
2730
|
};
|
|
2166
2731
|
|
|
2167
2732
|
|
|
2168
2733
|
|
|
2169
2734
|
|
|
2735
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2736
|
+
|
|
2737
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2170
2738
|
|
|
2171
2739
|
|
|
2172
2740
|
|
|
2173
|
-
async function $
|
|
2174
|
-
const
|
|
2175
|
-
if (!
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2741
|
+
async function $c99672cf2294e839$export$2d040992269b4717(providerPreference) {
|
|
2742
|
+
const provider = await $c99672cf2294e839$var$getWalletProviderForPreference(providerPreference);
|
|
2743
|
+
if (!provider.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Incompatible provider", (exports.CheckoutErrorType).PROVIDER_REQUEST_MISSING_ERROR, {
|
|
2744
|
+
details: `Unsupported provider for ${providerPreference}`
|
|
2745
|
+
});
|
|
2746
|
+
let accounts = [];
|
|
2747
|
+
try {
|
|
2748
|
+
accounts = await provider.provider.request({
|
|
2749
|
+
method: (0, $4f91c5f280efe242$export$a130407f3423b97d).CHECK_CONNECTION,
|
|
2750
|
+
params: []
|
|
2751
|
+
});
|
|
2752
|
+
} catch (err) {
|
|
2753
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`Check wallet connection request failed`, (exports.CheckoutErrorType).PROVIDER_REQUEST_FAILED_ERROR, {
|
|
2754
|
+
rpcMethod: ($4f91c5f280efe242$export$a130407f3423b97d).CHECK_CONNECTION
|
|
2755
|
+
});
|
|
2756
|
+
}
|
|
2757
|
+
// accounts[0] will have the active account if connected.
|
|
2758
|
+
return {
|
|
2759
|
+
isConnected: accounts && accounts.length > 0,
|
|
2760
|
+
walletAddress: accounts[0] ?? ""
|
|
2182
2761
|
};
|
|
2183
|
-
return networkInfo;
|
|
2184
2762
|
}
|
|
2185
|
-
async function $
|
|
2186
|
-
|
|
2187
|
-
|
|
2763
|
+
async function $c99672cf2294e839$export$fba2f6c3656e07c1(params) {
|
|
2764
|
+
const web3Provider = await $c99672cf2294e839$var$getWalletProviderForPreference(params.providerPreference);
|
|
2765
|
+
await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2766
|
+
if (!web3Provider || !web3Provider?.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Incompatible provider", (exports.CheckoutErrorType).PROVIDER_REQUEST_MISSING_ERROR, {
|
|
2767
|
+
details: `Unsupported provider for ${params.providerPreference}`
|
|
2768
|
+
});
|
|
2769
|
+
// this makes the request to the wallet to connect i.e request eth accounts ('eth_requestAccounts')
|
|
2770
|
+
await web3Provider.provider.request({
|
|
2771
|
+
method: ($4f91c5f280efe242$export$a130407f3423b97d).CONNECT,
|
|
2772
|
+
params: []
|
|
2773
|
+
});
|
|
2774
|
+
}, {
|
|
2775
|
+
type: (exports.CheckoutErrorType).USER_REJECTED_REQUEST_ERROR
|
|
2776
|
+
});
|
|
2777
|
+
return web3Provider;
|
|
2778
|
+
}
|
|
2779
|
+
async function $c99672cf2294e839$var$getWalletProviderForPreference(providerPreference) {
|
|
2780
|
+
let web3Provider = null;
|
|
2781
|
+
switch(providerPreference){
|
|
2782
|
+
case (exports.ConnectionProviders).METAMASK:
|
|
2783
|
+
web3Provider = await $c99672cf2294e839$var$getMetaMaskProvider();
|
|
2784
|
+
break;
|
|
2785
|
+
default:
|
|
2786
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Provider preference is not supported", (exports.CheckoutErrorType).PROVIDER_PREFERENCE_ERROR);
|
|
2787
|
+
}
|
|
2788
|
+
return web3Provider;
|
|
2789
|
+
}
|
|
2790
|
+
async function $c99672cf2294e839$var$getMetaMaskProvider() {
|
|
2791
|
+
const provider = await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2792
|
+
return await (detectEthereumProvider)();
|
|
2793
|
+
}, {
|
|
2794
|
+
type: (exports.CheckoutErrorType).METAMASK_PROVIDER_ERROR
|
|
2795
|
+
});
|
|
2796
|
+
if (!provider || !provider.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No MetaMask provider installed.", (exports.CheckoutErrorType).METAMASK_PROVIDER_ERROR);
|
|
2797
|
+
return new (providers.Web3Provider)(provider);
|
|
2798
|
+
}
|
|
2799
|
+
|
|
2800
|
+
|
|
2801
|
+
var $497c134ecbc8a50f$exports = {};
|
|
2802
|
+
$497c134ecbc8a50f$exports = JSON.parse('[{"chainId":1},{"chainId":5},{"chainId":137}]');
|
|
2803
|
+
|
|
2804
|
+
|
|
2805
|
+
const $de192de6ef100f9f$var$UNRECOGNISED_CHAIN_ERROR_CODE = 4902; // error code (MetaMask)
|
|
2806
|
+
async function $de192de6ef100f9f$export$79f13b4cfaaf0d09(provider) {
|
|
2807
|
+
return ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2808
|
+
const network = await provider.getNetwork();
|
|
2809
|
+
if (!Object.values((exports.ChainId)).includes(network.chainId)) // return empty details
|
|
2810
|
+
return {
|
|
2811
|
+
chainId: network.chainId,
|
|
2812
|
+
name: network.name,
|
|
2813
|
+
isSupported: false
|
|
2814
|
+
};
|
|
2815
|
+
const chainIdNetworkInfo = ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[network.chainId];
|
|
2816
|
+
return {
|
|
2817
|
+
name: chainIdNetworkInfo.chainName,
|
|
2818
|
+
chainId: parseInt(chainIdNetworkInfo.chainIdHex, 16),
|
|
2819
|
+
nativeCurrency: chainIdNetworkInfo.nativeCurrency,
|
|
2820
|
+
isSupported: true
|
|
2821
|
+
};
|
|
2822
|
+
}, {
|
|
2823
|
+
type: (exports.CheckoutErrorType).GET_NETWORK_INFO_ERROR
|
|
2824
|
+
});
|
|
2825
|
+
}
|
|
2826
|
+
async function $de192de6ef100f9f$export$b827d9418aeb5dbd(providerPreference, provider, chainId) {
|
|
2827
|
+
let currentProvider = provider;
|
|
2828
|
+
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);
|
|
2829
|
+
if (!currentProvider || !currentProvider.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Incompatible provider", (exports.CheckoutErrorType).PROVIDER_REQUEST_MISSING_ERROR, {
|
|
2830
|
+
details: `Unsupported provider`
|
|
2831
|
+
});
|
|
2188
2832
|
// WT-1146 - Refer to the README in this folder for explantion on the switch network flow
|
|
2189
2833
|
try {
|
|
2190
|
-
await $de192de6ef100f9f$var$switchNetworkInWallet(
|
|
2191
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2834
|
+
await $de192de6ef100f9f$var$switchNetworkInWallet(currentProvider, chainId);
|
|
2192
2835
|
} catch (err) {
|
|
2193
|
-
if (err.
|
|
2194
|
-
await $de192de6ef100f9f$var$addNetworkToWallet(
|
|
2195
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2836
|
+
if (err.code === $de192de6ef100f9f$var$UNRECOGNISED_CHAIN_ERROR_CODE) try {
|
|
2837
|
+
await $de192de6ef100f9f$var$addNetworkToWallet(currentProvider, chainId);
|
|
2196
2838
|
} catch (err) {
|
|
2197
|
-
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("
|
|
2839
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("User cancelled add network request", (exports.CheckoutErrorType).USER_REJECTED_REQUEST_ERROR);
|
|
2198
2840
|
}
|
|
2199
|
-
else throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("
|
|
2841
|
+
else throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("User cancelled switch network request", (exports.CheckoutErrorType).USER_REJECTED_REQUEST_ERROR);
|
|
2200
2842
|
}
|
|
2843
|
+
currentProvider = await ($c99672cf2294e839$export$fba2f6c3656e07c1)({
|
|
2844
|
+
providerPreference: providerPreference
|
|
2845
|
+
});
|
|
2846
|
+
if ((await currentProvider.getNetwork()).chainId !== chainId) // user didn't actually switch
|
|
2847
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("User cancelled switch network request", (exports.CheckoutErrorType).USER_REJECTED_REQUEST_ERROR);
|
|
2201
2848
|
// we can assume that if the above succeeds then user has successfully
|
|
2202
2849
|
// switched to the network specified
|
|
2203
2850
|
const newNetwork = ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId];
|
|
@@ -2206,7 +2853,28 @@ async function $de192de6ef100f9f$export$b827d9418aeb5dbd(provider, chainId) {
|
|
|
2206
2853
|
name: newNetwork.chainName,
|
|
2207
2854
|
chainId: parseInt(newNetwork.chainIdHex, 16),
|
|
2208
2855
|
nativeCurrency: newNetwork.nativeCurrency
|
|
2209
|
-
}
|
|
2856
|
+
},
|
|
2857
|
+
provider: currentProvider
|
|
2858
|
+
};
|
|
2859
|
+
}
|
|
2860
|
+
async function $de192de6ef100f9f$export$3043f6442a9ef563({ type: type = (exports.NetworkFilterTypes).ALL , exclude: exclude }) {
|
|
2861
|
+
const list = ((/*@__PURE__*/$parcel$interopDefault($497c134ecbc8a50f$exports))).filter((network)=>{
|
|
2862
|
+
const allowAllTokens = type === (exports.NetworkFilterTypes).ALL;
|
|
2863
|
+
const networkNotExcluded = !(exclude || []).map((exc)=>exc.chainId).includes(network.chainId);
|
|
2864
|
+
return allowAllTokens && networkNotExcluded;
|
|
2865
|
+
});
|
|
2866
|
+
const allowedNetworks = [];
|
|
2867
|
+
list.forEach((element)=>{
|
|
2868
|
+
const newNetwork = ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[element.chainId];
|
|
2869
|
+
allowedNetworks.push({
|
|
2870
|
+
name: newNetwork.chainName,
|
|
2871
|
+
chainId: parseInt(newNetwork.chainIdHex, 16),
|
|
2872
|
+
nativeCurrency: newNetwork.nativeCurrency,
|
|
2873
|
+
isSupported: true
|
|
2874
|
+
});
|
|
2875
|
+
});
|
|
2876
|
+
return {
|
|
2877
|
+
networks: allowedNetworks
|
|
2210
2878
|
};
|
|
2211
2879
|
}
|
|
2212
2880
|
// these functions should not be exported. These functions should be used as part of an exported function e.g switchWalletNetwork() above.
|
|
@@ -2243,67 +2911,24 @@ async function $de192de6ef100f9f$var$addNetworkToWallet(provider, chainId) {
|
|
|
2243
2911
|
|
|
2244
2912
|
|
|
2245
2913
|
|
|
2246
|
-
|
|
2247
|
-
(
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
const $
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
}
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
address: "0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0",
|
|
2263
|
-
decimals: 18,
|
|
2264
|
-
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"
|
|
2265
|
-
},
|
|
2266
|
-
{
|
|
2267
|
-
name: "Immutable X",
|
|
2268
|
-
symbol: "IMX",
|
|
2269
|
-
address: "0xF57e7e7C23978C3cAEC3C3548E3D615c346e79fF",
|
|
2270
|
-
decimals: 18,
|
|
2271
|
-
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"
|
|
2272
|
-
}
|
|
2273
|
-
];
|
|
2274
|
-
const $efe60cea83bfc4e8$var$goerliTokensList = [
|
|
2275
|
-
{
|
|
2276
|
-
name: "Ethereum",
|
|
2277
|
-
symbol: "ETH",
|
|
2278
|
-
decimals: 18,
|
|
2279
|
-
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"
|
|
2280
|
-
},
|
|
2281
|
-
{
|
|
2282
|
-
name: "Immutable X",
|
|
2283
|
-
symbol: "IMX",
|
|
2284
|
-
address: "0x1facdd0165489f373255a90304650e15481b2c85",
|
|
2285
|
-
decimals: 18,
|
|
2286
|
-
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"
|
|
2287
|
-
}
|
|
2288
|
-
];
|
|
2289
|
-
const $efe60cea83bfc4e8$var$polygonTokensList = [];
|
|
2290
|
-
const $efe60cea83bfc4e8$export$473cec51305fdae8 = (chainId)=>{
|
|
2291
|
-
let tokenList = [];
|
|
2292
|
-
switch(chainId){
|
|
2293
|
-
case (exports.ChainId).ETHEREUM:
|
|
2294
|
-
tokenList = $efe60cea83bfc4e8$export$3dbcce43073f40c7;
|
|
2295
|
-
break;
|
|
2296
|
-
case (exports.ChainId).GOERLI:
|
|
2297
|
-
tokenList = $efe60cea83bfc4e8$var$goerliTokensList;
|
|
2298
|
-
break;
|
|
2299
|
-
case (exports.ChainId).POLYGON:
|
|
2300
|
-
tokenList = $efe60cea83bfc4e8$var$polygonTokensList;
|
|
2301
|
-
break;
|
|
2302
|
-
default:
|
|
2303
|
-
tokenList = $efe60cea83bfc4e8$export$3dbcce43073f40c7;
|
|
2304
|
-
}
|
|
2914
|
+
var $cda6003506e4182e$exports = {};
|
|
2915
|
+
$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\"]}]");
|
|
2916
|
+
|
|
2917
|
+
|
|
2918
|
+
const $efe60cea83bfc4e8$export$473cec51305fdae8 = async function({ type: type = (exports.TokenFilterTypes).ALL , chainId: chainId , exclude: exclude }) {
|
|
2919
|
+
// todo:For API call, use the CheckoutError with errorType:API_CALL_ERROR?? or any other
|
|
2920
|
+
const filteredTokenList = ((/*@__PURE__*/$parcel$interopDefault($cda6003506e4182e$exports))).filter((token)=>{
|
|
2921
|
+
const chainIdMatches = token.chainId == chainId;
|
|
2922
|
+
const tokenNotExcluded = !exclude?.map((excludeToken)=>excludeToken.address).includes(token.address || "");
|
|
2923
|
+
const allowAllTokens = type === (exports.TokenFilterTypes).ALL;
|
|
2924
|
+
const tokenAllowedForType = token.tokenFeatures.includes(type);
|
|
2925
|
+
return chainIdMatches && tokenNotExcluded && (allowAllTokens || tokenAllowedForType);
|
|
2926
|
+
}).map((token)=>{
|
|
2927
|
+
const { chainId: chainId , tokenFeatures: tokenFeatures , ...tokenInfo } = token;
|
|
2928
|
+
return tokenInfo;
|
|
2929
|
+
});
|
|
2305
2930
|
return {
|
|
2306
|
-
tokens:
|
|
2931
|
+
tokens: filteredTokenList
|
|
2307
2932
|
};
|
|
2308
2933
|
};
|
|
2309
2934
|
|
|
@@ -2313,6 +2938,9 @@ const $efe60cea83bfc4e8$export$473cec51305fdae8 = (chainId)=>{
|
|
|
2313
2938
|
const $1564e43dde50bb61$export$df96cd8d56be0ab1 = async (provider, walletAddress)=>{
|
|
2314
2939
|
return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2315
2940
|
const networkInfo = await ($de192de6ef100f9f$export$79f13b4cfaaf0d09)(provider);
|
|
2941
|
+
if (!networkInfo.isSupported) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`Chain:${networkInfo.chainId} is not a supported chain`, (exports.CheckoutErrorType).CHAIN_NOT_SUPPORTED_ERROR, {
|
|
2942
|
+
chainName: networkInfo.name
|
|
2943
|
+
});
|
|
2316
2944
|
const balance = await provider.getBalance(walletAddress);
|
|
2317
2945
|
return {
|
|
2318
2946
|
balance: balance,
|
|
@@ -2320,7 +2948,7 @@ const $1564e43dde50bb61$export$df96cd8d56be0ab1 = async (provider, walletAddress
|
|
|
2320
2948
|
token: networkInfo.nativeCurrency
|
|
2321
2949
|
};
|
|
2322
2950
|
}, {
|
|
2323
|
-
type: (
|
|
2951
|
+
type: (exports.CheckoutErrorType).GET_BALANCE_ERROR
|
|
2324
2952
|
});
|
|
2325
2953
|
};
|
|
2326
2954
|
async function $1564e43dde50bb61$export$60e0fe116a0e6ed0(provider, walletAddress, contractAddress) {
|
|
@@ -2342,13 +2970,16 @@ async function $1564e43dde50bb61$export$60e0fe116a0e6ed0(provider, walletAddress
|
|
|
2342
2970
|
}
|
|
2343
2971
|
};
|
|
2344
2972
|
}, {
|
|
2345
|
-
type: (
|
|
2973
|
+
type: (exports.CheckoutErrorType).GET_ERC20_BALANCE_ERROR
|
|
2346
2974
|
});
|
|
2347
2975
|
}
|
|
2348
2976
|
const $1564e43dde50bb61$export$fee49741664a4d7e = async (provider, walletAddress, chainId)=>{
|
|
2349
|
-
if (!Object.values((exports.ChainId)).includes(chainId)) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`ChainId ${chainId} is not supported`, (
|
|
2350
|
-
if (!provider.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("provider object is missing request function", (
|
|
2351
|
-
const tokenList = ($efe60cea83bfc4e8$export$473cec51305fdae8)(
|
|
2977
|
+
if (!Object.values((exports.ChainId)).includes(chainId)) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`ChainId ${chainId} is not supported`, (exports.CheckoutErrorType).CHAIN_NOT_SUPPORTED_ERROR);
|
|
2978
|
+
if (!provider.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("provider object is missing request function", (exports.CheckoutErrorType).PROVIDER_REQUEST_MISSING_ERROR);
|
|
2979
|
+
const tokenList = await ($efe60cea83bfc4e8$export$473cec51305fdae8)({
|
|
2980
|
+
type: (exports.TokenFilterTypes).ALL,
|
|
2981
|
+
chainId: chainId
|
|
2982
|
+
});
|
|
2352
2983
|
const allBalancePromises = [];
|
|
2353
2984
|
allBalancePromises.push($1564e43dde50bb61$export$df96cd8d56be0ab1(provider, walletAddress));
|
|
2354
2985
|
tokenList.tokens.filter((token)=>token.address).forEach((token)=>allBalancePromises.push($1564e43dde50bb61$export$60e0fe116a0e6ed0(provider, walletAddress, token.address ?? "")));
|
|
@@ -2363,57 +2994,29 @@ const $1564e43dde50bb61$export$fee49741664a4d7e = async (provider, walletAddress
|
|
|
2363
2994
|
|
|
2364
2995
|
|
|
2365
2996
|
|
|
2366
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2367
2997
|
|
|
2368
2998
|
|
|
2369
2999
|
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
3000
|
+
|
|
3001
|
+
var $6f3c55a615003cbf$exports = {};
|
|
3002
|
+
$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"]}]');
|
|
3003
|
+
|
|
3004
|
+
|
|
3005
|
+
async function $5cdde2ffe6360fec$export$a822caa90d7eef09({ type: type = (exports.WalletFilterTypes).ALL , exclude: exclude }) {
|
|
3006
|
+
// todo:For async API call, use the CheckoutError with errorType:API_CALL_ERROR?? or any other
|
|
3007
|
+
const filteredWalletsList = ((/*@__PURE__*/$parcel$interopDefault($6f3c55a615003cbf$exports))).filter((wallet)=>{
|
|
3008
|
+
const walletNotExcluded = !exclude?.map((excludeWallet)=>excludeWallet.connectionProvider).includes(wallet.connectionProvider);
|
|
3009
|
+
const allowAllWallets = type === (exports.WalletFilterTypes).ALL;
|
|
3010
|
+
const walletsAllowedForType = wallet.platform.includes(type);
|
|
3011
|
+
return walletNotExcluded && (allowAllWallets || walletsAllowedForType);
|
|
3012
|
+
}).map((wallet)=>{
|
|
3013
|
+
const { platform: platform , ...walletInfo } = wallet;
|
|
3014
|
+
return walletInfo;
|
|
2376
3015
|
});
|
|
2377
|
-
// accounts[0] will have the active account if connected.
|
|
2378
3016
|
return {
|
|
2379
|
-
|
|
2380
|
-
walletAddress: accounts[0] ?? ""
|
|
3017
|
+
wallets: filteredWalletsList
|
|
2381
3018
|
};
|
|
2382
3019
|
}
|
|
2383
|
-
async function $c99672cf2294e839$export$fba2f6c3656e07c1(params) {
|
|
2384
|
-
const web3Provider = await $c99672cf2294e839$var$getWalletProviderForPreference(params.providerPreference);
|
|
2385
|
-
await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2386
|
-
if (!web3Provider || !web3Provider?.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No MetaMask provider installed.", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).METAMASK_PROVIDER_ERROR);
|
|
2387
|
-
// this makes the request to the wallet to connect i.e request eth accounts ('eth_requestAccounts')
|
|
2388
|
-
await web3Provider.provider.request({
|
|
2389
|
-
method: ($4f91c5f280efe242$export$a130407f3423b97d).CONNECT,
|
|
2390
|
-
params: []
|
|
2391
|
-
});
|
|
2392
|
-
}, {
|
|
2393
|
-
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR
|
|
2394
|
-
});
|
|
2395
|
-
return web3Provider;
|
|
2396
|
-
}
|
|
2397
|
-
async function $c99672cf2294e839$var$getWalletProviderForPreference(providerPreference) {
|
|
2398
|
-
let web3Provider = null;
|
|
2399
|
-
switch(providerPreference){
|
|
2400
|
-
case (exports.ConnectionProviders).METAMASK:
|
|
2401
|
-
web3Provider = await $c99672cf2294e839$var$getMetaMaskProvider();
|
|
2402
|
-
break;
|
|
2403
|
-
default:
|
|
2404
|
-
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Provider preference was not detected", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CONNECT_PROVIDER_ERROR);
|
|
2405
|
-
}
|
|
2406
|
-
return web3Provider;
|
|
2407
|
-
}
|
|
2408
|
-
async function $c99672cf2294e839$var$getMetaMaskProvider() {
|
|
2409
|
-
const provider = await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2410
|
-
return await (detectEthereumProvider)();
|
|
2411
|
-
}, {
|
|
2412
|
-
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).METAMASK_PROVIDER_ERROR
|
|
2413
|
-
});
|
|
2414
|
-
if (!provider || !provider.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No MetaMask provider installed.", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).METAMASK_PROVIDER_ERROR);
|
|
2415
|
-
return new (providers.Web3Provider)(provider);
|
|
2416
|
-
}
|
|
2417
3020
|
|
|
2418
3021
|
|
|
2419
3022
|
|
|
@@ -2428,41 +3031,105 @@ const $dbe95599a4661140$export$8e0e7ffc78696d30 = async (params)=>{
|
|
|
2428
3031
|
transactionResponse: transactionResponse
|
|
2429
3032
|
};
|
|
2430
3033
|
}, {
|
|
2431
|
-
type: (
|
|
3034
|
+
type: (exports.CheckoutErrorType).TRANSACTION_ERROR
|
|
2432
3035
|
});
|
|
2433
3036
|
};
|
|
2434
3037
|
|
|
2435
3038
|
|
|
2436
3039
|
|
|
2437
3040
|
|
|
3041
|
+
|
|
2438
3042
|
class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
|
|
2439
|
-
|
|
3043
|
+
/**
|
|
3044
|
+
* Check if a wallet is connected to the current application without requesting permission from the wallet and hence triggering a connect popup.
|
|
3045
|
+
* @param {CheckConnectionParams} params - The necessary data required to verify a wallet connection status.
|
|
3046
|
+
* @returns Wallet connection status details.
|
|
3047
|
+
* @throws {@link ErrorType}
|
|
3048
|
+
*/ async checkIsWalletConnected(params) {
|
|
2440
3049
|
return $c99672cf2294e839$export$2d040992269b4717(params.providerPreference);
|
|
2441
3050
|
}
|
|
2442
|
-
|
|
3051
|
+
/**
|
|
3052
|
+
* Establish a connection with a wallet provider such as MetaMask and returns the provider object and the current network details.
|
|
3053
|
+
* @param {ConnectParams} params - The necessary data required to establish a connection with a wallet provider.
|
|
3054
|
+
* @returns Wallet provider and current network information.
|
|
3055
|
+
* @throws {@link ErrorType}
|
|
3056
|
+
*/ async connect(params) {
|
|
3057
|
+
this.providerPreference = params.providerPreference;
|
|
2443
3058
|
const provider = await $c99672cf2294e839$export$fba2f6c3656e07c1(params);
|
|
2444
|
-
const
|
|
3059
|
+
const networkInfo = await $de192de6ef100f9f$export$79f13b4cfaaf0d09(provider);
|
|
2445
3060
|
return {
|
|
2446
3061
|
provider: provider,
|
|
2447
|
-
network:
|
|
3062
|
+
network: networkInfo
|
|
2448
3063
|
};
|
|
2449
3064
|
}
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
3065
|
+
/**
|
|
3066
|
+
* Switch the currently connected wallet to a new network.
|
|
3067
|
+
* @param {SwitchNetworkParams} params - The necessary data required to switch network.
|
|
3068
|
+
* @returns The new network information.
|
|
3069
|
+
* @throws {@link ErrorType}
|
|
3070
|
+
*/ async switchNetwork(params) {
|
|
3071
|
+
if (!this.providerPreference) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`connect should be called before switchNetwork to set the provider preference`, (exports.CheckoutErrorType).PROVIDER_PREFERENCE_ERROR);
|
|
3072
|
+
return await $de192de6ef100f9f$export$b827d9418aeb5dbd(this.providerPreference, params.provider, params.chainId);
|
|
3073
|
+
}
|
|
3074
|
+
/**
|
|
3075
|
+
* 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.
|
|
3076
|
+
* @param {GetBalanceParams} params - The necessary data required to fetch the wallet balance.
|
|
3077
|
+
* @returns Native token balance for the given wallet.
|
|
3078
|
+
* @throws {@link ErrorType}
|
|
3079
|
+
*/ async getBalance(params) {
|
|
2454
3080
|
if (!params.contractAddress || params.contractAddress === "") return await $1564e43dde50bb61$export$df96cd8d56be0ab1(params.provider, params.walletAddress);
|
|
2455
3081
|
return await $1564e43dde50bb61$export$60e0fe116a0e6ed0(params.provider, params.walletAddress, params.contractAddress);
|
|
2456
3082
|
}
|
|
2457
|
-
|
|
3083
|
+
/**
|
|
3084
|
+
* 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.
|
|
3085
|
+
* @param {GetAllBalancesParams} params - The necessary data required to fetch all the wallet balances.
|
|
3086
|
+
* @returns List of tokens balance for the given wallet.
|
|
3087
|
+
* @throws {@link ErrorType}
|
|
3088
|
+
*/ async getAllBalances(params) {
|
|
2458
3089
|
return $1564e43dde50bb61$export$fee49741664a4d7e(params.provider, params.walletAddress, params.chainId);
|
|
2459
3090
|
}
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
3091
|
+
/**
|
|
3092
|
+
* Fetch the list of available networks that a wallet can add or/and switch to.
|
|
3093
|
+
* @param {GetNetworkAllowListParams} params - The necessary data required to fetch the list of available networks.
|
|
3094
|
+
* @returns List of networks.
|
|
3095
|
+
* @throws {@link ErrorType}
|
|
3096
|
+
*/ async getNetworkAllowList(params) {
|
|
3097
|
+
return await $de192de6ef100f9f$export$3043f6442a9ef563(params);
|
|
3098
|
+
}
|
|
3099
|
+
/**
|
|
3100
|
+
* Get the list of tokens which are allowed to be used with the product.
|
|
3101
|
+
* @param {GetTokenAllowListParams} params - The necessary data required to fetch the list of allowed tokens.
|
|
3102
|
+
* @returns List of allowed tokens.
|
|
3103
|
+
* @throws {@link ErrorType}
|
|
3104
|
+
*/ async getTokenAllowList(params) {
|
|
3105
|
+
return await $efe60cea83bfc4e8$export$473cec51305fdae8(params);
|
|
3106
|
+
}
|
|
3107
|
+
/**
|
|
3108
|
+
* Fetch the list of wallets which are available to connect with.
|
|
3109
|
+
* @param {GetWalletAllowListParams} params - The necessary data required to fetch the list of allowed wallets.
|
|
3110
|
+
* @returns List of allowed wallets.
|
|
3111
|
+
* @throws {@link ErrorType}
|
|
3112
|
+
*/ async getWalletAllowList(params) {
|
|
3113
|
+
return await $5cdde2ffe6360fec$export$a822caa90d7eef09(params);
|
|
3114
|
+
}
|
|
3115
|
+
/**
|
|
3116
|
+
* Send a generic transaction to the provider.
|
|
3117
|
+
* @param {SendTransactionParams} params - The necessary data required to send a transaction.
|
|
3118
|
+
* @returns Transaction response.
|
|
3119
|
+
* @throws {@link ErrorType}
|
|
3120
|
+
* @remarks
|
|
3121
|
+
* Further documenation can be found at [MetaMask | Sending Transactions](https://docs.metamask.io/guide/sending-transactions.html).
|
|
3122
|
+
*/ async sendTransaction(params) {
|
|
2464
3123
|
return await $dbe95599a4661140$export$8e0e7ffc78696d30(params);
|
|
2465
3124
|
}
|
|
3125
|
+
/**
|
|
3126
|
+
* Get network information about the currently selected network.
|
|
3127
|
+
* @param {GetNetworkParams} params - The necessary data required to get the current network information.
|
|
3128
|
+
* @returns Network details.
|
|
3129
|
+
* @throws {@link ErrorType}
|
|
3130
|
+
*/ async getNetworkInfo(params) {
|
|
3131
|
+
return await $de192de6ef100f9f$export$79f13b4cfaaf0d09(params.provider);
|
|
3132
|
+
}
|
|
2466
3133
|
}
|
|
2467
3134
|
|
|
2468
3135
|
function $parcel$export(e, n, v, s) {
|
|
@@ -2488,6 +3155,7 @@ exports.ConnectEventType = void 0;
|
|
|
2488
3155
|
(function(ConnectEventType) {
|
|
2489
3156
|
ConnectEventType["SUCCESS"] = "success";
|
|
2490
3157
|
ConnectEventType["FAILURE"] = "failure";
|
|
3158
|
+
ConnectEventType["CLOSE_WIDGET"] = "close-widget";
|
|
2491
3159
|
})(exports.ConnectEventType || (exports.ConnectEventType = {}));
|
|
2492
3160
|
|
|
2493
3161
|
|
|
@@ -2554,13 +3222,20 @@ exports.WidgetTheme = void 0;
|
|
|
2554
3222
|
WidgetTheme["CUSTOM"] = "custom";
|
|
2555
3223
|
})(exports.WidgetTheme || (exports.WidgetTheme = {}));
|
|
2556
3224
|
|
|
3225
|
+
Object.defineProperty(exports, 'imxClientCreateStarkSigner', {
|
|
3226
|
+
enumerable: true,
|
|
3227
|
+
get: function () { return coreSdk.createStarkSigner; }
|
|
3228
|
+
});
|
|
3229
|
+
Object.defineProperty(exports, 'imxClientGenerateLegacyStarkPrivateKey', {
|
|
3230
|
+
enumerable: true,
|
|
3231
|
+
get: function () { return coreSdk.generateLegacyStarkPrivateKey; }
|
|
3232
|
+
});
|
|
2557
3233
|
exports.Checkout = $a8cb37a3fc8eb863$export$1f60ba4ec72508a0;
|
|
2558
|
-
exports.Config = Config;
|
|
2559
|
-
exports.Configuration = Configuration;
|
|
2560
3234
|
exports.GenericIMXProvider = GenericIMXProvider;
|
|
3235
|
+
exports.ImmutableConfiguration = ImmutableConfiguration;
|
|
3236
|
+
exports.ImmutableXClient = ImmutableXClient;
|
|
2561
3237
|
exports.MetaMaskIMXProvider = MetaMaskIMXProvider;
|
|
2562
|
-
exports.PRODUCTION = PRODUCTION;
|
|
2563
3238
|
exports.Passport = Passport;
|
|
3239
|
+
exports.PassportConfiguration = PassportConfiguration;
|
|
2564
3240
|
exports.PassportError = PassportError;
|
|
2565
|
-
exports.
|
|
2566
|
-
exports.StarkExAPIFactory = StarkExAPIFactory;
|
|
3241
|
+
exports.ProviderConfiguration = ProviderConfiguration;
|