@imtbl/sdk 1.5.0 → 1.5.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/blockchain_data.js +2 -2
- package/dist/browser/checkout/sdk.js +4 -4
- package/dist/browser/checkout/widgets.js +50 -50
- package/dist/checkout.d.ts +45 -5
- package/dist/checkout.js +56 -9
- 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 +98 -47
- package/dist/index.d.ts +52 -4
- package/dist/index.js +98 -47
- 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.1';
|
|
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.1' };
|
|
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.1',
|
|
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.1',
|
|
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.1';
|
|
37066
37070
|
let initialised = false;
|
|
37067
37071
|
const isInitialised = () => initialised;
|
|
37068
37072
|
const getReferrer = () => {
|
|
@@ -42170,7 +42174,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
|
|
|
42170
42174
|
maxPriorityFeePerGas: ethers.BigNumber.from(10e9),
|
|
42171
42175
|
};
|
|
42172
42176
|
|
|
42173
|
-
const SDK_VERSION_MARKER = '1.5.
|
|
42177
|
+
const SDK_VERSION_MARKER = '1.5.1';
|
|
42174
42178
|
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
42175
42179
|
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
42176
42180
|
|
|
@@ -45432,9 +45436,7 @@ const buy = async (config, provider, orders, overrides = {
|
|
|
45432
45436
|
};
|
|
45433
45437
|
};
|
|
45434
45438
|
|
|
45435
|
-
const
|
|
45436
|
-
waitFulfillmentSettlements: true,
|
|
45437
|
-
}) => {
|
|
45439
|
+
const cancelOnChain = async (config, orderbook, provider, orderIds, waitFulfillmentSettlements) => {
|
|
45438
45440
|
let unsignedCancelOrderTransaction;
|
|
45439
45441
|
if (orderIds.length === 0) {
|
|
45440
45442
|
throw new CheckoutError('No orderIds were provided to the orderIds array. Please provide at least one orderId.', CheckoutErrorType.CANCEL_ORDER_LISTING_ERROR);
|
|
@@ -45443,7 +45445,6 @@ const cancel = async (config, provider, orderIds, overrides = {
|
|
|
45443
45445
|
const orderId = orderIds[0];
|
|
45444
45446
|
try {
|
|
45445
45447
|
const offererAddress = await measureAsyncExecution(config, 'Time to get the address from the provider', provider.getSigner().getAddress());
|
|
45446
|
-
const orderbook = createOrderbookInstance(config);
|
|
45447
45448
|
const cancelOrderResponse = await measureAsyncExecution(config, 'Time to get the cancel order from the orderbook', orderbook.cancelOrdersOnChain([orderId], offererAddress));
|
|
45448
45449
|
unsignedCancelOrderTransaction = await cancelOrderResponse.cancellationAction.buildTransaction();
|
|
45449
45450
|
}
|
|
@@ -45453,7 +45454,7 @@ const cancel = async (config, provider, orderIds, overrides = {
|
|
|
45453
45454
|
error: err,
|
|
45454
45455
|
});
|
|
45455
45456
|
}
|
|
45456
|
-
if (
|
|
45457
|
+
if (waitFulfillmentSettlements) {
|
|
45457
45458
|
const result = await signFulfillmentTransactions(provider, [unsignedCancelOrderTransaction]);
|
|
45458
45459
|
if (result.type === SignTransactionStatusType.FAILED) {
|
|
45459
45460
|
return {
|
|
@@ -45481,6 +45482,56 @@ const cancel = async (config, provider, orderIds, overrides = {
|
|
|
45481
45482
|
transactions,
|
|
45482
45483
|
};
|
|
45483
45484
|
};
|
|
45485
|
+
const gaslessCancel = async (orderbook, provider, orderIds) => {
|
|
45486
|
+
try {
|
|
45487
|
+
const signer = provider.getSigner();
|
|
45488
|
+
const address = await signer.getAddress();
|
|
45489
|
+
const { signableAction } = await orderbook.prepareOrderCancellations(orderIds);
|
|
45490
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
45491
|
+
const signedMessage = await signer._signTypedData(signableAction.message.domain, signableAction.message.types, signableAction.message.value);
|
|
45492
|
+
const { result } = await orderbook.cancelOrders(orderIds, address, signedMessage);
|
|
45493
|
+
const successfulCancellations = [];
|
|
45494
|
+
const failedCancellations = [];
|
|
45495
|
+
const pendingCancellations = [];
|
|
45496
|
+
for (const success of result.successful_cancellations) {
|
|
45497
|
+
successfulCancellations.push({
|
|
45498
|
+
orderId: success,
|
|
45499
|
+
});
|
|
45500
|
+
}
|
|
45501
|
+
for (const failed of result.failed_cancellations) {
|
|
45502
|
+
failedCancellations.push({
|
|
45503
|
+
orderId: failed.order,
|
|
45504
|
+
reason: failed.reason_code,
|
|
45505
|
+
});
|
|
45506
|
+
}
|
|
45507
|
+
for (const pending of result.pending_cancellations) {
|
|
45508
|
+
pendingCancellations.push({
|
|
45509
|
+
orderId: pending,
|
|
45510
|
+
});
|
|
45511
|
+
}
|
|
45512
|
+
return {
|
|
45513
|
+
successfulCancellations,
|
|
45514
|
+
failedCancellations,
|
|
45515
|
+
pendingCancellations,
|
|
45516
|
+
};
|
|
45517
|
+
}
|
|
45518
|
+
catch (err) {
|
|
45519
|
+
throw new CheckoutError('An error occurred while cancelling the order listing', CheckoutErrorType.CANCEL_ORDER_LISTING_ERROR, {
|
|
45520
|
+
orderIds,
|
|
45521
|
+
error: err,
|
|
45522
|
+
});
|
|
45523
|
+
}
|
|
45524
|
+
};
|
|
45525
|
+
const cancel = async (config, provider, orderIds, overrides = {
|
|
45526
|
+
waitFulfillmentSettlements: true,
|
|
45527
|
+
useGaslessCancel: false,
|
|
45528
|
+
}) => {
|
|
45529
|
+
const orderbook = createOrderbookInstance(config);
|
|
45530
|
+
if (overrides.useGaslessCancel) {
|
|
45531
|
+
return await gaslessCancel(orderbook, provider, orderIds);
|
|
45532
|
+
}
|
|
45533
|
+
return await cancelOnChain(config, orderbook, provider, orderIds, overrides.waitFulfillmentSettlements ?? true);
|
|
45534
|
+
};
|
|
45484
45535
|
|
|
45485
45536
|
const getERC721Requirement = (id, contractAddress, spenderAddress) => ({
|
|
45486
45537
|
type: ItemType.ERC721,
|
package/dist/index.d.ts
CHANGED
|
@@ -30092,7 +30092,7 @@ type SellResultInsufficientFunds = {
|
|
|
30092
30092
|
/** The insufficient result of smart checkout */
|
|
30093
30093
|
smartCheckoutResult: SmartCheckoutInsufficient;
|
|
30094
30094
|
};
|
|
30095
|
-
type CancelResult = CancelResultSuccess | CancelResultFailed | CancelResultFulfillmentsUnsettled;
|
|
30095
|
+
type CancelResult = CancelResultSuccess | CancelResultFailed | CancelResultFulfillmentsUnsettled | CancelResultGasless;
|
|
30096
30096
|
/**
|
|
30097
30097
|
* Represents the result of {@link Checkout.cancel}
|
|
30098
30098
|
* @property {CheckoutStatus.SUCCESS} status
|
|
@@ -30121,18 +30121,58 @@ type CancelResultFailed = {
|
|
|
30121
30121
|
* @property {SendTransactionResult[]} transactions
|
|
30122
30122
|
*/
|
|
30123
30123
|
type CancelResultFulfillmentsUnsettled = {
|
|
30124
|
-
/** The status to indicate
|
|
30124
|
+
/** The status to indicate the fulfillments have not yet settled on chain. */
|
|
30125
30125
|
status: CheckoutStatus.FULFILLMENTS_UNSETTLED;
|
|
30126
30126
|
/** Array of transaction results */
|
|
30127
30127
|
transactions: TransactionResponse[];
|
|
30128
30128
|
};
|
|
30129
|
+
/**
|
|
30130
|
+
* Represents the result of {@link Checkout.cancel} when using gasless cancel
|
|
30131
|
+
* @property {SuccessfulGaslessCancellation[]} successfulCancellations
|
|
30132
|
+
* @property {FailedGaslessCancellation[]} failedCancellations
|
|
30133
|
+
* @property {PendingGaslessCancellation[]} pendingCancellations
|
|
30134
|
+
*/
|
|
30135
|
+
type CancelResultGasless = {
|
|
30136
|
+
successfulCancellations: SuccessfulGaslessCancellation[];
|
|
30137
|
+
failedCancellations: FailedGaslessCancellation[];
|
|
30138
|
+
pendingCancellations: PendingGaslessCancellation[];
|
|
30139
|
+
};
|
|
30140
|
+
/**
|
|
30141
|
+
* Represents a successful gasless cancellation
|
|
30142
|
+
* @property {string} orderId
|
|
30143
|
+
*/
|
|
30144
|
+
type SuccessfulGaslessCancellation = {
|
|
30145
|
+
/** The order id of the successful cancellation */
|
|
30146
|
+
orderId: string;
|
|
30147
|
+
};
|
|
30148
|
+
/**
|
|
30149
|
+
* Represents a failed gasless cancellation
|
|
30150
|
+
* @property {string} orderId
|
|
30151
|
+
* @property {string} reason
|
|
30152
|
+
*/
|
|
30153
|
+
type FailedGaslessCancellation = {
|
|
30154
|
+
/** The order id of the failed cancellation */
|
|
30155
|
+
orderId: string;
|
|
30156
|
+
/** The reason for failure */
|
|
30157
|
+
reason: string;
|
|
30158
|
+
};
|
|
30159
|
+
/**
|
|
30160
|
+
* Represents a pending gasless cancellation
|
|
30161
|
+
* @property {string} orderId
|
|
30162
|
+
*/
|
|
30163
|
+
type PendingGaslessCancellation = {
|
|
30164
|
+
/** The order id of the pending cancellation */
|
|
30165
|
+
orderId: string;
|
|
30166
|
+
};
|
|
30129
30167
|
/**
|
|
30130
30168
|
* Represents the overrides available for {@link Checkout.cancel}
|
|
30131
30169
|
* @property {boolean} waitFulfillmentSettlements
|
|
30132
30170
|
*/
|
|
30133
30171
|
type CancelOverrides = {
|
|
30134
|
-
/** If the
|
|
30172
|
+
/** If the cancel should wait for the fulfillment transactions to settle */
|
|
30135
30173
|
waitFulfillmentSettlements?: boolean;
|
|
30174
|
+
/** If the cancel should use the gasless option */
|
|
30175
|
+
useGaslessCancel?: boolean;
|
|
30136
30176
|
};
|
|
30137
30177
|
/**
|
|
30138
30178
|
* An enum representing the checkout status types
|
|
@@ -30151,7 +30191,7 @@ declare enum CheckoutStatus {
|
|
|
30151
30191
|
/**
|
|
30152
30192
|
* The type representing the order to buy
|
|
30153
30193
|
* @property {string} orderId
|
|
30154
|
-
* @property {
|
|
30194
|
+
* @property {OrderFee[]} takerFees
|
|
30155
30195
|
*/
|
|
30156
30196
|
type BuyOrder = {
|
|
30157
30197
|
/** the id of the order to buy */
|
|
@@ -32496,6 +32536,7 @@ type checkout_d_CancelParams = CancelParams;
|
|
|
32496
32536
|
type checkout_d_CancelResult = CancelResult;
|
|
32497
32537
|
type checkout_d_CancelResultFailed = CancelResultFailed;
|
|
32498
32538
|
type checkout_d_CancelResultFulfillmentsUnsettled = CancelResultFulfillmentsUnsettled;
|
|
32539
|
+
type checkout_d_CancelResultGasless = CancelResultGasless;
|
|
32499
32540
|
type checkout_d_CancelResultSuccess = CancelResultSuccess;
|
|
32500
32541
|
type checkout_d_ChainId = ChainId;
|
|
32501
32542
|
declare const checkout_d_ChainId: typeof ChainId;
|
|
@@ -32537,6 +32578,7 @@ type checkout_d_ERC721ItemRequirement = ERC721ItemRequirement;
|
|
|
32537
32578
|
type checkout_d_ErrorType = ErrorType;
|
|
32538
32579
|
type checkout_d_ExchangeType = ExchangeType;
|
|
32539
32580
|
declare const checkout_d_ExchangeType: typeof ExchangeType;
|
|
32581
|
+
type checkout_d_FailedGaslessCancellation = FailedGaslessCancellation;
|
|
32540
32582
|
type checkout_d_Fee = Fee;
|
|
32541
32583
|
type checkout_d_FeePercentage = FeePercentage;
|
|
32542
32584
|
type checkout_d_FeeToken = FeeToken;
|
|
@@ -32599,6 +32641,7 @@ type checkout_d_OrchestrationEventData = OrchestrationEventData;
|
|
|
32599
32641
|
type checkout_d_OrchestrationEventType = OrchestrationEventType;
|
|
32600
32642
|
declare const checkout_d_OrchestrationEventType: typeof OrchestrationEventType;
|
|
32601
32643
|
type checkout_d_OrderFee = OrderFee;
|
|
32644
|
+
type checkout_d_PendingGaslessCancellation = PendingGaslessCancellation;
|
|
32602
32645
|
type checkout_d_ProviderEvent<KEventName extends keyof ProviderEventMapping> = ProviderEvent<KEventName>;
|
|
32603
32646
|
type checkout_d_ProviderEventType = ProviderEventType;
|
|
32604
32647
|
declare const checkout_d_ProviderEventType: typeof ProviderEventType;
|
|
@@ -32639,6 +32682,7 @@ type checkout_d_SmartCheckoutParams = SmartCheckoutParams;
|
|
|
32639
32682
|
type checkout_d_SmartCheckoutResult = SmartCheckoutResult;
|
|
32640
32683
|
type checkout_d_SmartCheckoutRouter = SmartCheckoutRouter;
|
|
32641
32684
|
type checkout_d_SmartCheckoutSufficient = SmartCheckoutSufficient;
|
|
32685
|
+
type checkout_d_SuccessfulGaslessCancellation = SuccessfulGaslessCancellation;
|
|
32642
32686
|
type checkout_d_SwapEventType = SwapEventType;
|
|
32643
32687
|
declare const checkout_d_SwapEventType: typeof SwapEventType;
|
|
32644
32688
|
type checkout_d_SwapFailed = SwapFailed;
|
|
@@ -32711,6 +32755,7 @@ declare namespace checkout_d {
|
|
|
32711
32755
|
checkout_d_CancelResult as CancelResult,
|
|
32712
32756
|
checkout_d_CancelResultFailed as CancelResultFailed,
|
|
32713
32757
|
checkout_d_CancelResultFulfillmentsUnsettled as CancelResultFulfillmentsUnsettled,
|
|
32758
|
+
checkout_d_CancelResultGasless as CancelResultGasless,
|
|
32714
32759
|
checkout_d_CancelResultSuccess as CancelResultSuccess,
|
|
32715
32760
|
checkout_d_ChainId as ChainId,
|
|
32716
32761
|
checkout_d_ChainName as ChainName,
|
|
@@ -32742,6 +32787,7 @@ declare namespace checkout_d {
|
|
|
32742
32787
|
checkout_d_ERC721ItemRequirement as ERC721ItemRequirement,
|
|
32743
32788
|
checkout_d_ErrorType as ErrorType,
|
|
32744
32789
|
checkout_d_ExchangeType as ExchangeType,
|
|
32790
|
+
checkout_d_FailedGaslessCancellation as FailedGaslessCancellation,
|
|
32745
32791
|
checkout_d_Fee as Fee,
|
|
32746
32792
|
checkout_d_FeePercentage as FeePercentage,
|
|
32747
32793
|
checkout_d_FeeToken as FeeToken,
|
|
@@ -32795,6 +32841,7 @@ declare namespace checkout_d {
|
|
|
32795
32841
|
checkout_d_OrchestrationEventData as OrchestrationEventData,
|
|
32796
32842
|
checkout_d_OrchestrationEventType as OrchestrationEventType,
|
|
32797
32843
|
checkout_d_OrderFee as OrderFee,
|
|
32844
|
+
checkout_d_PendingGaslessCancellation as PendingGaslessCancellation,
|
|
32798
32845
|
checkout_d_ProviderEvent as ProviderEvent,
|
|
32799
32846
|
checkout_d_ProviderEventType as ProviderEventType,
|
|
32800
32847
|
checkout_d_ProviderUpdated as ProviderUpdated,
|
|
@@ -32831,6 +32878,7 @@ declare namespace checkout_d {
|
|
|
32831
32878
|
checkout_d_SmartCheckoutResult as SmartCheckoutResult,
|
|
32832
32879
|
checkout_d_SmartCheckoutRouter as SmartCheckoutRouter,
|
|
32833
32880
|
checkout_d_SmartCheckoutSufficient as SmartCheckoutSufficient,
|
|
32881
|
+
checkout_d_SuccessfulGaslessCancellation as SuccessfulGaslessCancellation,
|
|
32834
32882
|
checkout_d_SwapEventType as SwapEventType,
|
|
32835
32883
|
checkout_d_SwapFailed as SwapFailed,
|
|
32836
32884
|
checkout_d_SwapFundingStep as SwapFundingStep,
|