@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.js
CHANGED
|
@@ -24,6 +24,268 @@ import { SwapRouter, PaymentsExtended } from '@uniswap/router-sdk';
|
|
|
24
24
|
import { parseUnits } from '@ethersproject/units';
|
|
25
25
|
import { BigNumber as BigNumber$2 } from '@ethersproject/bignumber';
|
|
26
26
|
|
|
27
|
+
const isNode$1 = () => typeof window === 'undefined';
|
|
28
|
+
const isBrowser$1 = () => !isNode$1();
|
|
29
|
+
|
|
30
|
+
var Detail$1;
|
|
31
|
+
(function (Detail) {
|
|
32
|
+
Detail["RUNTIME_ID"] = "rid";
|
|
33
|
+
Detail["PASSPORT_CLIENT_ID"] = "passportClientId";
|
|
34
|
+
Detail["ENVIRONMENT"] = "env";
|
|
35
|
+
Detail["PUBLISHABLE_API_KEY"] = "pak";
|
|
36
|
+
Detail["IDENTITY"] = "uid";
|
|
37
|
+
Detail["DOMAIN"] = "domain";
|
|
38
|
+
})(Detail$1 || (Detail$1 = {}));
|
|
39
|
+
var Store$1;
|
|
40
|
+
(function (Store) {
|
|
41
|
+
Store["EVENTS"] = "events";
|
|
42
|
+
Store["RUNTIME"] = "runtime";
|
|
43
|
+
})(Store$1 || (Store$1 = {}));
|
|
44
|
+
const POLLING_FREQUENCY$1 = 5000;
|
|
45
|
+
|
|
46
|
+
const IMTBL_API$1 = 'https://api.x.immutable.com';
|
|
47
|
+
async function post$1(path, data) {
|
|
48
|
+
const client = globalAxios$1.create({
|
|
49
|
+
baseURL: IMTBL_API$1,
|
|
50
|
+
});
|
|
51
|
+
const payload = JSON.stringify(data);
|
|
52
|
+
const body = {
|
|
53
|
+
payload: btoa(payload),
|
|
54
|
+
};
|
|
55
|
+
const response = await client.post(path, body);
|
|
56
|
+
return response.data;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Abstraction on localstorage
|
|
61
|
+
*/
|
|
62
|
+
const localStoragePrefix$1 = '__IMX-';
|
|
63
|
+
const hasLocalstorage$1 = () => isBrowser$1() && window.localStorage;
|
|
64
|
+
const parseItem$1 = (payload) => {
|
|
65
|
+
// Try to parse, if can't be parsed assume string
|
|
66
|
+
// and return string
|
|
67
|
+
if (payload === null)
|
|
68
|
+
return undefined;
|
|
69
|
+
try {
|
|
70
|
+
return JSON.parse(payload);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
// Assumes it's a string.
|
|
74
|
+
return payload;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const serialiseItem$1 = (payload) => {
|
|
78
|
+
if (typeof payload === 'string') {
|
|
79
|
+
return payload;
|
|
80
|
+
}
|
|
81
|
+
return JSON.stringify(payload);
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* GenKey will take into account the namespace
|
|
85
|
+
* as well as if being run in the Link, it will tap into the link
|
|
86
|
+
* @param {string} key
|
|
87
|
+
* @returns key
|
|
88
|
+
*/
|
|
89
|
+
const genKey$1 = (key) => `${localStoragePrefix$1}${key}`;
|
|
90
|
+
function getItem$1(key) {
|
|
91
|
+
if (hasLocalstorage$1()) {
|
|
92
|
+
return parseItem$1(window.localStorage.getItem(genKey$1(key)));
|
|
93
|
+
}
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
const setItem$1 = (key, payload) => {
|
|
97
|
+
if (hasLocalstorage$1()) {
|
|
98
|
+
window.localStorage.setItem(genKey$1(key), serialiseItem$1(payload));
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
return false;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// In memory storage for events and other data
|
|
105
|
+
let EVENT_STORE$1;
|
|
106
|
+
let RUNTIME_DETAILS$1;
|
|
107
|
+
// Initialise store and runtime
|
|
108
|
+
const initialise$1$1 = () => {
|
|
109
|
+
EVENT_STORE$1 = getItem$1(Store$1.EVENTS) || [];
|
|
110
|
+
RUNTIME_DETAILS$1 = getItem$1(Store$1.RUNTIME) || {};
|
|
111
|
+
};
|
|
112
|
+
initialise$1$1();
|
|
113
|
+
// Runtime Details
|
|
114
|
+
const storeDetail$1 = (key, value) => {
|
|
115
|
+
RUNTIME_DETAILS$1 = {
|
|
116
|
+
...RUNTIME_DETAILS$1,
|
|
117
|
+
[key]: value,
|
|
118
|
+
};
|
|
119
|
+
setItem$1(Store$1.RUNTIME, RUNTIME_DETAILS$1);
|
|
120
|
+
};
|
|
121
|
+
const getDetail$1 = (key) => {
|
|
122
|
+
// Handle the scenario where detail is a falsy value
|
|
123
|
+
if (RUNTIME_DETAILS$1[key] === undefined) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
return RUNTIME_DETAILS$1[key];
|
|
127
|
+
};
|
|
128
|
+
const getAllDetails$1 = () => RUNTIME_DETAILS$1;
|
|
129
|
+
// Events
|
|
130
|
+
const getEvents$1 = () => EVENT_STORE$1;
|
|
131
|
+
const addEvent = (event) => {
|
|
132
|
+
EVENT_STORE$1.push(event);
|
|
133
|
+
setItem$1(Store$1.EVENTS, EVENT_STORE$1);
|
|
134
|
+
};
|
|
135
|
+
const removeSentEvents$1 = (numberOfEvents) => {
|
|
136
|
+
EVENT_STORE$1 = EVENT_STORE$1.slice(numberOfEvents);
|
|
137
|
+
setItem$1(Store$1.EVENTS, EVENT_STORE$1);
|
|
138
|
+
};
|
|
139
|
+
const flattenProperties$1 = (properties) => {
|
|
140
|
+
const propertyMap = [];
|
|
141
|
+
Object.entries(properties).forEach(([key, value]) => {
|
|
142
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
143
|
+
propertyMap.push([key, value.toString()]);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
return propertyMap;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
let initialised$1 = false;
|
|
150
|
+
const isInitialised$1 = () => initialised$1;
|
|
151
|
+
const getReferrer$1 = () => {
|
|
152
|
+
if (isNode$1()) {
|
|
153
|
+
return '';
|
|
154
|
+
}
|
|
155
|
+
if (window.location.ancestorOrigins
|
|
156
|
+
&& window.location.ancestorOrigins.length > 0) {
|
|
157
|
+
return new URL(window.location.ancestorOrigins[0]).hostname;
|
|
158
|
+
}
|
|
159
|
+
return document.referrer ? new URL(window.document.referrer).hostname : '';
|
|
160
|
+
};
|
|
161
|
+
const runtimeHost$1 = () => {
|
|
162
|
+
if (isNode$1()) {
|
|
163
|
+
return '';
|
|
164
|
+
}
|
|
165
|
+
if (window.opener || window.parent !== window) {
|
|
166
|
+
return getReferrer$1();
|
|
167
|
+
}
|
|
168
|
+
return new URL(window.location.href).hostname;
|
|
169
|
+
};
|
|
170
|
+
const getRuntimeDetails$1 = () => {
|
|
171
|
+
if (isNode$1()) {
|
|
172
|
+
return { browser: 'nodejs' };
|
|
173
|
+
}
|
|
174
|
+
const domain = runtimeHost$1();
|
|
175
|
+
if (domain) {
|
|
176
|
+
storeDetail$1(Detail$1.DOMAIN, domain);
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
browser: window.navigator.userAgent,
|
|
180
|
+
domain,
|
|
181
|
+
tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
182
|
+
screen: `${window.screen.width}x${window.screen.height}`,
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
const initialise$2 = async () => {
|
|
186
|
+
const runtimeDetails = flattenProperties$1(getRuntimeDetails$1());
|
|
187
|
+
// Get any existing runtimeId and send it along with the initialise
|
|
188
|
+
const existingRuntimeId = getDetail$1(Detail$1.RUNTIME_ID);
|
|
189
|
+
const body = {
|
|
190
|
+
version: 1,
|
|
191
|
+
data: {
|
|
192
|
+
runtimeDetails,
|
|
193
|
+
runtimeId: existingRuntimeId,
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
const response = await post$1('/v1/sdk/initialise', body);
|
|
197
|
+
// Get runtimeId and store it
|
|
198
|
+
const { runtimeId } = response;
|
|
199
|
+
storeDetail$1(Detail$1.RUNTIME_ID, runtimeId);
|
|
200
|
+
initialised$1 = true;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
function errorBoundary$1(fn) {
|
|
204
|
+
const wrappedFunction = ((...args) => {
|
|
205
|
+
try {
|
|
206
|
+
// Execute the original function
|
|
207
|
+
const result = fn(...args);
|
|
208
|
+
if (result instanceof Promise) {
|
|
209
|
+
// Silent fail for now, in future
|
|
210
|
+
// we can send errors to a logging service
|
|
211
|
+
return result.catch(() => undefined);
|
|
212
|
+
}
|
|
213
|
+
return result;
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
// As above, fail silently for now
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
return wrappedFunction;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function isTestEnvironment$1() {
|
|
224
|
+
if (typeof process === 'undefined') {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
return process.env.JEST_WORKER_ID !== undefined;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Store the event in the event store
|
|
231
|
+
const trackFn = (moduleName, eventName, properties) => {
|
|
232
|
+
const event = {
|
|
233
|
+
event: `${moduleName}.${eventName}`,
|
|
234
|
+
time: new Date().toISOString(),
|
|
235
|
+
...(properties && { properties: flattenProperties$1(properties) }),
|
|
236
|
+
};
|
|
237
|
+
addEvent(event);
|
|
238
|
+
};
|
|
239
|
+
const track = errorBoundary$1(trackFn);
|
|
240
|
+
// Sending events to the server
|
|
241
|
+
const flushFn$1 = async () => {
|
|
242
|
+
// Don't flush if not initialised
|
|
243
|
+
if (isInitialised$1() === false) {
|
|
244
|
+
await initialise$2();
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const events = getEvents$1();
|
|
248
|
+
if (events.length === 0) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
// Track events length here, incase
|
|
252
|
+
const numEvents = events.length;
|
|
253
|
+
// Get details and send it with the track request
|
|
254
|
+
const details = getAllDetails$1();
|
|
255
|
+
const metricsPayload = {
|
|
256
|
+
version: 1,
|
|
257
|
+
data: {
|
|
258
|
+
events,
|
|
259
|
+
details,
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
const response = await post$1('/v1/sdk/metrics', metricsPayload);
|
|
263
|
+
if (response instanceof Error) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
// Clear events if successfully posted
|
|
267
|
+
removeSentEvents$1(numEvents);
|
|
268
|
+
};
|
|
269
|
+
const flush$1 = errorBoundary$1(flushFn$1);
|
|
270
|
+
// Flush events every 5 seconds
|
|
271
|
+
const flushPoll$1 = async () => {
|
|
272
|
+
await flush$1();
|
|
273
|
+
setTimeout(flushPoll$1, POLLING_FREQUENCY$1);
|
|
274
|
+
};
|
|
275
|
+
// This will get initialised when module is imported.
|
|
276
|
+
if (!isTestEnvironment$1()) {
|
|
277
|
+
errorBoundary$1(flushPoll$1)();
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const setEnvironmentFn = (env) => {
|
|
281
|
+
storeDetail$1(Detail$1.ENVIRONMENT, env);
|
|
282
|
+
};
|
|
283
|
+
const setEnvironment = errorBoundary$1(setEnvironmentFn);
|
|
284
|
+
const setPublishableApiKeyFn = (publishableApiKey) => {
|
|
285
|
+
storeDetail$1(Detail$1.PUBLISHABLE_API_KEY, publishableApiKey);
|
|
286
|
+
};
|
|
287
|
+
const setPublishableApiKey = errorBoundary$1(setPublishableApiKeyFn);
|
|
288
|
+
|
|
27
289
|
var Environment$1;
|
|
28
290
|
(function (Environment) {
|
|
29
291
|
Environment["PRODUCTION"] = "production";
|
|
@@ -36,6 +298,8 @@ class ImmutableConfiguration {
|
|
|
36
298
|
publishableKey;
|
|
37
299
|
constructor(options) {
|
|
38
300
|
this.environment = options.environment;
|
|
301
|
+
setEnvironment(options.environment);
|
|
302
|
+
track('config', 'load_imtbl_config');
|
|
39
303
|
}
|
|
40
304
|
}
|
|
41
305
|
const API_KEY_PREFIX = 'sk_imapik-';
|
|
@@ -51,6 +315,7 @@ const addPublishableKeyToAxiosHeader = (publishableKey) => {
|
|
|
51
315
|
throw new Error('Invalid Publishable key. Create your Publishable key in Immutable developer hub.'
|
|
52
316
|
+ ' https://hub.immutable.com');
|
|
53
317
|
}
|
|
318
|
+
setPublishableApiKey(publishableKey);
|
|
54
319
|
globalAxios$1.defaults.headers.common['x-immutable-publishable-key'] = publishableKey;
|
|
55
320
|
};
|
|
56
321
|
const addRateLimitingKeyToAxiosHeader = (rateLimitingKey) => {
|
|
@@ -10619,7 +10884,7 @@ class MultiRollupApiClients {
|
|
|
10619
10884
|
}
|
|
10620
10885
|
|
|
10621
10886
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
10622
|
-
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.45.
|
|
10887
|
+
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.45.3-alpha' };
|
|
10623
10888
|
const createConfig = ({ basePath, headers, }) => {
|
|
10624
10889
|
if (!basePath.trim()) {
|
|
10625
10890
|
throw Error('basePath can not be empty');
|
|
@@ -10691,7 +10956,7 @@ class APIError extends Error {
|
|
|
10691
10956
|
|
|
10692
10957
|
/* eslint-disable implicit-arrow-linebreak */
|
|
10693
10958
|
const defaultHeaders = {
|
|
10694
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.45.
|
|
10959
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.45.3-alpha',
|
|
10695
10960
|
};
|
|
10696
10961
|
/**
|
|
10697
10962
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -11130,7 +11395,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
11130
11395
|
chainID,
|
|
11131
11396
|
coreContractAddress,
|
|
11132
11397
|
registrationContractAddress,
|
|
11133
|
-
sdkVersion: 'ts-immutable-sdk-0.45.
|
|
11398
|
+
sdkVersion: 'ts-immutable-sdk-0.45.3-alpha',
|
|
11134
11399
|
});
|
|
11135
11400
|
/**
|
|
11136
11401
|
* Sets `sdkVersion` at the time of build
|
|
@@ -36284,6 +36549,244 @@ class TokenBridge {
|
|
|
36284
36549
|
}
|
|
36285
36550
|
}
|
|
36286
36551
|
|
|
36552
|
+
const isNode = () => typeof window === 'undefined';
|
|
36553
|
+
const isBrowser = () => !isNode();
|
|
36554
|
+
|
|
36555
|
+
var Detail;
|
|
36556
|
+
(function (Detail) {
|
|
36557
|
+
Detail["RUNTIME_ID"] = "rid";
|
|
36558
|
+
Detail["PASSPORT_CLIENT_ID"] = "passportClientId";
|
|
36559
|
+
Detail["ENVIRONMENT"] = "env";
|
|
36560
|
+
Detail["PUBLISHABLE_API_KEY"] = "pak";
|
|
36561
|
+
Detail["IDENTITY"] = "uid";
|
|
36562
|
+
Detail["DOMAIN"] = "domain";
|
|
36563
|
+
})(Detail || (Detail = {}));
|
|
36564
|
+
var Store;
|
|
36565
|
+
(function (Store) {
|
|
36566
|
+
Store["EVENTS"] = "events";
|
|
36567
|
+
Store["RUNTIME"] = "runtime";
|
|
36568
|
+
})(Store || (Store = {}));
|
|
36569
|
+
const POLLING_FREQUENCY = 5000;
|
|
36570
|
+
|
|
36571
|
+
const IMTBL_API = 'https://api.x.immutable.com';
|
|
36572
|
+
async function post(path, data) {
|
|
36573
|
+
const client = axios$1.create({
|
|
36574
|
+
baseURL: IMTBL_API,
|
|
36575
|
+
});
|
|
36576
|
+
const payload = JSON.stringify(data);
|
|
36577
|
+
const body = {
|
|
36578
|
+
payload: btoa(payload),
|
|
36579
|
+
};
|
|
36580
|
+
const response = await client.post(path, body);
|
|
36581
|
+
return response.data;
|
|
36582
|
+
}
|
|
36583
|
+
|
|
36584
|
+
/**
|
|
36585
|
+
* Abstraction on localstorage
|
|
36586
|
+
*/
|
|
36587
|
+
const localStoragePrefix = '__IMX-';
|
|
36588
|
+
const hasLocalstorage = () => isBrowser() && window.localStorage;
|
|
36589
|
+
const parseItem = (payload) => {
|
|
36590
|
+
// Try to parse, if can't be parsed assume string
|
|
36591
|
+
// and return string
|
|
36592
|
+
if (payload === null)
|
|
36593
|
+
return undefined;
|
|
36594
|
+
try {
|
|
36595
|
+
return JSON.parse(payload);
|
|
36596
|
+
}
|
|
36597
|
+
catch (error) {
|
|
36598
|
+
// Assumes it's a string.
|
|
36599
|
+
return payload;
|
|
36600
|
+
}
|
|
36601
|
+
};
|
|
36602
|
+
const serialiseItem = (payload) => {
|
|
36603
|
+
if (typeof payload === 'string') {
|
|
36604
|
+
return payload;
|
|
36605
|
+
}
|
|
36606
|
+
return JSON.stringify(payload);
|
|
36607
|
+
};
|
|
36608
|
+
/**
|
|
36609
|
+
* GenKey will take into account the namespace
|
|
36610
|
+
* as well as if being run in the Link, it will tap into the link
|
|
36611
|
+
* @param {string} key
|
|
36612
|
+
* @returns key
|
|
36613
|
+
*/
|
|
36614
|
+
const genKey = (key) => `${localStoragePrefix}${key}`;
|
|
36615
|
+
function getItem(key) {
|
|
36616
|
+
if (hasLocalstorage()) {
|
|
36617
|
+
return parseItem(window.localStorage.getItem(genKey(key)));
|
|
36618
|
+
}
|
|
36619
|
+
return undefined;
|
|
36620
|
+
}
|
|
36621
|
+
const setItem = (key, payload) => {
|
|
36622
|
+
if (hasLocalstorage()) {
|
|
36623
|
+
window.localStorage.setItem(genKey(key), serialiseItem(payload));
|
|
36624
|
+
return true;
|
|
36625
|
+
}
|
|
36626
|
+
return false;
|
|
36627
|
+
};
|
|
36628
|
+
|
|
36629
|
+
// In memory storage for events and other data
|
|
36630
|
+
let EVENT_STORE;
|
|
36631
|
+
let RUNTIME_DETAILS;
|
|
36632
|
+
// Initialise store and runtime
|
|
36633
|
+
const initialise$1 = () => {
|
|
36634
|
+
EVENT_STORE = getItem(Store.EVENTS) || [];
|
|
36635
|
+
RUNTIME_DETAILS = getItem(Store.RUNTIME) || {};
|
|
36636
|
+
};
|
|
36637
|
+
initialise$1();
|
|
36638
|
+
// Runtime Details
|
|
36639
|
+
const storeDetail = (key, value) => {
|
|
36640
|
+
RUNTIME_DETAILS = {
|
|
36641
|
+
...RUNTIME_DETAILS,
|
|
36642
|
+
[key]: value,
|
|
36643
|
+
};
|
|
36644
|
+
setItem(Store.RUNTIME, RUNTIME_DETAILS);
|
|
36645
|
+
};
|
|
36646
|
+
const getDetail = (key) => {
|
|
36647
|
+
// Handle the scenario where detail is a falsy value
|
|
36648
|
+
if (RUNTIME_DETAILS[key] === undefined) {
|
|
36649
|
+
return undefined;
|
|
36650
|
+
}
|
|
36651
|
+
return RUNTIME_DETAILS[key];
|
|
36652
|
+
};
|
|
36653
|
+
const getAllDetails = () => RUNTIME_DETAILS;
|
|
36654
|
+
// Events
|
|
36655
|
+
const getEvents = () => EVENT_STORE;
|
|
36656
|
+
const removeSentEvents = (numberOfEvents) => {
|
|
36657
|
+
EVENT_STORE = EVENT_STORE.slice(numberOfEvents);
|
|
36658
|
+
setItem(Store.EVENTS, EVENT_STORE);
|
|
36659
|
+
};
|
|
36660
|
+
const flattenProperties = (properties) => {
|
|
36661
|
+
const propertyMap = [];
|
|
36662
|
+
Object.entries(properties).forEach(([key, value]) => {
|
|
36663
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
36664
|
+
propertyMap.push([key, value.toString()]);
|
|
36665
|
+
}
|
|
36666
|
+
});
|
|
36667
|
+
return propertyMap;
|
|
36668
|
+
};
|
|
36669
|
+
|
|
36670
|
+
let initialised = false;
|
|
36671
|
+
const isInitialised = () => initialised;
|
|
36672
|
+
const getReferrer = () => {
|
|
36673
|
+
if (isNode()) {
|
|
36674
|
+
return '';
|
|
36675
|
+
}
|
|
36676
|
+
if (window.location.ancestorOrigins
|
|
36677
|
+
&& window.location.ancestorOrigins.length > 0) {
|
|
36678
|
+
return new URL(window.location.ancestorOrigins[0]).hostname;
|
|
36679
|
+
}
|
|
36680
|
+
return document.referrer ? new URL(window.document.referrer).hostname : '';
|
|
36681
|
+
};
|
|
36682
|
+
const runtimeHost = () => {
|
|
36683
|
+
if (isNode()) {
|
|
36684
|
+
return '';
|
|
36685
|
+
}
|
|
36686
|
+
if (window.opener || window.parent !== window) {
|
|
36687
|
+
return getReferrer();
|
|
36688
|
+
}
|
|
36689
|
+
return new URL(window.location.href).hostname;
|
|
36690
|
+
};
|
|
36691
|
+
const getRuntimeDetails = () => {
|
|
36692
|
+
if (isNode()) {
|
|
36693
|
+
return { browser: 'nodejs' };
|
|
36694
|
+
}
|
|
36695
|
+
const domain = runtimeHost();
|
|
36696
|
+
if (domain) {
|
|
36697
|
+
storeDetail(Detail.DOMAIN, domain);
|
|
36698
|
+
}
|
|
36699
|
+
return {
|
|
36700
|
+
browser: window.navigator.userAgent,
|
|
36701
|
+
domain,
|
|
36702
|
+
tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
36703
|
+
screen: `${window.screen.width}x${window.screen.height}`,
|
|
36704
|
+
};
|
|
36705
|
+
};
|
|
36706
|
+
const initialise = async () => {
|
|
36707
|
+
const runtimeDetails = flattenProperties(getRuntimeDetails());
|
|
36708
|
+
// Get any existing runtimeId and send it along with the initialise
|
|
36709
|
+
const existingRuntimeId = getDetail(Detail.RUNTIME_ID);
|
|
36710
|
+
const body = {
|
|
36711
|
+
version: 1,
|
|
36712
|
+
data: {
|
|
36713
|
+
runtimeDetails,
|
|
36714
|
+
runtimeId: existingRuntimeId,
|
|
36715
|
+
},
|
|
36716
|
+
};
|
|
36717
|
+
const response = await post('/v1/sdk/initialise', body);
|
|
36718
|
+
// Get runtimeId and store it
|
|
36719
|
+
const { runtimeId } = response;
|
|
36720
|
+
storeDetail(Detail.RUNTIME_ID, runtimeId);
|
|
36721
|
+
initialised = true;
|
|
36722
|
+
};
|
|
36723
|
+
|
|
36724
|
+
function errorBoundary(fn) {
|
|
36725
|
+
const wrappedFunction = ((...args) => {
|
|
36726
|
+
try {
|
|
36727
|
+
// Execute the original function
|
|
36728
|
+
const result = fn(...args);
|
|
36729
|
+
if (result instanceof Promise) {
|
|
36730
|
+
// Silent fail for now, in future
|
|
36731
|
+
// we can send errors to a logging service
|
|
36732
|
+
return result.catch(() => undefined);
|
|
36733
|
+
}
|
|
36734
|
+
return result;
|
|
36735
|
+
}
|
|
36736
|
+
catch (error) {
|
|
36737
|
+
// As above, fail silently for now
|
|
36738
|
+
return undefined;
|
|
36739
|
+
}
|
|
36740
|
+
});
|
|
36741
|
+
return wrappedFunction;
|
|
36742
|
+
}
|
|
36743
|
+
|
|
36744
|
+
function isTestEnvironment() {
|
|
36745
|
+
if (typeof process === 'undefined') {
|
|
36746
|
+
return false;
|
|
36747
|
+
}
|
|
36748
|
+
return process.env.JEST_WORKER_ID !== undefined;
|
|
36749
|
+
}
|
|
36750
|
+
// Sending events to the server
|
|
36751
|
+
const flushFn = async () => {
|
|
36752
|
+
// Don't flush if not initialised
|
|
36753
|
+
if (isInitialised() === false) {
|
|
36754
|
+
await initialise();
|
|
36755
|
+
return;
|
|
36756
|
+
}
|
|
36757
|
+
const events = getEvents();
|
|
36758
|
+
if (events.length === 0) {
|
|
36759
|
+
return;
|
|
36760
|
+
}
|
|
36761
|
+
// Track events length here, incase
|
|
36762
|
+
const numEvents = events.length;
|
|
36763
|
+
// Get details and send it with the track request
|
|
36764
|
+
const details = getAllDetails();
|
|
36765
|
+
const metricsPayload = {
|
|
36766
|
+
version: 1,
|
|
36767
|
+
data: {
|
|
36768
|
+
events,
|
|
36769
|
+
details,
|
|
36770
|
+
},
|
|
36771
|
+
};
|
|
36772
|
+
const response = await post('/v1/sdk/metrics', metricsPayload);
|
|
36773
|
+
if (response instanceof Error) {
|
|
36774
|
+
return;
|
|
36775
|
+
}
|
|
36776
|
+
// Clear events if successfully posted
|
|
36777
|
+
removeSentEvents(numEvents);
|
|
36778
|
+
};
|
|
36779
|
+
const flush = errorBoundary(flushFn);
|
|
36780
|
+
// Flush events every 5 seconds
|
|
36781
|
+
const flushPoll = async () => {
|
|
36782
|
+
await flush();
|
|
36783
|
+
setTimeout(flushPoll, POLLING_FREQUENCY);
|
|
36784
|
+
};
|
|
36785
|
+
// This will get initialised when module is imported.
|
|
36786
|
+
if (!isTestEnvironment()) {
|
|
36787
|
+
errorBoundary(flushPoll)();
|
|
36788
|
+
}
|
|
36789
|
+
|
|
36287
36790
|
var Environment;
|
|
36288
36791
|
(function (Environment) {
|
|
36289
36792
|
Environment["PRODUCTION"] = "production";
|
|
@@ -36460,7 +36963,7 @@ class ApproveError extends ExchangeError {
|
|
|
36460
36963
|
/* Autogenerated file. Do not edit manually. */
|
|
36461
36964
|
/* tslint:disable */
|
|
36462
36965
|
/* eslint-disable */
|
|
36463
|
-
const _abi$
|
|
36966
|
+
const _abi$4 = [
|
|
36464
36967
|
{
|
|
36465
36968
|
constant: true,
|
|
36466
36969
|
inputs: [],
|
|
@@ -36683,19 +37186,19 @@ const _abi$3 = [
|
|
|
36683
37186
|
},
|
|
36684
37187
|
];
|
|
36685
37188
|
class ERC20__factory {
|
|
36686
|
-
static abi = _abi$
|
|
37189
|
+
static abi = _abi$4;
|
|
36687
37190
|
static createInterface() {
|
|
36688
|
-
return new utils$3.Interface(_abi$
|
|
37191
|
+
return new utils$3.Interface(_abi$4);
|
|
36689
37192
|
}
|
|
36690
37193
|
static connect(address, signerOrProvider) {
|
|
36691
|
-
return new Contract$1(address, _abi$
|
|
37194
|
+
return new Contract$1(address, _abi$4, signerOrProvider);
|
|
36692
37195
|
}
|
|
36693
37196
|
}
|
|
36694
37197
|
|
|
36695
37198
|
/* Autogenerated file. Do not edit manually. */
|
|
36696
37199
|
/* tslint:disable */
|
|
36697
37200
|
/* eslint-disable */
|
|
36698
|
-
const _abi$
|
|
37201
|
+
const _abi$3 = [
|
|
36699
37202
|
{
|
|
36700
37203
|
inputs: [
|
|
36701
37204
|
{
|
|
@@ -37469,7 +37972,7 @@ class ImmutableSwapProxy__factory extends ContractFactory {
|
|
|
37469
37972
|
super(...args);
|
|
37470
37973
|
}
|
|
37471
37974
|
else {
|
|
37472
|
-
super(_abi$
|
|
37975
|
+
super(_abi$3, _bytecode$2, args[0]);
|
|
37473
37976
|
}
|
|
37474
37977
|
}
|
|
37475
37978
|
deploy(_admin, _uniRouter, _wimx, overrides) {
|
|
@@ -37485,19 +37988,19 @@ class ImmutableSwapProxy__factory extends ContractFactory {
|
|
|
37485
37988
|
return super.connect(signer);
|
|
37486
37989
|
}
|
|
37487
37990
|
static bytecode = _bytecode$2;
|
|
37488
|
-
static abi = _abi$
|
|
37991
|
+
static abi = _abi$3;
|
|
37489
37992
|
static createInterface() {
|
|
37490
|
-
return new utils$3.Interface(_abi$
|
|
37993
|
+
return new utils$3.Interface(_abi$3);
|
|
37491
37994
|
}
|
|
37492
37995
|
static connect(address, signerOrProvider) {
|
|
37493
|
-
return new Contract$1(address, _abi$
|
|
37996
|
+
return new Contract$1(address, _abi$3, signerOrProvider);
|
|
37494
37997
|
}
|
|
37495
37998
|
}
|
|
37496
37999
|
|
|
37497
38000
|
/* Autogenerated file. Do not edit manually. */
|
|
37498
38001
|
/* tslint:disable */
|
|
37499
38002
|
/* eslint-disable */
|
|
37500
|
-
const _abi$
|
|
38003
|
+
const _abi$2 = [
|
|
37501
38004
|
{
|
|
37502
38005
|
inputs: [],
|
|
37503
38006
|
name: "getCurrentBlockTimestamp",
|
|
@@ -37597,7 +38100,7 @@ class Multicall__factory extends ContractFactory {
|
|
|
37597
38100
|
super(...args);
|
|
37598
38101
|
}
|
|
37599
38102
|
else {
|
|
37600
|
-
super(_abi$
|
|
38103
|
+
super(_abi$2, _bytecode$1, args[0]);
|
|
37601
38104
|
}
|
|
37602
38105
|
}
|
|
37603
38106
|
deploy(overrides) {
|
|
@@ -37613,19 +38116,19 @@ class Multicall__factory extends ContractFactory {
|
|
|
37613
38116
|
return super.connect(signer);
|
|
37614
38117
|
}
|
|
37615
38118
|
static bytecode = _bytecode$1;
|
|
37616
|
-
static abi = _abi$
|
|
38119
|
+
static abi = _abi$2;
|
|
37617
38120
|
static createInterface() {
|
|
37618
|
-
return new utils$3.Interface(_abi$
|
|
38121
|
+
return new utils$3.Interface(_abi$2);
|
|
37619
38122
|
}
|
|
37620
38123
|
static connect(address, signerOrProvider) {
|
|
37621
|
-
return new Contract$1(address, _abi$
|
|
38124
|
+
return new Contract$1(address, _abi$2, signerOrProvider);
|
|
37622
38125
|
}
|
|
37623
38126
|
}
|
|
37624
38127
|
|
|
37625
38128
|
/* Autogenerated file. Do not edit manually. */
|
|
37626
38129
|
/* tslint:disable */
|
|
37627
38130
|
/* eslint-disable */
|
|
37628
|
-
const _abi = [
|
|
38131
|
+
const _abi$1 = [
|
|
37629
38132
|
{
|
|
37630
38133
|
inputs: [],
|
|
37631
38134
|
stateMutability: "nonpayable",
|
|
@@ -38621,7 +39124,7 @@ class UniswapV3Pool__factory extends ContractFactory {
|
|
|
38621
39124
|
super(...args);
|
|
38622
39125
|
}
|
|
38623
39126
|
else {
|
|
38624
|
-
super(_abi, _bytecode, args[0]);
|
|
39127
|
+
super(_abi$1, _bytecode, args[0]);
|
|
38625
39128
|
}
|
|
38626
39129
|
}
|
|
38627
39130
|
deploy(overrides) {
|
|
@@ -38637,6 +39140,298 @@ class UniswapV3Pool__factory extends ContractFactory {
|
|
|
38637
39140
|
return super.connect(signer);
|
|
38638
39141
|
}
|
|
38639
39142
|
static bytecode = _bytecode;
|
|
39143
|
+
static abi = _abi$1;
|
|
39144
|
+
static createInterface() {
|
|
39145
|
+
return new utils$3.Interface(_abi$1);
|
|
39146
|
+
}
|
|
39147
|
+
static connect(address, signerOrProvider) {
|
|
39148
|
+
return new Contract$1(address, _abi$1, signerOrProvider);
|
|
39149
|
+
}
|
|
39150
|
+
}
|
|
39151
|
+
|
|
39152
|
+
/* Autogenerated file. Do not edit manually. */
|
|
39153
|
+
/* tslint:disable */
|
|
39154
|
+
/* eslint-disable */
|
|
39155
|
+
const _abi = [
|
|
39156
|
+
{
|
|
39157
|
+
constant: true,
|
|
39158
|
+
inputs: [],
|
|
39159
|
+
name: "name",
|
|
39160
|
+
outputs: [
|
|
39161
|
+
{
|
|
39162
|
+
name: "",
|
|
39163
|
+
type: "string",
|
|
39164
|
+
},
|
|
39165
|
+
],
|
|
39166
|
+
payable: false,
|
|
39167
|
+
stateMutability: "view",
|
|
39168
|
+
type: "function",
|
|
39169
|
+
},
|
|
39170
|
+
{
|
|
39171
|
+
constant: false,
|
|
39172
|
+
inputs: [
|
|
39173
|
+
{
|
|
39174
|
+
name: "guy",
|
|
39175
|
+
type: "address",
|
|
39176
|
+
},
|
|
39177
|
+
{
|
|
39178
|
+
name: "wad",
|
|
39179
|
+
type: "uint256",
|
|
39180
|
+
},
|
|
39181
|
+
],
|
|
39182
|
+
name: "approve",
|
|
39183
|
+
outputs: [
|
|
39184
|
+
{
|
|
39185
|
+
name: "",
|
|
39186
|
+
type: "bool",
|
|
39187
|
+
},
|
|
39188
|
+
],
|
|
39189
|
+
payable: false,
|
|
39190
|
+
stateMutability: "nonpayable",
|
|
39191
|
+
type: "function",
|
|
39192
|
+
},
|
|
39193
|
+
{
|
|
39194
|
+
constant: true,
|
|
39195
|
+
inputs: [],
|
|
39196
|
+
name: "totalSupply",
|
|
39197
|
+
outputs: [
|
|
39198
|
+
{
|
|
39199
|
+
name: "",
|
|
39200
|
+
type: "uint256",
|
|
39201
|
+
},
|
|
39202
|
+
],
|
|
39203
|
+
payable: false,
|
|
39204
|
+
stateMutability: "view",
|
|
39205
|
+
type: "function",
|
|
39206
|
+
},
|
|
39207
|
+
{
|
|
39208
|
+
constant: false,
|
|
39209
|
+
inputs: [
|
|
39210
|
+
{
|
|
39211
|
+
name: "src",
|
|
39212
|
+
type: "address",
|
|
39213
|
+
},
|
|
39214
|
+
{
|
|
39215
|
+
name: "dst",
|
|
39216
|
+
type: "address",
|
|
39217
|
+
},
|
|
39218
|
+
{
|
|
39219
|
+
name: "wad",
|
|
39220
|
+
type: "uint256",
|
|
39221
|
+
},
|
|
39222
|
+
],
|
|
39223
|
+
name: "transferFrom",
|
|
39224
|
+
outputs: [
|
|
39225
|
+
{
|
|
39226
|
+
name: "",
|
|
39227
|
+
type: "bool",
|
|
39228
|
+
},
|
|
39229
|
+
],
|
|
39230
|
+
payable: false,
|
|
39231
|
+
stateMutability: "nonpayable",
|
|
39232
|
+
type: "function",
|
|
39233
|
+
},
|
|
39234
|
+
{
|
|
39235
|
+
constant: false,
|
|
39236
|
+
inputs: [
|
|
39237
|
+
{
|
|
39238
|
+
name: "wad",
|
|
39239
|
+
type: "uint256",
|
|
39240
|
+
},
|
|
39241
|
+
],
|
|
39242
|
+
name: "withdraw",
|
|
39243
|
+
outputs: [],
|
|
39244
|
+
payable: false,
|
|
39245
|
+
stateMutability: "nonpayable",
|
|
39246
|
+
type: "function",
|
|
39247
|
+
},
|
|
39248
|
+
{
|
|
39249
|
+
constant: true,
|
|
39250
|
+
inputs: [],
|
|
39251
|
+
name: "decimals",
|
|
39252
|
+
outputs: [
|
|
39253
|
+
{
|
|
39254
|
+
name: "",
|
|
39255
|
+
type: "uint8",
|
|
39256
|
+
},
|
|
39257
|
+
],
|
|
39258
|
+
payable: false,
|
|
39259
|
+
stateMutability: "view",
|
|
39260
|
+
type: "function",
|
|
39261
|
+
},
|
|
39262
|
+
{
|
|
39263
|
+
constant: true,
|
|
39264
|
+
inputs: [
|
|
39265
|
+
{
|
|
39266
|
+
name: "",
|
|
39267
|
+
type: "address",
|
|
39268
|
+
},
|
|
39269
|
+
],
|
|
39270
|
+
name: "balanceOf",
|
|
39271
|
+
outputs: [
|
|
39272
|
+
{
|
|
39273
|
+
name: "",
|
|
39274
|
+
type: "uint256",
|
|
39275
|
+
},
|
|
39276
|
+
],
|
|
39277
|
+
payable: false,
|
|
39278
|
+
stateMutability: "view",
|
|
39279
|
+
type: "function",
|
|
39280
|
+
},
|
|
39281
|
+
{
|
|
39282
|
+
constant: true,
|
|
39283
|
+
inputs: [],
|
|
39284
|
+
name: "symbol",
|
|
39285
|
+
outputs: [
|
|
39286
|
+
{
|
|
39287
|
+
name: "",
|
|
39288
|
+
type: "string",
|
|
39289
|
+
},
|
|
39290
|
+
],
|
|
39291
|
+
payable: false,
|
|
39292
|
+
stateMutability: "view",
|
|
39293
|
+
type: "function",
|
|
39294
|
+
},
|
|
39295
|
+
{
|
|
39296
|
+
constant: false,
|
|
39297
|
+
inputs: [
|
|
39298
|
+
{
|
|
39299
|
+
name: "dst",
|
|
39300
|
+
type: "address",
|
|
39301
|
+
},
|
|
39302
|
+
{
|
|
39303
|
+
name: "wad",
|
|
39304
|
+
type: "uint256",
|
|
39305
|
+
},
|
|
39306
|
+
],
|
|
39307
|
+
name: "transfer",
|
|
39308
|
+
outputs: [
|
|
39309
|
+
{
|
|
39310
|
+
name: "",
|
|
39311
|
+
type: "bool",
|
|
39312
|
+
},
|
|
39313
|
+
],
|
|
39314
|
+
payable: false,
|
|
39315
|
+
stateMutability: "nonpayable",
|
|
39316
|
+
type: "function",
|
|
39317
|
+
},
|
|
39318
|
+
{
|
|
39319
|
+
constant: false,
|
|
39320
|
+
inputs: [],
|
|
39321
|
+
name: "deposit",
|
|
39322
|
+
outputs: [],
|
|
39323
|
+
payable: true,
|
|
39324
|
+
stateMutability: "payable",
|
|
39325
|
+
type: "function",
|
|
39326
|
+
},
|
|
39327
|
+
{
|
|
39328
|
+
constant: true,
|
|
39329
|
+
inputs: [
|
|
39330
|
+
{
|
|
39331
|
+
name: "",
|
|
39332
|
+
type: "address",
|
|
39333
|
+
},
|
|
39334
|
+
{
|
|
39335
|
+
name: "",
|
|
39336
|
+
type: "address",
|
|
39337
|
+
},
|
|
39338
|
+
],
|
|
39339
|
+
name: "allowance",
|
|
39340
|
+
outputs: [
|
|
39341
|
+
{
|
|
39342
|
+
name: "",
|
|
39343
|
+
type: "uint256",
|
|
39344
|
+
},
|
|
39345
|
+
],
|
|
39346
|
+
payable: false,
|
|
39347
|
+
stateMutability: "view",
|
|
39348
|
+
type: "function",
|
|
39349
|
+
},
|
|
39350
|
+
{
|
|
39351
|
+
payable: true,
|
|
39352
|
+
stateMutability: "payable",
|
|
39353
|
+
type: "fallback",
|
|
39354
|
+
},
|
|
39355
|
+
{
|
|
39356
|
+
anonymous: false,
|
|
39357
|
+
inputs: [
|
|
39358
|
+
{
|
|
39359
|
+
indexed: true,
|
|
39360
|
+
name: "src",
|
|
39361
|
+
type: "address",
|
|
39362
|
+
},
|
|
39363
|
+
{
|
|
39364
|
+
indexed: true,
|
|
39365
|
+
name: "guy",
|
|
39366
|
+
type: "address",
|
|
39367
|
+
},
|
|
39368
|
+
{
|
|
39369
|
+
indexed: false,
|
|
39370
|
+
name: "wad",
|
|
39371
|
+
type: "uint256",
|
|
39372
|
+
},
|
|
39373
|
+
],
|
|
39374
|
+
name: "Approval",
|
|
39375
|
+
type: "event",
|
|
39376
|
+
},
|
|
39377
|
+
{
|
|
39378
|
+
anonymous: false,
|
|
39379
|
+
inputs: [
|
|
39380
|
+
{
|
|
39381
|
+
indexed: true,
|
|
39382
|
+
name: "src",
|
|
39383
|
+
type: "address",
|
|
39384
|
+
},
|
|
39385
|
+
{
|
|
39386
|
+
indexed: true,
|
|
39387
|
+
name: "dst",
|
|
39388
|
+
type: "address",
|
|
39389
|
+
},
|
|
39390
|
+
{
|
|
39391
|
+
indexed: false,
|
|
39392
|
+
name: "wad",
|
|
39393
|
+
type: "uint256",
|
|
39394
|
+
},
|
|
39395
|
+
],
|
|
39396
|
+
name: "Transfer",
|
|
39397
|
+
type: "event",
|
|
39398
|
+
},
|
|
39399
|
+
{
|
|
39400
|
+
anonymous: false,
|
|
39401
|
+
inputs: [
|
|
39402
|
+
{
|
|
39403
|
+
indexed: true,
|
|
39404
|
+
name: "dst",
|
|
39405
|
+
type: "address",
|
|
39406
|
+
},
|
|
39407
|
+
{
|
|
39408
|
+
indexed: false,
|
|
39409
|
+
name: "wad",
|
|
39410
|
+
type: "uint256",
|
|
39411
|
+
},
|
|
39412
|
+
],
|
|
39413
|
+
name: "Deposit",
|
|
39414
|
+
type: "event",
|
|
39415
|
+
},
|
|
39416
|
+
{
|
|
39417
|
+
anonymous: false,
|
|
39418
|
+
inputs: [
|
|
39419
|
+
{
|
|
39420
|
+
indexed: true,
|
|
39421
|
+
name: "src",
|
|
39422
|
+
type: "address",
|
|
39423
|
+
},
|
|
39424
|
+
{
|
|
39425
|
+
indexed: false,
|
|
39426
|
+
name: "wad",
|
|
39427
|
+
type: "uint256",
|
|
39428
|
+
},
|
|
39429
|
+
],
|
|
39430
|
+
name: "Withdrawal",
|
|
39431
|
+
type: "event",
|
|
39432
|
+
},
|
|
39433
|
+
];
|
|
39434
|
+
class WIMX__factory {
|
|
38640
39435
|
static abi = _abi;
|
|
38641
39436
|
static createInterface() {
|
|
38642
39437
|
return new utils$3.Interface(_abi);
|
|
@@ -39265,6 +40060,13 @@ class NativeTokenService {
|
|
|
39265
40060
|
maybeWrapAmount(amount) {
|
|
39266
40061
|
return newAmount(amount.value, this.maybeWrapToken(amount.token));
|
|
39267
40062
|
}
|
|
40063
|
+
isWrappedNative(token) {
|
|
40064
|
+
return token.type === 'erc20' && token.address.toLowerCase() === this.wrappedToken.address.toLowerCase();
|
|
40065
|
+
}
|
|
40066
|
+
isWrapOrUnwrap(tokenIn, tokenOut) {
|
|
40067
|
+
return ((tokenIn === this.nativeToken && (this.isWrappedNative(tokenOut))) ||
|
|
40068
|
+
((this.isWrappedNative(tokenIn)) && tokenOut === this.nativeToken));
|
|
40069
|
+
}
|
|
39268
40070
|
}
|
|
39269
40071
|
|
|
39270
40072
|
// slippageToPercent takes the slippage as a percentage (e.g. 0.1) and
|
|
@@ -39363,6 +40165,16 @@ class Fees {
|
|
|
39363
40165
|
}
|
|
39364
40166
|
}
|
|
39365
40167
|
|
|
40168
|
+
// 45038 is the upper bound of the gas estimate for the deposit function.
|
|
40169
|
+
// This upper bound is reached when a user is wrapping for the first time (cold + unused storage slot)
|
|
40170
|
+
// The lower bound is 27,938, so the difference is 17,100 gas. If transactions are 10 gwei IMX,
|
|
40171
|
+
// this is about 0.000171 IMX difference. In order to avoid an extra remote call, we just use the upper bound instead.
|
|
40172
|
+
const IMX_WRAP_GAS_COST = 45038;
|
|
40173
|
+
// 35216 is the upper bound of the gas estimate for the withdraw function.
|
|
40174
|
+
// The differenfce between upper and normal is less than 0.0001 IMX, so we just use the upper bound
|
|
40175
|
+
// to avoid an extra remote call.
|
|
40176
|
+
const IMX_UNWRAP_GAS_COST = 35216;
|
|
40177
|
+
|
|
39366
40178
|
const IMMUTABLE_TESTNET_RPC_URL = 'https://rpc.testnet.immutable.com';
|
|
39367
40179
|
const IMMUTABLE_TESTNET_CHAIN_ID = 13473;
|
|
39368
40180
|
|
|
@@ -39876,6 +40688,67 @@ class Exchange {
|
|
|
39876
40688
|
decimals,
|
|
39877
40689
|
};
|
|
39878
40690
|
}
|
|
40691
|
+
async getUnwrapTransaction(fromAddress, tokenAmount, wimxInterface, gasPrice) {
|
|
40692
|
+
const calldata = wimxInterface.encodeFunctionData('withdraw', [tokenAmount]);
|
|
40693
|
+
const gasEstimate = ethers.BigNumber.from(IMX_UNWRAP_GAS_COST);
|
|
40694
|
+
const gasFeeEstimate = gasPrice ? toPublicAmount(calculateGasFee(gasPrice, gasEstimate)) : null;
|
|
40695
|
+
// This transaction is for calling calling `withdraw` on the WETH/WIMX contract.
|
|
40696
|
+
const transactionDetails = {
|
|
40697
|
+
transaction: {
|
|
40698
|
+
data: calldata,
|
|
40699
|
+
to: this.wrappedNativeToken.address,
|
|
40700
|
+
from: fromAddress,
|
|
40701
|
+
},
|
|
40702
|
+
gasFeeEstimate,
|
|
40703
|
+
};
|
|
40704
|
+
return {
|
|
40705
|
+
transaction: transactionDetails,
|
|
40706
|
+
approval: null,
|
|
40707
|
+
};
|
|
40708
|
+
}
|
|
40709
|
+
getWrapTransaction(fromAddress, tokenAmount, wimxInterface, gasPrice) {
|
|
40710
|
+
const calldata = wimxInterface.encodeFunctionData('deposit');
|
|
40711
|
+
const gasEstimate = ethers.BigNumber.from(IMX_WRAP_GAS_COST);
|
|
40712
|
+
const gasFeeEstimate = gasPrice ? toPublicAmount(calculateGasFee(gasPrice, gasEstimate)) : null;
|
|
40713
|
+
// This transaction is for calling calling `deposit` on the WETH/WIMX contract.
|
|
40714
|
+
const transactionDetails = {
|
|
40715
|
+
transaction: {
|
|
40716
|
+
data: calldata,
|
|
40717
|
+
to: this.wrappedNativeToken.address,
|
|
40718
|
+
value: tokenAmount,
|
|
40719
|
+
from: fromAddress,
|
|
40720
|
+
},
|
|
40721
|
+
gasFeeEstimate,
|
|
40722
|
+
};
|
|
40723
|
+
return {
|
|
40724
|
+
transaction: transactionDetails,
|
|
40725
|
+
approval: null,
|
|
40726
|
+
};
|
|
40727
|
+
}
|
|
40728
|
+
async getUnsignedWrapUnwrapTx(tokenSpecified, amountIn, fromAddress, gasPrice) {
|
|
40729
|
+
const isWrap = amountIn.token.type === 'native';
|
|
40730
|
+
const quoteToken = tokenSpecified.type === 'native' ? this.wrappedNativeToken : this.nativeToken;
|
|
40731
|
+
const otherTokenCoinAmount = {
|
|
40732
|
+
token: quoteToken,
|
|
40733
|
+
value: amountIn.value,
|
|
40734
|
+
};
|
|
40735
|
+
// The quote is always 1:1 (0 {price impact, slippage}) when wrapping/unwrapping.
|
|
40736
|
+
const quote = {
|
|
40737
|
+
amount: toPublicAmount(otherTokenCoinAmount),
|
|
40738
|
+
amountWithMaxSlippage: toPublicAmount(otherTokenCoinAmount),
|
|
40739
|
+
slippage: 0,
|
|
40740
|
+
fees: [],
|
|
40741
|
+
};
|
|
40742
|
+
const wimxInterface = WIMX__factory.createInterface();
|
|
40743
|
+
let transactionDetails;
|
|
40744
|
+
if (isWrap) {
|
|
40745
|
+
transactionDetails = this.getWrapTransaction(fromAddress, otherTokenCoinAmount.value, wimxInterface, gasPrice);
|
|
40746
|
+
}
|
|
40747
|
+
else {
|
|
40748
|
+
transactionDetails = await this.getUnwrapTransaction(fromAddress, otherTokenCoinAmount.value, wimxInterface, gasPrice);
|
|
40749
|
+
}
|
|
40750
|
+
return { quote, approval: transactionDetails.approval, swap: transactionDetails.transaction };
|
|
40751
|
+
}
|
|
39879
40752
|
async getUnsignedSwapTx(fromAddress, tokenInLiteral, tokenOutLiteral, amount, slippagePercent, maxHops, deadline, tradeType) {
|
|
39880
40753
|
Exchange.validate(tokenInLiteral, tokenOutLiteral, maxHops, slippagePercent, fromAddress);
|
|
39881
40754
|
// get the decimals of the tokens that will be swapped
|
|
@@ -39891,6 +40764,11 @@ class Exchange {
|
|
|
39891
40764
|
// determine which amount was specified for the swap from the TradeType
|
|
39892
40765
|
const [tokenSpecified, otherToken] = tradeType === TradeType.EXACT_INPUT ? [tokenIn, tokenOut] : [tokenOut, tokenIn];
|
|
39893
40766
|
const amountSpecified = newAmount(amount, tokenSpecified);
|
|
40767
|
+
if (this.nativeTokenService.isWrapOrUnwrap(tokenIn, tokenOut)) {
|
|
40768
|
+
// If the user is swapping between the native token and the wrapped native token,
|
|
40769
|
+
// we want to just wrap/unwrap the native token instead of swapping
|
|
40770
|
+
return this.getUnsignedWrapUnwrapTx(tokenSpecified, newAmount(amount, tokenIn), fromAddress, gasPrice);
|
|
40771
|
+
}
|
|
39894
40772
|
const fees = new Fees(secondaryFees, tokenIn);
|
|
39895
40773
|
const ourQuoteReqAmount = getOurQuoteReqAmount(amountSpecified, fees, tradeType, this.nativeTokenService);
|
|
39896
40774
|
// Quotes will always use ERC20s. If the user-specified token is Native, we use the Wrapped Native Token pool
|
|
@@ -40177,6 +41055,7 @@ var WalletAction;
|
|
|
40177
41055
|
WalletAction["ADD_NETWORK"] = "wallet_addEthereumChain";
|
|
40178
41056
|
WalletAction["SWITCH_NETWORK"] = "wallet_switchEthereumChain";
|
|
40179
41057
|
WalletAction["GET_CHAINID"] = "eth_chainId";
|
|
41058
|
+
WalletAction["REQUEST_PERMISSIONS"] = "wallet_requestPermissions";
|
|
40180
41059
|
})(WalletAction || (WalletAction = {}));
|
|
40181
41060
|
/**
|
|
40182
41061
|
* Enum representing the platform filters used in {@link GetWalletAllowListParams}.
|
|
@@ -40887,7 +41766,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
|
|
|
40887
41766
|
maxPriorityFeePerGas: BigNumber$1.from(10e9),
|
|
40888
41767
|
};
|
|
40889
41768
|
|
|
40890
|
-
const SDK_VERSION_MARKER = '0.45.
|
|
41769
|
+
const SDK_VERSION_MARKER = '0.45.3-alpha';
|
|
40891
41770
|
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
40892
41771
|
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
40893
41772
|
|
|
@@ -41471,6 +42350,21 @@ async function connectSite(web3Provider) {
|
|
|
41471
42350
|
}, { type: CheckoutErrorType.USER_REJECTED_REQUEST_ERROR });
|
|
41472
42351
|
return web3Provider;
|
|
41473
42352
|
}
|
|
42353
|
+
async function requestPermissions(web3Provider) {
|
|
42354
|
+
if (!web3Provider || !web3Provider.provider?.request) {
|
|
42355
|
+
throw new CheckoutError('Incompatible provider', CheckoutErrorType.PROVIDER_REQUEST_MISSING_ERROR, { details: 'Attempting to connect with an incompatible provider' });
|
|
42356
|
+
}
|
|
42357
|
+
await withCheckoutError(async () => {
|
|
42358
|
+
if (!web3Provider.provider.request)
|
|
42359
|
+
return;
|
|
42360
|
+
await web3Provider.provider.request({
|
|
42361
|
+
method: WalletAction.REQUEST_PERMISSIONS,
|
|
42362
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
42363
|
+
params: [{ eth_accounts: {} }],
|
|
42364
|
+
});
|
|
42365
|
+
}, { type: CheckoutErrorType.USER_REJECTED_REQUEST_ERROR });
|
|
42366
|
+
return web3Provider;
|
|
42367
|
+
}
|
|
41474
42368
|
|
|
41475
42369
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
41476
42370
|
async function getMetaMaskProvider() {
|
|
@@ -44619,7 +45513,12 @@ class Checkout {
|
|
|
44619
45513
|
*/
|
|
44620
45514
|
async connect(params) {
|
|
44621
45515
|
const web3Provider = await validateProvider(this.config, params.provider, { allowUnsupportedProvider: true });
|
|
44622
|
-
|
|
45516
|
+
if (params.requestWalletPermissions && !web3Provider.provider?.isPassport) {
|
|
45517
|
+
await requestPermissions(web3Provider);
|
|
45518
|
+
}
|
|
45519
|
+
else {
|
|
45520
|
+
await connectSite(web3Provider);
|
|
45521
|
+
}
|
|
44623
45522
|
return { provider: web3Provider };
|
|
44624
45523
|
}
|
|
44625
45524
|
/**
|