@imtbl/sdk 0.1.10-alpha.4 → 0.2.1-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blockchain-data.js +1 -1
- package/dist/browser/checkout.js +2 -2
- package/dist/checkout_sdk.js +76 -74
- package/dist/checkout_widgets.d.ts +4 -4
- package/dist/checkout_widgets.js +1 -1
- package/dist/immutablex_client.js +1 -1
- package/dist/index.cjs +308 -134
- package/dist/index.d.ts +30 -8
- package/dist/index.js +308 -134
- package/dist/orderbook.d.ts +3 -3
- package/dist/orderbook.js +16 -54
- package/dist/passport.d.ts +23 -1
- package/dist/passport.js +215 -4
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var axios$2 = require('axios');
|
|
4
4
|
var coreSdk = require('@imtbl/core-sdk');
|
|
5
5
|
var oidcClientTs = require('oidc-client-ts');
|
|
6
|
+
var jwt_decode = require('jwt-decode');
|
|
6
7
|
var magicSdk = require('magic-sdk');
|
|
7
8
|
var oidc = require('@magic-ext/oidc');
|
|
8
9
|
var BN$2 = require('bn.js');
|
|
@@ -10,7 +11,6 @@ var encUtils = require('enc-utils');
|
|
|
10
11
|
var providers = require('@ethersproject/providers');
|
|
11
12
|
var FormData$2 = require('form-data');
|
|
12
13
|
var ethers = require('ethers');
|
|
13
|
-
var dotenv = require('dotenv');
|
|
14
14
|
var seaportJs = require('@opensea/seaport-js');
|
|
15
15
|
var units = require('@ethersproject/units');
|
|
16
16
|
var bignumber = require('@ethersproject/bignumber');
|
|
@@ -5457,7 +5457,7 @@ class APIError extends Error {
|
|
|
5457
5457
|
|
|
5458
5458
|
/* eslint-disable implicit-arrow-linebreak */
|
|
5459
5459
|
const defaultHeaders = {
|
|
5460
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.1
|
|
5460
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.2.1-alpha',
|
|
5461
5461
|
};
|
|
5462
5462
|
/**
|
|
5463
5463
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -5723,7 +5723,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
5723
5723
|
chainID,
|
|
5724
5724
|
coreContractAddress,
|
|
5725
5725
|
registrationContractAddress,
|
|
5726
|
-
sdkVersion: 'ts-immutable-sdk-0.1
|
|
5726
|
+
sdkVersion: 'ts-immutable-sdk-0.2.1-alpha',
|
|
5727
5727
|
});
|
|
5728
5728
|
/**
|
|
5729
5729
|
* Sets `sdkVersion` at the time of build
|
|
@@ -10000,6 +10000,43 @@ const withPassportError = async (fn, customErrorType) => {
|
|
|
10000
10000
|
}
|
|
10001
10001
|
};
|
|
10002
10002
|
|
|
10003
|
+
const keyCrendentials = 'passport_credentials';
|
|
10004
|
+
const validCredentialsMinTtlSec = 3600; // 1 hour
|
|
10005
|
+
class DeviceCredentialsManager {
|
|
10006
|
+
saveCredentials(tokenResponse) {
|
|
10007
|
+
localStorage.setItem(keyCrendentials, JSON.stringify(tokenResponse));
|
|
10008
|
+
}
|
|
10009
|
+
getCredentials() {
|
|
10010
|
+
const credentialsJson = localStorage.getItem(keyCrendentials);
|
|
10011
|
+
if (credentialsJson) {
|
|
10012
|
+
return JSON.parse(credentialsJson);
|
|
10013
|
+
}
|
|
10014
|
+
return null;
|
|
10015
|
+
}
|
|
10016
|
+
areValid(tokenResponse) {
|
|
10017
|
+
if (tokenResponse) {
|
|
10018
|
+
const accessTokenValid = this.isTokenValid(tokenResponse.access_token);
|
|
10019
|
+
const idTokenValid = this.isTokenValid(tokenResponse.id_token);
|
|
10020
|
+
return accessTokenValid && idTokenValid;
|
|
10021
|
+
}
|
|
10022
|
+
return false;
|
|
10023
|
+
}
|
|
10024
|
+
isTokenValid(jwt) {
|
|
10025
|
+
const tokenPayload = jwt_decode(jwt);
|
|
10026
|
+
const expiresAt = tokenPayload.exp ?? 0;
|
|
10027
|
+
const now = (Date.now() / 1000) + validCredentialsMinTtlSec;
|
|
10028
|
+
return expiresAt > now;
|
|
10029
|
+
}
|
|
10030
|
+
clearCredentials() {
|
|
10031
|
+
localStorage.removeItem(keyCrendentials);
|
|
10032
|
+
}
|
|
10033
|
+
}
|
|
10034
|
+
|
|
10035
|
+
const formUrlEncodedHeader = {
|
|
10036
|
+
headers: {
|
|
10037
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
10038
|
+
},
|
|
10039
|
+
};
|
|
10003
10040
|
const getAuthConfiguration = ({ oidcConfiguration, authenticationDomain, }) => {
|
|
10004
10041
|
const baseConfiguration = {
|
|
10005
10042
|
authority: authenticationDomain,
|
|
@@ -10025,12 +10062,19 @@ const getAuthConfiguration = ({ oidcConfiguration, authenticationDomain, }) => {
|
|
|
10025
10062
|
}
|
|
10026
10063
|
return baseConfiguration;
|
|
10027
10064
|
};
|
|
10065
|
+
function wait$1(ms) {
|
|
10066
|
+
return new Promise((resolve) => {
|
|
10067
|
+
setTimeout(resolve, ms);
|
|
10068
|
+
});
|
|
10069
|
+
}
|
|
10028
10070
|
class AuthManager {
|
|
10029
10071
|
userManager;
|
|
10030
10072
|
config;
|
|
10073
|
+
deviceCredentialsManager;
|
|
10031
10074
|
constructor(config) {
|
|
10032
10075
|
this.config = config;
|
|
10033
10076
|
this.userManager = new oidcClientTs.UserManager(getAuthConfiguration(config));
|
|
10077
|
+
this.deviceCredentialsManager = new DeviceCredentialsManager();
|
|
10034
10078
|
}
|
|
10035
10079
|
static mapOidcUserToDomainModel = (oidcUser) => {
|
|
10036
10080
|
const passport = oidcUser.profile?.passport;
|
|
@@ -10060,6 +10104,27 @@ class AuthManager {
|
|
|
10060
10104
|
}
|
|
10061
10105
|
return user;
|
|
10062
10106
|
};
|
|
10107
|
+
static mapDeviceTokenResponseToDomainUserModel = (tokenResponse) => {
|
|
10108
|
+
const idTokenPayload = jwt_decode(tokenResponse.id_token);
|
|
10109
|
+
const user = {
|
|
10110
|
+
idToken: tokenResponse.id_token,
|
|
10111
|
+
accessToken: tokenResponse.access_token,
|
|
10112
|
+
refreshToken: tokenResponse.refresh_token,
|
|
10113
|
+
profile: {
|
|
10114
|
+
sub: idTokenPayload.sub,
|
|
10115
|
+
email: idTokenPayload.email,
|
|
10116
|
+
nickname: idTokenPayload.nickname,
|
|
10117
|
+
},
|
|
10118
|
+
};
|
|
10119
|
+
if (idTokenPayload?.passport?.imx_eth_address) {
|
|
10120
|
+
user.imx = {
|
|
10121
|
+
ethAddress: idTokenPayload?.passport?.imx_eth_address,
|
|
10122
|
+
starkAddress: idTokenPayload?.passport?.imx_stark_address,
|
|
10123
|
+
userAdminAddress: idTokenPayload?.passport?.imx_user_admin_address,
|
|
10124
|
+
};
|
|
10125
|
+
}
|
|
10126
|
+
return user;
|
|
10127
|
+
};
|
|
10063
10128
|
async login() {
|
|
10064
10129
|
return withPassportError(async () => {
|
|
10065
10130
|
const popupWindowFeatures = { width: 410, height: 450 };
|
|
@@ -10072,9 +10137,104 @@ class AuthManager {
|
|
|
10072
10137
|
async loginCallback() {
|
|
10073
10138
|
return withPassportError(async () => this.userManager.signinPopupCallback(), PassportErrorType.AUTHENTICATION_ERROR);
|
|
10074
10139
|
}
|
|
10140
|
+
async loginWithDeviceFlow() {
|
|
10141
|
+
return withPassportError(async () => {
|
|
10142
|
+
const response = await axios$2.post(`${this.config.authenticationDomain}/oauth/device/code`, {
|
|
10143
|
+
client_id: this.config.oidcConfiguration.clientId,
|
|
10144
|
+
scope: this.config.oidcConfiguration.scope,
|
|
10145
|
+
audience: this.config.oidcConfiguration.audience,
|
|
10146
|
+
}, formUrlEncodedHeader);
|
|
10147
|
+
return {
|
|
10148
|
+
code: response.data.user_code,
|
|
10149
|
+
deviceCode: response.data.device_code,
|
|
10150
|
+
url: response.data.verification_uri_complete,
|
|
10151
|
+
interval: response.data.interval,
|
|
10152
|
+
};
|
|
10153
|
+
}, PassportErrorType.AUTHENTICATION_ERROR);
|
|
10154
|
+
}
|
|
10155
|
+
/* eslint-disable no-await-in-loop */
|
|
10156
|
+
async connectImxDeviceFlow(deviceCode, interval, timeoutMs) {
|
|
10157
|
+
return withPassportError(async () => {
|
|
10158
|
+
const startTime = Date.now();
|
|
10159
|
+
const loopCondition = true;
|
|
10160
|
+
while (loopCondition) {
|
|
10161
|
+
if (timeoutMs != null && Date.now() - startTime > timeoutMs) {
|
|
10162
|
+
throw new Error('Timed out');
|
|
10163
|
+
}
|
|
10164
|
+
await wait$1(interval * 1000);
|
|
10165
|
+
try {
|
|
10166
|
+
const tokenResponse = await this.getDeviceFlowToken(deviceCode);
|
|
10167
|
+
const user = AuthManager.mapDeviceTokenResponseToDomainUserModel(tokenResponse);
|
|
10168
|
+
// Only persist credentials that contain the necessary data
|
|
10169
|
+
if (user.imx?.ethAddress && user.imx?.starkAddress && user.imx?.userAdminAddress) {
|
|
10170
|
+
this.deviceCredentialsManager.saveCredentials(tokenResponse);
|
|
10171
|
+
}
|
|
10172
|
+
return user;
|
|
10173
|
+
}
|
|
10174
|
+
catch (error) {
|
|
10175
|
+
if (axios$2.isAxiosError(error)) {
|
|
10176
|
+
const responseError = error.response?.data;
|
|
10177
|
+
switch (responseError.error) {
|
|
10178
|
+
case 'authorization_pending':
|
|
10179
|
+
break;
|
|
10180
|
+
case 'slow_down':
|
|
10181
|
+
break;
|
|
10182
|
+
case 'expired_token':
|
|
10183
|
+
throw new Error('Token expired, please log in again');
|
|
10184
|
+
case 'access_denied':
|
|
10185
|
+
throw new Error('User denied access');
|
|
10186
|
+
default:
|
|
10187
|
+
throw new Error('Error getting token');
|
|
10188
|
+
}
|
|
10189
|
+
}
|
|
10190
|
+
else {
|
|
10191
|
+
throw error;
|
|
10192
|
+
}
|
|
10193
|
+
}
|
|
10194
|
+
}
|
|
10195
|
+
throw new Error('Failed to get credentials');
|
|
10196
|
+
}, PassportErrorType.AUTHENTICATION_ERROR);
|
|
10197
|
+
}
|
|
10198
|
+
/* eslint-enable no-await-in-loop */
|
|
10199
|
+
async getDeviceFlowToken(deviceCode) {
|
|
10200
|
+
const response = await axios$2.post(`${this.config.authenticationDomain}/oauth/token`, {
|
|
10201
|
+
client_id: this.config.oidcConfiguration.clientId,
|
|
10202
|
+
grant_type: 'urn:ietf:params:oauth:grant-type:device_code',
|
|
10203
|
+
device_code: deviceCode,
|
|
10204
|
+
}, formUrlEncodedHeader);
|
|
10205
|
+
return response.data;
|
|
10206
|
+
}
|
|
10207
|
+
async connectImxWithCredentials(tokenResponse) {
|
|
10208
|
+
return withPassportError(async () => {
|
|
10209
|
+
if (this.deviceCredentialsManager.areValid(tokenResponse)) {
|
|
10210
|
+
// Credentials exist and are still valid
|
|
10211
|
+
return AuthManager.mapDeviceTokenResponseToDomainUserModel(tokenResponse);
|
|
10212
|
+
}
|
|
10213
|
+
const refreshToken = tokenResponse?.refresh_token ?? null;
|
|
10214
|
+
if (refreshToken) {
|
|
10215
|
+
// Token is no longer valid, but refresh token can be used to a new one
|
|
10216
|
+
const newTokenResponse = await this.refreshToken(refreshToken);
|
|
10217
|
+
return AuthManager.mapDeviceTokenResponseToDomainUserModel(newTokenResponse);
|
|
10218
|
+
}
|
|
10219
|
+
return null;
|
|
10220
|
+
}, PassportErrorType.AUTHENTICATION_ERROR);
|
|
10221
|
+
}
|
|
10222
|
+
async refreshToken(refreshToken) {
|
|
10223
|
+
const response = await axios$2.post(`${this.config.authenticationDomain}/oauth/token`, {
|
|
10224
|
+
client_id: this.config.oidcConfiguration.clientId,
|
|
10225
|
+
grant_type: 'refresh_token',
|
|
10226
|
+
refresh_token: refreshToken,
|
|
10227
|
+
}, formUrlEncodedHeader);
|
|
10228
|
+
return response.data;
|
|
10229
|
+
}
|
|
10075
10230
|
async logout() {
|
|
10076
10231
|
return withPassportError(async () => this.userManager.signoutRedirect(), PassportErrorType.LOGOUT_ERROR);
|
|
10077
10232
|
}
|
|
10233
|
+
async logoutDeviceFlow() {
|
|
10234
|
+
return withPassportError(async () => {
|
|
10235
|
+
this.deviceCredentialsManager.clearCredentials();
|
|
10236
|
+
}, PassportErrorType.LOGOUT_ERROR);
|
|
10237
|
+
}
|
|
10078
10238
|
async loginSilent() {
|
|
10079
10239
|
return withPassportError(async () => {
|
|
10080
10240
|
const existedUser = await this.getUser();
|
|
@@ -10091,12 +10251,28 @@ class AuthManager {
|
|
|
10091
10251
|
async getUser() {
|
|
10092
10252
|
return withPassportError(async () => {
|
|
10093
10253
|
const oidcUser = await this.userManager.getUser();
|
|
10094
|
-
if (
|
|
10095
|
-
return
|
|
10254
|
+
if (oidcUser) {
|
|
10255
|
+
return AuthManager.mapOidcUserToDomainModel(oidcUser);
|
|
10096
10256
|
}
|
|
10097
|
-
|
|
10257
|
+
const deviceToken = this.deviceCredentialsManager.getCredentials();
|
|
10258
|
+
if (deviceToken) {
|
|
10259
|
+
return AuthManager.mapDeviceTokenResponseToDomainUserModel(deviceToken);
|
|
10260
|
+
}
|
|
10261
|
+
return null;
|
|
10098
10262
|
}, PassportErrorType.NOT_LOGGED_IN_ERROR);
|
|
10099
10263
|
}
|
|
10264
|
+
async getUserDeviceFlow() {
|
|
10265
|
+
return withPassportError(async () => {
|
|
10266
|
+
const deviceToken = this.deviceCredentialsManager.getCredentials();
|
|
10267
|
+
if (deviceToken) {
|
|
10268
|
+
return AuthManager.mapDeviceTokenResponseToDomainUserModel(deviceToken);
|
|
10269
|
+
}
|
|
10270
|
+
return null;
|
|
10271
|
+
}, PassportErrorType.NOT_LOGGED_IN_ERROR);
|
|
10272
|
+
}
|
|
10273
|
+
checkStoredDeviceFlowCredentials() {
|
|
10274
|
+
return this.deviceCredentialsManager.getCredentials();
|
|
10275
|
+
}
|
|
10100
10276
|
}
|
|
10101
10277
|
|
|
10102
10278
|
class MagicAdapter {
|
|
@@ -10624,6 +10800,17 @@ class PassportImxProviderFactory {
|
|
|
10624
10800
|
}
|
|
10625
10801
|
return this.createProviderInstance(user);
|
|
10626
10802
|
}
|
|
10803
|
+
async getProviderWithDeviceFlow(deviceCode, interval, timeoutMs) {
|
|
10804
|
+
const user = await this.authManager.connectImxDeviceFlow(deviceCode, interval, timeoutMs);
|
|
10805
|
+
return this.createProviderInstance(user);
|
|
10806
|
+
}
|
|
10807
|
+
async getProviderWithCredentials(tokenResponse) {
|
|
10808
|
+
const user = await this.authManager.connectImxWithCredentials(tokenResponse);
|
|
10809
|
+
if (!user) {
|
|
10810
|
+
return null;
|
|
10811
|
+
}
|
|
10812
|
+
return this.createProviderInstance(user);
|
|
10813
|
+
}
|
|
10627
10814
|
async createProviderInstance(user) {
|
|
10628
10815
|
if (!user.idToken) {
|
|
10629
10816
|
throw new PassportError('Failed to initialise', PassportErrorType.WALLET_CONNECTION_ERROR);
|
|
@@ -10931,16 +11118,38 @@ class Passport {
|
|
|
10931
11118
|
async connectImx() {
|
|
10932
11119
|
return this.passportImxProviderFactory.getProvider();
|
|
10933
11120
|
}
|
|
11121
|
+
async loginWithDeviceFlow() {
|
|
11122
|
+
return this.authManager.loginWithDeviceFlow();
|
|
11123
|
+
}
|
|
11124
|
+
async connectImxDeviceFlow(deviceCode, interval, timeoutMs) {
|
|
11125
|
+
return this.passportImxProviderFactory.getProviderWithDeviceFlow(deviceCode, interval, timeoutMs);
|
|
11126
|
+
}
|
|
11127
|
+
/**
|
|
11128
|
+
* @returns {boolean} the stored device flow credentials if they exist
|
|
11129
|
+
*/
|
|
11130
|
+
checkStoredDeviceFlowCredentials() {
|
|
11131
|
+
return this.authManager.checkStoredDeviceFlowCredentials();
|
|
11132
|
+
}
|
|
11133
|
+
async connectImxWithCredentials(tokenResponse) {
|
|
11134
|
+
return this.passportImxProviderFactory.getProviderWithCredentials(tokenResponse);
|
|
11135
|
+
}
|
|
10934
11136
|
async loginCallback() {
|
|
10935
11137
|
return this.authManager.loginCallback();
|
|
10936
11138
|
}
|
|
10937
11139
|
async logout() {
|
|
10938
11140
|
return this.authManager.logout();
|
|
10939
11141
|
}
|
|
11142
|
+
async logoutDeviceFlow() {
|
|
11143
|
+
return this.authManager.logoutDeviceFlow();
|
|
11144
|
+
}
|
|
10940
11145
|
async getUserInfo() {
|
|
10941
11146
|
const user = await this.authManager.getUser();
|
|
10942
11147
|
return user?.profile;
|
|
10943
11148
|
}
|
|
11149
|
+
async getUserInfoDeviceFlow() {
|
|
11150
|
+
const user = await this.authManager.getUserDeviceFlow();
|
|
11151
|
+
return user?.profile;
|
|
11152
|
+
}
|
|
10944
11153
|
async getIdToken() {
|
|
10945
11154
|
const user = await this.authManager.getUser();
|
|
10946
11155
|
return user?.idToken;
|
|
@@ -11846,49 +12055,11 @@ class ImmutableApiClientFactory {
|
|
|
11846
12055
|
}
|
|
11847
12056
|
}
|
|
11848
12057
|
|
|
11849
|
-
// eslint-disable-next-line
|
|
11850
|
-
dotenv.config();
|
|
11851
|
-
function getConfigFromEnv() {
|
|
11852
|
-
if (!process.env.ORDERBOOK_MR_API_URL
|
|
11853
|
-
|| !process.env.SEAPORT_CONTRACT_ADDRESS
|
|
11854
|
-
|| !process.env.ZONE_CONTRACT_ADDRESS) {
|
|
11855
|
-
throw new Error('missing config');
|
|
11856
|
-
}
|
|
11857
|
-
return {
|
|
11858
|
-
apiUrl: process.env.ORDERBOOK_MR_API_URL,
|
|
11859
|
-
seaportContractAddress: process.env.SEAPORT_CONTRACT_ADDRESS,
|
|
11860
|
-
zoneContractAddress: process.env.ZONE_CONTRACT_ADDRESS,
|
|
11861
|
-
};
|
|
11862
|
-
}
|
|
11863
|
-
|
|
11864
|
-
dotenv.config();
|
|
11865
|
-
function getLocalhostProvider() {
|
|
11866
|
-
const endpoint = process.env.LOCAL_RPC_ENDPOINT;
|
|
11867
|
-
if (!endpoint) {
|
|
11868
|
-
throw new Error('LOCAL_RPC_ENDPOINT not set');
|
|
11869
|
-
}
|
|
11870
|
-
return new ethers.providers.JsonRpcProvider(endpoint);
|
|
11871
|
-
}
|
|
11872
|
-
|
|
11873
|
-
dotenv.config();
|
|
11874
|
-
|
|
11875
|
-
const LOCAL_CHAIN_NAME = 'imtbl-zkevm-local';
|
|
11876
12058
|
const DEVNET_CHAIN_NAME = 'imtbl-zkevm-devnet';
|
|
11877
12059
|
const TESTNET_CHAIN_NAME = 'imtbl-zkevm-testnet';
|
|
11878
12060
|
const MAINNET_CHAIN_NAME = 'imtbl-zkevm-mainnet';
|
|
11879
|
-
function localChainConfig() {
|
|
11880
|
-
const localConfig = getConfigFromEnv();
|
|
11881
|
-
return {
|
|
11882
|
-
seaportContractAddress: localConfig.seaportContractAddress,
|
|
11883
|
-
zoneContractAddress: localConfig.zoneContractAddress,
|
|
11884
|
-
apiEndpoint: localConfig.apiUrl,
|
|
11885
|
-
provider: getLocalhostProvider(),
|
|
11886
|
-
};
|
|
11887
|
-
}
|
|
11888
12061
|
function getOrderbookConfig(chainName) {
|
|
11889
12062
|
switch (chainName) {
|
|
11890
|
-
case LOCAL_CHAIN_NAME:
|
|
11891
|
-
return localChainConfig();
|
|
11892
12063
|
case DEVNET_CHAIN_NAME:
|
|
11893
12064
|
return {
|
|
11894
12065
|
seaportContractAddress: '0x41388404Efb7a68Fd31d75CEf71dF91e2BDBa2fb',
|
|
@@ -12864,24 +13035,26 @@ class SeaportLibFactory {
|
|
|
12864
13035
|
* @param {OrderbookModuleConfiguration} config - Configuration for Immutable services.
|
|
12865
13036
|
*/
|
|
12866
13037
|
class Orderbook {
|
|
12867
|
-
config;
|
|
12868
13038
|
apiClient;
|
|
12869
13039
|
seaport;
|
|
12870
|
-
|
|
12871
|
-
|
|
12872
|
-
|
|
12873
|
-
const
|
|
13040
|
+
orderbookConfig;
|
|
13041
|
+
constructor(config, localConfig) {
|
|
13042
|
+
// either use preconfigured config or local config passed in
|
|
13043
|
+
const maybeConfig = getOrderbookConfig(config.overrides?.chainName) || localConfig;
|
|
13044
|
+
if (!maybeConfig) {
|
|
13045
|
+
throw new Error('Orderbook configuration not passed, either select one of the preseet chainNames or pass in localConfig');
|
|
13046
|
+
}
|
|
13047
|
+
const { chainName, provider } = config.overrides;
|
|
13048
|
+
maybeConfig.provider = provider
|
|
13049
|
+
|| maybeConfig.provider;
|
|
13050
|
+
this.orderbookConfig = maybeConfig;
|
|
13051
|
+
const { apiEndpoint } = this.orderbookConfig;
|
|
12874
13052
|
if (!apiEndpoint) {
|
|
12875
13053
|
throw new Error('API endpoint must be provided as an override');
|
|
12876
13054
|
}
|
|
12877
|
-
|
|
12878
|
-
const
|
|
12879
|
-
|
|
12880
|
-
throw new Error('chainName must be provided as an override');
|
|
12881
|
-
}
|
|
12882
|
-
this.apiClient = new ImmutableApiClientFactory(apiEndpoint, chainName, orderbookConfig.seaportContractAddress).create();
|
|
12883
|
-
const seaportLibFactory = new SeaportLibFactory(orderbookConfig.seaportContractAddress, orderbookConfig.provider);
|
|
12884
|
-
this.seaport = new Seaport(seaportLibFactory, orderbookConfig.provider, orderbookConfig.seaportContractAddress, orderbookConfig.zoneContractAddress);
|
|
13055
|
+
this.apiClient = new ImmutableApiClientFactory(apiEndpoint, chainName, this.orderbookConfig.seaportContractAddress).create();
|
|
13056
|
+
const seaportLibFactory = new SeaportLibFactory(this.orderbookConfig.seaportContractAddress, this.orderbookConfig.provider);
|
|
13057
|
+
this.seaport = new Seaport(seaportLibFactory, this.orderbookConfig.provider, this.orderbookConfig.seaportContractAddress, this.orderbookConfig.zoneContractAddress);
|
|
12885
13058
|
}
|
|
12886
13059
|
/**
|
|
12887
13060
|
* Get an order by ID
|
|
@@ -12909,8 +13082,7 @@ class Orderbook {
|
|
|
12909
13082
|
* the order components that can be submitted to `createListing` with a signature.
|
|
12910
13083
|
*/
|
|
12911
13084
|
async prepareListing({ makerAddress, sell, buy, orderExpiry, }) {
|
|
12912
|
-
const
|
|
12913
|
-
const erc721 = new ERC721Factory(sell.contractAddress, orderbookConfig.provider).create();
|
|
13085
|
+
const erc721 = new ERC721Factory(sell.contractAddress, this.orderbookConfig.provider).create();
|
|
12914
13086
|
const royaltyInfo = await erc721.royaltyInfo(sell.tokenId, buy.amount);
|
|
12915
13087
|
return this.seaport.prepareSeaportOrder(makerAddress, sell, buy, royaltyInfo,
|
|
12916
13088
|
// Default order start to now
|
|
@@ -24384,9 +24556,8 @@ class ExchangeError extends Error {
|
|
|
24384
24556
|
}
|
|
24385
24557
|
}
|
|
24386
24558
|
class InvalidConfigurationError extends ExchangeError {
|
|
24387
|
-
constructor() {
|
|
24388
|
-
|
|
24389
|
-
super(message, ExchangeErrorCode.INVALID_CONFIGURATION);
|
|
24559
|
+
constructor(message) {
|
|
24560
|
+
super(message || 'Invalid configuration', ExchangeErrorCode.INVALID_CONFIGURATION);
|
|
24390
24561
|
}
|
|
24391
24562
|
}
|
|
24392
24563
|
class ChainNotSupportedError extends ExchangeError {
|
|
@@ -26487,20 +26658,84 @@ function getSwap(nativeToken, routeAndQuote, fromAddress, slippage, deadline, pe
|
|
|
26487
26658
|
};
|
|
26488
26659
|
}
|
|
26489
26660
|
|
|
26661
|
+
const CONTRACTS_FOR_CHAIN_ID = {
|
|
26662
|
+
[IMMUTABLE_TESTNET_CHAIN_ID]: {
|
|
26663
|
+
multicall: '0xb18c44b211065E69844FbA9AE146DA362104AfBf',
|
|
26664
|
+
coreFactory: '0x12739A8f1A8035F439092D016DAE19A2874F30d2',
|
|
26665
|
+
quoterV2: '0xF674847fBcca5C80315e3AE37043Dce99F6CC529',
|
|
26666
|
+
peripheryRouter: '0x0Afe6F5f4DC34461A801420634239FFaD50A2e44',
|
|
26667
|
+
},
|
|
26668
|
+
};
|
|
26669
|
+
const SUPPORTED_SANDBOX_CHAINS = {
|
|
26670
|
+
[IMMUTABLE_TESTNET_CHAIN_ID]: {
|
|
26671
|
+
chainId: IMMUTABLE_TESTNET_CHAIN_ID,
|
|
26672
|
+
rpcUrl: IMMUTABLE_TESTNET_RPC_URL,
|
|
26673
|
+
contracts: CONTRACTS_FOR_CHAIN_ID[IMMUTABLE_TESTNET_CHAIN_ID],
|
|
26674
|
+
commonRoutingTokens: IMMUTABLE_TESTNET_COMMON_ROUTING_TOKENS,
|
|
26675
|
+
nativeToken: TIMX_IMMUTABLE_TESTNET,
|
|
26676
|
+
},
|
|
26677
|
+
};
|
|
26678
|
+
const SUPPORTED_PRODUCTION_CHAINS = {};
|
|
26679
|
+
const SUPPORTED_CHAIN_IDS_FOR_ENVIRONMENT = {
|
|
26680
|
+
[exports.Environment.SANDBOX]: SUPPORTED_SANDBOX_CHAINS,
|
|
26681
|
+
[exports.Environment.PRODUCTION]: SUPPORTED_PRODUCTION_CHAINS,
|
|
26682
|
+
};
|
|
26683
|
+
function validateOverrides(overrides) {
|
|
26684
|
+
Object.entries(overrides).forEach(([key, value]) => {
|
|
26685
|
+
if (!value) {
|
|
26686
|
+
throw new InvalidConfigurationError(`Missing override: ${key}`);
|
|
26687
|
+
}
|
|
26688
|
+
});
|
|
26689
|
+
Object.entries(overrides.exchangeContracts).forEach(([key, contract]) => {
|
|
26690
|
+
if (!isValidNonZeroAddress(contract)) {
|
|
26691
|
+
throw new InvalidConfigurationError(`Invalid exchange contract address for ${key}`);
|
|
26692
|
+
}
|
|
26693
|
+
});
|
|
26694
|
+
}
|
|
26695
|
+
/**
|
|
26696
|
+
* {@link ExchangeConfiguration} is used to configure the {@link Exchange} class.
|
|
26697
|
+
* @param chainId the ID of the chain to configure. {@link SUPPORTED_CHAIN_IDS_FOR_ENVIRONMENT} contains the supported chains for each environment.
|
|
26698
|
+
* @param baseConfig the base {@link ImmutableConfiguration} for the {@link Exchange} class
|
|
26699
|
+
*/
|
|
26700
|
+
class ExchangeConfiguration {
|
|
26701
|
+
baseConfig;
|
|
26702
|
+
chain;
|
|
26703
|
+
constructor({ chainId, baseConfig, overrides }) {
|
|
26704
|
+
this.baseConfig = baseConfig;
|
|
26705
|
+
if (overrides) {
|
|
26706
|
+
validateOverrides(overrides);
|
|
26707
|
+
this.chain = {
|
|
26708
|
+
chainId,
|
|
26709
|
+
rpcUrl: overrides.rpcURL,
|
|
26710
|
+
contracts: overrides.exchangeContracts,
|
|
26711
|
+
commonRoutingTokens: overrides.commonRoutingTokens,
|
|
26712
|
+
nativeToken: overrides.nativeToken,
|
|
26713
|
+
};
|
|
26714
|
+
return;
|
|
26715
|
+
}
|
|
26716
|
+
const chain = SUPPORTED_CHAIN_IDS_FOR_ENVIRONMENT[baseConfig.environment][chainId];
|
|
26717
|
+
if (!chain) {
|
|
26718
|
+
throw new ChainNotSupportedError(chainId, baseConfig.environment);
|
|
26719
|
+
}
|
|
26720
|
+
this.chain = chain;
|
|
26721
|
+
}
|
|
26722
|
+
}
|
|
26723
|
+
|
|
26490
26724
|
class Exchange {
|
|
26491
26725
|
provider;
|
|
26492
26726
|
router;
|
|
26493
26727
|
chainId;
|
|
26494
26728
|
nativeToken;
|
|
26495
26729
|
constructor(configuration) {
|
|
26496
|
-
|
|
26497
|
-
this.
|
|
26498
|
-
this.
|
|
26499
|
-
this.
|
|
26500
|
-
|
|
26501
|
-
|
|
26502
|
-
|
|
26503
|
-
|
|
26730
|
+
const config = new ExchangeConfiguration(configuration);
|
|
26731
|
+
this.chainId = config.chain.chainId;
|
|
26732
|
+
this.nativeToken = config.chain.nativeToken;
|
|
26733
|
+
this.provider = new ethers.ethers.providers.JsonRpcProvider(config.chain.rpcUrl);
|
|
26734
|
+
this.router = new Router(this.provider, config.chain.commonRoutingTokens, {
|
|
26735
|
+
multicallAddress: config.chain.contracts.multicall,
|
|
26736
|
+
factoryAddress: config.chain.contracts.coreFactory,
|
|
26737
|
+
quoterAddress: config.chain.contracts.quoterV2,
|
|
26738
|
+
peripheryRouterAddress: config.chain.contracts.peripheryRouter,
|
|
26504
26739
|
});
|
|
26505
26740
|
}
|
|
26506
26741
|
static validate(tokenInAddress, tokenOutAddress, maxHops, slippagePercent, fromAddress) {
|
|
@@ -26580,67 +26815,6 @@ class Exchange {
|
|
|
26580
26815
|
}
|
|
26581
26816
|
}
|
|
26582
26817
|
|
|
26583
|
-
const CONTRACTS_FOR_CHAIN_ID = {
|
|
26584
|
-
[IMMUTABLE_TESTNET_CHAIN_ID]: {
|
|
26585
|
-
multicall: '0xb18c44b211065E69844FbA9AE146DA362104AfBf',
|
|
26586
|
-
coreFactory: '0x12739A8f1A8035F439092D016DAE19A2874F30d2',
|
|
26587
|
-
quoterV2: '0xF674847fBcca5C80315e3AE37043Dce99F6CC529',
|
|
26588
|
-
peripheryRouter: '0x0Afe6F5f4DC34461A801420634239FFaD50A2e44',
|
|
26589
|
-
},
|
|
26590
|
-
};
|
|
26591
|
-
const SUPPORTED_SANDBOX_CHAINS = {
|
|
26592
|
-
[IMMUTABLE_TESTNET_CHAIN_ID]: {
|
|
26593
|
-
chainId: IMMUTABLE_TESTNET_CHAIN_ID,
|
|
26594
|
-
rpcUrl: IMMUTABLE_TESTNET_RPC_URL,
|
|
26595
|
-
contracts: CONTRACTS_FOR_CHAIN_ID[IMMUTABLE_TESTNET_CHAIN_ID],
|
|
26596
|
-
commonRoutingTokens: IMMUTABLE_TESTNET_COMMON_ROUTING_TOKENS,
|
|
26597
|
-
nativeToken: TIMX_IMMUTABLE_TESTNET,
|
|
26598
|
-
},
|
|
26599
|
-
};
|
|
26600
|
-
const SUPPORTED_PRODUCTION_CHAINS = {};
|
|
26601
|
-
const SUPPORTED_CHAIN_IDS_FOR_ENVIRONMENT = {
|
|
26602
|
-
[exports.Environment.SANDBOX]: SUPPORTED_SANDBOX_CHAINS,
|
|
26603
|
-
[exports.Environment.PRODUCTION]: SUPPORTED_PRODUCTION_CHAINS,
|
|
26604
|
-
};
|
|
26605
|
-
function validateOverrides(overrides) {
|
|
26606
|
-
if (!overrides.rpcURL || !overrides.exchangeContracts || !overrides.commonRoutingTokens || !overrides.nativeToken) {
|
|
26607
|
-
throw new InvalidConfigurationError();
|
|
26608
|
-
}
|
|
26609
|
-
Object.values(overrides.exchangeContracts).forEach((contract) => {
|
|
26610
|
-
if (!isValidNonZeroAddress(contract)) {
|
|
26611
|
-
throw new InvalidConfigurationError();
|
|
26612
|
-
}
|
|
26613
|
-
});
|
|
26614
|
-
}
|
|
26615
|
-
/**
|
|
26616
|
-
* {@link ExchangeConfiguration} is used to configure the {@link Exchange} class.
|
|
26617
|
-
* @param chainId the ID of the chain to configure. {@link SUPPORTED_CHAIN_IDS_FOR_ENVIRONMENT} contains the supported chains for each environment.
|
|
26618
|
-
* @param baseConfig the base {@link ImmutableConfiguration} for the {@link Exchange} class
|
|
26619
|
-
*/
|
|
26620
|
-
class ExchangeConfiguration {
|
|
26621
|
-
baseConfig;
|
|
26622
|
-
chain;
|
|
26623
|
-
constructor({ chainId, baseConfig, overrides }) {
|
|
26624
|
-
this.baseConfig = baseConfig;
|
|
26625
|
-
if (overrides) {
|
|
26626
|
-
validateOverrides(overrides);
|
|
26627
|
-
this.chain = {
|
|
26628
|
-
chainId,
|
|
26629
|
-
rpcUrl: overrides.rpcURL,
|
|
26630
|
-
contracts: overrides.exchangeContracts,
|
|
26631
|
-
commonRoutingTokens: overrides.commonRoutingTokens,
|
|
26632
|
-
nativeToken: overrides.nativeToken,
|
|
26633
|
-
};
|
|
26634
|
-
return;
|
|
26635
|
-
}
|
|
26636
|
-
const chain = SUPPORTED_CHAIN_IDS_FOR_ENVIRONMENT[baseConfig.environment][chainId];
|
|
26637
|
-
if (!chain) {
|
|
26638
|
-
throw new ChainNotSupportedError(chainId, baseConfig.environment);
|
|
26639
|
-
}
|
|
26640
|
-
this.chain = chain;
|
|
26641
|
-
}
|
|
26642
|
-
}
|
|
26643
|
-
|
|
26644
26818
|
/* eslint-disable class-methods-use-this */
|
|
26645
26819
|
|
|
26646
26820
|
const $762782b6c862d954$export$db5daa1b5156ccfe = [
|
|
@@ -27393,13 +27567,13 @@ async function $67fc622a2b913d5f$export$989eefe1274a439c(fromChainId, toChainId,
|
|
|
27393
27567
|
}
|
|
27394
27568
|
async function $67fc622a2b913d5f$export$7cf6178417769841(chainId, config) {
|
|
27395
27569
|
const dexConfig = await config.remote.getConfig("dex");
|
|
27396
|
-
return new (Exchange)(
|
|
27570
|
+
return new (Exchange)({
|
|
27397
27571
|
chainId: chainId,
|
|
27398
27572
|
baseConfig: new (ImmutableConfiguration)({
|
|
27399
27573
|
environment: config.environment
|
|
27400
27574
|
}),
|
|
27401
27575
|
overrides: dexConfig?.overrides
|
|
27402
|
-
})
|
|
27576
|
+
});
|
|
27403
27577
|
}
|
|
27404
27578
|
|
|
27405
27579
|
|
|
@@ -27763,7 +27937,7 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
|
|
|
27763
27937
|
function $parcel$export(e, n, v, s) {
|
|
27764
27938
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
27765
27939
|
}
|
|
27766
|
-
const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.1
|
|
27940
|
+
const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.2.1-alpha";
|
|
27767
27941
|
const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
|
|
27768
27942
|
const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
|
|
27769
27943
|
|