@imtbl/sdk 0.0.1-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base.d.ts +18 -0
- package/dist/base.js +15 -0
- package/dist/browser/checkout.js +2 -0
- package/dist/checkout_sdk.d.ts +673 -0
- package/dist/checkout_sdk.js +471 -0
- package/dist/checkout_widgets.d.ts +14444 -0
- package/dist/checkout_widgets.js +185 -0
- package/dist/index.cjs +2576 -0
- package/dist/index.d.ts +23898 -0
- package/dist/index.js +2547 -0
- package/dist/passport.d.ts +736 -0
- package/dist/passport.js +910 -0
- package/dist/provider.d.ts +962 -0
- package/dist/provider.js +1139 -0
- package/dist/starkex.d.ts +8421 -0
- package/dist/starkex.js +10 -0
- package/package.json +97 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2576 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var coreSdk = require('@imtbl/core-sdk');
|
|
4
|
+
var BN = require('bn.js');
|
|
5
|
+
var encUtils = require('enc-utils');
|
|
6
|
+
var units = require('@ethersproject/units');
|
|
7
|
+
var bignumber = require('@ethersproject/bignumber');
|
|
8
|
+
var ethers = require('ethers');
|
|
9
|
+
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
|
+
var providers = require('@ethersproject/providers');
|
|
14
|
+
|
|
15
|
+
function _interopNamespaceDefault(e) {
|
|
16
|
+
var n = Object.create(null);
|
|
17
|
+
if (e) {
|
|
18
|
+
Object.keys(e).forEach(function (k) {
|
|
19
|
+
if (k !== 'default') {
|
|
20
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
21
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () { return e[k]; }
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
n.default = e;
|
|
29
|
+
return Object.freeze(n);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var encUtils__namespace = /*#__PURE__*/_interopNamespaceDefault(encUtils);
|
|
33
|
+
|
|
34
|
+
exports.Environment = void 0;
|
|
35
|
+
(function (Environment) {
|
|
36
|
+
Environment["PRODUCTION"] = "production";
|
|
37
|
+
Environment["SANDBOX"] = "sandbox";
|
|
38
|
+
})(exports.Environment || (exports.Environment = {}));
|
|
39
|
+
class ImmutableConfiguration {
|
|
40
|
+
environment;
|
|
41
|
+
apiKey;
|
|
42
|
+
constructor(options) {
|
|
43
|
+
this.environment = options.environment;
|
|
44
|
+
this.apiKey = options.apiKey;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
49
|
+
const StarkExAPIFactory = (config) => {
|
|
50
|
+
const imtblClient = new coreSdk.ImmutableX(config.immutableXConfig);
|
|
51
|
+
const { deposit, registerOffchain, isRegisteredOnchain, prepareWithdrawal, completeWithdrawal, createOrder, cancelOrder, createTrade, transfer, batchNftTransfer, ...StarkEx } = imtblClient;
|
|
52
|
+
return { ...StarkEx };
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// used to sign message with L1 keys. Used for registration
|
|
56
|
+
function serializeEthSignature(sig) {
|
|
57
|
+
// This is because golang appends a recovery param
|
|
58
|
+
// https://github.com/ethers-io/ethers.js/issues/823
|
|
59
|
+
return encUtils__namespace.addHexPrefix(encUtils__namespace.padLeft(sig.r.toString(16), 64) +
|
|
60
|
+
encUtils__namespace.padLeft(sig.s.toString(16), 64) +
|
|
61
|
+
encUtils__namespace.padLeft(sig.recoveryParam?.toString(16) || '', 2));
|
|
62
|
+
}
|
|
63
|
+
function importRecoveryParam(v) {
|
|
64
|
+
return v.trim()
|
|
65
|
+
? new BN(v, 16).cmp(new BN(27)) !== -1
|
|
66
|
+
? new BN(v, 16).sub(new BN(27)).toNumber()
|
|
67
|
+
: new BN(v, 16).toNumber()
|
|
68
|
+
: undefined;
|
|
69
|
+
}
|
|
70
|
+
// used chained with serializeEthSignature. serializeEthSignature(deserializeSignature(...))
|
|
71
|
+
function deserializeSignature(sig, size = 64) {
|
|
72
|
+
sig = encUtils__namespace.removeHexPrefix(sig);
|
|
73
|
+
return {
|
|
74
|
+
r: new BN(sig.substring(0, size), 'hex'),
|
|
75
|
+
s: new BN(sig.substring(size, size * 2), 'hex'),
|
|
76
|
+
recoveryParam: importRecoveryParam(sig.substring(size * 2, size * 2 + 2)),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
async function signRaw(payload, signer) {
|
|
80
|
+
const signature = deserializeSignature(await signer.signMessage(payload));
|
|
81
|
+
return serializeEthSignature(signature);
|
|
82
|
+
}
|
|
83
|
+
async function signMessage(message, signer) {
|
|
84
|
+
const ethAddress = await signer.getAddress();
|
|
85
|
+
const ethSignature = await signRaw(message, signer);
|
|
86
|
+
return {
|
|
87
|
+
message,
|
|
88
|
+
ethAddress,
|
|
89
|
+
ethSignature,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Helper method to convert token type to a SignableToken type
|
|
95
|
+
* @param token - the token type to convert to a SignableToken type
|
|
96
|
+
* @returns the converted SignableToken
|
|
97
|
+
*/
|
|
98
|
+
function convertToSignableToken(token) {
|
|
99
|
+
switch (token.type) {
|
|
100
|
+
case 'ERC721':
|
|
101
|
+
return {
|
|
102
|
+
type: 'ERC721',
|
|
103
|
+
data: {
|
|
104
|
+
token_id: token.tokenId,
|
|
105
|
+
token_address: token.tokenAddress,
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
case 'ERC20':
|
|
109
|
+
return {
|
|
110
|
+
type: 'ERC20',
|
|
111
|
+
data: {
|
|
112
|
+
token_address: token.tokenAddress,
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
case 'ETH':
|
|
116
|
+
return {
|
|
117
|
+
type: 'ETH',
|
|
118
|
+
data: {
|
|
119
|
+
decimals: 18,
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function isChainValid(chainID, config) {
|
|
126
|
+
return chainID === config.ethConfiguration.chainID;
|
|
127
|
+
}
|
|
128
|
+
async function validateChain(signer, config) {
|
|
129
|
+
const chainID = await signer.getChainId();
|
|
130
|
+
if (!isChainValid(chainID, config))
|
|
131
|
+
throw new Error('The wallet used for this operation is not connected to the correct network.');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async function transfer$1({ signers: { ethSigner, starkExSigner }, request, config, }) {
|
|
135
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
136
|
+
const ethAddress = await ethSigner.getAddress();
|
|
137
|
+
const transfersApi = new coreSdk.TransfersApi(config.immutableXConfig.apiConfiguration);
|
|
138
|
+
const transferAmount = request.type === 'ERC721' ? '1' : request.amount;
|
|
139
|
+
const signableResult = await transfersApi.getSignableTransferV1({
|
|
140
|
+
getSignableTransferRequest: {
|
|
141
|
+
sender: ethAddress,
|
|
142
|
+
token: convertToSignableToken(request),
|
|
143
|
+
amount: transferAmount,
|
|
144
|
+
receiver: request.receiver,
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
148
|
+
const ethSignature = await signRaw(signableMessage, ethSigner);
|
|
149
|
+
const starkSignature = await starkExSigner.signMessage(payloadHash);
|
|
150
|
+
const transferSigningParams = {
|
|
151
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
152
|
+
sender_stark_key: signableResult.data.sender_stark_key,
|
|
153
|
+
sender_vault_id: signableResult.data.sender_vault_id,
|
|
154
|
+
receiver_stark_key: signableResult.data.receiver_stark_key,
|
|
155
|
+
receiver_vault_id: signableResult.data.receiver_vault_id,
|
|
156
|
+
asset_id: signableResult.data.asset_id,
|
|
157
|
+
amount: signableResult.data.amount,
|
|
158
|
+
nonce: signableResult.data.nonce,
|
|
159
|
+
expiration_timestamp: signableResult.data.expiration_timestamp,
|
|
160
|
+
stark_signature: starkSignature,
|
|
161
|
+
};
|
|
162
|
+
const response = await transfersApi.createTransferV1({
|
|
163
|
+
createTransferRequest: transferSigningParams,
|
|
164
|
+
xImxEthAddress: ethAddress,
|
|
165
|
+
xImxEthSignature: ethSignature,
|
|
166
|
+
});
|
|
167
|
+
return {
|
|
168
|
+
sent_signature: response?.data.sent_signature,
|
|
169
|
+
status: response?.data.status?.toString(),
|
|
170
|
+
time: response?.data.time,
|
|
171
|
+
transfer_id: response?.data.transfer_id,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
async function batchTransfer({ signers: { ethSigner, starkExSigner }, request, config, }) {
|
|
175
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
176
|
+
const ethAddress = await ethSigner.getAddress();
|
|
177
|
+
const transfersApi = new coreSdk.TransfersApi(config.immutableXConfig.apiConfiguration);
|
|
178
|
+
const signableRequests = request.map((nftTransfer) => {
|
|
179
|
+
return {
|
|
180
|
+
amount: '1',
|
|
181
|
+
token: convertToSignableToken({
|
|
182
|
+
type: 'ERC721',
|
|
183
|
+
tokenId: nftTransfer.tokenId,
|
|
184
|
+
tokenAddress: nftTransfer.tokenAddress,
|
|
185
|
+
}),
|
|
186
|
+
receiver: nftTransfer.receiver,
|
|
187
|
+
};
|
|
188
|
+
});
|
|
189
|
+
const signableResult = await transfersApi.getSignableTransfer({
|
|
190
|
+
getSignableTransferRequestV2: {
|
|
191
|
+
sender_ether_key: ethAddress,
|
|
192
|
+
signable_requests: signableRequests,
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
const signableMessage = signableResult.data.signable_message;
|
|
196
|
+
if (signableMessage === undefined) {
|
|
197
|
+
throw new Error('Invalid response from Signable registration offchain');
|
|
198
|
+
}
|
|
199
|
+
const ethSignature = await signRaw(signableMessage, ethSigner);
|
|
200
|
+
const requests = [];
|
|
201
|
+
for (const resp of signableResult.data.signable_responses) {
|
|
202
|
+
const starkSignature = await starkExSigner.signMessage(resp.payload_hash);
|
|
203
|
+
const req = {
|
|
204
|
+
sender_vault_id: resp.sender_vault_id,
|
|
205
|
+
receiver_stark_key: resp.receiver_stark_key,
|
|
206
|
+
receiver_vault_id: resp.receiver_vault_id,
|
|
207
|
+
asset_id: resp.asset_id,
|
|
208
|
+
amount: resp.amount,
|
|
209
|
+
nonce: resp.nonce,
|
|
210
|
+
expiration_timestamp: resp.expiration_timestamp,
|
|
211
|
+
stark_signature: starkSignature,
|
|
212
|
+
};
|
|
213
|
+
requests.push(req);
|
|
214
|
+
}
|
|
215
|
+
// TODO: throw error on missing payload hash?
|
|
216
|
+
const transferSigningParams = {
|
|
217
|
+
sender_stark_key: signableResult.data.sender_stark_key,
|
|
218
|
+
requests,
|
|
219
|
+
};
|
|
220
|
+
const response = await transfersApi.createTransfer({
|
|
221
|
+
createTransferRequestV2: transferSigningParams,
|
|
222
|
+
xImxEthAddress: ethAddress,
|
|
223
|
+
xImxEthSignature: ethSignature,
|
|
224
|
+
});
|
|
225
|
+
return {
|
|
226
|
+
transfer_ids: response?.data.transfer_ids,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async function createOrder$1({ signers, request, config, }) {
|
|
231
|
+
await validateChain(signers.ethSigner, config.immutableXConfig);
|
|
232
|
+
const ethAddress = await signers.ethSigner.getAddress();
|
|
233
|
+
const ordersApi = new coreSdk.OrdersApi(config.immutableXConfig.apiConfiguration);
|
|
234
|
+
const amountSell = request.sell.type === 'ERC721' ? '1' : request.sell.amount;
|
|
235
|
+
const amountBuy = request.buy.type === 'ERC721' ? '1' : request.buy.amount;
|
|
236
|
+
const getSignableOrderRequest = {
|
|
237
|
+
user: ethAddress,
|
|
238
|
+
amount_buy: amountBuy,
|
|
239
|
+
token_buy: convertToSignableToken(request.buy),
|
|
240
|
+
amount_sell: amountSell,
|
|
241
|
+
token_sell: convertToSignableToken(request.sell),
|
|
242
|
+
fees: request.fees,
|
|
243
|
+
expiration_timestamp: request.expiration_timestamp,
|
|
244
|
+
};
|
|
245
|
+
const getSignableOrderResponse = await ordersApi.getSignableOrder({
|
|
246
|
+
getSignableOrderRequestV3: getSignableOrderRequest,
|
|
247
|
+
});
|
|
248
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = getSignableOrderResponse.data;
|
|
249
|
+
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
250
|
+
const starkSignature = await signers.starkExSigner.signMessage(payloadHash);
|
|
251
|
+
const resp = getSignableOrderResponse.data;
|
|
252
|
+
const orderParams = {
|
|
253
|
+
createOrderRequest: {
|
|
254
|
+
amount_buy: resp.amount_buy,
|
|
255
|
+
amount_sell: resp.amount_sell,
|
|
256
|
+
asset_id_buy: resp.asset_id_buy,
|
|
257
|
+
asset_id_sell: resp.asset_id_sell,
|
|
258
|
+
expiration_timestamp: resp.expiration_timestamp,
|
|
259
|
+
include_fees: true,
|
|
260
|
+
fees: request.fees,
|
|
261
|
+
nonce: resp.nonce,
|
|
262
|
+
stark_key: resp.stark_key,
|
|
263
|
+
stark_signature: starkSignature,
|
|
264
|
+
vault_id_buy: resp.vault_id_buy,
|
|
265
|
+
vault_id_sell: resp.vault_id_sell,
|
|
266
|
+
},
|
|
267
|
+
xImxEthAddress: ethAddress,
|
|
268
|
+
xImxEthSignature: ethSignature,
|
|
269
|
+
};
|
|
270
|
+
const createOrderResponse = await ordersApi.createOrder(orderParams);
|
|
271
|
+
return {
|
|
272
|
+
...createOrderResponse.data,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
async function cancelOrder$1({ signers, request, config, }) {
|
|
276
|
+
const ordersApi = new coreSdk.OrdersApi(config.immutableXConfig.apiConfiguration);
|
|
277
|
+
const getSignableCancelOrderResponse = await ordersApi.getSignableCancelOrder({
|
|
278
|
+
getSignableCancelOrderRequest: {
|
|
279
|
+
order_id: request.order_id,
|
|
280
|
+
},
|
|
281
|
+
});
|
|
282
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = getSignableCancelOrderResponse.data;
|
|
283
|
+
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
284
|
+
const starkSignature = await signers.starkExSigner.signMessage(payloadHash);
|
|
285
|
+
const ethAddress = await signers.ethSigner.getAddress();
|
|
286
|
+
const cancelOrderResponse = await ordersApi.cancelOrder({
|
|
287
|
+
id: request.order_id.toString(),
|
|
288
|
+
cancelOrderRequest: {
|
|
289
|
+
order_id: request.order_id,
|
|
290
|
+
stark_signature: starkSignature,
|
|
291
|
+
},
|
|
292
|
+
xImxEthAddress: ethAddress,
|
|
293
|
+
xImxEthSignature: ethSignature,
|
|
294
|
+
});
|
|
295
|
+
return {
|
|
296
|
+
order_id: cancelOrderResponse.data.order_id,
|
|
297
|
+
status: cancelOrderResponse.data.status,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
async function registerOffchain(signers, config) {
|
|
302
|
+
await validateChain(signers.ethSigner, config.immutableXConfig);
|
|
303
|
+
const usersApi = new coreSdk.UsersApi(config.immutableXConfig.apiConfiguration);
|
|
304
|
+
const userAddress = await signers.ethSigner.getAddress();
|
|
305
|
+
const starkPublicKey = await signers.starkExSigner.getAddress();
|
|
306
|
+
const signableResult = await usersApi.getSignableRegistrationOffchain({
|
|
307
|
+
getSignableRegistrationRequest: {
|
|
308
|
+
ether_key: userAddress,
|
|
309
|
+
stark_key: starkPublicKey,
|
|
310
|
+
},
|
|
311
|
+
});
|
|
312
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
313
|
+
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
314
|
+
const starkSignature = await signers.starkExSigner.signMessage(payloadHash);
|
|
315
|
+
const registeredUser = await usersApi.registerUser({
|
|
316
|
+
registerUserRequest: {
|
|
317
|
+
eth_signature: ethSignature,
|
|
318
|
+
ether_key: userAddress,
|
|
319
|
+
stark_signature: starkSignature,
|
|
320
|
+
stark_key: starkPublicKey,
|
|
321
|
+
},
|
|
322
|
+
});
|
|
323
|
+
return registeredUser.data;
|
|
324
|
+
}
|
|
325
|
+
async function isRegisteredOnChain(starkPublicKey, ethSigner, config) {
|
|
326
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
327
|
+
const registrationContract = coreSdk.Contracts.Registration.connect(config.immutableXConfig.ethConfiguration.registrationContractAddress, ethSigner);
|
|
328
|
+
try {
|
|
329
|
+
return await registrationContract.isRegistered(starkPublicKey);
|
|
330
|
+
}
|
|
331
|
+
catch (ex) {
|
|
332
|
+
if (ex.reason === 'USER_UNREGISTERED') {
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
throw ex;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
async function getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi) {
|
|
339
|
+
const response = await usersApi.getSignableRegistration({
|
|
340
|
+
getSignableRegistrationRequest: {
|
|
341
|
+
ether_key: etherKey,
|
|
342
|
+
stark_key: starkPublicKey,
|
|
343
|
+
},
|
|
344
|
+
});
|
|
345
|
+
return {
|
|
346
|
+
operator_signature: response.data.operator_signature,
|
|
347
|
+
payload_hash: response.data.payload_hash,
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const assertIsDefined = (value) => {
|
|
352
|
+
if (value !== undefined)
|
|
353
|
+
return value;
|
|
354
|
+
throw new Error('undefined field exception');
|
|
355
|
+
};
|
|
356
|
+
async function prepareWithdrawalAction(params) {
|
|
357
|
+
const { signers: { ethSigner, starkExSigner }, type, config, } = params;
|
|
358
|
+
await validateChain(ethSigner, params.config);
|
|
359
|
+
const withdrawalsApi = new coreSdk.WithdrawalsApi(config.apiConfiguration);
|
|
360
|
+
const withdrawalAmount = type === 'ERC721' ? '1' : params.amount;
|
|
361
|
+
const signableWithdrawalResult = await withdrawalsApi.getSignableWithdrawal({
|
|
362
|
+
getSignableWithdrawalRequest: {
|
|
363
|
+
user: await ethSigner.getAddress(),
|
|
364
|
+
token: convertToSignableToken(params),
|
|
365
|
+
amount: withdrawalAmount,
|
|
366
|
+
},
|
|
367
|
+
});
|
|
368
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = signableWithdrawalResult.data;
|
|
369
|
+
const starkSignature = await starkExSigner.signMessage(payloadHash);
|
|
370
|
+
const { ethAddress, ethSignature } = await signMessage(signableMessage, ethSigner);
|
|
371
|
+
const prepareWithdrawalResponse = await withdrawalsApi.createWithdrawal({
|
|
372
|
+
createWithdrawalRequest: {
|
|
373
|
+
stark_key: assertIsDefined(signableWithdrawalResult.data.stark_key),
|
|
374
|
+
amount: withdrawalAmount,
|
|
375
|
+
asset_id: assertIsDefined(signableWithdrawalResult.data.asset_id),
|
|
376
|
+
vault_id: assertIsDefined(signableWithdrawalResult.data.vault_id),
|
|
377
|
+
nonce: assertIsDefined(signableWithdrawalResult.data.nonce),
|
|
378
|
+
stark_signature: starkSignature,
|
|
379
|
+
},
|
|
380
|
+
xImxEthAddress: ethAddress,
|
|
381
|
+
xImxEthSignature: ethSignature,
|
|
382
|
+
});
|
|
383
|
+
return prepareWithdrawalResponse.data;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
async function getEncodeAssetInfo(assetType, tokenType, config, tokenData) {
|
|
387
|
+
const encodingApi = new coreSdk.EncodingApi(config.apiConfiguration);
|
|
388
|
+
const result = await encodingApi.encodeAsset({
|
|
389
|
+
assetType,
|
|
390
|
+
encodeAssetRequest: {
|
|
391
|
+
token: {
|
|
392
|
+
type: tokenType,
|
|
393
|
+
...(tokenData && { data: tokenData }),
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
});
|
|
397
|
+
return result.data;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
async function executeRegisterAndWithdrawERC20({ ethSigner, assetType, starkPublicKey, config, }) {
|
|
401
|
+
const etherKey = await ethSigner.getAddress();
|
|
402
|
+
const starkExConfig = config.immutableXConfig;
|
|
403
|
+
const usersApi = new coreSdk.UsersApi(starkExConfig.apiConfiguration);
|
|
404
|
+
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
405
|
+
const contract = coreSdk.Contracts.Registration.connect(config.immutableXConfig.ethConfiguration.registrationContractAddress, ethSigner);
|
|
406
|
+
const populatedTransaction = await contract.populateTransaction.registerAndWithdraw(etherKey, starkPublicKey, signableResult.operator_signature, assetType);
|
|
407
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
408
|
+
}
|
|
409
|
+
async function executeWithdrawERC20(ethSigner, assetType, starkPublicKey, config) {
|
|
410
|
+
const contract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
411
|
+
const populatedTransaction = await contract.populateTransaction.withdraw(starkPublicKey, assetType);
|
|
412
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
413
|
+
}
|
|
414
|
+
async function completeERC20WithdrawalAction({ ethSigner, starkPublicKey, token, config, }) {
|
|
415
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
416
|
+
const starkExConfig = config.immutableXConfig;
|
|
417
|
+
const assetType = await getEncodeAssetInfo('asset', 'ERC20', starkExConfig, {
|
|
418
|
+
token_address: token.tokenAddress,
|
|
419
|
+
});
|
|
420
|
+
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
421
|
+
if (!isRegistered) {
|
|
422
|
+
return executeRegisterAndWithdrawERC20({
|
|
423
|
+
ethSigner,
|
|
424
|
+
assetType: assetType.asset_type,
|
|
425
|
+
starkPublicKey,
|
|
426
|
+
config,
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
return executeWithdrawERC20(ethSigner, assetType.asset_type, starkPublicKey, starkExConfig);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
async function executeWithdrawMintableERC721(ethSigner, assetType, starkPublicKey, mintingBlob, config) {
|
|
435
|
+
const contract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
436
|
+
const populatedTransaction = await contract.populateTransaction.withdrawAndMint(starkPublicKey, assetType, mintingBlob);
|
|
437
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
438
|
+
}
|
|
439
|
+
async function executeRegisterAndWithdrawMintableERC721(ethSigner, assetType, starkPublicKey, mintingBlob, config) {
|
|
440
|
+
const etherKey = await ethSigner.getAddress();
|
|
441
|
+
const usersApi = new coreSdk.UsersApi(config.apiConfiguration);
|
|
442
|
+
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
443
|
+
const contract = coreSdk.Contracts.Registration.connect(config.ethConfiguration.registrationContractAddress, ethSigner);
|
|
444
|
+
const populatedTransaction = await contract.populateTransaction.regsiterAndWithdrawAndMint(etherKey, starkPublicKey, signableResult.operator_signature, assetType, mintingBlob);
|
|
445
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
446
|
+
}
|
|
447
|
+
function getMintingBlob(token) {
|
|
448
|
+
const id = token.data.id;
|
|
449
|
+
const blueprint = token.data.blueprint || '';
|
|
450
|
+
return encUtils__namespace.sanitizeHex(encUtils__namespace.utf8ToHex(`{${id}}:{${blueprint}}`));
|
|
451
|
+
}
|
|
452
|
+
async function completeMintableERC721Withdrawal(ethSigner, starkPublicKey, token, config) {
|
|
453
|
+
const starkExConfig = config.immutableXConfig;
|
|
454
|
+
const assetType = await getEncodeAssetInfo('mintable-asset', 'ERC721', starkExConfig, {
|
|
455
|
+
id: token.data.id,
|
|
456
|
+
token_address: token.data.tokenAddress,
|
|
457
|
+
...(token.data.blueprint && { blueprint: token.data.blueprint }),
|
|
458
|
+
});
|
|
459
|
+
const mintingBlob = getMintingBlob(token);
|
|
460
|
+
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
461
|
+
if (!isRegistered) {
|
|
462
|
+
return executeRegisterAndWithdrawMintableERC721(ethSigner, assetType.asset_type, starkPublicKey, mintingBlob, starkExConfig);
|
|
463
|
+
}
|
|
464
|
+
else {
|
|
465
|
+
return executeWithdrawMintableERC721(ethSigner, assetType.asset_type, starkPublicKey, mintingBlob, starkExConfig);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
async function executeRegisterAndWithdrawERC721(ethSigner, assetType, starkPublicKey, tokenId, config) {
|
|
469
|
+
const etherKey = await ethSigner.getAddress();
|
|
470
|
+
const usersApi = new coreSdk.UsersApi(config.apiConfiguration);
|
|
471
|
+
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
472
|
+
const contract = coreSdk.Contracts.Registration.connect(config.ethConfiguration.registrationContractAddress, ethSigner);
|
|
473
|
+
const populatedTransaction = await contract.populateTransaction.registerAndWithdrawNft(etherKey, starkPublicKey, signableResult.operator_signature, assetType, tokenId);
|
|
474
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
475
|
+
}
|
|
476
|
+
async function executeWithdrawERC721(ethSigner, assetType, starkPublicKey, tokenId, config) {
|
|
477
|
+
const contract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
478
|
+
const populatedTransaction = await contract.populateTransaction.withdrawNft(starkPublicKey, assetType, tokenId);
|
|
479
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
480
|
+
}
|
|
481
|
+
async function completeERC721Withdrawal(ethSigner, starkPublicKey, token, config) {
|
|
482
|
+
const starkExConfig = config.immutableXConfig;
|
|
483
|
+
const assetType = await getEncodeAssetInfo('asset', 'ERC721', starkExConfig, {
|
|
484
|
+
token_id: token.tokenId,
|
|
485
|
+
token_address: token.tokenAddress,
|
|
486
|
+
});
|
|
487
|
+
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
488
|
+
if (!isRegistered) {
|
|
489
|
+
return executeRegisterAndWithdrawERC721(ethSigner, assetType.asset_type, starkPublicKey, token.tokenId, starkExConfig);
|
|
490
|
+
}
|
|
491
|
+
else {
|
|
492
|
+
return executeWithdrawERC721(ethSigner, assetType.asset_type, starkPublicKey, token.tokenId, starkExConfig);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
async function completeERC721WithdrawalAction({ ethSigner, starkPublicKey, token, config, }) {
|
|
496
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
497
|
+
const tokenAddress = token.tokenAddress;
|
|
498
|
+
const tokenId = token.tokenId;
|
|
499
|
+
const starkExConfig = config.immutableXConfig;
|
|
500
|
+
const mintsApi = new coreSdk.MintsApi(starkExConfig.apiConfiguration);
|
|
501
|
+
return await mintsApi
|
|
502
|
+
.getMintableTokenDetailsByClientTokenId({
|
|
503
|
+
tokenAddress,
|
|
504
|
+
tokenId,
|
|
505
|
+
})
|
|
506
|
+
.then((mintableToken) => completeMintableERC721Withdrawal(ethSigner, starkPublicKey, {
|
|
507
|
+
type: 'ERC721',
|
|
508
|
+
data: {
|
|
509
|
+
id: tokenId,
|
|
510
|
+
tokenAddress: tokenAddress,
|
|
511
|
+
blueprint: mintableToken.data.blueprint,
|
|
512
|
+
},
|
|
513
|
+
}, config))
|
|
514
|
+
.catch((error) => {
|
|
515
|
+
if (error.response?.status === 404) {
|
|
516
|
+
// token is already minted on L1
|
|
517
|
+
return completeERC721Withdrawal(ethSigner, starkPublicKey, token, config);
|
|
518
|
+
}
|
|
519
|
+
throw error; // unable to recover from any other kind of error
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
async function executeRegisterAndWithdrawEth(ethSigner, assetType, starkPublicKey, config) {
|
|
524
|
+
const etherKey = await ethSigner.getAddress();
|
|
525
|
+
const usersApi = new coreSdk.UsersApi(config.apiConfiguration);
|
|
526
|
+
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
527
|
+
const contract = coreSdk.Contracts.Registration.connect(config.ethConfiguration.registrationContractAddress, ethSigner);
|
|
528
|
+
const populatedTransaction = await contract.populateTransaction.registerAndWithdraw(etherKey, starkPublicKey, signableResult.operator_signature, assetType);
|
|
529
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
530
|
+
}
|
|
531
|
+
async function executeWithdrawEth(ethSigner, assetType, starkPublicKey, config) {
|
|
532
|
+
const contract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
533
|
+
const populatedTransaction = await contract.populateTransaction.withdraw(starkPublicKey, assetType);
|
|
534
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
535
|
+
}
|
|
536
|
+
async function completeEthWithdrawalAction({ ethSigner, starkPublicKey, config, }) {
|
|
537
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
538
|
+
const starkExConfig = config.immutableXConfig;
|
|
539
|
+
const assetType = await getEncodeAssetInfo('asset', 'ETH', starkExConfig);
|
|
540
|
+
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
541
|
+
if (!isRegistered) {
|
|
542
|
+
return executeRegisterAndWithdrawEth(ethSigner, assetType.asset_type, starkPublicKey, starkExConfig);
|
|
543
|
+
}
|
|
544
|
+
else {
|
|
545
|
+
return executeWithdrawEth(ethSigner, assetType.asset_type, starkPublicKey, starkExConfig);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
async function prepareWithdrawal({ signers, withdrawal, config, }) {
|
|
550
|
+
return prepareWithdrawalAction({
|
|
551
|
+
signers,
|
|
552
|
+
config: config.immutableXConfig,
|
|
553
|
+
...withdrawal,
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
async function completeWithdrawal({ signers: { ethSigner }, starkPublicKey, token, config, }) {
|
|
557
|
+
switch (token.type) {
|
|
558
|
+
case 'ETH':
|
|
559
|
+
return completeEthWithdrawalAction({ ethSigner, starkPublicKey, config });
|
|
560
|
+
case 'ERC20':
|
|
561
|
+
return completeERC20WithdrawalAction({
|
|
562
|
+
ethSigner,
|
|
563
|
+
starkPublicKey,
|
|
564
|
+
token,
|
|
565
|
+
config,
|
|
566
|
+
});
|
|
567
|
+
case 'ERC721':
|
|
568
|
+
return completeERC721WithdrawalAction({
|
|
569
|
+
ethSigner,
|
|
570
|
+
starkPublicKey,
|
|
571
|
+
token,
|
|
572
|
+
config,
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
async function createTrade$1({ signers: { ethSigner, starkExSigner }, request, config, }) {
|
|
578
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
579
|
+
const ethAddress = await ethSigner.getAddress();
|
|
580
|
+
const tradesApi = new coreSdk.TradesApi(config.immutableXConfig.apiConfiguration);
|
|
581
|
+
const signableResult = await tradesApi.getSignableTrade({
|
|
582
|
+
getSignableTradeRequest: {
|
|
583
|
+
user: ethAddress,
|
|
584
|
+
order_id: request.order_id,
|
|
585
|
+
fees: request.fees,
|
|
586
|
+
},
|
|
587
|
+
});
|
|
588
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
589
|
+
const ethSignature = await signRaw(signableMessage, ethSigner);
|
|
590
|
+
const starkSignature = await starkExSigner.signMessage(payloadHash);
|
|
591
|
+
const createTradeResponse = await tradesApi.createTrade({
|
|
592
|
+
createTradeRequest: {
|
|
593
|
+
amount_buy: signableResult.data.amount_buy,
|
|
594
|
+
amount_sell: signableResult.data.amount_sell,
|
|
595
|
+
asset_id_buy: signableResult.data.asset_id_buy,
|
|
596
|
+
asset_id_sell: signableResult.data.asset_id_sell,
|
|
597
|
+
expiration_timestamp: signableResult.data.expiration_timestamp,
|
|
598
|
+
fee_info: signableResult.data.fee_info,
|
|
599
|
+
fees: request.fees,
|
|
600
|
+
include_fees: true,
|
|
601
|
+
nonce: signableResult.data.nonce,
|
|
602
|
+
order_id: request.order_id,
|
|
603
|
+
stark_key: signableResult.data.stark_key,
|
|
604
|
+
vault_id_buy: signableResult.data.vault_id_buy,
|
|
605
|
+
vault_id_sell: signableResult.data.vault_id_sell,
|
|
606
|
+
stark_signature: starkSignature,
|
|
607
|
+
},
|
|
608
|
+
xImxEthAddress: ethAddress,
|
|
609
|
+
xImxEthSignature: ethSignature,
|
|
610
|
+
});
|
|
611
|
+
return createTradeResponse.data;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
async function depositEth({ signers: { ethSigner }, deposit, config, }) {
|
|
615
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
616
|
+
const user = await ethSigner.getAddress();
|
|
617
|
+
const data = {
|
|
618
|
+
decimals: 18,
|
|
619
|
+
};
|
|
620
|
+
const amount = units.parseUnits(deposit.amount, 'wei');
|
|
621
|
+
const starkExConfig = config.immutableXConfig;
|
|
622
|
+
const depositsApi = new coreSdk.DepositsApi(starkExConfig.apiConfiguration);
|
|
623
|
+
const encodingApi = new coreSdk.EncodingApi(starkExConfig.apiConfiguration);
|
|
624
|
+
const usersApi = new coreSdk.UsersApi(starkExConfig.apiConfiguration);
|
|
625
|
+
const getSignableDepositRequest = {
|
|
626
|
+
user,
|
|
627
|
+
token: {
|
|
628
|
+
type: deposit.type,
|
|
629
|
+
data,
|
|
630
|
+
},
|
|
631
|
+
amount: amount.toString(),
|
|
632
|
+
};
|
|
633
|
+
const signableDepositResult = await depositsApi.getSignableDeposit({
|
|
634
|
+
getSignableDepositRequest,
|
|
635
|
+
});
|
|
636
|
+
const encodingResult = await encodingApi.encodeAsset({
|
|
637
|
+
assetType: 'asset',
|
|
638
|
+
encodeAssetRequest: {
|
|
639
|
+
token: {
|
|
640
|
+
type: deposit.type,
|
|
641
|
+
},
|
|
642
|
+
},
|
|
643
|
+
});
|
|
644
|
+
const assetType = encodingResult.data.asset_type;
|
|
645
|
+
const starkPublicKey = signableDepositResult.data.stark_key;
|
|
646
|
+
const vaultId = signableDepositResult.data.vault_id;
|
|
647
|
+
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
648
|
+
if (!isRegistered) {
|
|
649
|
+
return executeRegisterAndDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, starkExConfig, usersApi);
|
|
650
|
+
}
|
|
651
|
+
else {
|
|
652
|
+
return executeDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, starkExConfig);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
async function executeRegisterAndDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, config, usersApi) {
|
|
656
|
+
const etherKey = await ethSigner.getAddress();
|
|
657
|
+
const coreContract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
658
|
+
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
659
|
+
const populatedTransaction = await coreContract.populateTransaction.registerAndDepositEth(etherKey, starkPublicKey, signableResult.operator_signature, assetType, vaultId);
|
|
660
|
+
return ethSigner.sendTransaction({ ...populatedTransaction, value: amount });
|
|
661
|
+
}
|
|
662
|
+
async function executeDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, config) {
|
|
663
|
+
const coreContract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
664
|
+
const populatedTransaction = await coreContract.populateTransaction['deposit(uint256,uint256,uint256)'](starkPublicKey, assetType, vaultId);
|
|
665
|
+
return ethSigner.sendTransaction({ ...populatedTransaction, value: amount });
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
async function depositERC20({ signers: { ethSigner }, deposit, config, }) {
|
|
669
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
670
|
+
const { apiConfiguration, ethConfiguration } = config.immutableXConfig;
|
|
671
|
+
const user = await ethSigner.getAddress();
|
|
672
|
+
const tokensApi = new coreSdk.TokensApi(apiConfiguration);
|
|
673
|
+
const depositsApi = new coreSdk.DepositsApi(apiConfiguration);
|
|
674
|
+
const encodingApi = new coreSdk.EncodingApi(apiConfiguration);
|
|
675
|
+
const usersApi = new coreSdk.UsersApi(apiConfiguration);
|
|
676
|
+
// Get decimals for this specific ERC20
|
|
677
|
+
const token = await tokensApi.getToken({ address: deposit.tokenAddress });
|
|
678
|
+
const decimals = parseInt(token.data.decimals);
|
|
679
|
+
const data = {
|
|
680
|
+
decimals,
|
|
681
|
+
token_address: deposit.tokenAddress,
|
|
682
|
+
};
|
|
683
|
+
const amount = units.parseUnits(deposit.amount, 0); // 0 to always use undecimalized value
|
|
684
|
+
// Approve whether an amount of token from an account can be spent by a third-party account
|
|
685
|
+
const tokenContract = coreSdk.Contracts.IERC20.connect(deposit.tokenAddress, ethSigner);
|
|
686
|
+
const approveTransaction = await tokenContract.populateTransaction.approve(ethConfiguration.coreContractAddress, amount);
|
|
687
|
+
await ethSigner.sendTransaction(approveTransaction);
|
|
688
|
+
const getSignableDepositRequest = {
|
|
689
|
+
user,
|
|
690
|
+
token: {
|
|
691
|
+
type: deposit.type,
|
|
692
|
+
data,
|
|
693
|
+
},
|
|
694
|
+
amount: amount.toString(),
|
|
695
|
+
};
|
|
696
|
+
const signableDepositResult = await depositsApi.getSignableDeposit({
|
|
697
|
+
getSignableDepositRequest,
|
|
698
|
+
});
|
|
699
|
+
// Perform encoding on asset details to get an assetType (required for stark contract request)
|
|
700
|
+
const encodingResult = await encodingApi.encodeAsset({
|
|
701
|
+
assetType: 'asset',
|
|
702
|
+
encodeAssetRequest: {
|
|
703
|
+
token: {
|
|
704
|
+
type: deposit.type,
|
|
705
|
+
data: {
|
|
706
|
+
token_address: deposit.tokenAddress,
|
|
707
|
+
},
|
|
708
|
+
},
|
|
709
|
+
},
|
|
710
|
+
});
|
|
711
|
+
const assetType = encodingResult.data.asset_type;
|
|
712
|
+
const starkPublicKey = signableDepositResult.data.stark_key;
|
|
713
|
+
const vaultId = signableDepositResult.data.vault_id;
|
|
714
|
+
const quantizedAmount = bignumber.BigNumber.from(signableDepositResult.data.amount);
|
|
715
|
+
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
716
|
+
if (!isRegistered) {
|
|
717
|
+
return executeRegisterAndDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, ethConfiguration, usersApi);
|
|
718
|
+
}
|
|
719
|
+
else {
|
|
720
|
+
return executeDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, ethConfiguration);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
async function executeDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, config) {
|
|
724
|
+
const coreContract = coreSdk.Contracts.Core.connect(config.coreContractAddress, ethSigner);
|
|
725
|
+
const populatedTransaction = await coreContract.populateTransaction.depositERC20(starkPublicKey, assetType, vaultId, quantizedAmount);
|
|
726
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
727
|
+
}
|
|
728
|
+
async function executeRegisterAndDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, config, usersApi) {
|
|
729
|
+
const etherKey = await ethSigner.getAddress();
|
|
730
|
+
const coreContract = coreSdk.Contracts.Core.connect(config.coreContractAddress, ethSigner);
|
|
731
|
+
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
732
|
+
const populatedTransaction = await coreContract.populateTransaction.registerAndDepositERC20(etherKey, starkPublicKey, signableResult.operator_signature, assetType, vaultId, quantizedAmount);
|
|
733
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
async function depositERC721({ signers: { ethSigner }, deposit, config, }) {
|
|
737
|
+
await validateChain(ethSigner, config.immutableXConfig);
|
|
738
|
+
const user = await ethSigner.getAddress();
|
|
739
|
+
const { immutableXConfig } = config;
|
|
740
|
+
const depositsApi = new coreSdk.DepositsApi(immutableXConfig.apiConfiguration);
|
|
741
|
+
const encodingApi = new coreSdk.EncodingApi(immutableXConfig.apiConfiguration);
|
|
742
|
+
const usersApi = new coreSdk.UsersApi(immutableXConfig.apiConfiguration);
|
|
743
|
+
const data = {
|
|
744
|
+
token_address: deposit.tokenAddress,
|
|
745
|
+
token_id: deposit.tokenId,
|
|
746
|
+
};
|
|
747
|
+
const amount = '1';
|
|
748
|
+
const getSignableDepositRequest = {
|
|
749
|
+
user,
|
|
750
|
+
token: {
|
|
751
|
+
type: deposit.type,
|
|
752
|
+
data,
|
|
753
|
+
},
|
|
754
|
+
amount: amount.toString(),
|
|
755
|
+
};
|
|
756
|
+
const signableDepositResult = await depositsApi.getSignableDeposit({
|
|
757
|
+
getSignableDepositRequest,
|
|
758
|
+
});
|
|
759
|
+
// Perform encoding on asset details to get an assetType (required for stark contract request)
|
|
760
|
+
const encodingResult = await encodingApi.encodeAsset({
|
|
761
|
+
assetType: 'asset',
|
|
762
|
+
encodeAssetRequest: {
|
|
763
|
+
token: {
|
|
764
|
+
type: deposit.type,
|
|
765
|
+
data: {
|
|
766
|
+
token_address: deposit.tokenAddress,
|
|
767
|
+
token_id: deposit.tokenId,
|
|
768
|
+
},
|
|
769
|
+
},
|
|
770
|
+
},
|
|
771
|
+
});
|
|
772
|
+
const assetType = encodingResult.data.asset_type;
|
|
773
|
+
const starkPublicKey = signableDepositResult.data.stark_key;
|
|
774
|
+
const vaultId = signableDepositResult.data.vault_id;
|
|
775
|
+
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
776
|
+
// Approve whether an amount of token from an account can be spent by a third-party account
|
|
777
|
+
const tokenContract = coreSdk.Contracts.IERC721.connect(deposit.tokenAddress, ethSigner);
|
|
778
|
+
const operator = immutableXConfig.ethConfiguration.coreContractAddress;
|
|
779
|
+
const isApprovedForAll = await tokenContract.isApprovedForAll(user, operator);
|
|
780
|
+
if (!isApprovedForAll) {
|
|
781
|
+
await tokenContract.setApprovalForAll(operator, true);
|
|
782
|
+
}
|
|
783
|
+
if (!isRegistered) {
|
|
784
|
+
const signableResult = await getSignableRegistrationOnchain(user, starkPublicKey, usersApi);
|
|
785
|
+
const coreContract = coreSdk.Contracts.Core.connect(immutableXConfig.ethConfiguration.coreContractAddress, ethSigner);
|
|
786
|
+
// Note: proxy registration contract registerAndDepositNft method is not used as it currently fails erc721 transfer ownership check
|
|
787
|
+
await coreContract.registerUser(user, starkPublicKey, signableResult.operator_signature);
|
|
788
|
+
}
|
|
789
|
+
return executeDepositERC721(ethSigner, deposit.tokenId, assetType, starkPublicKey, vaultId, immutableXConfig);
|
|
790
|
+
}
|
|
791
|
+
async function executeDepositERC721(ethSigner, tokenId, assetType, starkPublicKey, vaultId, config) {
|
|
792
|
+
const coreContract = coreSdk.Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
793
|
+
const populatedTransaction = await coreContract.populateTransaction.depositNft(starkPublicKey, assetType, vaultId, tokenId);
|
|
794
|
+
return ethSigner.sendTransaction(populatedTransaction);
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
async function deposit({ signers, deposit, config }) {
|
|
798
|
+
switch (deposit.type) {
|
|
799
|
+
case 'ETH':
|
|
800
|
+
return depositEth({ signers, deposit, config });
|
|
801
|
+
case 'ERC20':
|
|
802
|
+
return depositERC20({ signers, deposit, config });
|
|
803
|
+
case 'ERC721':
|
|
804
|
+
return depositERC721({ signers, deposit, config });
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
async function exchangeTransfer$1({ signers, request, config, }) {
|
|
809
|
+
await validateChain(signers.ethSigner, config.immutableXConfig);
|
|
810
|
+
const exchangeApi = new coreSdk.ExchangesApi(config.immutableXConfig.apiConfiguration);
|
|
811
|
+
const ethAddress = await signers.ethSigner.getAddress();
|
|
812
|
+
const transferAmount = request.amount;
|
|
813
|
+
const signableResult = await exchangeApi.getExchangeSignableTransfer({
|
|
814
|
+
id: request.transactionID,
|
|
815
|
+
getSignableTransferRequest: {
|
|
816
|
+
sender: ethAddress,
|
|
817
|
+
token: convertToSignableToken(request),
|
|
818
|
+
amount: transferAmount,
|
|
819
|
+
receiver: request.receiver,
|
|
820
|
+
},
|
|
821
|
+
});
|
|
822
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
823
|
+
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
824
|
+
const starkSignature = await signers.starkExSigner.signMessage(payloadHash);
|
|
825
|
+
const transferSigningParams = {
|
|
826
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
827
|
+
sender_stark_key: signableResult.data.sender_stark_key,
|
|
828
|
+
sender_vault_id: signableResult.data.sender_vault_id,
|
|
829
|
+
receiver_stark_key: signableResult.data.receiver_stark_key,
|
|
830
|
+
receiver_vault_id: signableResult.data.receiver_vault_id,
|
|
831
|
+
asset_id: signableResult.data.asset_id,
|
|
832
|
+
amount: signableResult.data.amount,
|
|
833
|
+
nonce: signableResult.data.nonce,
|
|
834
|
+
expiration_timestamp: signableResult.data.expiration_timestamp,
|
|
835
|
+
stark_signature: starkSignature,
|
|
836
|
+
};
|
|
837
|
+
const response = await exchangeApi.createExchangeTransfer({
|
|
838
|
+
id: request.transactionID,
|
|
839
|
+
createTransferRequest: transferSigningParams,
|
|
840
|
+
xImxEthAddress: ethAddress,
|
|
841
|
+
xImxEthSignature: ethSignature,
|
|
842
|
+
});
|
|
843
|
+
return {
|
|
844
|
+
sent_signature: response?.data.sent_signature,
|
|
845
|
+
status: response?.data.status?.toString(),
|
|
846
|
+
time: response?.data.time,
|
|
847
|
+
transfer_id: response?.data.transfer_id,
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
class GenericIMXProvider {
|
|
852
|
+
config;
|
|
853
|
+
signers;
|
|
854
|
+
constructor(config, ethSigner, starkExSigner) {
|
|
855
|
+
this.config = config;
|
|
856
|
+
this.signers = { ethSigner, starkExSigner };
|
|
857
|
+
}
|
|
858
|
+
async getAddress() {
|
|
859
|
+
return await this.signers.ethSigner.getAddress();
|
|
860
|
+
}
|
|
861
|
+
registerOffchain() {
|
|
862
|
+
return registerOffchain(this.signers, this.config);
|
|
863
|
+
}
|
|
864
|
+
batchNftTransfer(request) {
|
|
865
|
+
return batchTransfer({
|
|
866
|
+
signers: this.signers,
|
|
867
|
+
request,
|
|
868
|
+
config: this.config,
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
cancelOrder(request) {
|
|
872
|
+
return cancelOrder$1({
|
|
873
|
+
signers: this.signers,
|
|
874
|
+
request,
|
|
875
|
+
config: this.config,
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
completeWithdrawal(starkPublicKey, token) {
|
|
879
|
+
return completeWithdrawal({
|
|
880
|
+
config: this.config,
|
|
881
|
+
signers: this.signers,
|
|
882
|
+
token,
|
|
883
|
+
starkPublicKey,
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
createOrder(request) {
|
|
887
|
+
return createOrder$1({
|
|
888
|
+
signers: this.signers,
|
|
889
|
+
request,
|
|
890
|
+
config: this.config,
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
createTrade(request) {
|
|
894
|
+
return createTrade$1({
|
|
895
|
+
signers: this.signers,
|
|
896
|
+
request,
|
|
897
|
+
config: this.config,
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
deposit(tokenAmount) {
|
|
901
|
+
return deposit({
|
|
902
|
+
signers: this.signers,
|
|
903
|
+
deposit: tokenAmount,
|
|
904
|
+
config: this.config,
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
exchangeTransfer(request) {
|
|
908
|
+
return exchangeTransfer$1({
|
|
909
|
+
signers: this.signers,
|
|
910
|
+
request,
|
|
911
|
+
config: this.config,
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
async isRegisteredOnchain() {
|
|
915
|
+
const starkPublicKey = await this.signers.starkExSigner.getAddress();
|
|
916
|
+
return isRegisteredOnChain(starkPublicKey, this.signers.ethSigner, this.config);
|
|
917
|
+
}
|
|
918
|
+
prepareWithdrawal(request) {
|
|
919
|
+
return prepareWithdrawal({
|
|
920
|
+
signers: this.signers,
|
|
921
|
+
withdrawal: request,
|
|
922
|
+
config: this.config,
|
|
923
|
+
});
|
|
924
|
+
}
|
|
925
|
+
transfer(request) {
|
|
926
|
+
return transfer$1({
|
|
927
|
+
signers: this.signers,
|
|
928
|
+
request,
|
|
929
|
+
config: this.config,
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
const WALLET_ACTION = {
|
|
935
|
+
SWITCH_CHAIN: 'wallet_switchEthereumChain',
|
|
936
|
+
CONNECT: 'eth_requestAccounts',
|
|
937
|
+
};
|
|
938
|
+
function isRequestableProvider(provider) {
|
|
939
|
+
return !!provider?.request;
|
|
940
|
+
}
|
|
941
|
+
async function connectProvider(provider, chainID) {
|
|
942
|
+
await provider.request({ method: WALLET_ACTION.CONNECT });
|
|
943
|
+
if (chainID) {
|
|
944
|
+
await provider.request({
|
|
945
|
+
method: WALLET_ACTION.SWITCH_CHAIN,
|
|
946
|
+
params: [{ chainId: `0x${chainID.toString(16)}` }],
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
const ERRORS = {
|
|
952
|
+
PROVIDER_NOT_FOUND: 'The Metamask provider was not found',
|
|
953
|
+
};
|
|
954
|
+
async function connect$1({ chainID, }) {
|
|
955
|
+
const provider = (await detectEthereumProvider());
|
|
956
|
+
if (!isRequestableProvider(provider)) {
|
|
957
|
+
throw new Error(ERRORS.PROVIDER_NOT_FOUND);
|
|
958
|
+
}
|
|
959
|
+
await connectProvider(provider, chainID);
|
|
960
|
+
// NOTE: if we want to listen to Metamask events in the future, we can add a
|
|
961
|
+
// listener here.
|
|
962
|
+
return new ethers.ethers.providers.Web3Provider(provider);
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
const COMMUNICATION_TYPE = 'message';
|
|
966
|
+
var RequestEventType;
|
|
967
|
+
(function (RequestEventType) {
|
|
968
|
+
RequestEventType["GET_CONNECTION_REQUEST"] = "GET_CONNECTION_REQUEST";
|
|
969
|
+
RequestEventType["CONNECT_WALLET_REQUEST"] = "CONNECT_WALLET_REQUEST";
|
|
970
|
+
RequestEventType["SIGN_MESSAGE_REQUEST"] = "SIGN_MESSAGE_REQUEST";
|
|
971
|
+
RequestEventType["DISCONNECT_WALLET_REQUEST"] = "DISCONNECT_WALLET_REQUEST";
|
|
972
|
+
})(RequestEventType || (RequestEventType = {}));
|
|
973
|
+
var ResponseEventType;
|
|
974
|
+
(function (ResponseEventType) {
|
|
975
|
+
ResponseEventType["CONNECT_WALLET_RESPONSE"] = "CONNECT_WALLET_RESPONSE";
|
|
976
|
+
ResponseEventType["SIGN_MESSAGE_RESPONSE"] = "SIGN_MESSAGE_RESPONSE";
|
|
977
|
+
ResponseEventType["GET_CONNECTION_RESPONSE"] = "GET_CONNECTION_RESPONSE";
|
|
978
|
+
ResponseEventType["DISCONNECT_WALLET_RESPONSE"] = "DISCONNECT_WALLET_RESPONSE";
|
|
979
|
+
})(ResponseEventType || (ResponseEventType = {}));
|
|
980
|
+
|
|
981
|
+
function postRequestMessage(iframe, payload) {
|
|
982
|
+
if (iframe && iframe.contentWindow) {
|
|
983
|
+
iframe.contentWindow.postMessage(payload, new URL(iframe.src).origin);
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
function messageResponseListener(iframe, event, eventType, callback) {
|
|
988
|
+
if (iframe && event.source !== iframe.contentWindow) {
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
const l2WalletMessage = event.data;
|
|
992
|
+
if (l2WalletMessage.type !== eventType) {
|
|
993
|
+
return;
|
|
994
|
+
}
|
|
995
|
+
callback(l2WalletMessage.details);
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
class ImxSigner {
|
|
999
|
+
publicAddress;
|
|
1000
|
+
iframe;
|
|
1001
|
+
constructor(publicAddress, iframe) {
|
|
1002
|
+
this.publicAddress = publicAddress;
|
|
1003
|
+
this.iframe = iframe;
|
|
1004
|
+
}
|
|
1005
|
+
getAddress() {
|
|
1006
|
+
return this.publicAddress;
|
|
1007
|
+
}
|
|
1008
|
+
signMessage(rawMessage) {
|
|
1009
|
+
return new Promise((resolve, reject) => {
|
|
1010
|
+
const listener = (event) => {
|
|
1011
|
+
messageResponseListener(this.iframe, event, ResponseEventType.SIGN_MESSAGE_RESPONSE, (messageDetails) => {
|
|
1012
|
+
window.removeEventListener(COMMUNICATION_TYPE, listener);
|
|
1013
|
+
if (!messageDetails.success) {
|
|
1014
|
+
reject(new Error(messageDetails.error?.message));
|
|
1015
|
+
}
|
|
1016
|
+
resolve(messageDetails.data.signedMessage);
|
|
1017
|
+
});
|
|
1018
|
+
};
|
|
1019
|
+
window.addEventListener(COMMUNICATION_TYPE, listener);
|
|
1020
|
+
postRequestMessage(this.iframe, {
|
|
1021
|
+
type: RequestEventType.SIGN_MESSAGE_REQUEST,
|
|
1022
|
+
details: { starkPublicKey: this.publicAddress, message: rawMessage },
|
|
1023
|
+
});
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
getIFrame() {
|
|
1027
|
+
return this.iframe;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
const IMX_WALLET_IFRAME_ID = 'imx-wallet-app';
|
|
1032
|
+
const IMX_WALLET_IFRAME_HOSTS = {
|
|
1033
|
+
[exports.Environment.SANDBOX]: 'https://wallets.sandbox.immutable.com',
|
|
1034
|
+
[exports.Environment.PRODUCTION]: 'https://wallets.immutable.com',
|
|
1035
|
+
};
|
|
1036
|
+
const IMX_WALLET_IFRAME_STYLE = 'display: none;';
|
|
1037
|
+
function getIFrame() {
|
|
1038
|
+
return document.querySelector(`iframe#${IMX_WALLET_IFRAME_ID}`);
|
|
1039
|
+
}
|
|
1040
|
+
async function setupIFrame(env) {
|
|
1041
|
+
return new Promise((resolve) => {
|
|
1042
|
+
const iframe = document.createElement('iframe');
|
|
1043
|
+
iframe.setAttribute('id', IMX_WALLET_IFRAME_ID);
|
|
1044
|
+
iframe.setAttribute('src', IMX_WALLET_IFRAME_HOSTS[env]);
|
|
1045
|
+
iframe.setAttribute('style', IMX_WALLET_IFRAME_STYLE);
|
|
1046
|
+
document.body.appendChild(iframe);
|
|
1047
|
+
iframe.onload = () => resolve(iframe);
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
async function getOrSetupIFrame(env) {
|
|
1051
|
+
const iframe = getIFrame();
|
|
1052
|
+
if (iframe)
|
|
1053
|
+
return iframe;
|
|
1054
|
+
return await setupIFrame(env);
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
const DEFAULT_CONNECTION_MESSAGE = 'Only sign this request if you’ve initiated an action with Immutable X.';
|
|
1058
|
+
const CONNECTION_FAILED_ERROR = 'The L2 IMX Wallet connection has failed';
|
|
1059
|
+
async function connect(l1Provider, env) {
|
|
1060
|
+
const l1Signer = l1Provider.getSigner();
|
|
1061
|
+
const address = await l1Signer.getAddress();
|
|
1062
|
+
const signature = await l1Signer.signMessage(DEFAULT_CONNECTION_MESSAGE);
|
|
1063
|
+
const iframe = await getOrSetupIFrame(env);
|
|
1064
|
+
return new Promise((resolve, reject) => {
|
|
1065
|
+
const listener = (event) => {
|
|
1066
|
+
messageResponseListener(iframe, event, ResponseEventType.CONNECT_WALLET_RESPONSE, (messageDetails) => {
|
|
1067
|
+
window.removeEventListener(COMMUNICATION_TYPE, listener);
|
|
1068
|
+
if (!messageDetails.success) {
|
|
1069
|
+
reject(new Error(CONNECTION_FAILED_ERROR));
|
|
1070
|
+
}
|
|
1071
|
+
resolve(new ImxSigner(messageDetails.data.starkPublicKey, iframe));
|
|
1072
|
+
});
|
|
1073
|
+
};
|
|
1074
|
+
window.addEventListener(COMMUNICATION_TYPE, listener);
|
|
1075
|
+
postRequestMessage(iframe, {
|
|
1076
|
+
type: RequestEventType.CONNECT_WALLET_REQUEST,
|
|
1077
|
+
details: { ethAddress: address, signature },
|
|
1078
|
+
});
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
async function disconnect(imxSigner) {
|
|
1082
|
+
const iframe = imxSigner.getIFrame();
|
|
1083
|
+
return new Promise((resolve, reject) => {
|
|
1084
|
+
const listener = (event) => {
|
|
1085
|
+
messageResponseListener(iframe, event, ResponseEventType.DISCONNECT_WALLET_RESPONSE, (messageDetails) => {
|
|
1086
|
+
window.removeEventListener(COMMUNICATION_TYPE, listener);
|
|
1087
|
+
if (!messageDetails.success && messageDetails.error) {
|
|
1088
|
+
reject(messageDetails.error);
|
|
1089
|
+
}
|
|
1090
|
+
iframe.remove();
|
|
1091
|
+
resolve();
|
|
1092
|
+
});
|
|
1093
|
+
};
|
|
1094
|
+
window.addEventListener(COMMUNICATION_TYPE, listener);
|
|
1095
|
+
postRequestMessage(iframe, {
|
|
1096
|
+
type: RequestEventType.DISCONNECT_WALLET_REQUEST,
|
|
1097
|
+
details: { starkPublicKey: imxSigner.getAddress() },
|
|
1098
|
+
});
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
var ProviderErrorType;
|
|
1103
|
+
(function (ProviderErrorType) {
|
|
1104
|
+
ProviderErrorType["PROVIDER_CONNECTION_ERROR"] = "PROVIDER_CONNECTION_ERROR";
|
|
1105
|
+
ProviderErrorType["WALLET_CONNECTION_ERROR"] = "WALLET_CONNECTION_ERROR";
|
|
1106
|
+
})(ProviderErrorType || (ProviderErrorType = {}));
|
|
1107
|
+
class ProviderError extends Error {
|
|
1108
|
+
type;
|
|
1109
|
+
constructor(message, type) {
|
|
1110
|
+
super(message);
|
|
1111
|
+
this.type = type;
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
const withProviderError = async (fn, customError) => {
|
|
1115
|
+
try {
|
|
1116
|
+
return await fn();
|
|
1117
|
+
}
|
|
1118
|
+
catch (error) {
|
|
1119
|
+
const errorMessage = customError.message || `${error.message}` || 'UnknownError';
|
|
1120
|
+
throw new ProviderError(errorMessage, customError.type);
|
|
1121
|
+
}
|
|
1122
|
+
};
|
|
1123
|
+
|
|
1124
|
+
class MetaMaskIMXProvider extends GenericIMXProvider {
|
|
1125
|
+
static imxSigner;
|
|
1126
|
+
constructor(config, ethSigner, starkExSigner) {
|
|
1127
|
+
super(config, ethSigner, starkExSigner);
|
|
1128
|
+
}
|
|
1129
|
+
static async connect(config) {
|
|
1130
|
+
return await withProviderError(async () => {
|
|
1131
|
+
const metaMaskProvider = await connect$1({
|
|
1132
|
+
chainID: config.immutableXConfig.ethConfiguration.chainID,
|
|
1133
|
+
});
|
|
1134
|
+
this.imxSigner = await connect(metaMaskProvider, config.baseConfig.environment);
|
|
1135
|
+
return new MetaMaskIMXProvider(config, metaMaskProvider.getSigner(), this.imxSigner);
|
|
1136
|
+
}, { type: ProviderErrorType.WALLET_CONNECTION_ERROR });
|
|
1137
|
+
}
|
|
1138
|
+
static async disconnect() {
|
|
1139
|
+
if (!this.imxSigner) {
|
|
1140
|
+
throw new ProviderError('Attempted to disconnect from the MetaMask IMX provider without an established connection', ProviderErrorType.PROVIDER_CONNECTION_ERROR);
|
|
1141
|
+
}
|
|
1142
|
+
return withProviderError(async () => {
|
|
1143
|
+
await disconnect(this.imxSigner);
|
|
1144
|
+
}, { type: ProviderErrorType.PROVIDER_CONNECTION_ERROR });
|
|
1145
|
+
}
|
|
1146
|
+
static async signMessage(message) {
|
|
1147
|
+
if (!this.imxSigner) {
|
|
1148
|
+
throw new ProviderError('Attempted to sign a message with the MetaMask IMX provider without an established connection', ProviderErrorType.PROVIDER_CONNECTION_ERROR);
|
|
1149
|
+
}
|
|
1150
|
+
return withProviderError(async () => {
|
|
1151
|
+
return await this.imxSigner.signMessage(message);
|
|
1152
|
+
}, { type: ProviderErrorType.PROVIDER_CONNECTION_ERROR });
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
class ProviderConfiguration {
|
|
1157
|
+
immutableXConfig;
|
|
1158
|
+
baseConfig;
|
|
1159
|
+
constructor({ baseConfig, overrides }) {
|
|
1160
|
+
this.baseConfig = baseConfig;
|
|
1161
|
+
if (overrides) {
|
|
1162
|
+
this.immutableXConfig = overrides.immutableXConfig;
|
|
1163
|
+
}
|
|
1164
|
+
else {
|
|
1165
|
+
switch (baseConfig.environment) {
|
|
1166
|
+
case exports.Environment.SANDBOX: {
|
|
1167
|
+
this.immutableXConfig = coreSdk.Config.SANDBOX;
|
|
1168
|
+
break;
|
|
1169
|
+
}
|
|
1170
|
+
case exports.Environment.PRODUCTION: {
|
|
1171
|
+
this.immutableXConfig = coreSdk.Config.PRODUCTION;
|
|
1172
|
+
break;
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
var PassportErrorType;
|
|
1180
|
+
(function (PassportErrorType) {
|
|
1181
|
+
PassportErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
|
|
1182
|
+
PassportErrorType["INVALID_CONFIGURATION"] = "INVALID_CONFIGURATION";
|
|
1183
|
+
PassportErrorType["WALLET_CONNECTION_ERROR"] = "WALLET_CONNECTION_ERROR";
|
|
1184
|
+
PassportErrorType["NOT_LOGGED_IN_ERROR"] = "NOT_LOGGED_IN_ERROR";
|
|
1185
|
+
PassportErrorType["REFRESH_TOKEN_ERROR"] = "REFRESH_TOKEN_ERROR";
|
|
1186
|
+
PassportErrorType["USER_REGISTRATION_ERROR"] = "USER_REGISTRATION_ERROR";
|
|
1187
|
+
PassportErrorType["LOGOUT_ERROR"] = "LOGOUT_ERROR";
|
|
1188
|
+
PassportErrorType["TRANSFER_ERROR"] = "TRANSFER_ERROR";
|
|
1189
|
+
PassportErrorType["CREATE_ORDER_ERROR"] = "CREATE_ORDER_ERROR";
|
|
1190
|
+
PassportErrorType["CANCEL_ORDER_ERROR"] = "CANCEL_ORDER_ERROR";
|
|
1191
|
+
PassportErrorType["EXCHANGE_TRANSFER_ERROR"] = "EXCHANGE_TRANSFER_ERROR";
|
|
1192
|
+
PassportErrorType["CREATE_TRADE_ERROR"] = "CREATE_TRADE_ERROR";
|
|
1193
|
+
PassportErrorType["OPERATION_NOT_SUPPORTED_ERROR"] = "OPERATION_NOT_SUPPORTED_ERROR";
|
|
1194
|
+
})(PassportErrorType || (PassportErrorType = {}));
|
|
1195
|
+
class PassportError extends Error {
|
|
1196
|
+
type;
|
|
1197
|
+
constructor(message, type) {
|
|
1198
|
+
super(message);
|
|
1199
|
+
this.type = type;
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
const withPassportError = async (fn, customErrorType) => {
|
|
1203
|
+
try {
|
|
1204
|
+
return await fn();
|
|
1205
|
+
}
|
|
1206
|
+
catch (error) {
|
|
1207
|
+
const errorMessage = `${customErrorType}: ${error.message}` || 'UnknownError';
|
|
1208
|
+
throw new PassportError(errorMessage, customErrorType);
|
|
1209
|
+
}
|
|
1210
|
+
};
|
|
1211
|
+
|
|
1212
|
+
const POLL_INTERVAL = 1 * 1000; // every 1 second
|
|
1213
|
+
const MAX_RETRIES = 3;
|
|
1214
|
+
const wait = (ms) => new Promise((resolve) => {
|
|
1215
|
+
setTimeout(() => resolve(), ms);
|
|
1216
|
+
});
|
|
1217
|
+
const retryWithDelay = async (fn, options) => {
|
|
1218
|
+
const { retries = MAX_RETRIES, interval = POLL_INTERVAL, finalErr = Error('Retry failed'), } = options || {};
|
|
1219
|
+
try {
|
|
1220
|
+
return await fn();
|
|
1221
|
+
}
|
|
1222
|
+
catch (err) {
|
|
1223
|
+
if (retries <= 0) {
|
|
1224
|
+
return Promise.reject(finalErr);
|
|
1225
|
+
}
|
|
1226
|
+
await wait(interval);
|
|
1227
|
+
return retryWithDelay(fn, { retries: retries - 1, finalErr });
|
|
1228
|
+
}
|
|
1229
|
+
};
|
|
1230
|
+
|
|
1231
|
+
const getAuthConfiguration = ({ oidcConfiguration, authenticationDomain, }) => {
|
|
1232
|
+
const baseConfiguration = {
|
|
1233
|
+
authority: authenticationDomain,
|
|
1234
|
+
redirect_uri: oidcConfiguration.redirectUri,
|
|
1235
|
+
popup_redirect_uri: oidcConfiguration.redirectUri,
|
|
1236
|
+
client_id: oidcConfiguration.clientId,
|
|
1237
|
+
metadata: {
|
|
1238
|
+
authorization_endpoint: `${authenticationDomain}/authorize`,
|
|
1239
|
+
token_endpoint: `${authenticationDomain}/oauth/token`,
|
|
1240
|
+
userinfo_endpoint: `${authenticationDomain}/userinfo`,
|
|
1241
|
+
end_session_endpoint: `${authenticationDomain}/v2/logout` +
|
|
1242
|
+
`?returnTo=${encodeURIComponent(oidcConfiguration.logoutRedirectUri)}` +
|
|
1243
|
+
`&client_id=${oidcConfiguration.clientId}`,
|
|
1244
|
+
},
|
|
1245
|
+
mergeClaims: true,
|
|
1246
|
+
loadUserInfo: true,
|
|
1247
|
+
scope: oidcConfiguration.scope,
|
|
1248
|
+
};
|
|
1249
|
+
if (oidcConfiguration.audience) {
|
|
1250
|
+
baseConfiguration.extraQueryParams = {
|
|
1251
|
+
audience: oidcConfiguration.audience,
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
1254
|
+
return baseConfiguration;
|
|
1255
|
+
};
|
|
1256
|
+
class AuthManager {
|
|
1257
|
+
userManager;
|
|
1258
|
+
config;
|
|
1259
|
+
constructor(config) {
|
|
1260
|
+
this.config = config;
|
|
1261
|
+
this.userManager = new oidcClientTs.UserManager(getAuthConfiguration(config));
|
|
1262
|
+
}
|
|
1263
|
+
mapOidcUserToDomainModel = (oidcUser) => {
|
|
1264
|
+
const passport = oidcUser.profile?.passport;
|
|
1265
|
+
return {
|
|
1266
|
+
idToken: oidcUser.id_token,
|
|
1267
|
+
accessToken: oidcUser.access_token,
|
|
1268
|
+
refreshToken: oidcUser.refresh_token,
|
|
1269
|
+
profile: {
|
|
1270
|
+
sub: oidcUser.profile.sub,
|
|
1271
|
+
email: oidcUser.profile.email,
|
|
1272
|
+
nickname: oidcUser.profile.nickname,
|
|
1273
|
+
},
|
|
1274
|
+
etherKey: passport?.ether_key || '',
|
|
1275
|
+
};
|
|
1276
|
+
};
|
|
1277
|
+
async login() {
|
|
1278
|
+
return withPassportError(async () => {
|
|
1279
|
+
const popupWindowFeatures = { width: 400, height: 420 };
|
|
1280
|
+
const oidcUser = await this.userManager.signinPopup({
|
|
1281
|
+
popupWindowFeatures,
|
|
1282
|
+
});
|
|
1283
|
+
return this.mapOidcUserToDomainModel(oidcUser);
|
|
1284
|
+
}, PassportErrorType.AUTHENTICATION_ERROR);
|
|
1285
|
+
}
|
|
1286
|
+
async loginCallback() {
|
|
1287
|
+
return withPassportError(async () => this.userManager.signinPopupCallback(), PassportErrorType.AUTHENTICATION_ERROR);
|
|
1288
|
+
}
|
|
1289
|
+
async logout() {
|
|
1290
|
+
return withPassportError(async () => this.userManager.signoutRedirect(), PassportErrorType.LOGOUT_ERROR);
|
|
1291
|
+
}
|
|
1292
|
+
async getUser() {
|
|
1293
|
+
return withPassportError(async () => {
|
|
1294
|
+
const oidcUser = await this.userManager.getUser();
|
|
1295
|
+
if (!oidcUser) {
|
|
1296
|
+
throw new Error('Failed to retrieve user');
|
|
1297
|
+
}
|
|
1298
|
+
return this.mapOidcUserToDomainModel(oidcUser);
|
|
1299
|
+
}, PassportErrorType.NOT_LOGGED_IN_ERROR);
|
|
1300
|
+
}
|
|
1301
|
+
async requestRefreshTokenAfterRegistration() {
|
|
1302
|
+
return withPassportError(async () => {
|
|
1303
|
+
const updatedUser = await retryWithDelay(async () => {
|
|
1304
|
+
const user = await this.userManager.signinSilent();
|
|
1305
|
+
const passportMetadata = user?.profile?.passport;
|
|
1306
|
+
const metadataExists = !!passportMetadata?.ether_key &&
|
|
1307
|
+
!!passportMetadata?.stark_key &&
|
|
1308
|
+
!!passportMetadata?.user_admin_key;
|
|
1309
|
+
if (metadataExists) {
|
|
1310
|
+
return user;
|
|
1311
|
+
}
|
|
1312
|
+
return Promise.reject('user wallet addresses not exist');
|
|
1313
|
+
});
|
|
1314
|
+
if (!updatedUser) {
|
|
1315
|
+
return null;
|
|
1316
|
+
}
|
|
1317
|
+
return this.mapOidcUserToDomainModel(updatedUser);
|
|
1318
|
+
}, PassportErrorType.REFRESH_TOKEN_ERROR);
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
class MagicAdapter {
|
|
1323
|
+
magicClient;
|
|
1324
|
+
config;
|
|
1325
|
+
constructor(config) {
|
|
1326
|
+
this.config = config;
|
|
1327
|
+
this.magicClient = new magicSdk.Magic(config.magicPublishableApiKey, {
|
|
1328
|
+
network: config.network,
|
|
1329
|
+
extensions: [new oidc.OpenIdExtension()],
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
async login(idToken) {
|
|
1333
|
+
return withPassportError(async () => {
|
|
1334
|
+
await this.magicClient.openid.loginWithOIDC({
|
|
1335
|
+
jwt: idToken,
|
|
1336
|
+
providerId: this.config.magicProviderId,
|
|
1337
|
+
});
|
|
1338
|
+
return new ethers.ethers.providers.Web3Provider(this.magicClient
|
|
1339
|
+
.rpcProvider);
|
|
1340
|
+
}, PassportErrorType.WALLET_CONNECTION_ERROR);
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
var ReceiveMessage;
|
|
1345
|
+
(function (ReceiveMessage) {
|
|
1346
|
+
ReceiveMessage["CONFIRMATION_WINDOW_READY"] = "confirmation_window_ready";
|
|
1347
|
+
ReceiveMessage["TRANSACTION_CONFIRMED"] = "transaction_confirmed";
|
|
1348
|
+
ReceiveMessage["TRANSACTION_ERROR"] = "transaction_error";
|
|
1349
|
+
})(ReceiveMessage || (ReceiveMessage = {}));
|
|
1350
|
+
var SendMessage;
|
|
1351
|
+
(function (SendMessage) {
|
|
1352
|
+
SendMessage["TRANSACTION_START"] = "transaction_start";
|
|
1353
|
+
})(SendMessage || (SendMessage = {}));
|
|
1354
|
+
var TransactionTypes;
|
|
1355
|
+
(function (TransactionTypes) {
|
|
1356
|
+
TransactionTypes["CancelOrder"] = "delete:v1/orders";
|
|
1357
|
+
TransactionTypes["CreateOrder"] = "post:v1/orders";
|
|
1358
|
+
TransactionTypes["CreateTrade"] = "post:v1/trades";
|
|
1359
|
+
TransactionTypes["CreateTransfer"] = "post:v1/transfers";
|
|
1360
|
+
TransactionTypes["CreateBatchTransfer"] = "post:v2/transfers";
|
|
1361
|
+
})(TransactionTypes || (TransactionTypes = {}));
|
|
1362
|
+
const PassportEventType = 'imx_passport_confirmation';
|
|
1363
|
+
|
|
1364
|
+
const openPopupCenter = ({ url, title, width, height, }) => {
|
|
1365
|
+
const left = Math.max(0, Math.round(window.screenX + (window.outerWidth - width) / 2));
|
|
1366
|
+
const top = Math.max(0, Math.round(window.screenY + (window.outerHeight - height) / 2));
|
|
1367
|
+
const newWindow = window.open(url, title, `
|
|
1368
|
+
scrollbars=yes,
|
|
1369
|
+
width=${width},
|
|
1370
|
+
height=${height},
|
|
1371
|
+
top=${top},
|
|
1372
|
+
left=${left}
|
|
1373
|
+
`);
|
|
1374
|
+
if (!newWindow) {
|
|
1375
|
+
throw new Error('Failed to open confirmation screen');
|
|
1376
|
+
}
|
|
1377
|
+
newWindow.focus();
|
|
1378
|
+
return newWindow;
|
|
1379
|
+
};
|
|
1380
|
+
|
|
1381
|
+
const ConfirmationWindowTitle = 'Confirm this transaction';
|
|
1382
|
+
const ConfirmationWindowHeight = 380;
|
|
1383
|
+
const ConfirmationWindowWidth = 480;
|
|
1384
|
+
const ConfirmationWindowClosedPollingDuration = 1000;
|
|
1385
|
+
class ConfirmationScreen {
|
|
1386
|
+
config;
|
|
1387
|
+
constructor(config) {
|
|
1388
|
+
this.config = config;
|
|
1389
|
+
}
|
|
1390
|
+
postMessage(destinationWindow, accessToken, message) {
|
|
1391
|
+
destinationWindow.postMessage({
|
|
1392
|
+
eventType: PassportEventType,
|
|
1393
|
+
accessToken,
|
|
1394
|
+
...message,
|
|
1395
|
+
}, this.config.passportDomain);
|
|
1396
|
+
}
|
|
1397
|
+
startTransaction(accessToken, transaction, popupOptions) {
|
|
1398
|
+
return new Promise((resolve, reject) => {
|
|
1399
|
+
const messageHandler = ({ data, origin }) => {
|
|
1400
|
+
if (origin != this.config.passportDomain ||
|
|
1401
|
+
data.eventType != PassportEventType) {
|
|
1402
|
+
return;
|
|
1403
|
+
}
|
|
1404
|
+
switch (data.messageType) {
|
|
1405
|
+
case ReceiveMessage.CONFIRMATION_WINDOW_READY: {
|
|
1406
|
+
this.postMessage(confirmationWindow, accessToken, {
|
|
1407
|
+
messageType: SendMessage.TRANSACTION_START,
|
|
1408
|
+
messageData: transaction,
|
|
1409
|
+
});
|
|
1410
|
+
break;
|
|
1411
|
+
}
|
|
1412
|
+
case ReceiveMessage.TRANSACTION_CONFIRMED: {
|
|
1413
|
+
resolve({ confirmed: true });
|
|
1414
|
+
break;
|
|
1415
|
+
}
|
|
1416
|
+
case ReceiveMessage.TRANSACTION_ERROR: {
|
|
1417
|
+
reject(new Error('Transaction error'));
|
|
1418
|
+
break;
|
|
1419
|
+
}
|
|
1420
|
+
default:
|
|
1421
|
+
reject(new Error('Unsupported message type'));
|
|
1422
|
+
}
|
|
1423
|
+
};
|
|
1424
|
+
window.addEventListener('message', messageHandler);
|
|
1425
|
+
const confirmationWindow = openPopupCenter({
|
|
1426
|
+
url: `${this.config.passportDomain}/transaction-confirmation`,
|
|
1427
|
+
title: ConfirmationWindowTitle,
|
|
1428
|
+
width: popupOptions?.width || ConfirmationWindowWidth,
|
|
1429
|
+
height: popupOptions?.height || ConfirmationWindowHeight,
|
|
1430
|
+
});
|
|
1431
|
+
// https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
|
|
1432
|
+
const timer = setInterval(function () {
|
|
1433
|
+
if (confirmationWindow.closed) {
|
|
1434
|
+
clearInterval(timer);
|
|
1435
|
+
window.removeEventListener('message', messageHandler);
|
|
1436
|
+
resolve({ confirmed: false });
|
|
1437
|
+
}
|
|
1438
|
+
}, ConfirmationWindowClosedPollingDuration);
|
|
1439
|
+
});
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
const ERC721$1 = 'ERC721';
|
|
1444
|
+
const transfer = ({ request, transfersApi, starkSigner, user, passportConfig, }) => {
|
|
1445
|
+
return withPassportError(async () => {
|
|
1446
|
+
const transferAmount = request.type === ERC721$1 ? '1' : request.amount;
|
|
1447
|
+
const getSignableTransferRequest = {
|
|
1448
|
+
sender: user.etherKey,
|
|
1449
|
+
token: convertToSignableToken(request),
|
|
1450
|
+
amount: transferAmount,
|
|
1451
|
+
receiver: request.receiver,
|
|
1452
|
+
};
|
|
1453
|
+
const signableResult = await transfersApi.getSignableTransferV1({
|
|
1454
|
+
getSignableTransferRequest,
|
|
1455
|
+
});
|
|
1456
|
+
const confirmationScreen = new ConfirmationScreen(passportConfig);
|
|
1457
|
+
const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
|
|
1458
|
+
transactionType: TransactionTypes.CreateTransfer,
|
|
1459
|
+
transactionData: getSignableTransferRequest,
|
|
1460
|
+
});
|
|
1461
|
+
if (!confirmationResult.confirmed) {
|
|
1462
|
+
throw new Error('Transaction rejected by user');
|
|
1463
|
+
}
|
|
1464
|
+
const signableResultData = signableResult.data;
|
|
1465
|
+
const { payload_hash: payloadHash } = signableResultData;
|
|
1466
|
+
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
1467
|
+
const senderStarkKey = await starkSigner.getAddress();
|
|
1468
|
+
const transferSigningParams = {
|
|
1469
|
+
sender_stark_key: signableResultData.sender_stark_key || senderStarkKey,
|
|
1470
|
+
sender_vault_id: signableResultData.sender_vault_id,
|
|
1471
|
+
receiver_stark_key: signableResultData.receiver_stark_key,
|
|
1472
|
+
receiver_vault_id: signableResultData.receiver_vault_id,
|
|
1473
|
+
asset_id: signableResultData.asset_id,
|
|
1474
|
+
amount: signableResultData.amount,
|
|
1475
|
+
nonce: signableResultData.nonce,
|
|
1476
|
+
expiration_timestamp: signableResultData.expiration_timestamp,
|
|
1477
|
+
stark_signature: starkSignature,
|
|
1478
|
+
};
|
|
1479
|
+
const createTransferRequest = {
|
|
1480
|
+
createTransferRequest: transferSigningParams,
|
|
1481
|
+
};
|
|
1482
|
+
const headers = {
|
|
1483
|
+
Authorization: 'Bearer ' + user.accessToken,
|
|
1484
|
+
};
|
|
1485
|
+
const { data: responseData } = await transfersApi.createTransferV1(createTransferRequest, { headers });
|
|
1486
|
+
return {
|
|
1487
|
+
sent_signature: responseData.sent_signature,
|
|
1488
|
+
status: responseData.status?.toString(),
|
|
1489
|
+
time: responseData.time,
|
|
1490
|
+
transfer_id: responseData.transfer_id,
|
|
1491
|
+
};
|
|
1492
|
+
}, PassportErrorType.TRANSFER_ERROR);
|
|
1493
|
+
};
|
|
1494
|
+
async function batchNftTransfer({ user, starkSigner, request, transfersApi, passportConfig, }) {
|
|
1495
|
+
return withPassportError(async () => {
|
|
1496
|
+
const ethAddress = user.etherKey;
|
|
1497
|
+
const signableRequests = request.map((nftTransfer) => {
|
|
1498
|
+
return {
|
|
1499
|
+
amount: '1',
|
|
1500
|
+
token: convertToSignableToken({
|
|
1501
|
+
type: ERC721$1,
|
|
1502
|
+
tokenId: nftTransfer.tokenId,
|
|
1503
|
+
tokenAddress: nftTransfer.tokenAddress,
|
|
1504
|
+
}),
|
|
1505
|
+
receiver: nftTransfer.receiver,
|
|
1506
|
+
};
|
|
1507
|
+
});
|
|
1508
|
+
const getSignableTransferRequestV2 = {
|
|
1509
|
+
sender_ether_key: ethAddress,
|
|
1510
|
+
signable_requests: signableRequests,
|
|
1511
|
+
};
|
|
1512
|
+
const signableResult = await transfersApi.getSignableTransfer({
|
|
1513
|
+
getSignableTransferRequestV2,
|
|
1514
|
+
});
|
|
1515
|
+
const confirmationScreen = new ConfirmationScreen(passportConfig);
|
|
1516
|
+
const popupWindowSize = { width: 480, height: 784 };
|
|
1517
|
+
const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
|
|
1518
|
+
transactionType: TransactionTypes.CreateBatchTransfer,
|
|
1519
|
+
transactionData: getSignableTransferRequestV2,
|
|
1520
|
+
}, popupWindowSize);
|
|
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);
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
const ERC721 = 'ERC721';
|
|
1554
|
+
async function createOrder({ starkSigner, user, request, ordersApi, passportConfig, }) {
|
|
1555
|
+
return withPassportError(async () => {
|
|
1556
|
+
const ethAddress = user.etherKey;
|
|
1557
|
+
const amountSell = request.sell.type === ERC721 ? '1' : request.sell.amount;
|
|
1558
|
+
const amountBuy = request.buy.type === ERC721 ? '1' : request.buy.amount;
|
|
1559
|
+
const getSignableOrderRequestV3 = {
|
|
1560
|
+
user: ethAddress,
|
|
1561
|
+
amount_buy: amountBuy,
|
|
1562
|
+
token_buy: convertToSignableToken(request.buy),
|
|
1563
|
+
amount_sell: amountSell,
|
|
1564
|
+
token_sell: convertToSignableToken(request.sell),
|
|
1565
|
+
fees: request.fees,
|
|
1566
|
+
expiration_timestamp: request.expiration_timestamp,
|
|
1567
|
+
};
|
|
1568
|
+
const getSignableOrderResponse = await ordersApi.getSignableOrder({
|
|
1569
|
+
getSignableOrderRequestV3,
|
|
1570
|
+
});
|
|
1571
|
+
const confirmationScreen = new ConfirmationScreen(passportConfig);
|
|
1572
|
+
const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
|
|
1573
|
+
transactionType: TransactionTypes.CreateOrder,
|
|
1574
|
+
transactionData: getSignableOrderRequestV3,
|
|
1575
|
+
});
|
|
1576
|
+
if (!confirmationResult.confirmed) {
|
|
1577
|
+
throw new Error('Transaction rejected by user');
|
|
1578
|
+
}
|
|
1579
|
+
const { payload_hash: payloadHash } = getSignableOrderResponse.data;
|
|
1580
|
+
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
1581
|
+
const signableResultData = getSignableOrderResponse.data;
|
|
1582
|
+
const orderParams = {
|
|
1583
|
+
createOrderRequest: {
|
|
1584
|
+
include_fees: true,
|
|
1585
|
+
fees: request.fees,
|
|
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,
|
|
1596
|
+
},
|
|
1597
|
+
};
|
|
1598
|
+
const headers = {
|
|
1599
|
+
Authorization: 'Bearer ' + user.accessToken,
|
|
1600
|
+
};
|
|
1601
|
+
const createOrderResponse = await ordersApi.createOrder(orderParams, {
|
|
1602
|
+
headers,
|
|
1603
|
+
});
|
|
1604
|
+
return {
|
|
1605
|
+
...createOrderResponse.data,
|
|
1606
|
+
};
|
|
1607
|
+
}, PassportErrorType.CREATE_ORDER_ERROR);
|
|
1608
|
+
}
|
|
1609
|
+
async function cancelOrder({ user, starkSigner, request, ordersApi, passportConfig, }) {
|
|
1610
|
+
return withPassportError(async () => {
|
|
1611
|
+
const getSignableCancelOrderRequest = {
|
|
1612
|
+
order_id: request.order_id,
|
|
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);
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1644
|
+
async function exchangeTransfer({ user, starkSigner, request, exchangesApi, }) {
|
|
1645
|
+
return withPassportError(async () => {
|
|
1646
|
+
const ethAddress = user.etherKey;
|
|
1647
|
+
const transferAmount = request.amount;
|
|
1648
|
+
const signableResult = await exchangesApi.getExchangeSignableTransfer({
|
|
1649
|
+
id: request.transactionID,
|
|
1650
|
+
getSignableTransferRequest: {
|
|
1651
|
+
sender: ethAddress,
|
|
1652
|
+
token: convertToSignableToken(request),
|
|
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);
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
async function createTrade({ request, tradesApi, user, starkSigner, passportConfig, }) {
|
|
1688
|
+
return withPassportError(async () => {
|
|
1689
|
+
const ethAddress = user.etherKey;
|
|
1690
|
+
const getSignableTradeRequest = {
|
|
1691
|
+
expiration_timestamp: request.expiration_timestamp,
|
|
1692
|
+
fees: request.fees,
|
|
1693
|
+
order_id: request.order_id,
|
|
1694
|
+
user: ethAddress,
|
|
1695
|
+
};
|
|
1696
|
+
const getSignableTradeResponse = await tradesApi.getSignableTrade({
|
|
1697
|
+
getSignableTradeRequest,
|
|
1698
|
+
});
|
|
1699
|
+
const confirmationScreen = new ConfirmationScreen(passportConfig);
|
|
1700
|
+
const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
|
|
1701
|
+
transactionType: TransactionTypes.CreateTrade,
|
|
1702
|
+
transactionData: getSignableTradeRequest,
|
|
1703
|
+
});
|
|
1704
|
+
if (!confirmationResult.confirmed) {
|
|
1705
|
+
throw new Error('Transaction rejected by user');
|
|
1706
|
+
}
|
|
1707
|
+
const { payload_hash: payloadHash } = getSignableTradeResponse.data;
|
|
1708
|
+
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
1709
|
+
const { data: signableResultData } = getSignableTradeResponse;
|
|
1710
|
+
const tradeParams = {
|
|
1711
|
+
createTradeRequest: {
|
|
1712
|
+
include_fees: true,
|
|
1713
|
+
fees: request?.fees,
|
|
1714
|
+
stark_signature: starkSignature,
|
|
1715
|
+
order_id: request?.order_id,
|
|
1716
|
+
fee_info: signableResultData.fee_info,
|
|
1717
|
+
amount_buy: signableResultData.amount_buy,
|
|
1718
|
+
amount_sell: signableResultData.amount_sell,
|
|
1719
|
+
asset_id_buy: signableResultData.asset_id_buy,
|
|
1720
|
+
asset_id_sell: signableResultData.asset_id_sell,
|
|
1721
|
+
expiration_timestamp: signableResultData.expiration_timestamp,
|
|
1722
|
+
nonce: signableResultData.nonce,
|
|
1723
|
+
stark_key: signableResultData.stark_key,
|
|
1724
|
+
vault_id_buy: signableResultData.vault_id_buy,
|
|
1725
|
+
vault_id_sell: signableResultData.vault_id_sell,
|
|
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);
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1736
|
+
class PassportImxProvider {
|
|
1737
|
+
user;
|
|
1738
|
+
starkSigner;
|
|
1739
|
+
transfersApi;
|
|
1740
|
+
ordersApi;
|
|
1741
|
+
passportConfig;
|
|
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.imxApiBasePath,
|
|
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);
|
|
1755
|
+
}
|
|
1756
|
+
async transfer(request) {
|
|
1757
|
+
return transfer({
|
|
1758
|
+
request,
|
|
1759
|
+
user: this.user,
|
|
1760
|
+
starkSigner: this.starkSigner,
|
|
1761
|
+
transfersApi: this.transfersApi,
|
|
1762
|
+
passportConfig: this.passportConfig,
|
|
1763
|
+
});
|
|
1764
|
+
}
|
|
1765
|
+
registerOffchain() {
|
|
1766
|
+
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
1767
|
+
}
|
|
1768
|
+
isRegisteredOnchain() {
|
|
1769
|
+
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
1770
|
+
}
|
|
1771
|
+
createOrder(request) {
|
|
1772
|
+
return createOrder({
|
|
1773
|
+
request,
|
|
1774
|
+
user: this.user,
|
|
1775
|
+
starkSigner: this.starkSigner,
|
|
1776
|
+
ordersApi: this.ordersApi,
|
|
1777
|
+
passportConfig: this.passportConfig,
|
|
1778
|
+
});
|
|
1779
|
+
}
|
|
1780
|
+
cancelOrder(request) {
|
|
1781
|
+
return cancelOrder({
|
|
1782
|
+
request,
|
|
1783
|
+
user: this.user,
|
|
1784
|
+
starkSigner: this.starkSigner,
|
|
1785
|
+
ordersApi: this.ordersApi,
|
|
1786
|
+
passportConfig: this.passportConfig,
|
|
1787
|
+
});
|
|
1788
|
+
}
|
|
1789
|
+
createTrade(request) {
|
|
1790
|
+
return createTrade({
|
|
1791
|
+
request,
|
|
1792
|
+
user: this.user,
|
|
1793
|
+
starkSigner: this.starkSigner,
|
|
1794
|
+
tradesApi: this.tradesApi,
|
|
1795
|
+
passportConfig: this.passportConfig,
|
|
1796
|
+
});
|
|
1797
|
+
}
|
|
1798
|
+
batchNftTransfer(request) {
|
|
1799
|
+
return batchNftTransfer({
|
|
1800
|
+
request,
|
|
1801
|
+
user: this.user,
|
|
1802
|
+
starkSigner: this.starkSigner,
|
|
1803
|
+
transfersApi: this.transfersApi,
|
|
1804
|
+
passportConfig: this.passportConfig,
|
|
1805
|
+
});
|
|
1806
|
+
}
|
|
1807
|
+
exchangeTransfer(request) {
|
|
1808
|
+
return exchangeTransfer({
|
|
1809
|
+
request,
|
|
1810
|
+
user: this.user,
|
|
1811
|
+
starkSigner: this.starkSigner,
|
|
1812
|
+
exchangesApi: this.exchangesApi,
|
|
1813
|
+
});
|
|
1814
|
+
}
|
|
1815
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1816
|
+
deposit(deposit) {
|
|
1817
|
+
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
1818
|
+
}
|
|
1819
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1820
|
+
prepareWithdrawal(request) {
|
|
1821
|
+
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
1822
|
+
}
|
|
1823
|
+
completeWithdrawal(
|
|
1824
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1825
|
+
starkPublicKey,
|
|
1826
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1827
|
+
token) {
|
|
1828
|
+
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
1829
|
+
}
|
|
1830
|
+
getAddress() {
|
|
1831
|
+
return Promise.resolve(this.starkSigner.getAddress());
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
var Networks;
|
|
1836
|
+
(function (Networks) {
|
|
1837
|
+
Networks["PRODUCTION"] = "mainnet";
|
|
1838
|
+
Networks["SANDBOX"] = "goerli";
|
|
1839
|
+
})(Networks || (Networks = {}));
|
|
1840
|
+
|
|
1841
|
+
const validateConfiguration = (configuration, requiredKeys, prefix) => {
|
|
1842
|
+
const missingKeys = requiredKeys
|
|
1843
|
+
.map((key) => !configuration[key] && key)
|
|
1844
|
+
.filter((n) => n)
|
|
1845
|
+
.join(', ');
|
|
1846
|
+
if (missingKeys !== '') {
|
|
1847
|
+
const errorMessage = prefix
|
|
1848
|
+
? `${prefix} - ${missingKeys} cannot be null`
|
|
1849
|
+
: `${missingKeys} cannot be null`;
|
|
1850
|
+
throw new PassportError(errorMessage, PassportErrorType.INVALID_CONFIGURATION);
|
|
1851
|
+
}
|
|
1852
|
+
};
|
|
1853
|
+
class PassportConfiguration {
|
|
1854
|
+
network;
|
|
1855
|
+
authenticationDomain;
|
|
1856
|
+
passportDomain;
|
|
1857
|
+
magicPublishableApiKey;
|
|
1858
|
+
magicProviderId;
|
|
1859
|
+
imxApiBasePath;
|
|
1860
|
+
oidcConfiguration;
|
|
1861
|
+
baseConfig;
|
|
1862
|
+
constructor({ baseConfig, overrides, ...oidcConfiguration }) {
|
|
1863
|
+
validateConfiguration(oidcConfiguration, [
|
|
1864
|
+
'clientId',
|
|
1865
|
+
'logoutRedirectUri',
|
|
1866
|
+
'redirectUri',
|
|
1867
|
+
]);
|
|
1868
|
+
this.oidcConfiguration = oidcConfiguration;
|
|
1869
|
+
this.baseConfig = baseConfig;
|
|
1870
|
+
if (overrides) {
|
|
1871
|
+
validateConfiguration(overrides, [
|
|
1872
|
+
'network',
|
|
1873
|
+
'authenticationDomain',
|
|
1874
|
+
'magicPublishableApiKey',
|
|
1875
|
+
'magicProviderId',
|
|
1876
|
+
'passportDomain',
|
|
1877
|
+
'imxApiBasePath',
|
|
1878
|
+
], 'overrides');
|
|
1879
|
+
this.network = overrides.network;
|
|
1880
|
+
this.authenticationDomain = overrides.authenticationDomain;
|
|
1881
|
+
this.passportDomain = overrides.passportDomain;
|
|
1882
|
+
this.magicPublishableApiKey = overrides.magicPublishableApiKey;
|
|
1883
|
+
this.magicProviderId = overrides.magicProviderId;
|
|
1884
|
+
this.imxApiBasePath = overrides.imxApiBasePath;
|
|
1885
|
+
}
|
|
1886
|
+
else {
|
|
1887
|
+
switch (baseConfig.environment) {
|
|
1888
|
+
case exports.Environment.SANDBOX: {
|
|
1889
|
+
this.network = Networks.SANDBOX;
|
|
1890
|
+
this.authenticationDomain = 'https://auth.immutable.com';
|
|
1891
|
+
this.magicPublishableApiKey = 'pk_live_10F423798A540ED7';
|
|
1892
|
+
this.magicProviderId = 'fSMzaRQ4O7p4fttl7pCyGVtJS_G70P8SNsLXtPPGHo0=';
|
|
1893
|
+
this.passportDomain = 'https://passport.immutable.com';
|
|
1894
|
+
this.imxApiBasePath = 'https://api.x.immutable.com';
|
|
1895
|
+
break;
|
|
1896
|
+
}
|
|
1897
|
+
case exports.Environment.PRODUCTION: {
|
|
1898
|
+
this.network = Networks.PRODUCTION;
|
|
1899
|
+
this.authenticationDomain = 'https://auth.immutable.com';
|
|
1900
|
+
this.magicPublishableApiKey = 'pk_live_10F423798A540ED7';
|
|
1901
|
+
this.magicProviderId = 'fSMzaRQ4O7p4fttl7pCyGVtJS_G70P8SNsLXtPPGHo0=';
|
|
1902
|
+
this.passportDomain = 'https://passport.sandbox.immutable.com';
|
|
1903
|
+
this.imxApiBasePath = 'https://api.sandbox.x.immutable.com';
|
|
1904
|
+
break;
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
const getStarkSigner = async (signer) => {
|
|
1912
|
+
return withPassportError(async () => {
|
|
1913
|
+
const privateKey = await coreSdk.generateLegacyStarkPrivateKey(signer);
|
|
1914
|
+
return coreSdk.createStarkSigner(privateKey);
|
|
1915
|
+
}, PassportErrorType.WALLET_CONNECTION_ERROR);
|
|
1916
|
+
};
|
|
1917
|
+
|
|
1918
|
+
async function registerPassport({ ethSigner, starkSigner, usersApi }, authorization) {
|
|
1919
|
+
return withPassportError(async () => {
|
|
1920
|
+
const userAddress = await ethSigner.getAddress();
|
|
1921
|
+
const starkPublicKey = await starkSigner.getAddress();
|
|
1922
|
+
const signableResult = await usersApi.getSignableRegistrationOffchain({
|
|
1923
|
+
getSignableRegistrationRequest: {
|
|
1924
|
+
ether_key: userAddress,
|
|
1925
|
+
stark_key: starkPublicKey,
|
|
1926
|
+
},
|
|
1927
|
+
});
|
|
1928
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
1929
|
+
const ethSignature = await signRaw(signableMessage, ethSigner);
|
|
1930
|
+
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
1931
|
+
const response = await usersApi.registerPassportUser({
|
|
1932
|
+
authorization: `Bearer ` + authorization,
|
|
1933
|
+
registerPassportUserRequest: {
|
|
1934
|
+
eth_signature: ethSignature,
|
|
1935
|
+
ether_key: userAddress,
|
|
1936
|
+
stark_signature: starkSignature,
|
|
1937
|
+
stark_key: starkPublicKey,
|
|
1938
|
+
},
|
|
1939
|
+
});
|
|
1940
|
+
return response.statusText;
|
|
1941
|
+
}, PassportErrorType.USER_REGISTRATION_ERROR);
|
|
1942
|
+
}
|
|
1943
|
+
|
|
1944
|
+
class Passport {
|
|
1945
|
+
authManager;
|
|
1946
|
+
magicAdapter;
|
|
1947
|
+
config;
|
|
1948
|
+
constructor(passportModuleConfiguration) {
|
|
1949
|
+
const passportConfiguration = new PassportConfiguration(passportModuleConfiguration);
|
|
1950
|
+
this.config = passportConfiguration;
|
|
1951
|
+
this.authManager = new AuthManager(this.config);
|
|
1952
|
+
this.magicAdapter = new MagicAdapter(this.config);
|
|
1953
|
+
}
|
|
1954
|
+
async connectImx() {
|
|
1955
|
+
const user = await this.authManager.login();
|
|
1956
|
+
if (!user.idToken) {
|
|
1957
|
+
throw new PassportError('Failed to initialise', PassportErrorType.WALLET_CONNECTION_ERROR);
|
|
1958
|
+
}
|
|
1959
|
+
const provider = await this.magicAdapter.login(user.idToken);
|
|
1960
|
+
const ethSigner = provider.getSigner();
|
|
1961
|
+
const starkSigner = await getStarkSigner(ethSigner);
|
|
1962
|
+
if (!user.etherKey) {
|
|
1963
|
+
const updatedUser = await this.registerUser(ethSigner, starkSigner, user.accessToken);
|
|
1964
|
+
return new PassportImxProvider({
|
|
1965
|
+
user: updatedUser,
|
|
1966
|
+
starkSigner,
|
|
1967
|
+
passportConfig: this.config,
|
|
1968
|
+
});
|
|
1969
|
+
}
|
|
1970
|
+
const userWithEtherKey = user;
|
|
1971
|
+
return new PassportImxProvider({
|
|
1972
|
+
user: userWithEtherKey,
|
|
1973
|
+
starkSigner,
|
|
1974
|
+
passportConfig: this.config,
|
|
1975
|
+
});
|
|
1976
|
+
}
|
|
1977
|
+
async loginCallback() {
|
|
1978
|
+
return this.authManager.loginCallback();
|
|
1979
|
+
}
|
|
1980
|
+
async logout() {
|
|
1981
|
+
return this.authManager.logout();
|
|
1982
|
+
}
|
|
1983
|
+
async getUserInfo() {
|
|
1984
|
+
const user = await this.authManager.getUser();
|
|
1985
|
+
return user.profile;
|
|
1986
|
+
}
|
|
1987
|
+
async getIdToken() {
|
|
1988
|
+
const user = await this.authManager.getUser();
|
|
1989
|
+
return user.idToken;
|
|
1990
|
+
}
|
|
1991
|
+
async getAccessToken() {
|
|
1992
|
+
const user = await this.authManager.getUser();
|
|
1993
|
+
return user.accessToken;
|
|
1994
|
+
}
|
|
1995
|
+
async registerUser(userAdminKeySigner, starkSigner, jwt) {
|
|
1996
|
+
const configuration = new coreSdk.Configuration({
|
|
1997
|
+
basePath: this.config.imxApiBasePath,
|
|
1998
|
+
});
|
|
1999
|
+
const usersApi = new coreSdk.UsersApi(configuration);
|
|
2000
|
+
await registerPassport({
|
|
2001
|
+
ethSigner: userAdminKeySigner,
|
|
2002
|
+
starkSigner,
|
|
2003
|
+
usersApi,
|
|
2004
|
+
}, jwt);
|
|
2005
|
+
const updatedUser = await this.authManager.requestRefreshTokenAfterRegistration();
|
|
2006
|
+
if (!updatedUser) {
|
|
2007
|
+
throw new PassportError('Failed to get refresh token', PassportErrorType.REFRESH_TOKEN_ERROR);
|
|
2008
|
+
}
|
|
2009
|
+
return updatedUser;
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
|
|
2013
|
+
function $parcel$interopDefault(a) {
|
|
2014
|
+
return a && a.__esModule ? a.default : a;
|
|
2015
|
+
}
|
|
2016
|
+
|
|
2017
|
+
const $762782b6c862d954$export$db5daa1b5156ccfe = [
|
|
2018
|
+
{
|
|
2019
|
+
constant: true,
|
|
2020
|
+
inputs: [],
|
|
2021
|
+
name: "name",
|
|
2022
|
+
outputs: [
|
|
2023
|
+
{
|
|
2024
|
+
name: "",
|
|
2025
|
+
type: "string"
|
|
2026
|
+
}
|
|
2027
|
+
],
|
|
2028
|
+
payable: false,
|
|
2029
|
+
type: "function"
|
|
2030
|
+
},
|
|
2031
|
+
{
|
|
2032
|
+
constant: true,
|
|
2033
|
+
inputs: [],
|
|
2034
|
+
name: "decimals",
|
|
2035
|
+
outputs: [
|
|
2036
|
+
{
|
|
2037
|
+
name: "",
|
|
2038
|
+
type: "uint8"
|
|
2039
|
+
}
|
|
2040
|
+
],
|
|
2041
|
+
payable: false,
|
|
2042
|
+
type: "function"
|
|
2043
|
+
},
|
|
2044
|
+
{
|
|
2045
|
+
constant: true,
|
|
2046
|
+
inputs: [
|
|
2047
|
+
{
|
|
2048
|
+
name: "_owner",
|
|
2049
|
+
type: "address"
|
|
2050
|
+
}
|
|
2051
|
+
],
|
|
2052
|
+
name: "balanceOf",
|
|
2053
|
+
outputs: [
|
|
2054
|
+
{
|
|
2055
|
+
name: "balance",
|
|
2056
|
+
type: "uint256"
|
|
2057
|
+
}
|
|
2058
|
+
],
|
|
2059
|
+
payable: false,
|
|
2060
|
+
type: "function"
|
|
2061
|
+
},
|
|
2062
|
+
{
|
|
2063
|
+
constant: true,
|
|
2064
|
+
inputs: [],
|
|
2065
|
+
name: "symbol",
|
|
2066
|
+
outputs: [
|
|
2067
|
+
{
|
|
2068
|
+
name: "",
|
|
2069
|
+
type: "string"
|
|
2070
|
+
}
|
|
2071
|
+
],
|
|
2072
|
+
payable: false,
|
|
2073
|
+
type: "function"
|
|
2074
|
+
}
|
|
2075
|
+
];
|
|
2076
|
+
|
|
2077
|
+
|
|
2078
|
+
exports.ConnectionProviders = void 0;
|
|
2079
|
+
(function(ConnectionProviders) {
|
|
2080
|
+
ConnectionProviders["METAMASK"] = "metamask";
|
|
2081
|
+
})(exports.ConnectionProviders || (exports.ConnectionProviders = {}));
|
|
2082
|
+
|
|
2083
|
+
|
|
2084
|
+
exports.ChainId = void 0;
|
|
2085
|
+
(function(ChainId) {
|
|
2086
|
+
ChainId[ChainId["ETHEREUM"] = 1] = "ETHEREUM";
|
|
2087
|
+
ChainId[ChainId["GOERLI"] = 5] = "GOERLI";
|
|
2088
|
+
ChainId[ChainId["POLYGON"] = 137] = "POLYGON";
|
|
2089
|
+
})(exports.ChainId || (exports.ChainId = {}));
|
|
2090
|
+
const $a47e48dd2c04791b$export$f61f4aaec62f6be9 = {
|
|
2091
|
+
[exports.ChainId.ETHEREUM]: {
|
|
2092
|
+
chainIdHex: "0x1",
|
|
2093
|
+
chainName: "Ethereum",
|
|
2094
|
+
rpcUrls: [
|
|
2095
|
+
"https://mainnet.infura.io/v3/"
|
|
2096
|
+
],
|
|
2097
|
+
nativeCurrency: {
|
|
2098
|
+
name: "Ethereum",
|
|
2099
|
+
symbol: "ETH",
|
|
2100
|
+
decimals: 18
|
|
2101
|
+
},
|
|
2102
|
+
blockExplorerUrls: [
|
|
2103
|
+
"https://etherscan.io/"
|
|
2104
|
+
]
|
|
2105
|
+
},
|
|
2106
|
+
[exports.ChainId.GOERLI]: {
|
|
2107
|
+
chainIdHex: "0x5",
|
|
2108
|
+
chainName: "Goerli",
|
|
2109
|
+
rpcUrls: [
|
|
2110
|
+
"https://goerli.infura.io/v3/"
|
|
2111
|
+
],
|
|
2112
|
+
nativeCurrency: {
|
|
2113
|
+
name: "Goerli Eth",
|
|
2114
|
+
symbol: "ETH",
|
|
2115
|
+
decimals: 18
|
|
2116
|
+
},
|
|
2117
|
+
blockExplorerUrls: [
|
|
2118
|
+
"https://goerli.etherscan.io/"
|
|
2119
|
+
]
|
|
2120
|
+
},
|
|
2121
|
+
[exports.ChainId.POLYGON]: {
|
|
2122
|
+
chainIdHex: "0x89",
|
|
2123
|
+
chainName: "Polygon",
|
|
2124
|
+
rpcUrls: [
|
|
2125
|
+
"https://polygon-rpc.com"
|
|
2126
|
+
],
|
|
2127
|
+
nativeCurrency: {
|
|
2128
|
+
name: "MATIC",
|
|
2129
|
+
symbol: "MATIC",
|
|
2130
|
+
decimals: 18
|
|
2131
|
+
},
|
|
2132
|
+
blockExplorerUrls: [
|
|
2133
|
+
"https://polygonscan.com/"
|
|
2134
|
+
]
|
|
2135
|
+
}
|
|
2136
|
+
};
|
|
2137
|
+
|
|
2138
|
+
|
|
2139
|
+
exports.TokenFilterTypes = void 0;
|
|
2140
|
+
(function(TokenFilterTypes) {
|
|
2141
|
+
TokenFilterTypes["SWAP"] = "swap";
|
|
2142
|
+
TokenFilterTypes["BRIDGE"] = "bridge";
|
|
2143
|
+
TokenFilterTypes["ALL"] = "all";
|
|
2144
|
+
})(exports.TokenFilterTypes || (exports.TokenFilterTypes = {}));
|
|
2145
|
+
|
|
2146
|
+
|
|
2147
|
+
|
|
2148
|
+
|
|
2149
|
+
const $4f91c5f280efe242$export$a130407f3423b97d = {
|
|
2150
|
+
CHECK_CONNECTION: "eth_accounts",
|
|
2151
|
+
CONNECT: "eth_requestAccounts",
|
|
2152
|
+
ADD_NETWORK: "wallet_addEthereumChain",
|
|
2153
|
+
SWITCH_NETWORK: "wallet_switchEthereumChain"
|
|
2154
|
+
};
|
|
2155
|
+
exports.WalletFilterTypes = void 0;
|
|
2156
|
+
(function(WalletFilterTypes) {
|
|
2157
|
+
WalletFilterTypes["ALL"] = "all";
|
|
2158
|
+
WalletFilterTypes["DESKTOP"] = "desktop";
|
|
2159
|
+
WalletFilterTypes["MOBILE"] = "mobile";
|
|
2160
|
+
})(exports.WalletFilterTypes || (exports.WalletFilterTypes = {}));
|
|
2161
|
+
|
|
2162
|
+
|
|
2163
|
+
|
|
2164
|
+
|
|
2165
|
+
let $a8bc256d81a5e2c1$export$e3dc0620abde7f5a;
|
|
2166
|
+
(function(CheckoutErrorType) {
|
|
2167
|
+
CheckoutErrorType["CONNECT_PROVIDER_ERROR"] = "CONNECT_PROVIDER_ERROR";
|
|
2168
|
+
CheckoutErrorType["GET_BALANCE_ERROR"] = "GET_BALANCE_ERROR";
|
|
2169
|
+
CheckoutErrorType["GET_ERC20_BALANCE_ERROR"] = "GET_ERC20_BALANCE_ERROR";
|
|
2170
|
+
CheckoutErrorType["METAMASK_PROVIDER_ERROR"] = "METAMASK_PROVIDER_ERROR";
|
|
2171
|
+
CheckoutErrorType["CHAIN_NOT_SUPPORTED_ERROR"] = "CHAIN_NOT_SUPPORTED_ERROR";
|
|
2172
|
+
CheckoutErrorType["PROVIDER_REQUEST_MISSING_ERROR"] = "PROVIDER_REQUEST_MISSING_ERROR";
|
|
2173
|
+
CheckoutErrorType["USER_REJECTED_REQUEST_ERROR"] = "USER_REJECTED_REQUEST_ERROR";
|
|
2174
|
+
CheckoutErrorType["TRANSACTION_ERROR"] = "TRANSACTION_ERROR";
|
|
2175
|
+
})($a8bc256d81a5e2c1$export$e3dc0620abde7f5a || ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a = {}));
|
|
2176
|
+
class $a8bc256d81a5e2c1$export$b722478a3cbfa3bc extends Error {
|
|
2177
|
+
constructor(message, type){
|
|
2178
|
+
super(message);
|
|
2179
|
+
this.type = type;
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2182
|
+
const $a8bc256d81a5e2c1$export$bacc563de539c6c3 = async (fn, customError)=>{
|
|
2183
|
+
try {
|
|
2184
|
+
return await fn();
|
|
2185
|
+
} catch (error) {
|
|
2186
|
+
const errorMessage = customError.message || `${error.message}` || "UnknownError";
|
|
2187
|
+
throw new $a8bc256d81a5e2c1$export$b722478a3cbfa3bc(errorMessage, customError.type);
|
|
2188
|
+
}
|
|
2189
|
+
};
|
|
2190
|
+
|
|
2191
|
+
|
|
2192
|
+
|
|
2193
|
+
|
|
2194
|
+
|
|
2195
|
+
|
|
2196
|
+
|
|
2197
|
+
async function $de192de6ef100f9f$export$79f13b4cfaaf0d09(provider) {
|
|
2198
|
+
const network = await provider.getNetwork();
|
|
2199
|
+
if (!Object.values((exports.ChainId)).includes(network.chainId)) // return empty details
|
|
2200
|
+
return {};
|
|
2201
|
+
const chainIdNetworkInfo = ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[network.chainId];
|
|
2202
|
+
const networkInfo = {
|
|
2203
|
+
name: chainIdNetworkInfo.chainName,
|
|
2204
|
+
chainId: parseInt(chainIdNetworkInfo.chainIdHex, 16),
|
|
2205
|
+
nativeCurrency: chainIdNetworkInfo.nativeCurrency
|
|
2206
|
+
};
|
|
2207
|
+
return networkInfo;
|
|
2208
|
+
}
|
|
2209
|
+
async function $de192de6ef100f9f$export$b827d9418aeb5dbd(provider, chainId) {
|
|
2210
|
+
if (!Object.values((exports.ChainId)).includes(chainId)) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`${chainId} is not a supported chain`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CHAIN_NOT_SUPPORTED_ERROR);
|
|
2211
|
+
if (!provider.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("provider object is missing request function", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_MISSING_ERROR);
|
|
2212
|
+
// WT-1146 - Refer to the README in this folder for explantion on the switch network flow
|
|
2213
|
+
try {
|
|
2214
|
+
await $de192de6ef100f9f$var$switchNetworkInWallet(provider, chainId);
|
|
2215
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2216
|
+
} catch (err) {
|
|
2217
|
+
if (err.message.includes("Unrecognized chain ID")) try {
|
|
2218
|
+
await $de192de6ef100f9f$var$addNetworkToWallet(provider, chainId);
|
|
2219
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2220
|
+
} catch (err) {
|
|
2221
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("user cancelled the add network request", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR);
|
|
2222
|
+
}
|
|
2223
|
+
else throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("user cancelled the switch network request", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR);
|
|
2224
|
+
}
|
|
2225
|
+
// we can assume that if the above succeeds then user has successfully
|
|
2226
|
+
// switched to the network specified
|
|
2227
|
+
const newNetwork = ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId];
|
|
2228
|
+
return {
|
|
2229
|
+
network: {
|
|
2230
|
+
name: newNetwork.chainName,
|
|
2231
|
+
chainId: parseInt(newNetwork.chainIdHex, 16),
|
|
2232
|
+
nativeCurrency: newNetwork.nativeCurrency
|
|
2233
|
+
}
|
|
2234
|
+
};
|
|
2235
|
+
}
|
|
2236
|
+
// these functions should not be exported. These functions should be used as part of an exported function e.g switchWalletNetwork() above.
|
|
2237
|
+
// make sure to check if(provider.provider?.request) in the exported function and throw an error
|
|
2238
|
+
async function $de192de6ef100f9f$var$switchNetworkInWallet(provider, chainId) {
|
|
2239
|
+
if (provider.provider?.request) return await provider.provider.request({
|
|
2240
|
+
method: ($4f91c5f280efe242$export$a130407f3423b97d).SWITCH_NETWORK,
|
|
2241
|
+
params: [
|
|
2242
|
+
{
|
|
2243
|
+
chainId: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].chainIdHex
|
|
2244
|
+
}
|
|
2245
|
+
]
|
|
2246
|
+
});
|
|
2247
|
+
}
|
|
2248
|
+
async function $de192de6ef100f9f$var$addNetworkToWallet(provider, chainId) {
|
|
2249
|
+
if (provider.provider?.request) {
|
|
2250
|
+
const addNetwork = {
|
|
2251
|
+
chainId: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].chainIdHex,
|
|
2252
|
+
chainName: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].chainName,
|
|
2253
|
+
rpcUrls: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].rpcUrls,
|
|
2254
|
+
nativeCurrency: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].nativeCurrency,
|
|
2255
|
+
blockExplorerUrls: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].blockExplorerUrls
|
|
2256
|
+
};
|
|
2257
|
+
return await provider.provider.request({
|
|
2258
|
+
method: ($4f91c5f280efe242$export$a130407f3423b97d).ADD_NETWORK,
|
|
2259
|
+
params: [
|
|
2260
|
+
addNetwork
|
|
2261
|
+
]
|
|
2262
|
+
});
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2266
|
+
|
|
2267
|
+
|
|
2268
|
+
|
|
2269
|
+
|
|
2270
|
+
var $cda6003506e4182e$exports = {};
|
|
2271
|
+
$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\"]}]");
|
|
2272
|
+
|
|
2273
|
+
|
|
2274
|
+
const $efe60cea83bfc4e8$export$473cec51305fdae8 = function({ type: type = (exports.TokenFilterTypes).ALL , chainId: chainId , exclude: exclude }) {
|
|
2275
|
+
// todo:For API call, use the CheckoutError with errorType:API_CALL_ERROR?? or any other
|
|
2276
|
+
const filteredTokenList = ((/*@__PURE__*/$parcel$interopDefault($cda6003506e4182e$exports))).filter((token)=>{
|
|
2277
|
+
const chainIdMatches = token.chainId == chainId;
|
|
2278
|
+
const tokenNotExcluded = !exclude?.map((excludeToken)=>excludeToken.address).includes(token.address || "");
|
|
2279
|
+
const allowAllTokens = type === (exports.TokenFilterTypes).ALL;
|
|
2280
|
+
const tokenAllowedForType = token.tokenFeatures.includes(type);
|
|
2281
|
+
return chainIdMatches && tokenNotExcluded && (allowAllTokens || tokenAllowedForType);
|
|
2282
|
+
}).map((token)=>{
|
|
2283
|
+
const { chainId: chainId , tokenFeatures: tokenFeatures , ...tokenInfo } = token;
|
|
2284
|
+
return tokenInfo;
|
|
2285
|
+
});
|
|
2286
|
+
return {
|
|
2287
|
+
tokens: filteredTokenList
|
|
2288
|
+
};
|
|
2289
|
+
};
|
|
2290
|
+
|
|
2291
|
+
|
|
2292
|
+
|
|
2293
|
+
|
|
2294
|
+
const $1564e43dde50bb61$export$df96cd8d56be0ab1 = async (provider, walletAddress)=>{
|
|
2295
|
+
return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2296
|
+
const networkInfo = await ($de192de6ef100f9f$export$79f13b4cfaaf0d09)(provider);
|
|
2297
|
+
const balance = await provider.getBalance(walletAddress);
|
|
2298
|
+
return {
|
|
2299
|
+
balance: balance,
|
|
2300
|
+
formattedBalance: (ethers.utils).formatUnits(balance, networkInfo.nativeCurrency.decimals),
|
|
2301
|
+
token: networkInfo.nativeCurrency
|
|
2302
|
+
};
|
|
2303
|
+
}, {
|
|
2304
|
+
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_BALANCE_ERROR
|
|
2305
|
+
});
|
|
2306
|
+
};
|
|
2307
|
+
async function $1564e43dde50bb61$export$60e0fe116a0e6ed0(provider, walletAddress, contractAddress) {
|
|
2308
|
+
return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2309
|
+
const contract = new (ethers.Contract)(contractAddress, JSON.stringify(($762782b6c862d954$export$db5daa1b5156ccfe)), provider);
|
|
2310
|
+
const name = await contract.name();
|
|
2311
|
+
const symbol = await contract.symbol();
|
|
2312
|
+
const balance = await contract.balanceOf(walletAddress);
|
|
2313
|
+
const decimals = await contract.decimals();
|
|
2314
|
+
const formattedBalance = (ethers.utils).formatUnits(balance, decimals);
|
|
2315
|
+
return {
|
|
2316
|
+
balance: balance,
|
|
2317
|
+
formattedBalance: formattedBalance,
|
|
2318
|
+
token: {
|
|
2319
|
+
name: name,
|
|
2320
|
+
symbol: symbol,
|
|
2321
|
+
decimals: decimals,
|
|
2322
|
+
address: contractAddress
|
|
2323
|
+
}
|
|
2324
|
+
};
|
|
2325
|
+
}, {
|
|
2326
|
+
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC20_BALANCE_ERROR
|
|
2327
|
+
});
|
|
2328
|
+
}
|
|
2329
|
+
const $1564e43dde50bb61$export$fee49741664a4d7e = async (provider, walletAddress, chainId)=>{
|
|
2330
|
+
if (!Object.values((exports.ChainId)).includes(chainId)) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`ChainId ${chainId} is not supported`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CHAIN_NOT_SUPPORTED_ERROR);
|
|
2331
|
+
if (!provider.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("provider object is missing request function", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_MISSING_ERROR);
|
|
2332
|
+
const tokenList = ($efe60cea83bfc4e8$export$473cec51305fdae8)({
|
|
2333
|
+
type: (exports.TokenFilterTypes).ALL,
|
|
2334
|
+
chainId: chainId
|
|
2335
|
+
});
|
|
2336
|
+
const allBalancePromises = [];
|
|
2337
|
+
allBalancePromises.push($1564e43dde50bb61$export$df96cd8d56be0ab1(provider, walletAddress));
|
|
2338
|
+
tokenList.tokens.filter((token)=>token.address).forEach((token)=>allBalancePromises.push($1564e43dde50bb61$export$60e0fe116a0e6ed0(provider, walletAddress, token.address ?? "")));
|
|
2339
|
+
const balanceResults = await Promise.allSettled(allBalancePromises);
|
|
2340
|
+
const getBalanceResults = balanceResults.filter((result)=>result.status === "fulfilled").map((fulfilledResult)=>fulfilledResult.value);
|
|
2341
|
+
return {
|
|
2342
|
+
balances: getBalanceResults
|
|
2343
|
+
};
|
|
2344
|
+
};
|
|
2345
|
+
|
|
2346
|
+
|
|
2347
|
+
|
|
2348
|
+
|
|
2349
|
+
|
|
2350
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2351
|
+
|
|
2352
|
+
|
|
2353
|
+
|
|
2354
|
+
async function $c99672cf2294e839$export$2d040992269b4717(providerPreference) {
|
|
2355
|
+
const provider = await $c99672cf2294e839$var$getWalletProviderForPreference(providerPreference);
|
|
2356
|
+
if (!provider.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Incompatible provider", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_MISSING_ERROR);
|
|
2357
|
+
const accounts = await provider.provider.request({
|
|
2358
|
+
method: ($4f91c5f280efe242$export$a130407f3423b97d).CHECK_CONNECTION,
|
|
2359
|
+
params: []
|
|
2360
|
+
});
|
|
2361
|
+
// accounts[0] will have the active account if connected.
|
|
2362
|
+
return {
|
|
2363
|
+
isConnected: accounts && accounts.length > 0,
|
|
2364
|
+
walletAddress: accounts[0] ?? ""
|
|
2365
|
+
};
|
|
2366
|
+
}
|
|
2367
|
+
async function $c99672cf2294e839$export$fba2f6c3656e07c1(params) {
|
|
2368
|
+
const web3Provider = await $c99672cf2294e839$var$getWalletProviderForPreference(params.providerPreference);
|
|
2369
|
+
await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2370
|
+
if (!web3Provider || !web3Provider?.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No MetaMask provider installed.", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).METAMASK_PROVIDER_ERROR);
|
|
2371
|
+
// this makes the request to the wallet to connect i.e request eth accounts ('eth_requestAccounts')
|
|
2372
|
+
await web3Provider.provider.request({
|
|
2373
|
+
method: ($4f91c5f280efe242$export$a130407f3423b97d).CONNECT,
|
|
2374
|
+
params: []
|
|
2375
|
+
});
|
|
2376
|
+
}, {
|
|
2377
|
+
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR
|
|
2378
|
+
});
|
|
2379
|
+
return web3Provider;
|
|
2380
|
+
}
|
|
2381
|
+
async function $c99672cf2294e839$var$getWalletProviderForPreference(providerPreference) {
|
|
2382
|
+
let web3Provider = null;
|
|
2383
|
+
switch(providerPreference){
|
|
2384
|
+
case (exports.ConnectionProviders).METAMASK:
|
|
2385
|
+
web3Provider = await $c99672cf2294e839$var$getMetaMaskProvider();
|
|
2386
|
+
break;
|
|
2387
|
+
default:
|
|
2388
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Provider preference was not detected", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CONNECT_PROVIDER_ERROR);
|
|
2389
|
+
}
|
|
2390
|
+
return web3Provider;
|
|
2391
|
+
}
|
|
2392
|
+
async function $c99672cf2294e839$var$getMetaMaskProvider() {
|
|
2393
|
+
const provider = await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2394
|
+
return await (detectEthereumProvider)();
|
|
2395
|
+
}, {
|
|
2396
|
+
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).METAMASK_PROVIDER_ERROR
|
|
2397
|
+
});
|
|
2398
|
+
if (!provider || !provider.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No MetaMask provider installed.", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).METAMASK_PROVIDER_ERROR);
|
|
2399
|
+
return new (providers.Web3Provider)(provider);
|
|
2400
|
+
}
|
|
2401
|
+
|
|
2402
|
+
|
|
2403
|
+
|
|
2404
|
+
|
|
2405
|
+
|
|
2406
|
+
var $6f3c55a615003cbf$exports = {};
|
|
2407
|
+
$6f3c55a615003cbf$exports = JSON.parse('[{"connectionProvider":"metamask","icon":"some-icon-url","name":"MetaMask","description":"complete web3 wallet solution","platform":["mobile","desktop"]},{"connectionProvider":"passport","icon":"pp-icon","name":"Passport","description":"Web3 with your email!","platform":["mobile"]},{"connectionProvider":"gamestop","icon":"gme-icon","name":"GameStop","description":"Never stopping the game!","platform":["desktop"]}]');
|
|
2408
|
+
|
|
2409
|
+
|
|
2410
|
+
async function $5cdde2ffe6360fec$export$a822caa90d7eef09({ type: type = (exports.WalletFilterTypes).ALL , exclude: exclude }) {
|
|
2411
|
+
// todo:For async API call, use the CheckoutError with errorType:API_CALL_ERROR?? or any other
|
|
2412
|
+
const filteredWalletsList = ((/*@__PURE__*/$parcel$interopDefault($6f3c55a615003cbf$exports))).filter((wallet)=>{
|
|
2413
|
+
const walletNotExcluded = !exclude?.map((excludeWallet)=>excludeWallet.connectionProvider).includes(wallet.connectionProvider);
|
|
2414
|
+
const allowAllWallets = type === (exports.WalletFilterTypes).ALL;
|
|
2415
|
+
const walletsAllowedForType = wallet.platform.includes(type);
|
|
2416
|
+
return walletNotExcluded && (allowAllWallets || walletsAllowedForType);
|
|
2417
|
+
}).map((wallet)=>{
|
|
2418
|
+
const { platform: platform , ...walletInfo } = wallet;
|
|
2419
|
+
return walletInfo;
|
|
2420
|
+
});
|
|
2421
|
+
return {
|
|
2422
|
+
allowedWallets: filteredWalletsList
|
|
2423
|
+
};
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2426
|
+
|
|
2427
|
+
|
|
2428
|
+
|
|
2429
|
+
|
|
2430
|
+
|
|
2431
|
+
const $dbe95599a4661140$export$8e0e7ffc78696d30 = async (params)=>{
|
|
2432
|
+
const { provider: provider , transaction: transaction } = params;
|
|
2433
|
+
return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2434
|
+
const transactionResponse = await provider.getSigner().sendTransaction(transaction);
|
|
2435
|
+
return {
|
|
2436
|
+
transactionResponse: transactionResponse
|
|
2437
|
+
};
|
|
2438
|
+
}, {
|
|
2439
|
+
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).TRANSACTION_ERROR
|
|
2440
|
+
});
|
|
2441
|
+
};
|
|
2442
|
+
|
|
2443
|
+
|
|
2444
|
+
|
|
2445
|
+
|
|
2446
|
+
class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
|
|
2447
|
+
async checkIsWalletConnected(params) {
|
|
2448
|
+
return $c99672cf2294e839$export$2d040992269b4717(params.providerPreference);
|
|
2449
|
+
}
|
|
2450
|
+
async connect(params) {
|
|
2451
|
+
const provider = await $c99672cf2294e839$export$fba2f6c3656e07c1(params);
|
|
2452
|
+
const network = await ($de192de6ef100f9f$export$79f13b4cfaaf0d09)(provider);
|
|
2453
|
+
return {
|
|
2454
|
+
provider: provider,
|
|
2455
|
+
network: network
|
|
2456
|
+
};
|
|
2457
|
+
}
|
|
2458
|
+
async switchNetwork(params) {
|
|
2459
|
+
return await ($de192de6ef100f9f$export$b827d9418aeb5dbd)(params.provider, params.chainId);
|
|
2460
|
+
}
|
|
2461
|
+
async getBalance(params) {
|
|
2462
|
+
if (!params.contractAddress || params.contractAddress === "") return await $1564e43dde50bb61$export$df96cd8d56be0ab1(params.provider, params.walletAddress);
|
|
2463
|
+
return await $1564e43dde50bb61$export$60e0fe116a0e6ed0(params.provider, params.walletAddress, params.contractAddress);
|
|
2464
|
+
}
|
|
2465
|
+
async getAllBalances(params) {
|
|
2466
|
+
return $1564e43dde50bb61$export$fee49741664a4d7e(params.provider, params.walletAddress, params.chainId);
|
|
2467
|
+
}
|
|
2468
|
+
getTokenAllowList(params) {
|
|
2469
|
+
return $efe60cea83bfc4e8$export$473cec51305fdae8(params);
|
|
2470
|
+
}
|
|
2471
|
+
async getWalletsAllowList(params) {
|
|
2472
|
+
return await $5cdde2ffe6360fec$export$a822caa90d7eef09(params);
|
|
2473
|
+
}
|
|
2474
|
+
async sendTransaction(params) {
|
|
2475
|
+
return await $dbe95599a4661140$export$8e0e7ffc78696d30(params);
|
|
2476
|
+
}
|
|
2477
|
+
}
|
|
2478
|
+
|
|
2479
|
+
function $parcel$export(e, n, v, s) {
|
|
2480
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
2481
|
+
}
|
|
2482
|
+
var $88e4c575901cd68c$exports = {};
|
|
2483
|
+
|
|
2484
|
+
$parcel$export($88e4c575901cd68c$exports, "IMTBLWidgetEvents", () => exports.IMTBLWidgetEvents);
|
|
2485
|
+
exports.IMTBLWidgetEvents = void 0;
|
|
2486
|
+
(function(IMTBLWidgetEvents) {
|
|
2487
|
+
IMTBLWidgetEvents["IMTBL_CONNECT_WIDGET_EVENT"] = "imtbl-connect-widget";
|
|
2488
|
+
IMTBLWidgetEvents["IMTBL_WALLET_WIDGET_EVENT"] = "imtbl-wallet-widget";
|
|
2489
|
+
IMTBLWidgetEvents["IMTBL_SWAP_WIDGET_EVENT"] = "imtbl-swap-widget";
|
|
2490
|
+
IMTBLWidgetEvents["IMTBL_BRIDGE_WIDGET_EVENT"] = "imtbl-bridge-widget";
|
|
2491
|
+
IMTBLWidgetEvents["IMTBL_BUY_WIDGET_EVENT"] = "imtbl-buy-widget";
|
|
2492
|
+
})(exports.IMTBLWidgetEvents || (exports.IMTBLWidgetEvents = {}));
|
|
2493
|
+
|
|
2494
|
+
|
|
2495
|
+
var $d71a87afc3136184$exports = {};
|
|
2496
|
+
|
|
2497
|
+
$parcel$export($d71a87afc3136184$exports, "ConnectEventType", () => exports.ConnectEventType);
|
|
2498
|
+
exports.ConnectEventType = void 0;
|
|
2499
|
+
(function(ConnectEventType) {
|
|
2500
|
+
ConnectEventType["SUCCESS"] = "success";
|
|
2501
|
+
ConnectEventType["FAILURE"] = "failure";
|
|
2502
|
+
})(exports.ConnectEventType || (exports.ConnectEventType = {}));
|
|
2503
|
+
|
|
2504
|
+
|
|
2505
|
+
var $9d0f1783d4d36e8a$exports = {};
|
|
2506
|
+
|
|
2507
|
+
$parcel$export($9d0f1783d4d36e8a$exports, "WalletEventType", () => exports.WalletEventType);
|
|
2508
|
+
//wallet widget events
|
|
2509
|
+
exports.WalletEventType = void 0;
|
|
2510
|
+
(function(WalletEventType) {
|
|
2511
|
+
WalletEventType["CLOSE_WIDGET"] = "close-widget";
|
|
2512
|
+
WalletEventType["NETWORK_SWITCH"] = "network-switch";
|
|
2513
|
+
})(exports.WalletEventType || (exports.WalletEventType = {}));
|
|
2514
|
+
|
|
2515
|
+
|
|
2516
|
+
var $5d497088f13bb116$exports = {};
|
|
2517
|
+
|
|
2518
|
+
$parcel$export($5d497088f13bb116$exports, "SwapEventType", () => exports.SwapEventType);
|
|
2519
|
+
exports.SwapEventType = void 0;
|
|
2520
|
+
(function(SwapEventType) {
|
|
2521
|
+
SwapEventType["SUCCESS"] = "success";
|
|
2522
|
+
SwapEventType["FAILURE"] = "failure";
|
|
2523
|
+
})(exports.SwapEventType || (exports.SwapEventType = {}));
|
|
2524
|
+
|
|
2525
|
+
|
|
2526
|
+
var $28a5fdc2f5e6c742$exports = {};
|
|
2527
|
+
|
|
2528
|
+
$parcel$export($28a5fdc2f5e6c742$exports, "BridgeEventType", () => exports.BridgeEventType);
|
|
2529
|
+
exports.BridgeEventType = void 0;
|
|
2530
|
+
(function(BridgeEventType) {
|
|
2531
|
+
BridgeEventType["CLOSE_WIDGET"] = "close-widget";
|
|
2532
|
+
BridgeEventType["SUCCESS"] = "success";
|
|
2533
|
+
BridgeEventType["FAILURE"] = "failure";
|
|
2534
|
+
})(exports.BridgeEventType || (exports.BridgeEventType = {}));
|
|
2535
|
+
|
|
2536
|
+
|
|
2537
|
+
var $ede253beebe0de4a$exports = {};
|
|
2538
|
+
|
|
2539
|
+
$parcel$export($ede253beebe0de4a$exports, "BuyEventType", () => exports.BuyEventType);
|
|
2540
|
+
exports.BuyEventType = void 0;
|
|
2541
|
+
(function(BuyEventType) {
|
|
2542
|
+
BuyEventType["SUCCESS"] = "success";
|
|
2543
|
+
BuyEventType["FAILURE"] = "failure";
|
|
2544
|
+
BuyEventType["NOT_CONNECTED"] = "not_connected";
|
|
2545
|
+
BuyEventType["CLOSE"] = "close";
|
|
2546
|
+
})(exports.BuyEventType || (exports.BuyEventType = {}));
|
|
2547
|
+
|
|
2548
|
+
|
|
2549
|
+
var $9234b4c577442a97$exports = {};
|
|
2550
|
+
|
|
2551
|
+
$parcel$export($9234b4c577442a97$exports, "Network", () => exports.Network);
|
|
2552
|
+
$parcel$export($9234b4c577442a97$exports, "WidgetTheme", () => exports.WidgetTheme);
|
|
2553
|
+
$parcel$export($9234b4c577442a97$exports, "ConnectionProviders", () => exports.ConnectionProviders);
|
|
2554
|
+
|
|
2555
|
+
exports.Network = void 0;
|
|
2556
|
+
(function(Network) {
|
|
2557
|
+
Network["ETHEREUM"] = "Ethereum";
|
|
2558
|
+
Network["GOERLI"] = "Goerli";
|
|
2559
|
+
Network["POLYGON"] = "Polygon";
|
|
2560
|
+
})(exports.Network || (exports.Network = {}));
|
|
2561
|
+
exports.WidgetTheme = void 0;
|
|
2562
|
+
(function(WidgetTheme) {
|
|
2563
|
+
WidgetTheme["LIGHT"] = "light";
|
|
2564
|
+
WidgetTheme["DARK"] = "dark";
|
|
2565
|
+
WidgetTheme["CUSTOM"] = "custom";
|
|
2566
|
+
})(exports.WidgetTheme || (exports.WidgetTheme = {}));
|
|
2567
|
+
|
|
2568
|
+
exports.Checkout = $a8cb37a3fc8eb863$export$1f60ba4ec72508a0;
|
|
2569
|
+
exports.GenericIMXProvider = GenericIMXProvider;
|
|
2570
|
+
exports.ImmutableConfiguration = ImmutableConfiguration;
|
|
2571
|
+
exports.MetaMaskIMXProvider = MetaMaskIMXProvider;
|
|
2572
|
+
exports.Passport = Passport;
|
|
2573
|
+
exports.PassportConfiguration = PassportConfiguration;
|
|
2574
|
+
exports.PassportError = PassportError;
|
|
2575
|
+
exports.ProviderConfiguration = ProviderConfiguration;
|
|
2576
|
+
exports.StarkExAPIFactory = StarkExAPIFactory;
|