@imtbl/sdk 1.5.0 → 1.5.2
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 +2 -2
- package/dist/browser/checkout/sdk.js +6 -6
- package/dist/browser/checkout/widgets.js +61 -61
- package/dist/checkout.d.ts +45 -5
- package/dist/checkout.js +124 -70
- package/dist/config.js +1 -1
- package/dist/index.browser.js +4 -4
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +166 -108
- package/dist/index.d.ts +52 -4
- package/dist/index.js +166 -108
- package/dist/orderbook.js +1 -1
- package/dist/passport.js +43 -39
- package/dist/x.js +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -173,7 +173,7 @@ const flattenProperties$1 = (properties) => {
|
|
|
173
173
|
};
|
|
174
174
|
|
|
175
175
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
176
|
-
const SDK_VERSION$1 = '1.5.
|
|
176
|
+
const SDK_VERSION$1 = '1.5.2';
|
|
177
177
|
let initialised$1 = false;
|
|
178
178
|
const isInitialised$1 = () => initialised$1;
|
|
179
179
|
const getReferrer$1 = () => {
|
|
@@ -11260,7 +11260,7 @@ class MultiRollupApiClients {
|
|
|
11260
11260
|
}
|
|
11261
11261
|
|
|
11262
11262
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
11263
|
-
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.5.
|
|
11263
|
+
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.5.2' };
|
|
11264
11264
|
const createConfig = ({ basePath, headers, }) => {
|
|
11265
11265
|
if (!basePath.trim()) {
|
|
11266
11266
|
throw Error('basePath can not be empty');
|
|
@@ -11332,7 +11332,7 @@ class APIError extends Error {
|
|
|
11332
11332
|
|
|
11333
11333
|
/* eslint-disable implicit-arrow-linebreak */
|
|
11334
11334
|
const defaultHeaders = {
|
|
11335
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.5.
|
|
11335
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.5.2',
|
|
11336
11336
|
};
|
|
11337
11337
|
/**
|
|
11338
11338
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -11765,7 +11765,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
11765
11765
|
chainID,
|
|
11766
11766
|
coreContractAddress,
|
|
11767
11767
|
registrationContractAddress,
|
|
11768
|
-
sdkVersion: 'ts-immutable-sdk-1.5.
|
|
11768
|
+
sdkVersion: 'ts-immutable-sdk-1.5.2',
|
|
11769
11769
|
});
|
|
11770
11770
|
/**
|
|
11771
11771
|
* Sets `sdkVersion` at the time of build
|
|
@@ -16835,12 +16835,14 @@ class GuardianClient {
|
|
|
16835
16835
|
messageAPI;
|
|
16836
16836
|
confirmationScreen;
|
|
16837
16837
|
crossSdkBridgeEnabled;
|
|
16838
|
-
|
|
16838
|
+
authManager;
|
|
16839
|
+
constructor({ confirmationScreen, config, authManager }) {
|
|
16839
16840
|
const guardianConfiguration = new Configuration({ basePath: config.imxPublicApiDomain });
|
|
16840
16841
|
this.confirmationScreen = confirmationScreen;
|
|
16841
16842
|
this.crossSdkBridgeEnabled = config.crossSdkBridgeEnabled;
|
|
16842
16843
|
this.messageAPI = new MessagesApi(guardianConfiguration);
|
|
16843
16844
|
this.transactionAPI = new TransactionsApi(guardianConfiguration);
|
|
16845
|
+
this.authManager = authManager;
|
|
16844
16846
|
}
|
|
16845
16847
|
/**
|
|
16846
16848
|
* Open confirmation screen and close it automatically if the
|
|
@@ -16864,10 +16866,11 @@ class GuardianClient {
|
|
|
16864
16866
|
withDefaultConfirmationScreenTask(task) {
|
|
16865
16867
|
return this.withConfirmationScreenTask()(task);
|
|
16866
16868
|
}
|
|
16867
|
-
async evaluateImxTransaction({ payloadHash
|
|
16869
|
+
async evaluateImxTransaction({ payloadHash }) {
|
|
16868
16870
|
const finallyFn = () => {
|
|
16869
16871
|
this.confirmationScreen.closeWindow();
|
|
16870
16872
|
};
|
|
16873
|
+
const user = await this.authManager.getUser();
|
|
16871
16874
|
const headers = { Authorization: `Bearer ${user.accessToken}` };
|
|
16872
16875
|
const transactionRes = await retryWithDelay(async () => this.transactionAPI.getTransactionByID({
|
|
16873
16876
|
transactionID: payloadHash,
|
|
@@ -16896,7 +16899,8 @@ class GuardianClient {
|
|
|
16896
16899
|
this.confirmationScreen.closeWindow();
|
|
16897
16900
|
}
|
|
16898
16901
|
}
|
|
16899
|
-
async evaluateEVMTransaction({ chainId, nonce,
|
|
16902
|
+
async evaluateEVMTransaction({ chainId, nonce, metaTransactions, }) {
|
|
16903
|
+
const user = await this.authManager.getUser();
|
|
16900
16904
|
const headers = { Authorization: `Bearer ${user.accessToken}` };
|
|
16901
16905
|
const guardianTransactions = transformGuardianTransactions(metaTransactions);
|
|
16902
16906
|
try {
|
|
@@ -16919,11 +16923,10 @@ class GuardianClient {
|
|
|
16919
16923
|
throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Transaction failed to validate with error: ${errorMessage}`);
|
|
16920
16924
|
}
|
|
16921
16925
|
}
|
|
16922
|
-
async validateEVMTransaction({ chainId, nonce,
|
|
16926
|
+
async validateEVMTransaction({ chainId, nonce, metaTransactions, }) {
|
|
16923
16927
|
const transactionEvaluationResponse = await this.evaluateEVMTransaction({
|
|
16924
16928
|
chainId,
|
|
16925
16929
|
nonce,
|
|
16926
|
-
user,
|
|
16927
16930
|
metaTransactions,
|
|
16928
16931
|
});
|
|
16929
16932
|
const { confirmationRequired, transactionId } = transactionEvaluationResponse;
|
|
@@ -16931,6 +16934,7 @@ class GuardianClient {
|
|
|
16931
16934
|
throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
|
|
16932
16935
|
}
|
|
16933
16936
|
if (confirmationRequired && !!transactionId) {
|
|
16937
|
+
const user = await this.authManager.getUser();
|
|
16934
16938
|
const confirmationResult = await this.confirmationScreen.requestConfirmation(transactionId, user.zkEvm.ethAddress, TransactionApprovalRequestChainTypeEnum.Evm, chainId);
|
|
16935
16939
|
if (!confirmationResult.confirmed) {
|
|
16936
16940
|
throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Transaction rejected by user');
|
|
@@ -16940,8 +16944,12 @@ class GuardianClient {
|
|
|
16940
16944
|
this.confirmationScreen.closeWindow();
|
|
16941
16945
|
}
|
|
16942
16946
|
}
|
|
16943
|
-
async evaluateMessage({ chainID, payload
|
|
16947
|
+
async evaluateMessage({ chainID, payload }) {
|
|
16944
16948
|
try {
|
|
16949
|
+
const user = await this.authManager.getUser();
|
|
16950
|
+
if (user === null) {
|
|
16951
|
+
throw new PassportError('evaluateMessage requires a valid ID token or refresh token. Please log in first', PassportErrorType.NOT_LOGGED_IN_ERROR);
|
|
16952
|
+
}
|
|
16945
16953
|
const messageEvalResponse = await this.messageAPI.evaluateMessage({ messageEvaluationRequest: { chainID, payload } }, { headers: { Authorization: `Bearer ${user.accessToken}` } });
|
|
16946
16954
|
return messageEvalResponse.data;
|
|
16947
16955
|
}
|
|
@@ -16950,12 +16958,13 @@ class GuardianClient {
|
|
|
16950
16958
|
throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Message failed to validate with error: ${errorMessage}`);
|
|
16951
16959
|
}
|
|
16952
16960
|
}
|
|
16953
|
-
async validateMessage({ chainID, payload
|
|
16954
|
-
const { messageId, confirmationRequired } = await this.evaluateMessage({ chainID, payload
|
|
16961
|
+
async validateMessage({ chainID, payload }) {
|
|
16962
|
+
const { messageId, confirmationRequired } = await this.evaluateMessage({ chainID, payload });
|
|
16955
16963
|
if (confirmationRequired && this.crossSdkBridgeEnabled) {
|
|
16956
16964
|
throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
|
|
16957
16965
|
}
|
|
16958
16966
|
if (confirmationRequired && !!messageId) {
|
|
16967
|
+
const user = await this.authManager.getUser();
|
|
16959
16968
|
const confirmationResult = await this.confirmationScreen.requestMessageConfirmation(messageId, user.zkEvm.ethAddress);
|
|
16960
16969
|
if (!confirmationResult.confirmed) {
|
|
16961
16970
|
throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Signature rejected by user');
|
|
@@ -17037,7 +17046,6 @@ async function createOrder$1({ starkSigner, user, request, ordersApi, guardianCl
|
|
|
17037
17046
|
getSignableOrderRequestV3,
|
|
17038
17047
|
}, { headers });
|
|
17039
17048
|
await guardianClient.evaluateImxTransaction({
|
|
17040
|
-
user,
|
|
17041
17049
|
payloadHash: getSignableOrderResponse.data.payload_hash,
|
|
17042
17050
|
});
|
|
17043
17051
|
const { payload_hash: payloadHash } = getSignableOrderResponse.data;
|
|
@@ -17080,7 +17088,6 @@ async function cancelOrder$1({ user, starkSigner, request, ordersApi, guardianCl
|
|
|
17080
17088
|
getSignableCancelOrderRequest,
|
|
17081
17089
|
}, { headers });
|
|
17082
17090
|
await guardianClient.evaluateImxTransaction({
|
|
17083
|
-
user,
|
|
17084
17091
|
payloadHash: getSignableCancelOrderResponse.data.payload_hash,
|
|
17085
17092
|
});
|
|
17086
17093
|
const { payload_hash: payloadHash } = getSignableCancelOrderResponse.data;
|
|
@@ -17142,7 +17149,6 @@ async function createTrade$1({ request, tradesApi, user, starkSigner, guardianCl
|
|
|
17142
17149
|
getSignableTradeRequest,
|
|
17143
17150
|
}, { headers });
|
|
17144
17151
|
await guardianClient.evaluateImxTransaction({
|
|
17145
|
-
user,
|
|
17146
17152
|
payloadHash: getSignableTradeResponse.data.payload_hash,
|
|
17147
17153
|
});
|
|
17148
17154
|
const { payload_hash: payloadHash } = getSignableTradeResponse.data;
|
|
@@ -17190,7 +17196,6 @@ async function transfer$1({ request, transfersApi, starkSigner, user, guardianCl
|
|
|
17190
17196
|
getSignableTransferRequest,
|
|
17191
17197
|
}, { headers });
|
|
17192
17198
|
await guardianClient.evaluateImxTransaction({
|
|
17193
|
-
user,
|
|
17194
17199
|
payloadHash: signableResult.data.payload_hash,
|
|
17195
17200
|
});
|
|
17196
17201
|
const signableResultData = signableResult.data;
|
|
@@ -17241,7 +17246,6 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, guar
|
|
|
17241
17246
|
},
|
|
17242
17247
|
}, { headers });
|
|
17243
17248
|
await guardianClient.evaluateImxTransaction({
|
|
17244
|
-
user,
|
|
17245
17249
|
payloadHash: signableResult.data.signable_responses[0]?.payload_hash,
|
|
17246
17250
|
});
|
|
17247
17251
|
const requests = await Promise.all(signableResult.data.signable_responses.map(async (resp) => {
|
|
@@ -17321,6 +17325,7 @@ class PassportImxProvider {
|
|
|
17321
17325
|
this.guardianClient = new GuardianClient({
|
|
17322
17326
|
confirmationScreen,
|
|
17323
17327
|
config,
|
|
17328
|
+
authManager,
|
|
17324
17329
|
});
|
|
17325
17330
|
this.magicAdapter = magicAdapter;
|
|
17326
17331
|
this.imxApiClients = imxApiClients;
|
|
@@ -17952,11 +17957,11 @@ const getEip155ChainId = (chainId) => `eip155:${chainId}`;
|
|
|
17952
17957
|
class RelayerClient {
|
|
17953
17958
|
config;
|
|
17954
17959
|
jsonRpcProvider;
|
|
17955
|
-
|
|
17956
|
-
constructor({ config, jsonRpcProvider,
|
|
17960
|
+
authManager;
|
|
17961
|
+
constructor({ config, jsonRpcProvider, authManager }) {
|
|
17957
17962
|
this.config = config;
|
|
17958
17963
|
this.jsonRpcProvider = jsonRpcProvider;
|
|
17959
|
-
this.
|
|
17964
|
+
this.authManager = authManager;
|
|
17960
17965
|
}
|
|
17961
17966
|
async postToRelayer(request) {
|
|
17962
17967
|
const body = {
|
|
@@ -17964,10 +17969,11 @@ class RelayerClient {
|
|
|
17964
17969
|
jsonrpc: '2.0',
|
|
17965
17970
|
...request,
|
|
17966
17971
|
};
|
|
17972
|
+
const user = await this.authManager.getUser();
|
|
17967
17973
|
const response = await fetch(`${this.config.relayerUrl}/v1/transactions`, {
|
|
17968
17974
|
method: 'POST',
|
|
17969
17975
|
headers: {
|
|
17970
|
-
Authorization: `Bearer ${
|
|
17976
|
+
Authorization: `Bearer ${user?.accessToken}`,
|
|
17971
17977
|
'Content-Type': 'application/json',
|
|
17972
17978
|
},
|
|
17973
17979
|
body: JSON.stringify(body),
|
|
@@ -18126,7 +18132,7 @@ const getMetaTransactions = async (metaTransaction, nonce, chainId, walletAddres
|
|
|
18126
18132
|
}
|
|
18127
18133
|
return [metaTransaction, feeMetaTransaction];
|
|
18128
18134
|
};
|
|
18129
|
-
const sendTransaction$1 = ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient,
|
|
18135
|
+
const sendTransaction$1 = ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, zkevmAddress, }) => guardianClient
|
|
18130
18136
|
.withConfirmationScreen({ width: 480, height: 720 })(async () => {
|
|
18131
18137
|
const transactionRequest = params[0];
|
|
18132
18138
|
if (!transactionRequest.to) {
|
|
@@ -18136,7 +18142,7 @@ const sendTransaction$1 = ({ params, magicProvider, jsonRpcProvider, relayerClie
|
|
|
18136
18142
|
const chainIdBigNumber = ethers.BigNumber.from(chainId);
|
|
18137
18143
|
const magicWeb3Provider = new providers.Web3Provider(magicProvider);
|
|
18138
18144
|
const signer = magicWeb3Provider.getSigner();
|
|
18139
|
-
const nonce = await getNonce(jsonRpcProvider,
|
|
18145
|
+
const nonce = await getNonce(jsonRpcProvider, zkevmAddress);
|
|
18140
18146
|
const metaTransaction = {
|
|
18141
18147
|
to: transactionRequest.to,
|
|
18142
18148
|
data: transactionRequest.data,
|
|
@@ -18144,17 +18150,16 @@ const sendTransaction$1 = ({ params, magicProvider, jsonRpcProvider, relayerClie
|
|
|
18144
18150
|
value: transactionRequest.value,
|
|
18145
18151
|
revertOnError: true,
|
|
18146
18152
|
};
|
|
18147
|
-
const metaTransactions = await getMetaTransactions(metaTransaction, nonce, chainIdBigNumber,
|
|
18153
|
+
const metaTransactions = await getMetaTransactions(metaTransaction, nonce, chainIdBigNumber, zkevmAddress, signer, relayerClient);
|
|
18148
18154
|
await guardianClient.validateEVMTransaction({
|
|
18149
18155
|
chainId: getEip155ChainId(chainId),
|
|
18150
18156
|
nonce: convertBigNumberishToString(nonce),
|
|
18151
|
-
user,
|
|
18152
18157
|
metaTransactions,
|
|
18153
18158
|
});
|
|
18154
18159
|
// NOTE: We sign again because we now are adding the fee transaction, so the
|
|
18155
18160
|
// whole payload is different and needs a new signature.
|
|
18156
|
-
const signedTransactions = await getSignedMetaTransactions(metaTransactions, nonce, chainIdBigNumber,
|
|
18157
|
-
const relayerId = await relayerClient.ethSendTransaction(
|
|
18161
|
+
const signedTransactions = await getSignedMetaTransactions(metaTransactions, nonce, chainIdBigNumber, zkevmAddress, signer);
|
|
18162
|
+
const relayerId = await relayerClient.ethSendTransaction(zkevmAddress, signedTransactions);
|
|
18158
18163
|
const retrieveRelayerTransaction = async () => {
|
|
18159
18164
|
const tx = await relayerClient.imGetTransactionByHash(relayerId);
|
|
18160
18165
|
// NOTE: The transaction hash is only available from the Relayer once the
|
|
@@ -18222,7 +18227,7 @@ const transformTypedData = (typedData, chainId) => {
|
|
|
18222
18227
|
}
|
|
18223
18228
|
return transformedTypedData;
|
|
18224
18229
|
};
|
|
18225
|
-
const signTypedDataV4 = async ({ params, method, magicProvider, jsonRpcProvider, relayerClient, guardianClient,
|
|
18230
|
+
const signTypedDataV4 = async ({ params, method, magicProvider, jsonRpcProvider, relayerClient, guardianClient, }) => guardianClient
|
|
18226
18231
|
.withConfirmationScreen({ width: 480, height: 730 })(async () => {
|
|
18227
18232
|
const fromAddress = params[0];
|
|
18228
18233
|
const typedDataParam = params[1];
|
|
@@ -18231,7 +18236,7 @@ const signTypedDataV4 = async ({ params, method, magicProvider, jsonRpcProvider,
|
|
|
18231
18236
|
}
|
|
18232
18237
|
const { chainId } = await jsonRpcProvider.ready;
|
|
18233
18238
|
const typedData = transformTypedData(typedDataParam, chainId);
|
|
18234
|
-
await guardianClient.validateMessage({ chainID: String(chainId), payload: typedData
|
|
18239
|
+
await guardianClient.validateMessage({ chainID: String(chainId), payload: typedData });
|
|
18235
18240
|
const relayerSignature = await relayerClient.imSignTypedData(fromAddress, typedData);
|
|
18236
18241
|
const magicWeb3Provider = new providers.Web3Provider(magicProvider);
|
|
18237
18242
|
const signer = magicWeb3Provider.getSigner();
|
|
@@ -18249,7 +18254,7 @@ class ZkEvmProvider {
|
|
|
18249
18254
|
guardianClient;
|
|
18250
18255
|
relayerClient;
|
|
18251
18256
|
magicProvider; // Used for signing
|
|
18252
|
-
|
|
18257
|
+
zkevmAddress;
|
|
18253
18258
|
isPassport = true;
|
|
18254
18259
|
constructor({ authManager, magicAdapter, config, confirmationScreen, multiRollupApiClients, passportEventEmitter, }) {
|
|
18255
18260
|
this.authManager = authManager;
|
|
@@ -18274,7 +18279,6 @@ class ZkEvmProvider {
|
|
|
18274
18279
|
handleLogout = () => {
|
|
18275
18280
|
const shouldEmitAccountsChanged = this.isLoggedIn();
|
|
18276
18281
|
this.magicProvider = undefined;
|
|
18277
|
-
this.user = undefined;
|
|
18278
18282
|
this.relayerClient = undefined;
|
|
18279
18283
|
this.guardianClient = undefined;
|
|
18280
18284
|
if (shouldEmitAccountsChanged) {
|
|
@@ -18283,7 +18287,7 @@ class ZkEvmProvider {
|
|
|
18283
18287
|
};
|
|
18284
18288
|
isLoggedIn() {
|
|
18285
18289
|
return this.magicProvider !== undefined
|
|
18286
|
-
&& this.
|
|
18290
|
+
&& this.zkevmAddress !== undefined
|
|
18287
18291
|
&& this.relayerClient !== undefined
|
|
18288
18292
|
&& this.guardianClient !== undefined;
|
|
18289
18293
|
}
|
|
@@ -18291,7 +18295,7 @@ class ZkEvmProvider {
|
|
|
18291
18295
|
switch (request.method) {
|
|
18292
18296
|
case 'eth_requestAccounts': {
|
|
18293
18297
|
if (this.isLoggedIn()) {
|
|
18294
|
-
return [this.
|
|
18298
|
+
return [this.zkevmAddress];
|
|
18295
18299
|
}
|
|
18296
18300
|
const { magicProvider, user } = await loginZkEvmUser({
|
|
18297
18301
|
authManager: this.authManager,
|
|
@@ -18300,19 +18304,20 @@ class ZkEvmProvider {
|
|
|
18300
18304
|
multiRollupApiClients: this.multiRollupApiClients,
|
|
18301
18305
|
jsonRpcProvider: this.jsonRpcProvider,
|
|
18302
18306
|
});
|
|
18303
|
-
this.user = user;
|
|
18304
18307
|
this.magicProvider = magicProvider;
|
|
18305
18308
|
this.relayerClient = new RelayerClient({
|
|
18306
18309
|
config: this.config,
|
|
18307
18310
|
jsonRpcProvider: this.jsonRpcProvider,
|
|
18308
|
-
|
|
18311
|
+
authManager: this.authManager,
|
|
18309
18312
|
});
|
|
18310
18313
|
this.guardianClient = new GuardianClient({
|
|
18311
18314
|
confirmationScreen: this.confirmationScreen,
|
|
18312
18315
|
config: this.config,
|
|
18316
|
+
authManager: this.authManager,
|
|
18313
18317
|
});
|
|
18314
|
-
this.
|
|
18315
|
-
|
|
18318
|
+
this.zkevmAddress = user.zkEvm.ethAddress;
|
|
18319
|
+
this.eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, [user.zkEvm.ethAddress]);
|
|
18320
|
+
return [user.zkEvm.ethAddress];
|
|
18316
18321
|
}
|
|
18317
18322
|
case 'eth_sendTransaction': {
|
|
18318
18323
|
if (!this.isLoggedIn()) {
|
|
@@ -18324,11 +18329,11 @@ class ZkEvmProvider {
|
|
|
18324
18329
|
guardianClient: this.guardianClient,
|
|
18325
18330
|
jsonRpcProvider: this.jsonRpcProvider,
|
|
18326
18331
|
relayerClient: this.relayerClient,
|
|
18327
|
-
|
|
18332
|
+
zkevmAddress: this.zkevmAddress,
|
|
18328
18333
|
});
|
|
18329
18334
|
}
|
|
18330
18335
|
case 'eth_accounts': {
|
|
18331
|
-
return this.
|
|
18336
|
+
return this.zkevmAddress ? [this.zkevmAddress] : [];
|
|
18332
18337
|
}
|
|
18333
18338
|
case 'eth_signTypedData':
|
|
18334
18339
|
case 'eth_signTypedData_v4': {
|
|
@@ -18341,7 +18346,6 @@ class ZkEvmProvider {
|
|
|
18341
18346
|
magicProvider: this.magicProvider,
|
|
18342
18347
|
jsonRpcProvider: this.jsonRpcProvider,
|
|
18343
18348
|
relayerClient: this.relayerClient,
|
|
18344
|
-
user: this.user,
|
|
18345
18349
|
guardianClient: this.guardianClient,
|
|
18346
18350
|
});
|
|
18347
18351
|
}
|
|
@@ -37062,7 +37066,7 @@ const flattenProperties = (properties) => {
|
|
|
37062
37066
|
};
|
|
37063
37067
|
|
|
37064
37068
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
37065
|
-
const SDK_VERSION = '1.5.
|
|
37069
|
+
const SDK_VERSION = '1.5.2';
|
|
37066
37070
|
let initialised = false;
|
|
37067
37071
|
const isInitialised = () => initialised;
|
|
37068
37072
|
const getReferrer = () => {
|
|
@@ -39881,6 +39885,9 @@ const MIN_MAX_HOPS = 1;
|
|
|
39881
39885
|
const BASIS_POINT_PRECISION = 10000;
|
|
39882
39886
|
// 10% maximum secondary fee
|
|
39883
39887
|
const MAX_SECONDARY_FEE_BASIS_POINTS = 1000;
|
|
39888
|
+
// How much more gas does a swap with secondary fees cost?
|
|
39889
|
+
// This number is the average difference of a number of different swaps with different hop amounts, etc.
|
|
39890
|
+
const AVERAGE_SECONDARY_FEE_EXTRA_GAS = 50876;
|
|
39884
39891
|
|
|
39885
39892
|
const quoteReturnMapping = {
|
|
39886
39893
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
@@ -40301,6 +40308,59 @@ startTokenIn = tokenIn) => {
|
|
|
40301
40308
|
return routes;
|
|
40302
40309
|
};
|
|
40303
40310
|
|
|
40311
|
+
const IMMUTABLE_TESTNET_RPC_URL = 'https://rpc.testnet.immutable.com';
|
|
40312
|
+
const IMMUTABLE_TESTNET_CHAIN_ID = 13473;
|
|
40313
|
+
|
|
40314
|
+
const IMMUTABLE_MAINNET_RPC_URL = 'https://rpc.immutable.com';
|
|
40315
|
+
const IMMUTABLE_MAINNET_CHAIN_ID = 13371;
|
|
40316
|
+
|
|
40317
|
+
const NATIVE_IMX_IMMUTABLE_TESTNET = {
|
|
40318
|
+
chainId: IMMUTABLE_TESTNET_CHAIN_ID,
|
|
40319
|
+
decimals: 18,
|
|
40320
|
+
symbol: 'tIMX',
|
|
40321
|
+
name: 'Immutable Testnet Token',
|
|
40322
|
+
type: 'native',
|
|
40323
|
+
};
|
|
40324
|
+
const WIMX_IMMUTABLE_TESTNET = {
|
|
40325
|
+
chainId: IMMUTABLE_TESTNET_CHAIN_ID,
|
|
40326
|
+
address: '0x1CcCa691501174B4A623CeDA58cC8f1a76dc3439',
|
|
40327
|
+
decimals: 18,
|
|
40328
|
+
symbol: 'WIMX',
|
|
40329
|
+
name: 'Wrapped Immutable Testnet Token',
|
|
40330
|
+
type: 'erc20',
|
|
40331
|
+
};
|
|
40332
|
+
const IMMUTABLE_TESTNET_COMMON_ROUTING_TOKENS = [
|
|
40333
|
+
WIMX_IMMUTABLE_TESTNET,
|
|
40334
|
+
];
|
|
40335
|
+
|
|
40336
|
+
const NATIVE_IMX_IMMUTABLE_MAINNET = {
|
|
40337
|
+
chainId: IMMUTABLE_MAINNET_CHAIN_ID,
|
|
40338
|
+
decimals: 18,
|
|
40339
|
+
symbol: 'IMX',
|
|
40340
|
+
name: 'Immutable Token',
|
|
40341
|
+
type: 'native',
|
|
40342
|
+
};
|
|
40343
|
+
const WIMX_IMMUTABLE_MAINNET = {
|
|
40344
|
+
chainId: IMMUTABLE_MAINNET_CHAIN_ID,
|
|
40345
|
+
address: '0x3a0c2ba54d6cbd3121f01b96dfd20e99d1696c9d',
|
|
40346
|
+
decimals: 18,
|
|
40347
|
+
symbol: 'WIMX',
|
|
40348
|
+
name: 'Wrapped Immutable Token',
|
|
40349
|
+
type: 'erc20',
|
|
40350
|
+
};
|
|
40351
|
+
const ETH_IMMUTABLE_MAINNET = {
|
|
40352
|
+
chainId: IMMUTABLE_MAINNET_CHAIN_ID,
|
|
40353
|
+
address: '0x52a6c53869ce09a731cd772f245b97a4401d3348',
|
|
40354
|
+
decimals: 18,
|
|
40355
|
+
symbol: 'ETH',
|
|
40356
|
+
name: 'Ethereum',
|
|
40357
|
+
type: 'erc20',
|
|
40358
|
+
};
|
|
40359
|
+
const IMMUTABLE_MAINNET_COMMON_ROUTING_TOKENS = [
|
|
40360
|
+
WIMX_IMMUTABLE_MAINNET,
|
|
40361
|
+
ETH_IMMUTABLE_MAINNET,
|
|
40362
|
+
];
|
|
40363
|
+
|
|
40304
40364
|
const getFeeData = async (provider) => {
|
|
40305
40365
|
const [block, maxPriorityFeePerGas] = await Promise.all([
|
|
40306
40366
|
provider.getBlock('latest'),
|
|
@@ -40336,9 +40396,13 @@ const fetchGasPrice = async (provider, nativeToken) => {
|
|
|
40336
40396
|
* @param {BigNumber} gasEstimate - The total gas units that will be used for the transaction
|
|
40337
40397
|
* @returns - The cost of the transaction in the gas token's smallest denomination (e.g. WEI)
|
|
40338
40398
|
*/
|
|
40339
|
-
const calculateGasFee = (gasPrice, gasEstimate) =>
|
|
40340
|
-
|
|
40341
|
-
|
|
40399
|
+
const calculateGasFee = (hasSecondaryFees, gasPrice, gasEstimate) => {
|
|
40400
|
+
const baseGasFee = newAmount(gasEstimate.mul(gasPrice.value), gasPrice.token);
|
|
40401
|
+
if (!hasSecondaryFees)
|
|
40402
|
+
return baseGasFee;
|
|
40403
|
+
return newAmount(baseGasFee.value.add(gasPrice.value.mul(AVERAGE_SECONDARY_FEE_EXTRA_GAS)), gasPrice.token);
|
|
40404
|
+
// eslint-disable-next-line implicit-arrow-linebreak
|
|
40405
|
+
};
|
|
40342
40406
|
|
|
40343
40407
|
/**
|
|
40344
40408
|
* Check if the spender needs approval for the token
|
|
@@ -40425,7 +40489,7 @@ const getApproval = async (provider, ownerAddress, preparedApproval, gasPrice) =
|
|
|
40425
40489
|
return null;
|
|
40426
40490
|
}
|
|
40427
40491
|
const gasEstimate = await getApproveGasEstimate(provider, ownerAddress, preparedApproval.spender, preparedApproval.amount.token.address);
|
|
40428
|
-
const gasFeeEstimate = gasPrice ? calculateGasFee(gasPrice, gasEstimate) : null;
|
|
40492
|
+
const gasFeeEstimate = gasPrice ? calculateGasFee(false, gasPrice, gasEstimate) : null;
|
|
40429
40493
|
return {
|
|
40430
40494
|
transaction: approveTransaction,
|
|
40431
40495
|
gasFeeEstimate: gasFeeEstimate ? toPublicAmount(gasFeeEstimate) : null,
|
|
@@ -40574,59 +40638,6 @@ const IMX_WRAP_GAS_COST = 45038;
|
|
|
40574
40638
|
// to avoid an extra remote call.
|
|
40575
40639
|
const IMX_UNWRAP_GAS_COST = 35216;
|
|
40576
40640
|
|
|
40577
|
-
const IMMUTABLE_TESTNET_RPC_URL = 'https://rpc.testnet.immutable.com';
|
|
40578
|
-
const IMMUTABLE_TESTNET_CHAIN_ID = 13473;
|
|
40579
|
-
|
|
40580
|
-
const IMMUTABLE_MAINNET_RPC_URL = 'https://rpc.immutable.com';
|
|
40581
|
-
const IMMUTABLE_MAINNET_CHAIN_ID = 13371;
|
|
40582
|
-
|
|
40583
|
-
const NATIVE_IMX_IMMUTABLE_TESTNET = {
|
|
40584
|
-
chainId: IMMUTABLE_TESTNET_CHAIN_ID,
|
|
40585
|
-
decimals: 18,
|
|
40586
|
-
symbol: 'tIMX',
|
|
40587
|
-
name: 'Immutable Testnet Token',
|
|
40588
|
-
type: 'native',
|
|
40589
|
-
};
|
|
40590
|
-
const WIMX_IMMUTABLE_TESTNET = {
|
|
40591
|
-
chainId: IMMUTABLE_TESTNET_CHAIN_ID,
|
|
40592
|
-
address: '0x1CcCa691501174B4A623CeDA58cC8f1a76dc3439',
|
|
40593
|
-
decimals: 18,
|
|
40594
|
-
symbol: 'WIMX',
|
|
40595
|
-
name: 'Wrapped Immutable Testnet Token',
|
|
40596
|
-
type: 'erc20',
|
|
40597
|
-
};
|
|
40598
|
-
const IMMUTABLE_TESTNET_COMMON_ROUTING_TOKENS = [
|
|
40599
|
-
WIMX_IMMUTABLE_TESTNET,
|
|
40600
|
-
];
|
|
40601
|
-
|
|
40602
|
-
const NATIVE_IMX_IMMUTABLE_MAINNET = {
|
|
40603
|
-
chainId: IMMUTABLE_MAINNET_CHAIN_ID,
|
|
40604
|
-
decimals: 18,
|
|
40605
|
-
symbol: 'IMX',
|
|
40606
|
-
name: 'Immutable Token',
|
|
40607
|
-
type: 'native',
|
|
40608
|
-
};
|
|
40609
|
-
const WIMX_IMMUTABLE_MAINNET = {
|
|
40610
|
-
chainId: IMMUTABLE_MAINNET_CHAIN_ID,
|
|
40611
|
-
address: '0x3a0c2ba54d6cbd3121f01b96dfd20e99d1696c9d',
|
|
40612
|
-
decimals: 18,
|
|
40613
|
-
symbol: 'WIMX',
|
|
40614
|
-
name: 'Wrapped Immutable Token',
|
|
40615
|
-
type: 'erc20',
|
|
40616
|
-
};
|
|
40617
|
-
const ETH_IMMUTABLE_MAINNET = {
|
|
40618
|
-
chainId: IMMUTABLE_MAINNET_CHAIN_ID,
|
|
40619
|
-
address: '0x52a6c53869ce09a731cd772f245b97a4401d3348',
|
|
40620
|
-
decimals: 18,
|
|
40621
|
-
symbol: 'ETH',
|
|
40622
|
-
name: 'Ethereum',
|
|
40623
|
-
type: 'erc20',
|
|
40624
|
-
};
|
|
40625
|
-
const IMMUTABLE_MAINNET_COMMON_ROUTING_TOKENS = [
|
|
40626
|
-
WIMX_IMMUTABLE_MAINNET,
|
|
40627
|
-
ETH_IMMUTABLE_MAINNET,
|
|
40628
|
-
];
|
|
40629
|
-
|
|
40630
40641
|
const zeroNativeCurrencyValue = '0x00';
|
|
40631
40642
|
const multicallWithDeadlineFunctionSignature = 'multicall(uint256,bytes[])';
|
|
40632
40643
|
function buildSinglePoolSwap(tokenIn, tokenOut, recipient, trade, route, amountIn, amountOut, routerContract, paymentsContract) {
|
|
@@ -40867,8 +40878,8 @@ const getSwapRecipient = (tokenOut, fromAddress, routerContractAddress, secondar
|
|
|
40867
40878
|
function getSwap(tokenIn, tokenOut, adjustedQuote, fromAddress, slippage, deadline, routerContractAddress, secondaryFeesContractAddress, gasPrice, secondaryFees) {
|
|
40868
40879
|
const swapRecipient = getSwapRecipient(tokenOut, fromAddress, routerContractAddress, secondaryFeesContractAddress, secondaryFees);
|
|
40869
40880
|
const { calldata, maximumAmountIn } = createSwapParameters(tokenIn, tokenOut, adjustedQuote, swapRecipient, slippage, deadline, secondaryFees);
|
|
40870
|
-
|
|
40871
|
-
const gasFeeEstimate = gasPrice ? calculateGasFee(gasPrice, adjustedQuote.gasEstimate) : null;
|
|
40881
|
+
const hasSecondaryFees = secondaryFees.length > 0;
|
|
40882
|
+
const gasFeeEstimate = gasPrice ? calculateGasFee(hasSecondaryFees, gasPrice, adjustedQuote.gasEstimate) : null;
|
|
40872
40883
|
const transactionValue = getTransactionValue(tokenIn, maximumAmountIn);
|
|
40873
40884
|
return {
|
|
40874
40885
|
transaction: {
|
|
@@ -41090,7 +41101,7 @@ class Exchange {
|
|
|
41090
41101
|
async getUnwrapTransaction(fromAddress, tokenAmount, wimxInterface, gasPrice) {
|
|
41091
41102
|
const calldata = wimxInterface.encodeFunctionData('withdraw', [tokenAmount]);
|
|
41092
41103
|
const gasEstimate = ethers.ethers.BigNumber.from(IMX_UNWRAP_GAS_COST);
|
|
41093
|
-
const gasFeeEstimate = gasPrice ? toPublicAmount(calculateGasFee(gasPrice, gasEstimate)) : null;
|
|
41104
|
+
const gasFeeEstimate = gasPrice ? toPublicAmount(calculateGasFee(false, gasPrice, gasEstimate)) : null;
|
|
41094
41105
|
// This transaction is for calling calling `withdraw` on the WETH/WIMX contract.
|
|
41095
41106
|
const transactionDetails = {
|
|
41096
41107
|
transaction: {
|
|
@@ -41108,7 +41119,7 @@ class Exchange {
|
|
|
41108
41119
|
getWrapTransaction(fromAddress, tokenAmount, wimxInterface, gasPrice) {
|
|
41109
41120
|
const calldata = wimxInterface.encodeFunctionData('deposit');
|
|
41110
41121
|
const gasEstimate = ethers.ethers.BigNumber.from(IMX_WRAP_GAS_COST);
|
|
41111
|
-
const gasFeeEstimate = gasPrice ? toPublicAmount(calculateGasFee(gasPrice, gasEstimate)) : null;
|
|
41122
|
+
const gasFeeEstimate = gasPrice ? toPublicAmount(calculateGasFee(false, gasPrice, gasEstimate)) : null;
|
|
41112
41123
|
// This transaction is for calling calling `deposit` on the WETH/WIMX contract.
|
|
41113
41124
|
const transactionDetails = {
|
|
41114
41125
|
transaction: {
|
|
@@ -42170,7 +42181,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
|
|
|
42170
42181
|
maxPriorityFeePerGas: ethers.BigNumber.from(10e9),
|
|
42171
42182
|
};
|
|
42172
42183
|
|
|
42173
|
-
const SDK_VERSION_MARKER = '1.5.
|
|
42184
|
+
const SDK_VERSION_MARKER = '1.5.2';
|
|
42174
42185
|
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
42175
42186
|
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
42176
42187
|
|
|
@@ -45432,9 +45443,7 @@ const buy = async (config, provider, orders, overrides = {
|
|
|
45432
45443
|
};
|
|
45433
45444
|
};
|
|
45434
45445
|
|
|
45435
|
-
const
|
|
45436
|
-
waitFulfillmentSettlements: true,
|
|
45437
|
-
}) => {
|
|
45446
|
+
const cancelOnChain = async (config, orderbook, provider, orderIds, waitFulfillmentSettlements) => {
|
|
45438
45447
|
let unsignedCancelOrderTransaction;
|
|
45439
45448
|
if (orderIds.length === 0) {
|
|
45440
45449
|
throw new CheckoutError('No orderIds were provided to the orderIds array. Please provide at least one orderId.', CheckoutErrorType.CANCEL_ORDER_LISTING_ERROR);
|
|
@@ -45443,7 +45452,6 @@ const cancel = async (config, provider, orderIds, overrides = {
|
|
|
45443
45452
|
const orderId = orderIds[0];
|
|
45444
45453
|
try {
|
|
45445
45454
|
const offererAddress = await measureAsyncExecution(config, 'Time to get the address from the provider', provider.getSigner().getAddress());
|
|
45446
|
-
const orderbook = createOrderbookInstance(config);
|
|
45447
45455
|
const cancelOrderResponse = await measureAsyncExecution(config, 'Time to get the cancel order from the orderbook', orderbook.cancelOrdersOnChain([orderId], offererAddress));
|
|
45448
45456
|
unsignedCancelOrderTransaction = await cancelOrderResponse.cancellationAction.buildTransaction();
|
|
45449
45457
|
}
|
|
@@ -45453,7 +45461,7 @@ const cancel = async (config, provider, orderIds, overrides = {
|
|
|
45453
45461
|
error: err,
|
|
45454
45462
|
});
|
|
45455
45463
|
}
|
|
45456
|
-
if (
|
|
45464
|
+
if (waitFulfillmentSettlements) {
|
|
45457
45465
|
const result = await signFulfillmentTransactions(provider, [unsignedCancelOrderTransaction]);
|
|
45458
45466
|
if (result.type === SignTransactionStatusType.FAILED) {
|
|
45459
45467
|
return {
|
|
@@ -45481,6 +45489,56 @@ const cancel = async (config, provider, orderIds, overrides = {
|
|
|
45481
45489
|
transactions,
|
|
45482
45490
|
};
|
|
45483
45491
|
};
|
|
45492
|
+
const gaslessCancel = async (orderbook, provider, orderIds) => {
|
|
45493
|
+
try {
|
|
45494
|
+
const signer = provider.getSigner();
|
|
45495
|
+
const address = await signer.getAddress();
|
|
45496
|
+
const { signableAction } = await orderbook.prepareOrderCancellations(orderIds);
|
|
45497
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
45498
|
+
const signedMessage = await signer._signTypedData(signableAction.message.domain, signableAction.message.types, signableAction.message.value);
|
|
45499
|
+
const { result } = await orderbook.cancelOrders(orderIds, address, signedMessage);
|
|
45500
|
+
const successfulCancellations = [];
|
|
45501
|
+
const failedCancellations = [];
|
|
45502
|
+
const pendingCancellations = [];
|
|
45503
|
+
for (const success of result.successful_cancellations) {
|
|
45504
|
+
successfulCancellations.push({
|
|
45505
|
+
orderId: success,
|
|
45506
|
+
});
|
|
45507
|
+
}
|
|
45508
|
+
for (const failed of result.failed_cancellations) {
|
|
45509
|
+
failedCancellations.push({
|
|
45510
|
+
orderId: failed.order,
|
|
45511
|
+
reason: failed.reason_code,
|
|
45512
|
+
});
|
|
45513
|
+
}
|
|
45514
|
+
for (const pending of result.pending_cancellations) {
|
|
45515
|
+
pendingCancellations.push({
|
|
45516
|
+
orderId: pending,
|
|
45517
|
+
});
|
|
45518
|
+
}
|
|
45519
|
+
return {
|
|
45520
|
+
successfulCancellations,
|
|
45521
|
+
failedCancellations,
|
|
45522
|
+
pendingCancellations,
|
|
45523
|
+
};
|
|
45524
|
+
}
|
|
45525
|
+
catch (err) {
|
|
45526
|
+
throw new CheckoutError('An error occurred while cancelling the order listing', CheckoutErrorType.CANCEL_ORDER_LISTING_ERROR, {
|
|
45527
|
+
orderIds,
|
|
45528
|
+
error: err,
|
|
45529
|
+
});
|
|
45530
|
+
}
|
|
45531
|
+
};
|
|
45532
|
+
const cancel = async (config, provider, orderIds, overrides = {
|
|
45533
|
+
waitFulfillmentSettlements: true,
|
|
45534
|
+
useGaslessCancel: false,
|
|
45535
|
+
}) => {
|
|
45536
|
+
const orderbook = createOrderbookInstance(config);
|
|
45537
|
+
if (overrides.useGaslessCancel) {
|
|
45538
|
+
return await gaslessCancel(orderbook, provider, orderIds);
|
|
45539
|
+
}
|
|
45540
|
+
return await cancelOnChain(config, orderbook, provider, orderIds, overrides.waitFulfillmentSettlements ?? true);
|
|
45541
|
+
};
|
|
45484
45542
|
|
|
45485
45543
|
const getERC721Requirement = (id, contractAddress, spenderAddress) => ({
|
|
45486
45544
|
type: ItemType.ERC721,
|