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