@imtbl/sdk 0.45.2 → 0.45.3-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blockchain_data.d.ts +2 -2
- package/dist/blockchain_data.js +239 -1
- package/dist/browser/checkout/sdk.js +6 -6
- package/dist/browser/checkout/widgets.js +61 -61
- package/dist/checkout.d.ts +5 -3
- package/dist/checkout.js +913 -19
- package/dist/config.d.ts +2 -2
- package/dist/config.js +265 -0
- package/dist/index.browser.js +12 -12
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +920 -21
- package/dist/index.d.ts +5 -3
- package/dist/index.js +920 -21
- package/dist/orderbook.d.ts +2 -2
- package/dist/orderbook.js +238 -0
- package/dist/passport.d.ts +2 -2
- package/dist/passport.js +240 -2
- package/dist/x.d.ts +2 -2
- package/dist/x.js +240 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -46,6 +46,268 @@ var crypto__namespace = /*#__PURE__*/_interopNamespaceDefault(crypto);
|
|
|
46
46
|
var encUtils__namespace = /*#__PURE__*/_interopNamespaceDefault(encUtils);
|
|
47
47
|
var Uniswap__namespace = /*#__PURE__*/_interopNamespaceDefault(Uniswap);
|
|
48
48
|
|
|
49
|
+
const isNode$1 = () => typeof window === 'undefined';
|
|
50
|
+
const isBrowser$1 = () => !isNode$1();
|
|
51
|
+
|
|
52
|
+
var Detail$1;
|
|
53
|
+
(function (Detail) {
|
|
54
|
+
Detail["RUNTIME_ID"] = "rid";
|
|
55
|
+
Detail["PASSPORT_CLIENT_ID"] = "passportClientId";
|
|
56
|
+
Detail["ENVIRONMENT"] = "env";
|
|
57
|
+
Detail["PUBLISHABLE_API_KEY"] = "pak";
|
|
58
|
+
Detail["IDENTITY"] = "uid";
|
|
59
|
+
Detail["DOMAIN"] = "domain";
|
|
60
|
+
})(Detail$1 || (Detail$1 = {}));
|
|
61
|
+
var Store$1;
|
|
62
|
+
(function (Store) {
|
|
63
|
+
Store["EVENTS"] = "events";
|
|
64
|
+
Store["RUNTIME"] = "runtime";
|
|
65
|
+
})(Store$1 || (Store$1 = {}));
|
|
66
|
+
const POLLING_FREQUENCY$1 = 5000;
|
|
67
|
+
|
|
68
|
+
const IMTBL_API$1 = 'https://api.x.immutable.com';
|
|
69
|
+
async function post$1(path, data) {
|
|
70
|
+
const client = globalAxios$1.create({
|
|
71
|
+
baseURL: IMTBL_API$1,
|
|
72
|
+
});
|
|
73
|
+
const payload = JSON.stringify(data);
|
|
74
|
+
const body = {
|
|
75
|
+
payload: btoa(payload),
|
|
76
|
+
};
|
|
77
|
+
const response = await client.post(path, body);
|
|
78
|
+
return response.data;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Abstraction on localstorage
|
|
83
|
+
*/
|
|
84
|
+
const localStoragePrefix$1 = '__IMX-';
|
|
85
|
+
const hasLocalstorage$1 = () => isBrowser$1() && window.localStorage;
|
|
86
|
+
const parseItem$1 = (payload) => {
|
|
87
|
+
// Try to parse, if can't be parsed assume string
|
|
88
|
+
// and return string
|
|
89
|
+
if (payload === null)
|
|
90
|
+
return undefined;
|
|
91
|
+
try {
|
|
92
|
+
return JSON.parse(payload);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
// Assumes it's a string.
|
|
96
|
+
return payload;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const serialiseItem$1 = (payload) => {
|
|
100
|
+
if (typeof payload === 'string') {
|
|
101
|
+
return payload;
|
|
102
|
+
}
|
|
103
|
+
return JSON.stringify(payload);
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* GenKey will take into account the namespace
|
|
107
|
+
* as well as if being run in the Link, it will tap into the link
|
|
108
|
+
* @param {string} key
|
|
109
|
+
* @returns key
|
|
110
|
+
*/
|
|
111
|
+
const genKey$1 = (key) => `${localStoragePrefix$1}${key}`;
|
|
112
|
+
function getItem$1(key) {
|
|
113
|
+
if (hasLocalstorage$1()) {
|
|
114
|
+
return parseItem$1(window.localStorage.getItem(genKey$1(key)));
|
|
115
|
+
}
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
const setItem$1 = (key, payload) => {
|
|
119
|
+
if (hasLocalstorage$1()) {
|
|
120
|
+
window.localStorage.setItem(genKey$1(key), serialiseItem$1(payload));
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// In memory storage for events and other data
|
|
127
|
+
let EVENT_STORE$1;
|
|
128
|
+
let RUNTIME_DETAILS$1;
|
|
129
|
+
// Initialise store and runtime
|
|
130
|
+
const initialise$1$1 = () => {
|
|
131
|
+
EVENT_STORE$1 = getItem$1(Store$1.EVENTS) || [];
|
|
132
|
+
RUNTIME_DETAILS$1 = getItem$1(Store$1.RUNTIME) || {};
|
|
133
|
+
};
|
|
134
|
+
initialise$1$1();
|
|
135
|
+
// Runtime Details
|
|
136
|
+
const storeDetail$1 = (key, value) => {
|
|
137
|
+
RUNTIME_DETAILS$1 = {
|
|
138
|
+
...RUNTIME_DETAILS$1,
|
|
139
|
+
[key]: value,
|
|
140
|
+
};
|
|
141
|
+
setItem$1(Store$1.RUNTIME, RUNTIME_DETAILS$1);
|
|
142
|
+
};
|
|
143
|
+
const getDetail$1 = (key) => {
|
|
144
|
+
// Handle the scenario where detail is a falsy value
|
|
145
|
+
if (RUNTIME_DETAILS$1[key] === undefined) {
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
return RUNTIME_DETAILS$1[key];
|
|
149
|
+
};
|
|
150
|
+
const getAllDetails$1 = () => RUNTIME_DETAILS$1;
|
|
151
|
+
// Events
|
|
152
|
+
const getEvents$1 = () => EVENT_STORE$1;
|
|
153
|
+
const addEvent = (event) => {
|
|
154
|
+
EVENT_STORE$1.push(event);
|
|
155
|
+
setItem$1(Store$1.EVENTS, EVENT_STORE$1);
|
|
156
|
+
};
|
|
157
|
+
const removeSentEvents$1 = (numberOfEvents) => {
|
|
158
|
+
EVENT_STORE$1 = EVENT_STORE$1.slice(numberOfEvents);
|
|
159
|
+
setItem$1(Store$1.EVENTS, EVENT_STORE$1);
|
|
160
|
+
};
|
|
161
|
+
const flattenProperties$1 = (properties) => {
|
|
162
|
+
const propertyMap = [];
|
|
163
|
+
Object.entries(properties).forEach(([key, value]) => {
|
|
164
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
165
|
+
propertyMap.push([key, value.toString()]);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
return propertyMap;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
let initialised$1 = false;
|
|
172
|
+
const isInitialised$1 = () => initialised$1;
|
|
173
|
+
const getReferrer$1 = () => {
|
|
174
|
+
if (isNode$1()) {
|
|
175
|
+
return '';
|
|
176
|
+
}
|
|
177
|
+
if (window.location.ancestorOrigins
|
|
178
|
+
&& window.location.ancestorOrigins.length > 0) {
|
|
179
|
+
return new URL(window.location.ancestorOrigins[0]).hostname;
|
|
180
|
+
}
|
|
181
|
+
return document.referrer ? new URL(window.document.referrer).hostname : '';
|
|
182
|
+
};
|
|
183
|
+
const runtimeHost$1 = () => {
|
|
184
|
+
if (isNode$1()) {
|
|
185
|
+
return '';
|
|
186
|
+
}
|
|
187
|
+
if (window.opener || window.parent !== window) {
|
|
188
|
+
return getReferrer$1();
|
|
189
|
+
}
|
|
190
|
+
return new URL(window.location.href).hostname;
|
|
191
|
+
};
|
|
192
|
+
const getRuntimeDetails$1 = () => {
|
|
193
|
+
if (isNode$1()) {
|
|
194
|
+
return { browser: 'nodejs' };
|
|
195
|
+
}
|
|
196
|
+
const domain = runtimeHost$1();
|
|
197
|
+
if (domain) {
|
|
198
|
+
storeDetail$1(Detail$1.DOMAIN, domain);
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
browser: window.navigator.userAgent,
|
|
202
|
+
domain,
|
|
203
|
+
tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
204
|
+
screen: `${window.screen.width}x${window.screen.height}`,
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
const initialise$2 = async () => {
|
|
208
|
+
const runtimeDetails = flattenProperties$1(getRuntimeDetails$1());
|
|
209
|
+
// Get any existing runtimeId and send it along with the initialise
|
|
210
|
+
const existingRuntimeId = getDetail$1(Detail$1.RUNTIME_ID);
|
|
211
|
+
const body = {
|
|
212
|
+
version: 1,
|
|
213
|
+
data: {
|
|
214
|
+
runtimeDetails,
|
|
215
|
+
runtimeId: existingRuntimeId,
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
const response = await post$1('/v1/sdk/initialise', body);
|
|
219
|
+
// Get runtimeId and store it
|
|
220
|
+
const { runtimeId } = response;
|
|
221
|
+
storeDetail$1(Detail$1.RUNTIME_ID, runtimeId);
|
|
222
|
+
initialised$1 = true;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
function errorBoundary$1(fn) {
|
|
226
|
+
const wrappedFunction = ((...args) => {
|
|
227
|
+
try {
|
|
228
|
+
// Execute the original function
|
|
229
|
+
const result = fn(...args);
|
|
230
|
+
if (result instanceof Promise) {
|
|
231
|
+
// Silent fail for now, in future
|
|
232
|
+
// we can send errors to a logging service
|
|
233
|
+
return result.catch(() => undefined);
|
|
234
|
+
}
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
// As above, fail silently for now
|
|
239
|
+
return undefined;
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
return wrappedFunction;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function isTestEnvironment$1() {
|
|
246
|
+
if (typeof process === 'undefined') {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
return process.env.JEST_WORKER_ID !== undefined;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Store the event in the event store
|
|
253
|
+
const trackFn = (moduleName, eventName, properties) => {
|
|
254
|
+
const event = {
|
|
255
|
+
event: `${moduleName}.${eventName}`,
|
|
256
|
+
time: new Date().toISOString(),
|
|
257
|
+
...(properties && { properties: flattenProperties$1(properties) }),
|
|
258
|
+
};
|
|
259
|
+
addEvent(event);
|
|
260
|
+
};
|
|
261
|
+
const track = errorBoundary$1(trackFn);
|
|
262
|
+
// Sending events to the server
|
|
263
|
+
const flushFn$1 = async () => {
|
|
264
|
+
// Don't flush if not initialised
|
|
265
|
+
if (isInitialised$1() === false) {
|
|
266
|
+
await initialise$2();
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
const events = getEvents$1();
|
|
270
|
+
if (events.length === 0) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
// Track events length here, incase
|
|
274
|
+
const numEvents = events.length;
|
|
275
|
+
// Get details and send it with the track request
|
|
276
|
+
const details = getAllDetails$1();
|
|
277
|
+
const metricsPayload = {
|
|
278
|
+
version: 1,
|
|
279
|
+
data: {
|
|
280
|
+
events,
|
|
281
|
+
details,
|
|
282
|
+
},
|
|
283
|
+
};
|
|
284
|
+
const response = await post$1('/v1/sdk/metrics', metricsPayload);
|
|
285
|
+
if (response instanceof Error) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
// Clear events if successfully posted
|
|
289
|
+
removeSentEvents$1(numEvents);
|
|
290
|
+
};
|
|
291
|
+
const flush$1 = errorBoundary$1(flushFn$1);
|
|
292
|
+
// Flush events every 5 seconds
|
|
293
|
+
const flushPoll$1 = async () => {
|
|
294
|
+
await flush$1();
|
|
295
|
+
setTimeout(flushPoll$1, POLLING_FREQUENCY$1);
|
|
296
|
+
};
|
|
297
|
+
// This will get initialised when module is imported.
|
|
298
|
+
if (!isTestEnvironment$1()) {
|
|
299
|
+
errorBoundary$1(flushPoll$1)();
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const setEnvironmentFn = (env) => {
|
|
303
|
+
storeDetail$1(Detail$1.ENVIRONMENT, env);
|
|
304
|
+
};
|
|
305
|
+
const setEnvironment = errorBoundary$1(setEnvironmentFn);
|
|
306
|
+
const setPublishableApiKeyFn = (publishableApiKey) => {
|
|
307
|
+
storeDetail$1(Detail$1.PUBLISHABLE_API_KEY, publishableApiKey);
|
|
308
|
+
};
|
|
309
|
+
const setPublishableApiKey = errorBoundary$1(setPublishableApiKeyFn);
|
|
310
|
+
|
|
49
311
|
var Environment$1;
|
|
50
312
|
(function (Environment) {
|
|
51
313
|
Environment["PRODUCTION"] = "production";
|
|
@@ -58,6 +320,8 @@ class ImmutableConfiguration {
|
|
|
58
320
|
publishableKey;
|
|
59
321
|
constructor(options) {
|
|
60
322
|
this.environment = options.environment;
|
|
323
|
+
setEnvironment(options.environment);
|
|
324
|
+
track('config', 'load_imtbl_config');
|
|
61
325
|
}
|
|
62
326
|
}
|
|
63
327
|
const API_KEY_PREFIX = 'sk_imapik-';
|
|
@@ -73,6 +337,7 @@ const addPublishableKeyToAxiosHeader = (publishableKey) => {
|
|
|
73
337
|
throw new Error('Invalid Publishable key. Create your Publishable key in Immutable developer hub.'
|
|
74
338
|
+ ' https://hub.immutable.com');
|
|
75
339
|
}
|
|
340
|
+
setPublishableApiKey(publishableKey);
|
|
76
341
|
globalAxios$1.defaults.headers.common['x-immutable-publishable-key'] = publishableKey;
|
|
77
342
|
};
|
|
78
343
|
const addRateLimitingKeyToAxiosHeader = (rateLimitingKey) => {
|
|
@@ -10641,7 +10906,7 @@ class MultiRollupApiClients {
|
|
|
10641
10906
|
}
|
|
10642
10907
|
|
|
10643
10908
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
10644
|
-
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.45.
|
|
10909
|
+
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.45.3-alpha' };
|
|
10645
10910
|
const createConfig = ({ basePath, headers, }) => {
|
|
10646
10911
|
if (!basePath.trim()) {
|
|
10647
10912
|
throw Error('basePath can not be empty');
|
|
@@ -10713,7 +10978,7 @@ class APIError extends Error {
|
|
|
10713
10978
|
|
|
10714
10979
|
/* eslint-disable implicit-arrow-linebreak */
|
|
10715
10980
|
const defaultHeaders = {
|
|
10716
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.45.
|
|
10981
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.45.3-alpha',
|
|
10717
10982
|
};
|
|
10718
10983
|
/**
|
|
10719
10984
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -11152,7 +11417,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
11152
11417
|
chainID,
|
|
11153
11418
|
coreContractAddress,
|
|
11154
11419
|
registrationContractAddress,
|
|
11155
|
-
sdkVersion: 'ts-immutable-sdk-0.45.
|
|
11420
|
+
sdkVersion: 'ts-immutable-sdk-0.45.3-alpha',
|
|
11156
11421
|
});
|
|
11157
11422
|
/**
|
|
11158
11423
|
* Sets `sdkVersion` at the time of build
|
|
@@ -36306,6 +36571,244 @@ class TokenBridge {
|
|
|
36306
36571
|
}
|
|
36307
36572
|
}
|
|
36308
36573
|
|
|
36574
|
+
const isNode = () => typeof window === 'undefined';
|
|
36575
|
+
const isBrowser = () => !isNode();
|
|
36576
|
+
|
|
36577
|
+
var Detail;
|
|
36578
|
+
(function (Detail) {
|
|
36579
|
+
Detail["RUNTIME_ID"] = "rid";
|
|
36580
|
+
Detail["PASSPORT_CLIENT_ID"] = "passportClientId";
|
|
36581
|
+
Detail["ENVIRONMENT"] = "env";
|
|
36582
|
+
Detail["PUBLISHABLE_API_KEY"] = "pak";
|
|
36583
|
+
Detail["IDENTITY"] = "uid";
|
|
36584
|
+
Detail["DOMAIN"] = "domain";
|
|
36585
|
+
})(Detail || (Detail = {}));
|
|
36586
|
+
var Store;
|
|
36587
|
+
(function (Store) {
|
|
36588
|
+
Store["EVENTS"] = "events";
|
|
36589
|
+
Store["RUNTIME"] = "runtime";
|
|
36590
|
+
})(Store || (Store = {}));
|
|
36591
|
+
const POLLING_FREQUENCY = 5000;
|
|
36592
|
+
|
|
36593
|
+
const IMTBL_API = 'https://api.x.immutable.com';
|
|
36594
|
+
async function post(path, data) {
|
|
36595
|
+
const client = axios$1.create({
|
|
36596
|
+
baseURL: IMTBL_API,
|
|
36597
|
+
});
|
|
36598
|
+
const payload = JSON.stringify(data);
|
|
36599
|
+
const body = {
|
|
36600
|
+
payload: btoa(payload),
|
|
36601
|
+
};
|
|
36602
|
+
const response = await client.post(path, body);
|
|
36603
|
+
return response.data;
|
|
36604
|
+
}
|
|
36605
|
+
|
|
36606
|
+
/**
|
|
36607
|
+
* Abstraction on localstorage
|
|
36608
|
+
*/
|
|
36609
|
+
const localStoragePrefix = '__IMX-';
|
|
36610
|
+
const hasLocalstorage = () => isBrowser() && window.localStorage;
|
|
36611
|
+
const parseItem = (payload) => {
|
|
36612
|
+
// Try to parse, if can't be parsed assume string
|
|
36613
|
+
// and return string
|
|
36614
|
+
if (payload === null)
|
|
36615
|
+
return undefined;
|
|
36616
|
+
try {
|
|
36617
|
+
return JSON.parse(payload);
|
|
36618
|
+
}
|
|
36619
|
+
catch (error) {
|
|
36620
|
+
// Assumes it's a string.
|
|
36621
|
+
return payload;
|
|
36622
|
+
}
|
|
36623
|
+
};
|
|
36624
|
+
const serialiseItem = (payload) => {
|
|
36625
|
+
if (typeof payload === 'string') {
|
|
36626
|
+
return payload;
|
|
36627
|
+
}
|
|
36628
|
+
return JSON.stringify(payload);
|
|
36629
|
+
};
|
|
36630
|
+
/**
|
|
36631
|
+
* GenKey will take into account the namespace
|
|
36632
|
+
* as well as if being run in the Link, it will tap into the link
|
|
36633
|
+
* @param {string} key
|
|
36634
|
+
* @returns key
|
|
36635
|
+
*/
|
|
36636
|
+
const genKey = (key) => `${localStoragePrefix}${key}`;
|
|
36637
|
+
function getItem(key) {
|
|
36638
|
+
if (hasLocalstorage()) {
|
|
36639
|
+
return parseItem(window.localStorage.getItem(genKey(key)));
|
|
36640
|
+
}
|
|
36641
|
+
return undefined;
|
|
36642
|
+
}
|
|
36643
|
+
const setItem = (key, payload) => {
|
|
36644
|
+
if (hasLocalstorage()) {
|
|
36645
|
+
window.localStorage.setItem(genKey(key), serialiseItem(payload));
|
|
36646
|
+
return true;
|
|
36647
|
+
}
|
|
36648
|
+
return false;
|
|
36649
|
+
};
|
|
36650
|
+
|
|
36651
|
+
// In memory storage for events and other data
|
|
36652
|
+
let EVENT_STORE;
|
|
36653
|
+
let RUNTIME_DETAILS;
|
|
36654
|
+
// Initialise store and runtime
|
|
36655
|
+
const initialise$1 = () => {
|
|
36656
|
+
EVENT_STORE = getItem(Store.EVENTS) || [];
|
|
36657
|
+
RUNTIME_DETAILS = getItem(Store.RUNTIME) || {};
|
|
36658
|
+
};
|
|
36659
|
+
initialise$1();
|
|
36660
|
+
// Runtime Details
|
|
36661
|
+
const storeDetail = (key, value) => {
|
|
36662
|
+
RUNTIME_DETAILS = {
|
|
36663
|
+
...RUNTIME_DETAILS,
|
|
36664
|
+
[key]: value,
|
|
36665
|
+
};
|
|
36666
|
+
setItem(Store.RUNTIME, RUNTIME_DETAILS);
|
|
36667
|
+
};
|
|
36668
|
+
const getDetail = (key) => {
|
|
36669
|
+
// Handle the scenario where detail is a falsy value
|
|
36670
|
+
if (RUNTIME_DETAILS[key] === undefined) {
|
|
36671
|
+
return undefined;
|
|
36672
|
+
}
|
|
36673
|
+
return RUNTIME_DETAILS[key];
|
|
36674
|
+
};
|
|
36675
|
+
const getAllDetails = () => RUNTIME_DETAILS;
|
|
36676
|
+
// Events
|
|
36677
|
+
const getEvents = () => EVENT_STORE;
|
|
36678
|
+
const removeSentEvents = (numberOfEvents) => {
|
|
36679
|
+
EVENT_STORE = EVENT_STORE.slice(numberOfEvents);
|
|
36680
|
+
setItem(Store.EVENTS, EVENT_STORE);
|
|
36681
|
+
};
|
|
36682
|
+
const flattenProperties = (properties) => {
|
|
36683
|
+
const propertyMap = [];
|
|
36684
|
+
Object.entries(properties).forEach(([key, value]) => {
|
|
36685
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
36686
|
+
propertyMap.push([key, value.toString()]);
|
|
36687
|
+
}
|
|
36688
|
+
});
|
|
36689
|
+
return propertyMap;
|
|
36690
|
+
};
|
|
36691
|
+
|
|
36692
|
+
let initialised = false;
|
|
36693
|
+
const isInitialised = () => initialised;
|
|
36694
|
+
const getReferrer = () => {
|
|
36695
|
+
if (isNode()) {
|
|
36696
|
+
return '';
|
|
36697
|
+
}
|
|
36698
|
+
if (window.location.ancestorOrigins
|
|
36699
|
+
&& window.location.ancestorOrigins.length > 0) {
|
|
36700
|
+
return new URL(window.location.ancestorOrigins[0]).hostname;
|
|
36701
|
+
}
|
|
36702
|
+
return document.referrer ? new URL(window.document.referrer).hostname : '';
|
|
36703
|
+
};
|
|
36704
|
+
const runtimeHost = () => {
|
|
36705
|
+
if (isNode()) {
|
|
36706
|
+
return '';
|
|
36707
|
+
}
|
|
36708
|
+
if (window.opener || window.parent !== window) {
|
|
36709
|
+
return getReferrer();
|
|
36710
|
+
}
|
|
36711
|
+
return new URL(window.location.href).hostname;
|
|
36712
|
+
};
|
|
36713
|
+
const getRuntimeDetails = () => {
|
|
36714
|
+
if (isNode()) {
|
|
36715
|
+
return { browser: 'nodejs' };
|
|
36716
|
+
}
|
|
36717
|
+
const domain = runtimeHost();
|
|
36718
|
+
if (domain) {
|
|
36719
|
+
storeDetail(Detail.DOMAIN, domain);
|
|
36720
|
+
}
|
|
36721
|
+
return {
|
|
36722
|
+
browser: window.navigator.userAgent,
|
|
36723
|
+
domain,
|
|
36724
|
+
tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
36725
|
+
screen: `${window.screen.width}x${window.screen.height}`,
|
|
36726
|
+
};
|
|
36727
|
+
};
|
|
36728
|
+
const initialise = async () => {
|
|
36729
|
+
const runtimeDetails = flattenProperties(getRuntimeDetails());
|
|
36730
|
+
// Get any existing runtimeId and send it along with the initialise
|
|
36731
|
+
const existingRuntimeId = getDetail(Detail.RUNTIME_ID);
|
|
36732
|
+
const body = {
|
|
36733
|
+
version: 1,
|
|
36734
|
+
data: {
|
|
36735
|
+
runtimeDetails,
|
|
36736
|
+
runtimeId: existingRuntimeId,
|
|
36737
|
+
},
|
|
36738
|
+
};
|
|
36739
|
+
const response = await post('/v1/sdk/initialise', body);
|
|
36740
|
+
// Get runtimeId and store it
|
|
36741
|
+
const { runtimeId } = response;
|
|
36742
|
+
storeDetail(Detail.RUNTIME_ID, runtimeId);
|
|
36743
|
+
initialised = true;
|
|
36744
|
+
};
|
|
36745
|
+
|
|
36746
|
+
function errorBoundary(fn) {
|
|
36747
|
+
const wrappedFunction = ((...args) => {
|
|
36748
|
+
try {
|
|
36749
|
+
// Execute the original function
|
|
36750
|
+
const result = fn(...args);
|
|
36751
|
+
if (result instanceof Promise) {
|
|
36752
|
+
// Silent fail for now, in future
|
|
36753
|
+
// we can send errors to a logging service
|
|
36754
|
+
return result.catch(() => undefined);
|
|
36755
|
+
}
|
|
36756
|
+
return result;
|
|
36757
|
+
}
|
|
36758
|
+
catch (error) {
|
|
36759
|
+
// As above, fail silently for now
|
|
36760
|
+
return undefined;
|
|
36761
|
+
}
|
|
36762
|
+
});
|
|
36763
|
+
return wrappedFunction;
|
|
36764
|
+
}
|
|
36765
|
+
|
|
36766
|
+
function isTestEnvironment() {
|
|
36767
|
+
if (typeof process === 'undefined') {
|
|
36768
|
+
return false;
|
|
36769
|
+
}
|
|
36770
|
+
return process.env.JEST_WORKER_ID !== undefined;
|
|
36771
|
+
}
|
|
36772
|
+
// Sending events to the server
|
|
36773
|
+
const flushFn = async () => {
|
|
36774
|
+
// Don't flush if not initialised
|
|
36775
|
+
if (isInitialised() === false) {
|
|
36776
|
+
await initialise();
|
|
36777
|
+
return;
|
|
36778
|
+
}
|
|
36779
|
+
const events = getEvents();
|
|
36780
|
+
if (events.length === 0) {
|
|
36781
|
+
return;
|
|
36782
|
+
}
|
|
36783
|
+
// Track events length here, incase
|
|
36784
|
+
const numEvents = events.length;
|
|
36785
|
+
// Get details and send it with the track request
|
|
36786
|
+
const details = getAllDetails();
|
|
36787
|
+
const metricsPayload = {
|
|
36788
|
+
version: 1,
|
|
36789
|
+
data: {
|
|
36790
|
+
events,
|
|
36791
|
+
details,
|
|
36792
|
+
},
|
|
36793
|
+
};
|
|
36794
|
+
const response = await post('/v1/sdk/metrics', metricsPayload);
|
|
36795
|
+
if (response instanceof Error) {
|
|
36796
|
+
return;
|
|
36797
|
+
}
|
|
36798
|
+
// Clear events if successfully posted
|
|
36799
|
+
removeSentEvents(numEvents);
|
|
36800
|
+
};
|
|
36801
|
+
const flush = errorBoundary(flushFn);
|
|
36802
|
+
// Flush events every 5 seconds
|
|
36803
|
+
const flushPoll = async () => {
|
|
36804
|
+
await flush();
|
|
36805
|
+
setTimeout(flushPoll, POLLING_FREQUENCY);
|
|
36806
|
+
};
|
|
36807
|
+
// This will get initialised when module is imported.
|
|
36808
|
+
if (!isTestEnvironment()) {
|
|
36809
|
+
errorBoundary(flushPoll)();
|
|
36810
|
+
}
|
|
36811
|
+
|
|
36309
36812
|
var Environment;
|
|
36310
36813
|
(function (Environment) {
|
|
36311
36814
|
Environment["PRODUCTION"] = "production";
|
|
@@ -36482,7 +36985,7 @@ class ApproveError extends ExchangeError {
|
|
|
36482
36985
|
/* Autogenerated file. Do not edit manually. */
|
|
36483
36986
|
/* tslint:disable */
|
|
36484
36987
|
/* eslint-disable */
|
|
36485
|
-
const _abi$
|
|
36988
|
+
const _abi$4 = [
|
|
36486
36989
|
{
|
|
36487
36990
|
constant: true,
|
|
36488
36991
|
inputs: [],
|
|
@@ -36705,19 +37208,19 @@ const _abi$3 = [
|
|
|
36705
37208
|
},
|
|
36706
37209
|
];
|
|
36707
37210
|
class ERC20__factory {
|
|
36708
|
-
static abi = _abi$
|
|
37211
|
+
static abi = _abi$4;
|
|
36709
37212
|
static createInterface() {
|
|
36710
|
-
return new ethers.utils.Interface(_abi$
|
|
37213
|
+
return new ethers.utils.Interface(_abi$4);
|
|
36711
37214
|
}
|
|
36712
37215
|
static connect(address, signerOrProvider) {
|
|
36713
|
-
return new ethers.Contract(address, _abi$
|
|
37216
|
+
return new ethers.Contract(address, _abi$4, signerOrProvider);
|
|
36714
37217
|
}
|
|
36715
37218
|
}
|
|
36716
37219
|
|
|
36717
37220
|
/* Autogenerated file. Do not edit manually. */
|
|
36718
37221
|
/* tslint:disable */
|
|
36719
37222
|
/* eslint-disable */
|
|
36720
|
-
const _abi$
|
|
37223
|
+
const _abi$3 = [
|
|
36721
37224
|
{
|
|
36722
37225
|
inputs: [
|
|
36723
37226
|
{
|
|
@@ -37491,7 +37994,7 @@ class ImmutableSwapProxy__factory extends ethers.ContractFactory {
|
|
|
37491
37994
|
super(...args);
|
|
37492
37995
|
}
|
|
37493
37996
|
else {
|
|
37494
|
-
super(_abi$
|
|
37997
|
+
super(_abi$3, _bytecode$2, args[0]);
|
|
37495
37998
|
}
|
|
37496
37999
|
}
|
|
37497
38000
|
deploy(_admin, _uniRouter, _wimx, overrides) {
|
|
@@ -37507,19 +38010,19 @@ class ImmutableSwapProxy__factory extends ethers.ContractFactory {
|
|
|
37507
38010
|
return super.connect(signer);
|
|
37508
38011
|
}
|
|
37509
38012
|
static bytecode = _bytecode$2;
|
|
37510
|
-
static abi = _abi$
|
|
38013
|
+
static abi = _abi$3;
|
|
37511
38014
|
static createInterface() {
|
|
37512
|
-
return new ethers.utils.Interface(_abi$
|
|
38015
|
+
return new ethers.utils.Interface(_abi$3);
|
|
37513
38016
|
}
|
|
37514
38017
|
static connect(address, signerOrProvider) {
|
|
37515
|
-
return new ethers.Contract(address, _abi$
|
|
38018
|
+
return new ethers.Contract(address, _abi$3, signerOrProvider);
|
|
37516
38019
|
}
|
|
37517
38020
|
}
|
|
37518
38021
|
|
|
37519
38022
|
/* Autogenerated file. Do not edit manually. */
|
|
37520
38023
|
/* tslint:disable */
|
|
37521
38024
|
/* eslint-disable */
|
|
37522
|
-
const _abi$
|
|
38025
|
+
const _abi$2 = [
|
|
37523
38026
|
{
|
|
37524
38027
|
inputs: [],
|
|
37525
38028
|
name: "getCurrentBlockTimestamp",
|
|
@@ -37619,7 +38122,7 @@ class Multicall__factory extends ethers.ContractFactory {
|
|
|
37619
38122
|
super(...args);
|
|
37620
38123
|
}
|
|
37621
38124
|
else {
|
|
37622
|
-
super(_abi$
|
|
38125
|
+
super(_abi$2, _bytecode$1, args[0]);
|
|
37623
38126
|
}
|
|
37624
38127
|
}
|
|
37625
38128
|
deploy(overrides) {
|
|
@@ -37635,19 +38138,19 @@ class Multicall__factory extends ethers.ContractFactory {
|
|
|
37635
38138
|
return super.connect(signer);
|
|
37636
38139
|
}
|
|
37637
38140
|
static bytecode = _bytecode$1;
|
|
37638
|
-
static abi = _abi$
|
|
38141
|
+
static abi = _abi$2;
|
|
37639
38142
|
static createInterface() {
|
|
37640
|
-
return new ethers.utils.Interface(_abi$
|
|
38143
|
+
return new ethers.utils.Interface(_abi$2);
|
|
37641
38144
|
}
|
|
37642
38145
|
static connect(address, signerOrProvider) {
|
|
37643
|
-
return new ethers.Contract(address, _abi$
|
|
38146
|
+
return new ethers.Contract(address, _abi$2, signerOrProvider);
|
|
37644
38147
|
}
|
|
37645
38148
|
}
|
|
37646
38149
|
|
|
37647
38150
|
/* Autogenerated file. Do not edit manually. */
|
|
37648
38151
|
/* tslint:disable */
|
|
37649
38152
|
/* eslint-disable */
|
|
37650
|
-
const _abi = [
|
|
38153
|
+
const _abi$1 = [
|
|
37651
38154
|
{
|
|
37652
38155
|
inputs: [],
|
|
37653
38156
|
stateMutability: "nonpayable",
|
|
@@ -38643,7 +39146,7 @@ class UniswapV3Pool__factory extends ethers.ContractFactory {
|
|
|
38643
39146
|
super(...args);
|
|
38644
39147
|
}
|
|
38645
39148
|
else {
|
|
38646
|
-
super(_abi, _bytecode, args[0]);
|
|
39149
|
+
super(_abi$1, _bytecode, args[0]);
|
|
38647
39150
|
}
|
|
38648
39151
|
}
|
|
38649
39152
|
deploy(overrides) {
|
|
@@ -38659,6 +39162,298 @@ class UniswapV3Pool__factory extends ethers.ContractFactory {
|
|
|
38659
39162
|
return super.connect(signer);
|
|
38660
39163
|
}
|
|
38661
39164
|
static bytecode = _bytecode;
|
|
39165
|
+
static abi = _abi$1;
|
|
39166
|
+
static createInterface() {
|
|
39167
|
+
return new ethers.utils.Interface(_abi$1);
|
|
39168
|
+
}
|
|
39169
|
+
static connect(address, signerOrProvider) {
|
|
39170
|
+
return new ethers.Contract(address, _abi$1, signerOrProvider);
|
|
39171
|
+
}
|
|
39172
|
+
}
|
|
39173
|
+
|
|
39174
|
+
/* Autogenerated file. Do not edit manually. */
|
|
39175
|
+
/* tslint:disable */
|
|
39176
|
+
/* eslint-disable */
|
|
39177
|
+
const _abi = [
|
|
39178
|
+
{
|
|
39179
|
+
constant: true,
|
|
39180
|
+
inputs: [],
|
|
39181
|
+
name: "name",
|
|
39182
|
+
outputs: [
|
|
39183
|
+
{
|
|
39184
|
+
name: "",
|
|
39185
|
+
type: "string",
|
|
39186
|
+
},
|
|
39187
|
+
],
|
|
39188
|
+
payable: false,
|
|
39189
|
+
stateMutability: "view",
|
|
39190
|
+
type: "function",
|
|
39191
|
+
},
|
|
39192
|
+
{
|
|
39193
|
+
constant: false,
|
|
39194
|
+
inputs: [
|
|
39195
|
+
{
|
|
39196
|
+
name: "guy",
|
|
39197
|
+
type: "address",
|
|
39198
|
+
},
|
|
39199
|
+
{
|
|
39200
|
+
name: "wad",
|
|
39201
|
+
type: "uint256",
|
|
39202
|
+
},
|
|
39203
|
+
],
|
|
39204
|
+
name: "approve",
|
|
39205
|
+
outputs: [
|
|
39206
|
+
{
|
|
39207
|
+
name: "",
|
|
39208
|
+
type: "bool",
|
|
39209
|
+
},
|
|
39210
|
+
],
|
|
39211
|
+
payable: false,
|
|
39212
|
+
stateMutability: "nonpayable",
|
|
39213
|
+
type: "function",
|
|
39214
|
+
},
|
|
39215
|
+
{
|
|
39216
|
+
constant: true,
|
|
39217
|
+
inputs: [],
|
|
39218
|
+
name: "totalSupply",
|
|
39219
|
+
outputs: [
|
|
39220
|
+
{
|
|
39221
|
+
name: "",
|
|
39222
|
+
type: "uint256",
|
|
39223
|
+
},
|
|
39224
|
+
],
|
|
39225
|
+
payable: false,
|
|
39226
|
+
stateMutability: "view",
|
|
39227
|
+
type: "function",
|
|
39228
|
+
},
|
|
39229
|
+
{
|
|
39230
|
+
constant: false,
|
|
39231
|
+
inputs: [
|
|
39232
|
+
{
|
|
39233
|
+
name: "src",
|
|
39234
|
+
type: "address",
|
|
39235
|
+
},
|
|
39236
|
+
{
|
|
39237
|
+
name: "dst",
|
|
39238
|
+
type: "address",
|
|
39239
|
+
},
|
|
39240
|
+
{
|
|
39241
|
+
name: "wad",
|
|
39242
|
+
type: "uint256",
|
|
39243
|
+
},
|
|
39244
|
+
],
|
|
39245
|
+
name: "transferFrom",
|
|
39246
|
+
outputs: [
|
|
39247
|
+
{
|
|
39248
|
+
name: "",
|
|
39249
|
+
type: "bool",
|
|
39250
|
+
},
|
|
39251
|
+
],
|
|
39252
|
+
payable: false,
|
|
39253
|
+
stateMutability: "nonpayable",
|
|
39254
|
+
type: "function",
|
|
39255
|
+
},
|
|
39256
|
+
{
|
|
39257
|
+
constant: false,
|
|
39258
|
+
inputs: [
|
|
39259
|
+
{
|
|
39260
|
+
name: "wad",
|
|
39261
|
+
type: "uint256",
|
|
39262
|
+
},
|
|
39263
|
+
],
|
|
39264
|
+
name: "withdraw",
|
|
39265
|
+
outputs: [],
|
|
39266
|
+
payable: false,
|
|
39267
|
+
stateMutability: "nonpayable",
|
|
39268
|
+
type: "function",
|
|
39269
|
+
},
|
|
39270
|
+
{
|
|
39271
|
+
constant: true,
|
|
39272
|
+
inputs: [],
|
|
39273
|
+
name: "decimals",
|
|
39274
|
+
outputs: [
|
|
39275
|
+
{
|
|
39276
|
+
name: "",
|
|
39277
|
+
type: "uint8",
|
|
39278
|
+
},
|
|
39279
|
+
],
|
|
39280
|
+
payable: false,
|
|
39281
|
+
stateMutability: "view",
|
|
39282
|
+
type: "function",
|
|
39283
|
+
},
|
|
39284
|
+
{
|
|
39285
|
+
constant: true,
|
|
39286
|
+
inputs: [
|
|
39287
|
+
{
|
|
39288
|
+
name: "",
|
|
39289
|
+
type: "address",
|
|
39290
|
+
},
|
|
39291
|
+
],
|
|
39292
|
+
name: "balanceOf",
|
|
39293
|
+
outputs: [
|
|
39294
|
+
{
|
|
39295
|
+
name: "",
|
|
39296
|
+
type: "uint256",
|
|
39297
|
+
},
|
|
39298
|
+
],
|
|
39299
|
+
payable: false,
|
|
39300
|
+
stateMutability: "view",
|
|
39301
|
+
type: "function",
|
|
39302
|
+
},
|
|
39303
|
+
{
|
|
39304
|
+
constant: true,
|
|
39305
|
+
inputs: [],
|
|
39306
|
+
name: "symbol",
|
|
39307
|
+
outputs: [
|
|
39308
|
+
{
|
|
39309
|
+
name: "",
|
|
39310
|
+
type: "string",
|
|
39311
|
+
},
|
|
39312
|
+
],
|
|
39313
|
+
payable: false,
|
|
39314
|
+
stateMutability: "view",
|
|
39315
|
+
type: "function",
|
|
39316
|
+
},
|
|
39317
|
+
{
|
|
39318
|
+
constant: false,
|
|
39319
|
+
inputs: [
|
|
39320
|
+
{
|
|
39321
|
+
name: "dst",
|
|
39322
|
+
type: "address",
|
|
39323
|
+
},
|
|
39324
|
+
{
|
|
39325
|
+
name: "wad",
|
|
39326
|
+
type: "uint256",
|
|
39327
|
+
},
|
|
39328
|
+
],
|
|
39329
|
+
name: "transfer",
|
|
39330
|
+
outputs: [
|
|
39331
|
+
{
|
|
39332
|
+
name: "",
|
|
39333
|
+
type: "bool",
|
|
39334
|
+
},
|
|
39335
|
+
],
|
|
39336
|
+
payable: false,
|
|
39337
|
+
stateMutability: "nonpayable",
|
|
39338
|
+
type: "function",
|
|
39339
|
+
},
|
|
39340
|
+
{
|
|
39341
|
+
constant: false,
|
|
39342
|
+
inputs: [],
|
|
39343
|
+
name: "deposit",
|
|
39344
|
+
outputs: [],
|
|
39345
|
+
payable: true,
|
|
39346
|
+
stateMutability: "payable",
|
|
39347
|
+
type: "function",
|
|
39348
|
+
},
|
|
39349
|
+
{
|
|
39350
|
+
constant: true,
|
|
39351
|
+
inputs: [
|
|
39352
|
+
{
|
|
39353
|
+
name: "",
|
|
39354
|
+
type: "address",
|
|
39355
|
+
},
|
|
39356
|
+
{
|
|
39357
|
+
name: "",
|
|
39358
|
+
type: "address",
|
|
39359
|
+
},
|
|
39360
|
+
],
|
|
39361
|
+
name: "allowance",
|
|
39362
|
+
outputs: [
|
|
39363
|
+
{
|
|
39364
|
+
name: "",
|
|
39365
|
+
type: "uint256",
|
|
39366
|
+
},
|
|
39367
|
+
],
|
|
39368
|
+
payable: false,
|
|
39369
|
+
stateMutability: "view",
|
|
39370
|
+
type: "function",
|
|
39371
|
+
},
|
|
39372
|
+
{
|
|
39373
|
+
payable: true,
|
|
39374
|
+
stateMutability: "payable",
|
|
39375
|
+
type: "fallback",
|
|
39376
|
+
},
|
|
39377
|
+
{
|
|
39378
|
+
anonymous: false,
|
|
39379
|
+
inputs: [
|
|
39380
|
+
{
|
|
39381
|
+
indexed: true,
|
|
39382
|
+
name: "src",
|
|
39383
|
+
type: "address",
|
|
39384
|
+
},
|
|
39385
|
+
{
|
|
39386
|
+
indexed: true,
|
|
39387
|
+
name: "guy",
|
|
39388
|
+
type: "address",
|
|
39389
|
+
},
|
|
39390
|
+
{
|
|
39391
|
+
indexed: false,
|
|
39392
|
+
name: "wad",
|
|
39393
|
+
type: "uint256",
|
|
39394
|
+
},
|
|
39395
|
+
],
|
|
39396
|
+
name: "Approval",
|
|
39397
|
+
type: "event",
|
|
39398
|
+
},
|
|
39399
|
+
{
|
|
39400
|
+
anonymous: false,
|
|
39401
|
+
inputs: [
|
|
39402
|
+
{
|
|
39403
|
+
indexed: true,
|
|
39404
|
+
name: "src",
|
|
39405
|
+
type: "address",
|
|
39406
|
+
},
|
|
39407
|
+
{
|
|
39408
|
+
indexed: true,
|
|
39409
|
+
name: "dst",
|
|
39410
|
+
type: "address",
|
|
39411
|
+
},
|
|
39412
|
+
{
|
|
39413
|
+
indexed: false,
|
|
39414
|
+
name: "wad",
|
|
39415
|
+
type: "uint256",
|
|
39416
|
+
},
|
|
39417
|
+
],
|
|
39418
|
+
name: "Transfer",
|
|
39419
|
+
type: "event",
|
|
39420
|
+
},
|
|
39421
|
+
{
|
|
39422
|
+
anonymous: false,
|
|
39423
|
+
inputs: [
|
|
39424
|
+
{
|
|
39425
|
+
indexed: true,
|
|
39426
|
+
name: "dst",
|
|
39427
|
+
type: "address",
|
|
39428
|
+
},
|
|
39429
|
+
{
|
|
39430
|
+
indexed: false,
|
|
39431
|
+
name: "wad",
|
|
39432
|
+
type: "uint256",
|
|
39433
|
+
},
|
|
39434
|
+
],
|
|
39435
|
+
name: "Deposit",
|
|
39436
|
+
type: "event",
|
|
39437
|
+
},
|
|
39438
|
+
{
|
|
39439
|
+
anonymous: false,
|
|
39440
|
+
inputs: [
|
|
39441
|
+
{
|
|
39442
|
+
indexed: true,
|
|
39443
|
+
name: "src",
|
|
39444
|
+
type: "address",
|
|
39445
|
+
},
|
|
39446
|
+
{
|
|
39447
|
+
indexed: false,
|
|
39448
|
+
name: "wad",
|
|
39449
|
+
type: "uint256",
|
|
39450
|
+
},
|
|
39451
|
+
],
|
|
39452
|
+
name: "Withdrawal",
|
|
39453
|
+
type: "event",
|
|
39454
|
+
},
|
|
39455
|
+
];
|
|
39456
|
+
class WIMX__factory {
|
|
38662
39457
|
static abi = _abi;
|
|
38663
39458
|
static createInterface() {
|
|
38664
39459
|
return new ethers.utils.Interface(_abi);
|
|
@@ -39287,6 +40082,13 @@ class NativeTokenService {
|
|
|
39287
40082
|
maybeWrapAmount(amount) {
|
|
39288
40083
|
return newAmount(amount.value, this.maybeWrapToken(amount.token));
|
|
39289
40084
|
}
|
|
40085
|
+
isWrappedNative(token) {
|
|
40086
|
+
return token.type === 'erc20' && token.address.toLowerCase() === this.wrappedToken.address.toLowerCase();
|
|
40087
|
+
}
|
|
40088
|
+
isWrapOrUnwrap(tokenIn, tokenOut) {
|
|
40089
|
+
return ((tokenIn === this.nativeToken && (this.isWrappedNative(tokenOut))) ||
|
|
40090
|
+
((this.isWrappedNative(tokenIn)) && tokenOut === this.nativeToken));
|
|
40091
|
+
}
|
|
39290
40092
|
}
|
|
39291
40093
|
|
|
39292
40094
|
// slippageToPercent takes the slippage as a percentage (e.g. 0.1) and
|
|
@@ -39385,6 +40187,16 @@ class Fees {
|
|
|
39385
40187
|
}
|
|
39386
40188
|
}
|
|
39387
40189
|
|
|
40190
|
+
// 45038 is the upper bound of the gas estimate for the deposit function.
|
|
40191
|
+
// This upper bound is reached when a user is wrapping for the first time (cold + unused storage slot)
|
|
40192
|
+
// The lower bound is 27,938, so the difference is 17,100 gas. If transactions are 10 gwei IMX,
|
|
40193
|
+
// this is about 0.000171 IMX difference. In order to avoid an extra remote call, we just use the upper bound instead.
|
|
40194
|
+
const IMX_WRAP_GAS_COST = 45038;
|
|
40195
|
+
// 35216 is the upper bound of the gas estimate for the withdraw function.
|
|
40196
|
+
// The differenfce between upper and normal is less than 0.0001 IMX, so we just use the upper bound
|
|
40197
|
+
// to avoid an extra remote call.
|
|
40198
|
+
const IMX_UNWRAP_GAS_COST = 35216;
|
|
40199
|
+
|
|
39388
40200
|
const IMMUTABLE_TESTNET_RPC_URL = 'https://rpc.testnet.immutable.com';
|
|
39389
40201
|
const IMMUTABLE_TESTNET_CHAIN_ID = 13473;
|
|
39390
40202
|
|
|
@@ -39898,6 +40710,67 @@ class Exchange {
|
|
|
39898
40710
|
decimals,
|
|
39899
40711
|
};
|
|
39900
40712
|
}
|
|
40713
|
+
async getUnwrapTransaction(fromAddress, tokenAmount, wimxInterface, gasPrice) {
|
|
40714
|
+
const calldata = wimxInterface.encodeFunctionData('withdraw', [tokenAmount]);
|
|
40715
|
+
const gasEstimate = ethers.ethers.BigNumber.from(IMX_UNWRAP_GAS_COST);
|
|
40716
|
+
const gasFeeEstimate = gasPrice ? toPublicAmount(calculateGasFee(gasPrice, gasEstimate)) : null;
|
|
40717
|
+
// This transaction is for calling calling `withdraw` on the WETH/WIMX contract.
|
|
40718
|
+
const transactionDetails = {
|
|
40719
|
+
transaction: {
|
|
40720
|
+
data: calldata,
|
|
40721
|
+
to: this.wrappedNativeToken.address,
|
|
40722
|
+
from: fromAddress,
|
|
40723
|
+
},
|
|
40724
|
+
gasFeeEstimate,
|
|
40725
|
+
};
|
|
40726
|
+
return {
|
|
40727
|
+
transaction: transactionDetails,
|
|
40728
|
+
approval: null,
|
|
40729
|
+
};
|
|
40730
|
+
}
|
|
40731
|
+
getWrapTransaction(fromAddress, tokenAmount, wimxInterface, gasPrice) {
|
|
40732
|
+
const calldata = wimxInterface.encodeFunctionData('deposit');
|
|
40733
|
+
const gasEstimate = ethers.ethers.BigNumber.from(IMX_WRAP_GAS_COST);
|
|
40734
|
+
const gasFeeEstimate = gasPrice ? toPublicAmount(calculateGasFee(gasPrice, gasEstimate)) : null;
|
|
40735
|
+
// This transaction is for calling calling `deposit` on the WETH/WIMX contract.
|
|
40736
|
+
const transactionDetails = {
|
|
40737
|
+
transaction: {
|
|
40738
|
+
data: calldata,
|
|
40739
|
+
to: this.wrappedNativeToken.address,
|
|
40740
|
+
value: tokenAmount,
|
|
40741
|
+
from: fromAddress,
|
|
40742
|
+
},
|
|
40743
|
+
gasFeeEstimate,
|
|
40744
|
+
};
|
|
40745
|
+
return {
|
|
40746
|
+
transaction: transactionDetails,
|
|
40747
|
+
approval: null,
|
|
40748
|
+
};
|
|
40749
|
+
}
|
|
40750
|
+
async getUnsignedWrapUnwrapTx(tokenSpecified, amountIn, fromAddress, gasPrice) {
|
|
40751
|
+
const isWrap = amountIn.token.type === 'native';
|
|
40752
|
+
const quoteToken = tokenSpecified.type === 'native' ? this.wrappedNativeToken : this.nativeToken;
|
|
40753
|
+
const otherTokenCoinAmount = {
|
|
40754
|
+
token: quoteToken,
|
|
40755
|
+
value: amountIn.value,
|
|
40756
|
+
};
|
|
40757
|
+
// The quote is always 1:1 (0 {price impact, slippage}) when wrapping/unwrapping.
|
|
40758
|
+
const quote = {
|
|
40759
|
+
amount: toPublicAmount(otherTokenCoinAmount),
|
|
40760
|
+
amountWithMaxSlippage: toPublicAmount(otherTokenCoinAmount),
|
|
40761
|
+
slippage: 0,
|
|
40762
|
+
fees: [],
|
|
40763
|
+
};
|
|
40764
|
+
const wimxInterface = WIMX__factory.createInterface();
|
|
40765
|
+
let transactionDetails;
|
|
40766
|
+
if (isWrap) {
|
|
40767
|
+
transactionDetails = this.getWrapTransaction(fromAddress, otherTokenCoinAmount.value, wimxInterface, gasPrice);
|
|
40768
|
+
}
|
|
40769
|
+
else {
|
|
40770
|
+
transactionDetails = await this.getUnwrapTransaction(fromAddress, otherTokenCoinAmount.value, wimxInterface, gasPrice);
|
|
40771
|
+
}
|
|
40772
|
+
return { quote, approval: transactionDetails.approval, swap: transactionDetails.transaction };
|
|
40773
|
+
}
|
|
39901
40774
|
async getUnsignedSwapTx(fromAddress, tokenInLiteral, tokenOutLiteral, amount, slippagePercent, maxHops, deadline, tradeType) {
|
|
39902
40775
|
Exchange.validate(tokenInLiteral, tokenOutLiteral, maxHops, slippagePercent, fromAddress);
|
|
39903
40776
|
// get the decimals of the tokens that will be swapped
|
|
@@ -39913,6 +40786,11 @@ class Exchange {
|
|
|
39913
40786
|
// determine which amount was specified for the swap from the TradeType
|
|
39914
40787
|
const [tokenSpecified, otherToken] = tradeType === Uniswap.TradeType.EXACT_INPUT ? [tokenIn, tokenOut] : [tokenOut, tokenIn];
|
|
39915
40788
|
const amountSpecified = newAmount(amount, tokenSpecified);
|
|
40789
|
+
if (this.nativeTokenService.isWrapOrUnwrap(tokenIn, tokenOut)) {
|
|
40790
|
+
// If the user is swapping between the native token and the wrapped native token,
|
|
40791
|
+
// we want to just wrap/unwrap the native token instead of swapping
|
|
40792
|
+
return this.getUnsignedWrapUnwrapTx(tokenSpecified, newAmount(amount, tokenIn), fromAddress, gasPrice);
|
|
40793
|
+
}
|
|
39916
40794
|
const fees = new Fees(secondaryFees, tokenIn);
|
|
39917
40795
|
const ourQuoteReqAmount = getOurQuoteReqAmount(amountSpecified, fees, tradeType, this.nativeTokenService);
|
|
39918
40796
|
// Quotes will always use ERC20s. If the user-specified token is Native, we use the Wrapped Native Token pool
|
|
@@ -40199,6 +41077,7 @@ var WalletAction;
|
|
|
40199
41077
|
WalletAction["ADD_NETWORK"] = "wallet_addEthereumChain";
|
|
40200
41078
|
WalletAction["SWITCH_NETWORK"] = "wallet_switchEthereumChain";
|
|
40201
41079
|
WalletAction["GET_CHAINID"] = "eth_chainId";
|
|
41080
|
+
WalletAction["REQUEST_PERMISSIONS"] = "wallet_requestPermissions";
|
|
40202
41081
|
})(WalletAction || (WalletAction = {}));
|
|
40203
41082
|
/**
|
|
40204
41083
|
* Enum representing the platform filters used in {@link GetWalletAllowListParams}.
|
|
@@ -40909,7 +41788,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
|
|
|
40909
41788
|
maxPriorityFeePerGas: ethers.BigNumber.from(10e9),
|
|
40910
41789
|
};
|
|
40911
41790
|
|
|
40912
|
-
const SDK_VERSION_MARKER = '0.45.
|
|
41791
|
+
const SDK_VERSION_MARKER = '0.45.3-alpha';
|
|
40913
41792
|
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
40914
41793
|
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
40915
41794
|
|
|
@@ -41493,6 +42372,21 @@ async function connectSite(web3Provider) {
|
|
|
41493
42372
|
}, { type: CheckoutErrorType.USER_REJECTED_REQUEST_ERROR });
|
|
41494
42373
|
return web3Provider;
|
|
41495
42374
|
}
|
|
42375
|
+
async function requestPermissions(web3Provider) {
|
|
42376
|
+
if (!web3Provider || !web3Provider.provider?.request) {
|
|
42377
|
+
throw new CheckoutError('Incompatible provider', CheckoutErrorType.PROVIDER_REQUEST_MISSING_ERROR, { details: 'Attempting to connect with an incompatible provider' });
|
|
42378
|
+
}
|
|
42379
|
+
await withCheckoutError(async () => {
|
|
42380
|
+
if (!web3Provider.provider.request)
|
|
42381
|
+
return;
|
|
42382
|
+
await web3Provider.provider.request({
|
|
42383
|
+
method: WalletAction.REQUEST_PERMISSIONS,
|
|
42384
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
42385
|
+
params: [{ eth_accounts: {} }],
|
|
42386
|
+
});
|
|
42387
|
+
}, { type: CheckoutErrorType.USER_REJECTED_REQUEST_ERROR });
|
|
42388
|
+
return web3Provider;
|
|
42389
|
+
}
|
|
41496
42390
|
|
|
41497
42391
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
41498
42392
|
async function getMetaMaskProvider() {
|
|
@@ -44641,7 +45535,12 @@ class Checkout {
|
|
|
44641
45535
|
*/
|
|
44642
45536
|
async connect(params) {
|
|
44643
45537
|
const web3Provider = await validateProvider(this.config, params.provider, { allowUnsupportedProvider: true });
|
|
44644
|
-
|
|
45538
|
+
if (params.requestWalletPermissions && !web3Provider.provider?.isPassport) {
|
|
45539
|
+
await requestPermissions(web3Provider);
|
|
45540
|
+
}
|
|
45541
|
+
else {
|
|
45542
|
+
await connectSite(web3Provider);
|
|
45543
|
+
}
|
|
44645
45544
|
return { provider: web3Provider };
|
|
44646
45545
|
}
|
|
44647
45546
|
/**
|