@imtbl/sdk 0.1.0-alpha → 0.1.1
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/immutablex_client.js +2 -2
- package/dist/index.cjs +10 -1776
- package/dist/index.d.ts +5 -15196
- package/dist/index.js +15 -1776
- package/dist/passport.d.ts +1 -13
- package/dist/passport.js +1 -1
- package/package.json +1 -13
- package/dist/checkout_sdk.d.ts +0 -932
- package/dist/checkout_sdk.js +0 -609
- package/dist/checkout_widgets.d.ts +0 -14458
- package/dist/checkout_widgets.js +0 -200
- package/dist/provider.d.ts +0 -962
- package/dist/provider.js +0 -1139
package/dist/index.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import { ImmutableX, Config, Configuration, UsersApi, TransfersApi, OrdersApi, ExchangesApi, TradesApi, generateLegacyStarkPrivateKey, createStarkSigner
|
|
1
|
+
import { ImmutableX, Config, Configuration, UsersApi, TransfersApi, OrdersApi, ExchangesApi, TradesApi, generateLegacyStarkPrivateKey, createStarkSigner } from '@imtbl/core-sdk';
|
|
2
2
|
export { createStarkSigner as imxClientCreateStarkSigner, generateLegacyStarkPrivateKey as imxClientGenerateLegacyStarkPrivateKey } from '@imtbl/core-sdk';
|
|
3
3
|
import { UserManager } from 'oidc-client-ts';
|
|
4
|
-
import { ethers
|
|
4
|
+
import { ethers } from 'ethers';
|
|
5
5
|
import { Magic } from 'magic-sdk';
|
|
6
6
|
import { OpenIdExtension } from '@magic-ext/oidc';
|
|
7
7
|
import BN from 'bn.js';
|
|
8
8
|
import * as encUtils from 'enc-utils';
|
|
9
|
-
import { parseUnits } from '@ethersproject/units';
|
|
10
|
-
import { BigNumber } from '@ethersproject/bignumber';
|
|
11
|
-
import detectEthereumProvider from '@metamask/detect-provider';
|
|
12
|
-
import { Web3Provider } from '@ethersproject/providers';
|
|
13
9
|
|
|
14
10
|
var Environment;
|
|
15
11
|
(function (Environment) {
|
|
@@ -32,7 +28,7 @@ const PRODUCTION = () => {
|
|
|
32
28
|
chainID: 1,
|
|
33
29
|
coreContractAddress: '0x5FDCCA53617f4d2b9134B29090C87D01058e27e9',
|
|
34
30
|
registrationContractAddress: '0x72a06bf2a1CE5e39cBA06c0CAb824960B587d64c',
|
|
35
|
-
sdkVersion: 'ts-immutable-sdk-0.
|
|
31
|
+
sdkVersion: 'ts-immutable-sdk-0.0.0',
|
|
36
32
|
});
|
|
37
33
|
};
|
|
38
34
|
// Set `sdkVersion` on config
|
|
@@ -42,7 +38,7 @@ const SANDBOX = () => {
|
|
|
42
38
|
chainID: 5,
|
|
43
39
|
coreContractAddress: '0x7917eDb51ecD6CdB3F9854c3cc593F33de10c623',
|
|
44
40
|
registrationContractAddress: '0x1C97Ada273C9A52253f463042f29117090Cd7D83',
|
|
45
|
-
sdkVersion: 'ts-immutable-sdk-0.
|
|
41
|
+
sdkVersion: 'ts-immutable-sdk-0.0.0',
|
|
46
42
|
});
|
|
47
43
|
};
|
|
48
44
|
class ImxConfiguration {
|
|
@@ -553,15 +549,6 @@ async function signRaw(payload, signer) {
|
|
|
553
549
|
const signature = deserializeSignature(await signer.signMessage(payload));
|
|
554
550
|
return serializeEthSignature(signature);
|
|
555
551
|
}
|
|
556
|
-
async function signMessage(message, signer) {
|
|
557
|
-
const ethAddress = await signer.getAddress();
|
|
558
|
-
const ethSignature = await signRaw(message, signer);
|
|
559
|
-
return {
|
|
560
|
-
message,
|
|
561
|
-
ethAddress,
|
|
562
|
-
ethSignature,
|
|
563
|
-
};
|
|
564
|
-
}
|
|
565
552
|
|
|
566
553
|
/**
|
|
567
554
|
* Helper method to convert token type to a SignableToken type
|
|
@@ -875,7 +862,7 @@ class ConfirmationScreen {
|
|
|
875
862
|
}
|
|
876
863
|
|
|
877
864
|
const ERC721$1 = 'ERC721';
|
|
878
|
-
const transfer
|
|
865
|
+
const transfer = ({ request, transfersApi, starkSigner, user, passportConfig, }) => {
|
|
879
866
|
return withPassportError(async () => {
|
|
880
867
|
const transferAmount = request.type === ERC721$1 ? '1' : request.amount;
|
|
881
868
|
const getSignableTransferRequest = {
|
|
@@ -985,7 +972,7 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, pass
|
|
|
985
972
|
}
|
|
986
973
|
|
|
987
974
|
const ERC721 = 'ERC721';
|
|
988
|
-
async function createOrder
|
|
975
|
+
async function createOrder({ starkSigner, user, request, ordersApi, passportConfig, }) {
|
|
989
976
|
return withPassportError(async () => {
|
|
990
977
|
const ethAddress = user.etherKey;
|
|
991
978
|
const amountSell = request.sell.type === ERC721 ? '1' : request.sell.amount;
|
|
@@ -1040,7 +1027,7 @@ async function createOrder$1({ starkSigner, user, request, ordersApi, passportCo
|
|
|
1040
1027
|
};
|
|
1041
1028
|
}, PassportErrorType.CREATE_ORDER_ERROR);
|
|
1042
1029
|
}
|
|
1043
|
-
async function cancelOrder
|
|
1030
|
+
async function cancelOrder({ user, starkSigner, request, ordersApi, passportConfig, }) {
|
|
1044
1031
|
return withPassportError(async () => {
|
|
1045
1032
|
const getSignableCancelOrderRequest = {
|
|
1046
1033
|
order_id: request.order_id,
|
|
@@ -1075,7 +1062,7 @@ async function cancelOrder$1({ user, starkSigner, request, ordersApi, passportCo
|
|
|
1075
1062
|
}, PassportErrorType.CANCEL_ORDER_ERROR);
|
|
1076
1063
|
}
|
|
1077
1064
|
|
|
1078
|
-
async function exchangeTransfer
|
|
1065
|
+
async function exchangeTransfer({ user, starkSigner, request, exchangesApi, }) {
|
|
1079
1066
|
return withPassportError(async () => {
|
|
1080
1067
|
const ethAddress = user.etherKey;
|
|
1081
1068
|
const transferAmount = request.amount;
|
|
@@ -1118,7 +1105,7 @@ async function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, })
|
|
|
1118
1105
|
}, PassportErrorType.EXCHANGE_TRANSFER_ERROR);
|
|
1119
1106
|
}
|
|
1120
1107
|
|
|
1121
|
-
async function createTrade
|
|
1108
|
+
async function createTrade({ request, tradesApi, user, starkSigner, passportConfig, }) {
|
|
1122
1109
|
return withPassportError(async () => {
|
|
1123
1110
|
const ethAddress = user.etherKey;
|
|
1124
1111
|
const getSignableTradeRequest = {
|
|
@@ -1188,7 +1175,7 @@ class PassportImxProvider {
|
|
|
1188
1175
|
this.tradesApi = new TradesApi(apiConfig);
|
|
1189
1176
|
}
|
|
1190
1177
|
async transfer(request) {
|
|
1191
|
-
return transfer
|
|
1178
|
+
return transfer({
|
|
1192
1179
|
request,
|
|
1193
1180
|
user: this.user,
|
|
1194
1181
|
starkSigner: this.starkSigner,
|
|
@@ -1203,7 +1190,7 @@ class PassportImxProvider {
|
|
|
1203
1190
|
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
1204
1191
|
}
|
|
1205
1192
|
createOrder(request) {
|
|
1206
|
-
return createOrder
|
|
1193
|
+
return createOrder({
|
|
1207
1194
|
request,
|
|
1208
1195
|
user: this.user,
|
|
1209
1196
|
starkSigner: this.starkSigner,
|
|
@@ -1212,7 +1199,7 @@ class PassportImxProvider {
|
|
|
1212
1199
|
});
|
|
1213
1200
|
}
|
|
1214
1201
|
cancelOrder(request) {
|
|
1215
|
-
return cancelOrder
|
|
1202
|
+
return cancelOrder({
|
|
1216
1203
|
request,
|
|
1217
1204
|
user: this.user,
|
|
1218
1205
|
starkSigner: this.starkSigner,
|
|
@@ -1221,7 +1208,7 @@ class PassportImxProvider {
|
|
|
1221
1208
|
});
|
|
1222
1209
|
}
|
|
1223
1210
|
createTrade(request) {
|
|
1224
|
-
return createTrade
|
|
1211
|
+
return createTrade({
|
|
1225
1212
|
request,
|
|
1226
1213
|
user: this.user,
|
|
1227
1214
|
starkSigner: this.starkSigner,
|
|
@@ -1239,7 +1226,7 @@ class PassportImxProvider {
|
|
|
1239
1226
|
});
|
|
1240
1227
|
}
|
|
1241
1228
|
exchangeTransfer(request) {
|
|
1242
|
-
return exchangeTransfer
|
|
1229
|
+
return exchangeTransfer({
|
|
1243
1230
|
request,
|
|
1244
1231
|
user: this.user,
|
|
1245
1232
|
starkSigner: this.starkSigner,
|
|
@@ -1454,1752 +1441,4 @@ class Passport {
|
|
|
1454
1441
|
}
|
|
1455
1442
|
}
|
|
1456
1443
|
|
|
1457
|
-
|
|
1458
|
-
return chainID === config.ethConfiguration.chainID;
|
|
1459
|
-
}
|
|
1460
|
-
async function validateChain(signer, config) {
|
|
1461
|
-
const chainID = await signer.getChainId();
|
|
1462
|
-
if (!isChainValid(chainID, config))
|
|
1463
|
-
throw new Error('The wallet used for this operation is not connected to the correct network.');
|
|
1464
|
-
}
|
|
1465
|
-
|
|
1466
|
-
async function transfer({ signers: { ethSigner, starkSigner }, request, config, }) {
|
|
1467
|
-
await validateChain(ethSigner, config.immutableXConfig);
|
|
1468
|
-
const ethAddress = await ethSigner.getAddress();
|
|
1469
|
-
const transfersApi = new TransfersApi(config.immutableXConfig.apiConfiguration);
|
|
1470
|
-
const transferAmount = request.type === 'ERC721' ? '1' : request.amount;
|
|
1471
|
-
const signableResult = await transfersApi.getSignableTransferV1({
|
|
1472
|
-
getSignableTransferRequest: {
|
|
1473
|
-
sender: ethAddress,
|
|
1474
|
-
token: convertToSignableToken(request),
|
|
1475
|
-
amount: transferAmount,
|
|
1476
|
-
receiver: request.receiver,
|
|
1477
|
-
},
|
|
1478
|
-
});
|
|
1479
|
-
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
1480
|
-
const ethSignature = await signRaw(signableMessage, ethSigner);
|
|
1481
|
-
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
1482
|
-
const transferSigningParams = {
|
|
1483
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1484
|
-
sender_stark_key: signableResult.data.sender_stark_key,
|
|
1485
|
-
sender_vault_id: signableResult.data.sender_vault_id,
|
|
1486
|
-
receiver_stark_key: signableResult.data.receiver_stark_key,
|
|
1487
|
-
receiver_vault_id: signableResult.data.receiver_vault_id,
|
|
1488
|
-
asset_id: signableResult.data.asset_id,
|
|
1489
|
-
amount: signableResult.data.amount,
|
|
1490
|
-
nonce: signableResult.data.nonce,
|
|
1491
|
-
expiration_timestamp: signableResult.data.expiration_timestamp,
|
|
1492
|
-
stark_signature: starkSignature,
|
|
1493
|
-
};
|
|
1494
|
-
const response = await transfersApi.createTransferV1({
|
|
1495
|
-
createTransferRequest: transferSigningParams,
|
|
1496
|
-
xImxEthAddress: ethAddress,
|
|
1497
|
-
xImxEthSignature: ethSignature,
|
|
1498
|
-
});
|
|
1499
|
-
return {
|
|
1500
|
-
sent_signature: response?.data.sent_signature,
|
|
1501
|
-
status: response?.data.status?.toString(),
|
|
1502
|
-
time: response?.data.time,
|
|
1503
|
-
transfer_id: response?.data.transfer_id,
|
|
1504
|
-
};
|
|
1505
|
-
}
|
|
1506
|
-
async function batchTransfer({ signers: { ethSigner, starkSigner }, request, config, }) {
|
|
1507
|
-
await validateChain(ethSigner, config.immutableXConfig);
|
|
1508
|
-
const ethAddress = await ethSigner.getAddress();
|
|
1509
|
-
const transfersApi = new TransfersApi(config.immutableXConfig.apiConfiguration);
|
|
1510
|
-
const signableRequests = request.map((nftTransfer) => {
|
|
1511
|
-
return {
|
|
1512
|
-
amount: '1',
|
|
1513
|
-
token: convertToSignableToken({
|
|
1514
|
-
type: 'ERC721',
|
|
1515
|
-
tokenId: nftTransfer.tokenId,
|
|
1516
|
-
tokenAddress: nftTransfer.tokenAddress,
|
|
1517
|
-
}),
|
|
1518
|
-
receiver: nftTransfer.receiver,
|
|
1519
|
-
};
|
|
1520
|
-
});
|
|
1521
|
-
const signableResult = await transfersApi.getSignableTransfer({
|
|
1522
|
-
getSignableTransferRequestV2: {
|
|
1523
|
-
sender_ether_key: ethAddress,
|
|
1524
|
-
signable_requests: signableRequests,
|
|
1525
|
-
},
|
|
1526
|
-
});
|
|
1527
|
-
const signableMessage = signableResult.data.signable_message;
|
|
1528
|
-
if (signableMessage === undefined) {
|
|
1529
|
-
throw new Error('Invalid response from Signable registration offchain');
|
|
1530
|
-
}
|
|
1531
|
-
const ethSignature = await signRaw(signableMessage, ethSigner);
|
|
1532
|
-
const requests = [];
|
|
1533
|
-
for (const resp of signableResult.data.signable_responses) {
|
|
1534
|
-
const starkSignature = await starkSigner.signMessage(resp.payload_hash);
|
|
1535
|
-
const req = {
|
|
1536
|
-
sender_vault_id: resp.sender_vault_id,
|
|
1537
|
-
receiver_stark_key: resp.receiver_stark_key,
|
|
1538
|
-
receiver_vault_id: resp.receiver_vault_id,
|
|
1539
|
-
asset_id: resp.asset_id,
|
|
1540
|
-
amount: resp.amount,
|
|
1541
|
-
nonce: resp.nonce,
|
|
1542
|
-
expiration_timestamp: resp.expiration_timestamp,
|
|
1543
|
-
stark_signature: starkSignature,
|
|
1544
|
-
};
|
|
1545
|
-
requests.push(req);
|
|
1546
|
-
}
|
|
1547
|
-
// TODO: throw error on missing payload hash?
|
|
1548
|
-
const transferSigningParams = {
|
|
1549
|
-
sender_stark_key: signableResult.data.sender_stark_key,
|
|
1550
|
-
requests,
|
|
1551
|
-
};
|
|
1552
|
-
const response = await transfersApi.createTransfer({
|
|
1553
|
-
createTransferRequestV2: transferSigningParams,
|
|
1554
|
-
xImxEthAddress: ethAddress,
|
|
1555
|
-
xImxEthSignature: ethSignature,
|
|
1556
|
-
});
|
|
1557
|
-
return {
|
|
1558
|
-
transfer_ids: response?.data.transfer_ids,
|
|
1559
|
-
};
|
|
1560
|
-
}
|
|
1561
|
-
|
|
1562
|
-
async function createOrder({ signers, request, config, }) {
|
|
1563
|
-
await validateChain(signers.ethSigner, config.immutableXConfig);
|
|
1564
|
-
const ethAddress = await signers.ethSigner.getAddress();
|
|
1565
|
-
const ordersApi = new OrdersApi(config.immutableXConfig.apiConfiguration);
|
|
1566
|
-
const amountSell = request.sell.type === 'ERC721' ? '1' : request.sell.amount;
|
|
1567
|
-
const amountBuy = request.buy.type === 'ERC721' ? '1' : request.buy.amount;
|
|
1568
|
-
const getSignableOrderRequest = {
|
|
1569
|
-
user: ethAddress,
|
|
1570
|
-
amount_buy: amountBuy,
|
|
1571
|
-
token_buy: convertToSignableToken(request.buy),
|
|
1572
|
-
amount_sell: amountSell,
|
|
1573
|
-
token_sell: convertToSignableToken(request.sell),
|
|
1574
|
-
fees: request.fees,
|
|
1575
|
-
expiration_timestamp: request.expiration_timestamp,
|
|
1576
|
-
};
|
|
1577
|
-
const getSignableOrderResponse = await ordersApi.getSignableOrder({
|
|
1578
|
-
getSignableOrderRequestV3: getSignableOrderRequest,
|
|
1579
|
-
});
|
|
1580
|
-
const { signable_message: signableMessage, payload_hash: payloadHash } = getSignableOrderResponse.data;
|
|
1581
|
-
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
1582
|
-
const starkSignature = await signers.starkSigner.signMessage(payloadHash);
|
|
1583
|
-
const resp = getSignableOrderResponse.data;
|
|
1584
|
-
const orderParams = {
|
|
1585
|
-
createOrderRequest: {
|
|
1586
|
-
amount_buy: resp.amount_buy,
|
|
1587
|
-
amount_sell: resp.amount_sell,
|
|
1588
|
-
asset_id_buy: resp.asset_id_buy,
|
|
1589
|
-
asset_id_sell: resp.asset_id_sell,
|
|
1590
|
-
expiration_timestamp: resp.expiration_timestamp,
|
|
1591
|
-
include_fees: true,
|
|
1592
|
-
fees: request.fees,
|
|
1593
|
-
nonce: resp.nonce,
|
|
1594
|
-
stark_key: resp.stark_key,
|
|
1595
|
-
stark_signature: starkSignature,
|
|
1596
|
-
vault_id_buy: resp.vault_id_buy,
|
|
1597
|
-
vault_id_sell: resp.vault_id_sell,
|
|
1598
|
-
},
|
|
1599
|
-
xImxEthAddress: ethAddress,
|
|
1600
|
-
xImxEthSignature: ethSignature,
|
|
1601
|
-
};
|
|
1602
|
-
const createOrderResponse = await ordersApi.createOrder(orderParams);
|
|
1603
|
-
return {
|
|
1604
|
-
...createOrderResponse.data,
|
|
1605
|
-
};
|
|
1606
|
-
}
|
|
1607
|
-
async function cancelOrder({ signers, request, config, }) {
|
|
1608
|
-
const ordersApi = new OrdersApi(config.immutableXConfig.apiConfiguration);
|
|
1609
|
-
const getSignableCancelOrderResponse = await ordersApi.getSignableCancelOrder({
|
|
1610
|
-
getSignableCancelOrderRequest: {
|
|
1611
|
-
order_id: request.order_id,
|
|
1612
|
-
},
|
|
1613
|
-
});
|
|
1614
|
-
const { signable_message: signableMessage, payload_hash: payloadHash } = getSignableCancelOrderResponse.data;
|
|
1615
|
-
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
1616
|
-
const starkSignature = await signers.starkSigner.signMessage(payloadHash);
|
|
1617
|
-
const ethAddress = await signers.ethSigner.getAddress();
|
|
1618
|
-
const cancelOrderResponse = await ordersApi.cancelOrder({
|
|
1619
|
-
id: request.order_id.toString(),
|
|
1620
|
-
cancelOrderRequest: {
|
|
1621
|
-
order_id: request.order_id,
|
|
1622
|
-
stark_signature: starkSignature,
|
|
1623
|
-
},
|
|
1624
|
-
xImxEthAddress: ethAddress,
|
|
1625
|
-
xImxEthSignature: ethSignature,
|
|
1626
|
-
});
|
|
1627
|
-
return {
|
|
1628
|
-
order_id: cancelOrderResponse.data.order_id,
|
|
1629
|
-
status: cancelOrderResponse.data.status,
|
|
1630
|
-
};
|
|
1631
|
-
}
|
|
1632
|
-
|
|
1633
|
-
async function registerOffchain(signers, config) {
|
|
1634
|
-
await validateChain(signers.ethSigner, config.immutableXConfig);
|
|
1635
|
-
const usersApi = new UsersApi(config.immutableXConfig.apiConfiguration);
|
|
1636
|
-
const userAddress = await signers.ethSigner.getAddress();
|
|
1637
|
-
const starkPublicKey = await signers.starkSigner.getAddress();
|
|
1638
|
-
const signableResult = await usersApi.getSignableRegistrationOffchain({
|
|
1639
|
-
getSignableRegistrationRequest: {
|
|
1640
|
-
ether_key: userAddress,
|
|
1641
|
-
stark_key: starkPublicKey,
|
|
1642
|
-
},
|
|
1643
|
-
});
|
|
1644
|
-
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
1645
|
-
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
1646
|
-
const starkSignature = await signers.starkSigner.signMessage(payloadHash);
|
|
1647
|
-
const registeredUser = await usersApi.registerUser({
|
|
1648
|
-
registerUserRequest: {
|
|
1649
|
-
eth_signature: ethSignature,
|
|
1650
|
-
ether_key: userAddress,
|
|
1651
|
-
stark_signature: starkSignature,
|
|
1652
|
-
stark_key: starkPublicKey,
|
|
1653
|
-
},
|
|
1654
|
-
});
|
|
1655
|
-
return registeredUser.data;
|
|
1656
|
-
}
|
|
1657
|
-
async function isRegisteredOnChain(starkPublicKey, ethSigner, config) {
|
|
1658
|
-
await validateChain(ethSigner, config.immutableXConfig);
|
|
1659
|
-
const registrationContract = Contracts.Registration.connect(config.immutableXConfig.ethConfiguration.registrationContractAddress, ethSigner);
|
|
1660
|
-
try {
|
|
1661
|
-
return await registrationContract.isRegistered(starkPublicKey);
|
|
1662
|
-
}
|
|
1663
|
-
catch (ex) {
|
|
1664
|
-
if (ex.reason === 'USER_UNREGISTERED') {
|
|
1665
|
-
return false;
|
|
1666
|
-
}
|
|
1667
|
-
throw ex;
|
|
1668
|
-
}
|
|
1669
|
-
}
|
|
1670
|
-
async function getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi) {
|
|
1671
|
-
const response = await usersApi.getSignableRegistration({
|
|
1672
|
-
getSignableRegistrationRequest: {
|
|
1673
|
-
ether_key: etherKey,
|
|
1674
|
-
stark_key: starkPublicKey,
|
|
1675
|
-
},
|
|
1676
|
-
});
|
|
1677
|
-
return {
|
|
1678
|
-
operator_signature: response.data.operator_signature,
|
|
1679
|
-
payload_hash: response.data.payload_hash,
|
|
1680
|
-
};
|
|
1681
|
-
}
|
|
1682
|
-
|
|
1683
|
-
const assertIsDefined = (value) => {
|
|
1684
|
-
if (value !== undefined)
|
|
1685
|
-
return value;
|
|
1686
|
-
throw new Error('undefined field exception');
|
|
1687
|
-
};
|
|
1688
|
-
async function prepareWithdrawalAction(params) {
|
|
1689
|
-
const { signers: { ethSigner, starkSigner }, type, config, } = params;
|
|
1690
|
-
await validateChain(ethSigner, params.config);
|
|
1691
|
-
const withdrawalsApi = new WithdrawalsApi(config.apiConfiguration);
|
|
1692
|
-
const withdrawalAmount = type === 'ERC721' ? '1' : params.amount;
|
|
1693
|
-
const signableWithdrawalResult = await withdrawalsApi.getSignableWithdrawal({
|
|
1694
|
-
getSignableWithdrawalRequest: {
|
|
1695
|
-
user: await ethSigner.getAddress(),
|
|
1696
|
-
token: convertToSignableToken(params),
|
|
1697
|
-
amount: withdrawalAmount,
|
|
1698
|
-
},
|
|
1699
|
-
});
|
|
1700
|
-
const { signable_message: signableMessage, payload_hash: payloadHash } = signableWithdrawalResult.data;
|
|
1701
|
-
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
1702
|
-
const { ethAddress, ethSignature } = await signMessage(signableMessage, ethSigner);
|
|
1703
|
-
const prepareWithdrawalResponse = await withdrawalsApi.createWithdrawal({
|
|
1704
|
-
createWithdrawalRequest: {
|
|
1705
|
-
stark_key: assertIsDefined(signableWithdrawalResult.data.stark_key),
|
|
1706
|
-
amount: withdrawalAmount,
|
|
1707
|
-
asset_id: assertIsDefined(signableWithdrawalResult.data.asset_id),
|
|
1708
|
-
vault_id: assertIsDefined(signableWithdrawalResult.data.vault_id),
|
|
1709
|
-
nonce: assertIsDefined(signableWithdrawalResult.data.nonce),
|
|
1710
|
-
stark_signature: starkSignature,
|
|
1711
|
-
},
|
|
1712
|
-
xImxEthAddress: ethAddress,
|
|
1713
|
-
xImxEthSignature: ethSignature,
|
|
1714
|
-
});
|
|
1715
|
-
return prepareWithdrawalResponse.data;
|
|
1716
|
-
}
|
|
1717
|
-
|
|
1718
|
-
async function getEncodeAssetInfo(assetType, tokenType, config, tokenData) {
|
|
1719
|
-
const encodingApi = new EncodingApi(config.apiConfiguration);
|
|
1720
|
-
const result = await encodingApi.encodeAsset({
|
|
1721
|
-
assetType,
|
|
1722
|
-
encodeAssetRequest: {
|
|
1723
|
-
token: {
|
|
1724
|
-
type: tokenType,
|
|
1725
|
-
...(tokenData && { data: tokenData }),
|
|
1726
|
-
},
|
|
1727
|
-
},
|
|
1728
|
-
});
|
|
1729
|
-
return result.data;
|
|
1730
|
-
}
|
|
1731
|
-
|
|
1732
|
-
async function executeRegisterAndWithdrawERC20({ ethSigner, assetType, starkPublicKey, config, }) {
|
|
1733
|
-
const etherKey = await ethSigner.getAddress();
|
|
1734
|
-
const imxConfig = config.immutableXConfig;
|
|
1735
|
-
const usersApi = new UsersApi(imxConfig.apiConfiguration);
|
|
1736
|
-
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
1737
|
-
const contract = Contracts.Registration.connect(config.immutableXConfig.ethConfiguration.registrationContractAddress, ethSigner);
|
|
1738
|
-
const populatedTransaction = await contract.populateTransaction.registerAndWithdraw(etherKey, starkPublicKey, signableResult.operator_signature, assetType);
|
|
1739
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
1740
|
-
}
|
|
1741
|
-
async function executeWithdrawERC20(ethSigner, assetType, starkPublicKey, config) {
|
|
1742
|
-
const contract = Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
1743
|
-
const populatedTransaction = await contract.populateTransaction.withdraw(starkPublicKey, assetType);
|
|
1744
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
1745
|
-
}
|
|
1746
|
-
async function completeERC20WithdrawalAction({ ethSigner, starkPublicKey, token, config, }) {
|
|
1747
|
-
await validateChain(ethSigner, config.immutableXConfig);
|
|
1748
|
-
const imxConfig = config.immutableXConfig;
|
|
1749
|
-
const assetType = await getEncodeAssetInfo('asset', 'ERC20', imxConfig, {
|
|
1750
|
-
token_address: token.tokenAddress,
|
|
1751
|
-
});
|
|
1752
|
-
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
1753
|
-
if (!isRegistered) {
|
|
1754
|
-
return executeRegisterAndWithdrawERC20({
|
|
1755
|
-
ethSigner,
|
|
1756
|
-
assetType: assetType.asset_type,
|
|
1757
|
-
starkPublicKey,
|
|
1758
|
-
config,
|
|
1759
|
-
});
|
|
1760
|
-
}
|
|
1761
|
-
else {
|
|
1762
|
-
return executeWithdrawERC20(ethSigner, assetType.asset_type, starkPublicKey, imxConfig);
|
|
1763
|
-
}
|
|
1764
|
-
}
|
|
1765
|
-
|
|
1766
|
-
async function executeWithdrawMintableERC721(ethSigner, assetType, starkPublicKey, mintingBlob, config) {
|
|
1767
|
-
const contract = Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
1768
|
-
const populatedTransaction = await contract.populateTransaction.withdrawAndMint(starkPublicKey, assetType, mintingBlob);
|
|
1769
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
1770
|
-
}
|
|
1771
|
-
async function executeRegisterAndWithdrawMintableERC721(ethSigner, assetType, starkPublicKey, mintingBlob, config) {
|
|
1772
|
-
const etherKey = await ethSigner.getAddress();
|
|
1773
|
-
const usersApi = new UsersApi(config.apiConfiguration);
|
|
1774
|
-
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
1775
|
-
const contract = Contracts.Registration.connect(config.ethConfiguration.registrationContractAddress, ethSigner);
|
|
1776
|
-
const populatedTransaction = await contract.populateTransaction.regsiterAndWithdrawAndMint(etherKey, starkPublicKey, signableResult.operator_signature, assetType, mintingBlob);
|
|
1777
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
1778
|
-
}
|
|
1779
|
-
function getMintingBlob(token) {
|
|
1780
|
-
const id = token.data.id;
|
|
1781
|
-
const blueprint = token.data.blueprint || '';
|
|
1782
|
-
return encUtils.sanitizeHex(encUtils.utf8ToHex(`{${id}}:{${blueprint}}`));
|
|
1783
|
-
}
|
|
1784
|
-
async function completeMintableERC721Withdrawal(ethSigner, starkPublicKey, token, config) {
|
|
1785
|
-
const imxConfig = config.immutableXConfig;
|
|
1786
|
-
const assetType = await getEncodeAssetInfo('mintable-asset', 'ERC721', imxConfig, {
|
|
1787
|
-
id: token.data.id,
|
|
1788
|
-
token_address: token.data.tokenAddress,
|
|
1789
|
-
...(token.data.blueprint && { blueprint: token.data.blueprint }),
|
|
1790
|
-
});
|
|
1791
|
-
const mintingBlob = getMintingBlob(token);
|
|
1792
|
-
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
1793
|
-
if (!isRegistered) {
|
|
1794
|
-
return executeRegisterAndWithdrawMintableERC721(ethSigner, assetType.asset_type, starkPublicKey, mintingBlob, imxConfig);
|
|
1795
|
-
}
|
|
1796
|
-
else {
|
|
1797
|
-
return executeWithdrawMintableERC721(ethSigner, assetType.asset_type, starkPublicKey, mintingBlob, imxConfig);
|
|
1798
|
-
}
|
|
1799
|
-
}
|
|
1800
|
-
async function executeRegisterAndWithdrawERC721(ethSigner, assetType, starkPublicKey, tokenId, config) {
|
|
1801
|
-
const etherKey = await ethSigner.getAddress();
|
|
1802
|
-
const usersApi = new UsersApi(config.apiConfiguration);
|
|
1803
|
-
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
1804
|
-
const contract = Contracts.Registration.connect(config.ethConfiguration.registrationContractAddress, ethSigner);
|
|
1805
|
-
const populatedTransaction = await contract.populateTransaction.registerAndWithdrawNft(etherKey, starkPublicKey, signableResult.operator_signature, assetType, tokenId);
|
|
1806
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
1807
|
-
}
|
|
1808
|
-
async function executeWithdrawERC721(ethSigner, assetType, starkPublicKey, tokenId, config) {
|
|
1809
|
-
const contract = Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
1810
|
-
const populatedTransaction = await contract.populateTransaction.withdrawNft(starkPublicKey, assetType, tokenId);
|
|
1811
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
1812
|
-
}
|
|
1813
|
-
async function completeERC721Withdrawal(ethSigner, starkPublicKey, token, config) {
|
|
1814
|
-
const imxConfig = config.immutableXConfig;
|
|
1815
|
-
const assetType = await getEncodeAssetInfo('asset', 'ERC721', imxConfig, {
|
|
1816
|
-
token_id: token.tokenId,
|
|
1817
|
-
token_address: token.tokenAddress,
|
|
1818
|
-
});
|
|
1819
|
-
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
1820
|
-
if (!isRegistered) {
|
|
1821
|
-
return executeRegisterAndWithdrawERC721(ethSigner, assetType.asset_type, starkPublicKey, token.tokenId, imxConfig);
|
|
1822
|
-
}
|
|
1823
|
-
else {
|
|
1824
|
-
return executeWithdrawERC721(ethSigner, assetType.asset_type, starkPublicKey, token.tokenId, imxConfig);
|
|
1825
|
-
}
|
|
1826
|
-
}
|
|
1827
|
-
async function completeERC721WithdrawalAction({ ethSigner, starkPublicKey, token, config, }) {
|
|
1828
|
-
await validateChain(ethSigner, config.immutableXConfig);
|
|
1829
|
-
const tokenAddress = token.tokenAddress;
|
|
1830
|
-
const tokenId = token.tokenId;
|
|
1831
|
-
const imxConfig = config.immutableXConfig;
|
|
1832
|
-
const mintsApi = new MintsApi(imxConfig.apiConfiguration);
|
|
1833
|
-
return await mintsApi
|
|
1834
|
-
.getMintableTokenDetailsByClientTokenId({
|
|
1835
|
-
tokenAddress,
|
|
1836
|
-
tokenId,
|
|
1837
|
-
})
|
|
1838
|
-
.then((mintableToken) => completeMintableERC721Withdrawal(ethSigner, starkPublicKey, {
|
|
1839
|
-
type: 'ERC721',
|
|
1840
|
-
data: {
|
|
1841
|
-
id: tokenId,
|
|
1842
|
-
tokenAddress: tokenAddress,
|
|
1843
|
-
blueprint: mintableToken.data.blueprint,
|
|
1844
|
-
},
|
|
1845
|
-
}, config))
|
|
1846
|
-
.catch((error) => {
|
|
1847
|
-
if (error.response?.status === 404) {
|
|
1848
|
-
// token is already minted on L1
|
|
1849
|
-
return completeERC721Withdrawal(ethSigner, starkPublicKey, token, config);
|
|
1850
|
-
}
|
|
1851
|
-
throw error; // unable to recover from any other kind of error
|
|
1852
|
-
});
|
|
1853
|
-
}
|
|
1854
|
-
|
|
1855
|
-
async function executeRegisterAndWithdrawEth(ethSigner, assetType, starkPublicKey, config) {
|
|
1856
|
-
const etherKey = await ethSigner.getAddress();
|
|
1857
|
-
const usersApi = new UsersApi(config.apiConfiguration);
|
|
1858
|
-
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
1859
|
-
const contract = Contracts.Registration.connect(config.ethConfiguration.registrationContractAddress, ethSigner);
|
|
1860
|
-
const populatedTransaction = await contract.populateTransaction.registerAndWithdraw(etherKey, starkPublicKey, signableResult.operator_signature, assetType);
|
|
1861
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
1862
|
-
}
|
|
1863
|
-
async function executeWithdrawEth(ethSigner, assetType, starkPublicKey, config) {
|
|
1864
|
-
const contract = Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
1865
|
-
const populatedTransaction = await contract.populateTransaction.withdraw(starkPublicKey, assetType);
|
|
1866
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
1867
|
-
}
|
|
1868
|
-
async function completeEthWithdrawalAction({ ethSigner, starkPublicKey, config, }) {
|
|
1869
|
-
await validateChain(ethSigner, config.immutableXConfig);
|
|
1870
|
-
const imxConfig = config.immutableXConfig;
|
|
1871
|
-
const assetType = await getEncodeAssetInfo('asset', 'ETH', imxConfig);
|
|
1872
|
-
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
1873
|
-
if (!isRegistered) {
|
|
1874
|
-
return executeRegisterAndWithdrawEth(ethSigner, assetType.asset_type, starkPublicKey, imxConfig);
|
|
1875
|
-
}
|
|
1876
|
-
else {
|
|
1877
|
-
return executeWithdrawEth(ethSigner, assetType.asset_type, starkPublicKey, imxConfig);
|
|
1878
|
-
}
|
|
1879
|
-
}
|
|
1880
|
-
|
|
1881
|
-
async function prepareWithdrawal({ signers, withdrawal, config, }) {
|
|
1882
|
-
return prepareWithdrawalAction({
|
|
1883
|
-
signers,
|
|
1884
|
-
config: config.immutableXConfig,
|
|
1885
|
-
...withdrawal,
|
|
1886
|
-
});
|
|
1887
|
-
}
|
|
1888
|
-
async function completeWithdrawal({ signers: { ethSigner }, starkPublicKey, token, config, }) {
|
|
1889
|
-
switch (token.type) {
|
|
1890
|
-
case 'ETH':
|
|
1891
|
-
return completeEthWithdrawalAction({ ethSigner, starkPublicKey, config });
|
|
1892
|
-
case 'ERC20':
|
|
1893
|
-
return completeERC20WithdrawalAction({
|
|
1894
|
-
ethSigner,
|
|
1895
|
-
starkPublicKey,
|
|
1896
|
-
token,
|
|
1897
|
-
config,
|
|
1898
|
-
});
|
|
1899
|
-
case 'ERC721':
|
|
1900
|
-
return completeERC721WithdrawalAction({
|
|
1901
|
-
ethSigner,
|
|
1902
|
-
starkPublicKey,
|
|
1903
|
-
token,
|
|
1904
|
-
config,
|
|
1905
|
-
});
|
|
1906
|
-
}
|
|
1907
|
-
}
|
|
1908
|
-
|
|
1909
|
-
async function createTrade({ signers: { ethSigner, starkSigner }, request, config, }) {
|
|
1910
|
-
await validateChain(ethSigner, config.immutableXConfig);
|
|
1911
|
-
const ethAddress = await ethSigner.getAddress();
|
|
1912
|
-
const tradesApi = new TradesApi(config.immutableXConfig.apiConfiguration);
|
|
1913
|
-
const signableResult = await tradesApi.getSignableTrade({
|
|
1914
|
-
getSignableTradeRequest: {
|
|
1915
|
-
user: ethAddress,
|
|
1916
|
-
order_id: request.order_id,
|
|
1917
|
-
fees: request.fees,
|
|
1918
|
-
},
|
|
1919
|
-
});
|
|
1920
|
-
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
1921
|
-
const ethSignature = await signRaw(signableMessage, ethSigner);
|
|
1922
|
-
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
1923
|
-
const createTradeResponse = await tradesApi.createTrade({
|
|
1924
|
-
createTradeRequest: {
|
|
1925
|
-
amount_buy: signableResult.data.amount_buy,
|
|
1926
|
-
amount_sell: signableResult.data.amount_sell,
|
|
1927
|
-
asset_id_buy: signableResult.data.asset_id_buy,
|
|
1928
|
-
asset_id_sell: signableResult.data.asset_id_sell,
|
|
1929
|
-
expiration_timestamp: signableResult.data.expiration_timestamp,
|
|
1930
|
-
fee_info: signableResult.data.fee_info,
|
|
1931
|
-
fees: request.fees,
|
|
1932
|
-
include_fees: true,
|
|
1933
|
-
nonce: signableResult.data.nonce,
|
|
1934
|
-
order_id: request.order_id,
|
|
1935
|
-
stark_key: signableResult.data.stark_key,
|
|
1936
|
-
vault_id_buy: signableResult.data.vault_id_buy,
|
|
1937
|
-
vault_id_sell: signableResult.data.vault_id_sell,
|
|
1938
|
-
stark_signature: starkSignature,
|
|
1939
|
-
},
|
|
1940
|
-
xImxEthAddress: ethAddress,
|
|
1941
|
-
xImxEthSignature: ethSignature,
|
|
1942
|
-
});
|
|
1943
|
-
return createTradeResponse.data;
|
|
1944
|
-
}
|
|
1945
|
-
|
|
1946
|
-
async function depositEth({ signers: { ethSigner }, deposit, config, }) {
|
|
1947
|
-
await validateChain(ethSigner, config.immutableXConfig);
|
|
1948
|
-
const user = await ethSigner.getAddress();
|
|
1949
|
-
const data = {
|
|
1950
|
-
decimals: 18,
|
|
1951
|
-
};
|
|
1952
|
-
const amount = parseUnits(deposit.amount, 'wei');
|
|
1953
|
-
const imxConfig = config.immutableXConfig;
|
|
1954
|
-
const depositsApi = new DepositsApi(imxConfig.apiConfiguration);
|
|
1955
|
-
const encodingApi = new EncodingApi(imxConfig.apiConfiguration);
|
|
1956
|
-
const usersApi = new UsersApi(imxConfig.apiConfiguration);
|
|
1957
|
-
const getSignableDepositRequest = {
|
|
1958
|
-
user,
|
|
1959
|
-
token: {
|
|
1960
|
-
type: deposit.type,
|
|
1961
|
-
data,
|
|
1962
|
-
},
|
|
1963
|
-
amount: amount.toString(),
|
|
1964
|
-
};
|
|
1965
|
-
const signableDepositResult = await depositsApi.getSignableDeposit({
|
|
1966
|
-
getSignableDepositRequest,
|
|
1967
|
-
});
|
|
1968
|
-
const encodingResult = await encodingApi.encodeAsset({
|
|
1969
|
-
assetType: 'asset',
|
|
1970
|
-
encodeAssetRequest: {
|
|
1971
|
-
token: {
|
|
1972
|
-
type: deposit.type,
|
|
1973
|
-
},
|
|
1974
|
-
},
|
|
1975
|
-
});
|
|
1976
|
-
const assetType = encodingResult.data.asset_type;
|
|
1977
|
-
const starkPublicKey = signableDepositResult.data.stark_key;
|
|
1978
|
-
const vaultId = signableDepositResult.data.vault_id;
|
|
1979
|
-
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
1980
|
-
if (!isRegistered) {
|
|
1981
|
-
return executeRegisterAndDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, imxConfig, usersApi);
|
|
1982
|
-
}
|
|
1983
|
-
else {
|
|
1984
|
-
return executeDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, imxConfig);
|
|
1985
|
-
}
|
|
1986
|
-
}
|
|
1987
|
-
async function executeRegisterAndDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, config, usersApi) {
|
|
1988
|
-
const etherKey = await ethSigner.getAddress();
|
|
1989
|
-
const coreContract = Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
1990
|
-
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
1991
|
-
const populatedTransaction = await coreContract.populateTransaction.registerAndDepositEth(etherKey, starkPublicKey, signableResult.operator_signature, assetType, vaultId);
|
|
1992
|
-
return ethSigner.sendTransaction({ ...populatedTransaction, value: amount });
|
|
1993
|
-
}
|
|
1994
|
-
async function executeDepositEth(ethSigner, amount, assetType, starkPublicKey, vaultId, config) {
|
|
1995
|
-
const coreContract = Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
1996
|
-
const populatedTransaction = await coreContract.populateTransaction['deposit(uint256,uint256,uint256)'](starkPublicKey, assetType, vaultId);
|
|
1997
|
-
return ethSigner.sendTransaction({ ...populatedTransaction, value: amount });
|
|
1998
|
-
}
|
|
1999
|
-
|
|
2000
|
-
async function depositERC20({ signers: { ethSigner }, deposit, config, }) {
|
|
2001
|
-
await validateChain(ethSigner, config.immutableXConfig);
|
|
2002
|
-
const { apiConfiguration, ethConfiguration } = config.immutableXConfig;
|
|
2003
|
-
const user = await ethSigner.getAddress();
|
|
2004
|
-
const tokensApi = new TokensApi(apiConfiguration);
|
|
2005
|
-
const depositsApi = new DepositsApi(apiConfiguration);
|
|
2006
|
-
const encodingApi = new EncodingApi(apiConfiguration);
|
|
2007
|
-
const usersApi = new UsersApi(apiConfiguration);
|
|
2008
|
-
// Get decimals for this specific ERC20
|
|
2009
|
-
const token = await tokensApi.getToken({ address: deposit.tokenAddress });
|
|
2010
|
-
const decimals = parseInt(token.data.decimals);
|
|
2011
|
-
const data = {
|
|
2012
|
-
decimals,
|
|
2013
|
-
token_address: deposit.tokenAddress,
|
|
2014
|
-
};
|
|
2015
|
-
const amount = parseUnits(deposit.amount, 0); // 0 to always use undecimalized value
|
|
2016
|
-
// Approve whether an amount of token from an account can be spent by a third-party account
|
|
2017
|
-
const tokenContract = Contracts.IERC20.connect(deposit.tokenAddress, ethSigner);
|
|
2018
|
-
const approveTransaction = await tokenContract.populateTransaction.approve(ethConfiguration.coreContractAddress, amount);
|
|
2019
|
-
await ethSigner.sendTransaction(approveTransaction);
|
|
2020
|
-
const getSignableDepositRequest = {
|
|
2021
|
-
user,
|
|
2022
|
-
token: {
|
|
2023
|
-
type: deposit.type,
|
|
2024
|
-
data,
|
|
2025
|
-
},
|
|
2026
|
-
amount: amount.toString(),
|
|
2027
|
-
};
|
|
2028
|
-
const signableDepositResult = await depositsApi.getSignableDeposit({
|
|
2029
|
-
getSignableDepositRequest,
|
|
2030
|
-
});
|
|
2031
|
-
// Perform encoding on asset details to get an assetType (required for stark contract request)
|
|
2032
|
-
const encodingResult = await encodingApi.encodeAsset({
|
|
2033
|
-
assetType: 'asset',
|
|
2034
|
-
encodeAssetRequest: {
|
|
2035
|
-
token: {
|
|
2036
|
-
type: deposit.type,
|
|
2037
|
-
data: {
|
|
2038
|
-
token_address: deposit.tokenAddress,
|
|
2039
|
-
},
|
|
2040
|
-
},
|
|
2041
|
-
},
|
|
2042
|
-
});
|
|
2043
|
-
const assetType = encodingResult.data.asset_type;
|
|
2044
|
-
const starkPublicKey = signableDepositResult.data.stark_key;
|
|
2045
|
-
const vaultId = signableDepositResult.data.vault_id;
|
|
2046
|
-
const quantizedAmount = BigNumber.from(signableDepositResult.data.amount);
|
|
2047
|
-
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
2048
|
-
if (!isRegistered) {
|
|
2049
|
-
return executeRegisterAndDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, ethConfiguration, usersApi);
|
|
2050
|
-
}
|
|
2051
|
-
else {
|
|
2052
|
-
return executeDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, ethConfiguration);
|
|
2053
|
-
}
|
|
2054
|
-
}
|
|
2055
|
-
async function executeDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, config) {
|
|
2056
|
-
const coreContract = Contracts.Core.connect(config.coreContractAddress, ethSigner);
|
|
2057
|
-
const populatedTransaction = await coreContract.populateTransaction.depositERC20(starkPublicKey, assetType, vaultId, quantizedAmount);
|
|
2058
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
2059
|
-
}
|
|
2060
|
-
async function executeRegisterAndDepositERC20(ethSigner, quantizedAmount, assetType, starkPublicKey, vaultId, config, usersApi) {
|
|
2061
|
-
const etherKey = await ethSigner.getAddress();
|
|
2062
|
-
const coreContract = Contracts.Core.connect(config.coreContractAddress, ethSigner);
|
|
2063
|
-
const signableResult = await getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi);
|
|
2064
|
-
const populatedTransaction = await coreContract.populateTransaction.registerAndDepositERC20(etherKey, starkPublicKey, signableResult.operator_signature, assetType, vaultId, quantizedAmount);
|
|
2065
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
2066
|
-
}
|
|
2067
|
-
|
|
2068
|
-
async function depositERC721({ signers: { ethSigner }, deposit, config, }) {
|
|
2069
|
-
await validateChain(ethSigner, config.immutableXConfig);
|
|
2070
|
-
const user = await ethSigner.getAddress();
|
|
2071
|
-
const { immutableXConfig } = config;
|
|
2072
|
-
const depositsApi = new DepositsApi(immutableXConfig.apiConfiguration);
|
|
2073
|
-
const encodingApi = new EncodingApi(immutableXConfig.apiConfiguration);
|
|
2074
|
-
const usersApi = new UsersApi(immutableXConfig.apiConfiguration);
|
|
2075
|
-
const data = {
|
|
2076
|
-
token_address: deposit.tokenAddress,
|
|
2077
|
-
token_id: deposit.tokenId,
|
|
2078
|
-
};
|
|
2079
|
-
const amount = '1';
|
|
2080
|
-
const getSignableDepositRequest = {
|
|
2081
|
-
user,
|
|
2082
|
-
token: {
|
|
2083
|
-
type: deposit.type,
|
|
2084
|
-
data,
|
|
2085
|
-
},
|
|
2086
|
-
amount: amount.toString(),
|
|
2087
|
-
};
|
|
2088
|
-
const signableDepositResult = await depositsApi.getSignableDeposit({
|
|
2089
|
-
getSignableDepositRequest,
|
|
2090
|
-
});
|
|
2091
|
-
// Perform encoding on asset details to get an assetType (required for stark contract request)
|
|
2092
|
-
const encodingResult = await encodingApi.encodeAsset({
|
|
2093
|
-
assetType: 'asset',
|
|
2094
|
-
encodeAssetRequest: {
|
|
2095
|
-
token: {
|
|
2096
|
-
type: deposit.type,
|
|
2097
|
-
data: {
|
|
2098
|
-
token_address: deposit.tokenAddress,
|
|
2099
|
-
token_id: deposit.tokenId,
|
|
2100
|
-
},
|
|
2101
|
-
},
|
|
2102
|
-
},
|
|
2103
|
-
});
|
|
2104
|
-
const assetType = encodingResult.data.asset_type;
|
|
2105
|
-
const starkPublicKey = signableDepositResult.data.stark_key;
|
|
2106
|
-
const vaultId = signableDepositResult.data.vault_id;
|
|
2107
|
-
const isRegistered = await isRegisteredOnChain(starkPublicKey, ethSigner, config);
|
|
2108
|
-
// Approve whether an amount of token from an account can be spent by a third-party account
|
|
2109
|
-
const tokenContract = Contracts.IERC721.connect(deposit.tokenAddress, ethSigner);
|
|
2110
|
-
const operator = immutableXConfig.ethConfiguration.coreContractAddress;
|
|
2111
|
-
const isApprovedForAll = await tokenContract.isApprovedForAll(user, operator);
|
|
2112
|
-
if (!isApprovedForAll) {
|
|
2113
|
-
await tokenContract.setApprovalForAll(operator, true);
|
|
2114
|
-
}
|
|
2115
|
-
if (!isRegistered) {
|
|
2116
|
-
const signableResult = await getSignableRegistrationOnchain(user, starkPublicKey, usersApi);
|
|
2117
|
-
const coreContract = Contracts.Core.connect(immutableXConfig.ethConfiguration.coreContractAddress, ethSigner);
|
|
2118
|
-
// Note: proxy registration contract registerAndDepositNft method is not used as it currently fails erc721 transfer ownership check
|
|
2119
|
-
await coreContract.registerUser(user, starkPublicKey, signableResult.operator_signature);
|
|
2120
|
-
}
|
|
2121
|
-
return executeDepositERC721(ethSigner, deposit.tokenId, assetType, starkPublicKey, vaultId, immutableXConfig);
|
|
2122
|
-
}
|
|
2123
|
-
async function executeDepositERC721(ethSigner, tokenId, assetType, starkPublicKey, vaultId, config) {
|
|
2124
|
-
const coreContract = Contracts.Core.connect(config.ethConfiguration.coreContractAddress, ethSigner);
|
|
2125
|
-
const populatedTransaction = await coreContract.populateTransaction.depositNft(starkPublicKey, assetType, vaultId, tokenId);
|
|
2126
|
-
return ethSigner.sendTransaction(populatedTransaction);
|
|
2127
|
-
}
|
|
2128
|
-
|
|
2129
|
-
async function deposit({ signers, deposit, config }) {
|
|
2130
|
-
switch (deposit.type) {
|
|
2131
|
-
case 'ETH':
|
|
2132
|
-
return depositEth({ signers, deposit, config });
|
|
2133
|
-
case 'ERC20':
|
|
2134
|
-
return depositERC20({ signers, deposit, config });
|
|
2135
|
-
case 'ERC721':
|
|
2136
|
-
return depositERC721({ signers, deposit, config });
|
|
2137
|
-
}
|
|
2138
|
-
}
|
|
2139
|
-
|
|
2140
|
-
async function exchangeTransfer({ signers, request, config, }) {
|
|
2141
|
-
await validateChain(signers.ethSigner, config.immutableXConfig);
|
|
2142
|
-
const exchangeApi = new ExchangesApi(config.immutableXConfig.apiConfiguration);
|
|
2143
|
-
const ethAddress = await signers.ethSigner.getAddress();
|
|
2144
|
-
const transferAmount = request.amount;
|
|
2145
|
-
const signableResult = await exchangeApi.getExchangeSignableTransfer({
|
|
2146
|
-
id: request.transactionID,
|
|
2147
|
-
getSignableTransferRequest: {
|
|
2148
|
-
sender: ethAddress,
|
|
2149
|
-
token: convertToSignableToken(request),
|
|
2150
|
-
amount: transferAmount,
|
|
2151
|
-
receiver: request.receiver,
|
|
2152
|
-
},
|
|
2153
|
-
});
|
|
2154
|
-
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
2155
|
-
const ethSignature = await signRaw(signableMessage, signers.ethSigner);
|
|
2156
|
-
const starkSignature = await signers.starkSigner.signMessage(payloadHash);
|
|
2157
|
-
const transferSigningParams = {
|
|
2158
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
2159
|
-
sender_stark_key: signableResult.data.sender_stark_key,
|
|
2160
|
-
sender_vault_id: signableResult.data.sender_vault_id,
|
|
2161
|
-
receiver_stark_key: signableResult.data.receiver_stark_key,
|
|
2162
|
-
receiver_vault_id: signableResult.data.receiver_vault_id,
|
|
2163
|
-
asset_id: signableResult.data.asset_id,
|
|
2164
|
-
amount: signableResult.data.amount,
|
|
2165
|
-
nonce: signableResult.data.nonce,
|
|
2166
|
-
expiration_timestamp: signableResult.data.expiration_timestamp,
|
|
2167
|
-
stark_signature: starkSignature,
|
|
2168
|
-
};
|
|
2169
|
-
const response = await exchangeApi.createExchangeTransfer({
|
|
2170
|
-
id: request.transactionID,
|
|
2171
|
-
createTransferRequest: transferSigningParams,
|
|
2172
|
-
xImxEthAddress: ethAddress,
|
|
2173
|
-
xImxEthSignature: ethSignature,
|
|
2174
|
-
});
|
|
2175
|
-
return {
|
|
2176
|
-
sent_signature: response?.data.sent_signature,
|
|
2177
|
-
status: response?.data.status?.toString(),
|
|
2178
|
-
time: response?.data.time,
|
|
2179
|
-
transfer_id: response?.data.transfer_id,
|
|
2180
|
-
};
|
|
2181
|
-
}
|
|
2182
|
-
|
|
2183
|
-
class GenericIMXProvider {
|
|
2184
|
-
config;
|
|
2185
|
-
signers;
|
|
2186
|
-
constructor(config, ethSigner, starkSigner) {
|
|
2187
|
-
this.config = config;
|
|
2188
|
-
this.signers = { ethSigner, starkSigner };
|
|
2189
|
-
}
|
|
2190
|
-
async getAddress() {
|
|
2191
|
-
return await this.signers.ethSigner.getAddress();
|
|
2192
|
-
}
|
|
2193
|
-
registerOffchain() {
|
|
2194
|
-
return registerOffchain(this.signers, this.config);
|
|
2195
|
-
}
|
|
2196
|
-
batchNftTransfer(request) {
|
|
2197
|
-
return batchTransfer({
|
|
2198
|
-
signers: this.signers,
|
|
2199
|
-
request,
|
|
2200
|
-
config: this.config,
|
|
2201
|
-
});
|
|
2202
|
-
}
|
|
2203
|
-
cancelOrder(request) {
|
|
2204
|
-
return cancelOrder({
|
|
2205
|
-
signers: this.signers,
|
|
2206
|
-
request,
|
|
2207
|
-
config: this.config,
|
|
2208
|
-
});
|
|
2209
|
-
}
|
|
2210
|
-
completeWithdrawal(starkPublicKey, token) {
|
|
2211
|
-
return completeWithdrawal({
|
|
2212
|
-
config: this.config,
|
|
2213
|
-
signers: this.signers,
|
|
2214
|
-
token,
|
|
2215
|
-
starkPublicKey,
|
|
2216
|
-
});
|
|
2217
|
-
}
|
|
2218
|
-
createOrder(request) {
|
|
2219
|
-
return createOrder({
|
|
2220
|
-
signers: this.signers,
|
|
2221
|
-
request,
|
|
2222
|
-
config: this.config,
|
|
2223
|
-
});
|
|
2224
|
-
}
|
|
2225
|
-
createTrade(request) {
|
|
2226
|
-
return createTrade({
|
|
2227
|
-
signers: this.signers,
|
|
2228
|
-
request,
|
|
2229
|
-
config: this.config,
|
|
2230
|
-
});
|
|
2231
|
-
}
|
|
2232
|
-
deposit(tokenAmount) {
|
|
2233
|
-
return deposit({
|
|
2234
|
-
signers: this.signers,
|
|
2235
|
-
deposit: tokenAmount,
|
|
2236
|
-
config: this.config,
|
|
2237
|
-
});
|
|
2238
|
-
}
|
|
2239
|
-
exchangeTransfer(request) {
|
|
2240
|
-
return exchangeTransfer({
|
|
2241
|
-
signers: this.signers,
|
|
2242
|
-
request,
|
|
2243
|
-
config: this.config,
|
|
2244
|
-
});
|
|
2245
|
-
}
|
|
2246
|
-
async isRegisteredOnchain() {
|
|
2247
|
-
const starkPublicKey = await this.signers.starkSigner.getAddress();
|
|
2248
|
-
return isRegisteredOnChain(starkPublicKey, this.signers.ethSigner, this.config);
|
|
2249
|
-
}
|
|
2250
|
-
prepareWithdrawal(request) {
|
|
2251
|
-
return prepareWithdrawal({
|
|
2252
|
-
signers: this.signers,
|
|
2253
|
-
withdrawal: request,
|
|
2254
|
-
config: this.config,
|
|
2255
|
-
});
|
|
2256
|
-
}
|
|
2257
|
-
transfer(request) {
|
|
2258
|
-
return transfer({
|
|
2259
|
-
signers: this.signers,
|
|
2260
|
-
request,
|
|
2261
|
-
config: this.config,
|
|
2262
|
-
});
|
|
2263
|
-
}
|
|
2264
|
-
}
|
|
2265
|
-
|
|
2266
|
-
const WALLET_ACTION = {
|
|
2267
|
-
SWITCH_CHAIN: 'wallet_switchEthereumChain',
|
|
2268
|
-
CONNECT: 'eth_requestAccounts',
|
|
2269
|
-
};
|
|
2270
|
-
function isRequestableProvider(provider) {
|
|
2271
|
-
return !!provider?.request;
|
|
2272
|
-
}
|
|
2273
|
-
async function connectProvider(provider, chainID) {
|
|
2274
|
-
await provider.request({ method: WALLET_ACTION.CONNECT });
|
|
2275
|
-
if (chainID) {
|
|
2276
|
-
await provider.request({
|
|
2277
|
-
method: WALLET_ACTION.SWITCH_CHAIN,
|
|
2278
|
-
params: [{ chainId: `0x${chainID.toString(16)}` }],
|
|
2279
|
-
});
|
|
2280
|
-
}
|
|
2281
|
-
}
|
|
2282
|
-
|
|
2283
|
-
const ERRORS = {
|
|
2284
|
-
PROVIDER_NOT_FOUND: 'The Metamask provider was not found',
|
|
2285
|
-
};
|
|
2286
|
-
async function connect$1({ chainID, }) {
|
|
2287
|
-
const provider = (await detectEthereumProvider());
|
|
2288
|
-
if (!isRequestableProvider(provider)) {
|
|
2289
|
-
throw new Error(ERRORS.PROVIDER_NOT_FOUND);
|
|
2290
|
-
}
|
|
2291
|
-
await connectProvider(provider, chainID);
|
|
2292
|
-
// NOTE: if we want to listen to Metamask events in the future, we can add a
|
|
2293
|
-
// listener here.
|
|
2294
|
-
return new ethers.providers.Web3Provider(provider);
|
|
2295
|
-
}
|
|
2296
|
-
|
|
2297
|
-
const COMMUNICATION_TYPE = 'message';
|
|
2298
|
-
var RequestEventType;
|
|
2299
|
-
(function (RequestEventType) {
|
|
2300
|
-
RequestEventType["GET_CONNECTION_REQUEST"] = "GET_CONNECTION_REQUEST";
|
|
2301
|
-
RequestEventType["CONNECT_WALLET_REQUEST"] = "CONNECT_WALLET_REQUEST";
|
|
2302
|
-
RequestEventType["SIGN_MESSAGE_REQUEST"] = "SIGN_MESSAGE_REQUEST";
|
|
2303
|
-
RequestEventType["DISCONNECT_WALLET_REQUEST"] = "DISCONNECT_WALLET_REQUEST";
|
|
2304
|
-
})(RequestEventType || (RequestEventType = {}));
|
|
2305
|
-
var ResponseEventType;
|
|
2306
|
-
(function (ResponseEventType) {
|
|
2307
|
-
ResponseEventType["CONNECT_WALLET_RESPONSE"] = "CONNECT_WALLET_RESPONSE";
|
|
2308
|
-
ResponseEventType["SIGN_MESSAGE_RESPONSE"] = "SIGN_MESSAGE_RESPONSE";
|
|
2309
|
-
ResponseEventType["GET_CONNECTION_RESPONSE"] = "GET_CONNECTION_RESPONSE";
|
|
2310
|
-
ResponseEventType["DISCONNECT_WALLET_RESPONSE"] = "DISCONNECT_WALLET_RESPONSE";
|
|
2311
|
-
})(ResponseEventType || (ResponseEventType = {}));
|
|
2312
|
-
|
|
2313
|
-
function postRequestMessage(iframe, payload) {
|
|
2314
|
-
if (iframe && iframe.contentWindow) {
|
|
2315
|
-
iframe.contentWindow.postMessage(payload, new URL(iframe.src).origin);
|
|
2316
|
-
}
|
|
2317
|
-
}
|
|
2318
|
-
|
|
2319
|
-
function messageResponseListener(iframe, event, eventType, callback) {
|
|
2320
|
-
if (iframe && event.source !== iframe.contentWindow) {
|
|
2321
|
-
return;
|
|
2322
|
-
}
|
|
2323
|
-
const l2WalletMessage = event.data;
|
|
2324
|
-
if (l2WalletMessage.type !== eventType) {
|
|
2325
|
-
return;
|
|
2326
|
-
}
|
|
2327
|
-
callback(l2WalletMessage.details);
|
|
2328
|
-
}
|
|
2329
|
-
|
|
2330
|
-
class ImxSigner {
|
|
2331
|
-
publicAddress;
|
|
2332
|
-
iframe;
|
|
2333
|
-
constructor(publicAddress, iframe) {
|
|
2334
|
-
this.publicAddress = publicAddress;
|
|
2335
|
-
this.iframe = iframe;
|
|
2336
|
-
}
|
|
2337
|
-
getAddress() {
|
|
2338
|
-
return this.publicAddress;
|
|
2339
|
-
}
|
|
2340
|
-
signMessage(rawMessage) {
|
|
2341
|
-
return new Promise((resolve, reject) => {
|
|
2342
|
-
const listener = (event) => {
|
|
2343
|
-
messageResponseListener(this.iframe, event, ResponseEventType.SIGN_MESSAGE_RESPONSE, (messageDetails) => {
|
|
2344
|
-
window.removeEventListener(COMMUNICATION_TYPE, listener);
|
|
2345
|
-
if (!messageDetails.success) {
|
|
2346
|
-
reject(new Error(messageDetails.error?.message));
|
|
2347
|
-
}
|
|
2348
|
-
resolve(messageDetails.data.signedMessage);
|
|
2349
|
-
});
|
|
2350
|
-
};
|
|
2351
|
-
window.addEventListener(COMMUNICATION_TYPE, listener);
|
|
2352
|
-
postRequestMessage(this.iframe, {
|
|
2353
|
-
type: RequestEventType.SIGN_MESSAGE_REQUEST,
|
|
2354
|
-
details: { starkPublicKey: this.publicAddress, message: rawMessage },
|
|
2355
|
-
});
|
|
2356
|
-
});
|
|
2357
|
-
}
|
|
2358
|
-
getIFrame() {
|
|
2359
|
-
return this.iframe;
|
|
2360
|
-
}
|
|
2361
|
-
}
|
|
2362
|
-
|
|
2363
|
-
const IMX_WALLET_IFRAME_ID = 'imx-wallet-app';
|
|
2364
|
-
const IMX_WALLET_IFRAME_HOSTS = {
|
|
2365
|
-
[Environment.SANDBOX]: 'https://wallets.sandbox.immutable.com',
|
|
2366
|
-
[Environment.PRODUCTION]: 'https://wallets.immutable.com',
|
|
2367
|
-
};
|
|
2368
|
-
const IMX_WALLET_IFRAME_STYLE = 'display: none;';
|
|
2369
|
-
function getIFrame() {
|
|
2370
|
-
return document.querySelector(`iframe#${IMX_WALLET_IFRAME_ID}`);
|
|
2371
|
-
}
|
|
2372
|
-
async function setupIFrame(env) {
|
|
2373
|
-
return new Promise((resolve) => {
|
|
2374
|
-
const iframe = document.createElement('iframe');
|
|
2375
|
-
iframe.setAttribute('id', IMX_WALLET_IFRAME_ID);
|
|
2376
|
-
iframe.setAttribute('src', IMX_WALLET_IFRAME_HOSTS[env]);
|
|
2377
|
-
iframe.setAttribute('style', IMX_WALLET_IFRAME_STYLE);
|
|
2378
|
-
document.body.appendChild(iframe);
|
|
2379
|
-
iframe.onload = () => resolve(iframe);
|
|
2380
|
-
});
|
|
2381
|
-
}
|
|
2382
|
-
async function getOrSetupIFrame(env) {
|
|
2383
|
-
const iframe = getIFrame();
|
|
2384
|
-
if (iframe)
|
|
2385
|
-
return iframe;
|
|
2386
|
-
return await setupIFrame(env);
|
|
2387
|
-
}
|
|
2388
|
-
|
|
2389
|
-
const DEFAULT_CONNECTION_MESSAGE = 'Only sign this request if you’ve initiated an action with Immutable X.';
|
|
2390
|
-
const CONNECTION_FAILED_ERROR = 'The L2 IMX Wallet connection has failed';
|
|
2391
|
-
async function connect(l1Provider, env) {
|
|
2392
|
-
const l1Signer = l1Provider.getSigner();
|
|
2393
|
-
const address = await l1Signer.getAddress();
|
|
2394
|
-
const signature = await l1Signer.signMessage(DEFAULT_CONNECTION_MESSAGE);
|
|
2395
|
-
const iframe = await getOrSetupIFrame(env);
|
|
2396
|
-
return new Promise((resolve, reject) => {
|
|
2397
|
-
const listener = (event) => {
|
|
2398
|
-
messageResponseListener(iframe, event, ResponseEventType.CONNECT_WALLET_RESPONSE, (messageDetails) => {
|
|
2399
|
-
window.removeEventListener(COMMUNICATION_TYPE, listener);
|
|
2400
|
-
if (!messageDetails.success) {
|
|
2401
|
-
reject(new Error(CONNECTION_FAILED_ERROR));
|
|
2402
|
-
}
|
|
2403
|
-
resolve(new ImxSigner(messageDetails.data.starkPublicKey, iframe));
|
|
2404
|
-
});
|
|
2405
|
-
};
|
|
2406
|
-
window.addEventListener(COMMUNICATION_TYPE, listener);
|
|
2407
|
-
postRequestMessage(iframe, {
|
|
2408
|
-
type: RequestEventType.CONNECT_WALLET_REQUEST,
|
|
2409
|
-
details: { ethAddress: address, signature },
|
|
2410
|
-
});
|
|
2411
|
-
});
|
|
2412
|
-
}
|
|
2413
|
-
async function disconnect(imxSigner) {
|
|
2414
|
-
const iframe = imxSigner.getIFrame();
|
|
2415
|
-
return new Promise((resolve, reject) => {
|
|
2416
|
-
const listener = (event) => {
|
|
2417
|
-
messageResponseListener(iframe, event, ResponseEventType.DISCONNECT_WALLET_RESPONSE, (messageDetails) => {
|
|
2418
|
-
window.removeEventListener(COMMUNICATION_TYPE, listener);
|
|
2419
|
-
if (!messageDetails.success && messageDetails.error) {
|
|
2420
|
-
reject(messageDetails.error);
|
|
2421
|
-
}
|
|
2422
|
-
iframe.remove();
|
|
2423
|
-
resolve();
|
|
2424
|
-
});
|
|
2425
|
-
};
|
|
2426
|
-
window.addEventListener(COMMUNICATION_TYPE, listener);
|
|
2427
|
-
postRequestMessage(iframe, {
|
|
2428
|
-
type: RequestEventType.DISCONNECT_WALLET_REQUEST,
|
|
2429
|
-
details: { starkPublicKey: imxSigner.getAddress() },
|
|
2430
|
-
});
|
|
2431
|
-
});
|
|
2432
|
-
}
|
|
2433
|
-
|
|
2434
|
-
var ProviderErrorType;
|
|
2435
|
-
(function (ProviderErrorType) {
|
|
2436
|
-
ProviderErrorType["PROVIDER_CONNECTION_ERROR"] = "PROVIDER_CONNECTION_ERROR";
|
|
2437
|
-
ProviderErrorType["WALLET_CONNECTION_ERROR"] = "WALLET_CONNECTION_ERROR";
|
|
2438
|
-
})(ProviderErrorType || (ProviderErrorType = {}));
|
|
2439
|
-
class ProviderError extends Error {
|
|
2440
|
-
type;
|
|
2441
|
-
constructor(message, type) {
|
|
2442
|
-
super(message);
|
|
2443
|
-
this.type = type;
|
|
2444
|
-
}
|
|
2445
|
-
}
|
|
2446
|
-
const withProviderError = async (fn, customError) => {
|
|
2447
|
-
try {
|
|
2448
|
-
return await fn();
|
|
2449
|
-
}
|
|
2450
|
-
catch (error) {
|
|
2451
|
-
const errorMessage = customError.message || `${error.message}` || 'UnknownError';
|
|
2452
|
-
throw new ProviderError(errorMessage, customError.type);
|
|
2453
|
-
}
|
|
2454
|
-
};
|
|
2455
|
-
|
|
2456
|
-
class MetaMaskIMXProvider extends GenericIMXProvider {
|
|
2457
|
-
static imxSigner;
|
|
2458
|
-
constructor(config, ethSigner, starkSigner) {
|
|
2459
|
-
super(config, ethSigner, starkSigner);
|
|
2460
|
-
}
|
|
2461
|
-
static async connect(config) {
|
|
2462
|
-
return await withProviderError(async () => {
|
|
2463
|
-
const metaMaskProvider = await connect$1({
|
|
2464
|
-
chainID: config.immutableXConfig.ethConfiguration.chainID,
|
|
2465
|
-
});
|
|
2466
|
-
this.imxSigner = await connect(metaMaskProvider, config.baseConfig.environment);
|
|
2467
|
-
return new MetaMaskIMXProvider(config, metaMaskProvider.getSigner(), this.imxSigner);
|
|
2468
|
-
}, { type: ProviderErrorType.WALLET_CONNECTION_ERROR });
|
|
2469
|
-
}
|
|
2470
|
-
static async disconnect() {
|
|
2471
|
-
if (!this.imxSigner) {
|
|
2472
|
-
throw new ProviderError('Attempted to disconnect from the MetaMask IMX provider without an established connection', ProviderErrorType.PROVIDER_CONNECTION_ERROR);
|
|
2473
|
-
}
|
|
2474
|
-
return withProviderError(async () => {
|
|
2475
|
-
await disconnect(this.imxSigner);
|
|
2476
|
-
}, { type: ProviderErrorType.PROVIDER_CONNECTION_ERROR });
|
|
2477
|
-
}
|
|
2478
|
-
static async signMessage(message) {
|
|
2479
|
-
if (!this.imxSigner) {
|
|
2480
|
-
throw new ProviderError('Attempted to sign a message with the MetaMask IMX provider without an established connection', ProviderErrorType.PROVIDER_CONNECTION_ERROR);
|
|
2481
|
-
}
|
|
2482
|
-
return withProviderError(async () => {
|
|
2483
|
-
return await this.imxSigner.signMessage(message);
|
|
2484
|
-
}, { type: ProviderErrorType.PROVIDER_CONNECTION_ERROR });
|
|
2485
|
-
}
|
|
2486
|
-
}
|
|
2487
|
-
|
|
2488
|
-
class ProviderConfiguration {
|
|
2489
|
-
immutableXConfig;
|
|
2490
|
-
baseConfig;
|
|
2491
|
-
constructor({ baseConfig, overrides }) {
|
|
2492
|
-
this.baseConfig = baseConfig;
|
|
2493
|
-
if (overrides) {
|
|
2494
|
-
this.immutableXConfig = overrides.immutableXConfig;
|
|
2495
|
-
}
|
|
2496
|
-
else {
|
|
2497
|
-
switch (baseConfig.environment) {
|
|
2498
|
-
case Environment.SANDBOX: {
|
|
2499
|
-
this.immutableXConfig = Config.SANDBOX;
|
|
2500
|
-
break;
|
|
2501
|
-
}
|
|
2502
|
-
case Environment.PRODUCTION: {
|
|
2503
|
-
this.immutableXConfig = Config.PRODUCTION;
|
|
2504
|
-
break;
|
|
2505
|
-
}
|
|
2506
|
-
}
|
|
2507
|
-
}
|
|
2508
|
-
}
|
|
2509
|
-
}
|
|
2510
|
-
|
|
2511
|
-
function $parcel$interopDefault(a) {
|
|
2512
|
-
return a && a.__esModule ? a.default : a;
|
|
2513
|
-
}
|
|
2514
|
-
|
|
2515
|
-
const $762782b6c862d954$export$db5daa1b5156ccfe = [
|
|
2516
|
-
{
|
|
2517
|
-
constant: true,
|
|
2518
|
-
inputs: [],
|
|
2519
|
-
name: "name",
|
|
2520
|
-
outputs: [
|
|
2521
|
-
{
|
|
2522
|
-
name: "",
|
|
2523
|
-
type: "string"
|
|
2524
|
-
}
|
|
2525
|
-
],
|
|
2526
|
-
payable: false,
|
|
2527
|
-
type: "function"
|
|
2528
|
-
},
|
|
2529
|
-
{
|
|
2530
|
-
constant: true,
|
|
2531
|
-
inputs: [],
|
|
2532
|
-
name: "decimals",
|
|
2533
|
-
outputs: [
|
|
2534
|
-
{
|
|
2535
|
-
name: "",
|
|
2536
|
-
type: "uint8"
|
|
2537
|
-
}
|
|
2538
|
-
],
|
|
2539
|
-
payable: false,
|
|
2540
|
-
type: "function"
|
|
2541
|
-
},
|
|
2542
|
-
{
|
|
2543
|
-
constant: true,
|
|
2544
|
-
inputs: [
|
|
2545
|
-
{
|
|
2546
|
-
name: "_owner",
|
|
2547
|
-
type: "address"
|
|
2548
|
-
}
|
|
2549
|
-
],
|
|
2550
|
-
name: "balanceOf",
|
|
2551
|
-
outputs: [
|
|
2552
|
-
{
|
|
2553
|
-
name: "balance",
|
|
2554
|
-
type: "uint256"
|
|
2555
|
-
}
|
|
2556
|
-
],
|
|
2557
|
-
payable: false,
|
|
2558
|
-
type: "function"
|
|
2559
|
-
},
|
|
2560
|
-
{
|
|
2561
|
-
constant: true,
|
|
2562
|
-
inputs: [],
|
|
2563
|
-
name: "symbol",
|
|
2564
|
-
outputs: [
|
|
2565
|
-
{
|
|
2566
|
-
name: "",
|
|
2567
|
-
type: "string"
|
|
2568
|
-
}
|
|
2569
|
-
],
|
|
2570
|
-
payable: false,
|
|
2571
|
-
type: "function"
|
|
2572
|
-
}
|
|
2573
|
-
];
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
let $d176a05e966364ba$export$3bfad4d03ada24c4;
|
|
2577
|
-
(function(ConnectionProviders) {
|
|
2578
|
-
ConnectionProviders["METAMASK"] = "metamask";
|
|
2579
|
-
})($d176a05e966364ba$export$3bfad4d03ada24c4 || ($d176a05e966364ba$export$3bfad4d03ada24c4 = {}));
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
let $a47e48dd2c04791b$export$c06e1e7429de6283;
|
|
2583
|
-
(function(ChainId) {
|
|
2584
|
-
ChainId[ChainId["ETHEREUM"] = 1] = "ETHEREUM";
|
|
2585
|
-
ChainId[ChainId["GOERLI"] = 5] = "GOERLI";
|
|
2586
|
-
ChainId[ChainId["POLYGON"] = 137] = "POLYGON";
|
|
2587
|
-
})($a47e48dd2c04791b$export$c06e1e7429de6283 || ($a47e48dd2c04791b$export$c06e1e7429de6283 = {}));
|
|
2588
|
-
const $a47e48dd2c04791b$export$f61f4aaec62f6be9 = {
|
|
2589
|
-
[$a47e48dd2c04791b$export$c06e1e7429de6283.ETHEREUM]: {
|
|
2590
|
-
chainIdHex: "0x1",
|
|
2591
|
-
chainName: "Ethereum",
|
|
2592
|
-
rpcUrls: [
|
|
2593
|
-
"https://mainnet.infura.io/v3/"
|
|
2594
|
-
],
|
|
2595
|
-
nativeCurrency: {
|
|
2596
|
-
name: "Ethereum",
|
|
2597
|
-
symbol: "ETH",
|
|
2598
|
-
decimals: 18
|
|
2599
|
-
},
|
|
2600
|
-
blockExplorerUrls: [
|
|
2601
|
-
"https://etherscan.io/"
|
|
2602
|
-
]
|
|
2603
|
-
},
|
|
2604
|
-
[$a47e48dd2c04791b$export$c06e1e7429de6283.GOERLI]: {
|
|
2605
|
-
chainIdHex: "0x5",
|
|
2606
|
-
chainName: "Goerli",
|
|
2607
|
-
rpcUrls: [
|
|
2608
|
-
"https://goerli.infura.io/v3/"
|
|
2609
|
-
],
|
|
2610
|
-
nativeCurrency: {
|
|
2611
|
-
name: "Goerli Eth",
|
|
2612
|
-
symbol: "ETH",
|
|
2613
|
-
decimals: 18
|
|
2614
|
-
},
|
|
2615
|
-
blockExplorerUrls: [
|
|
2616
|
-
"https://goerli.etherscan.io/"
|
|
2617
|
-
]
|
|
2618
|
-
},
|
|
2619
|
-
[$a47e48dd2c04791b$export$c06e1e7429de6283.POLYGON]: {
|
|
2620
|
-
chainIdHex: "0x89",
|
|
2621
|
-
chainName: "Polygon",
|
|
2622
|
-
rpcUrls: [
|
|
2623
|
-
"https://polygon-rpc.com"
|
|
2624
|
-
],
|
|
2625
|
-
nativeCurrency: {
|
|
2626
|
-
name: "MATIC",
|
|
2627
|
-
symbol: "MATIC",
|
|
2628
|
-
decimals: 18
|
|
2629
|
-
},
|
|
2630
|
-
blockExplorerUrls: [
|
|
2631
|
-
"https://polygonscan.com/"
|
|
2632
|
-
]
|
|
2633
|
-
}
|
|
2634
|
-
};
|
|
2635
|
-
let $a47e48dd2c04791b$export$1f05a55fe0680cc7;
|
|
2636
|
-
(function(NetworkFilterTypes) {
|
|
2637
|
-
NetworkFilterTypes["ALL"] = "all";
|
|
2638
|
-
})($a47e48dd2c04791b$export$1f05a55fe0680cc7 || ($a47e48dd2c04791b$export$1f05a55fe0680cc7 = {}));
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
let $08d5ddc39acd6833$export$fd9b17d87f4121d2;
|
|
2642
|
-
(function(TokenFilterTypes) {
|
|
2643
|
-
TokenFilterTypes["SWAP"] = "swap";
|
|
2644
|
-
TokenFilterTypes["BRIDGE"] = "bridge";
|
|
2645
|
-
TokenFilterTypes["ALL"] = "all";
|
|
2646
|
-
})($08d5ddc39acd6833$export$fd9b17d87f4121d2 || ($08d5ddc39acd6833$export$fd9b17d87f4121d2 = {}));
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
const $4f91c5f280efe242$export$a130407f3423b97d = {
|
|
2652
|
-
CHECK_CONNECTION: "eth_accounts",
|
|
2653
|
-
CONNECT: "eth_requestAccounts",
|
|
2654
|
-
ADD_NETWORK: "wallet_addEthereumChain",
|
|
2655
|
-
SWITCH_NETWORK: "wallet_switchEthereumChain"
|
|
2656
|
-
};
|
|
2657
|
-
let $4f91c5f280efe242$export$a75605c67ea83a5a;
|
|
2658
|
-
(function(WalletFilterTypes) {
|
|
2659
|
-
WalletFilterTypes["ALL"] = "all";
|
|
2660
|
-
WalletFilterTypes["DESKTOP"] = "desktop";
|
|
2661
|
-
WalletFilterTypes["MOBILE"] = "mobile";
|
|
2662
|
-
})($4f91c5f280efe242$export$a75605c67ea83a5a || ($4f91c5f280efe242$export$a75605c67ea83a5a = {}));
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
/**
|
|
2668
|
-
* The different types of errors that can be returned by the checkout process.
|
|
2669
|
-
*/ let $a8bc256d81a5e2c1$export$e3dc0620abde7f5a;
|
|
2670
|
-
(function(CheckoutErrorType) {
|
|
2671
|
-
CheckoutErrorType["PROVIDER_PREFERENCE_ERROR"] = "PROVIDER_PREFERENCE_ERROR";
|
|
2672
|
-
CheckoutErrorType["CONNECT_PROVIDER_ERROR"] = "CONNECT_PROVIDER_ERROR";
|
|
2673
|
-
CheckoutErrorType["GET_BALANCE_ERROR"] = "GET_BALANCE_ERROR";
|
|
2674
|
-
CheckoutErrorType["GET_ERC20_BALANCE_ERROR"] = "GET_ERC20_BALANCE_ERROR";
|
|
2675
|
-
CheckoutErrorType["GET_NETWORK_INFO_ERROR"] = "GET_NETWORK_INFO_ERROR";
|
|
2676
|
-
CheckoutErrorType["METAMASK_PROVIDER_ERROR"] = "METAMASK_PROVIDER_ERROR";
|
|
2677
|
-
CheckoutErrorType["CHAIN_NOT_SUPPORTED_ERROR"] = "CHAIN_NOT_SUPPORTED_ERROR";
|
|
2678
|
-
CheckoutErrorType["PROVIDER_REQUEST_MISSING_ERROR"] = "PROVIDER_REQUEST_MISSING_ERROR";
|
|
2679
|
-
CheckoutErrorType["PROVIDER_REQUEST_FAILED_ERROR"] = "PROVIDER_REQUEST_FAILED_ERROR";
|
|
2680
|
-
CheckoutErrorType["USER_REJECTED_REQUEST_ERROR"] = "USER_REJECTED_REQUEST_ERROR";
|
|
2681
|
-
CheckoutErrorType["TRANSACTION_ERROR"] = "TRANSACTION_ERROR";
|
|
2682
|
-
})($a8bc256d81a5e2c1$export$e3dc0620abde7f5a || ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a = {}));
|
|
2683
|
-
class $a8bc256d81a5e2c1$export$b722478a3cbfa3bc extends Error {
|
|
2684
|
-
constructor(message, type, data){
|
|
2685
|
-
super(message);
|
|
2686
|
-
this.message = message;
|
|
2687
|
-
this.type = type;
|
|
2688
|
-
this.data = data;
|
|
2689
|
-
}
|
|
2690
|
-
}
|
|
2691
|
-
let $a8bc256d81a5e2c1$export$a22d4e0719ee6def;
|
|
2692
|
-
(function(CheckoutInternalErrorType) {
|
|
2693
|
-
CheckoutInternalErrorType["REJECTED_SWITCH_AFTER_ADDING_NETWORK"] = "REJECTED_SWITCH_AFTER_ADDING_NETWORK";
|
|
2694
|
-
})($a8bc256d81a5e2c1$export$a22d4e0719ee6def || ($a8bc256d81a5e2c1$export$a22d4e0719ee6def = {}));
|
|
2695
|
-
const $a8bc256d81a5e2c1$export$bacc563de539c6c3 = async (fn, customError)=>{
|
|
2696
|
-
try {
|
|
2697
|
-
return await fn();
|
|
2698
|
-
} catch (error) {
|
|
2699
|
-
const cause = `${error.message}` || "UnknownError";
|
|
2700
|
-
const errorMessage = customError.message ? `[${customError.type}]:${customError.message}. Cause:${cause}` : `[${customError.type}] Cause:${cause}`;
|
|
2701
|
-
if (error instanceof $a8bc256d81a5e2c1$export$b722478a3cbfa3bc) throw new $a8bc256d81a5e2c1$export$b722478a3cbfa3bc(errorMessage, customError.type, {
|
|
2702
|
-
...customError.data,
|
|
2703
|
-
innerErrorType: error.type,
|
|
2704
|
-
...error.data
|
|
2705
|
-
});
|
|
2706
|
-
throw new $a8bc256d81a5e2c1$export$b722478a3cbfa3bc(errorMessage, customError.type, {
|
|
2707
|
-
...customError.data
|
|
2708
|
-
});
|
|
2709
|
-
}
|
|
2710
|
-
};
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2716
|
-
|
|
2717
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
async function $c99672cf2294e839$export$2d040992269b4717(providerPreference) {
|
|
2722
|
-
const provider = await $c99672cf2294e839$var$getWalletProviderForPreference(providerPreference);
|
|
2723
|
-
if (!provider.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Incompatible provider", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_MISSING_ERROR, {
|
|
2724
|
-
details: `Unsupported provider for ${providerPreference}`
|
|
2725
|
-
});
|
|
2726
|
-
let accounts = [];
|
|
2727
|
-
try {
|
|
2728
|
-
accounts = await provider.provider.request({
|
|
2729
|
-
method: (0, $4f91c5f280efe242$export$a130407f3423b97d).CHECK_CONNECTION,
|
|
2730
|
-
params: []
|
|
2731
|
-
});
|
|
2732
|
-
} catch (err) {
|
|
2733
|
-
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`Check wallet connection request failed`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_FAILED_ERROR, {
|
|
2734
|
-
rpcMethod: ($4f91c5f280efe242$export$a130407f3423b97d).CHECK_CONNECTION
|
|
2735
|
-
});
|
|
2736
|
-
}
|
|
2737
|
-
// accounts[0] will have the active account if connected.
|
|
2738
|
-
return {
|
|
2739
|
-
isConnected: accounts && accounts.length > 0,
|
|
2740
|
-
walletAddress: accounts[0] ?? ""
|
|
2741
|
-
};
|
|
2742
|
-
}
|
|
2743
|
-
async function $c99672cf2294e839$export$fba2f6c3656e07c1(params) {
|
|
2744
|
-
const web3Provider = await $c99672cf2294e839$var$getWalletProviderForPreference(params.providerPreference);
|
|
2745
|
-
await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2746
|
-
if (!web3Provider || !web3Provider?.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Incompatible provider", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_MISSING_ERROR, {
|
|
2747
|
-
details: `Unsupported provider for ${params.providerPreference}`
|
|
2748
|
-
});
|
|
2749
|
-
// this makes the request to the wallet to connect i.e request eth accounts ('eth_requestAccounts')
|
|
2750
|
-
await web3Provider.provider.request({
|
|
2751
|
-
method: ($4f91c5f280efe242$export$a130407f3423b97d).CONNECT,
|
|
2752
|
-
params: []
|
|
2753
|
-
});
|
|
2754
|
-
}, {
|
|
2755
|
-
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR
|
|
2756
|
-
});
|
|
2757
|
-
return web3Provider;
|
|
2758
|
-
}
|
|
2759
|
-
async function $c99672cf2294e839$var$getWalletProviderForPreference(providerPreference) {
|
|
2760
|
-
let web3Provider = null;
|
|
2761
|
-
switch(providerPreference){
|
|
2762
|
-
case ($d176a05e966364ba$export$3bfad4d03ada24c4).METAMASK:
|
|
2763
|
-
web3Provider = await $c99672cf2294e839$var$getMetaMaskProvider();
|
|
2764
|
-
break;
|
|
2765
|
-
default:
|
|
2766
|
-
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Provider preference is not supported", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_PREFERENCE_ERROR);
|
|
2767
|
-
}
|
|
2768
|
-
return web3Provider;
|
|
2769
|
-
}
|
|
2770
|
-
async function $c99672cf2294e839$var$getMetaMaskProvider() {
|
|
2771
|
-
const provider = await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2772
|
-
return await (detectEthereumProvider)();
|
|
2773
|
-
}, {
|
|
2774
|
-
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).METAMASK_PROVIDER_ERROR
|
|
2775
|
-
});
|
|
2776
|
-
if (!provider || !provider.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No MetaMask provider installed.", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).METAMASK_PROVIDER_ERROR);
|
|
2777
|
-
return new (Web3Provider)(provider);
|
|
2778
|
-
}
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
var $497c134ecbc8a50f$exports = {};
|
|
2782
|
-
$497c134ecbc8a50f$exports = JSON.parse('[{"chainId":1},{"chainId":5},{"chainId":137}]');
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
const $de192de6ef100f9f$var$UNRECOGNISED_CHAIN_ERROR_CODE = 4902; // error code (MetaMask)
|
|
2786
|
-
async function $de192de6ef100f9f$export$79f13b4cfaaf0d09(provider) {
|
|
2787
|
-
return ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2788
|
-
const network = await provider.getNetwork();
|
|
2789
|
-
if (!Object.values(($a47e48dd2c04791b$export$c06e1e7429de6283)).includes(network.chainId)) // return empty details
|
|
2790
|
-
return {
|
|
2791
|
-
chainId: network.chainId,
|
|
2792
|
-
name: network.name,
|
|
2793
|
-
isSupported: false
|
|
2794
|
-
};
|
|
2795
|
-
const chainIdNetworkInfo = ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[network.chainId];
|
|
2796
|
-
return {
|
|
2797
|
-
name: chainIdNetworkInfo.chainName,
|
|
2798
|
-
chainId: parseInt(chainIdNetworkInfo.chainIdHex, 16),
|
|
2799
|
-
nativeCurrency: chainIdNetworkInfo.nativeCurrency,
|
|
2800
|
-
isSupported: true
|
|
2801
|
-
};
|
|
2802
|
-
}, {
|
|
2803
|
-
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_NETWORK_INFO_ERROR
|
|
2804
|
-
});
|
|
2805
|
-
}
|
|
2806
|
-
async function $de192de6ef100f9f$export$b827d9418aeb5dbd(providerPreference, provider, chainId) {
|
|
2807
|
-
let currentProvider = provider;
|
|
2808
|
-
if (!Object.values(($a47e48dd2c04791b$export$c06e1e7429de6283)).includes(chainId)) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`Chain:${chainId} is not a supported chain`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CHAIN_NOT_SUPPORTED_ERROR);
|
|
2809
|
-
if (!currentProvider || !currentProvider.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Incompatible provider", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_MISSING_ERROR, {
|
|
2810
|
-
details: `Unsupported provider`
|
|
2811
|
-
});
|
|
2812
|
-
// WT-1146 - Refer to the README in this folder for explantion on the switch network flow
|
|
2813
|
-
try {
|
|
2814
|
-
await $de192de6ef100f9f$var$switchNetworkInWallet(currentProvider, chainId);
|
|
2815
|
-
} catch (err) {
|
|
2816
|
-
if (err.code === $de192de6ef100f9f$var$UNRECOGNISED_CHAIN_ERROR_CODE) try {
|
|
2817
|
-
await $de192de6ef100f9f$var$addNetworkToWallet(currentProvider, chainId);
|
|
2818
|
-
} catch (err) {
|
|
2819
|
-
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("User cancelled add network request", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR);
|
|
2820
|
-
}
|
|
2821
|
-
else throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("User cancelled switch network request", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR);
|
|
2822
|
-
}
|
|
2823
|
-
currentProvider = await ($c99672cf2294e839$export$fba2f6c3656e07c1)({
|
|
2824
|
-
providerPreference: providerPreference
|
|
2825
|
-
});
|
|
2826
|
-
if ((await currentProvider.getNetwork()).chainId !== chainId) // user didn't actually switch
|
|
2827
|
-
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("User cancelled switch network request", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).USER_REJECTED_REQUEST_ERROR);
|
|
2828
|
-
// we can assume that if the above succeeds then user has successfully
|
|
2829
|
-
// switched to the network specified
|
|
2830
|
-
const newNetwork = ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId];
|
|
2831
|
-
return {
|
|
2832
|
-
network: {
|
|
2833
|
-
name: newNetwork.chainName,
|
|
2834
|
-
chainId: parseInt(newNetwork.chainIdHex, 16),
|
|
2835
|
-
nativeCurrency: newNetwork.nativeCurrency
|
|
2836
|
-
},
|
|
2837
|
-
provider: currentProvider
|
|
2838
|
-
};
|
|
2839
|
-
}
|
|
2840
|
-
async function $de192de6ef100f9f$export$3043f6442a9ef563({ type: type = ($a47e48dd2c04791b$export$1f05a55fe0680cc7).ALL , exclude: exclude }) {
|
|
2841
|
-
const list = ((/*@__PURE__*/$parcel$interopDefault($497c134ecbc8a50f$exports))).filter((network)=>{
|
|
2842
|
-
const allowAllTokens = type === ($a47e48dd2c04791b$export$1f05a55fe0680cc7).ALL;
|
|
2843
|
-
const networkNotExcluded = !(exclude || []).map((exc)=>exc.chainId).includes(network.chainId);
|
|
2844
|
-
return allowAllTokens && networkNotExcluded;
|
|
2845
|
-
});
|
|
2846
|
-
const allowedNetworks = [];
|
|
2847
|
-
list.forEach((element)=>{
|
|
2848
|
-
const newNetwork = ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[element.chainId];
|
|
2849
|
-
allowedNetworks.push({
|
|
2850
|
-
name: newNetwork.chainName,
|
|
2851
|
-
chainId: parseInt(newNetwork.chainIdHex, 16),
|
|
2852
|
-
nativeCurrency: newNetwork.nativeCurrency,
|
|
2853
|
-
isSupported: true
|
|
2854
|
-
});
|
|
2855
|
-
});
|
|
2856
|
-
return {
|
|
2857
|
-
networks: allowedNetworks
|
|
2858
|
-
};
|
|
2859
|
-
}
|
|
2860
|
-
// these functions should not be exported. These functions should be used as part of an exported function e.g switchWalletNetwork() above.
|
|
2861
|
-
// make sure to check if(provider.provider?.request) in the exported function and throw an error
|
|
2862
|
-
async function $de192de6ef100f9f$var$switchNetworkInWallet(provider, chainId) {
|
|
2863
|
-
if (provider.provider?.request) return await provider.provider.request({
|
|
2864
|
-
method: ($4f91c5f280efe242$export$a130407f3423b97d).SWITCH_NETWORK,
|
|
2865
|
-
params: [
|
|
2866
|
-
{
|
|
2867
|
-
chainId: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].chainIdHex
|
|
2868
|
-
}
|
|
2869
|
-
]
|
|
2870
|
-
});
|
|
2871
|
-
}
|
|
2872
|
-
async function $de192de6ef100f9f$var$addNetworkToWallet(provider, chainId) {
|
|
2873
|
-
if (provider.provider?.request) {
|
|
2874
|
-
const addNetwork = {
|
|
2875
|
-
chainId: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].chainIdHex,
|
|
2876
|
-
chainName: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].chainName,
|
|
2877
|
-
rpcUrls: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].rpcUrls,
|
|
2878
|
-
nativeCurrency: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].nativeCurrency,
|
|
2879
|
-
blockExplorerUrls: ($a47e48dd2c04791b$export$f61f4aaec62f6be9)[chainId].blockExplorerUrls
|
|
2880
|
-
};
|
|
2881
|
-
return await provider.provider.request({
|
|
2882
|
-
method: ($4f91c5f280efe242$export$a130407f3423b97d).ADD_NETWORK,
|
|
2883
|
-
params: [
|
|
2884
|
-
addNetwork
|
|
2885
|
-
]
|
|
2886
|
-
});
|
|
2887
|
-
}
|
|
2888
|
-
}
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
var $cda6003506e4182e$exports = {};
|
|
2895
|
-
$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\"]}]");
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
const $efe60cea83bfc4e8$export$473cec51305fdae8 = async function({ type: type = ($08d5ddc39acd6833$export$fd9b17d87f4121d2).ALL , chainId: chainId , exclude: exclude }) {
|
|
2899
|
-
// todo:For API call, use the CheckoutError with errorType:API_CALL_ERROR?? or any other
|
|
2900
|
-
const filteredTokenList = ((/*@__PURE__*/$parcel$interopDefault($cda6003506e4182e$exports))).filter((token)=>{
|
|
2901
|
-
const chainIdMatches = token.chainId == chainId;
|
|
2902
|
-
const tokenNotExcluded = !exclude?.map((excludeToken)=>excludeToken.address).includes(token.address || "");
|
|
2903
|
-
const allowAllTokens = type === ($08d5ddc39acd6833$export$fd9b17d87f4121d2).ALL;
|
|
2904
|
-
const tokenAllowedForType = token.tokenFeatures.includes(type);
|
|
2905
|
-
return chainIdMatches && tokenNotExcluded && (allowAllTokens || tokenAllowedForType);
|
|
2906
|
-
}).map((token)=>{
|
|
2907
|
-
const { chainId: chainId , tokenFeatures: tokenFeatures , ...tokenInfo } = token;
|
|
2908
|
-
return tokenInfo;
|
|
2909
|
-
});
|
|
2910
|
-
return {
|
|
2911
|
-
tokens: filteredTokenList
|
|
2912
|
-
};
|
|
2913
|
-
};
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
const $1564e43dde50bb61$export$df96cd8d56be0ab1 = async (provider, walletAddress)=>{
|
|
2919
|
-
return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2920
|
-
const networkInfo = await ($de192de6ef100f9f$export$79f13b4cfaaf0d09)(provider);
|
|
2921
|
-
if (!networkInfo.isSupported) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`Chain:${networkInfo.chainId} is not a supported chain`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CHAIN_NOT_SUPPORTED_ERROR, {
|
|
2922
|
-
chainName: networkInfo.name
|
|
2923
|
-
});
|
|
2924
|
-
const balance = await provider.getBalance(walletAddress);
|
|
2925
|
-
return {
|
|
2926
|
-
balance: balance,
|
|
2927
|
-
formattedBalance: (utils).formatUnits(balance, networkInfo.nativeCurrency.decimals),
|
|
2928
|
-
token: networkInfo.nativeCurrency
|
|
2929
|
-
};
|
|
2930
|
-
}, {
|
|
2931
|
-
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_BALANCE_ERROR
|
|
2932
|
-
});
|
|
2933
|
-
};
|
|
2934
|
-
async function $1564e43dde50bb61$export$60e0fe116a0e6ed0(provider, walletAddress, contractAddress) {
|
|
2935
|
-
return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
2936
|
-
const contract = new (Contract)(contractAddress, JSON.stringify(($762782b6c862d954$export$db5daa1b5156ccfe)), provider);
|
|
2937
|
-
const name = await contract.name();
|
|
2938
|
-
const symbol = await contract.symbol();
|
|
2939
|
-
const balance = await contract.balanceOf(walletAddress);
|
|
2940
|
-
const decimals = await contract.decimals();
|
|
2941
|
-
const formattedBalance = (utils).formatUnits(balance, decimals);
|
|
2942
|
-
return {
|
|
2943
|
-
balance: balance,
|
|
2944
|
-
formattedBalance: formattedBalance,
|
|
2945
|
-
token: {
|
|
2946
|
-
name: name,
|
|
2947
|
-
symbol: symbol,
|
|
2948
|
-
decimals: decimals,
|
|
2949
|
-
address: contractAddress
|
|
2950
|
-
}
|
|
2951
|
-
};
|
|
2952
|
-
}, {
|
|
2953
|
-
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).GET_ERC20_BALANCE_ERROR
|
|
2954
|
-
});
|
|
2955
|
-
}
|
|
2956
|
-
const $1564e43dde50bb61$export$fee49741664a4d7e = async (provider, walletAddress, chainId)=>{
|
|
2957
|
-
if (!Object.values(($a47e48dd2c04791b$export$c06e1e7429de6283)).includes(chainId)) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`ChainId ${chainId} is not supported`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CHAIN_NOT_SUPPORTED_ERROR);
|
|
2958
|
-
if (!provider.provider?.request) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("provider object is missing request function", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_REQUEST_MISSING_ERROR);
|
|
2959
|
-
const tokenList = await ($efe60cea83bfc4e8$export$473cec51305fdae8)({
|
|
2960
|
-
type: ($08d5ddc39acd6833$export$fd9b17d87f4121d2).ALL,
|
|
2961
|
-
chainId: chainId
|
|
2962
|
-
});
|
|
2963
|
-
const allBalancePromises = [];
|
|
2964
|
-
allBalancePromises.push($1564e43dde50bb61$export$df96cd8d56be0ab1(provider, walletAddress));
|
|
2965
|
-
tokenList.tokens.filter((token)=>token.address).forEach((token)=>allBalancePromises.push($1564e43dde50bb61$export$60e0fe116a0e6ed0(provider, walletAddress, token.address ?? "")));
|
|
2966
|
-
const balanceResults = await Promise.allSettled(allBalancePromises);
|
|
2967
|
-
const getBalanceResults = balanceResults.filter((result)=>result.status === "fulfilled").map((fulfilledResult)=>fulfilledResult.value);
|
|
2968
|
-
return {
|
|
2969
|
-
balances: getBalanceResults
|
|
2970
|
-
};
|
|
2971
|
-
};
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
var $6f3c55a615003cbf$exports = {};
|
|
2982
|
-
$6f3c55a615003cbf$exports = JSON.parse('[{"connectionProvider":"metamask","icon":"some-icon-url","name":"MetaMask","description":"complete web3 wallet solution","platform":["desktop"]},{"connectionProvider":"passport","icon":"pp-icon","name":"Passport","description":"Web3 with your email!","platform":["mobile","desktop"]},{"connectionProvider":"gamestop","icon":"gme-icon","name":"GameStop","description":"Never stopping the game!","platform":["mobile"]}]');
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
async function $5cdde2ffe6360fec$export$a822caa90d7eef09({ type: type = ($4f91c5f280efe242$export$a75605c67ea83a5a).ALL , exclude: exclude }) {
|
|
2986
|
-
// todo:For async API call, use the CheckoutError with errorType:API_CALL_ERROR?? or any other
|
|
2987
|
-
const filteredWalletsList = ((/*@__PURE__*/$parcel$interopDefault($6f3c55a615003cbf$exports))).filter((wallet)=>{
|
|
2988
|
-
const walletNotExcluded = !exclude?.map((excludeWallet)=>excludeWallet.connectionProvider).includes(wallet.connectionProvider);
|
|
2989
|
-
const allowAllWallets = type === ($4f91c5f280efe242$export$a75605c67ea83a5a).ALL;
|
|
2990
|
-
const walletsAllowedForType = wallet.platform.includes(type);
|
|
2991
|
-
return walletNotExcluded && (allowAllWallets || walletsAllowedForType);
|
|
2992
|
-
}).map((wallet)=>{
|
|
2993
|
-
const { platform: platform , ...walletInfo } = wallet;
|
|
2994
|
-
return walletInfo;
|
|
2995
|
-
});
|
|
2996
|
-
return {
|
|
2997
|
-
wallets: filteredWalletsList
|
|
2998
|
-
};
|
|
2999
|
-
}
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
const $dbe95599a4661140$export$8e0e7ffc78696d30 = async (params)=>{
|
|
3007
|
-
const { provider: provider , transaction: transaction } = params;
|
|
3008
|
-
return await ($a8bc256d81a5e2c1$export$bacc563de539c6c3)(async ()=>{
|
|
3009
|
-
const transactionResponse = await provider.getSigner().sendTransaction(transaction);
|
|
3010
|
-
return {
|
|
3011
|
-
transactionResponse: transactionResponse
|
|
3012
|
-
};
|
|
3013
|
-
}, {
|
|
3014
|
-
type: ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).TRANSACTION_ERROR
|
|
3015
|
-
});
|
|
3016
|
-
};
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
|
|
3023
|
-
/**
|
|
3024
|
-
* Check if a wallet is connected to the current application without requesting permission from the wallet and hence triggering a connect popup.
|
|
3025
|
-
* @param {CheckConnectionParams} params - The necessary data required to verify a wallet connection status.
|
|
3026
|
-
* @returns Wallet connection status details.
|
|
3027
|
-
* @throws {@link ErrorType}
|
|
3028
|
-
*/ async checkIsWalletConnected(params) {
|
|
3029
|
-
return $c99672cf2294e839$export$2d040992269b4717(params.providerPreference);
|
|
3030
|
-
}
|
|
3031
|
-
/**
|
|
3032
|
-
* Establish a connection with a wallet provider such as MetaMask and returns the provider object and the current network details.
|
|
3033
|
-
* @param {ConnectParams} params - The necessary data required to establish a connection with a wallet provider.
|
|
3034
|
-
* @returns Wallet provider and current network information.
|
|
3035
|
-
* @throws {@link ErrorType}
|
|
3036
|
-
*/ async connect(params) {
|
|
3037
|
-
this.providerPreference = params.providerPreference;
|
|
3038
|
-
const provider = await $c99672cf2294e839$export$fba2f6c3656e07c1(params);
|
|
3039
|
-
const networkInfo = await $de192de6ef100f9f$export$79f13b4cfaaf0d09(provider);
|
|
3040
|
-
return {
|
|
3041
|
-
provider: provider,
|
|
3042
|
-
network: networkInfo
|
|
3043
|
-
};
|
|
3044
|
-
}
|
|
3045
|
-
/**
|
|
3046
|
-
* Switch the currently connected wallet to a new network.
|
|
3047
|
-
* @param {SwitchNetworkParams} params - The necessary data required to switch network.
|
|
3048
|
-
* @returns The new network information.
|
|
3049
|
-
* @throws {@link ErrorType}
|
|
3050
|
-
*/ async switchNetwork(params) {
|
|
3051
|
-
if (!this.providerPreference) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`connect should be called before switchNetwork to set the provider preference`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_PREFERENCE_ERROR);
|
|
3052
|
-
return await $de192de6ef100f9f$export$b827d9418aeb5dbd(this.providerPreference, params.provider, params.chainId);
|
|
3053
|
-
}
|
|
3054
|
-
/**
|
|
3055
|
-
* Fetch the balance of the native token of the current connected network or, if a contract address is provided, it will return the balance of that ERC20 token. For example, if the wallet is connected to the Ethereum Mainnet then the function gets the wallet ETH L1 balance.
|
|
3056
|
-
* @param {GetBalanceParams} params - The necessary data required to fetch the wallet balance.
|
|
3057
|
-
* @returns Native token balance for the given wallet.
|
|
3058
|
-
* @throws {@link ErrorType}
|
|
3059
|
-
*/ async getBalance(params) {
|
|
3060
|
-
if (!params.contractAddress || params.contractAddress === "") return await $1564e43dde50bb61$export$df96cd8d56be0ab1(params.provider, params.walletAddress);
|
|
3061
|
-
return await $1564e43dde50bb61$export$60e0fe116a0e6ed0(params.provider, params.walletAddress, params.contractAddress);
|
|
3062
|
-
}
|
|
3063
|
-
/**
|
|
3064
|
-
* Fetch all available balances (ERC20 & Native) of the current connected network of the given wallet. It will loop through the list of allowed tokens and check for balance on each one.
|
|
3065
|
-
* @param {GetAllBalancesParams} params - The necessary data required to fetch all the wallet balances.
|
|
3066
|
-
* @returns List of tokens balance for the given wallet.
|
|
3067
|
-
* @throws {@link ErrorType}
|
|
3068
|
-
*/ async getAllBalances(params) {
|
|
3069
|
-
return $1564e43dde50bb61$export$fee49741664a4d7e(params.provider, params.walletAddress, params.chainId);
|
|
3070
|
-
}
|
|
3071
|
-
/**
|
|
3072
|
-
* Fetch the list of available networks that a wallet can add or/and switch to.
|
|
3073
|
-
* @param {GetNetworkAllowListParams} params - The necessary data required to fetch the list of available networks.
|
|
3074
|
-
* @returns List of networks.
|
|
3075
|
-
* @throws {@link ErrorType}
|
|
3076
|
-
*/ async getNetworkAllowList(params) {
|
|
3077
|
-
return await $de192de6ef100f9f$export$3043f6442a9ef563(params);
|
|
3078
|
-
}
|
|
3079
|
-
/**
|
|
3080
|
-
* Get the list of tokens which are allowed to be used with the product.
|
|
3081
|
-
* @param {GetTokenAllowListParams} params - The necessary data required to fetch the list of allowed tokens.
|
|
3082
|
-
* @returns List of allowed tokens.
|
|
3083
|
-
* @throws {@link ErrorType}
|
|
3084
|
-
*/ async getTokenAllowList(params) {
|
|
3085
|
-
return await $efe60cea83bfc4e8$export$473cec51305fdae8(params);
|
|
3086
|
-
}
|
|
3087
|
-
/**
|
|
3088
|
-
* Fetch the list of wallets which are available to connect with.
|
|
3089
|
-
* @param {GetWalletAllowListParams} params - The necessary data required to fetch the list of allowed wallets.
|
|
3090
|
-
* @returns List of allowed wallets.
|
|
3091
|
-
* @throws {@link ErrorType}
|
|
3092
|
-
*/ async getWalletAllowList(params) {
|
|
3093
|
-
return await $5cdde2ffe6360fec$export$a822caa90d7eef09(params);
|
|
3094
|
-
}
|
|
3095
|
-
/**
|
|
3096
|
-
* Send a generic transaction to the provider.
|
|
3097
|
-
* @param {SendTransactionParams} params - The necessary data required to send a transaction.
|
|
3098
|
-
* @returns Transaction response.
|
|
3099
|
-
* @throws {@link ErrorType}
|
|
3100
|
-
* @remarks
|
|
3101
|
-
* Further documenation can be found at [MetaMask | Sending Transactions](https://docs.metamask.io/guide/sending-transactions.html).
|
|
3102
|
-
*/ async sendTransaction(params) {
|
|
3103
|
-
return await $dbe95599a4661140$export$8e0e7ffc78696d30(params);
|
|
3104
|
-
}
|
|
3105
|
-
/**
|
|
3106
|
-
* Get network information about the currently selected network.
|
|
3107
|
-
* @param {GetNetworkParams} params - The necessary data required to get the current network information.
|
|
3108
|
-
* @returns Network details.
|
|
3109
|
-
* @throws {@link ErrorType}
|
|
3110
|
-
*/ async getNetworkInfo(params) {
|
|
3111
|
-
return await $de192de6ef100f9f$export$79f13b4cfaaf0d09(params.provider);
|
|
3112
|
-
}
|
|
3113
|
-
}
|
|
3114
|
-
|
|
3115
|
-
function $parcel$export(e, n, v, s) {
|
|
3116
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
3117
|
-
}
|
|
3118
|
-
var $88e4c575901cd68c$exports = {};
|
|
3119
|
-
|
|
3120
|
-
$parcel$export($88e4c575901cd68c$exports, "IMTBLWidgetEvents", () => $88e4c575901cd68c$export$5a0ace85cae72d45);
|
|
3121
|
-
let $88e4c575901cd68c$export$5a0ace85cae72d45;
|
|
3122
|
-
(function(IMTBLWidgetEvents) {
|
|
3123
|
-
IMTBLWidgetEvents["IMTBL_CONNECT_WIDGET_EVENT"] = "imtbl-connect-widget";
|
|
3124
|
-
IMTBLWidgetEvents["IMTBL_WALLET_WIDGET_EVENT"] = "imtbl-wallet-widget";
|
|
3125
|
-
IMTBLWidgetEvents["IMTBL_SWAP_WIDGET_EVENT"] = "imtbl-swap-widget";
|
|
3126
|
-
IMTBLWidgetEvents["IMTBL_BRIDGE_WIDGET_EVENT"] = "imtbl-bridge-widget";
|
|
3127
|
-
IMTBLWidgetEvents["IMTBL_BUY_WIDGET_EVENT"] = "imtbl-buy-widget";
|
|
3128
|
-
})($88e4c575901cd68c$export$5a0ace85cae72d45 || ($88e4c575901cd68c$export$5a0ace85cae72d45 = {}));
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
var $d71a87afc3136184$exports = {};
|
|
3132
|
-
|
|
3133
|
-
$parcel$export($d71a87afc3136184$exports, "ConnectEventType", () => $d71a87afc3136184$export$e72e7f9969a47dd3);
|
|
3134
|
-
let $d71a87afc3136184$export$e72e7f9969a47dd3;
|
|
3135
|
-
(function(ConnectEventType) {
|
|
3136
|
-
ConnectEventType["SUCCESS"] = "success";
|
|
3137
|
-
ConnectEventType["FAILURE"] = "failure";
|
|
3138
|
-
ConnectEventType["CLOSE_WIDGET"] = "close-widget";
|
|
3139
|
-
})($d71a87afc3136184$export$e72e7f9969a47dd3 || ($d71a87afc3136184$export$e72e7f9969a47dd3 = {}));
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
var $9d0f1783d4d36e8a$exports = {};
|
|
3143
|
-
|
|
3144
|
-
$parcel$export($9d0f1783d4d36e8a$exports, "WalletEventType", () => $9d0f1783d4d36e8a$export$d9be06b70b28c742);
|
|
3145
|
-
//wallet widget events
|
|
3146
|
-
let $9d0f1783d4d36e8a$export$d9be06b70b28c742;
|
|
3147
|
-
(function(WalletEventType) {
|
|
3148
|
-
WalletEventType["CLOSE_WIDGET"] = "close-widget";
|
|
3149
|
-
WalletEventType["NETWORK_SWITCH"] = "network-switch";
|
|
3150
|
-
})($9d0f1783d4d36e8a$export$d9be06b70b28c742 || ($9d0f1783d4d36e8a$export$d9be06b70b28c742 = {}));
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
var $5d497088f13bb116$exports = {};
|
|
3154
|
-
|
|
3155
|
-
$parcel$export($5d497088f13bb116$exports, "SwapEventType", () => $5d497088f13bb116$export$140a49745ab55563);
|
|
3156
|
-
let $5d497088f13bb116$export$140a49745ab55563;
|
|
3157
|
-
(function(SwapEventType) {
|
|
3158
|
-
SwapEventType["SUCCESS"] = "success";
|
|
3159
|
-
SwapEventType["FAILURE"] = "failure";
|
|
3160
|
-
})($5d497088f13bb116$export$140a49745ab55563 || ($5d497088f13bb116$export$140a49745ab55563 = {}));
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
var $28a5fdc2f5e6c742$exports = {};
|
|
3164
|
-
|
|
3165
|
-
$parcel$export($28a5fdc2f5e6c742$exports, "BridgeEventType", () => $28a5fdc2f5e6c742$export$d1bfa21f7c76447a);
|
|
3166
|
-
let $28a5fdc2f5e6c742$export$d1bfa21f7c76447a;
|
|
3167
|
-
(function(BridgeEventType) {
|
|
3168
|
-
BridgeEventType["CLOSE_WIDGET"] = "close-widget";
|
|
3169
|
-
BridgeEventType["SUCCESS"] = "success";
|
|
3170
|
-
BridgeEventType["FAILURE"] = "failure";
|
|
3171
|
-
})($28a5fdc2f5e6c742$export$d1bfa21f7c76447a || ($28a5fdc2f5e6c742$export$d1bfa21f7c76447a = {}));
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
var $ede253beebe0de4a$exports = {};
|
|
3175
|
-
|
|
3176
|
-
$parcel$export($ede253beebe0de4a$exports, "BuyEventType", () => $ede253beebe0de4a$export$90db5fe1be5993c1);
|
|
3177
|
-
let $ede253beebe0de4a$export$90db5fe1be5993c1;
|
|
3178
|
-
(function(BuyEventType) {
|
|
3179
|
-
BuyEventType["SUCCESS"] = "success";
|
|
3180
|
-
BuyEventType["FAILURE"] = "failure";
|
|
3181
|
-
BuyEventType["NOT_CONNECTED"] = "not_connected";
|
|
3182
|
-
BuyEventType["CLOSE"] = "close";
|
|
3183
|
-
})($ede253beebe0de4a$export$90db5fe1be5993c1 || ($ede253beebe0de4a$export$90db5fe1be5993c1 = {}));
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
var $9234b4c577442a97$exports = {};
|
|
3187
|
-
|
|
3188
|
-
$parcel$export($9234b4c577442a97$exports, "Network", () => $9234b4c577442a97$export$95be4ae94445245a);
|
|
3189
|
-
$parcel$export($9234b4c577442a97$exports, "WidgetTheme", () => $9234b4c577442a97$export$c88931fdc51854eb);
|
|
3190
|
-
$parcel$export($9234b4c577442a97$exports, "ConnectionProviders", () => $d176a05e966364ba$export$3bfad4d03ada24c4);
|
|
3191
|
-
|
|
3192
|
-
let $9234b4c577442a97$export$95be4ae94445245a;
|
|
3193
|
-
(function(Network) {
|
|
3194
|
-
Network["ETHEREUM"] = "Ethereum";
|
|
3195
|
-
Network["GOERLI"] = "Goerli";
|
|
3196
|
-
Network["POLYGON"] = "Polygon";
|
|
3197
|
-
})($9234b4c577442a97$export$95be4ae94445245a || ($9234b4c577442a97$export$95be4ae94445245a = {}));
|
|
3198
|
-
let $9234b4c577442a97$export$c88931fdc51854eb;
|
|
3199
|
-
(function(WidgetTheme) {
|
|
3200
|
-
WidgetTheme["LIGHT"] = "light";
|
|
3201
|
-
WidgetTheme["DARK"] = "dark";
|
|
3202
|
-
WidgetTheme["CUSTOM"] = "custom";
|
|
3203
|
-
})($9234b4c577442a97$export$c88931fdc51854eb || ($9234b4c577442a97$export$c88931fdc51854eb = {}));
|
|
3204
|
-
|
|
3205
|
-
export { $28a5fdc2f5e6c742$export$d1bfa21f7c76447a as BridgeEventType, $ede253beebe0de4a$export$90db5fe1be5993c1 as BuyEventType, $a47e48dd2c04791b$export$c06e1e7429de6283 as ChainId, $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 as Checkout, $a8bc256d81a5e2c1$export$e3dc0620abde7f5a as CheckoutErrorType, $d71a87afc3136184$export$e72e7f9969a47dd3 as ConnectEventType, $d176a05e966364ba$export$3bfad4d03ada24c4 as ConnectionProviders, Environment, GenericIMXProvider, $88e4c575901cd68c$export$5a0ace85cae72d45 as IMTBLWidgetEvents, ImmutableConfiguration, ImmutableXClient, MetaMaskIMXProvider, $9234b4c577442a97$export$95be4ae94445245a as Network, $a47e48dd2c04791b$export$1f05a55fe0680cc7 as NetworkFilterTypes, Passport, PassportConfiguration, PassportError, ProviderConfiguration, $5d497088f13bb116$export$140a49745ab55563 as SwapEventType, $08d5ddc39acd6833$export$fd9b17d87f4121d2 as TokenFilterTypes, $9d0f1783d4d36e8a$export$d9be06b70b28c742 as WalletEventType, $4f91c5f280efe242$export$a75605c67ea83a5a as WalletFilterTypes, $9234b4c577442a97$export$c88931fdc51854eb as WidgetTheme };
|
|
1444
|
+
export { Environment, ImmutableConfiguration, ImmutableXClient, Passport, PassportError };
|