@imtbl/sdk 0.17.6 → 0.18.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 +1 -1
- package/dist/browser/checkout.js +2 -2
- package/dist/checkout_sdk.d.ts +29 -10
- package/dist/checkout_sdk.js +350 -59
- package/dist/checkout_widgets.d.ts +4 -5
- package/dist/checkout_widgets.js +17 -19
- package/dist/immutablex_client.js +1 -1
- package/dist/index.browser.js +15 -15
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +769 -107
- package/dist/index.d.ts +65 -14
- package/dist/index.js +771 -109
- package/dist/passport.d.ts +22 -1
- package/dist/passport.js +404 -31
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -24,6 +24,7 @@ var assert = require('assert');
|
|
|
24
24
|
var v3Sdk = require('@uniswap/v3-sdk');
|
|
25
25
|
var solidity = require('@ethersproject/solidity');
|
|
26
26
|
var routerSdk = require('@uniswap/router-sdk');
|
|
27
|
+
var utils$1 = require('ethers/lib/utils');
|
|
27
28
|
var jsxRuntime = require('react/jsx-runtime');
|
|
28
29
|
var react = require('react');
|
|
29
30
|
|
|
@@ -2724,7 +2725,7 @@ class MultiRollupApiClients {
|
|
|
2724
2725
|
}
|
|
2725
2726
|
|
|
2726
2727
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
2727
|
-
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.
|
|
2728
|
+
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.18.1' };
|
|
2728
2729
|
const createConfig = ({ basePath, headers, }) => {
|
|
2729
2730
|
if (!basePath.trim()) {
|
|
2730
2731
|
throw Error('basePath can not be empty');
|
|
@@ -2784,7 +2785,7 @@ class APIError extends Error {
|
|
|
2784
2785
|
|
|
2785
2786
|
/* eslint-disable implicit-arrow-linebreak */
|
|
2786
2787
|
const defaultHeaders = {
|
|
2787
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.
|
|
2788
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.18.1',
|
|
2788
2789
|
};
|
|
2789
2790
|
/**
|
|
2790
2791
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -3070,7 +3071,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
3070
3071
|
chainID,
|
|
3071
3072
|
coreContractAddress,
|
|
3072
3073
|
registrationContractAddress,
|
|
3073
|
-
sdkVersion: 'ts-immutable-sdk-0.
|
|
3074
|
+
sdkVersion: 'ts-immutable-sdk-0.18.1',
|
|
3074
3075
|
});
|
|
3075
3076
|
/**
|
|
3076
3077
|
* Sets `sdkVersion` at the time of build
|
|
@@ -6802,6 +6803,8 @@ var globalAxios = axios;
|
|
|
6802
6803
|
* https://openapi-generator.tech
|
|
6803
6804
|
* Do not edit the class manually.
|
|
6804
6805
|
*/
|
|
6806
|
+
// Some imports not used depending on template conditions
|
|
6807
|
+
// @ts-ignore
|
|
6805
6808
|
const BASE_PATH = "https://guardian.sandbox.imtbl.com".replace(/\/+$/, "");
|
|
6806
6809
|
/**
|
|
6807
6810
|
*
|
|
@@ -6829,10 +6832,10 @@ class BaseAPI {
|
|
|
6829
6832
|
*/
|
|
6830
6833
|
class RequiredError extends Error {
|
|
6831
6834
|
field;
|
|
6835
|
+
name = "RequiredError";
|
|
6832
6836
|
constructor(field, msg) {
|
|
6833
6837
|
super(msg);
|
|
6834
6838
|
this.field = field;
|
|
6835
|
-
this.name = "RequiredError";
|
|
6836
6839
|
}
|
|
6837
6840
|
}
|
|
6838
6841
|
|
|
@@ -6877,8 +6880,6 @@ const setBearerAuthToObject = async function (object, configuration) {
|
|
|
6877
6880
|
}
|
|
6878
6881
|
};
|
|
6879
6882
|
function setFlattenedQueryParams(urlSearchParams, parameter, key = "") {
|
|
6880
|
-
if (parameter == null)
|
|
6881
|
-
return;
|
|
6882
6883
|
if (typeof parameter === "object") {
|
|
6883
6884
|
if (Array.isArray(parameter)) {
|
|
6884
6885
|
parameter.forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
|
|
@@ -6936,6 +6937,208 @@ const createRequestFunction = function (axiosArgs, globalAxios, BASE_PATH, confi
|
|
|
6936
6937
|
};
|
|
6937
6938
|
};
|
|
6938
6939
|
|
|
6940
|
+
/* tslint:disable */
|
|
6941
|
+
/* eslint-disable */
|
|
6942
|
+
/**
|
|
6943
|
+
* Guardian
|
|
6944
|
+
* Guardian API
|
|
6945
|
+
*
|
|
6946
|
+
* The version of the OpenAPI document: 1.0.0
|
|
6947
|
+
* Contact: support@immutable.com
|
|
6948
|
+
*
|
|
6949
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
6950
|
+
* https://openapi-generator.tech
|
|
6951
|
+
* Do not edit the class manually.
|
|
6952
|
+
*/
|
|
6953
|
+
/**
|
|
6954
|
+
* MessagesApi - axios parameter creator
|
|
6955
|
+
* @export
|
|
6956
|
+
*/
|
|
6957
|
+
const MessagesApiAxiosParamCreator = function (configuration) {
|
|
6958
|
+
return {
|
|
6959
|
+
/**
|
|
6960
|
+
* Approve a pending evm message
|
|
6961
|
+
* @summary Approve a pending evm message
|
|
6962
|
+
* @param {string} messageID id for the message
|
|
6963
|
+
* @param {*} [options] Override http request option.
|
|
6964
|
+
* @throws {RequiredError}
|
|
6965
|
+
*/
|
|
6966
|
+
approvePendingMessage: async (messageID, options = {}) => {
|
|
6967
|
+
// verify required parameter 'messageID' is not null or undefined
|
|
6968
|
+
assertParamExists('approvePendingMessage', 'messageID', messageID);
|
|
6969
|
+
const localVarPath = `/guardian/v1/messages/{messageID}/approve`
|
|
6970
|
+
.replace(`{${"messageID"}}`, encodeURIComponent(String(messageID)));
|
|
6971
|
+
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
6972
|
+
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
6973
|
+
let baseOptions;
|
|
6974
|
+
if (configuration) {
|
|
6975
|
+
baseOptions = configuration.baseOptions;
|
|
6976
|
+
}
|
|
6977
|
+
const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
|
|
6978
|
+
const localVarHeaderParameter = {};
|
|
6979
|
+
const localVarQueryParameter = {};
|
|
6980
|
+
// authentication BearerAuth required
|
|
6981
|
+
// http bearer authentication required
|
|
6982
|
+
await setBearerAuthToObject(localVarHeaderParameter, configuration);
|
|
6983
|
+
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
6984
|
+
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
6985
|
+
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
6986
|
+
return {
|
|
6987
|
+
url: toPathString(localVarUrlObj),
|
|
6988
|
+
options: localVarRequestOptions,
|
|
6989
|
+
};
|
|
6990
|
+
},
|
|
6991
|
+
/**
|
|
6992
|
+
* Check if a given message is valid for EVM
|
|
6993
|
+
* @summary Evaluate an evm message to sign
|
|
6994
|
+
* @param {MessageEvaluationRequest} messageEvaluationRequest Specifies the kind of transaction
|
|
6995
|
+
* @param {*} [options] Override http request option.
|
|
6996
|
+
* @throws {RequiredError}
|
|
6997
|
+
*/
|
|
6998
|
+
evaluateMessage: async (messageEvaluationRequest, options = {}) => {
|
|
6999
|
+
// verify required parameter 'messageEvaluationRequest' is not null or undefined
|
|
7000
|
+
assertParamExists('evaluateMessage', 'messageEvaluationRequest', messageEvaluationRequest);
|
|
7001
|
+
const localVarPath = `/guardian/v1/messages/evaluate`;
|
|
7002
|
+
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
7003
|
+
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
7004
|
+
let baseOptions;
|
|
7005
|
+
if (configuration) {
|
|
7006
|
+
baseOptions = configuration.baseOptions;
|
|
7007
|
+
}
|
|
7008
|
+
const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
|
|
7009
|
+
const localVarHeaderParameter = {};
|
|
7010
|
+
const localVarQueryParameter = {};
|
|
7011
|
+
// authentication BearerAuth required
|
|
7012
|
+
// http bearer authentication required
|
|
7013
|
+
await setBearerAuthToObject(localVarHeaderParameter, configuration);
|
|
7014
|
+
localVarHeaderParameter['Content-Type'] = 'application/json';
|
|
7015
|
+
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
7016
|
+
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
7017
|
+
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
7018
|
+
localVarRequestOptions.data = serializeDataIfNeeded(messageEvaluationRequest, localVarRequestOptions, configuration);
|
|
7019
|
+
return {
|
|
7020
|
+
url: toPathString(localVarUrlObj),
|
|
7021
|
+
options: localVarRequestOptions,
|
|
7022
|
+
};
|
|
7023
|
+
},
|
|
7024
|
+
/**
|
|
7025
|
+
* Get an evm message by id
|
|
7026
|
+
* @summary Info for a specific evm message
|
|
7027
|
+
* @param {string} messageID The id of the evm message
|
|
7028
|
+
* @param {*} [options] Override http request option.
|
|
7029
|
+
* @throws {RequiredError}
|
|
7030
|
+
*/
|
|
7031
|
+
getMessageByID: async (messageID, options = {}) => {
|
|
7032
|
+
// verify required parameter 'messageID' is not null or undefined
|
|
7033
|
+
assertParamExists('getMessageByID', 'messageID', messageID);
|
|
7034
|
+
const localVarPath = `/guardian/v1/messages/{messageID}`
|
|
7035
|
+
.replace(`{${"messageID"}}`, encodeURIComponent(String(messageID)));
|
|
7036
|
+
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
7037
|
+
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
7038
|
+
let baseOptions;
|
|
7039
|
+
if (configuration) {
|
|
7040
|
+
baseOptions = configuration.baseOptions;
|
|
7041
|
+
}
|
|
7042
|
+
const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options };
|
|
7043
|
+
const localVarHeaderParameter = {};
|
|
7044
|
+
const localVarQueryParameter = {};
|
|
7045
|
+
// authentication BearerAuth required
|
|
7046
|
+
// http bearer authentication required
|
|
7047
|
+
await setBearerAuthToObject(localVarHeaderParameter, configuration);
|
|
7048
|
+
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
7049
|
+
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
7050
|
+
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
7051
|
+
return {
|
|
7052
|
+
url: toPathString(localVarUrlObj),
|
|
7053
|
+
options: localVarRequestOptions,
|
|
7054
|
+
};
|
|
7055
|
+
},
|
|
7056
|
+
};
|
|
7057
|
+
};
|
|
7058
|
+
/**
|
|
7059
|
+
* MessagesApi - functional programming interface
|
|
7060
|
+
* @export
|
|
7061
|
+
*/
|
|
7062
|
+
const MessagesApiFp = function (configuration) {
|
|
7063
|
+
const localVarAxiosParamCreator = MessagesApiAxiosParamCreator(configuration);
|
|
7064
|
+
return {
|
|
7065
|
+
/**
|
|
7066
|
+
* Approve a pending evm message
|
|
7067
|
+
* @summary Approve a pending evm message
|
|
7068
|
+
* @param {string} messageID id for the message
|
|
7069
|
+
* @param {*} [options] Override http request option.
|
|
7070
|
+
* @throws {RequiredError}
|
|
7071
|
+
*/
|
|
7072
|
+
async approvePendingMessage(messageID, options) {
|
|
7073
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.approvePendingMessage(messageID, options);
|
|
7074
|
+
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
7075
|
+
},
|
|
7076
|
+
/**
|
|
7077
|
+
* Check if a given message is valid for EVM
|
|
7078
|
+
* @summary Evaluate an evm message to sign
|
|
7079
|
+
* @param {MessageEvaluationRequest} messageEvaluationRequest Specifies the kind of transaction
|
|
7080
|
+
* @param {*} [options] Override http request option.
|
|
7081
|
+
* @throws {RequiredError}
|
|
7082
|
+
*/
|
|
7083
|
+
async evaluateMessage(messageEvaluationRequest, options) {
|
|
7084
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.evaluateMessage(messageEvaluationRequest, options);
|
|
7085
|
+
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
7086
|
+
},
|
|
7087
|
+
/**
|
|
7088
|
+
* Get an evm message by id
|
|
7089
|
+
* @summary Info for a specific evm message
|
|
7090
|
+
* @param {string} messageID The id of the evm message
|
|
7091
|
+
* @param {*} [options] Override http request option.
|
|
7092
|
+
* @throws {RequiredError}
|
|
7093
|
+
*/
|
|
7094
|
+
async getMessageByID(messageID, options) {
|
|
7095
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.getMessageByID(messageID, options);
|
|
7096
|
+
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
7097
|
+
},
|
|
7098
|
+
};
|
|
7099
|
+
};
|
|
7100
|
+
/**
|
|
7101
|
+
* MessagesApi - object-oriented interface
|
|
7102
|
+
* @export
|
|
7103
|
+
* @class MessagesApi
|
|
7104
|
+
* @extends {BaseAPI}
|
|
7105
|
+
*/
|
|
7106
|
+
class MessagesApi extends BaseAPI {
|
|
7107
|
+
/**
|
|
7108
|
+
* Approve a pending evm message
|
|
7109
|
+
* @summary Approve a pending evm message
|
|
7110
|
+
* @param {MessagesApiApprovePendingMessageRequest} requestParameters Request parameters.
|
|
7111
|
+
* @param {*} [options] Override http request option.
|
|
7112
|
+
* @throws {RequiredError}
|
|
7113
|
+
* @memberof MessagesApi
|
|
7114
|
+
*/
|
|
7115
|
+
approvePendingMessage(requestParameters, options) {
|
|
7116
|
+
return MessagesApiFp(this.configuration).approvePendingMessage(requestParameters.messageID, options).then((request) => request(this.axios, this.basePath));
|
|
7117
|
+
}
|
|
7118
|
+
/**
|
|
7119
|
+
* Check if a given message is valid for EVM
|
|
7120
|
+
* @summary Evaluate an evm message to sign
|
|
7121
|
+
* @param {MessagesApiEvaluateMessageRequest} requestParameters Request parameters.
|
|
7122
|
+
* @param {*} [options] Override http request option.
|
|
7123
|
+
* @throws {RequiredError}
|
|
7124
|
+
* @memberof MessagesApi
|
|
7125
|
+
*/
|
|
7126
|
+
evaluateMessage(requestParameters, options) {
|
|
7127
|
+
return MessagesApiFp(this.configuration).evaluateMessage(requestParameters.messageEvaluationRequest, options).then((request) => request(this.axios, this.basePath));
|
|
7128
|
+
}
|
|
7129
|
+
/**
|
|
7130
|
+
* Get an evm message by id
|
|
7131
|
+
* @summary Info for a specific evm message
|
|
7132
|
+
* @param {MessagesApiGetMessageByIDRequest} requestParameters Request parameters.
|
|
7133
|
+
* @param {*} [options] Override http request option.
|
|
7134
|
+
* @throws {RequiredError}
|
|
7135
|
+
* @memberof MessagesApi
|
|
7136
|
+
*/
|
|
7137
|
+
getMessageByID(requestParameters, options) {
|
|
7138
|
+
return MessagesApiFp(this.configuration).getMessageByID(requestParameters.messageID, options).then((request) => request(this.axios, this.basePath));
|
|
7139
|
+
}
|
|
7140
|
+
}
|
|
7141
|
+
|
|
6939
7142
|
/* tslint:disable */
|
|
6940
7143
|
/* eslint-disable */
|
|
6941
7144
|
/**
|
|
@@ -6959,7 +7162,7 @@ const TransactionsApiAxiosParamCreator = function (configuration) {
|
|
|
6959
7162
|
* Approve a pending transaction
|
|
6960
7163
|
* @summary Approve a pending transaction given chain
|
|
6961
7164
|
* @param {string} payloadHash Hash for the payload
|
|
6962
|
-
* @param {TransactionApprovalRequest} transactionApprovalRequest request body for approving a pending
|
|
7165
|
+
* @param {TransactionApprovalRequest} transactionApprovalRequest request body for approving a pending transaction
|
|
6963
7166
|
* @param {*} [options] Override http request option.
|
|
6964
7167
|
* @throws {RequiredError}
|
|
6965
7168
|
*/
|
|
@@ -7084,7 +7287,7 @@ const TransactionsApiFp = function (configuration) {
|
|
|
7084
7287
|
* Approve a pending transaction
|
|
7085
7288
|
* @summary Approve a pending transaction given chain
|
|
7086
7289
|
* @param {string} payloadHash Hash for the payload
|
|
7087
|
-
* @param {TransactionApprovalRequest} transactionApprovalRequest request body for approving a pending
|
|
7290
|
+
* @param {TransactionApprovalRequest} transactionApprovalRequest request body for approving a pending transaction
|
|
7088
7291
|
* @param {*} [options] Override http request option.
|
|
7089
7292
|
* @throws {RequiredError}
|
|
7090
7293
|
*/
|
|
@@ -7451,6 +7654,7 @@ const getAuthConfiguration = ({ oidcConfiguration, authenticationDomain, }) => {
|
|
|
7451
7654
|
mergeClaims: true,
|
|
7452
7655
|
loadUserInfo: true,
|
|
7453
7656
|
scope: oidcConfiguration.scope,
|
|
7657
|
+
userStore: new oidcClientTs.WebStorageStateStore({ store: window.localStorage }),
|
|
7454
7658
|
};
|
|
7455
7659
|
if (oidcConfiguration.audience) {
|
|
7456
7660
|
baseConfiguration.extraQueryParams = {
|
|
@@ -7850,18 +8054,18 @@ const transformGuardianTransactions = (txs) => {
|
|
|
7850
8054
|
};
|
|
7851
8055
|
class GuardianClient {
|
|
7852
8056
|
transactionAPI;
|
|
8057
|
+
messageAPI;
|
|
7853
8058
|
confirmationScreen;
|
|
7854
8059
|
// TODO: ID-977, make this rollup agnostic
|
|
7855
8060
|
imxEtherAddress;
|
|
7856
8061
|
crossSdkBridgeEnabled;
|
|
7857
8062
|
constructor({ accessToken, confirmationScreen, imxEtherAddress, config, }) {
|
|
8063
|
+
const guardianConfiguration = new Configuration({ accessToken, basePath: config.imxPublicApiDomain });
|
|
7858
8064
|
this.confirmationScreen = confirmationScreen;
|
|
7859
|
-
this.transactionAPI = new TransactionsApi(new Configuration(
|
|
7860
|
-
accessToken,
|
|
7861
|
-
basePath: config.imxPublicApiDomain,
|
|
7862
|
-
}));
|
|
8065
|
+
this.transactionAPI = new TransactionsApi(new Configuration(guardianConfiguration));
|
|
7863
8066
|
this.imxEtherAddress = imxEtherAddress;
|
|
7864
8067
|
this.crossSdkBridgeEnabled = config.crossSdkBridgeEnabled;
|
|
8068
|
+
this.messageAPI = new MessagesApi(guardianConfiguration);
|
|
7865
8069
|
}
|
|
7866
8070
|
/**
|
|
7867
8071
|
* Open confirmation screen and close it automatically if the
|
|
@@ -7960,6 +8164,31 @@ class GuardianClient {
|
|
|
7960
8164
|
this.confirmationScreen.closeWindow();
|
|
7961
8165
|
}
|
|
7962
8166
|
}
|
|
8167
|
+
async evaluateMessage({ chainID, payload, user }) {
|
|
8168
|
+
try {
|
|
8169
|
+
const messageEvalResponse = await this.messageAPI.evaluateMessage({ messageEvaluationRequest: { chainID, payload } }, { headers: { Authorization: `Bearer ${user.accessToken}` } });
|
|
8170
|
+
return messageEvalResponse.data;
|
|
8171
|
+
}
|
|
8172
|
+
catch (error) {
|
|
8173
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
8174
|
+
throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Message failed to validate with error: ${errorMessage}`);
|
|
8175
|
+
}
|
|
8176
|
+
}
|
|
8177
|
+
async validateMessage({ chainID, payload, user }) {
|
|
8178
|
+
const { messageId, confirmationRequired } = await this.evaluateMessage({ chainID, payload, user });
|
|
8179
|
+
if (confirmationRequired && this.crossSdkBridgeEnabled) {
|
|
8180
|
+
throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
|
|
8181
|
+
}
|
|
8182
|
+
if (confirmationRequired && !!messageId) {
|
|
8183
|
+
const confirmationResult = await this.confirmationScreen.requestMessageConfirmation(messageId);
|
|
8184
|
+
if (!confirmationResult.confirmed) {
|
|
8185
|
+
throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Signature rejected by user');
|
|
8186
|
+
}
|
|
8187
|
+
}
|
|
8188
|
+
else {
|
|
8189
|
+
this.confirmationScreen.closeWindow();
|
|
8190
|
+
}
|
|
8191
|
+
}
|
|
7963
8192
|
}
|
|
7964
8193
|
|
|
7965
8194
|
var PassportEvents;
|
|
@@ -8587,6 +8816,8 @@ var ReceiveMessage;
|
|
|
8587
8816
|
ReceiveMessage["CONFIRMATION_WINDOW_READY"] = "confirmation_window_ready";
|
|
8588
8817
|
ReceiveMessage["TRANSACTION_CONFIRMED"] = "transaction_confirmed";
|
|
8589
8818
|
ReceiveMessage["TRANSACTION_ERROR"] = "transaction_error";
|
|
8819
|
+
ReceiveMessage["MESSAGE_CONFIRMED"] = "message_confirmed";
|
|
8820
|
+
ReceiveMessage["MESSAGE_REJECTED"] = "message_rejected";
|
|
8590
8821
|
})(ReceiveMessage || (ReceiveMessage = {}));
|
|
8591
8822
|
const PASSPORT_EVENT_TYPE = 'imx_passport_confirmation';
|
|
8592
8823
|
|
|
@@ -8640,11 +8871,11 @@ class ConfirmationScreen {
|
|
|
8640
8871
|
reject(new Error('Unsupported message type'));
|
|
8641
8872
|
}
|
|
8642
8873
|
};
|
|
8643
|
-
window.addEventListener('message', messageHandler);
|
|
8644
8874
|
if (!this.confirmationWindow) {
|
|
8645
8875
|
resolve({ confirmed: false });
|
|
8646
8876
|
return;
|
|
8647
8877
|
}
|
|
8878
|
+
window.addEventListener('message', messageHandler);
|
|
8648
8879
|
let href = '';
|
|
8649
8880
|
if (chainType === TransactionApprovalRequestChainTypeEnum.Starkex) {
|
|
8650
8881
|
// eslint-disable-next-line max-len
|
|
@@ -8654,15 +8885,39 @@ class ConfirmationScreen {
|
|
|
8654
8885
|
// eslint-disable-next-line max-len
|
|
8655
8886
|
href = `${this.config.passportDomain}/transaction-confirmation/zkevm?transactionId=${transactionId}&imxEtherAddress=${imxEtherAddress}&chainType=evm&chainId=${chainId}`;
|
|
8656
8887
|
}
|
|
8657
|
-
this.
|
|
8658
|
-
|
|
8659
|
-
|
|
8660
|
-
|
|
8661
|
-
|
|
8662
|
-
|
|
8663
|
-
|
|
8888
|
+
this.showConfirmationScreen(href, messageHandler, resolve);
|
|
8889
|
+
});
|
|
8890
|
+
}
|
|
8891
|
+
requestMessageConfirmation(messageId) {
|
|
8892
|
+
return new Promise((resolve, reject) => {
|
|
8893
|
+
const messageHandler = ({ data, origin }) => {
|
|
8894
|
+
if (origin !== this.config.passportDomain
|
|
8895
|
+
|| data.eventType !== PASSPORT_EVENT_TYPE) {
|
|
8896
|
+
return;
|
|
8897
|
+
}
|
|
8898
|
+
switch (data.messageType) {
|
|
8899
|
+
case ReceiveMessage.CONFIRMATION_WINDOW_READY: {
|
|
8900
|
+
break;
|
|
8901
|
+
}
|
|
8902
|
+
case ReceiveMessage.MESSAGE_CONFIRMED: {
|
|
8903
|
+
resolve({ confirmed: true });
|
|
8904
|
+
break;
|
|
8905
|
+
}
|
|
8906
|
+
case ReceiveMessage.MESSAGE_REJECTED: {
|
|
8907
|
+
reject(new Error('Message rejected'));
|
|
8908
|
+
break;
|
|
8909
|
+
}
|
|
8910
|
+
default:
|
|
8911
|
+
reject(new Error('Unsupported message type'));
|
|
8664
8912
|
}
|
|
8665
|
-
}
|
|
8913
|
+
};
|
|
8914
|
+
if (!this.confirmationWindow) {
|
|
8915
|
+
resolve({ confirmed: false });
|
|
8916
|
+
return;
|
|
8917
|
+
}
|
|
8918
|
+
window.addEventListener('message', messageHandler);
|
|
8919
|
+
const href = `${this.config.passportDomain}/transaction-confirmation/zkevm/message?messageID=${messageId}`;
|
|
8920
|
+
this.showConfirmationScreen(href, messageHandler, resolve);
|
|
8666
8921
|
});
|
|
8667
8922
|
}
|
|
8668
8923
|
loading(popupOptions) {
|
|
@@ -8680,6 +8935,17 @@ class ConfirmationScreen {
|
|
|
8680
8935
|
closeWindow() {
|
|
8681
8936
|
this.confirmationWindow?.close();
|
|
8682
8937
|
}
|
|
8938
|
+
showConfirmationScreen(href, messageHandler, resolve) {
|
|
8939
|
+
this.confirmationWindow.location.href = href;
|
|
8940
|
+
// https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
|
|
8941
|
+
const timer = setInterval(() => {
|
|
8942
|
+
if (this.confirmationWindow?.closed) {
|
|
8943
|
+
clearInterval(timer);
|
|
8944
|
+
window.removeEventListener('message', messageHandler);
|
|
8945
|
+
resolve({ confirmed: false });
|
|
8946
|
+
}
|
|
8947
|
+
}, CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION);
|
|
8948
|
+
}
|
|
8683
8949
|
}
|
|
8684
8950
|
|
|
8685
8951
|
var RelayerTransactionStatus;
|
|
@@ -8708,13 +8974,9 @@ class TypedEventEmitter {
|
|
|
8708
8974
|
}
|
|
8709
8975
|
}
|
|
8710
8976
|
|
|
8711
|
-
|
|
8712
|
-
//
|
|
8713
|
-
//
|
|
8714
|
-
// Weight of a single signature in the multisig
|
|
8715
|
-
const SIGNATURE_WEIGHT = 1;
|
|
8716
|
-
// Total required weight in the multisig
|
|
8717
|
-
const SIGNATURE_THRESHOLD = 1;
|
|
8977
|
+
const SIGNATURE_WEIGHT = 1; // Weight of a single signature in the multi-sig
|
|
8978
|
+
const TRANSACTION_SIGNATURE_THRESHOLD = 1; // Total required weight in the multi-sig for a transaction
|
|
8979
|
+
const EIP712_SIGNATURE_THRESHOLD = 2; // Total required weight in the multi-sig for data signing
|
|
8718
8980
|
const ETH_SIGN_FLAG = '02';
|
|
8719
8981
|
const ETH_SIGN_PREFIX = '\x19\x01';
|
|
8720
8982
|
const META_TRANSACTIONS_TYPE = `tuple(
|
|
@@ -8747,11 +9009,12 @@ const getNonce = async (jsonRpcProvider, smartContractWalletAddress) => {
|
|
|
8747
9009
|
}
|
|
8748
9010
|
return 0;
|
|
8749
9011
|
};
|
|
9012
|
+
const encodeMessageSubDigest = (chainId, walletAddress, digest) => (ethers.ethers.utils.solidityPack(['string', 'uint256', 'address', 'bytes32'], [ETH_SIGN_PREFIX, chainId, walletAddress, digest]));
|
|
8750
9013
|
const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walletAddress, signer) => {
|
|
8751
9014
|
const normalisedMetaTransactions = getNormalisedTransactions(metaTransactions);
|
|
8752
9015
|
// Get the hash
|
|
8753
9016
|
const digest = digestOfTransactionsAndNonce(nonce, normalisedMetaTransactions);
|
|
8754
|
-
const completePayload =
|
|
9017
|
+
const completePayload = encodeMessageSubDigest(chainId, walletAddress, digest);
|
|
8755
9018
|
const hash = ethers.ethers.utils.keccak256(completePayload);
|
|
8756
9019
|
// Sign the digest
|
|
8757
9020
|
const hashArray = ethers.ethers.utils.arrayify(hash);
|
|
@@ -8759,7 +9022,7 @@ const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walle
|
|
|
8759
9022
|
const signedDigest = `${ethsigNoType}${ETH_SIGN_FLAG}`;
|
|
8760
9023
|
// Add metadata
|
|
8761
9024
|
const encodedSignature = config$1.encodeSignature({
|
|
8762
|
-
threshold:
|
|
9025
|
+
threshold: TRANSACTION_SIGNATURE_THRESHOLD,
|
|
8763
9026
|
signers: [
|
|
8764
9027
|
{
|
|
8765
9028
|
weight: SIGNATURE_WEIGHT,
|
|
@@ -8775,6 +9038,35 @@ const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walle
|
|
|
8775
9038
|
encodedSignature,
|
|
8776
9039
|
]);
|
|
8777
9040
|
};
|
|
9041
|
+
const decodeRelayerTypedDataSignature = (relayerSignature) => {
|
|
9042
|
+
const signatureWithThreshold = `0000${relayerSignature}`;
|
|
9043
|
+
return config$1.decodeSignature(signatureWithThreshold);
|
|
9044
|
+
};
|
|
9045
|
+
const getSignedTypedData = async (typedData, relayerSignature, chainId, walletAddress, signer) => {
|
|
9046
|
+
// Ethers auto-generates the EIP712Domain type in the TypedDataEncoder, and so it needs to be removed
|
|
9047
|
+
const types = { ...typedData.types };
|
|
9048
|
+
// @ts-ignore
|
|
9049
|
+
delete types.EIP712Domain;
|
|
9050
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
9051
|
+
const digest = ethers.ethers.utils._TypedDataEncoder.hash(typedData.domain, types, typedData.message);
|
|
9052
|
+
const completePayload = encodeMessageSubDigest(chainId, walletAddress, digest);
|
|
9053
|
+
const hash = ethers.ethers.utils.keccak256(completePayload);
|
|
9054
|
+
// Sign the digest
|
|
9055
|
+
const hashArray = ethers.ethers.utils.arrayify(hash);
|
|
9056
|
+
const ethsigNoType = await signer.signMessage(hashArray);
|
|
9057
|
+
const signedDigest = `${ethsigNoType}${ETH_SIGN_FLAG}`;
|
|
9058
|
+
const { signers } = decodeRelayerTypedDataSignature(relayerSignature);
|
|
9059
|
+
return config$1.encodeSignature({
|
|
9060
|
+
threshold: EIP712_SIGNATURE_THRESHOLD,
|
|
9061
|
+
signers: [
|
|
9062
|
+
...signers,
|
|
9063
|
+
{
|
|
9064
|
+
weight: SIGNATURE_WEIGHT,
|
|
9065
|
+
signature: signedDigest,
|
|
9066
|
+
},
|
|
9067
|
+
],
|
|
9068
|
+
});
|
|
9069
|
+
};
|
|
8778
9070
|
const getEip155ChainId = (chainId) => `eip155:${chainId}`;
|
|
8779
9071
|
|
|
8780
9072
|
class RelayerClient {
|
|
@@ -8840,6 +9132,19 @@ class RelayerClient {
|
|
|
8840
9132
|
const { result } = await this.postToRelayer(payload);
|
|
8841
9133
|
return result;
|
|
8842
9134
|
}
|
|
9135
|
+
async imSignTypedData(address, eip712Payload) {
|
|
9136
|
+
const { chainId } = await this.jsonRpcProvider.ready;
|
|
9137
|
+
const payload = {
|
|
9138
|
+
method: 'im_signTypedData',
|
|
9139
|
+
params: [{
|
|
9140
|
+
address,
|
|
9141
|
+
eip712Payload,
|
|
9142
|
+
chainId: getEip155ChainId(chainId),
|
|
9143
|
+
}],
|
|
9144
|
+
};
|
|
9145
|
+
const { result } = await this.postToRelayer(payload);
|
|
9146
|
+
return result;
|
|
9147
|
+
}
|
|
8843
9148
|
}
|
|
8844
9149
|
|
|
8845
9150
|
const MESSAGE_TO_SIGN = 'Only sign this message from Immutable Passport';
|
|
@@ -8980,6 +9285,60 @@ const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient
|
|
|
8980
9285
|
return relayerTransaction.hash;
|
|
8981
9286
|
});
|
|
8982
9287
|
|
|
9288
|
+
const REQUIRED_TYPED_DATA_PROPERTIES = ['types', 'domain', 'primaryType', 'message'];
|
|
9289
|
+
const isValidTypedDataPayload = (typedData) => (REQUIRED_TYPED_DATA_PROPERTIES.every((key) => key in typedData));
|
|
9290
|
+
const transformTypedData = (typedData, chainId) => {
|
|
9291
|
+
let transformedTypedData;
|
|
9292
|
+
if (typeof typedData === 'string') {
|
|
9293
|
+
try {
|
|
9294
|
+
transformedTypedData = JSON.parse(typedData);
|
|
9295
|
+
}
|
|
9296
|
+
catch (err) {
|
|
9297
|
+
throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `Failed to parse typed data JSON: ${err}`);
|
|
9298
|
+
}
|
|
9299
|
+
}
|
|
9300
|
+
else if (typeof typedData === 'object') {
|
|
9301
|
+
transformedTypedData = typedData;
|
|
9302
|
+
}
|
|
9303
|
+
else {
|
|
9304
|
+
throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `Invalid typed data argument: ${typedData}`);
|
|
9305
|
+
}
|
|
9306
|
+
if (!isValidTypedDataPayload(transformedTypedData)) {
|
|
9307
|
+
throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `Invalid typed data argument. The following properties are required: ${REQUIRED_TYPED_DATA_PROPERTIES.join(', ')}`);
|
|
9308
|
+
}
|
|
9309
|
+
const providedChainId = transformedTypedData.domain?.chainId;
|
|
9310
|
+
if (providedChainId) {
|
|
9311
|
+
// domain.chainId (if defined) can be a number, string, or hex value, but the relayer & guardian only accept a number.
|
|
9312
|
+
if (typeof providedChainId === 'string') {
|
|
9313
|
+
if (providedChainId.startsWith('0x')) {
|
|
9314
|
+
transformedTypedData.domain.chainId = parseInt(providedChainId, 16);
|
|
9315
|
+
}
|
|
9316
|
+
else {
|
|
9317
|
+
transformedTypedData.domain.chainId = parseInt(providedChainId, 10);
|
|
9318
|
+
}
|
|
9319
|
+
}
|
|
9320
|
+
if (transformedTypedData.domain.chainId !== chainId) {
|
|
9321
|
+
throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `Invalid chainId, expected ${chainId}`);
|
|
9322
|
+
}
|
|
9323
|
+
}
|
|
9324
|
+
return transformedTypedData;
|
|
9325
|
+
};
|
|
9326
|
+
const signTypedDataV4 = async ({ params, method, magicProvider, jsonRpcProvider, relayerClient, guardianClient, user, }) => guardianClient
|
|
9327
|
+
.withConfirmationScreen({ width: 480, height: 730 })(async () => {
|
|
9328
|
+
const fromAddress = params[0];
|
|
9329
|
+
const typedDataParam = params[1];
|
|
9330
|
+
if (!fromAddress || !typedDataParam) {
|
|
9331
|
+
throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `${method} requires an address and a typed data JSON`);
|
|
9332
|
+
}
|
|
9333
|
+
const { chainId } = await jsonRpcProvider.ready;
|
|
9334
|
+
const typedData = transformTypedData(typedDataParam, chainId);
|
|
9335
|
+
await guardianClient.validateMessage({ chainID: String(chainId), payload: typedData, user });
|
|
9336
|
+
const relayerSignature = await relayerClient.imSignTypedData(fromAddress, typedData);
|
|
9337
|
+
const magicWeb3Provider = new providers.Web3Provider(magicProvider);
|
|
9338
|
+
const signer = magicWeb3Provider.getSigner();
|
|
9339
|
+
return getSignedTypedData(typedData, relayerSignature, ethers.BigNumber.from(chainId), fromAddress, signer);
|
|
9340
|
+
});
|
|
9341
|
+
|
|
8983
9342
|
class ZkEvmProvider {
|
|
8984
9343
|
authManager;
|
|
8985
9344
|
config;
|
|
@@ -9063,6 +9422,21 @@ class ZkEvmProvider {
|
|
|
9063
9422
|
case 'eth_accounts': {
|
|
9064
9423
|
return this.isLoggedIn() ? [this.user.zkEvm.ethAddress] : [];
|
|
9065
9424
|
}
|
|
9425
|
+
case 'eth_signTypedData':
|
|
9426
|
+
case 'eth_signTypedData_v4': {
|
|
9427
|
+
if (!this.isLoggedIn()) {
|
|
9428
|
+
throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
|
|
9429
|
+
}
|
|
9430
|
+
return signTypedDataV4({
|
|
9431
|
+
method: request.method,
|
|
9432
|
+
params: request.params || [],
|
|
9433
|
+
magicProvider: this.magicProvider,
|
|
9434
|
+
jsonRpcProvider: this.jsonRpcProvider,
|
|
9435
|
+
relayerClient: this.relayerClient,
|
|
9436
|
+
user: this.user,
|
|
9437
|
+
guardianClient: this.guardianClient,
|
|
9438
|
+
});
|
|
9439
|
+
}
|
|
9066
9440
|
// Pass through methods
|
|
9067
9441
|
case 'eth_gasPrice':
|
|
9068
9442
|
case 'eth_getBalance':
|
|
@@ -27383,6 +27757,8 @@ var $bc2bfebf768286d3$export$8cb0af6b2bed4b64;
|
|
|
27383
27757
|
|
|
27384
27758
|
|
|
27385
27759
|
|
|
27760
|
+
|
|
27761
|
+
|
|
27386
27762
|
var $de275b98d2b651c3$export$788b1fd17f3dad84;
|
|
27387
27763
|
(function(GasEstimateType) {
|
|
27388
27764
|
GasEstimateType["BRIDGE_TO_L2"] = "BRIDGE_TO_L2";
|
|
@@ -27788,6 +28164,12 @@ var $4b58188d47aafe8d$export$537fa3efd10ed435;
|
|
|
27788
28164
|
GasTokenType["NATIVE"] = "NATIVE";
|
|
27789
28165
|
GasTokenType["ERC20"] = "ERC20";
|
|
27790
28166
|
})($4b58188d47aafe8d$export$537fa3efd10ed435 || ($4b58188d47aafe8d$export$537fa3efd10ed435 = {}));
|
|
28167
|
+
var $4b58188d47aafe8d$export$3af78bb3e8650ee6;
|
|
28168
|
+
(function(FundingRouteType) {
|
|
28169
|
+
FundingRouteType["BRIDGE"] = "BRIDGE";
|
|
28170
|
+
FundingRouteType["ONRAMP"] = "ONRAMP";
|
|
28171
|
+
FundingRouteType["SWAP"] = "SWAP";
|
|
28172
|
+
})($4b58188d47aafe8d$export$3af78bb3e8650ee6 || ($4b58188d47aafe8d$export$3af78bb3e8650ee6 = {}));
|
|
27791
28173
|
|
|
27792
28174
|
|
|
27793
28175
|
var $e055e79256bbc1dd$export$80f4da0d409a629d;
|
|
@@ -27833,6 +28215,7 @@ var $e055e79256bbc1dd$export$80f4da0d409a629d;
|
|
|
27833
28215
|
CheckoutErrorType["EXECUTE_FULFILMENT_TRANSACTION_ERROR"] = "EXECUTE_FULFILMENT_TRANSACTION_ERROR";
|
|
27834
28216
|
CheckoutErrorType["SIGN_MESSAGE_ERROR"] = "SIGN_MESSAGE_ERROR";
|
|
27835
28217
|
CheckoutErrorType["BRIDGE_GAS_ESTIMATE_ERROR"] = "BRIDGE_GAS_ESTIMATE_ERROR";
|
|
28218
|
+
CheckoutErrorType["ORDER_FEE_ERROR"] = "ORDER_FEE_ERROR";
|
|
27836
28219
|
})($a8bc256d81a5e2c1$export$e3dc0620abde7f5a || ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a = {}));
|
|
27837
28220
|
class $a8bc256d81a5e2c1$export$b722478a3cbfa3bc extends Error {
|
|
27838
28221
|
message;
|
|
@@ -29479,12 +29862,6 @@ var $b23305044c0e096a$export$3057de18ac0c076;
|
|
|
29479
29862
|
RouteCalculatorType["NO_ROUTES"] = "NO_ROUTES";
|
|
29480
29863
|
RouteCalculatorType["NO_OPTIONS"] = "NO_OPTIONS";
|
|
29481
29864
|
})($b23305044c0e096a$export$3057de18ac0c076 || ($b23305044c0e096a$export$3057de18ac0c076 = {}));
|
|
29482
|
-
var $b23305044c0e096a$export$3af78bb3e8650ee6;
|
|
29483
|
-
(function(FundingRouteType) {
|
|
29484
|
-
FundingRouteType["BRIDGE"] = "BRIDGE";
|
|
29485
|
-
FundingRouteType["ON_RAMP"] = "ONRAMP";
|
|
29486
|
-
FundingRouteType["SWAP"] = "SWAP";
|
|
29487
|
-
})($b23305044c0e096a$export$3af78bb3e8650ee6 || ($b23305044c0e096a$export$3af78bb3e8650ee6 = {}));
|
|
29488
29865
|
|
|
29489
29866
|
|
|
29490
29867
|
|
|
@@ -29544,7 +29921,6 @@ const $33acec7b4a26c053$export$23ddeb2642d2f9d = async (config, readOnlyProvider
|
|
|
29544
29921
|
|
|
29545
29922
|
|
|
29546
29923
|
|
|
29547
|
-
|
|
29548
29924
|
const $f730af3b727f04ac$export$22fea095b15361de = (balances)=>{
|
|
29549
29925
|
for (const balance of balances.balances){
|
|
29550
29926
|
if (!balance.token.address || balance.token.address === "") return balance.balance;
|
|
@@ -29628,6 +30004,18 @@ const $5a5ccedc98d53d25$var$filterTokens = (allowedTokens, balances)=>{
|
|
|
29628
30004
|
});
|
|
29629
30005
|
return [];
|
|
29630
30006
|
};
|
|
30007
|
+
const $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4 = async (config, availableRoutingOptions)=>{
|
|
30008
|
+
if (availableRoutingOptions.onRamp) {
|
|
30009
|
+
const onRampOptions = await config.remote.getConfig("onramp");
|
|
30010
|
+
const onRampAllowList = {};
|
|
30011
|
+
Object.entries(onRampOptions).forEach(([onRampProvider, onRampProviderConfig])=>{
|
|
30012
|
+
// Allowed list per onRamp provider
|
|
30013
|
+
onRampAllowList[onRampProvider] = onRampProviderConfig.tokens ?? [];
|
|
30014
|
+
});
|
|
30015
|
+
return onRampAllowList;
|
|
30016
|
+
}
|
|
30017
|
+
return {};
|
|
30018
|
+
};
|
|
29631
30019
|
const $5a5ccedc98d53d25$export$d744af9f1c0712bc = async (config, tokenBalances, availableRoutingOptions)=>{
|
|
29632
30020
|
if (availableRoutingOptions.bridge) {
|
|
29633
30021
|
const allowedTokens = (await config.remote.getConfig("bridge"))?.tokens ?? [];
|
|
@@ -29636,6 +30024,21 @@ const $5a5ccedc98d53d25$export$d744af9f1c0712bc = async (config, tokenBalances,
|
|
|
29636
30024
|
}
|
|
29637
30025
|
return [];
|
|
29638
30026
|
};
|
|
30027
|
+
const $5a5ccedc98d53d25$export$87ed7f956d73690 = async (config, tokenBalances, availableRoutingOptions)=>{
|
|
30028
|
+
if (availableRoutingOptions.swap) {
|
|
30029
|
+
const allowedTokens = (await config.remote.getConfig("dex"))?.tokens ?? [];
|
|
30030
|
+
const balances = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
|
|
30031
|
+
return $5a5ccedc98d53d25$var$filterTokens(allowedTokens, balances);
|
|
30032
|
+
}
|
|
30033
|
+
return [];
|
|
30034
|
+
};
|
|
30035
|
+
const $5a5ccedc98d53d25$export$1ad29657d49c5440 = async (config, tokenBalances, availableRoutingOptions)=>{
|
|
30036
|
+
const tokenAllowList = {};
|
|
30037
|
+
tokenAllowList.swap = await $5a5ccedc98d53d25$export$87ed7f956d73690(config, tokenBalances, availableRoutingOptions);
|
|
30038
|
+
tokenAllowList.bridge = await $5a5ccedc98d53d25$export$d744af9f1c0712bc(config, tokenBalances, availableRoutingOptions);
|
|
30039
|
+
tokenAllowList.onRamp = await $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4(config, availableRoutingOptions);
|
|
30040
|
+
return tokenAllowList;
|
|
30041
|
+
};
|
|
29639
30042
|
|
|
29640
30043
|
|
|
29641
30044
|
const $fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665 = (balances, totalFees)=>{
|
|
@@ -29663,14 +30066,14 @@ const $fa9ac5bfdbbf9dfa$export$952cdf461a00a8c6 = async (config, balanceRequirem
|
|
|
29663
30066
|
return l1address;
|
|
29664
30067
|
};
|
|
29665
30068
|
const $fa9ac5bfdbbf9dfa$export$da05aed50d75046 = async (config, readOnlyProviders, feeEstimates)=>{
|
|
29666
|
-
let bridgeFeeEstimate = feeEstimates.get(($
|
|
30069
|
+
let bridgeFeeEstimate = feeEstimates.get(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE);
|
|
29667
30070
|
if (bridgeFeeEstimate) return bridgeFeeEstimate;
|
|
29668
30071
|
bridgeFeeEstimate = await ($8a49d1a3783a2640$export$3aff971444a4f244)(config, readOnlyProviders);
|
|
29669
|
-
feeEstimates.set(($
|
|
30072
|
+
feeEstimates.set(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE, bridgeFeeEstimate);
|
|
29670
30073
|
return bridgeFeeEstimate;
|
|
29671
30074
|
};
|
|
29672
30075
|
const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance)=>({
|
|
29673
|
-
type: ($
|
|
30076
|
+
type: ($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE,
|
|
29674
30077
|
chainId: chainId,
|
|
29675
30078
|
asset: {
|
|
29676
30079
|
balance: balance.balance,
|
|
@@ -29726,6 +30129,7 @@ const $fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa = async (config, readOnlyProvide
|
|
|
29726
30129
|
|
|
29727
30130
|
|
|
29728
30131
|
|
|
30132
|
+
|
|
29729
30133
|
async function $0e0060cb42e136d2$export$339cb2be73677b30(config, existingReadOnlyProviders) {
|
|
29730
30134
|
if (config.isProduction && existingReadOnlyProviders?.has(($0472f23319457bfb$export$c06e1e7429de6283).ETHEREUM)) return existingReadOnlyProviders;
|
|
29731
30135
|
if (existingReadOnlyProviders?.has(($0472f23319457bfb$export$c06e1e7429de6283).SEPOLIA)) return existingReadOnlyProviders;
|
|
@@ -29743,16 +30147,199 @@ async function $0e0060cb42e136d2$export$339cb2be73677b30(config, existingReadOnl
|
|
|
29743
30147
|
|
|
29744
30148
|
|
|
29745
30149
|
|
|
30150
|
+
|
|
30151
|
+
|
|
30152
|
+
|
|
30153
|
+
|
|
30154
|
+
|
|
30155
|
+
const $049bba630af05555$export$6946a1f17c2bbf26 = async (config, chainId, walletAddress, requiredToken, swappableTokens)=>{
|
|
30156
|
+
const dexQuotes = new Map();
|
|
30157
|
+
try {
|
|
30158
|
+
const exchange = await $67fc622a2b913d5f$export$7cf6178417769841(chainId, config);
|
|
30159
|
+
const dexTransactionResponsePromises = [];
|
|
30160
|
+
// Create a quote for each swappable token
|
|
30161
|
+
for (const swappableToken of swappableTokens)dexTransactionResponsePromises.push(exchange.getUnsignedSwapTxFromAmountOut(walletAddress, swappableToken, requiredToken.address, requiredToken.amount));
|
|
30162
|
+
// Resolve all the quotes and link them back to the swappable token
|
|
30163
|
+
// The swappable token array is in the same position in the array as the quote in the promise array
|
|
30164
|
+
const dexTransactionResponse = await Promise.all(dexTransactionResponsePromises);
|
|
30165
|
+
dexTransactionResponse.forEach((response, index)=>{
|
|
30166
|
+
const swappableToken = swappableTokens[index];
|
|
30167
|
+
dexQuotes.set(swappableToken, {
|
|
30168
|
+
quote: response.quote,
|
|
30169
|
+
approval: response.approval?.gasFeeEstimate,
|
|
30170
|
+
swap: response.swap.gasFeeEstimate
|
|
30171
|
+
});
|
|
30172
|
+
});
|
|
30173
|
+
return dexQuotes;
|
|
30174
|
+
} catch {
|
|
30175
|
+
return dexQuotes;
|
|
30176
|
+
}
|
|
30177
|
+
};
|
|
30178
|
+
|
|
30179
|
+
|
|
30180
|
+
const $3ee85f12225c19f3$export$fb80fe94a81a3132 = async (config, dexQuoteCache, walletAddress, requiredToken, swappableTokens)=>{
|
|
30181
|
+
const dexQuotes = dexQuoteCache.get(requiredToken.address);
|
|
30182
|
+
if (dexQuotes) return dexQuotes;
|
|
30183
|
+
const quotes = await ($049bba630af05555$export$6946a1f17c2bbf26)(config, ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config), walletAddress, requiredToken, swappableTokens);
|
|
30184
|
+
dexQuoteCache.set(requiredToken.address, quotes);
|
|
30185
|
+
return quotes;
|
|
30186
|
+
};
|
|
30187
|
+
|
|
30188
|
+
|
|
30189
|
+
const $91807edfd7057288$export$85e4d8628aabb217 = (balanceRequirement)=>{
|
|
30190
|
+
let address = "";
|
|
30191
|
+
let amount = (ethers.BigNumber).from(0);
|
|
30192
|
+
switch(balanceRequirement.type){
|
|
30193
|
+
case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20:
|
|
30194
|
+
address = balanceRequirement.required.token.address ?? "";
|
|
30195
|
+
amount = balanceRequirement.delta.balance;
|
|
30196
|
+
break;
|
|
30197
|
+
case ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE:
|
|
30198
|
+
address = ($d85ad1457a3f1a83$export$b80040cb173ba6e9);
|
|
30199
|
+
amount = balanceRequirement.delta.balance;
|
|
30200
|
+
break;
|
|
30201
|
+
}
|
|
30202
|
+
return {
|
|
30203
|
+
address: address,
|
|
30204
|
+
amount: amount
|
|
30205
|
+
};
|
|
30206
|
+
};
|
|
30207
|
+
const $91807edfd7057288$export$7b6318fc1a8067b3 = (l2Balances, approval)=>{
|
|
30208
|
+
// Check if approval required
|
|
30209
|
+
if (!approval) return {
|
|
30210
|
+
sufficient: true,
|
|
30211
|
+
approvalGasFee: (ethers.BigNumber).from(0),
|
|
30212
|
+
approvalGasTokenAddress: ""
|
|
30213
|
+
};
|
|
30214
|
+
const approvalGasFee = approval.value;
|
|
30215
|
+
const approvalGasTokenAddress = approval.token.address;
|
|
30216
|
+
// No balance on L2 to cover approval fees
|
|
30217
|
+
if (l2Balances.length === 0) return {
|
|
30218
|
+
sufficient: false,
|
|
30219
|
+
approvalGasFee: approvalGasFee,
|
|
30220
|
+
approvalGasTokenAddress: approvalGasTokenAddress
|
|
30221
|
+
};
|
|
30222
|
+
// Find the users balance of the approval token
|
|
30223
|
+
const l2BalanceOfApprovalToken = l2Balances.find((balance)=>balance.token.address === approvalGasTokenAddress);
|
|
30224
|
+
if (!l2BalanceOfApprovalToken) return {
|
|
30225
|
+
sufficient: false,
|
|
30226
|
+
approvalGasFee: approvalGasFee,
|
|
30227
|
+
approvalGasTokenAddress: approvalGasTokenAddress
|
|
30228
|
+
};
|
|
30229
|
+
// If the user does not have enough of the token to cover approval fees then return sufficient false
|
|
30230
|
+
if (l2BalanceOfApprovalToken.balance.lt(approvalGasFee)) return {
|
|
30231
|
+
sufficient: false,
|
|
30232
|
+
approvalGasFee: approvalGasFee,
|
|
30233
|
+
approvalGasTokenAddress: approvalGasTokenAddress
|
|
30234
|
+
};
|
|
30235
|
+
// The user has enough to cover approval gas fees
|
|
30236
|
+
return {
|
|
30237
|
+
sufficient: true,
|
|
30238
|
+
approvalGasFee: approvalGasFee,
|
|
30239
|
+
approvalGasTokenAddress: approvalGasTokenAddress
|
|
30240
|
+
};
|
|
30241
|
+
};
|
|
30242
|
+
const $91807edfd7057288$export$38077235fe748d40 = (l2Balances, swapFees, approvalFees, tokenBeingSwapped)=>{
|
|
30243
|
+
// Set up a map of token addresses to amounts for each of the swap fees
|
|
30244
|
+
const feeMap = new Map();
|
|
30245
|
+
// Add the approval fee to list of fees
|
|
30246
|
+
if (approvalFees.approvalGasTokenAddress !== "") feeMap.set(approvalFees.approvalGasTokenAddress, approvalFees.approvalGasFee);
|
|
30247
|
+
// Add the token being swapped to list of fees to ensure the user can cover the fee + the token swap
|
|
30248
|
+
if (tokenBeingSwapped) {
|
|
30249
|
+
const fee = feeMap.get(tokenBeingSwapped.address);
|
|
30250
|
+
if (fee) feeMap.set(tokenBeingSwapped.address, fee.add(tokenBeingSwapped.amount));
|
|
30251
|
+
else feeMap.set(tokenBeingSwapped.address, tokenBeingSwapped.amount);
|
|
30252
|
+
}
|
|
30253
|
+
// Get all the fees and key them by their token id
|
|
30254
|
+
for (const swapFee of swapFees){
|
|
30255
|
+
const fee = feeMap.get(swapFee.amount.token.address);
|
|
30256
|
+
if (fee) {
|
|
30257
|
+
feeMap.set(swapFee.amount.token.address, fee.add(swapFee.amount.value));
|
|
30258
|
+
continue;
|
|
30259
|
+
}
|
|
30260
|
+
feeMap.set(swapFee.amount.token.address, swapFee.amount.value);
|
|
30261
|
+
}
|
|
30262
|
+
// Go through the map and for each token address check if the user has enough balance to cover the fee
|
|
30263
|
+
for (const [tokenAddress, fee] of feeMap.entries()){
|
|
30264
|
+
if (fee === (ethers.BigNumber).from(0)) continue;
|
|
30265
|
+
const l2BalanceOfFeeToken = l2Balances.find((balance)=>balance.token.address === tokenAddress);
|
|
30266
|
+
if (!l2BalanceOfFeeToken) return false;
|
|
30267
|
+
if (l2BalanceOfFeeToken.balance.lt(fee)) return false;
|
|
30268
|
+
}
|
|
30269
|
+
return true;
|
|
30270
|
+
};
|
|
30271
|
+
const $91807edfd7057288$export$8e03ea04d59f2402 = async (config, availableRoutingOptions, dexQuoteCache, walletAddress, balanceRequirement, tokenBalanceResults, swappableTokens)=>{
|
|
30272
|
+
if (!availableRoutingOptions.swap) return undefined;
|
|
30273
|
+
if (swappableTokens.length === 0) return undefined;
|
|
30274
|
+
const requiredToken = $91807edfd7057288$export$85e4d8628aabb217(balanceRequirement);
|
|
30275
|
+
if (requiredToken.address === "") return undefined;
|
|
30276
|
+
const l2TokenBalanceResult = tokenBalanceResults.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
|
|
30277
|
+
if (!l2TokenBalanceResult) return undefined;
|
|
30278
|
+
const l2Balances = l2TokenBalanceResult.balances;
|
|
30279
|
+
if (l2Balances.length === 0) return undefined;
|
|
30280
|
+
const quotes = await ($3ee85f12225c19f3$export$fb80fe94a81a3132)(config, dexQuoteCache, walletAddress, requiredToken, swappableTokens);
|
|
30281
|
+
const quoteTokenAddresses = Array.from(quotes.keys());
|
|
30282
|
+
for (const quoteTokenAddress of quoteTokenAddresses){
|
|
30283
|
+
const quote = quotes.get(quoteTokenAddress);
|
|
30284
|
+
if (!quote) continue;
|
|
30285
|
+
// Find the balance the user has for this quoted token
|
|
30286
|
+
const userBalanceOfQuotedToken = l2Balances.find((balance)=>balance.token.address === quoteTokenAddress);
|
|
30287
|
+
// If no balance found on L2 for this quoted token then continue
|
|
30288
|
+
if (!userBalanceOfQuotedToken) continue;
|
|
30289
|
+
// Check the amount of quoted token required against the user balance
|
|
30290
|
+
const amountOfQuoteTokenRequired = quote.quote.amount;
|
|
30291
|
+
// If user does not have enough balance to perform the swap with this token then continue
|
|
30292
|
+
if (userBalanceOfQuotedToken.balance.lt(amountOfQuoteTokenRequired.value)) continue;
|
|
30293
|
+
const approvalFees = $91807edfd7057288$export$7b6318fc1a8067b3(l2Balances, quote.approval);
|
|
30294
|
+
// If user does not have enough to cover approval fees then continue
|
|
30295
|
+
if (!approvalFees.sufficient) continue;
|
|
30296
|
+
// If user does not have enough to cover swap fees then continue
|
|
30297
|
+
if (!$91807edfd7057288$export$38077235fe748d40(l2Balances, quote.quote.fees, approvalFees, {
|
|
30298
|
+
amount: amountOfQuoteTokenRequired.value,
|
|
30299
|
+
address: quoteTokenAddress
|
|
30300
|
+
})) continue;
|
|
30301
|
+
// User has sufficient funds to cover any approval and swap fees so use this token for the funding route
|
|
30302
|
+
// Currently we are not prioritising any particular token so just taking the first sufficient token
|
|
30303
|
+
return {
|
|
30304
|
+
type: ($4b58188d47aafe8d$export$3af78bb3e8650ee6).SWAP,
|
|
30305
|
+
chainId: ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config),
|
|
30306
|
+
asset: {
|
|
30307
|
+
balance: userBalanceOfQuotedToken.balance,
|
|
30308
|
+
formattedBalance: userBalanceOfQuotedToken.formattedBalance,
|
|
30309
|
+
token: userBalanceOfQuotedToken.token
|
|
30310
|
+
}
|
|
30311
|
+
};
|
|
30312
|
+
}
|
|
30313
|
+
return undefined;
|
|
30314
|
+
};
|
|
30315
|
+
|
|
30316
|
+
|
|
30317
|
+
|
|
30318
|
+
|
|
30319
|
+
|
|
29746
30320
|
const $c16168a9c28ae4fd$export$31ce7ba1a2956195 = (balanceRequirements)=>{
|
|
29747
30321
|
let insufficientBalanceCount = 0;
|
|
29748
|
-
let
|
|
30322
|
+
let insufficientRequirement;
|
|
29749
30323
|
for (const balanceRequirement of balanceRequirements.balanceRequirements)if (!balanceRequirement.sufficient) {
|
|
29750
30324
|
insufficientBalanceCount++;
|
|
29751
|
-
|
|
30325
|
+
insufficientRequirement = balanceRequirement;
|
|
29752
30326
|
}
|
|
29753
|
-
if (insufficientBalanceCount === 1) return
|
|
30327
|
+
if (insufficientBalanceCount === 1) return insufficientRequirement;
|
|
29754
30328
|
return undefined;
|
|
29755
30329
|
};
|
|
30330
|
+
const $c16168a9c28ae4fd$export$c39a7b7dc167cdb4 = async (config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, swapTokenAllowList)=>{
|
|
30331
|
+
if (!availableRoutingOptions.swap) return undefined;
|
|
30332
|
+
if (insufficientRequirement === undefined) return undefined;
|
|
30333
|
+
if (swapTokenAllowList === undefined) return undefined;
|
|
30334
|
+
const tokenBalanceResult = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
|
|
30335
|
+
if (!tokenBalanceResult) return undefined;
|
|
30336
|
+
if (tokenBalanceResult.error !== undefined || !tokenBalanceResult.success) return undefined;
|
|
30337
|
+
if (swapTokenAllowList.length === 0) return undefined;
|
|
30338
|
+
const swappableTokens = swapTokenAllowList.filter((token)=>token.address).map((token)=>token.address);
|
|
30339
|
+
if (swappableTokens.length === 0) return undefined;
|
|
30340
|
+
const swapFundingStep = await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, tokenBalances, swappableTokens);
|
|
30341
|
+
return swapFundingStep;
|
|
30342
|
+
};
|
|
29756
30343
|
const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, balanceRequirements, availableRoutingOptions)=>{
|
|
29757
30344
|
let readOnlyProviders;
|
|
29758
30345
|
try {
|
|
@@ -29763,40 +30350,52 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
|
|
|
29763
30350
|
});
|
|
29764
30351
|
}
|
|
29765
30352
|
const tokenBalances = await ($33acec7b4a26c053$export$23ddeb2642d2f9d)(config, readOnlyProviders, ownerAddress, availableRoutingOptions);
|
|
30353
|
+
const allowList = await ($5a5ccedc98d53d25$export$1ad29657d49c5440)(config, tokenBalances, availableRoutingOptions);
|
|
29766
30354
|
// Bridge and swap fee cache
|
|
29767
30355
|
const feeEstimates = new Map();
|
|
29768
|
-
//
|
|
29769
|
-
|
|
30356
|
+
// Dex quotes cache
|
|
30357
|
+
const dexQuoteCache = new Map();
|
|
30358
|
+
// Ensures only 1 balance requirement is insufficient otherwise one bridge or one swap route cannot be recommended
|
|
29770
30359
|
const insufficientRequirement = $c16168a9c28ae4fd$export$31ce7ba1a2956195(balanceRequirements);
|
|
30360
|
+
let bridgeFundingStep;
|
|
29771
30361
|
if (availableRoutingOptions.bridge && insufficientRequirement) bridgeFundingStep = await ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, insufficientRequirement, tokenBalances, feeEstimates);
|
|
30362
|
+
const swapFundingStep = await $c16168a9c28ae4fd$export$c39a7b7dc167cdb4(config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList.swap);
|
|
29772
30363
|
// Check on-ramp routes
|
|
29773
30364
|
// Check swap routes
|
|
29774
30365
|
// > Could bridge first
|
|
29775
30366
|
// > Could on-ramp first
|
|
29776
30367
|
// > Could double swap
|
|
29777
|
-
|
|
29778
|
-
availableOptions: [],
|
|
29779
|
-
response: {
|
|
29780
|
-
type: ($b23305044c0e096a$export$3057de18ac0c076).ROUTES_FOUND,
|
|
29781
|
-
message: "Routes found"
|
|
29782
|
-
},
|
|
29783
|
-
fundingRoutes: [
|
|
29784
|
-
{
|
|
29785
|
-
priority: 1,
|
|
29786
|
-
steps: [
|
|
29787
|
-
bridgeFundingStep
|
|
29788
|
-
]
|
|
29789
|
-
}
|
|
29790
|
-
]
|
|
29791
|
-
};
|
|
29792
|
-
return {
|
|
29793
|
-
availableOptions: [],
|
|
30368
|
+
const response = {
|
|
29794
30369
|
response: {
|
|
29795
30370
|
type: ($b23305044c0e096a$export$3057de18ac0c076).NO_ROUTES,
|
|
29796
30371
|
message: "Routes not found"
|
|
29797
30372
|
},
|
|
29798
30373
|
fundingRoutes: []
|
|
29799
30374
|
};
|
|
30375
|
+
let priority = 0;
|
|
30376
|
+
if (bridgeFundingStep || swapFundingStep) {
|
|
30377
|
+
response.response.type = ($b23305044c0e096a$export$3057de18ac0c076).ROUTES_FOUND;
|
|
30378
|
+
response.response.message = "Routes found";
|
|
30379
|
+
}
|
|
30380
|
+
if (bridgeFundingStep) {
|
|
30381
|
+
priority++;
|
|
30382
|
+
response.fundingRoutes.push({
|
|
30383
|
+
priority: priority,
|
|
30384
|
+
steps: [
|
|
30385
|
+
bridgeFundingStep
|
|
30386
|
+
]
|
|
30387
|
+
});
|
|
30388
|
+
}
|
|
30389
|
+
if (swapFundingStep) {
|
|
30390
|
+
priority++;
|
|
30391
|
+
response.fundingRoutes.push({
|
|
30392
|
+
priority: priority,
|
|
30393
|
+
steps: [
|
|
30394
|
+
swapFundingStep
|
|
30395
|
+
]
|
|
30396
|
+
});
|
|
30397
|
+
}
|
|
30398
|
+
return response;
|
|
29800
30399
|
};
|
|
29801
30400
|
|
|
29802
30401
|
|
|
@@ -30120,27 +30719,80 @@ const $9c3db1bb9c8b69d3$export$70b61ad426ddbe54 = async (config, provider, order
|
|
|
30120
30719
|
|
|
30121
30720
|
|
|
30122
30721
|
|
|
30722
|
+
|
|
30723
|
+
|
|
30724
|
+
|
|
30725
|
+
|
|
30726
|
+
const $9051cee080948594$export$9ac1563efd38130 = 1; // 100%
|
|
30727
|
+
const $9051cee080948594$export$768e717351d4b176 = 6; // will allow 0.000001 (0.0001%) as the minimum value
|
|
30728
|
+
const $9051cee080948594$var$calculateFeesPercent = (orderFee, amountBn)=>{
|
|
30729
|
+
const feePercentage = orderFee.amount;
|
|
30730
|
+
// note: multiply in and out of the maximum decimal places to the power of ten to do the math in big number integers
|
|
30731
|
+
const feePercentageMultiplier = Math.round(feePercentage.percentageDecimal * 10 ** $9051cee080948594$export$768e717351d4b176);
|
|
30732
|
+
const bnFeeAmount = amountBn.mul((ethers.BigNumber).from(feePercentageMultiplier)).div(10 ** $9051cee080948594$export$768e717351d4b176);
|
|
30733
|
+
return bnFeeAmount;
|
|
30734
|
+
};
|
|
30735
|
+
const $9051cee080948594$var$calculateFeesToken = (orderFee, decimals)=>{
|
|
30736
|
+
const feeToken = orderFee.amount;
|
|
30737
|
+
const bnFeeAmount = (utils$1.parseUnits)(feeToken.token, decimals);
|
|
30738
|
+
return bnFeeAmount;
|
|
30739
|
+
};
|
|
30740
|
+
const $9051cee080948594$export$1e69c9cfc42e28d8 = (orderFees, weiAmount, decimals = 18)=>{
|
|
30741
|
+
let totalTokenFees = (ethers.BigNumber).from(0);
|
|
30742
|
+
const amountBn = (ethers.BigNumber).from(weiAmount);
|
|
30743
|
+
// note: multiply in and out of the maximum decimal places to the power of ten to do the math in big number integers
|
|
30744
|
+
const totalAllowableFees = amountBn.mul($9051cee080948594$export$9ac1563efd38130 * 10 ** $9051cee080948594$export$768e717351d4b176).div(10 ** $9051cee080948594$export$768e717351d4b176);
|
|
30745
|
+
const calculateFeesResult = [];
|
|
30746
|
+
for (const orderFee of orderFees){
|
|
30747
|
+
let currentFeeBn = (ethers.BigNumber).from(0);
|
|
30748
|
+
if (Object.hasOwn(orderFee.amount, "percentageDecimal")) {
|
|
30749
|
+
currentFeeBn = $9051cee080948594$var$calculateFeesPercent(orderFee, amountBn);
|
|
30750
|
+
totalTokenFees = totalTokenFees.add(currentFeeBn);
|
|
30751
|
+
} else if (Object.hasOwn(orderFee.amount, "token")) {
|
|
30752
|
+
currentFeeBn = $9051cee080948594$var$calculateFeesToken(orderFee, decimals);
|
|
30753
|
+
totalTokenFees = totalTokenFees.add(currentFeeBn);
|
|
30754
|
+
} else throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Unknown fee type parsed, must be percentageDecimal or token", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).ORDER_FEE_ERROR);
|
|
30755
|
+
if (totalTokenFees.gt(totalAllowableFees)) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)(`The combined fees are above the allowed maximum of ${$9051cee080948594$export$9ac1563efd38130 * 100}%`, ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).ORDER_FEE_ERROR);
|
|
30756
|
+
if (currentFeeBn.gt(0)) calculateFeesResult.push({
|
|
30757
|
+
amount: currentFeeBn.toString(),
|
|
30758
|
+
recipient: orderFee.recipient
|
|
30759
|
+
});
|
|
30760
|
+
} // for
|
|
30761
|
+
return calculateFeesResult;
|
|
30762
|
+
};
|
|
30763
|
+
|
|
30764
|
+
|
|
30123
30765
|
const $9085b221b72ac69e$export$af768ccdf17d5c04 = (id, contractAddress, spenderAddress)=>({
|
|
30124
30766
|
type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721,
|
|
30125
30767
|
id: id,
|
|
30126
30768
|
contractAddress: contractAddress,
|
|
30127
30769
|
spenderAddress: spenderAddress
|
|
30128
30770
|
});
|
|
30129
|
-
const $9085b221b72ac69e$export$586d02673c66d423 = (buyToken)=>{
|
|
30771
|
+
const $9085b221b72ac69e$export$586d02673c66d423 = (buyToken, decimals = 18)=>{
|
|
30772
|
+
const bnAmount = (utils$1.parseUnits)(buyToken.amount, decimals);
|
|
30130
30773
|
if (buyToken.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return {
|
|
30131
30774
|
type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE,
|
|
30132
|
-
amount:
|
|
30775
|
+
amount: bnAmount.toString()
|
|
30133
30776
|
};
|
|
30134
30777
|
return {
|
|
30135
30778
|
type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20,
|
|
30136
|
-
amount:
|
|
30779
|
+
amount: bnAmount.toString(),
|
|
30137
30780
|
contractAddress: buyToken.contractAddress
|
|
30138
30781
|
};
|
|
30139
30782
|
};
|
|
30140
|
-
const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider,
|
|
30783
|
+
const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, orders)=>{
|
|
30141
30784
|
let orderbook;
|
|
30142
30785
|
let listing;
|
|
30143
30786
|
let spenderAddress = "";
|
|
30787
|
+
if (orders.length === 0) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No orders were parsed, must parse at least one order", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PREPARE_ORDER_LISTING_ERROR);
|
|
30788
|
+
const { buyToken: buyToken, sellToken: sellToken, makerFees: makerFees } = orders[0];
|
|
30789
|
+
let decimals = 18;
|
|
30790
|
+
if (buyToken.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
|
|
30791
|
+
// get this from the allowed list
|
|
30792
|
+
const buyTokenContract = new (ethers.Contract)(buyToken.contractAddress, JSON.stringify(($d85ad1457a3f1a83$export$db5daa1b5156ccfe)), provider);
|
|
30793
|
+
decimals = buyTokenContract.decimals();
|
|
30794
|
+
}
|
|
30795
|
+
const buyTokenOrNative = $9085b221b72ac69e$export$586d02673c66d423(buyToken, decimals);
|
|
30144
30796
|
try {
|
|
30145
30797
|
const walletAddress = await provider.getSigner().getAddress();
|
|
30146
30798
|
orderbook = await $67fc622a2b913d5f$export$c60ce6c6a92bc2ff(config);
|
|
@@ -30148,22 +30800,22 @@ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, c
|
|
|
30148
30800
|
spenderAddress = seaportContractAddress;
|
|
30149
30801
|
listing = await orderbook.prepareListing({
|
|
30150
30802
|
makerAddress: walletAddress,
|
|
30151
|
-
buy:
|
|
30803
|
+
buy: buyTokenOrNative,
|
|
30152
30804
|
sell: {
|
|
30153
30805
|
type: (0, $4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721,
|
|
30154
|
-
contractAddress:
|
|
30155
|
-
tokenId: id
|
|
30806
|
+
contractAddress: sellToken.collectionAddress,
|
|
30807
|
+
tokenId: sellToken.id
|
|
30156
30808
|
}
|
|
30157
30809
|
});
|
|
30158
30810
|
} catch (err) {
|
|
30159
30811
|
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("An error occurred while preparing the listing", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PREPARE_ORDER_LISTING_ERROR, {
|
|
30160
30812
|
message: err.message,
|
|
30161
|
-
id: id,
|
|
30162
|
-
collectionAddress:
|
|
30813
|
+
id: sellToken.id,
|
|
30814
|
+
collectionAddress: sellToken.collectionAddress
|
|
30163
30815
|
});
|
|
30164
30816
|
}
|
|
30165
30817
|
const itemRequirements = [
|
|
30166
|
-
$9085b221b72ac69e$export$af768ccdf17d5c04(id,
|
|
30818
|
+
$9085b221b72ac69e$export$af768ccdf17d5c04(sellToken.id, sellToken.collectionAddress, spenderAddress)
|
|
30167
30819
|
];
|
|
30168
30820
|
const smartCheckoutResult = await ($0e7419077c373b24$export$9e073f9ada8c81e6)(config, provider, itemRequirements, {
|
|
30169
30821
|
type: ($4b58188d47aafe8d$export$65c64e46348ee3c1).GAS,
|
|
@@ -30177,15 +30829,15 @@ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, c
|
|
|
30177
30829
|
if (!unsignedMessage) // For sell it is expected the orderbook will always return an unsigned message
|
|
30178
30830
|
// If for some reason it is missing then we cannot proceed with the create listing
|
|
30179
30831
|
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("The unsigned message is missing after preparing the listing", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).SIGN_MESSAGE_ERROR, {
|
|
30180
|
-
id: id,
|
|
30181
|
-
collectionAddress:
|
|
30832
|
+
id: sellToken.id,
|
|
30833
|
+
collectionAddress: sellToken.collectionAddress
|
|
30182
30834
|
});
|
|
30183
30835
|
const signedMessage = await ($25ac589234c10b67$export$1d9a7a8a40780de)(provider, unsignedMessage);
|
|
30184
30836
|
const unsignedTransactions = await ($a7367d01c6e76b1c$export$b087719c36e0f2dc)(listing.actions);
|
|
30185
30837
|
const approvalResult = await ($25ac589234c10b67$export$19693ca396db083e)(provider, unsignedTransactions.approvalTransactions);
|
|
30186
30838
|
if (approvalResult.type === ($d855a5ba32004345$export$f51b97f3aaf2d5a8).FAILED) return {
|
|
30187
|
-
id: id,
|
|
30188
|
-
collectionAddress:
|
|
30839
|
+
id: sellToken.id,
|
|
30840
|
+
collectionAddress: sellToken.collectionAddress,
|
|
30189
30841
|
smartCheckoutResult: smartCheckoutResult,
|
|
30190
30842
|
status: {
|
|
30191
30843
|
type: ($c2874b006e92b115$export$a9780122aaa0801a).FAILED,
|
|
@@ -30194,23 +30846,31 @@ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, c
|
|
|
30194
30846
|
}
|
|
30195
30847
|
};
|
|
30196
30848
|
let orderId = "";
|
|
30849
|
+
const createListingParams = {
|
|
30850
|
+
orderComponents: signedMessage.orderComponents,
|
|
30851
|
+
orderHash: signedMessage.orderHash,
|
|
30852
|
+
orderSignature: signedMessage.signedMessage
|
|
30853
|
+
};
|
|
30854
|
+
if (makerFees !== undefined) {
|
|
30855
|
+
const orderBookFees = ($9051cee080948594$export$1e69c9cfc42e28d8)(makerFees, buyTokenOrNative.amount, decimals);
|
|
30856
|
+
// @TODO add support for an array of fees when the orderbook enables it
|
|
30857
|
+
if (orderBookFees.length !== makerFees.length) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("One of the fees is too small, must be greater than 0.000001", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CREATE_ORDER_LISTING_ERROR);
|
|
30858
|
+
const [makerFee] = orderBookFees;
|
|
30859
|
+
createListingParams.makerFee = makerFee;
|
|
30860
|
+
}
|
|
30197
30861
|
try {
|
|
30198
|
-
const order = await orderbook.createListing(
|
|
30199
|
-
orderComponents: signedMessage.orderComponents,
|
|
30200
|
-
orderHash: signedMessage.orderHash,
|
|
30201
|
-
orderSignature: signedMessage.signedMessage
|
|
30202
|
-
});
|
|
30862
|
+
const order = await orderbook.createListing(createListingParams);
|
|
30203
30863
|
orderId = order.result.id;
|
|
30204
30864
|
} catch (err) {
|
|
30205
30865
|
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("An error occurred while creating the listing", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).CREATE_ORDER_LISTING_ERROR, {
|
|
30206
30866
|
message: err.message,
|
|
30207
|
-
|
|
30208
|
-
collectionAddress:
|
|
30867
|
+
collectionId: sellToken.id,
|
|
30868
|
+
collectionAddress: sellToken.collectionAddress
|
|
30209
30869
|
});
|
|
30210
30870
|
}
|
|
30211
30871
|
return {
|
|
30212
|
-
id: id,
|
|
30213
|
-
collectionAddress:
|
|
30872
|
+
id: sellToken.id,
|
|
30873
|
+
collectionAddress: sellToken.collectionAddress,
|
|
30214
30874
|
smartCheckoutResult: smartCheckoutResult,
|
|
30215
30875
|
status: {
|
|
30216
30876
|
type: ($c2874b006e92b115$export$a9780122aaa0801a).SUCCESS,
|
|
@@ -30219,8 +30879,8 @@ const $9085b221b72ac69e$export$e761f9e0703de895 = async (config, provider, id, c
|
|
|
30219
30879
|
};
|
|
30220
30880
|
}
|
|
30221
30881
|
return {
|
|
30222
|
-
id: id,
|
|
30223
|
-
collectionAddress:
|
|
30882
|
+
id: sellToken.id,
|
|
30883
|
+
collectionAddress: sellToken.collectionAddress,
|
|
30224
30884
|
smartCheckoutResult: smartCheckoutResult
|
|
30225
30885
|
};
|
|
30226
30886
|
};
|
|
@@ -30406,12 +31066,16 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
|
|
|
30406
31066
|
/**
|
|
30407
31067
|
* Determines the requirements for performing a sell.
|
|
30408
31068
|
* @param {SellParams} params - The parameters for the sell.
|
|
31069
|
+
* Only currently actions the first order in the array until we support batch processing.
|
|
31070
|
+
* Only currently actions the first fee in the fees array of each order until we support multiple fees.
|
|
30409
31071
|
*/ async sell(params) {
|
|
30410
31072
|
if (this.config.isProduction) throw new Error("This endpoint is not currently available.");
|
|
30411
31073
|
// eslint-disable-next-line no-console
|
|
30412
31074
|
console.warn("This endpoint is currently under construction.");
|
|
31075
|
+
if (params.orders.length > 1) // eslint-disable-next-line no-console
|
|
31076
|
+
console.warn("This endpoint currently only actions the first order in the array.");
|
|
30413
31077
|
const web3Provider = await $bb88265fe45a0393$export$9e1fd9cc88c637a0(this.config, params.provider);
|
|
30414
|
-
await $9085b221b72ac69e$export$e761f9e0703de895(this.config, web3Provider, params.
|
|
31078
|
+
await $9085b221b72ac69e$export$e761f9e0703de895(this.config, web3Provider, params.orders);
|
|
30415
31079
|
}
|
|
30416
31080
|
/**
|
|
30417
31081
|
* Cancels a sell.
|
|
@@ -30509,31 +31173,30 @@ var checkout_sdk = /*#__PURE__*/Object.freeze({
|
|
|
30509
31173
|
function $parcel$export(e, n, v, s) {
|
|
30510
31174
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
30511
31175
|
}
|
|
30512
|
-
const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.
|
|
31176
|
+
const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.18.1";
|
|
30513
31177
|
const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
|
|
30514
31178
|
const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
|
|
30515
31179
|
|
|
30516
31180
|
|
|
30517
31181
|
function $430e3eda76fa4d5f$export$46b1ae20f762ad4c(version) {
|
|
30518
31182
|
const defaultPackageVersion = ($d663162fd5a0853f$export$1169f5475725171b)();
|
|
30519
|
-
if (version === undefined) return defaultPackageVersion;
|
|
30520
|
-
|
|
30521
|
-
|
|
30522
|
-
if (version.
|
|
30523
|
-
if (version.major
|
|
30524
|
-
if (version.minor
|
|
30525
|
-
if (version.patch
|
|
30526
|
-
if (version.prerelease !== "alpha") return defaultPackageVersion;
|
|
31183
|
+
if (version === undefined || version.major === undefined) return defaultPackageVersion;
|
|
31184
|
+
if (!Number.isInteger(version.major) || version.major < 0) return defaultPackageVersion;
|
|
31185
|
+
if (version.minor !== undefined && version.minor < 0) return defaultPackageVersion;
|
|
31186
|
+
if (version.patch !== undefined && version.patch < 0) return defaultPackageVersion;
|
|
31187
|
+
if (version.major === 0 && version.minor === undefined) return defaultPackageVersion;
|
|
31188
|
+
if (version.major === 0 && version.minor === 0 && version.patch === undefined) return defaultPackageVersion;
|
|
31189
|
+
if (version.major === 0 && version.minor === undefined && version.patch === undefined) return defaultPackageVersion;
|
|
30527
31190
|
if (version.major === 0 && version.minor === 0 && version.patch === 0) return defaultPackageVersion;
|
|
30528
|
-
let validatedVersion =
|
|
30529
|
-
if (
|
|
30530
|
-
if (
|
|
30531
|
-
if (
|
|
30532
|
-
|
|
30533
|
-
|
|
30534
|
-
|
|
30535
|
-
|
|
30536
|
-
if (version.build
|
|
31191
|
+
let validatedVersion = version.major.toString();
|
|
31192
|
+
if (version.minor === undefined) return validatedVersion;
|
|
31193
|
+
if (Number.isInteger(version.minor)) validatedVersion += `.${version.minor.toString()}`;
|
|
31194
|
+
if (version.patch === undefined) return validatedVersion;
|
|
31195
|
+
if (Number.isInteger(version.patch)) validatedVersion += `.${version.patch.toString()}`;
|
|
31196
|
+
if (version.prerelease === undefined || version.prerelease !== "alpha") return validatedVersion;
|
|
31197
|
+
if (version.prerelease === "alpha") validatedVersion += `-${version.prerelease}`;
|
|
31198
|
+
if (version.build === undefined) return validatedVersion;
|
|
31199
|
+
if (Number.isInteger(version.build) && version.build >= 0) validatedVersion += `.${version.build.toString()}`;
|
|
30537
31200
|
return validatedVersion;
|
|
30538
31201
|
}
|
|
30539
31202
|
function $430e3eda76fa4d5f$export$af210a0808087845(config) {
|
|
@@ -30665,7 +31328,6 @@ $parcel$export($045213b18e9f1f94$exports, "CheckoutWidgetTagNames", () => $04521
|
|
|
30665
31328
|
(function(WidgetTheme) {
|
|
30666
31329
|
WidgetTheme["LIGHT"] = "light";
|
|
30667
31330
|
WidgetTheme["DARK"] = "dark";
|
|
30668
|
-
WidgetTheme["CUSTOM"] = "custom";
|
|
30669
31331
|
})($045213b18e9f1f94$export$c88931fdc51854eb || ($045213b18e9f1f94$export$c88931fdc51854eb = {}));
|
|
30670
31332
|
var $045213b18e9f1f94$export$75be0f6af9650f2c;
|
|
30671
31333
|
(function(CheckoutWidgetTagNames) {
|